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"
32 #ifndef DRAM_DQ_ORDER /* If this is set to 1, the portbits */
33 #define DRAM_DQ_ORDER 0 /* for DRAM D1 and WE are swapped. */
38 #define F_CPU 20000000 /* system clock in Hz; defaults to 20MHz */
41 #define BAUD 38400 /* console baud rate */
45 #define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) /* clever rounding */
47 #define RXBUFSIZE 64 /* USART recieve buffer size. Must be power of 2 */
49 #define REFR_RATE 64000 /* dram refresh rate in cycles/s. */
50 /* Most drams need 1/15.6µs. */
51 #define REFR_PRE 8 /* timer prescale factor */
52 #define REFR_CS 0x02 /* timer clock select for 1/8 */
53 #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE
56 #if defined __ATmega8__
57 .equ refr_vect = OC2addr
59 .equ refr_vect = OC2Aaddr
62 #define DRAM_WORD_ACCESS 0 /* experimental */
64 #define EM_Z80 0 /* we don't have any z80 instructions yet */
93 .equ RAM_AH_MASK = (1<<ram_a8)|(1<<ram_a7)|(1<<ram_a6)|(1<<ram_a5)
94 .equ PD_OUTPUT_MASK = (1<<mmc_cs) | (1<<ram_oe) | RAM_AH_MASK
112 .equ RAM_AL_MASK = (1<<ram_a4)|(1<<ram_a3)|(1<<ram_a2)|(1<<ram_a1)|(1<<ram_a0)
113 .equ PB_OUTPUT_MASK = (1<<ram_ras) | RAM_AL_MASK
116 #if DRAM_DQ_ORDER == 1
132 .equ RAM_DQ_MASK = (1<<ram_d3)|(1<<ram_d2)|(1<<ram_d1)|(1<<ram_d0)
133 .equ PC_OUTPUT_MASK = (1<<ram_cas)|(1<<ram_w)
136 ;Flag bits in z_flags
144 ;Register definitions
186 ; This is the base z80 port address for clock access
187 #define TIMERPORT 0x40
188 #define TIMER_CTL TIMERPORT
189 #define TIMER_MSECS TIMERPORT+1
190 #define TIMER_SECS TIMER_MSECS+2
192 #define starttimercmd 1
193 #define quitTimerCmd 2
194 #define printTimerCmd 15
207 ;Sector buffer for 512 byte reads/writes from/to SD-card
215 rjmp start ; reset vector
217 rjmp refrint ; tim2cmpa
218 .org OC1Aaddr ; Timer/Counter1 Compare Match A
219 rjmp sysclockint ; 1ms system timer
221 rjmp rxint ; USART receive int.
225 .org INT_VECTORS_SIZE
228 ldi temp,low(RAMEND) ; top of memory
229 out SPL,temp ; init stack pointer
230 ldi temp,high(RAMEND) ; top of memory
231 out SPH,temp ; init stack pointer
235 #if defined __ATmega8__
238 ldi temp,(1<<WDCE) | (1<<WDE)
242 ldi temp,(1<<PUD) ;disable pullups
247 ldi temp,(1<<WDCE) | (1<<WDE)
251 ldi temp,(1<<PUD) ;disable pullups
256 ldi temp,PB_OUTPUT_MASK
258 ldi temp,PD_OUTPUT_MASK
260 ldi temp,PC_OUTPUT_MASK
272 sts rxcount,_0 ; reset receive buffer
277 #if defined __ATmega8__
278 ldi temp, (1<<TXEN) | (1<<RXEN) | (1<<RXCIE)
280 ldi temp, (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)
282 ldi temp, HIGH(UBRR_VAL)
284 ldi temp, LOW(UBRR_VAL)
287 ldi temp, (1<<TXEN0) | (1<<RXEN0) | (1<<RXCIE0)
289 ldi temp, (1<<UCSZ01) | (1<<UCSZ00)
291 ldi temp, HIGH(UBRR_VAL)
293 ldi temp, LOW(UBRR_VAL)
297 ;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
300 ldi temp,REFR_CNT*2 ; 2 cycles per int
302 ldi temp,(1<<WGM21) | REFR_CS ;CTC, clk/REFR_PRE
307 ldi temp,REFR_CNT ;=312 cycles
311 ldi temp, REFR_CS ;clk/REFR_PRE
318 ; Init clock/timer system
320 ldi zl,low(timer_base)
321 ldi zh,high(timer_base)
328 ; Init timer 1 as 1 ms system clock tick.
331 ldi temp,high(F_CPU/1000)
333 ldi temp,low(F_CPU/1000)
335 ldi temp,(1<<WGM12) | (1<<CS10) ;CTC, clk/1
341 ldi temp,high(F_CPU/1000)
343 ldi temp,low(F_CPU/1000)
345 ldi temp,(1<<WGM12) | (1<<CS10) ;CTC, clk/1
361 .db "CPM on an AVR, v1.0",13,0,0
365 .db "Initing mmc...",13,0
371 .db "Testing RAM: fill...",0,0
393 .db "reread...",13,0,0
425 ;Fill ram with cbs, which (for now) will trigger an invalid opcode error.
437 ;Load initial sector from MMC (512 bytes)
442 ;Save to Z80 RAM (only 128 bytes because that's retro)
444 ldi zh,high(sectbuff)
455 cpi zl,low(sectbuff+128)
457 cpi zh,high(sectbuff+128)
470 .db 13,"Ok, CPU is live!",13,0,0
499 ; *** Stage 1: Fetch next opcode
522 ; *** Stage 2: Decode it using the ins_table.
523 ldi zh,high(inst_table*2)
544 ; *** Stage 3: Fetch operand. Use the fetch jumptable for this.
548 ldi zl,low(fetchjumps)
549 ldi zh,high(fetchjumps)
569 ; *** Stage 4: Execute operation :) Use the op jumptable for this.
594 ; *** Stage 5: Store operand. Use the store jumptable for this.
603 ldi zl,low(storejumps)
604 ldi zh,high(storejumps)
631 ; ----------------Virtual peripherial interface ------
633 ;The hw is modelled to make writing a CPM BIOS easier.
635 ;0 - Con status. Returns 0xFF if the UART has a byte, 0 otherwise.
636 ;1 - Console input, aka UDR.
642 ;22 - Trigger - write 1 to read, 2 to write a sector using the above info.
643 ; This will automatically move track, sector and dma addr to the next sector.
645 ;Called with port in temp2. Should return value in temp.
652 cpi temp2,TIMER_MSECS
654 cpi temp2,TIMER_MSECS+6
662 ;Called with port in temp2 and value in temp.
681 cpi temp2,TIMER_MSECS+6
735 .db "Disk read: track ",0
753 ;First, convert track/sector to an LBA address (in 128byte blocks)
769 ;Now, see what has to be done.
777 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
782 ;Read 512-byte sector
786 ;Now, move the correct portion of the sector from AVR ram to Z80 ram
788 ldi zh,high(sectbuff)
813 brne dskDoItReadMemLoop
817 ;The write routines is a bit naive: it'll read the 512-byte sector the 128byte CPM-sector
818 ;resides in into memory, will overwrite the needed 128 byte with the Z80s memory buffer
819 ;and will then write it back to disk. In theory, this would mean that every 512 bytes
820 ;written will take 4 write cycles, while theoretically the writes could be deferred so we
821 ;would only have to do one write cycle.
826 .db "Disk write: track ",0
847 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
852 ;Read 512-byte sector
860 ;Copy the data from the Z80 DMA buffer in external memory to the right place in the
862 ;Now, move the correct portion of the sector from AVR ram to Z80 ram
864 ldi zh,high(sectbuff)
889 brne dskDoItWriteMemLoop
894 ;Convert from 128-byte LBA blocks to 512-byte LBA blocks
899 ;Write the sector back.
906 ; ----------------- MMC/SD routines ------------------
941 ;Wait till the mmc answers with the response in temp2, or till a timeout happens.
948 brne mmcWaitResploopEnd
961 .db ": Error: MMC resp timeout!",13,0
968 ;Init start: send 80 clocks with cs disabled
972 ldi temp2,10 ; exactly 80 clocks
1010 ldi temp,0xff ;return byte
1013 ldi temp2,0 ;Error Code 0
1014 rcall mmcWaitResp ;Test on CMD0 is OK
1016 sbi P_MMC_CS,mmc_cs ;disable /CS
1020 ;Read OCR till card is ready
1021 ldi temp2,20 ;repeat counter
1025 cbi P_MMC_CS,mmc_cs ;enable /CS
1026 ldi temp,0xff ;dummy
1038 ; ldi temp,0x95 ;crc
1044 rcall mmcWaitResp ;wait until mmc-card send a byte <> 0xFF
1045 ;the first answer must be 0x01 (Idle-Mode)
1047 breq mmcInitOcrLoopDone ;second answer is 0x00 (Idle-Mode leave) CMD1 is OK
1049 sbi P_MMC_CS,mmc_cs ;disable /CS
1051 ; rcall mmcByteNoSend ;unnecessary
1059 brne mmcInitOcrLoop ;repeat
1066 sbi P_MMC_CS,mmc_cs ;disable /CS
1073 ;Call this with adrh:adrl = sector number
1074 ;16bit lba address means a max reach of 32M.
1081 ldi temp,0x51 ;cmd (read sector)
1096 ldi temp,0xff ;return byte
1107 ;Read sector to AVR RAM
1108 ldi zl,low(sectbuff)
1109 ldi zh,high(sectbuff)
1113 cpi zl,low(sectbuff+512)
1115 cpi zh,high(sectbuff+512)
1129 ;Call this with adrh:adrl = sector number
1130 ;16bit lba address means a max reach of 32M.
1138 ldi temp,0x58 ;cmd (write sector)
1153 ldi temp,0xff ;return byte
1164 ;Write sector from AVR RAM
1165 ldi zl,low(sectbuff)
1166 ldi zh,high(sectbuff)
1170 cpi zl,low(sectbuff+512)
1172 cpi zh,high(sectbuff+512)
1179 ;Status. Ignored for now.
1182 ;Wait till the mmc has written everything
1195 ;Set up wdt to time out after 1 sec.
1198 #if defined __ATmega8__
1201 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)
1206 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)
1213 ; ------------------ DRAM routines -------------
1217 #if DRAM_DQ_ORDER == 1
1218 #define CLASSIC_DRAM 0
1220 #define CLASSIC_DRAM 1 /* Change manualy, if you want new hw w/ old sw */
1224 #if DRAM_DQ_ORDER == 0
1225 #if CLASSIC_DRAM == 1
1226 #error "Old harware can not work with new software!"
1230 ; ****************************************************************************
1234 ; ********************** DRAM routines from Sprite_tm ************************
1236 ;Sends the address in zh:zl to the ram
1281 andi temp2,~RAM_DQ_MASK
1284 ori temp2,(1<<ram_d0)
1286 ori temp2,(1<<ram_d1)
1288 ori temp2,(1<<ram_d2)
1290 ori temp2,(1<<ram_d3)
1297 ;Loads the byte on address adrh:adrl into temp.
1320 rcall dram_getnibble
1335 rcall dram_getnibble
1343 ;Writes the byte in temp to adrh:adrl
1348 ori temp2,RAM_DQ_MASK
1351 rcall dram_sendnibble
1387 rcall dram_sendnibble
1401 andi temp,~RAM_DQ_MASK
1404 andi temp,~RAM_DQ_MASK
1408 #endif /* CLASSIC_DRAM == 1 */
1410 ; ****************************************************************************
1414 ; ***************************** New DRAM routines ****************************
1420 andi temp,~RAM_AL_MASK
1422 ori temp,(1<<ram_a0)
1424 ori temp,(1<<ram_a1)
1426 ori temp,(1<<ram_a2)
1428 ori temp,(1<<ram_a3)
1430 ori temp,(1<<ram_a4)
1437 andi temp,~RAM_AH_MASK
1439 ori temp,(1<<ram_a5)
1441 ori temp,(1<<ram_a6)
1443 ori temp,(1<<ram_a7)
1449 ;Loads the byte on address adrh:adrl into temp.
1450 ;must not alter adrh:adrl
1463 in temp,P_DQ-2 ; PIN
1470 in temp2,P_DQ-2 ; PIN
1482 ;Writes the byte in temp to adrh:adrl
1483 ;must not alter adrh:adrl
1487 ldi temp2,RAM_DQ_MASK | (1<<ram_w) | (1<<ram_cas)
1491 andi temp,RAM_DQ_MASK & ~(1<<ram_w)
1492 ori temp,(1<<ram_cas)
1505 andi temp2,RAM_DQ_MASK & ~(1<<ram_w)
1506 ori temp2,(1<<ram_cas)
1512 ldi temp,~RAM_DQ_MASK | (1<<ram_w) | (1<<ram_cas)
1518 #endif /* CLASSIC_DRAM == 0 */
1520 ; ****************************************************************************
1522 ; refresh interupt; exec 2 cbr cycles
1525 cbi P_CAS,ram_cas ;2 1| 1|
1527 cbi P_RAS,ram_ras ;2 |0 1|
1531 sbi P_RAS,ram_ras ;2 |0 |0
1534 cbi P_RAS,ram_ras ;2 |0 1|
1536 sbi P_CAS,ram_cas ;2 |0 |0
1538 sbi P_RAS,ram_ras ;2 1| |0
1540 reti ;4 --> 21 cycles
1542 ; ****************************************************************************
1544 ; ------------- system timer 10ms ---------------
1554 ; don't change order here, clock put/get depends on it.
1555 cntms_out: ; register for ms
1557 utime_io: ; register for uptime.
1564 .equ timer_size = timer_top - timer_base
1566 .equ clkofs = cnt_1ms-cntms_out
1567 .equ timerofs = cnt_1ms-timer_ms
1588 ldi zl,high(1000) ;doesn't change flags
1621 sts delay_timer,temp
1623 lds temp,delay_timer
1632 subi temp2,TIMER_MSECS
1633 brcs clkget_end ;Port number in range?
1634 ldi zl,low(cntms_out)
1635 ldi zh,high(cntms_out)
1636 breq clkget_copy ;lowest byte requestet, latch clock
1638 brsh clkget_end ;Port number to high?
1663 subi temp2,TIMERPORT
1664 brcs clkput_end ;Port number in range?
1669 cpi temp,starttimercmd
1671 cpi temp,quitTimerCmd
1673 cpi temp,printTimerCmd
1687 ldi zl,low(cntms_out)
1688 ldi zh,high(cntms_out)
1689 breq clkput_copy ;lowest byte requestet, latch clock
1691 brsh clkput_end ;Port number to high?
1716 ldi zl,low(timer_ms)
1717 ldi zh,high(timer_ms)
1737 ldi zl,low(timer_ms)
1738 ldi zh,high(timer_ms)
1740 ; put ms on stack (16 bit)
1751 subi adrl,low(-1000)
1752 sbci adrh,high(-1000)
1764 ldd temp2,z+timerofs
1778 .db 13,"Timer running. Elapsed: ",0
1802 ldi zh,high(cnt_1ms)
1837 ; --------------- Debugging stuff ---------------
1839 ;Print a unsigned lonng value to the uart
1840 ; oph:opl:temp2:temp = value
1847 clr adrl ;adrl = stack level
1849 ultoa1: ldi insdech, 32 ;adrh = oph:temp % 10
1850 clr adrh ;oph:temp /= 10
1862 cpi adrh, 10 ;adrh is a numeral digit '0'-'9'
1866 cp temp,_0 ;Repeat until oph:temp gets zero
1873 ultoa5: cpi adrl,3 ; at least 3 digits (ms)
1879 ultoa6: pop temp ;Flush stacked digits
1890 ;Prints the lower nibble of temp in hex to the uart
1906 ;Prints temp in hex to the uart
1914 ;Prints the zero-terminated string following the call statement. WARNING: Destroys temp.
1945 ; --------------- AVR HW <-> Z80 periph stuff ------------------
1947 .equ memReadByte = dram_read
1948 .equ memWriteByte = dram_write
1949 #if DRAM_WORD_ACCESS
1950 .equ memReadWord = dram_read_w
1951 .equ memWriteWord = dram_write_w
1954 ; --------------------------------------------------------------
1958 #define RXBUFMASK RXBUFSIZE-1
1972 ; Save received character in a circular buffer. Do nothing if buffer overflows.
1985 lds zh,rxcount ;if rxcount < RXBUFSIZE
1986 cpi zh,RXBUFSIZE ; (room for at least 1 char?)
1989 sts rxcount,zh ; rxcount++
1991 ldi zl,low(rxfifo) ;
1996 sts rxidx_w,zh ; rxidx_w = ++rxidx_w % RXBUFSIZE
1997 ldi zh,high(rxfifo) ;
2000 st z,temp ; rxfifo[rxidx_w] = char
2010 ;Fetches a char from the buffer to temp. If none available, waits till one is.
2013 lds temp,rxcount ; Number of characters in buffer
2033 ld temp,z ;don't forget to get the char
2040 ;Sends a char from temp to the uart.
2042 #if defined __ATmega8__
2058 ; ------------ Fetch phase stuff -----------------
2060 .equ FETCH_NOP = (0<<0)
2061 .equ FETCH_A = (1<<0)
2062 .equ FETCH_B = (2<<0)
2063 .equ FETCH_C = (3<<0)
2064 .equ FETCH_D = (4<<0)
2065 .equ FETCH_E = (5<<0)
2066 .equ FETCH_H = (6<<0)
2067 .equ FETCH_L = (7<<0)
2068 .equ FETCH_AF = (8<<0)
2069 .equ FETCH_BC = (9<<0)
2070 .equ FETCH_DE = (10<<0)
2071 .equ FETCH_HL = (11<<0)
2072 .equ FETCH_SP = (12<<0)
2073 .equ FETCH_MBC = (13<<0)
2074 .equ FETCH_MDE = (14<<0)
2075 .equ FETCH_MHL = (15<<0)
2076 .equ FETCH_MSP = (16<<0)
2077 .equ FETCH_DIR8 = (17<<0)
2078 .equ FETCH_DIR16= (18<<0)
2079 .equ FETCH_RST = (19<<0)
2082 ;Jump table for fetch routines. Make sure to keep this in sync with the .equs!
2183 #if DRAM_WORD_ACCESS
2205 #if DRAM_WORD_ACCESS
2230 ; ------------ Store phase stuff -----------------
2232 .equ STORE_NOP = (0<<5)
2233 .equ STORE_A = (1<<5)
2234 .equ STORE_B = (2<<5)
2235 .equ STORE_C = (3<<5)
2236 .equ STORE_D = (4<<5)
2237 .equ STORE_E = (5<<5)
2238 .equ STORE_H = (6<<5)
2239 .equ STORE_L = (7<<5)
2240 .equ STORE_AF = (8<<5)
2241 .equ STORE_BC = (9<<5)
2242 .equ STORE_DE = (10<<5)
2243 .equ STORE_HL = (11<<5)
2244 .equ STORE_SP = (12<<5)
2245 .equ STORE_PC = (13<<5)
2246 .equ STORE_MBC = (14<<5)
2247 .equ STORE_MDE = (15<<5)
2248 .equ STORE_MHL = (16<<5)
2249 .equ STORE_MSP = (17<<5)
2250 .equ STORE_RET = (18<<5)
2251 .equ STORE_CALL = (19<<5)
2252 .equ STORE_AM = (20<<5)
2254 ;Jump table for store routines. Make sure to keep this in sync with the .equs!
2353 #if DRAM_WORD_ACCESS
2394 ; ------------ Operation phase stuff -----------------
2397 .equ OP_NOP = (0<<10)
2398 .equ OP_INC = (1<<10)
2399 .equ OP_DEC = (2<<10)
2400 .equ OP_INC16 = (3<<10)
2401 .equ OP_DEC16 = (4<<10)
2402 .equ OP_RLC = (5<<10)
2403 .equ OP_RRC = (6<<10)
2404 .equ OP_RR = (7<<10)
2405 .equ OP_RL = (8<<10)
2406 .equ OP_ADDA = (9<<10)
2407 .equ OP_ADCA = (10<<10)
2408 .equ OP_SUBFA = (11<<10)
2409 .equ OP_SBCFA = (12<<10)
2410 .equ OP_ANDA = (13<<10)
2411 .equ OP_ORA = (14<<10)
2412 .equ OP_XORA = (15<<10)
2413 .equ OP_ADDHL = (16<<10)
2414 .equ OP_STHL = (17<<10) ;store HL in fetched address
2415 .equ OP_RMEM16 = (18<<10) ;read mem at fetched address
2416 .equ OP_RMEM8 = (19<<10) ;read mem at fetched address
2417 .equ OP_DA = (20<<10)
2418 .equ OP_SCF = (21<<10)
2419 .equ OP_CPL = (22<<10)
2420 .equ OP_CCF = (23<<10)
2421 .equ OP_POP16 = (24<<10)
2422 .equ OP_PUSH16 = (25<<10)
2423 .equ OP_IFNZ = (26<<10)
2424 .equ OP_IFZ = (27<<10)
2425 .equ OP_IFNC = (28<<10)
2426 .equ OP_IFC = (29<<10)
2427 .equ OP_IFPO = (30<<10)
2428 .equ OP_IFPE = (31<<10)
2429 .equ OP_IFP = (32<<10)
2430 .equ OP_IFM = (33<<10)
2431 .equ OP_OUTA = (34<<10)
2432 .equ OP_IN = (35<<10)
2433 .equ OP_EXHL = (36<<10)
2434 .equ OP_DI = (37<<10)
2435 .equ OP_EI = (38<<10)
2436 .equ OP_INV = (39<<10)
2481 ;How the flags are supposed to work:
2482 ;7 ZFL_S - Sign flag (=MSBit of result)
2483 ;6 ZFL_Z - Zero flag. Is 1 when the result is 0
2484 ;4 ZFL_H - Half-carry (carry from bit 3 to 4)
2485 ;2 ZFL_P - Parity/2-complement Overflow
2486 ;1 ZFL_N - Subtract - set if last op was a subtract
2489 ;I sure hope I got the mapping between flags and instructions correct...
2491 ;----------------------------------------------------------------
2495 ;| ZZZZZZZ 88888 000 |
2501 ;| ZZZZZZZ 88888 000 |
2503 ;| Z80 MICROPROCESSOR Instruction Set Summary |
2505 ;----------------------------------------------------------------
2506 ;----------------------------------------------------------------
2507 ;|Mnemonic |SZHPNC|Description |Notes |
2508 ;|----------+------+---------------------+----------------------|
2509 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
2510 ;|ADC HL,ss |**?V0*|Add with Carry |HL=HL+ss+CY |
2511 ;|ADD A,s |***V0*|Add |A=A+s |
2512 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
2513 ;|ADD IX,pp |--?-0*|Add |IX=IX+pp |
2514 ;|ADD IY,rr |--?-0*|Add |IY=IY+rr |
2515 ;|AND s |**1P00|Logical AND |A=A&s |
2516 ;|BIT b,m |?*1?0-|Test Bit |m&{2^b} |
2517 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
2518 ;|CALL nn |------|Unconditional Call |-[SP]=PC,PC=nn |
2519 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
2520 ;|CP s |***V1*|Compare |A-s |
2521 ;|CPD |****1-|Compare and Decrement|A-[HL],HL=HL-1,BC=BC-1|
2522 ;|CPDR |****1-|Compare, Dec., Repeat|CPD till A=[HL]or BC=0|
2523 ;|CPI |****1-|Compare and Increment|A-[HL],HL=HL+1,BC=BC-1|
2524 ;|CPIR |****1-|Compare, Inc., Repeat|CPI till A=[HL]or BC=0|
2525 ;|CPL |--1-1-|Complement |A=~A |
2526 ;|DAA |***P-*|Decimal Adjust Acc. |A=BCD format |
2527 ;|DEC s |***V1-|Decrement |s=s-1 |
2528 ;|DEC xx |------|Decrement |xx=xx-1 |
2529 ;|DEC ss |------|Decrement |ss=ss-1 |
2530 ;|DI |------|Disable Interrupts | |
2531 ;|DJNZ e |------|Dec., Jump Non-Zero |B=B-1 till B=0 |
2532 ;|EI |------|Enable Interrupts | |
2533 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
2534 ;|EX [SP],xx|------|Exchange |[SP]<->xx |
2535 ;|EX AF,AF' |------|Exchange |AF<->AF' |
2536 ;|EX DE,HL |------|Exchange |DE<->HL |
2537 ;|EXX |------|Exchange |qq<->qq' (except AF)|
2538 ;|HALT |------|Halt | |
2539 ;|IM n |------|Interrupt Mode | (n=0,1,2)|
2540 ;|IN A,[n] |------|Input |A=[n] |
2541 ;|IN r,[C] |***P0-|Input |r=[C] |
2542 ;|INC r |***V0-|Increment |r=r+1 |
2543 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2544 ;|INC xx |------|Increment |xx=xx+1 |
2545 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2546 ;|INC ss |------|Increment |ss=ss+1 |
2547 ;|IND |?*??1-|Input and Decrement |[HL]=[C],HL=HL-1,B=B-1|
2548 ;|INDR |?1??1-|Input, Dec., Repeat |IND till B=0 |
2549 ;|INI |?*??1-|Input and Increment |[HL]=[C],HL=HL+1,B=B-1|
2550 ;|INIR |?1??1-|Input, Inc., Repeat |INI till B=0 |
2551 ;|JP [HL] |------|Unconditional Jump |PC=[HL] |
2552 ;|JP [xx] |------|Unconditional Jump |PC=[xx] |
2553 ;|JP nn |------|Unconditional Jump |PC=nn |
2554 ;|JP cc,nn |------|Conditional Jump |If cc JP |
2555 ;|JR e |------|Unconditional Jump |PC=PC+e |
2556 ;|JR cc,e |------|Conditional Jump |If cc JR(cc=C,NC,NZ,Z)|
2557 ;|LD dst,src|------|Load |dst=src |
2558 ;|LD A,i |**0*0-|Load |A=i (i=I,R)|
2559 ;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# |
2560 ;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 |
2561 ;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# |
2562 ;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 |
2563 ;|NEG |***V1*|Negate |A=-A |
2564 ;|NOP |------|No Operation | |
2565 ;|OR s |**0P00|Logical inclusive OR |A=Avs |
2566 ;|OTDR |?1??1-|Output, Dec., Repeat |OUTD till B=0 |
2567 ;|OTIR |?1??1-|Output, Inc., Repeat |OUTI till B=0 |
2568 ;|OUT [C],r |------|Output |[C]=r |
2569 ;|OUT [n],A |------|Output |[n]=A |
2570 ;|OUTD |?*??1-|Output and Decrement |[C]=[HL],HL=HL-1,B=B-1|
2571 ;|OUTI |?*??1-|Output and Increment |[C]=[HL],HL=HL+1,B=B-1|
2572 ;|POP xx |------|Pop |xx=[SP]+ |
2573 ;|POP qq |------|Pop |qq=[SP]+ |
2574 ;|PUSH xx |------|Push |-[SP]=xx |
2575 ;|PUSH qq |------|Push |-[SP]=qq |
2576 ;|RES b,m |------|Reset bit |m=m&{~2^b} |
2577 ;|RET |------|Return |PC=[SP]+ |
2578 ;|RET cc |------|Conditional Return |If cc RET |
2579 ;|RETI |------|Return from Interrupt|PC=[SP]+ |
2580 ;|RETN |------|Return from NMI |PC=[SP]+ |
2581 ;|RL m |**0P0*|Rotate Left |m={CY,m}<- |
2582 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
2583 ;|RLC m |**0P0*|Rotate Left Circular |m=m<- |
2584 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
2585 ;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##|
2586 ;|RR m |**0P0*|Rotate Right |m=->{CY,m} |
2587 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
2588 ;|RRC m |**0P0*|Rotate Right Circular|m=->m |
2589 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
2590 ;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##|
2591 ;|RST p |------|Restart | (p=0H,8H,10H,...,38H)|
2592 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
2593 ;|SBC HL,ss |**?V1*|Subtract with Carry |HL=HL-ss-CY |
2594 ;|SCF |--0-01|Set Carry Flag |CY=1 |
2595 ;|SET b,m |------|Set bit |m=mv{2^b} |
2596 ;|SLA m |**0P0*|Shift Left Arithmetic|m=m*2 |
2597 ;|SRA m |**0P0*|Shift Right Arith. |m=m/2 |
2598 ;|SRL m |**0P0*|Shift Right Logical |m=->{0,m,CY} |
2599 ;|SUB s |***V1*|Subtract |A=A-s |
2600 ;|XOR s |**0P00|Logical Exclusive OR |A=Axs |
2601 ;|----------+------+--------------------------------------------|
2602 ;| F |-*01? |Flag unaffected/affected/reset/set/unknown |
2603 ;| S |S |Sign flag (Bit 7) |
2604 ;| Z | Z |Zero flag (Bit 6) |
2605 ;| HC | H |Half Carry flag (Bit 4) |
2606 ;| P/V | P |Parity/Overflow flag (Bit 2, V=overflow) |
2607 ;| N | N |Add/Subtract flag (Bit 1) |
2608 ;| CY | C|Carry flag (Bit 0) |
2609 ;|-----------------+--------------------------------------------|
2610 ;| n |Immediate addressing |
2611 ;| nn |Immediate extended addressing |
2612 ;| e |Relative addressing (PC=PC+2+offset) |
2613 ;| [nn] |Extended addressing |
2614 ;| [xx+d] |Indexed addressing |
2615 ;| r |Register addressing |
2616 ;| [rr] |Register indirect addressing |
2617 ;| |Implied addressing |
2618 ;| b |Bit addressing |
2619 ;| p |Modified page zero addressing (see RST) |
2620 ;|-----------------+--------------------------------------------|
2621 ;|DEFB n(,...) |Define Byte(s) |
2622 ;|DEFB 'str'(,...) |Define Byte ASCII string(s) |
2623 ;|DEFS nn |Define Storage Block |
2624 ;|DEFW nn(,...) |Define Word(s) |
2625 ;|-----------------+--------------------------------------------|
2626 ;| A B C D E |Registers (8-bit) |
2627 ;| AF BC DE HL |Register pairs (16-bit) |
2628 ;| F |Flag register (8-bit) |
2629 ;| I |Interrupt page address register (8-bit) |
2630 ;| IX IY |Index registers (16-bit) |
2631 ;| PC |Program Counter register (16-bit) |
2632 ;| R |Memory Refresh register |
2633 ;| SP |Stack Pointer register (16-bit) |
2634 ;|-----------------+--------------------------------------------|
2635 ;| b |One bit (0 to 7) |
2636 ;| cc |Condition (C,M,NC,NZ,P,PE,PO,Z) |
2637 ;| d |One-byte expression (-128 to +127) |
2638 ;| dst |Destination s, ss, [BC], [DE], [HL], [nn] |
2639 ;| e |One-byte expression (-126 to +129) |
2640 ;| m |Any register r, [HL] or [xx+d] |
2641 ;| n |One-byte expression (0 to 255) |
2642 ;| nn |Two-byte expression (0 to 65535) |
2643 ;| pp |Register pair BC, DE, IX or SP |
2644 ;| qq |Register pair AF, BC, DE or HL |
2645 ;| qq' |Alternative register pair AF, BC, DE or HL |
2646 ;| r |Register A, B, C, D, E, H or L |
2647 ;| rr |Register pair BC, DE, IY or SP |
2648 ;| s |Any register r, value n, [HL] or [xx+d] |
2649 ;| src |Source s, ss, [BC], [DE], [HL], nn, [nn] |
2650 ;| ss |Register pair BC, DE, HL or SP |
2651 ;| xx |Index register IX or IY |
2652 ;|-----------------+--------------------------------------------|
2653 ;| + - * / ^ |Add/subtract/multiply/divide/exponent |
2654 ;| & ~ v x |Logical AND/NOT/inclusive OR/exclusive OR |
2655 ;| <- -> |Rotate left/right |
2656 ;| [ ] |Indirect addressing |
2657 ;| [ ]+ -[ ] |Indirect addressing auto-increment/decrement|
2658 ;| { } |Combination of operands |
2659 ;| # |Also BC=BC-1,DE=DE-1 |
2660 ;| ## |Only lower 4 bits of accumulator A used |
2661 ;----------------------------------------------------------------
2672 ;------------------------------------------------;
2673 ; Move single bit between two registers
2675 ; bmov dstreg,dstbit,srcreg.srcbit
2683 ;------------------------------------------------;
2684 ; Load table value from flash indexed by source reg.
2686 ; ldpmx dstreg,tablebase,indexreg
2688 ; (6 words, 8 cycles)
2691 ldi zh,high(@1*2) ; table must be page aligned
2696 .macro do_z80_flags_HP
2698 bmov z_flags, ZFL_P, temp, AVR_V
2699 bmov z_flags, ZFL_H, temp, AVR_H
2703 .macro do_z80_flags_set_N
2705 ori z_flags, (1<<ZFL_N) ; Negation auf 1
2709 .macro do_z80_flags_set_HN
2711 ori z_flags,(1<<ZFL_N)|(1<<ZFL_H)
2715 .macro do_z80_flags_clear_N
2717 andi z_flags,~(1<<ZFL_N)
2721 .macro do_z80_flags_op_rotate
2722 ; must not change avr carry flag!
2724 andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
2726 andi z_flags, ~( (1<<ZFL_C) )
2730 .macro do_z80_flags_op_and
2732 ori z_flags,(1<<ZFL_H)
2734 ori z_flags,(1<<ZFL_H)
2738 .macro do_z80_flags_op_or
2747 ;----------------------------------------------------------------
2748 ;|Mnemonic |SZHPNC|Description |Notes |
2749 ;----------------------------------------------------------------
2750 ;|INC r |***V0-|Increment |r=r+1 |
2751 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2752 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2753 ;|----------|SZHP C|---------- 8080 ----------------------------|
2754 ;|INC r |**-P0-|Increment |r=r+1 |
2755 ;|INC [HL] |**-P0-|Increment |[HL]=[HL]+1 |
2762 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
2763 ldpmx temp2, sz53p_tab, opl
2768 ;----------------------------------------------------------------
2769 ;|Mnemonic |SZHPNC|Description |Notes |
2770 ;----------------------------------------------------------------
2771 ;|DEC r |***V1-|Decrement |s=s-1 |
2772 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
2773 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
2774 ;|----------|SZHP C|---------- 8080 ----------------------------|
2775 ;|DEC r |**-P -|Increment |r=r+1 |
2776 ;|DEC [HL] |**-P -|Increment |[HL]=[HL]+1 |
2782 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
2783 ldpmx temp2, sz53p_tab, opl
2790 ;----------------------------------------------------------------
2791 ;|Mnemonic |SZHPNC|Description |Notes |
2792 ;----------------------------------------------------------------
2793 ;|INC xx |------|Increment |xx=xx+1 |
2794 ;|INC ss |------|Increment |ss=ss+1 |
2801 ;----------------------------------------------------------------
2802 ;|Mnemonic |SZHPNC|Description |Notes |
2803 ;----------------------------------------------------------------
2804 ;|DEC xx |------|Decrement |xx=xx-1 |
2805 ;|DEC ss |------|Decrement |ss=ss-1 |
2813 ;----------------------------------------------------------------
2814 ;|Mnemonic |SZHPNC|Description |Notes |
2815 ;----------------------------------------------------------------
2816 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
2817 ;|----------|SZHP C|---------- 8080 ----------------------------|
2818 ;|RLCA |---- *|Rotate Left Circular |A=A<- |
2822 ;Rotate Left Cyclical. All bits move 1 to the
2823 ;left, the msb becomes c and lsb.
2824 do_z80_flags_op_rotate
2828 ori z_flags, (1<<ZFL_C)
2832 ;----------------------------------------------------------------
2833 ;|Mnemonic |SZHPNC|Description |Notes |
2834 ;----------------------------------------------------------------
2835 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
2836 ;|----------|SZHP C|---------- 8080 ----------------------------|
2837 ;|RRCA |---- *|Rotate Right Circular|A=->A |
2841 ;Rotate Right Cyclical. All bits move 1 to the
2842 ;right, the lsb becomes c and msb.
2843 do_z80_flags_op_rotate
2847 ori z_flags, (1<<ZFL_C)
2851 ;----------------------------------------------------------------
2852 ;|Mnemonic |SZHPNC|Description |Notes |
2853 ;----------------------------------------------------------------
2854 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
2855 ;|----------|SZHP C|---------- 8080 ----------------------------|
2856 ;|RRA |---- *|Rotate Right Acc. |A=->{CY,A} |
2860 ;Rotate Right. All bits move 1 to the right, the lsb
2861 ;becomes c, c becomes msb.
2862 clc ; get z80 carry to avr carry
2865 do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C)
2866 bmov z_flags,ZFL_C, opl,0 ; Bit 0 --> CY
2870 ;----------------------------------------------------------------
2871 ;|Mnemonic |SZHPNC|Description |Notes |
2872 ;----------------------------------------------------------------
2873 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
2874 ;|----------|SZHP C|---------- 8080 ----------------------------|
2875 ;|RLA |---- *|Rotate Left Acc. |A={CY,A}<- |
2879 ;Rotate Left. All bits move 1 to the left, the msb
2880 ;becomes c, c becomes lsb.
2884 do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C)
2885 bmov z_flags,ZFL_C, opl,7 ; Bit 7 --> CY
2889 ;----------------------------------------------------------------
2890 ;|Mnemonic |SZHPNC|Description |Notes |
2891 ;----------------------------------------------------------------
2892 ;|ADD A,s |***V0*|Add |A=A+s |
2893 ;|----------|SZHP C|---------- 8080 ----------------------------|
2894 ;|ADD A,s |***P *|Add |A=A+s |
2900 ldpmx z_flags,sz53p_tab,opl ;S,Z,P flag
2901 bmov z_flags,ZFL_C, temp,AVR_C
2905 ;----------------------------------------------------------------
2906 ;|Mnemonic |SZHPNC|Description |Notes |
2907 ;----------------------------------------------------------------
2908 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
2909 ;|----------|SZHP C|---------- 8080 ----------------------------|
2910 ;|ADC A,s |***P *|Add with Carry |A=A+s+CY |
2919 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
2920 bmov z_flags,ZFL_C, temp,AVR_C
2924 ;----------------------------------------------------------------
2925 ;|Mnemonic |SZHPNC|Description |Notes |
2926 ;----------------------------------------------------------------
2927 ;|SUB s |***V1*|Subtract |A=A-s |
2928 ;|CP s |***V1*|Compare |A-s |
2929 ;|----------|SZHP C|---------- 8080 ----------------------------|
2930 ;|SUB s |***P *|Subtract |A=A-s |
2931 ;|CP s |***P *|Compare |A-s |
2939 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
2940 bmov z_flags,ZFL_C, temp,AVR_C
2945 ;----------------------------------------------------------------
2946 ;|Mnemonic |SZHPNC|Description |Notes |
2947 ;----------------------------------------------------------------
2948 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
2949 ;|----------|SZHP C|---------- 8080 ----------------------------|
2950 ;|SBC A,s |***P *|Subtract with Carry |A=A-s-CY |
2961 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
2962 bmov z_flags,ZFL_C, temp,AVR_C
2967 ;----------------------------------------------------------------
2968 ;|Mnemonic |SZHPNC|Description |Notes |
2969 ;----------------------------------------------------------------
2970 ;|AND s |**1P00|Logical AND |A=A&s |
2971 ;|----------|SZHP C|---------- 8080 ----------------------------|
2972 ;|AND s |**-P 0|Logical AND |A=A&s |
2977 ldpmx z_flags,sz53p_tab,opl ;S,Z,P,N,C
2982 ;----------------------------------------------------------------
2983 ;|Mnemonic |SZHPNC|Description |Notes |
2984 ;----------------------------------------------------------------
2985 ;|OR s |**0P00|Logical inclusive OR |A=Avs |
2986 ;|----------|SZHP C|---------- 8080 ----------------------------|
2987 ;|OR s |**-P00|Logical inclusive OR |A=Avs |
2992 ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N,C
2996 ;----------------------------------------------------------------
2997 ;|Mnemonic |SZHPNC|Description |Notes |
2998 ;----------------------------------------------------------------
2999 ;|XOR s |**0P00|Logical Exclusive OR |A=Axs |
3000 ;|----------|SZHP C|---------- 8080 ----------------------------|
3001 ;|XOR s |**-P 0|Logical Exclusive OR |A=Axs |
3006 ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N,C
3010 ;----------------------------------------------------------------
3011 ;|Mnemonic |SZHPNC|Description |Notes |
3012 ;----------------------------------------------------------------
3013 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
3014 ;|----------|SZHP C|---------- 8080 ----------------------------|
3015 ;|ADD HL,ss |---- *|Add |HL=HL+ss |
3022 bmov z_flags,ZFL_H, temp,AVR_H
3023 bmov z_flags,ZFL_C, temp,AVR_C
3024 do_z80_flags_clear_N
3027 ;----------------------------------------------------------------
3028 ;|Mnemonic |SZHPNC|Description |Notes |
3029 ;----------------------------------------------------------------
3030 ;|LD dst,src|------|Load |dst=src |
3033 do_op_sthl: ;store hl to mem loc in opl:h
3035 #if DRAM_WORD_ACCESS
3048 ;----------------------------------------------------------------
3049 ;|Mnemonic |SZHPNC|Description |Notes |
3050 ;----------------------------------------------------------------
3051 ;|LD dst,src|------|Load |dst=src |
3056 #if DRAM_WORD_ACCESS
3068 ;----------------------------------------------------------------
3069 ;|Mnemonic |SZHPNC|Description |Notes |
3070 ;----------------------------------------------------------------
3071 ;|LD dst,src|------|Load |dst=src |
3080 ;----------------------------------------------------------------
3081 ;|Mnemonic |SZHPNC|Description |Notes |
3082 ;----------------------------------------------------------------
3083 ;|DAA |***P-*|Decimal Adjust Acc. | |
3084 ;|----------|SZHP C|---------- 8080 ----------------------------|
3088 ; Description (http://www.z80.info/z80syntx.htm#DAA):
3089 ; This instruction conditionally adjusts the accumulator for BCD addition
3090 ; and subtraction operations. For addition (ADD, ADC, INC) or subtraction
3091 ; (SUB, SBC, DEC, NEC), the following table indicates the operation performed:
3093 ; -------------------------------------------------------------------------------
3094 ; | | C Flag | HEX value in | H Flag | HEX value in | Number | C flag|
3095 ; | Operation| Before | upper digit | Before | lower digit | added | After |
3096 ; | | DAA | (bit 7-4) | DAA | (bit 3-0) | to byte | DAA |
3097 ; |-----------------------------------------------------------------------------|
3098 ; | | 0 | 0-9 | 0 | 0-9 | 00 | 0 |
3099 ; | ADD | 0 | 0-8 | 0 | A-F | 06 | 0 |
3100 ; | | 0 | 0-9 | 1 | 0-3 | 06 | 0 |
3101 ; | ADC | 0 | A-F | 0 | 0-9 | 60 | 1 |
3102 ; | | 0 | 9-F | 0 | A-F | 66 | 1 |
3103 ; | INC | 0 | A-F | 1 | 0-3 | 66 | 1 |
3104 ; | | 1 | 0-2 | 0 | 0-9 | 60 | 1 |
3105 ; | | 1 | 0-2 | 0 | A-F | 66 | 1 |
3106 ; | | 1 | 0-3 | 1 | 0-3 | 66 | 1 |
3107 ; |-----------------------------------------------------------------------------|
3108 ; | SUB | 0 | 0-9 | 0 | 0-9 | 00 | 0 |
3109 ; | SBC | 0 | 0-8 | 1 | 6-F | FA | 0 |
3110 ; | DEC | 1 | 7-F | 0 | 0-9 | A0 | 1 |
3111 ; | NEG | 1 | 6-F | 1 | 6-F | 9A | 1 |
3112 ; |-----------------------------------------------------------------------------|
3115 ; C: See instruction.
3117 ; P/V: Set if Acc. is even parity after operation, reset otherwise.
3118 ; H: See instruction.
3119 ; Z: Set if Acc. is Zero after operation, reset otherwise.
3120 ; S: Set if most significant bit of Acc. is 1 after operation, reset otherwise.
3126 ldi oph,0 ; what to add
3127 sbrc z_flags,ZFL_H ; if H-Flag
3130 andi temp,0x0f ; ... or lower digit > 9
3136 sbrc z_flags,(1<<ZFL_C)
3145 ori z_flags,(1<<ZFL_C); set C
3147 sbrs z_flags,ZFL_N ; if sub-op
3148 rjmp op_da_add ; then
3151 op_da_add: ; else add-op
3164 ori z_flags,(1<<ZFL_C)
3165 andi z_flags,(1<<ZFL_N)|(1<<ZFL_C) ; preserve C,N
3166 ldpmx temp2, sz53p_tab, opl ; get S,Z,P
3168 bmov z_flags,ZFL_H, temp,AVR_H ; H (?)
3173 sbrc z_flags,ZFL_N ; if add-op
3174 rjmp do_op_da_sub ; then
3178 cpi temp,0x0a ; if lower digit > 9
3180 ori temp2,0x06 ; add 6 to lower digit
3182 sbrc z_flags,ZFL_H ; ... or H-Flag
3192 do_op_da_c: ; else sub-op
3193 sbrc z_flags,ZFL_C ;
3195 andi z_flags, ~( (1<<ZFL_S) | (1<<ZFL_Z) | (1<<ZFL_H) )
3198 bst temp,AVR_Z ;Z-Flag
3200 bst temp,AVR_N ;S-Flag
3202 sbrc temp2,5 ;C-Flag, set if 0x06 added
3203 ori z_flags,(1<<ZFL_C) ;
3207 do_op_da_sub: ;TODO:
3212 ;----------------------------------------------------------------
3213 ;|Mnemonic |SZHPNC|Description |Notes |
3214 ;----------------------------------------------------------------
3215 ;|SCF |--0-01|Set Carry Flag |CY=1 |
3216 ;|----------|SZHP C|---------- 8080 ----------------------------|
3220 andi z_flags,~((1<<ZFL_H)|(1<<ZFL_N))
3221 ori z_flags,(1<<ZFL_C)
3224 ;----------------------------------------------------------------
3225 ;|Mnemonic |SZHPNC|Description |Notes |
3226 ;----------------------------------------------------------------
3227 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
3228 ;|----------|SZHP C|---------- 8080 ----------------------------|
3229 ;|SCF |---- 1|Set Carry Flag |CY=1 |
3233 do_z80_flags_clear_N
3238 ;----------------------------------------------------------------
3239 ;|Mnemonic |SZHPNC|Description |Notes |
3240 ;----------------------------------------------------------------
3241 ;|CPL |--1-1-|Complement |A=~A |
3242 ;|----------|SZHP C|---------- 8080 ----------------------------|
3243 ;|CPL |---- -|Complement |A=~A |
3252 ;----------------------------------------------------------------
3253 ;|Mnemonic |SZHPNC|Description |Notes |
3254 ;----------------------------------------------------------------
3255 ;|PUSH xx |------|Push |-[SP]=xx |
3256 ;|PUSH qq |------|Push |-[SP]=qq |
3264 #if DRAM_WORD_ACCESS
3283 .db ", SP is now ",0
3294 ;----------------------------------------------------------------
3295 ;|Mnemonic |SZHPNC|Description |Notes |
3296 ;----------------------------------------------------------------
3297 ;|POP xx |------|Pop |xx=[SP]+ |
3298 ;|POP qq |------|Pop |qq=[SP]+ |
3303 #if DRAM_WORD_ACCESS
3320 .db "Stack pop: val ",0
3336 ;----------------------------------------------------------------
3337 ;|Mnemonic |SZHPNC|Description |Notes |
3338 ;----------------------------------------------------------------
3339 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
3340 ;|EX DE,HL |------|Exchange |DE<->HL |
3352 ;----------------------------------------------------------------
3353 ;|Mnemonic |SZHPNC|Description |Notes |
3354 ;----------------------------------------------------------------
3356 ; TODO: Implement IFF1, IFF2
3360 ;----------------------------------------------------------------
3361 ;|Mnemonic |SZHPNC|Description |Notes |
3362 ;----------------------------------------------------------------
3364 ; TODO: Implement IFF1, IFF2
3368 ;----------------------------------------------------------------
3369 ;|Mnemonic |SZHPNC|Description |Notes |
3370 ;----------------------------------------------------------------
3371 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3372 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3373 ;|RET cc |------|Conditional Return |If cc RET |
3383 ;----------------------------------------------------------------
3384 ;|Mnemonic |SZHPNC|Description |Notes |
3385 ;----------------------------------------------------------------
3386 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3387 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3388 ;|RET cc |------|Conditional Return |If cc RET |
3398 ;----------------------------------------------------------------
3399 ;|Mnemonic |SZHPNC|Description |Notes |
3400 ;----------------------------------------------------------------
3401 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3402 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3403 ;|RET cc |------|Conditional Return |If cc RET |
3413 ;----------------------------------------------------------------
3414 ;|Mnemonic |SZHPNC|Description |Notes |
3415 ;----------------------------------------------------------------
3416 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3417 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3418 ;|RET cc |------|Conditional Return |If cc RET |
3428 ;----------------------------------------------------------------
3429 ;|Mnemonic |SZHPNC|Description |Notes |
3430 ;----------------------------------------------------------------
3431 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3432 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3433 ;|RET cc |------|Conditional Return |If cc RET |
3443 ;----------------------------------------------------------------
3444 ;|Mnemonic |SZHPNC|Description |Notes |
3445 ;----------------------------------------------------------------
3446 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3447 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3448 ;|RET cc |------|Conditional Return |If cc RET |
3458 ;----------------------------------------------------------------
3459 ;|Mnemonic |SZHPNC|Description |Notes |
3460 ;----------------------------------------------------------------
3461 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3462 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3463 ;|RET cc |------|Conditional Return |If cc RET |
3466 do_op_ifp: ;sign positive, aka s=0
3473 ;----------------------------------------------------------------
3474 ;|Mnemonic |SZHPNC|Description |Notes |
3475 ;----------------------------------------------------------------
3476 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
3477 ;|JP cc,nn |------|Conditional Jump |If cc JP |
3478 ;|RET cc |------|Conditional Return |If cc RET |
3481 do_op_ifm: ;sign negative, aka s=1
3488 ;----------------------------------------------------------------
3489 ;|Mnemonic |SZHPNC|Description |Notes |
3490 ;----------------------------------------------------------------
3491 ;|OUT [n],A |------|Output |[n]=A |
3494 ;Interface with peripherials goes here :)
3495 do_op_outa: ; out (opl),a
3498 .db 13,"Port write: ",0
3513 ;----------------------------------------------------------------
3514 ;|Mnemonic |SZHPNC|Description |Notes |
3515 ;----------------------------------------------------------------
3516 ;|IN A,[n] |------|Input |A=[n] |
3519 do_op_in: ; in a,(opl)
3522 .db 13,"Port read: (",0
3541 ;----------------------------------------------------------------
3544 .db "Invalid opcode @ PC=",0,0
3550 ;----------------------------------------------------------------
3554 ;----------------------------------------------------------------
3555 ; Lookup table, stolen from z80ex, Z80 emulation library.
3556 ; http://z80ex.sourceforge.net/
3558 ; The S, Z, 5 and 3 bits and the parity of the lookup value
3559 .org (PC+255) & 0xff00
3561 .db 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00
3562 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c
3563 .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04
3564 .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08
3565 .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24
3566 .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28
3567 .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20
3568 .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c
3569 .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04
3570 .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08
3571 .db 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00
3572 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c
3573 .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20
3574 .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c
3575 .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24
3576 .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28
3577 .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
3578 .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88
3579 .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80
3580 .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c
3581 .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0
3582 .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac
3583 .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4
3584 .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8
3585 .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80
3586 .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c
3587 .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
3588 .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88
3589 .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4
3590 .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8
3591 .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0
3592 .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac
3595 ; ----------------------- Opcode decoding -------------------------
3597 ; Lookup table for Z80 opcodes. Translates the first byte of the instruction word into three
3598 ; operations: fetch, do something, store.
3599 ; The table is made of 256 words. These 16-bit words consist of
3600 ; the fetch operation (bit 0-4), the processing operation (bit 10-16) and the store
3601 ; operation (bit 5-9).
3603 .org (PC+255) & 0xff00
3605 .dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 00 NOP
3606 .dw (FETCH_DIR16| OP_NOP | STORE_BC ) ; 01 nn nn LD BC,nn
3607 .dw (FETCH_A | OP_NOP | STORE_MBC) ; 02 LD (BC),A
3608 .dw (FETCH_BC | OP_INC16 | STORE_BC ) ; 03 INC BC
3609 .dw (FETCH_B | OP_INC | STORE_B ) ; 04 INC B
3610 .dw (FETCH_B | OP_DEC | STORE_B ) ; 05 DEC B
3611 .dw (FETCH_DIR8 | OP_NOP | STORE_B ) ; 06 nn LD B,n
3612 .dw (FETCH_A | OP_RLC | STORE_A ) ; 07 RLCA
3613 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 08 EX AF,AF' (Z80)
3614 .dw (FETCH_BC | OP_ADDHL | STORE_HL ) ; 09 ADD HL,BC
3615 .dw (FETCH_MBC | OP_NOP | STORE_A ) ; 0A LD A,(BC)
3616 .dw (FETCH_BC | OP_DEC16 | STORE_BC ) ; 0B DEC BC
3617 .dw (FETCH_C | OP_INC | STORE_C ) ; 0C INC C
3618 .dw (FETCH_C | OP_DEC | STORE_C ) ; 0D DEC C
3619 .dw (FETCH_DIR8 | OP_NOP | STORE_C ) ; 0E nn LD C,n
3620 .dw (FETCH_A | OP_RRC | STORE_A ) ; 0F RRCA
3621 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 10 oo DJNZ o (Z80)
3622 .dw (FETCH_DIR16| OP_NOP | STORE_DE ) ; 11 nn nn LD DE,nn
3623 .dw (FETCH_A | OP_NOP | STORE_MDE) ; 12 LD (DE),A
3624 .dw (FETCH_DE | OP_INC16 | STORE_DE ) ; 13 INC DE
3625 .dw (FETCH_D | OP_INC | STORE_D ) ; 14 INC D
3626 .dw (FETCH_D | OP_DEC | STORE_D ) ; 15 DEC D
3627 .dw (FETCH_DIR8 | OP_NOP | STORE_D ) ; 16 nn LD D,n
3628 .dw (FETCH_A | OP_RL | STORE_A ) ; 17 RLA
3629 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 18 oo JR o (Z80)
3630 .dw (FETCH_DE | OP_ADDHL | STORE_HL ) ; 19 ADD HL,DE
3631 .dw (FETCH_MDE | OP_NOP | STORE_A ) ; 1A LD A,(DE)
3632 .dw (FETCH_DE | OP_DEC16 | STORE_DE ) ; 1B DEC DE
3633 .dw (FETCH_E | OP_INC | STORE_E ) ; 1C INC E
3634 .dw (FETCH_E | OP_DEC | STORE_E ) ; 1D DEC E
3635 .dw (FETCH_DIR8 | OP_NOP | STORE_E ) ; 1E nn LD E,n
3636 .dw (FETCH_A | OP_RR | STORE_A ) ; 1F RRA
3637 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 20 oo JR NZ,o (Z80)
3638 .dw (FETCH_DIR16| OP_NOP | STORE_HL ) ; 21 nn nn LD HL,nn
3639 .dw (FETCH_DIR16| OP_STHL | STORE_NOP) ; 22 nn nn LD (nn),HL
3640 .dw (FETCH_HL | OP_INC16 | STORE_HL ) ; 23 INC HL
3641 .dw (FETCH_H | OP_INC | STORE_H ) ; 24 INC H
3642 .dw (FETCH_H | OP_DEC | STORE_H ) ; 25 DEC H
3643 .dw (FETCH_DIR8 | OP_NOP | STORE_H ) ; 26 nn LD H,n
3644 .dw (FETCH_A | OP_DA | STORE_A ) ; 27 DAA
3645 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 28 oo JR Z,o (Z80)
3646 .dw (FETCH_HL | OP_ADDHL | STORE_HL ) ; 29 ADD HL,HL
3647 .dw (FETCH_DIR16| OP_RMEM16 | STORE_HL ) ; 2A nn nn LD HL,(nn)
3648 .dw (FETCH_HL | OP_DEC16 | STORE_HL ) ; 2B DEC HL
3649 .dw (FETCH_L | OP_INC | STORE_L ) ; 2C INC L
3650 .dw (FETCH_L | OP_DEC | STORE_L ) ; 2D DEC L
3651 .dw (FETCH_DIR8 | OP_NOP | STORE_L ) ; 2E nn LD L,n
3652 .dw (FETCH_A | OP_CPL | STORE_A ) ; 2F CPL
3653 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 30 oo JR NC,o (Z80)
3654 .dw (FETCH_DIR16| OP_NOP | STORE_SP ) ; 31 nn nn LD SP,nn
3655 .dw (FETCH_DIR16| OP_NOP | STORE_AM ) ; 32 nn nn LD (nn),A
3656 .dw (FETCH_SP | OP_INC16 | STORE_SP ) ; 33 INC SP
3657 .dw (FETCH_MHL | OP_INC | STORE_MHL) ; 34 INC (HL)
3658 .dw (FETCH_MHL | OP_DEC | STORE_MHL) ; 35 DEC (HL)
3659 .dw (FETCH_DIR8 | OP_NOP | STORE_MHL) ; 36 nn LD (HL),n
3660 .dw (FETCH_NOP | OP_SCF | STORE_NOP) ; 37 SCF
3661 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; 38 oo JR C,o (Z80)
3662 .dw (FETCH_SP | OP_ADDHL | STORE_HL ) ; 39 ADD HL,SP
3663 .dw (FETCH_DIR16| OP_RMEM8 | STORE_A ) ; 3A nn nn LD A,(nn)
3664 .dw (FETCH_SP | OP_DEC16 | STORE_SP ) ; 3B DEC SP
3665 .dw (FETCH_A | OP_INC | STORE_A ) ; 3C INC A
3666 .dw (FETCH_A | OP_DEC | STORE_A ) ; 3D DEC A
3667 .dw (FETCH_DIR8 | OP_NOP | STORE_A ) ; 3E nn LD A,n
3668 .dw (FETCH_NOP | OP_CCF | STORE_NOP) ; 3F CCF (Complement Carry Flag, gvd)
3669 .dw (FETCH_B | OP_NOP | STORE_B ) ; 40 LD B,r
3670 .dw (FETCH_C | OP_NOP | STORE_B ) ; 41 LD B,r
3671 .dw (FETCH_D | OP_NOP | STORE_B ) ; 42 LD B,r
3672 .dw (FETCH_E | OP_NOP | STORE_B ) ; 43 LD B,r
3673 .dw (FETCH_H | OP_NOP | STORE_B ) ; 44 LD B,r
3674 .dw (FETCH_L | OP_NOP | STORE_B ) ; 45 LD B,r
3675 .dw (FETCH_MHL | OP_NOP | STORE_B ) ; 46 LD B,r
3676 .dw (FETCH_A | OP_NOP | STORE_B ) ; 47 LD B,r
3677 .dw (FETCH_B | OP_NOP | STORE_C ) ; 48 LD C,r
3678 .dw (FETCH_C | OP_NOP | STORE_C ) ; 49 LD C,r
3679 .dw (FETCH_D | OP_NOP | STORE_C ) ; 4A LD C,r
3680 .dw (FETCH_E | OP_NOP | STORE_C ) ; 4B LD C,r
3681 .dw (FETCH_H | OP_NOP | STORE_C ) ; 4C LD C,r
3682 .dw (FETCH_L | OP_NOP | STORE_C ) ; 4D LD C,r
3683 .dw (FETCH_MHL | OP_NOP | STORE_C ) ; 4E LD C,r
3684 .dw (FETCH_A | OP_NOP | STORE_C ) ; 4F LD C,r
3685 .dw (FETCH_B | OP_NOP | STORE_D ) ; 50 LD D,r
3686 .dw (FETCH_C | OP_NOP | STORE_D ) ; 51 LD D,r
3687 .dw (FETCH_D | OP_NOP | STORE_D ) ; 52 LD D,r
3688 .dw (FETCH_E | OP_NOP | STORE_D ) ; 53 LD D,r
3689 .dw (FETCH_H | OP_NOP | STORE_D ) ; 54 LD D,r
3690 .dw (FETCH_L | OP_NOP | STORE_D ) ; 55 LD D,r
3691 .dw (FETCH_MHL | OP_NOP | STORE_D ) ; 56 LD D,r
3692 .dw (FETCH_A | OP_NOP | STORE_D ) ; 57 LD D,r
3693 .dw (FETCH_B | OP_NOP | STORE_E ) ; 58 LD E,r
3694 .dw (FETCH_C | OP_NOP | STORE_E ) ; 59 LD E,r
3695 .dw (FETCH_D | OP_NOP | STORE_E ) ; 5A LD E,r
3696 .dw (FETCH_E | OP_NOP | STORE_E ) ; 5B LD E,r
3697 .dw (FETCH_H | OP_NOP | STORE_E ) ; 5C LD E,r
3698 .dw (FETCH_L | OP_NOP | STORE_E ) ; 5D LD E,r
3699 .dw (FETCH_MHL | OP_NOP | STORE_E ) ; 5E LD E,r
3700 .dw (FETCH_A | OP_NOP | STORE_E ) ; 5F LD E,r
3701 .dw (FETCH_B | OP_NOP | STORE_H ) ; 60 LD H,r
3702 .dw (FETCH_C | OP_NOP | STORE_H ) ; 61 LD H,r
3703 .dw (FETCH_D | OP_NOP | STORE_H ) ; 62 LD H,r
3704 .dw (FETCH_E | OP_NOP | STORE_H ) ; 63 LD H,r
3705 .dw (FETCH_H | OP_NOP | STORE_H ) ; 64 LD H,r
3706 .dw (FETCH_L | OP_NOP | STORE_H ) ; 65 LD H,r
3707 .dw (FETCH_MHL | OP_NOP | STORE_H ) ; 66 LD H,r
3708 .dw (FETCH_A | OP_NOP | STORE_H ) ; 67 LD H,r
3709 .dw (FETCH_B | OP_NOP | STORE_L ) ; 68 LD L,r
3710 .dw (FETCH_C | OP_NOP | STORE_L ) ; 69 LD L,r
3711 .dw (FETCH_D | OP_NOP | STORE_L ) ; 6A LD L,r
3712 .dw (FETCH_E | OP_NOP | STORE_L ) ; 6B LD L,r
3713 .dw (FETCH_H | OP_NOP | STORE_L ) ; 6C LD L,r
3714 .dw (FETCH_L | OP_NOP | STORE_L ) ; 6D LD L,r
3715 .dw (FETCH_MHL | OP_NOP | STORE_L ) ; 6E LD L,r
3716 .dw (FETCH_A | OP_NOP | STORE_L ) ; 6F LD L,r
3717 .dw (FETCH_B | OP_NOP | STORE_MHL) ; 70 LD (HL),r
3718 .dw (FETCH_C | OP_NOP | STORE_MHL) ; 71 LD (HL),r
3719 .dw (FETCH_D | OP_NOP | STORE_MHL) ; 72 LD (HL),r
3720 .dw (FETCH_E | OP_NOP | STORE_MHL) ; 73 LD (HL),r
3721 .dw (FETCH_H | OP_NOP | STORE_MHL) ; 74 LD (HL),r
3722 .dw (FETCH_L | OP_NOP | STORE_MHL) ; 75 LD (HL),r
3723 .dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 76 HALT
3724 .dw (FETCH_A | OP_NOP | STORE_MHL) ; 77 LD (HL),r
3725 .dw (FETCH_B | OP_NOP | STORE_A ) ; 78 LD A,r
3726 .dw (FETCH_C | OP_NOP | STORE_A ) ; 79 LD A,r
3727 .dw (FETCH_D | OP_NOP | STORE_A ) ; 7A LD A,r
3728 .dw (FETCH_E | OP_NOP | STORE_A ) ; 7B LD A,r
3729 .dw (FETCH_H | OP_NOP | STORE_A ) ; 7C LD A,r
3730 .dw (FETCH_L | OP_NOP | STORE_A ) ; 7D LD A,r
3731 .dw (FETCH_MHL | OP_NOP | STORE_A ) ; 7E LD A,r
3732 .dw (FETCH_A | OP_NOP | STORE_A ) ; 7F LD A,r
3733 .dw (FETCH_B | OP_ADDA | STORE_A ) ; 80 ADD A,r
3734 .dw (FETCH_C | OP_ADDA | STORE_A ) ; 81 ADD A,r
3735 .dw (FETCH_D | OP_ADDA | STORE_A ) ; 82 ADD A,r
3736 .dw (FETCH_E | OP_ADDA | STORE_A ) ; 83 ADD A,r
3737 .dw (FETCH_H | OP_ADDA | STORE_A ) ; 84 ADD A,r
3738 .dw (FETCH_L | OP_ADDA | STORE_A ) ; 85 ADD A,r
3739 .dw (FETCH_MHL | OP_ADDA | STORE_A ) ; 86 ADD A,r
3740 .dw (FETCH_A | OP_ADDA | STORE_A ) ; 87 ADD A,r
3741 .dw (FETCH_B | OP_ADCA | STORE_A ) ; 88 ADC A,r
3742 .dw (FETCH_C | OP_ADCA | STORE_A ) ; 89 ADC A,r
3743 .dw (FETCH_D | OP_ADCA | STORE_A ) ; 8A ADC A,r
3744 .dw (FETCH_E | OP_ADCA | STORE_A ) ; 8B ADC A,r
3745 .dw (FETCH_H | OP_ADCA | STORE_A ) ; 8C ADC A,r
3746 .dw (FETCH_L | OP_ADCA | STORE_A ) ; 8D ADC A,r
3747 .dw (FETCH_MHL | OP_ADCA | STORE_A ) ; 8E ADC A,r
3748 .dw (FETCH_A | OP_ADCA | STORE_A ) ; 8F ADC A,r
3749 .dw (FETCH_B | OP_SUBFA | STORE_A ) ; 90 SUB A,r
3750 .dw (FETCH_C | OP_SUBFA | STORE_A ) ; 91 SUB A,r
3751 .dw (FETCH_D | OP_SUBFA | STORE_A ) ; 92 SUB A,r
3752 .dw (FETCH_E | OP_SUBFA | STORE_A ) ; 93 SUB A,r
3753 .dw (FETCH_H | OP_SUBFA | STORE_A ) ; 94 SUB A,r
3754 .dw (FETCH_L | OP_SUBFA | STORE_A ) ; 95 SUB A,r
3755 .dw (FETCH_MHL | OP_SUBFA | STORE_A ) ; 96 SUB A,r
3756 .dw (FETCH_A | OP_SUBFA | STORE_A ) ; 97 SUB A,r
3757 .dw (FETCH_B | OP_SBCFA | STORE_A ) ; 98 SBC A,r
3758 .dw (FETCH_C | OP_SBCFA | STORE_A ) ; 99 SBC A,r
3759 .dw (FETCH_D | OP_SBCFA | STORE_A ) ; 9A SBC A,r
3760 .dw (FETCH_E | OP_SBCFA | STORE_A ) ; 9B SBC A,r
3761 .dw (FETCH_H | OP_SBCFA | STORE_A ) ; 9C SBC A,r
3762 .dw (FETCH_L | OP_SBCFA | STORE_A ) ; 9D SBC A,r
3763 .dw (FETCH_MHL | OP_SBCFA | STORE_A ) ; 9E SBC A,r
3764 .dw (FETCH_A | OP_SBCFA | STORE_A ) ; 9F SBC A,r
3765 .dw (FETCH_B | OP_ANDA | STORE_A ) ; A0 AND A,r
3766 .dw (FETCH_C | OP_ANDA | STORE_A ) ; A1 AND A,r
3767 .dw (FETCH_D | OP_ANDA | STORE_A ) ; A2 AND A,r
3768 .dw (FETCH_E | OP_ANDA | STORE_A ) ; A3 AND A,r
3769 .dw (FETCH_H | OP_ANDA | STORE_A ) ; A4 AND A,r
3770 .dw (FETCH_L | OP_ANDA | STORE_A ) ; A5 AND A,r
3771 .dw (FETCH_MHL | OP_ANDA | STORE_A ) ; A6 AND A,r
3772 .dw (FETCH_A | OP_ANDA | STORE_A ) ; A7 AND A,r
3773 .dw (FETCH_B | OP_XORA | STORE_A ) ; A8 XOR A,r
3774 .dw (FETCH_C | OP_XORA | STORE_A ) ; A9 XOR A,r
3775 .dw (FETCH_D | OP_XORA | STORE_A ) ; AA XOR A,r
3776 .dw (FETCH_E | OP_XORA | STORE_A ) ; AB XOR A,r
3777 .dw (FETCH_H | OP_XORA | STORE_A ) ; AC XOR A,r
3778 .dw (FETCH_L | OP_XORA | STORE_A ) ; AD XOR A,r
3779 .dw (FETCH_MHL | OP_XORA | STORE_A ) ; AE XOR A,r
3780 .dw (FETCH_A | OP_XORA | STORE_A ) ; AF XOR A,r
3781 .dw (FETCH_B | OP_ORA | STORE_A ) ; B0 OR A,r
3782 .dw (FETCH_C | OP_ORA | STORE_A ) ; B1 OR A,r
3783 .dw (FETCH_D | OP_ORA | STORE_A ) ; B2 OR A,r
3784 .dw (FETCH_E | OP_ORA | STORE_A ) ; B3 OR A,r
3785 .dw (FETCH_H | OP_ORA | STORE_A ) ; B4 OR A,r
3786 .dw (FETCH_L | OP_ORA | STORE_A ) ; B5 OR A,r
3787 .dw (FETCH_MHL | OP_ORA | STORE_A ) ; B6 OR A,r
3788 .dw (FETCH_A | OP_ORA | STORE_A ) ; B7 OR A,r
3789 .dw (FETCH_B | OP_SUBFA | STORE_NOP) ; B8 CP A,r
3790 .dw (FETCH_C | OP_SUBFA | STORE_NOP) ; B9 CP A,r
3791 .dw (FETCH_D | OP_SUBFA | STORE_NOP) ; BA CP A,r
3792 .dw (FETCH_E | OP_SUBFA | STORE_NOP) ; BB CP A,r
3793 .dw (FETCH_H | OP_SUBFA | STORE_NOP) ; BC CP A,r
3794 .dw (FETCH_L | OP_SUBFA | STORE_NOP) ; BD CP A,r
3795 .dw (FETCH_MHL | OP_SUBFA | STORE_NOP) ; BE CP A,r
3796 .dw (FETCH_A | OP_SUBFA | STORE_NOP) ; BF CP A,r
3797 .dw (FETCH_NOP | OP_IFNZ | STORE_RET) ; C0 RET NZ
3798 .dw (FETCH_NOP | OP_POP16 | STORE_BC ) ; C1 POP BC
3799 .dw (FETCH_DIR16| OP_IFNZ | STORE_PC ) ; C2 nn nn JP NZ,nn
3800 .dw (FETCH_DIR16| OP_NOP | STORE_PC ) ; C3 nn nn JP nn
3801 .dw (FETCH_DIR16| OP_IFNZ | STORE_CALL) ; C4 nn nn CALL NZ,nn
3802 .dw (FETCH_BC | OP_PUSH16 | STORE_NOP) ; C5 PUSH BC
3803 .dw (FETCH_DIR8 | OP_ADDA | STORE_A ) ; C6 nn ADD A,n
3804 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; C7 RST 0
3805 .dw (FETCH_NOP | OP_IFZ | STORE_RET) ; C8 RET Z
3806 .dw (FETCH_NOP | OP_NOP | STORE_RET) ; C9 RET
3807 .dw (FETCH_DIR16| OP_IFZ | STORE_PC ) ; CA nn nn JP Z,nn
3808 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; CB (Z80 specific)
3809 .dw (FETCH_DIR16| OP_IFZ | STORE_CALL) ; CC nn nn CALL Z,nn
3810 .dw (FETCH_DIR16| OP_NOP | STORE_CALL) ; CD nn nn CALL nn
3811 .dw (FETCH_DIR8 | OP_ADCA | STORE_A ) ; CE nn ADC A,n
3812 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; CF RST 8H
3813 .dw (FETCH_NOP | OP_IFNC | STORE_RET) ; D0 RET NC
3814 .dw (FETCH_NOP | OP_POP16 | STORE_DE ) ; D1 POP DE
3815 .dw (FETCH_DIR16| OP_IFNC | STORE_PC ) ; D2 nn nn JP NC,nn
3816 .dw (FETCH_DIR8 | OP_OUTA | STORE_NOP) ; D3 nn OUT (n),A
3817 .dw (FETCH_DIR16| OP_IFNC | STORE_CALL) ; D4 nn nn CALL NC,nn
3818 .dw (FETCH_DE | OP_PUSH16 | STORE_NOP) ; D5 PUSH DE
3819 .dw (FETCH_DIR8 | OP_SUBFA | STORE_A ) ; D6 nn SUB n
3820 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; D7 RST 10H
3821 .dw (FETCH_NOP | OP_IFC | STORE_RET) ; D8 RET C
3822 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; D9 EXX (Z80)
3823 .dw (FETCH_DIR16| OP_IFC | STORE_PC ) ; DA nn nn JP C,nn
3824 .dw (FETCH_DIR8 | OP_IN | STORE_A ) ; DB nn IN A,(n)
3825 .dw (FETCH_DIR16| OP_IFC | STORE_CALL) ; DC nn nn CALL C,nn
3826 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; DD (Z80)
3827 .dw (FETCH_DIR8 | OP_SBCFA | STORE_A ) ; DE nn SBC A,n
3828 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; DF RST 18H
3829 .dw (FETCH_NOP | OP_IFPO | STORE_RET) ; E0 RET PO
3830 .dw (FETCH_NOP | OP_POP16 | STORE_HL ) ; E1 POP HL
3831 .dw (FETCH_DIR16| OP_IFPO | STORE_PC ) ; E2 nn nn JP PO,nn
3832 .dw (FETCH_MSP | OP_EXHL | STORE_MSP) ; E3 EX (SP),HL
3833 .dw (FETCH_DIR16| OP_IFPO | STORE_CALL) ; E4 nn nn CALL PO,nn
3834 .dw (FETCH_HL | OP_PUSH16 | STORE_NOP) ; E5 PUSH HL
3835 .dw (FETCH_DIR8 | OP_ANDA | STORE_A ) ; E6 nn AND n
3836 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; E7 RST 20H
3837 .dw (FETCH_NOP | OP_IFPE | STORE_RET) ; E8 RET PE
3838 .dw (FETCH_HL | OP_NOP | STORE_PC ) ; E9 JP (HL)
3839 .dw (FETCH_DIR16| OP_IFPE | STORE_PC ) ; EA nn nn JP PE,nn
3840 .dw (FETCH_DE | OP_EXHL | STORE_DE ) ; EB EX DE,HL
3841 .dw (FETCH_DIR16| OP_IFPE | STORE_CALL) ; EC nn nn CALL PE,nn
3842 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; ED (Z80 specific)
3843 .dw (FETCH_DIR8 | OP_XORA | STORE_A ) ; EE nn XOR n
3844 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; EF RST 28H
3845 .dw (FETCH_NOP | OP_IFP | STORE_RET) ; F0 RET P
3846 .dw (FETCH_NOP | OP_POP16 | STORE_AF ) ; F1 POP AF
3847 .dw (FETCH_DIR16| OP_IFP | STORE_PC ) ; F2 nn nn JP P,nn
3848 .dw (FETCH_NOP | OP_DI | STORE_NOP) ; F3 DI
3849 .dw (FETCH_DIR16| OP_IFP | STORE_CALL) ; F4 nn nn CALL P,nn
3850 .dw (FETCH_AF | OP_PUSH16 | STORE_NOP) ; F5 PUSH AF
3851 .dw (FETCH_DIR8 | OP_ORA | STORE_A ) ; F6 nn OR n
3852 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; F7 RST 30H
3853 .dw (FETCH_NOP | OP_IFM | STORE_RET) ; F8 RET M
3854 .dw (FETCH_HL | OP_NOP | STORE_SP ) ; F9 LD SP,HL
3855 .dw (FETCH_DIR16| OP_IFM | STORE_PC ) ; FA nn nn JP M,nn
3856 .dw (FETCH_NOP | OP_EI | STORE_NOP) ; FB EI
3857 .dw (FETCH_DIR16| OP_IFM | STORE_CALL) ; FC nn nn CALL M,nn
3858 .dw (FETCH_NOP | OP_INV | STORE_NOP) ; FD (Z80 specific)
3859 .dw (FETCH_DIR8 | OP_SUBFA | STORE_NOP) ; FE nn CP n
3860 .dw (FETCH_RST | OP_NOP | STORE_CALL) ; FF RST 38H
3862 ; vim:set ts=8 noet nowrap