59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
//
|
|
// Created by william on 6/14/24.
|
|
//
|
|
|
|
#include "pattern_window.h"
|
|
#include "dbg_pattern_table.h"
|
|
#include "dbg_palette.h"
|
|
|
|
#define PW_WIDTH (PW_ROW_TILE_COUNT * PATTERN_DRAW_SIZE)
|
|
#define PW_HEIGHT (PW_WIDTH * 2)
|
|
#define PW_BUFFER_SIZE (PW_WIDTH * PW_HEIGHT)
|
|
|
|
PatternWindow *pattern_window_create(int *window_id) {
|
|
PatternWindow *window = malloc(sizeof(PatternWindow));
|
|
|
|
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;
|
|
}
|
|
|
|
void pattern_window_destroy(PatternWindow *window) {
|
|
SDL_DestroyTexture(window->texture);
|
|
window_destroy(&window->window);
|
|
|
|
free(window);
|
|
}
|
|
|
|
void pattern_window_update(PatternWindow *window) {
|
|
dbg_palette_update();
|
|
|
|
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);
|
|
|
|
SDL_UpdateTexture(window->texture, NULL, buffer, PW_WIDTH * sizeof(pixel));
|
|
}
|
|
|
|
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) {
|
|
window_render_texture(&window->window, window->texture);
|
|
window_present(&window->window);
|
|
} |