Line 1... |
Line 1... |
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
#
|
#
|
# This script simulates 'sub' calculation and generates values for selected numbers.
|
# This script simulates 'sub' calculation and generates values for selected numbers.
|
# These can be compared with a real Z80 run values.
|
# These can be compared with a real Z80 run values.
|
#
|
#
|
import sys
|
import sys
|
Line 37... |
Line 37... |
s += ' '
|
s += ' '
|
if f & (1 << 0):
|
if f & (1 << 0):
|
s += 'C'
|
s += 'C'
|
else:
|
else:
|
s += ' '
|
s += ' '
|
print 'Flags = %s' % s
|
print ('Flags = %s' % s)
|
|
|
def sbc(inA, op2, CYin):
|
def sbc(inA, op2, CYin):
|
print '------------------------------------------'
|
print ('------------------------------------------')
|
print 'Input: %0.2X SUB %0.2X' % ( inA, op2)
|
print ('Input: %0.2X SUB %0.2X' % ( inA, op2))
|
|
|
cplA = inA ^ 0xFF # Bit-wise complement of A
|
cplA = inA ^ 0xFF # Bit-wise complement of A
|
CYin = 1
|
CYin = 1
|
finalA = cplA + 0 + CYin
|
finalA = cplA + 0 + CYin
|
finalA = finalA + op2
|
finalA = finalA + op2
|
Line 77... |
Line 77... |
vf = (carry_ins>>7)&1 # VF = Internal carry from bit [6] to [7]
|
vf = (carry_ins>>7)&1 # VF = Internal carry from bit [6] to [7]
|
vf ^= cf # XOR'ed with the final carry out
|
vf ^= cf # XOR'ed with the final carry out
|
|
|
flags = (sf<<7) | (zf<<6) | (yf<<5) | (hf<<4) | (xf<<3) | (vf<<2) | (nf<<1) | (cf<<0)
|
flags = (sf<<7) | (zf<<6) | (yf<<5) | (hf<<4) | (xf<<3) | (vf<<2) | (nf<<1) | (cf<<0)
|
|
|
print 'Out: A -> %0.2X Flags = %0.2X' % ( finalA, flags)
|
print ('Out: A -> %0.2X Flags = %0.2X' % ( finalA, flags))
|
printFlags(flags)
|
printFlags(flags)
|
|
|
sbc(0, 0, 0)
|
sbc(0, 0, 0)
|
print 'Should be A -> 00 Flags = 42'
|
print ('Should be A -> 00 Flags = 42')
|
printFlags(0x42)
|
printFlags(0x42)
|
sbc(0, 1, 0)
|
sbc(0, 1, 0)
|
print 'Should be A -> FF Flags = BB'
|
print ('Should be A -> FF Flags = BB')
|
printFlags(0xBB)
|
printFlags(0xBB)
|
|
|
sbc(0xAA, 0x55, 0)
|
sbc(0xAA, 0x55, 0)
|
print 'Should be A -> 55 Flags = 06'
|
print ('Should be A -> 55 Flags = 06')
|
printFlags(0x06)
|
printFlags(0x06)
|
sbc(0x55, 0xAA, 0)
|
sbc(0x55, 0xAA, 0)
|
print 'Should be A -> AB Flags = BF'
|
print ('Should be A -> AB Flags = BF')
|
printFlags(0xBF)
|
printFlags(0xBF)
|
|
|
sbc(0x0F, 0x03, 0)
|
sbc(0x0F, 0x03, 0)
|
print 'Should be A -> 0C Flags = 0A'
|
print ('Should be A -> 0C Flags = 0A')
|
printFlags(0x0A)
|
printFlags(0x0A)
|
|
|
No newline at end of file
|
No newline at end of file
|