OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [dongle/] [sbc/] [simulate-sbc.py] - Diff between revs 3 and 8

Show entire file | Details | Blame | View Log

Rev 3 Rev 8
Line 1... Line 1...
#!/usr/bin/env python
#!/usr/bin/env python3
#
#
# This script simulates 'sbc' calculation and generates values for selected numbers.
# This script simulates 'sbc' 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 SBC %0.2X  CY = %0.2X' % ( inA, op2, CYin)
    print ('Input: %0.2X SBC %0.2X  CY = %0.2X' % ( inA, op2, CYin))
 
 
    double_cpl = 0                  # Flag that we did a double 1's complement
    double_cpl = 0                  # Flag that we did a double 1's complement
    cplOp2 = op2 ^ 0xFF             # Bit-wise complement of OP2
    cplOp2 = op2 ^ 0xFF             # Bit-wise complement of OP2
 
 
    if CYin:                        # If CF was set, we'll also use complemented ACCT
    if CYin:                        # If CF was set, we'll also use complemented ACCT
Line 89... Line 89...
    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(0, 0, 1)
sbc(0, 0, 1)
print 'Should be A -> FF    Flags = BB'
print ('Should be A -> FF    Flags = BB')
printFlags(0xBB)
printFlags(0xBB)
sbc(0, 1, 1)
sbc(0, 1, 1)
print 'Should be A -> FE    Flags = BB'
print ('Should be A -> FE    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(0xAA, 0x55, 1)
sbc(0xAA, 0x55, 1)
print 'Should be A -> 54    Flags = 06'
print ('Should be A -> 54    Flags = 06')
printFlags(0x06)
printFlags(0x06)
sbc(0x55, 0xAA, 1)
sbc(0x55, 0xAA, 1)
print 'Should be A -> AA    Flags = BF'
print ('Should be A -> AA    Flags = BF')
printFlags(0xBF)
printFlags(0xBF)
 
 
sbc(0x0F, 0x03, 1)
sbc(0x0F, 0x03, 1)
print 'Should be A -> 0B    Flags = 0A'
print ('Should be A -> 0B    Flags = 0A')
printFlags(0x0A)
printFlags(0x0A)
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.