Skip to content

Commit

Permalink
Fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
allkern committed Mar 20, 2024
1 parent 8a5aaf0 commit ce32c2f
Show file tree
Hide file tree
Showing 26 changed files with 810 additions and 302 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ snap/
*.zip
*.cue
*.iso
*.mcd
*.mcd
*.rom
12 changes: 9 additions & 3 deletions frontend/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void psxe_cfg_destroy(psxe_config_t* cfg) {
}

void psxe_cfg_load_defaults(psxe_config_t* cfg) {
cfg->bios = NULL;
cfg->bios = "bios.bin";
cfg->bios_search = "bios";
cfg->exe = NULL;
cfg->help_model = 0;
Expand All @@ -91,6 +91,7 @@ void psxe_cfg_load_defaults(psxe_config_t* cfg) {
cfg->log_level = LOG_FATAL;
cfg->quiet = 0;
cfg->cd_path = NULL;
cfg->exp_path = NULL;
}

void psxe_cfg_load(psxe_config_t* cfg, int argc, const char* argv[]) {
Expand All @@ -111,6 +112,7 @@ void psxe_cfg_load(psxe_config_t* cfg, int argc, const char* argv[]) {
const char* region = NULL;
const char* psxe_version = NULL;
const char* cd_path = NULL;
const char* exp_path = NULL;

static const char *const usages[] = {
"psxe [options] path-to-cdrom",
Expand All @@ -124,15 +126,16 @@ void psxe_cfg_load(psxe_config_t* cfg, int argc, const char* argv[]) {
OPT_BOOLEAN ('v', "version" , &version , "Display version and build information", NULL, 0, 0),
OPT_GROUP("Basic options"),
OPT_BOOLEAN ('a', "use-args" , &use_args , "Ignore settings file, use CLI args instead", NULL, 0, 0),
OPT_STRING ('b', "bios" , &bios , "Use this BIOS file (ignores -B, -M)", NULL, 0, 0),
OPT_STRING ('b', "bios" , &bios , "Specify a BIOS file (ignores -B, -M)", NULL, 0, 0),
OPT_BOOLEAN ('B', "bios-folder" , &bios_search , "Specify a BIOS search folder", NULL, 0, 0),
OPT_STRING ('c', "console-source", &console_source, "Select console source (auto, null, kernel, atcons)"),
OPT_STRING ('e', "exp-rom" , &exp_path , "Specify an expansion ROM file"),
OPT_INTEGER ('L', "log-level" , &log_level , "Set log level"),
OPT_STRING ('M', "model" , &model , "Specify console model (SPCH-XXXX)", NULL, 0, 0),
OPT_STRING ('r', "region" , &region , "Specify console region"),
OPT_STRING ('S', "settings-file" , &settings_path , "Specify settings file path", NULL, 0, 0),
OPT_BOOLEAN ('q', "quiet" , &quiet , "Silence all logs (ignores -L)"),
OPT_STRING ('x', "exe" , &exe , "Boot this PS-X EXE file"),
OPT_STRING ('x', "exe" , &exe , "Launch a PS-X EXE file"),
OPT_STRING (0 , "cdrom" , &cd_path , "Specify a CDROM image"),
OPT_END()
};
Expand Down Expand Up @@ -274,6 +277,9 @@ void psxe_cfg_load(psxe_config_t* cfg, int argc, const char* argv[]) {

if (psxe_version)
cfg->psxe_version = psxe_version;

if (exp_path)
cfg->exp_path = exp_path;
}

// To-do: Implement BIOS searching
Expand Down
1 change: 1 addition & 0 deletions frontend/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct {
const char* region;
const char* psxe_version;
const char* cd_path;
const char* exp_path;
} psxe_config_t;

psxe_config_t* psxe_cfg_create();
Expand Down
2 changes: 1 addition & 1 deletion frontend/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main(int argc, const char* argv[]) {
log_set_level(cfg->log_level);

psx_t* psx = psx_create();
psx_init(psx, cfg->bios);
psx_init(psx, cfg->bios, cfg->exp_path);

psx_cdrom_t* cdrom = psx_get_cdrom(psx);

Expand Down
56 changes: 40 additions & 16 deletions frontend/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ void psxe_screen_init(psxe_screen_t* screen, psx_t* psx) {
screen->texture_height = PSX_GPU_FB_HEIGHT;

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "0");
SDL_SetRenderDrawColor(screen->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
}

void psxe_screen_reload(psxe_screen_t* screen) {
SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "0");

if (screen->texture) SDL_DestroyTexture(screen->texture);
if (screen->renderer) SDL_DestroyRenderer(screen->renderer);
if (screen->window) SDL_DestroyWindow(screen->window);
Expand All @@ -81,7 +78,7 @@ void psxe_screen_reload(psxe_screen_t* screen) {
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
screen->width * screen->scale,
screen->height * screen->scale,
SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI
0
);

screen->renderer = SDL_CreateRenderer(
Expand All @@ -90,13 +87,17 @@ void psxe_screen_reload(psxe_screen_t* screen) {
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
);

SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "linear"),

screen->texture = SDL_CreateTexture(
screen->renderer,
screen->format,
SDL_TEXTUREACCESS_STREAMING,
screen->texture_width, screen->texture_height
);

SDL_SetTextureScaleMode(screen->texture, screen->bilinear);

// Check for retina displays
int width = 0, height = 0;

Expand Down Expand Up @@ -130,19 +131,23 @@ void psxe_screen_toggle_debug_mode(psxe_screen_t* screen) {
}

void psxe_screen_update(psxe_screen_t* screen) {
void* display_buf = screen->debug_mode ?
psx_get_vram(screen->psx) : psx_get_display_buffer(screen->psx);
// void* vram = psx_get_vram(screen->psx);

// // Update texture with Lock/UnlockTexture
// int pitch;
// uint8_t* ptr = NULL;
// if (screen->field & 2) {
// for (int y = screen->field & 1; y < 512; y += 2) {
// memcpy(
// ((uint8_t*)screen->buf) + (y * PSX_GPU_FB_STRIDE),
// ((uint8_t*)vram) + (y * PSX_GPU_FB_STRIDE),
// PSX_GPU_FB_STRIDE
// );
// }
// }

// SDL_LockTexture(screen->texture, NULL, &ptr, &pitch);
// screen->field += 1;
// screen->field &= 3;

// for (int y = 0; y < screen->texture_height; y++)
// memcpy(ptr + (y * pitch), display_buf + (y * PSX_GPU_FB_STRIDE), pitch);

// SDL_UnlockTexture(screen->texture);
void* display_buf = screen->debug_mode ?
psx_get_vram(screen->psx) : psx_get_display_buffer(screen->psx);

SDL_UpdateTexture(screen->texture, NULL, display_buf, PSX_GPU_FB_STRIDE);
SDL_RenderClear(screen->renderer);
Expand Down Expand Up @@ -212,6 +217,12 @@ void psxe_screen_update(psxe_screen_t* screen) {
} break;

case SDLK_F4: {
screen->bilinear = !screen->bilinear;

psxe_gpu_dmode_event_cb(screen->psx->gpu);
} break;

case SDLK_F11: {
screen->fullscreen = !screen->fullscreen;

SDL_SetWindowFullscreen(
Expand All @@ -237,6 +248,14 @@ void psxe_screen_update(psxe_screen_t* screen) {
uint16_t mask = screen_get_button(event.key.keysym.sym);

psx_pad_button_press(screen->pad, 0, mask);

if (event.key.keysym.sym == SDLK_RETURN) {
psx_exp2_atcons_put(screen->psx->exp2, 13);
}
} break;

case SDL_TEXTINPUT: {
psx_exp2_atcons_put(screen->psx->exp2, event.text.text[0]);
} break;

case SDL_KEYUP: {
Expand Down Expand Up @@ -280,8 +299,11 @@ void psxe_gpu_dmode_event_cb(psx_gpu_t* gpu) {
screen->texture_height = PSX_GPU_FB_HEIGHT;
} else {
if (screen->fullscreen) {
screen->width = 1920;
screen->height = 1080;
SDL_DisplayMode dm;
SDL_GetCurrentDisplayMode(0, &dm);

screen->width = dm.w;
screen->height = dm.h;

if (screen->vertical_mode) {
screen->image_width = screen->height;
Expand Down Expand Up @@ -331,6 +353,8 @@ void psxe_gpu_dmode_event_cb(psx_gpu_t* gpu) {
screen->texture_width, screen->texture_height
);

SDL_SetTextureScaleMode(screen->texture, screen->bilinear);

SDL_SetWindowSize(screen->window, screen->width, screen->height);
}

Expand Down
1 change: 1 addition & 0 deletions frontend/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct {
unsigned int format;
unsigned int texture_width, texture_height;

int bilinear;
int fullscreen;
int vertical_mode;
int debug_mode;
Expand Down
10 changes: 10 additions & 0 deletions psx/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ uint32_t psx_bus_read32(psx_bus_t* bus, uint32_t addr) {
HANDLE_READ(ram, 32);
HANDLE_READ(dma, 32);
HANDLE_READ(exp1, 32);
HANDLE_READ(exp2, 32);
HANDLE_READ(mc1, 32);
HANDLE_READ(mc2, 32);
HANDLE_READ(mc3, 32);
Expand Down Expand Up @@ -82,6 +83,7 @@ uint16_t psx_bus_read16(psx_bus_t* bus, uint32_t addr) {
HANDLE_READ(ram, 16);
HANDLE_READ(dma, 16);
HANDLE_READ(exp1, 16);
HANDLE_READ(exp2, 16);
HANDLE_READ(mc1, 16);
HANDLE_READ(mc2, 16);
HANDLE_READ(mc3, 16);
Expand Down Expand Up @@ -112,6 +114,7 @@ uint8_t psx_bus_read8(psx_bus_t* bus, uint32_t addr) {
HANDLE_READ(ram, 8);
HANDLE_READ(dma, 8);
HANDLE_READ(exp1, 8);
HANDLE_READ(exp2, 8);
HANDLE_READ(mc1, 8);
HANDLE_READ(mc2, 8);
HANDLE_READ(mc3, 8);
Expand Down Expand Up @@ -146,6 +149,7 @@ void psx_bus_write32(psx_bus_t* bus, uint32_t addr, uint32_t value) {
HANDLE_WRITE(ram, 32);
HANDLE_WRITE(dma, 32);
HANDLE_WRITE(exp1, 32);
HANDLE_WRITE(exp2, 32);
HANDLE_WRITE(mc1, 32);
HANDLE_WRITE(mc2, 32);
HANDLE_WRITE(mc3, 32);
Expand Down Expand Up @@ -178,6 +182,7 @@ void psx_bus_write16(psx_bus_t* bus, uint32_t addr, uint16_t value) {
HANDLE_WRITE(ram, 16);
HANDLE_WRITE(dma, 16);
HANDLE_WRITE(exp1, 16);
HANDLE_WRITE(exp2, 16);
HANDLE_WRITE(mc1, 16);
HANDLE_WRITE(mc2, 16);
HANDLE_WRITE(mc3, 16);
Expand Down Expand Up @@ -206,6 +211,7 @@ void psx_bus_write8(psx_bus_t* bus, uint32_t addr, uint8_t value) {
HANDLE_WRITE(ram, 8);
HANDLE_WRITE(dma, 8);
HANDLE_WRITE(exp1, 8);
HANDLE_WRITE(exp2, 8);
HANDLE_WRITE(mc1, 8);
HANDLE_WRITE(mc2, 8);
HANDLE_WRITE(mc3, 8);
Expand Down Expand Up @@ -239,6 +245,10 @@ void psx_bus_init_exp1(psx_bus_t* bus, psx_exp1_t* exp1) {
bus->exp1 = exp1;
}

void psx_bus_init_exp2(psx_bus_t* bus, psx_exp2_t* exp2) {
bus->exp2 = exp2;
}

void psx_bus_init_mc1(psx_bus_t* bus, psx_mc1_t* mc1) {
bus->mc1 = mc1;
}
Expand Down
3 changes: 3 additions & 0 deletions psx/bus_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "dev/ram.h"
#include "dev/dma.h"
#include "dev/exp1.h"
#include "dev/exp2.h"
#include "dev/mc1.h"
#include "dev/mc2.h"
#include "dev/mc3.h"
Expand All @@ -22,6 +23,7 @@ struct psx_bus_t {
psx_ram_t* ram;
psx_dma_t* dma;
psx_exp1_t* exp1;
psx_exp2_t* exp2;
psx_mc1_t* mc1;
psx_mc2_t* mc2;
psx_mc3_t* mc3;
Expand All @@ -41,6 +43,7 @@ void psx_bus_init_bios(psx_bus_t*, psx_bios_t*);
void psx_bus_init_ram(psx_bus_t*, psx_ram_t*);
void psx_bus_init_dma(psx_bus_t*, psx_dma_t*);
void psx_bus_init_exp1(psx_bus_t*, psx_exp1_t*);
void psx_bus_init_exp2(psx_bus_t*, psx_exp2_t*);
void psx_bus_init_mc1(psx_bus_t*, psx_mc1_t*);
void psx_bus_init_mc2(psx_bus_t*, psx_mc2_t*);
void psx_bus_init_mc3(psx_bus_t*, psx_mc3_t*);
Expand Down
18 changes: 15 additions & 3 deletions psx/dev/bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ void psx_bios_init(psx_bios_t* bios) {
bios->io_base = PSX_BIOS_BEGIN;
bios->io_size = PSX_BIOS_SIZE;
bios->bus_delay = 18;

bios->buf = (uint8_t*)malloc(PSX_BIOS_SIZE);
}

void psx_bios_load(psx_bios_t* bios, const char* path) {
Expand All @@ -28,7 +26,21 @@ void psx_bios_load(psx_bios_t* bios, const char* path) {
exit(1);
}

if (!fread(bios->buf, 1, PSX_BIOS_SIZE, file)) {
// Almost all PS1 BIOS ROMs are 512 KiB in size.
// There's (at least) one exception, and that is SCPH-5903.
// This is a special asian model PS1 that had built-in support
// for Video CD (VCD) playback. Its BIOS is double the normal
// size
fseek(file, 0, SEEK_END);

size_t size = ftell(file);

fseek(file, 0, SEEK_SET);

bios->buf = malloc(size);
bios->io_size = size;

if (!fread(bios->buf, 1, size, file)) {
perror("Error reading BIOS file");

exit(1);
Expand Down
Loading

0 comments on commit ce32c2f

Please sign in to comment.