X-Git-Url: http://cloudbase.mooo.com/gitweb/avrcpm.git/blobdiff_plain/e7a0f4030d1a41cb3e95ce226ba3ab0fc73c158f..989795411ee623d1811073698620c97c467acc86:/avr/Z80int-jmp.asm diff --git a/avr/Z80int-jmp.asm b/avr/Z80int-jmp.asm index a172c92..442650b 100644 --- a/avr/Z80int-jmp.asm +++ b/avr/Z80int-jmp.asm @@ -25,63 +25,56 @@ ; #if EM_Z80 - #define OPC_TABSTART 0x1a00 -#else - #define OPC_TABSTART 0x1200 -#endif .dseg z_regs: -z_b: .byte 1 -z_c: .byte 1 -z_d: .byte 1 -z_e: .byte 1 -z_h: .byte 1 -z_l: .byte 1 - - .equ oz_b = 0 - .equ oz_c = 1 - .equ oz_d = 2 - .equ oz_e = 3 - .equ oz_h = 4 - .equ oz_l = 5 - - -#if EM_Z80 -z_b2: .byte 1 -z_c2: .byte 1 -z_d2: .byte 1 -z_e2: .byte 1 -z_h2: .byte 1 -z_l2: .byte 1 -z_f2: .byte 1 -z_a2: .byte 1 - .equ r2ofs = z_b2-z_b - .equ oz_b2 = 6 - .equ oz_c2 = 7 - .equ oz_d2 = 8 - .equ oz_e2 = 9 - .equ oz_h2 = 10 - .equ oz_l2 = 11 - .equ oz_f2 = 12 - .equ oz_a2 = 13 - -z_xh: .byte 1 -z_xl: .byte 1 -z_yh: .byte 1 -z_yl: .byte 1 - -z_i: .byte 1 -z_r: .byte 1 - .equ oz_xh = 14 - .equ oz_xl = 15 - .equ oz_yh = 16 - .equ oz_yl = 17 - .equ oz_i = 18 - .equ oz_r = 19 - -z_istat: .byte 1 - .equ oz_istat = 20 +z_c2: + .equ oz_c2 = z_c2 - z_regs + .byte 1 +z_b2: + .equ oz_b2 = z_b2 - z_regs + .byte 1 +z_e2: + .equ oz_e2 = z_e2 - z_regs + .byte 1 +z_d2: + .equ oz_d2 = z_d2 - z_regs + .byte 1 +z_l2: + .equ oz_l2 = z_l2 - z_regs + .byte 1 +z_h2: + .equ oz_h2 = z_h2 - z_regs + .byte 1 +z_f2: + .equ oz_f2 = z_f2 - z_regs + .byte 1 +z_a2: + .equ oz_a2 = z_a2 - z_regs + .byte 1 + +z_xl: + .equ oz_xl = z_xl - z_regs + .byte 1 +z_xh: + .equ oz_xh = z_xh - z_regs + .byte 1 +z_yl: + .equ oz_yl = z_yl - z_regs + .byte 1 +z_yh: + .equ oz_yh = z_yh - z_regs + .byte 1 +z_i: + .equ oz_i = z_i - z_regs + .byte 1 +z_r: + .equ oz_r = z_r - z_regs + .byte 1 + +z_istat: + .equ oz_istat = z_istat - z_regs + .byte 1 .equ IM_MASK = 0x03 ;Mask IM 0..2 .equ IM0 = 0 @@ -90,7 +83,6 @@ z_istat: .byte 1 .equ IFF1 = 2 ;IFF1 Flag .equ IFF2 = 3 ;IFF2 Flag - #endif .cseg @@ -100,7 +92,6 @@ z80_init: ldiw z_pc,IPLADDR ldiw y,z_regs - cbi flags,trace clr intstat printnewline @@ -130,7 +121,7 @@ noprintpc: ;TODO: hier kommt die Interruptbehandlung rein - cpse intstat,_0 ;fast path if no trace, int, break, ... + cpse intstat,_0 ;Fast path if no trace, int, break, ... rjmp int_test int_instr: @@ -143,6 +134,8 @@ int_instr: int_test: sbrs intstat,i_trace rjmp int_notrace + sbrc intstat,i_halt + rjmp int_notrace cpi z_pch,DBG_TRACE_BOTTOM brlo int_notrace cpi z_pch,DBG_TRACE_TOP @@ -158,39 +151,84 @@ int_notrace: mov z_pch,_0 int_nobreak: - rjmp int_instr ;continue with normal instruction interpretation + rjmp int_instr ;Continue with normal instruction interpretation ;-------------------------------------------------- ; init opcode table ; -; opctable opc_name +; opctable opc_name, pos ; -#if EM_Z80 - .equ numtabs_ = 5 -#else - .equ numtabs_ = 1 -#endif .macro opctable + + .set opcjmp_table_pos_ = (@1 + 255) & -0x100 ;0xff00 + .ifndef opc_tabnext_ - .if OPC_TABSTART & 0x00ff - .error "OPC_TABSTART is not page aligned!" - .endif - .set opc_tabnext_ = OPC_TABSTART - .equ opc_tablow_ = opc_tabnext_ - .equ opc_tabend_ = opc_tablow_ + (256 * numtabs_) + 128 - .equ sz53p_table_pos = opc_tablow_ + (256 * numtabs_) + .set opc_tabnext_ = opcjmp_table_pos_ + + .set opc_tablow_0 = 0 + .set opc_tablen_0 = 0 + .set opc_tablow_1 = 0 + .set opc_tablen_1 = 0 .endif - .set opcjmp_table_pos_ = opc_tabnext_ - .set opc_tabnext_ = opc_tabnext_ + 256 + .if opcjmp_table_pos_ < opc_tabnext_ + .set opcjmp_table_pos_ = opc_tabnext_ + .endif + + .if opc_tablow_0 == 0 + .set opc_tablow_0 = opcjmp_table_pos_ + .set opc_tablen_0 = 256 +;.message "add tab_0" + .elif opc_tablow_1 == 0 + .if (opc_tablow_0 + opc_tablen_0) == opcjmp_table_pos_ + .set opc_tablen_0 = opc_tablen_0 + 256 +;.message " tab_0++" + .else + .set opc_tablow_1 = opcjmp_table_pos_ + .set opc_tablen_1 = 256 +;.message "add tab_1" + .endif + .else + .if (opc_tablow_1 + opc_tablen_1) == opcjmp_table_pos_ + .set opc_tablen_1 = opc_tablen_1 + 256 +;.message "tab_1++" + .else + .error "Tab full_" + .endif + .endif + .set opc_tabnext_ = opcjmp_table_pos_ + 256 .equ @0 = opcjmp_table_pos_ - .set todo_table_pos_ = 0 +.endm +;-------------------------------------------------- +; +; checkspace frompos, size +; +.macro checkspace + + .ifdef opc_tablow_0 + .if @0 <= opc_tablow_0 + .if (@0 + @1) > opc_tablow_0 + .org opc_tablow_0 + opc_tablen_0 +; .message "skip tab, remove tab_0" + .if opc_tablow_1 == 0 + .set opc_tablow_0 = 0 + .set opc_tablen_0 = 0 + .else + .set opc_tablow_0 = opc_tablow_1 + .set opc_tablen_0 = opc_tablen_1 + .set opc_tablow_1 = 0 + .set opc_tablen_1 = 0 +; .message "remove tab_1" + .endif + .endif + .endif + .endif .endm ;-------------------------------------------------- @@ -200,84 +238,60 @@ int_nobreak: ; .macro instr - .set fetch_ = (do_@0 != do_fetch_nop) ; must call or jump to fetch phase - .set op_ = (do_@1 != do_op_nop) ; must call or jump to op phase - .set store_ = (do_@2 != do_store_nop) ; must jump to store phase - .set cnt_ = fetch_ + op_ + store_ - .set longdist_ = 0 - .set pc_save_ = PC + .set fetch_ = (do_@0 != do_fetch_nop) ; must call or jump to fetch action + .set op_ = (do_@1 != do_op_nop) ; must call or jump to op action + .set store_ = (do_@2 != do_store_nop) ; must jump to store action + .set cnt_ = fetch_ + op_ + store_ ; number of actions for this instruction - .org opcjmp_table_pos_ - .set opcjmp_table_pos_ = opcjmp_table_pos_ + 1 + + .set done_ = 0 + .set pc_save_ = PC .if cnt_ == 0 ; nothing to do (nop) + .org opcjmp_table_pos_ ret ; go back to main + .org pc_save_ + .set done_ = 1 .elif cnt_ == 1 ; jump direct to action - .if fetch_ ; - .if (PC - do_@0) > 2047 - .set longdist_ = 1 - .else - rjmp do_@0 ; do op and return to main - .endif - .endif - .if op_ - .if (PC - do_@1) > 2047 - .set longdist_ = 1 - .else - rjmp do_@1 ; do op and return to main - .endif - .endif - .if store_ ; - .if (PC - do_@2) > 2047 - .set longdist_ = 1 - .else - rjmp do_@2 ; do op and return to main - .endif - .endif - .endif - - .set done_ = 0 - .if (cnt_ > 1) || longdist_ - - .set labelexists_ = 0 - .if defined (l_@0_@1_@2) - .set labelexists_ = 1 + .if fetch_ + .set action_1_ = do_@0 + .elif op_ + .set action_1_ = do_@1 + .else + .set action_1_ = do_@2 .endif - ; two or tree actions - .if labelexists_ ; same combination of fetch/op/store allready present? - .if (PC - l_@0_@1_@2) <= 2047 - rjmp l_@0_@1_@2 ; generate a jump to action table - .set done_ = 1 - .endif + .if (opcjmp_table_pos_ - action_1_) <= 2047 + .org opcjmp_table_pos_ + rjmp action_1_ ; do op and return to main + .org pc_save_ + .set done_ = 1 .endif + .endif - .if !done_ - - .if todo_table_pos_ == 0 - .set todo_table_pos_ = opcjmp_table_pos_ - 2048 - .if todo_table_pos_ < pc_save_ - .set todo_table_pos_ = pc_save_ - .endif - .endif + .if !done_ - .if todo_table_pos_ < opc_tablow_ - .if todo_table_pos_ + 2*cnt_ > opc_tablow_ - .set todo_table_pos_ = opc_tabend_ - .endif - .endif + .if defined (l_@0_@1_@2) - .if labelexists_ - rjmp todo_table_pos_ - .org todo_table_pos_ + .if (opcjmp_table_pos_ - l_@0_@1_@2) <= 2047 + .org opcjmp_table_pos_ + rjmp l_@0_@1_@2 ; generate a jump to action table + .org pc_save_ + .else + checkspace pc_save_, 2 + .set pc_save_ = PC + .org opcjmp_table_pos_ + rjmp pc_save_ + .org pc_save_ jmp l_@0_@1_@2 - .set todo_table_pos_ = PC - .set done_ = 1 .endif - .endif - .if !done_ + .else + + checkspace pc_save_, 2*cnt_ + .set pc_save_ = PC - .equ l_@0_@1_@2 = todo_table_pos_ ; make a label + .org opcjmp_table_pos_ + .equ l_@0_@1_@2 = pc_save_ ; make a label rjmp l_@0_@1_@2 ; generate a jump to action table .org l_@0_@1_@2 @@ -323,16 +337,10 @@ int_nobreak: .endif .endif - .set todo_table_pos_ = PC - .endif .endif - .if todo_table_pos_ == 0 - .org pc_save_ - .else - .org todo_table_pos_ - .endif + .set opcjmp_table_pos_ = opcjmp_table_pos_ + 1 .endm @@ -342,9 +350,17 @@ do_x_nop: ; ------------ Fetch phase stuff ----------------- + fetch_ops: .equ do_fetch_nop = do_x_nop +do_fetch_rst: + movw x,z_pcl + sbiw x,1 + mem_read_d opl + andi opl,0x38 + ldi oph,0 + ret .macro m_do_fetch_a mov opl,z_a @@ -355,23 +371,25 @@ fetch_ops: ; ret .macro m_do_fetch_b - ldd opl,y+oz_b + mov opl,z_b .endm .equ do_fetch_b = 0 +; mov opl,z_b ; ldd opl,y+oz_b ; ret .macro m_do_fetch_c - ldd opl,y+oz_c + mov opl,z_c .endm .equ do_fetch_c = 0 +; mov opl,z_c ; ldd opl,y+oz_c ; ret .macro m_do_fetch_d - ldd opl,y+oz_d + mov opl,z_d .endm .equ do_fetch_d = 0 @@ -379,7 +397,7 @@ fetch_ops: ; ret .macro m_do_fetch_e - ldd opl,y+oz_e + mov opl,z_e .endm .equ do_fetch_e = 0 @@ -387,41 +405,50 @@ fetch_ops: ; ret .macro m_do_fetch_h - ldd opl,y+oz_h + mov opl,z_h .endm .equ do_fetch_h = 0 -; ldd opl,y+oz_h +; mov opl,z_h ; ret .macro m_do_fetch_l - ldd opl,y+oz_l + mov opl,z_l .endm .equ do_fetch_l = 0 -; ldd opl,y+oz_l +; mov opl,z_l ; ret do_fetch_af: - mov opl,z_flags - mov oph,z_a + movw opl,z_flags ret -do_fetch_bc: - ldd opl,y+oz_c - ldd oph,y+oz_b - ret +.macro m_do_fetch_bc + movw opl,z_c +.endm -do_fetch_de: - ldd opl,y+oz_e - ldd oph,y+oz_d - ret +.equ do_fetch_bc = 0 +; movw opl,z_c +; ret -do_fetch_hl: - ldd opl,y+oz_l - ldd oph,y+oz_h +.macro m_do_fetch_de + movw opl,z_e +.endm + +.equ do_fetch_de = 0 +; ldd opl,y+oz_e +; ldd oph,y+oz_d ret +.macro m_do_fetch_hl + movw opl,z_l +.endm + +.equ do_fetch_hl = 0 +; movw opl,z_l +; ret + .macro m_do_fetch_sp movw opl,z_spl .endm @@ -431,20 +458,19 @@ do_fetch_hl: ; ret do_fetch_mbc: - ldd xh,y+oz_b - ldd xl,y+oz_c + movw x,z_c mem_read_d z_a ret do_fetch_mde: - ldd xh,y+oz_d - ldd xl,y+oz_e + movw x,z_e +; ldd xh,y+oz_d +; ldd xl,y+oz_e mem_read_d z_a ret do_fetch_mhl: - ldd xh,y+oz_h - ldd xl,y+oz_l + movw x,z_l mem_read_d opl ret @@ -467,14 +493,6 @@ do_fetch_dir16: adiw z_pcl,1 ret -do_fetch_rst: - movw x,z_pcl - sbiw x,1 - mem_read_d opl - andi opl,0x38 - ldi oph,0 - ret - ; ------------ Store phase stuff ----------------- store_ops: @@ -490,64 +508,61 @@ do_store_a: ;.endm ;.equ do_store_b = 0 do_store_b: - std y+oz_b,opl + mov z_b,opl ret do_store_c: - std y+oz_c,opl + mov z_c,opl ret do_store_d: - std y+oz_d,opl + mov z_d,opl ret do_store_e: - std y+oz_e,opl + mov z_e,opl ret do_store_h: - std y+oz_h,opl + mov z_h,opl ret do_store_l: - std y+oz_l,opl + mov z_l,opl ret do_store_af: - mov z_a,oph - mov z_flags,opl + movw z_flags,opl ret do_store_bc: - std y+oz_b,oph - std y+oz_c,opl + movw z_c,opl ret do_store_de: - std y+oz_d,oph - std y+oz_e,opl + movw z_e,opl +; std y+oz_d,oph +; std y+oz_e,opl ret do_store_hl: - std y+oz_h,oph - std y+oz_l,opl + movw z_l,opl ret do_store_mbc: - ldd xh,y+oz_b - ldd xl,y+oz_c + movw x,z_c mem_write_s z_a ret do_store_mde: - ldd xh,y+oz_d - ldd xl,y+oz_e + movw x,z_e +; ldd xh,y+oz_d +; ldd xl,y+oz_e mem_write_s z_a ret do_store_mhl: - ldd xh,y+oz_h - ldd xl,y+oz_l + movw x,z_l mem_write_s opl ret @@ -567,6 +582,7 @@ do_store_pc: ret do_store_pcrel: ;add displacement to PC +#if EM_Z80 clr oph tst opl ;sign extend brpl stpcr1 @@ -575,7 +591,9 @@ stpcr1: add z_pcl,opl adc z_pch,oph ret - +#else + rjmp do_op_inv +#endif do_store_ret: movw x,z_spl @@ -829,7 +847,7 @@ do_store_am: ; ; ldpmx dstreg,tablebase,indexreg ; -; (6 words, 8 cycles) +; (3 words, 5 cycles) .macro ldpmx ldi zh,high(@1*2) ; table must be page aligned @@ -876,7 +894,7 @@ do_store_am: .macro do_z80_flags_copy_HC #if EM_Z80 - bmov z_flags, ZFL_H, z_flags, ZFL_H + bmov z_flags, ZFL_H, z_flags, ZFL_C #endif .endm @@ -961,11 +979,15 @@ do_op_outa: ; out (opl),a ; do_op_ina: ; in a,(opl) .if PORT_DEBUG + push opl + cp opl,_0 ; don't debug port 0 (con stat) + breq dbg_op_ina_1 printnewline printstring "Port read: (" mov temp,opl lcall printhex printstring ") -> " +dbg_op_ina_1: .endif mov temp2,opl @@ -973,8 +995,12 @@ do_op_ina: ; in a,(opl) mov z_a,temp .if PORT_DEBUG + pop temp + cp temp,_0 + breq dbg_op_ina_2 lcall printhex printstring " " +dbg_op_ina_2: .endif ret @@ -988,63 +1014,112 @@ do_op_ina: ; in a,(opl) ;|INC r |**-P0-|Increment |r=r+1 | ;|INC [HL] |**-P0-|Increment |[HL]=[HL]+1 | ; -; + do_op_inc: +#if EM_Z80 +#if 1 + andi z_flags,(1<= 0x0A)) + brlo op_da_s10 ; | +op_da_s01: ; then + ldi oph,0x06 ; add 6 to lower nibble + sub opl,oph ; + brhc PC+2 ; if + ori temp2,(1<= 0xA0) + brlo op_da_s13 ; +op_da_s12: ; + ldi oph,0x60 ; add 6 to lower nibble + sub opl,oph ; + ori temp2,(1<= 0x0A) @@ -1482,9 +1610,9 @@ op_da_a13: ori oph,0x06 ; add 0x06 mov temp,opl ; | andi temp,0x0f ; | - cpi temp,0x06 ; if (lower nibble >= 0x0A) + cpi temp,0x06 ; if (lower nibble < 0x6) brsh op_da_ae ; | - ori temp2,(1<= 0x0A) + brlo op_da_s10 ; | + ori oph,0x06 ; sub 6 + + sbrc z_flags,ZFL_C ; | + rjmp op_da_s02 ; if (C flag ... + cpi opl,0x90 ; |... or upper nibble >= 0x90) + brlo op_da_s03 ; | +op_da_s02: + ori oph,0x60 ; sub 0x60 + ori temp2,(1<= 0xA0) + brlo op_da_s13 ; +op_da_s12: + ori oph,0x60 ; sub 0x60 + ori temp2,(1<qq' (except AF)| +#if 1 + +do_op_EXX: + ldd temp ,y+oz_c2 + ldd temp2,y+oz_b2 + std y+oz_c2,z_c + std y+oz_b2,z_b + movw z_c,temp + + ldd temp ,y+oz_e2 + ldd temp2,y+oz_d2 + std y+oz_e2,z_e + std y+oz_d2,z_d + movw z_e,temp + + ldd temp ,y+oz_l2 + ldd temp2,y+oz_h2 + std y+oz_l2,z_l + std y+oz_h2,z_h + movw z_l,temp + ret +#else + do_op_EXX: ldiw z,z_b ldi temp3,6 @@ -1806,10 +2015,13 @@ opexx_loop: brne opexx_loop ret +#endif + #else do_op_djnz: do_op_EXAF: do_op_EXX: + ljmp do_op_inv ret #endif @@ -1819,6 +2031,7 @@ do_op_prefixED: mem_read_ds zl,z_pc ;zl = memReadByte(z_pc) adiw z_pcl,1 ;++z_pc ldi zh,high(EDjmp) ; +;;; ldi zh,high(0) ; ijmp @@ -1878,22 +2091,25 @@ do_op_prefixED: do_op_prefixDD: do_op_prefixFD: do_op_prefixCB: + ljmp do_op_inv ret #endif + ; ----------------------- Opcode decoding ------------------------- ; Lookup table for Z80 opcodes. Translates the first byte of the instruction word into three ; operations: fetch, do something, store. ; The table is made of 256 words. - opctable opcjmp + opctable opcjmp, PC ;+3*256 instr fetch_nop, op_nop, store_nop ;00 ;NOP instr fetch_DIR16, op_nop, store_BC ;01 nn nn ;LD BC,nn instr fetch_nop, op_nop, store_MBC ;02 ;LD (BC),A -instr fetch_BC, op_INC16, store_BC ;03 ;INC BC +;instr fetch_BC, op_INC16, store_BC ;03 ;INC BC +instr fetch_nop, op_INCBC, store_nop ;03 ;INC BC instr fetch_B, op_INC, store_B ;04 ;INC B instr fetch_B, op_DEC, store_B ;05 ;DEC B instr fetch_DIR8, op_nop, store_B ;06 ;LD B,n @@ -1901,15 +2117,17 @@ instr fetch_nop, op_RLCA, store_nop ;07 ;RLCA instr fetch_nop, op_EXAF, store_nop ;08 ;EX AF,AF' instr fetch_BC, op_ADDHL, store_nop ;09 ;ADD HL,BC instr fetch_MBC, op_nop, store_nop ;0A ;LD A,(BC) -instr fetch_BC, op_DEC16, store_BC ;0B ;DEC BC +;instr fetch_BC, op_DEC16, store_BC ;0B ;DEC BC +instr fetch_nop, op_DECBC, store_nop ;0B ;DEC BC instr fetch_C, op_INC, store_C ;0C ;INC C instr fetch_C, op_DEC, store_C ;0D ;DEC C instr fetch_DIR8, op_nop, store_C ;0E nn ;LD C,n instr fetch_nop, op_RRCA, store_nop ;0F ;RRCA -instr fetch_DIR8, op_DJNZ, store_pcrel ;10 oo ;DJNZ o +instr fetch_DIR8, op_DJNZ, store_nop ;10 oo ;DJNZ o instr fetch_DIR16, op_nop, store_DE ;11 nn nn ;LD DE,nn instr fetch_nop, op_nop, store_MDE ;12 ;LD (DE),A -instr fetch_DE, op_INC16, store_DE ;13 ;INC DE +;instr fetch_DE, op_INC16, store_DE ;13 ;INC DE +instr fetch_nop, op_INCDE, store_nop ;13 ;INC DE instr fetch_D, op_INC, store_D ;14 ;INC D instr fetch_D, op_DEC, store_D ;15 ;DEC D instr fetch_DIR8, op_nop, store_D ;16 nn ;LD D,n @@ -1917,7 +2135,8 @@ instr fetch_nop, op_RLA, store_nop ;17 ;RLA instr fetch_DIR8, op_nop, store_pcrel ;18 oo ;JR o instr fetch_DE, op_ADDHL, store_nop ;19 ;ADD HL,DE instr fetch_MDE, op_nop, store_nop ;1A ;LD A,(DE) -instr fetch_DE, op_DEC16, store_DE ;1B ;DEC DE +;instr fetch_DE, op_DEC16, store_DE ;1B ;DEC DE +instr fetch_nop, op_DECDE, store_nop ;1B ;DEC DE instr fetch_E, op_INC, store_E ;1C ;INC E instr fetch_E, op_DEC, store_E ;1D ;DEC E instr fetch_DIR8, op_nop, store_E ;1E nn ;LD E,n @@ -1925,15 +2144,17 @@ instr fetch_nop, op_RRA, store_nop ;1F ;RRA instr fetch_DIR8, op_IFNZ, store_pcrel ;20 oo ;JR NZ,o instr fetch_DIR16, op_nop, store_HL ;21 nn nn ;LD HL,nn instr fetch_DIR16, op_STHL, store_nop ;22 nn nn ;LD (nn),HL -instr fetch_HL, op_INC16, store_HL ;23 ;INC HL +;instr fetch_HL, op_INC16, store_HL ;23 ;INC HL +instr fetch_nop, op_INCHL, store_nop ;23 ;INC HL instr fetch_H, op_INC, store_H ;24 ;INC H instr fetch_H, op_DEC, store_H ;25 ;DEC H instr fetch_DIR8, op_nop, store_H ;26 nn ;LD H,n -instr fetch_A, op_DA, store_A ;27 ;DAA +instr fetch_A, op_DAA, store_A ;27 ;DAA instr fetch_DIR8, op_IFZ, store_pcrel ;28 oo ;JR Z,o instr fetch_HL, op_ADDHL, store_nop ;29 ;ADD HL,HL instr fetch_DIR16, op_RMEM16, store_HL ;2A nn nn ;LD HL,(nn) -instr fetch_HL, op_DEC16, store_HL ;2B ;DEC HL +;instr fetch_HL, op_DEC16, store_HL ;2B ;DEC HL +instr fetch_nop, op_DECHL, store_nop ;2B ;DEC HL instr fetch_L, op_INC, store_L ;2C ;INC L instr fetch_L, op_DEC, store_L ;2D ;DEC L instr fetch_DIR8, op_nop, store_L ;2E nn ;LD L,n @@ -2081,7 +2302,7 @@ instr fetch_E, op_CPFA, store_nop ;BB ;CP A,E instr fetch_H, op_CPFA, store_nop ;BC ;CP A,H instr fetch_L, op_CPFA, store_nop ;BD ;CP A,L instr fetch_MHL, op_CPFA, store_nop ;BE ;CP A,(HL) -instr fetch_A, op_CPFA, store_nop ;BF ;CP A,A +instr fetch_A, op_CPFA, store_nop ;BF ;CP A,A instr fetch_nop, op_IFNZ, store_RET ;C0 ;RET NZ instr fetch_nop, op_POP16, store_BC ;C1 ;POP BC instr fetch_DIR16, op_IFNZ, store_PC ;C2 nn nn ;JP NZ,nn @@ -2152,272 +2373,21 @@ instr fetch_RST, op_nop, store_CALL ;FF ;RST 38H -do_fetch_0: - ldi opl,0 - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|IN r,[C] |***P0-|Input |r=[C] | -; + checkspace PC, 2 -do_op_in: ; in opl,(opl) -.if PORT_DEBUG - printnewline - printstring "Port read: (" - mov temp,opl - rcall printhex - printstring ") -> " -.endif +do_op_noni: + sbiw z_pcl,1 ;--z_pc + ret - mov temp2,opl - lcall portRead - mov opl,temp - bst z_flags,ZFL_C ;save Carry - ldpmx z_flags,sz53p_tab,temp ;S,Z,P - bld z_flags,ZFL_C + checkspace PC, 16 -.if PORT_DEBUG - rcall printhex - printstring " " -.endif - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|OUT [C],r |------|Output |[C]=r | -; - -do_op_out: ; out (c),opl - mov temp,opl - ldd temp2,y+oz_c - lcall portWrite - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|LD dst,src|------|Load |dst=src | -; - -do_op_stbc: ;store bc to mem loc in opl:h - movw xl,opl - ldd temp,y+oz_c - mem_write - adiw xl,1 - ldd temp,y+oz_b - mem_write - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|LD dst,src|------|Load |dst=src | -; -; -do_op_stde: ;store de to mem loc in opl:h - movw xl,opl - ldd temp,y+oz_e - mem_write - adiw xl,1 - ldd temp,y+oz_d - mem_write - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|LD dst,src|------|Load |dst=src | -; -; -do_op_stsp: ;store sp to mem loc in opl:h - movw xl,opl - mem_write_s z_spl - adiw xl,1 - mem_write_s z_sph - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|ADC HL,ss |***V0*|Add with Carry |HL=HL+ss+CY | -; - -do_op_ADCHL: - ldd temp,y+oz_l - ldd temp2,y+oz_h - clc - sbrc z_flags,ZFL_C - sec - adc opl,temp - in temp,sreg ; save lower Z - adc oph,temp2 - in temp2,sreg - std y+oz_l,opl - std y+oz_h,oph - and temp,temp2 ; 16bit Z - ldi z_flags,0 ; clear N - bmov z_flags,ZFL_C, temp2,AVR_C - bmov z_flags,ZFL_P, temp2,AVR_V - bmov z_flags,ZFL_H, temp2,AVR_H - bmov z_flags,ZFL_Z, temp,AVR_Z - bmov z_flags,ZFL_S, temp2,AVR_N - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|SBC HL,ss |***V1*|Subtract with carry |HL=HL-ss-CY | -; -; -do_op_sbchl: - ldd temp,y+oz_l - ldd temp2,y+oz_h - cp temp,opl ; set z - clc - sbrc z_flags,ZFL_C - sec - sbc temp,opl - sbc temp2,oph - std y+oz_l,temp - std y+oz_h,temp2 - in temp,sreg - ldi z_flags,(1< P | -;|LD i,A |------|Load |(i=I,R) | - -do_op_ldai: - ldd z_a,y+oz_i - rjmp op_ldar1 - -do_op_ldar: - ldd z_a,y+oz_r -op_ldar1: - bst z_flags,ZFL_C ;save C - ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N - bld z_flags,ZFL_C ; - ldd temp,y+oz_istat - bmov z_flags,ZFL_P, temp,IFF2 - ret - -do_op_ldia: - std y+oz_i,z_a - ret - -do_op_ldra: - std y+oz_r,z_a - ret - -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##| -;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##| - -do_op_rld: - swap opl - mov oph,opl - andi opl,0xf0 - andi oph,0x0f - mov temp,z_a - andi temp,0x0f - or opl,temp - mov temp,z_a - andi temp,0xf0 - or temp,oph - mov z_a,temp - bst z_flags,ZFL_C ;save C - ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N - bld z_flags,ZFL_C ; - ret - -do_op_rrd: - mov oph,opl - andi opl,0xf0 - andi oph,0x0f - mov temp,z_a - andi temp,0x0f - or opl,temp - swap opl - mov temp,z_a - andi temp,0xf0 - or temp,oph - mov z_a,temp - bst z_flags,ZFL_C ;save C - ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N - bld z_flags,ZFL_C ; +do_fetch_dir8_2: + movw xl,z_pcl + adiw xl,1 + mem_read_d opl ret + checkspace PC, 5 do_fetch_xh: sbis flags,prefixfd @@ -2426,6 +2396,8 @@ do_fetch_xh: ldd opl,y+oz_yh ret + checkspace PC, 5 + do_fetch_xl: sbis flags,prefixfd ldd opl,y+oz_xl @@ -2434,6 +2406,8 @@ do_fetch_xl: ret + checkspace PC, 41 + do_fetch_mxx: sbic flags,prefixfd rjmp fetchmxx_fd @@ -2454,8 +2428,10 @@ fetchmxx2: add xl,opl ;add displacement adc xh,oph mem_read_d opl ;get operand - ret + ret ;(Ix+d) still in xl,xh + + checkspace PC, 8 do_fetch_xx: sbic flags,prefixfd @@ -2468,6 +2444,8 @@ fetchxx_fd: ldd oph,y+oz_yh ret + checkspace PC, 5 + do_store_xh: sbis flags,prefixfd std y+oz_xh,opl @@ -2475,6 +2453,8 @@ do_store_xh: std y+oz_yh,opl ret + checkspace PC, 5 + do_store_xl: sbis flags,prefixfd std y+oz_xl,opl @@ -2482,6 +2462,8 @@ do_store_xl: std y+oz_yl,opl ret + checkspace PC, 37 + do_store_mxx: sbic flags,prefixfd rjmp storemxx_fd @@ -2504,6 +2486,39 @@ storemxx2: mem_write_s opl ;store operand ret + checkspace PC, 10 + +do_store_mxx_0: + mem_write_s opl ;store operand + ret + + checkspace PC, 38 + +do_store_mxx_2: + sbic flags,prefixfd + rjmp storemxx2_fd + ldd xh,y+oz_xh + ldd xl,y+oz_xl + rjmp storemxx21 +storemxx2_fd: + ldd xh,y+oz_yh + ldd xl,y+oz_yl +storemxx21: + mem_read_s z_pc ;get displacement + adiw z_pcl,1 + adiw z_pcl,1 + clr temp2 ;sign extend + tst temp + brpl storemxx22 + com temp2 +storemxx22: + add xl,temp ;add displacement + adc xh,temp2 + mem_write_s opl ;store operand + ret + + checkspace PC, 8 + do_store_xx: sbic flags,prefixfd rjmp storexx_fd @@ -2520,10 +2535,12 @@ storexx_fd: ;---------------------------------------------------------------- ;|LD dst,src|------|Load |dst=src | ; -; + + checkspace PC, 30 + do_op_stxx: ;store xx to mem loc in opl:h - movw xl,opl + movw xl,opl sbis flags,prefixfd ldd temp,y+oz_xl sbic flags,prefixfd @@ -2544,6 +2561,8 @@ do_op_stxx: ;store xx to mem loc in opl:h ;|EX [SP],IX|------|Exchange |[SP]<->IX | ;|EX [SP],IY|------|Exchange |[SP]<->IY | ; + checkspace PC, 13 + do_op_EXxx: sbic flags,prefixfd rjmp opexxx_fd @@ -2567,7 +2586,9 @@ opexxxe: ;|ADD IX,pp |--*-0*|Add |IX=IX+pp | ;|ADD IY,rr |--*-0*|Add |IY=IY+rr | ; -; + + checkspace PC, 25 + do_op_addxx: sbic flags,prefixfd rjmp opadx_fd @@ -2592,181 +2613,372 @@ opadx_e: do_z80_flags_clear_N ret -;---------------------------------------------------------------- -;|Mnemonic |SZHPNC|Description |Notes | -;---------------------------------------------------------------- -;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# | -;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 | -;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# | -;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 | -; -do_op_LDD: - ldd oph,y+oz_b ;B - ldd opl,y+oz_c ;C - ldd xh,y+oz_d ;D - ldd xl,y+oz_e ;E - ldd zh,y+oz_h ;H - ldd zl,y+oz_l ;L - mem_read_ds temp, z - sbiw z,1 - mem_write_ds x, temp - sbiw x,1 - cbr z_flags,(1<m | +;|RL m |**0P0*|Rotate Left |m={CY,m}<- | +;|RR m |**0P0*|Rotate Right |m=->{CY,m} | +;|SLA m |**0P0*|Shift Left Arithmetic|m=m*2 | +;|SRA m |**0P0*|Shift Right Arith. |m=m/2 | +;|SLL m |**0P0*|Shift Right Logical | +;|SRL m |**0P0*|Shift Right Logical |m=->{0,m,CY} | + + + checkspace PC, 9 + +do_op_rlc: + ;Rotate Left Cyclical. All bits move 1 to the + ;left, the msb becomes c and lsb. + clr temp + lsl opl + adc temp,_0 + or opl,temp + ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N + or z_flags,temp ret -do_op_LDI: - ldd oph,y+oz_b ;B - ldd opl,y+oz_c ;C - ldd xh,y+oz_d ;D - ldd xl,y+oz_e ;E - ldd zh,y+oz_h ;H - ldd zl,y+oz_l ;L - mem_read_ds temp, z - adiw z,1 - mem_write_ds x, temp - adiw x,1 - cbr z_flags,(1< Bit 7 + ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N + bmov z_flags,ZFL_C, temp,AVR_C ; ret -do_op_CPD: - ldd xh,y+oz_h ;H - ldd xl,y+oz_l ;L - ldd zh,y+oz_b ;B - ldd zl,y+oz_c ;C - push zh - push zl - mem_read_ds opl, x - lcall do_op_cpfa - pop zl - pop zh - sbiw x,1 - sbiw z,1 - breq PC+2 - sbr z_flags,(1< Bit 7 + ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N + bmov z_flags,ZFL_C, temp,AVR_C ; ret -do_op_CPDR: - rcall do_op_CPD - sbrc z_flags,ZFL_Z - ret - sbrs z_flags,ZFL_P - ret - sbiw z_pcl,2 + checkspace PC, 9 + +do_op_sll: + sec + rol opl + in temp,sreg + ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N + bmov z_flags,ZFL_C, temp,AVR_C ; ret + checkspace PC, 8 + +do_op_srl: + lsr opl + in temp,sreg + ldpmx z_flags,sz53p_tab,opl ;S,Z,H,P,N + bmov z_flags,ZFL_C, temp,AVR_C ; + ret ;---------------------------------------------------------------- ;|Mnemonic |SZHPNC|Description |Notes | @@ -2775,38 +2987,46 @@ do_op_CPDR: ;|RES b,m |------|Reset bit |m=m&{~2^b} | ;|SET b,m |------|Set bit |m=mv{2^b} | -; .org ((PC+255) & 0xff00) + 0x600 - + checkspace PC, 2 do_op_BIT7: ldi temp,0x80 rjmp opbit + checkspace PC, 2 do_op_BIT6: ldi temp,0x40 rjmp opbit + checkspace PC, 2 do_op_BIT5: ldi temp,0x20 rjmp opbit + checkspace PC, 2 do_op_BIT4: ldi temp,0x10 rjmp opbit + checkspace PC, 2 do_op_BIT3: ldi temp,0x08 rjmp opbit + checkspace PC, 2 do_op_BIT2: ldi temp,0x04 rjmp opbit + checkspace PC, 2 do_op_BIT1: ldi temp,0x02 rjmp opbit + + checkspace PC, 7 do_op_BIT0: ldi temp,0x01 opbit: - and temp,opl - in temp,sreg + andi z_flags,~((1< " +dbg_op_in_1: +.endif + + mov temp2,opl + lcall portRead + mov opl,temp + bst z_flags,ZFL_C ;save Carry + ldpmx z_flags,sz53p_tab,temp ;S,Z,P + bld z_flags,ZFL_C + +.if PORT_DEBUG + pop temp + cp temp,_0 + breq dbg_op_in_2 + lcall printhex + printstring " " +dbg_op_in_2: +.endif + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|OUT [C],r |------|Output |[C]=r | +; + +do_op_out: ; out (c),opl +.if PORT_DEBUG + printnewline + printstring "Port write: " + mov temp,opl + lcall printhex + printstring " -> (" + mov temp,z_c + lcall printhex + printstring ") " +.endif + mov temp,opl + mov temp2,z_c + lcall portWrite + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|LD dst,src|------|Load |dst=src | +; + +do_op_stbc: ;store bc to mem loc in opl:h + movw xl,opl + mem_write_s z_c + adiw xl,1 + mem_write_s z_b + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|LD dst,src|------|Load |dst=src | +; +; +do_op_stde: ;store de to mem loc in opl:h + movw xl,opl + mem_write_s z_e + adiw xl,1 + mem_write_s z_d + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|LD dst,src|------|Load |dst=src | +; +; +do_op_stsp: ;store sp to mem loc in opl:h + movw xl,opl + mem_write_s z_spl + adiw xl,1 + mem_write_s z_sph + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|ADC HL,ss |***V0*|Add with Carry |HL=HL+ss+CY | +; + +do_op_ADCHL: + lsr z_flags ; ZFL_C --> Carry + ldi z_flags,0 ; clear N + adc z_l,opl + in temp,sreg ; save lower Z + adc z_h,oph + in temp2,sreg + + and temp,temp2 ; 16bit Z + bmov z_flags,ZFL_C, temp2,AVR_C + bmov z_flags,ZFL_P, temp2,AVR_V + bmov z_flags,ZFL_H, temp2,AVR_H + bmov z_flags,ZFL_Z, temp,AVR_Z + bmov z_flags,ZFL_S, temp2,AVR_N + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|SBC HL,ss |***V1*|Subtract with carry |HL=HL-ss-CY | +; + + checkspace PC, 24 + +do_op_sbchl: + lsr z_flags ; get Z80 carry + sez ; set z + sbc z_l,opl + sbc z_h,oph + in temp,sreg + ldi z_flags,(1< P | +;|LD i,A |------|Load |(i=I,R) | + +do_op_ldai: + ldd z_a,y+oz_i + rjmp op_ldar1 + +do_op_ldar: + ldd z_a,y+oz_r +op_ldar1: + bst z_flags,ZFL_C ;save C + ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N + bld z_flags,ZFL_C ; + ldd temp,y+oz_istat + bmov z_flags,ZFL_P, temp,IFF2 + ret + +do_op_ldia: + std y+oz_i,z_a + ret + +do_op_ldra: + std y+oz_r,z_a + ret + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##| +;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##| + +do_op_rld: + swap opl + mov oph,opl + andi opl,0xf0 + andi oph,0x0f + mov temp,z_a + andi temp,0x0f + or opl,temp + mov temp,z_a + andi temp,0xf0 + or temp,oph + mov z_a,temp + bst z_flags,ZFL_C ;save C + ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N + bld z_flags,ZFL_C ; + ret + +do_op_rrd: + mov oph,opl + andi opl,0xf0 + andi oph,0x0f + mov temp,z_a + andi temp,0x0f + or opl,temp + swap opl + mov temp,z_a + andi temp,0xf0 + or temp,oph + mov z_a,temp + bst z_flags,ZFL_C ;save C + ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N + bld z_flags,ZFL_C ; + ret + + +;---------------------------------------------------------------- +;|Mnemonic |SZHPNC|Description |Notes | +;---------------------------------------------------------------- +;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# | +;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 | +;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# | +;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 | +; + + checkspace PC, 13 + +op_LDxx_common: + movw x,z_l ;HL +; mem_read_ds temp, z + lcall dram_read ; temp = (HL) + movw x,z_e ;DE +; mem_write_ds x, temp + lcall dram_write ; (DE) = temp + + cbr z_flags,(1<