def transferencia(sign): # (DE) <- (HL) dir1 = int(Z80.D + Z80.E, 16) dir2 = int(Z80.H + Z80.L, 16) con = Z80.mem.obtenerContenido(hex(dir2)[2:]) flag = Z80.mem.cambiarContenido(con, hex(dir1)[2:]) # DE <- DE + 1 o DE <- DE - 1 dir1 = eval(str(dir1) + sign + '1') dir1 = funciones.tohex(dir1, 16) Z80.D = dir1[:2] Z80.E = dir1[2:] # HL <- HL + 1 o HL <- HL - 1 dir2 = eval(str(dir2) + sign + '1') dir2 = funciones.tohex(dir2, 16) Z80.H = dir2[:2] Z80.L = dir2[2:] # BC <- BC - 1 dir1 = int(Z80.B + Z80.C, 16) - 1 if dir1 == 0: Z80.changeFlag(2, '0') else: Z80.changeFlag(2, '1') dir1 = funciones.tohex(dir1, 16) Z80.B = dir1[:2] Z80.C = dir1[2:] return flag
def ADD(op1, op2): if op1 == 'A': s = Z80.obtenerS(op2) Z80.halfCarry(Z80.A, s, '+') s = int(Z80.A, 16) + int(s, 16) Z80.carry(s) Z80.zero(s) Z80.overflow(s) Z80.sign(s) Z80.changeFlag(1,'0') Z80.A = funciones.tohex(s, 8) elif op1 == 'IX' or op1 == 'IY': s = int(getattr(Z80, op1), 16) + int(Z80.obtenerSS(op2), 16) Z80.carry(s) Z80.changeFlag(1,'0') s = funciones.tohex(s, 16) setattr(Z80, op1, s) else: HL = ''.join([Z80.H, Z80.L]) ss = Z80.obtenerSS(op2) HL = int(HL, 16) + int(ss, 16) Z80.carry(HL) Z80.changeFlag(1,'0') HL = funciones.tohex(HL, 16) Z80.H = HL[:2] Z80.L = HL[2:]
def busqueda(o): # BC <- BC - 1 v = int(Z80.B + Z80.C, 16) - 1 if v == 0: Z80.changeFlag(2, '0') else: Z80.changeFlag(2, '1') v = funciones.tohex(v, 16) Z80.B = v[:2] Z80.C = v[2:] # HL <- HL + 1 o HL <- HL - 1 HL = Z80.H + Z80.L v = eval(str(int(HL, 16)) + o + '1') v = funciones.tohex(v, 16) Z80.H = v[:2] Z80.L = v[2:] # A - (HL) cont = Z80.mem.obtenerContenido(HL) Z80.halfCarry(Z80.A, cont, '-') Z80.changeFlag(1, '1') cont = int(Z80.A, 16) - int(cont, 16) Z80.sign(cont) if Z80.A == Z80.mem.obtenerContenido(HL): Z80.changeFlag(6, '1') return False else: Z80.changeFlag(6, '0') return True
def SBC(op1, op2): CY = getFlagBit(0) # Operacion de 8 bits if (op1 == "A"): s = funciones.tohex(int(Z80.obtenerS(op2),16) + int(CY,16), 8) Z80.halfCarry(Z80.A, s, "-") # Se realiza la operacion y se guarda en el acumulador Z80.A = int(Z80.A, 16) - int(s, 16) Z80.carry(Z80.A) Z80.zero(Z80.A) Z80.sign(Z80.A) Z80.overflow(Z80.A) Z80.A = funciontes.tohex(Z80.A, 8) Z80.changeFlag(1, "1") # Operacion de 16 bits else: # Se obtienen los respectivos valores HL = ''.join([Z80.H, Z80.L]) ss = funciones.tohex(int(Z80.obtenerSS(op2),16)+int(CY,16), 8) Z80.halfCarry(HL, ss, "-") # Se realiza la operacion HL = int(HL,16) - int(ss,16) Z80.carry(HL) Z80.zero(HL) Z80.sign(HL) Z80.overflow(HL) HL = funciones.tohex(HL, 16) Z80.changeFlag(1, "1") # El primer byte se guarda en H y el segundo en L Z80.H = HL[:2] Z80.L = HL[2:] """ >>>>> N = 1, C = Z = S = H = DE ACUERDO A LA OPERACION, P/V = SOBREPASAMIENTO <<<<< """
def ADC(op1, op2): CY = bin(int(Z80.F,16))[2:].zfill(8)[0] if (op1 == "A"): s = Z80.obtenerS(op2) Z80.halfCarry(Z80.A, s, '+') s = int(Z80.A, 16) + int(s, 16) + int(CY, 16) Z80.carry(s) Z80.zero(s) Z80.overflow(s) Z80.sign(s) Z80.changeFlag(1,'0') Z80.A = funciones.tohex(s, 8) else: HL = ''.join([Z80.H, Z80.L]) ss = Z80.obtenerSS(op2) HL = int(HL,16) + int(ss,16) + int(CY, 2) Z80.carry(s) Z80.zero(s) Z80.overflow(s) Z80.sign(s) Z80.changeFlag(1,'0') HL = funciones.tohex(HL, 16) # El primer byte se guarda en H y el segundo en L Z80.H = HL[:2] Z80.L = HL[2:]
def R3T(): Z80.SP = int(Z80.SP,16) ########################### if Z80.SP == 0: Z80.SP = 65536 ########################### if (Z80.SP >= 65024 and Z80.SP < 65535): Z80.PC = Z80.mem.obtenerContenido(funciones.tohex(Z80.SP+1,16))+Z80.mem.obtenerContenido(funciones.tohex(Z80.SP,16)) Z80.SP = str(funciones.tohex(Z80.SP + 2,16)) else: Z80.SP = funciones.tohex(Z80.SP, 16)
def POP(arg): Z80.SP = int(Z80.SP, 16) ####################### if Z80.SP == 0: Z80.SP = 65536 ############## if Z80.SP >= 65024 and Z80.SP < 65535: if arg == 'IX': Z80.IX = Z80.mem.obtenerContenido(hex(Z80.SP + 1)[2:]) + Z80.mem.obtenerContenido(hex(Z80.SP)[2:]) flag1 = Z80.mem.cambiarContenido('00', hex(Z80.SP + 1)) flag2 = Z80.mem.cambiarContenido('00', hex(Z80.SP)) Z80.SP = hex(Z80.SP + 2)[2:].zfill(4).upper() flag1.update(flag2) elif arg == 'IY': Z80.IY = Z80.mem.obtenerContenido(hex(Z80.SP + 1)[2:]) + Z80.mem.obtenerContenido(hex(Z80.SP)[2:]) flag1 = Z80.mem.cambiarContenido('00', hex(Z80.SP + 1)) flag2 = Z80.mem.cambiarContenido('00', hex(Z80.SP)) Z80.SP = hex(Z80.SP + 2)[2:].zfill(4).upper() flag1.update(flag2) else: setattr(Z80, arg[0], Z80.mem.obtenerContenido(hex(Z80.SP + 1)[2:])) setattr(Z80, arg[1], Z80.mem.obtenerContenido(hex(Z80.SP)[2:])) flag1 = Z80.mem.cambiarContenido('00', hex(Z80.SP + 1)) flag2 = Z80.mem.cambiarContenido('00', hex(Z80.SP)) Z80.SP = hex(Z80.SP + 2)[2:].zfill(4).upper() return flag1 else: Z80.SP = funciones.tohex(Z80.SP, 16)
def hexToDecJR(cadenahexa): numDec = int(cadenahexa,16) if numDec > 127: numDec = numDec - 256 nuevoPC = int(Z80.PC,16) + numDec Z80.PC = str(funciones.tohex(nuevoPC,16)) return
def LimpiarMemoriaCompleta(self): self.carga = 0 limpiaDic1 = {} for i in range(int("0000", 16), int("FFFF", 16) + 1): limpiaDic = z.mem.cambiarContenido("00", funciones.tohex(i, 16)) limpiaDic1.update(limpiaDic) self.cambiaLocalidad(limpiaDic1)
def C4LL(cadena): Z80.SP = int(Z80.SP,16) ################## if Z80.SP == 0: Z80.SP = 65536 ################## valorPC = Z80.PC if (Z80.SP > 65026 and Z80.SP <= 65536): flag1 = Z80.mem.cambiarContenido(valorPC[0:2],funciones.tohex(Z80.SP-1,16)) flag2 = Z80.mem.cambiarContenido(valorPC[2:4],funciones.tohex(Z80.SP-2,16)) Z80.SP = str(funciones.tohex(Z80.SP - 2,16)) Z80.PC = cadena.replace("H","") flag1.update(flag2) return flag1 else: Z80.SP = funciones.tohex(Z80.SP, 16)
def LimpiarMemoria(self): limpiaDic1 = {} inicio = self.clean1.text().zfill(4) fin = self.clean2.text().zfill(4) for i in range(int(inicio, 16), int(fin, 16) + 1): limpiaDic = z.mem.cambiarContenido("00", funciones.tohex(i, 16)) limpiaDic1.update(limpiaDic) self.cambiaLocalidad(limpiaDic1)
def DEC(op): # Decrementar valor de un registro if (len(op) == 1): a = Z80.obtenerS(op) Z80.halfCarry(a, "01", "-") a = int(a, 16) - 1 # CAMBIAR BANDERAS AQUI Z80.zero(a) Z80.sign(a) Z80.changeFlag(1, "1") Z80.overflow(a) a = funciones.tohex(a, 8) setattr(Z80, op, a) """ >>>>> Z = S = H = DE ACUERDO A LA OPERACION, N = 1, P/V = SOBREPASAMIENTO <<<<< """ # Decrementar valor de SP, IX o IY elif ((op == "SP") or (op == "IX") or (op == "IY")): a = funciones.tohex(int(Z80.obtenerSS(op), 16) - 1, 16) setattr(Z80, op, a) """ >>>>> No hay banderas afectadas <<<<< """ # Decrementar (HL), (IX+d), (IY+d) elif (op.find('(')!=-1): a = Z80.obtenerS(op) Z80.halfCarry(a, "01", "-") a = int(a, 16) - 1 # CAMBIAR BANDERAS AQUI Z80.zero(a) Z80.sign(a) Z80.changeFlag(1, "1") Z80.overflow(a) a = funciones.tohex(a, 8) if op[1:3] == "HL": flag = Z80.mem.cambiarContenido(a, ''.join([Z80.H, Z80.L])) return flag else: flag = Z80.mem.cambiarContenido(a, getattr(Z80, op[1:3])) return flag """ >>>>> Z = S = H = DE ACUERDO A LA OPERACION, N = 1, P/V = SOBREPASAMIENTO <<<<< """ # Incrementar BC, DE, HL else: a = funciones.tohex(int(Z80.obtenerSS(op), 16) - 1, 16) setattr(Z80, op[0], a[:2]) setattr(Z80, op[1], a[2:]) """ >>>>> No hay banderas afectadas <<<<< """
def RST(cadena): cadena = cadena[0:2] Z80.SP = int(Z80.SP,16) ######################### if Z80.SP == 0: Z80.SP = 65536 ########################## valorPC = Z80.PC if (Z80.SP > 65024 and Z80.SP <= 65536): fla1 = Z80.mem.cambiarContenido(valorPC[0:2], funciones.tohex(Z80.SP-1,16)) flag2 = Z80.mem.cambiarContenido(valorPC[2:4], funciones.tohex(Z80.SP-2,16)) Z80.SP = str(funciones.tohex(Z80.SP - 2,16)) Z80.PC = '00'+cadena flag1.update(flag2) return flag1 else: Z80.SP = funciones.tohex(Z80, 16)
def SCF(): flag = funciones.tobin(int(Z80.F, 16), 8) CY = "1" Z80.F = funciones.tohex(int( CY + flag[1:], 2), 8) Z80.changeFlag(0, "1") # Cambia a C Z80.changeFLag(1, "0") # Cambia a N Z80.changeFlag(4, "0") # Cambia a H """ >>>>> Banderas afectadas: C = 1, N =0 y H = 0 <<<<< """
def CPL(): a = list(funciones.tobin(int(Z80.A,16), 8)) for i in range(0,8): if (a[i] == "1"): a[i] = "0" else: a[i] = "1" Z80.A = funciones.tohex(int(''.join(a),2), 8) Z80.changeFlag(1, "1") # Cambia a N Z80.changeFlag(4, "1") # Cambia a H """ >>>>> Banderas afectadas: N = 1, H = 1 <<<<< """
def SUB(op1, op2): s = Z80.obtenerS(op2) Z80.halfCarry(Z80.A, s, '-') s = int(Z80.A, 16) - int(s, 16) Z80.carry(s) Z80.zero(s) Z80.overflow(s) Z80.sign(s) Z80.changeFlag(1,'1') Z80.A = funciones.tohex(s,8)
def NEG(): Z80.halfCarry("00", Z80.A,"-") Z80.A = 0 - int(Z80.A, 16) # CAMBIAR BANDERAS AQUI Z80.carry(Z80.A) Z80.zero(Z80.A) Z80.sign(Z80.A) Z80.overflow(Z80.A) Z80. A = funciones.tohex(Z80.A, 8) """ >>>>> C = Z = S = H = SE AFECTA DE ACUERDO A LA OPERACION, P/V = SOBREPASAMIENTO, N = 1 <<<<<"""
def CCF(): flag = funciones.tobin(int(Z80.F, 16), 8) CY = flag [7] if (CY == "0"): CY = "1" else: CY = "0" Z80.F = int( CY + flag[1:], 2) # CAMBIAR BANDERAS AQUI Z80.carry(Z80.F) Z80.changeFlag(1, "0") Z80.F = funciones.tohex(Z80.F, 8) """ >>>>> C = SE AFECTA DE ACUERDO A LA OPERACION, N = 0, H = DESCONOCIDO <<<<<"""
def createTable(self): # Create table self.tableWidget = QTableWidget() self.tableWidget.setRowCount(4096) self.tableWidget.setColumnCount(16) horizantalLabels = [] verticalLabels = [] for i in range(16): horizantalLabels.append(funciones.tohex(i, 8)) for i in range(4096): verticalLabels.append(funciones.tohex(i * 16, 16)) self.tableWidget.setHorizontalHeaderLabels(horizantalLabels) self.tableWidget.setVerticalHeaderLabels(verticalLabels) # table selection change6 for i in range(4096): for j in range(16): self.tableWidget.setItem(i, j, QTableWidgetItem("00")) self.tableWidget.setColumnWidth(j, 29) self.tableWidget.setItemDelegate(HexDelegate()) self.tableWidget.cellChanged.connect(self.changed)
def obtenerCont(op2): if (op2.find('IX+')!=-1 or op2.find('IY+')!=-1): op2 = op2.replace("(","").replace(")","").replace("H","").split("+") reg = getattr(Z80, op2[0]) des = op2[1] s = funciones.tohex(int(reg, 16) + funciones.hextodec(des), 16) cont = Z80.mem.obtenerContenido(s) elif op2.find('H)') != -1: op2 = op2.replace('(', '').replace(')', '').replace('H', '') cont = Z80.mem.obtenerContenido(op2) else: d = int(getattr(Z80, op2[0]) + getattr(Z80, op2[1]), 16) cont = Z80.mem.obtenerContenido(op2) return cont
def obtenerPosicion(op1): if (op1.find("IX+") != -1 or op1.find("IY+") != -1): op1 = op1.replace("(","").replace(")","").replace("H","").split("+") reg = getattr(Z80, op1[0]) des = op1[1] pos = funciones.tohex(int(reg, 16) + funciones.hextodec(des), 16) # Si es la direccion que contiene HL, se obtiene su contenido elif (op1 == "(HL)" or op1 == "(BC)" or op1 == "(DE)"): op1 = op1.replace('(','').replace(')','') pos = getattr(Z80, op1[0]) + getattr(Z80, op1[1]) # El ultimo caso es que sea un numero en hexadecimal else: pos = op1.replace('(','').replace(')','').replace('H','') return pos
def addPila(self): v = int(z.SP, 16) if v == 0: v = 65536 indicePila = int((65534 - v)/2) if indicePila >= 255: msgBox = QMessageBox() msgBox.setText("Pila Llena") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec_() return False label = self.pila[indicePila] label.setText(z.mem.obtenerContenido(funciones.tohex(int(z.SP, 16) + 1, 8)) + z.mem.obtenerContenido(z.SP)) return
def PUSH(arg): Z80.SP = int(Z80.SP, 16) #################### if Z80.SP == 0: Z80.SP = 65536 ##################### if Z80.SP >= 65026 and Z80.SP <= 65536: if arg == 'IX' or arg == 'IY': arg = getattr(Z80, arg) flag1 = Z80.mem.cambiarContenido(arg[:2], hex(Z80.SP - 1)[2:]) flag2 = Z80.mem.cambiarContenido(arg[2:], hex(Z80.SP - 2)[2:]) Z80.SP = funciones.tohex(Z80.SP - 2, 16) flag1.update(flag2) return flag1 else: qL = getattr(Z80, arg[1]) qH = getattr(Z80, arg[0]) flag1 = Z80.mem.cambiarContenido(qH, hex(Z80.SP - 1)[2:]) flag2 = Z80.mem.cambiarContenido(qL, hex(Z80.SP - 2)[2:]) Z80.SP = funciones.tohex(Z80.SP - 2, 16) flag1.update(flag2) return flag1 else: Z80.SP = funciones.tohex(Z80.SP, 16)
def cargaMemoria(self, dirCarga, archivo): try: code = open(archivo, 'r') self.carga = 1 for line in code.readlines(): line = line.replace(':', '').replace("\n", "") # El desensamble termina al encontrar la ultima linea del codigo objeto if (line != '00000001FF'): start = line[2:6] line = list(map(''.join, zip(*[iter(line)] * 2))) # Vemos que el checksum coincida con el resultado del codigo objeto checksum = line[len(line) - 1] line = line[:len(line) - 1] sum = funciones.compDos(eval('+'.join([str(int(num, 16)) for num in line]))) line = line[4:] if (sum == checksum): i = int(dirCarga, 16) + int(start, 16) while(len(line) > 0): localidad = funciones.tohex(i, 16) z.mem.cambiarContenido(line[0], localidad) row = int(localidad[:3], 16) column = int(localidad[3], 16) item = QTableWidgetItem(line[0]) self.tableWidget.setItem(row, column, item) App.ChangedPositions[int(localidad, 16)] = line[0] line = line[1:] i += 1 else: msgBox = QMessageBox() msgBox.setText("Código Alterado") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec_() return else: return z.mem except: msgBox = QMessageBox() msgBox.setText("Error al abrir archivo") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec_() return
def obtenerS(op2): # Si se trata de un registro, se obtiene su valor if (len(op2) == 1): s = getattr(Z80, op2) # En caso de tratarse de la direccion apuntada por IX o IY, se obtiene su contenido elif (op2.find("IX+") != -1 or op2.find("IY+") != -1): op2 = op2.replace("(","").replace(")","").replace("H","").split("+") reg = getattr(Z80, op2[0]) des = op2[1] s = funciones.tohex(int(reg, 16) + funciones.hextodec(des), 16) s = Z80.mem.obtenerContenido(s) # Si es la direccion que contiene HL, se obtiene su contenido elif (op2 == "(HL)"): s = Z80.mem.obtenerContenido(''.join([getattr(Z80,"H"), getattr(Z80,"L")])) # El ultimo caso es que sea un numero en hexadecimal else: s = op2.replace("H","") return s
def AND(op1, op2): a = getattr(Z80, op1) s = Z80.obtenerS(op2) a = list(funciones.tobin(int(a, 16), 8)) s = list(funciones.tobin(int(s, 16), 8)) for i in range(0, 8): # Si los caracteres en a y s son distintos, se cambia a 0 en el acumulador (a) if (a[i] != s[i]): a[i] = "0" Z80.A = int(''.join(a), 2) # CAMBIAR BANDERAS AQUI Z80.changeFlag(0, "0") Z80.changeFlag(1, "0") Z80.zero(Z80.A) Z80.sign(Z80.A) Z80.A = funciones.tohex(Z80.A, 8) Z80.parity(Z80.A) """ >>>>> C = N = 0, Z = S = H = DE ACUERDO A LA OPERACION, P/V = PARIDAD <<<<< """
def desensambladoPasoAPaso(self): inst = "" j = int(z.PC, 16) act = '' yes = 0 while(yes != 1): act += z.mem.obtenerContenido(funciones.tohex(j, 8)) j += 1 if act == 'DDCB' or act == 'FDCB': des = line[j] act += 'V' + line[j + 1] j += 2 inst = self.table.get(act)[0] inst = inst.replace('V', des + 'H') long = int(self.table.get(act)[1]) tiempo = self.table.get(act)[2:] if len(tiempo) == 1: z.time += int(tiempo[0]) z.PC = hex(j - 4 + long)[2:].zfill(4).upper() if int(z.PC, 16) >= int("10000", 16): z.PC = "0000" ''' self.instTime.setText(str(tiempo[0])) self.totalTime.setText(str(z.time))''' self.changeLabelLines(act, inst) self.changeTimeLbls(tiempo) res = self.ejecutar(act, inst) yes = 1 if res == False: self.salirPasoPaso() j = int(z.PC, 16) act = '' elif act in self.table: tem = act inst = self.table.get(act)[0] long = int(self.table.get(act)[1]) longact = len(act) / 2 tiempo = self.table.get(act)[2:] if len(tiempo) == 1: z.time += int(tiempo[0]) # Bandera para saber cuando poner la H en los numeros al desensamblar flagh = 0 while(long != longact): act = z.mem.obtenerContenido(funciones.tohex(j, 8)) tem += act longact += 1 j += 1 if inst.find('WW') != -1: inst = (act + 'H').join(inst.rsplit('W', 1)) flagh = 1 elif inst.find('V') != -1: inst = inst.replace('V', act + 'H') elif inst.find('W') != -1: if flagh == 1: inst = inst.replace('W', act) else: inst = inst.replace('W', act + 'H') z.PC = hex(j)[2:].zfill(4).upper() #Para imprimir las instrucciones de desensamble: if int(z.PC, 16) >= int("10000", 16): z.PC = "0000" self.changeLabelLines(tem, inst) self.changeTimeLbls(tiempo) res = self.ejecutar(inst) tiempo = self.table.get(act)[2:] yes = 1 if res == False: self.salirPasoPaso() j = int(z.PC, 16) act = '' tem = '' if (inst == "HALT"): z.time = 0 msgBox = QMessageBox() msgBox.setText("Fin de programa") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec_() self.salirPasoPaso()
def desensambladoTrazo(self): z.time = 0 inst = "" j = int(z.PC, 16) act = '' if self.carga != 0: while(inst != 'HALT'): act += z.mem.obtenerContenido(funciones.tohex(j, 8)) j += 1 if act == 'DDCB' or act == 'FDCB': des = z.mem.obtenerContenido(funciones.tohex(j, 8)) act += 'V' + z.mem.obtenerContenido(funciones.tohex(j + 1), 8) j += 2 inst = self.table.get(act)[0] inst = inst.replace('V', des + 'H') long = int(self.table.get(act)[1]) tiempo = self.table.get(act)[2:] if len(tiempo) == 1: z.time += int(tiempo[0]) z.PC = hex(j - 4 + long)[2:].zfill(4).upper() if int(z.PC, 16) >= int("10000", 16): z.PC = "0000" self.changeLabelLines(act, inst) self.changeTimeLbls(tiempo) res = self.ejecutar(act, inst) if res == False: return j = int(z.PC, 16) act = '' elif act in self.table: tem = act inst = self.table.get(act)[0] long = int(self.table.get(act)[1]) tiempo = self.table.get(act)[2:] if len(tiempo) == 1: z.time += int(tiempo[0]) longact = len(act)/2 # Bandera para saber cuando poner la H en los numeros al desensamblar flagh = 0 while(long != longact): act = z.mem.obtenerContenido(funciones.tohex(j, 8)) tem += act longact += 1 j += 1 if inst.find('WW') != -1: inst = (act + 'H').join(inst.rsplit('W', 1)) flagh = 1 elif inst.find('V') != -1: inst = inst.replace('V', act + 'H') elif inst.find('W') != -1: if flagh == 1: inst = inst.replace('W', act) else: inst = inst.replace('W', act + 'H') z.PC = hex(j)[2:].zfill(4).upper() if int(z.PC, 16) >= int("10000", 16): z.PC = "0000" self.changeLabelLines(tem, inst) self.changeTimeLbls(tiempo) res = self.ejecutar(inst) if res == False: return j = int(z.PC, 16) act = '' tem = '' z.PC = "0000" #Lineas agregadas para reiniciar el valor del tiempo z.time = 0 else: return
def DAA(): cy = Z80.getFlagBit(0) # Obtiene bandera de acarreo hc = Z80.getFlagBit(4) # Obtiene bandera de medio acarreo if ((cy == 0) and (hc == 0)): if (int(Z80.A[0],16) in range(0, 10) and int(Z80.A[1],16) in range(0, 10)): Z80.halfCarry(Z80.A, "00", "+") Z80.changeFlag(0, "0") Z80.A = int(Z80.A, 16) + int("00", 16) elif (int(Z80.A[0],16) in range(0, 9) and int(Z80.A[1],16) in range(10, 16)): Z80.halfCarry(Z80.A, "06", "+") Z80.A = int(Z80.A, 16) + int("06", 16) Z80.changeFlag(0, "0") elif (int(Z80.A[0],16) in range(10, 16) and int(Z80.A[1],16) in range(0, 10)): Z80.halfCarry(Z80.A, "60", "+") Z80.A = int(Z80.A, 16) + int("60", 16) Z80.changeFlag(0, "1") elif (int(Z80.A[0],16) in range(9, 16) and int(Z80.A[1],16) in range(10, 16)): Z80.halfCarry(Z80.A, "66", "+") Z80.A = int(Z80.A, 16) + int("66", 16) Z80.changeFlag(0, "1") elif ((cy == 0) and (hc == 1)): if (int(Z80.A[0],16) in range(0, 10) and int(Z80.A[1],16) in range(0, 4)): Z80.halfCarry(Z80.A, "06", "+") Z80.A = int(Z80.A, 16) + int("06", 16) Z80.changeFlag(0, "0") elif (int(Z80.A[0],16) in range(10, 16) and int(Z80.A[1],16) in range(0, 4)): Z80.halfCarry(Z80.A, "66", "+") Z80.A = int(Z80.A, 16) + int("66", 16) Z80.changeFlag(0, "1") elif (int(Z80.A[0],16) in range(0, 9) and int(Z80.A[1],16) in range(6, 16)): Z80.halfCarry(Z80.A, "FA", "+") Z80.A = int(Z80.A, 16) + int("FA", 16) Z80.changeFlag(0, "0") elif((cy == 1) and (hc == 0)): if (int(Z80.A[0],16) in range(0, 3) and int(Z80.A[1],16) in range(0, 10)): Z80.halfCarry(Z80.A, "60", "+") Z80.A = int(Z80.A, 16) + int("60", 16) Z80.changeFlag(0, "1") elif (int(Z80.A[0],16) in range(0, 3) and int(Z80.A[1],16) in range(10, 16)): Z80.halfCarry(Z80.A, "66", "+") Z80.A = int(Z80.A, 16) + int("66", 16) Z80.changeFlag(0, "1") elif (int(Z80.A[0],16) in range(7, 16) and int(Z80.A[1],16) in range(0, 10)): Z80.halfCarry(Z80.A, "A0", "+") Z80.A = int(Z80.A, 16) + int("A0", 16) Z80.changeFlag(0, "1") elif((cy == 1) and (hc == 1)): if (int(Z80.A[0],16) in range(0, 4) and int(Z80.A[1],16) in range(0, 4)): Z80.halfCarry(Z80.A, "66", "+") Z80.A = int(Z80.A, 16) + int("66", 16) Z80.changeFlag(0, "1") elif (int(Z80.A[0],16) in range(6, 16) and int(Z80.A[1],16) in range(6, 16)): Z80.halfCarry(Z80.A, "9A", "+") Z80.A = int(Z80.A, 16) + int("9A", 16) Z80.changeFlag(0, "1") #CAMBIAR BANDERAS AQUI Z80.carry(Z80.A) Z80.zero(Z80.A) Z80.sign(Z80.A) Z80.A = funciones.tohex(Z80.A, 8) Z80.parity(int(Z80.A, 16)) """ C = Z = S = H = CAMBIAN SEGUN EL RESULTADO, P/V = PARIDAD """