3 @* (C) notaz, 2007-2008
5 @* This work is licensed under the terms of MAME license.
6 @* See COPYING file in the top-level directory.
9 @ SekRunPS runs PicoCpuCM68k and PicoCpuCS68k interleaved in steps of PS_STEP_M68K
10 @ cycles. This is done without calling CycloneRun and jumping directly to
11 @ Cyclone code to avoid pushing/popping all the registers every time.
14 .equiv PS_STEP_M68K, ((488<<16)/20) @ ~24
16 @ .extern is ignored by gas, we add these here just to see what we depend on.
17 .extern CycloneJumpTab
18 .extern CycloneDoInterrupt
23 .extern SekCycleAimS68k
24 .extern SekCycleCntS68k
31 .global SekRunPS @ cyc_m68k, cyc_s68k
34 stmfd sp!, {r4-r8,r10,r11,lr}
35 sub sp, sp, #2*4 @ sp[0] = main_cycle_cnt, sp[4] = run_cycle_cnt
37 @ override CycloneEnd for both contexts
40 ldr r2, =CycloneEnd_M68k
41 ldr r3, =CycloneEnd_S68k
47 ldr r10,=SekCycleAimS68k
55 ldr r6, =CycloneJumpTab
57 ldr r0, =((488<<16)-PS_STEP_M68K)
59 str r6, [lr,#0x54] @ make copies to avoid literal pools
61 @ schedule m68k for the first time..
63 str r0, [sp] @ main target 'left cycle' counter
65 subs r5, r1, r0, asr #16
66 ble schedule_s68k @ m68k has not enough cycles
68 str r5, [sp,#4] @ run_cycle_cnt
75 ldr r0, [sp,#4] @ run_cycle_cnt
77 str r4, [r7,#0x40] ;@ Save Current PC + Memory Base
78 strb r10,[r7,#0x46] ;@ Save Flags (NZCV)
79 sub r0, r0, r5 @ subtract leftover cycles (which should be negative)
84 ldr r8, =SekCycleCntS68k
85 ldr r10,=SekCycleAimS68k
92 add r3, r3, r2, asr #1
93 add r3, r3, r2, asr #3 @ cycn_s68k = (cycn + cycn/2 + cycn/8)
95 subs r5, r0, r3, asr #16
96 ble schedule_m68k @ s68k has not enough cycles
99 str r5, [sp,#4] @ run_cycle_cnt
105 ldr r3, =SekCycleCntS68k
106 ldr r0, [sp,#4] @ run_cycle_cnt
108 str r4, [r7,#0x40] ;@ Save Current PC + Memory Base
109 strb r10,[r7,#0x46] ;@ Save Flags (NZCV)
110 sub r0, r0, r5 @ subtract leftover cycles (should be negative)
115 ldr r1, =PS_STEP_M68K
116 ldr r3, [sp] @ main_cycle_cnt
124 str r3, [sp] @ update main_cycle_cnt
127 subs r5, r0, r3, asr #16
128 ble schedule_s68k @ m68k has not enough cycles
130 ldr r7, =PicoCpuCM68k
131 str r5, [sp,#4] @ run_cycle_cnt
137 ldr r7, =PicoCpuCM68k
138 ldr lr, =PicoCpuCS68k
140 str r0, [r7,#0x98] @ remove CycloneEnd handler
144 ldmfd sp!, {r4-r8,r10,r11,pc}
149 ;@ r0-3 = Temporary registers
150 ldr r4,[r7,#0x40] ;@ r4 = Current PC + Memory Base
152 ;@ r6 = Opcode Jump table
153 ;@ r7 = Pointer to Cpu Context
154 ;@ r8 = Current Opcode
155 ldrb r10,[r7,#0x46];@ r10 = Flags (NZCV)
156 ldr r1,[r7,#0x44] ;@ get SR high and IRQ level
157 orr r10,r10,r10,lsl #28 ;@ r10 = Flags 0xf0000000, cpsr format
160 movs r0,r1,lsr #24 ;@ Get IRQ level
163 andle r1,r1,#7 ;@ Get interrupt mask
164 cmple r0,r1 ;@ irq<=6: Is irq<=mask ?
165 bgt CycloneDoInterrupt
168 ;@ Check if our processor is in special state
169 ;@ and jump to opcode handler if not
170 ldr r0,[r7,#0x58] ;@ state_flags
171 ldrh r8,[r4],#2 ;@ Fetch first opcode
172 tst r0,#0x03 ;@ special state?
173 andeq r10,r10,#0xf0000000
174 ldreq pc,[r6,r8,asl #2] ;@ Jump to opcode handler
177 tst r0,#2 ;@ tracing?
185 @ vim:filetype=armasm