- [CHG] Més neteja de basura
- [FIX] Intentant arreglar un "pop" que fa el só al inici, he descobert que no fa falta més sincronització que la del àudio! - [CHG] De fet, ara en compte de fer 20 cicles de cpu cada iteració, faig un cicle per iteració i nomes refresque events cada 125ms. No detecte canvis, pero seria molt més net. A vore que tal. - [NEW] Comence la classe directora "gameboy"
This commit is contained in:
+5
-4
@@ -1,6 +1,6 @@
|
|||||||
#include "apu.h"
|
#include "apu.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
//#include "audio_viewer.h"
|
|
||||||
namespace apu
|
namespace apu
|
||||||
{
|
{
|
||||||
#define SAMPLING_FREQ 44100
|
#define SAMPLING_FREQ 44100
|
||||||
@@ -10,9 +10,7 @@ namespace apu
|
|||||||
SDL_AudioDeviceID sdlAudioDevice;
|
SDL_AudioDeviceID sdlAudioDevice;
|
||||||
uint8_t sound_buffer[AUDIO_BUFFER_SIZE];
|
uint8_t sound_buffer[AUDIO_BUFFER_SIZE];
|
||||||
uint16_t sound_pos=0;
|
uint16_t sound_pos=0;
|
||||||
uint16_t sound_start=0;
|
|
||||||
float t_sound = 0.0f;
|
float t_sound = 0.0f;
|
||||||
uint32_t samples_generated=0;
|
|
||||||
|
|
||||||
#define CH1 channels[0]
|
#define CH1 channels[0]
|
||||||
#define CH2 channels[1]
|
#define CH2 channels[1]
|
||||||
@@ -87,9 +85,11 @@ namespace apu
|
|||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
for (int i=0; i<AUDIO_BUFFER_SIZE; ++i) sound_buffer[i] = 128;
|
||||||
SDL_AudioSpec audioSpec{SAMPLING_FREQ, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE, 0, 0, NULL, NULL};
|
SDL_AudioSpec audioSpec{SAMPLING_FREQ, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE, 0, 0, NULL, NULL};
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||||
resume();
|
resume();
|
||||||
|
SDL_QueueAudio(sdlAudioDevice, sound_buffer, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
@@ -428,7 +428,8 @@ namespace apu
|
|||||||
if (sound_pos>=1000) {
|
if (sound_pos>=1000) {
|
||||||
SDL_QueueAudio(sdlAudioDevice, sound_buffer, sound_pos);
|
SDL_QueueAudio(sdlAudioDevice, sound_buffer, sound_pos);
|
||||||
sound_pos = 0;
|
sound_pos = 0;
|
||||||
while (SDL_GetQueuedAudioSize(sdlAudioDevice) > 4096 ) {}
|
while (SDL_GetQueuedAudioSize(sdlAudioDevice) > 4096 ) { SDL_Delay(1); }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#include "gameboy.h"
|
||||||
|
|
||||||
|
gameboy::gameboy(const std::string &rom_file)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gameboy::~gameboy()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void gameboy::step()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class gameboy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
gameboy(const std::string &rom_file);
|
||||||
|
~gameboy();
|
||||||
|
|
||||||
|
void step();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
+17
-11
@@ -108,9 +108,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
time = SDL_GetTicks();
|
time = SDL_GetTicks();
|
||||||
t_states = 0;
|
t_states = 0;
|
||||||
|
uint8_t wait = 125;
|
||||||
while (!should_exit)
|
while (!should_exit)
|
||||||
{
|
{
|
||||||
|
if (wait==0) {
|
||||||
while (SDL_PollEvent(&e))
|
while (SDL_PollEvent(&e))
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
@@ -175,10 +176,11 @@ int main(int argc, char *argv[])
|
|||||||
if (!result)
|
if (!result)
|
||||||
should_exit = true; break;
|
should_exit = true; break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!debug::debugging() && !debug::paused()) {
|
if (!debug::debugging() && !debug::paused()) {
|
||||||
// En cada pas de bucle fem 10 pasos de la CPU, sino s'ofega
|
// En cada pas de bucle fem 10 pasos de la CPU, sino s'ofega
|
||||||
for (int i=0;i<20;++i) {
|
//for (int i=0;i<20;++i) {
|
||||||
if (debug::isbreak(sm83::getPC(), 9)) {
|
if (debug::isbreak(sm83::getPC(), 9)) {
|
||||||
debug::stop();
|
debug::stop();
|
||||||
display::redraw();
|
display::redraw();
|
||||||
@@ -186,11 +188,10 @@ int main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
uint8_t dt = sm83::step();
|
uint8_t dt = sm83::step();
|
||||||
t_states += dt;
|
t_states += dt;
|
||||||
//zx_ula::sound_update(dt);
|
|
||||||
ppu::refresh(dt);
|
ppu::refresh(dt);
|
||||||
if (debug::debugging()) break;
|
if (debug::debugging()) break;
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Sincronització:
|
// Sincronització:
|
||||||
// la frequència del rellotge diu quants t_states pot executar per segon.
|
// la frequència del rellotge diu quants t_states pot executar per segon.
|
||||||
@@ -198,12 +199,12 @@ int main(int argc, char *argv[])
|
|||||||
// pot executar cada 125 ms. Ací comprobem si ja havem executat eixe nombre
|
// pot executar cada 125 ms. Ací comprobem si ja havem executat eixe nombre
|
||||||
// de t_states i, si ho havem fet, esperem fins que passen 125ms des de l'ultima
|
// de t_states i, si ho havem fet, esperem fins que passen 125ms des de l'ultima
|
||||||
// vegada que ho comprobarem.
|
// vegada que ho comprobarem.
|
||||||
if (t_states>=update_freq)
|
//if (t_states>=update_freq)
|
||||||
{
|
//{
|
||||||
while (SDL_GetTicks()<(time+125)) {}
|
// while (SDL_GetTicks()<(time+125)) {}
|
||||||
t_states -= update_freq;
|
// t_states -= update_freq;
|
||||||
time = SDL_GetTicks();
|
// time = SDL_GetTicks();
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
} else if (!debug::debugging() && debug::paused()) {
|
} else if (!debug::debugging() && debug::paused()) {
|
||||||
@@ -211,7 +212,12 @@ int main(int argc, char *argv[])
|
|||||||
ui::menu::show();
|
ui::menu::show();
|
||||||
display::present();
|
display::present();
|
||||||
}
|
}
|
||||||
ui::setClicked(false);
|
if (wait == 0) {
|
||||||
|
ui::setClicked(false);
|
||||||
|
wait = 125;
|
||||||
|
} else {
|
||||||
|
wait--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+1
-7
@@ -552,13 +552,7 @@ namespace sm83
|
|||||||
halted = true;
|
halted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*if (exit_from_halt) {
|
rPC--;
|
||||||
exit_from_halt = false;
|
|
||||||
halted = false;
|
|
||||||
} else {*/
|
|
||||||
//printf("HALT\n");
|
|
||||||
rPC--;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void STOP()
|
void STOP()
|
||||||
|
|||||||
Reference in New Issue
Block a user