this repo has no description
1/*
2 ROMEMDEV.c
3
4 Copyright (C) 2007 Philip Cummins, Paul C. Pratt
5
6 You can redistribute this file and/or modify it under the terms
7 of version 2 of the GNU General Public License as published by
8 the Free Software Foundation. You should have received a copy
9 of the license along with this file; see the file COPYING.
10
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 license for more details.
15*/
16
17/*
18 Read Only Memory EMulated DEVice
19
20 Checks the header of the loaded ROM image, and then patches
21 the ROM image.
22
23 This code descended from "ROM.c" in vMac by Philip Cummins.
24
25 Support for "Twiggy" Mac by Mathew Hybler.
26*/
27
28#include "PICOMMON.h"
29
30#include "ROMEMDEV.h"
31
32#define UseSonyPatch \
33 ((CurEmMd <= kEmMd_Classic) || (CurEmMd == kEmMd_II) \
34 || (CurEmMd == kEmMd_IIx))
35
36#ifndef UseLargeScreenHack
37#define UseLargeScreenHack 0
38#endif
39
40#if UseSonyPatch
41LOCALVAR const ui3b sony_driver[] = {
42/*
43 Replacement for .Sony driver
44 68k machine code, compiled from mydriver.a
45*/
460x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
470x00, 0xF4, 0x00, 0x18, 0x00, 0x24, 0x00, 0x4A,
480x00, 0x8A, 0x05, 0x2E, 0x53, 0x6F, 0x6E, 0x79,
490x48, 0xE7, 0x00, 0xC0, 0x55, 0x4F, 0x3F, 0x3C,
500x00, 0x01, 0x60, 0x30, 0x48, 0xE7, 0x00, 0xC0,
510x55, 0x4F, 0x3F, 0x3C, 0x00, 0x02, 0x41, 0xFA,
520x01, 0xA4, 0x2F, 0x18, 0x20, 0x50, 0x20, 0x8F,
530x5C, 0x4F, 0x30, 0x1F, 0x4C, 0xDF, 0x03, 0x00,
540x0C, 0x68, 0x00, 0x01, 0x00, 0x1A, 0x66, 0x1E,
550x4E, 0x75, 0x48, 0xE7, 0x00, 0xC0, 0x55, 0x4F,
560x3F, 0x3C, 0x00, 0x03, 0x41, 0xFA, 0x01, 0x7E,
570x2F, 0x18, 0x20, 0x50, 0x20, 0x8F, 0x5C, 0x4F,
580x30, 0x1F, 0x4C, 0xDF, 0x03, 0x00, 0x32, 0x28,
590x00, 0x06, 0x08, 0x01, 0x00, 0x09, 0x67, 0x0C,
600x4A, 0x40, 0x6F, 0x02, 0x42, 0x40, 0x31, 0x40,
610x00, 0x10, 0x4E, 0x75, 0x4A, 0x40, 0x6F, 0x04,
620x42, 0x40, 0x4E, 0x75, 0x2F, 0x38, 0x08, 0xFC,
630x4E, 0x75, 0x48, 0xE7, 0x00, 0xC0, 0x55, 0x4F,
640x3F, 0x3C, 0x00, 0x04, 0x41, 0xFA, 0x01, 0x3E,
650x2F, 0x18, 0x20, 0x50, 0x20, 0x8F, 0x5C, 0x4F,
660x30, 0x1F, 0x4C, 0xDF, 0x03, 0x00, 0x4E, 0x75,
670x48, 0xE7, 0xE0, 0xC0, 0x20, 0x2F, 0x00, 0x14,
680x59, 0x4F, 0x2F, 0x00, 0x55, 0x4F, 0x3F, 0x3C,
690x00, 0x08, 0x41, 0xFA, 0x01, 0x18, 0x2F, 0x18,
700x20, 0x50, 0x20, 0x8F, 0x5C, 0x4F, 0x32, 0x1F,
710x58, 0x4F, 0x20, 0x1F, 0x4A, 0x41, 0x66, 0x06,
720x30, 0x7C, 0x00, 0x07, 0xA0, 0x2F, 0x4C, 0xDF,
730x03, 0x07, 0x58, 0x4F, 0x4E, 0x73, 0x21, 0x40,
740x00, 0x06, 0x43, 0xF8, 0x03, 0x08, 0x4E, 0xF9,
750x00, 0x40, 0x0B, 0x20, 0x31, 0x78, 0x0E, 0x19,
760x00, 0x0A, 0x4E, 0x75, 0x48, 0xE7, 0x1F, 0x18,
770x48, 0xE7, 0x00, 0xC0, 0x5D, 0x4F, 0x3F, 0x3C,
780x00, 0x05, 0x41, 0xFA, 0x00, 0xD0, 0x2F, 0x18,
790x20, 0x50, 0x20, 0x8F, 0x5C, 0x4F, 0x30, 0x1F,
800x2E, 0x1F, 0x0C, 0x40, 0xFF, 0xCF, 0x66, 0x06,
810x42, 0x40, 0x60, 0x00, 0x00, 0xA8, 0x4A, 0x40,
820x66, 0x00, 0x00, 0xA2, 0x20, 0x07, 0xA7, 0x1E,
830x28, 0x48, 0x20, 0x0C, 0x67, 0x00, 0x00, 0xA0,
840x9E, 0xFC, 0x00, 0x10, 0x2F, 0x0C, 0x2F, 0x07,
850x55, 0x4F, 0x3F, 0x3C, 0x00, 0x06, 0x41, 0xFA,
860x00, 0x94, 0x2F, 0x18, 0x20, 0x50, 0x20, 0x8F,
870x5C, 0x4F, 0x30, 0x1F, 0x50, 0x4F, 0x2E, 0x1F,
880x76, 0x00, 0x36, 0x1F, 0x38, 0x1F, 0x3C, 0x1F,
890x3A, 0x1F, 0x26, 0x5F, 0x4A, 0x40, 0x66, 0x64,
900x41, 0xEC, 0x00, 0x30, 0x43, 0xFA, 0xFF, 0x86,
910x31, 0x7C, 0x00, 0x01, 0x00, 0x04, 0x21, 0x49,
920x00, 0x06, 0x31, 0x78, 0x0E, 0x19, 0x00, 0x0A,
930xA0, 0x33, 0x20, 0x0B, 0x67, 0x0E, 0x41, 0xFA,
940xFF, 0x72, 0x27, 0x48, 0x00, 0x06, 0x20, 0x4B,
950xA0, 0x58, 0x60, 0x1A, 0x41, 0xFA, 0xFF, 0x50,
960x30, 0x3C, 0xA0, 0x4E, 0xA0, 0x47, 0x60, 0x0E,
970x20, 0x47, 0x30, 0x06, 0x48, 0x40, 0x30, 0x05,
980xA0, 0x4E, 0xDE, 0x83, 0x52, 0x46, 0x51, 0xCC,
990xFF, 0xF0, 0x48, 0x7A, 0xFE, 0xFC, 0x55, 0x4F,
1000x3F, 0x3C, 0x00, 0x07, 0x41, 0xFA, 0x00, 0x1E,
1010x2F, 0x18, 0x20, 0x50, 0x20, 0x8F, 0x5C, 0x4F,
1020x30, 0x1F, 0x58, 0x4F, 0x4C, 0xDF, 0x03, 0x00,
1030x4C, 0xDF, 0x18, 0xF8, 0x4E, 0x75, 0x30, 0x3C,
1040xFF, 0xFF, 0x60, 0xF0
105};
106#endif
107
108#if UseSonyPatch
109LOCALVAR const ui3b my_disk_icon[] = {
110 0x7F, 0xFF, 0xFF, 0xF0,
111 0x81, 0x00, 0x01, 0x08,
112 0x81, 0x00, 0x71, 0x04,
113 0x81, 0x00, 0x89, 0x02,
114 0x81, 0x00, 0x89, 0x01,
115 0x81, 0x00, 0x89, 0x01,
116 0x81, 0x00, 0x89, 0x01,
117 0x81, 0x00, 0x89, 0x01,
118 0x81, 0x00, 0x89, 0x01,
119 0x81, 0x00, 0x71, 0x01,
120 0x81, 0x00, 0x01, 0x01,
121 0x80, 0xFF, 0xFE, 0x01,
122 0x80, 0x00, 0x00, 0x01,
123 0x80, 0x00, 0x00, 0x01,
124 0x80, 0x00, 0x00, 0x01,
125 0x80, 0x00, 0x00, 0x01,
126 0x83, 0xFF, 0xFF, 0xC1,
127 0x84, 0x00, 0x00, 0x21,
128 0x84, 0x00, 0x00, 0x21,
129 0x84, 0x00, 0x00, 0x21,
130 0x84, 0x00, 0x00, 0x21,
131 0x84, 0x00, 0x00, 0x21,
132 0x84, 0x06, 0x30, 0x21,
133 0x84, 0x06, 0x60, 0x21,
134 0x84, 0x06, 0xC0, 0x21,
135 0x84, 0x07, 0x80, 0x21,
136 0x84, 0x07, 0x00, 0x21,
137 0x84, 0x06, 0x00, 0x21,
138 0x84, 0x00, 0x00, 0x21,
139 0x84, 0x00, 0x00, 0x21,
140 0x84, 0x00, 0x00, 0x21,
141 0x7F, 0xFF, 0xFF, 0xFE,
142
143 /* mask */
144
145 0x3F, 0xFF, 0xFF, 0xF0,
146 0x7F, 0xFF, 0xFF, 0xF0,
147 0xFF, 0xFF, 0xFF, 0xFC,
148 0xFF, 0xFF, 0xFF, 0xFC,
149 0xFF, 0xFF, 0xFF, 0xFF,
150 0xFF, 0xFF, 0xFF, 0xFF,
151 0xFF, 0xFF, 0xFF, 0xFF,
152 0xFF, 0xFF, 0xFF, 0xFF,
153 0xFF, 0xFF, 0xFF, 0xFF,
154 0xFF, 0xFF, 0xFF, 0xFF,
155 0xFF, 0xFF, 0xFF, 0xFF,
156 0xFF, 0xFF, 0xFF, 0xFF,
157 0xFF, 0xFF, 0xFF, 0xFF,
158 0xFF, 0xFF, 0xFF, 0xFF,
159 0xFF, 0xFF, 0xFF, 0xFF,
160 0xFF, 0xFF, 0xFF, 0xFF,
161 0xFF, 0xFF, 0xFF, 0xFF,
162 0xFF, 0xFF, 0xFF, 0xFF,
163 0xFF, 0xFF, 0xFF, 0xFF,
164 0xFF, 0xFF, 0xFF, 0xFF,
165 0xFF, 0xFF, 0xFF, 0xFF,
166 0xFF, 0xFF, 0xFF, 0xFF,
167 0xFF, 0xFF, 0xFF, 0xFF,
168 0xFF, 0xFF, 0xFF, 0xFF,
169 0xFF, 0xFF, 0xFF, 0xFF,
170 0xFF, 0xFF, 0xFF, 0xFF,
171 0xFF, 0xFF, 0xFF, 0xFF,
172 0xFF, 0xFF, 0xFF, 0xFF,
173 0xFF, 0xFF, 0xFF, 0xFF,
174 0xFF, 0xFF, 0xFF, 0xFF,
175 0x7F, 0xFF, 0xFF, 0xFC,
176 0x3F, 0xFF, 0xFF, 0xFC,
177
178 /* empty pascal string */
179 0x00, 0x00,
180};
181#endif
182
183#if CurEmMd <= kEmMd_Twig43
184#define Sony_DriverBase 0x1836
185#elif CurEmMd <= kEmMd_Twiggy
186#define Sony_DriverBase 0x16E4
187#elif CurEmMd <= kEmMd_128K
188#define Sony_DriverBase 0x1690
189#elif CurEmMd <= kEmMd_Plus
190#define Sony_DriverBase 0x17D30
191#elif CurEmMd <= kEmMd_Classic
192#define Sony_DriverBase 0x34680
193#elif (CurEmMd == kEmMd_II) || (CurEmMd == kEmMd_IIx)
194#define Sony_DriverBase 0x2D72C
195#endif
196
197#define kVidMem_Base 0x00540000
198
199#if UseSonyPatch
200LOCALPROC Sony_Install(void)
201{
202 ui3p pto = Sony_DriverBase + ROM;
203
204 MyMoveBytes((anyp)sony_driver, (anyp)pto, sizeof(sony_driver));
205#if CurEmMd <= kEmMd_Twiggy
206 do_put_mem_long(pto + 0x14, 0x4469736B);
207 /* 'Disk' instead of 'Sony' */
208#if CurEmMd <= kEmMd_Twig43
209 do_put_mem_word(pto + 0xEA, 0x0C8A);
210#else
211 do_put_mem_word(pto + 0xEA, 0x0B74);
212#endif
213#endif
214
215 pto += sizeof(sony_driver);
216
217 do_put_mem_word(pto, kcom_callcheck);
218 pto += 2;
219 do_put_mem_word(pto, kExtnSony);
220 pto += 2;
221 do_put_mem_long(pto, kExtn_Block_Base); /* pokeaddr */
222 pto += 4;
223
224 my_disk_icon_addr = (pto - ROM) + kROM_Base;
225 MyMoveBytes((anyp)my_disk_icon, (anyp)pto, sizeof(my_disk_icon));
226 pto += sizeof(my_disk_icon);
227
228#if UseLargeScreenHack
229 {
230 ui3p patchp = pto;
231
232#include "SCRNHACK.h"
233 }
234#endif
235
236 (void) pto; /* avoid warning about unused */
237}
238#endif
239
240#ifndef DisableRomCheck
241#define DisableRomCheck 1
242#endif
243
244#ifndef DisableRamTest
245#define DisableRamTest 1
246#endif
247
248#ifdef CurAltHappyMac
249#include "HPMCHACK.h"
250#endif
251
252#ifdef ln2mtb
253LOCALPROC ROMscrambleForMTB(void)
254{
255 si5r j;
256 ui3p p = ROM;
257 ui3p p2 = ROM + (1 << ln2mtb);
258
259 for (j = kROM_Size / (1 << ln2mtb) / 2; --j >= 0; ) {
260 si5r i;
261
262 for (i = (1 << ln2mtb); --i >= 0; ) {
263 ui3b t0 = *p;
264 ui3b t1 = *p2;
265 *p++ = t1;
266 *p2++ = t0;
267 }
268
269 p += (1 << ln2mtb);
270 p2 += (1 << ln2mtb);
271 }
272}
273#endif
274
275GLOBALFUNC blnr ROM_Init(void)
276{
277#if DisableRomCheck
278
279/* skip the rom checksum */
280#if CurEmMd <= kEmMd_Twig43
281 /* no checksum code */
282#elif CurEmMd <= kEmMd_Twiggy
283 do_put_mem_word(0x136 + ROM, 0x6004);
284#elif CurEmMd <= kEmMd_128K
285 do_put_mem_word(0xE2 + ROM, 0x6004);
286#elif CurEmMd <= kEmMd_Plus
287 do_put_mem_word(0xD7A + ROM, 0x6022);
288#elif CurEmMd <= kEmMd_Classic
289 do_put_mem_word(0x1C68 + ROM, 0x6008);
290#elif (CurEmMd == kEmMd_II) || (CurEmMd == kEmMd_IIx)
291 do_put_mem_word(0x2AB0 + ROM, 0x6008);
292#endif
293
294#endif /* DisableRomCheck */
295
296
297#if DisableRamTest
298
299#if CurEmMd <= kEmMd_128K
300#elif CurEmMd <= kEmMd_Plus
301 do_put_mem_word(3752 + ROM, 0x4E71);
302 /* shorten the ram check read */
303 do_put_mem_word(3728 + ROM, 0x4E71);
304 /* shorten the ram check write */
305#elif CurEmMd <= kEmMd_Classic
306 do_put_mem_word(134 + ROM, 0x6002);
307 do_put_mem_word(286 + ROM, 0x6002);
308#elif (CurEmMd == kEmMd_II) || (CurEmMd == kEmMd_IIx)
309 do_put_mem_word(0xEE + ROM, 0x6002);
310 do_put_mem_word(0x1AA + ROM, 0x6002);
311#endif
312
313#endif /* DisableRamTest */
314
315#ifdef CurAltHappyMac
316 PatchHappyMac();
317#endif
318
319 /* do_put_mem_word(862 + ROM, 0x4E71); */ /* shorten set memory */
320
321#if UseSonyPatch
322 Sony_Install();
323#endif
324
325#ifdef ln2mtb
326 ROMscrambleForMTB();
327#endif
328
329 return trueblnr;
330}