diff --git a/CHANGES.txt b/CHANGES.txt index fdf9ea8..f0a1026 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,8 @@ - Fixed assembling 65C02 opcodes whose mnemonics have a digit such as "RMB3". + - Reformatted source code to comply with PEP8. + 0.13 (2012-11-15) - Fixed a bug where negative numbers could be entered diff --git a/docs/conf.py b/docs/conf.py index 707e8cb..a1c392e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,15 +3,18 @@ # test documentation build configuration file, created by # sphinx-quickstart on Sun Nov 30 14:39:06 2008. # -# This file is execfile()d with the current directory set to its containing dir. +# This file is execfile()d with the current dir set to its containing +# directory. # # The contents of this file are pickled, so don't put values in the namespace -# that aren't pickleable (module imports are okay, they're removed automatically). +# that aren't pickleable (module imports are okay, they're removed +# automatically). # # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys # If your extensions are in another directory, add it here. If the directory # is relative to the documentation root, use os.path.abspath to make it @@ -21,8 +24,8 @@ import sys, os # General configuration # --------------------- -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc'] # Add any paths that contain templates here, relative to this directory. @@ -67,7 +70,8 @@ release = '0.14-dev' # for source files. exclude_trees = [] -# The reST default role (used for this markup: `text`) to use for all documents. +# The reST default role (used for this markup: `text`) to use for all +# documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. @@ -163,10 +167,11 @@ htmlhelp_basename = 'testdoc' #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, document class [howto/manual]). +# (source start file, target name, title, author, document class +# [howto/manual]). latex_documents = [ - ('index', 'test.tex', ur'test Documentation', - ur'foo', 'manual'), + ('index', 'test.tex', ur'test Documentation', + ur'foo', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/py65/assembler.py b/py65/assembler.py index 28a0e65..eca5279 100644 --- a/py65/assembler.py +++ b/py65/assembler.py @@ -2,44 +2,76 @@ import re from py65.devices.mpu6502 import MPU from py65.utils.addressing import AddressParser + class Assembler: Statement = re.compile(r'^([A-z]{3}[0-7]?\s+' r'\(?\s*)([^,\s\)]+)(\s*[,xXyY\s]*\)?' r'[,xXyY\s]*)$') Addressing8 = [ - ['zpi', re.compile(r'^\(\$00([0-9A-F]{2})\)$')], # "($0012)" - ['zpx', re.compile(r'^\$00([0-9A-F]{2}),X$')], # "$0012,X" - ['zpy', re.compile(r'^\$00([0-9A-F]{2}),Y$')], # "$0012,Y" - ['zpg', re.compile(r'^\$00([0-9A-F]{2})$')], # "$0012" - ['inx', re.compile(r'^\(\$00([0-9A-F]{2}),X\)$')], # "($0012,X)" - ['iny', re.compile(r'^\(\$00([0-9A-F]{2})\),Y$')], # "($0012),Y" - ['ind', re.compile(r'^\(\$([0-9A-F]{2})([0-9A-F]{2})\)$')], # "($1234)" - ['abx', re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2}),X$')], # "$1234,X" - ['aby', re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2}),Y$')], # "$1234,Y" - ['abs', re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2})$')], # "$1234" - ['rel', re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2})$')], # "$1234" - ['imp', re.compile(r'^$')], # "" - ['acc', re.compile(r'^$')], # "" - ['acc', re.compile(r'^A$')], # "A" - ['imm', re.compile(r'^#\$([0-9A-F]{2})$')] # "#$12" + ['zpi', # "($0012)" + re.compile(r'^\(\$00([0-9A-F]{2})\)$')], + ['zpx', # "$0012,X" + re.compile(r'^\$00([0-9A-F]{2}),X$')], + ['zpy', # "$0012,Y" + re.compile(r'^\$00([0-9A-F]{2}),Y$')], + ['zpg', # "$0012" + re.compile(r'^\$00([0-9A-F]{2})$')], + ['inx', # "($0012,X) + re.compile(r'^\(\$00([0-9A-F]{2}),X\)$')], + ['iny', # "($0012),Y" + re.compile(r'^\(\$00([0-9A-F]{2})\),Y$')], + ['ind', # "($1234)" + re.compile(r'^\(\$([0-9A-F]{2})([0-9A-F]{2})\)$')], + ['abx', # "$1234,X" + re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2}),X$')], + ['aby', # "$1234,Y" + re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2}),Y$')], + ['abs', # "$1234" + re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2})$')], + ['rel', # "$1234" + re.compile(r'^\$([0-9A-F]{2})([0-9A-F]{2})$')], + ['imp', # "" + re.compile(r'^$')], + ['acc', # "" + re.compile(r'^$')], + ['acc', # "A" + re.compile(r'^A$')], + ['imm', # "#$12" + re.compile(r'^#\$([0-9A-F]{2})$')] ] + Addressing16 = [ - ['zpi', re.compile(r'^\(\$0000([0-9A-F]{4})\)$')], # "($00001234)" - ['zpx', re.compile(r'^\$0000([0-9A-F]{4}),X$')], # "$00001234,X" - ['zpy', re.compile(r'^\$0000([0-9A-F]{4}),Y$')], # "$00001234,Y" - ['zpg', re.compile(r'^\$0000([0-9A-F]{4})$')], # "$00001234" - ['inx', re.compile(r'^\(\$0000([0-9A-F]{4}),X\)$')], # "($00001234,X)" - ['iny', re.compile(r'^\(\$0000([0-9A-F]{4})\),Y$')], # "($00001234),Y" - ['ind', re.compile(r'^\(\$([0-9A-F]{4})([0-9A-F]{4})\)$')], # "($12345678)" - ['abx', re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4}),X$')], # "$12345678,X" - ['aby', re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4}),Y$')], # "$12345678,Y" - ['abs', re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4})$')], # "$12345678" - ['rel', re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4})$')], # "$12345678" - ['imp', re.compile(r'^$')], # "" - ['acc', re.compile(r'^$')], # "" - ['acc', re.compile(r'^A$')], # "A" - ['imm', re.compile(r'^#\$([0-9A-F]{4})$')] # "#$1234" + ['zpi', # "($00001234)" + re.compile(r'^\(\$0000([0-9A-F]{4})\)$')], + ['zpx', # "$00001234,X" + re.compile(r'^\$0000([0-9A-F]{4}),X$')], + ['zpy', # "$00001234,Y" + re.compile(r'^\$0000([0-9A-F]{4}),Y$')], + ['zpg', # "$00001234" + re.compile(r'^\$0000([0-9A-F]{4})$')], + ['inx', # "($00001234,X)" + re.compile(r'^\(\$0000([0-9A-F]{4}),X\)$')], + ['iny', # "($00001234),Y" + re.compile(r'^\(\$0000([0-9A-F]{4})\),Y$')], + ['ind', # "($12345678)" + re.compile(r'^\(\$([0-9A-F]{4})([0-9A-F]{4})\)$')], + ['abx', # "$12345678,X" + re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4}),X$')], + ['aby', # "$12345678,Y" + re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4}),Y$')], + ['abs', # "$12345678" + re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4})$')], + ['rel', # "$12345678" + re.compile(r'^\$([0-9A-F]{4})([0-9A-F]{4})$')], + ['imp', # "" + re.compile(r'^$')], + ['acc', # "" + re.compile(r'^$')], + ['acc', # "A" + re.compile(r'^A$')], + ['imm', # "#$1234" + re.compile(r'^#\$([0-9A-F]{4})$')] ] Addressing = Addressing8 @@ -77,7 +109,7 @@ class Assembler: if match: try: - bytes = [ self._mpu.disassemble.index((opcode, mode)) ] + bytes = [self._mpu.disassemble.index((opcode, mode))] except ValueError: continue @@ -88,13 +120,13 @@ class Assembler: absolute = int(''.join(operands), 16) relative = (absolute - pc) - 2 relative = relative & self.byteMask - operands = [ (self.byteFmt % relative) ] + operands = [(self.byteFmt % relative)] elif len(operands) == 2: # swap bytes operands = (operands[1], operands[0]) - operands = [ int(hex, 16) for hex in operands ] + operands = [int(hex, 16) for hex in operands] bytes.extend(operands) return bytes diff --git a/py65/devices/mpu6502.py b/py65/devices/mpu6502.py index 0067b55..76e101c 100644 --- a/py65/devices/mpu6502.py +++ b/py65/devices/mpu6502.py @@ -1,34 +1,35 @@ from py65.utils.conversions import convert_to_bin, convert_to_bcd, itoa from py65.utils.devices import make_instruction_decorator + class MPU: # vectors ResetTo = 0xfffc - IrqTo = 0xfffe - NMITo = 0xfffa + IrqTo = 0xfffe + NMITo = 0xfffa # processor flags - NEGATIVE = 128 - OVERFLOW = 64 - UNUSED = 32 - BREAK = 16 # there is no BREAK flag, but this position indicates BREAK - DECIMAL = 8 + NEGATIVE = 128 + OVERFLOW = 64 + UNUSED = 32 + BREAK = 16 # there is no actual BREAK flag but this indicates BREAK + DECIMAL = 8 INTERRUPT = 4 - ZERO = 2 - CARRY = 1 + ZERO = 2 + CARRY = 1 - BYTE_WIDTH = 8 + BYTE_WIDTH = 8 BYTE_FORMAT = "%02x" - ADDR_WIDTH = 16 + ADDR_WIDTH = 16 ADDR_FORMAT = "%04x" def __init__(self, memory=None, pc=0x0000): # config self.name = '6502' - self.byteMask = ((1<>self.BYTE_WIDTH)&self.byteMask) - self.stPush(z&self.byteMask) + self.stPush((z >> self.BYTE_WIDTH) & self.byteMask) + self.stPush(z & self.byteMask) def stPopWord(self): z = self.stPop() - z += self.stPop()<> 1 if tbyte: - pass # {} + pass else: self.p |= self.ZERO if x is None: self.a = tbyte else: - self.memory[addr]=tbyte + self.memory[addr] = tbyte def opBCL(self, x): - if self.p & x: - self.pc += 1 - else: - self.BranchRelAddr() + if self.p & x: + self.pc += 1 + else: + self.BranchRelAddr() def opBST(self, x): - if self.p & x: - self.BranchRelAddr() - else: - self.pc += 1 + if self.p & x: + self.BranchRelAddr() + else: + self.pc += 1 def opCLR(self, x): - self.p &=~x + self.p &= ~x def opSET(self, x): self.p |= x @@ -255,10 +255,10 @@ class MPU: def opBIT(self, x): tbyte = self.ByteAt(x()) - self.p &=~(self.ZERO+self.NEGATIVE+self.OVERFLOW) + self.p &= ~(self.ZERO + self.NEGATIVE + self.OVERFLOW) if (self.a & tbyte) == 0: self.p |= self.ZERO - self.p |= tbyte&(self.NEGATIVE+self.OVERFLOW) + self.p |= tbyte & (self.NEGATIVE + self.OVERFLOW) def opROL(self, x): if x is None: @@ -281,7 +281,7 @@ class MPU: self.FlagsNZ(tbyte) if x is None: - self.a = tbyte + self.a = tbyte else: self.memory[addr] = tbyte @@ -314,14 +314,14 @@ class MPU: # the final A contents will be decimally adjusted nibble0 = (nibble0 + adjust0) & 0xf nibble1 = (nibble1 + adjust1) & 0xf - self.p &= ~(self.CARRY+self.OVERFLOW+self.NEGATIVE+self.ZERO) + self.p &= ~(self.CARRY + self.OVERFLOW + self.NEGATIVE + self.ZERO) if aluresult == 0: self.p |= self.ZERO else: self.p |= aluresult & self.NEGATIVE if decimalcarry == 1: self.p |= self.CARRY - if ( ~(self.a ^ data) & (self.a ^ aluresult) ) & self.NEGATIVE: + if (~(self.a ^ data) & (self.a ^ aluresult)) & self.NEGATIVE: self.p |= self.OVERFLOW self.a = (nibble1 << 4) + nibble0 else: @@ -330,13 +330,13 @@ class MPU: else: tmp = 0 result = data + self.a + tmp - self.p &= ~(self.CARRY+self.OVERFLOW+self.NEGATIVE+self.ZERO) - if ( ~(self.a ^ data) & (self.a ^ result) ) & self.NEGATIVE: + self.p &= ~(self.CARRY + self.OVERFLOW + self.NEGATIVE + self.ZERO) + if (~(self.a ^ data) & (self.a ^ result)) & self.NEGATIVE: self.p |= self.OVERFLOW data = result if data > self.byteMask: self.p |= self.CARRY - data &=self.byteMask + data &= self.byteMask if data == 0: self.p |= self.ZERO else: @@ -347,19 +347,19 @@ class MPU: if x is None: tbyte = self.a else: - addr=x() + addr = x() tbyte = self.ByteAt(addr) if self.p & self.CARRY: if tbyte & 1: - pass # {} + pass else: - self.p &=~ self.CARRY - tbyte=(tbyte>>1)|self.NEGATIVE + self.p &= ~self.CARRY + tbyte = (tbyte >> 1) | self.NEGATIVE else: - if tbyte & 1: - self.p |= self.CARRY - tbyte=tbyte>>1 + if tbyte & 1: + self.p |= self.CARRY + tbyte = tbyte >> 1 self.FlagsNZ(tbyte) if x is None: @@ -378,7 +378,7 @@ class MPU: def opCMPR(self, get_address, register_value): tbyte = self.ByteAt(get_address()) - self.p &= ~(self.CARRY+self.ZERO+self.NEGATIVE) + self.p &= ~(self.CARRY + self.ZERO + self.NEGATIVE) if register_value == tbyte: self.p |= self.CARRY + self.ZERO elif register_value > tbyte: @@ -386,59 +386,61 @@ class MPU: self.p |= (register_value - tbyte) & self.NEGATIVE def opSBC(self, x): - data = self.ByteAt(x()) + data = self.ByteAt(x()) - if self.p & self.DECIMAL: - halfcarry = 1 - decimalcarry = 0 - adjust0 = 0 - adjust1 = 0 + if self.p & self.DECIMAL: + halfcarry = 1 + decimalcarry = 0 + adjust0 = 0 + adjust1 = 0 - nibble0 = (self.a & 0xf) + (~data & 0xf) + (self.p & self.CARRY) - if nibble0 <= 0xf: - halfcarry = 0 - adjust0 = 10 - nibble1 = ((self.a >> 4) & 0xf) + ((~data >> 4) & 0xf) + halfcarry - if nibble1 <= 0xf: - adjust1 = 10 << 4 + nibble0 = (self.a & 0xf) + (~data & 0xf) + (self.p & self.CARRY) + if nibble0 <= 0xf: + halfcarry = 0 + adjust0 = 10 + nibble1 = ((self.a >> 4) & 0xf) + ((~data >> 4) & 0xf) + halfcarry + if nibble1 <= 0xf: + adjust1 = 10 << 4 - # the ALU outputs are not decimally adjusted - aluresult = self.a + (~data & self.byteMask) + (self.p & self.CARRY) - if aluresult > self.byteMask: - decimalcarry = 1 - aluresult &= self.byteMask + # the ALU outputs are not decimally adjusted + aluresult = self.a + (~data & self.byteMask) + \ + (self.p & self.CARRY) - # but the final result will be adjusted - nibble0 = (aluresult + adjust0) & 0xf - nibble1 = ((aluresult + adjust1) >> 4) & 0xf + if aluresult > self.byteMask: + decimalcarry = 1 + aluresult &= self.byteMask - self.p &= ~(self.CARRY + self.ZERO + self.NEGATIVE + self.OVERFLOW) - if aluresult == 0: - self.p |= self.ZERO - else: - self.p |= aluresult & self.NEGATIVE - if decimalcarry == 1: - self.p |= self.CARRY - if ( (self.a ^ data) & (self.a ^ aluresult) ) & self.NEGATIVE: - self.p |= self.OVERFLOW - self.a = (nibble1 << 4) + nibble0 - else: - if self.p & self.CARRY: - borrow = 0 - else: - borrow = 1 + # but the final result will be adjusted + nibble0 = (aluresult + adjust0) & 0xf + nibble1 = ((aluresult + adjust1) >> 4) & 0xf - result = self.a + (~data & self.byteMask) + (self.p & self.CARRY) - self.p &= ~(self.CARRY + self.ZERO + self.OVERFLOW + self.NEGATIVE) - if ( (self.a ^ data) & (self.a ^ result) ) & self.NEGATIVE: - self.p |= self.OVERFLOW - data = result & self.byteMask - if data == 0: - self.p |= self.ZERO - if result > self.byteMask: - self.p |= self.CARRY - self.p |= data & self.NEGATIVE - self.a = data + self.p &= ~(self.CARRY + self.ZERO + self.NEGATIVE + self.OVERFLOW) + if aluresult == 0: + self.p |= self.ZERO + else: + self.p |= aluresult & self.NEGATIVE + if decimalcarry == 1: + self.p |= self.CARRY + if ((self.a ^ data) & (self.a ^ aluresult)) & self.NEGATIVE: + self.p |= self.OVERFLOW + self.a = (nibble1 << 4) + nibble0 + else: + if self.p & self.CARRY: + borrow = 0 + else: + borrow = 1 + + result = self.a + (~data & self.byteMask) + (self.p & self.CARRY) + self.p &= ~(self.CARRY + self.ZERO + self.OVERFLOW + self.NEGATIVE) + if ((self.a ^ data) & (self.a ^ result)) & self.NEGATIVE: + self.p |= self.OVERFLOW + data = result & self.byteMask + if data == 0: + self.p |= self.ZERO + if result > self.byteMask: + self.p |= self.CARRY + self.p |= data & self.NEGATIVE + self.a = data def opDECR(self, x): if x is None: @@ -495,8 +497,8 @@ class MPU: def inst_not_implemented(self): self.pc += 1 - instruct = [inst_not_implemented] * 256 - cycletime = [0] * 256 + instruct = [inst_not_implemented] * 256 + cycletime = [0] * 256 extracycles = [0] * 256 disassemble = [('???', 'imp')] * 256 @@ -505,7 +507,8 @@ class MPU: @instruction(name="BRK", mode="imp", cycles=7) def inst_0x00(self): - pc = (self.pc + 1) & self.addrMask # The pc has already been increased one + # pc has already been increased one + pc = (self.pc + 1) & self.addrMask self.stPushWord(pc) self.p |= self.BREAK @@ -592,8 +595,8 @@ class MPU: @instruction(name="JSR", mode="abs", cycles=6) def inst_0x20(self): - self.stPushWord((self.pc+1)&self.addrMask) - self.pc=self.WordAt(self.pc) + self.stPushWord((self.pc + 1) & self.addrMask) + self.pc = self.WordAt(self.pc) @instruction(name="AND", mode="inx", cycles=6) def inst_0x21(self): @@ -716,7 +719,7 @@ class MPU: @instruction(name="JMP", mode="abs", cycles=3) def inst_0x4c(self): - self.pc=self.WordAt(self.pc) + self.pc = self.WordAt(self.pc) @instruction(name="EOR", mode="abs", cycles=4) def inst_0x4d(self): @@ -754,7 +757,7 @@ class MPU: @instruction(name="EOR", mode="aby", cycles=4, extracycles=1) def inst_0x59(self): self.opEOR(self.AbsoluteYAddr) - self.pc +=2 + self.pc += 2 @instruction(name="EOR", mode="abx", cycles=4, extracycles=1) def inst_0x5d(self): @@ -768,7 +771,7 @@ class MPU: @instruction(name="RTS", mode="imp", cycles=6) def inst_0x60(self): - self.pc=self.stPopWord() + self.pc = self.stPopWord() self.pc += 1 @instruction(name="ADC", mode="inx", cycles=6) @@ -808,7 +811,7 @@ class MPU: @instruction(name="ADC", mode="abs", cycles=4) def inst_0x6d(self): self.opADC(self.AbsoluteAddr) - self.pc +=2 + self.pc += 2 @instruction(name="ROR", mode="abs", cycles=6) def inst_0x6e(self): @@ -876,12 +879,12 @@ class MPU: @instruction(name="DEY", mode="imp", cycles=2) def inst_0x88(self): self.y -= 1 - self.y&=self.byteMask + self.y &= self.byteMask self.FlagsNZ(self.y) @instruction(name="TXA", mode="imp", cycles=2) def inst_0x8a(self): - self.a=self.x + self.a = self.x self.FlagsNZ(self.a) @instruction(name="STY", mode="abs", cycles=4) @@ -935,7 +938,7 @@ class MPU: @instruction(name="TXS", mode="imp", cycles=2) def inst_0x9a(self): - self.sp=self.x + self.sp = self.x @instruction(name="STA", mode="abx", cycles=5) def inst_0x9d(self): @@ -1089,7 +1092,7 @@ class MPU: @instruction(name="CMP", mode="imm", cycles=2) def inst_0xc9(self): self.opCMPR(self.ProgramCounter, self.a) - self.pc +=1 + self.pc += 1 @instruction(name="DEX", mode="imp", cycles=2) def inst_0xca(self): @@ -1177,8 +1180,8 @@ class MPU: @instruction(name="INX", mode="imp", cycles=2) def inst_0xe8(self): - self.x+=1 - self.x&=self.byteMask + self.x += 1 + self.x &= self.byteMask self.FlagsNZ(self.x) @instruction(name="SBC", mode="imm", cycles=2) diff --git a/py65/devices/mpu65c02.py b/py65/devices/mpu65c02.py index c729aec..b2604bb 100644 --- a/py65/devices/mpu65c02.py +++ b/py65/devices/mpu65c02.py @@ -1,6 +1,7 @@ from py65.devices import mpu6502 from py65.utils.devices import make_instruction_decorator + class MPU(mpu6502.MPU): def __init__(self, *args, **kwargs): mpu6502.MPU.__init__(self, *args, **kwargs) @@ -15,18 +16,18 @@ class MPU(mpu6502.MPU): return self # Make copies of the lists - instruct = mpu6502.MPU.instruct[:] - cycletime = mpu6502.MPU.cycletime[:] + instruct = mpu6502.MPU.instruct[:] + cycletime = mpu6502.MPU.cycletime[:] extracycles = mpu6502.MPU.extracycles[:] disassemble = mpu6502.MPU.disassemble[:] instruction = make_instruction_decorator(instruct, disassemble, - cycletime, extracycles) + cycletime, extracycles) # addressing modes def ZeroPageIndirectAddr(self): - return self.WordAt( 255 & (self.ByteAt(self.pc))) + return self.WordAt(255 & (self.ByteAt(self.pc))) def AccumulatorAddr(self): return self.a @@ -267,4 +268,3 @@ class MPU(mpu6502.MPU): def inst_0xf2(self): self.opSBC(self.ZeroPageIndirectAddr) self.pc += 1 - diff --git a/py65/devices/mpu65org16.py b/py65/devices/mpu65org16.py index fca196b..4fab41c 100644 --- a/py65/devices/mpu65org16.py +++ b/py65/devices/mpu65org16.py @@ -1,6 +1,7 @@ from py65.devices import mpu6502 from py65.utils.devices import make_instruction_decorator + class MPU(mpu6502.MPU): """ The 65Org16 is a derivative of the 6502 architecture @@ -10,21 +11,22 @@ class MPU(mpu6502.MPU): - and otherwise all opcodes and addressing modes are like the NMOS 6502 - sign bit is bit 15, overflow bit is bit 14 - One implementation can be found here: https://github.com/BigEd/verilog-6502/wiki + One implementation can be found here: + https://github.com/BigEd/verilog-6502/wiki """ - BYTE_WIDTH = 16 + BYTE_WIDTH = 16 BYTE_FORMAT = "%04x" - ADDR_WIDTH = 32 + ADDR_WIDTH = 32 ADDR_FORMAT = "%08x" def __init__(self, *args, **kwargs): mpu6502.MPU.__init__(self, *args, **kwargs) self.name = '65Org16' self.waiting = False - self.IrqTo = (1<") - self._output("Display the specified number in decimal, hex, octal, and binary.") + self._output("Display a number in decimal, hex, octal, and binary.") def do_tilde(self, args): try: @@ -439,7 +456,7 @@ class Monitor(cmd.Cmd): self._output(itoa(num, 2).zfill(8)) def help_registers(self): - self._output("registers[ = [, = ]*]") + self._output("registers[= [, =]*]") self._output("Assign respective registers. With no parameters,") self._output("display register values.") @@ -487,7 +504,7 @@ class Monitor(cmd.Cmd): def help_load(self): self._output("load \"filename\"
") - self._output("Load the specified file into memory at the specified address.") + self._output("Load a file into memory at the specified address.") self._output("Commodore-style load address bytes are ignored.") def do_load(self, args): @@ -524,12 +541,15 @@ class Monitor(cmd.Cmd): # if the start address was -1, we load to top of memory if start == -1: - start = self.addrMask - len(bytes)/(self.byteWidth/8) + 1 + start = self.addrMask - len(bytes) / (self.byteWidth / 8) + 1 - if self.byteWidth==8: - bytes=map(ord, bytes) - elif self.byteWidth==16: - bytes=map(lambda msb,lsb: (ord(msb)<<8)+ord(lsb),bytes[0::2],bytes[1::2]) + if self.byteWidth == 8: + bytes = map(ord, bytes) + + elif self.byteWidth == 16: + def format(msb, lsb): + return (ord(msb) << 8) + ord(lsb) + bytes = map(format, bytes[0::2], bytes[1::2]) self._fill(start, start, bytes) @@ -541,15 +561,15 @@ class Monitor(cmd.Cmd): filename = split[0] start = self._address_parser.number(split[1]) - end = self._address_parser.number(split[2]) + end = self._address_parser.number(split[2]) - bytes = self._mpu.memory[start:end+1] + bytes = self._mpu.memory[start:end + 1] try: f = open(filename, 'wb') for byte in bytes: # output each octect from msb first - for shift in range (self.byteWidth-8,-1,-8): - f.write(chr((byte>>shift) & 0xff)) + for shift in range(self.byteWidth - 8, -1, -8): + f.write(chr((byte >> shift) & 0xff)) f.close() except (OSError, IOError), why: msg = "Cannot save file: [%d] %s" % (why[0], why[1]) @@ -560,14 +580,15 @@ class Monitor(cmd.Cmd): def help_save(self): self._output("save \"filename\" ") - self._output("Save the specified memory range to disk as a binary file.") + self._output("Save the specified memory range as a binary file.") self._output("Commodore-style load address bytes are not written.") def help_fill(self): self._output("fill ") - self._output("Fill memory in the specified address range with the data in") - self._output(". If the size of the address range is greater") - self._output("than the size of the data_list, the data_list is repeated.") + self._output("Fill memory in the address range with the data in") + self._output(". If the size of the address range is") + self._output("greater than the size of the data_list, the data_list ") + self._output("is repeated.") def do_fill(self, args): split = shlex.split(args) @@ -613,7 +634,7 @@ class Monitor(cmd.Cmd): start, end = self._address_parser.range(split[0]) line = self.addrFmt % start + ":" - for address in range(start, end+1): + for address in range(start, end + 1): byte = self._mpu.memory[address] more = " " + self.byteFmt % byte @@ -635,7 +656,7 @@ class Monitor(cmd.Cmd): return self.help_add_label() address = self._address_parser.number(split[0]) - label = split[1] + label = split[1] self._address_parser.labels[label] = address @@ -681,6 +702,7 @@ class Monitor(cmd.Cmd): self._output("Set the width used by some commands to wrap output.") self._output("With no argument, the current width is printed.") + def main(args=None): c = Monitor() diff --git a/py65/tests/devices/test_mpu6502.py b/py65/tests/devices/test_mpu6502.py index b9dfc21..9832a0a 100644 --- a/py65/tests/devices/test_mpu6502.py +++ b/py65/tests/devices/test_mpu6502.py @@ -3,6 +3,7 @@ import sys import py65.assembler import py65.devices.mpu6502 + class Common6502Tests: """Tests common to 6502-based microprocessors""" @@ -22,23 +23,23 @@ class Common6502Tests: def test_benchmark(self): mpu = self._make_mpu() self._write(mpu.memory, 0x0000, ( - 0xd8, # $0000 d8 CLD - 0x18, # $0001 18 CLC - 0xa9, 0x00, # $0002 a9 00 LDA #$00 - 0xa2, 0x00, # $0004 a2 00 LDX #$00 - 0xa0, 0x00, # $0006 a0 00 LDY #$00 - 0xc8, # $0008 c8 INY - 0xd0, 0xfd, # $0009 d0 fd BNE $0008 - 0xe8, # $000b e8 INX - 0xd0, 0xf8, # $000c d0 f8 BNE $0006 - 0x69, 0x01, # $000e 69 01 ADC #$01 - 0xd0, 0xf2, # $0010 d0 f2 BNE $0004 - 0x00, # $0012 00 BRK + 0xd8, # $0000 d8 CLD + 0x18, # $0001 18 CLC + 0xa9, 0x00, # $0002 a9 00 LDA #$00 + 0xa2, 0x00, # $0004 a2 00 LDX #$00 + 0xa0, 0x00, # $0006 a0 00 LDY #$00 + 0xc8, # $0008 c8 INY + 0xd0, 0xfd, # $0009 d0 fd BNE $0008 + 0xe8, # $000b e8 INX + 0xd0, 0xf8, # $000c d0 f8 BNE $0006 + 0x69, 0x01, # $000e 69 01 ADC #$01 + 0xd0, 0xf2, # $0010 d0 f2 BNE $0004 + 0x00, # $0012 00 BRK 0xed)) # need a larger limit for this test to dominate the test time # (but when benchmarking it doesn't need to pass) - for i in range(1,100): + for i in range(1, 100): mpu.step() self.assertEqual(47, mpu.y) @@ -51,7 +52,8 @@ class Common6502Tests: def test_adc_bcd_off_absolute_carry_clear_in_accumulator_zeroes(self): mpu = self._make_mpu() mpu.a = 0 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) self.assertEqual(0x10000, len(mpu.memory)) mpu.memory[0xC000] = 0x00 @@ -66,7 +68,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -78,7 +81,8 @@ class Common6502Tests: def test_adc_bcd_off_absolute_carry_clear_in_no_carry_clear_out(self): mpu = self._make_mpu() mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0xFE mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -90,7 +94,8 @@ class Common6502Tests: def test_adc_bcd_off_absolute_carry_clear_in_carry_set_out(self): mpu = self._make_mpu() mpu.a = 0x02 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -99,22 +104,24 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_absolute_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_absolute_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_absolute_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_absolute_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0xff mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -125,7 +132,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -136,7 +144,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0xff mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -147,7 +156,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) mpu.a = 0x40 - self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + # $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) mpu.memory[0xC000] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -161,7 +171,8 @@ class Common6502Tests: def test_adc_bcd_off_zp_carry_clear_in_accumulator_zeroes(self): mpu = self._make_mpu() mpu.a = 0 - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -174,7 +185,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -186,7 +198,8 @@ class Common6502Tests: def test_adc_bcd_off_zp_carry_clear_in_no_carry_clear_out(self): mpu = self._make_mpu() mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0xFE mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -198,7 +211,8 @@ class Common6502Tests: def test_adc_bcd_off_zp_carry_clear_in_carry_set_out(self): mpu = self._make_mpu() mpu.a = 0x02 - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -207,22 +221,24 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_zp_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_zp_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_zp_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_zp_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0xff mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -233,7 +249,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -244,7 +261,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0xff mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -255,7 +273,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x40 mpu.p &= ~(mpu.OVERFLOW) - self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + # $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) mpu.memory[0x00B0] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -269,7 +288,8 @@ class Common6502Tests: def test_adc_bcd_off_immediate_carry_clear_in_accumulator_zeroes(self): mpu = self._make_mpu() mpu.a = 0 - self._write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 + # $0000 ADC #$00 + self._write(mpu.memory, 0x0000, (0x69, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -281,7 +301,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 + # $0000 ADC #$00 + self._write(mpu.memory, 0x0000, (0x69, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x01, mpu.a) @@ -292,7 +313,8 @@ class Common6502Tests: def test_adc_bcd_off_immediate_carry_clear_in_no_carry_clear_out(self): mpu = self._make_mpu() mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x69, 0xFE)) #=> $0000 ADC #$FE + # $0000 ADC #$FE + self._write(mpu.memory, 0x0000, (0x69, 0xFE)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0xFF, mpu.a) @@ -303,7 +325,8 @@ class Common6502Tests: def test_adc_bcd_off_immediate_carry_clear_in_carry_set_out(self): mpu = self._make_mpu() mpu.a = 0x02 - self._write(mpu.memory, 0x0000, (0x69, 0xFF)) #=> $0000 ADC #$FF + # $0000 ADC #$FF + self._write(mpu.memory, 0x0000, (0x69, 0xFF)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x01, mpu.a) @@ -311,21 +334,23 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_immediate_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_immediate_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x000, (0x69, 0x01)) #=> $0000 ADC #$01 + # $0000 ADC #$01 + self._write(mpu.memory, 0x000, (0x69, 0x01)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_immediate_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_immediate_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x000, (0x69, 0xff)) #=> $0000 ADC #$FF + # $0000 ADC #$FF + self._write(mpu.memory, 0x000, (0x69, 0xff)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -335,7 +360,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f - self._write(mpu.memory, 0x000, (0x69, 0x01)) #=> $0000 ADC #$01 + # $0000 ADC #$01 + self._write(mpu.memory, 0x000, (0x69, 0x01)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -345,7 +371,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 - self._write(mpu.memory, 0x000, (0x69, 0xff)) #=> $0000 ADC #$FF + # $0000 ADC #$FF + self._write(mpu.memory, 0x000, (0x69, 0xff)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x7f, mpu.a) @@ -354,7 +381,8 @@ class Common6502Tests: def test_adc_bcd_off_immediate_overflow_set_on_40_plus_40(self): mpu = self._make_mpu() mpu.a = 0x40 - self._write(mpu.memory, 0x0000, (0x69, 0x40)) #=> $0000 ADC #$40 + # $0000 ADC #$40 + self._write(mpu.memory, 0x0000, (0x69, 0x40)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -367,7 +395,8 @@ class Common6502Tests: mpu.p |= mpu.DECIMAL mpu.p |= mpu.CARRY mpu.a = 0x79 - self._write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 + # $0000 ADC #$00 + self._write(mpu.memory, 0x0000, (0x69, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -381,7 +410,8 @@ class Common6502Tests: mpu.p |= mpu.DECIMAL mpu.p |= mpu.CARRY mpu.a = 0x6f - self._write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 + # $0000 ADC #$00 + self._write(mpu.memory, 0x0000, (0x69, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x76, mpu.a) @@ -395,8 +425,10 @@ class Common6502Tests: mpu.p |= mpu.DECIMAL mpu.p &= ~(mpu.CARRY) mpu.a = 0x9c - self._write(mpu.memory, 0x0000, (0x69, 0x9d)) #=> $0000 ADC #$9d - self._write(mpu.memory, 0x0002, (0x69, 0x9d)) #=> $0000 ADC #$9d + # $0000 ADC #$9d + # $0002 ADC #$9d + self._write(mpu.memory, 0x0000, (0x69, 0x9d)) + self._write(mpu.memory, 0x0002, (0x69, 0x9d)) mpu.step() self.assertEqual(0x9f, mpu.a) self.assertEqual(mpu.CARRY, mpu.p & mpu.CARRY) @@ -414,7 +446,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -428,7 +461,8 @@ class Common6502Tests: mpu.a = 0 mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -441,7 +475,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0xFE mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -454,7 +489,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x02 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -463,22 +499,24 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_abs_x_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_abs_x_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_abs_x_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_abs_x_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0xff mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -489,7 +527,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -500,7 +539,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0xff mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -512,7 +552,8 @@ class Common6502Tests: mpu.p &= ~(mpu.OVERFLOW) mpu.a = 0x40 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + # $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.x] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -527,7 +568,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -541,7 +583,8 @@ class Common6502Tests: mpu.a = 0 mpu.y = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -554,7 +597,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x01 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0xFE mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -567,7 +611,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x02 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -576,22 +621,24 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_abs_y_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_abs_y_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_abs_y_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_abs_y_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -602,7 +649,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -613,7 +661,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -625,7 +674,8 @@ class Common6502Tests: mpu.p &= ~(mpu.OVERFLOW) mpu.a = 0x40 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + # $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) mpu.memory[0xC000 + mpu.y] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -640,7 +690,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -654,7 +705,8 @@ class Common6502Tests: mpu.a = 0 mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -667,7 +719,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFE mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -680,7 +733,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x02 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -689,24 +743,26 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_zp_x_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_zp_x_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_zp_x_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_zp_x_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -718,7 +774,8 @@ class Common6502Tests: mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -730,7 +787,8 @@ class Common6502Tests: mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xff mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -742,7 +800,8 @@ class Common6502Tests: mpu.p &= ~(mpu.OVERFLOW) mpu.a = 0x40 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + # $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -753,12 +812,14 @@ class Common6502Tests: # ADC Indirect, Indexed (X) - def test_adc_bcd_off_indirect_indexed_carry_clear_in_accumulator_zeroes(self): + def test_adc_bcd_off_ind_indexed_carry_clear_in_accumulator_zeroes(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -767,13 +828,15 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_adc_bcd_off_indirect_indexed_carry_set_in_accumulator_zero(self): + def test_adc_bcd_off_ind_indexed_carry_set_in_accumulator_zero(self): mpu = self._make_mpu() mpu.a = 0 mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -782,12 +845,14 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.ZERO) self.assertNotEquals(mpu.CARRY, mpu.p & mpu.CARRY) - def test_adc_bcd_off_indirect_indexed_carry_clear_in_no_carry_clear_out(self): + def test_adc_bcd_off_ind_indexed_carry_clear_in_no_carry_clear_out(self): mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFE mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -796,12 +861,14 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.CARRY) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_indirect_indexed_carry_clear_in_carry_set_out(self): + def test_adc_bcd_off_ind_indexed_carry_clear_in_carry_set_out(self): mpu = self._make_mpu() mpu.a = 0x02 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -810,65 +877,75 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_indirect_indexed_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_ind_indexed_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indirect_indexed_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_ind_indexed_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indirect_indexed_overflow_set_no_carry_7f_plus_01(self): + def test_adc_bcd_off_ind_indexed_overflow_set_no_carry_7f_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indirect_indexed_overflow_set_no_carry_80_plus_ff(self): + def test_adc_bcd_off_ind_indexed_overflow_set_no_carry_80_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x7f, mpu.a) self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indirect_indexed_overflow_set_on_40_plus_40(self): + def test_adc_bcd_off_ind_indexed_overflow_set_on_40_plus_40(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) mpu.a = 0x40 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -879,12 +956,14 @@ class Common6502Tests: # ADC Indexed, Indirect (Y) - def test_adc_bcd_off_indexed_indirect_carry_clear_in_accumulator_zeroes(self): + def test_adc_bcd_off_indexed_ind_carry_clear_in_accumulator_zeroes(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -893,13 +972,15 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_adc_bcd_off_indexed_indirect_carry_set_in_accumulator_zero(self): + def test_adc_bcd_off_indexed_ind_carry_set_in_accumulator_zero(self): mpu = self._make_mpu() mpu.a = 0 mpu.y = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -908,12 +989,14 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.ZERO) self.assertNotEquals(mpu.CARRY, mpu.p & mpu.CARRY) - def test_adc_bcd_off_indexed_indirect_carry_clear_in_no_carry_clear_out(self): + def test_adc_bcd_off_indexed_ind_carry_clear_in_no_carry_clear_out(self): mpu = self._make_mpu() mpu.a = 0x01 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFE mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -922,12 +1005,14 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.CARRY) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_indexed_indirect_carry_clear_in_carry_set_out(self): + def test_adc_bcd_off_indexed_ind_carry_clear_in_carry_set_out(self): mpu = self._make_mpu() mpu.a = 0x02 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -936,65 +1021,75 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_indexed_indirect_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_indexed_ind_overflow_clr_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indexed_indirect_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_indexed_ind_overflow_clr_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indexed_indirect_overflow_set_no_carry_7f_plus_01(self): + def test_adc_bcd_off_indexed_ind_overflow_set_no_carry_7f_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indexed_indirect_overflow_set_no_carry_80_plus_ff(self): + def test_adc_bcd_off_indexed_ind_overflow_set_no_carry_80_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x7f, mpu.a) self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_indexed_indirect_overflow_set_on_40_plus_40(self): + def test_adc_bcd_off_indexed_ind_overflow_set_on_40_plus_40(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) mpu.a = 0x40 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1008,7 +1103,8 @@ class Common6502Tests: def test_and_absolute_all_zeros_setting_zero_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) #=> AND $ABCD + # $0000 AND $ABCD + self._write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1019,7 +1115,8 @@ class Common6502Tests: def test_and_absolute_zeros_and_ones_setting_negative_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) #=> AND $ABCD + # $0000 AND $ABCD + self._write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xAA mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1032,7 +1129,8 @@ class Common6502Tests: def test_and_zp_all_zeros_setting_zero_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x25, 0x10)) #=> AND $0010 + # $0000 AND $0010 + self._write(mpu.memory, 0x0000, (0x25, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1043,7 +1141,8 @@ class Common6502Tests: def test_and_zp_zeros_and_ones_setting_negative_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x25, 0x10)) #=> AND $0010 + # $0000 AND $0010 + self._write(mpu.memory, 0x0000, (0x25, 0x10)) mpu.memory[0x0010] = 0xAA mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1056,7 +1155,8 @@ class Common6502Tests: def test_and_immediate_all_zeros_setting_zero_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x29, 0x00)) #=> AND #$00 + # $0000 AND #$00 + self._write(mpu.memory, 0x0000, (0x29, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -1066,7 +1166,8 @@ class Common6502Tests: def test_and_immediate_zeros_and_ones_setting_negative_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x29, 0xAA)) #=> AND #$AA + # $0000 AND #$AA + self._write(mpu.memory, 0x0000, (0x29, 0xAA)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0xAA, mpu.a) @@ -1079,7 +1180,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) #=> AND $ABCD,X + # $0000 AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1091,7 +1193,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) #=> AND $ABCD,X + # $0000 AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0xAA mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1105,7 +1208,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) #=> AND $ABCD,X + # $0000 AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1117,7 +1221,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) #=> AND $ABCD,X + # $0000 AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xAA mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1127,12 +1232,14 @@ class Common6502Tests: # AND Indirect, Indexed (X) - def test_and_indirect_indexed_x_all_zeros_setting_zero_flag(self): + def test_and_ind_indexed_x_all_zeros_setting_zero_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x21, 0x10)) #=> AND ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 AND ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x21, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1140,12 +1247,14 @@ class Common6502Tests: self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_and_indirect_indexed_x_zeros_and_ones_setting_negative_flag(self): + def test_and_ind_indexed_x_zeros_and_ones_setting_negative_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x21, 0x10)) #=> AND ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 AND ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x21, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xAA mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1155,12 +1264,14 @@ class Common6502Tests: # AND Indexed, Indirect (Y) - def test_and_indexed_indirect_y_all_zeros_setting_zero_flag(self): + def test_and_indexed_ind_y_all_zeros_setting_zero_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x31, 0x10)) #=> AND ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 AND ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x31, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1168,12 +1279,14 @@ class Common6502Tests: self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_and_indexed_indirect_y_zeros_and_ones_setting_negative_flag(self): + def test_and_indexed_ind_y_zeros_and_ones_setting_negative_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x31, 0x10)) #=> AND ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 AND ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x31, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xAA mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1187,7 +1300,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x35, 0x10)) #=> AND $0010,X + # $0000 AND $0010,X + self._write(mpu.memory, 0x0000, (0x35, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1199,7 +1313,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x35, 0x10)) #=> AND $0010,X + # $0000 AND $0010,X + self._write(mpu.memory, 0x0000, (0x35, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xAA mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1212,7 +1327,8 @@ class Common6502Tests: def test_asl_accumulator_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - mpu.memory[0x0000] = 0x0A #=> ASL A + # $0000 ASL A + mpu.memory[0x0000] = 0x0A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -1222,7 +1338,8 @@ class Common6502Tests: def test_asl_accumulator_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x40 - mpu.memory[0x0000] = 0x0A #=> ASL A + # $0000 ASL A + mpu.memory[0x0000] = 0x0A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -1232,7 +1349,8 @@ class Common6502Tests: def test_asl_accumulator_shifts_out_zero(self): mpu = self._make_mpu() mpu.a = 0x7F - mpu.memory[0x0000] = 0x0A #=> ASL A + # $0000 ASL A + mpu.memory[0x0000] = 0x0A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xFE, mpu.a) @@ -1241,7 +1359,8 @@ class Common6502Tests: def test_asl_accumulator_shifts_out_one(self): mpu = self._make_mpu() mpu.a = 0xFF - mpu.memory[0x0000] = 0x0A #=> ASL A + # $0000 ASL A + mpu.memory[0x0000] = 0x0A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xFE, mpu.a) @@ -1251,7 +1370,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x80 mpu.p &= ~(mpu.ZERO) - mpu.memory[0x0000] = 0x0A #=> ASL A + # $0000 ASL A + mpu.memory[0x0000] = 0x0A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -1261,7 +1381,8 @@ class Common6502Tests: def test_asl_absolute_sets_z_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + # $0000 ASL $ABCD + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1271,7 +1392,8 @@ class Common6502Tests: def test_asl_absolute_sets_n_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + # $0000 ASL $ABCD + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1282,7 +1404,8 @@ class Common6502Tests: def test_asl_absolute_shifts_out_zero(self): mpu = self._make_mpu() mpu.a = 0xAA - self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + # $0000 ASL $ABCD + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x7F mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1293,7 +1416,8 @@ class Common6502Tests: def test_asl_absolute_shifts_out_one(self): mpu = self._make_mpu() mpu.a = 0xAA - self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + # $0000 ASL $ABCD + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1305,7 +1429,8 @@ class Common6502Tests: def test_asl_zp_sets_z_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + # $0000 ASL $0010 + self._write(mpu.memory, 0x0000, (0x06, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1315,7 +1440,8 @@ class Common6502Tests: def test_asl_zp_sets_n_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + # $0000 ASL $0010 + self._write(mpu.memory, 0x0000, (0x06, 0x10)) mpu.memory[0x0010] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1326,7 +1452,8 @@ class Common6502Tests: def test_asl_zp_shifts_out_zero(self): mpu = self._make_mpu() mpu.a = 0xAA - self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + # $0000 ASL $0010 + self._write(mpu.memory, 0x0000, (0x06, 0x10)) mpu.memory[0x0010] = 0x7F mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1337,7 +1464,8 @@ class Common6502Tests: def test_asl_zp_shifts_out_one(self): mpu = self._make_mpu() mpu.a = 0xAA - self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + # $0000 ASL $0010 + self._write(mpu.memory, 0x0000, (0x06, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1347,10 +1475,11 @@ class Common6502Tests: # ASL Absolute, X-Indexed - def test_asl_absolute_x_indexed_sets_z_flag(self): + def test_asl_abs_x_indexed_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + # $0000 ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1358,10 +1487,11 @@ class Common6502Tests: self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_asl_absolute_x_indexed_sets_n_flag(self): + def test_asl_abs_x_indexed_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + # $0000 ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1369,11 +1499,12 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_asl_absolute_x_indexed_shifts_out_zero(self): + def test_asl_abs_x_indexed_shifts_out_zero(self): mpu = self._make_mpu() mpu.a = 0xAA mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + # $0000 ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x7F mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1381,11 +1512,12 @@ class Common6502Tests: self.assertEqual(0xFE, mpu.memory[0xABCD + mpu.x]) self.assertEqual(0, mpu.p & mpu.CARRY) - def test_asl_absolute_x_indexed_shifts_out_one(self): + def test_asl_abs_x_indexed_shifts_out_one(self): mpu = self._make_mpu() mpu.a = 0xAA mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + # $0000 ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1398,7 +1530,8 @@ class Common6502Tests: def test_asl_zp_x_indexed_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + # $0000 ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1409,7 +1542,8 @@ class Common6502Tests: def test_asl_zp_x_indexed_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + # $0000 ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1421,7 +1555,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.a = 0xAA - self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + # $0000 ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x7F mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1433,7 +1568,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.a = 0xAA - self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + # $0000 ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1446,7 +1582,8 @@ class Common6502Tests: def test_bcc_carry_clear_branches_relative_forward(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x90, 0x06)) #=> BCC +6 + # $0000 BCC +6 + self._write(mpu.memory, 0x0000, (0x90, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1454,15 +1591,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0x90, rel)) #=> BCC -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + # $0000 BCC -6 + self._write(mpu.memory, 0x0050, (0x90, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bcc_carry_set_does_not_branch(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x90, 0x06)) #=> BCC +6 + # $0000 BCC +6 + self._write(mpu.memory, 0x0000, (0x90, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1471,7 +1610,8 @@ class Common6502Tests: def test_bcs_carry_set_branches_relative_forward(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0xB0, 0x06)) #=> BCS +6 + # $0000 BCS +6 + self._write(mpu.memory, 0x0000, (0xB0, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1479,15 +1619,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.CARRY mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0xB0, rel)) #=> BCS -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + # $0000 BCS -6 + self._write(mpu.memory, 0x0050, (0xB0, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bcs_carry_clear_does_not_branch(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0xB0, 0x06)) #=> BCS +6 + # $0000 BCS +6 + self._write(mpu.memory, 0x0000, (0xB0, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1496,7 +1638,8 @@ class Common6502Tests: def test_beq_zero_set_branches_relative_forward(self): mpu = self._make_mpu() mpu.p |= mpu.ZERO - self._write(mpu.memory, 0x0000, (0xF0, 0x06)) #=> BEQ +6 + # $0000 BEQ +6 + self._write(mpu.memory, 0x0000, (0xF0, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1504,15 +1647,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.ZERO mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0xF0, rel)) #=> BEQ -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + # $0000 BEQ -6 + self._write(mpu.memory, 0x0050, (0xF0, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_beq_zero_clear_does_not_branch(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0xF0, 0x06)) #=> BEQ +6 + # $0000 BEQ +6 + self._write(mpu.memory, 0x0000, (0xF0, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1521,7 +1666,8 @@ class Common6502Tests: def test_bit_abs_copies_bit_7_of_memory_to_n_flag_when_0(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0xFF mpu.a = 0xFF mpu.step() @@ -1530,7 +1676,8 @@ class Common6502Tests: def test_bit_abs_copies_bit_7_of_memory_to_n_flag_when_1(self): mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0xFF mpu.step() @@ -1539,7 +1686,8 @@ class Common6502Tests: def test_bit_abs_copies_bit_6_of_memory_to_v_flag_when_0(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0xFF mpu.a = 0xFF mpu.step() @@ -1548,16 +1696,18 @@ class Common6502Tests: def test_bit_abs_copies_bit_6_of_memory_to_v_flag_when_1(self): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0xFF mpu.step() self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_bit_abs_stores_result_of_and_in_z_while_preserving_a_when_1(self): + def test_bit_abs_stores_result_of_and_in_z_preserves_a_when_1(self): mpu = self._make_mpu() mpu.p &= ~mpu.ZERO - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0x01 mpu.step() @@ -1565,25 +1715,27 @@ class Common6502Tests: self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0xFEED]) - def test_bit_abs_stores_result_of_and_when_nonzero_in_z_while_preserving_a(self): + def test_bit_abs_stores_result_of_and_when_nonzero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p |= mpu.ZERO - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0x01 mpu.a = 0x01 mpu.step() - self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero + self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x01, mpu.memory[0xFEED]) - def test_bit_abs_stores_result_of_and_when_zero_in_z_while_preserving_a(self): + def test_bit_abs_stores_result_of_and_when_zero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + # $0000 BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0x01 mpu.step() - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0xFEED]) @@ -1592,7 +1744,8 @@ class Common6502Tests: def test_bit_zp_copies_bit_7_of_memory_to_n_flag_when_0(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0xFF mpu.a = 0xFF mpu.step() @@ -1603,7 +1756,8 @@ class Common6502Tests: def test_bit_zp_copies_bit_7_of_memory_to_n_flag_when_1(self): mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0x00 mpu.a = 0xFF mpu.step() @@ -1614,7 +1768,8 @@ class Common6502Tests: def test_bit_zp_copies_bit_6_of_memory_to_v_flag_when_0(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0xFF mpu.a = 0xFF mpu.step() @@ -1625,7 +1780,8 @@ class Common6502Tests: def test_bit_zp_copies_bit_6_of_memory_to_v_flag_when_1(self): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0x00 mpu.a = 0xFF mpu.step() @@ -1633,10 +1789,11 @@ class Common6502Tests: self.assertEqual(3, mpu.processorCycles) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_bit_zp_stores_result_of_and_in_z_while_preserving_a_when_1(self): + def test_bit_zp_stores_result_of_and_in_z_preserves_a_when_1(self): mpu = self._make_mpu() mpu.p &= ~mpu.ZERO - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0x00 mpu.a = 0x01 mpu.step() @@ -1646,29 +1803,31 @@ class Common6502Tests: self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0x0010]) - def test_bit_zp_stores_result_of_and_when_nonzero_in_z_while_preserving_a(self): + def test_bit_zp_stores_result_of_and_when_nonzero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p |= mpu.ZERO - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0x01 mpu.a = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(3, mpu.processorCycles) - self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero + self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x01, mpu.memory[0x0010]) - def test_bit_zp_stores_result_of_and_when_zero_in_z_while_preserving_a(self): + def test_bit_zp_stores_result_of_and_when_zero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + # $0000 BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) mpu.memory[0x0010] = 0x00 mpu.a = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(3, mpu.processorCycles) - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0x0010]) @@ -1677,7 +1836,8 @@ class Common6502Tests: def test_bmi_negative_set_branches_relative_forward(self): mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE - self._write(mpu.memory, 0x0000, (0x30, 0x06)) #=> BMI +06 + # $0000 BMI +06 + self._write(mpu.memory, 0x0000, (0x30, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1685,15 +1845,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0x30, rel)) #=> BMI -6 + # $0000 BMI -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + self._write(mpu.memory, 0x0050, (0x30, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bmi_negative_clear_does_not_branch(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) - self._write(mpu.memory, 0x0000, (0x30, 0x06)) #=> BEQ +6 + # $0000 BEQ +6 + self._write(mpu.memory, 0x0000, (0x30, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1702,7 +1864,8 @@ class Common6502Tests: def test_bne_zero_clear_branches_relative_forward(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0xD0, 0x06)) #=> BNE +6 + # $0000 BNE +6 + self._write(mpu.memory, 0x0000, (0xD0, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1710,15 +1873,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0xD0, rel)) #=> BNE -6 + # $0050 BNE -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + self._write(mpu.memory, 0x0050, (0xD0, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bne_zero_set_does_not_branch(self): mpu = self._make_mpu() mpu.p |= mpu.ZERO - self._write(mpu.memory, 0x0000, (0xD0, 0x06)) #=> BNE +6 + # $0000 BNE +6 + self._write(mpu.memory, 0x0000, (0xD0, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1727,7 +1892,8 @@ class Common6502Tests: def test_bpl_negative_clear_branches_relative_forward(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) - self._write(mpu.memory, 0x0000, (0x10, 0x06)) #=> BPL +06 + # $0000 BPL +06 + self._write(mpu.memory, 0x0000, (0x10, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1735,15 +1901,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0x10, rel)) #=> BPL -6 + # $0050 BPL -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + self._write(mpu.memory, 0x0050, (0x10, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bpl_negative_set_does_not_branch(self): mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE - self._write(mpu.memory, 0x0000, (0x10, 0x06)) #=> BPL +6 + # $0000 BPL +6 + self._write(mpu.memory, 0x0000, (0x10, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1753,14 +1921,15 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = mpu.BREAK | mpu.UNUSED self._write(mpu.memory, 0xFFFE, (0xCD, 0xAB)) - mpu.memory[0xC000] = 0x00 #=> BRK + # $C000 BRK + mpu.memory[0xC000] = 0x00 mpu.pc = 0xC000 mpu.step() self.assertEqual(0xABCD, mpu.pc) - self.assertEqual(0xC0, mpu.memory[0x1FF]) # PCH - self.assertEqual(0x02, mpu.memory[0x1FE]) # PCL - self.assertEqual(mpu.BREAK | mpu.UNUSED, mpu.memory[0x1FD]) # Status (P) + self.assertEqual(0xC0, mpu.memory[0x1FF]) # PCH + self.assertEqual(0x02, mpu.memory[0x1FE]) # PCL + self.assertEqual(mpu.BREAK | mpu.UNUSED, mpu.memory[0x1FD]) # Status self.assertEqual(0xFC, mpu.sp) self.assertEqual(mpu.BREAK | mpu.UNUSED | mpu.INTERRUPT, mpu.p) @@ -1770,7 +1939,8 @@ class Common6502Tests: def test_bvc_overflow_clear_branches_relative_forward(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) - self._write(mpu.memory, 0x0000, (0x50, 0x06)) #=> BVC +6 + # $0000 BVC +6 + self._write(mpu.memory, 0x0000, (0x50, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1778,15 +1948,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0x50, rel)) #=> BVC -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + # $0050 BVC -6 + self._write(mpu.memory, 0x0050, (0x50, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bvc_overflow_set_does_not_branch(self): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW - self._write(mpu.memory, 0x0000, (0x50, 0x06)) #=> BVC +6 + # $0000 BVC +6 + self._write(mpu.memory, 0x0000, (0x50, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1795,7 +1967,8 @@ class Common6502Tests: def test_bvs_overflow_set_branches_relative_forward(self): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW - self._write(mpu.memory, 0x0000, (0x70, 0x06)) #=> BVS +6 + # $0000 BVS +6 + self._write(mpu.memory, 0x0000, (0x70, 0x06)) mpu.step() self.assertEqual(0x0002 + 0x06, mpu.pc) @@ -1803,15 +1976,17 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW mpu.pc = 0x0050 - rel = (0x06^0xFF + 1) # two's complement of 6 - self._write(mpu.memory, 0x0050, (0x70, rel)) #=> BVS -6 + rel = (0x06 ^ 0xFF + 1) # two's complement of 6 + # $0050 BVS -6 + self._write(mpu.memory, 0x0050, (0x70, rel)) mpu.step() self.assertEqual(0x0052 + rel, mpu.pc) def test_bvs_overflow_clear_does_not_branch(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) - self._write(mpu.memory, 0x0000, (0x70, 0x06)) #=> BVS +6 + # $0000 BVS +6 + self._write(mpu.memory, 0x0000, (0x70, 0x06)) mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1820,7 +1995,8 @@ class Common6502Tests: def test_clc_clears_carry_flag(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - mpu.memory[0x0000] = 0x18 #=> CLC + # $0000 CLC + mpu.memory[0x0000] = 0x18 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0, mpu.p & mpu.CARRY) @@ -1830,7 +2006,8 @@ class Common6502Tests: def test_cld_clears_decimal_flag(self): mpu = self._make_mpu() mpu.p |= mpu.DECIMAL - mpu.memory[0x0000] = 0xD8 #=> CLD + # $0000 CLD + mpu.memory[0x0000] = 0xD8 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0, mpu.p & mpu.DECIMAL) @@ -1840,7 +2017,8 @@ class Common6502Tests: def test_cli_clears_interrupt_mask_flag(self): mpu = self._make_mpu() mpu.p |= mpu.INTERRUPT - mpu.memory[0x0000] = 0x58 #=> CLI + # $0000 CLI + mpu.memory[0x0000] = 0x58 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0, mpu.p & mpu.INTERRUPT) @@ -1850,7 +2028,8 @@ class Common6502Tests: def test_clv_clears_overflow_flag(self): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW - mpu.memory[0x0000] = 0xB8 #=> CLV + # $0000 CLV + mpu.memory[0x0000] = 0xB8 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0, mpu.p & mpu.OVERFLOW) @@ -1859,7 +2038,8 @@ class Common6502Tests: def test_dec_abs_decrements_memory(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD + # $0000 DEC 0xABCD + self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x10 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1869,7 +2049,8 @@ class Common6502Tests: def test_dec_abs_below_00_rolls_over_and_sets_negative_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD + # $0000 DEC 0xABCD + self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1879,7 +2060,8 @@ class Common6502Tests: def test_dec_abs_sets_zero_flag_when_decrementing_to_zero(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD + # $0000 DEC 0xABCD + self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1891,7 +2073,8 @@ class Common6502Tests: def test_dec_zp_decrements_memory(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 + # $0000 DEC 0x0010 + self._write(mpu.memory, 0x0000, (0xC6, 0x10)) mpu.memory[0x0010] = 0x10 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1901,7 +2084,8 @@ class Common6502Tests: def test_dec_zp_below_00_rolls_over_and_sets_negative_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 + # $0000 DEC 0x0010 + self._write(mpu.memory, 0x0000, (0xC6, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1911,7 +2095,8 @@ class Common6502Tests: def test_dec_zp_sets_zero_flag_when_decrementing_to_zero(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 + # $0000 DEC 0x0010 + self._write(mpu.memory, 0x0000, (0xC6, 0x10)) mpu.memory[0x0010] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -1923,7 +2108,8 @@ class Common6502Tests: def test_dec_abs_x_decrements_memory(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X + # $0000 DEC 0xABCD,X + self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) mpu.x = 0x03 mpu.memory[0xABCD + mpu.x] = 0x10 mpu.step() @@ -1934,7 +2120,8 @@ class Common6502Tests: def test_dec_abs_x_below_00_rolls_over_and_sets_negative_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X + # $0000 DEC 0xABCD,X + self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1944,7 +2131,8 @@ class Common6502Tests: def test_dec_abs_x_sets_zero_flag_when_decrementing_to_zero(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X + # $0000 DEC 0xABCD,X + self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -1956,7 +2144,8 @@ class Common6502Tests: def test_dec_zp_x_decrements_memory(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X + # $0000 DEC 0x0010,X + self._write(mpu.memory, 0x0000, (0xD6, 0x10)) mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x10 mpu.step() @@ -1967,7 +2156,8 @@ class Common6502Tests: def test_dec_zp_x_below_00_rolls_over_and_sets_negative_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X + # $0000 DEC 0x0010,X + self._write(mpu.memory, 0x0000, (0xD6, 0x10)) mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() @@ -1978,7 +2168,8 @@ class Common6502Tests: def test_dec_zp_x_sets_zero_flag_when_decrementing_to_zero(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X + # $0000 DEC 0x0010,X + self._write(mpu.memory, 0x0000, (0xD6, 0x10)) mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x01 mpu.step() @@ -1992,7 +2183,8 @@ class Common6502Tests: def test_dex_decrements_x(self): mpu = self._make_mpu() mpu.x = 0x10 - mpu.memory[0x0000] = 0xCA #=> DEX + # $0000 DEX + mpu.memory[0x0000] = 0xCA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x0F, mpu.x) @@ -2002,7 +2194,8 @@ class Common6502Tests: def test_dex_below_00_rolls_over_and_sets_negative_flag(self): mpu = self._make_mpu() mpu.x = 0x00 - mpu.memory[0x0000] = 0xCA #=> DEX + # $0000 DEX + mpu.memory[0x0000] = 0xCA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xFF, mpu.x) @@ -2012,7 +2205,8 @@ class Common6502Tests: def test_dex_sets_zero_flag_when_decrementing_to_zero(self): mpu = self._make_mpu() mpu.x = 0x01 - mpu.memory[0x0000] = 0xCA #=> DEX + # $0000 DEX + mpu.memory[0x0000] = 0xCA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.x) @@ -2024,7 +2218,8 @@ class Common6502Tests: def test_dey_decrements_y(self): mpu = self._make_mpu() mpu.y = 0x10 - mpu.memory[0x0000] = 0x88 #=> DEY + # $0000 DEY + mpu.memory[0x0000] = 0x88 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x0F, mpu.y) @@ -2034,7 +2229,8 @@ class Common6502Tests: def test_dey_below_00_rolls_over_and_sets_negative_flag(self): mpu = self._make_mpu() mpu.y = 0x00 - mpu.memory[0x0000] = 0x88 #=> DEY + # $0000 DEY + mpu.memory[0x0000] = 0x88 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xFF, mpu.y) @@ -2043,7 +2239,8 @@ class Common6502Tests: def test_dey_sets_zero_flag_when_decrementing_to_zero(self): mpu = self._make_mpu() mpu.y = 0x01 - mpu.memory[0x0000] = 0x88 #=> DEY + # $0000 DEY + mpu.memory[0x0000] = 0x88 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.y) @@ -2122,7 +2319,7 @@ class Common6502Tests: # EOR Absolute, X-Indexed - def test_eor_absolute_x_indexed_flips_bits_over_setting_z_flag(self): + def test_eor_abs_x_indexed_flips_bits_over_setting_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 @@ -2134,7 +2331,7 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.memory[0xABCD + mpu.x]) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_eor_absolute_x_indexed_flips_bits_over_setting_n_flag(self): + def test_eor_abs_x_indexed_flips_bits_over_setting_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 @@ -2149,7 +2346,7 @@ class Common6502Tests: # EOR Absolute, Y-Indexed - def test_eor_absolute_y_indexed_flips_bits_over_setting_z_flag(self): + def test_eor_abs_y_indexed_flips_bits_over_setting_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 @@ -2161,7 +2358,7 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.memory[0xABCD + mpu.y]) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_eor_absolute_y_indexed_flips_bits_over_setting_n_flag(self): + def test_eor_abs_y_indexed_flips_bits_over_setting_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 @@ -2176,12 +2373,12 @@ class Common6502Tests: # EOR Indirect, Indexed (X) - def test_eor_indirect_indexed_x_flips_bits_over_setting_z_flag(self): + def test_eor_ind_indexed_x_flips_bits_over_setting_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x41, 0x10)) #=> EOR ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x41, 0x10)) # => EOR ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) # => Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2189,12 +2386,12 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.memory[0xABCD]) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_eor_indirect_indexed_x_flips_bits_over_setting_n_flag(self): + def test_eor_ind_indexed_x_flips_bits_over_setting_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x41, 0x10)) #=> EOR ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x41, 0x10)) # => EOR ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) # => Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2205,12 +2402,12 @@ class Common6502Tests: # EOR Indexed, Indirect (Y) - def test_eor_indexed_indirect_y_flips_bits_over_setting_z_flag(self): + def test_eor_indexed_ind_y_flips_bits_over_setting_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x51, 0x10)) #=> EOR ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x51, 0x10)) # => EOR ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) # => Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2218,12 +2415,12 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.memory[0xABCD + mpu.y]) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_eor_indexed_indirect_y_flips_bits_over_setting_n_flag(self): + def test_eor_indexed_ind_y_flips_bits_over_setting_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x51, 0x10)) #=> EOR ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x51, 0x10)) # => EOR ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) # => Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2396,7 +2593,7 @@ class Common6502Tests: def test_inx_increments_x(self): mpu = self._make_mpu() mpu.x = 0x09 - mpu.memory[0x0000] = 0xE8 #=> INX + mpu.memory[0x0000] = 0xE8 # => INX mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x0A, mpu.x) @@ -2406,7 +2603,7 @@ class Common6502Tests: def test_inx_above_FF_rolls_over_and_sets_zero_flag(self): mpu = self._make_mpu() mpu.x = 0xFF - mpu.memory[0x0000] = 0xE8 #=> INX + mpu.memory[0x0000] = 0xE8 # => INX mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.x) @@ -2415,7 +2612,7 @@ class Common6502Tests: def test_inx_sets_negative_flag_when_incrementing_above_7F(self): mpu = self._make_mpu() mpu.x = 0x7f - mpu.memory[0x0000] = 0xE8 #=> INX + mpu.memory[0x0000] = 0xE8 # => INX mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.x) @@ -2426,7 +2623,7 @@ class Common6502Tests: def test_iny_increments_y(self): mpu = self._make_mpu() mpu.y = 0x09 - mpu.memory[0x0000] = 0xC8 #=> INY + mpu.memory[0x0000] = 0xC8 # => INY mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x0A, mpu.y) @@ -2436,7 +2633,7 @@ class Common6502Tests: def test_iny_above_FF_rolls_over_and_sets_zero_flag(self): mpu = self._make_mpu() mpu.y = 0xFF - mpu.memory[0x0000] = 0xC8 #=> INY + mpu.memory[0x0000] = 0xC8 # => INY mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.y) @@ -2445,7 +2642,7 @@ class Common6502Tests: def test_iny_sets_negative_flag_when_incrementing_above_7F(self): mpu = self._make_mpu() mpu.y = 0x7f - mpu.memory[0x0000] = 0xC8 #=> INY + mpu.memory[0x0000] = 0xC8 # => INY mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.y) @@ -2455,13 +2652,15 @@ class Common6502Tests: def test_jmp_jumps_to_absolute_address(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0x4C, 0xCD, 0xAB)) #=> JMP $ABCD + # $0000 JMP $ABCD + self._write(mpu.memory, 0x0000, (0x4C, 0xCD, 0xAB)) mpu.step() self.assertEqual(0xABCD, mpu.pc) def test_jmp_jumps_to_indirect_address(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, (0x6C, 0x00, 0x02)) #=> JMP ($ABCD) + # $0000 JMP ($ABCD) + self._write(mpu.memory, 0x0000, (0x6C, 0x00, 0x02)) self._write(mpu.memory, 0x0200, (0xCD, 0xAB)) mpu.step() self.assertEqual(0xABCD, mpu.pc) @@ -2470,20 +2669,22 @@ class Common6502Tests: def test_jsr_pushes_pc_plus_2_and_sets_pc(self): mpu = self._make_mpu() - self._write(mpu.memory, 0xC000, (0x20, 0xD2, 0xFF)) #=> JSR $FFD2 + # $C000 JSR $FFD2 + self._write(mpu.memory, 0xC000, (0x20, 0xD2, 0xFF)) mpu.pc = 0xC000 mpu.step() self.assertEqual(0xFFD2, mpu.pc) self.assertEqual(0xFD, mpu.sp) - self.assertEqual(0xC0, mpu.memory[0x01FF]) # PCH - self.assertEqual(0x02, mpu.memory[0x01FE]) # PCL+2 + self.assertEqual(0xC0, mpu.memory[0x01FF]) # PCH + self.assertEqual(0x02, mpu.memory[0x01FE]) # PCL+2 # LDA Absolute def test_lda_absolute_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD + # $0000 LDA $ABCD + self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2494,7 +2695,8 @@ class Common6502Tests: def test_lda_absolute_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD + # $0000 LDA $ABCD + self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2507,7 +2709,8 @@ class Common6502Tests: def test_lda_zp_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xA5, 0x10)) #=> LDA $0010 + # $0000 LDA $0010 + self._write(mpu.memory, 0x0000, (0xA5, 0x10)) mpu.memory[0x0010] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2518,7 +2721,8 @@ class Common6502Tests: def test_lda_zp_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0xA5, 0x10)) #=> LDA $0010 + # $0000 LDA $0010 + self._write(mpu.memory, 0x0000, (0xA5, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2531,7 +2735,8 @@ class Common6502Tests: def test_lda_immediate_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xA9, 0x80)) #=> LDA #$80 + # $0000 LDA #$80 + self._write(mpu.memory, 0x0000, (0xA9, 0x80)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -2541,7 +2746,8 @@ class Common6502Tests: def test_lda_immediate_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0xA9, 0x00)) #=> LDA #$00 + # $0000 LDA #$00 + self._write(mpu.memory, 0x0000, (0xA9, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -2550,11 +2756,12 @@ class Common6502Tests: # LDA Absolute, X-Indexed - def test_lda_absolute_x_indexed_loads_a_sets_n_flag(self): + def test_lda_abs_x_indexed_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) #=> LDA $ABCD,X + # $0000 LDA $ABCD,X + self._write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2562,11 +2769,12 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_lda_absolute_x_indexed_loads_x_sets_z_flag(self): + def test_lda_abs_x_indexed_loads_x_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) #=> LDA $ABCD,X + # $0000 LDA $ABCD,X + self._write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2576,11 +2784,12 @@ class Common6502Tests: # LDA Absolute, Y-Indexed - def test_lda_absolute_y_indexed_loads_a_sets_n_flag(self): + def test_lda_abs_y_indexed_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) #=> LDA $ABCD,Y + # $0000 LDA $ABCD,Y + self._write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2588,11 +2797,12 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_lda_absolute_y_indexed_loads_a_sets_z_flag(self): + def test_lda_abs_y_indexed_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) #=> LDA $ABCD,Y + # $0000 LDA $ABCD,Y + self._write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2602,12 +2812,14 @@ class Common6502Tests: # LDA Indirect, Indexed (X) - def test_lda_indirect_indexed_x_loads_a_sets_n_flag(self): + def test_lda_ind_indexed_x_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xA1, 0x10)) #=> LDA ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 LDA ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xA1, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2615,12 +2827,14 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_lda_indirect_indexed_x_loads_a_sets_z_flag(self): + def test_lda_ind_indexed_x_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xA1, 0x10)) #=> LDA ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 LDA ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xA1, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2630,12 +2844,14 @@ class Common6502Tests: # LDA Indexed, Indirect (Y) - def test_lda_indexed_indirect_y_loads_a_sets_n_flag(self): + def test_lda_indexed_ind_y_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xB1, 0x10)) #=> LDA ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 LDA ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xB1, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2643,12 +2859,14 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_lda_indexed_indirect_y_loads_a_sets_z_flag(self): + def test_lda_indexed_ind_y_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xB1, 0x10)) #=> LDA ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 LDA ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xB1, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2662,7 +2880,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xB5, 0x10)) #=> LDA $0010,X + # $0000 LDA $0010,X + self._write(mpu.memory, 0x0000, (0xB5, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2674,7 +2893,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xB5, 0x10)) #=> LDA $0010,X + # $0000 LDA $0010,X + self._write(mpu.memory, 0x0000, (0xB5, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2687,7 +2907,8 @@ class Common6502Tests: def test_ldx_absolute_loads_x_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x00 - self._write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) #=> LDX $ABCD + # $0000 LDX $ABCD + self._write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2698,7 +2919,8 @@ class Common6502Tests: def test_ldx_absolute_loads_x_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0xFF - self._write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) #=> LDX $ABCD + # $0000 LDX $ABCD + self._write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2711,7 +2933,8 @@ class Common6502Tests: def test_ldx_zp_loads_x_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x00 - self._write(mpu.memory, 0x0000, (0xA6, 0x10)) #=> LDX $0010 + # $0000 LDX $0010 + self._write(mpu.memory, 0x0000, (0xA6, 0x10)) mpu.memory[0x0010] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2722,7 +2945,8 @@ class Common6502Tests: def test_ldx_zp_loads_x_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0xFF - self._write(mpu.memory, 0x0000, (0xA6, 0x10)) #=> LDX $0010 + # $0000 LDX $0010 + self._write(mpu.memory, 0x0000, (0xA6, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2735,7 +2959,8 @@ class Common6502Tests: def test_ldx_immediate_loads_x_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x00 - self._write(mpu.memory, 0x0000, (0xA2, 0x80)) #=> LDX #$80 + # $0000 LDX #$80 + self._write(mpu.memory, 0x0000, (0xA2, 0x80)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.x) @@ -2745,7 +2970,8 @@ class Common6502Tests: def test_ldx_immediate_loads_x_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0xFF - self._write(mpu.memory, 0x0000, (0xA2, 0x00)) #=> LDX #$00 + # $0000 LDX #$00 + self._write(mpu.memory, 0x0000, (0xA2, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.x) @@ -2754,11 +2980,12 @@ class Common6502Tests: # LDX Absolute, Y-Indexed - def test_ldx_absolute_y_indexed_loads_x_sets_n_flag(self): + def test_ldx_abs_y_indexed_loads_x_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) #=> LDX $ABCD,Y + # $0000 LDX $ABCD,Y + self._write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2766,11 +2993,12 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_ldx_absolute_y_indexed_loads_x_sets_z_flag(self): + def test_ldx_abs_y_indexed_loads_x_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) #=> LDX $ABCD,Y + # $0000 LDX $ABCD,Y + self._write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2784,7 +3012,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xB6, 0x10)) #=> LDX $0010,Y + # $0000 LDX $0010,Y + self._write(mpu.memory, 0x0000, (0xB6, 0x10)) mpu.memory[0x0010 + mpu.y] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2796,7 +3025,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xB6, 0x10)) #=> LDX $0010,Y + # $0000 LDX $0010,Y + self._write(mpu.memory, 0x0000, (0xB6, 0x10)) mpu.memory[0x0010 + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2809,7 +3039,8 @@ class Common6502Tests: def test_ldy_absolute_loads_y_sets_n_flag(self): mpu = self._make_mpu() mpu.y = 0x00 - self._write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) #=> LDY $ABCD + # $0000 LDY $ABCD + self._write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2820,7 +3051,8 @@ class Common6502Tests: def test_ldy_absolute_loads_y_sets_z_flag(self): mpu = self._make_mpu() mpu.y = 0xFF - self._write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) #=> LDY $ABCD + # $0000 LDY $ABCD + self._write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2833,7 +3065,8 @@ class Common6502Tests: def test_ldy_zp_loads_y_sets_n_flag(self): mpu = self._make_mpu() mpu.y = 0x00 - self._write(mpu.memory, 0x0000, (0xA4, 0x10)) #=> LDY $0010 + # $0000 LDY $0010 + self._write(mpu.memory, 0x0000, (0xA4, 0x10)) mpu.memory[0x0010] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2844,7 +3077,8 @@ class Common6502Tests: def test_ldy_zp_loads_y_sets_z_flag(self): mpu = self._make_mpu() mpu.y = 0xFF - self._write(mpu.memory, 0x0000, (0xA4, 0x10)) #=> LDY $0010 + # $0000 LDY $0010 + self._write(mpu.memory, 0x0000, (0xA4, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2857,7 +3091,8 @@ class Common6502Tests: def test_ldy_immediate_loads_y_sets_n_flag(self): mpu = self._make_mpu() mpu.y = 0x00 - self._write(mpu.memory, 0x0000, (0xA0, 0x80)) #=> LDY #$80 + # $0000 LDY #$80 + self._write(mpu.memory, 0x0000, (0xA0, 0x80)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.y) @@ -2867,7 +3102,8 @@ class Common6502Tests: def test_ldy_immediate_loads_y_sets_z_flag(self): mpu = self._make_mpu() mpu.y = 0xFF - self._write(mpu.memory, 0x0000, (0xA0, 0x00)) #=> LDY #$00 + # $0000 LDY #$00 + self._write(mpu.memory, 0x0000, (0xA0, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.y) @@ -2876,11 +3112,12 @@ class Common6502Tests: # LDY Absolute, X-Indexed - def test_ldy_absolute_x_indexed_loads_x_sets_n_flag(self): + def test_ldy_abs_x_indexed_loads_x_sets_n_flag(self): mpu = self._make_mpu() mpu.y = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) #=> LDY $ABCD,X + # $0000 LDY $ABCD,X + self._write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2888,11 +3125,12 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_ldy_absolute_x_indexed_loads_x_sets_z_flag(self): + def test_ldy_abs_x_indexed_loads_x_sets_z_flag(self): mpu = self._make_mpu() mpu.y = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) #=> LDY $ABCD,X + # $0000 LDY $ABCD,X + self._write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2906,7 +3144,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.y = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xB4, 0x10)) #=> LDY $0010,X + # $0000 LDY $0010,X + self._write(mpu.memory, 0x0000, (0xB4, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2918,7 +3157,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.y = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0xB4, 0x10)) #=> LDY $0010,X + # $0000 LDY $0010,X + self._write(mpu.memory, 0x0000, (0xB4, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -2931,7 +3171,8 @@ class Common6502Tests: def test_lsr_accumulator_rotates_in_zero_not_carry(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - mpu.memory[0x0000] = (0x4A) #=> LSR A + # $0000 LSR A + mpu.memory[0x0000] = (0x4A) mpu.a = 0x00 mpu.step() self.assertEqual(0x0001, mpu.pc) @@ -2943,7 +3184,8 @@ class Common6502Tests: def test_lsr_accumulator_sets_carry_and_zero_flags_after_rotation(self): mpu = self._make_mpu() mpu.p &= ~mpu.CARRY - mpu.memory[0x0000] = (0x4A) #=> LSR A + # $0000 LSR A + mpu.memory[0x0000] = (0x4A) mpu.a = 0x01 mpu.step() self.assertEqual(0x0001, mpu.pc) @@ -2955,7 +3197,8 @@ class Common6502Tests: def test_lsr_accumulator_rotates_bits_right(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - mpu.memory[0x0000] = (0x4A) #=> LSR A + # $0000 LSR A + mpu.memory[0x0000] = (0x4A) mpu.a = 0x04 mpu.step() self.assertEqual(0x0001, mpu.pc) @@ -2969,7 +3212,8 @@ class Common6502Tests: def test_lsr_absolute_rotates_in_zero_not_carry(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD + # $0000 LSR $ABCD + self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2981,7 +3225,8 @@ class Common6502Tests: def test_lsr_absolute_sets_carry_and_zero_flags_after_rotation(self): mpu = self._make_mpu() mpu.p &= ~mpu.CARRY - self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD + # $0000 LSR $ABCD + self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -2993,7 +3238,8 @@ class Common6502Tests: def test_lsr_absolute_rotates_bits_right(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD + # $0000 LSR $ABCD + self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x04 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3007,7 +3253,8 @@ class Common6502Tests: def test_lsr_zp_rotates_in_zero_not_carry(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 + # $0000 LSR $0010 + self._write(mpu.memory, 0x0000, (0x46, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3019,7 +3266,8 @@ class Common6502Tests: def test_lsr_zp_sets_carry_and_zero_flags_after_rotation(self): mpu = self._make_mpu() mpu.p &= ~mpu.CARRY - self._write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 + # $0000 LSR $0010 + self._write(mpu.memory, 0x0000, (0x46, 0x10)) mpu.memory[0x0010] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3031,7 +3279,8 @@ class Common6502Tests: def test_lsr_zp_rotates_bits_right(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 + # $0000 LSR $0010 + self._write(mpu.memory, 0x0000, (0x46, 0x10)) mpu.memory[0x0010] = 0x04 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3042,11 +3291,12 @@ class Common6502Tests: # LSR Absolute, X-Indexed - def test_lsr_absolute_x_indexed_rotates_in_zero_not_carry(self): + def test_lsr_abs_x_indexed_rotates_in_zero_not_carry(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X + # $0000 LSR $ABCD,X + self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3055,11 +3305,12 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.CARRY) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_lsr_absolute_x_indexed_sets_carry_and_zero_flags_after_rotation(self): + def test_lsr_abs_x_indexed_sets_c_and_z_flags_after_rotation(self): mpu = self._make_mpu() mpu.p &= ~mpu.CARRY mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X + # $0000 LSR $ABCD,X + self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3068,10 +3319,11 @@ class Common6502Tests: self.assertEqual(mpu.CARRY, mpu.p & mpu.CARRY) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_lsr_absolute_x_indexed_rotates_bits_right(self): + def test_lsr_abs_x_indexed_rotates_bits_right(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X + # $0000 LSR $ABCD,X + self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x04 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3086,7 +3338,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.CARRY mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X + # $0000 LSR $0010,X + self._write(mpu.memory, 0x0000, (0x56, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3099,7 +3352,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~mpu.CARRY mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X + # $0000 LSR $0010,X + self._write(mpu.memory, 0x0000, (0x56, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3112,7 +3366,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.CARRY mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X + # $0000 LSR $0010,X + self._write(mpu.memory, 0x0000, (0x56, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x04 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3125,7 +3380,8 @@ class Common6502Tests: def test_nop_does_nothing(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0xEA #=> NOP + # $0000 NOP + mpu.memory[0x0000] = 0xEA mpu.step() self.assertEqual(0x0001, mpu.pc) @@ -3135,7 +3391,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) #=> ORA $ABCD + # $0000 ORA $ABCD + self._write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3146,7 +3403,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 - self._write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) #=> ORA $ABCD + # $0000 ORA $ABCD + self._write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x82 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3160,7 +3418,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x05, 0x10)) #=> ORA $0010 + # $0000 ORA $0010 + self._write(mpu.memory, 0x0000, (0x05, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3171,7 +3430,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 - self._write(mpu.memory, 0x0000, (0x05, 0x10)) #=> ORA $0010 + # $0000 ORA $0010 + self._write(mpu.memory, 0x0000, (0x05, 0x10)) mpu.memory[0x0010] = 0x82 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3185,7 +3445,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x09, 0x00)) #=> ORA #$00 + # $0000 ORA #$00 + self._write(mpu.memory, 0x0000, (0x09, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -3195,7 +3456,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 - self._write(mpu.memory, 0x0000, (0x09, 0x82)) #=> ORA #$82 + # $0000 ORA #$82 + self._write(mpu.memory, 0x0000, (0x09, 0x82)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x83, mpu.a) @@ -3204,24 +3466,26 @@ class Common6502Tests: # ORA Absolute, X - def test_ora_absolute_x_indexed_zeroes_or_zeros_sets_z_flag(self): + def test_ora_abs_x_indexed_zeroes_or_zeros_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) #=> ORA $ABCD,X + # $0000 ORA $ABCD,X + self._write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_ora_absolute_x_indexed_turns_bits_on_sets_n_flag(self): + def test_ora_abs_x_indexed_turns_bits_on_sets_n_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) #=> ORA $ABCD,X + # $0000 ORA $ABCD,X + self._write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x82 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3231,24 +3495,26 @@ class Common6502Tests: # ORA Absolute, Y - def test_ora_absolute_y_indexed_zeroes_or_zeros_sets_z_flag(self): + def test_ora_abs_y_indexed_zeroes_or_zeros_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) #=> ORA $ABCD,Y + # $0000 ORA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_ora_absolute_y_indexed_turns_bits_on_sets_n_flag(self): + def test_ora_abs_y_indexed_turns_bits_on_sets_n_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) #=> ORA $ABCD,Y + # $0000 ORA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x82 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3258,26 +3524,30 @@ class Common6502Tests: # ORA Indirect, Indexed (X) - def test_ora_indirect_indexed_x_zeroes_or_zeros_sets_z_flag(self): + def test_ora_ind_indexed_x_zeroes_or_zeros_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x01, 0x10)) #=> ORA ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ORA ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x01, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_ora_indirect_indexed_x_turns_bits_on_sets_n_flag(self): + def test_ora_ind_indexed_x_turns_bits_on_sets_n_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x01, 0x10)) #=> ORA ($0010,X) - self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ORA ($0010,X) + # $0013 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x01, 0x10)) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x82 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3287,26 +3557,30 @@ class Common6502Tests: # ORA Indexed, Indirect (Y) - def test_ora_indexed_indirect_y_zeroes_or_zeros_sets_z_flag(self): + def test_ora_indexed_ind_y_zeroes_or_zeros_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x11, 0x10)) #=> ORA ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ORA ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x11, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_ora_indexed_indirect_y_turns_bits_on_sets_n_flag(self): + def test_ora_indexed_ind_y_turns_bits_on_sets_n_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x11, 0x10)) #=> ORA ($0010),Y - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ORA ($0010),Y + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x11, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x82 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3321,7 +3595,8 @@ class Common6502Tests: mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x15, 0x10)) #=> ORA $0010,X + # $0000 ORA $0010,X + self._write(mpu.memory, 0x0000, (0x15, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3333,7 +3608,8 @@ class Common6502Tests: mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x15, 0x10)) #=> ORA $0010,X + # $0000 ORA $0010,X + self._write(mpu.memory, 0x0000, (0x15, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x82 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3346,7 +3622,8 @@ class Common6502Tests: def test_pha_pushes_a_and_updates_sp(self): mpu = self._make_mpu() mpu.a = 0xAB - mpu.memory[0x0000] = 0x48 #=> PHA + # $0000 PHA + mpu.memory[0x0000] = 0x48 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.a) @@ -3359,17 +3636,20 @@ class Common6502Tests: for flags in range(0x100): mpu = self._make_mpu() mpu.p = flags | mpu.BREAK | mpu.UNUSED - mpu.memory[0x0000] = 0x08 #=> PHP + # $0000 PHP + mpu.memory[0x0000] = 0x08 mpu.step() self.assertEqual(0x0001, mpu.pc) - self.assertEqual((flags | mpu.BREAK | mpu.UNUSED), mpu.memory[0x1FF]) - self.assertEqual(0xFE, mpu.sp) + self.assertEqual((flags | mpu.BREAK | mpu.UNUSED), + mpu.memory[0x1FF]) + self.assertEqual(0xFE, mpu.sp) # PLA def test_pla_pulls_top_byte_from_stack_into_a_and_updates_sp(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0x68 #=> PLA + # $0000 PLA + mpu.memory[0x0000] = 0x68 mpu.memory[0x01FF] = 0xAB mpu.sp = 0xFE mpu.step() @@ -3381,8 +3661,9 @@ class Common6502Tests: def test_plp_pulls_top_byte_from_stack_into_flags_and_updates_sp(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0x28 #=> PLP - mpu.memory[0x01FF] = 0xBA # must have BREAK and UNUSED set + # $0000 PLP + mpu.memory[0x0000] = 0x28 + mpu.memory[0x01FF] = 0xBA # must have BREAK and UNUSED set mpu.sp = 0xFE mpu.step() self.assertEqual(0x0001, mpu.pc) @@ -3395,7 +3676,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.p &= ~(mpu.CARRY) - mpu.memory[0x0000] = 0x2A #=> ROL A + # $0000 ROL A + mpu.memory[0x0000] = 0x2A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -3407,7 +3689,8 @@ class Common6502Tests: mpu.a = 0x80 mpu.p &= ~(mpu.CARRY) mpu.p &= ~(mpu.ZERO) - mpu.memory[0x0000] = 0x2A #=> ROL A + # $0000 ROL A + mpu.memory[0x0000] = 0x2A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -3418,7 +3701,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.p |= mpu.CARRY - mpu.memory[0x0000] = 0x2A #=> ROL A + # $0000 ROL A + mpu.memory[0x0000] = 0x2A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x01, mpu.a) @@ -3429,7 +3713,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x40 mpu.p |= mpu.CARRY - mpu.memory[0x0000] = 0x2A #=> ROL A + # $0000 ROL A + mpu.memory[0x0000] = 0x2A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x81, mpu.a) @@ -3440,7 +3725,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x7F mpu.p &= ~(mpu.CARRY) - mpu.memory[0x0000] = 0x2A #=> ROL A + # $0000 ROL A + mpu.memory[0x0000] = 0x2A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xFE, mpu.a) @@ -3450,7 +3736,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xFF mpu.p &= ~(mpu.CARRY) - mpu.memory[0x0000] = 0x2A #=> ROL A + # $0000 ROL A + mpu.memory[0x0000] = 0x2A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xFE, mpu.a) @@ -3461,7 +3748,8 @@ class Common6502Tests: def test_rol_absolute_zero_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + # $0000 ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3473,7 +3761,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + # $0000 ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3485,7 +3774,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + # $0000 ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3496,7 +3786,8 @@ class Common6502Tests: def test_rol_absolute_sets_n_flag(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + # $0000 ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3507,7 +3798,8 @@ class Common6502Tests: def test_rol_absolute_shifts_out_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + # $0000 ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x7F mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3517,7 +3809,8 @@ class Common6502Tests: def test_rol_absolute_shifts_out_one(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + # $0000 ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3529,7 +3822,8 @@ class Common6502Tests: def test_rol_zp_zero_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + # $0000 ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3541,7 +3835,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + # $0000 ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) mpu.memory[0x0010] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3553,7 +3848,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + # $0000 ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3564,7 +3860,8 @@ class Common6502Tests: def test_rol_zp_sets_n_flag(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + # $0000 ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) mpu.memory[0x0010] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3575,7 +3872,8 @@ class Common6502Tests: def test_rol_zp_shifts_out_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + # $0000 ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) mpu.memory[0x0010] = 0x7F mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3585,7 +3883,8 @@ class Common6502Tests: def test_rol_zp_shifts_out_one(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + # $0000 ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3594,11 +3893,12 @@ class Common6502Tests: # ROL Absolute, X-Indexed - def test_rol_absolute_x_indexed_zero_and_carry_zero_sets_z_flag(self): + def test_rol_abs_x_indexed_zero_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + # $0000 ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3606,12 +3906,13 @@ class Common6502Tests: self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_rol_absolute_x_indexed_80_and_carry_zero_sets_z_flag(self): + def test_rol_abs_x_indexed_80_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.p &= ~(mpu.ZERO) mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + # $0000 ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x80 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3619,11 +3920,12 @@ class Common6502Tests: self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_rol_absolute_x_indexed_zero_and_carry_one_clears_z_flag(self): + def test_rol_abs_x_indexed_zero_and_carry_one_clears_z_flag(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + # $0000 ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3631,11 +3933,12 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_rol_absolute_x_indexed_sets_n_flag(self): + def test_rol_abs_x_indexed_sets_n_flag(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + # $0000 ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x40 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3643,22 +3946,24 @@ class Common6502Tests: self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_rol_absolute_x_indexed_shifts_out_zero(self): + def test_rol_abs_x_indexed_shifts_out_zero(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + # $0000 ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x7F mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0xFE, mpu.memory[0xABCD + mpu.x]) self.assertEqual(0, mpu.p & mpu.CARRY) - def test_rol_absolute_x_indexed_shifts_out_one(self): + def test_rol_abs_x_indexed_shifts_out_one(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + # $0000 ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3671,7 +3976,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) + # $0000 ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3684,7 +3990,8 @@ class Common6502Tests: mpu.p &= ~(mpu.CARRY) mpu.p &= ~(mpu.ZERO) mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) + # $0000 ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3696,7 +4003,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) + # $0000 ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3708,7 +4016,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + # $0000 ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3720,7 +4029,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + # $0000 ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x7F mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3731,7 +4041,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + # $0000 ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3744,7 +4055,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.p &= ~(mpu.CARRY) - mpu.memory[0x0000] = 0x6A #=> ROR A + # $0000 ROR A + mpu.memory[0x0000] = 0x6A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -3755,7 +4067,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x00 mpu.p |= mpu.CARRY - mpu.memory[0x0000] = 0x6A #=> ROR A + # $0000 ROR A + mpu.memory[0x0000] = 0x6A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -3766,7 +4079,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x02 mpu.p |= mpu.CARRY - mpu.memory[0x0000] = 0x6A #=> ROR A + # $0000 ROR A + mpu.memory[0x0000] = 0x6A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x81, mpu.a) @@ -3776,7 +4090,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0x03 mpu.p |= mpu.CARRY - mpu.memory[0x0000] = 0x6A #=> ROR A + # $0000 ROR A + mpu.memory[0x0000] = 0x6A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x81, mpu.a) @@ -3787,7 +4102,8 @@ class Common6502Tests: def test_ror_absolute_zero_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + # $0000 ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3798,7 +4114,8 @@ class Common6502Tests: def test_ror_absolute_zero_and_carry_one_rotates_in_sets_n_flags(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + # $0000 ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3809,7 +4126,8 @@ class Common6502Tests: def test_ror_absolute_shifts_out_zero(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + # $0000 ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x02 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3819,7 +4137,8 @@ class Common6502Tests: def test_ror_absolute_shifts_out_one(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + # $0000 ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x03 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3831,7 +4150,8 @@ class Common6502Tests: def test_ror_zp_zero_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + # $0000 ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3842,7 +4162,8 @@ class Common6502Tests: def test_ror_zp_zero_and_carry_one_rotates_in_sets_n_flags(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + # $0000 ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3853,7 +4174,8 @@ class Common6502Tests: def test_ror_zp_zero_absolute_shifts_out_zero(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + # $0000 ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) mpu.memory[0x0010] = 0x02 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3863,7 +4185,8 @@ class Common6502Tests: def test_ror_zp_shifts_out_one(self): mpu = self._make_mpu() mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + # $0000 ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) mpu.memory[0x0010] = 0x03 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3872,11 +4195,12 @@ class Common6502Tests: # ROR Absolute, X-Indexed - def test_ror_absolute_x_indexed_zero_and_carry_zero_sets_z_flag(self): + def test_ror_abs_x_indexed_zero_and_carry_zero_sets_z_flag(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + # $0000 ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3884,11 +4208,12 @@ class Common6502Tests: self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_ror_absolute_x_indexed_zero_and_carry_one_rotates_in_sets_n_flags(self): + def test_ror_abs_x_indexed_z_and_c_1_rotates_in_sets_n_flags(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + # $0000 ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3896,22 +4221,24 @@ class Common6502Tests: self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) - def test_ror_absolute_x_indexed_shifts_out_zero(self): + def test_ror_abs_x_indexed_shifts_out_zero(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + # $0000 ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x02 mpu.step() self.assertEqual(0x0003, mpu.pc) self.assertEqual(0x81, mpu.memory[0xABCD + mpu.x]) self.assertEqual(0, mpu.p & mpu.CARRY) - def test_ror_absolute_x_indexed_shifts_out_one(self): + def test_ror_abs_x_indexed_shifts_out_one(self): mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + # $0000 ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x03 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -3924,7 +4251,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p &= ~(mpu.CARRY) - self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + # $0000 ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3936,7 +4264,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + # $0000 ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3948,7 +4277,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + # $0000 ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x02 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3959,7 +4289,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0x03 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + # $0000 ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x03 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -3968,10 +4299,11 @@ class Common6502Tests: # RTI - def test_rti_restores_status_register_and_program_counter_and_updates_sp(self): + def test_rti_restores_status_and_pc_and_updates_sp(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0x40 #=> RTI - self._write(mpu.memory, 0x01FD, (0xFC, 0x03, 0xC0)) # Status (P), PCL, PCH + # $0000 RTI + mpu.memory[0x0000] = 0x40 + self._write(mpu.memory, 0x01FD, (0xFC, 0x03, 0xC0)) # Status, PCL, PCH mpu.sp = 0xFC mpu.step() @@ -3981,8 +4313,9 @@ class Common6502Tests: def test_rti_forces_break_and_unused_flags_high(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0x40 #=> RTI - self._write(mpu.memory, 0x01FD, (0x00, 0x03, 0xC0)) # Status (P), PCL, PCH + # $0000 RTI + mpu.memory[0x0000] = 0x40 + self._write(mpu.memory, 0x01FD, (0x00, 0x03, 0xC0)) # Status, PCL, PCH mpu.sp = 0xFC mpu.step() @@ -3991,10 +4324,11 @@ class Common6502Tests: # RTS - def test_rts_restores_program_counter_and_increments_then_updates_sp(self): + def test_rts_restores_pc_and_increments_then_updates_sp(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0x60 #=> RTS - self._write(mpu.memory, 0x01FE, (0x03, 0xC0)) # PCL, PCH + # $0000 RTS + mpu.memory[0x0000] = 0x60 + self._write(mpu.memory, 0x01FE, (0x03, 0xC0)) # PCL, PCH mpu.sp = 0xFD mpu.step() @@ -4006,9 +4340,10 @@ class Common6502Tests: def test_sbc_abs_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + # $0000 SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4019,9 +4354,10 @@ class Common6502Tests: def test_sbc_abs_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + # $0000 SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4032,9 +4368,10 @@ class Common6502Tests: def test_sbc_abs_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + # $0000 SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4045,9 +4382,10 @@ class Common6502Tests: def test_sbc_abs_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + # $0000 SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x02 mpu.step() self.assertEqual(0x04, mpu.a) @@ -4060,9 +4398,10 @@ class Common6502Tests: def test_sbc_zp_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + # $0000 SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4073,9 +4412,10 @@ class Common6502Tests: def test_sbc_zp_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + # $0000 SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) mpu.memory[0x0010] = 0x01 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4086,9 +4426,10 @@ class Common6502Tests: def test_sbc_zp_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + # => SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4099,9 +4440,10 @@ class Common6502Tests: def test_sbc_zp_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + # => SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) mpu.memory[0x0010] = 0x02 mpu.step() self.assertEqual(0x04, mpu.a) @@ -4114,9 +4456,10 @@ class Common6502Tests: def test_sbc_imm_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xE9, 0x00)) #=> SBC #$00 + # $0000 SBC #$00 + self._write(mpu.memory, 0x0000, (0xE9, 0x00)) mpu.step() self.assertEqual(0x00, mpu.a) self.assertEqual(0, mpu.p & mpu.NEGATIVE) @@ -4126,9 +4469,10 @@ class Common6502Tests: def test_sbc_imm_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xE9, 0x01)) #=> SBC #$01 + # $0000 SBC #$01 + self._write(mpu.memory, 0x0000, (0xE9, 0x01)) mpu.step() self.assertEqual(0x00, mpu.a) self.assertEqual(0, mpu.p & mpu.NEGATIVE) @@ -4138,9 +4482,10 @@ class Common6502Tests: def test_sbc_imm_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xE9, 0x00)) #=> SBC #$00 + # $0000 SBC #$00 + self._write(mpu.memory, 0x0000, (0xE9, 0x00)) mpu.step() self.assertEqual(0x00, mpu.a) self.assertEqual(0, mpu.p & mpu.NEGATIVE) @@ -4150,9 +4495,10 @@ class Common6502Tests: def test_sbc_imm_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xE9, 0x02)) #=> SBC #$02 + # $0000 SBC #$02 + self._write(mpu.memory, 0x0000, (0xE9, 0x02)) mpu.step() self.assertEqual(0x04, mpu.a) self.assertEqual(0, mpu.p & mpu.NEGATIVE) @@ -4164,7 +4510,8 @@ class Common6502Tests: mpu.p |= mpu.DECIMAL mpu.p |= mpu.CARRY mpu.a = 0x0a - self._write(mpu.memory, 0x0000, (0xe9, 0x00)) #=> $0000 SBC #$00 + # $0000 SBC #$00 + self._write(mpu.memory, 0x0000, (0xe9, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x0a, mpu.a) @@ -4178,7 +4525,8 @@ class Common6502Tests: mpu.p |= mpu.DECIMAL mpu.p |= mpu.CARRY mpu.a = 0x9a - self._write(mpu.memory, 0x0000, (0xe9, 0x00)) #=> $0000 SBC #$00 + #$0000 SBC #$00 + self._write(mpu.memory, 0x0000, (0xe9, 0x00)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x9a, mpu.a) @@ -4194,7 +4542,8 @@ class Common6502Tests: mpu.p |= mpu.ZERO mpu.p |= mpu.CARRY mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xe9, 0x01)) #=> $0000 SBC #$00 + # => $0000 SBC #$00 + self._write(mpu.memory, 0x0000, (0xe9, 0x01)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x99, mpu.a) @@ -4207,7 +4556,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p |= mpu.DECIMAL mpu.a = 0x20 - self._write(mpu.memory, 0x0000, (0xe9, 0x0a)) #=> $0000 SBC #$00 + # $0000 SBC #$00 + self._write(mpu.memory, 0x0000, (0xe9, 0x0a)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x1f, mpu.a) @@ -4221,9 +4571,10 @@ class Common6502Tests: def test_sbc_abs_x_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + # $0000 SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) mpu.x = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -4235,9 +4586,10 @@ class Common6502Tests: def test_sbc_abs_x_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + # $0000 SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) mpu.x = 0x0D mpu.memory[0xFEED] = 0x01 mpu.step() @@ -4249,9 +4601,10 @@ class Common6502Tests: def test_sbc_abs_x_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + # $0000 SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) mpu.x = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -4263,9 +4616,10 @@ class Common6502Tests: def test_sbc_abs_x_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + # $0000 SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) mpu.x = 0x0D mpu.memory[0xFEED] = 0x02 mpu.step() @@ -4279,9 +4633,10 @@ class Common6502Tests: def test_sbc_abs_y_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + # $0000 SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) mpu.y = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -4293,9 +4648,10 @@ class Common6502Tests: def test_sbc_abs_y_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + # $0000 SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) mpu.y = 0x0D mpu.memory[0xFEED] = 0x01 mpu.step() @@ -4307,9 +4663,10 @@ class Common6502Tests: def test_sbc_abs_y_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + # $0000 SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) mpu.y = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -4321,9 +4678,10 @@ class Common6502Tests: def test_sbc_abs_y_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + # $0000 SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) mpu.y = 0x0D mpu.memory[0xFEED] = 0x02 mpu.step() @@ -4337,10 +4695,12 @@ class Common6502Tests: def test_sbc_ind_x_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10,X) + # $0013 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) mpu.x = 0x03 mpu.memory[0xFEED] = 0x00 mpu.step() @@ -4352,10 +4712,12 @@ class Common6502Tests: def test_sbc_ind_x_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10,X) + # $0013 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) mpu.x = 0x03 mpu.memory[0xFEED] = 0x01 mpu.step() @@ -4367,10 +4729,12 @@ class Common6502Tests: def test_sbc_ind_x_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10,X) + # $0013 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) mpu.x = 0x03 mpu.memory[0xFEED] = 0x00 mpu.step() @@ -4382,10 +4746,12 @@ class Common6502Tests: def test_sbc_ind_x_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10,X) + # $0013 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) mpu.x = 0x03 mpu.memory[0xFEED] = 0x02 mpu.step() @@ -4399,11 +4765,13 @@ class Common6502Tests: def test_sbc_ind_y_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10),Y + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED + mpu.y] = 0x00 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4414,10 +4782,12 @@ class Common6502Tests: def test_sbc_ind_y_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10),Y + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED + mpu.y] = 0x01 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4428,10 +4798,12 @@ class Common6502Tests: def test_sbc_ind_y_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10),Y + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED + mpu.y] = 0x00 mpu.step() self.assertEqual(0x00, mpu.a) @@ -4442,10 +4814,12 @@ class Common6502Tests: def test_sbc_ind_y_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10),Y + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED + mpu.y] = 0x02 mpu.step() self.assertEqual(0x04, mpu.a) @@ -4458,9 +4832,10 @@ class Common6502Tests: def test_sbc_zp_x_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + # $0000 SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) mpu.x = 0x0D mpu.memory[0x001D] = 0x00 mpu.step() @@ -4472,9 +4847,10 @@ class Common6502Tests: def test_sbc_zp_x_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + # $0000 SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) mpu.x = 0x0D mpu.memory[0x001D] = 0x01 mpu.step() @@ -4486,9 +4862,10 @@ class Common6502Tests: def test_sbc_zp_x_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + # $0000 SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) mpu.x = 0x0D mpu.memory[0x001D] = 0x00 mpu.step() @@ -4500,9 +4877,10 @@ class Common6502Tests: def test_sbc_zp_x_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + # $0000 SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) mpu.x = 0x0D mpu.memory[0x001D] = 0x02 mpu.step() @@ -4516,7 +4894,8 @@ class Common6502Tests: def test_sec_sets_carry_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) - mpu.memory[0x0000] = 0x038 #=> SEC + # $0000 SEC + mpu.memory[0x0000] = 0x038 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(mpu.CARRY, mpu.p & mpu.CARRY) @@ -4526,7 +4905,8 @@ class Common6502Tests: def test_sed_sets_decimal_mode_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.memory[0x0000] = 0xF8 #=> SED + # $0000 SED + mpu.memory[0x0000] = 0xF8 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(mpu.DECIMAL, mpu.p & mpu.DECIMAL) @@ -4536,7 +4916,8 @@ class Common6502Tests: def test_sei_sets_interrupt_disable_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.INTERRUPT) - mpu.memory[0x0000] = 0x78 #=> SEI + # $0000 SEI + mpu.memory[0x0000] = 0x78 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(mpu.INTERRUPT, mpu.p & mpu.INTERRUPT) @@ -4547,7 +4928,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) #=> STA $ABCD + # $0000 STA $ABCD + self._write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4559,7 +4941,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) #=> STA $ABCD + # $0000 STA $ABCD + self._write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4573,7 +4956,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x85, 0x10)) #=> STA $0010 + # $0000 STA $0010 + self._write(mpu.memory, 0x0000, (0x85, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4585,7 +4969,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x85, 0x10)) #=> STA $0010 + # $0000 STA $0010 + self._write(mpu.memory, 0x0000, (0x85, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4595,12 +4980,13 @@ class Common6502Tests: # STA Absolute, X-Indexed - def test_sta_absolute_x_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): + def test_sta_abs_x_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) #=> STA $ABCD,X + # $0000 STA $ABCD,X + self._write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4608,12 +4994,13 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.a) self.assertEqual(flags, mpu.p) - def test_sta_absolute_x_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): + def test_sta_abs_x_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) #=> STA $ABCD,X + # $0000 STA $ABCD,X + self._write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4623,12 +5010,13 @@ class Common6502Tests: # STA Absolute, Y-Indexed - def test_sta_absolute_y_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): + def test_sta_abs_y_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) #=> STA $ABCD,Y + # $0000 STA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4636,12 +5024,13 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.a) self.assertEqual(flags, mpu.p) - def test_sta_absolute_y_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): + def test_sta_abs_y_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) #=> STA $ABCD,Y + # $0000 STA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4651,13 +5040,15 @@ class Common6502Tests: # STA Indirect, Indexed (X) - def test_sta_indirect_indexed_x_stores_a_leaves_a_and_n_flag_unchanged(self): + def test_sta_ind_indexed_x_stores_a_leaves_a_and_n_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x81, 0x10)) #=> STA ($0010,X) - self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 STA ($0010,X) + # $0013 Vector to $FEED + self._write(mpu.memory, 0x0000, (0x81, 0x10)) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4665,13 +5056,15 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.a) self.assertEqual(flags, mpu.p) - def test_sta_indirect_indexed_x_stores_a_leaves_a_and_z_flag_unchanged(self): + def test_sta_ind_indexed_x_stores_a_leaves_a_and_z_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x81, 0x10)) #=> STA ($0010,X) - self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 STA ($0010,X) + # $0013 Vector to $FEED + self._write(mpu.memory, 0x0000, (0x81, 0x10)) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) mpu.memory[0xFEED] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4681,13 +5074,15 @@ class Common6502Tests: # STA Indexed, Indirect (Y) - def test_sta_indexed_indirect_y_stores_a_leaves_a_and_n_flag_unchanged(self): + def test_sta_indexed_ind_y_stores_a_leaves_a_and_n_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x91, 0x10)) #=> STA ($0010),Y - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 STA ($0010),Y + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0x91, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4695,13 +5090,15 @@ class Common6502Tests: self.assertEqual(0xFF, mpu.a) self.assertEqual(flags, mpu.p) - def test_sta_indexed_indirect_y_stores_a_leaves_a_and_z_flag_unchanged(self): + def test_sta_indexed_ind_y_stores_a_leaves_a_and_z_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x91, 0x10)) #=> STA ($0010),Y - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 STA ($0010),Y + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0x91, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4716,7 +5113,8 @@ class Common6502Tests: mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x95, 0x10)) #=> STA $0010,X + # $0000 STA $0010,X + self._write(mpu.memory, 0x0000, (0x95, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4729,7 +5127,8 @@ class Common6502Tests: mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x95, 0x10)) #=> STA $0010,X + # $0000 STA $0010,X + self._write(mpu.memory, 0x0000, (0x95, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4743,7 +5142,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.x = 0xFF - self._write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) #=> STX $ABCD + # $0000 STX $ABCD + self._write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4755,7 +5155,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.x = 0x00 - self._write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) #=> STX $ABCD + # $0000 STX $ABCD + self._write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4769,7 +5170,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.x = 0xFF - self._write(mpu.memory, 0x0000, (0x86, 0x10)) #=> STX $0010 + # $0000 STX $0010 + self._write(mpu.memory, 0x0000, (0x86, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4781,7 +5183,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.x = 0x00 - self._write(mpu.memory, 0x0000, (0x86, 0x10)) #=> STX $0010 + # $0000 STX $0010 + self._write(mpu.memory, 0x0000, (0x86, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4796,7 +5199,8 @@ class Common6502Tests: mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.x = 0xFF mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x96, 0x10)) #=> STX $0010,Y + # $0000 STX $0010,Y + self._write(mpu.memory, 0x0000, (0x96, 0x10)) mpu.memory[0x0010 + mpu.y] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4809,7 +5213,8 @@ class Common6502Tests: mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.x = 0x00 mpu.y = 0x03 - self._write(mpu.memory, 0x0000, (0x96, 0x10)) #=> STX $0010,Y + # $0000 STX $0010,Y + self._write(mpu.memory, 0x0000, (0x96, 0x10)) mpu.memory[0x0010 + mpu.y] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4823,7 +5228,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.y = 0xFF - self._write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) #=> STY $ABCD + # $0000 STY $ABCD + self._write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4835,7 +5241,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.y = 0x00 - self._write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) #=> STY $ABCD + # $0000 STY $ABCD + self._write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0003, mpu.pc) @@ -4849,7 +5256,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.y = 0xFF - self._write(mpu.memory, 0x0000, (0x84, 0x10)) #=> STY $0010 + # $0000 STY $0010 + self._write(mpu.memory, 0x0000, (0x84, 0x10)) mpu.memory[0x0010] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4861,7 +5269,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.y = 0x00 - self._write(mpu.memory, 0x0000, (0x84, 0x10)) #=> STY $0010 + # $0000 STY $0010 + self._write(mpu.memory, 0x0000, (0x84, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4876,7 +5285,8 @@ class Common6502Tests: mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.y = 0xFF mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x94, 0x10)) #=> STY $0010,X + # $0000 STY $0010,X + self._write(mpu.memory, 0x0000, (0x94, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4889,7 +5299,8 @@ class Common6502Tests: mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.y = 0x00 mpu.x = 0x03 - self._write(mpu.memory, 0x0000, (0x94, 0x10)) #=> STY $0010,X + # $0000 STY $0010,X + self._write(mpu.memory, 0x0000, (0x94, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -4903,7 +5314,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xAB mpu.x = 0x00 - mpu.memory[0x0000] = 0xAA #=> TAX + # $0000 TAX + mpu.memory[0x0000] = 0xAA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.a) @@ -4914,7 +5326,8 @@ class Common6502Tests: mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x80 mpu.x = 0x00 - mpu.memory[0x0000] = 0xAA #=> TAX + # $0000 TAX + mpu.memory[0x0000] = 0xAA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -4926,7 +5339,8 @@ class Common6502Tests: mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0xFF - mpu.memory[0x0000] = 0xAA #=> TAX + # $0000 TAX + mpu.memory[0x0000] = 0xAA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -4939,7 +5353,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.a = 0xAB mpu.y = 0x00 - mpu.memory[0x0000] = 0xA8 #=> TAY + # $0000 TAY + mpu.memory[0x0000] = 0xA8 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.a) @@ -4950,7 +5365,8 @@ class Common6502Tests: mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x80 mpu.y = 0x00 - mpu.memory[0x0000] = 0xA8 #=> TAY + # $0000 TAY + mpu.memory[0x0000] = 0xA8 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -4962,7 +5378,8 @@ class Common6502Tests: mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0xFF - mpu.memory[0x0000] = 0xA8 #=> TAY + # $0000 TAY + mpu.memory[0x0000] = 0xA8 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -4975,7 +5392,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.sp = 0xAB mpu.x = 0x00 - mpu.memory[0x0000] = 0xBA #=> TSX + # $0000 TSX + mpu.memory[0x0000] = 0xBA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.sp) @@ -4986,7 +5404,8 @@ class Common6502Tests: mpu.p &= ~(mpu.NEGATIVE) mpu.sp = 0x80 mpu.x = 0x00 - mpu.memory[0x0000] = 0xBA #=> TSX + # $0000 TSX + mpu.memory[0x0000] = 0xBA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.sp) @@ -4997,8 +5416,9 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.sp = 0x00 - mpu.y = 0xFF - mpu.memory[0x0000] = 0xBA #=> TSX + mpu.y = 0xFF + # $0000 TSX + mpu.memory[0x0000] = 0xBA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.sp) @@ -5011,7 +5431,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0xAB mpu.a = 0x00 - mpu.memory[0x0000] = 0x8A #=> TXA + # $0000 TXA + mpu.memory[0x0000] = 0x8A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.a) @@ -5022,7 +5443,8 @@ class Common6502Tests: mpu.p &= ~(mpu.NEGATIVE) mpu.x = 0x80 mpu.a = 0x00 - mpu.memory[0x0000] = 0x8A #=> TXA + # $0000 TXA + mpu.memory[0x0000] = 0x8A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -5033,8 +5455,9 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.x = 0x00 - mpu.a = 0xFF - mpu.memory[0x0000] = 0x8A #=> TXA + mpu.a = 0xFF + # $0000 TXA + mpu.memory[0x0000] = 0x8A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.a) @@ -5046,7 +5469,8 @@ class Common6502Tests: def test_txs_transfers_x_into_stack_pointer(self): mpu = self._make_mpu() mpu.x = 0xAB - mpu.memory[0x0000] = 0x9A #=> TXS + # $0000 TXS + mpu.memory[0x0000] = 0x9A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.sp) @@ -5056,7 +5480,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.x = 0x80 - mpu.memory[0x0000] = 0x9A #=> TXS + # $0000 TXS + mpu.memory[0x0000] = 0x9A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.sp) @@ -5067,7 +5492,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.x = 0x00 - mpu.memory[0x0000] = 0x9A #=> TXS + # $0000 TXS + mpu.memory[0x0000] = 0x9A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x00, mpu.sp) @@ -5080,7 +5506,8 @@ class Common6502Tests: mpu = self._make_mpu() mpu.y = 0xAB mpu.a = 0x00 - mpu.memory[0x0000] = 0x98 #=> TYA + # $0000 TYA + mpu.memory[0x0000] = 0x98 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.a) @@ -5091,7 +5518,8 @@ class Common6502Tests: mpu.p &= ~(mpu.NEGATIVE) mpu.y = 0x80 mpu.a = 0x00 - mpu.memory[0x0000] = 0x98 #=> TYA + # $0000 TYA + mpu.memory[0x0000] = 0x98 mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0x80, mpu.a) @@ -5102,8 +5530,9 @@ class Common6502Tests: mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.y = 0x00 - mpu.a = 0xFF - mpu.memory[0x0000] = 0x98 #=> TYA + mpu.a = 0xFF + # $0000 TYA + mpu.memory[0x0000] = 0x98 mpu.step() self.assertEqual(0x00, mpu.a) self.assertEqual(0x00, mpu.y) @@ -5120,67 +5549,71 @@ class Common6502Tests: def test_brk_interrupt(self): mpu = self._make_mpu() mpu.p = 0x00 - self._write(mpu.memory, 0xFFFE, (0x00, 0x04)) # 0x0400 + self._write(mpu.memory, 0xFFFE, (0x00, 0x04)) - self._write(mpu.memory, 0x0000, (0xA9, 0x01, #=> LDA #$01 - 0x00, 0xEA, #=> BRK (and skipped byte) - 0xEA, 0xEA, #=> NOP, NOP - 0xA9, 0x03)) #=> LDA #$03 + self._write(mpu.memory, 0x0000, (0xA9, 0x01, # LDA #$01 + 0x00, 0xEA, # BRK + skipped byte + 0xEA, 0xEA, # NOP, NOP + 0xA9, 0x03)) # LDA #$03 - self._write(mpu.memory, 0x0400, (0xA9, 0x02, #=> LDA #$02 - 0x40)) #=> RTI + self._write(mpu.memory, 0x0400, (0xA9, 0x02, # LDA #$02 + 0x40)) # RTI - mpu.step() # LDA #$01 + mpu.step() # LDA #$01 self.assertEqual(0x01, mpu.a) self.assertEqual(0x0002, mpu.pc) - mpu.step() # BRK + mpu.step() # BRK self.assertEqual(0x0400, mpu.pc) - mpu.step() # LDA #$02 + mpu.step() # LDA #$02 self.assertEqual(0x02, mpu.a) self.assertEqual(0x0402, mpu.pc) - mpu.step() # RTI + mpu.step() # RTI self.assertEqual(0x0004, mpu.pc) - mpu.step() # A NOP - mpu.step() # The second NOP + mpu.step() # A NOP + mpu.step() # The second NOP - mpu.step() # LDA #$03 + mpu.step() # LDA #$03 self.assertEqual(0x03, mpu.a) self.assertEqual(0x0008, mpu.pc) # Test page wrapping - def test_zeropage_indexed_indirect_wrap(self): + def test_zeropage_indexed_ind_wrap(self): mpu = self._make_mpu() mpu.y = 0 mpu.memory[0xb100] = 0x31 mpu.memory[0x00ff] = 0 - self._write(mpu.memory, 0, (0xb1, 0xff)) # LDA ($FF),Y + # $0000 LDA ($FF),Y + self._write(mpu.memory, 0, (0xb1, 0xff)) mpu.step() self.assertEqual(0x31, mpu.a) def test_zeropage_indexed_wrap(self): mpu = self._make_mpu() mpu.x = 1 - self._write(mpu.memory, 0, (0xb5, 0xff)) # LDA $FF,X + # $0000 LDA $FF,X + self._write(mpu.memory, 0, (0xb5, 0xff)) mpu.step() self.assertEqual(0xb5, mpu.a) - def test_zeropage_indirect_indexed_wrap(self): + def test_zeropage_ind_indexed_wrap(self): mpu = self._make_mpu() mpu.x = 0 mpu.memory[0xa100] = 0x31 mpu.memory[0xff] = 0 - self._write(mpu.memory, 0, (0xa1, 0xff)) # LDA ($FF,X) + # $0000 LDA ($FF,X) + self._write(mpu.memory, 0, (0xa1, 0xff)) mpu.step() self.assertEqual(0x31, mpu.a) - def test_zeropage_indirect_indexed_indexwrap(self): + def test_zeropage_ind_indexed_indexwrap(self): mpu = self._make_mpu() mpu.x = 0xff mpu.memory[0xa100] = 0x31 mpu.memory[0x00ff] = 0 - self._write(mpu.memory, 0, (0xa1, 0)) # LDA ($00,X) + # $0000 LDA ($00,X) + self._write(mpu.memory, 0, (0xa1, 0)) mpu.step() self.assertEqual(0x31, mpu.a) @@ -5188,24 +5621,25 @@ class Common6502Tests: mpu = self._make_mpu() mpu.x = 0xff mpu.memory[0x00ff] = 0 - self._write(mpu.memory, 0, (0x6c, 0xff, 0x00)) # LDA ($00,X) + # $0000 LDA ($00,X) + self._write(mpu.memory, 0, (0x6c, 0xff, 0x00)) mpu.step() self.assertEqual(0x6c00, mpu.pc) # Test Helpers def _write(self, memory, start_address, bytes): - memory[start_address:start_address+len(bytes)] = bytes + memory[start_address:start_address + len(bytes)] = bytes def _make_mpu(self, *args, **kargs): klass = self._get_target_class() mpu = klass(*args, **kargs) - if not kargs.has_key('memory'): + if 'memory' not in kargs: mpu.memory = 0x10000 * [0xAA] return mpu def _get_target_class(self): - raise NotImplementedError, "Target class not specified" + raise NotImplementedError("Target class not specified") class MPUTests(unittest.TestCase, Common6502Tests): diff --git a/py65/tests/devices/test_mpu65c02.py b/py65/tests/devices/test_mpu65c02.py index 2965492..dfd34f7 100644 --- a/py65/tests/devices/test_mpu65c02.py +++ b/py65/tests/devices/test_mpu65c02.py @@ -13,11 +13,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): # ADC Zero Page, Indirect - def test_adc_bcd_off_zp_indirect_carry_clear_in_accumulator_zeroes(self): + def test_adc_bcd_off_zp_ind_carry_clear_in_accumulator_zeroes(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -27,12 +29,14 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_adc_bcd_off_zp_indirect_carry_set_in_accumulator_zero(self): + def test_adc_bcd_off_zp_ind_carry_set_in_accumulator_zero(self): mpu = self._make_mpu() mpu.a = 0 mpu.p |= mpu.CARRY - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -42,11 +46,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0, mpu.p & mpu.ZERO) self.assertNotEquals(mpu.CARRY, mpu.p & mpu.CARRY) - def test_adc_bcd_off_zp_indirect_carry_clear_in_no_carry_clear_out(self): + def test_adc_bcd_off_zp_ind_carry_clear_in_no_carry_clear_out(self): mpu = self._make_mpu() mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFE mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -56,11 +62,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0, mpu.p & mpu.CARRY) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_zp_indirect_carry_clear_in_carry_set_out(self): + def test_adc_bcd_off_zp_ind_carry_clear_in_carry_set_out(self): mpu = self._make_mpu() mpu.a = 0x02 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -70,59 +78,69 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_adc_bcd_off_zp_indirect_overflow_cleared_no_carry_01_plus_01(self): + def test_adc_bcd_off_zp_ind_overflow_cleared_no_carry_01_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x02, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_zp_indirect_overflow_cleared_no_carry_01_plus_ff(self): + def test_adc_bcd_off_zp_ind_overflow_cleared_no_carry_01_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x00, mpu.a) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_zp_indirect_overflow_set_no_carry_7f_plus_01(self): + def test_adc_bcd_off_zp_ind_overflow_set_no_carry_7f_plus_01(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x7f - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x80, mpu.a) self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_zp_indirect_overflow_set_no_carry_80_plus_ff(self): + def test_adc_bcd_off_zp_ind_overflow_set_no_carry_80_plus_ff(self): mpu = self._make_mpu() mpu.p &= ~(mpu.CARRY) mpu.a = 0x80 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x7f, mpu.a) self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) - def test_adc_bcd_off_zp_indirect_overflow_set_on_40_plus_40(self): + def test_adc_bcd_off_zp_ind_overflow_set_on_40_plus_40(self): mpu = self._make_mpu() mpu.a = 0x40 - self._write(mpu.memory, 0x0000, (0x72, 0x10)) #=> $0000 ADC ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ADC ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x72, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x40 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -133,11 +151,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): # AND Zero Page, Indirect - def test_and_zp_indirect_all_zeros_setting_zero_flag(self): + def test_and_zp_ind_all_zeros_setting_zero_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x32, 0x10)) #=> AND ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 AND ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x32, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -146,11 +166,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - def test_and_zp_indirect_zeros_and_ones_setting_negative_flag(self): + def test_and_zp_ind_zeros_and_ones_setting_negative_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x32, 0x10)) #=> AND ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 AND ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x32, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xAA mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -165,7 +187,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0xFF mpu.a = 0xFF mpu.step() @@ -177,7 +200,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0xFF mpu.step() @@ -189,7 +213,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0xFF mpu.a = 0xFF mpu.step() @@ -201,7 +226,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0xFF mpu.step() @@ -209,11 +235,12 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(4, mpu.processorCycles) self.assertEqual(0x0003, mpu.pc) - def test_bit_abs_x_stores_result_of_and_in_z_while_preserving_a_when_1(self): + def test_bit_abs_x_stores_result_of_and_in_z_preserves_a_when_1(self): mpu = self._make_mpu() mpu.p &= ~mpu.ZERO mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0x01 mpu.step() @@ -223,29 +250,31 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(4, mpu.processorCycles) self.assertEqual(0x0003, mpu.pc) - def test_bit_abs_x_stores_result_of_and_when_nonzero_in_z_while_preserving_a(self): + def test_bit_abs_x_stores_result_of_and_nonzero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p |= mpu.ZERO mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0x01 mpu.a = 0x01 mpu.step() - self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero + self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x01, mpu.memory[0xFEED]) self.assertEqual(4, mpu.processorCycles) self.assertEqual(0x0003, mpu.pc) - def test_bit_abs_x_stores_result_of_and_when_zero_in_z_while_preserving_a(self): + def test_bit_abs_x_stores_result_of_and_when_zero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.x = 0x02 - self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) #=> BIT $FEEB,X + # $0000 BIT $FEEB,X + self._write(mpu.memory, 0x0000, (0x3C, 0xEB, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.a = 0x01 mpu.step() - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0xFEED]) self.assertEqual(4, mpu.processorCycles) @@ -256,7 +285,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_bit_zp_x_copies_bit_7_of_memory_to_n_flag_when_0(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0xFF mpu.x = 0x03 mpu.a = 0xFF @@ -268,7 +298,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_bit_zp_x_copies_bit_7_of_memory_to_n_flag_when_1(self): mpu = self._make_mpu() mpu.p |= mpu.NEGATIVE - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0x00 mpu.x = 0x03 mpu.a = 0xFF @@ -280,7 +311,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_bit_zp_x_copies_bit_6_of_memory_to_v_flag_when_0(self): mpu = self._make_mpu() mpu.p &= ~(mpu.OVERFLOW) - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0xFF mpu.x = 0x03 mpu.a = 0xFF @@ -292,7 +324,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_bit_zp_x_copies_bit_6_of_memory_to_v_flag_when_1(self): mpu = self._make_mpu() mpu.p |= mpu.OVERFLOW - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0x00 mpu.x = 0x03 mpu.a = 0xFF @@ -301,10 +334,11 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(4, mpu.processorCycles) self.assertEqual(0, mpu.p & mpu.OVERFLOW) - def test_bit_zp_x_stores_result_of_and_in_z_while_preserving_a_when_1(self): + def test_bit_zp_x_stores_result_of_and_in_z_preserves_a_when_1(self): mpu = self._make_mpu() mpu.p &= ~mpu.ZERO - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0x00 mpu.x = 0x03 mpu.a = 0x01 @@ -315,41 +349,45 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0x0010 + mpu.x]) - def test_bit_zp_x_stores_result_of_and_when_nonzero_in_z_while_preserving_a(self): + def test_bit_zp_x_stores_result_of_and_when_nonzero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p |= mpu.ZERO - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0x01 mpu.x = 0x03 mpu.a = 0x01 mpu.step() - self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero + self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero self.assertEqual(0x0002, mpu.pc) self.assertEqual(4, mpu.processorCycles) self.assertEqual(0x01, mpu.a) self.assertEqual(0x01, mpu.memory[0x0010 + mpu.x]) - def test_bit_zp_x_stores_result_of_and_when_zero_in_z_while_preserving_a(self): + def test_bit_zp_x_stores_result_of_and_when_zero_in_z_preserves_a(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) - self._write(mpu.memory, 0x0000, (0x34, 0x10)) #=> BIT $0010,X + # $0000 BIT $0010,X + self._write(mpu.memory, 0x0000, (0x34, 0x10)) mpu.memory[0x0013] = 0x00 mpu.x = 0x03 mpu.a = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(4, mpu.processorCycles) - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero self.assertEqual(0x01, mpu.a) self.assertEqual(0x00, mpu.memory[0x0010 + mpu.x]) # EOR Zero Page, Indirect - def test_eor_zp_indirect_flips_bits_over_setting_z_flag(self): + def test_eor_zp_ind_flips_bits_over_setting_z_flag(self): mpu = self._make_mpu() mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x52, 0x10)) #=> EOR ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 EOR ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x52, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -358,11 +396,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0xFF, mpu.memory[0xABCD]) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_eor_zp_indirect_flips_bits_over_setting_n_flag(self): + def test_eor_zp_ind_flips_bits_over_setting_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x52, 0x10)) #=> EOR ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 EOR ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x52, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -374,11 +414,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): # LDA Zero Page, Indirect - def test_lda_zp_indirect_loads_a_sets_n_flag(self): + def test_lda_zp_ind_loads_a_sets_n_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xB2, 0x10)) #=> LDA ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 LDA ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xB2, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -387,11 +429,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) - def test_lda_zp_indirect_loads_a_sets_z_flag(self): + def test_lda_zp_ind_loads_a_sets_z_flag(self): mpu = self._make_mpu() mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xB2, 0x10)) #=> LDA ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 LDA ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xB2, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -402,14 +446,16 @@ class MPUTests(unittest.TestCase, Common6502Tests): # ORA Zero Page, Indirect - def test_ora_zp_indirect_zeroes_or_zeros_sets_z_flag(self): + def test_ora_zp_ind_zeroes_or_zeros_sets_z_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.ZERO) mpu.a = 0x00 - mpu.y = 0x12 # These should not affect the ORA + mpu.y = 0x12 # These should not affect the ORA mpu.x = 0x34 - self._write(mpu.memory, 0x0000, (0x12, 0x10)) #=> ORA ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ORA ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x12, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -417,12 +463,14 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x00, mpu.a) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_ora_zp_indirect_turns_bits_on_sets_n_flag(self): + def test_ora_zp_ind_turns_bits_on_sets_n_flag(self): mpu = self._make_mpu() mpu.p &= ~(mpu.NEGATIVE) mpu.a = 0x03 - self._write(mpu.memory, 0x0000, (0x12, 0x10)) #=> ORA ($0010) - self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + # $0000 ORA ($0010) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x12, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) mpu.memory[0xABCD] = 0x82 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -436,7 +484,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_phx_pushes_x_and_updates_sp(self): mpu = self._make_mpu() mpu.x = 0xAB - mpu.memory[0x0000] = 0xDA #=> PHX + # $0000 PHX + mpu.memory[0x0000] = 0xDA mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.x) @@ -449,7 +498,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_phy_pushes_y_and_updates_sp(self): mpu = self._make_mpu() mpu.y = 0xAB - mpu.memory[0x0000] = 0x5A #=> PHY + # $0000 PHY + mpu.memory[0x0000] = 0x5A mpu.step() self.assertEqual(0x0001, mpu.pc) self.assertEqual(0xAB, mpu.y) @@ -461,7 +511,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_plx_pulls_top_byte_from_stack_into_x_and_updates_sp(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0xFA #=> PLX + # $0000 PLX + mpu.memory[0x0000] = 0xFA mpu.memory[0x01FF] = 0xAB mpu.sp = 0xFE mpu.step() @@ -474,7 +525,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_ply_pulls_top_byte_from_stack_into_y_and_updates_sp(self): mpu = self._make_mpu() - mpu.memory[0x0000] = 0x7A #=> PLY + # $0000 PLY + mpu.memory[0x0000] = 0x7A mpu.memory[0x01FF] = 0xAB mpu.sp = 0xFE mpu.step() @@ -487,8 +539,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb0_clears_bit_0_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x07, 0x43)) #=> RMB0 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB0 $43 + self._write(mpu.memory, 0x0000, (0x07, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -497,8 +550,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb0_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x07, 0x43)) #=> RMB0 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB0 $43 + self._write(mpu.memory, 0x0000, (0x07, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -508,8 +562,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb1_clears_bit_1_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x17, 0x43)) #=> RMB1 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB1 $43 + self._write(mpu.memory, 0x0000, (0x17, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -518,8 +573,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb1_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x17, 0x43)) #=> RMB1 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB1 $43 + self._write(mpu.memory, 0x0000, (0x17, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -529,8 +585,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb2_clears_bit_2_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x27, 0x43)) #=> RMB2 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB2 $43 + self._write(mpu.memory, 0x0000, (0x27, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -539,8 +596,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb2_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x27, 0x43)) #=> RMB2 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB2 $43 + self._write(mpu.memory, 0x0000, (0x27, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -550,8 +608,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb3_clears_bit_3_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x37, 0x43)) #=> RMB3 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB3 $43 + self._write(mpu.memory, 0x0000, (0x37, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -560,8 +619,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb3_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x37, 0x43)) #=> RMB3 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB3 $43 + self._write(mpu.memory, 0x0000, (0x37, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -571,8 +631,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb4_clears_bit_4_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x47, 0x43)) #=> RMB4 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB4 $43 + self._write(mpu.memory, 0x0000, (0x47, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -581,8 +642,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb4_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x47, 0x43)) #=> RMB4 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB4 $43 + self._write(mpu.memory, 0x0000, (0x47, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -592,8 +654,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb5_clears_bit_5_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x57, 0x43)) #=> RMB5 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB5 $43 + self._write(mpu.memory, 0x0000, (0x57, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -602,8 +665,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb5_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x57, 0x43)) #=> RMB5 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB5 $43 + self._write(mpu.memory, 0x0000, (0x57, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -613,8 +677,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb6_clears_bit_6_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x67, 0x43)) #=> RMB6 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB6 $43 + self._write(mpu.memory, 0x0000, (0x67, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -623,8 +688,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb6_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x67, 0x43)) #=> RMB6 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB6 $43 + self._write(mpu.memory, 0x0000, (0x67, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -634,8 +700,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb7_clears_bit_7_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x77, 0x43)) #=> RMB7 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB7 $43 + self._write(mpu.memory, 0x0000, (0x77, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -644,8 +711,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_rmb7_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('11111111',2) - self._write(mpu.memory, 0x0000, (0x77, 0x43)) #=> RMB7 $43 + mpu.memory[0x0043] = int('11111111', 2) + # $0000 RMB7 $43 + self._write(mpu.memory, 0x0000, (0x77, 0x43)) expected = int('01010101', 2) mpu.p = expected mpu.step() @@ -653,12 +721,14 @@ class MPUTests(unittest.TestCase, Common6502Tests): # STA Zero Page, Indirect - def test_sta_zp_indirect_stores_a_leaves_a_and_n_flag_unchanged(self): + def test_sta_zp_ind_stores_a_leaves_a_and_n_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF - self._write(mpu.memory, 0x0000, (0x92, 0x10)) #=> STA ($0010) - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 STA ($0010) + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0x92, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -667,12 +737,14 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0xFF, mpu.a) self.assertEqual(flags, mpu.p) - def test_sta_zp_indirect_stores_a_leaves_a_and_z_flag_unchanged(self): + def test_sta_zp_ind_stores_a_leaves_a_and_z_flag_unchanged(self): mpu = self._make_mpu() mpu.p = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0x92, 0x10)) #=> STA ($0010) - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 STA ($0010) + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0x92, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED] = 0xFF mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -685,8 +757,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb0_sets_bit_0_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0x87, 0x43)) #=> SMB0 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB0 $43 + self._write(mpu.memory, 0x0000, (0x87, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -695,8 +768,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb0_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0x87, 0x43)) #=> SMB0 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB0 $43 + self._write(mpu.memory, 0x0000, (0x87, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -706,8 +780,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb1_sets_bit_1_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0x97, 0x43)) #=> SMB1 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB1 $43 + self._write(mpu.memory, 0x0000, (0x97, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -716,8 +791,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb1_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0x97, 0x43)) #=> SMB1 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB1 $43 + self._write(mpu.memory, 0x0000, (0x97, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -727,8 +803,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb2_sets_bit_2_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xA7, 0x43)) #=> SMB2 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB2 $43 + self._write(mpu.memory, 0x0000, (0xA7, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -737,8 +814,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb2_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xA7, 0x43)) #=> SMB2 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB2 $43 + self._write(mpu.memory, 0x0000, (0xA7, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -748,8 +826,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb3_sets_bit_3_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xB7, 0x43)) #=> SMB3 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB3 $43 + self._write(mpu.memory, 0x0000, (0xB7, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -758,8 +837,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb3_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xB7, 0x43)) #=> SMB3 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB3 $43 + self._write(mpu.memory, 0x0000, (0xB7, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -769,8 +849,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb4_sets_bit_4_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xC7, 0x43)) #=> SMB4 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB4 $43 + self._write(mpu.memory, 0x0000, (0xC7, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -779,8 +860,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb4_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xC7, 0x43)) #=> SMB4 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB4 $43 + self._write(mpu.memory, 0x0000, (0xC7, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -790,8 +872,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb5_sets_bit_5_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xD7, 0x43)) #=> SMB5 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB5 $43 + self._write(mpu.memory, 0x0000, (0xD7, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -800,8 +883,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb5_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xD7, 0x43)) #=> SMB5 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB5 $43 + self._write(mpu.memory, 0x0000, (0xD7, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -811,8 +895,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb6_sets_bit_6_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xE7, 0x43)) #=> SMB6 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB6 $43 + self._write(mpu.memory, 0x0000, (0xE7, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -821,8 +906,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb6_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xE7, 0x43)) #=> SMB6 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB6 $43 + self._write(mpu.memory, 0x0000, (0xE7, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -832,8 +918,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb7_sets_bit_7_without_affecting_other_bits(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xF7, 0x43)) #=> SMB7 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB7 $43 + self._write(mpu.memory, 0x0000, (0xF7, 0x43)) mpu.step() self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -842,8 +929,9 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_smb7_does_not_affect_status_register(self): mpu = self._make_mpu() - mpu.memory[0x0043] = int('00000000',2) - self._write(mpu.memory, 0x0000, (0xF7, 0x43)) #=> SMB7 $43 + mpu.memory[0x0043] = int('00000000', 2) + # $0000 SMB7 $43 + self._write(mpu.memory, 0x0000, (0xF7, 0x43)) expected = int('11001100', 2) mpu.p = expected mpu.step() @@ -851,13 +939,15 @@ class MPUTests(unittest.TestCase, Common6502Tests): # SBC Zero Page, Indirect - def test_sbc_zp_indirect_all_zeros_and_no_borrow_is_zero(self): + def test_sbc_zp_ind_all_zeros_and_no_borrow_is_zero(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - self._write(mpu.memory, 0x0000, (0xF2, 0x10)) #=> SBC ($10) - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10) + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF2, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -867,13 +957,15 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.CARRY, mpu.CARRY) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_sbc_zp_indirect_downto_zero_no_borrow_sets_z_clears_n(self): + def test_sbc_zp_ind_downto_zero_no_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p |= mpu.CARRY # borrow = 0 + mpu.p |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF2, 0x10)) #=> SBC ($10) - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10) + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF2, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED] = 0x01 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -883,13 +975,15 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.CARRY, mpu.CARRY) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_sbc_zp_indirect_downto_zero_with_borrow_sets_z_clears_n(self): + def test_sbc_zp_ind_downto_zero_with_borrow_sets_z_clears_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - self._write(mpu.memory, 0x0000, (0xF2, 0x10)) #=> SBC ($10) - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10) + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF2, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED] = 0x00 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -899,13 +993,15 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.CARRY, mpu.CARRY) self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - def test_sbc_zp_indirect_downto_four_with_borrow_clears_z_n(self): + def test_sbc_zp_ind_downto_four_with_borrow_clears_z_n(self): mpu = self._make_mpu() mpu.p &= ~(mpu.DECIMAL) - mpu.p &= ~(mpu.CARRY) # borrow = 1 + mpu.p &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - self._write(mpu.memory, 0x0000, (0xF2, 0x10)) #=> SBC ($10) - self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + # $0000 SBC ($10) + # $0010 Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF2, 0x10)) + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) mpu.memory[0xFEED] = 0x02 mpu.step() self.assertEqual(0x0002, mpu.pc) @@ -920,7 +1016,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_stz_zp_stores_zero(self): mpu = self._make_mpu() mpu.memory[0x0032] = 0x88 - mpu.memory[0x0000:0x0000+2] = [0x64, 0x32] #=> STZ $32 + # #0000 STZ $32 + mpu.memory[0x0000:0x0000 + 2] = [0x64, 0x32] self.assertEqual(0x88, mpu.memory[0x0032]) mpu.step() self.assertEqual(0x00, mpu.memory[0x0032]) @@ -932,7 +1029,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_stz_zp_x_stores_zero(self): mpu = self._make_mpu() mpu.memory[0x0032] = 0x88 - mpu.memory[0x0000:0x0000+2] = [0x74, 0x32] #=> STZ $32,X + # $0000 STZ $32,X + mpu.memory[0x0000:0x0000 + 2] = [0x74, 0x32] self.assertEqual(0x88, mpu.memory[0x0032]) mpu.step() self.assertEqual(0x00, mpu.memory[0x0032]) @@ -944,7 +1042,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_stz_abs_stores_zero(self): mpu = self._make_mpu() mpu.memory[0xFEED] = 0x88 - mpu.memory[0x0000:0x0000+3] = [0x9C, 0xED, 0xFE] #=> STZ $FEED + # $0000 STZ $FEED + mpu.memory[0x0000:0x0000 + 3] = [0x9C, 0xED, 0xFE] self.assertEqual(0x88, mpu.memory[0xFEED]) mpu.step() self.assertEqual(0x00, mpu.memory[0xFEED]) @@ -957,7 +1056,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu = self._make_mpu() mpu.memory[0xFEED] = 0x88 mpu.x = 0x0D - mpu.memory[0x0000:0x0000+3] = [0x9E, 0xE0, 0xFE] #=> STZ $FEE0,X + # $0000 STZ $FEE0,X + mpu.memory[0x0000:0x0000 + 3] = [0x9E, 0xE0, 0xFE] self.assertEqual(0x88, mpu.memory[0xFEED]) self.assertEqual(0x0D, mpu.x) mpu.step() @@ -970,7 +1070,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_tsb_sp_ones(self): mpu = self._make_mpu() mpu.memory[0x00BB] = 0xE0 - self._write(mpu.memory, 0x0000, [0x04, 0xBB]) #=> TSB $BD + # $0000 TSB $BD + self._write(mpu.memory, 0x0000, [0x04, 0xBB]) mpu.a = 0x70 self.assertEqual(0xE0, mpu.memory[0x00BB]) mpu.step() @@ -982,7 +1083,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_tsb_sp_zeros(self): mpu = self._make_mpu() mpu.memory[0x00BB] = 0x80 - self._write(mpu.memory, 0x0000, [0x04, 0xBB]) #=> TSB $BD + # $0000 TSB $BD + self._write(mpu.memory, 0x0000, [0x04, 0xBB]) mpu.a = 0x60 self.assertEqual(0x80, mpu.memory[0x00BB]) mpu.step() @@ -991,13 +1093,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) - # TSB Absolute def test_tsb_abs_ones(self): mpu = self._make_mpu() mpu.memory[0xFEED] = 0xE0 - self._write(mpu.memory, 0x0000, [0x0C, 0xED, 0xFE]) #=> TSB $FEED + # $0000 TSB $FEED + self._write(mpu.memory, 0x0000, [0x0C, 0xED, 0xFE]) mpu.a = 0x70 self.assertEqual(0xE0, mpu.memory[0xFEED]) mpu.step() @@ -1009,7 +1111,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_tsb_abs_zeros(self): mpu = self._make_mpu() mpu.memory[0xFEED] = 0x80 - self._write(mpu.memory, 0x0000, [0x0C, 0xED, 0xFE]) #=> TSB $FEED + # $0000 TSB $FEED + self._write(mpu.memory, 0x0000, [0x0C, 0xED, 0xFE]) mpu.a = 0x60 self.assertEqual(0x80, mpu.memory[0xFEED]) mpu.step() @@ -1023,7 +1126,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_trb_sp_ones(self): mpu = self._make_mpu() mpu.memory[0x00BB] = 0xE0 - self._write(mpu.memory, 0x0000, [0x14, 0xBB]) #=> TRB $BD + # $0000 TRB $BD + self._write(mpu.memory, 0x0000, [0x14, 0xBB]) mpu.a = 0x70 self.assertEqual(0xE0, mpu.memory[0x00BB]) mpu.step() @@ -1035,7 +1139,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_trb_sp_zeros(self): mpu = self._make_mpu() mpu.memory[0x00BB] = 0x80 - self._write(mpu.memory, 0x0000, [0x14, 0xBB]) #=> TRB $BD + # $0000 TRB $BD + self._write(mpu.memory, 0x0000, [0x14, 0xBB]) mpu.a = 0x60 self.assertEqual(0x80, mpu.memory[0x00BB]) mpu.step() @@ -1044,13 +1149,13 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) - # TRB Absolute def test_trb_abs_ones(self): mpu = self._make_mpu() mpu.memory[0xFEED] = 0xE0 - self._write(mpu.memory, 0x0000, [0x1C, 0xED, 0xFE]) #=> TRB $FEED + # $0000 TRB $FEED + self._write(mpu.memory, 0x0000, [0x1C, 0xED, 0xFE]) mpu.a = 0x70 self.assertEqual(0xE0, mpu.memory[0xFEED]) mpu.step() @@ -1062,7 +1167,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_trb_abs_zeros(self): mpu = self._make_mpu() mpu.memory[0xFEED] = 0x80 - self._write(mpu.memory, 0x0000, [0x1C, 0xED, 0xFE]) #=> TRB $FEED + # $0000 TRB $FEED + self._write(mpu.memory, 0x0000, [0x1C, 0xED, 0xFE]) mpu.a = 0x60 self.assertEqual(0x80, mpu.memory[0xFEED]) mpu.step() @@ -1073,7 +1179,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_dec_a_decreases_a(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, [0x3A]) #=> DEC A + # $0000 DEC A + self._write(mpu.memory, 0x0000, [0x3A]) mpu.a = 0x48 mpu.step() self.assertEqual(0, mpu.p & mpu.ZERO) @@ -1082,7 +1189,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_dec_a_sets_zero_flag(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, [0x3A]) #=> DEC A + # $0000 DEC A + self._write(mpu.memory, 0x0000, [0x3A]) mpu.a = 0x01 mpu.step() self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) @@ -1091,7 +1199,8 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_dec_a_wraps_at_zero(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, [0x3A]) #=> DEC A + # $0000 DEC A + self._write(mpu.memory, 0x0000, [0x3A]) mpu.a = 0x00 mpu.step() self.assertEqual(0, mpu.p & mpu.ZERO) @@ -1100,18 +1209,20 @@ class MPUTests(unittest.TestCase, Common6502Tests): def test_bra_forward(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0000, [0x80, 0x10]) #=> BRA $10 + # $0000 BRA $10 + self._write(mpu.memory, 0x0000, [0x80, 0x10]) mpu.step() self.assertEqual(0x12, mpu.pc) self.assertEqual(2, mpu.processorCycles) def test_bra_backward(self): mpu = self._make_mpu() - self._write(mpu.memory, 0x0204, [0x80, 0xF0]) #=> BRA $F0 + # $0240 BRA $F0 + self._write(mpu.memory, 0x0204, [0x80, 0xF0]) mpu.pc = 0x0204 mpu.step() self.assertEqual(0x1F6, mpu.pc) - self.assertEqual(3, mpu.processorCycles) # Crossed boundry + self.assertEqual(3, mpu.processorCycles) # Crossed boundry # Test Helpers diff --git a/py65/tests/test_assembler.py b/py65/tests/test_assembler.py index 05bb02c..75d113a 100644 --- a/py65/tests/test_assembler.py +++ b/py65/tests/test_assembler.py @@ -5,6 +5,7 @@ from py65.devices.mpu65c02 import MPU as MPU65C02 from py65.assembler import Assembler from py65.utils.addressing import AddressParser + class AssemblerTests(unittest.TestCase): def test_assemble_bad_syntax_raises_syntaxerror(self): self.assertRaises(SyntaxError, @@ -955,6 +956,7 @@ class AssemblerTests(unittest.TestCase): assembler = Assembler(mpu, address_parser) return assembler.assemble(statement, pc) + def test_suite(): return unittest.findTestCases(sys.modules[__name__]) diff --git a/py65/tests/test_disassembler.py b/py65/tests/test_disassembler.py index 700a799..18bfe65 100644 --- a/py65/tests/test_disassembler.py +++ b/py65/tests/test_disassembler.py @@ -5,6 +5,7 @@ from py65.devices.mpu65c02 import MPU as MPU65C02 from py65.disassembler import Disassembler from py65.utils.addressing import AddressParser + class DisassemblerTests(unittest.TestCase): def test_disassembles_00(self): length, disasm = self.disassemble([0x00]) @@ -1304,9 +1305,10 @@ class DisassemblerTests(unittest.TestCase): mpu = MPU() address_parser = AddressParser() disasm = Disassembler(mpu, address_parser) - mpu.memory[pc:len(bytes)-1] = bytes + mpu.memory[pc:len(bytes) - 81] = bytes return disasm.instruction_at(pc) + def test_suite(): return unittest.findTestCases(sys.modules[__name__]) diff --git a/py65/tests/test_memory.py b/py65/tests/test_memory.py index 7ccddaf..5ad224f 100644 --- a/py65/tests/test_memory.py +++ b/py65/tests/test_memory.py @@ -4,6 +4,7 @@ import re import os from py65.memory import ObservableMemory + class ObservableMemoryTests(unittest.TestCase): # __setitem__ @@ -56,7 +57,7 @@ class ObservableMemoryTests(unittest.TestCase): def read_subscriber(address, value): return 0xAB - mem.subscribe_to_read(xrange(0xC000, 0xC001+1), read_subscriber) + mem.subscribe_to_read(xrange(0xC000, 0xC001 + 1), read_subscriber) mem[0xC000] = 0xAB mem[0xC001] = 0xAB @@ -68,6 +69,7 @@ class ObservableMemoryTests(unittest.TestCase): mem = ObservableMemory(subject=subject) calls = [] + def read_subscriber(address): calls.append('read_subscriber') @@ -107,6 +109,7 @@ class ObservableMemoryTests(unittest.TestCase): mem = ObservableMemory(subject=subject) calls = [] + def read_subscriber_1(address): calls.append('read_subscriber_1') return 0x01 @@ -139,7 +142,7 @@ class ObservableMemoryTests(unittest.TestCase): def write_subscriber(address, value): return 0xFF - mem.subscribe_to_write([0xC000,0xC001], write_subscriber) + mem.subscribe_to_write([0xC000, 0xC001], write_subscriber) mem.write(0xC000, [0x01, 002]) self.assertEqual(0x01, subject[0xC000]) diff --git a/py65/tests/test_monitor.py b/py65/tests/test_monitor.py index 5e6d0b5..686519e 100644 --- a/py65/tests/test_monitor.py +++ b/py65/tests/test_monitor.py @@ -6,6 +6,7 @@ import tempfile from py65.monitor import Monitor from StringIO import StringIO + class MonitorTests(unittest.TestCase): # line processing @@ -213,7 +214,7 @@ class MonitorTests(unittest.TestCase): def test_do_cycles_shows_count_after_step(self): stdout = StringIO() mon = Monitor(stdout=stdout) - mon._mpu.memory[0x0000] = 0xEA #=> NOP (2 cycles) + mon._mpu.memory[0x0000] = 0xEA # => NOP (2 cycles) mon._mpu.step() mon.do_cycles("") @@ -249,7 +250,7 @@ class MonitorTests(unittest.TestCase): mon = Monitor(stdout=stdout) mon._address_parser.labels['foo'] = 0xc000 mon.do_delete_label('foo') - self.assertFalse(mon._address_parser.labels.has_key('foo')) + self.assertFalse('foo' in mon._address_parser.labels) out = stdout.getvalue() self.assertEqual('', out) @@ -280,7 +281,7 @@ class MonitorTests(unittest.TestCase): def test_disassemble_will_disassemble_one_address(self): stdout = StringIO() mon = Monitor(stdout=stdout) - mon._mpu.memory[0xc000] = 0xEA #=> NOP + mon._mpu.memory[0xc000] = 0xEA # => NOP mon._mpu.step() mon.do_disassemble("c000") @@ -291,8 +292,8 @@ class MonitorTests(unittest.TestCase): def test_disassemble_will_disassemble_an_address_range(self): stdout = StringIO() mon = Monitor(stdout=stdout) - mon._mpu.memory[0xc000] = 0xEA #=> NOP - mon._mpu.memory[0xc001] = 0xEA #=> NOP + mon._mpu.memory[0xc000] = 0xEA # => NOP + mon._mpu.memory[0xc001] = 0xEA # => NOP mon._mpu.step() mon.do_disassemble("c000:c002") @@ -462,7 +463,8 @@ class MonitorTests(unittest.TestCase): mon.do_load("'%s' a600" % filename) self.assertEqual('Wrote +3 bytes from $a600 to $a602\n', stdout.getvalue()) - self.assertEqual([0xAA, 0xBB, 0xCC], mon._mpu.memory[0xA600:0xA603]) + self.assertEqual([0xAA, 0xBB, 0xCC], + mon._mpu.memory[0xA600:0xA603]) finally: os.unlink(filename) @@ -632,7 +634,6 @@ class MonitorTests(unittest.TestCase): out = stdout.getvalue() self.assertEqual("%s\n" % os.getcwd(), out) - def test_help_pwd(self): stdout = StringIO() mon = Monitor(stdout=stdout) @@ -714,7 +715,7 @@ class MonitorTests(unittest.TestCase): mon = Monitor(stdout=stdout) mon.help_registers() out = stdout.getvalue() - self.assertTrue(out.startswith("registers[")) + self.assertTrue(out.startswith("registers[")) # return diff --git a/py65/tests/utils/test_addressing.py b/py65/tests/utils/test_addressing.py index 40164f8..a4ce268 100644 --- a/py65/tests/utils/test_addressing.py +++ b/py65/tests/utils/test_addressing.py @@ -2,6 +2,7 @@ import unittest import sys from py65.utils.addressing import AddressParser + class AddressParserTests(unittest.TestCase): def test_maxwidth_can_be_set_in_constructor(self): parser = AddressParser(maxwidth=24) @@ -122,7 +123,7 @@ class AddressParserTests(unittest.TestCase): self.assertRaises(OverflowError, parser.number, 'foo+5') def test_label_for_returns_label(self): - parser = AddressParser(labels={'chrout':0xFFD2}) + parser = AddressParser(labels={'chrout': 0xFFD2}) self.assertEqual('chrout', parser.label_for(0xFFD2)) def test_label_for_returns_none_by_default(self): diff --git a/py65/tests/utils/test_console.py b/py65/tests/utils/test_console.py index 34a1163..c64a87a 100644 --- a/py65/tests/utils/test_console.py +++ b/py65/tests/utils/test_console.py @@ -2,6 +2,7 @@ import sys import unittest from py65.utils.console import getch + class ConsoleTopLevelTests(unittest.TestCase): pass diff --git a/py65/tests/utils/test_conversions.py b/py65/tests/utils/test_conversions.py index 88325dc..1d79527 100644 --- a/py65/tests/utils/test_conversions.py +++ b/py65/tests/utils/test_conversions.py @@ -2,6 +2,7 @@ import sys import unittest from py65.utils.conversions import itoa + class ConversionsTopLevelTests(unittest.TestCase): def test_itoa_decimal_output(self): self.assertEqual('10', itoa(10, base=10)) diff --git a/py65/tests/utils/test_hexdump.py b/py65/tests/utils/test_hexdump.py index fc897d7..0bedce7 100644 --- a/py65/tests/utils/test_hexdump.py +++ b/py65/tests/utils/test_hexdump.py @@ -2,6 +2,7 @@ import unittest import sys from py65.utils.hexdump import load, Loader + class TopLevelHexdumpTests(unittest.TestCase): def test_load(self): text = 'c000: aa bb' @@ -9,6 +10,7 @@ class TopLevelHexdumpTests(unittest.TestCase): self.assertEqual(0xC000, start) self.assertEqual([0xAA, 0xBB], data) + class HexdumpLoaderTests(unittest.TestCase): def test_empty_string_does_nothing(self): text = '' @@ -126,7 +128,6 @@ class HexdumpLoaderTests(unittest.TestCase): self.assertEqual([0xAA, 0xBB], load.data) - def test_suite(): return unittest.findTestCases(sys.modules[__name__]) diff --git a/py65/utils/addressing.py b/py65/utils/addressing.py index 6e9fbab..2782177 100644 --- a/py65/utils/addressing.py +++ b/py65/utils/addressing.py @@ -1,5 +1,6 @@ import re + class AddressParser(object): """Parse user input into addresses or ranges of addresses. """ diff --git a/py65/utils/console.py b/py65/utils/console.py index bfa4253..dbbcc9a 100644 --- a/py65/utils/console.py +++ b/py65/utils/console.py @@ -4,11 +4,11 @@ if sys.platform[:3] == "win": import msvcrt def getch(stdin): - """ Read one character from the Windows console, blocking until one - is available. Does not echo the character. The stdin argument is - for function signature compatibility and is ignored. - """ - return msvcrt.getch() + """ Read one character from the Windows console, blocking until one + is available. Does not echo the character. The stdin argument is + for function signature compatibility and is ignored. + """ + return msvcrt.getch() def getch_noblock(stdin): """ Read one character from the Windows console without blocking. @@ -26,19 +26,19 @@ else: import fcntl def getch(stdin): - """ Read one character from stdin, blocking until one is available. - Does not echo the character. - """ - fd = stdin.fileno() - oldattr = termios.tcgetattr(fd) - newattr = oldattr[:] - newattr[3] &= ~termios.ICANON & ~termios.ECHO - try: - termios.tcsetattr(fd, termios.TCSANOW, newattr) - char = stdin.read(1) - finally: - termios.tcsetattr(fd, termios.TCSAFLUSH, oldattr) - return char + """ Read one character from stdin, blocking until one is available. + Does not echo the character. + """ + fd = stdin.fileno() + oldattr = termios.tcgetattr(fd) + newattr = oldattr[:] + newattr[3] &= ~termios.ICANON & ~termios.ECHO + try: + termios.tcsetattr(fd, termios.TCSANOW, newattr) + char = stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSAFLUSH, oldattr) + return char def getch_noblock(stdin): """ Read one character from stdin without blocking. Does not echo the @@ -63,7 +63,7 @@ else: if char == "\n": char = "\r" else: - char = '' + char = '' finally: termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) @@ -79,18 +79,18 @@ def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout): stdout.write(prompt) line = '' while True: - char = getch(stdin) - code = ord(char) - if char in ("\n", "\r"): - break - elif code in (0x7f, 0x08): # backspace - if len(line) > 0: - line = line[:-1] - stdout.write("\r%s\r%s%s" % \ - (' ' * (len(prompt+line) +5), prompt, line)) - elif code == 0x1b: # escape - pass - else: - line += char - stdout.write(char) + char = getch(stdin) + code = ord(char) + if char in ("\n", "\r"): + break + elif code in (0x7f, 0x08): # backspace + if len(line) > 0: + line = line[:-1] + stdout.write("\r%s\r%s%s" % + (' ' * (len(prompt + line) + 5), prompt, line)) + elif code == 0x1b: # escape + pass + else: + line += char + stdout.write(char) return line diff --git a/py65/utils/conversions.py b/py65/utils/conversions.py index b983e59..79dfea3 100644 --- a/py65/utils/conversions.py +++ b/py65/utils/conversions.py @@ -1,53 +1,59 @@ + + def itoa(num, base=10): """ Convert a decimal number to its equivalent in another base. This is essentially the inverse of int(num, base). """ negative = num < 0 if negative: - num = -num + num = -num digits = [] while num > 0: - num, last_digit = divmod(num, base) - digits.append('0123456789abcdefghijklmnopqrstuvwxyz'[last_digit]) + num, last_digit = divmod(num, base) + digits.append('0123456789abcdefghijklmnopqrstuvwxyz'[last_digit]) if negative: - digits.append('-') + digits.append('-') digits.reverse() return ''.join(digits) + def convert_to_bin(bcd): return bcd2bin[bcd] + def convert_to_bcd(bin): return bin2bcd[bin] + bcd2bin = [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # 0x00 - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, # 0x10 - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, # 0x20 - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, # 0x30 - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, # 0x40 - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, # 0x50 - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, # 0x60 - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, # 0x70 - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, # 0x80 - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105, # 0x90 - 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115, # 0xA0 - 110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125, # 0xB0 - 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135, # 0xC0 - 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145, # 0xD0 - 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155, # 0xE0 - 150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165 # 0xF0 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + 74, 75, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 90, 91, + 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 100, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, + 124, 125, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, + 132, 133, 134, 135, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, + 140, 141, 142, 143, 144, 145, 140, 141, 142, 143, 144, 145, 146, 147, + 148, 149, 150, 151, 152, 153, 154, 155, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, 162, 163, 164, 165 ] + bin2bcd = [ - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59, - 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69, - 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79, - 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89, - 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99 + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99 ] diff --git a/py65/utils/devices.py b/py65/utils/devices.py index df432b5..66d53b8 100644 --- a/py65/utils/devices.py +++ b/py65/utils/devices.py @@ -1,4 +1,5 @@ + def make_instruction_decorator(instruct, disasm, allcycles, allextras): def instruction(name, mode, cycles, extracycles=0): def decorate(f): @@ -7,6 +8,6 @@ def make_instruction_decorator(instruct, disasm, allcycles, allextras): disasm[opcode] = (name, mode) allcycles[opcode] = cycles allextras[opcode] = extracycles - return f # Return the original function + return f # Return the original function return decorate return instruction diff --git a/py65/utils/hexdump.py b/py65/utils/hexdump.py index cd08173..bd24d16 100644 --- a/py65/utils/hexdump.py +++ b/py65/utils/hexdump.py @@ -1,9 +1,11 @@ from binascii import a2b_hex + def load(text): load = Loader(text) return (load.start_address, load.data) + class Loader: def __init__(self, text): self.load(text) @@ -42,15 +44,15 @@ class Loader: def _parse_address(self, piece): try: - addr_bytes = [ ord(c) for c in a2b_hex(piece) ] + addr_bytes = [ord(c) for c in a2b_hex(piece)] except (TypeError, ValueError): msg = "Could not parse address: %s" % piece - raise ValueError, msg + raise ValueError(msg) if len(addr_bytes) != 2: msg = "Expected address to be 2 bytes, got %d" % ( - len(addr_bytes)) - raise ValueError, msg + len(addr_bytes)) + raise ValueError(msg) address = (addr_bytes[0] << 8) + addr_bytes[1] @@ -61,20 +63,20 @@ class Loader: elif address != (self.current_address): msg = "Non-contigous block detected. Expected next address " \ "to be $%04x, label was $%04x" % (self.current_address, - address) - raise ValueError, msg + address) + raise ValueError(msg) def _parse_bytes(self, piece): if self.start_address is None: msg = "Start address was not found in data" - raise ValueError, msg + raise ValueError(msg) else: try: - bytes = [ ord(c) for c in a2b_hex(piece) ] + bytes = [ord(c) for c in a2b_hex(piece)] except (TypeError, ValueError): msg = "Could not parse data: %s" % piece - raise ValueError, msg + raise ValueError(msg) self.current_address += len(bytes) self.data.extend(bytes) diff --git a/setup.py b/setup.py index a890f8a..b4cdbcd 100644 --- a/setup.py +++ b/setup.py @@ -30,31 +30,31 @@ CLASSIFIERS = [ 'Topic :: Software Development :: Interpreters', 'Topic :: System :: Emulators', 'Topic :: System :: Hardware' - ] +] setup( - name = 'py65', - version = __version__, - license = 'License :: OSI Approved :: BSD License', - url = 'https://github.com/mnaberez/py65', - description = '6502 microprocessor simulation package', - long_description= DESC, - classifiers = CLASSIFIERS, - author = "Mike Naberezny", - author_email = "mike@naberezny.com", - maintainer = "Mike Naberezny", - maintainer_email = "mike@naberezny.com", - packages = find_packages(), - install_requires = [], - extras_require = {}, - tests_require = [], - include_package_data = True, - zip_safe = False, - namespace_packages = ['py65'], - test_suite = "py65.tests", - entry_points = { - 'console_scripts': [ - 'py65mon = py65.monitor:main', - ], - }, + name='py65', + version=__version__, + license='License :: OSI Approved :: BSD License', + url='https://github.com/mnaberez/py65', + description='6502 microprocessor simulation package', + long_description=DESC, + classifiers=CLASSIFIERS, + author="Mike Naberezny", + author_email="mike@naberezny.com", + maintainer="Mike Naberezny", + maintainer_email="mike@naberezny.com", + packages=find_packages(), + install_requires=[], + extras_require={}, + tests_require=[], + include_package_data=True, + zip_safe=False, + namespace_packages=['py65'], + test_suite="py65.tests", + entry_points={ + 'console_scripts': [ + 'py65mon = py65.monitor:main', + ], + }, )