Add palette switch to the debug pattern view.
This commit is contained in:
parent
81451b24ad
commit
0066e77455
|
@ -8,6 +8,10 @@ only tested on Linux. Here is how to run the project:
|
|||
- Build the project with Make: ```make```
|
||||
- Run the emulator: ```./nes_emulator```
|
||||
|
||||
## Controls
|
||||
- `p`: Pauses the emulation
|
||||
- `o`: Go to the next palette in the pattern viewer
|
||||
|
||||
## Dependencies
|
||||
- GCC compiler
|
||||
- CMake
|
||||
|
|
|
@ -93,7 +93,7 @@ void dbg_pattern_draw_pos(int x, int y, int bank, pixel *buffer, int buffer_widt
|
|||
dbg_pattern_draw_pattern(pattern, buffer, buffer_width, palette);
|
||||
}
|
||||
|
||||
void dbg_pattern_draw_bank(int bank, pixel *buffer) {
|
||||
void dbg_pattern_draw_bank(int bank, pixel *buffer, int palette) {
|
||||
int buffer_width = PATTERN_TABLE_WIDTH * PATTERN_DRAW_SIZE;
|
||||
|
||||
for (int x = 0; x < PATTERN_TABLE_WIDTH; x++) {
|
||||
|
@ -101,7 +101,7 @@ void dbg_pattern_draw_bank(int bank, pixel *buffer) {
|
|||
address row_addr = (y * PATTERN_DRAW_SIZE) * buffer_width;
|
||||
address tile_addr = row_addr + (x * PATTERN_DRAW_SIZE);
|
||||
|
||||
dbg_pattern_draw_pos(x, y, bank, &buffer[tile_addr], buffer_width, 01);
|
||||
dbg_pattern_draw_pos(x, y, bank, &buffer[tile_addr], buffer_width, palette);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -78,7 +78,8 @@ void dbg_pattern_draw_pos(int x, int y, int bank, pixel *buffer, int buffer_widt
|
|||
* Draws a pattern bank to a buffer. Uses the palette #0.
|
||||
* @param bank The bank to draw (0 -> 0x0000, 1 -> 0x1000)
|
||||
* @param buffer The buffer to write the patterns data to.
|
||||
* @param palette The background palette to use
|
||||
*/
|
||||
void dbg_pattern_draw_bank(int bank, pixel *buffer);
|
||||
void dbg_pattern_draw_bank(int bank, pixel *buffer, int palette);
|
||||
|
||||
#endif //NES_EMULATOR_DBG_PATTERN_TABLE_H
|
||||
|
|
|
@ -70,6 +70,7 @@ void gui_post_sysinit() {
|
|||
dbg_pattern_table_init();
|
||||
dbg_nametable_init();
|
||||
|
||||
// TODO: The texture is rendered before the palette data is in the PPU memory, so the only color is grey
|
||||
pattern_window_build_table(&gui.pattern_window);
|
||||
nametable_window_update(&gui.nametable_window);
|
||||
#endif
|
||||
|
@ -83,8 +84,14 @@ int gui_input() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_p) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
if (event.key.keysym.sym == SDLK_p) {
|
||||
system_toggle_pause();
|
||||
} else {
|
||||
#if DEBUG
|
||||
pattern_window_key_up(&gui.pattern_window, event.key.keysym.sym);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "window.h"
|
||||
#include "../include/types.h"
|
||||
|
||||
#define NW_SCALE 2
|
||||
#define NW_SCALE 1
|
||||
#define NW_ROW_COUNT 60
|
||||
#define NW_ROW_TILE_COUNT 64
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ void pattern_window_init(NesPatternWindow *window) {
|
|||
|
||||
window->texture = SDL_CreateTexture(window->sdl_context.renderer, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STATIC, PW_WIDTH, PW_HEIGHT);
|
||||
window->palette = 0;
|
||||
}
|
||||
|
||||
void pattern_window_uninit(NesPatternWindow *window) {
|
||||
|
@ -23,12 +24,25 @@ void pattern_window_uninit(NesPatternWindow *window) {
|
|||
|
||||
void pattern_window_build_table(NesPatternWindow *window) {
|
||||
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)]);
|
||||
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(NesPatternWindow *window, SDL_KeyCode keycode) {
|
||||
if (keycode != SDLK_o) {
|
||||
return;
|
||||
}
|
||||
|
||||
window->palette++;
|
||||
if (window->palette > PW_PALETTE_MAX) {
|
||||
window->palette = 0;
|
||||
}
|
||||
|
||||
pattern_window_build_table(window);
|
||||
}
|
||||
|
||||
void pattern_window_render(NesPatternWindow *window) {
|
||||
SDL_RenderClear(window->sdl_context.renderer);
|
||||
SDL_RenderCopy(window->sdl_context.renderer, window->texture, NULL, NULL);
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
|
||||
#define PW_SCALE 2
|
||||
#define PW_ROW_TILE_COUNT 16
|
||||
#define PW_PALETTE_MAX 3
|
||||
|
||||
typedef struct nes_pattern_window {
|
||||
NesSdlContext sdl_context;
|
||||
SDL_Texture *texture;
|
||||
byte palette;
|
||||
} NesPatternWindow;
|
||||
|
||||
void pattern_window_init(NesPatternWindow *window);
|
||||
|
@ -21,6 +23,7 @@ void pattern_window_uninit(NesPatternWindow *window);
|
|||
|
||||
void pattern_window_build_table(NesPatternWindow *window);
|
||||
|
||||
void pattern_window_key_up(NesPatternWindow *window, SDL_KeyCode keycode);
|
||||
void pattern_window_render(NesPatternWindow *window);
|
||||
void pattern_window_present(NesPatternWindow *window);
|
||||
|
||||
|
|
Loading…
Reference in New Issue