.data /* * DrZ80 Version 1.0 * Z80 Emulator by Reesy * Copyright 2005 Reesy * * This file is part of DrZ80. * * DrZ80 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * DrZ80 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DrZ80; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ .global DrZ80Run .global DrZ80Ver .equiv INTERRUPT_MODE, 0 ;@0 = Use internal int handler, 1 = Use Mames int handler .equiv FAST_Z80SP, 1 ;@0 = Use mem functions for stack pointer, 1 = Use direct mem pointer ;@ .equiv FIXED_MEMBASE 1 ;@ just assume memory is at 0xe0000000 .if INTERRUPT_MODE .extern Interrupt .endif DrZ80Ver: .long 0x0001 ;@--------------------------------------- .macro fetch cycs ;@stmfd sp!,{r0-r12} ;@ldr r0,[cpucontext,#z80pc_base] ;@sub r0,z80pc,r0 ;@bl pdb ;@ldmfd sp!,{r0-r12} ;@stmfd sp!,{r0-r4} ;@mov r0, z80_icount ;@bl pdb ;@ldmfd sp!,{r0-r4} subs z80_icount,z80_icount,#\cycs ldrplb r0,[z80pc],#1 ldrpl pc,[opcodes,r0, lsl #2] bmi z80_execute_end .endm .macro eatcycles cycs sub z80_icount,z80_icount,#\cycs .endm .macro readmem8 stmfd sp!,{r3,r12} mov lr,pc ldr pc,[cpucontext,#z80_read8] ;@ r0 = addr - data returned in r0 ldmfd sp!,{r3,r12} .endm .macro readmem8HL mov r0,z80hl, lsr #16 readmem8 .endm .macro readmem16 stmfd sp!,{r3,r12} mov lr,pc ldr pc,[cpucontext,#z80_read16] ldmfd sp!,{r3,r12} .endm .macro writemem8 stmfd sp!,{r3,r12} mov lr,pc ldr pc,[cpucontext,#z80_write8] ;@ r0=data r1=addr ldmfd sp!,{r3,r12} .endm .macro writemem8DE mov r1,z80de, lsr #16 writemem8 .endm .macro writemem8HL mov r1,z80hl, lsr #16 writemem8 .endm .macro writemem16 stmfd sp!,{r3,r12} mov lr,pc ldr pc,[cpucontext,#z80_write16] ;@ r0=data r1=addr ldmfd sp!,{r3,r12} .endm .macro copymem8HL_DE mov r0,z80hl, lsr #16 stmfd sp!,{r3,r12} mov lr,pc ldr pc,[cpucontext,#z80_read8] ;@ r0 = addr - data returned in r0 mov r1,z80de, lsr #16 mov lr,pc ldr pc,[cpucontext,#z80_write8] ;@ r0=data r1=addr ldmfd sp!,{r3,r12} .endm ;@--------------------------------------- .macro rebasepc stmfd sp!,{r3,r12} mov lr,pc ldr pc,[cpucontext,#z80_rebasePC] ;@ r0=new pc - external function sets z80pc_base and returns new z80pc in r0 ldmfd sp!,{r3,r12} mov z80pc,r0 .endm .macro rebasesp ;@.if FIXED_MEMBASE mov z80sp, r0, lsl#16 lsr z80sp, #16 orr z80sp, #0xe0000000 ;@.else ;@ stmfd sp!,{r3,r12} ;@ mov lr,pc ;@ ldr pc,[cpucontext,#z80_rebaseSP] ;@ external function must rebase sp ;@ ldmfd sp!,{r3,r12} ;@.endif .endm ;@---------------------------------------------------------------------------- .macro opADC movs z80f,z80f,lsr#2 ;@ get C subcs r0,r0,#0x100 eor z80f,r0,z80a,lsr#24 ;@ prepare for check of half carry adcs z80a,z80a,r0,ror#8 mrs r0,cpsr ;@ S,Z,V&C eor z80f,z80f,z80a,lsr#24 and z80f,z80f,#1< 0xFF writemem8HL add z80hl,z80hl,#1<<16 sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF writemem8HL sub z80hl,z80hl,#1<<16 sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF writemem8HL add z80hl,z80hl,#1<<16 sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF writemem8HL sub z80hl,z80hl,#1<<16 sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1< 0xFF sub z80bc,z80bc,#1<<24 tst z80bc,#0xFF<<24 orrmi z80f,z80f,#1<