m68k_intrf.h
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include "dcastaway.h" 4 5 extern int waitstate; 6 7 #ifndef USE_FAME_CORE 8 9 #include "castaway/68000.h" 10 #include "castaway/op68k.h" 11 12 extern unsigned IO_CYCLE; 13 14 static __inline__ unsigned long cpu_loop(unsigned slice) { 15 16 extern unsigned long (*jmp_table[8192])(operin); 17 18 #define initialize_memmap() 19 //printf("%8x =>%8x\n",pc,myinst); 20 21 #define cpuinst \ 22 address = pc&MEMADDRMASK; \ 23 if (address<MEMSIZE) myinst=biginst=ReadSL(mymembase+address); \ 24 else if (address>=ROMBASE2) myinst=biginst=ReadSL(myrombase+address); \ 25 else { HWReset(); return slice-IO_CYCLE; } \ 26 pc+=2; \ 27 IO_CYCLE-=(*jmp_table[(myinst<<16)>>19])(reg); 28 29 register unsigned long *p_reg=(unsigned long *)®[0]; 30 register unsigned long address; 31 register int8 *mymembase=membase; 32 register int8 *myrombase=rombase; 33 register uint32 myinst; 34 IO_CYCLE=slice; 35 //Execute 10 instructions 36 cpuinst 37 cpuinst 38 cpuinst 39 cpuinst 40 cpuinst 41 cpuinst 42 cpuinst 43 cpuinst 44 cpuinst 45 cpuinst 46 return slice-IO_CYCLE; 47 #undef cpuinst 48 } 49 50 51 #else 52 53 #include "fame.h" 54 55 56 #if defined(DREAMCAST) || defined(USE_FAME_CORE_C) 57 #define M68KCONTEXT m68kcontext 58 #define IO_CYCLE io_cycle_counter 59 #else 60 #define M68KCONTEXT _m68kcontext 61 #define IO_CYCLE __io_cycle_counter 62 #endif 63 64 extern unsigned IO_CYCLE; 65 66 //extern struct M68K_CONTEXT M68KCONTEXT; 67 extern M68K_CONTEXT M68KCONTEXT; 68 extern int recalc_int; 69 extern void SetMemW(unsigned long address, unsigned short value); 70 extern void HWReset(void); 71 72 #define GetS() ((M68KCONTEXT.sr >> 13) & 1) 73 #define GetFC2() GetS() 74 #define GetI() ((M68KCONTEXT.sr >> 8) & 7) 75 #ifdef DEBUG_FAME 76 #define Interrupt(NUM,LEV) \ 77 { \ 78 extern int fame_debug_output; \ 79 extern FILE *fame_debug_file; \ 80 if (fame_debug_output) \ 81 { fprintf(fame_debug_file,"Interrupt(%i,%i)\n",(NUM),(LEV)); DEBUG_FAME_FFLUSH; } \ 82 m68k_lower_irq((LEV)); \ 83 m68k_raise_irq((LEV),(NUM)); \ 84 } 85 #else 86 #define Interrupt(NUM,LEV) \ 87 { \ 88 M68KCONTEXT.interrupts[0] |= (1 << (LEV)); \ 89 M68KCONTEXT.interrupts[(LEV)]=(NUM); \ 90 M68KCONTEXT.execinfo &= 0x7F; \ 91 } 92 #endif 93 94 #define ClearInterrupt(LEV) M68KCONTEXT.interrupts[0] &= ~(1 << (LEV)) 95 96 97 #define MEMADDRMASK 0x00ffffffl 98 #define MEMADDRMASKS 0x00fffffel 99 #define MEMIDXSHIFT 11 100 #define MEMADDRSIZE (MEMADDRMASK + 1) 101 #define AUTOINT2 26 102 #define AUTOINT4 28 103 #define BUSERR 2 104 #define ADDRESSERR 3 105 106 char GetMemB(unsigned long address); 107 short GetMemW(unsigned long address); 108 void initialize_memmap(void); 109 void ExceptionGroup0( int, unsigned long, int); 110 void ExceptionGroup0_execute(void); 111 112 113 #ifdef DEBUG_FAME 114 static char dis_msg[96]; 115 static unsigned short dis_buf[10]; 116 void disassemble68k(char *buf, unsigned short *inst_stream); 117 static __inline__ unsigned long cpu_loop(unsigned slice) 118 { 119 unsigned i; 120 extern int number_exg0_fame; 121 extern int in_fame_core; 122 extern unsigned fame_debug_count; 123 extern int fame_debug_output; 124 extern FILE *fame_debug_file; 125 126 #ifdef DEBUG_FAME_START 127 if (fame_debug_count>=((unsigned)(DEBUG_FAME_START))) 128 fame_debug_output=1; 129 else { 130 unsigned long cycles_actual=M68KCONTEXT.cycles_counter; 131 short lastint=M68KCONTEXT.sr&0x700; 132 133 in_fame_core=1; 134 m68k_emulate(slice); 135 in_fame_core=0; 136 137 fprintf(fame_debug_file,"SLICE(%u) %u (%u) ret=%u (%x %x)\n",slice,fame_debug_count,slice,M68KCONTEXT.cycles_counter-cycles_actual,M68KCONTEXT.execinfo&0x80,M68KCONTEXT.interrupts[0]); 138 fame_debug_count++; 139 140 if (number_exg0_fame) 141 ExceptionGroup0_execute(); 142 143 if ((M68KCONTEXT.execinfo&0x80)&&(lastint!=(M68KCONTEXT.sr&0x700))) 144 M68KCONTEXT.execinfo&=0x7f; 145 146 return (M68KCONTEXT.cycles_counter-cycles_actual); 147 } 148 149 if (fame_debug_output) 150 fprintf(fame_debug_file,"SLICE(%u) %u (%u)\n",slice,fame_debug_count,slice); 151 #endif 152 153 in_fame_core=1; 154 unsigned long cycles_actual=M68KCONTEXT.cycles_counter; 155 short lastint=M68KCONTEXT.sr&0x700; 156 while(M68KCONTEXT.cycles_counter-cycles_actual<slice) 157 { 158 if (fame_debug_output) 159 { 160 dis_msg[0]= 0; 161 dis_buf[0]= m68k_fetch(m68k_get_pc(),0); 162 dis_buf[1]= m68k_fetch(m68k_get_pc()+2,0); 163 dis_buf[2]= m68k_fetch(m68k_get_pc()+4,0); 164 dis_buf[3]= m68k_fetch(m68k_get_pc()+6,0); 165 dis_buf[4]= m68k_fetch(m68k_get_pc()+8,0); 166 dis_buf[5]= m68k_fetch(m68k_get_pc()+10,0); 167 dis_buf[6]= m68k_fetch(m68k_get_pc()+12,0); 168 dis_buf[7]= m68k_fetch(m68k_get_pc()+14,0); 169 disassemble68k(dis_msg,dis_buf); 170 fprintf(fame_debug_file,"- PC=%.8X (%s) SR=%.2X - INT=%.2X STAT=%.4X E0=%i\n",m68k_get_pc(), dis_msg, M68KCONTEXT.sr,M68KCONTEXT.interrupts[0],M68KCONTEXT.execinfo,number_exg0_fame); 171 fprintf(fame_debug_file,"\tD0=%.8X D1=%.8X D2=%.8X D3=%.8X\n",M68KCONTEXT.dreg[0],M68KCONTEXT.dreg[1],M68KCONTEXT.dreg[2],M68KCONTEXT.dreg[3]); 172 fprintf(fame_debug_file,"\tD4=%.8X D5=%.8X D6=%.8X D7=%.8X\n",M68KCONTEXT.dreg[4],M68KCONTEXT.dreg[5],M68KCONTEXT.dreg[6],M68KCONTEXT.dreg[7]); 173 fprintf(fame_debug_file,"\tA0=%.8X A1=%.8X A2=%.8X A3=%.8X\n",M68KCONTEXT.areg[0],M68KCONTEXT.areg[1],M68KCONTEXT.areg[2],M68KCONTEXT.areg[3]); 174 fprintf(fame_debug_file,"\tA4=%.8X A5=%.8X A6=%.8X A7=%.8X\n",M68KCONTEXT.areg[4],M68KCONTEXT.areg[5],M68KCONTEXT.areg[6],M68KCONTEXT.areg[7]);DEBUG_FAME_FFLUSH; 175 } 176 m68k_emulate(1); 177 if (fame_debug_output) 178 { fputs(".",fame_debug_file); DEBUG_FAME_FFLUSH; } 179 if (M68KCONTEXT.execinfo&0x80) 180 break; 181 } 182 in_fame_core=0; 183 184 fame_debug_count++; 185 186 #ifdef DEBUG_FAME_STOP 187 if (fame_debug_count>((unsigned)(DEBUG_FAME_STOP))) 188 { 189 #ifdef DEBUG_FAME_FILE 190 extern FILE *fame_debug_file; 191 if (fame_debug_file) 192 fclose(fame_debug_file); 193 fame_debug_file=NULL; 194 #endif 195 free(malloc(24*1024*1024)); exit(0); } 196 #endif 197 if (number_exg0_fame) 198 { 199 ExceptionGroup0_execute(); 200 number_exg0_fame=0; 201 } 202 if ((M68KCONTEXT.execinfo&0x80)&&(lastint!=(M68KCONTEXT.sr&0x700))) 203 M68KCONTEXT.execinfo&=0x7f; 204 return (M68KCONTEXT.cycles_counter-cycles_actual); 205 } 206 207 #else 208 static __inline__ unsigned long cpu_loop(unsigned slice) 209 { 210 extern int in_fame_core; 211 extern int number_exg0_fame; 212 213 unsigned long cycles_actual=M68KCONTEXT.cycles_counter; 214 short lastint=M68KCONTEXT.sr&0x700; 215 216 in_fame_core=1; 217 m68k_emulate(slice); 218 in_fame_core=0; 219 220 if (number_exg0_fame) 221 ExceptionGroup0_execute(); 222 223 if ((M68KCONTEXT.execinfo&0x80)&&(lastint!=(M68KCONTEXT.sr&0x700))) 224 M68KCONTEXT.execinfo&=0x7f; 225 226 return (M68KCONTEXT.cycles_counter-cycles_actual); 227 } 228 #endif 229 230 231 #endif