diff --git a/128k.rom b/128k.rom new file mode 100644 index 0000000..1ddee8c Binary files /dev/null and b/128k.rom differ diff --git a/main.cpp b/main.cpp index 236d50f..b897ea4 100644 --- a/main.cpp +++ b/main.cpp @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) SDL_Init(SDL_INIT_EVERYTHING); z80debug::init(); - zxscreen::init(0x4000, 0x5800); + zxscreen::init(SCREEN_MODE_48K); ui::menu::init(); ui::menu::setexitcallback(actions::exitMenu); diff --git a/z80mem.h b/z80mem.h index b1a50c6..b41a19e 100644 --- a/z80mem.h +++ b/z80mem.h @@ -34,6 +34,8 @@ class z80mem virtual void loadState(FILE* f) = 0; virtual uint32_t getSize() = 0; + + virtual uint8_t *rawPtr(uint32_t address) = 0; protected: diff --git a/zx_48mem.cpp b/zx_48mem.cpp index 24afe3d..fa1e612 100644 --- a/zx_48mem.cpp +++ b/zx_48mem.cpp @@ -59,3 +59,7 @@ uint32_t zx_48mem::getSize() return 65536; } +uint8_t *zx_48mem::rawPtr(uint32_t address) +{ + return &memory[address]; +} \ No newline at end of file diff --git a/zx_48mem.h b/zx_48mem.h index b1fa26f..5309b20 100644 --- a/zx_48mem.h +++ b/zx_48mem.h @@ -20,7 +20,9 @@ class zx_48mem : public z80mem void loadState(FILE* f); uint32_t getSize(); - + + uint8_t *rawPtr(uint32_t address); + protected: uint8_t memory[65536]; diff --git a/zx_screen.cpp b/zx_screen.cpp index ba96ca9..1d8ec28 100644 --- a/zx_screen.cpp +++ b/zx_screen.cpp @@ -19,6 +19,12 @@ namespace zxscreen SDL_Texture *tex = nullptr; SDL_Texture *uitex = nullptr; + int mode = SCREEN_MODE_48K; + + uint32_t t_states_total = 69888; + uint32_t t_states_per_scanline = 224; + uint32_t vsync_lines = 16; + uint8_t zoom = 1; bool fullscreen = false; bool full_refresh = true; @@ -36,8 +42,8 @@ namespace zxscreen uint16_t pixel_base_addr = 0x4000; uint16_t color_base_addr = 0x5800; - uint16_t pixel_addr[69888]; - uint16_t color_addr[69888]; + uint16_t *pixel_addr = nullptr; //[69888]; + uint16_t *color_addr = nullptr; //[69888]; uint8_t zx_pixels[352*296]; uint8_t *ptr_pixel = zx_pixels; @@ -48,16 +54,21 @@ namespace zxscreen { uint32_t count = 0; + if (pixel_addr) free(pixel_addr); + if (color_addr) free(color_addr); + pixel_addr = (uint16_t*)malloc(t_states_total*sizeof(uint16_t)); + color_addr = (uint16_t*)malloc(t_states_total*sizeof(uint16_t)); + uint16_t *ptr_pixel = pixel_addr; uint16_t *ptr_color = color_addr; // vsync - for (int i=0; i<224*16;++i) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; } + for (int i=0; irawPtr(pixel_base_addr); + const uint8_t* color_mem = z80mem::get()->rawPtr(color_base_addr); const uint8_t border_color = zx_ula::get_border_color(); for (int i=0;ireadMem(color_base_addr + color_addr[t_screen]); + uint8_t color = *(color_mem + color_addr[t_screen]); // z80mem::get()->readMem(color_base_addr + color_addr[t_screen]); uint8_t c1 = color&0x7, c2 = (color>>3)&0x7; if ((color&0x80) && flash) { c1=c2; c2=color&0x7; } if ((color&0x40)) { c1 |= 0x8; c2 |= 0x8; } uint16_t address = /*(0x4000) |*/ (pixel_addr[t_screen]&0x1FFF); uint8_t mask = 1 << (pixel_addr[t_screen]>>13); - uint8_t block = z80mem::get()->readMem(pixel_base_addr + address); + uint8_t block = *(pixel_mem + address); // z80mem::get()->readMem(pixel_base_addr + address); *(ptr_pixel++)=(block&mask) ? c1 : c2; mask>>=1; *(ptr_pixel++)=(block&mask) ? c1 : c2; diff --git a/zx_screen.h b/zx_screen.h index 6b4790e..57e6f4a 100644 --- a/zx_screen.h +++ b/zx_screen.h @@ -1,10 +1,13 @@ #pragma once #include +#define SCREEN_MODE_48K 0 +#define SCREEN_MODE_128K 1 + namespace zxscreen { - void init(const uint16_t pixeladdr, const uint16_t coloraddr); - void setBaseAddresses(const uint16_t pixeladdr, const uint16_t coloraddr); + void init(int mode); + void setBaseAddresses(const uint32_t pixeladdr, const uint32_t coloraddr); void reinit(); void focus(); void refresh(const uint32_t dt, const bool full=false); diff --git a/zx_ula.cpp b/zx_ula.cpp index 6b98bec..b41c3cd 100644 --- a/zx_ula.cpp +++ b/zx_ula.cpp @@ -1,5 +1,5 @@ #include "zx_ula.h" -#include +#include "z80.h" #include #define AUDIO_BUFFER_SIZE 2048