1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Commutes Vic-20 machine configuration options to its Target.

This commit is contained in:
Thomas Harte 2018-03-26 19:01:57 -04:00
parent 8067bf548a
commit a2da51c30b
3 changed files with 24 additions and 62 deletions

View File

@ -22,7 +22,16 @@ struct Target: public ::Analyser::Static::Target {
ThirtyTwoKB ThirtyTwoKB
}; };
enum class Region {
American,
Danish,
Japanese,
European,
Swedish
};
MemoryModel memory_model = MemoryModel::Unexpanded; MemoryModel memory_model = MemoryModel::Unexpanded;
Region region = Region::European;
bool has_c1540 = false; bool has_c1540 = false;
}; };

View File

@ -368,24 +368,12 @@ class ConcreteMachine:
} }
void configure_as_target(const Analyser::Static::Target *target) override final { void configure_as_target(const Analyser::Static::Target *target) override final {
auto *const commodore_target = dynamic_cast<const Analyser::Static::Commodore::Target *>(target); commodore_target_ = *dynamic_cast<const Analyser::Static::Commodore::Target *>(target);
if(target->loading_command.length()) { if(target->loading_command.length()) {
type_string(target->loading_command); type_string(target->loading_command);
} }
switch(commodore_target->memory_model) {
case Analyser::Static::Commodore::Target::MemoryModel::Unexpanded:
set_memory_size(Default);
break;
case Analyser::Static::Commodore::Target::MemoryModel::EightKB:
set_memory_size(ThreeKB);
break;
case Analyser::Static::Commodore::Target::MemoryModel::ThirtyTwoKB:
set_memory_size(ThirtyTwoKB);
break;
}
if(target->media.disks.size()) { if(target->media.disks.size()) {
// construct the 1540 // construct the 1540
c1540_.reset(new ::Commodore::C1540::Machine(Commodore::C1540::Machine::C1540)); c1540_.reset(new ::Commodore::C1540::Machine(Commodore::C1540::Machine::C1540));
@ -439,16 +427,6 @@ class ConcreteMachine:
return joysticks_; return joysticks_;
} }
void set_memory_size(MemorySize size) override final {
memory_size_ = size;
needs_configuration_ = true;
}
void set_region(Region region) override final {
region_ = region;
needs_configuration_ = true;
}
void set_ntsc_6560() { void set_ntsc_6560() {
set_clock_rate(1022727); set_clock_rate(1022727);
if(mos6560_) { if(mos6560_) {
@ -465,9 +443,9 @@ class ConcreteMachine:
} }
} }
void configure_memory() { void set_memory_map(Analyser::Static::Commodore::Target::MemoryModel memory_model, Analyser::Static::Commodore::Target::Region region) {
// Determine PAL/NTSC // Determine PAL/NTSC
if(region_ == American || region_ == Japanese) { if(region == Analyser::Static::Commodore::Target::Region::American || region == Analyser::Static::Commodore::Target::Region::Japanese) {
// NTSC // NTSC
set_ntsc_6560(); set_ntsc_6560();
} else { } else {
@ -479,13 +457,14 @@ class ConcreteMachine:
memset(processor_write_memory_map_, 0, sizeof(processor_write_memory_map_)); memset(processor_write_memory_map_, 0, sizeof(processor_write_memory_map_));
memset(mos6560_->video_memory_map, 0, sizeof(mos6560_->video_memory_map)); memset(mos6560_->video_memory_map, 0, sizeof(mos6560_->video_memory_map));
switch(memory_size_) { switch(memory_model) {
default: break; default: break;
case ThreeKB: case Analyser::Static::Commodore::Target::MemoryModel::EightKB:
// TODO: is this 3kb or 8kb?
write_to_map(processor_read_memory_map_, expansion_ram_, 0x0000, 0x1000); write_to_map(processor_read_memory_map_, expansion_ram_, 0x0000, 0x1000);
write_to_map(processor_write_memory_map_, expansion_ram_, 0x0000, 0x1000); write_to_map(processor_write_memory_map_, expansion_ram_, 0x0000, 0x1000);
break; break;
case ThirtyTwoKB: case Analyser::Static::Commodore::Target::MemoryModel::ThirtyTwoKB:
write_to_map(processor_read_memory_map_, expansion_ram_, 0x0000, 0x8000); write_to_map(processor_read_memory_map_, expansion_ram_, 0x0000, 0x8000);
write_to_map(processor_write_memory_map_, expansion_ram_, 0x0000, 0x8000); write_to_map(processor_write_memory_map_, expansion_ram_, 0x0000, 0x8000);
break; break;
@ -508,24 +487,24 @@ class ConcreteMachine:
ROM character_rom; ROM character_rom;
ROM kernel_rom; ROM kernel_rom;
switch(region_) { switch(region) {
default: default:
character_rom = CharactersEnglish; character_rom = CharactersEnglish;
kernel_rom = KernelPAL; kernel_rom = KernelPAL;
break; break;
case American: case Analyser::Static::Commodore::Target::Region::American:
character_rom = CharactersEnglish; character_rom = CharactersEnglish;
kernel_rom = KernelNTSC; kernel_rom = KernelNTSC;
break; break;
case Danish: case Analyser::Static::Commodore::Target::Region::Danish:
character_rom = CharactersDanish; character_rom = CharactersDanish;
kernel_rom = KernelDanish; kernel_rom = KernelDanish;
break; break;
case Japanese: case Analyser::Static::Commodore::Target::Region::Japanese:
character_rom = CharactersJapanese; character_rom = CharactersJapanese;
kernel_rom = KernelJapanese; kernel_rom = KernelJapanese;
break; break;
case Swedish: case Analyser::Static::Commodore::Target::Region::Swedish:
character_rom = CharactersSwedish; character_rom = CharactersSwedish;
kernel_rom = KernelSwedish; kernel_rom = KernelSwedish;
break; break;
@ -648,10 +627,6 @@ class ConcreteMachine:
} }
void run_for(const Cycles cycles) override final { void run_for(const Cycles cycles) override final {
if(needs_configuration_) {
needs_configuration_ = false;
configure_memory();
}
m6502_.run_for(cycles); m6502_.run_for(cycles);
} }
@ -659,7 +634,7 @@ class ConcreteMachine:
mos6560_.reset(new Vic6560()); mos6560_.reset(new Vic6560());
mos6560_->set_high_frequency_cutoff(1600); // There is a 1.6Khz low-pass filter in the Vic-20. mos6560_->set_high_frequency_cutoff(1600); // There is a 1.6Khz low-pass filter in the Vic-20.
// Make a guess: PAL. Without setting a clock rate the 6560 isn't fully set up so contractually something must be set. // Make a guess: PAL. Without setting a clock rate the 6560 isn't fully set up so contractually something must be set.
set_pal_6560(); set_memory_map(commodore_target_.memory_model, commodore_target_.region);
} }
void close_output() override final { void close_output() override final {
@ -718,6 +693,8 @@ class ConcreteMachine:
} }
private: private:
Analyser::Static::Commodore::Target commodore_target_;
CPU::MOS6502::Processor<ConcreteMachine, false> m6502_; CPU::MOS6502::Processor<ConcreteMachine, false> m6502_;
std::vector<uint8_t> roms_[9]; std::vector<uint8_t> roms_[9];
@ -748,10 +725,6 @@ class ConcreteMachine:
} }
} }
Region region_ = European;
MemorySize memory_size_ = MemorySize::Default;
bool needs_configuration_ = true;
Commodore::Vic20::KeyboardMapper keyboard_mapper_; Commodore::Vic20::KeyboardMapper keyboard_mapper_;
std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_; std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_;

View File

@ -14,20 +14,6 @@
namespace Commodore { namespace Commodore {
namespace Vic20 { namespace Vic20 {
enum MemorySize {
Default,
ThreeKB,
ThirtyTwoKB
};
enum Region {
American,
Danish,
Japanese,
European,
Swedish
};
/// @returns The options available for a Vic-20. /// @returns The options available for a Vic-20.
std::vector<std::unique_ptr<Configurable::Option>> get_options(); std::vector<std::unique_ptr<Configurable::Option>> get_options();
@ -37,12 +23,6 @@ class Machine {
/// Creates and returns a Vic-20. /// Creates and returns a Vic-20.
static Machine *Vic20(); static Machine *Vic20();
/// Sets the memory size of this Vic-20.
virtual void set_memory_size(MemorySize size) = 0;
/// Sets the region of this Vic-20.
virtual void set_region(Region region) = 0;
}; };
} }