-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopper.cpp
More file actions
210 lines (160 loc) · 5.28 KB
/
Copy pathCopper.cpp
File metadata and controls
210 lines (160 loc) · 5.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
//
// Copper.cpp
// SDL3Test
//
// Created by Matt Parsons on 16/02/2026.
//
#include "Copper.hpp"
//#include "Bus.hpp"
#include "Gayle.hpp"
// Register handler
uint16_t Copper::COPCON(bool isWrite, uint16_t value){
if(isWrite){
cdang = value & 0x2;
return 0;
}
return cdang ? 0x2 : 0x0;
}
uint16_t Copper::COP1LCH(bool isWrite, uint16_t value){
if(isWrite){
cop1lc = (cop1lc & 0x0000FFFF) | (value << 16);
return 0;
}
return cop1lc >> 16;
}
uint16_t Copper::COP1LCL(bool isWrite, uint16_t value){
if(isWrite){
cop1lc = (cop1lc & 0xFFFF0000) | value;
return 0;
}
return cop1lc & 0xFFFF;
}
uint16_t Copper::COP2LCH(bool isWrite, uint16_t value){
if(isWrite){ cop2lc = (cop2lc & 0x0000FFFF) | (value << 16); return 0; }
return cop2lc >> 16;
}
uint16_t Copper::COP2LCL(bool isWrite, uint16_t value){
if(isWrite){ cop2lc = (cop2lc & 0xFFFF0000) | value; return 0; }
return cop2lc & 0xFFFF;
}
uint16_t Copper::COPJMP1(bool isWrite, uint16_t value){
Reset(1);
return 0;
}
uint16_t Copper::COPJMP2(bool isWrite, uint16_t value){
Reset(2);
return 0;
}
void Copper::Init(void* bus){
this->bus = bus;
cop1lc = 0;
cop2lc = 0;
pc = 0;
state = 0;
halted = true;
}
void Copper::Reset(int list){
pc = (list == 1) ? cop1lc : cop2lc;
halted = false;
state = 0;
}
bool Copper::isMove(){ return !(ir1 & 0x0001); }
bool Copper::isWait(){ return (ir1 & 0x0001) && !(ir2 & 0x0001); }
bool Copper::isSkip(){ return (ir1 & 0x0001) && (ir2 & 0x0001); }
bool Copper::waitMet(){
/*
uint8_t vp = (ir1 >> 8) & 0xFF;
uint8_t hp = (ir1 & 0xFE);
uint8_t ve = (ir2 >> 8) | 0x80; // vertical enable, bit 7 always set
uint8_t he = (ir2 & 0xFE);
uint16_t vhpos = ((Gayle*)bus)->chipset->denise.VHPOSR(false, 0);
uint8_t vb = vhpos >> 8;
uint8_t hb = vhpos & 0xFE;
return ((vb & ve) > (vp & ve)) || ((vb & ve) == (vp & ve) && (hb & he) >= (hp & he)); // ((vb & ve) > (vp & ve)) || ((vb & ve) == (vp & ve) && (hb & he) >= (hp & he));
*/
/*
int vp = (ir1 >> 8) & 0xFF;
int hp = (ir1 & 0xFF);
int ve = (ir2 >> 8);// | 0x80; // vertical enable, bit 7 always set
int he = (ir2 & 0xFF);
int vb = ((Gayle*)bus)->chipset->denise.Hline & 0xFF;
int hb = ((Gayle*)bus)->chipset->denise.ColorClock;
return ((vb & ve) > (vp & ve)) || ((vb & ve) == (vp & ve) && (hb & he) > (hp & he));// ((vb & ve) > (vp & ve)) || ((vb & ve) == (vp & ve) && (hb & he) >= (hp & he));
*/
vhpos &= ir2;
uint16_t v = (ir1 & ir2);
if(vhpos >= v){
return true;
}
return false;
}
bool Copper::Execute(){
if( !(((Gayle*)bus)->chipset->dmacon & 0x280) ){
return false;
}
// Don't do anything if halted - wait for COPJMP to reset us
if(halted){
return false;
}
vhpos = ((Gayle*)bus)->chipset->denise.VHPOSR(false, 0);
switch(state){
case 0:
ir1 = ((Gayle*)bus)->chipram->Read16(pc);
pc += 2;
state = 1;
return true;
case 1:
ir2 = ((Gayle*)bus)->chipram->Read16(pc);
pc += 2;
// On real hardware, MOVE executes during the IR2 fetch cycle
if(isMove()){
int reg = (ir1 & 0x1FE);
// Copper cannot write to registers below 0x40
// unless the danger bit (CDANG) in COPCON is set
if(reg < 0x80 && !cdang){
halted = true;
return true;
}
((Gayle*)bus)->chipset->Registers[reg >> 1](true,ir2);
state = 0; // No idle cycle after MOVE
return true;
}
state = 2; // WAIT/SKIP needs decode
return true;
case 2:
if(isWait()){
// WAIT for $FFFF,$FFFE is the standard end-of-list marker
// and will never be satisfied - halt the copper
if(ir1 == 0xFFFF && ir2 == 0xFFFE){
halted = true;
return false;
}
state = 3; //always one extra cycle
}else if(isSkip()){
if(waitMet()){
pc += 4;
}
state = 4;
}
return false;
case 3:
if(vhpos > ir1){
state = 4;
// printf("Wait Met sinple\n");
return false;
}
//printf("Line %d, Clock %d: Request Wait for: %d, %d\n", vhpos >> 8, ((Gayle*)bus)->chipset->denise.ColorClock,ir1 >> 8, ir1 & 0xFF);
if(waitMet()){
// printf("Wait MEt old\n");
state = 4;
return false;
}
// printf("Line %d, Clock %d: Waiting for: %d, %d\n", vhpos >> 8, ((Gayle*)bus)->chipset->denise.ColorClock,ir1 >> 8, ir1 & 0xFF);
return false;
case 4:
//Copper needs an idle cycle after the Wait completes
state = 0;
return false;
}
return false;
}