- Afegim el tap i el savestate de Alien 8 per a provar

- Provant el berserk mode
- Medint els t-states de altra forma
- iff1, iff2 i im afegits al array de registres de la cpu
- [NEW] getRegs() del modul z80
- [NEW] loadstate() i savestate() al modul z80debug
- [NEW] "load arxiu" i "save arxiu" en consola per a carregar i guardar savestates
- [ONGOING] "tape load arxiu" i "tape play" per a canviar de cinta i playarla
- Buffer de audio més gran. Ara el buffer es circular. Continuem intentant desfer-se del jittering
This commit is contained in:
2024-12-02 15:32:09 +01:00
parent 4a9b13126b
commit 18406d4332
9 changed files with 95 additions and 33 deletions

BIN
alien8.sav Normal file

Binary file not shown.

BIN
alien8.tap Normal file

Binary file not shown.

View File

@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
zx_ula::sound_init();
zx_tape::load("abusimbel.tap");
zx_tape::load("alien8.tap");
if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
@@ -80,6 +80,7 @@ int main(int argc, char *argv[])
zxscreen::redraw();
}
if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
zx_tape::go_berserk();
zx_tape::play();
}
if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
@@ -98,11 +99,22 @@ int main(int argc, char *argv[])
uint8_t dt = z80::step();
t_states += dt;
zx_tape::update(dt);
while (zx_tape::berserk())
{
zx_tape::update(z80::step());
}
zx_ula::sound_update(dt);
zxscreen::refresh(dt);
if (t_states>=350000)
if (t_states>=3500000)
{
//if (SDL_GetTicks()>=time+1000)
//printf("%i\n", SDL_GetTicks()-(time+1000));
//else
// printf("%i\n", SDL_GetTicks()-(time+1000));
//t_states = 0;
while (SDL_GetTicks()<time+100) {}
t_states -= 350000;
time = SDL_GetTicks();

13
z80.cpp
View File

@@ -34,7 +34,7 @@ namespace z80
#define cP 6
#define cM 7
uint8_t regs[28];
uint8_t regs[31];
uint8_t *_rF = &regs[0];
uint8_t *_rA = &regs[1];
@@ -82,7 +82,11 @@ namespace z80
uint8_t *_rZ = (uint8_t*)&regs[26];
uint8_t *_rW = (uint8_t*)&regs[27];
uint8_t iff1, iff2, im;
uint8_t *_rIFF1 = &regs[28];
uint8_t *_rIFF2 = &regs[29];
uint8_t *_rIM = &regs[30];
//uint8_t iff1, iff2, im;
bool exit_from_halt = false;
#define rA (*_rA)
@@ -129,6 +133,10 @@ namespace z80
#define rPC (*_rPC)
#define iff1 (*_rIFF1)
#define iff2 (*_rIFF2)
#define im (*_rIM)
#define EX(a,b) {auto temp=a;a=b;b=temp;}
uint8_t READ_MEM_8(const uint16_t addr)
@@ -2685,6 +2693,7 @@ namespace z80
}
uint8_t *getMem() { return memory; }
uint8_t *getRegs() { return regs; }
uint16_t getAF(const bool alt) { return alt?rAF2:rAF; }
uint16_t getBC(const bool alt) { return alt?rBC2:rBC; }

3
z80.h
View File

@@ -11,7 +11,8 @@ namespace z80
uint32_t step();
uint8_t *getMem();
uint8_t *getRegs();
uint16_t getAF(const bool alt=false);
uint16_t getBC(const bool alt=false);
uint16_t getDE(const bool alt=false);

View File

@@ -3,6 +3,7 @@
#include "z80.h"
#include "z80dis.h"
#include "zx_ula.h"
#include "zx_tape.h"
namespace z80debug
{
#define CHR_W 6
@@ -421,16 +422,33 @@ namespace z80debug
int address = getnum(cmd);
if (address<0 || address>65536) { strcpy(console_error, "Illegal memory address"); return; }
mem_viewer_pos = address;
} else if (strcmp(cmd, "st")==0 || strcmp(cmd, "save")==0) {
getcmd();
char filename[256];
strcpy(filename, cmd);
savestate(filename);
} else if (strcmp(cmd, "l")==0 || strcmp(cmd, "load")==0) {
getcmd();
char filename[256];
strcpy(filename, cmd);
//getcmd();
//char address[256];
//strcpy(address, cmd);
//loadngo(filename, address);
loadstate(filename);
} else if (strcmp(cmd, "t")==0 || strcmp(cmd, "tape")==0) {
getcmd();
char address[256];
strcpy(address, cmd);
loadngo(filename, address);
}
}
if (strcmp(cmd, "load")==0) {
getcmd();
char filename[256];
strcpy(filename, cmd);
zx_tape::load(filename);
} else if (strcmp(cmd, "play")==0) {
zx_tape::play();
}
}
}
const bool isbreak(const uint16_t address, const uint8_t type)
{
@@ -465,4 +483,24 @@ namespace z80debug
z80::setPC(address);
is_debugging = false;
}
void savestate(const char *filename)
{
uint8_t *regs = z80::getRegs();
uint8_t *memory = z80::getMem();
FILE *f = fopen(filename, "wb");
fwrite(regs, 31, 1, f);
fwrite(&memory[16*1024], 48*1024, 1, f);
fclose(f);
}
void loadstate(const char *filename)
{
uint8_t *regs = z80::getRegs();
uint8_t *memory = z80::getMem();
FILE *f = fopen(filename, "rb");
fread(regs, 31, 1, f);
fread(&memory[16*1024], 48*1024, 1, f);
fclose(f);
}
}

View File

@@ -18,5 +18,7 @@ namespace z80debug
const bool isbreak(const uint16_t address, const uint8_t type=1);
uint32_t next();
void savestate(const char *filename);
void loadstate(const char *filename);
void loadngo(const char* filename, const char* addr);
}

View File

@@ -85,7 +85,7 @@ namespace zxscreen
{
if (win) return;
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 296, SDL_WINDOW_SHOWN);
ren = SDL_CreateRenderer(win, -1, 0);
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 296);
create_tables();
redraw();

View File

@@ -1,6 +1,8 @@
#include "zx_ula.h"
#include <SDL2/SDL.h>
#define AUDIO_BUFFER_SIZE 2048
namespace zx_ula
{
#define KEY_SHIFT 0
@@ -218,17 +220,22 @@ namespace zx_ula
SDL_AudioDeviceID sdlAudioDevice;
uint8_t sound_buffer[1024];
uint16_t sound_pos;
uint8_t sound_buffer[AUDIO_BUFFER_SIZE];
uint16_t sound_pos=0;
uint16_t sound_start=0;
uint16_t t_sound=0;
void audioCallback(void * userdata, uint8_t * stream, int len)
{
const uint16_t top = sound_pos < len ? sound_pos : len;
printf("top: %i, len: %i, pos: %i\n", top, len, sound_pos);
memcpy(stream, sound_buffer, top);
if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
if (top<sound_pos)
//const uint16_t top = sound_pos < len ? sound_pos : len;
//if (top<len) printf("top: %i, len: %i, pos: %i\n", top, len, sound_pos);
//memcpy(stream, sound_buffer, top);
for (int i=0;i<len;++i)
{
stream[i] = sound_buffer[(sound_start++)&(AUDIO_BUFFER_SIZE-1)];
}
//if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
/*if (top<sound_pos)
{
if (last_1>top)
{
@@ -244,12 +251,12 @@ namespace zx_ula
else
{
sound_pos=last_1=0;
}
}*/
}
void sound_init()
{
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE>>2, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
sound_enable();
}
@@ -267,22 +274,15 @@ namespace zx_ula
void sound_update(const uint8_t dt)
{
t_sound += dt;
if (t_sound>=316) {
t_sound-=316;
if (t_sound>=317) {
t_sound-=317;
//sound_pos = (sound_pos+1) & 0x3ff;
//sound_buffer[sound_pos] = ear*128;
if (sound_pos<1024)
{
sound_buffer[sound_pos++] = ear*128;
if (ear) last_1 = sound_pos;
}
else
{
//for now, drop then buffer
sound_pos = last_1 = 0;
//printf("WARNING! Sound buffer overflow!\n");
}
//if (sound_pos>=AUDIO_BUFFER_SIZE) sound_pos = last_1 = 0;
sound_buffer[(sound_pos++)&(AUDIO_BUFFER_SIZE-1)] = ear*128;
//if (ear) last_1 = sound_pos;
}
}
}