From 0750e8d0c09c6f6206cf946c0c98d2c146e9779d Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 15 Apr 2020 17:01:15 -0400 Subject: [PATCH] Use IY for IP instead of RAM+06 --- blk/081 | 2 +- emul/forth/z80c.bin | Bin 2157 -> 2148 bytes forth/boot.fs | 56 ++++++++++++++++++++------------------------ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/blk/081 b/blk/081 index 8916df1..13fee0c 100644 --- a/blk/081 +++ b/blk/081 @@ -2,7 +2,7 @@ RAMSTART INITIAL_SP +53 readln's variables +02 CURRENT +55 adev's variables +04 HERE +57 blk's variables -+06 IP +59 z80a's variables ++06 FUTURE USES +59 z80a's variables +08 FLAGS +5b FUTURE USES +0a PARSEPTR +70 DRIVERS +0c CINPTR +80 RAMEND diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index 9de982f52fbca05ce37338619410c6a794bffd39..892e604023bf05d948318089fd32c9530afaa4f4 100644 GIT binary patch delta 1283 zcmYjROH31C5T4mrD}e=6Krx0w4YsJn7Y79;x~|wnsgy-)RD4iP^q>_n(Zr;9gNtH3 zaIqdd8A4)=@kD$i8`Bd9560+85>ZT}7cX9#`pv&Z?V-E#`ewdwCi|oAOI^-?OukR* z=U-$0Ec*ugwOss8euDi@9;drBjNl^W(lC{du~_ecfU3o(eaRosP$a5Q?Pw_h~ zm)9IRcz9pmpiQP7p)d^^4#l$PMz3G!h}TmXzAEKAw0uJ$h}-@gzI6 zZ+|l7ZNN}(^>?V+6DGEGV*=y$1g{Y)mvz&jz11obAto`;WHaYRM(WXWh9lHUwwVQk zIlMDD6rrs&t4V}ZBo~CrWrxJMg4X{{7heIsDtf8qH7QsYCKEpiVP?2XmzphTo250C z7J2QSDY?@;s}(>)-V40VoM9P*D>!p3$V~YhX6e$WVFoEn<$%XD&!ITjL;N!Iyk|~m zSxEmIS~xwmq+t=&5WPVcu{PV#U;>7z%YTG4%4-wQ7Rj5}B3Zocl^EJqV#fz_z0ITp zs+Dv@4Wx;}Uh;S{b)X3v+SUxGt)R67ifQ@@StPnntUNyv}$GjgV$#?jvd%p}Nt!W^;lSFeus z#J2+|LY+!tnY^+vuo9ni+@DN(QKf2d|40knz+>qCDzeta=x zzA(uUqRp<5Lx&Sy|0#tZp%$w}C>=TC9_W?Z79O)&7qG{v4;$-VNq6iGxX>2si7wLa kmWyZ)$qu@$fPEuQJQQB;Vjwk5tE(#9e}w|}XLb_*0i|dml>h($ delta 1273 zcmYjR%TE(=5T4oHE|rwEh+4&ng&ML2UooB(A+S^>5sGEi8hivq6E$LkUVOw#LgKl2 zQBQcFS7Vwc9=t74FPM7p;z^B~8iMf;Fsa}Censt}yYu>HzHcV`HM$zj2Sp0rkopC8 zIJm+=n1dEx`9Z-j2m5)B=4lS$V5Az{XZ@ViPfBHnd?G8hypcNWYS5}s+{u~b1~|Ly z>iNW}?ydER+Xw$93dKGzZ>M`@_Y>lYM8^(Qr*jiX{QwkL-<}^$ufBj?c-qd-3a>76 z+oJ?`b@ub>xLuvR*3z;%rtnwJZ>E)&A1GOFrWG_4kVn(Jg?E%5@_Qp+G(0+Ty#MH! zLm?+lVLEGhD4p~A~q8^QTqi4F2tpyuY zXg07!oV*le={rEjFHPT?xqYq^WM$e4zp*tJRvQyG6^JT6Ii|AV+Q3ql@N`vqvIpf) z>|eI`@1&x%4z9PBEJ>!k4y1X=kMpzgj+w>L&jMy1@4PdW~y(|$s!V8F8oU&q?U)D_RdBa^OGAgZBNRId;H<@oWPkom$SLx?s54IUjI z@<+}p{5ZL`E0l(ZQ-ghS+rp!4^aA?Vj(q48yoA~e>Z6M7Y-2r0gq1<8~^|S diff --git a/forth/boot.fs b/forth/boot.fs index 6ef4ffc..c08fb12 100644 --- a/forth/boot.fs +++ b/forth/boot.fs @@ -1,6 +1,13 @@ ( Configuration words: RAMSTART, RS_ADDR ) H@ 256 /MOD 2 PC! 2 PC! +( RESERVED REGISTERS + + At all times, IX points to RSP TOS and IY is IP. SP points + to PSP TOS, but you can still use the stack in native code. + you just have to make sure you've restored it before "next". +) + ( STABLE ABI Those jumps below are supposed to stay at these offsets, always. If they change bootstrap binaries have to be @@ -44,10 +51,10 @@ NOP, ( unused ) 'E' A, 'X' A, 'I' A, 'T' A, 0 A,, ( prev ) 4 A, -L1 BSET ( EXIT ) +L1 BSET ( EXIT, 0x43 ) 0x17 A, ( nativeWord ) - 0x14 CALLnn, ( popRS ) - RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) + 0x14 CALLnn, ( popRS ) + HL PUSHqq, IY POPqq, ( --> IP ) JPNEXT, NOP, NOP, NOP, NOP, ( unused ) @@ -58,13 +65,13 @@ PC L1 @ - A,, ( prev ) L1 BSET ( BR ) 0x17 A, ( nativeWord ) L2 BSET ( used in CBR ) - RAMSTART 0x06 + LDHL(nn), ( RAMSTART+0x06 == IP ) + IY PUSHqq, HL POPqq, ( <-- IP ) E (HL) LDrr, HL INCss, D (HL) LDrr, HL DECss, DE ADDHLss, - RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) + HL PUSHqq, IY POPqq, ( --> IP ) JPNEXT, NOP, ( unused ) @@ -80,10 +87,8 @@ H@ XCURRENT ! ( set current tip of dict ) L ORr, JRZ, L2 BWR ( BR + 2. False, branch ) ( True, skip next 2 bytes and don't branch ) - RAMSTART 0x06 + LDHL(nn), ( RAMSTART+0x06 == IP ) - HL INCss, - HL INCss, - RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) + IY INCss, + IY INCss, JPNEXT, ( END OF STABLE ABI ) @@ -101,12 +106,10 @@ PC ORG @ 0x24 + ! ( addrWord ) compiled word list. What we need to do to fetch that number is to play with the IP. ) - RAMSTART 0x06 + LDHL(nn), ( RAMSTART+0x06 == IP ) - E (HL) LDrr, - HL INCss, - D (HL) LDrr, - HL INCss, - RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) + E 0 IY+ LDrIXY, + D 1 IY+ LDrIXY, + IY INCss, + IY INCss, DE PUSHqq, JPNEXT, @@ -115,7 +118,7 @@ PC ORG @ 0x22 + ! ( litWord ) string literal. Instead of being followed by a 2 bytes number, it's followed by a null-terminated string. When called, puts the string's address on PS ) - RAMSTART 0x06 + LDHL(nn), ( RAMSTART+0x06 == IP ) + IY PUSHqq, HL POPqq, ( <-- IP ) HL PUSHqq, ( skip to null char ) A XORr, ( look for null ) @@ -125,7 +128,7 @@ PC ORG @ 0x22 + ! ( litWord ) ( CPIR advances HL regardless of comparison, so goes one char after NULL. This is good, because that's what we want... ) - RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) + HL PUSHqq, IY POPqq, ( --> IP ) JPNEXT, ( Name of BOOT word ) @@ -294,17 +297,10 @@ PC ORG @ 0x1b + ! ( next ) ( Before we continue: are stacks within bounds? ) 0x1d CALLnn, ( chkPS ) L2 @ CALLnn, ( chkRS ) - DE RAMSTART 0x06 + LDdd(nn), ( RAMSTART+0x06 == IP ) - H D LDrr, - L E LDrr, - DE INCss, - DE INCss, - RAMSTART 0x06 + DE LD(nn)dd, ( RAMSTART+0x06 == IP ) - ( HL is an atom list pointer. We need to go into it to - have a wordref ) - E (HL) LDrr, - HL INCss, - D (HL) LDrr, + E 0 IY+ LDrIXY, + D 1 IY+ LDrIXY, + IY INCss, + IY INCss, ( continue to execute ) PC ORG @ 0x34 + ! ( execute ) @@ -324,7 +320,7 @@ PC ORG @ 0x0f + ! ( compiledWord ) 1. Push current IP to RS 2. Set new IP to the second atom of the list 3. Execute the first atom of the list. ) - RAMSTART 0x06 + LDHL(nn), ( RAMSTART+0x06 == IP ) + IY PUSHqq, HL POPqq, ( <-- IP ) 0x11 CALLnn, ( 11 == pushRS ) EXDEHL, ( HL points to PFA ) ( While we increase, dereference into DE for execute call @@ -333,7 +329,7 @@ PC ORG @ 0x0f + ! ( compiledWord ) HL INCss, D (HL) LDrr, HL INCss, - RAMSTART 0x06 + LD(nn)HL, ( RAMSTART+0x06 == IP ) + HL PUSHqq, IY POPqq, ( --> IP ) 0x33 JPnn, ( 33 == execute ) PC ORG @ 0x0c + ! ( cellWord )