Skip to content

Commit f9a699d

Browse files
committed
Use cgia_reg_read/write functions
1 parent 46eca3b commit f9a699d

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

src/chips/cgia.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static uint64_t _cgia_tick(cgia_t* vpu, uint64_t pins) {
9595
}
9696
}
9797
else {
98-
vpu->regs[CGIA_REG_RASTER] = 0;
98+
vpu->chip[CGIA_REG_RASTER] = 0;
9999
}
100100
}
101101

@@ -774,7 +774,7 @@ void cgia_mem_wr(cgia_t* vpu, uint32_t addr, uint8_t data) {
774774
}
775775

776776
static void _copy_internal_regs(cgia_t* vpu) {
777-
vpu->regs = (uint8_t*)&CGIA;
777+
vpu->chip = (uint8_t*)&CGIA;
778778
for (int i = 0; i < CGIA_PLANES; ++i) {
779779
vpu->internal[i].memory_scan = plane_int[i].memory_scan;
780780
vpu->internal[i].colour_scan = plane_int[i].colour_scan;

src/chips/cgia.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ typedef struct {
193193

194194
uint scan_line; // currently rendered physical scan line
195195

196-
// CGIA registers
197-
uint8_t* regs;
196+
// CGIA internal registers
197+
uint8_t* chip;
198198

199199
// copy of CGIA internal registers
200200
struct cgia_internal {
@@ -249,6 +249,10 @@ void cgia_snapshot_onload(cgia_t* snapshot, cgia_t* sys);
249249
void cgia_mem_wr(cgia_t* vpu, uint32_t addr, uint8_t data);
250250
// copy VRAM - after fastload
251251
void cgia_mirror_vram(cgia_t* vpu);
252+
// read CGIA register value
253+
uint8_t cgia_reg_read(uint8_t reg_no);
254+
// write CGIA register
255+
void cgia_reg_write(uint8_t reg_no, uint8_t value);
252256

253257
#ifdef __cplusplus
254258
} // extern "C"

src/systems/x65.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ uint8_t mem_rd(x65_t* sys, uint8_t bank, uint16_t addr) {
269269
return 0xFF;
270270
}
271271
else if (addr >= 0xFF00) {
272-
return sys->cgia.regs[addr & 0x7F];
272+
return cgia_reg_read((uint8_t)addr);
273273
}
274274
}
275275
return sys->ram[(bank << 16) | addr];
@@ -285,7 +285,7 @@ void mem_wr(x65_t* sys, uint8_t bank, uint16_t addr, uint8_t data) {
285285
return;
286286
}
287287
else if (addr >= 0xFF00) {
288-
sys->cgia.regs[addr & 0x7F] = data;
288+
cgia_reg_write((uint8_t)addr, data);
289289
return;
290290
}
291291
}

src/ui/ui_cgia.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void _ui_cgia_draw_rgb(const char* label, uint32_t val) {
7373

7474
static void _ui_cgia_draw_registers(const ui_cgia_t* win) {
7575
if (ImGui::CollapsingHeader("Registers", ImGuiTreeNodeFlags_DefaultOpen)) {
76-
const fwcgia_t* chip = (fwcgia_t*)win->cgia->regs;
76+
const fwcgia_t* chip = (fwcgia_t*)win->cgia->chip;
7777
ui_util_b8("mode : ", chip->mode);
7878
ui_util_b8("planes: ", chip->planes);
7979

@@ -118,7 +118,7 @@ static void _ui_cgia_draw_raster_unit(const ui_cgia_t* win) {
118118
ImGui::Text("V Counter: %4d", win->cgia->v_count);
119119
ImGui::Text("V Period: %4d", MODE_V_TOTAL_LINES - 1);
120120
ImGui::Text("Scan Line: %4d", win->cgia->scan_line);
121-
const fwcgia_t* chip = (fwcgia_t*)win->cgia->regs;
121+
const fwcgia_t* chip = (fwcgia_t*)win->cgia->chip;
122122
ImGui::Text("Raster Line: %4d", chip->raster);
123123
}
124124
}
@@ -192,7 +192,7 @@ static void _ui_cgia_decode_BG_flags(uint8_t flags) {
192192
}
193193

194194
static void _ui_cgia_draw_bg_plane(const ui_cgia_t* win, size_t p) {
195-
fwcgia_t* chip = (fwcgia_t*)win->cgia->regs;
195+
fwcgia_t* chip = (fwcgia_t*)win->cgia->chip;
196196
ImGui::Text(
197197
"MS:%04x CS:%04x BS:%04x CG:%04x",
198198
win->cgia->internal[p].memory_scan,
@@ -250,7 +250,7 @@ static void _ui_cgia_draw_bg_plane(const ui_cgia_t* win, size_t p) {
250250
}
251251

252252
static void _ui_cgia_draw_sprite_plane(const ui_cgia_t* win, size_t p) {
253-
fwcgia_t* chip = (fwcgia_t*)win->cgia->regs;
253+
fwcgia_t* chip = (fwcgia_t*)win->cgia->chip;
254254
if (win->cgia->internal[p].sprites_need_update) {
255255
ImGui::SameLine();
256256
ImGui::Text(" Need update");
@@ -310,7 +310,7 @@ static void _ui_cgia_draw_sprite_plane(const ui_cgia_t* win, size_t p) {
310310
}
311311

312312
static void _ui_cgia_draw_planes(const ui_cgia_t* win) {
313-
fwcgia_t* chip = (fwcgia_t*)win->cgia->regs;
313+
fwcgia_t* chip = (fwcgia_t*)win->cgia->chip;
314314
for (int i = 0; i < CGIA_PLANES; i++) {
315315
ImGui::PushID(i);
316316
bool plane_active = chip->planes & (1u << i);
@@ -351,8 +351,8 @@ static void _ui_cgia_draw_beepers(const ui_cgia_t* win) {
351351
ImGui::Text(" Duty: %.1f%% (%02x)", (float)cgia->pwm[i].duty * 100.0 / 255.0, cgia->pwm[i].duty);
352352
ImGui::Text(
353353
" Freq: %4dHz",
354-
(uint16_t)((uint16_t)(cgia->regs[i ? CGIA_REG_PWM_1_FREQ : CGIA_REG_PWM_0_FREQ])
355-
| ((uint16_t)(cgia->regs[(i ? CGIA_REG_PWM_1_FREQ : CGIA_REG_PWM_0_FREQ) + 1]) << 8)));
354+
(uint16_t)((uint16_t)(cgia->chip[i ? CGIA_REG_PWM_1_FREQ : CGIA_REG_PWM_0_FREQ])
355+
| ((uint16_t)(cgia->chip[(i ? CGIA_REG_PWM_1_FREQ : CGIA_REG_PWM_0_FREQ) + 1]) << 8)));
356356
}
357357
}
358358
}

0 commit comments

Comments
 (0)