1 ; Z80 emulator with CP/M support. The Z80-specific instructions themselves actually aren't
2 ; implemented yet, making this more of an i8080 emulator.
4 ; Copyright (C) 2010 Sprite_tm
6 ; This program is free software: you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation, either version 3 of the License, or
9 ; (at your option) any later version.
11 ; This program is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
16 ; You should have received a copy of the GNU General Public License
17 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #elif defined atmega48
32 #define F_CPU 20000000 /* system clock in Hz; defaults to 20MHz */
35 #define BAUD 38400 /* console baud rate */
39 .equ UBRR_VAL = ((F_CPU+BAUD*8)/(BAUD*16)-1) ; clever rounding
41 #define REFR_RATE 64000 /* dram refresh rate. most drams need 1/15.6µs */
42 #define REFR_PRE 8 /* timer prescale factor */
43 #define REFR_CS 0x02 /* timer clock select for 1/8 */
44 #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE
47 #if defined __ATmega8__
48 .equ refr_vect = OC2addr
50 .equ refr_vect = OC2Aaddr
105 ;Register definitions
123 .def temp = R16 ;The temp register
124 .def temp2 = R17 ;Second temp register
139 ;Sector buffer for 512 byte reads/writes from/to SD-card
147 rjmp start ; reset vector
149 rjmp refrint ; tim2cmpa
151 .org INT_VECTORS_SIZE
153 ldi temp,low(RAMEND) ; top of memory
154 out SPL,temp ; init stack pointer
155 ldi temp,high(RAMEND) ; top of memory
156 out SPH,temp ; init stack pointer
160 #if defined __ATmega8__
164 ldi temp,(1<<WDCE) | (1<<WDE)
172 ldi temp,(1<<WDCE) | (1<<WDE)
194 #if defined __ATmega8__
195 ldi temp, (1<<TXEN) | (1<<RXEN)
197 ldi temp, (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)
199 ldi temp, HIGH(UBRR_VAL)
201 ldi temp, LOW(UBRR_VAL)
204 ldi temp, (1<<TXEN0) | (1<<RXEN0)
206 ldi temp, (1<<UCSZ01) | (1<<UCSZ00)
208 ldi temp, HIGH(UBRR_VAL)
210 ldi temp, LOW(UBRR_VAL)
214 ;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
219 ldi temp,(1<<WGM21) | REFR_CS ;CTC, clk/REFR_PRE
224 ldi temp,REFR_CNT ;=312 cycles
228 ldi temp, REFR_CS ;clk/REFR_PRE
252 .db "CPM on an AVR, v1.0",13,0,0
256 .db "Initing mmc...",13,0
262 .db "Testing RAM...",13,0
310 ;Fill ram with cbs, which (for now) will trigger an invalid opcode error.
325 ;Load initial sector from MMC (512 bytes)
330 ;Save to Z80 RAM (only 128 bytes because that's retro)
332 ldi zh,high(sectbuff)
346 cpi zl,low(sectbuff+128)
348 cpi zh,high(sectbuff+128)
361 .db 13,"Ok, CPU is live!",13,0,0
390 ; *** Stage 1: Fetch next opcode
414 ; *** Stage 2: Decode it using the ins_table.
416 ldi zl,low(inst_table*2)
417 ldi zh,high(inst_table*2)
439 ; *** Stage 3: Fetch operand. Use the fetch jumptable for this.
446 ldi zl,low(fetchjumps*2)
447 ldi zh,high(fetchjumps*2)
472 ; *** Stage 4: Execute operation :) Use the op jumptable for this.
478 ldi zl,low(opjumps*2)
479 ldi zh,high(opjumps*2)
502 ; *** Stage 5: Store operand. Use the store jumptable for this.
511 ldi zl,low(storejumps*2)
512 ldi zh,high(storejumps*2)
544 ; ----------------Virtual peripherial interface ------
546 ;The hw is modelled to make writing a CPM BIOS easier.
548 ;0 - Con status. Returns 0xFF if the UART has a byte, 0 otherwise.
549 ;1 - Console input, aka UDR.
555 ;22 - Trigger - write 1 to read, 2 to write a sector using the above info.
556 ; This will automatically move track, sector and dma addr to the next sector.
558 ;Called with port in temp2. Should return value in temp.
566 ;Called with port in temp2 and value in temp.
587 #if defined __ATmega8__
632 .db "Disk read: track ",0
650 ;First, convert track/sector to an LBA address (in 128byte blocks)
667 ;Now, see what has to be done.
675 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
680 ;Read 512-byte sector
684 ;Now, move the correct portion of the sector from AVR ram to Z80 ram
686 ldi zh,high(sectbuff)
714 brne dskDoItReadMemLoop
718 ;The write routines is a bit naive: it'll read the 512-byte sector the 128byte CPM-sector
719 ;resides in into memory, will overwrite the needed 128 byte with the Z80s memory buffer
720 ;and will then write it back to disk. In theory, this would mean that every 512 bytes
721 ;written will take 4 write cycles, while theoretically the writes could be deferred so we
722 ;would only have to do one write cycle.
727 .db "Disk write: track ",0
748 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
753 ;Read 512-byte sector
761 ;Copy the data from the Z80 DMA buffer in external memory to the right place in the
763 ;Now, move the correct portion of the sector from AVR ram to Z80 ram
765 ldi zh,high(sectbuff)
793 brne dskDoItWriteMemLoop
798 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
803 ;Write the sector back.
809 ; ----------------- MMC/SD routines ------------------
844 ;Wait till the mmc answers with the response in temp2, or till a timeout happens.
851 brne mmcWaitResploopEnd
864 .db ": Error: MMC resp timeout!",13,0
871 ;Init start: send 80 clocks with cs disabled
912 ldi temp,0xff ;return byte
922 ;Read OCR till card is ready
947 breq mmcInitOcrLoopDone
970 ;Call this with adrh:adrl = sector number
971 ;16bit lba address means a max reach of 32M.
978 ldi temp,0x51 ;cmd (read sector)
993 ldi temp,0xff ;return byte
1004 ;Read sector to AVR RAM
1005 ldi zl,low(sectbuff)
1006 ldi zh,high(sectbuff)
1010 cpi zl,low(sectbuff+512)
1012 cpi zh,high(sectbuff+512)
1027 ;Call this with adrh:adrl = sector number
1028 ;16bit lba address means a max reach of 32M.
1036 ldi temp,0x58 ;cmd (write sector)
1051 ldi temp,0xff ;return byte
1062 ;Write sector from AVR RAM
1063 ldi zl,low(sectbuff)
1064 ldi zh,high(sectbuff)
1068 cpi zl,low(sectbuff+512)
1070 cpi zh,high(sectbuff+512)
1077 ;Status. Ignored for now.
1080 ;Wait till the mmc has written everything
1094 ;Set up wdt to time out after 1 sec.
1097 #if defined __ATmega8__
1100 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)
1105 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)
1112 ; ------------------ DRAM routines -------------
1114 ;Sends the address in zh:zl to the ram
1162 ori temp2,(1<<ram_d1)
1164 ori temp2,(1<<ram_d2)
1166 ori temp2,(1<<ram_d3)
1168 ori temp2,(1<<ram_d4)
1175 ;Loads the byte on address adrh:adrl into temp.
1198 rcall dram_getnibble
1213 rcall dram_getnibble
1221 ;Writes the byte in temp to adrh:adrl
1229 rcall dram_sendnibble
1265 rcall dram_sendnibble
1317 ; --------------- Debugging stuff ---------------
1319 ;Prints the lower nibble of temp in hex to the uart
1335 ;Prints temp in hex to the uart
1343 ;Prints the zero-terminated string following the call statement. WARNING: Destroys temp.
1374 ; --------------- AVR HW <-> Z80 periph stuff ------------------
1376 .equ memReadByte = dram_read
1377 .equ memWriteByte = dram_write
1381 ;Fetches a char from the uart to temp. If none available, waits till one is.
1383 #if defined __ATmega8__
1395 ;Sends a char from temp to the uart.
1397 #if defined __ATmega8__
1413 ; ------------ Fetch phase stuff -----------------
1415 .equ FETCH_NOP = (0<<0)
1416 .equ FETCH_A = (1<<0)
1417 .equ FETCH_B = (2<<0)
1418 .equ FETCH_C = (3<<0)
1419 .equ FETCH_D = (4<<0)
1420 .equ FETCH_E = (5<<0)
1421 .equ FETCH_H = (6<<0)
1422 .equ FETCH_L = (7<<0)
1423 .equ FETCH_AF = (8<<0)
1424 .equ FETCH_BC = (9<<0)
1425 .equ FETCH_DE = (10<<0)
1426 .equ FETCH_HL = (11<<0)
1427 .equ FETCH_SP = (12<<0)
1428 .equ FETCH_MBC = (13<<0)
1429 .equ FETCH_MDE = (14<<0)
1430 .equ FETCH_MHL = (15<<0)
1431 .equ FETCH_MSP = (16<<0)
1432 .equ FETCH_DIR8 = (17<<0)
1433 .equ FETCH_DIR16= (18<<0)
1434 .equ FETCH_RST = (19<<0)
1437 ;Jump table for fetch routines. Make sure to keep this in sync with the .equs!
1494 rcall do_op_calcparity
1495 andi opl,~(1<<ZFL_P)
1589 ; ------------ Store phase stuff -----------------
1591 .equ STORE_NOP = (0<<5)
1592 .equ STORE_A = (1<<5)
1593 .equ STORE_B = (2<<5)
1594 .equ STORE_C = (3<<5)
1595 .equ STORE_D = (4<<5)
1596 .equ STORE_E = (5<<5)
1597 .equ STORE_H = (6<<5)
1598 .equ STORE_L = (7<<5)
1599 .equ STORE_AF = (8<<5)
1600 .equ STORE_BC = (9<<5)
1601 .equ STORE_DE = (10<<5)
1602 .equ STORE_HL = (11<<5)
1603 .equ STORE_SP = (12<<5)
1604 .equ STORE_PC = (13<<5)
1605 .equ STORE_MBC = (14<<5)
1606 .equ STORE_MDE = (15<<5)
1607 .equ STORE_MHL = (16<<5)
1608 .equ STORE_MSP = (17<<5)
1609 .equ STORE_RET = (18<<5)
1610 .equ STORE_CALL = (19<<5)
1611 .equ STORE_AM = (20<<5)
1613 ;Jump table for store routines. Make sure to keep this in sync with the .equs!
1765 ; ------------ Operation phase stuff -----------------
1768 .equ OP_NOP = (0<<10)
1769 .equ OP_INC = (1<<10)
1770 .equ OP_DEC = (2<<10)
1771 .equ OP_INC16 = (3<<10)
1772 .equ OP_DEC16 = (4<<10)
1773 .equ OP_RLC = (5<<10)
1774 .equ OP_RRC = (6<<10)
1775 .equ OP_RR = (7<<10)
1776 .equ OP_RL = (8<<10)
1777 .equ OP_ADDA = (9<<10)
1778 .equ OP_ADCA = (10<<10)
1779 .equ OP_SUBFA = (11<<10)
1780 .equ OP_SBCFA = (12<<10)
1781 .equ OP_ANDA = (13<<10)
1782 .equ OP_ORA = (14<<10)
1783 .equ OP_XORA = (15<<10)
1784 .equ OP_ADDHL = (16<<10)
1785 .equ OP_STHL = (17<<10) ;store HL in fetched address
1786 .equ OP_RMEM16 = (18<<10) ;read mem at fetched address
1787 .equ OP_RMEM8 = (19<<10) ;read mem at fetched address
1788 .equ OP_DA = (20<<10)
1789 .equ OP_SCF = (21<<10)
1790 .equ OP_CPL = (22<<10)
1791 .equ OP_CCF = (23<<10)
1792 .equ OP_POP16 = (24<<10)
1793 .equ OP_PUSH16 = (25<<10)
1794 .equ OP_IFNZ = (26<<10)
1795 .equ OP_IFZ = (27<<10)
1796 .equ OP_IFNC = (28<<10)
1797 .equ OP_IFC = (29<<10)
1798 .equ OP_IFPO = (30<<10)
1799 .equ OP_IFPE = (31<<10)
1800 .equ OP_IFP = (32<<10)
1801 .equ OP_IFM = (33<<10)
1802 .equ OP_OUTA = (34<<10)
1803 .equ OP_IN = (35<<10)
1804 .equ OP_EXHL = (36<<10)
1805 .equ OP_DI = (37<<10)
1806 .equ OP_EI = (38<<10)
1807 .equ OP_INV = (39<<10)
1852 ;How the flags are supposed to work:
1853 ;7 ZFL_S - Sign flag (=MSBit of result)
1854 ;6 ZFL_Z - Zero flag. Is 1 when the result is 0
1855 ;4 ZFL_H - Half-carry (carry from bit 3 to 4)
1856 ;2 ZFL_P - Parity/2-complement Overflow
1857 ;1 ZFL_N - Subtract - set if last op was a subtract
1860 ;I sure hope I got the mapping between flags and instructions correct...
1862 ;----------------------------------------------------------------
1866 ;| ZZZZZZZ 88888 000 |
1872 ;| ZZZZZZZ 88888 000 |
1874 ;| Z80 MICROPROCESSOR Instruction Set Summary |
1876 ;----------------------------------------------------------------
1877 ;----------------------------------------------------------------
1878 ;|Mnemonic |SZHPNC|Description |Notes |
1879 ;|----------+------+---------------------+----------------------|
1880 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
1881 ;|ADC HL,ss |**?V0*|Add with Carry |HL=HL+ss+CY |
1882 ;|ADD A,s |***V0*|Add |A=A+s |
1883 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
1884 ;|ADD IX,pp |--?-0*|Add |IX=IX+pp |
1885 ;|ADD IY,rr |--?-0*|Add |IY=IY+rr |
1886 ;|AND s |***P00|Logical AND |A=A&s |
1887 ;|BIT b,m |?*1?0-|Test Bit |m&{2^b} |
1888 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1889 ;|CALL nn |------|Unconditional Call |-[SP]=PC,PC=nn |
1890 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
1891 ;|CP s |***V1*|Compare |A-s |
1892 ;|CPD |****1-|Compare and Decrement|A-[HL],HL=HL-1,BC=BC-1|
1893 ;|CPDR |****1-|Compare, Dec., Repeat|CPD till A=[HL]or BC=0|
1894 ;|CPI |****1-|Compare and Increment|A-[HL],HL=HL+1,BC=BC-1|
1895 ;|CPIR |****1-|Compare, Inc., Repeat|CPI till A=[HL]or BC=0|
1896 ;|CPL |--1-1-|Complement |A=~A |
1897 ;|DAA |***P-*|Decimal Adjust Acc. |A=BCD format |
1898 ;|DEC s |***V1-|Decrement |s=s-1 |
1899 ;|DEC xx |------|Decrement |xx=xx-1 |
1900 ;|DEC ss |------|Decrement |ss=ss-1 |
1901 ;|DI |------|Disable Interrupts | |
1902 ;|DJNZ e |------|Dec., Jump Non-Zero |B=B-1 till B=0 |
1903 ;|EI |------|Enable Interrupts | |
1904 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
1905 ;|EX [SP],xx|------|Exchange |[SP]<->xx |
1906 ;|EX AF,AF' |------|Exchange |AF<->AF' |
1907 ;|EX DE,HL |------|Exchange |DE<->HL |
1908 ;|EXX |------|Exchange |qq<->qq' (except AF)|
1909 ;|HALT |------|Halt | |
1910 ;|IM n |------|Interrupt Mode | (n=0,1,2)|
1911 ;|IN A,[n] |------|Input |A=[n] |
1912 ;|IN r,[C] |***P0-|Input |r=[C] |
1913 ;|INC r |***V0-|Increment |r=r+1 |
1914 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
1915 ;|INC xx |------|Increment |xx=xx+1 |
1916 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
1917 ;|INC ss |------|Increment |ss=ss+1 |
1918 ;|IND |?*??1-|Input and Decrement |[HL]=[C],HL=HL-1,B=B-1|
1919 ;|INDR |?1??1-|Input, Dec., Repeat |IND till B=0 |
1920 ;|INI |?*??1-|Input and Increment |[HL]=[C],HL=HL+1,B=B-1|
1921 ;|INIR |?1??1-|Input, Inc., Repeat |INI till B=0 |
1922 ;|JP [HL] |------|Unconditional Jump |PC=[HL] |
1923 ;|JP [xx] |------|Unconditional Jump |PC=[xx] |
1924 ;|JP nn |------|Unconditional Jump |PC=nn |
1925 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1926 ;|JR e |------|Unconditional Jump |PC=PC+e |
1927 ;|JR cc,e |------|Conditional Jump |If cc JR(cc=C,NC,NZ,Z)|
1928 ;|LD dst,src|------|Load |dst=src |
1929 ;|LD A,i |**0*0-|Load |A=i (i=I,R)|
1930 ;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# |
1931 ;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 |
1932 ;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# |
1933 ;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 |
1934 ;|NEG |***V1*|Negate |A=-A |
1935 ;|NOP |------|No Operation | |
1936 ;|OR s |***P00|Logical inclusive OR |A=Avs |
1937 ;|OTDR |?1??1-|Output, Dec., Repeat |OUTD till B=0 |
1938 ;|OTIR |?1??1-|Output, Inc., Repeat |OUTI till B=0 |
1939 ;|OUT [C],r |------|Output |[C]=r |
1940 ;|OUT [n],A |------|Output |[n]=A |
1941 ;|OUTD |?*??1-|Output and Decrement |[C]=[HL],HL=HL-1,B=B-1|
1942 ;|OUTI |?*??1-|Output and Increment |[C]=[HL],HL=HL+1,B=B-1|
1943 ;|POP xx |------|Pop |xx=[SP]+ |
1944 ;|POP qq |------|Pop |qq=[SP]+ |
1945 ;|PUSH xx |------|Push |-[SP]=xx |
1946 ;|PUSH qq |------|Push |-[SP]=qq |
1947 ;|RES b,m |------|Reset bit |m=m&{~2^b} |
1948 ;|RET |------|Return |PC=[SP]+ |
1949 ;|RET cc |------|Conditional Return |If cc RET |
1950 ;|RETI |------|Return from Interrupt|PC=[SP]+ |
1951 ;|RETN |------|Return from NMI |PC=[SP]+ |
1952 ;|RL m |**0P0*|Rotate Left |m={CY,m}<- |
1953 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
1954 ;|RLC m |**0P0*|Rotate Left Circular |m=m<- |
1955 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
1956 ;----------------------------------------------------------------
1957 ;----------------------------------------------------------------
1958 ;|Mnemonic |SZHPNC|Description |Notes |
1959 ;|----------+------+---------------------+----------------------|
1960 ;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##|
1961 ;|RR m |**0P0*|Rotate Right |m=->{CY,m} |
1962 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
1963 ;|RRC m |**0P0*|Rotate Right Circular|m=->m |
1964 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
1965 ;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##|
1966 ;|RST p |------|Restart | (p=0H,8H,10H,...,38H)|
1967 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
1968 ;|SBC HL,ss |**?V1*|Subtract with Carry |HL=HL-ss-CY |
1969 ;|SCF |--0-01|Set Carry Flag |CY=1 |
1970 ;|SET b,m |------|Set bit |m=mv{2^b} |
1971 ;|SLA m |**0P0*|Shift Left Arithmetic|m=m*2 |
1972 ;|SRA m |**0P0*|Shift Right Arith. |m=m/2 |
1973 ;|SRL m |**0P0*|Shift Right Logical |m=->{0,m,CY} |
1974 ;|SUB s |***V1*|Subtract |A=A-s |
1975 ;|XOR s |***P00|Logical Exclusive OR |A=Axs |
1976 ;|----------+------+--------------------------------------------|
1977 ;| F |-*01? |Flag unaffected/affected/reset/set/unknown |
1978 ;| S |S |Sign flag (Bit 7) |
1979 ;| Z | Z |Zero flag (Bit 6) |
1980 ;| HC | H |Half Carry flag (Bit 4) |
1981 ;| P/V | P |Parity/Overflow flag (Bit 2, V=overflow) |
1982 ;| N | N |Add/Subtract flag (Bit 1) |
1983 ;| CY | C|Carry flag (Bit 0) |
1984 ;|-----------------+--------------------------------------------|
1985 ;| n |Immediate addressing |
1986 ;| nn |Immediate extended addressing |
1987 ;| e |Relative addressing (PC=PC+2+offset) |
1988 ;| [nn] |Extended addressing |
1989 ;| [xx+d] |Indexed addressing |
1990 ;| r |Register addressing |
1991 ;| [rr] |Register indirect addressing |
1992 ;| |Implied addressing |
1993 ;| b |Bit addressing |
1994 ;| p |Modified page zero addressing (see RST) |
1995 ;|-----------------+--------------------------------------------|
1996 ;|DEFB n(,...) |Define Byte(s) |
1997 ;|DEFB 'str'(,...) |Define Byte ASCII string(s) |
1998 ;|DEFS nn |Define Storage Block |
1999 ;|DEFW nn(,...) |Define Word(s) |
2000 ;|-----------------+--------------------------------------------|
2001 ;| A B C D E |Registers (8-bit) |
2002 ;| AF BC DE HL |Register pairs (16-bit) |
2003 ;| F |Flag register (8-bit) |
2004 ;| I |Interrupt page address register (8-bit) |
2005 ;| IX IY |Index registers (16-bit) |
2006 ;| PC |Program Counter register (16-bit) |
2007 ;| R |Memory Refresh register |
2008 ;| SP |Stack Pointer register (16-bit) |
2009 ;|-----------------+--------------------------------------------|
2010 ;| b |One bit (0 to 7) |
2011 ;| cc |Condition (C,M,NC,NZ,P,PE,PO,Z) |
2012 ;| d |One-byte expression (-128 to +127) |
2013 ;| dst |Destination s, ss, [BC], [DE], [HL], [nn] |
2014 ;| e |One-byte expression (-126 to +129) |
2015 ;| m |Any register r, [HL] or [xx+d] |
2016 ;| n |One-byte expression (0 to 255) |
2017 ;| nn |Two-byte expression (0 to 65535) |
2018 ;| pp |Register pair BC, DE, IX or SP |
2019 ;| qq |Register pair AF, BC, DE or HL |
2020 ;| qq' |Alternative register pair AF, BC, DE or HL |
2021 ;| r |Register A, B, C, D, E, H or L |
2022 ;| rr |Register pair BC, DE, IY or SP |
2023 ;| s |Any register r, value n, [HL] or [xx+d] |
2024 ;| src |Source s, ss, [BC], [DE], [HL], nn, [nn] |
2025 ;| ss |Register pair BC, DE, HL or SP |
2026 ;| xx |Index register IX or IY |
2027 ;|-----------------+--------------------------------------------|
2028 ;| + - * / ^ |Add/subtract/multiply/divide/exponent |
2029 ;| & ~ v x |Logical AND/NOT/inclusive OR/exclusive OR |
2030 ;| <- -> |Rotate left/right |
2031 ;| [ ] |Indirect addressing |
2032 ;| [ ]+ -[ ] |Indirect addressing auto-increment/decrement|
2033 ;| { } |Combination of operands |
2034 ;| # |Also BC=BC-1,DE=DE-1 |
2035 ;| ## |Only lower 4 bits of accumulator A used |
2036 ;----------------------------------------------------------------
2039 ;ToDo: Parity at more instructions...
2051 ;----------------------------------------------------------------
2052 ;|Mnemonic |SZHPNC|Description |Notes |
2053 ;----------------------------------------------------------------
2054 ;|INC r |***V0-|Increment |r=r+1 |
2055 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2056 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2060 andi z_flags, (1<<ZFL_C) ; bis auf Carry alles auf 0
2065 bst temp, AVR_Z ; Zero
2068 ori z_flags, (1<<ZFL_S)
2069 bst temp, AVR_H ; Half Sign
2071 bst temp, AVR_C ; Overflow
2075 ;----------------------------------------------------------------
2076 ;|Mnemonic |SZHPNC|Description |Notes |
2077 ;----------------------------------------------------------------
2078 ;|DEC s |***V1-|Decrement |s=s-1 |
2082 andi z_flags, (1<<ZFL_C) ; bis auf Carry alles auf 0
2083 ori z_flags, (1<<ZFL_N) ; Negation auf 1
2088 bst temp, AVR_Z ; Zero
2090 bst temp, AVR_S ; Sign
2092 bst temp, AVR_H ; Half Sign
2094 bst temp, AVR_C ; Underflow
2099 ;----------------------------------------------------------------
2100 ;|Mnemonic |SZHPNC|Description |Notes |
2101 ;----------------------------------------------------------------
2102 ;|INC xx |------|Increment |xx=xx+1 |
2103 ;|INC ss |------|Increment |ss=ss+1 |
2113 ;----------------------------------------------------------------
2114 ;|Mnemonic |SZHPNC|Description |Notes |
2115 ;----------------------------------------------------------------
2116 ;|DEC xx |------|Decrement |xx=xx-1 |
2117 ;|DEC ss |------|Decrement |ss=ss-1 |
2127 ;----------------------------------------------------------------
2128 ;|Mnemonic |SZHPNC|Description |Notes |
2129 ;----------------------------------------------------------------
2130 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
2134 ;Rotate Left Cyclical. All bits move 1 to the
2135 ;left, the msb becomes c and lsb.
2136 andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
2140 ori z_flags, (1<<ZFL_C)
2144 ;----------------------------------------------------------------
2145 ;|Mnemonic |SZHPNC|Description |Notes |
2146 ;----------------------------------------------------------------
2147 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
2151 ;Rotate Right Cyclical. All bits move 1 to the
2152 ;right, the lsb becomes c and msb.
2153 andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
2157 ori z_flags, (1<<ZFL_C)
2161 ;----------------------------------------------------------------
2162 ;|Mnemonic |SZHPNC|Description |Notes |
2163 ;----------------------------------------------------------------
2164 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
2168 ;Rotate Right. All bits move 1 to the right, the lsb
2169 ;becomes c, c becomes msb.
2175 andi z_flags,~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
2180 ;----------------------------------------------------------------
2181 ;|Mnemonic |SZHPNC|Description |Notes |
2182 ;----------------------------------------------------------------
2186 ;Rotate Left. All bits move 1 to the left, the msb
2187 ;becomes c, c becomes lsb.
2193 andi z_flags,0b11101100
2198 ;----------------------------------------------------------------
2199 ;|Mnemonic |SZHPNC|Description |Notes |
2200 ;----------------------------------------------------------------
2212 ori z_flags,(1<<ZFL_S)
2222 ;----------------------------------------------------------------
2223 ;|Mnemonic |SZHPNC|Description |Notes |
2224 ;----------------------------------------------------------------
2237 ori z_flags,(1<<ZFL_S)
2244 andi z_flags,~(1<<ZFL_N)
2247 ;----------------------------------------------------------------
2248 ;|Mnemonic |SZHPNC|Description |Notes |
2249 ;----------------------------------------------------------------
2267 ori z_flags,(1<<ZFL_N)
2270 ;----------------------------------------------------------------
2271 ;|Mnemonic |SZHPNC|Description |Notes |
2272 ;----------------------------------------------------------------
2291 cpi opl,0 ;AVR doesn't set Z?
2295 ori z_flags,(1<<ZFL_N)
2298 ;----------------------------------------------------------------
2299 ;|Mnemonic |SZHPNC|Description |Notes |
2300 ;----------------------------------------------------------------
2316 ;----------------------------------------------------------------
2317 ;|Mnemonic |SZHPNC|Description |Notes |
2318 ;----------------------------------------------------------------
2334 ;----------------------------------------------------------------
2335 ;|Mnemonic |SZHPNC|Description |Notes |
2336 ;----------------------------------------------------------------
2352 ;----------------------------------------------------------------
2353 ;|Mnemonic |SZHPNC|Description |Notes |
2354 ;----------------------------------------------------------------
2363 andi z_flags,~(1<<ZFL_N)
2366 ;----------------------------------------------------------------
2367 ;|Mnemonic |SZHPNC|Description |Notes |
2368 ;----------------------------------------------------------------
2371 do_op_sthl: ;store hl to mem loc in opl
2390 ;----------------------------------------------------------------
2391 ;|Mnemonic |SZHPNC|Description |Notes |
2392 ;----------------------------------------------------------------
2408 ;----------------------------------------------------------------
2409 ;|Mnemonic |SZHPNC|Description |Notes |
2410 ;----------------------------------------------------------------
2420 ;----------------------------------------------------------------
2421 ;|Mnemonic |SZHPNC|Description |Notes |
2422 ;----------------------------------------------------------------
2432 ;----------------------------------------------------------------
2433 ;|Mnemonic |SZHPNC|Description |Notes |
2434 ;----------------------------------------------------------------
2438 ori z_flags,(1<<ZFL_C)
2441 ;----------------------------------------------------------------
2442 ;|Mnemonic |SZHPNC|Description |Notes |
2443 ;----------------------------------------------------------------
2451 ;----------------------------------------------------------------
2452 ;|Mnemonic |SZHPNC|Description |Notes |
2453 ;----------------------------------------------------------------
2458 ori z_flags,(1<<ZFL_N)|(1<<ZFL_H)
2461 ;----------------------------------------------------------------
2462 ;|Mnemonic |SZHPNC|Description |Notes |
2463 ;----------------------------------------------------------------
2495 .db ", SP is now ",0
2506 ;----------------------------------------------------------------
2507 ;|Mnemonic |SZHPNC|Description |Notes |
2508 ;----------------------------------------------------------------
2534 .db "Stack pop: val ",0
2550 ;----------------------------------------------------------------
2551 ;|Mnemonic |SZHPNC|Description |Notes |
2552 ;----------------------------------------------------------------
2564 ;----------------------------------------------------------------
2565 ;|Mnemonic |SZHPNC|Description |Notes |
2566 ;----------------------------------------------------------------
2572 ;----------------------------------------------------------------
2573 ;|Mnemonic |SZHPNC|Description |Notes |
2574 ;----------------------------------------------------------------
2580 ;----------------------------------------------------------------
2581 ;|Mnemonic |SZHPNC|Description |Notes |
2582 ;----------------------------------------------------------------
2592 ;----------------------------------------------------------------
2593 ;|Mnemonic |SZHPNC|Description |Notes |
2594 ;----------------------------------------------------------------
2604 ;----------------------------------------------------------------
2605 ;|Mnemonic |SZHPNC|Description |Notes |
2606 ;----------------------------------------------------------------
2616 ;----------------------------------------------------------------
2617 ;|Mnemonic |SZHPNC|Description |Notes |
2618 ;----------------------------------------------------------------
2628 ;----------------------------------------------------------------
2629 ;|Mnemonic |SZHPNC|Description |Notes |
2630 ;----------------------------------------------------------------
2634 rcall do_op_calcparity
2641 ;----------------------------------------------------------------
2642 ;|Mnemonic |SZHPNC|Description |Notes |
2643 ;----------------------------------------------------------------
2647 rcall do_op_calcparity
2654 ;----------------------------------------------------------------
2655 ;|Mnemonic |SZHPNC|Description |Notes |
2656 ;----------------------------------------------------------------
2659 do_op_ifp: ;sign positive, aka s=0
2666 ;----------------------------------------------------------------
2667 ;|Mnemonic |SZHPNC|Description |Notes |
2668 ;----------------------------------------------------------------
2671 do_op_ifm: ;sign negative, aka s=1
2678 ;----------------------------------------------------------------
2679 ;|Mnemonic |SZHPNC|Description |Notes |
2680 ;----------------------------------------------------------------
2683 ;Interface with peripherials goes here :)
2684 do_op_outa: ; out (opl),a
2687 .db 13,"Port write: ",0
2702 ;----------------------------------------------------------------
2703 ;|Mnemonic |SZHPNC|Description |Notes |
2704 ;----------------------------------------------------------------
2707 do_op_in: ; in a,(opl)
2710 .db 13,"Port read: (",0
2728 ;----------------------------------------------------------------
2750 ;----------------------------------------------------------------
2753 .db "Invalid opcode @ PC=",0,0
2759 ;----------------------------------------------------------------
2764 ; ----------------------- Opcode decoding -------------------------
2766 ; Lookup table for Z80 opcodes. Translates the first byte of the instruction word into three
2767 ; operations: fetch, do something, store.
2768 ; The table is made of 256 words. These 16-bit words consist of
2769 ; the fetch operation (bit 0-4), the processing operation (bit 10-16) and the store
2770 ; operation (bit 5-9).
2773 .dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 00 NOP
2774 .dw (FETCH_DIR16| OP_NOP | STORE_BC ) ; 01 nn nn LD BC,nn
2775 .dw (FETCH_A | OP_NOP | STORE_MBC ) ; 02 LD (BC),A
2776 .dw (FETCH_BC | OP_INC16 | STORE_BC ) ; 03 INC BC
2777 .dw (FETCH_B | OP_INC | STORE_B ) ; 04 INC B
2778 .dw (FETCH_B | OP_DEC | STORE_B ) ; 05 DEC B
2779 .dw (FETCH_DIR8 | OP_NOP | STORE_B ) ; 06 nn LD B,n
2780 .dw (FETCH_A | OP_RLC | STORE_A ) ; 07 RLCA
2781 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 08 EX AF,AF' (Z80)
2782 .dw (FETCH_BC | OP_ADDHL | STORE_HL ) ; 09 ADD HL,BC
2783 .dw (FETCH_MBC | OP_NOP | STORE_A ) ; 0A LD A,(BC)
2784 .dw (FETCH_BC | OP_DEC16 | STORE_BC ) ; 0B DEC BC
2785 .dw (FETCH_C | OP_INC | STORE_C ) ; 0C INC C
2786 .dw (FETCH_C | OP_DEC | STORE_C ) ; 0D DEC C
2787 .dw (FETCH_DIR8 | OP_NOP | STORE_C ) ; 0E nn LD C,n
2788 .dw (FETCH_A | OP_RRC | STORE_A ) ; 0F RRCA
2789 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 10 oo DJNZ o (Z80)
2790 .dw (FETCH_DIR16| OP_NOP | STORE_DE ) ; 11 nn nn LD DE,nn
2791 .dw (FETCH_A | OP_NOP | STORE_MDE) ; 12 LD (DE),A
2792 .dw (FETCH_DE | OP_INC16 | STORE_DE ) ; 13 INC DE
2793 .dw (FETCH_D | OP_INC | STORE_D ) ; 14 INC D
2794 .dw (FETCH_D | OP_DEC | STORE_D ) ; 15 DEC D
2795 .dw (FETCH_DIR8 | OP_NOP | STORE_D ) ; 16 nn LD D,n
2796 .dw (FETCH_A | OP_RL | STORE_A ) ; 17 RLA
2797 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 18 oo JR o (Z80)
2798 .dw (FETCH_DE | OP_ADDHL | STORE_HL ) ; 19 ADD HL,DE
2799 .dw (FETCH_MDE | OP_NOP | STORE_A ) ; 1A LD A,(DE)
2800 .dw (FETCH_DE | OP_DEC16 | STORE_DE ) ; 1B DEC DE
2801 .dw (FETCH_E | OP_INC | STORE_E ) ; 1C INC E
2802 .dw (FETCH_E | OP_DEC | STORE_E ) ; 1D DEC E
2803 .dw (FETCH_DIR8 | OP_NOP | STORE_E ) ; 1E nn LD E,n
2804 .dw (FETCH_A | OP_RR | STORE_A ) ; 1F RRA
2805 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 20 oo JR NZ,o (Z80)
2806 .dw (FETCH_DIR16| OP_NOP | STORE_HL ) ; 21 nn nn LD HL,nn
2807 .dw (FETCH_DIR16| OP_STHL | STORE_NOP) ; 22 nn nn LD (nn),HL
2808 .dw (FETCH_HL | OP_INC16 | STORE_HL ) ; 23 INC HL
2809 .dw (FETCH_H | OP_INC | STORE_H ) ; 24 INC H
2810 .dw (FETCH_H | OP_DEC | STORE_H ) ; 25 DEC H
2811 .dw (FETCH_DIR8 | OP_NOP | STORE_H ) ; 26 nn LD H,n
2812 .dw (FETCH_A | OP_DA | STORE_A ) ; 27 DAA
2813 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 28 oo JR Z,o (Z80)
2814 .dw (FETCH_HL | OP_ADDHL | STORE_HL ) ; 29 ADD HL,HL
2815 .dw (FETCH_DIR16| OP_RMEM16 | STORE_HL ) ; 2A nn nn LD HL,(nn)
2816 .dw (FETCH_HL | OP_DEC16 | STORE_HL ) ; 2B DEC HL
2817 .dw (FETCH_L | OP_INC | STORE_L ) ; 2C INC L
2818 .dw (FETCH_L | OP_DEC | STORE_L ) ; 2D DEC L
2819 .dw (FETCH_DIR8 | OP_NOP | STORE_L ) ; 2E nn LD L,n
2820 .dw (FETCH_A | OP_CPL | STORE_A ) ; 2F CPL
2821 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 30 oo JR NC,o (Z80)
2822 .dw (FETCH_DIR16| OP_NOP | STORE_SP ) ; 31 nn nn LD SP,nn
2823 .dw (FETCH_DIR16| OP_NOP | STORE_AM ) ; 32 nn nn LD (nn),A
2824 .dw (FETCH_SP | OP_INC16 | STORE_SP ) ; 33 INC SP
2825 .dw (FETCH_MHL | OP_INC | STORE_MHL) ; 34 INC (HL)
2826 .dw (FETCH_MHL | OP_DEC | STORE_MHL) ; 35 DEC (HL)
2827 .dw (FETCH_DIR8 | OP_NOP | STORE_MHL) ; 36 nn LD (HL),n
2828 .dw (FETCH_NOP | OP_SCF | STORE_NOP) ; 37 SCF
2829 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 38 oo JR C,o (Z80)
2830 .dw (FETCH_SP | OP_ADDHL | STORE_HL ) ; 39 ADD HL,SP
2831 .dw (FETCH_DIR16| OP_RMEM8 | STORE_A ) ; 3A nn nn LD A,(nn)
2832 .dw (FETCH_SP | OP_DEC16 | STORE_SP ) ; 3B DEC SP
2833 .dw (FETCH_A | OP_INC | STORE_A ) ; 3C INC A
2834 .dw (FETCH_A | OP_DEC | STORE_A ) ; 3D DEC A
2835 .dw (FETCH_DIR8 | OP_NOP | STORE_A ) ; 3E nn LD A,n
2836 .dw (FETCH_NOP | OP_CCF | STORE_NOP) ; 3F CCF (Complement Carry Flag, gvd)
2837 .dw (FETCH_B | OP_NOP | STORE_B ) ; 40 LD B,r
2838 .dw (FETCH_C | OP_NOP | STORE_B ) ; 41 LD B,r
2839 .dw (FETCH_D | OP_NOP | STORE_B ) ; 42 LD B,r
2840 .dw (FETCH_E | OP_NOP | STORE_B ) ; 43 LD B,r
2841 .dw (FETCH_H | OP_NOP | STORE_B ) ; 44 LD B,r
2842 .dw (FETCH_L | OP_NOP | STORE_B ) ; 45 LD B,r
2843 .dw (FETCH_MHL | OP_NOP | STORE_B ) ; 46 LD B,r
2844 .dw (FETCH_A | OP_NOP | STORE_B ) ; 47 LD B,r
2845 .dw (FETCH_B | OP_NOP | STORE_C ) ; 48 LD C,r
2846 .dw (FETCH_C | OP_NOP | STORE_C ) ; 49 LD C,r
2847 .dw (FETCH_D | OP_NOP | STORE_C ) ; 4A LD C,r
2848 .dw (FETCH_E | OP_NOP | STORE_C ) ; 4B LD C,r
2849 .dw (FETCH_H | OP_NOP | STORE_C ) ; 4C LD C,r
2850 .dw (FETCH_L | OP_NOP | STORE_C ) ; 4D LD C,r
2851 .dw (FETCH_MHL | OP_NOP | STORE_C ) ; 4E LD C,r
2852 .dw (FETCH_A | OP_NOP | STORE_C ) ; 4F LD C,r
2853 .dw (FETCH_B | OP_NOP | STORE_D ) ; 50 LD D,r
2854 .dw (FETCH_C | OP_NOP | STORE_D ) ; 51 LD D,r
2855 .dw (FETCH_D | OP_NOP | STORE_D ) ; 52 LD D,r
2856 .dw (FETCH_E | OP_NOP | STORE_D ) ; 53 LD D,r
2857 .dw (FETCH_H | OP_NOP | STORE_D ) ; 54 LD D,r
2858 .dw (FETCH_L | OP_NOP | STORE_D ) ; 55 LD D,r
2859 .dw (FETCH_MHL | OP_NOP | STORE_D ) ; 56 LD D,r
2860 .dw (FETCH_A | OP_NOP | STORE_D ) ; 57 LD D,r
2861 .dw (FETCH_B | OP_NOP | STORE_E ) ; 58 LD E,r
2862 .dw (FETCH_C | OP_NOP | STORE_E ) ; 59 LD E,r
2863 .dw (FETCH_D | OP_NOP | STORE_E ) ; 5A LD E,r
2864 .dw (FETCH_E | OP_NOP | STORE_E ) ; 5B LD E,r
2865 .dw (FETCH_H | OP_NOP | STORE_E ) ; 5C LD E,r
2866 .dw (FETCH_L | OP_NOP | STORE_E ) ; 5D LD E,r
2867 .dw (FETCH_MHL | OP_NOP | STORE_E ) ; 5E LD E,r
2868 .dw (FETCH_A | OP_NOP | STORE_E ) ; 5F LD E,r
2869 .dw (FETCH_B | OP_NOP | STORE_H ) ; 60 LD H,r
2870 .dw (FETCH_C | OP_NOP | STORE_H ) ; 61 LD H,r
2871 .dw (FETCH_D | OP_NOP | STORE_H ) ; 62 LD H,r
2872 .dw (FETCH_E | OP_NOP | STORE_H ) ; 63 LD H,r
2873 .dw (FETCH_H | OP_NOP | STORE_H ) ; 64 LD H,r
2874 .dw (FETCH_L | OP_NOP | STORE_H ) ; 65 LD H,r
2875 .dw (FETCH_MHL | OP_NOP | STORE_H ) ; 66 LD H,r
2876 .dw (FETCH_A | OP_NOP | STORE_H ) ; 67 LD H,r
2877 .dw (FETCH_B | OP_NOP | STORE_L ) ; 68 LD L,r
2878 .dw (FETCH_C | OP_NOP | STORE_L ) ; 69 LD L,r
2879 .dw (FETCH_D | OP_NOP | STORE_L ) ; 6A LD L,r
2880 .dw (FETCH_E | OP_NOP | STORE_L ) ; 6B LD L,r
2881 .dw (FETCH_H | OP_NOP | STORE_L ) ; 6C LD L,r
2882 .dw (FETCH_L | OP_NOP | STORE_L ) ; 6D LD L,r
2883 .dw (FETCH_MHL | OP_NOP | STORE_L ) ; 6E LD L,r
2884 .dw (FETCH_A | OP_NOP | STORE_L ) ; 6F LD L,r
2885 .dw (FETCH_B | OP_NOP | STORE_MHL) ; 70 LD (HL),r
2886 .dw (FETCH_C | OP_NOP | STORE_MHL) ; 71 LD (HL),r
2887 .dw (FETCH_D | OP_NOP | STORE_MHL) ; 72 LD (HL),r
2888 .dw (FETCH_E | OP_NOP | STORE_MHL) ; 73 LD (HL),r
2889 .dw (FETCH_H | OP_NOP | STORE_MHL) ; 74 LD (HL),r
2890 .dw (FETCH_L | OP_NOP | STORE_MHL) ; 75 LD (HL),r
2891 .dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 76 HALT
2892 .dw (FETCH_A | OP_NOP | STORE_MHL) ; 77 LD (HL),r
2893 .dw (FETCH_B | OP_NOP | STORE_A ) ; 78 LD A,r
2894 .dw (FETCH_C | OP_NOP | STORE_A ) ; 79 LD A,r
2895 .dw (FETCH_D | OP_NOP | STORE_A ) ; 7A LD A,r
2896 .dw (FETCH_E | OP_NOP | STORE_A ) ; 7B LD A,r
2897 .dw (FETCH_H | OP_NOP | STORE_A ) ; 7C LD A,r
2898 .dw (FETCH_L | OP_NOP | STORE_A ) ; 7D LD A,r
2899 .dw (FETCH_MHL | OP_NOP | STORE_A ) ; 7E LD A,r
2900 .dw (FETCH_A | OP_NOP | STORE_A ) ; 7F LD A,r
2901 .dw (FETCH_B | OP_ADDA | STORE_A ) ; 80 ADD A,r
2902 .dw (FETCH_C | OP_ADDA | STORE_A ) ; 81 ADD A,r
2903 .dw (FETCH_D | OP_ADDA | STORE_A ) ; 82 ADD A,r
2904 .dw (FETCH_E | OP_ADDA | STORE_A ) ; 83 ADD A,r
2905 .dw (FETCH_H | OP_ADDA | STORE_A ) ; 84 ADD A,r
2906 .dw (FETCH_L | OP_ADDA | STORE_A ) ; 85 ADD A,r
2907 .dw (FETCH_MHL | OP_ADDA | STORE_A ) ; 86 ADD A,r
2908 .dw (FETCH_A | OP_ADDA | STORE_A ) ; 87 ADD A,r
2909 .dw (FETCH_B | OP_ADCA | STORE_A ) ; 88 ADC A,r
2910 .dw (FETCH_C | OP_ADCA | STORE_A ) ; 89 ADC A,r
2911 .dw (FETCH_D | OP_ADCA | STORE_A ) ; 8A ADC A,r
2912 .dw (FETCH_E | OP_ADCA | STORE_A ) ; 8B ADC A,r
2913 .dw (FETCH_H | OP_ADCA | STORE_A ) ; 8C ADC A,r
2914 .dw (FETCH_L | OP_ADCA | STORE_A ) ; 8D ADC A,r
2915 .dw (FETCH_MHL | OP_ADCA | STORE_A ) ; 8E ADC A,r
2916 .dw (FETCH_A | OP_ADCA | STORE_A ) ; 8F ADC A,r
2917 .dw (FETCH_B | OP_SUBFA | STORE_A ) ; 90 SUB A,r
2918 .dw (FETCH_C | OP_SUBFA | STORE_A ) ; 91 SUB A,r
2919 .dw (FETCH_D | OP_SUBFA | STORE_A ) ; 92 SUB A,r
2920 .dw (FETCH_E | OP_SUBFA | STORE_A ) ; 93 SUB A,r
2921 .dw (FETCH_H | OP_SUBFA | STORE_A ) ; 94 SUB A,r
2922 .dw (FETCH_L | OP_SUBFA | STORE_A ) ; 95 SUB A,r
2923 .dw (FETCH_MHL | OP_SUBFA | STORE_A ) ; 96 SUB A,r
2924 .dw (FETCH_A | OP_SUBFA | STORE_A ) ; 97 SUB A,r
2925 .dw (FETCH_B | OP_SBCFA | STORE_A ) ; 98 SBC A,r
2926 .dw (FETCH_C | OP_SBCFA | STORE_A ) ; 99 SBC A,r
2927 .dw (FETCH_D | OP_SBCFA | STORE_A ) ; 9A SBC A,r
2928 .dw (FETCH_E | OP_SBCFA | STORE_A ) ; 9B SBC A,r
2929 .dw (FETCH_H | OP_SBCFA | STORE_A ) ; 9C SBC A,r
2930 .dw (FETCH_L | OP_SBCFA | STORE_A ) ; 9D SBC A,r
2931 .dw (FETCH_MHL | OP_SBCFA | STORE_A ) ; 9E SBC A,r
2932 .dw (FETCH_A | OP_SBCFA | STORE_A ) ; 9F SBC A,r
2933 .dw (FETCH_B | OP_ANDA | STORE_A ) ; A0 AND A,r
2934 .dw (FETCH_C | OP_ANDA | STORE_A ) ; A1 AND A,r
2935 .dw (FETCH_D | OP_ANDA | STORE_A ) ; A2 AND A,r
2936 .dw (FETCH_E | OP_ANDA | STORE_A ) ; A3 AND A,r
2937 .dw (FETCH_H | OP_ANDA | STORE_A ) ; A4 AND A,r
2938 .dw (FETCH_L | OP_ANDA | STORE_A ) ; A5 AND A,r
2939 .dw (FETCH_MHL | OP_ANDA | STORE_A ) ; A6 AND A,r
2940 .dw (FETCH_A | OP_ANDA | STORE_A ) ; A7 AND A,r
2941 .dw (FETCH_B | OP_XORA | STORE_A ) ; A8 XOR A,r
2942 .dw (FETCH_C | OP_XORA | STORE_A ) ; A9 XOR A,r
2943 .dw (FETCH_D | OP_XORA | STORE_A ) ; AA XOR A,r
2944 .dw (FETCH_E | OP_XORA | STORE_A ) ; AB XOR A,r
2945 .dw (FETCH_H | OP_XORA | STORE_A ) ; AC XOR A,r
2946 .dw (FETCH_L | OP_XORA | STORE_A ) ; AD XOR A,r
2947 .dw (FETCH_MHL | OP_XORA | STORE_A ) ; AE XOR A,r
2948 .dw (FETCH_A | OP_XORA | STORE_A ) ; AF XOR A,r
2949 .dw (FETCH_B | OP_ORA | STORE_A ) ; B0 OR A,r
2950 .dw (FETCH_C | OP_ORA | STORE_A ) ; B1 OR A,r
2951 .dw (FETCH_D | OP_ORA | STORE_A ) ; B2 OR A,r
2952 .dw (FETCH_E | OP_ORA | STORE_A ) ; B3 OR A,r
2953 .dw (FETCH_H | OP_ORA | STORE_A ) ; B4 OR A,r
2954 .dw (FETCH_L | OP_ORA | STORE_A ) ; B5 OR A,r
2955 .dw (FETCH_MHL | OP_ORA | STORE_A ) ; B6 OR A,r
2956 .dw (FETCH_A | OP_ORA | STORE_A ) ; B7 OR A,r
2957 .dw (FETCH_B | OP_SUBFA | STORE_NOP) ; B8 CP A,r
2958 .dw (FETCH_C | OP_SUBFA | STORE_NOP) ; B9 CP A,r
2959 .dw (FETCH_D | OP_SUBFA | STORE_NOP) ; BA CP A,r
2960 .dw (FETCH_E | OP_SUBFA | STORE_NOP) ; BB CP A,r
2961 .dw (FETCH_H | OP_SUBFA | STORE_NOP) ; BC CP A,r
2962 .dw (FETCH_L | OP_SUBFA | STORE_NOP) ; BD CP A,r
2963 .dw (FETCH_MHL | OP_SUBFA | STORE_NOP) ; BE CP A,r
2964 .dw (FETCH_A | OP_SUBFA | STORE_NOP) ; BF CP A,r
2965 .dw (FETCH_NOP | OP_IFNZ | STORE_RET) ; C0 RET NZ
2966 .dw (FETCH_NOP | OP_POP16 | STORE_BC ) ; C1 POP BC
2967 .dw (FETCH_DIR16| OP_IFNZ | STORE_PC ) ; C2 nn nn JP NZ,nn
2968 .dw (FETCH_DIR16| OP_NOP | STORE_PC ) ; C3 nn nn JP nn
2969 .dw (FETCH_DIR16| OP_IFNZ | STORE_CALL) ; C4 nn nn CALL NZ,nn
2970 .dw (FETCH_BC | OP_PUSH16 | STORE_NOP) ; C5 PUSH BC
2971 .dw (FETCH_DIR8 | OP_ADDA | STORE_A ) ; C6 nn ADD A,n
2972 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; C7 RST 0
2973 .dw (FETCH_NOP | OP_IFZ | STORE_RET) ; C8 RET Z
2974 .dw (FETCH_NOP | OP_NOP | STORE_RET) ; C9 RET
2975 .dw (FETCH_DIR16| OP_IFZ | STORE_PC ) ; CA nn nn JP Z,nn
2976 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; CB (Z80 specific)
2977 .dw (FETCH_DIR16| OP_IFZ | STORE_CALL) ; CC nn nn CALL Z,nn
2978 .dw (FETCH_DIR16| OP_NOP | STORE_CALL) ; CD nn nn CALL nn
2979 .dw (FETCH_DIR8 | OP_ADCA | STORE_A ) ; CE nn ADC A,n
2980 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; CF RST 8H
2981 .dw (FETCH_NOP | OP_IFNC | STORE_RET) ; D0 RET NC
2982 .dw (FETCH_NOP | OP_POP16 | STORE_DE ) ; D1 POP DE
2983 .dw (FETCH_DIR16| OP_IFNC | STORE_PC ) ; D2 nn nn JP NC,nn
2984 .dw (FETCH_DIR8 | OP_OUTA | STORE_NOP) ; D3 nn OUT (n),A
2985 .dw (FETCH_DIR16| OP_IFNC | STORE_CALL) ; D4 nn nn CALL NC,nn
2986 .dw (FETCH_DE | OP_PUSH16 | STORE_NOP) ; D5 PUSH DE
2987 .dw (FETCH_DIR8 | OP_SUBFA | STORE_A ) ; D6 nn SUB n
2988 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; D7 RST 10H
2989 .dw (FETCH_NOP | OP_IFC | STORE_RET) ; D8 RET C
2990 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; D9 EXX (Z80)
2991 .dw (FETCH_DIR16| OP_IFC | STORE_PC ) ; DA nn nn JP C,nn
2992 .dw (FETCH_DIR8 | OP_IN | STORE_A ) ; DB nn IN A,(n)
2993 .dw (FETCH_DIR16| OP_IFC | STORE_CALL) ; DC nn nn CALL C,nn
2994 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; DD (Z80)
2995 .dw (FETCH_DIR8 | OP_SBCFA | STORE_A ) ; DE nn SBC A,n
2996 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; DF RST 18H
2997 .dw (FETCH_NOP | OP_IFPO | STORE_RET) ; E0 RET PO
2998 .dw (FETCH_NOP | OP_POP16 | STORE_HL ) ; E1 POP HL
2999 .dw (FETCH_DIR16| OP_IFPO | STORE_PC ) ; E2 nn nn JP PO,nn
3000 .dw (FETCH_MSP | OP_EXHL | STORE_MSP) ; E3 EX (SP),HL
3001 .dw (FETCH_DIR16| OP_IFPO | STORE_CALL) ; E4 nn nn CALL PO,nn
3002 .dw (FETCH_HL | OP_PUSH16 | STORE_NOP) ; E5 PUSH HL
3003 .dw (FETCH_DIR8 | OP_ANDA | STORE_A ) ; E6 nn AND n
3004 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; E7 RST 20H
3005 .dw (FETCH_NOP | OP_IFPE | STORE_RET) ; E8 RET PE
3006 .dw (FETCH_HL | OP_NOP | STORE_PC ) ; E9 JP (HL)
3007 .dw (FETCH_DIR16| OP_IFPE | STORE_PC ) ; EA nn nn JP PE,nn
3008 .dw (FETCH_DE | OP_EXHL | STORE_DE ) ; EB EX DE,HL
3009 .dw (FETCH_DIR16| OP_IFPE | STORE_CALL) ; EC nn nn CALL PE,nn
3010 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; ED (Z80 specific)
3011 .dw (FETCH_DIR8 | OP_XORA | STORE_A ) ; EE nn XOR n
3012 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; EF RST 28H
3013 .dw (FETCH_NOP | OP_IFP | STORE_RET) ; F0 RET P
3014 .dw (FETCH_NOP | OP_POP16 | STORE_AF ) ; F1 POP AF
3015 .dw (FETCH_DIR16| OP_IFP | STORE_PC ) ; F2 nn nn JP P,nn
3016 .dw (FETCH_NOP | OP_DI | STORE_NOP) ; F3 DI
3017 .dw (FETCH_DIR16| OP_IFP | STORE_CALL) ; F4 nn nn CALL P,nn
3018 .dw (FETCH_AF | OP_PUSH16 | STORE_NOP) ; F5 PUSH AF
3019 .dw (FETCH_DIR8 | OP_ORA | STORE_A ) ; F6 nn OR n
3020 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; F7 RST 30H
3021 .dw (FETCH_NOP | OP_IFM | STORE_RET) ; F8 RET M
3022 .dw (FETCH_HL | OP_NOP | STORE_SP ) ; F9 LD SP,HL
3023 .dw (FETCH_DIR16| OP_IFM | STORE_PC ) ; FA nn nn JP M,nn
3024 .dw (FETCH_NOP | OP_EI | STORE_NOP) ; FB EI
3025 .dw (FETCH_DIR16| OP_IFM | STORE_CALL) ; FC nn nn CALL M,nn
3026 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; FD (Z80 specific)
3027 .dw (FETCH_DIR8 | OP_SUBFA | STORE_NOP) ; FE nn CP n
3028 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; FF RST 38H