mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-30 20:08:06 +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:
parent
d4f65911c0
commit
d996dd8c9e
@ -21,6 +21,23 @@ directly, but as part of another word.
|
|||||||
|
|
||||||
"*I*" in description indicates an IMMEDIATE 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 ***
|
*** Defining words ***
|
||||||
(find) a -- a f Read at a and find it in dict. If found, f=1 and
|
(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.
|
a = wordref. If not found, f=0 and a = string addr.
|
||||||
|
@ -1 +1 @@
|
|||||||
: INIT (c<$) INTERPRET ;
|
: INIT RDLN$ Z80A$ INTERPRET ;
|
||||||
|
Binary file not shown.
@ -8,22 +8,23 @@
|
|||||||
routine. )
|
routine. )
|
||||||
|
|
||||||
64 CONSTANT INBUFSZ
|
64 CONSTANT INBUFSZ
|
||||||
( points to INBUF )
|
: RDLNMEM+ 0x53 RAM+ @ + ;
|
||||||
: IN( 0x53 RAM+ ;
|
|
||||||
( points to INBUF's end )
|
|
||||||
: IN) 0x55 RAM+ ;
|
|
||||||
( current position in INBUF )
|
( 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 )
|
( flush input buffer )
|
||||||
( set IN> to IN( and set IN> @ to null )
|
( 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
|
( handle backspace: go back one char in IN>, if possible, then
|
||||||
emit SPC + BS )
|
emit SPC + BS )
|
||||||
: (inbs)
|
: (inbs)
|
||||||
( already at IN( ? )
|
( already at IN( ? )
|
||||||
IN> @ IN( @ = IF EXIT THEN
|
IN> @ IN( = IF EXIT THEN
|
||||||
IN> @ 1 - IN> !
|
IN> @ 1 - IN> !
|
||||||
SPC BS
|
SPC BS
|
||||||
;
|
;
|
||||||
@ -32,7 +33,7 @@
|
|||||||
should continue, that is, whether CR was not met. )
|
should continue, that is, whether CR was not met. )
|
||||||
: (rdlnc) ( -- f )
|
: (rdlnc) ( -- f )
|
||||||
( buffer overflow? same as if we typed a newline )
|
( 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 )
|
( del? same as backspace )
|
||||||
DUP 0x7f = IF DROP 0x8 THEN
|
DUP 0x7f = IF DROP 0x8 THEN
|
||||||
( lf? same as cr )
|
( lf? same as cr )
|
||||||
@ -58,7 +59,7 @@
|
|||||||
FLAGS @ 0x1 AND NOT IF '>' EMIT SPC THEN
|
FLAGS @ 0x1 AND NOT IF '>' EMIT SPC THEN
|
||||||
(infl)
|
(infl)
|
||||||
BEGIN (rdlnc) NOT UNTIL
|
BEGIN (rdlnc) NOT UNTIL
|
||||||
LF IN( @ IN> !
|
LF IN( IN> !
|
||||||
;
|
;
|
||||||
|
|
||||||
( And finally, implement a replacement for the (c<) routine )
|
( And finally, implement a replacement for the (c<) routine )
|
||||||
@ -71,13 +72,12 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
( Initializes the readln subsystem )
|
( Initializes the readln subsystem )
|
||||||
: (c<$)
|
: RDLN$
|
||||||
H@ IN( !
|
( 53 == rdln's memory )
|
||||||
INBUFSZ ALLOT
|
H@ 0x53 RAM+ !
|
||||||
H@ IN) !
|
( 2 for IN>, plus 2 for extra bytes after buffer: 1 for
|
||||||
( We need two extra bytes. 1 for the last typed 0x0a and
|
the last typed 0x0a and one for the following NULL. )
|
||||||
one for the following NULL. )
|
INBUFSZ 4 + ALLOT
|
||||||
2 ALLOT
|
|
||||||
(infl)
|
(infl)
|
||||||
['] (rdln<) 0x0c RAM+ !
|
['] (rdln<) 0x0c RAM+ !
|
||||||
;
|
;
|
||||||
|
@ -1,21 +1,11 @@
|
|||||||
( Z80 assembler )
|
( Z80 assembler )
|
||||||
|
|
||||||
( Splits word into msb/lsb, lsb being on TOS )
|
: Z80AMEM+ 0x59 RAM+ @ + ;
|
||||||
: SPLITB
|
|
||||||
256 /MOD SWAP
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
( H@ offset at which we consider our PC 0. Used to compute
|
( H@ offset at which we consider our PC 0. Used to compute
|
||||||
PC. To have a proper PC, call "H@ ORG !" at the beginning
|
PC. To have a proper PC, call "H@ ORG !" at the beginning
|
||||||
of your assembly process. )
|
of your assembly process. )
|
||||||
: ORG 0x59 RAM+ ;
|
: ORG 0 Z80AMEM+ ;
|
||||||
: 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, ;
|
|
||||||
|
|
||||||
( Labels are a convenient way of managing relative jump
|
( Labels are a convenient way of managing relative jump
|
||||||
calculations. Backward labels are easy. It is only a matter
|
calculations. Backward labels are easy. It is only a matter
|
||||||
@ -27,13 +17,31 @@
|
|||||||
To avoid using dict memory in compilation targets, we
|
To avoid using dict memory in compilation targets, we
|
||||||
pre-declare label variables here, which means we have a
|
pre-declare label variables here, which means we have a
|
||||||
limited number of it. For now, 6 ought to be enough. )
|
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+ ;
|
: Z80A$
|
||||||
: L2 0x5d RAM+ ;
|
( 59 == z80a's memory )
|
||||||
: L3 0x5f RAM+ ;
|
H@ 0x59 RAM+ !
|
||||||
: L4 0x61 RAM+ ;
|
14 ALLOT
|
||||||
: L5 0x63 RAM+ ;
|
;
|
||||||
: L6 0x65 RAM+ ;
|
|
||||||
|
( 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
|
( There are 2 label types: backward and forward. For each
|
||||||
type, there are two actions: set and write. Setting a label
|
type, there are two actions: set and write. Setting a label
|
||||||
|
15
notes.txt
15
notes.txt
@ -89,17 +89,10 @@ RAMSTART INITIAL_SP
|
|||||||
+2e BOOT C< PTR
|
+2e BOOT C< PTR
|
||||||
+4e INTJUMP
|
+4e INTJUMP
|
||||||
+51 CURRENTPTR
|
+51 CURRENTPTR
|
||||||
+53 readln's IN(
|
+53 readln's variables
|
||||||
+55 readln's IN)
|
+55 FUTURE USES
|
||||||
+57 readln's IN>
|
+59 z80a's variables
|
||||||
+59 z80a's ORG
|
+5b FUTURE USES
|
||||||
+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
|
|
||||||
+70 DRIVERS
|
+70 DRIVERS
|
||||||
+80 RAMEND
|
+80 RAMEND
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user