class Register(object):
    def __init__(self, name, bitwidth):
        self.name = name
        self.value = 0
        self.past = [0] # maybe for rewind?
        self.symbVal = [z3.BitVec(self.name, bitwidth)] # maybe for 
                                                        # symbolic
                                                        # execution?
    def GetValue(self):
        return self.value
    
    def SetValue(self, value):
        self.value = value

    def GetCurrentSymb(self):
        return self.symbVal[-1]

    def GetInitialSymb(self):
        return self.symbVal[0]

    def SetInitialSymb(self, value):
        self.symbVal[0] = value


class CPU(object):
    def __init__(self, bitwidth, baseAddress):
        self.regs = {  'A': Register('A', bitwidth),
                       'X': Register('X', bitwidth),
                       'Y': Register('Y', bitwidth),
                       'PC': Register('PC', bitwidth * 2),
                       'S': Register('S', bitwidth),
                       'P': Register('P', bitwidth)}

        self.bitwidth = bitwidth
        self.ptrSize = 2 # 2 bytes for PC
        self.memory = []
        self.pastMemory = []
        self.symbMemory = z3Array('mem', z3.BitVecSort(bitwidth), z3.BitVecSort(8))

        if (baseAddress):
            self.regs['PC'].SetValue(baseAddress)

        def ReadMemory(self, address): # always read 1 byte
            return self.memory[address]

        def SetMemory(self, address, value): # always write 1 byte
            self.memory[address] = value
            return value

        def GetRegister(name):
            return self.regs[name].GetValue()

        def SetRegister(self, name, value):
            self.regs[name].SetValue(value)
            return value

@@ -1752,28 +1752,1211 @@
 e)%0A            return value%0A
+%0A        def SetFlag(self, flagName, value):%0A            flags = %7B   'C':0,  # Carry%0A                        'Z':1,  # Zero%0A                        'I':3,  # Interrupt mask%0A                        'V':6,  # Overflow%0A                        'N':7%7D  # Negative%0A%0A            flagReg = self.GetRegister('P')%0A            if value == 1:%0A                newFlag = flagReg %7C 1 %3C%3C flags%5BflagName%5D%0A            else:%0A                newFlag = flagReg & ~(1 %3C%3C flags%5BflagName%5D)%0A%0A            self.SetRegister('P', newFlag)%0A%0A        def CreateOverflowCondition(oldDst, oldSrc):%0A            pass%0A%0A        def CreatecarryCondition(oldDst, oldSrc, subOp):%0A            pass%0A%0A        def UpdateFlags(self, flags, oldDst, oldSrc, newVal, carry, subOp):%0A            ofCond = self.CreateOverflowCondition(oldDst, oldSrc)%0A            cfConf = self.CreateCarryCondition(oldDst, oldSrc, subOp)%0A%0A            validFlags = %7B  'C': cfCond == True,%0A                            'Z': newVal == 0,%0A                            'V': ofCond == True,%0A                            'N': ((newVal & 0x80) != 0)%7D%0A%0A            for flag in flags:%0A                self.SetFlag(flag, validFlags%5Bflag%5D)%0A%0A%0A                        %0A

Add some flags handling code