diff --git a/main.cpp b/main.cpp index 25320ce..6fb2d19 100644 --- a/main.cpp +++ b/main.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) SDL_Init(SDL_INIT_EVERYTHING); z80debug::show(); - zxscreen::show(); + zxscreen::init(); zx_ula::sound_init(); @@ -75,15 +75,19 @@ int main(int argc, char *argv[]) } } else { 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(); zxscreen::redraw(); - } - if (e.key.keysym.scancode==SDL_SCANCODE_F12) { + } else if (e.key.keysym.scancode==SDL_SCANCODE_F12) { zx_tape::go_berserk(); zx_tape::play(); - } - if (e.key.keysym.scancode==SDL_SCANCODE_F11) { + } else if (e.key.keysym.scancode==SDL_SCANCODE_F11) { zx_tape::rewind(); } } diff --git a/zx_screen.cpp b/zx_screen.cpp index b16d4a8..75fe6d0 100644 --- a/zx_screen.cpp +++ b/zx_screen.cpp @@ -13,6 +13,10 @@ namespace zxscreen SDL_Window *win = nullptr; SDL_Renderer *ren = nullptr; SDL_Texture *tex = nullptr; + uint8_t zoom = 1; + bool fullscreen = false; + int fullscreen_scale = 1; + SDL_Rect dest_rect; uint32_t time=0; @@ -78,19 +82,46 @@ namespace zxscreen //border 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; - win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 296, SDL_WINDOW_SHOWN); + if (tex) SDL_DestroyTexture(tex); + 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); 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(); } + void init() + { + create_tables(); + reinit(); + } + void refresh(const uint8_t dt) { const uint8_t* memory = z80::getMem(); @@ -151,7 +182,46 @@ namespace zxscreen SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch); for (int i=0; i<352*296;++i) *(pixels++) = palette[zx_pixels[i]]; 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); } + + 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(); + } + } diff --git a/zx_screen.h b/zx_screen.h index 6d86042..64f9485 100644 --- a/zx_screen.h +++ b/zx_screen.h @@ -3,7 +3,12 @@ namespace zxscreen { - void show(); + void init(); + void reinit(); void refresh(const uint8_t dt); void redraw(); + + void incZoom(); + void decZoom(); + void toggleFullscreen(); }