- [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:
28
main.cpp
28
main.cpp
@@ -8,8 +8,6 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
SDL_AudioDeviceID sdlAudioDevice;
|
|
||||||
|
|
||||||
uint8_t memory[65536];
|
uint8_t memory[65536];
|
||||||
uint32_t t = 0;
|
uint32_t t = 0;
|
||||||
uint16_t ts = 0;
|
uint16_t ts = 0;
|
||||||
@@ -17,20 +15,6 @@ uint8_t ft = 0;
|
|||||||
uint32_t fps=0;
|
uint32_t fps=0;
|
||||||
uint32_t fps_time=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;
|
uint8_t test = 0;
|
||||||
|
|
||||||
@@ -47,9 +31,7 @@ int main(int argc, char *argv[])
|
|||||||
z80debug::show();
|
z80debug::show();
|
||||||
zxscreen::show();
|
zxscreen::show();
|
||||||
|
|
||||||
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
|
zx_ula::sound_init();
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
|
||||||
|
|
||||||
bool should_exit = false;
|
bool should_exit = false;
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
@@ -112,13 +94,7 @@ int main(int argc, char *argv[])
|
|||||||
ts += t_states;
|
ts += t_states;
|
||||||
if (ts>=400) {
|
if (ts>=400) {
|
||||||
ts-=400;
|
ts-=400;
|
||||||
uint8_t ear = zx_ula::get_ear();
|
zx_ula::sound_update();
|
||||||
//if (ear)
|
|
||||||
sound_buffer[sound_pos++] = ear*128;
|
|
||||||
//SDL_QueueAudio(sdlAudioDevice, &beep[ear], 1);
|
|
||||||
//else
|
|
||||||
//SDL_ClearQueuedAudio(sdlAudioDevice);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (t>=69888) {
|
if (t>=69888) {
|
||||||
ft++;
|
ft++;
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ namespace z80debug
|
|||||||
z80debug::refresh();
|
z80debug::refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop() { is_debugging = true; breakpoints[z80::getPC()] &= ~8; refresh(); }
|
void stop() { zx_ula::sound_disable(); is_debugging = true; breakpoints[z80::getPC()] &= ~8; refresh(); }
|
||||||
void cont() { is_debugging = false; refresh();}
|
void cont() { is_debugging = false; refresh(); zx_ula::sound_enable(); }
|
||||||
const bool debugging() { return is_debugging; }
|
const bool debugging() { return is_debugging; }
|
||||||
|
|
||||||
void box(int x, int y, int w, int h, uint8_t color)
|
void box(int x, int y, int w, int h, uint8_t color)
|
||||||
|
|||||||
35
zx_ula.cpp
35
zx_ula.cpp
@@ -97,4 +97,39 @@ namespace zx_ula
|
|||||||
|
|
||||||
uint8_t get_border_color() { return border_color; }
|
uint8_t get_border_color() { return border_color; }
|
||||||
uint8_t get_ear() { return ear; }
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user