3 @ SekRunPS runs PicoCpuCM68k and PicoCpuCS68k interleaved in steps of PS_STEP_M68K
4 @ cycles. This is done without calling CycloneRun and jumping directly to
5 @ Cyclone code to avoid pushing/popping all the registers every time.
7 @ (c) Copyright 2007, Grazvydas "notaz" Ignotas
11 .equiv PS_STEP_M68K, ((488<<16)/20) @ ~24
13 @ .extern is ignored by gas, we add these here just to see what we depend on.
14 .extern CycloneJumpTab
15 .extern CycloneDoInterrupt
20 .extern SekCycleAimS68k
21 .extern SekCycleCntS68k
28 .global SekRunPS @ cyc_m68k, cyc_s68k
31 stmfd sp!, {r4-r8,r10,r11,lr}
32 sub sp, sp, #2*4 @ sp[0] = main_cycle_cnt, sp[4] = run_cycle_cnt
34 @ override CycloneEnd for both contexts
37 ldr r2, =CycloneEnd_M68k
38 ldr r3, =CycloneEnd_S68k
44 ldr r10,=SekCycleAimS68k
52 ldr r6, =CycloneJumpTab
54 ldr r0, =((488<<16)-PS_STEP_M68K)
56 str r6, [lr,#0x54] @ make copies to avoid literal pools
58 @ schedule m68k for the first time..
60 str r0, [sp] @ main target 'left cycle' counter
62 subs r5, r1, r0, asr #16
63 ble schedule_s68k @ m68k has not enough cycles
65 str r5, [sp,#4] @ run_cycle_cnt
72 ldr r0, [sp,#4] @ run_cycle_cnt
74 str r4, [r7,#0x40] ;@ Save Current PC + Memory Base
75 strb r10,[r7,#0x46] ;@ Save Flags (NZCV)
76 sub r0, r0, r5 @ subtract leftover cycles (which should be negative)
81 ldr r8, =SekCycleCntS68k
82 ldr r10,=SekCycleAimS68k
89 add r3, r3, r2, asr #1
90 add r3, r3, r2, asr #3 @ cycn_s68k = (cycn + cycn/2 + cycn/8)
92 subs r5, r0, r3, asr #16
93 ble schedule_m68k @ s68k has not enough cycles
96 str r5, [sp,#4] @ run_cycle_cnt
102 ldr r3, =SekCycleCntS68k
103 ldr r0, [sp,#4] @ run_cycle_cnt
105 str r4, [r7,#0x40] ;@ Save Current PC + Memory Base
106 strb r10,[r7,#0x46] ;@ Save Flags (NZCV)
107 sub r0, r0, r5 @ subtract leftover cycles (should be negative)
112 ldr r1, =PS_STEP_M68K
113 ldr r3, [sp] @ main_cycle_cnt
121 str r3, [sp] @ update main_cycle_cnt
124 subs r5, r0, r3, asr #16
125 ble schedule_s68k @ m68k has not enough cycles
127 ldr r7, =PicoCpuCM68k
128 str r5, [sp,#4] @ run_cycle_cnt
134 ldr r7, =PicoCpuCM68k
135 ldr lr, =PicoCpuCS68k
137 str r0, [r7,#0x98] @ remove CycloneEnd handler
141 ldmfd sp!, {r4-r8,r10,r11,pc}
146 ;@ r0-3 = Temporary registers
147 ldr r4,[r7,#0x40] ;@ r4 = Current PC + Memory Base
149 ;@ r6 = Opcode Jump table
150 ;@ r7 = Pointer to Cpu Context
151 ;@ r8 = Current Opcode
152 ldrb r10,[r7,#0x46];@ r10 = Flags (NZCV)
153 ldr r1,[r7,#0x44] ;@ get SR high and IRQ level
154 orr r10,r10,r10,lsl #28 ;@ r10 = Flags 0xf0000000, cpsr format
157 movs r0,r1,lsr #24 ;@ Get IRQ level
160 andle r1,r1,#7 ;@ Get interrupt mask
161 cmple r0,r1 ;@ irq<=6: Is irq<=mask ?
162 bgt CycloneDoInterrupt
165 ;@ Check if our processor is in special state
166 ;@ and jump to opcode handler if not
167 ldr r0,[r7,#0x58] ;@ state_flags
168 ldrh r8,[r4],#2 ;@ Fetch first opcode
169 tst r0,#0x03 ;@ special state?
170 andeq r10,r10,#0xf0000000
171 ldreq pc,[r6,r8,asl #2] ;@ Jump to opcode handler
174 tst r0,#2 ;@ tracing?