- [NEW] EAR getter in the ULA module
- [NEW] Flash attribute implemented - [NEW] Sound somewhat working (BEEP hangs)
This commit is contained in:
53
main.cpp
53
main.cpp
@@ -8,8 +8,31 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string.h>
|
||||
|
||||
SDL_AudioDeviceID sdlAudioDevice;
|
||||
|
||||
uint8_t memory[65536];
|
||||
uint32_t t = 0;
|
||||
uint16_t ts = 0;
|
||||
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;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -24,6 +47,10 @@ 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);
|
||||
|
||||
bool should_exit = false;
|
||||
SDL_Event e;
|
||||
|
||||
@@ -48,6 +75,8 @@ int main(int argc, char *argv[])
|
||||
} else if (e.key.keysym.scancode==SDL_SCANCODE_F5) {
|
||||
z80::step();
|
||||
z80debug::cont();
|
||||
fps=0;
|
||||
fps_time = SDL_GetTicks();
|
||||
zxscreen::refresh();
|
||||
} else if (e.key.keysym.scancode==SDL_SCANCODE_RETURN) {
|
||||
z80debug::executeConsole();
|
||||
@@ -72,8 +101,30 @@ int main(int argc, char *argv[])
|
||||
z80debug::stop();
|
||||
zxscreen::refresh();
|
||||
} else {
|
||||
t += z80::step();
|
||||
uint8_t t_states = z80::step();
|
||||
t += t_states;
|
||||
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);
|
||||
|
||||
}
|
||||
if (t>=69888) {
|
||||
ft++;
|
||||
if (ft==16) { ft=0; zxscreen::flash(); }
|
||||
/*
|
||||
fps++;
|
||||
if (SDL_GetTicks() - fps_time >= 1000) {
|
||||
printf("FPS: %i\n", fps);
|
||||
fps = 0;
|
||||
fps_time = SDL_GetTicks();
|
||||
}
|
||||
*/
|
||||
t=0;
|
||||
zxscreen::refresh();
|
||||
z80::interrupt();
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace zxscreen
|
||||
SDL_Renderer *ren = nullptr;
|
||||
SDL_Texture *tex = nullptr;
|
||||
|
||||
bool _flash = false;
|
||||
|
||||
void flash() { _flash = not _flash; }
|
||||
|
||||
void show()
|
||||
{
|
||||
if (win) return;
|
||||
@@ -48,9 +52,11 @@ namespace zxscreen
|
||||
|
||||
uint16_t address = 0x4000 | (x&0x1f) | ((y&0x7)<<8) | ((y&0x38)<<2) | ((y&0xc0)<<5);
|
||||
uint8_t block = memory[address];
|
||||
uint8_t c1 = color&0x7, c2 = (color>>3)&0x7;
|
||||
if ((color&0x80) && _flash) { c1=c2; c2=color&0x7; }
|
||||
for (int i=0;i<8;++i)
|
||||
{
|
||||
*(pixels++)=(block&0x80) ? palette[color&0x7] : palette[(color>>3)&0x7];
|
||||
*(pixels++)=(block&0x80) ? palette[c1] : palette[c2];
|
||||
block = block<<1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ namespace zxscreen
|
||||
{
|
||||
void show();
|
||||
void refresh();
|
||||
void flash();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,9 @@ namespace zx_ula
|
||||
border_color = val & 0x7;
|
||||
mic = (val>>3)&0x1;
|
||||
ear = (val>>4)&0x1;
|
||||
//printf("EAR:%i MIC:%i\n", ear, mic);
|
||||
}
|
||||
|
||||
uint8_t get_border_color() { return border_color; }
|
||||
uint8_t get_ear() { return ear; }
|
||||
}
|
||||
Reference in New Issue
Block a user