Demarshal and marshal data, use linecnt for delay

This commit is contained in:
simon.kagstrom 2009-11-06 06:31:06 +00:00
parent e65c29ed4c
commit 6d79aaee12
4 changed files with 34 additions and 9 deletions

View File

@ -327,8 +327,7 @@ void MOS6510::write_byte_io(uint16 adr, uint8 byte)
case 0x5:
case 0x6:
case 0x7:
if (this->network_connection_type != CLIENT)
TheSID->WriteRegister(adr & 0x1f, byte);
TheSID->WriteRegister(adr & 0x1f, byte);
return;
case 0x8: // Color RAM
case 0x9:

View File

@ -402,16 +402,16 @@ void Network::EncodeTextMessage(char *str)
static int bytes = 0;
void Network::PushSound(uint8 adr, uint8 val)
void Network::PushSound(uint32 linecnt, 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;
cur->delay_cycles = linecnt - sound_last_cycles;
/* Update the cycle counter */
sound_last_cycles = TheC64->CycleCounter;
sound_last_cycles = linecnt;
this->sound_head++;
if (this->sound_head >= NETWORK_SOUND_BUF_SIZE)
@ -650,7 +650,6 @@ bool Network::MarshalData(NetworkUpdate *p)
case DISPLAY_UPDATE_RAW:
case DISPLAY_UPDATE_RLE:
case DISPLAY_UPDATE_DIFF:
case SOUND_UPDATE:
case JOYSTICK_UPDATE:
case DISCONNECT:
case CONNECT_TO_PEER:
@ -695,6 +694,20 @@ bool Network::MarshalData(NetworkUpdate *p)
pi->key = htons(pi->key);
pi->version = htonl(pi->version);
} break;
case SOUND_UPDATE:
{
NetworkUpdateSound *snd = (NetworkUpdateSound *)p->data;
NetworkUpdateSoundInfo *info = (NetworkUpdateSoundInfo *)snd->info;
snd->flags = htons(snd->flags);
snd->n_items = htons(snd->flags);
for (unsigned int i = 0; i < snd->n_items; i++)
{
NetworkUpdateSoundInfo *cur = &info[i];
cur->delay_cycles = htons(cur->delay_cycles);
}
}
default:
/* Unknown data... */
fprintf(stderr, "Got unknown data %d while marshalling. Something is wrong\n",
@ -741,7 +754,6 @@ bool Network::DeMarshalData(NetworkUpdate *p)
case DISPLAY_UPDATE_RAW:
case DISPLAY_UPDATE_RLE:
case DISPLAY_UPDATE_DIFF:
case SOUND_UPDATE:
case JOYSTICK_UPDATE:
case DISCONNECT:
case CONNECT_TO_PEER:
@ -779,6 +791,20 @@ bool Network::DeMarshalData(NetworkUpdate *p)
}
lp->your_port = ntohs(lp->your_port);
} break;
case SOUND_UPDATE:
{
NetworkUpdateSound *snd = (NetworkUpdateSound *)p->data;
NetworkUpdateSoundInfo *info = (NetworkUpdateSoundInfo *)snd->info;
snd->flags = ntohs(snd->flags);
snd->n_items = ntohs(snd->flags);
for (unsigned int i = 0; i < snd->n_items; i++)
{
NetworkUpdateSoundInfo *cur = &info[i];
cur->delay_cycles = ntohs(cur->delay_cycles);
}
}
default:
/* Unknown data... */
printf("Got unknown data: %d\n", p->type);

View File

@ -179,7 +179,7 @@ public:
void EncodeTextMessage(char *str);
void PushSound(uint8 addr, uint8 val);
void PushSound(uint32 linecnt, uint8 addr, uint8 val);
void FlushSound(void);

View File

@ -921,7 +921,7 @@ void DigitalRenderer::WriteRegister(uint16 adr, uint8 byte)
if (TheC64) {
if (TheC64->network_connection_type == MASTER)
TheC64->peer->PushSound(adr, byte);
TheC64->peer->PushSound(this->linecnt, adr, byte);
else if (TheC64->network_connection_type == CLIENT)
return;
}