- [NEW] zx_screen preparat per al ZX Spectrum 128k
- [NEW] Afegida rom del ZX Spectrum 128K
This commit is contained in:
2
main.cpp
2
main.cpp
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
z80debug::init();
|
z80debug::init();
|
||||||
zxscreen::init(0x4000, 0x5800);
|
zxscreen::init(SCREEN_MODE_48K);
|
||||||
|
|
||||||
ui::menu::init();
|
ui::menu::init();
|
||||||
ui::menu::setexitcallback(actions::exitMenu);
|
ui::menu::setexitcallback(actions::exitMenu);
|
||||||
|
|||||||
2
z80mem.h
2
z80mem.h
@@ -35,6 +35,8 @@ class z80mem
|
|||||||
|
|
||||||
virtual uint32_t getSize() = 0;
|
virtual uint32_t getSize() = 0;
|
||||||
|
|
||||||
|
virtual uint8_t *rawPtr(uint32_t address) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static z80mem *singleton;
|
static z80mem *singleton;
|
||||||
|
|||||||
@@ -59,3 +59,7 @@ uint32_t zx_48mem::getSize()
|
|||||||
return 65536;
|
return 65536;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t *zx_48mem::rawPtr(uint32_t address)
|
||||||
|
{
|
||||||
|
return &memory[address];
|
||||||
|
}
|
||||||
@@ -21,6 +21,8 @@ class zx_48mem : public z80mem
|
|||||||
|
|
||||||
uint32_t getSize();
|
uint32_t getSize();
|
||||||
|
|
||||||
|
uint8_t *rawPtr(uint32_t address);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint8_t memory[65536];
|
uint8_t memory[65536];
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ namespace zxscreen
|
|||||||
SDL_Texture *tex = nullptr;
|
SDL_Texture *tex = nullptr;
|
||||||
SDL_Texture *uitex = 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;
|
uint8_t zoom = 1;
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
bool full_refresh = true;
|
bool full_refresh = true;
|
||||||
@@ -36,8 +42,8 @@ namespace zxscreen
|
|||||||
uint16_t pixel_base_addr = 0x4000;
|
uint16_t pixel_base_addr = 0x4000;
|
||||||
uint16_t color_base_addr = 0x5800;
|
uint16_t color_base_addr = 0x5800;
|
||||||
|
|
||||||
uint16_t pixel_addr[69888];
|
uint16_t *pixel_addr = nullptr; //[69888];
|
||||||
uint16_t color_addr[69888];
|
uint16_t *color_addr = nullptr; //[69888];
|
||||||
uint8_t zx_pixels[352*296];
|
uint8_t zx_pixels[352*296];
|
||||||
uint8_t *ptr_pixel = zx_pixels;
|
uint8_t *ptr_pixel = zx_pixels;
|
||||||
|
|
||||||
@@ -48,16 +54,21 @@ namespace zxscreen
|
|||||||
{
|
{
|
||||||
uint32_t count = 0;
|
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_pixel = pixel_addr;
|
||||||
uint16_t *ptr_color = color_addr;
|
uint16_t *ptr_color = color_addr;
|
||||||
|
|
||||||
// vsync
|
// vsync
|
||||||
for (int i=0; i<224*16;++i) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; }
|
for (int i=0; i<t_states_per_scanline*vsync_lines;++i) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; } // En el 128K 16 passa a ser 15 i 224 passa a ser 228
|
||||||
|
|
||||||
// Upper border
|
// Upper border
|
||||||
for (int i=0; i<48;++i) {
|
for (int i=0; i<48;++i) {
|
||||||
// hsync
|
// hsync
|
||||||
for (int j=0;j<48;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; }
|
for (int j=0;j<t_states_per_scanline-176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; } // En el 128K 48 passsa a ser 52
|
||||||
//border
|
//border
|
||||||
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_BORDER; count+=2; }
|
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_BORDER; count+=2; }
|
||||||
}
|
}
|
||||||
@@ -66,7 +77,7 @@ namespace zxscreen
|
|||||||
for (uint8_t y=0; y<192; ++y)
|
for (uint8_t y=0; y<192; ++y)
|
||||||
{
|
{
|
||||||
// hsync
|
// hsync
|
||||||
for (int j=0;j<48;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; }
|
for (int j=0;j<t_states_per_scanline-176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; } // En el 128K 48 passsa a ser 52
|
||||||
|
|
||||||
// Left border
|
// Left border
|
||||||
for (int j=0;j<24;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_BORDER; count+=2; }
|
for (int j=0;j<24;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_BORDER; count+=2; }
|
||||||
@@ -91,7 +102,7 @@ namespace zxscreen
|
|||||||
// Lower border
|
// Lower border
|
||||||
for (int i=0; i<56;++i) {
|
for (int i=0; i<56;++i) {
|
||||||
// hsync
|
// hsync
|
||||||
for (int j=0;j<48;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; }
|
for (int j=0;j<t_states_per_scanline-176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_SYNC; } // En el 128K 48 passsa a ser 52
|
||||||
//border
|
//border
|
||||||
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_BORDER; count+=2; }
|
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = SCREEN_BORDER; count+=2; }
|
||||||
}
|
}
|
||||||
@@ -178,15 +189,27 @@ namespace zxscreen
|
|||||||
focus();
|
focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaseAddresses(const uint16_t pixeladdr, const uint16_t coloraddr)
|
void setBaseAddresses(const uint32_t pixeladdr, const uint32_t coloraddr)
|
||||||
{
|
{
|
||||||
pixel_base_addr = pixeladdr;
|
pixel_base_addr = pixeladdr;
|
||||||
color_base_addr = coloraddr;
|
color_base_addr = coloraddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(const uint16_t pixeladdr, const uint16_t coloraddr)
|
void init(int mode)
|
||||||
{
|
{
|
||||||
setBaseAddresses(pixeladdr, coloraddr);
|
zxscreen::mode = mode;
|
||||||
|
if (mode==SCREEN_MODE_48K) {
|
||||||
|
setBaseAddresses(0x4000, 0x5800);
|
||||||
|
t_states_total = 69888;
|
||||||
|
t_states_per_scanline = 224;
|
||||||
|
vsync_lines = 16;
|
||||||
|
} else if (mode==SCREEN_MODE_128K) {
|
||||||
|
setBaseAddresses(0x14000, 0x15800);
|
||||||
|
t_states_total = 70908;
|
||||||
|
t_states_per_scanline = 228;
|
||||||
|
vsync_lines = 15;
|
||||||
|
}
|
||||||
|
|
||||||
create_tables();
|
create_tables();
|
||||||
reinit();
|
reinit();
|
||||||
}
|
}
|
||||||
@@ -202,7 +225,8 @@ namespace zxscreen
|
|||||||
|
|
||||||
void refresh(const uint32_t dt, const bool full)
|
void refresh(const uint32_t dt, const bool full)
|
||||||
{
|
{
|
||||||
//const uint8_t* memory = z80mem::getRawPointer(0x4000);
|
const uint8_t* pixel_mem = z80mem::get()->rawPtr(pixel_base_addr);
|
||||||
|
const uint8_t* color_mem = z80mem::get()->rawPtr(color_base_addr);
|
||||||
const uint8_t border_color = zx_ula::get_border_color();
|
const uint8_t border_color = zx_ula::get_border_color();
|
||||||
|
|
||||||
for (int i=0;i<dt;++i)
|
for (int i=0;i<dt;++i)
|
||||||
@@ -213,13 +237,13 @@ namespace zxscreen
|
|||||||
*(ptr_pixel++) = border_color;
|
*(ptr_pixel++) = border_color;
|
||||||
*(ptr_pixel++) = border_color;
|
*(ptr_pixel++) = border_color;
|
||||||
} else {
|
} else {
|
||||||
uint8_t color = z80mem::get()->readMem(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;
|
uint8_t c1 = color&0x7, c2 = (color>>3)&0x7;
|
||||||
if ((color&0x80) && flash) { c1=c2; c2=color&0x7; }
|
if ((color&0x80) && flash) { c1=c2; c2=color&0x7; }
|
||||||
if ((color&0x40)) { c1 |= 0x8; c2 |= 0x8; }
|
if ((color&0x40)) { c1 |= 0x8; c2 |= 0x8; }
|
||||||
uint16_t address = /*(0x4000) |*/ (pixel_addr[t_screen]&0x1FFF);
|
uint16_t address = /*(0x4000) |*/ (pixel_addr[t_screen]&0x1FFF);
|
||||||
uint8_t mask = 1 << (pixel_addr[t_screen]>>13);
|
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;
|
*(ptr_pixel++)=(block&mask) ? c1 : c2;
|
||||||
mask>>=1;
|
mask>>=1;
|
||||||
*(ptr_pixel++)=(block&mask) ? c1 : c2;
|
*(ptr_pixel++)=(block&mask) ? c1 : c2;
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#define SCREEN_MODE_48K 0
|
||||||
|
#define SCREEN_MODE_128K 1
|
||||||
|
|
||||||
namespace zxscreen
|
namespace zxscreen
|
||||||
{
|
{
|
||||||
void init(const uint16_t pixeladdr, const uint16_t coloraddr);
|
void init(int mode);
|
||||||
void setBaseAddresses(const uint16_t pixeladdr, const uint16_t coloraddr);
|
void setBaseAddresses(const uint32_t pixeladdr, const uint32_t coloraddr);
|
||||||
void reinit();
|
void reinit();
|
||||||
void focus();
|
void focus();
|
||||||
void refresh(const uint32_t dt, const bool full=false);
|
void refresh(const uint32_t dt, const bool full=false);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "zx_ula.h"
|
#include "zx_ula.h"
|
||||||
#include <z80.h>
|
#include "z80.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#define AUDIO_BUFFER_SIZE 2048
|
#define AUDIO_BUFFER_SIZE 2048
|
||||||
|
|||||||
Reference in New Issue
Block a user