2024-07-12 13:07:16 -04:00
|
|
|
//
|
|
|
|
// Created by william on 12/07/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nametable_window.h"
|
2024-07-23 20:46:13 -04:00
|
|
|
#include "dbg_nametable.h"
|
2024-07-12 13:07:16 -04:00
|
|
|
|
2024-07-23 18:50:11 -04:00
|
|
|
#define NW_WIDTH (NW_ROW_TILE_COUNT * PATTERN_DRAW_SIZE)
|
|
|
|
#define NW_HEIGHT (NW_ROW_COUNT * PATTERN_DRAW_SIZE)
|
2024-07-23 20:46:13 -04:00
|
|
|
#define NW_BUFFER_SIZE (NAMETABLE_ROW_WIDTH * NAMETABLE_COL_HEIGHT * PATTERN_DRAW_SIZE * PATTERN_DRAW_SIZE)
|
2024-07-12 18:52:54 -04:00
|
|
|
|
2024-07-21 16:41:38 -04:00
|
|
|
void nametable_window_init(NesNametableWindow *window) {
|
2024-09-01 15:54:41 -04:00
|
|
|
window->window = window_create("Nametable", NW_WIDTH, NW_HEIGHT, NW_SCALE);
|
|
|
|
window->texture = window_create_texture(&window->window, SDL_TEXTUREACCESS_STREAMING);
|
2024-07-12 13:07:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nametable_window_uninit(NesNametableWindow *window) {
|
2024-07-23 18:50:11 -04:00
|
|
|
SDL_DestroyTexture(window->texture);
|
2024-09-01 15:54:41 -04:00
|
|
|
window_destroy(&window->window);
|
2024-07-12 13:07:16 -04:00
|
|
|
}
|
|
|
|
|
2024-07-25 21:22:00 -04:00
|
|
|
void nametable_window_update_bank(NesNametableWindow *window, int bank, pixel *buffer) {
|
2024-07-23 20:46:13 -04:00
|
|
|
dbg_nametable_render_bank(bank, buffer);
|
|
|
|
|
|
|
|
SDL_Rect rect;
|
|
|
|
rect.w = NAMETABLE_ROW_WIDTH * PATTERN_DRAW_SIZE;
|
|
|
|
rect.h = NAMETABLE_COL_HEIGHT * PATTERN_DRAW_SIZE;
|
|
|
|
rect.x = (bank & 1) * rect.w;
|
|
|
|
rect.y = ((bank & 2) >> 1) * rect.h;
|
|
|
|
|
|
|
|
SDL_UpdateTexture(window->texture, &rect, buffer, (NW_WIDTH / 2) * sizeof(pixel));
|
|
|
|
}
|
|
|
|
|
|
|
|
void nametable_window_update(NesNametableWindow *window) {
|
|
|
|
dbg_nametable_update();
|
|
|
|
|
|
|
|
pixel buffer[NW_BUFFER_SIZE * 4] = {0};
|
|
|
|
nametable_window_update_bank(window, 0, buffer);
|
|
|
|
nametable_window_update_bank(window, 1, buffer);
|
|
|
|
nametable_window_update_bank(window, 2, buffer);
|
|
|
|
nametable_window_update_bank(window, 3, buffer);
|
2024-07-12 13:07:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nametable_window_render(NesNametableWindow *window) {
|
2024-09-01 15:54:41 -04:00
|
|
|
window_render_texture(&window->window, window->texture);
|
2024-07-12 13:07:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nametable_window_present(NesNametableWindow *window) {
|
2024-09-01 15:54:41 -04:00
|
|
|
window_present(&window->window);
|
2024-07-12 13:07:16 -04:00
|
|
|
}
|