From 45eceaaf616f7a44c3a06e0930bdd7d404a7b041 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 7 Dec 2020 22:18:10 -0500 Subject: [PATCH] Remove indirect memory access I got bitten again, I've over-designed my solution. The last time it happened, it was that memory mapping thing I was wanting to add. The indirect memory access feature I was adding was to solve a specific problem: Allow Collapse OS to cross-compile directly on a AT28 EEPROM. It began well. As long as we were staying in the assembler realm, things were looking good. However, when we got into the xcomp realm (B260), things became ugly, and I had to creep up indirection where I didn't want to. All of this because I wanted to solve my initial problem in a slightly more generalized way. The broad idea was that these indirect memory access could allow xcomp into a broad kind of memory-like devices. This idea broke on the "@" part of the equation. If I want indirections to be two-way and allow xcomp to work properly, I have to add this indirection to FIND (and possibly others) and this just isn't practical or elegant. So, I'm taking a step back and accepting that the solution I design for now is exclusively for the AT28. What I'm thinking is to add a low-level hook for memory writing, at the assembly level. --- blk.fs | 225 +++++++++++++++++++++++++++------------------------------ cvm/stage.bin | Bin 5065 -> 5008 bytes doc/dict.txt | 17 ++--- doc/impl.txt | 14 +--- doc/usage.txt | 17 ----- tools/upload.c | 2 +- 6 files changed, 115 insertions(+), 160 deletions(-) diff --git a/blk.fs b/blk.fs index fe3ec3e..5eaccfe 100644 --- a/blk.fs +++ b/blk.fs @@ -54,19 +54,16 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : CPO 4 ; : CPE 5 ; : CP 6 ; : CM 7 ; ( ----- 007 ) : PC H@ ORG @ - BIN( @ + ; -( C,* spits an assembled byte, A,, spits an assembled word - Both increase PC. ) -: A,, |L C,* C,* ; : <<3 3 LSHIFT ; : <<4 4 LSHIFT ; ( As a general rule, IX and IY are equivalent to spitting an extra 0xdd / 0xfd and then spit the equivalent of HL ) -: IX 0xdd C,* HL ; : IY 0xfd C,* HL ; -: _ix+- 0xff AND 0xdd C,* (HL) ; -: _iy+- 0xff AND 0xfd C,* (HL) ; +: IX 0xdd C, HL ; : IY 0xfd C, HL ; +: _ix+- 0xff AND 0xdd C, (HL) ; +: _iy+- 0xff AND 0xfd C, (HL) ; : IX+ _ix+- ; : IX- 0 -^ _ix+- ; : IY+ _iy+- ; : IY- 0 -^ _iy+- ; ( ----- 008 ) -: OP1 CREATE C, DOES> C@ C,* ; +: OP1 CREATE C, DOES> C@ C, ; 0xf3 OP1 DI, 0xfb OP1 EI, 0xeb OP1 EXDEHL, 0xd9 OP1 EXX, 0x08 OP1 EXAFAF', 0xe3 OP1 EX(SP)HL, @@ -95,22 +92,22 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 C@ ( r op ) SWAP ( op r ) <<3 ( op r<<3 ) - OR C,* + OR C, ; 0x04 OP1r INCr, 0x05 OP1r DECr, -: INC(IXY+), INCr, C,* ; -: DEC(IXY+), DECr, C,* ; +: INC(IXY+), INCr, C, ; +: DEC(IXY+), DECr, C, ; ( also works for c ) 0xc0 OP1r RETc, ( ----- 011 ) : OP1r0 ( r -- ) CREATE C, DOES> - C@ ( r op ) OR C,* ; + C@ ( r op ) OR C, ; 0x80 OP1r0 ADDr, 0x88 OP1r0 ADCr, 0xa0 OP1r0 ANDr, 0xb8 OP1r0 CPr, 0xb0 OP1r0 ORr, 0x90 OP1r0 SUBr, 0x98 OP1r0 SBCr, 0xa8 OP1r0 XORr, -: CP(IXY+), CPr, C,* ; +: CP(IXY+), CPr, C, ; ( ----- 012 ) : OP1d CREATE C, @@ -118,20 +115,20 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 C@ ( d op ) SWAP ( op d ) <<4 ( op d<<4 ) - OR C,* + OR C, ; 0xc5 OP1d PUSH, 0xc1 OP1d POP, 0x03 OP1d INCd, 0x0b OP1d DECd, 0x09 OP1d ADDHLd, -: ADDIXd, 0xdd C,* ADDHLd, ; : ADDIXIX, HL ADDIXd, ; -: ADDIYd, 0xfd C,* ADDHLd, ; : ADDIYIY, HL ADDIYd, ; +: ADDIXd, 0xdd C, ADDHLd, ; : ADDIXIX, HL ADDIXd, ; +: ADDIYd, 0xfd C, ADDHLd, ; : ADDIYIY, HL ADDIYd, ; ( ----- 013 ) : _1rr C@ ( rd rr op ) ROT ( rr op rd ) <<3 ( rr op rd<<3 ) - OR OR C,* + OR OR C, ; ( rd rr ) @@ -146,7 +143,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : LDIXYr, ( dd/fd has already been spit ) LDrr, ( ixy+- ) - C,* + C, ; ( rd ixy+- HL ) @@ -156,7 +153,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 LDIXYr, ; ( ----- 015 ) -: OP2 CREATE , DOES> @ |M C,* C,* ; +: OP2 CREATE , DOES> @ |M C, C, ; 0xeda1 OP2 CPI, 0xedb1 OP2 CPIR, 0xeda9 OP2 CPD, 0xedb9 OP2 CPDR, 0xed46 OP2 IM0, 0xed56 OP2 IM1, @@ -169,7 +166,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OP2i ( i -- ) CREATE C, DOES> - C@ C,* C,* + C@ C, C, ; 0xd3 OP2i OUTiA, 0xdb OP2i INAi, @@ -186,7 +183,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 C@ ( r i op ) ROT ( i op r ) <<3 ( i op r<<3 ) - OR C,* C,* + OR C, C, ; 0x06 OP2ri LDri, ( ----- 018 ) @@ -194,11 +191,11 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OP2br CREATE C, DOES> - 0xcb C,* + 0xcb C, C@ ( b r op ) ROT ( r op b ) <<3 ( r op b<<3 ) - OR OR C,* + OR OR C, ; 0xc0 OP2br SET, 0x80 OP2br RES, @@ -208,9 +205,9 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OProt ( r -- ) CREATE C, DOES> - 0xcb C,* + 0xcb C, C@ ( r op ) - OR C,* + OR C, ; 0x10 OProt RL, 0x00 OProt RLC, @@ -225,10 +222,10 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OP2r CREATE , DOES> - @ |M ( r lsb msb ) - C,* ( r lsb ) + @ |M ( r lsb msb ) + C, ( r lsb ) SWAP <<3 ( lsb r<<3 ) - OR C,* + OR C, ; 0xed41 OP2r OUT(C)r, 0xed40 OP2r INr(C), @@ -236,10 +233,10 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OP2d ( d -- ) CREATE C, DOES> - 0xed C,* + 0xed C, C@ SWAP ( op d ) <<4 ( op d<< 4 ) - OR C,* + OR C, ; 0x4a OP2d ADCHLd, 0x42 OP2d SBCHLd, @@ -251,8 +248,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 C@ ( d n op ) ROT ( n op d ) <<4 ( n op d<<4 ) - OR C,* - A,, + OR C, , ; 0x01 OP3di LDdi, ( ----- 023 ) @@ -260,8 +256,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OP3i CREATE C, DOES> - C@ C,* - A,, + C@ C, , ; 0xcd OP3i CALL, 0xc3 OP3i JP, @@ -269,21 +264,19 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 0x32 OP3i LD(i)A, 0x3a OP3i LDA(i), ( ----- 024 ) : LDd(i), ( d i -- ) - 0xed C,* - SWAP <<4 0x4b OR C,* - A,, + 0xed C, + SWAP <<4 0x4b OR C, , ; : LD(i)d, ( i d -- ) - 0xed C,* - <<4 0x43 OR C,* - A,, + 0xed C, + <<4 0x43 OR C, , ; -: RST, 0xc7 OR C,* ; +: RST, 0xc7 OR C, ; : JP(IX), IX DROP JP(HL), ; : JP(IY), IY DROP JP(HL), ; ( ----- 025 ) -: JPc, SWAP <<3 0xc2 OR C,* A,, ; +: JPc, SWAP <<3 0xc2 OR C, , ; : BCALL, BIN( @ + CALL, ; : BJP, BIN( @ + JP, ; : BJPc, BIN( @ + JPc, ; @@ -301,7 +294,7 @@ CREATE lblnext 0 , ( stable ABI until set in B300 ) : BEGIN, PC ; : BSET PC SWAP ! ; ( same as BSET, but we need to write a placeholder ) -: FJR, PC 0 C,* ; +: FJR, PC 0 C, ; : IFZ, JRNZ, FJR, ; : IFNZ, JRZ, FJR, ; : IFC, JRNC, FJR, ; @@ -311,15 +304,15 @@ CREATE lblnext 0 , ( stable ABI until set in B300 ) -^ 1- ( l off ) ( warning: l is a PC offset, not a mem addr! ) SWAP ORG @ + BIN( @ - ( off addr ) - C!* ; + C! ; ( ----- 027 ) -: FWR BSET 0 C,* ; +: FWR BSET 0 C, ; : FSET @ THEN, ; : BREAK, FJR, 0x8000 OR ; : BREAK?, DUP 0x8000 AND IF 0x7fff AND 1 ALLOT THEN, -1 ALLOT THEN ; -: AGAIN, BREAK?, PC - 1- C,* ; +: AGAIN, BREAK?, PC - 1- C, ; : BWR @ AGAIN, ; ( ----- 028 ) ( Macros ) @@ -351,9 +344,8 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : <<3 3 LSHIFT ; ( ----- 032 ) : PC H@ ORG @ - BIN( @ + ; -: A,, |L C,* C,* ; ( ----- 033 ) -: OP1 CREATE C, DOES> C@ C,* ; +: OP1 CREATE C, DOES> C@ C, ; 0xc3 OP1 RET, 0xfa OP1 CLI, 0xfb OP1 STI, 0xf4 OP1 HLT, 0xfc OP1 CLD, 0xfd OP1 STD, 0x90 OP1 NOP, 0x98 OP1 CBW, @@ -366,12 +358,12 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 0x75 OP1 JNZ, 0x72 OP1 JC, 0x73 OP1 JNC, 0xe8 OP1 CALL, -: OP1r CREATE C, DOES> C@ + C,* ; +: OP1r CREATE C, DOES> C@ + C, ; 0x40 OP1r INCx, 0x48 OP1r DECx, 0x58 OP1r POPx, 0x50 OP1r PUSHx, ( ----- 034 ) : OPr0 ( reg op ) CREATE C, C, DOES> - C@+ C,* C@ <<3 OR 0xc0 OR C,* ; + C@+ C, C@ <<3 OR 0xc0 OR C, ; 0 0xd0 OPr0 ROLr1, 0 0xd1 OPr0 ROLx1, 4 0xf6 OPr0 MULr, 1 0xd0 OPr0 RORr1, 1 0xd1 OPr0 RORx1, 4 0xf7 OPr0 MULx, 4 0xd0 OPr0 SHLr1, 4 0xd1 OPr0 SHLx1, 6 0xf6 OPr0 DIVr, @@ -381,65 +373,65 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 4 0xd2 OPr0 SHLrCL, 4 0xd3 OPr0 SHLxCL, 5 0xd2 OPr0 SHRrCL, 5 0xd3 OPr0 SHRxCL, ( ----- 035 ) -: OPrr CREATE C, DOES> C@ C,* <<3 OR 0xc0 OR C,* ; +: OPrr CREATE C, DOES> C@ C, <<3 OR 0xc0 OR C, ; 0x31 OPrr XORxx, 0x30 OPrr XORrr, 0x88 OPrr MOVrr, 0x89 OPrr MOVxx, 0x28 OPrr SUBrr, 0x29 OPrr SUBxx, 0x08 OPrr ORrr, 0x09 OPrr ORxx, 0x38 OPrr CMPrr, 0x39 OPrr CMPxx, 0x00 OPrr ADDrr, 0x01 OPrr ADDxx, 0x20 OPrr ANDrr, 0x21 OPrr ANDxx, ( ----- 036 ) -: OPm ( modrm op ) CREATE C, C, DOES> C@+ C,* C@ OR C,* ; +: OPm ( modrm op ) CREATE C, C, DOES> C@+ C, C@ OR C, ; 0 0xff OPm INC[w], 0 0xfe OPm INC[b], 0x8 0xff OPm DEC[w], 0x8 0xfe OPm DEC[b], 0x30 0xff OPm PUSH[w], 0 0x8f OPm POP[w], : OPm+ ( modrm op ) CREATE C, C, DOES> - ( m off ) C@+ C,* C@ ROT OR C,* C,* ; + ( m off ) C@+ C, C@ ROT OR C, C, ; 0x40 0xff OPm+ INC[w]+, 0x40 0xfe OPm+ INC[b]+, 0x48 0xff OPm+ DEC[w]+, 0x48 0xfe OPm+ DEC[b]+, 0x70 0xff OPm+ PUSH[w]+, 0x40 0x8f OPm+ POP[w]+, ( ----- 037 ) -: OPrm CREATE C, DOES> C@ C,* SWAP 3 LSHIFT OR C,* ; +: OPrm CREATE C, DOES> C@ C, SWAP 3 LSHIFT OR C, ; 0x8a OPrm MOVr[], 0x8b OPrm MOVx[], 0x3a OPrm CMPr[], 0x3b OPrm CMPx[], -: OPmr CREATE C, DOES> C@ C,* 3 LSHIFT OR C,* ; +: OPmr CREATE C, DOES> C@ C, 3 LSHIFT OR C, ; 0x88 OPmr MOV[]r, 0x89 OPmr MOV[]x, : OPrm+ ( r m off ) CREATE C, DOES> - C@ C,* ROT 3 LSHIFT ROT OR 0x40 OR C,* C,* ; + C@ C, ROT 3 LSHIFT ROT OR 0x40 OR C, C, ; 0x8a OPrm+ MOVr[]+, 0x8b OPrm+ MOVx[]+, 0x3a OPrm+ CMPr[]+, 0x3b OPrm+ CMPx[]+, : OPm+r ( m off r ) CREATE C, DOES> - C@ C,* 3 LSHIFT ROT OR 0x40 OR C,* C,* ; + C@ C, 3 LSHIFT ROT OR 0x40 OR C, C, ; 0x88 OPm+r MOV[]+r, 0x89 OPm+r MOV[]+x, ( ----- 038 ) -: OPi CREATE C, DOES> C@ C,* C,* ; +: OPi CREATE C, DOES> C@ C, C, ; 0x04 OPi ADDALi, 0x24 OPi ANDALi, 0x2c OPi SUBALi, 0xcd OPi INT, -: OPI CREATE C, DOES> C@ C,* A,, ; +: OPI CREATE C, DOES> C@ C, , ; 0x05 OPI ADDAXI, 0x25 OPI ANDAXI, 0x2d OPI SUBAXI, ( ----- 040 ) -: MOVri, SWAP 0xb0 OR C,* C,* ; -: MOVxI, SWAP 0xb8 OR C,* A,, ; -: MOVsx, 0x8e C,* SWAP <<3 OR 0xc0 OR C,* ; -: MOVrm, 0x8a C,* SWAP <<3 0x6 OR C,* A,, ; -: MOVxm, 0x8b C,* SWAP <<3 0x6 OR C,* A,, ; -: MOVmr, 0x88 C,* <<3 0x6 OR C,* A,, ; -: MOVmx, 0x89 C,* <<3 0x6 OR C,* A,, ; -: PUSHs, <<3 0x06 OR C,* ; : POPs, <<3 0x07 OR C,* ; -: SUBxi, 0x83 C,* SWAP 0xe8 OR C,* C,* ; -: ADDxi, 0x83 C,* SWAP 0xc0 OR C,* C,* ; -: JMPr, 0xff C,* 7 AND 0xe0 OR C,* ; -: JMPf, ( seg off ) 0xea C,* |L C,* C,* A,, ; +: MOVri, SWAP 0xb0 OR C, C, ; +: MOVxI, SWAP 0xb8 OR C, , ; +: MOVsx, 0x8e C, SWAP <<3 OR 0xc0 OR C, ; +: MOVrm, 0x8a C, SWAP <<3 0x6 OR C, , ; +: MOVxm, 0x8b C, SWAP <<3 0x6 OR C, , ; +: MOVmr, 0x88 C, <<3 0x6 OR C, , ; +: MOVmx, 0x89 C, <<3 0x6 OR C, , ; +: PUSHs, <<3 0x06 OR C, ; : POPs, <<3 0x07 OR C, ; +: SUBxi, 0x83 C, SWAP 0xe8 OR C, C, ; +: ADDxi, 0x83 C, SWAP 0xc0 OR C, C, ; +: JMPr, 0xff C, 7 AND 0xe0 OR C, ; +: JMPf, ( seg off ) 0xea C, |L C, C, , ; ( ----- 041 ) ( 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 C,* ; +: FJR, PC 0 C, ; : IFZ, JNZ, FJR, ; : IFNZ, JZ, FJR, ; : IFC, JNC, FJR, ; @@ -449,13 +441,13 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 -^ 1- ( l off ) ( warning: l is a PC offset, not a mem addr! ) SWAP ORG @ + BIN( @ - ( off addr ) - C!* ; + C! ; ( ----- 042 ) -: FWRs BSET 0 C,* ; +: FWRs BSET 0 C, ; : FSET @ THEN, ; ( TODO: add BREAK, ) -: RPCs, PC - 1- DUP 128 + 0xff > IF ABORT" PC ovfl" THEN C,* ; -: RPCn, PC - 2- A,, ; +: RPCs, PC - 1- DUP 128 + 0xff > IF ABORT" PC ovfl" THEN C, ; +: RPCn, PC - 2- , ; : AGAIN, ( BREAK?, ) RPCs, ; ( Use RPCx with appropriate JMP/CALL op. Example: JMPs, 0x42 RPCs, or CALL, 0x1234 RPCn, ) @@ -474,9 +466,6 @@ VARIABLE ORG VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 ( We divide by 2 because each PC represents a word. ) : PC H@ ORG @ - 1 RSHIFT ; -( C,* spits an assembled byte, A,, spits an assembled word - Both increase PC. ) -: A,, |L C,* C,* ; ( ----- 052 ) : _oor ." arg out of range: " .X SPC ." PC: " PC .X NL ABORT ; : _r8c DUP 7 > IF _oor THEN ; @@ -487,7 +476,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : _Rdp ( op rd -- op', place Rd ) 4 LSHIFT OR ; ( ----- 053 ) ( 0000 000d dddd 0000 ) -: OPRd CREATE , DOES> @ SWAP _r32c _Rdp A,, ; +: OPRd CREATE , DOES> @ SWAP _r32c _Rdp , ; 0b1001010000000101 OPRd ASR, 0b1001010000000000 OPRd COM, 0b1001010000001010 OPRd DEC, 0b1001010000000011 OPRd INC, 0b1001001000000110 OPRd LAC, 0b1001001000000101 OPRd LAS, @@ -501,7 +490,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : OPRdRr CREATE C, DOES> C@ ( rd rr op ) OVER _r32c 0x10 AND 3 RSHIFT OR ( rd rr op' ) 8 LSHIFT OR 0xff0f AND ( rd op' ) - SWAP _r32c _Rdp A,, ; + SWAP _r32c _Rdp , ; 0x1c OPRdRr ADC, 0x0c OPRdRr ADD, 0x20 OPRdRr AND, 0x14 OPRdRr CP, 0x04 OPRdRr CPC, 0x10 OPRdRr CPSE, 0x24 OPRdRr EOR, 0x2c OPRdRr MOV, 0x9c OPRdRr MUL, @@ -510,24 +499,24 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 ( 0000 0AAd dddd AAAA ) : OPRdA CREATE C, DOES> C@ ( rd A op ) OVER _r64c 0x30 AND 3 RSHIFT OR ( rd A op' ) - 8 LSHIFT OR 0xff0f AND ( rd op' ) SWAP _r32c _Rdp A,, ; + 8 LSHIFT OR 0xff0f AND ( rd op' ) SWAP _r32c _Rdp , ; 0xb0 OPRdA IN, 0xb8 OPRdA _ : OUT, SWAP _ ; ( ----- 055 ) ( 0000 KKKK dddd KKKK ) : OPRdK CREATE C, DOES> C@ ( rd K op ) OVER _r256c 0xf0 AND 4 RSHIFT OR ( rd K op' ) - ROT _r16+c 4 LSHIFT ROT 0x0f AND OR ( op' rdK ) C,* C,* ; + ROT _r16+c 4 LSHIFT ROT 0x0f AND OR ( op' rdK ) C, C, ; 0x70 OPRdK ANDI, 0x30 OPRdK CPI, 0xe0 OPRdK LDI, 0x60 OPRdK ORI, 0x40 OPRdK SBCI, 0x60 OPRdK SBR, 0x50 OPRdK SUBI, ( 0000 0000 AAAA Abbb ) : OPAb CREATE C, DOES> C@ ( A b op ) - ROT _r32c 3 LSHIFT ROT _r8c OR C,* C,* ; + ROT _r32c 3 LSHIFT ROT _r8c OR C, C, ; 0x98 OPAb CBI, 0x9a OPAb SBI, 0x99 OPAb SBIC, 0x9b OPAb SBIS, ( ----- 056 ) -: OPNA CREATE , DOES> @ A,, ; +: OPNA CREATE , DOES> @ , ; 0x9598 OPNA BREAK, 0x9488 OPNA CLC, 0x94d8 OPNA CLH, 0x94f8 OPNA CLI, 0x94a8 OPNA CLN, 0x94c8 OPNA CLS, 0x94e8 OPNA CLT, 0x94b8 OPNA CLV, 0x9498 OPNA CLZ, @@ -540,12 +529,12 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 ( ----- 057 ) ( 0000 0000 0sss 0000 ) : OPb CREATE , DOES> @ ( b op ) - SWAP _r8c _Rdp A,, ; + SWAP _r8c _Rdp , ; 0b1001010010001000 OPb BCLR, 0b1001010000001000 OPb BSET, ( 0000 000d dddd 0bbb ) : OPRdb CREATE , DOES> @ ( rd b op ) - ROT _r32c _Rdp SWAP _r8c OR A,, ; + ROT _r32c _Rdp SWAP _r8c OR , ; 0b1111100000000000 OPRdb BLD, 0b1111101000000000 OPRdb BST, 0b1111110000000000 OPRdb SBRC, 0b1111111000000000 OPRdb SBRS, @@ -558,7 +547,7 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 PC - DUP 0< IF 0x800 + _r7ffc 0x800 OR ELSE _r7ffc THEN ; : RJMP _raddr12 0xc000 OR ; : RCALL _raddr12 0xd000 OR ; -: RJMP, RJMP A,, ; : RCALL, RCALL A,, ; +: RJMP, RJMP , ; : RCALL, RCALL , ; ( ----- 059 ) ( a -- k7, absolute addr a, relative to PC in a k7 addr ) : _r3fc DUP 0x3f > IF _oor THEN ; @@ -576,22 +565,22 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 0b11101 CONSTANT X+ 0b11001 CONSTANT Y+ 0b10001 CONSTANT Z+ 0b11110 CONSTANT -X 0b11010 CONSTANT -Y 0b10010 CONSTANT -Z : _ldst ( Rd XYZ op ) SWAP DUP 0x10 AND 8 LSHIFT SWAP 0xf AND - OR OR ( Rd op' ) SWAP _Rdp A,, ; + OR OR ( Rd op' ) SWAP _Rdp , ; : LD, 0x8000 _ldst ; : ST, SWAP 0x8200 _ldst ; ( ----- 061 ) ( L1 LBL! .. L1 ' RJMP LBL, ) : LBL! ( l -- ) PC SWAP ! ; -: LBL, ( l op -- ) SWAP @ 1- SWAP EXECUTE A,, ; -: SKIP, PC 0 A,, ; +: LBL, ( l op -- ) SWAP @ 1- SWAP EXECUTE , ; +: SKIP, PC 0 , ; : TO, ( opw pc ) ( TODO: use !* instead of ! ) ( warning: pc is a PC offset, not a mem addr! ) 2 * ORG @ + PC 1- H@ ( opw addr tgt hbkp ) ROT HERE ! ( opw tgt hbkp ) SWAP ROT EXECUTE H@ ! ( hbkp ) HERE ! ; ( L1 FLBL, .. L1 ' RJMP FLBL! ) -: FLBL, ( l -- ) LBL! 0 A,, ; +: FLBL, ( l -- ) LBL! 0 , ; : FLBL! ( l opw -- ) SWAP @ TO, ; -: BEGIN, PC ; : AGAIN?, ( op ) SWAP 1- SWAP EXECUTE A,, ; +: BEGIN, PC ; : AGAIN?, ( op ) SWAP 1- SWAP EXECUTE , ; : AGAIN, ['] RJMP AGAIN?, ; : IF, ['] BREQ SKIP, ; : THEN, TO, ; ( ----- 062 ) @@ -945,16 +934,16 @@ VARIABLE aspprevx 0xc0 ( b msb lsb 0xc0 ) _cmd DROP asprdy ; ( ----- 165 ) ( Sega ROM signer. See doc/sega.txt ) -: C!*+^ ( a c -- a+1 ) OVER C!* 1+ ; +: C!+^ ( a c -- a+1 ) OVER C! 1+ ; : segasig ( addr size -- ) 0x2000 OVER LSHIFT ( a sz bytesz ) ROT TUCK + 0x10 - ( sz a end ) TUCK SWAP 0 ROT> ( sz end sum end a ) DO ( sz end sum ) - I C@* + LOOP ( sz end sum ) SWAP ( sz sum end ) - 'T' C!*+^ 'M' C!*+^ 'R' C!*+^ 0x20 C!*+^ 'S' C!*+^ - 'E' C!*+^ 'G' C!*+^ 'A' C!*+^ 0 C!*+^ 0 C!*+^ - ( sum's LSB ) OVER C!*+^ ( MSB ) SWAP 8 RSHIFT OVER C!* 1+ - ( sz end ) 0 C!*+^ 0 C!*+^ 0 C!*+^ SWAP 0x4a + SWAP C!* ; + I C@ + LOOP ( sz end sum ) SWAP ( sz sum end ) + 'T' C!+^ 'M' C!+^ 'R' C!+^ 0x20 C!+^ 'S' C!+^ + 'E' C!+^ 'G' C!+^ 'A' C!+^ 0 C!+^ 0 C!+^ + ( sum's LSB ) OVER C!+^ ( MSB ) SWAP 8 RSHIFT OVER C! 1+ + ( sz end ) 0 C!+^ 0 C!+^ 0 C!+^ SWAP 0x4a + SWAP C! ; ( ----- 260 ) Cross compilation program @@ -1068,9 +1057,9 @@ NOP, NOP, NOP, NOP, NOP, NOP, ( unused ) 0 JP, ( RST 10 ) NOP, NOP, ( 13, oflw ) NOP, NOP, NOP, NOP, NOP, ( unused ) 0 JP, ( 1a, next ) NOP, NOP, NOP, ( unused ) -0 JP, ( RST 20 ) 0 C,* 0 C,* 0 C,* 0 C,* 0 C,* ( unused ) -0 JP, ( RST 28 ) 0 C,* 0 C,* 0 C,* 0 C,* 0 C,* ( unused ) -0 JP, ( RST 30 ) 0 C,* 0 C,* 0 C,* 0 C,* 0 C,* ( unused ) +0 JP, ( RST 20 ) 5 ALLOT0 +0 JP, ( RST 28 ) 5 ALLOT0 +0 JP, ( RST 30 ) 5 ALLOT0 0 JP, ( RST 38 ) ( ----- 284 ) PC ORG @ 1 + ! ( main ) @@ -1726,12 +1715,9 @@ with "390 LOAD" : / /MOD NIP ; : MOD /MOD DROP ; : ALLOT HERE +! ; -SYSVARS 0x3e + :** C@* -SYSVARS 0x40 + :** C!* -SYSVARS 0x42 + :** C,* : FILL ( a n b -- ) ROT> OVER ( b a n a ) + SWAP ( b a+n a ) DO ( b ) - DUP I C!* LOOP DROP ; + DUP I C! LOOP DROP ; : ALLOT0 ( n -- ) H@ OVER 0 FILL ALLOT ; ( ----- 356 ) SYSVARS 0x53 + :** EMIT @@ -1865,23 +1851,23 @@ SYSVARS 0x0c + :** C<* ( ----- 367 ) : MOVE ( a1 a2 u -- ) ?DUP IF ( u ) 0 DO ( a1 a2 ) - OVER I + C@* ( src dst x ) + OVER I + C@ ( src dst x ) OVER I + ( src dst x dst ) - C!* ( src dst ) + C! ( src dst ) LOOP THEN 2DROP ; : MOVE- ( a1 a2 u -- ) ?DUP IF ( u ) 0 DO ( a1 a2 ) - OVER I' + I - 1- C@* ( src dst x ) + OVER I' + I - 1- C@ ( src dst x ) OVER I' + I - 1- ( src dst x dst ) - C!* ( src dst ) + C! ( src dst ) 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 ) + 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 -- ) @@ -2120,7 +2106,6 @@ SYSVARS 0x55 + :** KEY ['] (emit) ['] EMIT **! ['] (key) ['] KEY **! ['] CRLF ['] NL **! ['] (boot<) ['] C<* **! - ['] C@ ['] C@* **! ['] C! ['] C!* **! ['] C, ['] C,* **! ( boot< always has a char waiting. 06 == CyHP9%mb{=QS-!6m2XeE-Yu zfBk*?uK9HHDiVL58p}bS@g;s#t4P_cBm@FTy#Iji{#M8XNQpaQ-x2&s|EgG#qIyBhw3|ZK;)J3k^qr->y z)(#Di)D8~6HMCderz}Nwl>ct|p0)BXtmFQFEFm&$G-x$mUsqn|E5ZWrm)qEGJ}z(Z z4$39csh;kbLSzxuO!A-QE&fSaqkLv(Cfn&k*_@prVK^s0qFGwt0VPnVR{X45(MZ^M zP*b%s!ydwBK@O2TM@>-8QjpECL3tJtHqj$?2i=>K?^1|vm#JD&*adh6neebSDUD>V z=ASCMFRTYM8OfV4%!q04LHn!O+?mN9`rEo19vz}r<7y$3l33Gx~PVl&8+pzt#En|wB z0stA4CuQ;NXBfx6p^?MKTIxw=VdWk`quE#_A9JExUb{{v5*_S~WRnp+g6Kk;$dL& zZEjeXNZ3DJfGesH_?gcDsDJ|1g057sb|!mJr^I?SRVR|rMCl>mgt)U~H5xF*_N%=- z;_$0i)H2Ph0_`k+-Lds~L68!8%prp7My&lbt6~L*Siu*`46(6-6H+7H)2Jhi4G6H~ z{1?a8jycDKBp!`6?OF?h{l)G(?mIN=wAUX@(J-blBRjCY5g=)ZgG-bwEh#G$0*XfT4Ti{P@aY8d zS5D+Q;S|+O@V2TAjzysA^){_$O8EodZ=m?Uq}lDbU;s3W!;xlDT{c z(dW?vw~=WAG^qp;0Olp>xKYM7Y;zSxZF8;5iJqW2H_c(Xy@EQv)F_$G$Fe=ySbh)L zu!N#qotX4=kVTUqkF`k#vqq>J+zk?xMT+KL;%hm1;;F@0=4=PBcU)hL$A;eru)Ho{g|zUj@FE*OiJudgvQ zT?PtAIy1PUh4%%_M0jtie|8XoKKJT0Es4Y;dM2B%_s}W!4P-Y>LZ-(O$+VkJ;{P8E z5|L!ujzcA2#`L5yg>*idsx}mrte+_Qyy#CWf7!P-cuiUMJZW2BG}GOaOvQ@T^dY;Z Sh(LYKMLUh*u0)+w1So!k#k znY0^L?@BAs?CVX!JuX&R!k!FN<+nCc*(`!#%iJMXvoLRzw}r#9PW6*V4>oKinJr6Q zN>RTWBdm-)A&F&$W9MnxZB*9Du>TA5N_dY7@j(q zjSWeqKiZUW)cVA+2kZ_eJb^jw*uuK`M-CmLS7_Sa!DiW2C_r@Cv2)L-4%3#j)j+$b zEGdExG1UFQ(TQVI4PjDPUR9ksC9|nSF6Bm9nw$pNNR(<{BHNiTG6+g#&+xdjMZ1ks z9CYe1@duxD?%h;`R?_V0%O!epbwbNoR4(x!ogtRze>o@EIDb*AKFL(hMzjz+%S?O$ zt<2u)S|n;}HLMly1eN4Er8D`yJzD^W5wKCB3!0_f=7V;Dg#P~>y{-vHh&5XVN=9K- zM)txNTG-i(d?YsBt{FrUXD6g`SBc%;x(SKSvQyf)HjE<2;7gf76f5>Pt%;O+pWBYB z*R?rX)r6M|yvMcsNihip^4p^XlTE<)S>|D5E`hbD$PTuJwMD6xe%Glrj#k&OS$@&A zyY;4PQ4+6C&HX`4(x1%XcDQvKazaVmkHcDl9BxfENJ1oHG;7!$OHGq`++ANMM)TJo zhNeB=-P@1wR-`%HRH+i9jAG3L(ZkfjPrG->S0zop%9q^j)oX5H-f4{jax};d%h%k9 zbrJpxw8$$xJ6#)YgJimoak;<3P0wR&fWPe7C7)@#gz<|K zY;=)r^zgD2l=+Z%7c=?$-kO?Kbf`3DA*__sUXkuP3!!%gm047p|Ll#7tZKF7?YF8S z#Qh|OK4T`@8{YvW1aNHZoVUcv`oNmE)?WuQnRNx_bKW@Jdnj$xfsN9QISX=PQ=0sM z?{Q=|7Flo@*kgp#x+O=y$x#3EvOB=L0M2D-YG>;F~mD$=|w;tvZy7+ zpm9)-Uw_m4tWCrjNGb&+5E5rcCBM~1~ ztKiAt75Rt$x|7S&3f4`#xr1JV!(l37^hJVZua^qo#4V1>ZurHdXF78|n}8?-6)Y;k zXuXT3Sr@T}ym|uDaUX8HfNGO-mMtlHtO3ZL77|ThO2;jo27!k_fxcCvw7qPC(A^?h zEGLwvKrMX_45VAFXrff)gMrEyZusZ0OLaIK62uj*v?N_t zyd2IiVP%`PGxqani@4n!-VUqR0tPKhB8r4zW^-Xby}|wlZ^c&RzXU=jMgIR~oA1eW zW;WC7aEMSI5ex*7bQ&-jEJLm(5GBp--p)+QLvOO%Y7;D$>ND_=Ke(ArLm(Uv)D1f6 Yl%<8i#-hib+fh|ll}h)u@yYVwzw$| (emit) KEY -> (key) NL -> CRLF - C@* -> C@ - C!* -> C! - C,* -> C, 3. Set "C<*", the word that C< calls, to (boot<). 4. Call INTERPRET which interprets boot source code until ASCII EOT (4) is met. This usually initializes drivers. diff --git a/doc/usage.txt b/doc/usage.txt index 6d8587b..7342876 100644 --- a/doc/usage.txt +++ b/doc/usage.txt @@ -82,23 +82,6 @@ addresses in RAM (because the core code is designed to run from ROM, we can't have regular variables). You are unlikely to need ialiases in regular code. -Aliases and ialiases generally have their name end with "*". -Core words such as KEY and EMIT, which are ialiases, are -exceptions. - -# Indirect memory access - -C@*, C!*, and C,* are the indirect versions of C@, C! and C,. -They are ialias words and initially point to C@, C! and C,. - -Indirect memory access words can be useful to "pipe" processing -to places outside of regular memory. - -Many core words, such as MOVE, use indirect memory access. This -gives a lot of flexibility to those words, allowing for complex -data transfers. The cost of the indirection is small because of -the optimized ways aliases are built. - # Disk blocks Disk blocks are Collapse OS' main access to permanent storage. diff --git a/tools/upload.c b/tools/upload.c index cea14d5..23ac2cb 100644 --- a/tools/upload.c +++ b/tools/upload.c @@ -42,7 +42,7 @@ int main(int argc, char **argv) } char s[0x40]; sprintf(s, - ": _ 0x%04x 0x%04x DO KEY DUP .x I C!* LOOP ; _", + ": _ 0x%04x 0x%04x DO KEY DUP .x I C! LOOP ; _", memptr+bytecount, memptr); sendcmd(fd, s);