From fdc854c0c2aee18ae7b098a7e4523e7a738b9347 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 13 Jun 2016 21:49:59 -0400 Subject: [PATCH] Fixed tone channels; made an attempt at loading PRGs that are supposed to go into RAM. --- Components/6560/6560.cpp | 17 +++++++++++------ Components/6560/6560.hpp | 2 ++ Machines/Vic-20/Vic20.cpp | 11 +++++++++-- Machines/Vic-20/Vic20.hpp | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Components/6560/6560.cpp b/Components/6560/6560.cpp index 182cf8cd3..4d1abce6a 100644 --- a/Components/6560/6560.cpp +++ b/Components/6560/6560.cpp @@ -312,30 +312,32 @@ void MOS6560::set_graphics_value(uint8_t value, uint8_t colour_value) void MOS6560::update_audio() { - _speaker.run_for_cycles(_cycles_since_speaker_update >> 4); - _cycles_since_speaker_update &= 15; + _speaker.run_for_cycles(_cycles_since_speaker_update >> 2); + _cycles_since_speaker_update &= 3; } #pragma mark - Audio -MOS6560Speaker::MOS6560Speaker() +MOS6560Speaker::MOS6560Speaker() : + _volume(0), + _control_registers{0, 0, 0, 0}, + _shift_registers{0, 0, 0, 0}, + _counters{0, 1, 2, 0} { } void MOS6560Speaker::set_volume(uint8_t volume) { _volume = volume; - printf("Volume: %d\n", volume); } void MOS6560Speaker::set_control(int channel, uint8_t value) { _control_registers[channel] = value; - printf("Control %02x: %d\n", channel, value); } #define shift(r) _shift_registers[r] = (uint8_t)((_shift_registers[r] << 1) | (((_shift_registers[r]^0x80)&_control_registers[r]) >> 7)); -#define update(r, m) _counters[r]++; if((_counters[r] >> m) == 0xff) { shift(r); _counters[r] = _control_registers[r]&0x7f; } +#define update(r, m) _counters[r]++; if((_counters[r] >> m) == 0x7f) { shift(r); _counters[r] = _control_registers[r]&0x7f; } void MOS6560Speaker::get_samples(unsigned int number_of_samples, int16_t *target) { @@ -360,3 +362,6 @@ void MOS6560Speaker::skip_samples(unsigned int number_of_samples) update(2, 0); } } + +#undef shift +#undef update diff --git a/Components/6560/6560.hpp b/Components/6560/6560.hpp index b8b66fc85..59a73d8f4 100644 --- a/Components/6560/6560.hpp +++ b/Components/6560/6560.hpp @@ -40,6 +40,8 @@ class MOS6560 { uint16_t get_address(); void set_graphics_value(uint8_t value, uint8_t colour_value); + void synchronise() { update_audio(); } + void set_register(int address, uint8_t value); uint8_t get_register(int address); diff --git a/Machines/Vic-20/Vic20.cpp b/Machines/Vic-20/Vic20.cpp index 1212c589f..5a60dcc1d 100644 --- a/Machines/Vic-20/Vic20.cpp +++ b/Machines/Vic-20/Vic20.cpp @@ -123,7 +123,14 @@ void Machine::add_prg(size_t length, const uint8_t *data) { _rom_address = (uint16_t)(data[0] | (data[1] << 8)); _rom_length = (uint16_t)(length - 2); - _rom = new uint8_t[length - 2]; - memcpy(_rom, &data[2], length - 2); + if(_rom_address >= 0x1000 && _rom_address+_rom_length < 0x2000) + { + memcpy(&_screenMemory[_rom_address - 0x1000], &data[2], length - 2); + } + else + { + _rom = new uint8_t[length - 2]; + memcpy(_rom, &data[2], length - 2); + } } } diff --git a/Machines/Vic-20/Vic20.hpp b/Machines/Vic-20/Vic20.hpp index 3843d392a..6e9e09a85 100644 --- a/Machines/Vic-20/Vic20.hpp +++ b/Machines/Vic-20/Vic20.hpp @@ -100,7 +100,7 @@ class Machine: public CPU6502::Processor, public CRTMachine::Machine, p // to satisfy CPU6502::Processor unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); - void synchronise() {} + void synchronise() { _mos6560->synchronise(); } // to satisfy CRTMachine::Machine virtual void setup_output(float aspect_ratio);