nesemu/gui/pattern_window.c

39 lines
1.3 KiB
C
Raw Normal View History

2024-06-16 19:22:40 -04:00
//
// Created by william on 6/14/24.
//
#include "pattern_window.h"
2024-07-21 16:41:38 -04:00
#include "dbg_pattern_table.h"
2024-06-16 19:22:40 -04:00
2024-07-21 16:41:38 -04:00
#define PW_WIDTH (PW_ROW_TILE_COUNT * PATTERN_DRAW_SIZE)
#define PW_HEIGHT (PW_WIDTH * 2)
#define PW_BUFFER_SIZE (PW_WIDTH * PW_HEIGHT)
2024-06-16 19:22:40 -04:00
2024-07-21 16:41:38 -04:00
void pattern_window_init(NesPatternWindow *window) {
2024-07-25 21:22:00 -04:00
window->sdl_context = window_init("Pattern Table", PW_WIDTH, PW_HEIGHT, PW_SCALE);
2024-06-16 19:22:40 -04:00
2024-07-21 16:41:38 -04:00
window->texture = SDL_CreateTexture(window->sdl_context.renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, PW_WIDTH, PW_HEIGHT);
2024-06-16 19:22:40 -04:00
}
void pattern_window_uninit(NesPatternWindow *window) {
2024-07-21 16:41:38 -04:00
SDL_DestroyTexture(window->texture);
2024-06-16 19:22:40 -04:00
window_uninit(window->sdl_context);
}
2024-07-12 18:52:54 -04:00
void pattern_window_build_table(NesPatternWindow *window) {
2024-07-21 16:41:38 -04:00
pixel buffer[PW_BUFFER_SIZE] = {0};
dbg_pattern_draw_bank(PATTERN_BANK_0, buffer);
dbg_pattern_draw_bank(PATTERN_BANK_1, &buffer[PW_WIDTH * (PW_HEIGHT / 2)]);
SDL_UpdateTexture(window->texture, NULL, buffer, PW_WIDTH * sizeof(pixel));
2024-06-16 19:22:40 -04:00
}
void pattern_window_render(NesPatternWindow *window) {
SDL_RenderClear(window->sdl_context.renderer);
2024-07-21 16:41:38 -04:00
SDL_RenderCopy(window->sdl_context.renderer, window->texture, NULL, NULL);
2024-06-16 19:22:40 -04:00
}
void pattern_window_present(NesPatternWindow *window) {
SDL_RenderPresent(window->sdl_context.renderer);
}