diff --git a/arch/z80/sms/blk/603 b/arch/z80/sms/blk/603 index 62d26c6..981342c 100644 --- a/arch/z80/sms/blk/603 +++ b/arch/z80/sms/blk/603 @@ -1,4 +1,3 @@ -: XYPOS [ VDP_MEM LITN ] ; CODE _ctl ( a -- sends LSB then MSB ) HL POP, chkPS, A L LDrr, VDP_CTLPORT OUTiA, diff --git a/arch/z80/sms/blk/607 b/arch/z80/sms/blk/607 index 41edeed..81d03b6 100644 --- a/arch/z80/sms/blk/607 +++ b/arch/z80/sms/blk/607 @@ -1,9 +1,3 @@ -: _cell! ( tilenum pos ) - 2 * 0x7800 OR _ctl ( tilenum ) _data 1 _zero ; -: _lf - XYPOS @ BEGIN ( pos ) - 0 ( blank ) SWAP TUCK _cell! - 1+ DUP [ VDP_COLS LITN ] MOD NOT UNTIL - [ VDP_COLS VDP_ROWS * LITN ] MOD XYPOS ! ; -: _bs 0 ( blank ) XYPOS @ TUCK _cell! ( pos ) 1- - [ VDP_COLS VDP_ROWS * LITN ] MOD XYPOS ! ; +: CELL! ( tilenum pos ) + 2 * 0x7800 OR _ctl ( tilenum ) + 0x5e MOD _data 1 _zero ; diff --git a/arch/z80/sms/blk/608 b/arch/z80/sms/blk/608 index 92871ac..e04cde5 100644 --- a/arch/z80/sms/blk/608 +++ b/arch/z80/sms/blk/608 @@ -1,10 +1,3 @@ -: (emit) - DUP 0x08 = IF DROP _bs EXIT THEN - DUP 0x0d = IF DROP _lf EXIT THEN - 0x20 - DUP 0< IF DROP EXIT THEN - DUP 0x5e > IF DROP 0x5e THEN ( tilenum ) XYPOS @ _cell! - XYPOS @ 1+ DUP [ VDP_COLS VDP_ROWS * LITN ] - = IF DROP 0 THEN XYPOS ! ; : VDP$ 9 0 DO _idat I 2 * + @ _ctl LOOP _blank ( palettes ) @@ -12,5 +5,4 @@ ( BG ) 1 _zero 0x3f _data 14 _zero ( sprite, inverted colors ) 0x3f _data 15 _zero 0x4000 _ctl 0x5e 0 DO ~FNT I 7 * + _sfont LOOP - 0 XYPOS ! ( bit 6, enable display, bit 7, ?? ) 0x81c0 _ctl ; diff --git a/arch/z80/sms/xcomp.fs b/arch/z80/sms/xcomp.fs index 7dd3d04..822e36d 100644 --- a/arch/z80/sms/xcomp.fs +++ b/arch/z80/sms/xcomp.fs @@ -4,11 +4,11 @@ 0xddca CONSTANT PS_ADDR RS_ADDR 0x80 - CONSTANT SYSVARS 0xc000 CONSTANT HERESTART -SYSVARS 0x70 + CONSTANT VDP_MEM 0xbf CONSTANT VDP_CTLPORT 0xbe CONSTANT VDP_DATAPORT -32 CONSTANT VDP_COLS -24 CONSTANT VDP_ROWS +SYSVARS 0x70 + CONSTANT GRID_MEM +32 CONSTANT COLS +24 CONSTANT ROWS SYSVARS 0x72 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 @@ -30,12 +30,13 @@ CURRENT @ XCURRENT ! 353 LOAD ( xcomp core low ) CREATE ~FNT CPFNT7x7 603 608 LOADR ( VDP ) +402 404 LOADR ( Grid ) 625 626 LOADR ( SMS ports ) 612 617 LOADR ( PAD ) 390 LOAD ( xcomp core high ) (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," VDP$ PAD$ (im1) " EOT, +," VDP$ 0 0 AT-XY PAD$ (im1) " EOT, ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/arch/z80/sms/xcompkbd.fs b/arch/z80/sms/xcompkbd.fs index 6b5e833..f99e09f 100644 --- a/arch/z80/sms/xcompkbd.fs +++ b/arch/z80/sms/xcompkbd.fs @@ -5,11 +5,11 @@ 0xddca CONSTANT PS_ADDR RS_ADDR 0x80 - CONSTANT SYSVARS 0xc000 CONSTANT HERESTART -SYSVARS 0x70 + CONSTANT VDP_MEM 0xbf CONSTANT VDP_CTLPORT 0xbe CONSTANT VDP_DATAPORT -32 CONSTANT VDP_COLS -24 CONSTANT VDP_ROWS +SYSVARS 0x70 + CONSTANT GRID_MEM +32 CONSTANT COLS +24 CONSTANT ROWS SYSVARS 0x72 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 @@ -31,12 +31,13 @@ CURRENT @ XCURRENT ! 353 LOAD ( xcomp core low ) CREATE ~FNT CPFNT7x7 603 608 LOADR ( VDP ) +402 404 LOADR ( Grid ) 625 626 LOADR ( SMS ports ) 620 LOAD ( PAD ) : (ps2kc) (ps2kcA) ; 411 414 LOADR 390 LOAD ( xcomp core high ) (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," VDP$ PS2$ (im1) " EOT, +," VDP$ 0 0 AT-XY PS2$ (im1) " EOT, ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/arch/z80/sms/xcompsdc.fs b/arch/z80/sms/xcompsdc.fs index ead098a..63bccbb 100644 --- a/arch/z80/sms/xcompsdc.fs +++ b/arch/z80/sms/xcompsdc.fs @@ -6,11 +6,11 @@ 0xddca CONSTANT PS_ADDR RS_ADDR 0x80 - CONSTANT SYSVARS 0xc000 CONSTANT HERESTART -SYSVARS 0x70 + CONSTANT VDP_MEM 0xbf CONSTANT VDP_CTLPORT 0xbe CONSTANT VDP_DATAPORT -32 CONSTANT VDP_COLS -24 CONSTANT VDP_ROWS +SYSVARS 0x70 + CONSTANT GRID_MEM +32 CONSTANT COLS +24 CONSTANT ROWS SYSVARS 0x72 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 @@ -32,6 +32,7 @@ CURRENT @ XCURRENT ! 353 LOAD ( xcomp core low ) CREATE ~FNT CPFNT7x7 603 608 LOADR ( VDP ) +402 404 LOADR ( Grid ) 625 626 LOADR ( SMS ports ) 620 LOAD ( PAD ) : (ps2kc) (ps2kcA) ; 411 414 LOADR 622 LOAD ( SPI ) @@ -40,6 +41,6 @@ CREATE ~FNT CPFNT7x7 (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," VDP$ PS2$ BLK$ (im1) " EOT, +," VDP$ 0 0 AT-XY PS2$ BLK$ (im1) " EOT, ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/blk/001 b/blk/001 index 30ae562..cd018a1 100644 --- a/blk/001 +++ b/blk/001 @@ -6,7 +6,7 @@ MASTER INDEX 160 AVR SPI programmer 170-259 unused 260 Cross compilation 280 Z80 boot code 350 Core words -400 AT28 EEPROM driver 401-410 unused +400 AT28 EEPROM driver 401 Grid subsystem 410 PS/2 keyboard subsystem 418 Z80 SPI Relay driver 420 SD Card subsystem 440 8086 boot code 470-519 unused 520 Fonts diff --git a/blk/401 b/blk/401 new file mode 100644 index 0000000..a378f49 --- /dev/null +++ b/blk/401 @@ -0,0 +1,11 @@ +Grid subsystem + +Given a device driver following the Grid protocol, implement +AT-XY and (emit). (emit) makes the grid behave like a regular +terminal, honoring line feeds and backspaces, wrapping at the +end of a line. + +2 bytes of system memory at GRID_MEM are needed for cursor +position. + +Load range: B402-B403 diff --git a/blk/402 b/blk/402 new file mode 100644 index 0000000..753a778 --- /dev/null +++ b/blk/402 @@ -0,0 +1,10 @@ +: XYPOS [ GRID_MEM LITN ] ; +: AT-XY ( x y -- ) [ ROWS LITN ] * + + [ COLS ROWS * LITN ] MOD XYPOS ! ; +: _lf + XYPOS @ BEGIN ( pos ) + 0 ( blank ) SWAP TUCK CELL! + 1+ DUP [ COLS LITN ] MOD NOT UNTIL + [ COLS ROWS * LITN ] MOD XYPOS ! ; +: _bs 0 ( blank ) XYPOS @ TUCK CELL! ( pos ) 1- + [ COLS ROWS * LITN ] MOD XYPOS ! ; diff --git a/blk/403 b/blk/403 new file mode 100644 index 0000000..92413cb --- /dev/null +++ b/blk/403 @@ -0,0 +1,7 @@ +: (emit) + DUP 0x08 = IF DROP _bs EXIT THEN + DUP 0x0d = IF DROP _lf EXIT THEN + 0x20 - DUP 0< IF DROP EXIT THEN + XYPOS @ CELL! + XYPOS @ 1+ DUP [ COLS ROWS * LITN ] + = IF DROP 0 THEN XYPOS ! ; diff --git a/doc/protocol.txt b/doc/protocol.txt index 85b06bf..b8cafef 100644 --- a/doc/protocol.txt +++ b/doc/protocol.txt @@ -37,3 +37,19 @@ previously enabled one. (spix) n -- n Perform SPI exchange (push a number, get a number back) +# Grid protocol + +A grid is a device that shows as a grid of ASCII characters and +allows random access to it. + +COLS -- n Number of columns in the device +ROWS -- n Number of rows in the device +CELL! g pos -- Set glyph at pos + +"pos" is a simple number (y * cols) + x. For example, if we +have 40 columns per row, the position (x, y) (12, 10) is 412. + +A glyph is ASCII-0x20. If the resulting glyph number exceeds the +number of glyphs in the font, it's up to CELL! to ignore it. + +Glyph 0 is always blank.