From 3b21ba635d90935bcea2918faa9e562e3bd5a682 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 18 Jun 2020 21:21:46 -0400 Subject: [PATCH] pcat: add PICK and (roll) --- blk/750 | 2 +- blk/751 | 1 + blk/753 | 7 ++++--- blk/754 | 18 ++++++++---------- blk/755 | 22 +++++++++------------- blk/756 | 10 ---------- blk/757 | 30 ++++++++++++++---------------- blk/758 | 20 ++++++++++---------- blk/759 | 19 ++++++++++++++++--- blk/760 | 10 ++++++++++ blk/761 | 3 +++ blk/821 | 14 +++++++++----- blk/822 | 11 +++++------ blk/824 | 6 ++++++ recipes/pcat/xcomp.fs | 2 +- 15 files changed, 97 insertions(+), 78 deletions(-) delete mode 100644 blk/756 create mode 100644 blk/760 create mode 100644 blk/761 create mode 100644 blk/824 diff --git a/blk/750 b/blk/750 index dfa31f7..80836cc 100644 --- a/blk/750 +++ b/blk/750 @@ -1 +1 @@ -1 9 LOADR+ +1 11 LOADR+ diff --git a/blk/751 b/blk/751 index 3ec81cb..8ea06c4 100644 --- a/blk/751 +++ b/blk/751 @@ -8,3 +8,4 @@ VARIABLE L1 VARIABLE L2 VARIABLE L3 VARIABLE L4 : ES 0 ; : CS 1 ; : SS 2 ; : DS 3 ; : [BX+SI] 0 ; : [BX+DI] 1 ; : [BP+SI] 2 ; : [BP+DI] 3 ; : [SI] 4 ; : [DI] 5 ; : [BP] 6 ; : [BX] 7 ; +: <<3 3 LSHIFT ; diff --git a/blk/753 b/blk/753 index 20d198d..535c12b 100644 --- a/blk/753 +++ b/blk/753 @@ -2,12 +2,13 @@ 0xc3 OP1 RETn, 0xfa OP1 CLI, 0xfb OP1 STI, 0xf4 OP1 HLT, 0xfc OP1 CLD, 0xfd OP1 STD, 0x90 OP1 NOP, +0xf3 OP1 REPZ, 0xf2 OP1 REPNZ, 0xac OP1 LODSB, +0xad OP1 LODSW, 0xa6 OP1 CMPSB, 0xa7 OP1 CMPSW, +0xa4 OP1 MOVSB, 0xa5 OP1 MOVSW, 0xae OP1 SCASB, +0xaf OP1 SCASW, 0xaa OP1 STOSB, 0xab OP1 STOSW, ( no argument, jumps with relative addrs are special ) 0xeb OP1 JMPs, 0xe9 OP1 JMPn, 0x74 OP1 JZ, 0x75 OP1 JNZ, 0xe8 OP1 CALLn, -0xf3 OP1 REPZ, 0xf2 OP1 REPNZ, 0xac OP1 LODSB, -0xa6 OP1 CMPSB, 0xa4 OP1 MOVSB, 0xae OP1 SCASB, -0xaa OP1 STOSB, : OP1r CREATE C, DOES> C@ + A, ; 0x40 OP1r INCx, 0x48 OP1r DECx, diff --git a/blk/754 b/blk/754 index b5ac009..275f665 100644 --- a/blk/754 +++ b/blk/754 @@ -1,16 +1,14 @@ -: OPrr CREATE C, DOES> C@ A, 3 LSHIFT OR 0xc0 OR A, ; +: OPr0 ( reg op ) CREATE C, C, DOES> + C@+ A, C@ <<3 OR 0xc0 OR A, ; +0 0xd0 OPr0 ROLr1, 0 0xd1 OPr0 ROLx1, +1 0xd0 OPr0 RORr1, 1 0xd1 OPr0 RORx1, +4 0xd0 OPr0 SHLr1, 4 0xd1 OPr0 SHLx1, +5 0xd0 OPr0 SHRr1, 5 0xd1 OPr0 SHRx1, + +: OPrr CREATE C, DOES> C@ A, <<3 OR 0xc0 OR A, ; 0x31 OPrr XORxx, 0x30 OPrr XORrr, 0x88 OPrr MOVrr, 0x89 OPrr MOVxx, 0x28 OPrr SUBrr, 0x29 OPrr SUBxx, 0x08 OPrr ORrr, 0x09 OPrr ORxx, 0x3a OPrr CMPrr, 0x3b OPrr CMPxx, 0x00 OPrr ADDrr, 0x01 OPrr ADDxx, -: OPm ( modrm op ) CREATE C, C, DOES> C@+ A, C@ OR A, ; -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@+ A, C@ ROT OR A, A, ; -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]+, diff --git a/blk/755 b/blk/755 index 19337f7..472d027 100644 --- a/blk/755 +++ b/blk/755 @@ -1,14 +1,10 @@ -: OPrm CREATE C, DOES> C@ A, SWAP 3 LSHIFT OR A, ; -0x8a OPrm MOVr[], 0x8b OPrm MOVx[], +: OPm ( modrm op ) CREATE C, C, DOES> C@+ A, C@ OR A, ; +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], -: 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[]+, -0x3a OPrm+ CMPr[]+, 0x3b OPrm+ CMPx[]+, - -: 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, +: OPm+ ( modrm op ) CREATE C, C, DOES> + ( m off ) C@+ A, C@ ROT OR A, A, ; +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]+, diff --git a/blk/756 b/blk/756 deleted file mode 100644 index 762fc04..0000000 --- a/blk/756 +++ /dev/null @@ -1,10 +0,0 @@ -: 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, ; -: ADDxi, 0x83 A, SWAP 0xc0 OR A, A, ; -: JMPr, 0xff A, 7 AND 0xe0 OR A, ; -: JMPf, ( seg off ) 0xea A, SPLITB A, A, A,, ; diff --git a/blk/757 b/blk/757 index 3ff2e8b..19337f7 100644 --- a/blk/757 +++ b/blk/757 @@ -1,16 +1,14 @@ -( 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! ; +: 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[]+, +0x3a OPrm+ CMPr[]+, 0x3b OPrm+ CMPx[]+, + +: 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, diff --git a/blk/758 b/blk/758 index ba1f378..762fc04 100644 --- a/blk/758 +++ b/blk/758 @@ -1,10 +1,10 @@ -: 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, ) +: 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, ; +: ADDxi, 0x83 A, SWAP 0xc0 OR A, A, ; +: JMPr, 0xff A, 7 AND 0xe0 OR A, ; +: JMPf, ( seg off ) 0xea A, SPLITB A, A, A,, ; diff --git a/blk/759 b/blk/759 index 7c8c317..3ff2e8b 100644 --- a/blk/759 +++ b/blk/759 @@ -1,3 +1,16 @@ -: CODE ( same as CREATE, but with native word ) - (entry) 0 ( native ) C, ; -: ;CODE JMPn, 0x1a ( next ) 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! ; diff --git a/blk/760 b/blk/760 new file mode 100644 index 0000000..ba1f378 --- /dev/null +++ b/blk/760 @@ -0,0 +1,10 @@ +: 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, ) diff --git a/blk/761 b/blk/761 new file mode 100644 index 0000000..7c8c317 --- /dev/null +++ b/blk/761 @@ -0,0 +1,3 @@ +: CODE ( same as CREATE, but with native word ) + (entry) 0 ( native ) C, ; +: ;CODE JMPn, 0x1a ( next ) RPCn, ; diff --git a/blk/821 b/blk/821 index 2b0901c..aba8804 100644 --- a/blk/821 +++ b/blk/821 @@ -5,8 +5,12 @@ CODE SWAP AX POPx, BX POPx, AX PUSHx, BX PUSHx, ;CODE CODE OVER ( a b -- a b a ) DI SP MOVxx, AX [DI] 2 MOVx[]+, AX PUSHx, ;CODE -CODE 0 AX AX XORxx, AX PUSHx, ;CODE -CODE 1 AX 1 MOVxI, AX PUSHx, ;CODE -CODE I [BP] 0 PUSH[w]+, ;CODE -CODE 1+ DI SP MOVxx, [DI] INC[w], ;CODE -CODE 1- DI SP MOVxx, [DI] DEC[w], ;CODE +CODE PICK + DI POPx, DI SHLx1, ( x2 ) + DI SP ADDxx, DI [DI] MOVx[], DI PUSHx, +;CODE +CODE (roll) ( "2 3 4 5 4 --> 2 4 5 5". See B311 ) + CX POPx, SI SP MOVxx, SI CX ADDxx, + DI SI MOVxx, SI DECx, SI DECx, + STD, REPZ, MOVSB, +;CODE diff --git a/blk/822 b/blk/822 index 5b1e035..039c38b 100644 --- a/blk/822 +++ b/blk/822 @@ -1,6 +1,5 @@ -CODE BYE BEGIN, JMPs, AGAIN, ;CODE -CODE EMIT - AX POPx, AH 0x0e MOVri, ( print char ) 0x10 INT, -;CODE -: FOO 'A' 'B' 'C' OVER EMIT EMIT EMIT ; -: BOOT ['] FOO EXECUTE BYE ; +CODE 0 AX AX XORxx, AX PUSHx, ;CODE +CODE 1 AX 1 MOVxI, AX PUSHx, ;CODE +CODE I [BP] 0 PUSH[w]+, ;CODE +CODE 1+ DI SP MOVxx, [DI] INC[w], ;CODE +CODE 1- DI SP MOVxx, [DI] DEC[w], ;CODE diff --git a/blk/824 b/blk/824 new file mode 100644 index 0000000..8b7d3ce --- /dev/null +++ b/blk/824 @@ -0,0 +1,6 @@ +CODE BYE BEGIN, JMPs, AGAIN, ;CODE +CODE EMIT + AX POPx, AH 0x0e MOVri, ( print char ) 0x10 INT, +;CODE +: FOO 'A' 'B' 'C' 2 PICK 4 (roll) EMIT EMIT EMIT EMIT ; +: BOOT ['] FOO EXECUTE BYE ; diff --git a/recipes/pcat/xcomp.fs b/recipes/pcat/xcomp.fs index 420dd40..e9cc40e 100644 --- a/recipes/pcat/xcomp.fs +++ b/recipes/pcat/xcomp.fs @@ -3,7 +3,7 @@ 750 LOAD ( 8086 asm ) 262 LOAD ( xcomp ) 270 LOAD ( xcomp overrides ) -812 822 LOADR +812 824 LOADR (entry) _ ( Update LATEST ) PC ORG @ 8 + !