From f3e0cef4418b7ed4d8db9024894cdb538c31b946 Mon Sep 17 00:00:00 2001 From: James Tauber Date: Sat, 13 Aug 2011 09:47:18 -0400 Subject: [PATCH] refactored memory so RAM just subclasses ROM, adding write_byte --- applepy.py | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/applepy.py b/applepy.py index 6497e91..d6ffc93 100644 --- a/applepy.py +++ b/applepy.py @@ -238,28 +238,31 @@ class Display: del pixels -class RAM: +class ROM: def __init__(self, start, size): self.start = start self.end = start + size - 1 - self.__mem = [0x00] * size + self._mem = [0x00] * size def load(self, address, data): for offset, datum in enumerate(data): - self.__mem[address - self.start + offset] = datum + self._mem[address - self.start + offset] = datum def load_file(self, address, filename): with open(filename) as f: for offset, datum in enumerate(f.read()): - self.__mem[address - self.start + offset] = ord(datum) + self._mem[address - self.start + offset] = ord(datum) def read_byte(self, address): assert self.start <= address <= self.end - return self.__mem[address - self.start] + return self._mem[address - self.start] + + +class RAM(ROM): def write_byte(self, address, value): - self.__mem[address] = value + self._mem[address] = value class SoftSwitches: @@ -297,27 +300,6 @@ class SoftSwitches: return 0x00 -class ROM: - - def __init__(self, start, size): - self.start = start - self.end = start + size - 1 - self.__mem = [0x00] * size - - def load(self, address, data): - for offset, datum in enumerate(data): - self.__mem[address - self.start + offset] = datum - - def load_file(self, address, filename): - with open(filename) as f: - for offset, datum in enumerate(f.read()): - self.__mem[address - self.start + offset] = ord(datum) - - def read_byte(self, address): - assert self.start <= address <= self.end - return self.__mem[address - self.start] - - class Memory: def __init__(self, display=None): @@ -757,7 +739,7 @@ class CPU: self.ops[0xF9] = lambda: self.SBC(self.absolute_y_mode()) self.ops[0xFD] = lambda: self.SBC(self.absolute_x_mode()) self.ops[0xFE] = lambda: self.INC(self.absolute_x_mode()) - + def reset(self): self.program_counter = self.memory.read_word(self.RESET_VECTOR)