From 977f3042f08a091dca07a2616d54794461628f5f Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Wed, 4 Nov 2009 17:41:54 +0000 Subject: [PATCH] Implement some of the sound stuff (not working) --- Src/Network.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ Src/Network.h | 12 +++++++++++- Src/SID.cpp | 10 ++++++++++ Src/SID_linux.h | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Src/Network.cpp b/Src/Network.cpp index ebb94af..c599c28 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -77,6 +77,10 @@ Network::Network(const char *remote_host, int port) this->screen = (Uint8 *)malloc(DISPLAY_X * DISPLAY_Y); assert(this->screen); + this->sound_head = this->sound_tail = 0; + memset(this->sound_active, 0, sizeof(this->sound_active)); + memset(this->sound_network, 0, sizeof(this->sound_network)); + /* Assume black screen */ memset(this->screen, 0, DISPLAY_X * DISPLAY_Y); memset(this->screenshot, 0, sizeof(this->screenshot)); @@ -397,6 +401,44 @@ void Network::EncodeTextMessage(char *str) } +static int bytes = 0; +void Network::PushSound(uint8 adr, uint8 val) +{ + NetworkUpdateSoundInfo *cur = &this->sound_active[this->sound_head]; + + cur->adr = adr; + cur->val = val; + cur->delay_cycles = TheC64->CycleCounter - sound_last_cycles; + + /* Update the cycle counter */ + sound_last_cycles = TheC64->CycleCounter; + this->sound_head++; + + if (this->sound_head >= NETWORK_SOUND_BUF_SIZE) + this->sound_head = 0; + if (this->sound_head >= this->sound_tail) + this->sound_tail = (this->sound_head + 1) % NETWORK_SOUND_BUF_SIZE; + bytes += 3; +} + +void Network::FlushSound(void) +{ + struct NetworkUpdate *dst = this->cur_ud; + struct NetworkUpdateSound *snd = (NetworkUpdateSound *)dst->data; + struct NetworkUpdateSoundInfo *snd_info = snd->info; + + static int last_cycles = 0; + + snd->flags = 0; + snd->n_items = 0; + if (SDL_GetTicks() - last_cycles < 125) + return; + printf("Flushing sound (%d bytes in %d ms)\n", bytes, SDL_GetTicks() - last_cycles); + last_cycles = SDL_GetTicks(); + bytes = 0; +} + + void Network::EncodeJoystickUpdate(Uint8 v) { struct NetworkUpdate *dst = this->cur_ud; diff --git a/Src/Network.h b/Src/Network.h index 39a318a..2683f14 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -16,7 +16,7 @@ #define FRODO_NETWORK_MAGIC 0x1976 #define NETWORK_UPDATE_SIZE (256 * 1024) -#define NETWORK_SOUND_BUF_SIZE 4096 +#define NETWORK_SOUND_BUF_SIZE 8192 #define SCREENSHOT_FACTOR 4 #define SCREENSHOT_X (DISPLAY_X / SCREENSHOT_FACTOR) @@ -179,6 +179,10 @@ public: void EncodeTextMessage(char *str); + void PushSound(uint8 addr, uint8 val); + + void FlushSound(void); + bool DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst); @@ -356,6 +360,12 @@ protected: network_connection_state_t network_connection_state; + NetworkUpdateSoundInfo sound_active[NETWORK_SOUND_BUF_SIZE]; + NetworkUpdateSoundInfo sound_network[NETWORK_SOUND_BUF_SIZE]; + int sound_head; + int sound_tail; + uint32 sound_last_cycles; + public: static bool networking_started; }; diff --git a/Src/SID.cpp b/Src/SID.cpp index 64aaa31..bfd8326 100644 --- a/Src/SID.cpp +++ b/Src/SID.cpp @@ -910,11 +910,21 @@ void DigitalRenderer::Reset(void) * Write to register */ +#include "C64.h" +extern C64 *TheC64; + void DigitalRenderer::WriteRegister(uint16 adr, uint8 byte) { if (!ready) return; + if (TheC64) { + if (TheC64->network_connection_type == MASTER) + TheC64->peer->PushSound(adr, byte); + else if (TheC64->network_connection_type == CLIENT) + return; + } + int v = adr/7; // Voice number switch (adr) { diff --git a/Src/SID_linux.h b/Src/SID_linux.h index c2695c4..a4c57b7 100644 --- a/Src/SID_linux.h +++ b/Src/SID_linux.h @@ -144,6 +144,8 @@ void DigitalRenderer::EmulateLine(void) { if (!ready) return; + if (TheC64->network_connection_type == MASTER) + TheC64->peer->FlushSound(); this->PushVolume(volume); }