1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 05:08:05 +11:00

Add ~C! to override memory low level write routines

Also, turn AT28! and AT28, into ~AT28, pluggable into ~C!.

~AT28 doesn't check for mismatches. It was too complicated to turn
a mismatch into a compiled word we would jump to next. Data
integrity has to be checked through another path.

Also, remove MOVEW. Without indirect memory access, this word
doesn't make sense. Some AVR-specific words will have to be
defined.
This commit is contained in:
Virgil Dupras 2020-12-08 21:51:05 -05:00
parent 953e040231
commit 594b3c3348
4 changed files with 41 additions and 39 deletions

53
blk.fs
View File

@ -1048,6 +1048,11 @@ VARIABLE lbluflw VARIABLE lblexec
( 7.373MHz target: 737t. outer: 37t inner: 16t )
( tickfactor = (737 - 37) / 16 )
CREATE tickfactor 44 ,
( Perform a byte write by taking into account the SYSVARS+3e
override. )
: LD(HL)E*, SYSVARS 0x3e + LDA(i), A ORr,
IFZ, (HL) E LDrr, ELSE, SYSVARS 0x3e + CALL, THEN, ;
( ----- 283 )
H@ ORG ! ( STABLE ABI )
0 JP, ( 00, main ) NOP, ( unused ) NOP, NOP, ( 04, BOOT )
@ -1072,6 +1077,7 @@ HERESTART [IF]
HL HERESTART LDdi,
[THEN]
SYSVARS 0x04 + LD(i)HL, ( RAM+04 == HERE )
A XORr, SYSVARS 0x3e + LD(i)A, ( 3e == ~C! )
DE BIN( @ 0x04 ( BOOT ) + LDd(i),
JR, L1 FWR ( execute, B287 )
( ----- 286 )
@ -1458,9 +1464,8 @@ CODE TICKS
( ----- 322 )
CODE !
HL POP, DE POP, chkPS,
(HL) E LDrr,
HL INCd,
(HL) D LDrr,
LD(HL)E*, HL INCd,
E D LDrr, LD(HL)E*,
;CODE
CODE @
HL POP, chkPS,
@ -1472,14 +1477,17 @@ CODE @
( ----- 323 )
CODE C!
HL POP, DE POP, chkPS,
(HL) E LDrr,
;CODE
LD(HL)E*, ;CODE
CODE C@
HL POP, chkPS,
L (HL) LDrr,
H 0 LDri,
HL PUSH,
H 0 LDri, HL PUSH, ;CODE
CODE ~C!
HL POP, chkPS,
SYSVARS 0x3f + LD(i)HL,
HLZ, ( makes A zero if Z is set ) IFNZ,
A 0xc3 ( JP ) LDri, THEN,
( A is either 0 or c3 ) SYSVARS 0x3e + LD(i)A,
;CODE
( ----- 324 )
CODE PC! EXX, ( protect BC )
@ -1862,12 +1870,6 @@ SYSVARS 0x0c + :** C<*
LOOP THEN 2DROP ;
: MOVE, ( a u -- ) H@ OVER ALLOT SWAP MOVE ;
( ----- 368 )
: MOVEW ( src dst u -- )
( u ) 0 DO
SWAP DUP I 1 LSHIFT + C@ ( dst src x )
ROT TUCK I 1 LSHIFT + ( src dst x dst )
C! ( src dst )
LOOP 2DROP ;
: PREV 3 - DUP @ - ;
: [entry] ( w -- )
C@+ ( w+1 len ) TUCK MOVE, ( len )
@ -2162,21 +2164,14 @@ XCURRENT @ _xapply ORG @ 0x04 ( stable ABI BOOT ) + !
':' X' _ 4 - C! ( give : its name )
'(' X' _ 4 - C!
( ----- 400 )
( With dst being assumed to be an AT28 EEPROM, perform C!
operation while doing the right thing. Checks data integrity
and ABORT on mismatch. )
: _ ( n a -- wait until addr is "stable", err on mismatch )
( as long as writing operation is running, IO/6 will toggle
at each read attempt. We know that write is finished when
we read the same value twice. )
BEGIN ( n1 a )
DUP C@ ( n1 a n2 )
OVER C@ ( n1 a n2 n3 )
= UNTIL
( We're finished writing. do we have a mismatch? )
C@ SWAP 0xff AND = NOT IF ABORT" mismatch" THEN ;
: AT28! ( n a -- ) 2DUP C! _ ;
: AT28, ( n -- ) H@ 2DUP C! DUP 1+ HERE ! _ ;
( Write byte E at addr HL, assumed to be an AT28 EEPROM.
After that, poll repeatedly that address until writing is
complete. )
(entry) ~AT28 ( warning: don't touch D register )
(HL) E LDrr, E (HL) LDrr, ( poll ) BEGIN,
A (HL) LDrr, ( poll ) E CPr, ( same as old? )
E A LDrr, ( save old poll, Z preserved )
JRNZ, AGAIN, RET,
( ----- 401 )
Grid subsystem

Binary file not shown.

View File

@ -152,6 +152,7 @@ J -- n Copy RS third item to PS
, n -- Write n in HERE and advance it.
? a -- Print value of addr a
+! n a -- Increase value of addr a by n
~C! a -- Set C! and ! overrides. See notes.
C@ a -- c Set c to byte at address a
C@+ a -- a+1 c Fetch c from a and inc a.
C@- a -- a-1 c Fetch c from a and dec a.
@ -173,13 +174,15 @@ MOVE a1 a2 u -- Copy u bytes from a1 to a2, starting
MOVE- a1 a2 u -- Copy u bytes from a1 to a2, starting
with a1+u, going down.
MOVE, a u -- Copy u bytes from a to HERE.
MOVEW src dst u -- Same as MOVE, but with words
MOVEW notes: this word's purpose is to interface with word-
based systems. src and dst are addressed as *bytes* but u is a
*word* count. Every iteration increases src and dst by 2. This
shouldn't be used on regular memory, it will yield weird
results. Use it with C!* ialias pointing to a word-based target.
Notes:
~C!: When supplied a non-zero address, sets the SYSVARS+3e (see
impl.txt) override routine address. This should link dir-
ectly to assembly code because we call this address. This
routine shouldn't end with a call to next, but rather a
regular assembly return. Registers used are arch-specific.
When supplied 0, unsets override.
# Arithmetic / Bits

View File

@ -159,10 +159,10 @@ offsets, but thankfully, there aren't many system variables.
Here's a list of them:
SYSVARS FUTURE USES +3c BLK(*
+02 CURRENT +3e FUTURE USES
+04 HERE +40 FUTURE USES
+06 C<? +42 FUTURE USES
+08 C<* override +44 FUTURE USES
+02 CURRENT +3e ~C!*
+04 HERE +41 FUTURE USES
+06 C<? +43 FUTURE USES
+08 C<* override +45 FUTURE USES
+0a NL ialias +51 CURRENTPTR
+0c C<* +53 EMIT ialias
+0e WORDBUF +55 KEY ialias
@ -193,6 +193,10 @@ for example), it can point elsewhere.
BLK* "Disk blocks" in usage.txt.
~C!* if nonzero, contains a jump to assembly code that overrides
the routine that writes a byte to memory and then returns.
Register usage is arch-dependent, see boot code for details.
DRIVERS section is reserved for recipe-specific drivers.
FUTURE USES section is unused for now.