mirror of
https://github.com/jtauber/applepy.git
synced 2024-11-22 19:30:54 +00:00
PEP8 compliance
This commit is contained in:
parent
d340d9cb5f
commit
934bf1a495
38
applepy.py
38
applepy.py
@ -86,22 +86,22 @@ class Display:
|
||||
]
|
||||
|
||||
lores_colours = [
|
||||
(0, 0, 0), # black
|
||||
(208, 0, 48), # magenta / dark red
|
||||
(0, 0, 128), # dark blue
|
||||
(255, 0, 255), # purple / violet
|
||||
(0, 128, 0), # dark green
|
||||
(128, 128, 128), # gray 1
|
||||
(0, 0, 255), # medium blue / blue
|
||||
(96, 160, 255), # light blue
|
||||
(128, 80, 0), # brown / dark orange
|
||||
(255, 128 ,0), # orange
|
||||
(192, 192, 192), # gray 2
|
||||
(255, 144, 128), # pink / light red
|
||||
(0, 255, 0), # light green / green
|
||||
(255, 255, 0), # yellow / light orange
|
||||
(64, 255, 144), # aquamarine / light green
|
||||
(255, 255, 255), # white
|
||||
(0, 0, 0), # black
|
||||
(208, 0, 48), # magenta / dark red
|
||||
(0, 0, 128), # dark blue
|
||||
(255, 0, 255), # purple / violet
|
||||
(0, 128, 0), # dark green
|
||||
(128, 128, 128), # gray 1
|
||||
(0, 0, 255), # medium blue / blue
|
||||
(96, 160, 255), # light blue
|
||||
(128, 80, 0), # brown / dark orange
|
||||
(255, 128, 0), # orange
|
||||
(192, 192, 192), # gray 2
|
||||
(255, 144, 128), # pink / light red
|
||||
(0, 255, 0), # light green / green
|
||||
(255, 255, 0), # yellow / light orange
|
||||
(64, 255, 144), # aquamarine / light green
|
||||
(255, 255, 255), # white
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@ -175,7 +175,7 @@ class Display:
|
||||
base = address - start_text
|
||||
self.flash_chars[self.page - 1][base] = value
|
||||
hi, lo = divmod(base, 0x80)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row = hi + 8 * row_group
|
||||
|
||||
if row_group == 3:
|
||||
@ -213,7 +213,7 @@ class Display:
|
||||
base = address - start_hires
|
||||
row8, b = divmod(base, 0x400)
|
||||
hi, lo = divmod(b, 0x80)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row = 8 * (hi + 8 * row_group) + row8
|
||||
|
||||
if self.mix and row >= 160:
|
||||
@ -358,7 +358,7 @@ class SoftSwitches:
|
||||
if self.cassette:
|
||||
return self.cassette.read_byte(cycle)
|
||||
else:
|
||||
pass # print "%04X" % address
|
||||
pass # print "%04X" % address
|
||||
return 0x00
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ kbd = 0
|
||||
def write_screen(win, address, value):
|
||||
base = address - 0x400
|
||||
hi, lo = divmod(base, 0x80)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row = hi + 8 * row_group
|
||||
|
||||
# skip if writing to row group 3
|
||||
@ -68,7 +68,7 @@ def run(win):
|
||||
"--rom", options.rom,
|
||||
]
|
||||
|
||||
p = subprocess.Popen(args)
|
||||
subprocess.Popen(args)
|
||||
cpu, _ = listener.accept()
|
||||
|
||||
win.clear()
|
||||
|
14
control.py
14
control.py
@ -1,16 +1,18 @@
|
||||
import json
|
||||
import readline
|
||||
import sys
|
||||
import urllib
|
||||
|
||||
URL_PREFIX = "http://localhost:6502"
|
||||
|
||||
|
||||
def get(url):
|
||||
return json.loads(urllib.urlopen(URL_PREFIX + url).read())
|
||||
|
||||
|
||||
def post(url, data=None):
|
||||
return urllib.urlopen(URL_PREFIX + url, json.dumps(data) if data is not None else "")
|
||||
|
||||
|
||||
def value(s):
|
||||
if s.startswith("$"):
|
||||
return int(s[1:], 16)
|
||||
@ -18,6 +20,7 @@ def value(s):
|
||||
return int(s[2:], 16)
|
||||
return int(s)
|
||||
|
||||
|
||||
def format_disassemble(dis):
|
||||
r = "%04X- " % dis["address"]
|
||||
for i in range(3):
|
||||
@ -32,6 +35,7 @@ def format_disassemble(dis):
|
||||
r += "[%04X] = %0*X" % tuple(dis["memory"])
|
||||
return r
|
||||
|
||||
|
||||
def cmd_disassemble(a):
|
||||
"""Disassemble"""
|
||||
if len(a) > 1:
|
||||
@ -43,6 +47,7 @@ def cmd_disassemble(a):
|
||||
for d in disasm:
|
||||
print format_disassemble(d)
|
||||
|
||||
|
||||
def cmd_dump(a):
|
||||
"""Dump memory"""
|
||||
start = value(a[1])
|
||||
@ -78,6 +83,7 @@ def cmd_dump(a):
|
||||
print s
|
||||
addr += 16
|
||||
|
||||
|
||||
def cmd_help(a):
|
||||
"""Help commands"""
|
||||
if len(a) > 1:
|
||||
@ -91,18 +97,21 @@ def cmd_help(a):
|
||||
for c in sorted(Commands):
|
||||
print " ", c
|
||||
|
||||
|
||||
def cmd_peek(a):
|
||||
"""Peek memory location"""
|
||||
addr = value(a[1])
|
||||
dump = get("/memory/%d" % addr)
|
||||
print "%04X: %02X" % (addr, dump[0])
|
||||
|
||||
|
||||
def cmd_poke(a):
|
||||
"""Poke memory location"""
|
||||
addr = value(a[1])
|
||||
val = value(a[2])
|
||||
post("/memory/%d" % addr, [val])
|
||||
|
||||
|
||||
def cmd_status(a):
|
||||
"""CPU status"""
|
||||
status = get("/status")
|
||||
@ -123,10 +132,12 @@ def cmd_status(a):
|
||||
disasm = get("/disassemble/%d" % status["program_counter"])
|
||||
print format_disassemble(disasm[0])
|
||||
|
||||
|
||||
def cmd_quit(a):
|
||||
"""Quit"""
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def cmd_reset(a):
|
||||
"""Reset"""
|
||||
post("/reset")
|
||||
@ -142,6 +153,7 @@ Commands = {
|
||||
"reset": cmd_reset,
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
print "ApplePy control console"
|
||||
while True:
|
||||
|
11
cpu6502.py
11
cpu6502.py
@ -714,7 +714,7 @@ class CPU:
|
||||
|
||||
count = 1000
|
||||
while count > 0 and self.running:
|
||||
self.cycles += 2 # all instructions take this as a minimum
|
||||
self.cycles += 2 # all instructions take this as a minimum
|
||||
op = self.read_pc_byte()
|
||||
func = self.ops[op]
|
||||
if func is None:
|
||||
@ -729,7 +729,7 @@ class CPU:
|
||||
def test_run(self, start, end):
|
||||
self.program_counter = start
|
||||
while True:
|
||||
self.cycles += 2 # all instructions take this as a minimum
|
||||
self.cycles += 2 # all instructions take this as a minimum
|
||||
if self.program_counter == end:
|
||||
break
|
||||
op = self.read_pc_byte()
|
||||
@ -948,7 +948,7 @@ class CPU:
|
||||
else:
|
||||
self.cycles += 2
|
||||
self.carry_flag = self.read_byte(operand_address) % 2
|
||||
self.write_byte(operand_address, self.update_nz(self.read_byte(operand_address) >> 1))
|
||||
self.write_byte(operand_address, self.update_nz(self.read_byte(operand_address) >> 1))
|
||||
|
||||
# JUMPS / RETURNS
|
||||
|
||||
@ -1128,8 +1128,8 @@ class CPU:
|
||||
|
||||
def BIT(self, operand_address):
|
||||
value = self.read_byte(operand_address)
|
||||
self.sign_flag = ((value >> 7) % 2) # bit 7
|
||||
self.overflow_flag = ((value >> 6) % 2) # bit 6
|
||||
self.sign_flag = ((value >> 7) % 2) # bit 7
|
||||
self.overflow_flag = ((value >> 6) % 2) # bit 6
|
||||
self.zero_flag = [0, 1][((self.accumulator & value) == 0)]
|
||||
|
||||
# COMPARISON
|
||||
@ -1166,7 +1166,6 @@ class CPU:
|
||||
self.status_from_byte(self.pull_byte())
|
||||
self.program_counter = self.pull_word()
|
||||
|
||||
|
||||
# @@@ IRQ
|
||||
# @@@ NMI
|
||||
|
||||
|
36
tests.py
36
tests.py
@ -355,7 +355,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.accumulator = 0x7F
|
||||
self.memory.write_byte(None, 0x1000, 0x01)
|
||||
self.cpu.ADC(0x1000)
|
||||
self.assertEqual(self.cpu.accumulator, 0x80) # @@@
|
||||
self.assertEqual(self.cpu.accumulator, 0x80) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 0)
|
||||
self.assertEqual(self.cpu.overflow_flag, 1)
|
||||
|
||||
@ -364,7 +364,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.accumulator = 0x80
|
||||
self.memory.write_byte(None, 0x1000, 0xFF)
|
||||
self.cpu.ADC(0x1000)
|
||||
self.assertEqual(self.cpu.accumulator, 0x7F) # @@@
|
||||
self.assertEqual(self.cpu.accumulator, 0x7F) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.assertEqual(self.cpu.overflow_flag, 1)
|
||||
|
||||
@ -390,7 +390,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.SBC(0x1000)
|
||||
self.assertEqual(self.cpu.accumulator, 0xFF)
|
||||
self.assertEqual(self.cpu.carry_flag, 0)
|
||||
self.assertEqual(self.cpu.overflow_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.overflow_flag, 0) # @@@
|
||||
|
||||
## test cases from http://www.6502.org/tutorials/vflag.html
|
||||
|
||||
@ -401,7 +401,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.SBC(0x1000)
|
||||
self.assertEqual(self.cpu.accumulator, 0xFF)
|
||||
self.assertEqual(self.cpu.carry_flag, 0)
|
||||
self.assertEqual(self.cpu.overflow_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.overflow_flag, 0) # @@@
|
||||
|
||||
# -128 - 1 = -129 (V = 1)
|
||||
self.cpu.carry_flag = 1
|
||||
@ -428,7 +428,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.SBC(0x1000)
|
||||
self.assertEqual(self.cpu.accumulator, 0x7F)
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.assertEqual(self.cpu.overflow_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.overflow_flag, 1) # @@@
|
||||
|
||||
## @@@ BCD versions still to do
|
||||
|
||||
@ -464,7 +464,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.accumulator = 0x0A
|
||||
self.memory.write_byte(None, 0x1000, 0xA0)
|
||||
self.cpu.CMP(0x1000)
|
||||
self.assertEqual(self.cpu.sign_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.sign_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0)
|
||||
self.assertEqual(self.cpu.carry_flag, 0)
|
||||
|
||||
@ -500,7 +500,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.x_index = 0x0A
|
||||
self.memory.write_byte(None, 0x1000, 0xA0)
|
||||
self.cpu.CPX(0x1000)
|
||||
self.assertEqual(self.cpu.sign_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.sign_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0)
|
||||
self.assertEqual(self.cpu.carry_flag, 0)
|
||||
|
||||
@ -536,7 +536,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
self.cpu.y_index = 0x0A
|
||||
self.memory.write_byte(None, 0x1000, 0xA0)
|
||||
self.cpu.CPY(0x1000)
|
||||
self.assertEqual(self.cpu.sign_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.sign_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0)
|
||||
self.assertEqual(self.cpu.carry_flag, 0)
|
||||
|
||||
@ -709,21 +709,21 @@ class TestShiftOperations(unittest.TestCase):
|
||||
self.cpu.ROL()
|
||||
self.assertEqual(self.cpu.accumulator, 0x01)
|
||||
self.assertEqual(self.cpu.sign_flag, 0)
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.cpu.carry_flag = 0
|
||||
self.memory.write_byte(None, 0x1000, 0x80)
|
||||
self.cpu.ROL(0x1000)
|
||||
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
|
||||
self.assertEqual(self.cpu.sign_flag, 0)
|
||||
self.assertEqual(self.cpu.zero_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.cpu.carry_flag = 1
|
||||
self.memory.write_byte(None, 0x1000, 0x80)
|
||||
self.cpu.ROL(0x1000)
|
||||
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x01)
|
||||
self.assertEqual(self.cpu.sign_flag, 0)
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
|
||||
def test_ROR(self):
|
||||
@ -732,28 +732,28 @@ class TestShiftOperations(unittest.TestCase):
|
||||
self.cpu.ROR()
|
||||
self.assertEqual(self.cpu.accumulator, 0x00)
|
||||
self.assertEqual(self.cpu.sign_flag, 0)
|
||||
self.assertEqual(self.cpu.zero_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.cpu.carry_flag = 1
|
||||
self.cpu.accumulator = 0x01
|
||||
self.cpu.ROR()
|
||||
self.assertEqual(self.cpu.accumulator, 0x80)
|
||||
self.assertEqual(self.cpu.sign_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.sign_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.cpu.carry_flag = 0
|
||||
self.memory.write_byte(None, 0x1000, 0x01)
|
||||
self.cpu.ROR(0x1000)
|
||||
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
|
||||
self.assertEqual(self.cpu.sign_flag, 0)
|
||||
self.assertEqual(self.cpu.zero_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
self.cpu.carry_flag = 1
|
||||
self.memory.write_byte(None, 0x1000, 0x01)
|
||||
self.cpu.ROR(0x1000)
|
||||
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x80)
|
||||
self.assertEqual(self.cpu.sign_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.sign_flag, 1) # @@@
|
||||
self.assertEqual(self.cpu.zero_flag, 0) # @@@
|
||||
self.assertEqual(self.cpu.carry_flag, 1)
|
||||
|
||||
|
||||
@ -786,7 +786,7 @@ class TestJumpCallOperations(unittest.TestCase):
|
||||
self.cpu.JSR(0x2000)
|
||||
self.assertEqual(self.cpu.program_counter, 0x2000)
|
||||
self.cpu.RTS()
|
||||
self.assertEqual(self.cpu.program_counter, 0x1000) # @@@
|
||||
self.assertEqual(self.cpu.program_counter, 0x1000) # @@@
|
||||
|
||||
|
||||
class TestBranchOperations(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user