diff --git a/src/cpu/drz80/DrZ80.s b/src/cpu/drz80/DrZ80.s index 3357003..9b474e3 100644 --- a/src/cpu/drz80/DrZ80.s +++ b/src/cpu/drz80/DrZ80.s @@ -13,9 +13,9 @@ .global DrZ80Run .global DrZ80Ver - + .equiv INTERRUPT_DOZE, 1 ;@0 = Use internal int handler, 1 = Use Doze int handler - + DrZ80Ver: .long 0x0001 ;@ --------------------------- Defines ---------------------------- @@ -29,12 +29,12 @@ DrZ80Ver: .long 0x0001 z80bc .req r9 z80de .req r10 z80hl .req r11 - z80sp .req r12 + z80sp .req r12 z80xx .req lr .equ z80a_pointer, 0 ;@ 0 .equ z80f_pointer, z80a_pointer+4 ;@ 4 - .equ z80bc_pointer, z80f_pointer+4 ;@ + .equ z80bc_pointer, z80f_pointer+4 ;@ .equ z80de_pointer, z80bc_pointer+4 .equ z80hl_pointer, z80de_pointer+4 .equ z80pc_pointer, z80hl_pointer+4 @@ -48,8 +48,8 @@ DrZ80Ver: .long 0x0001 .equ z80f2, z80a2+4 .equ z80bc2, z80f2+4 .equ z80de2, z80bc2+4 - .equ z80hl2, z80de2+4 - .equ z80irq, z80hl2+4 + .equ z80hl2, z80de2+4 + .equ z80irq, z80hl2+4 .equ z80if, z80irq+1 .equ z80im, z80if+1 .equ z80spare, z80im+1 @@ -70,13 +70,13 @@ DrZ80Ver: .long 0x0001 .equ z80_read16, z80_read8+4 .equ z80_rebaseSP, z80_read16+4 .equ z80_rebasePC, z80_rebaseSP+4 - + .equ ppMemFetch, z80_rebasePC+4 .equ ppMemFetchData, ppMemFetch+4 .equ ppMemRead, ppMemFetchData+4 .equ ppMemWrite, ppMemRead+4 .equ debugCallback, ppMemWrite+4 - + .equ VFlag, 0 .equ CFlag, 1 .equ ZFlag, 2 @@ -110,17 +110,17 @@ DrZ80Ver: .long 0x0001 .macro DAM_READ8 jpname ;@ r0 = addr stmdb sp!,{r3,r12} - + ;@str z80pc,[cpucontext,#z80pc_pointer] ;@ save pc for debug only - + ldr r3,[cpucontext,#ppMemRead] ;@ r3 point to ppMemRead[0] - mov r2,r0,lsr#8 + mov r2,r0,lsr#8 ldr r3,[r3,r2,lsl#2] ;@ r3 = ppMemRead[addr >> 8] - + cmp r3,#0 ldrneb r0,[r3,r0] bne read8_end_\jpname - + mov lr,pc ;@ call z80_read8(r0, r1) ldr pc,[cpucontext,#z80_read8] read8_end_\jpname: @@ -131,13 +131,13 @@ read8_end_\jpname: ;@ r0 = addr stmdb sp!,{r0,r3,r12} ldr r3,[cpucontext,#ppMemRead] ;@ r3 point to ppMemRead[0] - mov r2,r0,lsr#8 + mov r2,r0,lsr#8 ldr r3,[r3,r2,lsl#2] ;@ r3 = ppMemRead[addr >> 8] - + cmp r3,#0 ldrneb r0,[r3,r0] bne read8r1_end_\jpname - + mov lr,pc ;@ call z80_read8(r0, r1) ldr pc,[cpucontext,#z80_read8] read8r1_end_\jpname: @@ -147,14 +147,14 @@ read8r1_end_\jpname: .macro DAM_READ16 jpname ;@ r0 = addr stmdb sp!,{r3,r12} - + ldr r3,[cpucontext,#ppMemRead] ;@ r3 point to ppMemRead[0] - mov r2,r0,lsr#8 + mov r2,r0,lsr#8 ldr r3,[r3,r2,lsl#2] ;@ r3 = ppMemRead[addr >> 8] - + cmp r3,#0 beq read16_call_\jpname - + add r3,r3,r0 ldrb r0,[r3],#1 ldrb r1,[r3] @@ -164,7 +164,7 @@ read8r1_end_\jpname: read16_call_\jpname: ;@ str z80pc,[cpucontext,#z80pc_pointer] - + mov lr,pc ;@ call z80_read8(r0, r1) ldr pc,[cpucontext,#z80_read16] read16_end_\jpname: @@ -176,22 +176,22 @@ read16_end_\jpname: ;@ r0 = data, r1 = addr stmdb sp!,{r3,r12} ldr r3,[cpucontext,#ppMemWrite] ;@ r3 point to ppMemWrite[0] - mov r2,r1,lsr#8 + mov r2,r1,lsr#8 ldr r3,[r3,r2,lsl#2] ;@ r3 = ppMemWrite[addr >> 8] - + cmp r3,#0 strneb r0,[r3,r1] bne write8_end_\jpname - + mov r2,r1 ;@ swp r1, r0 mov r1,r0 mov r0,r2 - + ;@str z80_icount,[cpucontext,#nCyclesLeft] - + mov lr,pc ;@ call z80_write8(r0, r1) ldr pc,[cpucontext,#z80_write8] - + write8_end_\jpname: ldmia sp!,{r3,r12} .endm @@ -200,20 +200,20 @@ write8_end_\jpname: ;@ r0 = data, r1 = addr stmdb sp!,{r3,r12} ldr r3,[cpucontext,#ppMemWrite] ;@ r3 point to ppMemWrite[0] - mov r2,r1,lsr#8 + mov r2,r1,lsr#8 ldr r3,[r3,r2,lsl#2] ;@ r3 = ppMemWrite[addr >> 8] - + cmp r3,#0 addne r3,r3,r1 movne r2,r0,lsr#8 strneb r0,[r3],#1 strneb r2,[r3] bne write16_end_\jpname - + ;@ str z80pc,[cpucontext,#z80pc_pointer] mov lr,pc ;@ call z80_write8(r0, r1) ldr pc,[cpucontext,#z80_write16] - + write16_end_\jpname: ldmia sp!,{r3,r12} .endm @@ -223,9 +223,9 @@ write16_end_\jpname: ldr r2,[cpucontext,#z80pc_base] ;@ r2 = z80 pc sub r2,z80pc,r2 ldr r1,[cpucontext,#ppMemFetch] ;@ r1 point to ppMemFetchData[0] - mov r0,r2,lsr#8 + mov r0,r2,lsr#8 ldr r1,[r1,r0,lsl#2] ;@ r1 = ppMemFetchData[addr >> 8] - + ldrb r0,[r1,r2] add z80pc,z80pc,#1 .endm @@ -235,22 +235,22 @@ write16_end_\jpname: ldr r2,[cpucontext,#z80pc_base] ;@ r2 = z80 pc sub r2,z80pc,r2 ldr r1,[cpucontext,#ppMemFetchData] ;@ r1 point to ppMemFetchData[0] - mov r0,r2,lsr#8 + mov r0,r2,lsr#8 ldr r1,[r1,r0,lsl#2] ;@ r1 = ppMemFetchData[addr >> 8] - + ldrb \reg,[r1,r2] add z80pc,z80pc,#1 .endm .macro DAM_FETCH8D_S inc_pc ;@ldrb r0,[z80pc],#1 - + ldr r2,[cpucontext,#z80pc_base] ;@ r2 = z80 pc sub r2,z80pc,r2 ldr r1,[cpucontext,#ppMemFetchData] ;@ r1 point to ppMemFetchData[0] - mov r0,r2,lsr#8 + mov r0,r2,lsr#8 ldr r1,[r1,r0,lsl#2] ;@ r1 = ppMemFetchData[addr >> 8] - + ldrsb r0,[r1,r2] add z80pc,z80pc,#\inc_pc .endm @@ -263,9 +263,9 @@ write16_end_\jpname: ldr r2,[cpucontext,#z80pc_base] ;@ r2 = z80 pc sub r2,z80pc,r2 ldr r1,[cpucontext,#ppMemFetchData] ;@ r1 point to ppMemFetchData[0] - mov r0,r2,lsr#8 + mov r0,r2,lsr#8 ldr r1,[r1,r0,lsl#2] ;@ r1 = ppMemFetchData[addr >> 8] - + ldrb r0,[r1,r2] add r2,r2,#1 ldrb r1,[r1,r2] @@ -279,25 +279,27 @@ write16_end_\jpname: ;@ldr pc,[cpucontext,#z80_rebasePC] ;@ r0=new pc - external function sets z80pc_base and returns new z80pc in r0 ;@ldmia sp!,{r3,r12} ;@mov z80pc,r0 - + ldr r1,[cpucontext,#ppMemFetch] mov r2,r0,lsr#8 ldr r1,[r1,r2,lsl#2] - + str r1,[cpucontext,#z80pc_base] add z80pc,r1,r0 .endm .macro PUSH_r0 dec_sp sub z80sp,z80sp,#\dec_sp + bic z80sp,#0xFF000000 + bic z80sp,#0xFF0000 ldr r2,[cpucontext,#ppMemWrite] - mov r1,z80sp,lsr#8 + mov r1,z80sp,lsr#8 ldr r1,[r2,r1,lsl#2] - + cmp r1,#0 beq end_loop - + add r1,r1,z80sp mov r2,r0,lsr#8 strb r0,[r1],#1 @@ -306,33 +308,33 @@ write16_end_\jpname: .macro POP_r0 inc_sp ldr r2,[cpucontext,#ppMemRead] - mov r1,z80sp,lsr#8 + mov r1,z80sp,lsr#8 ldr r1,[r2,r1,lsl#2] - + cmp r1,#0 beq end_loop - + add r2,r1,z80sp ldrb r0,[r2],#1 ldrb r1,[r2] - orr r0,r0,r1,lsl #8 - + orr r0,r0,r1,lsl #8 + add z80sp,z80sp,#\inc_sp .endm .macro POP_r0_r1 ldr r2,[cpucontext,#ppMemRead] - mov r1,z80sp,lsr#8 + mov r1,z80sp,lsr#8 ldr r1,[r2,r1,lsl#2] - + cmp r1,#0 beq end_loop - + add r2,r1,z80sp ldrb r0,[r2],#1 ldrb r1,[r2] - ;@orr r0,r0,r1,lsl #8 - + ;@orr r0,r0,r1,lsl #8 + add z80sp,z80sp,#2 .endm @@ -340,8 +342,8 @@ write16_end_\jpname: DrZ80Run: ;@ r0 = pointer to cpu context - ;@ r1 = ISTATES to execute - ;@######################################### + ;@ r1 = ISTATES to execute + ;@######################################### stmdb sp!,{r4-r12,lr} ;@ save registers on stack mov cpucontext,r0 ;@ setup main memory pointer ldr z80a,[cpucontext,#z80a_pointer] ;@ load Z80 registers @@ -352,22 +354,22 @@ DrZ80Run: ldr z80sp,[cpucontext,#z80sp_pointer] ldr z80pc,[cpucontext,#z80pc_pointer] - - + + mov z80_icount,r1 ;@ setup number of Tstates to execute ldr opcodes,MAIN_opcodes_POINTER2 - + .if INTERRUPT_DOZE == 0 ;@ check ints - bl DoInterrupt + bl DoInterrupt .endif - + ldrb r0,[z80pc],#1 ;@ get first op code ldr pc,[opcodes,r0, lsl #2] ;@ execute op code - + MAIN_opcodes_POINTER2: .word MAIN_opcodes - + z80_execute_end: ;@ save registers in CPU context str z80a,[cpucontext,#z80a_pointer] @@ -384,158 +386,158 @@ z80_execute_end: DAATable: .hword (0x00<<8)|(1< r1 sub r0,z80pc,r0 + @bic r0,#0xff000000 + @bic r0,#0xff0000 PUSH_r0 2 ldmia sp!,{r0} ;@ pop new pc @@ -4888,7 +4883,7 @@ opcode_C_F: ;@mov r0,z80pc, lsr #8 ;@strb r0,[z80sp,#-1]! ;@strb z80pc,[z80sp,#-1]! - + ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 @@ -4911,7 +4906,7 @@ opcode_D_1: POP_r0 2 mov z80de,r0,lsl #16 - + fetch 10 ;@JP NC, $+3 opcode_D_2 : @@ -4941,10 +4936,10 @@ opcode_D_5: ;@strb r1,[z80sp,#-1]! ;@mov r1,z80de, lsr #16 ;@strb r1,[z80sp,#-1]! - + mov r0,z80de,lsr#16 PUSH_r0 2 - + fetch 11 ;@SUB N opcode_D_6: @@ -4968,11 +4963,11 @@ opcode_D_7: ;@mov r0,z80pc, lsr #8 ;@strb r0,[z80sp,#-1]! ;@strb z80pc,[z80sp,#-1]! - + ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 - + mov r0,#0x10 REBASE_PC @@ -4985,21 +4980,11 @@ opcode_D_8: ;@EXX opcode_D_9: add r1,cpucontext,#z80bc2 - //swp z80bc,z80bc,[r1] - ldr r0,[r1] - str z80bc,[r1] - mov z80bc,r0 - + swp z80bc,z80bc,[r1] add r1,cpucontext,#z80de2 - //swp z80de,z80de,[r1] - ldr r0,[r1] - str z80de,[r1] - mov z80de,r0 + swp z80de,z80de,[r1] add r1,cpucontext,#z80hl2 - //swp z80hl,z80hl,[r1] - ldr r0,[r1] - str z80hl,[r1] - mov z80hl,r0 + swp z80hl,z80hl,[r1] fetch 4 ;@JP C,$+3 opcode_D_A: @@ -5033,7 +5018,7 @@ opcode_F_D: opcode_D_D_F_D: ldrb r1,[z80pc],#1 ;@ DAM_FETCH8 - ldr pc,[pc,r1, lsl #2] + ldr pc,[pc,r1, lsl #2] opcodes_DD: .word 0x00000000 .word opcode_0_0, opcode_0_1, opcode_0_2, opcode_0_3, opcode_0_4, opcode_0_5, opcode_0_6, opcode_0_7 .word opcode_0_8, opcode_DD_09,opcode_0_A, opcode_0_B, opcode_0_C, opcode_0_D, opcode_0_E, opcode_0_F @@ -5068,7 +5053,7 @@ opcodes_DD: .word 0x00000000 .word opcode_F_0, opcode_F_1, opcode_F_2, opcode_F_3, opcode_F_4, opcode_F_5, opcode_F_6, opcode_F_7 .word opcode_F_8, opcode_DD_F9,opcode_F_A, opcode_F_B, opcode_F_C, opcode_F_D, opcode_F_E, opcode_F_F -;@SBC A,N +;@SBC A,N opcode_D_E: DAM_FETCH8D r1 mov r0,z80a @@ -5094,7 +5079,7 @@ opcode_D_F: ;@mov r0,z80pc, lsr #8 ;@strb r0,[z80sp,#-1]! ;@strb z80pc,[z80sp,#-1]! - + ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 @@ -5114,10 +5099,10 @@ opcode_E_1: ;@ldrb r2,[z80sp],#1 ;@orr z80hl,r1,r2, lsl #8 ;@mov z80hl,z80hl, lsl #16 - + POP_r0 2 mov z80hl,r0, lsl #16 - + fetch 10 ;@JP PO,$+3 opcode_E_2: @@ -5156,10 +5141,10 @@ opcode_E_5: ;@strb r1,[z80sp,#-1]! ;@mov r1,z80hl, lsr #16 ;@strb r1,[z80sp,#-1]! - + mov r0,z80hl,lsr #16 PUSH_r0 2 - + fetch 11 ;@AND N opcode_E_6: @@ -5176,11 +5161,11 @@ opcode_E_7: ;@mov r0,z80pc, lsr #8 ;@strb r0,[z80sp,#-1]! ;@strb z80pc,[z80sp,#-1]! - + ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 - + mov r0,#0x20 REBASE_PC @@ -5220,7 +5205,7 @@ opcode_E_D: ldrb r1,[z80pc],#1 ;@ DAM_FETCH8 ldr pc,[pc,r1, lsl #2] - + opcodes_ED: .word 0x00000000 .word opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF .word opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF @@ -5254,7 +5239,7 @@ opcodes_ED: .word 0x00000000 .word opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF .word opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF .word opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF,opcode_ED_NF - + ;@XOR N opcode_E_E: DAM_FETCH8D r1 @@ -5269,7 +5254,7 @@ opcode_E_F: ;@mov r0,z80pc, lsr #8 ;@strb r0,[z80sp,#-1]! ;@strb z80pc,[z80sp,#-1]! - + ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 @@ -5290,13 +5275,13 @@ opcode_F_1: ;@ldrb z80f,[r0,z80f] ;@ldrb z80a,[z80sp],#1 ;@mov z80a,z80a, lsl #24 - + POP_r0_r1 mov z80a,r1,lsl #24 - + sub r1,opcodes,#0x200 ldrb z80f,[r1,r0] - + fetch 10 ;@JP P,$+3 opcode_F_2: @@ -5323,15 +5308,15 @@ opcode_F_5: ;@sub r0,opcodes,#0x300 ;@ldrb r1,[r0,z80f] ;@strb r1,[z80sp,#-1]! - + mov r1,z80a, lsr #24 - + sub r0,opcodes,#0x300 ldrb r0,[r0,z80f] - + orr r0,r0,r1,lsl #8 PUSH_r0 2 - + fetch 11 ;@OR N opcode_F_6: @@ -5347,7 +5332,7 @@ opcode_F_7: ;@mov r0,z80pc, lsr #8 ;@strb r0,[z80sp,#-1]! ;@strb z80pc,[z80sp,#-1]! - + ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 @@ -5378,17 +5363,17 @@ MAIN_opcodes_POINTER: .word MAIN_opcodes ;@EI opcode_F_B: - + ldr r1,[cpucontext,#nEI] ;@tst r1, #1 ;@beq EiContinue cmp r1, #1 bne EiContinue - + ldrb r1,[cpucontext,#z80if] cmp r1,#(Z80_IF1)|(Z80_IF2) beq EiContinue - + mov r1,#(Z80_IF1)|(Z80_IF2) strb r1,[cpucontext,#z80if] mov r1,#2 @@ -5402,7 +5387,7 @@ EiContinue: strb r1,[cpucontext,#z80if] fetch 4 - + .else EI_DUMMY_opcodes_POINTER: .word EI_DUMMY_opcodes @@ -5411,14 +5396,14 @@ opcode_F_B: ldrb r1,[cpucontext,#z80if] tst r1,#Z80_IF1 bne ei_return_exit - + orr r1,r1,#(Z80_IF1)|(Z80_IF2) strb r1,[cpucontext,#z80if] - + mov r2,opcodes ldr opcodes,EI_DUMMY_opcodes_POINTER ldr pc,[r2,r0, lsl #2] - + ei_return: ;@point that program returns from EI to check interupts ;@an interupt can not be taken directly after a EI opcode @@ -5466,13 +5451,13 @@ opcode_F_F: ldr r0,[cpucontext,#z80pc_base] sub r0,z80pc,r0 PUSH_r0 2 - + mov r0,#0x38 REBASE_PC fetch 11 - + ;@################################## ;@################################## ;@### opcodes CB ######################### @@ -5487,7 +5472,7 @@ opcode_CB_00: orrcs r0,r0,#1<<24 sub r2,opcodes,#0x100 ldrb z80f,[r2,r0, lsr #24] - orrcs z80f,z80f,#1<> 8] ldrb r1,[r1,r2] - + ;@add z80pc,z80pc,#1 ;@DAM_FETCH8D r1 ;@sub z80pc,z80pc,#2 ldr pc,[pc,r1, lsl #2] - + .word 0x00 -opcodes_DD_CB: +opcodes_DD_CB: .word opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_CB_06,opcode_DD_NF2 .word opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_CB_0E,opcode_DD_NF2 .word opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_CB_16,opcode_DD_NF2 @@ -8139,7 +8124,7 @@ opcodes_DD_CB: .word opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_CB_F6,opcode_DD_NF2 .word opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_NF2,opcode_DD_CB_FE,opcode_DD_NF2 -;@RLC (IX+N) +;@RLC (IX+N) opcode_DD_CB_06: DAM_FETCH8D_S 2 ldr r1,[cpucontext,z80xx] @@ -8149,11 +8134,11 @@ opcode_DD_CB_06: orrcs r0,r0,#1<<24 sub r2,opcodes,#0x100 ldrb z80f,[r2,r0, lsr #24] - orrcs z80f,z80f,#1<