1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 09:48:05 +11:00

Add one layer of indirection in subsystem memory management

This allows optional subsystems to not needlessly reserve too much
system memory and it also reduces offsets bookkeeping.
This commit is contained in:
Virgil Dupras 2020-04-12 20:42:00 -04:00
parent d4f65911c0
commit d996dd8c9e
6 changed files with 64 additions and 46 deletions

View File

@ -21,6 +21,23 @@ directly, but as part of another word.
"*I*" in description indicates an IMMEDIATE word.
*** Symbols ***
Throughout words, different symbols are used in different contexts, but we try
to been consistent in their use. Here's their definitions:
! - Store
@ - Fetch
$ - Initialize
^ - Arguments in their opposite order
> - Pointer in a buffer
( - Lower boundary
) - Upper boundary
< - Input
* - Word indirection (pointer to word)
~ - Container for native code. Usually not an executable word.
? - Is it ...? (example: IMMED?)
*** Defining words ***
(find) a -- a f Read at a and find it in dict. If found, f=1 and
a = wordref. If not found, f=0 and a = string addr.

View File

@ -1 +1 @@
: INIT (c<$) INTERPRET ;
: INIT RDLN$ Z80A$ INTERPRET ;

Binary file not shown.

View File

@ -8,22 +8,23 @@
routine. )
64 CONSTANT INBUFSZ
( points to INBUF )
: IN( 0x53 RAM+ ;
( points to INBUF's end )
: IN) 0x55 RAM+ ;
: RDLNMEM+ 0x53 RAM+ @ + ;
( current position in INBUF )
: IN> 0x57 RAM+ ;
: IN> 0 RDLNMEM+ ;
( points to INBUF )
: IN( 2 RDLNMEM+ ;
( points to INBUF's end )
: IN) INBUFSZ 2 + RDLNMEM+ ;
( flush input buffer )
( set IN> to IN( and set IN> @ to null )
: (infl) 0 IN( @ DUP IN> ! ! ;
: (infl) 0 IN( DUP IN> ! ! ;
( handle backspace: go back one char in IN>, if possible, then
emit SPC + BS )
: (inbs)
( already at IN( ? )
IN> @ IN( @ = IF EXIT THEN
IN> @ IN( = IF EXIT THEN
IN> @ 1 - IN> !
SPC BS
;
@ -32,7 +33,7 @@
should continue, that is, whether CR was not met. )
: (rdlnc) ( -- f )
( buffer overflow? same as if we typed a newline )
IN> @ IN) @ = IF 0x0a ELSE KEY THEN ( c )
IN> @ IN) = IF 0x0a ELSE KEY THEN ( c )
( del? same as backspace )
DUP 0x7f = IF DROP 0x8 THEN
( lf? same as cr )
@ -58,7 +59,7 @@
FLAGS @ 0x1 AND NOT IF '>' EMIT SPC THEN
(infl)
BEGIN (rdlnc) NOT UNTIL
LF IN( @ IN> !
LF IN( IN> !
;
( And finally, implement a replacement for the (c<) routine )
@ -71,13 +72,12 @@
;
( Initializes the readln subsystem )
: (c<$)
H@ IN( !
INBUFSZ ALLOT
H@ IN) !
( We need two extra bytes. 1 for the last typed 0x0a and
one for the following NULL. )
2 ALLOT
: RDLN$
( 53 == rdln's memory )
H@ 0x53 RAM+ !
( 2 for IN>, plus 2 for extra bytes after buffer: 1 for
the last typed 0x0a and one for the following NULL. )
INBUFSZ 4 + ALLOT
(infl)
['] (rdln<) 0x0c RAM+ !
;

View File

@ -1,21 +1,11 @@
( Z80 assembler )
( Splits word into msb/lsb, lsb being on TOS )
: SPLITB
256 /MOD SWAP
;
: Z80AMEM+ 0x59 RAM+ @ + ;
( H@ offset at which we consider our PC 0. Used to compute
PC. To have a proper PC, call "H@ ORG !" at the beginning
of your assembly process. )
: ORG 0x59 RAM+ ;
: PC H@ ORG @ - ;
( A, spits an assembled byte, A,, spits an assembled word
Both increase PC. To debug, change C, to .X )
: A, C, ;
: A,, SPLITB A, A, ;
: ORG 0 Z80AMEM+ ;
( Labels are a convenient way of managing relative jump
calculations. Backward labels are easy. It is only a matter
@ -27,13 +17,31 @@
To avoid using dict memory in compilation targets, we
pre-declare label variables here, which means we have a
limited number of it. For now, 6 ought to be enough. )
: L1 2 Z80AMEM+ ;
: L2 4 Z80AMEM+ ;
: L3 6 Z80AMEM+ ;
: L4 8 Z80AMEM+ ;
: L5 10 Z80AMEM+ ;
: L6 12 Z80AMEM+ ;
: L1 0x5b RAM+ ;
: L2 0x5d RAM+ ;
: L3 0x5f RAM+ ;
: L4 0x61 RAM+ ;
: L5 0x63 RAM+ ;
: L6 0x65 RAM+ ;
: Z80A$
( 59 == z80a's memory )
H@ 0x59 RAM+ !
14 ALLOT
;
( Splits word into msb/lsb, lsb being on TOS )
: SPLITB
256 /MOD SWAP
;
: PC H@ ORG @ - ;
( A, spits an assembled byte, A,, spits an assembled word
Both increase PC. To debug, change C, to .X )
: A, C, ;
: A,, SPLITB A, A, ;
( There are 2 label types: backward and forward. For each
type, there are two actions: set and write. Setting a label

View File

@ -89,17 +89,10 @@ RAMSTART INITIAL_SP
+2e BOOT C< PTR
+4e INTJUMP
+51 CURRENTPTR
+53 readln's IN(
+55 readln's IN)
+57 readln's IN>
+59 z80a's ORG
+5b z80a's L1
+5d z80a's L2
+5f z80a's L3
+61 z80a's L4
+63 z80a's L5
+65 z80a's L6
+67 FUTURE USES
+53 readln's variables
+55 FUTURE USES
+59 z80a's variables
+5b FUTURE USES
+70 DRIVERS
+80 RAMEND