From bfd9957c81a7e6e0e4133c221d0527c47296ce85 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 6 Jan 2016 21:09:49 -0500 Subject: [PATCH] =?UTF-8?q?You=20now=20get=20an=20Electron=20only=20if=20y?= =?UTF-8?q?ou=20ask=20for=20a=20new=20file.=20That'll=20do=20for=20now=20w?= =?UTF-8?q?hile=20it's=20the=20only=20thing=20that=20one=20might=20want=20?= =?UTF-8?q?to=20start=20without=20supplying=20a=20file.=20The=206502=20now?= =?UTF-8?q?=20starts=20from=20a=20defined=20point=20=E2=80=94=20being=20re?= =?UTF-8?q?set.=20The=20Electron=20is=20starting=20to=20grow=20the=20absol?= =?UTF-8?q?ute=20most=20simple=20buds=20of=20its=20memory=20map.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Machines/Electron/Electron.cpp | 38 +++++++++++++++++++ Machines/Electron/Electron.hpp | 9 +++++ OSBindings/Mac/Clock Signal/AppDelegate.swift | 7 ++-- Processors/6502/CPU6502.hpp | 5 +++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 808bff52b..6d8a0fd2c 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -8,10 +8,13 @@ #include "Electron.hpp" +#include + using namespace Electron; Machine::Machine() { + setup6502(); } Machine::~Machine() @@ -20,5 +23,40 @@ Machine::~Machine() unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { + if(address < 32768) + { + if(isReadOperation(operation)) + { + *value = ram[address]; + } + else + { + ram[address] = *value; + } + } + else + { + if(address > 49152) + { + if(isReadOperation(operation)) *value = os[address - 49152]; + } + else + { + if(isReadOperation(operation)) *value = basic[address - 32768]; + } + } + return 1; } + +void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) +{ + uint8_t *target = nullptr; + switch(slot) + { + case ROMTypeBASIC: target = basic; break; + case ROMTypeOS: target = os; break; + } + + memcpy(target, data, std::min((size_t)16384, length)); +} diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index 23f5930c7..82ab352e3 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -16,6 +16,11 @@ namespace Electron { +enum ROMSlot: int { + ROMTypeBASIC = 12, + ROMTypeOS = 16, +}; + class Machine: public CPU6502::Processor { public: @@ -25,6 +30,10 @@ class Machine: public CPU6502::Processor { unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); + void set_rom(ROMSlot slot, size_t length, const uint8_t *data); + + private: + uint8_t os[16384], basic[16384], ram[32768]; }; } diff --git a/OSBindings/Mac/Clock Signal/AppDelegate.swift b/OSBindings/Mac/Clock Signal/AppDelegate.swift index 2abf97a3a..2286db90e 100644 --- a/OSBindings/Mac/Clock Signal/AppDelegate.swift +++ b/OSBindings/Mac/Clock Signal/AppDelegate.swift @@ -11,8 +11,6 @@ import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - - func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application } @@ -21,6 +19,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { // Insert code here to tear down your application } - + // decline to open a new file unless the user explicitly requests it + func applicationShouldOpenUntitledFile(sender: NSApplication) -> Bool { + return false + } } diff --git a/Processors/6502/CPU6502.hpp b/Processors/6502/CPU6502.hpp index 3c420e0a0..2411bc30b 100644 --- a/Processors/6502/CPU6502.hpp +++ b/Processors/6502/CPU6502.hpp @@ -946,6 +946,11 @@ template class Processor { _overflowFlag &= Flag::Overflow; _s = 0; _nextBusOperation = BusOperation::None; + + // TODO: is this accurate? It feels more likely that a CPU would need to wait + // on an explicit reset command, since the relative startup times of different + // components from power on would be a bit unpredictable. + schedule_program(get_reset_program()); } void return_from_subroutine()