Annotation of hatari/src/cpu/hatari-glue.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari - hatari-glue.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   This file contains some code to glue the UAE CPU core to the rest of the
                      8:   emulator and Hatari's "illegal" opcodes.
                      9: */
                     10: const char HatariGlue_fileid[] = "Hatari hatari-glue.c : " __DATE__ " " __TIME__;
                     11: 
                     12: 
                     13: #include <stdio.h>
                     14: 
                     15: #include "main.h"
                     16: #include "configuration.h"
                     17: #include "cycInt.h"
                     18: #include "tos.h"
                     19: #include "gemdos.h"
                     20: #include "cart.h"
                     21: #include "vdi.h"
                     22: #include "stMemory.h"
                     23: #include "ikbd.h"
                     24: #include "screen.h"
                     25: #include "video.h"
1.1.1.2   root       26: #include "psg.h"
1.1       root       27: 
                     28: #include "sysdeps.h"
                     29: #include "maccess.h"
                     30: #include "memory.h"
                     31: #include "newcpu.h"
1.1.1.3 ! root       32: #include "cpu_prefetch.h"
1.1       root       33: #include "hatari-glue.h"
                     34: 
                     35: 
                     36: struct uae_prefs currprefs, changed_prefs;
                     37: 
                     38: int pendingInterrupts = 0;
                     39: 
                     40: 
                     41: /**
                     42:  * Reset custom chips
                     43:  */
                     44: void customreset(void)
                     45: {
                     46:        pendingInterrupts = 0;
                     47: 
                     48:        /* In case the 6301 was executing a custom program from its RAM */
                     49:        /* we must turn it back to the 'normal' mode. */
                     50:        IKBD_Reset_ExeMode ();
                     51: 
                     52:        /* Reseting the GLUE video chip should also set freq/res register to 0 */
                     53:        Video_Reset_Glue ();
1.1.1.2   root       54: 
                     55:         /* Reset the YM2149 (stop any sound) */
                     56:         PSG_Reset ();
1.1       root       57: }
                     58: 
                     59: 
                     60: /**
                     61:  * Return interrupt number (1 - 7), -1 means no interrupt.
                     62:  * Note that the interrupt stays pending if it can't be executed yet
                     63:  * due to the interrupt level field in the SR.
                     64:  */
                     65: int intlev(void)
                     66: {
                     67:        /* There are only VBL and HBL autovector interrupts in the ST... */
                     68:        assert((pendingInterrupts & ~((1<<4)|(1<<2))) == 0);
                     69: 
                     70:        if (pendingInterrupts & (1 << 4))         /* VBL interrupt? */
                     71:        {
                     72:                if (regs.intmask < 4)
                     73:                        pendingInterrupts &= ~(1 << 4);
                     74:                return 4;
                     75:        }
                     76:        else if (pendingInterrupts & (1 << 2))    /* HBL interrupt? */
                     77:        {
                     78:                if (regs.intmask < 2)
                     79:                        pendingInterrupts &= ~(1 << 2);
                     80:                return 2;
                     81:        }
                     82: 
                     83:        return -1;
                     84: }
                     85: 
                     86: /**
                     87:  * Initialize 680x0 emulation
                     88:  */
                     89: int Init680x0(void)
                     90: {
                     91:        currprefs.cpu_level = changed_prefs.cpu_level = ConfigureParams.System.nCpuLevel;
                     92: 
                     93:        switch (currprefs.cpu_level) {
                     94:                case 0 : currprefs.cpu_model = 68000; break;
                     95:                case 1 : currprefs.cpu_model = 68010; break;
                     96:                case 2 : currprefs.cpu_model = 68020; break;
                     97:                case 3 : currprefs.cpu_model = 68030; break;
                     98:                case 4 : currprefs.cpu_model = 68040; break;
                     99:                case 5 : currprefs.cpu_model = 68060; break;
                    100:                default: fprintf (stderr, "Init680x0() : Error, cpu_level unknown\n");
                    101:        }
                    102:        
                    103:        currprefs.cpu_compatible = changed_prefs.cpu_compatible = ConfigureParams.System.bCompatibleCpu;
                    104:        currprefs.address_space_24 = changed_prefs.address_space_24 = ConfigureParams.System.bAddressSpace24;
                    105:        currprefs.cpu_cycle_exact = changed_prefs.cpu_cycle_exact = ConfigureParams.System.bCycleExactCpu;
                    106:        currprefs.fpu_model = changed_prefs.fpu_model = ConfigureParams.System.n_FPUType;
                    107:        currprefs.fpu_strict = changed_prefs.fpu_strict = ConfigureParams.System.bCompatibleFPU;
                    108:        currprefs.mmu_model = changed_prefs.mmu_model = ConfigureParams.System.bMMU;
                    109: 
                    110:        init_m68k();
                    111: 
                    112:        return true;
                    113: }
                    114: 
                    115: 
                    116: /**
                    117:  * Deinitialize 680x0 emulation
                    118:  */
                    119: void Exit680x0(void)
                    120: {
                    121:        memory_uninit();
                    122: 
                    123:        free(table68k);
                    124:        table68k = NULL;
                    125: }
                    126: 
                    127: /**
                    128:  * This function will be called at system init by the cartridge routine
                    129:  * (after gemdos init, before booting floppies).
                    130:  * The GEMDOS vector (#$84) is setup and we also initialize the connected
                    131:  * drive mask and Line-A  variables (for an extended VDI resolution) from here.
                    132:  */
                    133: unsigned long OpCode_SysInit(uae_u32 opcode)
                    134: {
                    135:        /* Add any drives mapped by TOS in the interim */
                    136:        ConnectedDriveMask |= STMemory_ReadLong(0x4c2);
                    137:        /* Initialize the connected drive mask */
                    138:        STMemory_WriteLong(0x4c2, ConnectedDriveMask);
                    139: 
                    140:        if (!bInitGemDOS)
                    141:        {
                    142:                /* Init on boot - see cart.c */
                    143:                GemDOS_Boot();
                    144: 
                    145:                /* Update LineA for extended VDI res
                    146:                 * D0: LineA base, A1: Font base
                    147:                 */
                    148:                VDI_LineA(regs.regs[0], regs.regs[9]);
                    149:        }
                    150: 
                    151:        m68k_incpc(2);
1.1.1.3 ! root      152:        regs.ir = regs.irc;
        !           153:        get_word_prefetch(2);
        !           154: 
        !           155:        return 4 * CYCLE_UNIT / 2;
1.1       root      156: }
                    157: 
                    158: 
                    159: /**
                    160:  * Intercept GEMDOS calls.
                    161:  * Used for GEMDOS HD emulation (see gemdos.c).
                    162:  */
                    163: unsigned long OpCode_GemDos(uae_u32 opcode)
                    164: {
                    165:        GemDOS_OpCode();    /* handler code in gemdos.c */
                    166: 
                    167:        m68k_incpc(2);
1.1.1.3 ! root      168:        regs.ir = regs.irc;
        !           169:        get_word_prefetch(2);
        !           170: 
        !           171:        return 4 * CYCLE_UNIT / 2;
1.1       root      172: }
                    173: 
                    174: 
                    175: /**
                    176:  * This is called after completion of each VDI call
                    177:  */
                    178: unsigned long OpCode_VDI(uae_u32 opcode)
                    179: {
                    180:        VDI_Complete();
                    181: 
                    182:        /* Set PC back to where originated from to continue instruction decoding */
                    183:        m68k_setpc(VDI_OldPC);
                    184: 
1.1.1.3 ! root      185:        get_word_prefetch (0);
        !           186:        regs.ir = regs.irc;
        !           187:        get_word_prefetch(2);
        !           188: 
        !           189:        return 4 * CYCLE_UNIT / 2;
1.1       root      190: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.