ref: d24ee6196a33d64a075213000d4b994e3a8dcf7f
parent: 6d3047e01b59cc63a1f51db845d9bb091a95fd1e
author: allkern <lisandroaalarcon@gmail.com>
date: Fri Dec 22 07:36:31 EST 2023
Implement disc swap API Implement soft reset
--- a/frontend/screen.c
+++ b/frontend/screen.c
@@ -224,6 +224,14 @@
SDL_SetRenderDrawColor(screen->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(screen->renderer);
} break;
+
+ case SDLK_F5: {+ psx_soft_reset(screen->psx);
+ } break;
+
+ case SDLK_F6: {+ psx_swap_disc(screen->psx, ".\\roms\\Street Fighter II Movie (Japan) (Disc 2)\\Street Fighter II Movie (Japan) (Disc 2).cue");
+ } break;
}
uint16_t mask = screen_get_button(event.key.keysym.sym);
--- a/psx/dev/cdrom.c
+++ b/psx/dev/cdrom.c
@@ -1561,9 +1561,9 @@
cdrom->xa_right_buf = malloc(XA_STEREO_SAMPLES * sizeof(int16_t));
cdrom->xa_mono_buf = malloc(XA_MONO_SAMPLES * sizeof(int16_t));
cdrom->xa_upsample_buf = malloc(((14112 * 2) + 6) * sizeof(int16_t));
- cdrom->xa_left_resample_buf = malloc(2352 * sizeof(int16_t));
- cdrom->xa_right_resample_buf = malloc(2352 * sizeof(int16_t));
- cdrom->xa_mono_resample_buf = malloc(XA_MONO_RESAMPLE_SIZE * sizeof(int16_t));
+ cdrom->xa_left_resample_buf = malloc((XA_STEREO_RESAMPLE_SIZE * 2) * sizeof(int16_t));
+ cdrom->xa_right_resample_buf = malloc((XA_STEREO_RESAMPLE_SIZE * 2) * sizeof(int16_t));
+ cdrom->xa_mono_resample_buf = malloc((XA_MONO_RESAMPLE_SIZE * 2) * sizeof(int16_t));
cdrom->xa_step = 6;
// We will use this whenever we implement proper
@@ -1574,9 +1574,9 @@
memset(cdrom->xa_right_buf, 0, XA_STEREO_SAMPLES * sizeof(int16_t));
memset(cdrom->xa_mono_buf, 0, XA_MONO_SAMPLES * sizeof(int16_t));
memset(cdrom->xa_upsample_buf, 0, ((14112 * 2) + 6) * sizeof(int16_t));
- memset(cdrom->xa_left_resample_buf, 0, 2352 * sizeof(int16_t));
- memset(cdrom->xa_right_resample_buf, 0, 2352 * sizeof(int16_t));
- memset(cdrom->xa_mono_resample_buf, 0, XA_MONO_RESAMPLE_SIZE * sizeof(int16_t));
+ memset(cdrom->xa_left_resample_buf, 0, (XA_STEREO_RESAMPLE_SIZE * 2) * sizeof(int16_t));
+ memset(cdrom->xa_right_resample_buf, 0, (XA_STEREO_RESAMPLE_SIZE * 2) * sizeof(int16_t));
+ memset(cdrom->xa_mono_resample_buf, 0, (XA_MONO_RESAMPLE_SIZE * 2) * sizeof(int16_t));
}
uint32_t psx_cdrom_read32(psx_cdrom_t* cdrom, uint32_t offset) {@@ -1784,29 +1784,12 @@
};
void cdrom_resample_xa_buf(psx_cdrom_t* cdrom, int16_t* dst, int16_t* src, int stereo) {- // To-do: Account for 18KHz samples
- // int f18khz = ((cdrom->xa_sector_buf[0x13] >> 2) & 1) == 1;
+ int f18khz = ((cdrom->xa_sector_buf[0x13] >> 2) & 1) == 1;
+ int sample_count = stereo ? XA_STEREO_SAMPLES : XA_MONO_SAMPLES;
+ int resample_count = stereo ? XA_STEREO_RESAMPLE_SIZE : XA_MONO_RESAMPLE_SIZE;
- if (stereo) {- for (int i = 0; i < XA_STEREO_SAMPLES; i++) {- int j = i * 7;
-
- cdrom->xa_upsample_buf[j] = src[i];
-
- // Nearest neighbor
- for (int k = 0; k < 7; k++)
- cdrom->xa_upsample_buf[j+k] = src[i];
- }
-
- for (int i = 0; i < XA_STEREO_RESAMPLE_SIZE; i++)
- dst[i] = cdrom->xa_upsample_buf[i*6];
-
- cdrom->xa_remaining_samples = XA_STEREO_RESAMPLE_SIZE;
-
- return;
- }
-
- for (int i = 0; i < XA_MONO_SAMPLES; i++) {+ // Upsampling
+ for (int i = 0; i < sample_count; i++) {int j = i * 7;
cdrom->xa_upsample_buf[j] = src[i];
@@ -1816,10 +1799,17 @@
cdrom->xa_upsample_buf[j+k] = src[i];
}
- for (int i = 0; i < XA_MONO_RESAMPLE_SIZE; i++)
- dst[i] = cdrom->xa_upsample_buf[i*6];
+ if (f18khz) {+ for (int i = 0; i < resample_count; i++) {+ *dst++ = cdrom->xa_upsample_buf[i*3];
+ *dst++ = cdrom->xa_upsample_buf[i*3];
+ }
+ } else {+ for (int i = 0; i < resample_count; i++)
+ dst[i] = cdrom->xa_upsample_buf[i*6];
+ }
- cdrom->xa_remaining_samples = XA_MONO_RESAMPLE_SIZE;
+ cdrom->xa_remaining_samples = resample_count * (f18khz + 1);
}
void cdrom_decode_xa_block(psx_cdrom_t* cdrom, int idx, int blk, int nib, int16_t* buf, int16_t* h) {--- a/psx/psx.c
+++ b/psx/psx.c
@@ -56,11 +56,21 @@
}
uint32_t psx_get_display_width(psx_t* psx) {- return psx->gpu->draw_x2 - psx->gpu->draw_x1;
+ // int draw = psx->gpu->draw_x2 - psx->gpu->draw_x1;
+ // int dmode = psx_get_dmode_width(psx);
+
+ // return (draw > dmode) ? dmode : draw;
+
+ return psx_get_dmode_width(psx);
}
uint32_t psx_get_display_height(psx_t* psx) {- return psx->gpu->draw_y2 - psx->gpu->draw_y1;
+ // int draw = psx->gpu->draw_y2 - psx->gpu->draw_y1;
+ // int dmode = psx_get_dmode_height(psx);
+
+ // return (draw > dmode) ? dmode : draw;
+
+ return psx_get_dmode_height(psx);
}
uint32_t psx_get_display_format(psx_t* psx) {@@ -86,6 +96,10 @@
double psx_get_display_aspect(psx_t* psx) {double width = psx_get_dmode_width(psx);
double height = psx_get_dmode_height(psx);
+
+ if (height > width)
+ return 4.0 / 3.0;
+
double aspect = width / height;
if (aspect > (4.0 / 3.0))
@@ -160,9 +174,7 @@
}
void psx_soft_reset(psx_t* psx) {- log_fatal("Soft reset not yet implemented");-
- exit(1);
+ psx_cpu_init(psx->cpu, psx->bus);
}
uint32_t* psx_take_screenshot(psx_t* psx) {@@ -169,6 +181,17 @@
log_fatal("Screenshots not yet supported");exit(1);
+}
+
+void psx_swap_disc(psx_t* psx, const char* path) {+ psx_cdrom_destroy(psx->cdrom);
+
+ psx->cdrom = psx_cdrom_create();
+
+ psx_bus_init_cdrom(psx->bus, psx->cdrom);
+
+ psx_cdrom_init(psx->cdrom, psx->ic);
+ psx_cdrom_open(psx->cdrom, path);
}
void psx_destroy(psx_t* psx) {--- a/psx/psx.h
+++ b/psx/psx.h
@@ -46,6 +46,7 @@
uint32_t psx_get_display_format(psx_t*);
double psx_get_display_aspect(psx_t*);
uint32_t* psx_take_screenshot(psx_t*);
+void psx_swap_disc(psx_t*, const char*);
psx_bios_t* psx_get_bios(psx_t*);
psx_ram_t* psx_get_ram(psx_t*);
psx_dma_t* psx_get_dma(psx_t*);
--
⑨