- [CHG] zx_screen pinta t_state a t_state, per a que es vegen les ralles al carregar

- [FIX] Ja carrega blocs capçalera i blocs programa. Falla el següent...
This commit is contained in:
2024-04-21 21:53:34 +02:00
parent ddcb40b289
commit 9b603604e9
5 changed files with 144 additions and 60 deletions

View File

@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
if (z80debug::debugging()) {
if ((e.type==SDL_WINDOWEVENT) && ((e.window.event==SDL_WINDOWEVENT_SHOWN) || (e.window.event==SDL_WINDOWEVENT_EXPOSED))) {
z80debug::refresh();
zxscreen::refresh(0, true);
zxscreen::redraw();
}
if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.scancode==SDL_SCANCODE_ESCAPE) {
@@ -47,10 +47,12 @@ int main(int argc, char *argv[])
} else if (e.key.keysym.scancode==SDL_SCANCODE_F10) {
const uint8_t dt = z80::step();
z80debug::refresh();
zxscreen::refresh(dt, true);
zxscreen::refresh(dt);
zxscreen::redraw();
} else if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
const uint8_t dt = z80debug::next();
zxscreen::refresh(dt, true);
zxscreen::refresh(dt);
zxscreen::redraw();
} else if (e.key.keysym.scancode==SDL_SCANCODE_F5) {
const uint8_t dt = z80::step();
z80debug::cont();
@@ -68,18 +70,21 @@ int main(int argc, char *argv[])
if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.scancode==SDL_SCANCODE_F8) {
z80debug::stop();
zxscreen::refresh(0, true);
zxscreen::redraw();
}
if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
zx_tape::play();
}
if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
zx_tape::rewind();
}
}
}
}
if (!z80debug::debugging()) {
if (z80debug::isbreak(z80::getPC(), 9)) {
z80debug::stop();
zxscreen::refresh(0, true);
zxscreen::redraw();
} else {
uint8_t dt = z80::step();
zx_tape::update(dt);

View File

@@ -13,72 +13,143 @@ namespace zxscreen
SDL_Renderer *ren = nullptr;
SDL_Texture *tex = nullptr;
uint32_t time=0;
uint32_t t_screen = 0;
uint8_t t_flash = 0;
bool flash = false;
void show()
int pixels_draw = 0;
uint16_t pixel_addr[69888];
uint16_t color_addr[69888];
uint8_t zx_pixels[352*296];
uint8_t *ptr_pixel = zx_pixels;
void create_tables()
{
if (win) return;
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 288, SDL_WINDOW_RESIZABLE);
ren = SDL_CreateRenderer(win, -1, 0);
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 288);
refresh(0);
}
uint32_t count = 0;
void refresh(const uint8_t dt, const bool force_refresh)
{
t_screen += dt;
if (t_screen>=69888) {
t_flash++;
if (t_flash==16) { t_flash=0; flash = !flash; }
t_screen=0;
} else if (!force_refresh) return;
uint16_t *ptr_pixel = pixel_addr;
uint16_t *ptr_color = color_addr;
const uint8_t* memory = z80::getMem();
const uint8_t border_color = zx_ula::get_border_color();
//memory+=0x4000;
Uint32* pixels;
int pitch;
SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch);
// vsync
for (int i=0; i<224*16;++i) { *(ptr_pixel++) = 0; *(ptr_color++) = 0; }
// Upper border
for (int i=0; i<352*48;++i) *(pixels++) = palette[border_color];
for (int i=0; i<48;++i) {
// hsync
for (int j=0;j<48;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 0; }
//border
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; }
}
// scanlines
for (uint8_t y=0; y<192; ++y)
{
// hsync
for (int j=0;j<48;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 0; }
// Left border
for (int j=0;j<48;++j) *(pixels++) = palette[border_color];
for (int j=0;j<24;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; }
// Actual screen
for (uint8_t x=0;x<32;++x)
{
uint8_t color = memory[0x5800 + x + (y>>3)*32];
uint16_t color = 0x5800 + x + (y>>3)*32;
uint16_t address = 0x4000 | (x&0x1f) | ((y&0x7)<<8) | ((y&0x38)<<2) | ((y&0xc0)<<5);
uint8_t block = memory[address];
uint8_t c1 = color&0x7, c2 = (color>>3)&0x7;
if ((color&0x80) && flash) { c1=c2; c2=color&0x7; }
for (int i=0;i<8;++i)
for (int i=6;i>=0;i-=2)
{
*(pixels++)=(block&0x80) ? palette[c1] : palette[c2];
block = block<<1;
*(ptr_pixel++) = (address & 0x1FFF) | (i << 13);
*(ptr_color++) = color;
count+=2;
}
}
// Right border
for (int j=0;j<48;++j) *(pixels++) = palette[border_color];
for (int j=0;j<24;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; }
}
// Lower border
for (int i=0; i<352*48;++i) *(pixels++)=palette[border_color];
for (int i=0; i<56;++i) {
// hsync
for (int j=0;j<48;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 0; }
//border
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; }
}
printf("COUNT: %i\n", count);
}
void show()
{
if (win) return;
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 296, SDL_WINDOW_RESIZABLE);
ren = SDL_CreateRenderer(win, -1, 0);
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 296);
create_tables();
redraw();
}
void refresh(const uint8_t dt)
{
const uint8_t* memory = z80::getMem();
const uint8_t border_color = zx_ula::get_border_color();
for (int i=0;i<dt;++i)
{
if (color_addr[t_screen] != 0)
{
if (color_addr[t_screen] == 1)
{
*(ptr_pixel++) = border_color;
*(ptr_pixel++) = border_color;
//pixels_draw+=2;
}
else
{
uint8_t color = memory[color_addr[t_screen]];
uint8_t c1 = color&0x7, c2 = (color>>3)&0x7;
if ((color&0x80) && flash) { c1=c2; c2=color&0x7; }
if ((color&040)) { 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 = memory[address];
*(ptr_pixel++)=(block&mask) ? c1 : c2;
mask>>=1;
*(ptr_pixel++)=(block&mask) ? c1 : c2;
}
pixels_draw+=2;
}
t_screen++;
/*if (pixels_draw>352*296)
{
printf("PIXELS OVERFLOW: %i\n", pixels_draw);
}*/
if (t_screen>=69888) {
//printf("PIXELS DRAWN: %i\n", pixels_draw);
pixels_draw=0;
t_flash++;
if (t_flash==16) { t_flash=0; flash = !flash; }
t_screen=0;
ptr_pixel = zx_pixels;
redraw();
//while (SDL_GetTicks()-time < 20) {}
//time = SDL_GetTicks();
z80::interrupt();
}
}
}
void redraw()
{
Uint32* pixels;
int pitch;
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);
SDL_RenderPresent(ren);
if (t_screen==0) z80::interrupt();
}
}

View File

@@ -4,5 +4,6 @@
namespace zxscreen
{
void show();
void refresh(const uint8_t dt, const bool force_refresh=false);
void refresh(const uint8_t dt);
void redraw();
}

View File

@@ -28,9 +28,7 @@ namespace zx_tape
struct block_t
{
uint16_t length;
uint8_t flag;
uint8_t *data;
uint8_t checksum;
};
bool playing = false;
@@ -56,11 +54,11 @@ namespace zx_tape
{
block_t block;
fread(&block.length, 2, 1, f);
fread(&block.flag, 1, 1, f);
block.length -= 2; // substract flag and checksum
//fread(&block.flag, 1, 1, f);
//block.length -= 2; // substract flag and checksum
block.data = (uint8_t *)malloc(block.length);
fread(block.data, block.length, 1, f);
fread(&block.checksum, 1, 1, f);
//fread(&block.checksum, 1, 1, f);
blocks.push_back(block);
}
fclose(f);
@@ -73,7 +71,7 @@ namespace zx_tape
void play()
{
if (!loaded) return;
playing = true;
playing = !playing; //true;
}
void stop()
@@ -98,13 +96,17 @@ namespace zx_tape
if (current_section == PULSE_PILOT)
{
const uint16_t pulse_count = blocks[current_block].flag<128 ? PULSE_COUNT_PILOT_HEADER : PULSE_COUNT_PILOT_DATA;
const uint16_t pulse_count = blocks[current_block].data[0]<128 ? PULSE_COUNT_PILOT_HEADER : PULSE_COUNT_PILOT_DATA;
if (pulse_pos >= PULSE_LEN_PILOT )
{
pulse_pos -= PULSE_LEN_PILOT;
current_pulse++;
pulse_level = pulse_level?0:1;
if (current_pulse >= pulse_count)
if (current_pulse == pulse_count && pulse_level==0)
{
pulse_level = 0;
}
else if (current_pulse >= pulse_count)
{
current_pulse = 0;
pulse_level = 1;
@@ -132,18 +134,21 @@ namespace zx_tape
current_section = PULSE_DATA;
}
}
static int level[2] = {0, 0};
if (current_section == PULSE_DATA)
{
level[pulse_level]+=dt;
const uint8_t datum = blocks[current_block].data[block_pos];
const uint16_t pulse_len = (datum & (0x80>>current_bit)) == 0 ? PULSE_LEN_ZERO : PULSE_LEN_ONE;
if (pulse_pos >= pulse_len)
{
pulse_pos -= pulse_len;
pulse_pos =0;//-= pulse_len;
pulse_level--;
if (pulse_level>=2)
{
pulse_level = 1;
//printf("%i\n",current_bit);
level[0]=level[1]=0;
current_bit++;
if (current_bit>=8)
{
@@ -152,16 +157,16 @@ namespace zx_tape
if (block_pos>=blocks[current_block].length)
{
block_pos = 0;
current_section = PULSE_CHECKSUM;
current_section = PULSE_SYNC3;
}
}
}
}
}
if (current_section == PULSE_CHECKSUM)
/*if (current_section == PULSE_CHECKSUM)
{
const uint8_t datum = blocks[current_block].checksum;
const uint8_t datum = 1;//blocks[current_block].checksum;
const uint16_t pulse_len = (datum & (0x80>>current_bit)) == 0 ? PULSE_LEN_ZERO : PULSE_LEN_ONE;
if (pulse_pos >= pulse_len)
{
@@ -178,7 +183,7 @@ namespace zx_tape
}
}
}
}
}*/
if (current_section == PULSE_SYNC3)
{
@@ -196,6 +201,7 @@ namespace zx_tape
pulse_level = 0;
if (pulse_pos >= 3500000)
{
pulse_pos = 0;
current_section = PULSE_PILOT;
pulse_level = 1;
current_block++;

View File

@@ -90,8 +90,8 @@ namespace zx_ula
void port_out(int port, int val)
{
border_color = val & 0x7;
mic = (val>>3)&0x1;
ear = (val>>4)&0x1;
mic = (val&0x08)==0;
ear = val&0x10;
//printf("EAR:%i MIC:%i\n", ear, mic);
}
@@ -111,6 +111,7 @@ namespace zx_ula
{
const uint16_t top = sound_pos < len ? sound_pos : len;
memcpy(stream, sound_buffer, top);
if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
sound_pos=0;
}
@@ -133,8 +134,8 @@ namespace zx_ula
void sound_update(const uint8_t dt)
{
t_sound += dt;
if (t_sound>=400) {
t_sound-=400;
if (t_sound>=317) {
t_sound-=317;
sound_buffer[sound_pos++] = ear*128;
}
}