1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-26 10:28:05 +11:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Virgil Dupras
a92864a595 pcat: implement RSP mechanism in execution model 2020-06-16 20:41:53 -04:00
link2xt
4017fd04ac
Replace deprecated bzero with memset (#119) 2020-06-16 18:58:23 -05:00
link2xt
79da1db90e
tools: mark local C functions as static (#120) 2020-06-16 18:58:00 -05:00
link2xt
472331b450
Check spelling (#121) 2020-06-16 18:57:31 -05:00
link2xt
6a09910dfc
BROWSE: ignore invalid digits (#123)
Documentation in block 100 says a number followed by a space or return
lists the contents of the block. However, typing any other character
does this too, because _pdacc returns -1 in this case.

This is annoying because typing "n" instead of "N" immediately after
jumping to some block was bringing you to block 0. Now "n" is ignored
instead.

This commit changes the condition for printing to explicitly check for
the value of 1, which means whitespace according to _pdacc documentation
in block 355.
2020-06-16 18:55:26 -05:00
link2xt
f1a225ef3d
Fix unreadable sentence in block 031. (#122)
This clearly has some words missing.
2020-06-16 18:28:06 -05:00
Virgil Dupras
16d6a0b377 pcat: begin implementing compiledWord/next 2020-06-16 19:05:36 -04:00
Virgil Dupras
feeedcc55c z80: small optimization in execute
I had more ambitious goals, but I backed out of it: not worth it.
This small optimization is an easy picking though.
2020-06-16 16:37:21 -04:00
29 changed files with 91 additions and 70 deletions

View File

@ -9,7 +9,7 @@ Many blocks contain code. That code can be interpreted through
LOAD. Programs stored in blocks frequently have "loader blocks"
that take care of loading all blocks relevant to the program.
Blocks spanning multipls disks are tricky. If your media isn't
Blocks spanning multiple disks are tricky. If your media isn't
large enough to hold all Collapse OS blocks in one unit, you'll
have to make it span multiple disks. Block reference in
informational texts aren't a problem: When you swap your disk,

View File

@ -7,9 +7,9 @@ modified. "I:" prefix means "IMMEDIATE", that is, that this
stack transformation is made at compile time.
Word references (wordref): When we say we have a "word
reference", it's a pointer to a word's *code link*. For
example, the address that "' DUP" is a wordref, that is, a
reference to the code link of the word DUP.
reference", it's a pointer to a word's *code link*. For example,
the address that "' DUP" puts on the stack is a wordref, that
is, a reference to the code link of the word DUP.
PF: Parameter field. The area following the code link of a
word. For example, "' H@ 1+" points to the PF of the word H@.

View File

@ -1,6 +1,6 @@
(cont.)
0x2b: doesWord. This word is created by "DOES>" and is followed
by a 2-byte value as well as the adress where "DOES>" was
by a 2-byte value as well as the address where "DOES>" was
compiled. At that address is an atom list exactly like in a
compiled word. Upon execution, after having pushed its cell
addr to PSP, it execute its reference exactly like a

View File

@ -2,7 +2,7 @@ CREATE ACC 0 ,
: _LIST ." Block " DUP . NL LIST ;
: _NUM
ACC @ SWAP _pdacc
IF _LIST 0 THEN
1 = IF _LIST 0 THEN
ACC !
;
: L BLK> @ _LIST ;

View File

@ -3,7 +3,7 @@ effect described below.
Pressing a 0-9 digit accumulates that digit into what is named
the "modifier". That modifier affects the behavior of many
keystokes described below. The modifier starts at zero, but
keystrokes described below. The modifier starts at zero, but
most commands interpret a zero as a 1 so that they can have an
effect.

View File

@ -1,5 +1,5 @@
On top of that, you have the very nice BREAK, instruction,
which must also be preceeded by a JRxx, and will jump to the
which must also be preceded by a JRxx, and will jump to the
PC following the next AGAIN,

View File

@ -10,7 +10,7 @@ compile it with offsets. We abort on IMMED? because we're
never supposed to encounter an immediate at this point.
If not found, we try the same word on system dict (RAM+02).
If found and is immediate, execute. If founf and not immediate,
If found and is immediate, execute. If found and not immediate,
error. If not found, try number.

12
blk/301
View File

@ -1,14 +1,12 @@
L3 BSET PC ORG @ 0x34 + ! ( execute )
EXDEHL, ( HL now points to wordref )
L3 BSET PC ORG @ 0x34 + ! ( execute. DE -> wordref )
( We don't apply BIN( reliably on stable ABI stuff, we
might need to adjust addr. Ugly, but well... )
BIN( @ [IF]
A XORr, H ORr, IFZ, H BIN( @ 256 / LDrn, THEN,
A XORr, D ORr, IFZ, D BIN( @ 256 / LDrn, THEN,
[THEN]
E (HL) LDrr,
D BIN( @ 256 / LDrn,
EXDEHL,
( HL points to code pointer )
LDA(DE),
L A LDrr,
H BIN( @ 256 / LDrn,
DE INCss,
( DE points to PFA )
JP(HL),

View File

@ -2,7 +2,7 @@
( buffer overflow? same as if we typed a newline )
IN> @ IN) = IF 0x0a ELSE KEY THEN ( c )
DUP 0x0a = IF DROP 0xd THEN ( lf? same as cr )
( bacspace? handle and exit )
( backspace? handle and exit )
DUP BS? IF _bs EXIT THEN
( echo back )
DUP EMIT ( c )

View File

@ -13,4 +13,4 @@ Core words (low) (B350)
Then comes the part where we begin defining words in Forth.
Core words are designed to be cross-compiled (B260), from a
full Forth interpreter. This means that it has access to more
than boot words. This somes with tricky limitations. (cont.)
than boot words. This comes with tricky limitations. (cont.)

View File

@ -6,7 +6,7 @@ to scroll more efficiently. Instead of having to copy the LCD
ram around at each linefeed (or instead of having to maintain
an in-memory buffer), we can use this feature.
The Z-Offet goes upwards, with wrapping. For example, if we
The Z-Offset goes upwards, with wrapping. For example, if we
have an 8 pixels high line at row 0 and if our offset is 8,
that line will go up 8 pixels, wrapping itself to the bottom of
the screen.

View File

@ -7,7 +7,7 @@ Start - A - C - B - Right - Left - Down - Up
Each bit is high when button is unpressed and low if button is
pressed. When no button is pressed, 0xff is returned.
This logic below is for the Genesis controller, which is modal.
TH is an output pin that swiches the meaning of TL and TR. When
TH is an output pin that switches the meaning of TL and TR. When
TH is high (unselected), TL = Button B and TR = Button C. When
TH is low (selected), TL = Button A and TR = Start. )

View File

@ -1 +1 @@
1 8 LOADR+
1 9 LOADR+

View File

@ -1,6 +1,7 @@
: OP1 CREATE C, DOES> C@ A, ;
0xc3 OP1 RETn, 0xfa OP1 CLI, 0xfb OP1 STI,
0xf4 OP1 HLT, 0xfc OP1 CLD, 0xfd OP1 STD,
0x90 OP1 NOP,
( no argument, jumps with relative addrs are special )
0xeb OP1 JMPs, 0xe9 OP1 JMPn, 0x74 OP1 JZ,
0x75 OP1 JNZ, 0xe8 OP1 CALLn,

15
blk/755
View File

@ -1,16 +1,13 @@
: OPrm CREATE C, DOES> C@ A, SWAP 3 LSHIFT OR A, ;
0x8a OPrm MOVr[], 0x8b OPrm MOVx[],
: OPmr CREATE C, DOES> C@ A, 3 LSHIFT OR A, ;
0x88 OPmr MOV[]r, 0x89 OPmr MOV[]x,
: OPrm+ ( r m off ) CREATE C, DOES>
C@ A, ROT 3 LSHIFT ROT OR 0x40 OR A, A, ;
0x8a OPrm+ MOVr[]+, 0x8b OPrm+ MOVx[]+,
: MOVri, SWAP 0xb0 OR A, A, ;
: MOVxI, SWAP 0xb8 OR A, A,, ;
: MOVsx, 0x8e A, SWAP 3 LSHIFT OR 0xc0 OR A, ;
: MOVxm, 0x8b A, SWAP 3 LSHIFT 0x6 OR A, A,, ;
: INT, 0xcd A, A, ;
: ADDAXI, 0x05 A, A,, ; : ADDALi, 0x04 A, A, ;
: SUBxi, 0x83 A, SWAP 0xe8 OR A, A, ;
: JMPr, 0xff A, 7 AND 0xe0 OR A, ;
: JMPf, ( seg off ) 0xea A, SPLITB A, A, A,, ;
: OPm+r ( m off r ) CREATE C, DOES>
C@ A, 3 LSHIFT ROT OR 0x40 OR A, A, ;
0x88 OPm+r MOV[]+r, 0x89 OPm+r MOV[]+x,

25
blk/756
View File

@ -1,16 +1,9 @@
( Place BEGIN, where you want to jump back and AGAIN after
a relative jump operator. Just like BSET and BWR. )
: BEGIN, PC ;
: BSET PC SWAP ! ;
( same as BSET, but we need to write a placeholder )
: FJR, PC 0 A, ;
: IFZ, JNZ, FJR, ;
: IFNZ, JZ, FJR, ;
( : IFC, JRNC, FJR, ;
: IFNC, JRC, FJR, ; )
: THEN,
DUP PC ( l l pc )
-^ 1- ( l off )
( warning: l is a PC offset, not a mem addr! )
SWAP ORG @ + BIN( @ - ( off addr )
C! ;
: MOVri, SWAP 0xb0 OR A, A, ;
: MOVxI, SWAP 0xb8 OR A, A,, ;
: MOVsx, 0x8e A, SWAP 3 LSHIFT OR 0xc0 OR A, ;
: MOVxm, 0x8b A, SWAP 3 LSHIFT 0x6 OR A, A,, ;
: INT, 0xcd A, A, ;
: ADDAXI, 0x05 A, A,, ; : ADDALi, 0x04 A, A, ;
: SUBxi, 0x83 A, SWAP 0xe8 OR A, A, ;
: JMPr, 0xff A, 7 AND 0xe0 OR A, ;
: JMPf, ( seg off ) 0xea A, SPLITB A, A, A,, ;

26
blk/757
View File

@ -1,10 +1,16 @@
: FWRs BSET 0 A, ;
: FSET @ THEN, ;
( : BREAK, FJR, 0x8000 OR ;
: BREAK?, DUP 0x8000 AND IF
0x7fff AND 1 ALLOT THEN, -1 ALLOT
THEN ; )
: RPCs, PC - 1- A, ; : RPCn, PC - 2- A,, ;
: AGAIN, ( BREAK?, ) RPCs, ;
( Use RPCx with appropriate JMP/CALL op. Example:
JMPs, 0x42 RPCs, or CALLn, 0x1234 RPCn, )
( Place BEGIN, where you want to jump back and AGAIN after
a relative jump operator. Just like BSET and BWR. )
: BEGIN, PC ;
: BSET PC SWAP ! ;
( same as BSET, but we need to write a placeholder )
: FJR, PC 0 A, ;
: IFZ, JNZ, FJR, ;
: IFNZ, JZ, FJR, ;
( : IFC, JRNC, FJR, ;
: IFNC, JRC, FJR, ; )
: THEN,
DUP PC ( l l pc )
-^ 1- ( l off )
( warning: l is a PC offset, not a mem addr! )
SWAP ORG @ + BIN( @ - ( off addr )
C! ;

14
blk/758
View File

@ -1,4 +1,10 @@
: CODE ( same as CREATE, but with native word )
(entry)
23 C, ( 23 == nativeWord ) ;
: ;CODE ;
: FWRs BSET 0 A, ;
: FSET @ THEN, ;
( : BREAK, FJR, 0x8000 OR ;
: BREAK?, DUP 0x8000 AND IF
0x7fff AND 1 ALLOT THEN, -1 ALLOT
THEN ; )
: RPCs, PC - 1- A, ; : RPCn, PC - 2- A,, ;
: AGAIN, ( BREAK?, ) RPCs, ;
( Use RPCx with appropriate JMP/CALL op. Example:
JMPs, 0x42 RPCs, or CALLn, 0x1234 RPCn, )

4
blk/759 Normal file
View File

@ -0,0 +1,4 @@
: CODE ( same as CREATE, but with native word )
(entry)
23 C, ( 23 == nativeWord ) ;
: ;CODE JMPn, 0x1a ( next ) RPCn, ;

View File

@ -2,4 +2,6 @@ PC/AT Recipe
Work in progress.
Register usage: SP is PSP, BP is RSP, DX is IP
811 Hello World boot

View File

@ -3,7 +3,7 @@ JMPs, L1 FWRs ( start )
ORG @ 0x25 + HERE ! ( bypass BPB )
L1 FSET ( start )
CLI, CLD, AX 0x800 MOVxI, DS AX MOVsx, ES AX MOVsx,
SS AX MOVsx, SP 0xffff MOVxI, STI,
SS AX MOVsx, STI,
AH 2 MOVri, DX 0 MOVxI, CH 0 MOVri, CL 2 MOVri, AL 1 MOVri,
BX 0 MOVxI, 0x13 INT, ( read 2nd sector of boot floppy )
0x800 0 JMPf,

View File

@ -1,4 +1,3 @@
( Registers. SP -> PSP DX -> RSP CX -> IP )
H@ ORG !
JMPn, 0 A,, ( 00, main ) JMPn, 0 A,, ( 03, find )
0 A,, ( 06, unused ) 0 A,, ( 08, LATEST )

View File

@ -6,8 +6,10 @@
4 A,
H@ XCURRENT ! ( set current tip of dict, 0x42 )
0x17 A, ( nativeWord )
DX [BP] 0 MOVx[]+, BP DECx, BP DECx, ( popRS )
;CODE
CODE BYE BEGIN, JMPs, AGAIN, ;CODE
CODE FOO
AH 0x0e MOVri, ( print char ) AL 'X' MOVri, 0x10 INT,
BEGIN, JMPs, AGAIN,
;CODE
: BAR FOO FOO ; : BAZ BAR FOO BYE ;

15
blk/814
View File

@ -1,5 +1,14 @@
L1 BSET PC 3 - ORG @ 0x34 + ! ( execute -- DI -> wordref )
AH AH XORrr,
AL [DI] MOVr[],
PC 0x1d - ORG @ 0x1b + ! ( next )
DI DX MOVxx, ( <-- IP ) DX INCx, DX INCx,
DI [DI] MOVx[], ( wordref )
( continue to execute )
L1 BSET PC 0x36 - ORG @ 0x34 + ! ( execute -- DI -> wordref )
AH AH XORrr, AL [DI] MOVr[],
DI INCx, ( PFA )
AX JMPr,
PC 0x11 - ORG @ 0x0f + ! ( compiledWord -- DI -> PFA )
BP INCx, BP INCx, [BP] 0 DX MOV[]+x, ( pushRS )
DX DI MOVxx, DX INCx, DX INCx, ( --> IP )
DI [DI] MOVx[],
JMPs, L1 @ RPCs,

View File

@ -1,5 +1,7 @@
L3 BSET 3 A, 'F' A, 'O' A, 'O' A,
L3 BSET 3 A, 'B' A, 'A' A, 'Z' A,
PC 3 - ORG @ 1+ ! ( main )
SP PS_ADDR MOVxI,
BP RS_ADDR MOVxI,
DI 0x08 MOVxm, ( LATEST )
SI L3 @ MOVxI,
CALLn, L4 @ RPCn, ( find )

Binary file not shown.

View File

@ -1,3 +1,5 @@
0xff00 CONSTANT RS_ADDR
0xfffa CONSTANT PS_ADDR
750 LOAD ( 8086 asm )
262 LOAD ( xcomp )
270 LOAD ( xcomp overrides )

View File

@ -6,7 +6,7 @@
#include <string.h>
#include <sys/stat.h>
void usage()
static void usage()
{
fprintf(stderr, "Usage: blkpack dirname\n");
}
@ -34,7 +34,7 @@ int main(int argc, char *argv[])
if (blkid >= blkcnt) {
int newcnt = blkid+1;
buf = realloc(buf, newcnt*1024);
bzero(buf+(blkcnt*1024), (newcnt-blkcnt)*1024);
memset(buf+(blkcnt*1024), 0, (newcnt-blkcnt)*1024);
blkcnt = newcnt;
}
char fullpath[0x200];

View File

@ -16,7 +16,7 @@ void mread(int fd, char *s, int count)
}
}
void mexpect(int fd, char ec)
static void mexpect(int fd, char ec)
{
char c;
mread(fd, &c, 1);