URL
https://opencores.org/ocsvn/a-z80/a-z80/trunk
Subversion Repositories a-z80
[/] [a-z80/] [trunk/] [tools/] [zmac/] [zexall.asm] - Rev 3
Compare with Previous | Blame | View Log
title 'Z80 instruction set exerciser'; zexall.src - Z80 instruction set exerciser; Original Copyright (C) 1994 Frank D. Cringle; Changes at 03-Nov-2002 Copyright (C) 2002 J.G.Harston; + Source syntax tweeked to assemble with ZMAC Z80 Macro Assembler; and MAXAM Assembler, marked in the source with 'jgh:'; + labels on equates mustn't have trailing colon; + macros don't understand <...> sequence, so parameters are passed; explicitly; + ds n,c not supported, so strings are set to full explicity length;; This program is free software; you can redistribute it and/or; modify it under the terms of the GNU General Public License; as published by the Free Software Foundation; either version 2; of the License, or (at your option) any later version.;; This program is distributed in the hope that it will be useful,; but WITHOUT ANY WARRANTY; without even the implied warranty of; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License; along with this program; if not, write to the Free Software; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.aseg;; Boot code for the A-Z80 CPU FPGA implementation;org 0start:jmp boot; BDOS entry point for various functions; We implement subfunctions:; C=2 Print a character given in E; C=9 Print a string pointed to by DE; string ends with '$'org 5ld a,ccp a,2jz bdos_asciicp a,9jz bdos_msgretbdos_ascii:ld bc,10*256 ; Port to check for busyin a,(c) ; Poll until the port is not busybit 0,ajnz bdos_asciild bc,8*256 ; Port to write a character outout (c),eretbdos_msg:push depop hllp0:ld e,(hl)ld a,ecp a,'$'ret zcall bdos_asciiinc hljmp lp0;---------------------------------------------------------------------; RST38 (also INT M0) handler;---------------------------------------------------------------------org 038hpush deld de,int_msgint_common:push afpush bcpush hlld c,9call 5pop hlpop bcpop afpop deeiretiint_msg:db "_INT_",'$';---------------------------------------------------------------------; NMI handler;---------------------------------------------------------------------org 066hpush afpush bcpush depush hlld de,nmi_msgld c,9call 5pop hlpop depop bcpop afretnnmi_msg:db "_NMI_",'$';---------------------------------------------------------------------; IM2 vector address and the handler (to push 0x80 by the IORQ);---------------------------------------------------------------------org 080hdw im2_handlerim2_handler:push deld de,int_im2_msgjmp int_commonint_im2_msg:db "_IM2_",'$'boot:; Set the stack pointerld sp, 16384 ; 16 Kb of RAM; Jump into the executable at 100hjmp 100horg 100hjp start100; machine state before test (needs to be at predictably constant address)msbt: ds 14spbt: ds 2msbthi equ msbt / 0100hmsbtlo equ msbt & 0ffh; For the purposes of this test program, the machine state consists of:; a 2 byte memory operand, followed by; the registers iy,ix,hl,de,bc,af,sp; for a total of 16 bytes.; The program tests instructions (or groups of similar instructions); by cycling through a sequence of machine states, executing the test; instruction for each one and running a 32-bit crc over the resulting; machine states. At the end of the sequence the crc is compared to; an expected value that was found empirically on a real Z80.; A test case is defined by a descriptor which consists of:; a flag mask byte,; the base case,; the incement vector,; the shift vector,; the expected crc,; a short descriptive message.;; The flag mask byte is used to prevent undefined flag bits from; influencing the results. Documented flags are as per Mostek Z80; Technical Manual.;; The next three parts of the descriptor are 20 byte vectors; corresponding to a 4 byte instruction and a 16 byte machine state.; The first part is the base case, which is the first test case of; the sequence. This base is then modified according to the next 2; vectors. Each 1 bit in the increment vector specifies a bit to be; cycled in the form of a binary counter. For instance, if the byte; corresponding to the accumulator is set to 0ffh in the increment; vector, the test will be repeated for all 256 values of the; accumulator. Note that 1 bits don't have to be contiguous. The; number of test cases 'caused' by the increment vector is equal to; 2^(number of 1 bits). The shift vector is similar, but specifies a; set of bits in the test case that are to be successively inverted.; Thus the shift vector 'causes' a number of test cases equal to the; number of 1 bits in it.; The total number of test cases is the product of those caused by the; counter and shift vectors and can easily become unweildy. Each; individual test case can take a few milliseconds to execute, due to; the overhead of test setup and crc calculation, so test design is a; compromise between coverage and execution time.; This program is designed to detect differences between; implementations and is not ideal for diagnosing the causes of any; discrepancies. However, provided a reference implementation (or; real system) is available, a failing test case can be isolated by; hand using a binary search of the test space.start100: ld hl,(6);ld sp,hlld de,msg1ld c,9call bdosld hl,tests ; first test caseloop: ld a,(hl) ; end of list ?inc hlor (hl)jp z,donedec hlcall sttjp loopdone: ld de,msg2ld c,9call bdosdie: jr diejp 0 ; warm boottests:dw adc16dw add16dw add16xdw add16ydw alu8idw alu8rdw alu8rxdw alu8xdw bitxdw bitz80dw cpd1dw cpi1dw daaop ; can't use opcode as labeldw incadw incbdw incbcdw inccdw incddw incdedw incedw inchdw inchldw incixdw inciydw incldw incmdw incspdw incxdw incxhdw incxldw incyhdw incyldw ld161dw ld162dw ld163dw ld164dw ld165dw ld166dw ld167dw ld168dw ld16imdw ld16ixdw ld8bddw ld8imdw ld8imxdw ld8ix1dw ld8ix2dw ld8ix3dw ld8ixydw ld8rrdw ld8rrxdw ldadw ldd1dw ldd2dw ldi1dw ldi2dw negop ; jgh: can't use opcode as labeldw rldop ; jgh: can't use opcode as labeldw rot8080dw rotxydw rotz80dw srz80dw srzxdw st8ix1dw st8ix2dw st8ix3dw stabddw 0; jgh: macro syntax changed for ZMAC and MAXAM; can't use opcodes as labels; ZMAC allows &nn as hex, so & removed from local labels;tstr macro insn1,insn2,insn3,insn4,memop,riy,rix,rhl,rde,rbc,flags,acc,rsp,?lab?lab: db insn1,insn2,insn3,insn4dw memop,riy,rix,rhl,rde,rbcdb flagsdb accdw rspif $-?lab ne 20error 'missing parameter'endifendmtmsg macro msg,?lab?lab: db 'msg'if $ ge ?lab+31error 'message too long'else; ds ?lab+30-$,'.' ; jgh: ZMAC/MAXAM don't have char parameterendifdb '$'endm; jgh: ZMAC/MAXAM don't recognise <n,m> syntax for macros, so full parameters given; jgh: each tmsg has full string, as ZMAC/MAXAM don't have ds n,c pseudo-op; <adc,sbc> hl,<bc,de,hl,sp> (38,912 cycles)adc16: db 0ffh ; flag masktstr 0edh,042h,0,0,0832ch,04f88h,0f22bh,0b339h,07e1fh,01563h,0d3h,089h,0465ehtstr 0,038h,0,0,0,0,0,0f821h,0,0,0,0,0 ; (1024 cycles)tstr 0,0,0,0,0,0,0,-1,-1,-1,0d7h,0,-1 ; (38 cycles)db 0d4h,08ah,0d5h,019h ; expected crctmsg '<adc,sbc> hl,<bc,de,hl,sp>....'; add hl,<bc,de,hl,sp> (19,456 cycles)add16: db 0ffh ; flag masktstr 9,0,0,0,0c4a5h,0c4c7h,0d226h,0a050h,058eah,08566h,0c6h,0deh,09bc9htstr 030h,0,0,0,0,0,0,0f821h,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,-1,-1,-1,0d7h,0,-1 ; (38 cycles)db 0d9h,0a4h,0cah,005h ; expected crctmsg 'add hl,<bc,de,hl,sp>..........'; add ix,<bc,de,ix,sp> (19,456 cycles)add16x: db 0ffh ; flag masktstr 0ddh,9,0,0,0ddach,0c294h,0635bh,033d3h,06a76h,0fa20h,094h,068h,036f5htstr 0,030h,0,0,0,0,0f821h,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,-1,0,-1,-1,0d7h,0,-1 ; (38 cycles)db 0b1h,0dfh,08eh,0c0h ; expected crctmsg 'add ix,<bc,de,ix,sp>..........'; add iy,<bc,de,iy,sp> (19,456 cycles)add16y: db 0ffh ; flag masktstr 0fdh,9,0,0,0c7c2h,0f407h,051c1h,03e96h,00bf4h,0510fh,092h,01eh,071eahtstr 0,030h,0,0,0,0f821h,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,-1,0,0,-1,-1,0d7h,0,-1 ; (38 cycles)db 039h,0c8h,058h,09bh ; expected crctmsg 'add iy,<bc,de,iy,sp>..........'; aluop a,nn (28,672 cycles)alu8i: db 0ffh ; flag masktstr 0c6h,0,0,0,009140h,07e3ch,07a67h,0df6dh,05b61h,00b29h,010h,066h,085b2htstr 038h,0,0,0,0,0,0,0,0,0,0,-1,0 ; (2048 cycles)tstr 0,-1,0,0,0,0,0,0,0,0,0d7h,0,0 ; (14 cycles)db 051h,0c1h,09ch,02eh ; expected crctmsg 'aluop a,nn....................'; aluop a,<b,c,d,e,h,l,(hl),a> (753,664 cycles)alu8r: db 0ffh ; flag masktstr 080h,0,0,0,0c53eh,0573ah,04c4dh,msbt,0e309h,0a666h,0d0h,03bh,0adbbhtstr 03fh,0,0,0,0,0,0,0,0,0,0,-1,0 ; (16,384 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,0d7h,0,0 ; (46 cycles)db 006h,0c7h,0aah,08eh ; expected crctmsg 'aluop a,<b,c,d,e,h,l,(hl),a>..'; aluop a,<ixh,ixl,iyh,iyl> (376,832 cycles)alu8rx: db 0ffh ; flag masktstr 0ddh,084h,0,0,0d6f7h,0c76eh,0accfh,02847h,022ddh,0c035h,0c5h,038h,0234bhtstr 020h,039h,0,0,0,0,0,0,0,0,0,-1,0 ; (8,192 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,0d7h,0,0 ; (46 cycles)db 0a8h,086h,0cch,044h ; expected crctmsg 'aluop a,<ixh,ixl,iyh,iyl>.....'; aluop a,(<ix,iy>+1) (229,376 cycles)alu8x: db 0ffh ; flag masktstr 0ddh,086h,1,0,090b7h,msbt-1,msbt-1,032fdh,0406eh,0c1dch,045h,06eh,0e5fahtstr 020h,038h,0,0,0,1,1,0,0,0,0,-1,0 ; (16,384 cycles)tstr 0,0,0,0,0ffh,0,0,0,0,0,0d7h,0,0 ; (14 cycles)db 0d3h,0f2h,0d7h,04ah ; expected crctmsg 'aluop a,(<ix,iy>+1)...........'; bit n,(<ix,iy>+1) (2048 cycles)bitx: db 0ffh ; flag masktstr 0ddh,0cbh,1,046h,02075h,msbt-1,msbt-1,03cfch,0a79ah,03d74h,051h,027h,0ca14htstr 020h,0,0,038h,0,0,0,0,0,0,053h,0,0 ; (256 cycles)tstr 0,0,0,0,0ffh,0,0,0,0,0,0,0,0 ; (8 cycles)db 083h,053h,04eh,0e1h ; expected crctmsg 'bit n,(<ix,iy>+1).............'; bit n,<b,c,d,e,h,l,(hl),a> (49,152 cycles)bitz80: db 0ffh ; flag masktstr 0cbh,040h,0,0,03ef1h,09dfch,07acch,msbt,0be61h,07a86h,050h,024h,01998htstr 0,03fh,0,0,0,0,0,0,0,0,053h,0,0 ; (1024 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,0,-1,0 ; (48 cycles)db 05eh,002h,00eh,098h ; expected crctmsg 'bit n,<b,c,d,e,h,l,(hl),a>....'; cpd<r> (1) (6144 cycles)cpd1: db 0ffh ; flag masktstr 0edh,0a9h,0,0,0c7b6h,072b4h,018f6h,msbt+17,08dbdh,1,0c0h,030h,094a3htstr 0,010h,0,0,0,0,0,0,0,010,0,-1,0 ; (1024 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 013h,04bh,062h,02dh ; expected crctmsg 'cpd<r>........................'; cpi<r> (1) (6144 cycles)cpi1: db 0ffh ; flag masktstr 0edh,0a1h,0,0,04d48h,0af4ah,0906bh,msbt,04e71h,1,093h,06ah,0907chtstr 0,010h,0,0,0,0,0,0,0,010,0,-1,0 ; (1024 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 02dh,0a4h,02dh,019h ; expected crctmsg 'cpi<r>........................'; <daa,cpl,scf,ccf>daaop: db 0ffh ; flag masktstr 027h,0,0,0,02141h,009fah,01d60h,0a559h,08d5bh,09079h,004h,08eh,0299dhtstr 018h,0,0,0,0,0,0,0,0,0,0d7h,-1,0 ; (65,536 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0,0,0 ; (1 cycle)db 06dh,02dh,0d2h,013h ; expected crctmsg '<daa,cpl,scf,ccf>.............'; <inc,dec> a (3072 cycles)inca: db 0ffh ; flag masktstr 03ch,0,0,0,04adfh,0d5d8h,0e598h,08a2bh,0a7b0h,0431bh,044h,05ah,0d030htstr 001h,0,0,0,0,0,0,0,0,0,0,-1,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 081h,0fah,081h,000h ; expected crctmsg '<inc,dec> a...................'; <inc,dec> b (3072 cycles)incb: db 0ffh ; flag masktstr 004h,0,0,0,0d623h,0432dh,07a61h,08180h,05a86h,01e85h,086h,058h,09bbbhtstr 001h,0,0,0,0,0,0,0,0,0ff00h,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 077h,0f3h,05ah,073h ; expected crctmsg '<inc,dec> b...................'; <inc,dec> bc (1536 cycles)incbc: db 0ffh ; flag masktstr 003h,0,0,0,0cd97h,044abh,08dc9h,0e3e3h,011cch,0e8a4h,002h,049h,02a4dhtstr 008h,0,0,0,0,0,0,0,0,0f821h,0,0,0 ; (256 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0d2h,0aeh,03bh,0ech ; expected crctmsg '<inc,dec> bc..................'; <inc,dec> c (3072 cycles)incc: db 0ffh ; flag masktstr 00ch,0,0,0,0d789h,00935h,0055bh,09f85h,08b27h,0d208h,095h,005h,00660htstr 001h,0,0,0,0,0,0,0,0,0ffh,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 01ah,0f6h,012h,0a7h ; expected crctmsg '<inc,dec> c...................'; <inc,dec> d (3072 cycles)incd: db 0ffh ; flag masktstr 014h,0,0,0,0a0eah,05fbah,065fbh,0981ch,038cch,0debch,043h,05ch,003bdhtstr 001h,0,0,0,0,0,0,0,0ff00h,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0d1h,046h,0bfh,051h ; expected crctmsg '<inc,dec> d...................'; <inc,dec> de (1536 cycles)incde: db 0ffh ; flag masktstr 013h,0,0,0,0342eh,0131dh,028c9h,00acah,09967h,03a2eh,092h,0f6h,09d54htstr 008h,0,0,0,0,0,0,0,0f821h,0,0,0,0 ; (256 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0aeh,0c6h,0d4h,02ch ; expected crctmsg '<inc,dec> de..................'; <inc,dec> e (3072 cycles)ince: db 0ffh ; flag masktstr 01ch,0,0,0,0602fh,04c0dh,02402h,0e2f5h,0a0f4h,0a10ah,013h,032h,05925htstr 001h,0,0,0,0,0,0,0,0ffh,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0cah,08ch,06ah,0c2h ; expected crctmsg '<inc,dec> e...................'; <inc,dec> h (3072 cycles)inch: db 0ffh ; flag masktstr 024h,0,0,0,01506h,0f2ebh,0e8ddh,0262bh,011a6h,0bc1ah,017h,006h,02818htstr 001h,0,0,0,0,0,0,0ff00h,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 056h,00fh,095h,05eh ; expected crctmsg '<inc,dec> h...................'; <inc,dec> hl (1536 cycles)inchl: db 0ffh ; flag masktstr 023h,0,0,0,0c3f4h,007a5h,01b6dh,04f04h,0e2c2h,0822ah,057h,0e0h,0c3e1htstr 008h,0,0,0,0,0,0,0f821h,0,0,0,0,0 ; (256 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0fch,00dh,06dh,04ah ; expected crctmsg '<inc,dec> hl..................'; <inc,dec> ix (1536 cycles)incix: db 0ffh ; flag masktstr 0ddh,023h,0,0,0bc3ch,00d9bh,0e081h,0adfdh,09a7fh,096e5h,013h,085h,00be2htstr 0,8,0,0,0,0,0f821h,0,0,0,0,0,0 ; (256 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0a5h,04dh,0beh,031h ; expected crctmsg '<inc,dec> ix..................'; <inc,dec> iy (1536 cycles)inciy: db 0ffh ; flag masktstr 0fdh,023h,0,0,09402h,0637ah,03182h,0c65ah,0b2e9h,0abb4h,016h,0f2h,06d05htstr 0,8,0,0,0,0f821h,0,0,0,0,0,0,0 ; (256 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 050h,05dh,051h,0a3h ; expected crctmsg '<inc,dec> iy..................'; <inc,dec> l (3072 cycles)incl: db 0ffh ; flag masktstr 02ch,0,0,0,08031h,0a520h,04356h,0b409h,0f4c1h,0dfa2h,0d1h,03ch,03ea2htstr 001h,0,0,0,0,0,0,0ffh,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 0a0h,0a1h,0b4h,09fh ; expected crctmsg '<inc,dec> l...................'; <inc,dec> (hl) (3072 cycles)incm: db 0ffh ; flag masktstr 034h,0,0,0,0b856h,00c7ch,0e53eh,msbt,0877eh,0da58h,015h,05ch,01f37htstr 001h,0,0,0,0ffh,0,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 028h,029h,05eh,0ceh ; expected crctmsg '<inc,dec> (hl)................'; <inc,dec> sp (1536 cycles)incsp: db 0ffh ; flag masktstr 033h,0,0,0,0346fh,0d482h,0d169h,0deb6h,0a494h,0f476h,053h,002h,0855bhtstr 008h,0,0,0,0,0,0,0,0,0,0,0,0f821h ; (256 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 05dh,0ach,0d5h,027h ; expected crctmsg '<inc,dec> sp..................'; <inc,dec> (<ix,iy>+1) (6144 cycles)incx: db 0ffh ; flag masktstr 0ddh,034h,1,0,0fa6eh,msbt-1,msbt-1,02c28h,08894h,05057h,016h,033h,0286fhtstr 020h,1,0,0,0ffh,0,0,0,0,0,0,0,0 ; (1024 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 00bh,095h,0a8h,0eah ; expected crctmsg '<inc,dec> (<ix,iy>+1).........'; <inc,dec> ixh (3072 cycles)incxh: db 0ffh ; flag masktstr 0ddh,024h,0,0,0b838h,0316ch,0c6d4h,03e01h,08358h,015b4h,081h,0deh,04259htstr 0,1,0,0,0,0ff00h,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 06fh,046h,036h,062h ; expected crctmsg '<inc,dec> ixh.................'; <inc,dec> ixl (3072 cycles)incxl: db 0ffh ; flag masktstr 0ddh,02ch,0,0,04d14h,07460h,076d4h,006e7h,032a2h,0213ch,0d6h,0d7h,099a5htstr 0,1,0,0,0,0ffh,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 002h,07bh,0efh,02ch ; expected crctmsg '<inc,dec> ixl.................'; <inc,dec> iyh (3072 cycles)incyh: db 0ffh ; flag masktstr 0ddh,024h,0,0,02836h,09f6fh,09116h,061b9h,082cbh,0e219h,092h,073h,0a98chtstr 0,1,0,0,0ff00h,0,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 02dh,096h,06ch,0f3h ; expected crctmsg '<inc,dec> iyh.................'; <inc,dec> iyl (3072 cycles)incyl: db 0ffh ; flag masktstr 0ddh,02ch,0,0,0d7c6h,062d5h,0a09eh,07039h,03e7eh,09f12h,090h,0d9h,0220fhtstr 0,1,0,0,0ffh,0,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 036h,0c1h,01eh,075h ; expected crctmsg '<inc,dec> iyl.................'; ld <bc,de>,(nnnn) (32 cycles)ld161: db 0ffh ; flag masktstr 0edh,04bh,msbtlo,msbthi,0f9a8h,0f559h,093a4h,0f5edh,06f96h,0d968h,086h,0e6h,04bd8htstr 0,010h,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 04dh,045h,0a9h,0ach ; expected crctmsg 'ld <bc,de>,(nnnn).............'; ld hl,(nnnn) (16 cycles)ld162: db 0ffh ; flag masktstr 02ah,msbtlo,msbthi,0,09863h,07830h,02077h,0b1feh,0b9fah,0abb8h,004h,006h,06015htstr 0,0,0,0,0,0,0,0,0,0,0,0,0 ; (1 cycle)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 05fh,097h,024h,087h ; expected crctmsg 'ld hl,(nnnn)..................'; ld sp,(nnnn) (16 cycles)ld163: db 0ffh ; flag masktstr 0edh,07bh,msbtlo,msbthi,08dfch,057d7h,02161h,0ca18h,0c185h,027dah,083h,01eh,0f460htstr 0,0,0,0,0,0,0,0,0,0,0,0,0 ; (1 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 07ah,0ceh,0a1h,01bh ; expected crctmsg 'ld sp,(nnnn)..................'; ld <ix,iy>,(nnnn) (32 cycles)ld164: db 0ffh ; flag masktstr 0ddh,02ah,msbtlo,msbthi,0ded7h,0a6fah,0f780h,0244ch,087deh,0bcc2h,016h,063h,04c96htstr 020h,0,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 085h,08bh,0f1h,06dh ; expected crctmsg 'ld <ix,iy>,(nnnn).............'; ld (nnnn),<bc,de> (64 cycles)ld165: db 0ffh ; flag masktstr 0edh,043h,msbtlo,msbthi,01f98h,0844dh,0e8ach,0c9edh,0c95dh,08f61h,080h,03fh,0c7bfhtstr 0,010h,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,0,0,0,0,-1,-1,0,0,0 ; (32 cycles)db 064h,01eh,087h,015h ; expected crctmsg 'ld (nnnn),<bc,de>.............'; ld (nnnn),hl (16 cycles)ld166: db 0ffh ; flag masktstr 022h,msbtlo,msbthi,0,0d003h,07772h,07f53h,03f72h,064eah,0e180h,010h,02dh,035e9htstr 0,0,0,0,0,0,0,0,0,0,0,0,0 ; (1 cycle)tstr 0,0,0,0,0,0,0,-1,0,0,0,0,0 ; (16 cycles)db 0a3h,060h,08bh,047h ; expected crctmsg 'ld (nnnn),hl..................'; ld (nnnn),sp (16 cycles)ld167: db 0ffh ; flag masktstr 0edh,073h,msbtlo,msbthi,0c0dch,0d1d6h,0ed5ah,0f356h,0afdah,06ca7h,044h,09fh,03f0ahtstr 0,0,0,0,0,0,0,0,0,0,0,0,0 ; (1 cycle)tstr 0,0,0,0,0,0,0,0,0,0,0,0,-1 ; (16 cycles)db 016h,058h,05fh,0d7h ; expected crctmsg 'ld (nnnn),sp..................'; ld (nnnn),<ix,iy> (64 cycles)ld168: db 0ffh ; flag masktstr 0ddh,022h,msbtlo,msbthi,06cc3h,00d91h,06900h,08ef8h,0e3d6h,0c3f7h,0c6h,0d9h,0c2dfhtstr 020h,0,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,0,-1,-1,0,0,0,0,0,0 ; (32 cycles)db 0bah,010h,02ah,06bh ; expected crctmsg 'ld (nnnn),<ix,iy>.............'; ld <bc,de,hl,sp>,nnnn (64 cycles)ld16im: db 0ffh ; flag masktstr 1,0,0,0,05c1ch,02d46h,08eb9h,06078h,074b1h,0b30eh,046h,0d1h,030cchtstr 030h,0,0,0,0,0,0,0,0,0,0,0,0 ; (4 cycles)tstr 0,0ffh,0ffh,0,0,0,0,0,0,0,0,0,0 ; (16 cycles)db 0deh,039h,019h,069h ; expected crctmsg 'ld <bc,de,hl,sp>,nnnn.........'; ld <ix,iy>,nnnn (32 cycles)ld16ix: db 0ffh ; flag masktstr 0ddh,021h,0,0,087e8h,02006h,0bd12h,0b69bh,07253h,0a1e5h,051h,013h,0f1bdhtstr 020h,0,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0ffh,0ffh,0,0,0,0,0,0,0,0,0 ; (16 cycles)db 022h,07dh,0d5h,025h ; expected crctmsg 'ld <ix,iy>,nnnn...............'; ld a,<(bc),(de)> (44 cycles)ld8bd: db 0ffh ; flag masktstr 00ah,0,0,0,0b3a8h,01d2ah,07f8eh,042ach,msbt,msbt,0c6h,0b1h,0ef8ehtstr 010h,0,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,0ffh,0,0,0,0,0,0d7h,-1,0 ; (22 cycles)db 0b0h,081h,089h,035h ; expected crctmsg 'ld a,<(bc),(de)>..............'; ld <b,c,d,e,h,l,(hl),a>,nn (64 cycles)ld8im: db 0ffh ; flag masktstr 6,0,0,0,0c407h,0f49dh,0d13dh,00339h,0de89h,07455h,053h,0c0h,05509htstr 038h,0,0,0,0,0,0,0,0,0,0,0,0 ; (8 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0,-1,0 ; (8 cycles)db 0f1h,0dah,0b5h,056h ; expected crctmsg 'ld <b,c,d,e,h,l,(hl),a>,nn....'; ld (<ix,iy>+1),nn (32 cycles)ld8imx: db 0ffh ; flag masktstr 0ddh,036h,1,0,01b45h,msbt-1,msbt-1,0d5c1h,061c7h,0bdc4h,0c0h,085h,0cd16htstr 020h,0,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,-1,0,0,0,0,0,0,0,-1,0 ; (16 cycles)db 026h,0dbh,047h,07eh ; expected crctmsg 'ld (<ix,iy>+1),nn.............'; ld <b,c,d,e>,(<ix,iy>+1) (512 cycles)ld8ix1: db 0ffh ; flag masktstr 0ddh,046h,1,0,0d016h,msbt-1,msbt-1,04260h,07f39h,00404h,097h,04ah,0d085htstr 020h,018h,0,0,0,1,1,0,0,0,0,0,0 ; (32 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 0cch,011h,006h,0a8h ; expected crctmsg 'ld <b,c,d,e>,(<ix,iy>+1)......'; ld <h,l>,(<ix,iy>+1) (256 cycles)ld8ix2: db 0ffh ; flag masktstr 0ddh,066h,1,0,084e0h,msbt-1,msbt-1,09c52h,0a799h,049b6h,093h,000h,0eeadhtstr 020h,008h,0,0,0,1,1,0,0,0,0,0,0 ; (16 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 0fah,02ah,04dh,003h ; expected crctmsg 'ld <h,l>,(<ix,iy>+1)..........'; ld a,(<ix,iy>+1) (128 cycles)ld8ix3: db 0ffh ; flag masktstr 0ddh,07eh,1,0,0d8b6h,msbt-1,msbt-1,0c612h,0df07h,09cd0h,043h,0a6h,0a0e5htstr 020h,0,0,0,0,1,1,0,0,0,0,0,0 ; (8 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,0,0 ; (16 cycles)db 0a5h,0e9h,0ach,064h ; expected crctmsg 'ld a,(<ix,iy>+1)..............'; ld <ixh,ixl,iyh,iyl>,nn (32 cycles)ld8ixy: db 0ffh ; flag masktstr 0ddh,026h,0,0,03c53h,04640h,0e179h,07711h,0c107h,01afah,081h,0adh,05d9bhtstr 020h,8,0,0,0,0,0,0,0,0,0,0,0 ; (4 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0,-1,0 ; (8 cycles)db 024h,0e8h,082h,08bh ; expected crctmsg 'ld <ixh,ixl,iyh,iyl>,nn.......'; ld <b,c,d,e,h,l,a>,<b,c,d,e,h,l,a> (3456 cycles)ld8rr: db 0ffh ; flag masktstr 040h,0,0,0,072a4h,0a024h,061ach,msbt,082c7h,0718fh,097h,08fh,0ef8ehtstr 03fh,0,0,0,0,0,0,0,0,0,0,0,0 ; (64 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,0d7h,-1,0 ; (54 cycles)db 074h,04bh,001h,018h ; expected crctmsg 'ld <bcdehla>,<bcdehla>........'; ld <b,c,d,e,ixy,a>,<b,c,d,e,ixy,a> (6912 cycles)ld8rrx: db 0ffh ; flag masktstr 0ddh,040h,0,0,0bcc5h,msbt,msbt,msbt,02fc2h,098c0h,083h,01fh,03bcdhtstr 020h,03fh,0,0,0,0,0,0,0,0,0,0,0 ; (128 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,0d7h,-1,0 ; (54 cycles)db 047h,08bh,0a3h,06bh ; expected crctmsg 'ld <bcdexya>,<bcdexya>........'; ld a,(nnnn) / ld (nnnn),a (44 cycles)lda: db 0ffh ; flag masktstr 032h,msbtlo,msbthi,0,0fd68h,0f4ech,044a0h,0b543h,00653h,0cdbah,0d2h,04fh,01fd8htstr 008h,0,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycle)tstr 0,0,0,0,0ffh,0,0,0,0,0,0d7h,-1,0 ; (22 cycles)db 0c9h,026h,02dh,0e5h ; expected crctmsg 'ld a,(nnnn) / ld (nnnn),a.....'; ldd<r> (1) (44 cycles)ldd1: db 0ffh ; flag masktstr 0edh,0a8h,0,0,09852h,068fah,066a1h,msbt+3,msbt+1,1,0c1h,068h,020b7htstr 0,010h,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0d7h,0,0 ; (22 cycles)db 094h,0f4h,027h,069h ; expected crctmsg 'ldd<r> (1)....................'; ldd<r> (2) (44 cycles)ldd2: db 0ffh ; flag masktstr 0edh,0a8h,0,0,0f12eh,0eb2ah,0d5bah,msbt+3,msbt+1,2,047h,0ffh,0fbe4htstr 0,010h,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0d7h,0,0 ; (22 cycles)db 039h,0ddh,03dh,0e1h ; expected crctmsg 'ldd<r> (2)....................'; ldi<r> (1) (44 cycles)ldi1: db 0ffh ; flag masktstr 0edh,0a0h,0,0,0fe30h,003cdh,06058h,msbt+2,msbt,1,004h,060h,02688htstr 0,010h,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0d7h,0,0 ; (22 cycles)db 0f7h,082h,0b0h,0d1h ; expected crctmsg 'ldi<r> (1)....................'; ldi<r> (2) (44 cycles)ldi2: db 0ffh ; flag masktstr 0edh,0a0h,0,0,04aceh,0c26eh,0b188h,msbt+2,msbt,2,014h,02dh,0a39fhtstr 0,010h,0,0,0,0,0,0,0,0,0,0,0 ; (2 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0d7h,0,0 ; (22 cycles)db 0e9h,0eah,0d0h,0aeh ; expected crctmsg 'ldi<r> (2)....................'; neg (16,384 cycles)negop: db 0ffh ; flag masktstr 0edh,044h,0,0,038a2h,05f6bh,0d934h,057e4h,0d2d6h,04642h,043h,05ah,009cchtstr 0,0,0,0,0,0,0,0,0,0,0d7h,-1,0 ; (16,384 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0,0,0 ; (1 cycle)db 0d6h,038h,0ddh,06ah ; expected crctmsg 'neg...........................'; <rld,rrd> (7168 cycles)rldop: db 0ffh ; flag masktstr 0edh,067h,0,0,091cbh,0c48bh,0fa62h,msbt,0e720h,0b479h,040h,006h,08ae2htstr 0,8,0,0,0ffh,0,0,0,0,0,0,0,0 ; (512 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,-1,0 ; (14 cycles)db 0ffh,082h,03eh,077h ; expected crctmsg '<rrd,rld>.....................'; <rlca,rrca,rla,rra> (6144 cycles)rot8080: db 0ffh ; flag masktstr 7,0,0,0,0cb92h,06d43h,00a90h,0c284h,00c53h,0f50eh,091h,0ebh,040fchtstr 018h,0,0,0,0,0,0,0,0,0,0,-1,0 ; (1024 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0d7h,0,0 ; (6 cycles)db 09bh,0a3h,080h,07ch ; expected crctmsg '<rlca,rrca,rla,rra>...........'; shift/rotate (<ix,iy>+1) (416 cycles)rotxy: db 0ffh ; flag masktstr 0ddh,0cbh,1,6,0ddafh,msbt-1,msbt-1,0ff3ch,0dbf6h,094f4h,082h,080h,061d9htstr 020h,0,0,038h,0,0,0,0,0,0,080h,0,0 ; (32 cycles)tstr 0,0,0,0,0ffh,0,0,0,0,0,057h,0,0 ; (13 cycles)db 071h,000h,034h,0cbh ; expected crctmsg 'shf/rot (<ix,iy>+1)...........'; shift/rotate <b,c,d,e,h,l,(hl),a> (6784 cycles)rotz80: db 0ffh ; flag masktstr 0cbh,0,0,0,0ccebh,05d4ah,0e007h,msbt,01395h,030eeh,043h,078h,03dadhtstr 0,03fh,0,0,0,0,0,0,0,0,080h,0,0 ; (128 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,057h,-1,0 ; (53 cycles)db 0a4h,025h,058h,033h ; expected crctmsg 'shf/rot <b,c,d,e,h,l,(hl),a>..'; <set,res> n,<b,c,d,e,h,l,(hl),a> (7936 cycles)srz80: db 0ffh ; flag masktstr 0cbh,080h,0,0,02cd5h,097abh,039ffh,msbt,0d14bh,06ab2h,053h,027h,0b538htstr 0,07fh,0,0,0,0,0,0,0,0,0,0,0 ; (128 cycles)tstr 0,0,0,0,0ffh,0,0,0,-1,-1,0d7h,-1,0 ; (62 cycles)db 08bh,057h,0f0h,008h ; expected crctmsg '<set,res> n,<bcdehl(hl)a>.....'; <set,res> n,(<ix,iy>+1) (1792 cycles)srzx: db 0ffh ; flag masktstr 0ddh,0cbh,1,086h,0fb44h,msbt-1,msbt-1,0ba09h,068beh,032d8h,010h,05eh,0a867htstr 020h,0,0,078h,0,0,0,0,0,0,0,0,0 ; (128 cycles)tstr 0,0,0,0,0ffh,0,0,0,0,0,0d7h,0,0 ;(14 cycles)db 0cch,063h,0f9h,08ah ; expected crctmsg '<set,res> n,(<ix,iy>+1).......'; ld (<ix,iy>+1),<b,c,d,e> (1024 cycles)st8ix1: db 0ffh ; flag masktstr 0ddh,070h,1,0,0270dh,msbt-1,msbt-1,0b73ah,0887bh,099eeh,086h,070h,0ca07htstr 020h,003h,0,0,0,1,1,0,0,0,0,0,0 ; (32 cycles)tstr 0,0,0,0,0,0,0,0,-1,-1,0,0,0 ; (32 cycles)db 004h,062h,06ah,0bfh ; expected crctmsg 'ld (<ix,iy>+1),<b,c,d,e>......'; ld (<ix,iy>+1),<h,l> (256 cycles)st8ix2: db 0ffh ; flag masktstr 0ddh,074h,1,0,0b664h,msbt-1,msbt-1,0e8ach,0b5f5h,0aafeh,012h,010h,09566htstr 020h,001h,0,0,0,1,1,0,0,0,0,0,0 ; (16 cycles)tstr 0,0,0,0,0,0,0,-1,0,0,0,0,0 ; (32 cycles)db 06ah,01ah,088h,031h ; expected crctmsg 'ld (<ix,iy>+1),<h,l>..........'; ld (<ix,iy>+1),a (64 cycles)st8ix3: db 0ffh ; flag masktstr 0ddh,077h,1,0,067afh,msbt-1,msbt-1,04f13h,00644h,0bcd7h,050h,0ach,05fafhtstr 020h,0,0,0,0,1,1,0,0,0,0,0,0 ; (8 cycles)tstr 0,0,0,0,0,0,0,0,0,0,0,-1,0 ; (8 cycles)db 0cch,0beh,05ah,096h ; expected crctmsg 'ld (<ix,iy>+1),a..............'; ld (<bc,de>),a (96 cycles)stabd: db 0ffh ; flag masktstr 2,0,0,0,00c3bh,0b592h,06cffh,0959eh,msbt,msbt+1,0c1h,021h,0bde7htstr 018h,0,0,0,0,0,0,0,0,0,0,0,0 ; (4 cycles)tstr 0,0,0,0,-1,0,0,0,0,0,0,-1,0 ; (24 cycles)db 07ah,04ch,011h,04fh ; expected crctmsg 'ld (<bc,de>),a................'; start test pointed to by (hl)stt: push hlld a,(hl) ; get pointer to testinc hlld h,(hl)ld l,ald a,(hl) ; flag maskld (flgmsk+1),ainc hlpush hlld de,20add hl,de ; point to incmaskld de,countercall initmaskpop hlpush hlld de,20+20add hl,de ; point to scanmaskld de,shiftercall initmaskld hl,shifterld (hl),1 ; first bitpop hlpush hlld de,iut ; copy initial instruction under testld bc,4ldirld de,msbt ; copy initial machine stateld bc,16ldirld de,20+20+4 ; skip incmask, scanmask and expcrcadd hl,deex de,hlld c,9call bdos ; show test namecall initcrc ; initialise crc; test looptlp: ld a,(iut)cp 076h ; pragmatically avoid halt intructionsjp z,tlp2and a,0dfhcp 0ddhjp nz,tlp1ld a,(iut+1)cp 076htlp1: call nz,test ; execute the test instructiontlp2: call count ; increment the countercall nz,shift ; shift the scan bitpop hl ; pointer to test casejp z,tlp3 ; done if shift returned NZld de,20+20+20add hl,de ; point to expected crccall cmpcrcld de,okmsgjp z,tlpokld de,ermsg1ld c,9call bdoscall phex8ld de,ermsg2ld c,9call bdosld hl,crcvalcall phex8ld de,crlftlpok: ld c,9call bdospop hlinc hlinc hlrettlp3: push hlld a,1 ; initialise count and shift scannersld (cntbit),ald (shfbit),ald hl,counterld (cntbyt),hlld hl,shifterld (shfbyt),hlld b,4 ; bytes in iut fieldpop hl ; pointer to test casepush hlld de,iutcall setup ; setup iutld b,16 ; bytes in machine stateld de,msbtcall setup ; setup machine statejp tlp; setup a field of the test case; b = number of bytes; hl = pointer to base case; de = destinationsetup: call subyteinc hldec bjp nz,setupretsubyte: push bcpush depush hlld c,(hl) ; get base byteld de,20add hl,de ; point to incmaskld a,(hl)cp 0jp z,subshfld b,8 ; 8 bitssubclp: rrcapush afld a,0call c,nxtcbit ; get next counter bit if mask bit was setxor c ; flip bit if counter bit was setrrcald c,apop afdec bjp nz,subclpld b,8subshf: ld de,20add hl,de ; point to shift maskld a,(hl)cp 0jp z,substrld b,8 ; 8 bitssbshf1: rrcapush afld a,0call c,nxtsbit ; get next shifter bit if mask bit was setxor c ; flip bit if shifter bit was setrrcald c,apop afdec bjp nz,sbshf1substr: pop hlpop deld a,cld (de),a ; mangled byte to destinationinc depop bcret; get next counter bit in low bit of acntbit: ds 1cntbyt: ds 2nxtcbit: push bcpush hlld hl,(cntbyt)ld b,(hl)ld hl,cntbitld a,(hl)ld c,arlcald (hl),acp a,1jp nz,ncb1ld hl,(cntbyt)inc hlld (cntbyt),hlncb1: ld a,band cpop hlpop bcret zld a,1ret; get next shifter bit in low bit of ashfbit: ds 1shfbyt: ds 2nxtsbit: push bcpush hlld hl,(shfbyt)ld b,(hl)ld hl,shfbitld a,(hl)ld c,arlcald (hl),acp a,1jp nz,nsb1ld hl,(shfbyt)inc hlld (shfbyt),hlnsb1: ld a,band cpop hlpop bcret zld a,1ret; clear memory at hl, bc bytesclrmem: push afpush bcpush depush hlld (hl),0ld d,hld e,linc dedec bcldirpop hlpop depop bcpop afret; initialise counter or shifter; de = pointer to work area for counter or shifter; hl = pointer to maskinitmask:push deex de,hlld bc,20+20call clrmem ; clear work areaex de,hlld b,20 ; byte counterld c,1 ; first bitld d,0 ; bit counterimlp: ld e,(hl)imlp1: ld a,eand a,cjp z,imlp2inc dimlp2: ld a,crlcald c,acp a,1jp nz,imlp1inc hldec bjp nz,imlp; got number of 1-bits in mask in reg dld a,dand 0f8hrrcarrcarrca ; divide by 8 (get byte offset)ld l,ald h,0ld a,dand a,7 ; bit offsetinc ald b,ald a,080himlp3: rlcadec bjp nz,imlp3pop deadd hl,deld de,20add hl,deld (hl),aret; multi-byte countercount: push bcpush depush hlld hl,counter ; 20 byte counter starts hereld de,20 ; somewhere in here is the stop bitex de,hladd hl,deex de,hlcntlp: inc (hl)ld a,(hl)cp 0jp z,cntlp1 ; overflow to next byteld b,ald a,(de)and a,b ; test for terminal valuejp z,cntendld (hl),0 ; reset to zerocntend: pop bcpop depop hlretcntlp1: inc hlinc dejp cntlp; multi-byte shiftershift: push bcpush depush hlld hl,shifter ; 20 byte shift register starts hereld de,20 ; somewhere in here is the stop bitex de,hladd hl,deex de,hlshflp: ld a,(hl)or ajp z,shflp1ld b,ald a,(de)and bjp nz,shlpeld a,brlcacp a,1jp nz,shflp2ld (hl),0inc hlinc deshflp2: ld (hl),axor a ; set Zshlpe: pop hlpop depop bcretshflp1: inc hlinc dejp shflpcounter: ds 2*20shifter: ds 2*20; test harnesstest: push afpush bcpush depush hlif 0ld de,crlfld c,9call bdosld hl,iutld b,4call hexstrld e,' 'ld c,2call bdosld b,16ld hl,msbtcall hexstrendifdi ; disable interruptsld (spsav),sp ; save stack pointerld sp,msbt+2 ; point to test-case machine statepop iy ; and load all regspop ixpop hlpop depop bcpop afld sp,(spbt)iut: ds 4 ; max 4 byte instruction under testld (spat),sp ; save stack pointerld sp,spatpush af ; save other registerspush bcpush depush hlpush ixpush iyld sp,(spsav) ; restore stack pointerei ; enable interruptsld hl,(msbt) ; copy memory operandld (msat),hlld hl,flgsat ; flags after testld a,(hl)flgmsk: and a,0d7h ; mask-out irrelevant bits (self-modified code!)ld (hl),ald b,16 ; total of 16 bytes of stateld de,msatld hl,crcvaltcrc: ld a,(de)inc decall updcrc ; accumulate crc of this test casedec bjp nz,tcrcif 0ld e,' 'ld c,2call bdosld hl,crcvalcall phex8ld de,crlfld c,9call bdosld hl,msatld b,16call hexstrld de,crlfld c,9call bdosendifpop hlpop depop bcpop afret; machine state after testmsat: ds 14 ; memop,iy,ix,hl,de,bc,afspat: ds 2 ; stack pointer after test; ZMAC/MAXAM doesn't like ':' after label with EQUsflgsat equ spat-2 ; flagsspsav: ds 2 ; saved stack pointer; display hex string (pointer in hl, byte count in b)hexstr: ld a,(hl)call phex2inc hldec bjp nz,hexstrret; display hex; display the big-endian 32-bit value pointed to by hlphex8: push afpush bcpush hlld b,4ph8lp: ld a,(hl)call phex2inc hldec bjp nz,ph8lppop hlpop bcpop afret; display byte in aphex2: push afrrcarrcarrcarrcacall phex1pop af; fall through; display low nibble in aphex1: push afpush bcpush depush hland a,0fhcp a,10jp c,ph11add a,'a'-'9'-1ph11: add a,'0'ld e,ald c,2call bdospop hlpop depop bcpop afretbdos push afpush bcpush depush hlcall 5pop hlpop depop bcpop afretmsg1: db 10,13,10,13,'Z80all instruction exerciser',10,13,'$'msg2: db 'Tests complete$'okmsg: db ' OK',10,13,'$'ermsg1: db ' ERROR **** crc expected:$'ermsg2: db ' found:$'crlf: db 10,13,'$'; compare crc; hl points to value to compare to crcvalcmpcrc: push bcpush depush hlld de,crcvalld b,4cclp: ld a,(de)cp a,(hl)jp nz,cceinc hlinc dedec bjp nz,cclpcce: pop hlpop depop bcret; 32-bit crc routine; entry: a contains next byte, hl points to crc; exit: crc updatedupdcrc: push afpush bcpush depush hlpush hlld de,3add hl,de ; point to low byte of old crcxor a,(hl) ; xor with new byteld l,ald h,0add hl,hl ; use result as index into table of 4 byte entriesadd hl,hlex de,hlld hl,crctabadd hl,de ; point to selected entry in crctabex de,hlpop hlld bc,4 ; c = byte count, b = accumulatorcrclp: ld a,(de)xor a,bld b,(hl)ld (hl),ainc deinc hldec cjp nz,crclpif 0ld hl,crcvalcall phex8ld de,crlfld c,9call bdosendifpop hlpop depop bcpop afretinitcrc:push afpush bcpush hlld hl,crcvalld a,0ffhld b,4icrclp: ld (hl),ainc hldec bjp nz,icrclppop hlpop bcpop afretcrcval ds 4crctab: db 000h,000h,000h,000hdb 077h,007h,030h,096hdb 0eeh,00eh,061h,02chdb 099h,009h,051h,0bahdb 007h,06dh,0c4h,019hdb 070h,06ah,0f4h,08fhdb 0e9h,063h,0a5h,035hdb 09eh,064h,095h,0a3hdb 00eh,0dbh,088h,032hdb 079h,0dch,0b8h,0a4hdb 0e0h,0d5h,0e9h,01ehdb 097h,0d2h,0d9h,088hdb 009h,0b6h,04ch,02bhdb 07eh,0b1h,07ch,0bdhdb 0e7h,0b8h,02dh,007hdb 090h,0bfh,01dh,091hdb 01dh,0b7h,010h,064hdb 06ah,0b0h,020h,0f2hdb 0f3h,0b9h,071h,048hdb 084h,0beh,041h,0dehdb 01ah,0dah,0d4h,07dhdb 06dh,0ddh,0e4h,0ebhdb 0f4h,0d4h,0b5h,051hdb 083h,0d3h,085h,0c7hdb 013h,06ch,098h,056hdb 064h,06bh,0a8h,0c0hdb 0fdh,062h,0f9h,07ahdb 08ah,065h,0c9h,0echdb 014h,001h,05ch,04fhdb 063h,006h,06ch,0d9hdb 0fah,00fh,03dh,063hdb 08dh,008h,00dh,0f5hdb 03bh,06eh,020h,0c8hdb 04ch,069h,010h,05ehdb 0d5h,060h,041h,0e4hdb 0a2h,067h,071h,072hdb 03ch,003h,0e4h,0d1hdb 04bh,004h,0d4h,047hdb 0d2h,00dh,085h,0fdhdb 0a5h,00ah,0b5h,06bhdb 035h,0b5h,0a8h,0fahdb 042h,0b2h,098h,06chdb 0dbh,0bbh,0c9h,0d6hdb 0ach,0bch,0f9h,040hdb 032h,0d8h,06ch,0e3hdb 045h,0dfh,05ch,075hdb 0dch,0d6h,00dh,0cfhdb 0abh,0d1h,03dh,059hdb 026h,0d9h,030h,0achdb 051h,0deh,000h,03ahdb 0c8h,0d7h,051h,080hdb 0bfh,0d0h,061h,016hdb 021h,0b4h,0f4h,0b5hdb 056h,0b3h,0c4h,023hdb 0cfh,0bah,095h,099hdb 0b8h,0bdh,0a5h,00fhdb 028h,002h,0b8h,09ehdb 05fh,005h,088h,008hdb 0c6h,00ch,0d9h,0b2hdb 0b1h,00bh,0e9h,024hdb 02fh,06fh,07ch,087hdb 058h,068h,04ch,011hdb 0c1h,061h,01dh,0abhdb 0b6h,066h,02dh,03dhdb 076h,0dch,041h,090hdb 001h,0dbh,071h,006hdb 098h,0d2h,020h,0bchdb 0efh,0d5h,010h,02ahdb 071h,0b1h,085h,089hdb 006h,0b6h,0b5h,01fhdb 09fh,0bfh,0e4h,0a5hdb 0e8h,0b8h,0d4h,033hdb 078h,007h,0c9h,0a2hdb 00fh,000h,0f9h,034hdb 096h,009h,0a8h,08ehdb 0e1h,00eh,098h,018hdb 07fh,06ah,00dh,0bbhdb 008h,06dh,03dh,02dhdb 091h,064h,06ch,097hdb 0e6h,063h,05ch,001hdb 06bh,06bh,051h,0f4hdb 01ch,06ch,061h,062hdb 085h,065h,030h,0d8hdb 0f2h,062h,000h,04ehdb 06ch,006h,095h,0edhdb 01bh,001h,0a5h,07bhdb 082h,008h,0f4h,0c1hdb 0f5h,00fh,0c4h,057hdb 065h,0b0h,0d9h,0c6hdb 012h,0b7h,0e9h,050hdb 08bh,0beh,0b8h,0eahdb 0fch,0b9h,088h,07chdb 062h,0ddh,01dh,0dfhdb 015h,0dah,02dh,049hdb 08ch,0d3h,07ch,0f3hdb 0fbh,0d4h,04ch,065hdb 04dh,0b2h,061h,058hdb 03ah,0b5h,051h,0cehdb 0a3h,0bch,000h,074hdb 0d4h,0bbh,030h,0e2hdb 04ah,0dfh,0a5h,041hdb 03dh,0d8h,095h,0d7hdb 0a4h,0d1h,0c4h,06dhdb 0d3h,0d6h,0f4h,0fbhdb 043h,069h,0e9h,06ahdb 034h,06eh,0d9h,0fchdb 0adh,067h,088h,046hdb 0dah,060h,0b8h,0d0hdb 044h,004h,02dh,073hdb 033h,003h,01dh,0e5hdb 0aah,00ah,04ch,05fhdb 0ddh,00dh,07ch,0c9hdb 050h,005h,071h,03chdb 027h,002h,041h,0aahdb 0beh,00bh,010h,010hdb 0c9h,00ch,020h,086hdb 057h,068h,0b5h,025hdb 020h,06fh,085h,0b3hdb 0b9h,066h,0d4h,009hdb 0ceh,061h,0e4h,09fhdb 05eh,0deh,0f9h,00ehdb 029h,0d9h,0c9h,098hdb 0b0h,0d0h,098h,022hdb 0c7h,0d7h,0a8h,0b4hdb 059h,0b3h,03dh,017hdb 02eh,0b4h,00dh,081hdb 0b7h,0bdh,05ch,03bhdb 0c0h,0bah,06ch,0adhdb 0edh,0b8h,083h,020hdb 09ah,0bfh,0b3h,0b6hdb 003h,0b6h,0e2h,00chdb 074h,0b1h,0d2h,09ahdb 0eah,0d5h,047h,039hdb 09dh,0d2h,077h,0afhdb 004h,0dbh,026h,015hdb 073h,0dch,016h,083hdb 0e3h,063h,00bh,012hdb 094h,064h,03bh,084hdb 00dh,06dh,06ah,03ehdb 07ah,06ah,05ah,0a8hdb 0e4h,00eh,0cfh,00bhdb 093h,009h,0ffh,09dhdb 00ah,000h,0aeh,027hdb 07dh,007h,09eh,0b1hdb 0f0h,00fh,093h,044hdb 087h,008h,0a3h,0d2hdb 01eh,001h,0f2h,068hdb 069h,006h,0c2h,0fehdb 0f7h,062h,057h,05dhdb 080h,065h,067h,0cbhdb 019h,06ch,036h,071hdb 06eh,06bh,006h,0e7hdb 0feh,0d4h,01bh,076hdb 089h,0d3h,02bh,0e0hdb 010h,0dah,07ah,05ahdb 067h,0ddh,04ah,0cchdb 0f9h,0b9h,0dfh,06fhdb 08eh,0beh,0efh,0f9hdb 017h,0b7h,0beh,043hdb 060h,0b0h,08eh,0d5hdb 0d6h,0d6h,0a3h,0e8hdb 0a1h,0d1h,093h,07ehdb 038h,0d8h,0c2h,0c4hdb 04fh,0dfh,0f2h,052hdb 0d1h,0bbh,067h,0f1hdb 0a6h,0bch,057h,067hdb 03fh,0b5h,006h,0ddhdb 048h,0b2h,036h,04bhdb 0d8h,00dh,02bh,0dahdb 0afh,00ah,01bh,04chdb 036h,003h,04ah,0f6hdb 041h,004h,07ah,060hdb 0dfh,060h,0efh,0c3hdb 0a8h,067h,0dfh,055hdb 031h,06eh,08eh,0efhdb 046h,069h,0beh,079hdb 0cbh,061h,0b3h,08chdb 0bch,066h,083h,01ahdb 025h,06fh,0d2h,0a0hdb 052h,068h,0e2h,036hdb 0cch,00ch,077h,095hdb 0bbh,00bh,047h,003hdb 022h,002h,016h,0b9hdb 055h,005h,026h,02fhdb 0c5h,0bah,03bh,0behdb 0b2h,0bdh,00bh,028hdb 02bh,0b4h,05ah,092hdb 05ch,0b3h,06ah,004hdb 0c2h,0d7h,0ffh,0a7hdb 0b5h,0d0h,0cfh,031hdb 02ch,0d9h,09eh,08bhdb 05bh,0deh,0aeh,01dhdb 09bh,064h,0c2h,0b0hdb 0ech,063h,0f2h,026hdb 075h,06ah,0a3h,09chdb 002h,06dh,093h,00ahdb 09ch,009h,006h,0a9hdb 0ebh,00eh,036h,03fhdb 072h,007h,067h,085hdb 005h,000h,057h,013hdb 095h,0bfh,04ah,082hdb 0e2h,0b8h,07ah,014hdb 07bh,0b1h,02bh,0aehdb 00ch,0b6h,01bh,038hdb 092h,0d2h,08eh,09bhdb 0e5h,0d5h,0beh,00dhdb 07ch,0dch,0efh,0b7hdb 00bh,0dbh,0dfh,021hdb 086h,0d3h,0d2h,0d4hdb 0f1h,0d4h,0e2h,042hdb 068h,0ddh,0b3h,0f8hdb 01fh,0dah,083h,06ehdb 081h,0beh,016h,0cdhdb 0f6h,0b9h,026h,05bhdb 06fh,0b0h,077h,0e1hdb 018h,0b7h,047h,077hdb 088h,008h,05ah,0e6hdb 0ffh,00fh,06ah,070hdb 066h,006h,03bh,0cahdb 011h,001h,00bh,05chdb 08fh,065h,09eh,0ffhdb 0f8h,062h,0aeh,069hdb 061h,06bh,0ffh,0d3hdb 016h,06ch,0cfh,045hdb 0a0h,00ah,0e2h,078hdb 0d7h,00dh,0d2h,0eehdb 04eh,004h,083h,054hdb 039h,003h,0b3h,0c2hdb 0a7h,067h,026h,061hdb 0d0h,060h,016h,0f7hdb 049h,069h,047h,04dhdb 03eh,06eh,077h,0dbhdb 0aeh,0d1h,06ah,04ahdb 0d9h,0d6h,05ah,0dchdb 040h,0dfh,00bh,066hdb 037h,0d8h,03bh,0f0hdb 0a9h,0bch,0aeh,053hdb 0deh,0bbh,09eh,0c5hdb 047h,0b2h,0cfh,07fhdb 030h,0b5h,0ffh,0e9hdb 0bdh,0bdh,0f2h,01chdb 0cah,0bah,0c2h,08ahdb 053h,0b3h,093h,030hdb 024h,0b4h,0a3h,0a6hdb 0bah,0d0h,036h,005hdb 0cdh,0d7h,006h,093hdb 054h,0deh,057h,029hdb 023h,0d9h,067h,0bfhdb 0b3h,066h,07ah,02ehdb 0c4h,061h,04ah,0b8hdb 05dh,068h,01bh,002hdb 02ah,06fh,02bh,094hdb 0b4h,00bh,0beh,037hdb 0c3h,00ch,08eh,0a1hdb 05ah,005h,0dfh,01bhdb 02dh,002h,0efh,08dh
