--- hatari/src/uae-cpu/newcpu.c 2019/04/01 07:09:30 1.1.1.2 +++ hatari/src/uae-cpu/newcpu.c 2019/04/01 07:10:24 1.1.1.5 @@ -16,12 +16,14 @@ #include "newcpu.h" #include "compiler.h" #include "events.h" +#include "../includes/main.h" #include "../includes/tos.h" +#include "../includes/vdi.h" +#include "../includes/cart.h" +#include "../includes/debugui.h" + -/*int crashtrace=0;*/ -int quit_program = 0; -int debugging = 0; struct flag_struct regflags; int lastInstructionCycles; /* how many cycles last instruction took to execute */ @@ -117,7 +119,8 @@ static unsigned long REGPARAM2 op_illg_1 return 4; } -static void build_cpufunctbl (void) + +void build_cpufunctbl(void) { int i; unsigned long opcode; @@ -156,29 +159,15 @@ static void build_cpufunctbl (void) } /* Hataris illegal opcodes: */ + cpufunctbl[cft_map(GEMDOS_OPCODE)] = OpCode_GemDos; + cpufunctbl[cft_map(RUNOLDGEMDOS_OPCODE)] = OpCode_OldGemDos; cpufunctbl[cft_map(CONDRV_OPCODE)] = OpCode_ConnectedDrive; cpufunctbl[cft_map(TIMERD_OPCODE)] = OpCode_TimerD; + cpufunctbl[cft_map(VDI_OPCODE)] = OpCode_VDI; } -/* -void check_prefs_changed_cpu (void) -{ - if (currprefs.cpu_level != changed_prefs.cpu_level - || currprefs.cpu_compatible != changed_prefs.cpu_compatible) { - currprefs.cpu_level = changed_prefs.cpu_level; - currprefs.cpu_compatible = changed_prefs.cpu_compatible; - build_cpufunctbl (); - } - if (currprefs.m68k_speed != changed_prefs.m68k_speed) { - currprefs.m68k_speed = changed_prefs.m68k_speed; - reset_frame_rate_hack (); - update_68k_cycles (); - } -} -*/ - void init_m68k (void) { int i; @@ -250,6 +239,7 @@ void init_m68k (void) build_cpufunctbl (); } + struct regstruct regs, lastint_regs; static struct regstruct regs_backup[16]; static int backup_pointer = 0; @@ -323,8 +313,7 @@ uae_s32 ShowEA (FILE *f, int reg, amodes sprintf (buffer,"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), - disp,outer, - (unsigned long)addr); + (long)disp, (long)outer, (unsigned long)addr); } else { addr = m68k_areg(regs,reg) + (uae_s32)((uae_s8)disp8) + dispreg; sprintf (buffer,"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg, @@ -370,8 +359,7 @@ uae_s32 ShowEA (FILE *f, int reg, amodes sprintf (buffer,"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), - disp,outer, - (unsigned long)addr); + (long)disp, (long)outer, (unsigned long)addr); } else { addr += (uae_s32)((uae_s8)disp8) + dispreg; sprintf (buffer,"(PC, %c%d.%c*%d, $%02x) == $%08lx", dp & 0x8000 ? 'A' : 'D', @@ -445,7 +433,7 @@ static int verify_ea (int reg, amodes mo int r; uae_u32 dispreg; uaecptr addr; - uae_s32 offset = 0; + /*uae_s32 offset = 0;*/ switch (mode){ case Dreg: @@ -684,12 +672,46 @@ void MakeFromSR (void) unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); } + void Exception(int nr, uaecptr oldpc) { uae_u32 currpc = m68k_getpc (); /*if( nr>=2 && nr<10 ) fprintf(stderr,"Exception (-> %i bombs)!\n",nr);*/ + /* Intercept exceptions... - FIXME: Find a better way to do this! */ + if(bUseVDIRes) + { + if(nr == 0x22) /* Trap 2 - intercept VDI call */ + { + if( !VDI() ) + { + /* Set 'PC' as address of 'VDI_OPCODE' illegal instruction + * This will call OpCode_VDI after completion of Trap call! + * Use to modify return structure from VDI */ + /*if (bUseVDIRes)*/ + { + VDI_OldPC = currpc; + currpc = CART_VDI_OPCODE_ADDR; + } + } + } + else if(nr == 0x0a) /* Line A */ + { + if((get_word(currpc)&0x0fff) == 0x0ff) /* 0xA0FF opcode? */ + { + /* we use this to get pointer to Line-A structure details + * (to fix for extended VDI res) */ + LineABase = regs.regs[0]; /* D0 */ + FontBase = regs.regs[9]; /* A1 */ + VDI_LineA(); + m68k_setpc(currpc + 2); + fill_prefetch_0(); + return; + } + } + } + compiler_flush_jsr_stack(); MakeSR(); @@ -732,26 +754,39 @@ void Exception(int nr, uaecptr oldpc) m68k_areg(regs, 7) -= 2; put_word (m68k_areg(regs, 7), nr * 4); } - } else { - if (nr == 2 || nr == 3) { - /*crashtrace=4;*/ - /*sleep(1);*/ - m68k_areg(regs, 7) -= 12; - /* ??????? */ - if (nr == 3) { - put_long (m68k_areg(regs, 7), last_fault_for_exception_3); - put_word (m68k_areg(regs, 7)+4, last_op_for_exception_3); - put_long (m68k_areg(regs, 7)+8, last_addr_for_exception_3); - } - /*write_log ("UAE CPU Exception.\n");*/ - goto kludge_me_do; - } } + + /* Push PC on stack: */ m68k_areg(regs, 7) -= 4; put_long (m68k_areg(regs, 7), currpc); -kludge_me_do: + /* Push SR on stack: */ m68k_areg(regs, 7) -= 2; put_word (m68k_areg(regs, 7), regs.sr); + + /* 68000 bus/address errors: */ + if (cpu_level==0 && (nr==2 || nr==3)) { + m68k_areg(regs, 7) -= 8; + if (nr == 3) { /* Address error */ + put_word (m68k_areg(regs, 7), regs.sr); /*?*/ + put_long (m68k_areg(regs, 7)+2, last_fault_for_exception_3); + put_word (m68k_areg(regs, 7)+6, last_op_for_exception_3); + put_long (m68k_areg(regs, 7)+10, last_addr_for_exception_3); + if( bEnableDebug ) { + fprintf(stderr,"Address Error at address $%x, PC=$%x\n",last_fault_for_exception_3,currpc); + DebugUI(); + } + } + else { /* Bus error */ + put_word (m68k_areg(regs, 7), regs.sr); /*?*/ + put_long (m68k_areg(regs, 7)+2, BusAddressLocation); + put_word (m68k_areg(regs, 7)+6, get_word(currpc)); + if( bEnableDebug && BusAddressLocation!=0xff8a00) { + fprintf(stderr,"Bus Error at address $%lx, PC=$%lx\n",BusAddressLocation,(long)currpc); + DebugUI(); + } + } + } + m68k_setpc (get_long (regs.vbr + 4*nr)); fill_prefetch_0 (); regs.t1 = regs.t0 = regs.m = 0; @@ -1093,8 +1128,8 @@ static char* ccnames[] = void m68k_reset (void) { - m68k_areg (regs, 7) = get_long (ROMmem_start); - m68k_setpc (get_long (ROMmem_start+4)); + m68k_areg(regs, 7) = get_long(0); + m68k_setpc(get_long(4)); fill_prefetch_0 (); regs.s = 1; regs.m = 0; @@ -1129,7 +1164,7 @@ unsigned long REGPARAM2 op_illg (uae_u32 write_log ("This program requires a 68020 CPU!\n"); broken_in = 1; set_special (SPCFLAG_BRK); - quit_program = 1; + bQuitProgram = 1; } /* if (opcode == 0xFF0D) { @@ -1173,7 +1208,7 @@ unsigned long REGPARAM2 op_illg (uae_u32 return 4; } -#if 1 +#if 0 write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); #endif Exception (4,0); @@ -1240,28 +1275,31 @@ static int do_specialties (void) } while (regs.spcflags & SPCFLAG_STOP) { do_cycles (4); - /*if (regs.spcflags & SPCFLAG_COPPER) - do_copper ();*/ - if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)){ - int intr = intlev (); + if (regs.intmask>5) { + /* We still have to care about events when IPL==7 ! */ + Main_EventHandler(); + if(bQuitProgram) unset_special(SPCFLAG_STOP); + } + if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { + /*int intr = intlev ();*/ unset_special (SPCFLAG_INT | SPCFLAG_DOINT); - if (intr != -1 && intr > regs.intmask) { + /*if (intr != -1 && intr > regs.intmask) { Interrupt (intr); regs.stopped = 0; unset_special (SPCFLAG_STOP); - } + }*/ } } if (regs.spcflags & SPCFLAG_TRACE) do_trace (); if (regs.spcflags & SPCFLAG_DOINT) { - int intr = intlev (); + /*int intr = intlev ();*/ unset_special (SPCFLAG_DOINT); - if (intr != -1 && intr > regs.intmask) { + /*if (intr != -1 && intr > regs.intmask) { Interrupt (intr); regs.stopped = 0; - } + }*/ } if (regs.spcflags & SPCFLAG_INT) { unset_special (SPCFLAG_INT); @@ -1274,6 +1312,7 @@ static int do_specialties (void) return 0; } + /* It's really sad to have two almost identical functions for this, but we do it all for performance... :( */ static void m68k_run_1 (void) @@ -1282,7 +1321,7 @@ static void m68k_run_1 (void) uae_u8 saved_bytes[20]; uae_u16 *oldpcp; #endif - while(!quit_program) { + while(!bQuitProgram) { int cycles; uae_u32 opcode = get_iword_prefetch (0); #ifdef DEBUG_PREFETCH @@ -1296,8 +1335,7 @@ static void m68k_run_1 (void) #endif /*m68k_dumpstate(stderr, NULL);*/ - m68k_disasm(stderr, m68k_getpc (), NULL, 1); - /*if( opcode == 0 ) sleep(1);*/ + /*m68k_disasm(stderr, m68k_getpc (), NULL, 1);*/ /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1326,12 +1364,11 @@ static void m68k_run_1 (void) } } -#define DEBUG_PREFETCH /* Same thing, but don't use prefetch to get opcode. */ static void m68k_run_2 (void) { - while(!quit_program) { + while(!bQuitProgram) { int cycles; #ifdef HAVE_GET_WORD_UNSWAPPED uae_u32 opcode = do_get_mem_word_unswapped (regs.pc_p); @@ -1340,9 +1377,7 @@ static void m68k_run_2 (void) #endif /*m68k_dumpstate(stderr, NULL);*/ - /*if(crashtrace) - { --crashtrace ; m68k_disasm(stderr, m68k_getpc (), NULL, 1); }*/ - /*if( opcode == 0 ) sleep(1); */ + /*m68k_disasm(stderr, m68k_getpc (), NULL, 1);*/ /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1374,21 +1409,7 @@ void m68k_go (int may_quit) } in_m68k_go++; - while(!quit_program) { -/* - if (quit_program > 0) { - if (quit_program == 1) - break; - quit_program = 0; - m68k_reset (); - //reset_all_systems (); - customreset (); - } -*/ -/* - if (debugging) - debug (); -*/ + while(!bQuitProgram) { if(cpu_compatible) m68k_run_1(); else @@ -1473,11 +1494,11 @@ void m68k_disasm (FILE *f, uaecptr addr, } if (ccpt != 0) { if (cctrue(dp->cc)) - fprintf (f, " == %08lx (TRUE)", newpc); + fprintf (f, " == %08lx (TRUE)", (long)newpc); else - fprintf (f, " == %08lx (FALSE)", newpc); + fprintf (f, " == %08lx (FALSE)", (long)newpc); } else if ((opcode & 0xff00) == 0x6100) /* BSR */ - fprintf (f, " == %08lx", newpc); + fprintf (f, " == %08lx", (long)newpc); fprintf (f, "\n"); } if (nextpc) @@ -1488,18 +1509,18 @@ void m68k_dumpstate (FILE *f, uaecptr *n { int i; for (i = 0; i < 8; i++){ - fprintf (f, "D%d: %08lx ", i, m68k_dreg(regs, i)); + fprintf (f, "D%d: %08lx ", i, (long)m68k_dreg(regs, i)); if ((i & 3) == 3) fprintf (f, "\n"); } for (i = 0; i < 8; i++){ - fprintf (f, "A%d: %08lx ", i, m68k_areg(regs, i)); + fprintf (f, "A%d: %08lx ", i, (long)m68k_areg(regs, i)); if ((i & 3) == 3) fprintf (f, "\n"); } if (regs.s == 0) regs.usp = m68k_areg(regs, 7); if (regs.s && regs.m) regs.msp = m68k_areg(regs, 7); if (regs.s && regs.m == 0) regs.isp = m68k_areg(regs, 7); fprintf (f, "USP=%08lx ISP=%08lx MSP=%08lx VBR=%08lx\n", - regs.usp,regs.isp,regs.msp,regs.vbr); + (long)regs.usp,(long)regs.isp,(long)regs.msp,(long)regs.vbr); fprintf (f, "T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d\n", regs.t1, regs.t0, regs.s, regs.m, GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG, regs.intmask); @@ -1517,5 +1538,5 @@ void m68k_dumpstate (FILE *f, uaecptr *n m68k_disasm (f, m68k_getpc (), nextpc, 1); if (nextpc) - fprintf (f, "next PC: %08lx\n", *nextpc); + fprintf (f, "next PC: %08lx\n", (long)*nextpc); }