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/>.
22 #elif defined atmega168
23 .include "m168def.inc"
33 #ifndef DRAM_DQ_ORDER /* If this is set to 1, the portbits */
34 #define DRAM_DQ_ORDER 0 /* for DRAM D1 and WE are swapped. */
39 #define F_CPU 20000000 /* system clock in Hz; defaults to 20MHz */
42 #define BAUD 38400 /* console baud rate */
46 #define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) /* clever rounding */
48 #define RXBUFSIZE 64 /* USART recieve buffer size. Must be power of 2 */
50 #define REFR_RATE 64000 /* dram refresh rate in cycles/s. */
51 /* Most drams need 1/15.6µs. */
52 #define REFR_PRE 8 /* timer prescale factor */
53 #define REFR_CS 0x02 /* timer clock select for 1/8 */
54 #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE
57 #if defined __ATmega8__
58 .equ refr_vect = OC2addr
60 .equ refr_vect = OC2Aaddr
64 #define EM_Z80 0 /* we don't have any z80 instructions yet */
89 .equ RAM_AH_MASK = 0xE0 ; ram_a[7..5]
90 .equ PD_OUTPUT_MASK = 0xFE
105 .equ RAM_AL_MASK = 0x1F ; ram_a[4..0]
106 .equ PB_OUTPUT_MASK = 0x3F
109 #if DRAM_DQ_ORDER == 1
123 .equ RAM_DQ_MASK = (1<<ram_d3)|(1<<ram_d2)|(1<<ram_d1)|(1<<ram_d0)
124 .equ PC_OUTPUT_MASK = (1<<ram_cas)|(1<<ram_w)
127 ;Flag bits in z_flags
135 ;Register definitions
153 .def temp = R16 ;The temp register
154 .def temp2 = R17 ;Second temp register
169 ; This is the base z80 port address for clock access
170 #define TIMERPORT 0x40
171 #define TIMER_CTL TIMERPORT
172 #define TIMER_MSECS TIMERPORT+1
173 #define TIMER_SECS TIMER_MSECS+2
175 #define starttimercmd 1
176 #define quitTimerCmd 2
177 #define printTimerCmd 15
185 ;Sector buffer for 512 byte reads/writes from/to SD-card
193 rjmp start ; reset vector
195 rjmp refrint ; tim2cmpa
196 .org OC1Aaddr ; Timer/Counter1 Compare Match A
197 rjmp sysclockint ; 1ms system timer
199 rjmp rxint ; USART receive int.
203 .org INT_VECTORS_SIZE
206 ldi temp,low(RAMEND) ; top of memory
207 out SPL,temp ; init stack pointer
208 ldi temp,high(RAMEND) ; top of memory
209 out SPH,temp ; init stack pointer
213 #if defined __ATmega8__
217 ldi temp,(1<<WDCE) | (1<<WDE)
225 ldi temp,(1<<WDCE) | (1<<WDE)
232 ldi temp,PB_OUTPUT_MASK
234 ldi temp,PD_OUTPUT_MASK
236 ldi temp,PC_OUTPUT_MASK
248 ldi temp,0 ; reset receive buffer
254 #if defined __ATmega8__
255 ldi temp, (1<<TXEN) | (1<<RXEN) | (1<<RXCIE)
257 ldi temp, (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)
259 ldi temp, HIGH(UBRR_VAL)
261 ldi temp, LOW(UBRR_VAL)
264 ldi temp, (1<<TXEN0) | (1<<RXEN0) | (1<<RXCIE0)
266 ldi temp, (1<<UCSZ01) | (1<<UCSZ00)
268 ldi temp, HIGH(UBRR_VAL)
270 ldi temp, LOW(UBRR_VAL)
274 ;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
277 ldi temp,REFR_CNT*2 ; 2 cycles per int
279 ldi temp,(1<<WGM21) | REFR_CS ;CTC, clk/REFR_PRE
284 ldi temp,REFR_CNT ;=312 cycles
288 ldi temp, REFR_CS ;clk/REFR_PRE
295 ; Init clock/timer system
297 ldi zl,low(timer_base)
298 ldi zh,high(timer_base)
306 ; Init timer 1 as 1 ms system clock tick.
309 ldi temp,high(F_CPU/1000)
311 ldi temp,low(F_CPU/1000)
313 ldi temp,(1<<WGM12) | (1<<CS10) ;CTC, clk/1
319 ldi temp,high(F_CPU/1000)
321 ldi temp,low(F_CPU/1000)
323 ldi temp,(1<<WGM12) | (1<<CS10) ;CTC, clk/1
339 .db "CPM on an AVR, v1.0",13,0,0
343 .db "Initing mmc...",13,0
349 .db "Testing RAM: fill...",0,0
374 .db "reread...",13,0,0
409 ;Fill ram with cbs, which (for now) will trigger an invalid opcode error.
424 ;Load initial sector from MMC (512 bytes)
429 ;Save to Z80 RAM (only 128 bytes because that's retro)
431 ldi zh,high(sectbuff)
445 cpi zl,low(sectbuff+128)
447 cpi zh,high(sectbuff+128)
460 .db 13,"Ok, CPU is live!",13,0,0
489 ; *** Stage 1: Fetch next opcode
513 ; *** Stage 2: Decode it using the ins_table.
515 ldi zl,low(inst_table*2)
516 ldi zh,high(inst_table*2)
538 ; *** Stage 3: Fetch operand. Use the fetch jumptable for this.
545 ldi zl,low(fetchjumps*2)
546 ldi zh,high(fetchjumps*2)
570 ; *** Stage 4: Execute operation :) Use the op jumptable for this.
576 ldi zl,low(opjumps*2)
577 ldi zh,high(opjumps*2)
600 ; *** Stage 5: Store operand. Use the store jumptable for this.
608 ldi zl,low(storejumps*2)
609 ldi zh,high(storejumps*2)
641 ; ----------------Virtual peripherial interface ------
643 ;The hw is modelled to make writing a CPM BIOS easier.
645 ;0 - Con status. Returns 0xFF if the UART has a byte, 0 otherwise.
646 ;1 - Console input, aka UDR.
652 ;22 - Trigger - write 1 to read, 2 to write a sector using the above info.
653 ; This will automatically move track, sector and dma addr to the next sector.
655 ;Called with port in temp2. Should return value in temp.
662 cpi temp2,TIMER_MSECS
664 cpi temp2,TIMER_MSECS+6
672 ;Called with port in temp2 and value in temp.
691 cpi temp2,TIMER_MSECS+6
745 .db "Disk read: track ",0
763 ;First, convert track/sector to an LBA address (in 128byte blocks)
780 ;Now, see what has to be done.
788 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
793 ;Read 512-byte sector
797 ;Now, move the correct portion of the sector from AVR ram to Z80 ram
799 ldi zh,high(sectbuff)
827 brne dskDoItReadMemLoop
831 ;The write routines is a bit naive: it'll read the 512-byte sector the 128byte CPM-sector
832 ;resides in into memory, will overwrite the needed 128 byte with the Z80s memory buffer
833 ;and will then write it back to disk. In theory, this would mean that every 512 bytes
834 ;written will take 4 write cycles, while theoretically the writes could be deferred so we
835 ;would only have to do one write cycle.
840 .db "Disk write: track ",0
861 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
866 ;Read 512-byte sector
874 ;Copy the data from the Z80 DMA buffer in external memory to the right place in the
876 ;Now, move the correct portion of the sector from AVR ram to Z80 ram
878 ldi zh,high(sectbuff)
906 brne dskDoItWriteMemLoop
911 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
916 ;Write the sector back.
923 ; ----------------- MMC/SD routines ------------------
958 ;Wait till the mmc answers with the response in temp2, or till a timeout happens.
965 brne mmcWaitResploopEnd
978 .db ": Error: MMC resp timeout!",13,0
985 ;Init start: send 80 clocks with cs disabled
1010 ldi temp,0xff ;dummy
1012 ldi temp,0xff ;dummy
1026 ldi temp,0xff ;return byte
1036 ;Read OCR till card is ready
1042 ldi temp,0xff ;dummy
1061 breq mmcInitOcrLoopDone
1084 ;Call this with adrh:adrl = sector number
1085 ;16bit lba address means a max reach of 32M.
1092 ldi temp,0x51 ;cmd (read sector)
1107 ldi temp,0xff ;return byte
1118 ;Read sector to AVR RAM
1119 ldi zl,low(sectbuff)
1120 ldi zh,high(sectbuff)
1124 cpi zl,low(sectbuff+512)
1126 cpi zh,high(sectbuff+512)
1141 ;Call this with adrh:adrl = sector number
1142 ;16bit lba address means a max reach of 32M.
1150 ldi temp,0x58 ;cmd (write sector)
1165 ldi temp,0xff ;return byte
1176 ;Write sector from AVR RAM
1177 ldi zl,low(sectbuff)
1178 ldi zh,high(sectbuff)
1182 cpi zl,low(sectbuff+512)
1184 cpi zh,high(sectbuff+512)
1191 ;Status. Ignored for now.
1194 ;Wait till the mmc has written everything
1208 ;Set up wdt to time out after 1 sec.
1211 #if defined __ATmega8__
1214 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)
1219 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)
1226 ; ------------------ DRAM routines -------------
1230 #if DRAM_DQ_ORDER == 1
1231 #define CLASSIC_DRAM 0
1233 #define CLASSIC_DRAM 1 /* Change manualy, if you want new hw w/ old sw */
1237 #if DRAM_DQ_ORDER == 0
1238 #if CLASSIC_DRAM == 1
1239 #error "Old harware can not work with new software!"
1243 ; ****************************************************************************
1247 ; ********************** DRAM routines from Sprite_tm ************************
1249 ;Sends the address in zh:zl to the ram
1294 andi temp2,~RAM_DQ_MASK
1297 ori temp2,(1<<ram_d0)
1299 ori temp2,(1<<ram_d1)
1301 ori temp2,(1<<ram_d2)
1303 ori temp2,(1<<ram_d3)
1310 ;Loads the byte on address adrh:adrl into temp.
1333 rcall dram_getnibble
1348 rcall dram_getnibble
1356 ;Writes the byte in temp to adrh:adrl
1361 ori temp2,RAM_DQ_MASK
1364 rcall dram_sendnibble
1400 rcall dram_sendnibble
1414 andi temp,~RAM_DQ_MASK
1417 andi temp,~RAM_DQ_MASK
1421 #endif /* CLASSIC_DRAM == 1 */
1423 ; ****************************************************************************
1427 ; ***************************** New DRAM routines ****************************
1429 ; Defines how the dram nibbles are arganized.
1430 ; RAMORG == 0 : A7 == 0: low nibble, A7 == 1: high nibble (Original Sprite_tm design)
1431 ; RAMORG == 1 : A8 == 0: low nibble, A8 == 1: high nibble (faster)
1436 ;Sends the address in zh:zl to the ram
1440 andi temp,~RAM_AL_MASK
1442 ori temp,(1<<ram_a0)
1444 ori temp,(1<<ram_a1)
1446 ori temp,(1<<ram_a2)
1448 ori temp,(1<<ram_a3)
1450 ori temp,(1<<ram_a4)
1454 andi temp,~RAM_AH_MASK
1456 ori temp,(1<<ram_a5)
1458 ori temp,(1<<ram_a6)
1460 ori temp,(1<<ram_a7)
1462 ori temp,(1<<ram_a8)
1465 #else /* RAMORG == 1 */
1469 andi temp,~RAM_AL_MASK
1471 ori temp,(1<<ram_a0)
1473 ori temp,(1<<ram_a1)
1475 ori temp,(1<<ram_a2)
1477 ori temp,(1<<ram_a3)
1479 ori temp,(1<<ram_a4)
1483 andi temp,~RAM_AH_MASK
1485 ori temp,(1<<ram_a5)
1487 ori temp,(1<<ram_a6)
1489 ori temp,(1<<ram_a7)
1496 .macro DRAM_SENDNIBBLE
1498 andi temp2,~RAM_DQ_MASK
1499 andi temp,RAM_DQ_MASK
1505 ;Loads the byte on address adrh:adrl into temp.
1506 ;must not alter adrh:adrl
1579 ;Writes the byte in temp to adrh:adrl
1580 ;must not alter adrh:adrl
1585 in temp2,DDRC ;DRAM data ports as outputs
1586 ori temp2,RAM_DQ_MASK
1606 cbi PORTC,ram_w ;early write
1625 andi temp,~RAM_DQ_MASK
1628 andi temp,~RAM_DQ_MASK
1630 #else /* RAMORG == 1 */
1631 in temp2,DDRC ;DRAM data ports as outputs
1632 ori temp2,RAM_DQ_MASK
1643 cbi PORTC,ram_w ;early write
1661 andi temp,~RAM_DQ_MASK
1664 andi temp,~RAM_DQ_MASK
1670 #endif /* CLASSIC_DRAM == 0 */
1672 ; ****************************************************************************
1674 ; refresh interupt; exec 2 cbr cycles
1677 cbi P_CAS,ram_cas ;2 1| 1|
1679 cbi P_RAS,ram_ras ;2 |0 1|
1683 sbi P_RAS,ram_ras ;2 |0 |0
1686 cbi P_RAS,ram_ras ;2 |0 1|
1688 sbi P_CAS,ram_cas ;2 |0 |0
1690 sbi P_RAS,ram_ras ;2 1| |0
1692 reti ;4 --> 21 cycles
1694 ; ****************************************************************************
1696 ; ------------- system timer 10ms ---------------
1706 ; don't change order here, clock put/get depends on it.
1707 cntms_out: ; register for ms
1709 utime_io: ; register for uptime.
1716 .equ timer_size = timer_top - timer_base
1718 .equ clkofs = cnt_1ms-cntms_out
1719 .equ timerofs = cnt_1ms-timer_ms
1740 ldi zl,high(1000) ;doesn't change flags
1774 sts delay_timer,temp
1776 lds temp,delay_timer
1785 subi temp2,TIMER_MSECS
1786 brcs clkget_end ;Port number in range?
1787 ldi zl,low(cntms_out)
1788 ldi zh,high(cntms_out)
1789 breq clkget_copy ;lowest byte requestet, latch clock
1791 brsh clkget_end ;Port number to high?
1816 subi temp2,TIMERPORT
1817 brcs clkput_end ;Port number in range?
1822 cpi temp,starttimercmd
1824 cpi temp,quitTimerCmd
1826 cpi temp,printTimerCmd
1840 ldi zl,low(cntms_out)
1841 ldi zh,high(cntms_out)
1842 breq clkput_copy ;lowest byte requestet, latch clock
1844 brsh clkput_end ;Port number to high?
1869 ldi zl,low(timer_ms)
1870 ldi zh,high(timer_ms)
1890 ldi zl,low(timer_ms)
1891 ldi zh,high(timer_ms)
1893 ; put ms on stack (16 bit)
1904 subi adrl,low(-1000)
1905 sbci adrh,high(-1000)
1917 ldd temp2,z+timerofs
1931 .db 13,"Timer running. Elapsed: ",0
1955 ldi zh,high(cnt_1ms)
1990 ; --------------- Debugging stuff ---------------
1992 ;Print a unsigned lonng value to the uart
1993 ; oph:opl:temp2:temp = value
2000 clr adrl ;adrl = stack level
2002 ultoa1: ldi insdech, 32 ;adrh = oph:temp % 10
2003 clr adrh ;oph:temp /= 10
2015 cpi adrh, 10 ;adrh is a numeral digit '0'-'9'
2020 cp temp,insdech ;Repeat until oph:temp gets zero
2027 ultoa5: cpi adrl,3 ; at least 3 digits (ms)
2033 ultoa6: pop temp ;Flush stacked digits
2044 ;Prints the lower nibble of temp in hex to the uart
2060 ;Prints temp in hex to the uart
2068 ;Prints the zero-terminated string following the call statement. WARNING: Destroys temp.
2099 ; --------------- AVR HW <-> Z80 periph stuff ------------------
2101 .equ memReadByte = dram_read
2102 .equ memWriteByte = dram_write
2104 ; --------------------------------------------------------------
2108 #define RXBUFMASK RXBUFSIZE-1
2122 ; Save received character in a circular buffer. Do nothing if buffer overflows.
2135 lds zh,rxcount ;if rxcount < RXBUFSIZE
2136 cpi zh,RXBUFSIZE ; (room for at least 1 char?)
2139 sts rxcount,zh ; rxcount++
2141 ldi zl,low(rxfifo) ;
2146 sts rxidx_w,zh ; rxidx_w = ++rxidx_w % RXBUFSIZE
2147 ldi zh,high(rxfifo) ;
2150 st z,temp ; rxfifo[rxidx_w] = char
2160 ;Fetches a char from the buffer to temp. If none available, waits till one is.
2163 lds temp,rxcount ; Number of characters in buffer
2183 ld temp,z ;don't forget to get the char
2190 ;Sends a char from temp to the uart.
2192 #if defined __ATmega8__
2208 ; ------------ Fetch phase stuff -----------------
2210 .equ FETCH_NOP = (0<<0)
2211 .equ FETCH_A = (1<<0)
2212 .equ FETCH_B = (2<<0)
2213 .equ FETCH_C = (3<<0)
2214 .equ FETCH_D = (4<<0)
2215 .equ FETCH_E = (5<<0)
2216 .equ FETCH_H = (6<<0)
2217 .equ FETCH_L = (7<<0)
2218 .equ FETCH_AF = (8<<0)
2219 .equ FETCH_BC = (9<<0)
2220 .equ FETCH_DE = (10<<0)
2221 .equ FETCH_HL = (11<<0)
2222 .equ FETCH_SP = (12<<0)
2223 .equ FETCH_MBC = (13<<0)
2224 .equ FETCH_MDE = (14<<0)
2225 .equ FETCH_MHL = (15<<0)
2226 .equ FETCH_MSP = (16<<0)
2227 .equ FETCH_DIR8 = (17<<0)
2228 .equ FETCH_DIR16= (18<<0)
2229 .equ FETCH_RST = (19<<0)
2232 ;Jump table for fetch routines. Make sure to keep this in sync with the .equs!
2380 ; ------------ Store phase stuff -----------------
2382 .equ STORE_NOP = (0<<5)
2383 .equ STORE_A = (1<<5)
2384 .equ STORE_B = (2<<5)
2385 .equ STORE_C = (3<<5)
2386 .equ STORE_D = (4<<5)
2387 .equ STORE_E = (5<<5)
2388 .equ STORE_H = (6<<5)
2389 .equ STORE_L = (7<<5)
2390 .equ STORE_AF = (8<<5)
2391 .equ STORE_BC = (9<<5)
2392 .equ STORE_DE = (10<<5)
2393 .equ STORE_HL = (11<<5)
2394 .equ STORE_SP = (12<<5)
2395 .equ STORE_PC = (13<<5)
2396 .equ STORE_MBC = (14<<5)
2397 .equ STORE_MDE = (15<<5)
2398 .equ STORE_MHL = (16<<5)
2399 .equ STORE_MSP = (17<<5)
2400 .equ STORE_RET = (18<<5)
2401 .equ STORE_CALL = (19<<5)
2402 .equ STORE_AM = (20<<5)
2404 ;Jump table for store routines. Make sure to keep this in sync with the .equs!
2550 ; ------------ Operation phase stuff -----------------
2553 .equ OP_NOP = (0<<10)
2554 .equ OP_INC = (1<<10)
2555 .equ OP_DEC = (2<<10)
2556 .equ OP_INC16 = (3<<10)
2557 .equ OP_DEC16 = (4<<10)
2558 .equ OP_RLC = (5<<10)
2559 .equ OP_RRC = (6<<10)
2560 .equ OP_RR = (7<<10)
2561 .equ OP_RL = (8<<10)
2562 .equ OP_ADDA = (9<<10)
2563 .equ OP_ADCA = (10<<10)
2564 .equ OP_SUBFA = (11<<10)
2565 .equ OP_SBCFA = (12<<10)
2566 .equ OP_ANDA = (13<<10)
2567 .equ OP_ORA = (14<<10)
2568 .equ OP_XORA = (15<<10)
2569 .equ OP_ADDHL = (16<<10)
2570 .equ OP_STHL = (17<<10) ;store HL in fetched address
2571 .equ OP_RMEM16 = (18<<10) ;read mem at fetched address
2572 .equ OP_RMEM8 = (19<<10) ;read mem at fetched address
2573 .equ OP_DA = (20<<10)
2574 .equ OP_SCF = (21<<10)
2575 .equ OP_CPL = (22<<10)
2576 .equ OP_CCF = (23<<10)
2577 .equ OP_POP16 = (24<<10)
2578 .equ OP_PUSH16 = (25<<10)
2579 .equ OP_IFNZ = (26<<10)
2580 .equ OP_IFZ = (27<<10)
2581 .equ OP_IFNC = (28<<10)
2582 .equ OP_IFC = (29<<10)
2583 .equ OP_IFPO = (30<<10)
2584 .equ OP_IFPE = (31<<10)
2585 .equ OP_IFP = (32<<10)
2586 .equ OP_IFM = (33<<10)
2587 .equ OP_OUTA = (34<<10)
2588 .equ OP_IN = (35<<10)
2589 .equ OP_EXHL = (36<<10)
2590 .equ OP_DI = (37<<10)
2591 .equ OP_EI = (38<<10)
2592 .equ OP_INV = (39<<10)
2637 ;How the flags are supposed to work:
2638 ;7 ZFL_S - Sign flag (=MSBit of result)
2639 ;6 ZFL_Z - Zero flag. Is 1 when the result is 0
2640 ;4 ZFL_H - Half-carry (carry from bit 3 to 4)
2641 ;2 ZFL_P - Parity/2-complement Overflow
2642 ;1 ZFL_N - Subtract - set if last op was a subtract
2645 ;I sure hope I got the mapping between flags and instructions correct...
2647 ;----------------------------------------------------------------
2651 ;| ZZZZZZZ 88888 000 |
2657 ;| ZZZZZZZ 88888 000 |
2659 ;| Z80 MICROPROCESSOR Instruction Set Summary |
2661 ;----------------------------------------------------------------
2662 ;----------------------------------------------------------------
2663 ;|Mnemonic |SZHPNC|Description |Notes |
2664 ;|----------+------+---------------------+----------------------|
2665 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
2666 ;|ADC HL,ss |**?V0*|Add with Carry |HL=HL+ss+CY |
2667 ;|ADD A,s |***V0*|Add |A=A+s |
2668 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
2669 ;|ADD IX,pp |--?-0*|Add |IX=IX+pp |
2670 ;|ADD IY,rr |--?-0*|Add |IY=IY+rr |
2671 ;|AND s |**1P00|Logical AND |A=A&s |
2672 ;|BIT b,m |?*1?0-|Test Bit |m&{2^b} |
2673 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
2674 ;|CALL nn |------|Unconditional Call |-[SP]=PC,PC=nn |
2675 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
2676 ;|CP s |***V1*|Compare |A-s |
2677 ;|CPD |****1-|Compare and Decrement|A-[HL],HL=HL-1,BC=BC-1|
2678 ;|CPDR |****1-|Compare, Dec., Repeat|CPD till A=[HL]or BC=0|
2679 ;|CPI |****1-|Compare and Increment|A-[HL],HL=HL+1,BC=BC-1|
2680 ;|CPIR |****1-|Compare, Inc., Repeat|CPI till A=[HL]or BC=0|
2681 ;|CPL |--1-1-|Complement |A=~A |
2682 ;|DAA |***P-*|Decimal Adjust Acc. |A=BCD format |
2683 ;|DEC s |***V1-|Decrement |s=s-1 |
2684 ;|DEC xx |------|Decrement |xx=xx-1 |
2685 ;|DEC ss |------|Decrement |ss=ss-1 |
2686 ;|DI |------|Disable Interrupts | |
2687 ;|DJNZ e |------|Dec., Jump Non-Zero |B=B-1 till B=0 |
2688 ;|EI |------|Enable Interrupts | |
2689 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
2690 ;|EX [SP],xx|------|Exchange |[SP]<->xx |
2691 ;|EX AF,AF' |------|Exchange |AF<->AF' |
2692 ;|EX DE,HL |------|Exchange |DE<->HL |
2693 ;|EXX |------|Exchange |qq<->qq' (except AF)|
2694 ;|HALT |------|Halt | |
2695 ;|IM n |------|Interrupt Mode | (n=0,1,2)|
2696 ;|IN A,[n] |------|Input |A=[n] |
2697 ;|IN r,[C] |***P0-|Input |r=[C] |
2698 ;|INC r |***V0-|Increment |r=r+1 |
2699 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2700 ;|INC xx |------|Increment |xx=xx+1 |
2701 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2702 ;|INC ss |------|Increment |ss=ss+1 |
2703 ;|IND |?*??1-|Input and Decrement |[HL]=[C],HL=HL-1,B=B-1|
2704 ;|INDR |?1??1-|Input, Dec., Repeat |IND till B=0 |
2705 ;|INI |?*??1-|Input and Increment |[HL]=[C],HL=HL+1,B=B-1|
2706 ;|INIR |?1??1-|Input, Inc., Repeat |INI till B=0 |
2707 ;|JP [HL] |------|Unconditional Jump |PC=[HL] |
2708 ;|JP [xx] |------|Unconditional Jump |PC=[xx] |
2709 ;|JP nn |------|Unconditional Jump |PC=nn |
2710 ;|JP cc,nn |------|Conditional Jump |If cc JP |
2711 ;|JR e |------|Unconditional Jump |PC=PC+e |
2712 ;|JR cc,e |------|Conditional Jump |If cc JR(cc=C,NC,NZ,Z)|
2713 ;|LD dst,src|------|Load |dst=src |
2714 ;|LD A,i |**0*0-|Load |A=i (i=I,R)|
2715 ;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# |
2716 ;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 |
2717 ;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# |
2718 ;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 |
2719 ;|NEG |***V1*|Negate |A=-A |
2720 ;|NOP |------|No Operation | |
2721 ;|OR s |**0P00|Logical inclusive OR |A=Avs |
2722 ;|OTDR |?1??1-|Output, Dec., Repeat |OUTD till B=0 |
2723 ;|OTIR |?1??1-|Output, Inc., Repeat |OUTI till B=0 |
2724 ;|OUT [C],r |------|Output |[C]=r |
2725 ;|OUT [n],A |------|Output |[n]=A |
2726 ;|OUTD |?*??1-|Output and Decrement |[C]=[HL],HL=HL-1,B=B-1|
2727 ;|OUTI |?*??1-|Output and Increment |[C]=[HL],HL=HL+1,B=B-1|
2728 ;|POP xx |------|Pop |xx=[SP]+ |
2729 ;|POP qq |------|Pop |qq=[SP]+ |
2730 ;|PUSH xx |------|Push |-[SP]=xx |
2731 ;|PUSH qq |------|Push |-[SP]=qq |
2732 ;|RES b,m |------|Reset bit |m=m&{~2^b} |
2733 ;|RET |------|Return |PC=[SP]+ |
2734 ;|RET cc |------|Conditional Return |If cc RET |
2735 ;|RETI |------|Return from Interrupt|PC=[SP]+ |
2736 ;|RETN |------|Return from NMI |PC=[SP]+ |
2737 ;|RL m |**0P0*|Rotate Left |m={CY,m}<- |
2738 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
2739 ;|RLC m |**0P0*|Rotate Left Circular |m=m<- |
2740 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
2741 ;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##|
2742 ;|RR m |**0P0*|Rotate Right |m=->{CY,m} |
2743 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
2744 ;|RRC m |**0P0*|Rotate Right Circular|m=->m |
2745 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
2746 ;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##|
2747 ;|RST p |------|Restart | (p=0H,8H,10H,...,38H)|
2748 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
2749 ;|SBC HL,ss |**?V1*|Subtract with Carry |HL=HL-ss-CY |
2750 ;|SCF |--0-01|Set Carry Flag |CY=1 |
2751 ;|SET b,m |------|Set bit |m=mv{2^b} |
2752 ;|SLA m |**0P0*|Shift Left Arithmetic|m=m*2 |
2753 ;|SRA m |**0P0*|Shift Right Arith. |m=m/2 |
2754 ;|SRL m |**0P0*|Shift Right Logical |m=->{0,m,CY} |
2755 ;|SUB s |***V1*|Subtract |A=A-s |
2756 ;|XOR s |**0P00|Logical Exclusive OR |A=Axs |
2757 ;|----------+------+--------------------------------------------|
2768 ;------------------------------------------------;
2769 ; Move single bit between two registers
2771 ; bmov dstreg,dstbit,srcreg.srcbit
2779 ;------------------------------------------------;
2780 ; Load table value from flash indexed by source reg.
2782 ; ldpmx dstreg,tablebase,indexreg
2784 ; (6 words, 8 cycles)
2795 .macro do_z80_flags_HP
2797 bmov z_flags, ZFL_P, temp, AVR_V
2798 bmov z_flags, ZFL_H, temp, AVR_H
2802 .macro do_z80_flags_set_N
2804 ori z_flags, (1<<ZFL_N) ; Negation auf 1
2808 .macro do_z80_flags_set_HN
2810 ori z_flags,(1<<ZFL_N)|(1<<ZFL_H)
2814 .macro do_z80_flags_clear_N
2816 andi z_flags,~(1<<ZFL_N)
2820 .macro do_z80_flags_op_rotate
2821 ; must not change avr carry flag!
2823 andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
2825 andi z_flags, ~( (1<<ZFL_C) )
2829 .macro do_z80_flags_op_and
2831 ori z_flags,(1<<ZFL_H)
2833 ori z_flags,(1<<ZFL_H)
2837 .macro do_z80_flags_op_or
2846 ;----------------------------------------------------------------
2847 ;|Mnemonic |SZHPNC|Description |Notes |
2848 ;----------------------------------------------------------------
2849 ;|INC r |***V0-|Increment |r=r+1 |
2850 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2851 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2852 ;|----------|SZHP C|---------- 8080 ----------------------------|
2853 ;|INC r |**-P0-|Increment |r=r+1 |
2854 ;|INC [HL] |**-P0-|Increment |[HL]=[HL]+1 |
2861 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
2862 ldpmx temp2, sz53p_tab, opl
2867 ;----------------------------------------------------------------
2868 ;|Mnemonic |SZHPNC|Description |Notes |
2869 ;----------------------------------------------------------------
2870 ;|DEC r |***V1-|Decrement |s=s-1 |
2871 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2872 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2873 ;|----------|SZHP C|---------- 8080 ----------------------------|
2874 ;|DEC r |**-P -|Increment |r=r+1 |
2875 ;|DEC [HL] |**-P -|Increment |[HL]=[HL]+1 |
2881 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
2882 ldpmx temp2, sz53p_tab, opl
2889 ;----------------------------------------------------------------
2890 ;|Mnemonic |SZHPNC|Description |Notes |
2891 ;----------------------------------------------------------------
2892 ;|INC xx |------|Increment |xx=xx+1 |
2893 ;|INC ss |------|Increment |ss=ss+1 |
2903 ;----------------------------------------------------------------
2904 ;|Mnemonic |SZHPNC|Description |Notes |
2905 ;----------------------------------------------------------------
2906 ;|DEC xx |------|Decrement |xx=xx-1 |
2907 ;|DEC ss |------|Decrement |ss=ss-1 |
2915 ;----------------------------------------------------------------
2916 ;|Mnemonic |SZHPNC|Description |Notes |
2917 ;----------------------------------------------------------------
2918 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
2919 ;|----------|SZHP C|---------- 8080 ----------------------------|
2920 ;|RLCA |---- *|Rotate Left Circular |A=A<- |
2924 ;Rotate Left Cyclical. All bits move 1 to the
2925 ;left, the msb becomes c and lsb.
2926 do_z80_flags_op_rotate
2930 ori z_flags, (1<<ZFL_C)
2934 ;----------------------------------------------------------------
2935 ;|Mnemonic |SZHPNC|Description |Notes |
2936 ;----------------------------------------------------------------
2937 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
2938 ;|----------|SZHP C|---------- 8080 ----------------------------|
2939 ;|RRCA |---- *|Rotate Right Circular|A=->A |
2943 ;Rotate Right Cyclical. All bits move 1 to the
2944 ;right, the lsb becomes c and msb.
2945 do_z80_flags_op_rotate
2949 ori z_flags, (1<<ZFL_C)
2953 ;----------------------------------------------------------------
2954 ;|Mnemonic |SZHPNC|Description |Notes |
2955 ;----------------------------------------------------------------
2956 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
2957 ;|----------|SZHP C|---------- 8080 ----------------------------|
2958 ;|RRA |---- *|Rotate Right Acc. |A=->{CY,A} |
2962 ;Rotate Right. All bits move 1 to the right, the lsb
2963 ;becomes c, c becomes msb.
2964 clc ; get z80 carry to avr carry
2967 do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C)
2968 bmov z_flags,ZFL_C, opl,0 ; Bit 0 --> CY
2972 ;----------------------------------------------------------------
2973 ;|Mnemonic |SZHPNC|Description |Notes |
2974 ;----------------------------------------------------------------
2975 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
2976 ;|----------|SZHP C|---------- 8080 ----------------------------|
2977 ;|RLA |---- *|Rotate Left Acc. |A={CY,A}<- |
2981 ;Rotate Left. All bits move 1 to the left, the msb
2982 ;becomes c, c becomes lsb.
2986 do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C)
2987 bmov z_flags,ZFL_C, opl,7 ; Bit 7 --> CY
2991 ;----------------------------------------------------------------
2992 ;|Mnemonic |SZHPNC|Description |Notes |
2993 ;----------------------------------------------------------------
2994 ;|ADD A,s |***V0*|Add |A=A+s |
2995 ;|----------|SZHP C|---------- 8080 ----------------------------|
2996 ;|ADD A,s |***P *|Add |A=A+s |
3002 ldpmx z_flags,sz53p_tab,opl ;S,Z,P flag
3003 bmov z_flags,ZFL_C, temp,AVR_C
3007 ;----------------------------------------------------------------
3008 ;|Mnemonic |SZHPNC|Description |Notes |
3009 ;----------------------------------------------------------------
3010 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
3011 ;|----------|SZHP C|---------- 8080 ----------------------------|
3012 ;|ADC A,s |***P *|Add with Carry |A=A+s+CY |
3021 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
3022 bmov z_flags,ZFL_C, temp,AVR_C
3026 ;----------------------------------------------------------------
3027 ;|Mnemonic |SZHPNC|Description |Notes |
3028 ;----------------------------------------------------------------
3029 ;|SUB s |***V1*|Subtract |A=A-s |
3030 ;|CP s |***V1*|Compare |A-s |
3031 ;|----------|SZHP C|---------- 8080 ----------------------------|
3032 ;|SUB s |***P *|Subtract |A=A-s |
3033 ;|CP s |***P *|Compare |A-s |
3041 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
3042 bmov z_flags,ZFL_C, temp,AVR_C
3047 ;----------------------------------------------------------------
3048 ;|Mnemonic |SZHPNC|Description |Notes |
3049 ;----------------------------------------------------------------
3050 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
3051 ;|----------|SZHP C|---------- 8080 ----------------------------|
3052 ;|SBC A,s |***P *|Subtract with Carry |A=A-s-CY |
3063 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
3064 bmov z_flags,ZFL_C, temp,AVR_C
3069 ;----------------------------------------------------------------
3070 ;|Mnemonic |SZHPNC|Description |Notes |
3071 ;----------------------------------------------------------------
3072 ;|AND s |**1P00|Logical AND |A=A&s |
3073 ;|----------|SZHP C|---------- 8080 ----------------------------|
3074 ;|AND s |**-P 0|Logical AND |A=A&s |
3079 ldpmx z_flags,sz53p_tab,opl ;S,Z,P,N,C
3084 ;----------------------------------------------------------------
3085 ;|Mnemonic |SZHPNC|Description |Notes |
3086 ;----------------------------------------------------------------
3087 ;|OR s |**0P00|Logical inclusive OR |A=Avs |
3088 ;|----------|SZHP C|---------- 8080 ----------------------------|
3089 ;|OR s |**-P00|Logical inclusive OR |A=Avs |
3094 ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N,C
3098 ;----------------------------------------------------------------
3099 ;|Mnemonic |SZHPNC|Description |Notes |
3100 ;----------------------------------------------------------------
3101 ;|XOR s |**0P00|Logical Exclusive OR |A=Axs |
3102 ;|----------|SZHP C|---------- 8080 ----------------------------|
3103 ;|XOR s |**-P 0|Logical Exclusive OR |A=Axs |
3108 ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N,C
3112 ;----------------------------------------------------------------
3113 ;|Mnemonic |SZHPNC|Description |Notes |
3114 ;----------------------------------------------------------------
3115 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
3116 ;|----------|SZHP C|---------- 8080 ----------------------------|
3117 ;|ADD HL,ss |---- *|Add |HL=HL+ss |
3124 bmov z_flags,ZFL_H, temp,AVR_H
3125 bmov z_flags,ZFL_C, temp,AVR_C
3126 do_z80_flags_clear_N
3129 ;----------------------------------------------------------------
3130 ;|Mnemonic |SZHPNC|Description |Notes |
3131 ;----------------------------------------------------------------
3132 ;|LD dst,src|------|Load |dst=src |
3135 do_op_sthl: ;store hl to mem loc in opl:h
3152 ;----------------------------------------------------------------
3153 ;|Mnemonic |SZHPNC|Description |Notes |
3154 ;----------------------------------------------------------------
3155 ;|LD dst,src|------|Load |dst=src |
3171 ;----------------------------------------------------------------
3172 ;|Mnemonic |SZHPNC|Description |Notes |
3173 ;----------------------------------------------------------------
3174 ;|LD dst,src|------|Load |dst=src |
3184 ;----------------------------------------------------------------
3185 ;|Mnemonic |SZHPNC|Description |Notes |
3186 ;----------------------------------------------------------------
3187 ;|DAA |***P-*|Decimal Adjust Acc. | |
3188 ;|----------|SZHP C|---------- 8080 ----------------------------|
3192 ; Description (http://www.z80.info/z80syntx.htm#DAA):
3193 ; This instruction conditionally adjusts the accumulator for BCD addition
3194 ; and subtraction operations. For addition (ADD, ADC, INC) or subtraction
3195 ; (SUB, SBC, DEC, NEC), the following table indicates the operation performed:
3197 ; -------------------------------------------------------------------------------
3198 ; | | C Flag | HEX value in | H Flag | HEX value in | Number | C flag|
3199 ; | Operation| Before | upper digit | Before | lower digit | added | After |
3200 ; | | DAA | (bit 7-4) | DAA | (bit 3-0) | to byte | DAA |
3201 ; |-----------------------------------------------------------------------------|
3202 ; | | 0 | 0-9 | 0 | 0-9 | 00 | 0 |
3203 ; | ADD | 0 | 0-8 | 0 | A-F | 06 | 0 |
3204 ; | | 0 | 0-9 | 1 | 0-3 | 06 | 0 |
3205 ; | ADC | 0 | A-F | 0 | 0-9 | 60 | 1 |
3206 ; | | 0 | 9-F | 0 | A-F | 66 | 1 |
3207 ; | INC | 0 | A-F | 1 | 0-3 | 66 | 1 |
3208 ; | | 1 | 0-2 | 0 | 0-9 | 60 | 1 |
3209 ; | | 1 | 0-2 | 0 | A-F | 66 | 1 |
3210 ; | | 1 | 0-3 | 1 | 0-3 | 66 | 1 |
3211 ; |-----------------------------------------------------------------------------|
3212 ; | SUB | 0 | 0-9 | 0 | 0-9 | 00 | 0 |
3213 ; | SBC | 0 | 0-8 | 1 | 6-F | FA | 0 |
3214 ; | DEC | 1 | 7-F | 0 | 0-9 | A0 | 1 |
3215 ; | NEG | 1 | 6-F | 1 | 6-F | 9A | 1 |
3216 ; |-----------------------------------------------------------------------------|
3219 ; C: See instruction.
3221 ; P/V: Set if Acc. is even parity after operation, reset otherwise.
3222 ; H: See instruction.
3223 ; Z: Set if Acc. is Zero after operation, reset otherwise.
3224 ; S: Set if most significant bit of Acc. is 1 after operation, reset otherwise.
3230 ldi oph,0 ; what to add
3231 sbrc z_flags,ZFL_H ; if H-Flag
3234 andi temp,0x0f ; ... or lower digit > 9
3240 sbrc z_flags,(1<<ZFL_C)
3249 ori z_flags,(1<<ZFL_C); set C
3251 sbrs z_flags,ZFL_N ; if sub-op
3252 rjmp op_da_add ; then
3255 op_da_add: ; else add-op
3268 ori z_flags,(1<<ZFL_C)
3269 andi z_flags,(1<<ZFL_N)|(1<<ZFL_C) ; preserve C,N
3270 ldpmx temp2, sz53p_tab, opl ; get S,Z,P
3272 bmov z_flags,ZFL_H, temp,AVR_H ; H (?)
3277 sbrc z_flags,ZFL_N ; if add-op
3278 rjmp do_op_da_sub ; then
3282 cpi temp,0x0a ; if lower digit > 9
3284 ori temp2,0x06 ; add 6 to lower digit
3286 sbrc z_flags,ZFL_H ; ... or H-Flag
3296 do_op_da_c: ; else sub-op
3297 sbrc z_flags,ZFL_C ;
3299 andi z_flags, ~( (1<<ZFL_S) | (1<<ZFL_Z) | (1<<ZFL_H) )
3302 bst temp,AVR_Z ;Z-Flag
3304 bst temp,AVR_N ;S-Flag
3306 sbrc temp2,5 ;C-Flag, set if 0x06 added
3307 ori z_flags,(1<<ZFL_C) ;
3311 do_op_da_sub: ;TODO:
3316 ;----------------------------------------------------------------
3317 ;|Mnemonic |SZHPNC|Description |Notes |
3318 ;----------------------------------------------------------------
3319 ;|SCF |--0-01|Set Carry Flag |CY=1 |
3320 ;|----------|SZHP C|---------- 8080 ----------------------------|
3324 andi z_flags,~((1<<ZFL_H)|(1<<ZFL_N))
3325 ori z_flags,(1<<ZFL_C)
3328 ;----------------------------------------------------------------
3329 ;|Mnemonic |SZHPNC|Description |Notes |
3330 ;----------------------------------------------------------------
3331 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
3332 ;|----------|SZHP C|---------- 8080 ----------------------------|
3333 ;|SCF |---- 1|Set Carry Flag |CY=1 |
3337 do_z80_flags_clear_N
3342 ;----------------------------------------------------------------
3343 ;|Mnemonic |SZHPNC|Description |Notes |
3344 ;----------------------------------------------------------------
3345 ;|CPL |--1-1-|Complement |A=~A |
3346 ;|----------|SZHP C|---------- 8080 ----------------------------|
3347 ;|CPL |---- -|Complement |A=~A |
3356 ;----------------------------------------------------------------
3357 ;|Mnemonic |SZHPNC|Description |Notes |
3358 ;----------------------------------------------------------------
3359 ;|PUSH xx |------|Push |-[SP]=xx |
3360 ;|PUSH qq |------|Push |-[SP]=qq |
3410 .db ", SP is now ",0
3421 ;----------------------------------------------------------------
3422 ;|Mnemonic |SZHPNC|Description |Notes |
3423 ;----------------------------------------------------------------
3424 ;|POP xx |------|Pop |xx=[SP]+ |
3425 ;|POP qq |------|Pop |qq=[SP]+ |
3451 .db "Stack pop: val ",0
3467 ;----------------------------------------------------------------
3468 ;|Mnemonic |SZHPNC|Description |Notes |
3469 ;----------------------------------------------------------------
3470 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
3471 ;|EX DE,HL |------|Exchange |DE<->HL |
3483 ;----------------------------------------------------------------
3484 ;|Mnemonic |SZHPNC|Description |Notes |
3485 ;----------------------------------------------------------------
3487 ; TODO: Implement IFF1, IFF2
3491 ;----------------------------------------------------------------
3492 ;|Mnemonic |SZHPNC|Description |Notes |
3493 ;----------------------------------------------------------------
3495 ; TODO: Implement IFF1, IFF2
3499 ;----------------------------------------------------------------
3500 ;|Mnemonic |SZHPNC|Description |Notes |
3501 ;----------------------------------------------------------------
3502 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3503 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3504 ;|RET cc |------|Conditional Return |If cc RET |
3514 ;----------------------------------------------------------------
3515 ;|Mnemonic |SZHPNC|Description |Notes |
3516 ;----------------------------------------------------------------
3517 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3518 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3519 ;|RET cc |------|Conditional Return |If cc RET |
3529 ;----------------------------------------------------------------
3530 ;|Mnemonic |SZHPNC|Description |Notes |
3531 ;----------------------------------------------------------------
3532 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3533 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3534 ;|RET cc |------|Conditional Return |If cc RET |
3544 ;----------------------------------------------------------------
3545 ;|Mnemonic |SZHPNC|Description |Notes |
3546 ;----------------------------------------------------------------
3547 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3548 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3549 ;|RET cc |------|Conditional Return |If cc RET |
3559 ;----------------------------------------------------------------
3560 ;|Mnemonic |SZHPNC|Description |Notes |
3561 ;----------------------------------------------------------------
3562 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3563 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3564 ;|RET cc |------|Conditional Return |If cc RET |
3574 ;----------------------------------------------------------------
3575 ;|Mnemonic |SZHPNC|Description |Notes |
3576 ;----------------------------------------------------------------
3577 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3578 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3579 ;|RET cc |------|Conditional Return |If cc RET |
3589 ;----------------------------------------------------------------
3590 ;|Mnemonic |SZHPNC|Description |Notes |
3591 ;----------------------------------------------------------------
3592 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3593 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3594 ;|RET cc |------|Conditional Return |If cc RET |
3597 do_op_ifp: ;sign positive, aka s=0
3604 ;----------------------------------------------------------------
3605 ;|Mnemonic |SZHPNC|Description |Notes |
3606 ;----------------------------------------------------------------
3607 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3608 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3609 ;|RET cc |------|Conditional Return |If cc RET |
3612 do_op_ifm: ;sign negative, aka s=1
3619 ;----------------------------------------------------------------
3620 ;|Mnemonic |SZHPNC|Description |Notes |
3621 ;----------------------------------------------------------------
3622 ;|OUT [n],A |------|Output |[n]=A |
3625 ;Interface with peripherials goes here :)
3626 do_op_outa: ; out (opl),a
3629 .db 13,"Port write: ",0
3644 ;----------------------------------------------------------------
3645 ;|Mnemonic |SZHPNC|Description |Notes |
3646 ;----------------------------------------------------------------
3647 ;|IN A,[n] |------|Input |A=[n] |
3650 do_op_in: ; in a,(opl)
3653 .db 13,"Port read: (",0
3671 ;----------------------------------------------------------------
3696 ;----------------------------------------------------------------
3699 .db "Invalid opcode @ PC=",0,0
3705 ;----------------------------------------------------------------
3709 ;----------------------------------------------------------------
3710 ; Lookup table, stolen from z80ex, Z80 emulation library.
3711 ; http://z80ex.sourceforge.net/
3713 ; The S, Z, 5 and 3 bits and the parity of the lookup value
3715 .db 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00
3716 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c
3717 .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04
3718 .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08
3719 .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24
3720 .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28
3721 .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20
3722 .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c
3723 .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04
3724 .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08
3725 .db 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00
3726 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c
3727 .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20
3728 .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c
3729 .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24
3730 .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28
3731 .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
3732 .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88
3733 .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80
3734 .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c
3735 .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0
3736 .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac
3737 .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4
3738 .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8
3739 .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80
3740 .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c
3741 .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
3742 .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88
3743 .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4
3744 .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8
3745 .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0
3746 .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac
3749 ; ----------------------- Opcode decoding -------------------------
3751 ; Lookup table for Z80 opcodes. Translates the first byte of the instruction word into three
3752 ; operations: fetch, do something, store.
3753 ; The table is made of 256 words. These 16-bit words consist of
3754 ; the fetch operation (bit 0-4), the processing operation (bit 10-16) and the store
3755 ; operation (bit 5-9).
3758 .dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 00 NOP
3759 .dw (FETCH_DIR16| OP_NOP | STORE_BC ) ; 01 nn nn LD BC,nn
3760 .dw (FETCH_A | OP_NOP | STORE_MBC ) ; 02 LD (BC),A
3761 .dw (FETCH_BC | OP_INC16 | STORE_BC ) ; 03 INC BC
3762 .dw (FETCH_B | OP_INC | STORE_B ) ; 04 INC B
3763 .dw (FETCH_B | OP_DEC | STORE_B ) ; 05 DEC B
3764 .dw (FETCH_DIR8 | OP_NOP | STORE_B ) ; 06 nn LD B,n
3765 .dw (FETCH_A | OP_RLC | STORE_A ) ; 07 RLCA
3766 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 08 EX AF,AF' (Z80)
3767 .dw (FETCH_BC | OP_ADDHL | STORE_HL ) ; 09 ADD HL,BC
3768 .dw (FETCH_MBC | OP_NOP | STORE_A ) ; 0A LD A,(BC)
3769 .dw (FETCH_BC | OP_DEC16 | STORE_BC ) ; 0B DEC BC
3770 .dw (FETCH_C | OP_INC | STORE_C ) ; 0C INC C
3771 .dw (FETCH_C | OP_DEC | STORE_C ) ; 0D DEC C
3772 .dw (FETCH_DIR8 | OP_NOP | STORE_C ) ; 0E nn LD C,n
3773 .dw (FETCH_A | OP_RRC | STORE_A ) ; 0F RRCA
3774 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 10 oo DJNZ o (Z80)
3775 .dw (FETCH_DIR16| OP_NOP | STORE_DE ) ; 11 nn nn LD DE,nn
3776 .dw (FETCH_A | OP_NOP | STORE_MDE) ; 12 LD (DE),A
3777 .dw (FETCH_DE | OP_INC16 | STORE_DE ) ; 13 INC DE
3778 .dw (FETCH_D | OP_INC | STORE_D ) ; 14 INC D
3779 .dw (FETCH_D | OP_DEC | STORE_D ) ; 15 DEC D
3780 .dw (FETCH_DIR8 | OP_NOP | STORE_D ) ; 16 nn LD D,n
3781 .dw (FETCH_A | OP_RL | STORE_A ) ; 17 RLA
3782 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 18 oo JR o (Z80)
3783 .dw (FETCH_DE | OP_ADDHL | STORE_HL ) ; 19 ADD HL,DE
3784 .dw (FETCH_MDE | OP_NOP | STORE_A ) ; 1A LD A,(DE)
3785 .dw (FETCH_DE | OP_DEC16 | STORE_DE ) ; 1B DEC DE
3786 .dw (FETCH_E | OP_INC | STORE_E ) ; 1C INC E
3787 .dw (FETCH_E | OP_DEC | STORE_E ) ; 1D DEC E
3788 .dw (FETCH_DIR8 | OP_NOP | STORE_E ) ; 1E nn LD E,n
3789 .dw (FETCH_A | OP_RR | STORE_A ) ; 1F RRA
3790 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 20 oo JR NZ,o (Z80)
3791 .dw (FETCH_DIR16| OP_NOP | STORE_HL ) ; 21 nn nn LD HL,nn
3792 .dw (FETCH_DIR16| OP_STHL | STORE_NOP) ; 22 nn nn LD (nn),HL
3793 .dw (FETCH_HL | OP_INC16 | STORE_HL ) ; 23 INC HL
3794 .dw (FETCH_H | OP_INC | STORE_H ) ; 24 INC H
3795 .dw (FETCH_H | OP_DEC | STORE_H ) ; 25 DEC H
3796 .dw (FETCH_DIR8 | OP_NOP | STORE_H ) ; 26 nn LD H,n
3797 .dw (FETCH_A | OP_DA | STORE_A ) ; 27 DAA
3798 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 28 oo JR Z,o (Z80)
3799 .dw (FETCH_HL | OP_ADDHL | STORE_HL ) ; 29 ADD HL,HL
3800 .dw (FETCH_DIR16| OP_RMEM16 | STORE_HL ) ; 2A nn nn LD HL,(nn)
3801 .dw (FETCH_HL | OP_DEC16 | STORE_HL ) ; 2B DEC HL
3802 .dw (FETCH_L | OP_INC | STORE_L ) ; 2C INC L
3803 .dw (FETCH_L | OP_DEC | STORE_L ) ; 2D DEC L
3804 .dw (FETCH_DIR8 | OP_NOP | STORE_L ) ; 2E nn LD L,n
3805 .dw (FETCH_A | OP_CPL | STORE_A ) ; 2F CPL
3806 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 30 oo JR NC,o (Z80)
3807 .dw (FETCH_DIR16| OP_NOP | STORE_SP ) ; 31 nn nn LD SP,nn
3808 .dw (FETCH_DIR16| OP_NOP | STORE_AM ) ; 32 nn nn LD (nn),A
3809 .dw (FETCH_SP | OP_INC16 | STORE_SP ) ; 33 INC SP
3810 .dw (FETCH_MHL | OP_INC | STORE_MHL) ; 34 INC (HL)
3811 .dw (FETCH_MHL | OP_DEC | STORE_MHL) ; 35 DEC (HL)
3812 .dw (FETCH_DIR8 | OP_NOP | STORE_MHL) ; 36 nn LD (HL),n
3813 .dw (FETCH_NOP | OP_SCF | STORE_NOP) ; 37 SCF
3814 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 38 oo JR C,o (Z80)
3815 .dw (FETCH_SP | OP_ADDHL | STORE_HL ) ; 39 ADD HL,SP
3816 .dw (FETCH_DIR16| OP_RMEM8 | STORE_A ) ; 3A nn nn LD A,(nn)
3817 .dw (FETCH_SP | OP_DEC16 | STORE_SP ) ; 3B DEC SP
3818 .dw (FETCH_A | OP_INC | STORE_A ) ; 3C INC A
3819 .dw (FETCH_A | OP_DEC | STORE_A ) ; 3D DEC A
3820 .dw (FETCH_DIR8 | OP_NOP | STORE_A ) ; 3E nn LD A,n
3821 .dw (FETCH_NOP | OP_CCF | STORE_NOP) ; 3F CCF (Complement Carry Flag, gvd)
3822 .dw (FETCH_B | OP_NOP | STORE_B ) ; 40 LD B,r
3823 .dw (FETCH_C | OP_NOP | STORE_B ) ; 41 LD B,r
3824 .dw (FETCH_D | OP_NOP | STORE_B ) ; 42 LD B,r
3825 .dw (FETCH_E | OP_NOP | STORE_B ) ; 43 LD B,r
3826 .dw (FETCH_H | OP_NOP | STORE_B ) ; 44 LD B,r
3827 .dw (FETCH_L | OP_NOP | STORE_B ) ; 45 LD B,r
3828 .dw (FETCH_MHL | OP_NOP | STORE_B ) ; 46 LD B,r
3829 .dw (FETCH_A | OP_NOP | STORE_B ) ; 47 LD B,r
3830 .dw (FETCH_B | OP_NOP | STORE_C ) ; 48 LD C,r
3831 .dw (FETCH_C | OP_NOP | STORE_C ) ; 49 LD C,r
3832 .dw (FETCH_D | OP_NOP | STORE_C ) ; 4A LD C,r
3833 .dw (FETCH_E | OP_NOP | STORE_C ) ; 4B LD C,r
3834 .dw (FETCH_H | OP_NOP | STORE_C ) ; 4C LD C,r
3835 .dw (FETCH_L | OP_NOP | STORE_C ) ; 4D LD C,r
3836 .dw (FETCH_MHL | OP_NOP | STORE_C ) ; 4E LD C,r
3837 .dw (FETCH_A | OP_NOP | STORE_C ) ; 4F LD C,r
3838 .dw (FETCH_B | OP_NOP | STORE_D ) ; 50 LD D,r
3839 .dw (FETCH_C | OP_NOP | STORE_D ) ; 51 LD D,r
3840 .dw (FETCH_D | OP_NOP | STORE_D ) ; 52 LD D,r
3841 .dw (FETCH_E | OP_NOP | STORE_D ) ; 53 LD D,r
3842 .dw (FETCH_H | OP_NOP | STORE_D ) ; 54 LD D,r
3843 .dw (FETCH_L | OP_NOP | STORE_D ) ; 55 LD D,r
3844 .dw (FETCH_MHL | OP_NOP | STORE_D ) ; 56 LD D,r
3845 .dw (FETCH_A | OP_NOP | STORE_D ) ; 57 LD D,r
3846 .dw (FETCH_B | OP_NOP | STORE_E ) ; 58 LD E,r
3847 .dw (FETCH_C | OP_NOP | STORE_E ) ; 59 LD E,r
3848 .dw (FETCH_D | OP_NOP | STORE_E ) ; 5A LD E,r
3849 .dw (FETCH_E | OP_NOP | STORE_E ) ; 5B LD E,r
3850 .dw (FETCH_H | OP_NOP | STORE_E ) ; 5C LD E,r
3851 .dw (FETCH_L | OP_NOP | STORE_E ) ; 5D LD E,r
3852 .dw (FETCH_MHL | OP_NOP | STORE_E ) ; 5E LD E,r
3853 .dw (FETCH_A | OP_NOP | STORE_E ) ; 5F LD E,r
3854 .dw (FETCH_B | OP_NOP | STORE_H ) ; 60 LD H,r
3855 .dw (FETCH_C | OP_NOP | STORE_H ) ; 61 LD H,r
3856 .dw (FETCH_D | OP_NOP | STORE_H ) ; 62 LD H,r
3857 .dw (FETCH_E | OP_NOP | STORE_H ) ; 63 LD H,r
3858 .dw (FETCH_H | OP_NOP | STORE_H ) ; 64 LD H,r
3859 .dw (FETCH_L | OP_NOP | STORE_H ) ; 65 LD H,r
3860 .dw (FETCH_MHL | OP_NOP | STORE_H ) ; 66 LD H,r
3861 .dw (FETCH_A | OP_NOP | STORE_H ) ; 67 LD H,r
3862 .dw (FETCH_B | OP_NOP | STORE_L ) ; 68 LD L,r
3863 .dw (FETCH_C | OP_NOP | STORE_L ) ; 69 LD L,r
3864 .dw (FETCH_D | OP_NOP | STORE_L ) ; 6A LD L,r
3865 .dw (FETCH_E | OP_NOP | STORE_L ) ; 6B LD L,r
3866 .dw (FETCH_H | OP_NOP | STORE_L ) ; 6C LD L,r
3867 .dw (FETCH_L | OP_NOP | STORE_L ) ; 6D LD L,r
3868 .dw (FETCH_MHL | OP_NOP | STORE_L ) ; 6E LD L,r
3869 .dw (FETCH_A | OP_NOP | STORE_L ) ; 6F LD L,r
3870 .dw (FETCH_B | OP_NOP | STORE_MHL) ; 70 LD (HL),r
3871 .dw (FETCH_C | OP_NOP | STORE_MHL) ; 71 LD (HL),r
3872 .dw (FETCH_D | OP_NOP | STORE_MHL) ; 72 LD (HL),r
3873 .dw (FETCH_E | OP_NOP | STORE_MHL) ; 73 LD (HL),r
3874 .dw (FETCH_H | OP_NOP | STORE_MHL) ; 74 LD (HL),r
3875 .dw (FETCH_L | OP_NOP | STORE_MHL) ; 75 LD (HL),r
3876 .dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 76 HALT
3877 .dw (FETCH_A | OP_NOP | STORE_MHL) ; 77 LD (HL),r
3878 .dw (FETCH_B | OP_NOP | STORE_A ) ; 78 LD A,r
3879 .dw (FETCH_C | OP_NOP | STORE_A ) ; 79 LD A,r
3880 .dw (FETCH_D | OP_NOP | STORE_A ) ; 7A LD A,r
3881 .dw (FETCH_E | OP_NOP | STORE_A ) ; 7B LD A,r
3882 .dw (FETCH_H | OP_NOP | STORE_A ) ; 7C LD A,r
3883 .dw (FETCH_L | OP_NOP | STORE_A ) ; 7D LD A,r
3884 .dw (FETCH_MHL | OP_NOP | STORE_A ) ; 7E LD A,r
3885 .dw (FETCH_A | OP_NOP | STORE_A ) ; 7F LD A,r
3886 .dw (FETCH_B | OP_ADDA | STORE_A ) ; 80 ADD A,r
3887 .dw (FETCH_C | OP_ADDA | STORE_A ) ; 81 ADD A,r
3888 .dw (FETCH_D | OP_ADDA | STORE_A ) ; 82 ADD A,r
3889 .dw (FETCH_E | OP_ADDA | STORE_A ) ; 83 ADD A,r
3890 .dw (FETCH_H | OP_ADDA | STORE_A ) ; 84 ADD A,r
3891 .dw (FETCH_L | OP_ADDA | STORE_A ) ; 85 ADD A,r
3892 .dw (FETCH_MHL | OP_ADDA | STORE_A ) ; 86 ADD A,r
3893 .dw (FETCH_A | OP_ADDA | STORE_A ) ; 87 ADD A,r
3894 .dw (FETCH_B | OP_ADCA | STORE_A ) ; 88 ADC A,r
3895 .dw (FETCH_C | OP_ADCA | STORE_A ) ; 89 ADC A,r
3896 .dw (FETCH_D | OP_ADCA | STORE_A ) ; 8A ADC A,r
3897 .dw (FETCH_E | OP_ADCA | STORE_A ) ; 8B ADC A,r
3898 .dw (FETCH_H | OP_ADCA | STORE_A ) ; 8C ADC A,r
3899 .dw (FETCH_L | OP_ADCA | STORE_A ) ; 8D ADC A,r
3900 .dw (FETCH_MHL | OP_ADCA | STORE_A ) ; 8E ADC A,r
3901 .dw (FETCH_A | OP_ADCA | STORE_A ) ; 8F ADC A,r
3902 .dw (FETCH_B | OP_SUBFA | STORE_A ) ; 90 SUB A,r
3903 .dw (FETCH_C | OP_SUBFA | STORE_A ) ; 91 SUB A,r
3904 .dw (FETCH_D | OP_SUBFA | STORE_A ) ; 92 SUB A,r
3905 .dw (FETCH_E | OP_SUBFA | STORE_A ) ; 93 SUB A,r
3906 .dw (FETCH_H | OP_SUBFA | STORE_A ) ; 94 SUB A,r
3907 .dw (FETCH_L | OP_SUBFA | STORE_A ) ; 95 SUB A,r
3908 .dw (FETCH_MHL | OP_SUBFA | STORE_A ) ; 96 SUB A,r
3909 .dw (FETCH_A | OP_SUBFA | STORE_A ) ; 97 SUB A,r
3910 .dw (FETCH_B | OP_SBCFA | STORE_A ) ; 98 SBC A,r
3911 .dw (FETCH_C | OP_SBCFA | STORE_A ) ; 99 SBC A,r
3912 .dw (FETCH_D | OP_SBCFA | STORE_A ) ; 9A SBC A,r
3913 .dw (FETCH_E | OP_SBCFA | STORE_A ) ; 9B SBC A,r
3914 .dw (FETCH_H | OP_SBCFA | STORE_A ) ; 9C SBC A,r
3915 .dw (FETCH_L | OP_SBCFA | STORE_A ) ; 9D SBC A,r
3916 .dw (FETCH_MHL | OP_SBCFA | STORE_A ) ; 9E SBC A,r
3917 .dw (FETCH_A | OP_SBCFA | STORE_A ) ; 9F SBC A,r
3918 .dw (FETCH_B | OP_ANDA | STORE_A ) ; A0 AND A,r
3919 .dw (FETCH_C | OP_ANDA | STORE_A ) ; A1 AND A,r
3920 .dw (FETCH_D | OP_ANDA | STORE_A ) ; A2 AND A,r
3921 .dw (FETCH_E | OP_ANDA | STORE_A ) ; A3 AND A,r
3922 .dw (FETCH_H | OP_ANDA | STORE_A ) ; A4 AND A,r
3923 .dw (FETCH_L | OP_ANDA | STORE_A ) ; A5 AND A,r
3924 .dw (FETCH_MHL | OP_ANDA | STORE_A ) ; A6 AND A,r
3925 .dw (FETCH_A | OP_ANDA | STORE_A ) ; A7 AND A,r
3926 .dw (FETCH_B | OP_XORA | STORE_A ) ; A8 XOR A,r
3927 .dw (FETCH_C | OP_XORA | STORE_A ) ; A9 XOR A,r
3928 .dw (FETCH_D | OP_XORA | STORE_A ) ; AA XOR A,r
3929 .dw (FETCH_E | OP_XORA | STORE_A ) ; AB XOR A,r
3930 .dw (FETCH_H | OP_XORA | STORE_A ) ; AC XOR A,r
3931 .dw (FETCH_L | OP_XORA | STORE_A ) ; AD XOR A,r
3932 .dw (FETCH_MHL | OP_XORA | STORE_A ) ; AE XOR A,r
3933 .dw (FETCH_A | OP_XORA | STORE_A ) ; AF XOR A,r
3934 .dw (FETCH_B | OP_ORA | STORE_A ) ; B0 OR A,r
3935 .dw (FETCH_C | OP_ORA | STORE_A ) ; B1 OR A,r
3936 .dw (FETCH_D | OP_ORA | STORE_A ) ; B2 OR A,r
3937 .dw (FETCH_E | OP_ORA | STORE_A ) ; B3 OR A,r
3938 .dw (FETCH_H | OP_ORA | STORE_A ) ; B4 OR A,r
3939 .dw (FETCH_L | OP_ORA | STORE_A ) ; B5 OR A,r
3940 .dw (FETCH_MHL | OP_ORA | STORE_A ) ; B6 OR A,r
3941 .dw (FETCH_A | OP_ORA | STORE_A ) ; B7 OR A,r
3942 .dw (FETCH_B | OP_SUBFA | STORE_NOP) ; B8 CP A,r
3943 .dw (FETCH_C | OP_SUBFA | STORE_NOP) ; B9 CP A,r
3944 .dw (FETCH_D | OP_SUBFA | STORE_NOP) ; BA CP A,r
3945 .dw (FETCH_E | OP_SUBFA | STORE_NOP) ; BB CP A,r
3946 .dw (FETCH_H | OP_SUBFA | STORE_NOP) ; BC CP A,r
3947 .dw (FETCH_L | OP_SUBFA | STORE_NOP) ; BD CP A,r
3948 .dw (FETCH_MHL | OP_SUBFA | STORE_NOP) ; BE CP A,r
3949 .dw (FETCH_A | OP_SUBFA | STORE_NOP) ; BF CP A,r
3950 .dw (FETCH_NOP | OP_IFNZ | STORE_RET) ; C0 RET NZ
3951 .dw (FETCH_NOP | OP_POP16 | STORE_BC ) ; C1 POP BC
3952 .dw (FETCH_DIR16| OP_IFNZ | STORE_PC ) ; C2 nn nn JP NZ,nn
3953 .dw (FETCH_DIR16| OP_NOP | STORE_PC ) ; C3 nn nn JP nn
3954 .dw (FETCH_DIR16| OP_IFNZ | STORE_CALL) ; C4 nn nn CALL NZ,nn
3955 .dw (FETCH_BC | OP_PUSH16 | STORE_NOP) ; C5 PUSH BC
3956 .dw (FETCH_DIR8 | OP_ADDA | STORE_A ) ; C6 nn ADD A,n
3957 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; C7 RST 0
3958 .dw (FETCH_NOP | OP_IFZ | STORE_RET) ; C8 RET Z
3959 .dw (FETCH_NOP | OP_NOP | STORE_RET) ; C9 RET
3960 .dw (FETCH_DIR16| OP_IFZ | STORE_PC ) ; CA nn nn JP Z,nn
3961 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; CB (Z80 specific)
3962 .dw (FETCH_DIR16| OP_IFZ | STORE_CALL) ; CC nn nn CALL Z,nn
3963 .dw (FETCH_DIR16| OP_NOP | STORE_CALL) ; CD nn nn CALL nn
3964 .dw (FETCH_DIR8 | OP_ADCA | STORE_A ) ; CE nn ADC A,n
3965 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; CF RST 8H
3966 .dw (FETCH_NOP | OP_IFNC | STORE_RET) ; D0 RET NC
3967 .dw (FETCH_NOP | OP_POP16 | STORE_DE ) ; D1 POP DE
3968 .dw (FETCH_DIR16| OP_IFNC | STORE_PC ) ; D2 nn nn JP NC,nn
3969 .dw (FETCH_DIR8 | OP_OUTA | STORE_NOP) ; D3 nn OUT (n),A
3970 .dw (FETCH_DIR16| OP_IFNC | STORE_CALL) ; D4 nn nn CALL NC,nn
3971 .dw (FETCH_DE | OP_PUSH16 | STORE_NOP) ; D5 PUSH DE
3972 .dw (FETCH_DIR8 | OP_SUBFA | STORE_A ) ; D6 nn SUB n
3973 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; D7 RST 10H
3974 .dw (FETCH_NOP | OP_IFC | STORE_RET) ; D8 RET C
3975 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; D9 EXX (Z80)
3976 .dw (FETCH_DIR16| OP_IFC | STORE_PC ) ; DA nn nn JP C,nn
3977 .dw (FETCH_DIR8 | OP_IN | STORE_A ) ; DB nn IN A,(n)
3978 .dw (FETCH_DIR16| OP_IFC | STORE_CALL) ; DC nn nn CALL C,nn
3979 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; DD (Z80)
3980 .dw (FETCH_DIR8 | OP_SBCFA | STORE_A ) ; DE nn SBC A,n
3981 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; DF RST 18H
3982 .dw (FETCH_NOP | OP_IFPO | STORE_RET) ; E0 RET PO
3983 .dw (FETCH_NOP | OP_POP16 | STORE_HL ) ; E1 POP HL
3984 .dw (FETCH_DIR16| OP_IFPO | STORE_PC ) ; E2 nn nn JP PO,nn
3985 .dw (FETCH_MSP | OP_EXHL | STORE_MSP) ; E3 EX (SP),HL
3986 .dw (FETCH_DIR16| OP_IFPO | STORE_CALL) ; E4 nn nn CALL PO,nn
3987 .dw (FETCH_HL | OP_PUSH16 | STORE_NOP) ; E5 PUSH HL
3988 .dw (FETCH_DIR8 | OP_ANDA | STORE_A ) ; E6 nn AND n
3989 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; E7 RST 20H
3990 .dw (FETCH_NOP | OP_IFPE | STORE_RET) ; E8 RET PE
3991 .dw (FETCH_HL | OP_NOP | STORE_PC ) ; E9 JP (HL)
3992 .dw (FETCH_DIR16| OP_IFPE | STORE_PC ) ; EA nn nn JP PE,nn
3993 .dw (FETCH_DE | OP_EXHL | STORE_DE ) ; EB EX DE,HL
3994 .dw (FETCH_DIR16| OP_IFPE | STORE_CALL) ; EC nn nn CALL PE,nn
3995 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; ED (Z80 specific)
3996 .dw (FETCH_DIR8 | OP_XORA | STORE_A ) ; EE nn XOR n
3997 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; EF RST 28H
3998 .dw (FETCH_NOP | OP_IFP | STORE_RET) ; F0 RET P
3999 .dw (FETCH_NOP | OP_POP16 | STORE_AF ) ; F1 POP AF
4000 .dw (FETCH_DIR16| OP_IFP | STORE_PC ) ; F2 nn nn JP P,nn
4001 .dw (FETCH_NOP | OP_DI | STORE_NOP) ; F3 DI
4002 .dw (FETCH_DIR16| OP_IFP | STORE_CALL) ; F4 nn nn CALL P,nn
4003 .dw (FETCH_AF | OP_PUSH16 | STORE_NOP) ; F5 PUSH AF
4004 .dw (FETCH_DIR8 | OP_ORA | STORE_A ) ; F6 nn OR n
4005 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; F7 RST 30H
4006 .dw (FETCH_NOP | OP_IFM | STORE_RET) ; F8 RET M
4007 .dw (FETCH_HL | OP_NOP | STORE_SP ) ; F9 LD SP,HL
4008 .dw (FETCH_DIR16| OP_IFM | STORE_PC ) ; FA nn nn JP M,nn
4009 .dw (FETCH_NOP | OP_EI | STORE_NOP) ; FB EI
4010 .dw (FETCH_DIR16| OP_IFM | STORE_CALL) ; FC nn nn CALL M,nn
4011 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; FD (Z80 specific)
4012 .dw (FETCH_DIR8 | OP_SUBFA | STORE_NOP) ; FE nn CP n
4013 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; FF RST 38H
4015 ; vim:set ts=8 noet nowrap