2024-05-01 12:58:15 -04:00
|
|
|
//
|
|
|
|
// Created by william on 5/1/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "ppu_view.h"
|
|
|
|
|
|
|
|
void ppv_print_line(PpuView *view, byte reg, int line, char *fmt) {
|
2024-05-06 20:23:44 -04:00
|
|
|
int reg_value = ppu_get_state()->registers[reg];
|
2024-05-01 12:58:15 -04:00
|
|
|
window_print(view->window, 0, line, fmt);
|
|
|
|
|
|
|
|
for (int i = 0; i < 0x8; i++) {
|
|
|
|
byte mask = 0x80 >> i;
|
|
|
|
byte bit = (reg_value & mask) >> (8 - i - 1);
|
|
|
|
|
|
|
|
int print_offset = 10 + i;
|
|
|
|
if (i > 3) {
|
|
|
|
print_offset += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_print(view->window, print_offset, line, "%d", bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ppv_print(PpuView *view) {
|
|
|
|
ppv_print_line(view, PPU_REGISTER_CTRL, 0, " CTRL:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_MASK, 1, " MASK:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_STATUS, 2, " STATUS:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_OAM_ADDR, 3, "OAM_ADDR:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_OAM_DATA, 4, "OAM_DATA:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_SCROLL, 5, " SCROLL:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_ADDR, 6, " ADDR:");
|
|
|
|
ppv_print_line(view, PPU_REGISTER_DATA, 7, " DATA:");
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:23:44 -04:00
|
|
|
PpuView *ppv_init(int x, int y) {
|
2024-05-01 12:58:15 -04:00
|
|
|
PpuView *view = malloc(sizeof(PpuView));
|
|
|
|
view->window = malloc(sizeof(Window));
|
|
|
|
|
|
|
|
window_init(view->window, x, y, PPU_VIEW_WIDTH, PPU_VIEW_HEIGHT, "PPU VIEW");
|
|
|
|
ppv_print(view);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ppv_uninit(PpuView *view) {
|
|
|
|
free(view->window);
|
|
|
|
free(view);
|
|
|
|
}
|