str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
.if DRZ80_FOR_PICODRIVE\r
- bic r0,r0,#0xfe000\r
ldr r1,[cpucontext,#z80pc_base]\r
+ bic r0,r0,#0xfe000\r
add z80pc,r1,r0\r
.else\r
stmfd sp!,{r3,r12}\r
mov z80_icount,r1 ;@ setup number of Tstates to execute\r
\r
.if INTERRUPT_MODE == 0\r
- ldrh r0,[cpucontext,#z80irq] @ 0x4C\r
+ ldrh r0,[cpucontext,#z80irq] @ 0x4C, irq and IFF bits\r
.endif\r
ldmia cpucontext,{z80pc-z80sp} ;@ load Z80 registers\r
\r
.if INTERRUPT_MODE == 0\r
;@ check ints\r
- tst r0,#1\r
- movnes r0,r0,lsr #8\r
- blne DoInterrupt\r
+ tst r0,#0xff\r
+ movne r0,r0,lsr #8\r
+ tstne r0,#1\r
+ blne DoInterrupt\r
.endif\r
\r
- ldrb r0,[z80pc],#1 ;@ get first op code\r
ldr opcodes,MAIN_opcodes_POINTER2\r
- ldr pc,[opcodes,r0, lsl #2] ;@ execute op code\r
\r
-MAIN_opcodes_POINTER2: .word MAIN_opcodes\r
+ cmp z80_icount,#0 ;@ irq might have used all cycles\r
+ ldrplb r0,[z80pc],#1\r
+ ldrpl pc,[opcodes,r0, lsl #2]\r
\r
\r
z80_execute_end:\r
;@ save registers in CPU context\r
stmia cpucontext,{z80pc-z80sp} ;@ save Z80 registers\r
- mov r0,z80_icount\r
+ mov r0,z80_icount\r
ldmia sp!,{r4-r12,pc} ;@ restore registers from stack and return to C code\r
\r
+MAIN_opcodes_POINTER2: .word MAIN_opcodes\r
.if INTERRUPT_MODE\r
Interrupt_local: .word Interrupt\r
.endif\r
ldmia cpucontext,{z80pc-z80sp} ;@ load Z80 registers\r
mov pc,lr ;@ return\r
.else\r
+\r
+ ;@ r0 == z80if\r
stmfd sp!,{lr}\r
\r
tst r0,#4 ;@ check halt\r
strb r0,[cpucontext,#z80if]\r
\r
;@ now check int mode\r
- tst r1,#1\r
- bne DoInterrupt_mode1\r
- tst r1,#2\r
- bne DoInterrupt_mode2\r
+ cmp r1,#1\r
+ beq DoInterrupt_mode1\r
+ bgt DoInterrupt_mode2\r
\r
DoInterrupt_mode0:\r
;@ get 3 byte vector\r
;@ rebase new pc\r
rebasepc\r
\r
+ eatcycles 13\r
b DoInterrupt_end\r
\r
1:\r
;@ rebase new pc\r
rebasepc\r
\r
+ eatcycles 13\r
b DoInterrupt_end\r
\r
DoInterrupt_mode1:\r
mov r0,#0x38\r
rebasepc\r
\r
+ eatcycles 13\r
b DoInterrupt_end\r
\r
DoInterrupt_mode2:\r
ldmfd sp!,{r3,r12}\r
mov z80pc,r0 \r
.endif\r
+ eatcycles 17\r
\r
DoInterrupt_end:\r
;@ interupt accepted so callback irq interface\r
ldr r0,[cpucontext, #z80irqcallback]\r
tst r0,r0\r
+ streqb r0,[cpucontext,#z80irq] ;@ default handling\r
ldmeqfd sp!,{pc}\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
mov pc,r0 ;@ call callback function\r
ldmfd sp!,{r3,r12}\r
ldmfd sp!,{pc} ;@ return\r
-\r
.endif\r
\r
.data\r
fetch 5\r
\r
opcode_C_9_cond:\r
- sub z80_icount,#1\r
+ eatcycles 1\r
;@RET\r
opcode_C_9:\r
opPOP\r
;@EI\r
opcode_F_B:\r
ldrb r1,[cpucontext,#z80if]\r
- tst r1,#Z80_IF1\r
- bne ei_return_exit\r
-\r
+ mov r2,opcodes\r
orr r1,r1,#(Z80_IF1)|(Z80_IF2)\r
strb r1,[cpucontext,#z80if]\r
\r
- mov r2,opcodes\r
+ ldrb r0,[z80pc],#1\r
+ eatcycles 4\r
ldr opcodes,EI_DUMMY_opcodes_POINTER\r
ldr pc,[r2,r0, lsl #2]\r
\r
;@point that program returns from EI to check interupts\r
;@an interupt can not be taken directly after a EI opcode\r
;@ reset z80pc and opcode pointer\r
- ldrh r0,[cpucontext,#z80irq] @ 0x4C\r
+ ldrh r0,[cpucontext,#z80irq] @ 0x4C, irq and IFF bits\r
sub z80pc,z80pc,#1\r
ldr opcodes,MAIN_opcodes_POINTER\r
;@ check ints\r
- tst r0,#1\r
- movnes r0,r0,lsr #8\r
- blne DoInterrupt\r
+ tst r0,#0xff\r
+ movne r0,r0,lsr #8\r
+ tstne r0,#1\r
+ blne DoInterrupt\r
+\r
;@ continue\r
-ei_return_exit:\r
- fetch 4\r
+ fetch 0\r
\r
;@CALL M,NN\r
opcode_F_C:\r
;@end_loop:\r
;@ b end_loop\r
\r
-\r
+;@ vim:filetype=armasm\r
\r