- [NEW] Ja es pot especificar zoom i fullscreen seguint el standard Jailer

This commit is contained in:
2024-12-02 18:38:04 +01:00
parent cbbf39c6cc
commit 810cdf4ecb
3 changed files with 92 additions and 13 deletions

View File

@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
SDL_Init(SDL_INIT_EVERYTHING); SDL_Init(SDL_INIT_EVERYTHING);
z80debug::show(); z80debug::show();
zxscreen::show(); zxscreen::init();
zx_ula::sound_init(); zx_ula::sound_init();
@@ -75,15 +75,19 @@ int main(int argc, char *argv[])
} }
} else { } else {
if (e.type == SDL_KEYDOWN) { if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.scancode==SDL_SCANCODE_F8) { if (e.key.keysym.scancode==SDL_SCANCODE_F1) {
zxscreen::decZoom();
} else if (e.key.keysym.scancode==SDL_SCANCODE_F2) {
zxscreen::incZoom();
} else if (e.key.keysym.scancode==SDL_SCANCODE_F3) {
zxscreen::toggleFullscreen();
} else if (e.key.keysym.scancode==SDL_SCANCODE_F8) {
z80debug::stop(); z80debug::stop();
zxscreen::redraw(); zxscreen::redraw();
} } else if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
zx_tape::go_berserk(); zx_tape::go_berserk();
zx_tape::play(); zx_tape::play();
} } else if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
zx_tape::rewind(); zx_tape::rewind();
} }
} }

View File

@@ -13,6 +13,10 @@ namespace zxscreen
SDL_Window *win = nullptr; SDL_Window *win = nullptr;
SDL_Renderer *ren = nullptr; SDL_Renderer *ren = nullptr;
SDL_Texture *tex = nullptr; SDL_Texture *tex = nullptr;
uint8_t zoom = 1;
bool fullscreen = false;
int fullscreen_scale = 1;
SDL_Rect dest_rect;
uint32_t time=0; uint32_t time=0;
@@ -78,19 +82,46 @@ namespace zxscreen
//border //border
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; } for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; }
} }
printf("COUNT: %i\n", count); //printf("COUNT: %i\n", count);
} }
void show() void reinit()
{ {
if (win) return; if (tex) SDL_DestroyTexture(tex);
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 296, SDL_WINDOW_SHOWN); if (ren) SDL_DestroyRenderer(ren);
if (win) SDL_DestroyWindow(win);
const int z = fullscreen ? 1 : zoom;
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352*z, 296*z, fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN);
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 296); tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 296);
create_tables();
if (fullscreen)
{
int w, h;
SDL_GetWindowSize(win, &w, &h);
fullscreen_scale = h/296;
dest_rect.w = 352 * fullscreen_scale;
dest_rect.h = 296 * fullscreen_scale;
dest_rect.x = (w - dest_rect.w)/2;
dest_rect.y = (h - dest_rect.h)/2;
}
else
{
dest_rect.x = dest_rect.y = 0;
dest_rect.w = 352 * zoom;
dest_rect.h = 296 * zoom;
}
redraw(); redraw();
} }
void init()
{
create_tables();
reinit();
}
void refresh(const uint8_t dt) void refresh(const uint8_t dt)
{ {
const uint8_t* memory = z80::getMem(); const uint8_t* memory = z80::getMem();
@@ -151,7 +182,46 @@ namespace zxscreen
SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch); SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch);
for (int i=0; i<352*296;++i) *(pixels++) = palette[zx_pixels[i]]; for (int i=0; i<352*296;++i) *(pixels++) = palette[zx_pixels[i]];
SDL_UnlockTexture(tex); SDL_UnlockTexture(tex);
SDL_RenderCopy(ren, tex, NULL, NULL);
if (fullscreen)
{
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
SDL_RenderClear(ren);
}
// Pintem la textura a pantalla
SDL_RenderCopy(ren, tex, NULL, &dest_rect);
SDL_RenderPresent(ren); SDL_RenderPresent(ren);
} }
void setZoom(const int value)
{
if (value < 1) return;
SDL_DisplayMode dm;
SDL_GetCurrentDisplayMode(0, &dm);
if (352*value > dm.w) return;
if (296*value > dm.h) return;
zoom = value;
reinit();
}
void incZoom()
{
setZoom(zoom+1);
}
void decZoom()
{
setZoom(zoom-1);
}
void toggleFullscreen()
{
fullscreen = !fullscreen;
reinit();
}
} }

View File

@@ -3,7 +3,12 @@
namespace zxscreen namespace zxscreen
{ {
void show(); void init();
void reinit();
void refresh(const uint8_t dt); void refresh(const uint8_t dt);
void redraw(); void redraw();
void incZoom();
void decZoom();
void toggleFullscreen();
} }