nesemu/gui/pattern_window.c

59 lines
1.6 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"
#include "dbg_palette.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
PatternWindow *pattern_window_create(int *window_id) {
PatternWindow *window = malloc(sizeof(PatternWindow));
2024-09-01 15:54:41 -04:00
window->window = window_create("Pattern Table", PW_WIDTH, PW_HEIGHT, PW_SCALE);
window->texture = window_create_texture(&window->window, SDL_TEXTUREACCESS_STATIC);
window->palette = 0;
dbg_pattern_table_init();
*window_id = window->window.id;
return window;
2024-06-16 19:22:40 -04:00
}
void pattern_window_destroy(PatternWindow *window) {
2024-07-21 16:41:38 -04:00
SDL_DestroyTexture(window->texture);
2024-09-01 15:54:41 -04:00
window_destroy(&window->window);
free(window);
2024-06-16 19:22:40 -04:00
}
void pattern_window_update(PatternWindow *window) {
dbg_palette_update();
2024-07-21 16:41:38 -04:00
pixel buffer[PW_BUFFER_SIZE] = {0};
dbg_pattern_draw_bank(PATTERN_BANK_0, buffer, window->palette);
dbg_pattern_draw_bank(PATTERN_BANK_1, &buffer[PW_WIDTH * (PW_HEIGHT / 2)], window->palette);
2024-07-21 16:41:38 -04:00
SDL_UpdateTexture(window->texture, NULL, buffer, PW_WIDTH * sizeof(pixel));
2024-06-16 19:22:40 -04:00
}
void pattern_window_key_up(PatternWindow *window, SDL_KeyCode keycode) {
if (keycode != SDLK_o) {
return;
}
window->palette++;
if (window->palette > PW_PALETTE_MAX) {
window->palette = 0;
}
pattern_window_update(window);
}
void pattern_window_render(PatternWindow *window) {
2024-09-01 15:54:41 -04:00
window_render_texture(&window->window, window->texture);
window_present(&window->window);
2024-06-16 19:22:40 -04:00
}