- Treballant en que funcione al temps correcte

- Treballant en el só
This commit is contained in:
2024-12-01 21:50:20 +01:00
parent 7eb5df248f
commit 7cb6ae527b
2 changed files with 51 additions and 6 deletions

View File

@@ -10,6 +10,8 @@
#include <string.h> #include <string.h>
uint8_t memory[65536]; uint8_t memory[65536];
uint32_t time = 0;
uint32_t t_states = 0;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -26,13 +28,16 @@ int main(int argc, char *argv[])
zx_ula::sound_init(); zx_ula::sound_init();
zx_tape::load("manic.tap"); zx_tape::load("abusimbel.tap");
if (argc==3) { z80debug::loadngo(argv[1], argv[2]); } if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
bool should_exit = false; bool should_exit = false;
SDL_Event e; SDL_Event e;
time = SDL_GetTicks();
t_states = 0;
while (!should_exit) while (!should_exit)
{ {
while (SDL_PollEvent(&e)) while (SDL_PollEvent(&e))
@@ -83,16 +88,25 @@ int main(int argc, char *argv[])
} }
} }
} }
if (!z80debug::debugging()) { if (!z80debug::debugging()) {
if (z80debug::isbreak(z80::getPC(), 9)) { if (z80debug::isbreak(z80::getPC(), 9)) {
z80debug::stop(); z80debug::stop();
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(); uint8_t dt = z80::step();
t_states += dt;
zx_tape::update(dt); zx_tape::update(dt);
zx_ula::sound_update(dt); zx_ula::sound_update(dt);
zxscreen::refresh(dt); zxscreen::refresh(dt);
if (t_states>=350000)
{
while (SDL_GetTicks()<time+100) {}
t_states -= 350000;
time = SDL_GetTicks();
}
} }
} }
} }

View File

@@ -57,6 +57,8 @@ namespace zx_ula
static uint8_t ear = 0; static uint8_t ear = 0;
static uint8_t mic = 0; static uint8_t mic = 0;
static uint16_t last_1 = 0;
void update_zx_keyboard() void update_zx_keyboard()
{ {
const uint8_t *keys = SDL_GetKeyboardState(NULL); const uint8_t *keys = SDL_GetKeyboardState(NULL);
@@ -220,15 +222,33 @@ namespace zx_ula
void audioCallback(void * userdata, uint8_t * stream, int len) void audioCallback(void * userdata, uint8_t * stream, int len)
{ {
const uint16_t top = sound_pos < len ? sound_pos : 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); memcpy(stream, sound_buffer, top);
if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top); if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
sound_pos=0; if (top<sound_pos)
{
if (last_1>top)
{
memcpy(sound_buffer, &sound_buffer[top], sound_pos-top);
sound_pos=sound_pos-top;
last_1=last_1-top;
}
else
{
sound_pos=last_1=0;
}
}
else
{
sound_pos=last_1=0;
}
} }
void sound_init() void sound_init()
{ {
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL}; SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0); sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
sound_enable();
} }
void sound_enable() void sound_enable()
@@ -244,9 +264,20 @@ namespace zx_ula
void sound_update(const uint8_t dt) void sound_update(const uint8_t dt)
{ {
t_sound += dt; t_sound += dt;
if (t_sound>=317) { if (t_sound>=318) {
t_sound-=317; t_sound-=318;
//sound_pos = (sound_pos+1) & 0x3ff;
//sound_buffer[sound_pos] = ear*128;
if (sound_pos<1024)
{
sound_buffer[sound_pos++] = ear*128; sound_buffer[sound_pos++] = ear*128;
if (ear) last_1 = sound_pos;
}
/*else
{
printf("WARNING! Sound buffer overflow!\n");
}*/
} }
} }
} }