-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
317 lines (236 loc) · 9.28 KB
/
Copy pathmain.cpp
File metadata and controls
317 lines (236 loc) · 9.28 KB
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
//
// main.cpp
// SDL3Test
//
// Created by Matt Parsons on 11/02/2026.
//
#include <SDL3/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include "DMA.hpp"
#include "CPU.hpp"
#include "IDE.hpp"
#include "Drives.hpp"
#include "Gayle.hpp"
#define DISP_WIDTH 912
#define DISP_HEIGHT 312
//File handling
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char * argv[]) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == false) {
SDL_Log("SDL could not initialize! %s", SDL_GetError());
return 1;
}
SDL_Window* window = SDL_CreateWindow(
"Omega 3 - Multithreaded Version", // title
DISP_WIDTH, // width
DISP_HEIGHT*2, // height
SDL_WINDOW_RESIZABLE // flags
);
if (!window) {
SDL_Log("Window could not be created! %s", SDL_GetError());
SDL_Quit();
return 1;
}
//SDL_SetWindowMouseGrab(window, true);
//SDL_HideCursor();
SDL_SetWindowPosition(window, 0, 0);
SDL_Renderer* renderer = SDL_CreateRenderer(window, NULL);
SDL_SetRenderVSync(renderer, 1);
SDL_SetRenderLogicalPresentation(renderer, DISP_WIDTH, DISP_HEIGHT*2, SDL_LOGICAL_PRESENTATION_LETTERBOX);
SDL_Texture* amigaDisplay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_XRGB8888, SDL_TEXTUREACCESS_STREAMING, DISP_WIDTH, DISP_HEIGHT);
SDL_SetTextureScaleMode(amigaDisplay, SDL_SCALEMODE_PIXELART);
const char* romPath = nullptr;
//const char* romPath = "/Users/Shared/Kick3.rom";
const char* HDPath = nullptr;//"/Users/Shared/OmegaTestHD.hdf";
//const char* HDPath ="/Users/Shared/Connor540.hdf";
const char* df0Path = "/Users/Shared/WB-1.3.adf";
//const char* df0Path = "/Users/Shared/DLXP4.ADF"; WB-1.3.adf
//const char* df0Path = "/Users/Shared/CAST.ADF";
//const char* df0Path = "/Users/Shared/SOTB1.ADF";
//const char* df1Path = nullptr;
const char* df1Path = "/Users/Shared/CAST2.ADF";
//const char* df1Path = "/Users/Shared/SOTB2.ADF";
const char* df2Path = nullptr;
const char* df3Path = nullptr;
int CPUType = 68000;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-rom") == 0 && i + 1 < argc) {
romPath = argv[++i];
} else if (strcmp(argv[i], "-hdd") == 0 && i + 1 < argc) {
HDPath = argv[++i];
} else if (strcmp(argv[i], "-df0") == 0 && i + 1 < argc) {
df0Path = argv[++i];
} else if (strcmp(argv[i], "-df1") == 0 && i + 1 < argc) {
df1Path = argv[++i];
} else if (strcmp(argv[i], "-df2") == 0 && i + 1 < argc) {
df2Path = argv[++i];
} else if (strcmp(argv[i], "-df3") == 0 && i + 1 < argc) {
df3Path = argv[++i];
} else if (strcmp(argv[i], "-68020") == 0) {
CPUType = 68020;
}
}
uint8_t kick[524288];
//uint8_t* kick = (uint8_t*)malloc(524288);
uint8_t* romPointer = NULL;
//fd = open("/Users/Shared/rom.bin",O_RDONLY);
//fd = open("/Users/Shared/Kick13.rom",O_RDONLY);
//fd = open("/Users/Shared/DiagROM1",O_RDONLY);
//fd = open("/Users/Shared/DiagROM2",O_RDONLY);
//fd = open("/Users/Shared/DiagROM3",O_RDONLY);
//fd = open("/Users/Shared/DiagROM4",O_RDONLY);
//fd = open("/Users/Shared/ROMTestProg31.40-262.rom",O_RDONLY);
//fd = open("/Users/Shared/aros-rom.bin",O_RDONLY);
int fd = 0;
fd = open(romPath,O_RDONLY);
if(fd > 0){
int size = (int)lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
read(fd, kick, size);
if(size < 524288){
lseek(fd, 0, SEEK_SET);
read(fd, kick+262144, size);
}
// set the pointer to where it needs to be
printf("BootROM Loaded OK!\n");
close(fd);
romPointer = kick;
}
/*
//Ext ROM
uint8_t extROM[524288];
fd = open("/Users/Shared/aros-ext.bin",O_RDONLY);
if(fd > 0){
int size = (int)lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
read(fd, extROM, size);
// set the pointer to where it needs to be
printf("ExtROM Loaded OK!\n");
close(fd);
}
*/
//Setup drives
Drives floppyDrives; // main thread owns the floppy disks
if(df0Path) floppyDrives.disk[0].InsertDisk(df0Path);
if(df1Path) floppyDrives.disk[1].InsertDisk(df1Path);
if(df2Path) floppyDrives.disk[2].InsertDisk(df2Path);
if(df3Path) floppyDrives.disk[3].InsertDisk(df3Path);
InitIDE((char*)HDPath);
//InitIDE((char*)"/Users/Shared/OmegaTestHD2.hdf");
//InitIDE("/Users/Shared/Connor540.hdf");
//InitIDE("/Users/Shared/540MEG Copy.hdf");
//Agnus, Denise, Paula.
Chipset chipset;
//Gayle
Gayle gayle;
gayle.SetChipset(&chipset);
gayle.Init(2097152, 2097152, romPointer); // 524288 2097152
//ExtROM
//gayle.LoadExtROM(extROM);
//Setup the CIAs and then the Chipset
chipset.CIAA.Init(&floppyDrives);
chipset.CIAB.Init(&floppyDrives);
chipset.drives = &floppyDrives;
chipset.Init(&gayle);
IDESetCIA(&chipset.CIAA); // So the IDE Drive can flash the LED
//Start the threads
SDL_Thread* dma = SDL_CreateThread(DMAThread,"DMA", &gayle);
SDL_Delay(16);
SDL_Thread* cpu = SDL_CreateThread(CPUThread, "CPU", &gayle);
SDL_Event event;
int running = 1;
while (running) {
while (SDL_PollEvent(&event)) {
switch(event.type){
case SDL_EVENT_QUIT:
running = 0;
break;
case SDL_EVENT_KEY_UP:
//printf("^%c\n",event.key.raw);
chipset.CIAA.keyup(event.key.scancode);
break;
case SDL_EVENT_KEY_DOWN:
//printf("|%c (%d) ",event.key.key,event.key.scancode);
chipset.CIAA.keydown(event.key.scancode);
break;
}
}
//Do mouse
float dx, dy;
Uint32 button = SDL_GetRelativeMouseState(&dx, &dy);
uint16_t JOY0DAT = chipset.JOY0DAT(false, 0);
int16_t mx = (int16_t)(JOY0DAT & 0xFF);
int16_t my = (int16_t)(JOY0DAT >> 8);
mx += (int16_t)dx * 2;
my += (int16_t)dy * 2;
chipset.JOY0DAT(true , (my << 8) | (mx & 0xFF));
switch(button){
case 1:
chipset.CIAA.FIR0 = true;// left mouse button down;
break;
case 4:
chipset.potgo = chipset.potgo & 0xFBFF; // Right mouse button down;
break;
case 5:
chipset.CIAA.FIR0 = true;// Left mouse button down;
chipset.potgo = chipset.potgo & 0xFBFF;// Right mouse button down;
break;
default:
chipset.CIAA.FIR0 = false;// left mouse button up;
chipset.potgo = chipset.potgo | 0x400;// Right mouse button up;
break;
}
void* pixels;
int pitch;
const int rowSize = DISP_WIDTH * sizeof(uint32_t);
SDL_LockTexture(amigaDisplay, NULL, &pixels, &pitch);
uint8_t* s = (uint8_t*)chipset.denise.framebuffer;
uint8_t* d = (uint8_t*)pixels;
if(pitch==rowSize){
memcpy(pixels, chipset.denise.framebuffer, rowSize * DISP_HEIGHT);
}else{
//do row by row copy implement later
for(int i = 0; i < DISP_HEIGHT; ++i){
memcpy(d, s, rowSize);
s +=rowSize;
d +=pitch;
}
}
SDL_UnlockTexture(amigaDisplay);
//SDL_SetRenderDrawColor(renderer,chipset.denise.palette[0] >> 16, (chipset.denise.palette[0] >> 8) & 0xFF, (chipset.denise.palette[0]) & 0xFF, 255);
//SDL_RenderClear(renderer);
//SDL_FRect source = {0,0,DISP_WIDTH,DISP_HEIGHT};
SDL_FRect source = {200,30,DISP_WIDTH-200,DISP_HEIGHT-30};
SDL_RenderTexture(renderer, amigaDisplay, &source, NULL);
//Overlay
SDL_FRect r = {10,10,60,10};
if(chipset.CIAA.LED){
SDL_SetRenderDrawColor(renderer,0, 255, 0, 255);
}else{
SDL_SetRenderDrawColor(renderer,0, 65, 0, 255);
}
SDL_RenderFillRect(renderer, &r);
//Overlay
SDL_FRect r1 = {10,30,60,10};
if(chipset.CIAA.HDLED){ //if(chipset.CIAA.drives->motor()){
SDL_SetRenderDrawColor(renderer,0, 255, 0, 255);
}else{
SDL_SetRenderDrawColor(renderer,0, 65, 0, 255);
}
SDL_RenderFillRect(renderer, &r1);
// 2. Signal the DMA Thread that we are ready for the next frame
{
std::lock_guard<std::mutex> lock(chipset.frame_mtx);
chipset.ready_for_next_frame = true;
}
chipset.cv.notify_one();
SDL_RenderPresent(renderer);
}
SDL_DetachThread(cpu);
SDL_DetachThread(dma);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}