-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU.cpp
More file actions
185 lines (119 loc) · 5.2 KB
/
Copy pathCPU.cpp
File metadata and controls
185 lines (119 loc) · 5.2 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
//
// CPU.cpp
// SDL3Test
//
// Created by Matt Parsons on 06/03/2026.
//
#include "CPU.hpp"
#include "m68k.h"
#include "Gayle.hpp"
static Gayle* gayle;
// Fast RAM range — accessed directly without DMA sync, same as chip RAM.
#define IS_FASTRAM(addr) ((addr) >= 0x200000 && (addr) < 0xA00000)
#define IS_CHIPFULL(addr)( (addr > 0x3FF && addr < 0x200000) || (addr > 0xDFEFFF && addr < 0xE00000) ) // only use if there are serious timing issues.
#define IS_CHIP(addr)( (addr > 0x3FF && addr < 0x200000) || (addr > 0xDFF01E && addr < 0xE00000) ) // doesn't protect the read only chipset registers.
unsigned int cpu_read_byte(unsigned int address){
if(IS_CHIP(address)){
return gayle->SyncRead8(address);
}
return gayle->Read8(address);
}
unsigned int cpu_read_word(unsigned int address){
if(IS_CHIP(address)){
return gayle->SyncRead16(address);
}
return gayle->Read16(address);
}
unsigned int cpu_read_long(unsigned int address){
if(IS_CHIP(address)){
return gayle->SyncRead32(address);
}
return gayle->Read32(address);
}
void cpu_write_byte(unsigned int address, unsigned int value){
if(IS_CHIP(address)){
gayle->SyncWrite8(address, value);
return;
}
gayle->Write8(address, value);
return;
}
void cpu_write_word(unsigned int address, unsigned int value){
if(IS_CHIP(address)){
gayle->SyncWrite16(address, value);
return;
}
gayle->Write16(address, value);
return;
}
void cpu_write_long(unsigned int address, unsigned int value){
if(IS_CHIP(address)){
gayle->SyncWrite32(address, value);
return;
}
gayle->Write32(address, value);
return;
}
void cpu_pulse_reset(void){
m68k_pulse_reset(); //This MUST be called
//Any custom setup we might neet later
gayle->Reset();
}
void cpu_set_fc(unsigned int fc){
}
int cpu_irq_ack(int level){
return M68K_INT_ACK_AUTOVECTOR;
}
unsigned int cpu_read_word_dasm(unsigned int address){
return cpu_read_word(address);
}
unsigned int cpu_read_long_dasm(unsigned int address){
return cpu_read_long(address);
}
#include "SDL3/SDL.h"
int CPUThread(void* data){
int fileOut = 0;
FILE* fptr = NULL;
if(fileOut){
// 1. Open the file for writing ("w")
fptr = fopen("/Users/Shared/AlphaOmegaLog.txt", "w");
// 2. Error check
if (fptr == NULL) {
perror("Error opening Log file");
return 1;
}
// 3. Use fprintf just like printf
//int age = 25;
//fprintf(fptr, "User age: %d\n", age);
//fprintf(fptr, "Hello, this is written to a file!\n");
// 4. Close the file
//fclose(fptr);
}
gayle = (Gayle*)data;
m68k_init();
m68k_set_cpu_type(M68K_CPU_TYPE_68020); //Pretend to be an A500 for now...
cpu_pulse_reset();
uint64_t cycles = 0;
char buffer[100];
int dis = 0;
//gayle->Write32(0x4, 0xF80000);
//m68k_set_reg(M68K_REG_PC, 0xF80000);
while(1){
m68k_execute(1500);
//SDL_DelayNS(280);
cycles++;
gayle->chipset->CheckInterrupt();
if(dis){
unsigned int pc = m68k_get_reg(NULL, M68K_REG_PC);
m68k_disassemble(buffer, pc, M68K_CPU_TYPE_68000);
if(fileOut){
// fprintf(fptr,"D0: 0x%x | D1: 0x%x | D2: 0x%x | D3: 0x%x | D4: 0x%x | D5: 0x%x | D6: 0x%x | D7: 0x%x | A0: 0x%x | A1: 0x%x | A2: 0x%x | A3: 0x%x | A4: 0x%x | A5: 0x%x | A6: 0x%x | A7: 0x%x | SR: 0x%x\n", m68k_get_reg(NULL,M68K_REG_D0), m68k_get_reg(NULL,M68K_REG_D1), m68k_get_reg(NULL,M68K_REG_D2), m68k_get_reg(NULL,M68K_REG_D3), m68k_get_reg(NULL,M68K_REG_D4), m68k_get_reg(NULL,M68K_REG_D5), m68k_get_reg(NULL,M68K_REG_D6), m68k_get_reg(NULL,M68K_REG_D7), m68k_get_reg(NULL,M68K_REG_A0), m68k_get_reg(NULL,M68K_REG_A1), m68k_get_reg(NULL,M68K_REG_A2), m68k_get_reg(NULL,M68K_REG_A3), m68k_get_reg(NULL,M68K_REG_A4), m68k_get_reg(NULL,M68K_REG_A5), m68k_get_reg(NULL,M68K_REG_A6), m68k_get_reg(NULL,M68K_REG_A7),m68k_get_reg(NULL,M68K_REG_SR));
fprintf(fptr,"%08X: %s \n\n", pc, buffer);
}else{
printf("D0: 0x%x | D1: 0x%x | D2: 0x%x | D3: 0x%x | D4: 0x%x | D5: 0x%x | D6: 0x%x | D7: 0x%x | A0: 0x%x | A1: 0x%x | A2: 0x%x | A3: 0x%x | A4: 0x%x | A5: 0x%x | A6: 0x%x | A7: 0x%x | SR: 0x%x\n", m68k_get_reg(NULL,M68K_REG_D0), m68k_get_reg(NULL,M68K_REG_D1), m68k_get_reg(NULL,M68K_REG_D2), m68k_get_reg(NULL,M68K_REG_D3), m68k_get_reg(NULL,M68K_REG_D4), m68k_get_reg(NULL,M68K_REG_D5), m68k_get_reg(NULL,M68K_REG_D6), m68k_get_reg(NULL,M68K_REG_D7), m68k_get_reg(NULL,M68K_REG_A0), m68k_get_reg(NULL,M68K_REG_A1), m68k_get_reg(NULL,M68K_REG_A2), m68k_get_reg(NULL,M68K_REG_A3), m68k_get_reg(NULL,M68K_REG_A4), m68k_get_reg(NULL,M68K_REG_A5), m68k_get_reg(NULL,M68K_REG_A6), m68k_get_reg(NULL,M68K_REG_A7),m68k_get_reg(NULL,M68K_REG_SR));
printf("%08X: %s \n\n", pc, buffer);
}
}
}
return 0;
}