- [FIX] la cpu ja actualitza el registre R com toca

- [FIX] EI no activa les interrupcions fins a després de la següent instrucció, like in real life
- [FIX] actualitzar el offset de la UI després de usar el debugger
- [ONGOING] Depurant el jittering del só. Ara executa 10 instruccions de CPu per cada bucle, per a que vaja mes apresa i no es retrase el cheneraor de só
- Afegit el TAP de Las Tres Luces de Glaurung pa provar
This commit is contained in:
2024-12-04 13:12:58 +01:00
parent 486bd648d3
commit e0bb34052f
5 changed files with 39 additions and 8 deletions

BIN
glaurung.tap Normal file

Binary file not shown.

View File

@@ -172,25 +172,29 @@ int main(int argc, char *argv[])
zxscreen::redraw(); zxscreen::redraw();
} else { } else {
//if (z80::getPC()==0x05C8) zx_tape::go_berserk(); //if (z80::getPC()==0x05C8) zx_tape::go_berserk();
uint8_t dt = z80::step();
t_states += dt;
zx_tape::update(dt);
while (zx_tape::getplaying() && zx_tape::getberserk()) while (zx_tape::getplaying() && zx_tape::getberserk())
{ {
zx_tape::update(z80::step()); zx_tape::update(z80::step());
} }
// En cada bucle fem 10 pasos de la CPU, sino s'ofega
for (int i=0;i<10;++i) {
uint8_t dt = z80::step();
t_states += dt;
zx_tape::update(dt);
zx_ula::sound_update(dt); zx_ula::sound_update(dt);
zxscreen::refresh(dt); zxscreen::refresh(dt);
}
if (t_states>=3500000) if (t_states>=350000)
{ {
//if (SDL_GetTicks()>=time+1000) //if (SDL_GetTicks()>=time+1000)
//printf("%i\n", SDL_GetTicks()-(time+1000)); //printf("%i\n", SDL_GetTicks()-(time+1000));
//else //else
// printf("%i\n", SDL_GetTicks()-(time+1000)); // printf("%i\n", SDL_GetTicks()-(time+1000));
//t_states = 0; //t_states = 0;
//printf("%i: %i\n", SDL_GetTicks()-(time+1000), t_states);
while (SDL_GetTicks()<time+100) {} while (SDL_GetTicks()<time+100) {}
t_states -= 350000; t_states -= 350000;
time = SDL_GetTicks(); time = SDL_GetTicks();

1
ui.cpp
View File

@@ -43,6 +43,7 @@ namespace ui
if (tex) SDL_DestroyTexture(tex); if (tex) SDL_DestroyTexture(tex);
tex = SDL_CreateTextureFromSurface(ren, surf); tex = SDL_CreateTextureFromSurface(ren, surf);
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
offset_x = offset_y = 0;
} }
void setoffset(uint8_t x, uint8_t y) void setoffset(uint8_t x, uint8_t y)

10
z80.cpp
View File

@@ -88,6 +88,7 @@ namespace z80
//uint8_t iff1, iff2, im; //uint8_t iff1, iff2, im;
bool exit_from_halt = false; bool exit_from_halt = false;
int pending_ei = 0;
#define rA (*_rA) #define rA (*_rA)
#define rF (*_rF) #define rF (*_rF)
@@ -683,6 +684,11 @@ namespace z80
} }
void EI() void EI()
{
pending_ei=1;
}
void actualEI()
{ {
iff1 = iff2 = 1; iff1 = iff2 = 1;
} }
@@ -1328,6 +1334,9 @@ namespace z80
case 0xFE: CP(READ_MEM_8()); break; case 0xFE: CP(READ_MEM_8()); break;
case 0xFF: RST(0x38); break; case 0xFF: RST(0x38); break;
} }
if (pending_ei==2) { pending_ei=0; actualEI(); }
if (pending_ei==1) pending_ei=2;
return t; return t;
} }
@@ -2115,6 +2124,7 @@ namespace z80
void MISC_INSTRUCTIONS() void MISC_INSTRUCTIONS()
{ {
const uint8_t opcode = READ_M1(); const uint8_t opcode = READ_M1();
rR = (rR&0x80) + ((rR+1) & 0x7f);
uint16_t tmp; uint16_t tmp;
switch (opcode) switch (opcode)

View File

@@ -224,6 +224,9 @@ namespace zx_ula
uint16_t sound_pos=0; uint16_t sound_pos=0;
uint16_t sound_start=0; uint16_t sound_start=0;
uint16_t t_sound=0; uint16_t t_sound=0;
uint32_t samples_generated=0;
uint32_t samples_time =0;
uint32_t samples_t=0;
void audioCallback(void * userdata, uint8_t * stream, int len) void audioCallback(void * userdata, uint8_t * stream, int len)
{ {
@@ -259,6 +262,7 @@ namespace zx_ula
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE>>2, 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); sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
sound_enable(); sound_enable();
samples_time=SDL_GetTicks();
} }
void sound_enable() void sound_enable()
@@ -274,8 +278,20 @@ namespace zx_ula
void sound_update(const uint8_t dt) void sound_update(const uint8_t dt)
{ {
t_sound += dt; t_sound += dt;
samples_t += dt;
if (t_sound>=317) { if (t_sound>=317) {
t_sound-=317; t_sound-=317;
samples_generated++;
if (samples_t >=3500000) {
printf("%i\n", samples_generated);
samples_generated=0;
samples_t = 0;
}
/*if (SDL_GetTicks()>=samples_time+1000) {
printf("%i\n", samples_generated);
samples_generated=0;
samples_time = SDL_GetTicks();
}*/
//sound_pos = (sound_pos+1) & 0x3ff; //sound_pos = (sound_pos+1) & 0x3ff;
//sound_buffer[sound_pos] = ear*128; //sound_buffer[sound_pos] = ear*128;