4 static void CheckPc()
\r
6 ot(";@ Check Memory Base+pc (r4)\n");
\r
7 ot(" add lr,pc,#4\n");
\r
9 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");
\r
14 // Push 32-bit value in r1 - trashes r0-r3
\r
17 ot(";@ Push r1 onto stack\n");
\r
18 ot(" ldr r0,[r7,#0x3c]\n");
\r
19 ot(" sub r0,r0,#4 ;@ Predecrement A7\n");
\r
20 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");
\r
25 // Push SR - trashes r0-r3
\r
26 void OpPushSr(int high)
\r
28 ot(";@ Push SR:\n");
\r
30 ot(" ldr r0,[r7,#0x3c]\n");
\r
31 ot(" sub r0,r0,#2 ;@ Predecrement A7\n");
\r
32 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");
\r
37 // Pop SR - trashes r0-r3
\r
38 static void PopSr(int high)
\r
41 ot(" ldr r0,[r7,#0x3c]\n");
\r
42 ot(" add r1,r0,#2 ;@ Postincrement A7\n");
\r
43 ot(" str r1,[r7,#0x3c] ;@ Save A7\n");
\r
49 // Pop PC - assumes r10=Memory Base - trashes r0-r3
\r
53 ot(" ldr r0,[r7,#0x3c]\n");
\r
54 ot(" add r1,r0,#4 ;@ Postincrement A7\n");
\r
55 ot(" str r1,[r7,#0x3c] ;@ Save A7\n");
\r
57 ot(" add r4,r0,r10 ;@ r4=Memory Base+PC\n");
\r
67 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
70 ot(" and r0,r8,#0xf ;@ Get trap number\n");
\r
71 ot(" orr r0,r0,#0x20\n");
\r
72 ot(" mov r0,r0,asl #2\n");
\r
73 ot(" str r0,[r7,#0x50] ;@ Save Exception Vector\n");
\r
74 ot(" bl Exception\n");
\r
82 // --------------------- Opcodes 0x4e50+ ---------------------
\r
88 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
93 EaCalc(10, 7, 8, 2);
\r
94 EaRead(10, 1, 8, 2, 1);
\r
96 ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n");
\r
97 ot(" sub r0,r0,#4 ;@ A7-=4\n");
\r
98 ot(" mov r11,r0\n");
\r
101 ot(";@ Write An to Stack\n");
\r
104 ot(";@ Save to An\n");
\r
105 EaWrite(10,11, 8, 2, 1);
\r
107 ot(";@ Get offset:\n");
\r
108 EaCalc(0,0,0x3c,1);
\r
109 EaRead(0,0,0x3c,1);
\r
111 ot(" add r11,r11,r0 ;@ Add offset to A7\n");
\r
112 ot(" str r11,[r7,#0x3c]\n");
\r
120 // --------------------- Opcodes 0x4e58+ ---------------------
\r
126 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
131 EaCalc(10, 7, 8, 2);
\r
132 EaRead(10, 0, 8, 2, 1);
\r
134 ot(" add r11,r0,#4 ;@ A7+=4\n");
\r
136 ot(";@ Pop An from stack:\n");
\r
139 ot(" str r11,[r7,#0x3c] ;@ Save A7\n");
\r
141 ot(";@ An = value from stack:\n");
\r
142 EaWrite(10, 0, 8, 2, 1);
\r
149 // --------------------- Opcodes 0x4e70+ ---------------------
\r
155 // 01001110 01110ttt, reset/nop/stop/rte/rtd/rts/trapv/rtr
\r
156 if (type==1) { OpStart(op); Cycles=4; OpEnd(); return 0; } // nop
\r
158 if (type==3 || type==7) // rte/rtr
\r
160 OpStart(op); Cycles=20;
\r
162 ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n");
\r
164 if (type==3) CheckInterrupt();
\r
169 if (type==5) // rts
\r
171 OpStart(op); Cycles=16;
\r
172 ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n");
\r
181 // --------------------- Opcodes 0x4e80+ ---------------------
\r
182 // Emit a Jsr/Jmp opcode, 01001110 1mEEEeee
\r
190 // See if we can do this opcode:
\r
191 if (EaCanRead(sea,-1)==0) return 1;
\r
194 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
196 OpStart(op); Cycles=14; // Correct?
\r
198 ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n");
\r
200 EaCalc(0,0x003f,sea,0);
\r
202 ot(";@ Jump - Get new PC from r0\n");
\r
205 // Jmp - Get new PC from r0
\r
206 ot(" add r4,r0,r10 ;@ r4 = Memory Base + New PC\n");
\r
211 ot(";@ Jsr - Push old PC first\n");
\r
212 ot(" sub r1,r4,r10 ;@ r1 = Old PC\n");
\r
213 ot(" add r4,r0,r10 ;@ r4 = Memory Base + New PC\n");
\r
220 if (Amatch && sea==0x10) Cycles-=2; // (An) Correct?
\r
229 // --------------------- Opcodes 0x50c8+ ---------------------
\r
231 // ARM version of 68000 condition codes:
\r
232 static char *Cond[16]=
\r
234 "", "", "hi","ls","cc","cs","ne","eq",
\r
235 "vc","vs","pl","mi","ge","lt","gt","le"
\r
238 // Emit a Dbra opcode, 0101cccc 11001nnn vv
\r
244 use=op&~7; // Use same handler
\r
247 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
248 OpStart(op); Cycles=10;
\r
250 ot(";@ Decrement Dn.w\n");
\r
251 ot(" and r1,r8,#0x0007\n");
\r
252 ot(" mov r1,r1,lsl #2\n");
\r
253 ot(" ldrsh r0,[r7,r1]\n");
\r
254 ot(" sub r0,r0,#1\n");
\r
255 ot(" strh r0,[r7,r1]\n");
\r
260 ot(";@ Is the condition true?\n");
\r
261 if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000 ;@ Invert carry for hi/ls\n");
\r
262 ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n");
\r
263 if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000\n");
\r
264 ot(";@ If so, don't dbra\n");
\r
265 ot(" b%s DbraEnd%.4x\n",Cond[cc],op);
\r
269 ot(";@ Check if Dn.w is -1\n");
\r
270 ot(" cmps r0,#-1\n");
\r
271 ot(" beq DbraEnd%.4x\n",op);
\r
274 ot(";@ Get Branch offset:\n");
\r
275 ot(" ldrsh r0,[r4]\n");
\r
276 ot(" add r4,r4,r0 ;@ r4 = New PC\n");
\r
280 ot("DbraEnd%.4x%s\n", op, ms?"":":");
\r
282 ot(" add r4,r4,#2 ;@ Skip branch offset\n");
\r
289 // --------------------- Opcodes 0x6000+ ---------------------
\r
290 // Emit a Branch opcode 0110cccc nn (cccc=condition)
\r
291 int OpBranch(int op)
\r
297 offset=(char)(op&0xff);
\r
300 // Special offsets:
\r
301 if (offset==0) size=1;
\r
302 if (offset==-1) size=2;
\r
304 if (size) use=op; // 16-bit or 32-bit
\r
305 else use=(op&0xff00)+1; // Use same opcode for all 8-bit branches
\r
307 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
308 OpStart(op); Cycles=10; // Assume branch taken
\r
310 ot(";@ Get Branch offset:\n");
\r
313 EaCalc(0,0,0x3c,size);
\r
314 EaRead(0,0,0x3c,size);
\r
315 if (Amatch && size==1) Cycles-=4;
\r
318 if (size==0) ot(" mov r0,r8,asl #24 ;@ Shift 8-bit signed offset up...\n\n");
\r
322 ot(";@ Is the condition true?\n");
\r
323 if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000 ;@ Invert carry for hi/ls\n");
\r
324 ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n");
\r
325 if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000\n");
\r
327 if (size==0) ot(" mov r0,r0,asr #24 ;@ ...shift down\n\n");
\r
329 ot(" b%s DontBranch%.4x\n",Cond[cc^1],op);
\r
335 if (size==0) ot(" mov r0,r0,asr #24 ;@ ...shift down\n\n");
\r
338 ot(";@ Branch taken - Add on r0 to PC\n");
\r
342 ot(";@ Bsr - remember old PC\n");
\r
343 ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n");
\r
344 ot(" sub r1,r4,r10 ;@ r1 = Old PC\n");
\r
346 if (size) ot(" sub r4,r4,#%d ;@ (Branch is relative to Opcode+2)\n",1<<size);
\r
347 ot(" add r4,r4,r0 ;@ r4 = New PC\n");
\r
354 if (size) ot(" sub r4,r4,#%d ;@ (Branch is relative to Opcode+2)\n",1<<size);
\r
355 ot(" add r4,r4,r0 ;@ r4 = New PC\n");
\r
359 if (offset==0 || offset==-1)
\r
361 ot(";@ Branch is quite far, so may be a good idea to check Memory Base+pc\n");
\r
369 ot("DontBranch%.4x%s\n", op, ms?"":":");
\r
370 Cycles-=2; // Branch not taken
\r