-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.c
358 lines (259 loc) · 10.2 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
//
// main.c
// The Omega Project
// https://github.com/h5n1xp/Omega
//
// Created by Matt Parsons on 02/02/2019.
// Copyright © 2019 Matt Parsons. All rights reserved.
// <[email protected]>
//
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#include "CPU.h"
#include "Host.h"
#include "Memory.h"
#include "DMA.h"
#include "Chipset.h"
#include "CIA.h"
#include "Floppy.h"
#include "m68k.h"
#define PAL 1 // PAL system
//define PAL 0 // NTSC system
int screenWidth = 640;
int screenHeight = 200;
int disass = 0; //set to any value greter than 0 to turn on dissassembler
//run the CPU in a seprate thread... need to sort out interrupts first...
int thd68k(void* data){
SDL_Delay(500);
printf("CPU Running\n");
while(1){
cpu_execute();
//SDL_Delay(1);
}
}
int main(int argc, char * argv[]) {
//load rom from disk if need be
int fd=0;
if(argc>1){
fd = open(argv[1],O_RDWR);
}else{
fd = open("/Users/Shared/uae/roms/Kick2.rom",O_RDONLY); //"/Users/Shared/uae/roms/Kick12.rom" "/Users/Shared/uae/roms/DiagROM" "/Users/Shared/uae/roms/Kick3.rom"
if(fd<1){
printf("Usage: zorro <kickstart.rom> <raw adf image>\n");
return 0;
}
}
int size = (int)lseek(fd, 0, SEEK_END);
//hack to load 256k roms
if(size==0x40000){
lseek(fd, 0, SEEK_SET);
read(fd, &low16Meg[0xF80000], size);
lseek(fd, 0, SEEK_SET);
read(fd, &low16Meg[0xFC0000], size);
}else{
lseek(fd, 0, SEEK_SET);
read(fd, &low16Meg[0xF80000], size);
}
close(fd);
fd=0;
if(low16Meg[0xF80000]==0x11){
printf("ROM loaded\n");
}else{
printf("Not an Amiga ROM\n");
return 0;
}
//Floppy disk
if(argc>2){
fd = open(argv[2],O_RDWR);
printf("%s\n",argv[2]);
}else{
//fd = open("/Users/Shared/uae/WORKBENCH/WB-1.3.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/WORKBENCH/WB-2_05.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/Blitz2-1.ADF",O_RDONLY);
fd = open("/Users/Shared/uae/DosUae/Blitz2-1-2.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DLXP4.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DISK1.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/Fright Night.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/JUGGLER.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/amiga_500a_Tutorial_Disk.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/CuAmiga15.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/LEMM1.ADF",O_RDONLY);
//fd =open("/Users/Shared/uae/ADF/Defender of the Crown (1986)(Mindscape)(Disk 1 of 2).adf",O_RDONLY);
//fd = open("/Users/Shared/uae/ADF/AmigaTestKit.adf",O_RDONLY);
}
//fd = open("/Users/Shared/uae/WORKBENCH/raw3.adf",O_RDONLY);
if(fd<1){
printf("No disk in DF0:\n");
}else{
//int size =(int) lseek(fd, 0, SEEK_END);
//lseek(fd, 2004, SEEK_SET);
//read(fd, floppyInit(0), size);
ADF2MFM(fd, floppyInit(0));
close(fd);
printf("DF0: Loaded (press F1 to insert disk)\n");
}
fd=0;
//DF1
//Floppy disk
if(argc>3){
printf("%s\n",argv[3]);
fd = open(argv[3],O_RDWR);
}else{
//fd = open("/Users/Shared/uae/WORKBENCH/WB-1.3.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/WORKBENCH/EX-2_05.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DLXP4.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DISK1.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/Fright Night.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/JUGGLER.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/amiga_500a_Tutorial_Disk.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/af025_1991_08_d025.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/CuAmiga15.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/WORKBENCH/EX-1_3.adf",O_RDONLY);
fd = open("/Users/Shared/uae/DosUae/Blitz2-2.ADF",O_RDONLY);
//fd =open("/Users/Shared/uae/ADF/Defender of the Crown (1986)(Mindscape)(Disk 2 of 2).adf",O_RDONLY);
}
if(fd<1){
printf("No disk in DF1:\n");
}else{
ADF2MFM(fd,floppyInit(1));
close(fd);
printf("DF1: Loaded (press F2 to insert disk)\n");
}
fd=0;
//DF2
//Floppy disk
if(argc>4){
printf("%s\n",argv[4]);
fd = open(argv[4],O_RDWR);
}else{
//fd = open("/Users/Shared/uae/WORKBENCH/WB-1.3.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DLXP4.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DISK1.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/Fright Night.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/JUGGLER.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/amiga_500a_Tutorial_Disk.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/af025_1991_08_d025.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/CuAmiga15.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/WORKBENCH/EX-1_3.adf",O_RDONLY);
fd = open("/Users/Shared/uae/DosUae/Blitz2-3.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/ADF/Pro Tracker v2.3 (1993)(Noxious).adf",O_RDONLY);
}
if(fd<1){
printf("No disk in DF2:\n");
}else{
ADF2MFM(fd,floppyInit(2));
close(fd);
printf("DF2: Loaded (press F3 to insert disk)\n");
}
fd=0;
//DF2
//Floppy disk
if(argc>5){
printf("%s\n",argv[5]);
fd = open(argv[5],O_RDWR);
}else{
//fd = open("/Users/Shared/uae/WORKBENCH/WB-1.3.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DLXP4.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/DISK1.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/Fright Night.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/JUGGLER.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/amiga_500a_Tutorial_Disk.ADF",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/af025_1991_08_d025.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/DosUae/CuAmiga15.adf",O_RDONLY);
//fd = open("/Users/Shared/uae/WORKBENCH/EX-1_3.adf",O_RDONLY);
fd = open("/Users/Shared/uae/DosUae/Blitz2-4.ADF",O_RDONLY);
}
if(fd<1){
printf("No disk in DF3:\n");
}else{
ADF2MFM(fd,floppyInit(3));
close(fd);
printf("DF3: Loaded (press F4 to insert disk)\n");
}
fd=0;
//setup emulator
hostInit();
cpu_init();
ChipsetInit();
//SDL_Thread* clockThread = SDL_CreateThread(thdClock, "Clock", &sec);
//SDL_DetachThread(clockThread);
//cpuWait = SDL_CreateSemaphore(0);
//SDL_Thread* cpuThread = SDL_CreateThread(thd68k, "CPU", 0);
//SDL_DetachThread(cpuThread);
Chipset_t* chipView = &chipset;
Internal_t* internalView = &internal;
printf("\nEntering main loop\n");
int running = 1;
while(running){
while (SDL_PollEvent(&host.event)) {
switch (host.event.type) {
case SDL_QUIT:
running=0;
break;
case SDL_KEYUP:
if(host.event.key.keysym.sym==SDLK_F1){
//Capture F1
break;
}
if(host.event.key.keysym.sym==SDLK_F2){
//Capture F2
break;
}
if(host.event.key.keysym.sym==SDLK_F3){
//Capture F3
break;
}
if(host.event.key.keysym.sym==SDLK_F4){
//Capture F4
break;
}
if(host.event.key.keysym.sym==SDLK_F5){
//Capture F5
break;
}
releaseKey(host.event.key.keysym.sym);
break;
case SDL_KEYDOWN:
if(host.event.key.keysym.sym==167){
running = 0;
}
if(host.event.key.keysym.sym==SDLK_F1){
floppyInsert(0);
break;
}
if(host.event.key.keysym.sym==SDLK_F2){
floppyInsert(1);
break;
}
if(host.event.key.keysym.sym==SDLK_F3){
floppyInsert(2);
break;
}
if(host.event.key.keysym.sym==SDLK_F4){
floppyInsert(3);
break;
}
if(host.event.key.keysym.sym==SDLK_F5){
toggleLEDs();
break;
}
pressKey(host.event.key.keysym.sym);
break;
default:
break;
}
}
for(int cpuCycles =0;cpuCycles<200;++cpuCycles){
dma_execute();
cpu_execute();
}
}
SDL_Quit();
return 0;
}