- [NEW] Minim makefile

- [NEW] Sound stops while debugging
- [CHG] Now all sound related code is in the zx_ula module
This commit is contained in:
2024-04-17 22:41:29 +02:00
parent 9f67286779
commit e80de06d2c
5 changed files with 46 additions and 28 deletions

2
Makefile Normal file
View File

@@ -0,0 +1,2 @@
default:
g++ -g *.cpp -lSDL2 -o z80

View File

@@ -8,8 +8,6 @@
#include <SDL2/SDL.h>
#include <string.h>
SDL_AudioDeviceID sdlAudioDevice;
uint8_t memory[65536];
uint32_t t = 0;
uint16_t ts = 0;
@@ -17,20 +15,6 @@ uint8_t ft = 0;
uint32_t fps=0;
uint32_t fps_time=0;
uint8_t sound_buffer[1024];
uint16_t sound_pos;
void audioCallback(void * userdata, uint8_t * stream, int len)
{
uint16_t top = len;
if (sound_pos < len)
{
top = sound_pos;
//printf("buffer underrun!\n");
}
memcpy(stream, sound_buffer, top);
sound_pos=0;
}
uint8_t test = 0;
@@ -47,9 +31,7 @@ int main(int argc, char *argv[])
z80debug::show();
zxscreen::show();
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
SDL_PauseAudioDevice(sdlAudioDevice, 0);
zx_ula::sound_init();
bool should_exit = false;
SDL_Event e;
@@ -112,13 +94,7 @@ int main(int argc, char *argv[])
ts += t_states;
if (ts>=400) {
ts-=400;
uint8_t ear = zx_ula::get_ear();
//if (ear)
sound_buffer[sound_pos++] = ear*128;
//SDL_QueueAudio(sdlAudioDevice, &beep[ear], 1);
//else
//SDL_ClearQueuedAudio(sdlAudioDevice);
zx_ula::sound_update();
}
if (t>=69888) {
ft++;

View File

@@ -82,8 +82,8 @@ namespace z80debug
z80debug::refresh();
}
void stop() { is_debugging = true; breakpoints[z80::getPC()] &= ~8; refresh(); }
void cont() { is_debugging = false; refresh();}
void stop() { zx_ula::sound_disable(); is_debugging = true; breakpoints[z80::getPC()] &= ~8; refresh(); }
void cont() { is_debugging = false; refresh(); zx_ula::sound_enable(); }
const bool debugging() { return is_debugging; }
void box(int x, int y, int w, int h, uint8_t color)

View File

@@ -97,4 +97,39 @@ namespace zx_ula
uint8_t get_border_color() { return border_color; }
uint8_t get_ear() { return ear; }
SDL_AudioDeviceID sdlAudioDevice;
uint8_t sound_buffer[1024];
uint16_t sound_pos;
void audioCallback(void * userdata, uint8_t * stream, int len)
{
const uint16_t top = sound_pos < len ? sound_pos : len;
memcpy(stream, sound_buffer, top);
sound_pos=0;
}
void sound_init()
{
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
}
void sound_enable()
{
SDL_PauseAudioDevice(sdlAudioDevice, 0);
}
void sound_disable()
{
SDL_PauseAudioDevice(sdlAudioDevice, 1);
}
void sound_update()
{
sound_buffer[sound_pos++] = ear*128;
}
}

View File

@@ -9,4 +9,9 @@ namespace zx_ula
uint8_t get_border_color();
uint8_t get_ear();
void sound_init();
void sound_enable();
void sound_disable();
void sound_update();
}