detect and fix incorect format args
[cyclone68000.git] / Main.cpp
CommitLineData
6003a768 1\r
619b1824 2// This file is part of the Cyclone 68000 Emulator\r
3\r
d9d77995 4// Copyright (c) 2004,2011 FinalDave (emudave (at) gmail.com)\r
5// Copyright (c) 2005-2011 Gražvydas "notaz" Ignotas (notasas (at) gmail.com)\r
c41b9b97 6\r
619b1824 7// This code is licensed under the GNU General Public License version 2.0 and the MAME License.\r
8// You can choose the license that has the most advantages for you.\r
9\r
10// SVN repository can be found at http://code.google.com/p/cyclone68000/\r
11\r
d9d77995 12\r
6003a768 13#include "app.h"\r
14\r
15static FILE *AsmFile=NULL;\r
16\r
d9d77995 17static int CycloneVer=0x0099; // Version number of library\r
6003a768 18int *CyJump=NULL; // Jump table\r
d9d77995 19int ms=USE_MS_SYNTAX; // If non-zero, output in Microsoft ARMASM format\r
20const char * const Narm[4]={ "b", "h","",""}; // Normal ARM Extensions for operand sizes 0,1,2\r
21const char * const Sarm[4]={"sb","sh","",""}; // Sign-extend ARM Extensions for operand sizes 0,1,2\r
22int Cycles; // Current cycles for opcode\r
23int pc_dirty; // something changed PC during processing\r
24int arm_op_count;\r
25\r
26// opcodes often used by games\r
27static const unsigned short hot_opcodes[] = {\r
c6237d9e 28 0x6702, // beq $3\r
29 0x6602, // bne $3\r
d9d77995 30 0x51c8, // dbra Dn, $2\r
31 0x4a38, // tst.b $0.w\r
32 0xd040, // add.w Dn, Dn\r
33 0x4a79, // tst.w $0.l\r
34 0x0240, // andi.w #$0, D0\r
35 0x2038, // move.l $0.w, D0\r
36 0xb0b8, // cmp.l $0.w, D0\r
c6237d9e 37 0x6002, // bra $3\r
d9d77995 38 0x30c0, // move.w D0, (A0)+\r
39 0x3028, // move.w ($0,A0), D0\r
40 0x0c40, // cmpi.w #$0, D0\r
41 0x0c79, // cmpi.w #$0, $0.l\r
42 0x4e75, // rts\r
43 0x4e71, // nop\r
44 0x3000, // move.w D0, D0\r
45 0x0839, // btst #$0, $0.l\r
46 0x7000, // moveq #$0, D0\r
47 0x3040, // movea.w D0, A0\r
48 0x0838, // btst #$0, $0.w\r
49 0x4a39, // tst.b $0.l\r
50 0x33d8, // move.w (A0)+, $0.l\r
51 0x6700, // beq $2\r
52 0xb038, // cmp.b $0.w, D0\r
53 0x3039, // move.w $0.l, D0\r
54 0x4840, // swap D0\r
c6237d9e 55 0x6102, // bsr $3\r
d9d77995 56 0x6100, // bsr $2\r
57 0x5e40, // addq.w #7, D0\r
58 0x1039, // move.b $0.l, D0\r
59 0x20c0, // move.l D0, (A0)+\r
60 0x1018, // move.b (A0)+, D0\r
61 0x30d0, // move.w (A0), (A0)+\r
62 0x3080, // move.w D0, (A0)\r
63 0x3018, // move.w (A0)+, D0\r
64 0xc040, // and.w D0, D0\r
65 0x3180, // move.w D0, (A0,D0.w)\r
66 0x1198, // move.b (A0)+, (A0,D0.w)\r
c6237d9e 67 0x6502, // bcs $3\r
d9d77995 68 0x6500, // bcs $2\r
c6237d9e 69 0x6402, // bcc $3\r
70 0x6a02, // bpl $3\r
d9d77995 71 0x41f0, // lea (A0,D0.w), A0\r
72 0x4a28, // tst.b ($0,A0)\r
73 0x0828, // btst #$0, ($0,A0)\r
74 0x0640, // addi.w #$0, D0\r
75 0x10c0, // move.b D0, (A0)+\r
76 0x10d8, // move.b (A0)+, (A0)+\r
77};\r
78#define hot_opcode_count (int)(sizeof(hot_opcodes) / sizeof(hot_opcodes[0]))\r
79\r
80static int is_op_hot(int op)\r
81{\r
82 int i;\r
83 for (i = 0; i < hot_opcode_count; i++)\r
84 if (op == hot_opcodes[i])\r
85 return 1;\r
86 return 0;\r
87}\r
6003a768 88\r
c30e2e2d 89void ot(const char *format, ...)\r
6003a768 90{\r
c30e2e2d 91 va_list valist;\r
d9d77995 92 int i, len;\r
93\r
94 // notaz: stop me from leaving newlines in the middle of format string\r
95 // and generating bad code\r
96 for(i=0, len=strlen(format); i < len && format[i] != '\n'; i++);\r
97 if(i < len-1 && format[len-1] != '\n') printf("\nWARNING: possible improper newline placement:\n%s\n", format);\r
98\r
99 if (format[0] == ' ' && format[1] == ' ' && format[2] != ' ' && format[2] != '.')\r
100 arm_op_count++;\r
101\r
6003a768 102 va_start(valist,format);\r
103 if (AsmFile) vfprintf(AsmFile,format,valist);\r
104 va_end(valist);\r
105}\r
106\r
107void ltorg()\r
108{\r
109 if (ms) ot(" LTORG\n");\r
110 else ot(" .ltorg\n");\r
111}\r
112\r
d9d77995 113#if (CYCLONE_FOR_GENESIS == 2)\r
114// r12=ptr to tas in table, trashes r0,r1\r
115static void ChangeTAS(int norm)\r
6003a768 116{\r
d9d77995 117 ot(" ldr r0,=Op4ad0%s\n",norm?"_":"");\r
118 ot(" mov r1,#8\n");\r
119 ot("setrtas_loop%i0%s ;@ 4ad0-4ad7\n",norm,ms?"":":");\r
120 ot(" subs r1,r1,#1\n");\r
121 ot(" str r0,[r12],#4\n");\r
122 ot(" bne setrtas_loop%i0\n",norm);\r
123 ot(" ldr r0,=Op4ad8%s\n",norm?"_":"");\r
124 ot(" mov r1,#7\n");\r
125 ot("setrtas_loop%i1%s ;@ 4ad8-4ade\n",norm,ms?"":":");\r
126 ot(" subs r1,r1,#1\n");\r
127 ot(" str r0,[r12],#4\n");\r
128 ot(" bne setrtas_loop%i1\n",norm);\r
129 ot(" ldr r0,=Op4adf%s\n",norm?"_":"");\r
130 ot(" str r0,[r12],#4\n");\r
131 ot(" ldr r0,=Op4ae0%s\n",norm?"_":"");\r
132 ot(" mov r1,#7\n");\r
133 ot("setrtas_loop%i2%s ;@ 4ae0-4ae6\n",norm,ms?"":":");\r
134 ot(" subs r1,r1,#1\n");\r
135 ot(" str r0,[r12],#4\n");\r
136 ot(" bne setrtas_loop%i2\n",norm);\r
137 ot(" ldr r0,=Op4ae7%s\n",norm?"_":"");\r
138 ot(" str r0,[r12],#4\n");\r
139 ot(" ldr r0,=Op4ae8%s\n",norm?"_":"");\r
140 ot(" mov r1,#8\n");\r
141 ot("setrtas_loop%i3%s ;@ 4ae8-4aef\n",norm,ms?"":":");\r
142 ot(" subs r1,r1,#1\n");\r
143 ot(" str r0,[r12],#4\n");\r
144 ot(" bne setrtas_loop%i3\n",norm);\r
145 ot(" ldr r0,=Op4af0%s\n",norm?"_":"");\r
146 ot(" mov r1,#8\n");\r
147 ot("setrtas_loop%i4%s ;@ 4af0-4af7\n",norm,ms?"":":");\r
148 ot(" subs r1,r1,#1\n");\r
149 ot(" str r0,[r12],#4\n");\r
150 ot(" bne setrtas_loop%i4\n",norm);\r
151 ot(" ldr r0,=Op4af8%s\n",norm?"_":"");\r
152 ot(" str r0,[r12],#4\n");\r
153 ot(" ldr r0,=Op4af9%s\n",norm?"_":"");\r
154 ot(" str r0,[r12],#4\n");\r
6003a768 155}\r
d9d77995 156#endif\r
6003a768 157\r
d9d77995 158#if EMULATE_ADDRESS_ERRORS_JUMP || EMULATE_ADDRESS_ERRORS_IO\r
159static void AddressErrorWrapper(char rw, const char *dataprg, int iw)\r
6003a768 160{\r
d9d77995 161 ot("ExceptionAddressError_%c_%s%s\n", rw, dataprg, ms?"":":");\r
162 ot(" ldr r1,[r7,#0x44]\n");\r
163 ot(" mov r6,#0x%02x\n", iw);\r
164 ot(" mov r11,r0\n");\r
165 ot(" tst r1,#0x20\n");\r
166 ot(" orrne r6,r6,#4\n");\r
167 ot(" b ExceptionAddressError\n");\r
6003a768 168 ot("\n");\r
169}\r
d9d77995 170#endif\r
171\r
355815eb 172void FlushPC(int force)\r
d9d77995 173{\r
174#if MEMHANDLERS_NEED_PC\r
355815eb 175 force |= pc_dirty;\r
d9d77995 176 pc_dirty = 0;\r
355815eb 177#endif\r
178 if (force)\r
179 ot(" str r4,[r7,#0x40] ;@ Save PC\n");\r
d9d77995 180}\r
6003a768 181\r
182static void PrintFramework()\r
183{\r
d9d77995 184 int state_flags_to_check = 1; // stopped\r
185#if EMULATE_TRACE\r
186 state_flags_to_check |= 2; // tracing\r
187#endif\r
188#if EMULATE_HALT\r
189 state_flags_to_check |= 0x10; // halted\r
190#endif\r
191\r
6003a768 192 ot(";@ --------------------------- Framework --------------------------\n");\r
193 if (ms) ot("CycloneRun\n");\r
194 else ot("CycloneRun:\n");\r
195\r
d9d77995 196 ot(" stmdb sp!,{r4-r8,r10,r11,lr}\n");\r
6003a768 197\r
198 ot(" mov r7,r0 ;@ r7 = Pointer to Cpu Context\n");\r
199 ot(" ;@ r0-3 = Temporary registers\n");\r
d9d77995 200 ot(" ldrb r10,[r7,#0x46] ;@ r10 = Flags (NZCV)\n");\r
201 ot(" ldr r6,=CycloneJumpTab ;@ r6 = Opcode Jump table\n");\r
6003a768 202 ot(" ldr r5,[r7,#0x5c] ;@ r5 = Cycles\n");\r
203 ot(" ldr r4,[r7,#0x40] ;@ r4 = Current PC + Memory Base\n");\r
204 ot(" ;@ r8 = Current Opcode\n");\r
d9d77995 205 ot(" ldr r1,[r7,#0x44] ;@ Get SR high T_S__III and irq level\n");\r
206 ot(" mov r10,r10,lsl #28;@ r10 = Flags 0xf0000000, cpsr format\n");\r
207 ot(" ;@ r11 = Source value / Memory Base\n");\r
208 ot(" str r6,[r7,#0x54] ;@ make a copy to avoid literal pools\n");\r
209 ot("\n");\r
210#if (CYCLONE_FOR_GENESIS == 2) || EMULATE_TRACE\r
211 ot(" mov r2,#0\n");\r
212 ot(" str r2,[r7,#0x98] ;@ clear custom CycloneEnd\n");\r
213#endif\r
214 ot(";@ CheckInterrupt:\n");\r
215 ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47]\r
216 ot(" beq NoInts0\n");\r
217 ot(" cmp r0,#6 ;@ irq>6 ?\n");\r
218 ot(" andle r1,r1,#7 ;@ Get interrupt mask\n");\r
219 ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n");\r
220 ot(" bgt CycloneDoInterrupt\n");\r
221 ot("NoInts0%s\n", ms?"":":");\r
222 ot("\n");\r
223 ot(";@ Check if our processor is in special state\n");\r
224 ot(";@ and jump to opcode handler if not\n");\r
225 ot(" ldr r0,[r7,#0x58] ;@ state_flags\n");\r
226 ot(" ldrh r8,[r4],#2 ;@ Fetch first opcode\n");\r
227 ot(" tst r0,#0x%02x ;@ special state?\n", state_flags_to_check);\r
228 ot(" ldreq pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r
229 ot("\n");\r
230 ot("CycloneSpecial%s\n", ms?"":":");\r
231#if EMULATE_TRACE\r
232 ot(" tst r0,#2 ;@ tracing?\n");\r
233 ot(" bne CycloneDoTrace\n");\r
234#endif\r
235 ot(";@ stopped or halted\n");\r
236 ot(" mov r5,#0\n");\r
237 ot(" str r5,[r7,#0x5C] ;@ eat all cycles\n");\r
238 ot(" ldmia sp!,{r4-r8,r10,r11,pc} ;@ we are stopped, do nothing!\n");\r
6003a768 239 ot("\n");\r
6003a768 240 ot("\n");\r
241\r
242 ot(";@ We come back here after execution\n");\r
243 ot("CycloneEnd%s\n", ms?"":":");\r
244 ot(" sub r4,r4,#2\n");\r
245 ot("CycloneEndNoBack%s\n", ms?"":":");\r
d9d77995 246#if (CYCLONE_FOR_GENESIS == 2) || EMULATE_TRACE\r
247 ot(" ldr r1,[r7,#0x98]\n");\r
248 ot(" mov r10,r10,lsr #28\n");\r
249 ot(" tst r1,r1\n");\r
250 ot(" bxne r1 ;@ jump to alternative CycloneEnd\n");\r
251#else\r
252 ot(" mov r10,r10,lsr #28\n");\r
253#endif\r
6003a768 254 ot(" str r4,[r7,#0x40] ;@ Save Current PC + Memory Base\n");\r
255 ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
d9d77995 256 ot(" strb r10,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
257 ot(" ldmia sp!,{r4-r8,r10,r11,pc}\n");\r
258 ltorg();\r
6003a768 259 ot("\n");\r
6003a768 260 ot("\n");\r
d9d77995 261\r
262 ot("CycloneInit%s\n", ms?"":":");\r
263#if COMPRESS_JUMPTABLE\r
264 ot(";@ decompress jump table\n");\r
265 ot(" ldr r12,=CycloneJumpTab\n");\r
266 ot(" add r0,r12,#0xe000*4 ;@ ctrl code pointer\n");\r
267 ot(" ldr r1,[r0,#-4]\n");\r
268 ot(" tst r1,r1\n");\r
269 ot(" movne pc,lr ;@ already uncompressed\n");\r
270 ot(" add r3,r12,#0xa000*4 ;@ handler table pointer, r12=dest\n");\r
271 ot("unc_loop%s\n", ms?"":":");\r
272 ot(" ldrh r1,[r0],#2\n");\r
273 ot(" and r2,r1,#0xf\n");\r
274 ot(" bic r1,r1,#0xf\n");\r
275 ot(" ldr r1,[r3,r1,lsr #2] ;@ r1=handler\n");\r
276 ot(" cmp r2,#0xf\n");\r
277 ot(" addeq r2,r2,#1 ;@ 0xf is really 0x10\n");\r
278 ot(" tst r2,r2\n");\r
279 ot(" ldreqh r2,[r0],#2 ;@ counter is in next word\n");\r
280 ot(" tst r2,r2\n");\r
281 ot(" beq unc_finish ;@ done decompressing\n");\r
282 ot(" tst r1,r1\n");\r
283 ot(" addeq r12,r12,r2,lsl #2 ;@ 0 handler means we should skip those bytes\n");\r
284 ot(" beq unc_loop\n");\r
285 ot("unc_loop_in%s\n", ms?"":":");\r
286 ot(" subs r2,r2,#1\n");\r
287 ot(" str r1,[r12],#4\n");\r
288 ot(" bgt unc_loop_in\n");\r
289 ot(" b unc_loop\n");\r
290 ot("unc_finish%s\n", ms?"":":");\r
291 ot(" ldr r12,=CycloneJumpTab\n");\r
292 ot(" ;@ set a-line and f-line handlers\n");\r
293 ot(" add r0,r12,#0xa000*4\n");\r
294 ot(" ldr r1,[r0,#4] ;@ a-line handler\n");\r
295 ot(" ldr r3,[r0,#8] ;@ f-line handler\n");\r
296 ot(" mov r2,#0x1000\n");\r
297 ot("unc_fill3%s\n", ms?"":":");\r
298 ot(" subs r2,r2,#1\n");\r
299 ot(" str r1,[r0],#4\n");\r
300 ot(" bgt unc_fill3\n");\r
301 ot(" add r0,r12,#0xf000*4\n");\r
302 ot(" mov r2,#0x1000\n");\r
303 ot("unc_fill4%s\n", ms?"":":");\r
304 ot(" subs r2,r2,#1\n");\r
305 ot(" str r3,[r0],#4\n");\r
306 ot(" bgt unc_fill4\n");\r
307 ot(" bx lr\n");\r
308 ltorg();\r
309#else\r
590d780f 310 ot(";@ fix final jumptable entries\n");\r
311 ot(" ldr r12,=CycloneJumpTab\n");\r
312 ot(" add r12,r12,#0x10000*4\n");\r
313 ot(" ldr r0,[r12,#-3*4]\n");\r
314 ot(" str r0,[r12,#-2*4]\n");\r
315 ot(" str r0,[r12,#-1*4]\n");\r
d9d77995 316 ot(" bx lr\n");\r
317#endif\r
6003a768 318 ot("\n");\r
d9d77995 319\r
320 // --------------\r
321 ot("CycloneReset%s\n", ms?"":":");\r
322 ot(" stmfd sp!,{r7,lr}\n");\r
323 ot(" mov r7,r0\n");\r
324 ot(" mov r0,#0\n");\r
325 ot(" str r0,[r7,#0x58] ;@ state_flags\n");\r
326 ot(" str r0,[r7,#0x48] ;@ OSP\n");\r
327 ot(" mov r1,#0x27 ;@ Supervisor mode\n");\r
328 ot(" strb r1,[r7,#0x44] ;@ set SR high\n");\r
329 ot(" strb r0,[r7,#0x47] ;@ IRQ\n");\r
6003a768 330 MemHandler(0,2);\r
d9d77995 331 ot(" str r0,[r7,#0x3c] ;@ Stack pointer\n");\r
332 ot(" mov r0,#0\n");\r
333 ot(" str r0,[r7,#0x60] ;@ Membase\n");\r
334 ot(" mov r0,#4\n");\r
335 MemHandler(0,2);\r
336#ifdef MEMHANDLERS_DIRECT_PREFIX\r
337 ot(" bl %scheckpc ;@ Call checkpc()\n", MEMHANDLERS_DIRECT_PREFIX);\r
338#else\r
6003a768 339 ot(" mov lr,pc\n");\r
340 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");\r
d9d77995 341#endif\r
342 ot(" str r0,[r7,#0x40] ;@ PC + base\n");\r
343 ot(" ldmfd sp!,{r7,pc}\n");\r
344 ot("\n");\r
345\r
346 // --------------\r
347 // 68k: XNZVC, ARM: NZCV\r
348 ot("CycloneSetSr%s\n", ms?"":":");\r
349 ot(" mov r2,r1,lsr #8\n");\r
350// ot(" ldrb r3,[r0,#0x44] ;@ get SR high\n");\r
351// ot(" eor r3,r3,r2\n");\r
352// ot(" tst r3,#0x20\n");\r
353#if EMULATE_TRACE\r
354 ot(" and r2,r2,#0xa7 ;@ only defined bits\n");\r
355#else\r
356 ot(" and r2,r2,#0x27 ;@ only defined bits\n");\r
357#endif\r
358 ot(" strb r2,[r0,#0x44] ;@ set SR high\n");\r
359 ot(" mov r2,r1,lsl #25\n");\r
360 ot(" str r2,[r0,#0x4c] ;@ the X flag\n");\r
361 ot(" bic r2,r1,#0xf3\n");\r
362 ot(" tst r1,#1\n");\r
363 ot(" orrne r2,r2,#2\n");\r
364 ot(" tst r1,#2\n");\r
365 ot(" orrne r2,r2,#1\n");\r
366 ot(" strb r2,[r0,#0x46] ;@ flags\n");\r
367 ot(" bx lr\n");\r
368 ot("\n");\r
369\r
370 // --------------\r
371 ot("CycloneGetSr%s\n", ms?"":":");\r
372 ot(" ldrb r1,[r0,#0x46] ;@ flags\n");\r
373 ot(" bic r2,r1,#0xf3\n");\r
374 ot(" tst r1,#1\n");\r
375 ot(" orrne r2,r2,#2\n");\r
376 ot(" tst r1,#2\n");\r
377 ot(" orrne r2,r2,#1\n");\r
378 ot(" ldr r1,[r0,#0x4c] ;@ the X flag\n");\r
379 ot(" tst r1,#0x20000000\n");\r
380 ot(" orrne r2,r2,#0x10\n");\r
381 ot(" ldrb r1,[r0,#0x44] ;@ the SR high\n");\r
382 ot(" orr r0,r2,r1,lsl #8\n");\r
383 ot(" bx lr\n");\r
384 ot("\n");\r
385\r
386 // --------------\r
387 ot("CyclonePack%s\n", ms?"":":");\r
388 ot(" stmfd sp!,{r4,r5,lr}\n");\r
6003a768 389 ot(" mov r4,r0\n");\r
d9d77995 390 ot(" mov r5,r1\n");\r
391 ot(" mov r3,#16\n");\r
392 ot(";@ 0x00-0x3f: DA registers\n");\r
393 ot("c_pack_loop%s\n",ms?"":":");\r
394 ot(" ldr r1,[r0],#4\n");\r
395 ot(" subs r3,r3,#1\n");\r
396 ot(" str r1,[r5],#4\n");\r
397 ot(" bne c_pack_loop\n");\r
398 ot(";@ 0x40: PC\n");\r
399 ot(" ldr r0,[r4,#0x40] ;@ PC + Memory Base\n");\r
400 ot(" ldr r1,[r4,#0x60] ;@ Memory base\n");\r
401 ot(" sub r0,r0,r1\n");\r
402 ot(" str r0,[r5],#4\n");\r
403 ot(";@ 0x44: SR\n");\r
404 ot(" mov r0,r4\n");\r
405 ot(" bl CycloneGetSr\n");\r
406 ot(" strh r0,[r5],#2\n");\r
407 ot(";@ 0x46: IRQ level\n");\r
408 ot(" ldrb r0,[r4,#0x47]\n");\r
409 ot(" strb r0,[r5],#2\n");\r
410 ot(";@ 0x48: other SP\n");\r
411 ot(" ldr r0,[r4,#0x48]\n");\r
412 ot(" str r0,[r5],#4\n");\r
413 ot(";@ 0x4c: CPU state flags\n");\r
414 ot(" ldr r0,[r4,#0x58]\n");\r
415 ot(" str r0,[r5],#4\n");\r
416 ot(" ldmfd sp!,{r4,r5,pc}\n");\r
417 ot("\n");\r
418\r
419 // --------------\r
420 ot("CycloneUnpack%s\n", ms?"":":");\r
421 ot(" stmfd sp!,{r5,r7,lr}\n");\r
422 ot(" mov r7,r0\n");\r
423 ot(" movs r5,r1\n");\r
424 ot(" beq c_unpack_do_pc\n");\r
425 ot(" mov r3,#16\n");\r
426 ot(";@ 0x00-0x3f: DA registers\n");\r
427 ot("c_unpack_loop%s\n",ms?"":":");\r
428 ot(" ldr r1,[r5],#4\n");\r
429 ot(" subs r3,r3,#1\n");\r
430 ot(" str r1,[r0],#4\n");\r
431 ot(" bne c_unpack_loop\n");\r
432 ot(";@ 0x40: PC\n");\r
433 ot(" ldr r0,[r5],#4 ;@ PC\n");\r
434 ot(" str r0,[r7,#0x40] ;@ handle later\n");\r
435 ot(";@ 0x44: SR\n");\r
436 ot(" ldrh r1,[r5],#2\n");\r
437 ot(" mov r0,r7\n");\r
438 ot(" bl CycloneSetSr\n");\r
439 ot(";@ 0x46: IRQ level\n");\r
440 ot(" ldrb r0,[r5],#2\n");\r
441 ot(" strb r0,[r7,#0x47]\n");\r
442 ot(";@ 0x48: other SP\n");\r
443 ot(" ldr r0,[r5],#4\n");\r
444 ot(" str r0,[r7,#0x48]\n");\r
445 ot(";@ 0x4c: CPU state flags\n");\r
446 ot(" ldr r0,[r5],#4\n");\r
447 ot(" str r0,[r7,#0x58]\n");\r
448 ot("c_unpack_do_pc%s\n",ms?"":":");\r
449 ot(" ldr r0,[r7,#0x40] ;@ unbased PC\n");\r
450#if USE_CHECKPC_CALLBACK\r
451 ot(" mov r1,#0\n");\r
452 ot(" str r1,[r7,#0x60] ;@ Memory base\n");\r
453 #ifdef MEMHANDLERS_DIRECT_PREFIX\r
454 ot(" bl %scheckpc ;@ Call checkpc()\n", MEMHANDLERS_DIRECT_PREFIX);\r
455 #else\r
456 ot(" mov lr,pc\n");\r
457 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");\r
458 #endif\r
459#else\r
460 ot(" ldr r1,[r7,#0x60] ;@ Memory base\n");\r
461 ot(" add r0,r0,r1 ;@ r0 = Memory Base + New PC\n");\r
462#endif\r
463 ot(" str r0,[r7,#0x40] ;@ PC + Memory Base\n");\r
464 ot(" ldmfd sp!,{r5,r7,pc}\n");\r
465 ot("\n");\r
466\r
467 // --------------\r
468 ot("CycloneFlushIrq%s\n", ms?"":":");\r
469 ot(" ldr r1,[r0,#0x44] ;@ Get SR high T_S__III and irq level\n");\r
470 ot(" mov r2,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47]\r
471 ot(" cmp r2,#6 ;@ irq>6 ?\n");\r
472 ot(" andle r1,r1,#7 ;@ Get interrupt mask\n");\r
473 ot(" cmple r2,r1 ;@ irq<=6: Is irq<=mask ?\n");\r
474 ot(" movle r0,#0\n");\r
475 ot(" bxle lr ;@ no ints\n");\r
476 ot("\n");\r
477 ot(" stmdb sp!,{r4,r5,r7,r8,r10,r11,lr}\n");\r
478 ot(" mov r7,r0\n");\r
479 ot(" mov r0,r2\n");\r
480 ot(" ldrb r10,[r7,#0x46] ;@ r10 = Flags (NZCV)\n");\r
481 ot(" mov r5,#0\n");\r
482 ot(" ldr r4,[r7,#0x40] ;@ r4 = Current PC + Memory Base\n");\r
483 ot(" mov r10,r10,lsl #28 ;@ r10 = Flags 0xf0000000, cpsr format\n");\r
484 ot(" adr r2,CycloneFlushIrqEnd\n");\r
485 ot(" str r2,[r7,#0x98] ;@ set custom CycloneEnd\n");\r
486 ot(" b CycloneDoInterrupt\n");\r
487 ot("\n");\r
488 ot("CycloneFlushIrqEnd%s\n", ms?"":":");\r
489 ot(" rsb r0,r5,#0\n");\r
490 ot(" str r4,[r7,#0x40] ;@ Save Current PC + Memory Base\n");\r
491 ot(" strb r10,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
492 ot(" ldmia sp!,{r4,r5,r7,r8,r10,r11,lr}\n");\r
493 ot(" bx lr\n");\r
494 ot("\n");\r
495 ot("\n");\r
496\r
497 // --------------\r
498 ot("CycloneSetRealTAS%s\n", ms?"":":");\r
499#if (CYCLONE_FOR_GENESIS == 2)\r
500 ot(" ldr r12,=CycloneJumpTab\n");\r
501 ot(" tst r0,r0\n");\r
502 ot(" add r12,r12,#0x4a00*4\n");\r
503 ot(" add r12,r12,#0x00d0*4\n");\r
504 ot(" beq setrtas_off\n");\r
505 ChangeTAS(1);\r
506 ot(" bx lr\n");\r
507 ot("setrtas_off%s\n",ms?"":":");\r
508 ChangeTAS(0);\r
509 ot(" bx lr\n");\r
510 ltorg();\r
511#else\r
512 ot(" bx lr\n");\r
513#endif\r
514 ot("\n");\r
515\r
516 // --------------\r
517 ot(";@ DoInterrupt - r0=IRQ level\n");\r
518 ot("CycloneDoInterruptGoBack%s\n", ms?"":":");\r
519 ot(" sub r4,r4,#2\n");\r
520 ot("CycloneDoInterrupt%s\n", ms?"":":");\r
521 ot(" bic r8,r8,#0xff000000\n");\r
522 ot(" orr r8,r8,r0,lsl #29 ;@ abuse r8\n");\r
523\r
524 // Steps are from "M68000 8-/16-/32-BIT MICROPROCESSORS USER'S MANUAL", p. 6-4\r
525 // but their order is based on http://pasti.fxatari.com/68kdocs/68kPrefetch.html\r
526 // 1. Make a temporary copy of the status register and set the status register for exception processing.\r
527 ot(" ldr r2,[r7,#0x58] ;@ state flags\n");\r
528 ot(" and r0,r0,#7\n");\r
529 ot(" orr r3,r0,#0x20 ;@ Supervisor mode + IRQ level\n");\r
530 ot(" bic r2,r2,#3 ;@ clear stopped and trace states\n");\r
531#if EMULATE_ADDRESS_ERRORS_JUMP || EMULATE_ADDRESS_ERRORS_IO\r
532 ot(" orr r2,r2,#4 ;@ set activity bit: 'not processing instruction'\n");\r
533#endif\r
534 ot(" str r2,[r7,#0x58]\n");\r
535 ot(" ldrb r6,[r7,#0x44] ;@ Get old SR high, abuse r6\n");\r
536 ot(" strb r3,[r7,#0x44] ;@ Put new SR high\n");\r
6003a768 537 ot("\n");\r
d9d77995 538\r
539 // 3. Save the current processor context.\r
540 ot(" ldr r1,[r7,#0x60] ;@ Get Memory base\n");\r
541 ot(" ldr r11,[r7,#0x3c] ;@ Get A7\n");\r
542 ot(" tst r6,#0x20\n");\r
543 ot(";@ get our SP:\n");\r
544 ot(" ldreq r2,[r7,#0x48] ;@ ...or OSP as our stack pointer\n");\r
545 ot(" streq r11,[r7,#0x48]\n");\r
546 ot(" moveq r11,r2\n");\r
547 ot(";@ Push old PC onto stack\n");\r
548 ot(" sub r0,r11,#4 ;@ Predecremented A7\n");\r
549 ot(" sub r1,r4,r1 ;@ r1 = Old PC\n");\r
550 MemHandler(1,2);\r
551 ot(";@ Push old SR:\n");\r
552 ot(" ldr r0,[r7,#0x4c] ;@ X bit\n");\r
553 ot(" mov r1,r10,lsr #28 ;@ ____NZCV\n");\r
554 ot(" eor r2,r1,r1,ror #1 ;@ Bit 0=C^V\n");\r
555 ot(" tst r2,#1 ;@ 1 if C!=V\n");\r
556 ot(" eorne r1,r1,#3 ;@ ____NZVC\n");\r
557 ot(" and r0,r0,#0x20000000\n");\r
558 ot(" orr r1,r1,r0,lsr #25 ;@ ___XNZVC\n");\r
559 ot(" orr r1,r1,r6,lsl #8 ;@ Include old SR high\n");\r
560 ot(" sub r0,r11,#6 ;@ Predecrement A7\n");\r
561 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
562 MemHandler(1,1,0,0); // already checked for address error by prev MemHandler\r
6003a768 563 ot("\n");\r
d9d77995 564\r
565 // 2. Obtain the exception vector.\r
566 ot(" mov r11,r8,lsr #29\n");\r
567 ot(" mov r0,r11\n");\r
568#if USE_INT_ACK_CALLBACK\r
569 ot(";@ call IrqCallback if it is defined\n");\r
570#if INT_ACK_NEEDS_STUFF\r
571 ot(" str r4,[r7,#0x40] ;@ Save PC\n");\r
572 ot(" mov r1,r10,lsr #28\n");\r
573 ot(" strb r1,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
574 ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
575#endif\r
576 ot(" ldr r3,[r7,#0x8c] ;@ IrqCallback\n");\r
577 ot(" add lr,pc,#4*3\n");\r
578 ot(" tst r3,r3\n");\r
579 ot(" streqb r3,[r7,#0x47] ;@ just clear IRQ if there is no callback\n");\r
580 ot(" mvneq r0,#0 ;@ and simulate -1 return\n");\r
581 ot(" bxne r3\n");\r
582#if INT_ACK_CHANGES_CYCLES\r
583 ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
584#endif\r
585 ot(";@ get IRQ vector address:\n");\r
586 ot(" cmn r0,#1 ;@ returned -1?\n");\r
587 ot(" addeq r0,r11,#0x18 ;@ use autovector then\n");\r
588 ot(" cmn r0,#2 ;@ returned -2?\n"); // should be safe as above add should never result in -2\r
589 ot(" moveq r0,#0x18 ;@ use spurious interrupt then\n");\r
590#else // !USE_INT_ACK_CALLBACK\r
6003a768 591 ot(";@ Clear irq:\n");\r
d9d77995 592 ot(" mov r2,#0\n");\r
593 ot(" strb r2,[r7,#0x47]\n");\r
594 ot(" add r0,r0,#0x18 ;@ use autovector\n");\r
595#endif\r
596 ot(" mov r0,r0,lsl #2 ;@ get vector address\n");\r
597 ot("\n");\r
598 ot(" ldr r11,[r7,#0x60] ;@ Get Memory base\n");\r
599 ot(";@ Read IRQ Vector:\n");\r
600 MemHandler(0,2,0,0);\r
601 ot(" tst r0,r0 ;@ uninitialized int vector?\n");\r
602 ot(" moveq r0,#0x3c\n");\r
603 #ifdef MEMHANDLERS_DIRECT_PREFIX\r
604 ot(" bleq %sread32 ;@ Call read32(r0) handler\n", MEMHANDLERS_DIRECT_PREFIX);\r
605 #else\r
606 ot(" moveq lr,pc\n");\r
607 ot(" ldreq pc,[r7,#0x70] ;@ Call read32(r0) handler\n");\r
608 #endif\r
609#if USE_CHECKPC_CALLBACK\r
610 ot(" add lr,pc,#4\n");\r
611 ot(" add r0,r0,r11 ;@ r0 = Memory Base + New PC\n");\r
612 #ifdef MEMHANDLERS_DIRECT_PREFIX\r
613 ot(" bl %scheckpc ;@ Call checkpc()\n", MEMHANDLERS_DIRECT_PREFIX);\r
614 #else\r
615 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");\r
616 #endif\r
617 #if EMULATE_ADDRESS_ERRORS_JUMP\r
618 ot(" mov r4,r0\n");\r
619 #else\r
620 ot(" bic r4,r0,#1\n");\r
621 #endif\r
622#else\r
623 ot(" add r4,r0,r11 ;@ r4 = Memory Base + New PC\n");\r
624 #if EMULATE_ADDRESS_ERRORS_JUMP\r
625 ot(" bic r4,r4,#1\n");\r
626 #endif\r
627#endif\r
6003a768 628 ot("\n");\r
629\r
d9d77995 630 // 4. Obtain a new context and resume instruction processing.\r
631 // note: the obtain part was already done in previous steps\r
632#if EMULATE_ADDRESS_ERRORS_JUMP\r
633 ot(" tst r4,#1\n");\r
634 ot(" bne ExceptionAddressError_r_prg_r4\n");\r
635#endif\r
636 ot(" ldr r6,[r7,#0x54]\n");\r
637 ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");\r
638 ot(" subs r5,r5,#44 ;@ Subtract cycles\n");\r
c204973a 639 ot(" ldrgt pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r
d9d77995 640 ot(" b CycloneEnd\n");\r
6003a768 641 ot("\n");\r
d9d77995 642\r
643 // --------------\r
644 // trashes all temp regs\r
645 ot("Exception%s\n", ms?"":":");\r
646 ot(" ;@ Cause an Exception - Vector number in r0\n");\r
6003a768 647 ot(" mov r11,lr ;@ Preserve ARM return address\n");\r
d9d77995 648 ot(" bic r8,r8,#0xff000000\n");\r
649 ot(" orr r8,r8,r0,lsl #24 ;@ abuse r8\n");\r
650\r
651 // 1. Make a temporary copy of the status register and set the status register for exception processing.\r
652 ot(" ldr r6,[r7,#0x44] ;@ Get old SR high, abuse r6\n");\r
653 ot(" ldr r2,[r7,#0x58] ;@ state flags\n");\r
654 ot(" and r3,r6,#0x27 ;@ clear trace and unused flags\n");\r
655 ot(" orr r3,r3,#0x20 ;@ set supervisor mode\n");\r
656 ot(" bic r2,r2,#3 ;@ clear stopped and trace states\n");\r
657 ot(" str r2,[r7,#0x58]\n");\r
658 ot(" strb r3,[r7,#0x44] ;@ Put new SR high\n");\r
659 ot("\n");\r
660\r
661 // 3. Save the current processor context.\r
662 ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n");\r
663 ot(" tst r6,#0x20\n");\r
664 ot(";@ get our SP:\n");\r
665 ot(" ldreq r2,[r7,#0x48] ;@ ...or OSP as our stack pointer\n");\r
666 ot(" streq r0,[r7,#0x48]\n");\r
667 ot(" moveq r0,r2\n");\r
668 ot(";@ Push old PC onto stack\n");\r
669 ot(" ldr r1,[r7,#0x60] ;@ Get Memory base\n");\r
670 ot(" sub r0,r0,#4 ;@ Predecremented A7\n");\r
671 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
672 ot(" sub r1,r4,r1 ;@ r1 = Old PC\n");\r
673 MemHandler(1,2);\r
674 ot(";@ Push old SR:\n");\r
675 ot(" ldr r0,[r7,#0x4c] ;@ X bit\n");\r
676 ot(" mov r1,r10,lsr #28 ;@ ____NZCV\n");\r
677 ot(" eor r2,r1,r1,ror #1 ;@ Bit 0=C^V\n");\r
678 ot(" tst r2,#1 ;@ 1 if C!=V\n");\r
679 ot(" eorne r1,r1,#3 ;@ ____NZVC\n");\r
680 ot(" and r0,r0,#0x20000000\n");\r
681 ot(" orr r1,r1,r0,lsr #25 ;@ ___XNZVC\n");\r
682 ot(" ldr r0,[r7,#0x3c] ;@ A7\n");\r
683 ot(" orr r1,r1,r6,lsl #8 ;@ Include SR high\n");\r
684 ot(" sub r0,r0,#2 ;@ Predecrement A7\n");\r
685 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
686 MemHandler(1,1,0,0);\r
687 ot("\n");\r
688\r
689 // 2. Obtain the exception vector\r
690 ot(";@ Read Exception Vector:\n");\r
691 ot(" mov r0,r8,lsr #24\n");\r
692 ot(" mov r0,r0,lsl #2\n");\r
693 MemHandler(0,2,0,0);\r
694 ot(" ldr r3,[r7,#0x60] ;@ Get Memory base\n");\r
695#if USE_CHECKPC_CALLBACK\r
696 ot(" add lr,pc,#4\n");\r
697 ot(" add r0,r0,r3 ;@ r0 = Memory Base + New PC\n");\r
698 #ifdef MEMHANDLERS_DIRECT_PREFIX\r
699 ot(" bl %scheckpc ;@ Call checkpc()\n", MEMHANDLERS_DIRECT_PREFIX);\r
700 #else\r
701 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");\r
702 #endif\r
703 #if EMULATE_ADDRESS_ERRORS_JUMP\r
704 ot(" mov r4,r0\n");\r
705 #else\r
706 ot(" bic r4,r0,#1\n");\r
707 #endif\r
708#else\r
709 ot(" add r4,r0,r3 ;@ r4 = Memory Base + New PC\n");\r
710 #if EMULATE_ADDRESS_ERRORS_JUMP\r
711 ot(" bic r4,r4,#1\n");\r
712 #endif\r
713#endif\r
6003a768 714 ot("\n");\r
d9d77995 715\r
716 // 4. Resume execution.\r
717#if EMULATE_ADDRESS_ERRORS_JUMP\r
718 ot(" tst r4,#1\n");\r
719 ot(" bne ExceptionAddressError_r_prg_r4\n");\r
720#endif\r
721 ot(" ldr r6,[r7,#0x54]\n");\r
722 ot(" bx r11 ;@ Return\n");\r
723 ot("\n");\r
724\r
725 // --------------\r
726#if EMULATE_ADDRESS_ERRORS_JUMP || EMULATE_ADDRESS_ERRORS_IO\r
727 // first some wrappers: I see no point inlining this code,\r
728 // as it will be executed in really rare cases.\r
729 AddressErrorWrapper('r', "data", 0x11);\r
730 AddressErrorWrapper('r', "prg", 0x12);\r
731 AddressErrorWrapper('w', "data", 0x01);\r
732 // there are no program writes\r
733 // cpu space is only for bus errors?\r
734 ot("ExceptionAddressError_r_prg_r4%s\n", ms?"":":");\r
735 ot(" ldr r1,[r7,#0x44]\n");\r
736 ot(" ldr r3,[r7,#0x60] ;@ Get Memory base\n");\r
737 ot(" mov r6,#0x12\n");\r
738 ot(" sub r11,r4,r3\n");\r
739 ot(" tst r1,#0x20\n");\r
740 ot(" orrne r6,r6,#4\n");\r
741 ot("\n");\r
742\r
743 ot("ExceptionAddressError%s\n", ms?"":":");\r
744 ot(";@ r6 - info word (without instruction/not bit), r11 - faulting address\n");\r
745\r
746 // 1. Make a temporary copy of the status register and set the status register for exception processing.\r
747 ot(" ldrb r0,[r7,#0x44] ;@ Get old SR high\n");\r
748 ot(" ldr r2,[r7,#0x58] ;@ state flags\n");\r
749 ot(" and r3,r0,#0x27 ;@ clear trace and unused flags\n");\r
750 ot(" orr r3,r3,#0x20 ;@ set supervisor mode\n");\r
751 ot(" strb r3,[r7,#0x44] ;@ Put new SR high\n");\r
752 ot(" bic r2,r2,#3 ;@ clear stopped and trace states\n");\r
753 ot(" tst r2,#4\n");\r
754 ot(" orrne r6,r6,#8 ;@ complete info word\n");\r
755 ot(" orr r2,r2,#4 ;@ set activity bit: 'not processing instruction'\n");\r
756#if EMULATE_HALT\r
757 ot(" tst r2,#8\n");\r
758 ot(" orrne r2,r2,#0x10 ;@ HALT\n");\r
759 ot(" orr r2,r2,#8 ;@ processing address error\n");\r
760 ot(" str r2,[r7,#0x58]\n");\r
761 ot(" movne r5,#0\n");\r
762 ot(" bne CycloneEndNoBack ;@ bye bye\n");\r
763#else\r
764 ot(" str r2,[r7,#0x58]\n");\r
765#endif\r
766 ot(" and r10,r10,#0xf0000000\n");\r
767 ot(" orr r10,r10,r0,lsl #4 ;@ some preparations for SR push\n");\r
768 ot("\n");\r
769\r
770 // 3. Save the current processor context + additional information.\r
771 ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n");\r
772 ot(" tst r10,#0x200\n");\r
773 ot(";@ get our SP:\n");\r
774 ot(" ldreq r2,[r7,#0x48] ;@ ...or OSP as our stack pointer\n");\r
775 ot(" streq r0,[r7,#0x48]\n");\r
776 ot(" moveq r0,r2\n");\r
777 // PC\r
778 ot(";@ Push old PC onto stack\n");\r
779 ot(" ldr r1,[r7,#0x60] ;@ Get Memory base\n");\r
780 ot(" sub r0,r0,#4 ;@ Predecremented A7\n");\r
781 ot(" sub r1,r4,r1 ;@ r1 = Old PC\n");\r
782 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
783 MemHandler(1,2,0,EMULATE_HALT);\r
784 // SR\r
785 ot(";@ Push old SR:\n");\r
786 ot(" ldr r0,[r7,#0x4c] ;@ X bit\n");\r
787 ot(" mov r1,r10,ror #28 ;@ ____NZCV\n");\r
788 ot(" eor r2,r1,r1,ror #1 ;@ Bit 0=C^V\n");\r
789 ot(" tst r2,#1 ;@ 1 if C!=V\n");\r
790 ot(" eorne r1,r1,#3 ;@ ____NZVC\n");\r
791 ot(" and r0,r0,#0x20000000\n");\r
792 ot(" orr r1,r1,r0,lsr #25 ;@ ___XNZVC\n");\r
793 ot(" ldr r0,[r7,#0x3c] ;@ A7\n");\r
794 ot(" and r10,r10,#0xf0000000\n");\r
795 ot(" sub r0,r0,#2 ;@ Predecrement A7\n");\r
796 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
797 MemHandler(1,1,0,0);\r
798 // IR (instruction register)\r
799 ot(";@ Push IR:\n");\r
800 ot(" ldr r0,[r7,#0x3c] ;@ A7\n");\r
801 ot(" mov r1,r8\n");\r
802 ot(" sub r0,r0,#2 ;@ Predecrement A7\n");\r
803 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
804 MemHandler(1,1,0,0);\r
805 // access address\r
806 ot(";@ Push address:\n");\r
807 ot(" ldr r0,[r7,#0x3c] ;@ A7\n");\r
808 ot(" mov r1,r11\n");\r
809 ot(" sub r0,r0,#4 ;@ Predecrement A7\n");\r
810 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
811 MemHandler(1,2,0,0);\r
812 // information word\r
813 ot(";@ Push info word:\n");\r
814 ot(" ldr r0,[r7,#0x3c] ;@ A7\n");\r
815 ot(" mov r1,r6\n");\r
816 ot(" sub r0,r0,#2 ;@ Predecrement A7\n");\r
817 ot(" str r0,[r7,#0x3c] ;@ Save A7\n");\r
818 MemHandler(1,1,0,0);\r
819 ot("\n");\r
820\r
821 // 2. Obtain the exception vector\r
822 ot(";@ Read Exception Vector:\n");\r
823 ot(" mov r0,#0x0c\n");\r
824 MemHandler(0,2,0,0);\r
825 ot(" ldr r3,[r7,#0x60] ;@ Get Memory base\n");\r
826#if USE_CHECKPC_CALLBACK\r
827 ot(" add lr,pc,#4\n");\r
828 ot(" add r0,r0,r3 ;@ r0 = Memory Base + New PC\n");\r
829 #ifdef MEMHANDLERS_DIRECT_PREFIX\r
830 ot(" bl %scheckpc ;@ Call checkpc()\n", MEMHANDLERS_DIRECT_PREFIX);\r
831 #else\r
832 ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n");\r
833 #endif\r
834 ot(" mov r4,r0\n");\r
835#else\r
836 ot(" add r4,r0,r3 ;@ r4 = Memory Base + New PC\n");\r
837#endif\r
838 ot("\n");\r
839\r
840#if EMULATE_ADDRESS_ERRORS_JUMP && EMULATE_HALT\r
841 ot(" tst r4,#1\n");\r
842 ot(" bne ExceptionAddressError_r_prg_r4\n");\r
843#else\r
844 ot(" bic r4,r4,#1\n");\r
845#endif\r
846\r
847 // 4. Resume execution.\r
848 ot(" ldr r6,[r7,#0x54]\n");\r
849 ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");\r
850 ot(" subs r5,r5,#50 ;@ Subtract cycles\n");\r
c204973a 851 ot(" ldrgt pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r
d9d77995 852 ot(" b CycloneEnd\n");\r
853 ot("\n");\r
854#endif\r
855\r
856 // --------------\r
857#if EMULATE_TRACE\r
858 // expects srh and irq level in r1, next opcode already fetched to r8\r
859 ot("CycloneDoTraceWithChecks%s\n", ms?"":":");\r
860 ot(" ldr r0,[r7,#0x58]\n");\r
861 ot(" cmp r5,#0\n");\r
862 ot(" orr r0,r0,#2 ;@ go to trace mode\n");\r
863 ot(" str r0,[r7,#0x58]\n");\r
c204973a 864 ot(" ble CycloneEnd\n"); // should take care of situation where we come here when already tracing\r
d9d77995 865 ot(";@ CheckInterrupt:\n");\r
866 ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n");\r
867 ot(" beq CycloneDoTrace\n");\r
868 ot(" cmp r0,#6 ;@ irq>6 ?\n");\r
869 ot(" andle r1,r1,#7 ;@ Get interrupt mask\n");\r
870 ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n");\r
871 ot(" bgt CycloneDoInterruptGoBack\n");\r
872 ot("\n");\r
873\r
874 // expects next opcode to be already fetched to r8\r
875 ot("CycloneDoTrace%s\n", ms?"":":");\r
876 ot(" str r5,[r7,#0x9c] ;@ save cycles\n");\r
877 ot(" ldr r1,[r7,#0x98]\n");\r
878 ot(" mov r5,#0\n");\r
879 ot(" str r1,[r7,#0xa0]\n");\r
880 ot(" adr r0,TraceEnd\n");\r
881 ot(" str r0,[r7,#0x98] ;@ store TraceEnd as CycloneEnd hadler\n");\r
882 ot(" ldr pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r
883 ot("\n");\r
884\r
885 ot("TraceEnd%s\n", ms?"":":");\r
886 ot(" ldr r2,[r7,#0x58]\n");\r
887 ot(" ldr r0,[r7,#0x9c] ;@ restore cycles\n");\r
888 ot(" ldr r1,[r7,#0xa0] ;@ old CycloneEnd handler\n");\r
889 ot(" mov r10,r10,lsl #28\n");\r
890 ot(" add r5,r0,r5\n");\r
891 ot(" str r1,[r7,#0x98]\n");\r
892 ot(";@ still tracing?\n"); // exception might have happend\r
893 ot(" tst r2,#2\n");\r
894 ot(" beq TraceDisabled\n");\r
895 ot(";@ trace exception\n");\r
896#if EMULATE_ADDRESS_ERRORS_JUMP || EMULATE_ADDRESS_ERRORS_IO\r
897 ot(" ldr r1,[r7,#0x58]\n");\r
898 ot(" mov r0,#9\n");\r
899 ot(" orr r1,r1,#4 ;@ set activity bit: 'not processing instruction'\n");\r
900 ot(" str r1,[r7,#0x58]\n");\r
901#else\r
902 ot(" mov r0,#9\n");\r
903#endif\r
904 ot(" bl Exception\n");\r
905 ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");\r
906 ot(" subs r5,r5,#34 ;@ Subtract cycles\n");\r
c204973a 907 ot(" ldrgt pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r
d9d77995 908 ot(" b CycloneEnd\n");\r
909 ot("\n");\r
910 ot("TraceDisabled%s\n", ms?"":":");\r
911 ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n");\r
912 ot(" cmp r5,#0\n");\r
c204973a 913 ot(" ldrgt pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n");\r
d9d77995 914 ot(" b CycloneEnd\n");\r
915 ot("\n");\r
916#endif\r
6003a768 917}\r
918\r
919// ---------------------------------------------------------------------------\r
920// Call Read(r0), Write(r0,r1) or Fetch(r0)\r
d9d77995 921// Trashes r0-r3,r12,lr\r
922int MemHandler(int type,int size,int addrreg,int need_addrerr_check)\r
6003a768 923{\r
d9d77995 924 int func=0x68+type*0xc+(size<<2); // Find correct offset\r
925 char what[32];\r
6003a768 926\r
d9d77995 927#if MEMHANDLERS_NEED_FLAGS\r
928 ot(" mov r3,r10,lsr #28\n");\r
929 ot(" strb r3,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
930#endif\r
931 FlushPC();\r
6003a768 932\r
d9d77995 933#if (MEMHANDLERS_ADDR_MASK & 0xff000000)\r
934 ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0xff000000);\r
935 addrreg=0;\r
936#endif\r
937#if (MEMHANDLERS_ADDR_MASK & 0x00ff0000)\r
938 ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x00ff0000);\r
939 addrreg=0;\r
940#endif\r
941#if (MEMHANDLERS_ADDR_MASK & 0x0000ff00)\r
942 ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x0000ff00);\r
943 addrreg=0;\r
944#endif\r
945#if (MEMHANDLERS_ADDR_MASK & 0x000000ff)\r
946 ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x000000ff);\r
947 addrreg=0;\r
948#endif\r
949\r
950#if EMULATE_ADDRESS_ERRORS_IO\r
951 if (size > 0 && need_addrerr_check)\r
952 {\r
953 ot(" add lr,pc,#4*%i\n", addrreg==0?2:3); // helps to prevent interlocks\r
954 if (addrreg != 0) ot(" mov r0,r%i\n", addrreg);\r
955 ot(" tst r0,#1 ;@ address error?\n");\r
956 switch (type) {\r
957 case 0: ot(" bne ExceptionAddressError_r_data\n"); break;\r
958 case 1: ot(" bne ExceptionAddressError_w_data\n"); break;\r
959 case 2: ot(" bne ExceptionAddressError_r_prg\n"); break;\r
960 }\r
961 }\r
962 else\r
963#endif\r
964\r
965 sprintf(what, "%s%d", type==0 ? "read" : (type==1 ? "write" : "fetch"), 8<<size);\r
966#ifdef MEMHANDLERS_DIRECT_PREFIX\r
967 if (addrreg != 0)\r
968 ot(" mov r0,r%i\n", addrreg);\r
969 ot(" bl %s%s ;@ Call ", MEMHANDLERS_DIRECT_PREFIX, what);\r
970 (void)func; // avoid warning\r
971#else\r
972 if (addrreg != 0)\r
973 {\r
974 ot(" add lr,pc,#4\n");\r
975 ot(" mov r0,r%i\n", addrreg);\r
976 }\r
977 else\r
978 ot(" mov lr,pc\n");\r
6003a768 979 ot(" ldr pc,[r7,#0x%x] ;@ Call ",func);\r
d9d77995 980#endif\r
6003a768 981\r
982 // Document what we are calling:\r
d9d77995 983 if (type==1) ot("%s(r0,r1)",what);\r
984 else ot("%s(r0)", what);\r
6003a768 985 ot(" handler\n");\r
986\r
d9d77995 987#if MEMHANDLERS_CHANGE_FLAGS\r
988 ot(" ldrb r10,[r7,#0x46] ;@ r10 = Load Flags (NZCV)\n");\r
989 ot(" mov r10,r10,lsl #28\n");\r
990#endif\r
991#if MEMHANDLERS_CHANGE_PC\r
992 ot(" ldr r4,[r7,#0x40] ;@ Load PC\n");\r
993#endif\r
994\r
6003a768 995 return 0;\r
996}\r
997\r
998static void PrintOpcodes()\r
999{\r
1000 int op=0;\r
d9d77995 1001\r
6003a768 1002 printf("Creating Opcodes: [");\r
1003\r
1004 ot(";@ ---------------------------- Opcodes ---------------------------\n");\r
1005\r
1006 // Emit null opcode:\r
1007 ot("Op____%s ;@ Called if an opcode is not recognised\n", ms?"":":");\r
d9d77995 1008#if EMULATE_ADDRESS_ERRORS_JUMP || EMULATE_ADDRESS_ERRORS_IO\r
1009 ot(" ldr r1,[r7,#0x58]\n");\r
1010 ot(" sub r4,r4,#2\n");\r
1011 ot(" orr r1,r1,#4 ;@ set activity bit: 'not processing instruction'\n");\r
1012 ot(" str r1,[r7,#0x58]\n");\r
1013#else\r
1014 ot(" sub r4,r4,#2\n");\r
1015#endif\r
1016#if USE_UNRECOGNIZED_CALLBACK\r
1017 ot(" str r4,[r7,#0x40] ;@ Save PC\n");\r
1018 ot(" mov r1,r10,lsr #28\n");\r
1019 ot(" strb r1,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
1020 ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
1021 ot(" ldr r11,[r7,#0x94] ;@ UnrecognizedCallback\n");\r
1022 ot(" tst r11,r11\n");\r
1023 ot(" movne lr,pc\n");\r
1024 ot(" movne pc,r11 ;@ call UnrecognizedCallback if it is defined\n");\r
1025 ot(" ldrb r10,[r7,#0x46] ;@ r10 = Load Flags (NZCV)\n");\r
1026 ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
1027 ot(" ldr r4,[r7,#0x40] ;@ Load PC\n");\r
1028 ot(" mov r10,r10,lsl #28\n");\r
1029 ot(" tst r0,r0\n");\r
1030 ot(" moveq r0,#4\n");\r
1031 ot(" bleq Exception\n");\r
1032#else\r
1033 ot(" mov r0,#4\n");\r
1034 ot(" bl Exception\n");\r
1035#endif\r
1036 ot("\n");\r
1037 Cycles=34;\r
1038 OpEnd();\r
1039\r
1040 // Unrecognised a-line and f-line opcodes throw an exception:\r
1041 ot("Op__al%s ;@ Unrecognised a-line opcode\n", ms?"":":");\r
1042 ot(" sub r4,r4,#2\n");\r
1043#if USE_AFLINE_CALLBACK\r
1044 ot(" str r4,[r7,#0x40] ;@ Save PC\n");\r
1045 ot(" mov r1,r10,lsr #28\n");\r
1046 ot(" strb r1,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
1047 ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
1048 ot(" ldr r11,[r7,#0x94] ;@ UnrecognizedCallback\n");\r
1049 ot(" tst r11,r11\n");\r
1050 ot(" movne lr,pc\n");\r
1051 ot(" movne pc,r11 ;@ call UnrecognizedCallback if it is defined\n");\r
1052 ot(" ldrb r10,[r7,#0x46] ;@ r10 = Load Flags (NZCV)\n");\r
1053 ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
1054 ot(" ldr r4,[r7,#0x40] ;@ Load PC\n");\r
1055 ot(" mov r10,r10,lsl #28\n");\r
1056 ot(" tst r0,r0\n");\r
1057 ot(" moveq r0,#0x0a\n");\r
1058 ot(" bleq Exception\n");\r
1059#else\r
1060 ot(" mov r0,#0x0a\n");\r
1061 ot(" bl Exception\n");\r
1062#endif\r
1063 ot("\n");\r
1064 Cycles=4;\r
1065 OpEnd();\r
1066\r
1067 ot("Op__fl%s ;@ Unrecognised f-line opcode\n", ms?"":":");\r
1068 ot(" sub r4,r4,#2\n");\r
1069#if USE_AFLINE_CALLBACK\r
1070 ot(" str r4,[r7,#0x40] ;@ Save PC\n");\r
1071 ot(" mov r1,r10,lsr #28\n");\r
1072 ot(" strb r1,[r7,#0x46] ;@ Save Flags (NZCV)\n");\r
1073 ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n");\r
1074 ot(" ldr r11,[r7,#0x94] ;@ UnrecognizedCallback\n");\r
1075 ot(" tst r11,r11\n");\r
1076 ot(" movne lr,pc\n");\r
1077 ot(" movne pc,r11 ;@ call UnrecognizedCallback if it is defined\n");\r
1078 ot(" ldrb r10,[r7,#0x46] ;@ r10 = Load Flags (NZCV)\n");\r
1079 ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
1080 ot(" ldr r4,[r7,#0x40] ;@ Load PC\n");\r
1081 ot(" mov r10,r10,lsl #28\n");\r
1082 ot(" tst r0,r0\n");\r
1083 ot(" moveq r0,#0x0b\n");\r
1084 ot(" bleq Exception\n");\r
1085#else\r
1086 ot(" mov r0,#0x0b\n");\r
1087 ot(" bl Exception\n");\r
1088#endif\r
1089 ot("\n");\r
1090 Cycles=4;\r
1091 OpEnd();\r
1092\r
6003a768 1093\r
d9d77995 1094 for (op=0;op<hot_opcode_count;op++)\r
1095 OpAny(hot_opcodes[op]);\r
6003a768 1096\r
1097 for (op=0;op<0x10000;op++)\r
1098 {\r
1099 if ((op&0xfff)==0) { printf("%x",op>>12); fflush(stdout); } // Update progress\r
1100\r
d9d77995 1101 if (!is_op_hot(op))\r
1102 OpAny(op);\r
6003a768 1103 }\r
1104\r
1105 ot("\n");\r
1106\r
1107 printf("]\n");\r
1108}\r
1109\r
d9d77995 1110// helper\r
1111static void ott(const char *str, int par, const char *nl, int nlp, int counter, int size)\r
1112{\r
1113 switch(size) {\r
1114 case 0: if((counter&7)==0) ot(ms?" dcb ":" .byte "); break;\r
1115 case 1: if((counter&7)==0) ot(ms?" dcw ":" .hword "); break;\r
1116 case 2: if((counter&7)==0) ot(ms?" dcd ":" .long "); break;\r
1117 }\r
1118 ot(str, par);\r
1119 if((counter&7)==7) ot(nl,nlp); else ot(",");\r
1120}\r
1121\r
6003a768 1122static void PrintJumpTable()\r
1123{\r
1124 int i=0,op=0,len=0;\r
1125\r
1126 ot(";@ -------------------------- Jump Table --------------------------\n");\r
6003a768 1127\r
d9d77995 1128 // space for decompressed table\r
1129 ot(ms?" area |.data|, data\n":" .data\n .align 4\n\n");\r
6003a768 1130\r
d9d77995 1131#if COMPRESS_JUMPTABLE\r
1132 int handlers=0,reps=0,*indexes,ip,u,out;\r
1133 // use some weird compression on the jump table\r
1134 indexes=(int *)malloc(0x10000*4);\r
1135 if(!indexes) { printf("ERROR: out of memory\n"); exit(1); }\r
1136 len=0x10000;\r
6003a768 1137\r
d9d77995 1138 ot("CycloneJumpTab%s\n", ms?"":":");\r
1139 if(ms) {\r
1140 for(i = 0; i < 0xa000/8; i++)\r
1141 ot(" dcd 0,0,0,0,0,0,0,0\n");\r
1142 } else\r
1143 ot(" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", 0xa000/8);\r
1144\r
1145 // hanlers live in "a-line" part of the table\r
1146 // first output nop,a-line,f-line handlers\r
1147 ot(ms?" dcd Op____,Op__al,Op__fl,":" .long Op____,Op__al,Op__fl,");\r
1148 handlers=3;\r
1149\r
1150 for(i=0;i<len;i++)\r
1151 {\r
1152 op=CyJump[i];\r
1153\r
1154 for(u=i-1; u>=0; u--) if(op == CyJump[u]) break; // already done with this op?\r
1155 if(u==-1 && op >= 0) {\r
1156 ott("Op%.4x",op," ;@ %.4x\n",i,handlers,2);\r
1157 indexes[op] = handlers;\r
1158 handlers++;\r
1159 }\r
1160 }\r
1161 if(handlers&7) {\r
1162 fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
1163 for(i = 8-(handlers&7); i > 0; i--)\r
1164 ot(",000000");\r
1165 ot("\n");\r
1166 }\r
1167 if(ms) {\r
1168 for(i = (0x4000-handlers)/8; i > 0; i--)\r
1169 ot(" dcd 0,0,0,0,0,0,0,0\n");\r
1170 } else {\r
1171 ot(ms?"":" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", (0x4000-handlers)/8);\r
1172 }\r
1173 printf("total distinct hanlers: %i\n",handlers);\r
1174 // output data\r
1175 for(i=0,ip=0; i < 0xf000; i++, ip++) {\r
1176 op=CyJump[i];\r
1177 if(op == -2) {\r
1178 // it must skip a-line area, because we keep our data there\r
1179 ott("0x%.4x", handlers<<4, "\n",0,ip++,1);\r
1180 ott("0x%.4x", 0x1000, "\n",0,ip,1);\r
1181 i+=0xfff;\r
1182 continue;\r
1183 }\r
1184 for(reps=1; i < 0xf000; i++, reps++) if(op != CyJump[i+1]) break;\r
1185 if(op>=0) out=indexes[op]<<4; else out=0; // unrecognised\r
1186 if(reps <= 0xe || reps==0x10) {\r
1187 if(reps!=0x10) out|=reps; else out|=0xf; // 0xf means 0x10 (0xf appeared to be unused anyway)\r
1188 ott("0x%.4x", out, "\n",0,ip,1);\r
1189 } else {\r
1190 ott("0x%.4x", out, "\n",0,ip++,1);\r
1191 ott("0x%.4x", reps,"\n",0,ip,1);\r
1192 }\r
1193 }\r
1194 if(ip&1) ott("0x%.4x", 0, "\n",0,ip++,1);\r
1195 if(ip&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
1196 if(ip&7) {\r
1197 for(i = 8-(ip&7); i > 0; i--)\r
1198 ot(",0x0000");\r
1199 }\r
1200 ot("\n");\r
1201 if(ms) {\r
1202 for(i = (0x2000-ip/2)/8+1; i > 0; i--)\r
1203 ot(" dcd 0,0,0,0,0,0,0,0\n");\r
1204 } else {\r
1205 ot(" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", (0x2000-ip/2)/8+1);\r
1206 }\r
1207 ot("\n");\r
1208 free(indexes);\r
1209#else\r
1210 ot("CycloneJumpTab%s\n", ms?"":":");\r
1211 len=0xfffe; // Hmmm, armasm 2.50.8684 messes up with a 0x10000 long jump table\r
1212 // notaz: same thing with GNU as 2.9-psion-98r2 (reloc overflow)\r
1213 // this is due to COFF objects using only 2 bytes for reloc count\r
1214\r
1215 for (i=0;i<len;i++)\r
1216 {\r
1217 op=CyJump[i];\r
1218\r
1219 if(op>=0) ott("Op%.4x",op," ;@ %.4x\n",i-7,i,2);\r
1220 else if(op==-2) ott("Op__al",0, " ;@ %.4x\n",i-7,i,2);\r
1221 else if(op==-3) ott("Op__fl",0, " ;@ %.4x\n",i-7,i,2);\r
1222 else ott("Op____",0, " ;@ %.4x\n",i-7,i,2);\r
1223 }\r
1224 if(i&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma\r
1225\r
1226 ot("\n");\r
1227 ot(";@ notaz: we don't want to crash if we run into those 2 missing opcodes\n");\r
1228 ot(";@ so we leave this pattern to patch it later\n");\r
1229 ot("%s 0x78563412\n", ms?" dcd":" .long");\r
1230 ot("%s 0x56341290\n", ms?" dcd":" .long");\r
1231#endif\r
6003a768 1232}\r
1233\r
1234static int CycloneMake()\r
1235{\r
d9d77995 1236 int i;\r
1237 const char *name="Cyclone.s";\r
1238 const char *globl=ms?"export":".global";\r
1239\r
6003a768 1240 // Open the assembly file\r
1241 if (ms) name="Cyclone.asm";\r
1242 AsmFile=fopen(name,"wt"); if (AsmFile==NULL) return 1;\r
d9d77995 1243\r
6003a768 1244 printf("Making %s...\n",name);\r
1245\r
1246 ot("\n;@ Cyclone 68000 Emulator v%x.%.3x - Assembler Output\n\n",CycloneVer>>12,CycloneVer&0xfff);\r
1247\r
d9d77995 1248 ot(";@ Copyright (c) 2004,2011 FinalDave (emudave (at) gmail.com)\n");\r
1249 ot(";@ Copyright (c) 2005-2011 Gražvydas \"notaz\" Ignotas (notasas (at) gmail.com)\n\n");\r
c41b9b97 1250\r
6003a768 1251 ot(";@ This code is licensed under the GNU General Public License version 2.0 and the MAME License.\n");\r
1252 ot(";@ You can choose the license that has the most advantages for you.\n\n");\r
1253 ot(";@ SVN repository can be found at http://code.google.com/p/cyclone68000/\n\n");\r
1254\r
1255 CyJump=(int *)malloc(0x40000); if (CyJump==NULL) return 1;\r
1256 memset(CyJump,0xff,0x40000); // Init to -1\r
d9d77995 1257 for(i=0xa000; i<0xb000; i++) CyJump[i] = -2; // a-line emulation\r
1258 for(i=0xf000; i<0x10000; i++) CyJump[i] = -3; // f-line emulation\r
6003a768 1259\r
d9d77995 1260 ot(ms?" area |.text|, code\n":" .text\n .align 4\n\n");\r
1261 ot(" %s CycloneInit\n",globl);\r
1262 ot(" %s CycloneReset\n",globl);\r
1263 ot(" %s CycloneRun\n",globl);\r
1264 ot(" %s CycloneSetSr\n",globl);\r
1265 ot(" %s CycloneGetSr\n",globl);\r
1266 ot(" %s CycloneFlushIrq\n",globl);\r
1267 ot(" %s CyclonePack\n",globl);\r
1268 ot(" %s CycloneUnpack\n",globl);\r
1269 ot(" %s CycloneVer\n",globl);\r
1270#if (CYCLONE_FOR_GENESIS == 2)\r
1271 ot(" %s CycloneSetRealTAS\n",globl);\r
1272 ot(" %s CycloneDoInterrupt\n",globl);\r
1273 ot(" %s CycloneDoTrace\n",globl);\r
1274 ot(" %s CycloneJumpTab\n",globl);\r
1275 ot(" %s Op____\n",globl);\r
c6237d9e 1276 ot(" %s Op6002\n",globl);\r
1277 ot(" %s Op6602\n",globl);\r
1278 ot(" %s Op6702\n",globl);\r
d9d77995 1279#endif\r
1280 ot("\n");\r
1281 ot(ms?"CycloneVer dcd 0x":"CycloneVer: .long 0x");\r
1282 ot("%.4x\n",CycloneVer);\r
6003a768 1283 ot("\n");\r
1284\r
1285 PrintFramework();\r
d9d77995 1286 arm_op_count = 0;\r
6003a768 1287 PrintOpcodes();\r
d9d77995 1288 printf("~%i ARM instructions used for opcode handlers\n", arm_op_count);\r
6003a768 1289 PrintJumpTable();\r
1290\r
1291 if (ms) ot(" END\n");\r
1292\r
d9d77995 1293 ot("\n\n;@ vim:filetype=armasm\n");\r
1294\r
6003a768 1295 fclose(AsmFile); AsmFile=NULL;\r
1296\r
d9d77995 1297#if 0\r
6003a768 1298 printf("Assembling...\n");\r
1299 // Assemble the file\r
1300 if (ms) system("armasm Cyclone.asm");\r
1301 else system("as -o Cyclone.o Cyclone.s");\r
1302 printf("Done!\n\n");\r
d9d77995 1303#endif\r
6003a768 1304\r
1305 free(CyJump);\r
1306 return 0;\r
1307}\r
1308\r
1309int main()\r
1310{\r
1311 printf("\n Cyclone 68000 Emulator v%x.%.3x - Core Creator\n\n",CycloneVer>>12,CycloneVer&0xfff);\r
1312\r
d9d77995 1313 // Make GAS or ARMASM version\r
1314 CycloneMake();\r
6003a768 1315 return 0;\r
1316}\r
d9d77995 1317\r