diff --git a/arch/z80/sms/xcomp.fs b/arch/z80/sms/xcomp.fs index cbd046b..82118cb 100644 --- a/arch/z80/sms/xcomp.fs +++ b/arch/z80/sms/xcomp.fs @@ -7,11 +7,11 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 0xbf CONSTANT TMS_CTLPORT 0xbe CONSTANT TMS_DATAPORT SYSVARS 0x70 + CONSTANT GRID_MEM -SYSVARS 0x72 + CONSTANT CPORT_MEM +SYSVARS 0x73 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 0xdd CONSTANT CPORT_D2 -SYSVARS 0x73 + CONSTANT PAD_MEM +SYSVARS 0x74 + CONSTANT PAD_MEM 5 LOAD ( z80 assembler ) : ZFILL, ( u ) 0 DO 0 A, LOOP ; 262 LOAD ( xcomp ) @@ -36,6 +36,6 @@ CREATE ~FNT CPFNT7x7 (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," VDP$ 0 0 AT-XY PAD$ (im1) " EOT, +," VDP$ GRID$ 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 909cb49..c04f488 100644 --- a/arch/z80/sms/xcompkbd.fs +++ b/arch/z80/sms/xcompkbd.fs @@ -8,11 +8,11 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 0xbf CONSTANT TMS_CTLPORT 0xbe CONSTANT TMS_DATAPORT SYSVARS 0x70 + CONSTANT GRID_MEM -SYSVARS 0x72 + CONSTANT CPORT_MEM +SYSVARS 0x73 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 0xdd CONSTANT CPORT_D2 -SYSVARS 0x73 + CONSTANT PS2_MEM +SYSVARS 0x74 + CONSTANT PS2_MEM 5 LOAD ( z80 assembler ) : ZFILL, ( u ) 0 DO 0 A, LOOP ; 262 LOAD ( xcomp ) @@ -37,6 +37,6 @@ CREATE ~FNT CPFNT7x7 (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," VDP$ 0 0 AT-XY PS2$ (im1) " EOT, +," VDP$ GRID$ 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 6daac4b..ae61224 100644 --- a/arch/z80/sms/xcompsdc.fs +++ b/arch/z80/sms/xcompsdc.fs @@ -9,11 +9,11 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 0xbf CONSTANT TMS_CTLPORT 0xbe CONSTANT TMS_DATAPORT SYSVARS 0x70 + CONSTANT GRID_MEM -SYSVARS 0x72 + CONSTANT CPORT_MEM +SYSVARS 0x73 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 0xdd CONSTANT CPORT_D2 -SYSVARS 0x73 + CONSTANT PS2_MEM +SYSVARS 0x74 + CONSTANT PS2_MEM 5 LOAD ( z80 assembler ) : ZFILL, ( u ) 0 DO 0 A, LOOP ; 262 LOAD ( xcomp ) @@ -40,6 +40,6 @@ CREATE ~FNT CPFNT7x7 (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," VDP$ 0 0 AT-XY PS2$ BLK$ (im1) " EOT, +," VDP$ GRID$ PS2$ BLK$ (im1) " EOT, ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/arch/z80/sms/xcomptextmode.fs b/arch/z80/sms/xcomptextmode.fs index 9ed050e..46230fe 100644 --- a/arch/z80/sms/xcomptextmode.fs +++ b/arch/z80/sms/xcomptextmode.fs @@ -9,11 +9,11 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 0xbf CONSTANT TMS_CTLPORT 0xbe CONSTANT TMS_DATAPORT SYSVARS 0x70 + CONSTANT GRID_MEM -SYSVARS 0x72 + CONSTANT CPORT_MEM +SYSVARS 0x73 + CONSTANT CPORT_MEM 0x3f CONSTANT CPORT_CTL 0xdc CONSTANT CPORT_D1 0xdd CONSTANT CPORT_D2 -SYSVARS 0x73 + CONSTANT PS2_MEM +SYSVARS 0x74 + CONSTANT PS2_MEM 5 LOAD ( z80 assembler ) : ZFILL, ( u ) 0 DO 0 A, LOOP ; 262 LOAD ( xcomp ) @@ -33,10 +33,12 @@ CREATE ~FNT CPFNT5x7 402 404 LOADR ( Grid ) 625 626 LOADR ( SMS ports ) 620 LOAD ( PAD ) : (ps2kc) (ps2kcA) ; 411 414 LOADR +622 LOAD ( SPI ) +1 CONSTANT SDC_DEVID 423 436 LOADR ( SDC ) 390 LOAD ( xcomp core high ) (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," TMS$ 0 0 AT-XY PS2$ (im1) " EOT, +," TMS$ GRID$ PS2$ BLK$ ' SDC@ BLK@* ! (im1) " EOT, ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/arch/z80/ti84/xcomp.fs b/arch/z80/ti84/xcomp.fs index a48c155..fe4cb26 100644 --- a/arch/z80/ti84/xcomp.fs +++ b/arch/z80/ti84/xcomp.fs @@ -4,7 +4,7 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 0x8000 CONSTANT HERESTART SYSVARS 0x70 + CONSTANT LCD_MEM SYSVARS 0x72 + CONSTANT GRID_MEM -SYSVARS 0x74 + CONSTANT KBD_MEM +SYSVARS 0x75 + CONSTANT KBD_MEM 0x01 CONSTANT KBD_PORT 5 LOAD ( z80 assembler ) : ZFILL, ( u ) 0 DO 0 A, LOOP ; @@ -72,6 +72,6 @@ CREATE ~FNT CPFNT3x5 (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," LCD$ KBD$ " EOT, +," LCD$ KBD$ GRID$ " EOT, ORG @ 0x100 - 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/blk.fs b/blk.fs index 18bf55a..8040a8b 100644 --- a/blk.fs +++ b/blk.fs @@ -902,15 +902,15 @@ CREATE PREVPOS 0 , CREATE PREVBLK 0 , CREATE xoff 0 , DUP CMD 2+ C! CMD FIND IF EXECUTE ELSE DROP THEN 0 ACC ! UPPER 'Q' = ; : bufp ( buf -- ) - DUP 3 col- + SWAP DO I C@ 0x20 MAX EMIT LOOP ; + DUP 3 col- + SWAP DO I C@ EMIT LOOP ; : bufs 1 aty ." I: " IBUF bufp 2 aty ." F: " FBUF bufp large? IF 0 3 gutter THEN ; : VE - clrscr 0 ACC ! 0 PREVPOS ! nums contents + 1 XYMODE C! clrscr 0 ACC ! 0 PREVPOS ! nums contents BEGIN xoff? status bufs setpos KEY handle UNTIL - 19 aty (infl) ; + 0 XYMODE C! 19 aty (infl) ; ( ----- 160 ) ( AVR Programmer, load range 160-163. doc/avr.txt ) ( page size in words, 64 is default on atmega328P ) @@ -2209,23 +2209,17 @@ XCURRENT @ _xapply ORG @ 0x04 ( stable ABI BOOT ) + ! ( ----- 401 ) 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. +See doc/grid.txt. Load range: B402-B403 ( ----- 402 ) -: XYPOS [ GRID_MEM LITN ] ; +: XYPOS [ GRID_MEM LITN ] ; : XYMODE [ GRID_MEM LITN ] 2+ ; : _cl* COLS LINES * ; : AT-XY ( x y -- ) COLS * + _cl* MOD XYPOS ! ; '? NEWLN NIP NOT [IF] : NEWLN ( ln -- ) COLS * DUP COLS + SWAP DO 0 I CELL! LOOP ; [THEN] -: _lf +: _lf XYMODE C@ IF EXIT THEN XYPOS @ COLS / 1+ LINES MOD DUP NEWLN COLS * XYPOS ! ; : _bs 0 ( blank ) XYPOS @ TUCK CELL! ( pos ) 1- @@ -2237,6 +2231,7 @@ Load range: B402-B403 0x20 - DUP 0< IF DROP EXIT THEN XYPOS @ CELL! XYPOS @ 1+ DUP COLS MOD IF XYPOS ! ELSE _lf THEN ; +: GRID$ 0 XYPOS ! 0 XYMODE C! ; ( ----- 410 ) PS/2 keyboard subsystem diff --git a/cvm/forth.c b/cvm/forth.c index 6f7bfd2..764b570 100644 --- a/cvm/forth.c +++ b/cvm/forth.c @@ -52,11 +52,8 @@ static void iowr_stdio(uint8_t val) if (fp != NULL) { putchar(val); } else { - if (val >= 0x20 || val == '\n') { + if (val >= 0x20) { wechochar(w, val); - } else if (val == 0x08) { - int y, x; getyx(w, y, x); - wmove(w, y, x-1); } } } diff --git a/cvm/forth.fs b/cvm/forth.fs index e72064a..a6899bf 100644 --- a/cvm/forth.fs +++ b/cvm/forth.fs @@ -9,7 +9,7 @@ SYSVARS 0x70 + CONSTANT GRID_MEM (entry) _ ( Update LATEST ) PC ORG @ 8 + ! -," BLK$ ' EFS@ BLK@* ! ' EFS! BLK!* ! 0 0 AT-XY " EOT, +," BLK$ ' EFS@ BLK@* ! ' EFS! BLK!* ! GRID$ " EOT, ORG @ 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! diff --git a/doc/grid.txt b/doc/grid.txt new file mode 100644 index 0000000..81cd1d7 --- /dev/null +++ b/doc/grid.txt @@ -0,0 +1,40 @@ +# The Grid subsystem + +The grid subsystem at B401 supplies a set of words on top of +the Grid protocol (see doc/protocol.txt) that facilitates the +development of programs presenting a complex text interface, +for example, the Visual Editor. + +It create the concept of a cursor, always being a some position +on screen. That position is in the variable XYPOS, which is a +simple integer following the same "pos" logic as in the Grid +protocol. + +It implements (emit), which sets the cell under the cursor to +the specified character, then moves the cursor right. If the +cursor is at the last column of the screen, it overflows to the +next line. If it's on the last line, it overflows to the first +line. + +Grid's (emit) handles 0xd by moving the cursor to the next line +and 0x8 by moving the cursor left. + +AT-XY ( x y -- ) moves the cursor to the specified position. It +is equivalent to setting XYPOS directly, but uses separate X +and y numbers. + +When the grid's cursor enters a new line, it clears its +contents through a repeated call to CELL!. That implementation +is in its world named NEWLN ( ln -- ). This word can be over- +ridden. If it exists when the grid subsystem is loaded, the ex- +isting NEWLN will be used. + +The clearing of the newly entered line is usually only desirable +when in "shell" mode. In "graphical" mode, we usually don't +want this to happen. XYMODE is a flag to indicate whether the +grid system is in "graphical" mode. When its value is nonzero, +NEWLN is not called when entering a new line. + +At build time, the Grid subsystem needs 3 bytes of system me- +mory through the GRID_MEM constant. At run time, GRID$ needs to +be called to initialize the system.