rc2014: add a declaration part to ACIA drivers

Driver configuration don't need their own words at runtime, we only
need to compile them as literals when compiling words.

Now that we have this "declaration blocks" pattern emerging, it
seems like a good idea to take advantage of this in drivers, both
for simplifying the xcomp unit and to make final binary slimmer.
This commit is contained in:
Virgil Dupras 2020-06-28 17:30:01 -04:00
parent b8800be76f
commit 9424770caa
9 changed files with 37 additions and 49 deletions

16
blk/581
View File

@ -2,15 +2,11 @@ ACIA driver
Manage I/O from an asynchronous communication interface adapter Manage I/O from an asynchronous communication interface adapter
(ACIA). provides "(emit)" to put c char on the ACIA as well as (ACIA). provides "(emit)" to put c char on the ACIA as well as
an input buffer from which a provided "(key)" reads. You have an input buffer from which a provided "(key)" reads. This driver
to call "~ACIA" on interrupt for this module to work well. installs an interrupt handler at RST38 to handle RX.
CONFIGURATION To use, begin by loading declarations (B582) before xcomp is
loaded. These declarations provide default values for ports and
memory offsets that you can override. See B582.
ACIA_CTL: IO port for the ACIA's control registers Then, in the driver part, load range 583-588.
ACIA_IO: IO port for the ACIA's data registers
ACIA_MEM: Address in memory that can be used variables shared
with ACIA's native words. 8 bytes used.
The whole driver is cross-compilable and is loaded with
"582 LOAD"

22
blk/582
View File

@ -1,7 +1,15 @@
( Memory layout 0x80 CONSTANT ACIA_CTL ( IO port for ACIA's control register )
+0 ACIAR> 0x81 CONSTANT ACIA_IO ( IO port for ACIA's data registers )
+2 ACIAW> ( Address in memory that can be used variables shared
+4 ACIA( with ACIA's native words. 8 bytes used. )
+6 ACIA) ) CREATE ACIA_MEM RAMSTART 0x70 + ,
( Points to ACIA buf )
1 6 LOADR+ : ACIA( ACIA_MEM @ 4 + ;
( Points to ACIA buf end )
: ACIA) ACIA_MEM @ 6 + ;
( Read buf pointer. Pre-inc )
: ACIAR> ACIA_MEM @ ;
( Write buf pointer. Post-inc )
: ACIAW> ACIA_MEM @ 2+ ;
( This means that if W> == R>, buffer is full.
If R>+1 == W>, buffer is empty. )

View File

@ -5,10 +5,9 @@
0x01 ANDi, ( is ACIA rcv buf full? ) 0x01 ANDi, ( is ACIA rcv buf full? )
IFNZ, IFNZ,
( correct interrupt cause ) ( correct interrupt cause )
( +2 == ACIAW> ) ACIAW> LDHL(n),
ACIA_MEM 2+ LDHL(n),
( is it == to ACIAR>? ) ( is it == to ACIAR>? )
( +0 == ACIAR> ) ( +0 == ACIAR> )
DE ACIA_MEM LDdd(n), DE ACIAR> LDdd(n),
( carry cleared from ANDi above ) ( carry cleared from ANDi above )
DE SBCHLd, ( cont. ) DE SBCHLd, ( cont. )

View File

@ -6,10 +6,8 @@
(HL) A LDrr, (HL) A LDrr,
( advance W> ) ( advance W> )
HL INCd, HL INCd,
( +2 == ACIAW> ) ACIAW> LD(n)HL,
ACIA_MEM 2+ LD(n)HL, DE ACIA) LDdd(n),
( +6 == ACIA) )
DE ACIA_MEM 6 + LDdd(n),
DE SUBHLd, DE SUBHLd,

View File

@ -1,9 +1,7 @@
IFZ, ( end of buffer reached? ) IFZ, ( end of buffer reached? )
( yes ) ( yes )
( +4 == ACIA( ) ACIA( LDHL(n),
ACIA_MEM 4 + LDHL(n), ACIAW> LD(n)HL,
( +2 == ACIAW> )
ACIA_MEM 2+ LD(n)HL,
THEN, THEN,
THEN, THEN,
THEN, THEN,

10
blk/586
View File

@ -1,10 +0,0 @@
( Points to ACIA buf )
: ACIA( [ ACIA_MEM 4 + LITN ] ;
( Points to ACIA buf end )
: ACIA) [ ACIA_MEM 6 + LITN ] ;
( Read buf pointer. Pre-inc )
: ACIAR> [ ACIA_MEM LITN ] ;
( Write buf pointer. Post-inc )
: ACIAW> [ ACIA_MEM 2 + LITN ] ;
( This means that if W> == R>, buffer is full.
If R>+1 == W>, buffer is empty. )

10
blk/587
View File

@ -1,12 +1,12 @@
: (key) : (key)
( inc then fetch ) ( inc then fetch )
ACIAR> @ 1+ DUP ACIA) @ = IF [ ACIAR> LITN ] @ 1+ DUP [ ACIA) LITN ] @ = IF
DROP ACIA( @ DROP [ ACIA( LITN ] @
THEN THEN
( As long as R> == W>-1, it means that buffer is empty ) ( As long as R> == W>-1, it means that buffer is empty )
BEGIN DUP ACIAW> @ = NOT UNTIL BEGIN DUP [ ACIAW> LITN ] @ = NOT UNTIL
ACIAR> ! [ ACIAR> LITN ] !
ACIAR> @ C@ [ ACIAR> LITN ] @ C@
; ;
: (emit) : (emit)
( As long at CTL bit 1 is low, we are transmitting. wait ) ( As long at CTL bit 1 is low, we are transmitting. wait )

View File

@ -1,8 +1,8 @@
: ACIA$ : ACIA$
H@ DUP DUP ACIA( ! ACIAR> ! H@ DUP DUP [ ACIA( LITN ] ! [ ACIAR> LITN ] !
1+ ACIAW> ! ( write index starts one position later ) 1+ [ ACIAW> LITN ] ! ( write index starts one pos later )
0x20 ( buffer size ) ALLOT 0x20 ( buffer size ) ALLOT
H@ ACIA) ! H@ [ ACIA) LITN ] !
( setup ACIA ( setup ACIA
CR7 (1) - Receive Interrupt enabled CR7 (1) - Receive Interrupt enabled
CR6:5 (00) - RTS low, transmit interrupt disabled. CR6:5 (00) - RTS low, transmit interrupt disabled.

View File

@ -1,13 +1,12 @@
0x8000 CONSTANT RAMSTART 0x8000 CONSTANT RAMSTART
0xff00 CONSTANT RS_ADDR 0xfffa CONSTANT PS_ADDR 0xff00 CONSTANT RS_ADDR 0xfffa CONSTANT PS_ADDR
0x80 CONSTANT ACIA_CTL 0x81 CONSTANT ACIA_IO
4 CONSTANT SDC_SPI 4 CONSTANT SDC_SPI
5 CONSTANT SDC_CSLOW 6 CONSTANT SDC_CSHIGH 5 CONSTANT SDC_CSLOW 6 CONSTANT SDC_CSHIGH
RAMSTART 0x70 + CONSTANT ACIA_MEM 582 LOAD ( acia decl )
212 LOAD ( z80 assembler ) 212 LOAD ( z80 assembler )
262 LOAD ( xcomp ) 282 LOAD ( boot.z80.decl ) 262 LOAD ( xcomp ) 282 LOAD ( boot.z80.decl )
270 LOAD ( xcomp overrides ) 283 335 LOADR ( boot.z80 ) 270 LOAD ( xcomp overrides ) 283 335 LOADR ( boot.z80 )
353 LOAD ( xcomp core low ) 582 LOAD ( acia ) 353 LOAD ( xcomp core low ) 583 588 LOADR ( acia )
380 LOAD ( xcomp core high ) 380 LOAD ( xcomp core high )
(entry) _ (entry) _
( Update LATEST ) ( Update LATEST )