Esempio n. 1
0
 def _pull(self, type):
     self.sp = (self.sp + 1) & vm.BITS8 
     if self.sp == 0: 
         raise StackError('Stack underflow')
     if self.stack_contents[self.sp] != type: 
         raise StackError('Corrupt stack, expected {} but pulled {}, sp: {}'
                          .format(type, self.stack_contents[self.sp], 
                                  vm.hex8(self.sp)))
         
     return self.mem[memmap.STACK_PAGE + self.sp] 
Esempio n. 2
0
 def _setitem_single(self, index, value):
     """
     Notifies listeners for each byte store and calls abstract _load. 
     Emits warning if read only. 
     """
     if self.read_only: 
         raise ReadOnlyError('Write {} to read-only location {}'
                             .format(vm.hex8(value), vm.hex16(index)))
     else:
         self._store(vm.size16(index), value)
         [listener(index, value) for listener in self.store_listeners]
Esempio n. 3
0
def get_instruction_set():
    """
    Returns a dictionary containing all of the instructions recognized by the 
    x6502 CPU. Values are :class:`Instruction` objects keyed by opcode. 
    """
    from mach8 import instructions
    
    instruction_set = dict() 
    for op_name in instructions.__all__: 
        op = getattr(instructions, op_name)
        if op.opcode in instruction_set: 
            raise ValueError('Duplicate opcode: {}', vm.hex8(op.opcode)) 
        instruction_set[op.opcode] = op
    return instruction_set
Esempio n. 4
0
 def next(self):
     """
     Executes the next instruction.
     """
     try:
         opcode = self.fetch()
         address = self.pc 
         try:
             instruction = self._instruction_set[opcode] 
         except KeyError: 
             raise IllegalInstructionError('Invalid opcode: {}' 
                                           .format(vm.hex8(opcode))) 
         instruction.execute(self, instruction.operation, 
                             instruction.addressing_mode)
         [listener(address, instruction) for listener in self.run_listeners]
     except: 
         self.exit = EXIT_TRAP 
         raise   
Esempio n. 5
0
 def _format_instruction(self):
     """
     Formats the instruction name and arguments. 
     """
     i = self.instruction
     try:
         formatter, has_argument = FORMAT_TABLE[i.addressing_mode]
     except KeyError:
         raise ValueError('Invalid addressing mode: ' + 
                          str(i.addressing_mode)) 
     
     if not has_argument: 
         return formatter.format(i.operation) 
     
     if self.argument is None:
         # Format the raw bytes 
         if len(self.bytes) == 2: 
             arg = vm.hex8(self.bytes[1])
         else: 
             arg = vm.hex16(vm.to_words(self.bytes[1:3])[0]) 
     else: 
         arg = self.argument 
     return formatter.format(i.operation, arg) 
Esempio n. 6
0
 def _memory_watcher(self, address, value):
     if address in self.watches: 
         print 'mem {} <-= {}{}'.format(vm.hex16(address), vm.hex8(value), 
                                        self._labels_at_address(address))  
Esempio n. 7
0
 def memory_store_listener(self, address, value):
     if not self.logging_run:
         suite.log.info('mem {} <-= {}'.format(vm.hex16(address), 
                                               vm.hex8(value)))
Esempio n. 8
0
 def test_hex8(self):
     self.assertEquals('$0a', vm.hex8(0x0a))