Finish ppu, and mbc1 mapping

This commit is contained in:
2025-02-01 19:05:25 -07:00
parent 2603916972
commit 89a99b160d
17 changed files with 779 additions and 18 deletions

View File

@ -1,5 +1,7 @@
#include <ui.h>
#include <emu.h>
#include <ppu.h>
#include <gamepad.h>
#include <SDL.h>
#include <SDL_ttf.h>
@ -23,6 +25,19 @@ void ui_init(){
printf("TTF INIT\n");
SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &sdlWindow, &sdlRenderer);
screen = SDL_CreateRGBSurface(0, SCREEN_WIDTH,
SCREEN_HEIGHT, 32,
0x00FF0000,
0x0000FF00,
0x000000FF,
0xFF000000);
sdlTexture = SDL_CreateTexture(sdlRenderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
SCREEN_WIDTH,
SCREEN_HEIGHT);
SDL_CreateWindowAndRenderer(16 * 8 * scale, 32 * 8 * scale, 0, &sdlDebugWindow, &sdlDebugRenderer);
debugScreen = SDL_CreateRGBSurface(0, (16 * 8 * scale) + (16 * scale),
(32 * 8 * scale) + (64 * scale), 32,
@ -95,15 +110,73 @@ void update_debug_window() {
}
void ui_update() {
SDL_Rect rc;
rc.x = rc.y = 0;
rc.w = rc.h = 2048;
u32 *video_buffer = ppu_get_context()->video_buffer;
for(int line_num = 0; line_num < YRES; line_num++) {
for(int x = 0; x < XRES; x++) {
rc.x = x * scale;
rc.y = line_num * scale;
rc.w = scale;
rc.h = scale;
SDL_FillRect(screen, &rc, video_buffer[x + (line_num * XRES)]);
}
}
SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(sdlRenderer);
update_debug_window();
}
static bool ff = false;
void ui_on_key(bool down, u32 key_code) {
if(key_code == SDLK_SPACE && down == true) {
ff = !ff;
if(ff){
target_frame_time = 1000/300;
} else {
target_frame_time = 1000/60;
}
printf("target frame time: %d\n", target_frame_time);
}
switch(key_code){
case SDLK_z: gamepad_get_state()->b = down; break;
case SDLK_x: gamepad_get_state()->a = down; break;
case SDLK_RETURN: gamepad_get_state()->start = down; break;
case SDLK_TAB: gamepad_get_state()->select = down; break;
case SDLK_UP: gamepad_get_state()->up = down; break;
case SDLK_DOWN: gamepad_get_state()->down = down; break;
case SDLK_LEFT: gamepad_get_state()->left = down; break;
case SDLK_RIGHT: gamepad_get_state()->right = down; break;
}
}
void ui_handle_events(){
SDL_Event e;
while(SDL_PollEvent(&e) > 0) {
if(e.type == SDL_KEYDOWN) {
ui_on_key(true, e.key.keysym.sym);
}
if(e.type == SDL_KEYUP) {
ui_on_key(false, e.key.keysym.sym);
}
if(e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_CLOSE) {
emu_get_context()->die = true;
}
}
}