]> Shamusworld >> Repos - virtualjaguar/blob - src/m68000/m68kinterface.c
2.0.2 release.
[virtualjaguar] / src / m68000 / m68kinterface.c
1 //
2 // m68kinterface.c: Code interface to the UAE 68000 core and support code
3 //
4 // by James L. Hammons
5 // (C) 2011 Underground Software
6 //
7 // JLH = James L. Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  10/28/2011  Created this file ;-)
12 //
13
14 #include "m68kinterface.h"
15 #include "cpudefs.h"
16 #include "inlines.h"
17 #include "cpuextra.h"
18 #include "readcpu.h"
19
20
21 // Exception Vectors handled by emulation
22 #define EXCEPTION_BUS_ERROR                2 /* This one is not emulated! */
23 #define EXCEPTION_ADDRESS_ERROR            3 /* This one is partially emulated (doesn't stack a proper frame yet) */
24 #define EXCEPTION_ILLEGAL_INSTRUCTION      4
25 #define EXCEPTION_ZERO_DIVIDE              5
26 #define EXCEPTION_CHK                      6
27 #define EXCEPTION_TRAPV                    7
28 #define EXCEPTION_PRIVILEGE_VIOLATION      8
29 #define EXCEPTION_TRACE                    9
30 #define EXCEPTION_1010                    10
31 #define EXCEPTION_1111                    11
32 #define EXCEPTION_FORMAT_ERROR            14
33 #define EXCEPTION_UNINITIALIZED_INTERRUPT 15
34 #define EXCEPTION_SPURIOUS_INTERRUPT      24
35 #define EXCEPTION_INTERRUPT_AUTOVECTOR    24
36 #define EXCEPTION_TRAP_BASE               32
37
38 // These are found in obj/cpustbl.c (generated by gencpu)
39
40 //extern const struct cputbl op_smalltbl_0_ff[];        /* 68040 */
41 //extern const struct cputbl op_smalltbl_1_ff[];        /* 68020 + 68881 */
42 //extern const struct cputbl op_smalltbl_2_ff[];        /* 68020 */
43 //extern const struct cputbl op_smalltbl_3_ff[];        /* 68010 */
44 extern const struct cputbl op_smalltbl_4_ff[];  /* 68000 */
45 extern const struct cputbl op_smalltbl_5_ff[];  /* 68000 slow but compatible.  */
46
47 // Externs, supplied by the user...
48 extern int irq_ack_handler(int);
49
50 // Function prototypes...
51 STATIC_INLINE void m68ki_check_interrupts(void);
52 void m68ki_exception_interrupt(uint32_t intLevel);
53 STATIC_INLINE uint32_t m68ki_init_exception(void);
54 STATIC_INLINE void m68ki_stack_frame_3word(uint32_t pc, uint32_t sr);
55 unsigned long IllegalOpcode(uint32_t opcode);
56 void BuildCPUFunctionTable(void);
57
58 // Local "Global" vars
59 static int32_t initialCycles;
60 cpuop_func * cpuFunctionTable[65536];
61
62
63 #if 0
64 #define ADD_CYCLES(A)    m68ki_remaining_cycles += (A)
65 #define USE_CYCLES(A)    m68ki_remaining_cycles -= (A)
66 #define SET_CYCLES(A)    m68ki_remaining_cycles = A
67 #define GET_CYCLES()     m68ki_remaining_cycles
68 #define USE_ALL_CYCLES() m68ki_remaining_cycles = 0
69
70 #define CPU_INT_LEVEL    m68ki_cpu.int_level /* ASG: changed from CPU_INTS_PENDING */
71 #define CPU_INT_CYCLES   m68ki_cpu.int_cycles /* ASG */
72 #define CPU_STOPPED      m68ki_cpu.stopped
73 #define CPU_PREF_ADDR    m68ki_cpu.pref_addr
74 #define CPU_PREF_DATA    m68ki_cpu.pref_data
75 #define CPU_ADDRESS_MASK m68ki_cpu.address_mask
76 #define CPU_SR_MASK      m68ki_cpu.sr_mask
77 #endif
78
79 #define CPU_DEBUG
80 void Dasm(uint32_t offset, uint32_t qt)
81 {
82 #ifdef CPU_DEBUG
83 // back up a few instructions...
84 //offset -= 100;
85         static char buffer[2048];//, mem[64];
86         int pc = offset, oldpc;
87         uint32_t i;
88
89         for(i=0; i<qt; i++)
90         {
91 /*              oldpc = pc;
92                 for(int j=0; j<64; j++)
93                         mem[j^0x01] = jaguar_byte_read(pc + j);
94
95                 pc += Dasm68000((char *)mem, buffer, 0);
96                 WriteLog("%08X: %s\n", oldpc, buffer);//*/
97                 oldpc = pc;
98                 pc += m68k_disassemble(buffer, pc, 0);//M68K_CPU_TYPE_68000);
99 //              WriteLog("%08X: %s\n", oldpc, buffer);//*/
100                 printf("%08X: %s\n", oldpc, buffer);//*/
101         }
102 #endif
103 }
104
105 #ifdef CPU_DEBUG
106 void DumpRegisters(void)
107 {
108         uint32_t i;
109
110         for(i=0; i<16; i++)
111         {
112                 printf("%s%i: %08X ", (i < 8 ? "D" : "A"), i & 0x7, regs.regs[i]);
113
114                 if ((i & 0x03) == 3)
115                         printf("\n");
116         }
117 }
118 #endif
119
120
121 void m68k_set_cpu_type(unsigned int type)
122 {
123 }
124
125 // Pulse the RESET line on the CPU
126 void m68k_pulse_reset(void)
127 {
128         static uint32_t emulation_initialized = 0;
129
130         // The first call to this function initializes the opcode handler jump table
131         if (!emulation_initialized)
132         {
133 #if 0
134                 m68ki_build_opcode_table();
135                 m68k_set_int_ack_callback(NULL);
136                 m68k_set_bkpt_ack_callback(NULL);
137                 m68k_set_reset_instr_callback(NULL);
138                 m68k_set_pc_changed_callback(NULL);
139                 m68k_set_fc_callback(NULL);
140                 m68k_set_instr_hook_callback(NULL);
141 #else
142                 // Build opcode handler table here...
143                 read_table68k();
144                 do_merges();
145                 BuildCPUFunctionTable();
146 #endif
147                 emulation_initialized = 1;
148         }
149
150 //      if (CPU_TYPE == 0)      /* KW 990319 */
151 //              m68k_set_cpu_type(M68K_CPU_TYPE_68000);
152
153 #if 0
154         /* Clear all stop levels and eat up all remaining cycles */
155         CPU_STOPPED = 0;
156         SET_CYCLES(0);
157
158         /* Turn off tracing */
159         FLAG_T1 = FLAG_T0 = 0;
160         m68ki_clear_trace();
161         /* Interrupt mask to level 7 */
162         FLAG_INT_MASK = 0x0700;
163         /* Reset VBR */
164         REG_VBR = 0;
165         /* Go to supervisor mode */
166         m68ki_set_sm_flag(SFLAG_SET | MFLAG_CLEAR);
167
168         /* Invalidate the prefetch queue */
169 #if M68K_EMULATE_PREFETCH
170         /* Set to arbitrary number since our first fetch is from 0 */
171         CPU_PREF_ADDR = 0x1000;
172 #endif /* M68K_EMULATE_PREFETCH */
173
174         /* Read the initial stack pointer and program counter */
175         m68ki_jump(0);
176         REG_SP = m68ki_read_imm_32();
177         REG_PC = m68ki_read_imm_32();
178         m68ki_jump(REG_PC);
179 #else
180         regs.stopped = 0;
181         regs.remainingCycles = 0;
182         
183         regs.intmask = 0x07;
184         regs.s = 1;                                                             // Supervisor mode ON
185
186         // Read initial SP and PC
187         m68k_areg(regs, 7) = m68k_read_memory_32(0);
188         m68k_setpc(m68k_read_memory_32(4));
189         refill_prefetch(m68k_getpc(), 0);
190 #endif
191 }
192
193 int m68k_execute(int num_cycles)
194 {
195 #if 0
196         /* Make sure we're not stopped */
197         if (CPU_STOPPED)
198         {
199                 /* We get here if the CPU is stopped or halted */
200                 SET_CYCLES(0);
201                 CPU_INT_CYCLES = 0;
202
203                 return num_cycles;
204         }
205 #else
206         if (regs.stopped)
207         {
208                 regs.remainingCycles = 0;       // int32_t
209                 regs.interruptCycles = 0;       // uint32_t
210
211                 return num_cycles;
212         }
213 #endif
214
215 #if 0
216         /* Set our pool of clock cycles available */
217         SET_CYCLES(num_cycles);
218         m68ki_initial_cycles = num_cycles;
219
220         /* ASG: update cycles */
221         USE_CYCLES(CPU_INT_CYCLES);
222         CPU_INT_CYCLES = 0;
223
224         /* Return point if we had an address error */
225         m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */
226 #else
227         regs.remainingCycles = num_cycles;
228         /*int32_t*/ initialCycles = num_cycles;
229         
230         regs.remainingCycles -= regs.interruptCycles;
231         regs.interruptCycles = 0;
232 #endif
233
234         /* Main loop.  Keep going until we run out of clock cycles */
235         do
236         {
237 #if 0
238                 /* Set tracing accodring to T1. (T0 is done inside instruction) */
239                 m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */
240
241                 /* Set the address space for reads */
242                 m68ki_use_data_space(); /* auto-disable (see m68kcpu.h) */
243
244                 /* Call external hook to peek at CPU */
245                 m68ki_instr_hook(); /* auto-disable (see m68kcpu.h) */
246
247                 /* Record previous program counter */
248                 REG_PPC = REG_PC;
249
250                 /* Read an instruction and call its handler */
251                 REG_IR = m68ki_read_imm_16();
252                 m68ki_instruction_jump_table[REG_IR]();
253                 USE_CYCLES(CYC_INSTRUCTION[REG_IR]);
254
255                 /* Trace m68k_exception, if necessary */
256                 m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */
257 #else
258 //Testing Hover Strike...
259 #if 0
260 //Dasm(regs.pc, 1);
261 static int hitCount = 0;
262 static int inRoutine = 0;
263 static int instSeen;
264
265 //if (regs.pc == 0x80340A)
266 if (regs.pc == 0x803416)
267 {
268         hitCount++;
269         inRoutine = 1;
270         instSeen = 0;
271         printf("%i: $80340A start. A0=%08X, A1=%08X ", hitCount, regs.regs[8], regs.regs[9]);
272 }
273 else if (regs.pc == 0x803422)
274 {
275         inRoutine = 0;
276         printf("(%i instructions)\n", instSeen);
277 }
278
279 if (inRoutine)
280         instSeen++;
281 #endif
282 // AvP testing... (problem was: 32 bit addresses on 24 bit address cpu--FIXED)
283 #if 0
284         static int go = 0;
285
286         if (regs.pc == 0x94BA)
287         {
288                 go = 1;
289                 printf("\n");
290         }
291
292         if (regs.pc == 0x94C6)
293                 go = 0;
294
295 //      if (regs.regs[10] == 0xFFFFFFFF && go)
296         if (go)
297         {
298 //              printf("A2=-1, PC=%08X\n", regs.pc);
299 //              go = 0;
300 //              Dasm(regs.pc, 130);
301                 Dasm(regs.pc, 1);
302                 DumpRegisters();
303         }
304 //94BA: 2468 0000                MOVEA.L        (A0,$0000) == $0002328A, A2
305 //94BE: 200A                     MOVE.L A2, D0
306 //94C0: 6A02                     BPL.B  $94C4
307 //94C2: 2452                     MOVEA.L        (A2), A2                        ; <--- HERE
308 //94C4: 4283                     CLR.L  D3
309 #endif
310                 uint32_t opcode = get_iword(0);
311 //if ((opcode & 0xFFF8) == 0x31C0)
312 //{
313 //      printf("MOVE.W D%i, EA\n", opcode & 0x07);
314 //}
315                 int32_t cycles = (int32_t)(*cpuFunctionTable[opcode])(opcode);
316                 regs.remainingCycles -= cycles;
317 //printf("Executed opcode $%04X (%i cycles)...\n", opcode, cycles);
318 #endif
319         }
320 #if 0
321         while (GET_CYCLES() > 0);
322 #else
323         while (regs.remainingCycles > 0);
324 #endif
325
326 #if 0
327         /* set previous PC to current PC for the next entry into the loop */
328         REG_PPC = REG_PC;
329
330         /* ASG: update cycles */
331         USE_CYCLES(CPU_INT_CYCLES);
332         CPU_INT_CYCLES = 0;
333
334         /* return how many clocks we used */
335         return m68ki_initial_cycles - GET_CYCLES();
336 #else
337         regs.remainingCycles -= regs.interruptCycles;
338         regs.interruptCycles = 0;
339
340         // Return # of clock cycles used
341         return initialCycles - regs.remainingCycles;
342 #endif
343 }
344
345 /* ASG: rewrote so that the int_level is a mask of the IPL0/IPL1/IPL2 bits */
346 void m68k_set_irq(unsigned int intLevel)
347 {
348 #if 0
349         uint old_level = CPU_INT_LEVEL;
350         CPU_INT_LEVEL = int_level << 8;
351
352         /* A transition from < 7 to 7 always interrupts (NMI) */
353         /* Note: Level 7 can also level trigger like a normal IRQ */
354         if(old_level != 0x0700 && CPU_INT_LEVEL == 0x0700)
355                 m68ki_exception_interrupt(7); /* Edge triggered level 7 (NMI) */
356         else
357                 m68ki_check_interrupts(); /* Level triggered (IRQ) */
358 #else
359         int oldLevel = regs.intLevel;
360         regs.intLevel = intLevel;
361
362         // A transition from < 7 to 7 always interrupts (NMI)
363         // Note: Level 7 can also level trigger like a normal IRQ
364         if (oldLevel != 0x07 && regs.intLevel == 0x07)
365                 m68ki_exception_interrupt(7);           // Edge triggered level 7 (NMI)
366         else
367                 m68ki_check_interrupts();                       // Level triggered (IRQ)
368 #endif
369 }
370
371 // Check for interrupts
372 STATIC_INLINE void m68ki_check_interrupts(void)
373 {
374 #if 0
375         if(CPU_INT_LEVEL > FLAG_INT_MASK)
376                 m68ki_exception_interrupt(CPU_INT_LEVEL>>8);
377 #else
378         if (regs.intLevel > regs.intmask)
379                 m68ki_exception_interrupt(regs.intLevel);
380 #endif
381 }
382
383 // Service an interrupt request and start exception processing
384 void m68ki_exception_interrupt(uint32_t intLevel)
385 {
386 #if 0
387         uint vector;
388         uint sr;
389         uint new_pc;
390
391         /* Turn off the stopped state */
392         CPU_STOPPED &= ~STOP_LEVEL_STOP;
393
394         /* If we are halted, don't do anything */
395         if(CPU_STOPPED)
396                 return;
397
398         /* Acknowledge the interrupt */
399         vector = m68ki_int_ack(int_level);
400
401         /* Get the interrupt vector */
402         if(vector == M68K_INT_ACK_AUTOVECTOR)
403                 /* Use the autovectors.  This is the most commonly used implementation */
404                 vector = EXCEPTION_INTERRUPT_AUTOVECTOR+int_level;
405         else if(vector == M68K_INT_ACK_SPURIOUS)
406                 /* Called if no devices respond to the interrupt acknowledge */
407                 vector = EXCEPTION_SPURIOUS_INTERRUPT;
408         else if(vector > 255)
409         {
410                 M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: Interrupt acknowledge returned invalid vector $%x\n",
411                          m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC), vector));
412                 return;
413         }
414
415         /* Start exception processing */
416         sr = m68ki_init_exception();
417
418         /* Set the interrupt mask to the level of the one being serviced */
419         FLAG_INT_MASK = int_level<<8;
420
421         /* Get the new PC */
422         new_pc = m68ki_read_data_32((vector<<2) + REG_VBR);
423
424         /* If vector is uninitialized, call the uninitialized interrupt vector */
425         if(new_pc == 0)
426                 new_pc = m68ki_read_data_32((EXCEPTION_UNINITIALIZED_INTERRUPT<<2) + REG_VBR);
427
428         /* Generate a stack frame */
429         m68ki_stack_frame_0000(REG_PC, sr, vector);
430
431         if(FLAG_M && CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
432         {
433                 /* Create throwaway frame */
434                 m68ki_set_sm_flag(FLAG_S);      /* clear M */
435                 sr |= 0x2000; /* Same as SR in master stack frame except S is forced high */
436                 m68ki_stack_frame_0001(REG_PC, sr, vector);
437         }
438
439         m68ki_jump(new_pc);
440
441         /* Defer cycle counting until later */
442         CPU_INT_CYCLES += CYC_EXCEPTION[vector];
443
444 #if !M68K_EMULATE_INT_ACK
445         /* Automatically clear IRQ if we are not using an acknowledge scheme */
446         CPU_INT_LEVEL = 0;
447 #endif /* M68K_EMULATE_INT_ACK */
448 #else
449         // Turn off the stopped state
450         regs.stopped = 0;
451
452 //JLH: need to add halt state?
453         // If we are halted, don't do anything
454 //      if (CPU_STOPPED)
455 //              return;
456
457         // Acknowledge the interrupt (NOTE: This is a user supplied function!)
458         uint32_t vector = irq_ack_handler(intLevel);
459
460         // Get the interrupt vector
461         if (vector == M68K_INT_ACK_AUTOVECTOR)
462                 // Use the autovectors.  This is the most commonly used implementation
463                 vector = EXCEPTION_INTERRUPT_AUTOVECTOR + intLevel;
464         else if (vector == M68K_INT_ACK_SPURIOUS)
465                 // Called if no devices respond to the interrupt acknowledge
466                 vector = EXCEPTION_SPURIOUS_INTERRUPT;
467         else if (vector > 255)
468         {
469 //              M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: Interrupt acknowledge returned invalid vector $%x\n",
470 //                       m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC), vector));
471                 return;
472         }
473
474         // Start exception processing
475         uint32_t sr = m68ki_init_exception();
476
477         // Set the interrupt mask to the level of the one being serviced
478         regs.intmask = intLevel;
479
480         // Get the new PC
481         uint32_t newPC = m68k_read_memory_32(vector << 2);
482
483         // If vector is uninitialized, call the uninitialized interrupt vector
484         if (newPC == 0)
485                 newPC = m68k_read_memory_32(EXCEPTION_UNINITIALIZED_INTERRUPT << 2);
486
487         // Generate a stack frame
488         m68ki_stack_frame_3word(regs.pc, sr);
489
490         m68k_setpc(newPC);
491
492         // Defer cycle counting until later
493         regs.interruptCycles += 56;     // NOT ACCURATE-- !!! FIX !!!
494 //      CPU_INT_CYCLES += CYC_EXCEPTION[vector];
495 #endif
496 }
497
498 // Initiate exception processing
499 STATIC_INLINE uint32_t m68ki_init_exception(void)
500 {
501 #if 0
502         /* Save the old status register */
503         uint sr = m68ki_get_sr();
504
505         /* Turn off trace flag, clear pending traces */
506         FLAG_T1 = FLAG_T0 = 0;
507         m68ki_clear_trace();
508         /* Enter supervisor mode */
509         m68ki_set_s_flag(SFLAG_SET);
510
511         return sr;
512 #else
513         MakeSR();
514         uint32_t sr = regs.sr;                                  // Save old status register
515         regs.s = 1;                                                             // Set supervisor mode
516
517         return sr;
518 #endif
519 }
520
521 // 3 word stack frame (68000 only)
522 STATIC_INLINE void m68ki_stack_frame_3word(uint32_t pc, uint32_t sr)
523 {
524 #if 0
525         m68ki_push_32(pc);
526         m68ki_push_16(sr);
527 #else
528         // Push PC on stack:
529         m68k_areg(regs, 7) -= 4;
530         m68k_write_memory_32(m68k_areg(regs, 7), pc);
531         // Push SR on stack:
532         m68k_areg(regs, 7) -= 2;
533         m68k_write_memory_16(m68k_areg(regs, 7), sr);
534 #endif
535 }
536
537 unsigned int m68k_get_reg(void * context, m68k_register_t reg)
538 {
539         if (reg <= M68K_REG_A7)
540                 return regs.regs[reg];
541         else if (reg == M68K_REG_PC)
542                 return regs.pc;
543         else if (reg == M68K_REG_SR)
544         {
545                 MakeSR();
546                 return regs.sr;
547         }
548         else if (reg == M68K_REG_SP)
549                 return regs.regs[15];
550
551         return 0;
552 }
553
554 void m68k_set_reg(m68k_register_t reg, unsigned int value)
555 {
556         if (reg <= M68K_REG_A7)
557                 regs.regs[reg] = value;
558         else if (reg == M68K_REG_PC)
559                 regs.pc = value;
560         else if (reg == M68K_REG_SR)
561         {
562                 regs.sr = value;
563                 MakeFromSR();
564         }
565         else if (reg == M68K_REG_SP)
566                 regs.regs[15] = value;
567 }
568
569 //
570 // Check if the instruction is a valid one
571 //
572 unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type)
573 {
574         instruction &= 0xFFFF;
575
576         if (cpuFunctionTable[instruction] == IllegalOpcode)
577                 return 0;
578
579         return 1;
580 }
581
582 // Dummy functions, for now, until we prove the concept here. :-)
583
584 // Temp, while we're using the Musashi disassembler...
585 #if 0
586 unsigned int m68k_disassemble(char * str_buff, unsigned int pc, unsigned int cpu_type)
587 {
588         return 0;
589 }
590 #endif
591
592 int m68k_cycles_run(void) {}              /* Number of cycles run so far */
593 int m68k_cycles_remaining(void) {}        /* Number of cycles left */
594 void m68k_modify_timeslice(int cycles) {} /* Modify cycles left */
595 //void m68k_end_timeslice(void) {}          /* End timeslice now */
596
597 void m68k_end_timeslice(void)
598 {
599 #if 0
600         m68ki_initial_cycles = GET_CYCLES();
601         SET_CYCLES(0);
602 #else
603         initialCycles = regs.remainingCycles;
604         regs.remainingCycles = 0;
605 #endif
606 }
607
608
609 unsigned long IllegalOpcode(uint32_t opcode)
610 {
611 #if 0
612         uint32_t pc = m68k_getpc ();
613 #endif
614         if ((opcode & 0xF000) == 0xF000)
615         {
616                 Exception(0x0B, 0, M68000_EXC_SRC_CPU); // LineF exception...
617                 return 4;
618         }
619         else if ((opcode & 0xF000) == 0xA000)
620         {
621                 Exception(0x0A, 0, M68000_EXC_SRC_CPU); // LineA exception...
622                 return 4;
623         }
624
625 #if 0
626         write_log ("Illegal instruction: %04x at %08lx\n", opcode, (long)pc);
627 #endif
628
629         Exception(0x04, 0, M68000_EXC_SRC_CPU);         // Illegal opcode exception...
630         return 4;
631 }
632
633
634 void BuildCPUFunctionTable(void)
635 {
636         int i;
637         unsigned long opcode;
638
639         // We're only using the "fast" 68000 emulation here, not the "compatible"
640         // ("fast" doesn't throw exceptions, so we're using "compatible" now :-P)
641 #if 0
642         const struct cputbl * tbl = (currprefs.cpu_compatible
643                 ? op_smalltbl_5_ff : op_smalltbl_4_ff);
644 #else
645 //let's try "compatible" and see what happens here...
646 //      const struct cputbl * tbl = op_smalltbl_4_ff;
647         const struct cputbl * tbl = op_smalltbl_5_ff;
648 #endif
649
650 //      Log_Printf(LOG_DEBUG, "Building CPU function table (%d %d %d).\n",
651 //              currprefs.cpu_level, currprefs.cpu_compatible, currprefs.address_space_24);
652
653         // Set all instructions to Illegal...
654         for(opcode=0; opcode<65536; opcode++)
655                 cpuFunctionTable[opcode] = IllegalOpcode;
656
657         // Move functions from compact table into our full function table...
658         for(i=0; tbl[i].handler!=NULL; i++)
659                 cpuFunctionTable[tbl[i].opcode] = tbl[i].handler;
660
661 //JLH: According to readcpu.c, handler is set to -1 and never changes.
662 // Actually, it does read this crap in readcpu.c, do_merges() does it... :-P
663 // Again, seems like a build time thing could be done here...
664 #if 1
665         for(opcode=0; opcode<65536; opcode++)
666         {
667 //              if (table68k[opcode].mnemo == i_ILLG || table68k[opcode].clev > currprefs.cpu_level)
668                 if (table68k[opcode].mnemo == i_ILLG || table68k[opcode].clev > 0)
669                         continue;
670
671                 if (table68k[opcode].handler != -1)
672                 {
673 //printf("Relocate: $%04X->$%04X\n", table68k[opcode].handler, opcode);
674                         cpuop_func * f = cpuFunctionTable[table68k[opcode].handler];
675
676                         if (f == IllegalOpcode)
677                                 abort();
678
679                         cpuFunctionTable[opcode] = f;
680                 }
681         }
682 #endif
683 }