From 4de2ce3cebf4192989b14ed65e3af02149d86aeb Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 12 Nov 2019 14:07:45 -0500 Subject: [PATCH] zasm: add RST instruction --- apps/zasm/instr.asm | 37 ++++++++++++++++++++++++++------ tools/emul/zasm/kernel.bin | Bin 1529 -> 1522 bytes tools/emul/zasm/zasm.bin | Bin 4572 -> 4630 bytes tools/tests/zasm/allinstrs.asm | 8 +++++++ tools/tests/zasm/allinstrs.asm.expected | Bin 5626 -> 5634 bytes tools/tests/zasm/geninstrs.py | 9 +++++--- 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index b938f95..a7401e8 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -58,13 +58,14 @@ .equ I_RRA 0x33 .equ I_RRC 0x34 .equ I_RRCA 0x35 -.equ I_SBC 0x36 -.equ I_SCF 0x37 -.equ I_SET 0x38 -.equ I_SLA 0x39 -.equ I_SRL 0x3a -.equ I_SUB 0x3b -.equ I_XOR 0x3c +.equ I_RST 0x36 +.equ I_SBC 0x37 +.equ I_SCF 0x38 +.equ I_SET 0x39 +.equ I_SLA 0x3a +.equ I_SRL 0x3b +.equ I_SUB 0x3c +.equ I_XOR 0x3d ; *** Variables *** ; Args are 3 bytes: argspec, then values of numerical constants (when that's @@ -555,6 +556,26 @@ handleLDrr: ld c, 1 ret +handleRST: + ld a, (INS_CURARG1+1) + ; verify that A is either 0x08, 0x10, 0x18, 0x20, 0x28, 0x30 or 0x38. + ; Good news: they're all multiples of 8. + ; to verify that we're within range, we to 8-bit rotation. If any of + ; the first 3 bytes are set (thus not a multiple of 8), the cp 8 + ; later will yield NC because those bits will now be upwards. + rrca \ rrca \ rrca + cp 8 + jr nc, .error + ; good, we have a proper arg. Now let's get those 3 bits in position + rlca \ rlca \ rlca + or 0b11000111 + ld (INS_UPCODE), a + ld c, 1 + ret +.error: + ld c, 0 + ret + ; Compute the upcode for argspec row at (DE) and arguments in curArg{1,2} and ; writes the resulting upcode to IO. ; A is zero, with Z set, on success. A is non-zero, with Z unset, on error. @@ -1045,6 +1066,7 @@ instrNames: .db "RRA", 0 .db "RRC", 0 .db "RRCA" + .db "RST", 0 .db "SBC", 0 .db "SCF", 0 .db "SET", 0 @@ -1214,6 +1236,7 @@ instrTBlRET: .db I_RRA, 0, 0, 0, 0x1f , 0 ; RRA .db I_RRC, 0xb, 0,0x40, 0xcb, 0b00001000 ; RRC r .db I_RRCA,0, 0, 0, 0x0f , 0 ; RRCA + .db I_RST, 'n', 0, 0x20 \ .dw handleRST ; RST p .db I_SBC, 'A', 'l', 0, 0x9e , 0 ; SBC A, (HL) .db I_SBC, 'A', 0xb, 0, 0b10011000 , 0 ; SBC A, r .db I_SBC,'h',0x3,0x44, 0xed, 0b01000010 ; SBC HL, ss diff --git a/tools/emul/zasm/kernel.bin b/tools/emul/zasm/kernel.bin index ac964951782a490db9e6d1ef68d9ebfb539bb42d..54be8c0df343727f7fd94fc20a2095d4729ace50 100644 GIT binary patch delta 1085 zcmY*YO=#Rk6n-O(HXFNcym4to`eP}guCggjFecbb5Mu&ehz*4VLZNK}G4vQ{F6)Gi zw@~Pzv`ZaR-?&p)Z#QoK+naVEAzWy4ny0bE{XUk&OH_5Cv0RIx1ss5#{yCY%UqvAS@ z?+0RyWN|;r6DiT7ScZv-%yA0n-y>#gUd#FzMrs2STO`dQnTQQdv>?vR?V-G<M9YIocl$K;%Ia22 zZ3>xxTzLO7bnGfCy(@f(#OKCCndCbkO|$9@^FZ9C{Wud3biPPKS({_)?pt+_*g%jO z-$TMGi$!YbUGu2;M;DvAXafcq%2vs;&oOa>X2C=ASSSyVUlvEmrKj1Jx*fC5!$jIk zdgUA=I_%u**mJD(CI*wm0j8IHAU@NrDJj0utugU2we~QI2d-xRi~ep+&#|m>o{??em5A_ljNhVC?&sn%VJwK~i*_EgF6r5uigxC!xDtsCLHlQw|( zo7!)Hr>Tm_J86T8+q9WB4E$xCNaWO|9i@tT;yUf(U@C+pQkxDxV#p-KVXssfDXUU^ zPj@a)v--&y_Pj+MbF@=>N#*B*X9QRPnN+K+g5Ga}WnhU+(naYr``}>T(<=COnnWxb T_D}xL#;ZEI_cx6*S{wccTT1j= delta 1074 zcmY*YU1%It6h3$6&bm#E$!0-^`qLQ)+hHxVhES3c$18%XAlM`zf>^K*lD_yPZiHmF z6zr1^4Z9C5k8Qvl4`j=T5eWGt8ZH&v(wb z=bZ1{zb5x5t8&|rcR;=gat-7IkS&n!f?Nh!2l*w)3?ygrGLzd(E^v8+%TtD22kA0- zm&pN>RZaFa`P=-?Ga|`E787w^g6g^d^KC%~zm^EkFg2q|%EjHhXw2nK`t9l&QU}oRPZI*xjNNmrR^H-VdWU0q&23XaS0c953An-1WlOT<-ui}TF`>N@sp7l@*K!rBTMTYw}88bV-6|ZURqc3%zokrnKwnUH$jU6?4rQ$ zp`hVVQ{V

zniuWKW2~F+2yODYrbDaHmHNcXm{C^(Sz*`HKEzgMwHpQjr$($Jbt8 zg|=N0g_C$40=#1Eq*1o_-khk+3lH!bAA|{Zb-BWO>Dfimai6PFKYh5Q{*F2QX!|*B8#^WtCz@@k=u~9Zi&FcdUOFR~4tqD+ z_M#{}OUWdmPt`n84=JgT`1W+lX|;4wCnQXQvrA$GIenG!NGK{v&RHJI!!_Qefm0HJ1oa&`Wu#G$rnpoQtf=b#itnw?i4UHi7yt3mHYeMK$5k=c z!83fSHjOG3QKHk=!7`{JChL;+p?z?$?`b8v6qgyU81^>?!W*BQwqAmb+ideT`vp2K OrA`h((>G3OE%+B2`Rca- diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index 6144871015bb9503b1c4182e8559c0c282036aad..0b6ad17982b00b696f28d3146bf43acbc0aa13b5 100644 GIT binary patch delta 1718 zcmYLKTWl0n7(TPNUUqi3(@HzNP-b>pJKb8S3-+?@4it!VTbkC=c6MpBBM(Zn@*-}# z1hzbwNO(}1i9`}Zf|qD~U?rH;faz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_1z+KMNbC#fxFXER+~V zT4aDg!&I|u(S98 delta 1692 zcmYjSU2M}<6uwT<^e0Kvv@3OgLhU$NO}avtv6B9|P}-67hZJbydPrdHVW3f_Nn7*0 zYQRnuOJV2iIM?h(a!U7QH71o|tJ1g;wZf9Jr>9hAUdHa(Z+g31P;NHbz+22ljo4iOx~(5|F=9r>Z9_PSvI<=-;x@z)fJ-9;iPC2FJ~*f02hbOc z0PvZ!cFAU8-0jFWywm2S+>5OTKsr82YH;V6Dq_n<(M|{2zD#u)-*DF?s#@l{ zClNY_x*Z68gu35E=oi!jmakC{ST3U;u>6h&`q2Q72KU5cdw0DO9f`%qqq}$ZM|WQy z|6`nqABmriUy0w2S3intM&-}bTSa^}!nR?r^ry3>5m=N{OoqLScSfn-$OmQ+V+47n zt*(IG@Z%QgpsQ)r%TsmqDN)f1tNT(SF7m8P-$0ggHKfI)ZJ_|6(?hxGAtR9sL%dVb zRNN*2ug`*v2+9lKd6#bxs5bMF7%rvBOv+Pk*mL4$@Z`G12`Ej@yT#br~T2SuesYF&QZa@r!gAv^t zZq#jIw_XyqkPVnd;aY|#%TjnF3Og9yFxU>x8;`);4OHpvh6d=zp`c763yoqTN%=|& z9>@L4_Ct$_Jnn?wyNP^mbQs@(XyA zs8Ftk1H4+0xmLWLUpmTjZN~Tx&jpR~eLlCE(C`?K8>Lfj?~IqvuE2G`YgcI>#oAwrmmD8sj7_CM(da zHTYYBtT$^1vkB&SswpZ@S<>*AfZ#HsLBHs0P8!8|lTf#@0T{+p(O`4Z=NFAC!8|Yj E3xM^l2><{9 diff --git a/tools/tests/zasm/allinstrs.asm b/tools/tests/zasm/allinstrs.asm index ffb880b..09c9e0c 100644 --- a/tools/tests/zasm/allinstrs.asm +++ b/tools/tests/zasm/allinstrs.asm @@ -1797,6 +1797,14 @@ RRC H RRC L RRC A RRCA +RST 0 +RST 8 +RST 16 +RST 24 +RST 32 +RST 40 +RST 48 +RST 56 SBC A, (HL) SBC A, B SBC A, C diff --git a/tools/tests/zasm/allinstrs.asm.expected b/tools/tests/zasm/allinstrs.asm.expected index 9fe2b1cc964c8c4f3d2ff0a6991862d0777cca58..59ad40fd8967be77cac5383984d9fc1eae87938e 100644 GIT binary patch delta 21 dcmeyR-K4X@TZH5I`Rn(ezyJP!v$x24MgV^Y3&j8c delta 12 TcmZqD`K7(VTV!*v$a+QqA-V*u diff --git a/tools/tests/zasm/geninstrs.py b/tools/tests/zasm/geninstrs.py index 8629fd1..9cb7950 100755 --- a/tools/tests/zasm/geninstrs.py +++ b/tools/tests/zasm/geninstrs.py @@ -84,9 +84,10 @@ def getDbLines(fp, tblname): line = fp.readline() while line: line = cleanupLine(line) - if line: - if not line.startswith('.db'): - break + if line == '.db 0xff': + break + # skip index labels lines + if line.startswith('.db'): result.append([s.strip() for s in line[4:].split(',')]) line = fp.readline() return result @@ -151,6 +152,8 @@ def main(): args1 = eargs(args1) if n == 'IM': args1 = [0, 1, 2] + if n == 'RST': + args1 = [i*8 for i in range(8)] if args1: for arg1 in args1: args2 = genargs(a2)