Skip to content

Commit

Permalink
Merge pull request #497 from paulscottrobson/debugprint
Browse files Browse the repository at this point in the history
Serial/Stderr output
  • Loading branch information
paulscottrobson authored May 24, 2024
2 parents 0e7444b + 414001f commit 774e821
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 75 deletions.
76 changes: 9 additions & 67 deletions basic/test.bsc
Original file line number Diff line number Diff line change
@@ -1,68 +1,10 @@
'
' *** Tile map demonstration program ***
'
cls:sprite clear:gload "graphics.gfx"
rect 0,0 solid ink 4 to 319,239

call CreateTileMap()
xPos = 0:yPos = 0
call DrawTileMap(xPos,yPos)
repeat
if event(t1,2)
fire = joypad(dx,dy)
xPos = max(xPos+dx,0):yPos = max(yPos+dy,0)
call DrawTileMap(xPos,yPos)
endif
until false
end
'
' This draws the tilemap offset by x,y
'
proc DrawTileMap(xo,yo)
ink 7:print chr$(20);"At offset ";xo;" ";yo;" "
' Sets the tilemap data to draw with and the offset in pixels.
tilemap map,xo,yo
' Draw the tilemap in a window
tiledraw 10,20 to 240,210
' Draw a small second one using the same data
tiledraw 250,20 to 310,80
endproc
'
' This creates a single tile map in memory. See api.pdf
'
proc CreateTileMap()
width = 30:height = 20
' an array of memory with a small header : type, width and height.
map = alloc(width*height+3)
poke map,1: poke map+1, width: poke map+2, height
' Fill the map with $F2 which is a solid green block.
for i = 0 to width*height-1:poke map+3+i,$F2:next
' Draw a frame around the whole screen
call DrawRect(0,0,width,height,$F3,-1)
' Draw some things on the tilemap
call DrawRect(3,2,8,5,6,0)
call DrawRect(17,6,10,7,6,3)
call DrawRect(5,10,10,7,6,5)
endproc

'
' Draw a rectangle on the tile map at (x,y) size (w,h) with frame edgeColour
' and fill with fillColour (if >= 0)
'
proc DrawRect(x,y,w,h,edgeColour,fillColour)
if fillColour >= 0
for i = x to x+w-1
for j = y to y+h-1
call set(i,j,fillColour)
next
next
endif
for i = x to x+w-1:call set(i,y,edgeColour):call set(i,y+h-1,edgeColour):next
for i = y to y+h-1:call set(x,i,edgeColour):call set(x+w-1,i,edgeColour):next
endproc
'
' Set tilemap tile to x,y
'
proc set(x,y,t)
poke map+x+3+y*width,t
endproc
' error test
'
a$ = "Hello world"+chr$(13)+chr$(10)
for i = 1 to len(a$)
c = asc(mid$(a$,i,1))
poke $FF04,c
poke $FF01,10
poke $FF00,1
next
5 changes: 5 additions & 0 deletions documents/release/source/api.gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Execute Sweet 16 VM Code with the register set provided. The error return value
call for Windows emulation ; if it returns non-zero it means the VM has been executed, if it returns zero
then the emulation can update as at the end of a normal frame.

## Function 10 : Write character to debug

Writes a single character to the debug port (the UART on the Pico, or stderr on the emulator). This allows
maximum flexibility.

\newpage

# Group 2 : Console
Expand Down
1 change: 1 addition & 0 deletions emulator/src/core/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void HWQueueKeyboardEvent(int sdlCode,int isDown) {
// *******************************************************************************************************************************

void FDBWrite(uint8_t c) {
fputc(c,stderr);
}

// ***************************************************************************************
Expand Down
8 changes: 7 additions & 1 deletion firmware/common/config/system/group1_system.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ GROUP 1 System
Execute Sweet 16 VM Code with the register set provided. The error return value is actually a re-entrant
call for Windows emulation ; if it returns non-zero it means the VM has been executed, if it returns zero
then the emulation can update as at the end of a normal frame.


FUNCTION 10 Write character to debug
FDBWrite(DPARAMS[0]);
DOCUMENTATION
Writes a single character to the debug port (the UART on the Pico, or stderr on the emulator). This allows
maximum flexibility.

1 change: 1 addition & 0 deletions firmware/common/include/interface/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bool SERIsByteAvailable(void);
uint8_t SERReadByte(void);
void SERWriteByte(uint8_t b);
void SERCheckDataAvailable(void);
bool SERSetup(void);

#endif

Expand Down
26 changes: 19 additions & 7 deletions firmware/common/sources/interface/serialmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,38 @@

static bool SERCommand(uint8_t command,uint8_t *data,uint8_t size);

static bool isInitialised = false;

// ***************************************************************************************
//
// Input and process buffer.
// Attempt to initialise Serial I/O
//
// ***************************************************************************************

static uint8_t sBuffer[256]; // Input buffer.
static bool isInitialised = false;

void SERCheckDataAvailable(void) {
bool SERSetup(void) {
if (!isInitialised) { // Try to initialise it.
isInitialised = SERInitialise(); // Initialise serial port.
if (!isInitialised) {
CONWriteString("Serial not functioning.\r"); // Failed to initialise.
return;
return false;
}
while (SERIsByteAvailable()) SERReadByte(); // Clear anything already incoming.
}
SERSetSerialFormat(SERIAL_TRANSFER_BAUD_RATE,SERIAL_PROTOCOL_8N1); // Set transceive format.

return true;
}

// ***************************************************************************************
//
// Input and process buffer.
//
// ***************************************************************************************

static uint8_t sBuffer[256]; // Input buffer.

void SERCheckDataAvailable(void) {

if (!SERSetup()) return; // Initialise serial I/O if not done
bool completed = false;
CONWriteString("Serial link enabled.\r");
while (!completed) {
Expand Down
12 changes: 12 additions & 0 deletions firmware/sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ int main() {
while (1) CPUExecute(); // Doesn't have to loop but can.
}

// ***************************************************************************************
//
// Dummy debug write
//
// ***************************************************************************************

void FDBWrite(uint8_t c) {
if (SERSetup()) {
SERWriteByte(c);
}
}

// ***************************************************************************************
//
// Date Revision
Expand Down

0 comments on commit 774e821

Please sign in to comment.