nesemu/gui/pattern_window.c

40 lines
1.4 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-12 13:07:16 -04:00
int win_width = pattern_display_get_size(PW_ROW_TILE_COUNT);
window->sdl_context = window_init("Pattern Table", win_width, win_width * 2, 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);
}