|
|
1.1 root 1: /*
1.1.1.4 root 2: Hatari - cart.c
3:
1.1.1.12! root 4: This file is distributed under the GNU General Public License, version 2
! 5: or at your option any later version. Read the file gpl.txt for details.
1.1 root 6:
1.1.1.5 root 7: Cartridge program
1.1 root 8:
1.1.1.7 root 9: To load programs into memory, through TOS, we need to intercept GEMDOS so we
10: can relocate/execute programs via GEMDOS call $4B (Pexec).
1.1.1.5 root 11: We have some 68000 assembler, located at 0xFA0000 (cartridge memory), which is
12: used as our new GEMDOS handler. This checks if we need to intercept the call.
1.1 root 13:
1.1.1.7 root 14: The assembler routine can be found in 'cart_asm.s', and has been converted to
15: a byte array and stored in 'Cart_data[]' (see cartData.c).
1.1 root 16: */
1.1.1.10 root 17: const char Cart_fileid[] = "Hatari cart.c : " __DATE__ " " __TIME__;
1.1.1.8 root 18:
19: /* 2007/12/09 [NP] Change the function associated to opcodes $8, $a and $c only if hard drive */
20: /* emulation is ON. Else, these opcodes should give illegal instructions (also */
21: /* see uae-cpu/newcpu.c). */
22:
1.1 root 23:
24: #include "main.h"
25: #include "cart.h"
1.1.1.4 root 26: #include "configuration.h"
27: #include "file.h"
1.1.1.7 root 28: #include "log.h"
1.1.1.9 root 29: #include "m68000.h"
1.1 root 30: #include "stMemory.h"
1.1.1.12! root 31: #include "tos.h"
1.1.1.4 root 32: #include "vdi.h"
1.1.1.8 root 33: #include "hatari-glue.h"
34: #include "newcpu.h"
1.1 root 35:
1.1.1.5 root 36: #include "cartData.c"
1.1 root 37:
38:
1.1.1.7 root 39: /* Possible cartridge file extensions to scan for */
40: static const char * const psCartNameExts[] =
41: {
42: ".img",
43: ".rom",
44: ".stc",
45: NULL
46: };
47:
48:
1.1 root 49: /*-----------------------------------------------------------------------*/
1.1.1.8 root 50: /**
51: * Load an external cartridge image file.
52: */
1.1.1.7 root 53: static void Cart_LoadImage(void)
1.1 root 54: {
1.1.1.7 root 55: Uint8 *pCartData;
56: long nCartSize;
1.1.1.4 root 57: char *pCartFileName = ConfigureParams.Rom.szCartridgeImageFileName;
58:
1.1.1.7 root 59: /* Try to load the image file: */
1.1.1.8 root 60: pCartData = File_Read(pCartFileName, &nCartSize, psCartNameExts);
1.1.1.7 root 61: if (!pCartData)
62: {
63: Log_Printf(LOG_ERROR, "Failed to load '%s'.\n", pCartFileName);
64: return;
65: }
66:
67: if (nCartSize < 40 || (nCartSize > 0x20000 && nCartSize != 0x20004))
68: {
69: Log_Printf(LOG_ERROR, "Cartridge file '%s' has illegal size.\n", pCartFileName);
70: free(pCartData);
71: return;
72: }
73:
74: /* There are two type of cartridge images, normal 1:1 images which are
75: * always smaller than or equal to 0x20000 bytes, and the .STC images,
76: * which are always 0x20004 bytes (the first 4 bytes are a dummy header).
77: * So if size is 0x20004 bytes we have to skip the first 4 bytes */
78: if (nCartSize == 0x20004)
79: {
1.1.1.8 root 80: memcpy(&RomMem[0xfa0000], pCartData+4, 0x20000);
1.1.1.7 root 81: }
82: else
83: {
1.1.1.8 root 84: memcpy(&RomMem[0xfa0000], pCartData, nCartSize);
1.1.1.7 root 85: }
86:
87: free(pCartData);
88: }
89:
90:
91: /*-----------------------------------------------------------------------*/
1.1.1.8 root 92: /**
93: * Copy ST GEMDOS intercept program image into cartridge memory space
94: * or load an external cartridge file.
95: * The intercept program is part of Hatari and used as an interface to the host
96: * file system through GemDOS. It is also needed for Line-A-Init when using
97: * extended VDI resolutions.
98: */
1.1.1.7 root 99: void Cart_ResetImage(void)
100: {
1.1.1.11 root 101: int PatchIllegal = false;
1.1.1.8 root 102:
1.1.1.4 root 103: /* "Clear" cartridge ROM space */
1.1.1.8 root 104: memset(&RomMem[0xfa0000], 0xff, 0x20000);
1.1.1.4 root 105:
1.1.1.7 root 106: /* Print a warning if user tries to use an external cartridge file
107: * together with GEMDOS HD emulation or extended VDI resolution: */
108: if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
109: {
110: if (bUseVDIRes)
111: Log_Printf(LOG_WARN, "Cartridge can't be used together with extended VDI resolution!\n");
112: if (ConfigureParams.HardDisk.bUseHardDiskDirectories)
113: Log_Printf(LOG_WARN, "Cartridge can't be used together with GEMDOS hard disk emulation!\n");
114: }
115:
1.1.1.12! root 116: /* Use internal cartridge when user wants extended VDI resolution or
! 117: * GEMDOS HD. But don't use it on TOS 0.00, it does not work there. */
! 118: if ((bUseVDIRes || ConfigureParams.HardDisk.bUseHardDiskDirectories)
! 119: && TosVersion >= 0x100)
1.1.1.4 root 120: {
1.1.1.12! root 121: /* Copy built-in cartridge data into the cartridge memory of the ST */
1.1.1.9 root 122: memcpy(&RomMem[0xfa0000], Cart_data, sizeof(Cart_data));
1.1.1.11 root 123: PatchIllegal = true;
1.1.1.4 root 124: }
1.1.1.7 root 125: else if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
1.1.1.4 root 126: {
1.1.1.7 root 127: /* Load external image file: */
128: Cart_LoadImage();
1.1.1.4 root 129: }
1.1.1.8 root 130:
1.1.1.11 root 131: if (PatchIllegal == true)
1.1.1.8 root 132: {
133: //fprintf ( stderr ," Cart_ResetImage patch\n" );
134: /* Hatari's specific illegal opcodes for HD emulation */
135: cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos; /* 0x0008 */
136: cpufunctbl[SYSINIT_OPCODE] = OpCode_SysInit; /* 0x000a */
137: cpufunctbl[VDI_OPCODE] = OpCode_VDI; /* 0x000c */
138: }
139: else
140: {
141: //fprintf ( stderr ," Cart_ResetImage no patch\n" );
142: /* No built-in cartridge loaded : set same handler as 0x4afc (illegal) */
143: cpufunctbl[GEMDOS_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x0008 */
144: cpufunctbl[SYSINIT_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x000a */
145: cpufunctbl[VDI_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x000c */
146: }
1.1.1.12! root 147:
! 148: /* although these don't need cartridge code, it's better
! 149: * to configure all illegal opcodes in same place...
! 150: */
! 151: if (ConfigureParams.Log.bNatFeats)
! 152: {
! 153: /* illegal opcodes for emulators Native Features */
! 154: cpufunctbl[NATFEAT_ID_OPCODE] = OpCode_NatFeat_ID; /* 0x7300 */
! 155: cpufunctbl[NATFEAT_CALL_OPCODE] = OpCode_NatFeat_Call; /* 0x7301 */
! 156: }
! 157: else
! 158: {
! 159: /* No Native Features : set same handler as 0x4afc (illegal) */
! 160: cpufunctbl[NATFEAT_ID_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x7300 */
! 161: cpufunctbl[NATFEAT_CALL_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x7300 */
! 162: }
1.1 root 163: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.