mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2025-04-21 03:51:37 +02:00
Also handle the client (well, a bit)
This commit is contained in:
parent
6d79aaee12
commit
22fad7d05b
@ -401,31 +401,39 @@ void Network::EncodeTextMessage(char *str)
|
||||
}
|
||||
|
||||
|
||||
static int bytes = 0;
|
||||
void Network::PushSound(uint32 linecnt, uint8 adr, uint8 val)
|
||||
void Network::EnqueueSound(uint32 linecnt_diff, uint8 adr, uint8 val)
|
||||
{
|
||||
NetworkUpdateSoundInfo *cur = &this->sound_active[this->sound_head];
|
||||
|
||||
cur->adr = adr;
|
||||
cur->val = val;
|
||||
cur->delay_cycles = linecnt - sound_last_cycles;
|
||||
cur->delay_cycles = linecnt_diff;
|
||||
|
||||
/* Update the cycle counter */
|
||||
sound_last_cycles = linecnt;
|
||||
this->sound_head++;
|
||||
|
||||
if (this->sound_head >= NETWORK_SOUND_BUF_SIZE)
|
||||
this->sound_head = 0;
|
||||
|
||||
/* Head has reached tail */
|
||||
if (this->sound_head >= this->sound_tail)
|
||||
this->sound_tail = (this->sound_head + 1) % NETWORK_SOUND_BUF_SIZE;
|
||||
bytes += 3;
|
||||
}
|
||||
|
||||
static int bytes = 0;
|
||||
void Network::RegisterSidWrite(uint32 linecnt, uint8 adr, uint8 val)
|
||||
{
|
||||
this->EnqueueSound(linecnt - this->sound_last_cycles, adr, val);
|
||||
|
||||
/* Update the cycle counter */
|
||||
sound_last_cycles = linecnt;
|
||||
bytes += sizeof(NetworkUpdateSound);
|
||||
}
|
||||
|
||||
void Network::FlushSound(void)
|
||||
{
|
||||
struct NetworkUpdate *dst = this->cur_ud;
|
||||
struct NetworkUpdateSound *snd = (NetworkUpdateSound *)dst->data;
|
||||
struct NetworkUpdateSoundInfo *snd_info = snd->info;
|
||||
NetworkUpdate *dst = this->cur_ud;
|
||||
NetworkUpdateSound *snd = (NetworkUpdateSound *)dst->data;
|
||||
NetworkUpdateSoundInfo *snd_info = snd->info;
|
||||
|
||||
snd->flags = 0;
|
||||
snd->n_items = this->sound_head - this->sound_tail;
|
||||
@ -443,9 +451,9 @@ void Network::FlushSound(void)
|
||||
memcpy(snd_info, &this->sound_active[this->sound_head],
|
||||
(this->sound_head - this->sound_tail) * sizeof(struct NetworkUpdateSoundInfo));
|
||||
}
|
||||
this->sound_tail = (this->sound_tail + snd->n_items) % NETWORK_SOUND_BUF_SIZE;
|
||||
|
||||
/* Reset the buffer again */
|
||||
this->sound_head = this->sound_tail = 0;
|
||||
printf("Flushing sound (%d bytes in %d ms)\n", bytes, SDL_GetTicks() - this->sound_last_send);
|
||||
this->sound_last_send = SDL_GetTicks();
|
||||
|
||||
@ -456,11 +464,10 @@ void Network::FlushSound(void)
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
struct NetworkUpdateSoundInfo *Network::UnqueueSound()
|
||||
struct NetworkUpdateSoundInfo *Network::DequeueSound()
|
||||
{
|
||||
struct NetworkUpdateSoundInfo *out;
|
||||
|
||||
|
||||
if (this->sound_tail == this->sound_head)
|
||||
return NULL;
|
||||
out = &this->sound_active[this->sound_tail];
|
||||
@ -707,7 +714,7 @@ bool Network::MarshalData(NetworkUpdate *p)
|
||||
|
||||
cur->delay_cycles = htons(cur->delay_cycles);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
/* Unknown data... */
|
||||
fprintf(stderr, "Got unknown data %d while marshalling. Something is wrong\n",
|
||||
|
@ -179,11 +179,13 @@ public:
|
||||
|
||||
void EncodeTextMessage(char *str);
|
||||
|
||||
void PushSound(uint32 linecnt, uint8 addr, uint8 val);
|
||||
void EnqueueSound(uint32 linecnt, uint8 addr, uint8 val);
|
||||
|
||||
void RegisterSidWrite(uint32 linecnt, uint8 addr, uint8 val);
|
||||
|
||||
void FlushSound(void);
|
||||
|
||||
struct NetworkUpdateSoundInfo *UnqueueSound();
|
||||
struct NetworkUpdateSoundInfo *DequeueSound();
|
||||
|
||||
|
||||
bool DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst);
|
||||
|
@ -921,7 +921,7 @@ void DigitalRenderer::WriteRegister(uint16 adr, uint8 byte)
|
||||
|
||||
if (TheC64) {
|
||||
if (TheC64->network_connection_type == MASTER)
|
||||
TheC64->peer->PushSound(this->linecnt, adr, byte);
|
||||
TheC64->peer->RegisterSidWrite(this->linecnt, adr, byte);
|
||||
else if (TheC64->network_connection_type == CLIENT)
|
||||
return;
|
||||
}
|
||||
|
@ -149,6 +149,24 @@ void DigitalRenderer::EmulateLine(void)
|
||||
if (TheC64->network_connection_type == MASTER &&
|
||||
this->linecnt % 2048 == 0)
|
||||
TheC64->peer->FlushSound();
|
||||
else if (TheC64->network_connection_type == CLIENT)
|
||||
{
|
||||
static NetworkUpdateSoundInfo *cur = NULL;
|
||||
|
||||
if (!cur)
|
||||
cur = TheC64->peer->DequeueSound();
|
||||
|
||||
while (cur) {
|
||||
printf("Delaying for %d cycles\n", cur->delay_cycles);
|
||||
cur->delay_cycles--;
|
||||
if (cur->delay_cycles > 0)
|
||||
break;
|
||||
/* Delayed long enough - write to the SID! */
|
||||
printf("Writing %02x:%02x\n", cur->adr, cur->val);
|
||||
this->WriteRegister(cur->adr, cur->val);
|
||||
cur = TheC64->peer->DequeueSound();
|
||||
}
|
||||
}
|
||||
this->PushVolume(volume);
|
||||
this->linecnt++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user