ref: 2cfb4cbaf324e7b997a7695e9cdfaa8025fc66d9
parent: 5cd9010ecf17b644e5cf965cc76eb0cd9a1ac9a3
author: Snesrev <[email protected]>
date: Fri Oct 14 15:36:03 EDT 2022
PPU now renders 256x224 instead of 512x448
--- a/main.c
+++ b/main.c
@@ -44,7 +44,6 @@
enum {
kDefaultFullscreen = 0,
- kDefaultWindowScale = 2,
kMaxWindowScale = 10,
kDefaultFreq = 44100,
kDefaultChannels = 2,
@@ -99,14 +98,14 @@
bt = 31;
}
// Allow a scale level slightly above the max that fits on screen
- int mw = (bounds.w - bl - br + (g_snes_width / kDefaultWindowScale) / 4) / (g_snes_width / kDefaultWindowScale);
- int mh = (bounds.h - bt - bb + (g_snes_height / kDefaultWindowScale) / 4) / (g_snes_height / kDefaultWindowScale);
+ int mw = (bounds.w - bl - br + g_snes_width / 4) / g_snes_width;
+ int mh = (bounds.h - bt - bb + g_snes_height / 4) / g_snes_height;
max_scale = IntMin(mw, mh);
}
int new_scale = IntMax(IntMin(g_current_window_scale + scale_step, max_scale), 1);
g_current_window_scale = new_scale;
- int w = new_scale * (g_snes_width / kDefaultWindowScale);
- int h = new_scale * (g_snes_height / kDefaultWindowScale);
+ int w = new_scale * g_snes_width;
+ int h = new_scale * g_snes_height;
//SDL_RenderSetLogicalSize(g_renderer, w, h);
SDL_SetWindowSize(g_window, w, h);
@@ -212,8 +211,8 @@
ZeldaInitialize();
g_zenv.ppu->extraLeftRight = UintMin(g_config.extended_aspect_ratio, kPpuExtraLeftRight);
- g_snes_width = 2 * (g_config.extended_aspect_ratio * 2 + 256);
- g_snes_height = (g_config.extend_y ? 240 : 224) * 2;
+ g_snes_width = (g_config.extended_aspect_ratio * 2 + 256);
+ g_snes_height = (g_config.extend_y ? 240 : 224);
// Delay actually setting those features in ram until any snapshots finish playing.
@@ -252,8 +251,8 @@
}
bool custom_size = g_config.window_width != 0 && g_config.window_height != 0;
- int window_width = custom_size ? g_config.window_width : g_current_window_scale * (g_snes_width / kDefaultWindowScale);
- int window_height = custom_size ? g_config.window_height : g_current_window_scale * (g_snes_height / kDefaultWindowScale);
+ int window_width = custom_size ? g_config.window_width : g_current_window_scale * g_snes_width;
+ int window_height = custom_size ? g_config.window_height : g_current_window_scale * g_snes_height;
SDL_Window* window = SDL_CreateWindow(kWindowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, g_win_flags);
if(window == NULL) {
@@ -280,7 +279,7 @@
g_renderer = renderer;
if (!g_config.ignore_aspect_ratio)
SDL_RenderSetLogicalSize(renderer, g_snes_width, g_snes_height);
- SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, g_snes_width * 2, g_snes_height * 2);
+ SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, g_snes_width * 4, g_snes_height * 4);
if(texture == NULL) {
printf("Failed to create texture: %s\n", SDL_GetError());
return 1;
@@ -489,7 +488,7 @@
uint8 *pixels = 0;
int pitch = 0;
int render_scale = PpuGetCurrentRenderScale(g_zenv.ppu, g_ppu_render_flags);
- SDL_Rect src_rect = { 0, 0, g_snes_width * render_scale >> 1, g_snes_height * render_scale >> 1};
+ SDL_Rect src_rect = { 0, 0, g_snes_width * render_scale, g_snes_height * render_scale};
uint64 t0 = SDL_GetPerformanceCounter();
if(SDL_LockTexture(texture, &src_rect, (void**)&pixels, &pitch) != 0) {
--- a/snes/ppu.c
+++ b/snes/ppu.c
@@ -125,7 +125,7 @@
int PpuGetCurrentRenderScale(Ppu *ppu, uint32_t render_flags) {
bool hq = ppu->mode == 7 && !ppu->forcedBlank &&
(render_flags & (kPpuRenderFlags_4x4Mode7 | kPpuRenderFlags_NewRenderer)) == (kPpuRenderFlags_4x4Mode7 | kPpuRenderFlags_NewRenderer);
- return hq ? 4 : 2;
+ return hq ? 4 : 1;
}
void PpuBeginDrawing(Ppu *ppu, uint8_t *pixels, size_t pitch, uint32_t render_flags) {
@@ -884,9 +884,9 @@
uint32 cw_clip_math = ((cwin.bits & kCwBitsMod[ppu->clipMode]) ^ kCwBitsMod[ppu->clipMode + 4]) |
((cwin.bits & kCwBitsMod[ppu->preventMathMode]) ^ kCwBitsMod[ppu->preventMathMode + 4]) << 8;
- uint32 *dst = (uint32*)&ppu->renderBuffer[(y - 1) * 2 * ppu->renderPitch], *dst_org = dst;
+ uint32 *dst = (uint32*)&ppu->renderBuffer[(y - 1) * ppu->renderPitch], *dst_org = dst;
- dst += 2 * (ppu->extraLeftRight - ppu->extraLeftCur);
+ dst += (ppu->extraLeftRight - ppu->extraLeftCur);
uint32 windex = 0;
do {
@@ -900,10 +900,10 @@
uint32 i = left;
do {
uint32 color = ppu->cgram[ppu->bgBuffers[0].data[i] & 0xff];
- dst[1] = dst[0] = ppu->brightnessMult[color & clip_color_mask] << 16 |
- ppu->brightnessMult[(color >> 5) & clip_color_mask] << 8 |
- ppu->brightnessMult[(color >> 10) & clip_color_mask];
- } while (dst += 2, ++i < right);
+ dst[0] = ppu->brightnessMult[color & clip_color_mask] << 16 |
+ ppu->brightnessMult[(color >> 5) & clip_color_mask] << 8 |
+ ppu->brightnessMult[(color >> 10) & clip_color_mask];
+ } while (dst++, ++i < right);
} else {
uint8 *half_color_map = ppu->halfColor ? ppu->brightnessMultHalf : ppu->brightnessMult;
// Store this in locals
@@ -937,20 +937,17 @@
b += b2;
}
}
- dst[0] = dst[1] = color_map[b] | color_map[g] << 8 | color_map[r] << 16;
- } while (dst += 2, ++i < right);
+ dst[0] = color_map[b] | color_map[g] << 8 | color_map[r] << 16;
+ } while (dst++, ++i < right);
}
} while (cw_clip_math >>= 1, ++windex < cwin.nr);
// Clear out stuff on the sides.
if (ppu->extraLeftRight - ppu->extraLeftCur != 0)
- memset(dst_org, 0, 2 * sizeof(uint32) * (ppu->extraLeftRight - ppu->extraLeftCur));
+ memset(dst_org, 0, sizeof(uint32) * (ppu->extraLeftRight - ppu->extraLeftCur));
if (ppu->extraLeftRight - ppu->extraRightCur != 0)
- memset(dst_org + 2 * (256 + ppu->extraLeftRight * 2 - (ppu->extraLeftRight - ppu->extraRightCur)), 0,
- 2 * sizeof(uint32) * (ppu->extraLeftRight - ppu->extraRightCur));
-
- // Duplicate one line
- memcpy((uint8*)dst_org + ppu->renderPitch, dst_org, (ppu->extraLeftRight * 2 + 256) * 2 * sizeof(uint32));
+ memset(dst_org + (256 + ppu->extraLeftRight * 2 - (ppu->extraLeftRight - ppu->extraRightCur)), 0,
+ sizeof(uint32) * (ppu->extraLeftRight - ppu->extraRightCur));
}
static void ppu_handlePixel(Ppu* ppu, int x, int y) {
@@ -1006,15 +1003,11 @@
}
}
int row = y - 1;
- uint8 *pixelBuffer = (uint8*) &ppu->renderBuffer[row * 2 * ppu->renderPitch + (x + ppu->extraLeftRight) * 8];
- pixelBuffer[0] = ((b2 << 3) | (b2 >> 2)) * ppu->brightness / 15;
- pixelBuffer[1] = ((g2 << 3) | (g2 >> 2)) * ppu->brightness / 15;
- pixelBuffer[2] = ((r2 << 3) | (r2 >> 2)) * ppu->brightness / 15;
+ uint8 *pixelBuffer = (uint8*) &ppu->renderBuffer[row * ppu->renderPitch + (x + ppu->extraLeftRight) * 4];
+ pixelBuffer[0] = ((b << 3) | (b >> 2)) * ppu->brightness / 15;
+ pixelBuffer[1] = ((g << 3) | (g >> 2)) * ppu->brightness / 15;
+ pixelBuffer[2] = ((r << 3) | (r >> 2)) * ppu->brightness / 15;
pixelBuffer[3] = 0;
- pixelBuffer[4] = ((b << 3) | (b >> 2)) * ppu->brightness / 15;
- pixelBuffer[5] = ((g << 3) | (g >> 2)) * ppu->brightness / 15;
- pixelBuffer[6] = ((r << 3) | (r >> 2)) * ppu->brightness / 15;
- pixelBuffer[7] = 0;
}
static const int bitDepthsPerMode[10][4] = {