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

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [dongle/] [daa/] [simulate-daa.py] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 gdevic
#!/usr/bin/env python3
2 3 gdevic
#
3
# This script simulates 'daa' calculation and generates values for numbers 0-255.
4
# These can be compared with a real Z80 run values.
5
#
6
import sys
7
 
8
# Open opcode file and read opcode + mnemonics
9
with open('daa-concise.txt') as tmpFile:
10
    testVectors = [line.rstrip('\n') for line in tmpFile]
11
 
12
for line in testVectors:
13
    # F:00 A:00 -> 00 F:44
14
    inF = int(line[2:4], 16)
15
    inA = int(line[7:9], 16)
16
    outA = int(line[13:15], 16)
17
    outF = int(line[18:20], 16)
18 8 gdevic
    #print ('F:' + ("%0.2X" % inF) + ' A:' + ("%0.2X" % inA) + ' -> ' + ("%0.2X" % outA) + ' F:' + ("%0.2X" % outF))
19 3 gdevic
 
20
    # Get the flags that will determine daa operation
21
    hf = (inF>>4) & 1
22
    nf = (inF>>1) & 1
23
    cf = (inF>>0) & 1
24
 
25
    correction = 0x00               # Initial correction byte
26
    low_nibble_flag = 0             # Flag to keep the compare state of the low nibble
27
    if (inA & 0x0F) > 9:
28
        low_nibble_flag = 1
29
 
30
    if low_nibble_flag or hf:
31
        correction |= 0x06          # Setup lower nibble
32
 
33
    # if inA > 0x99 or cf:
34
    upperA = (inA >> 4) & 0xF       # Simulate ALU: get the upper nibble
35
    if (upperA == 9 and low_nibble_flag) or upperA > 9 or cf:
36
        correction |= 0x60          # Setup upper nibble
37
        cf = 1
38
    else:
39
        cf = 0
40
 
41
    if nf:
42
        finalA = inA - correction
43
    else:
44
        finalA = inA + correction
45
    finalA &= 0xFF                  # Formality
46
 
47
    #-------------------------------------------------------------------------------
48
    # Flag calculation: SF, ZF, YF, HF, XF, VF/PF, NF, CF
49
    #-------------------------------------------------------------------------------
50
    sf = (finalA>>7) & 1            # Copy of [7]
51
    zf = finalA==0                  # Set if the final value is zero
52
    yf = (finalA>>5) & 1            # Copy of [5]
53
    hf = 0                          # Standard way to compute HF
54
    if (inA&0x10)!=(finalA&0x10):
55
        hf = 1
56
    xf = (finalA>>3) & 1            # Copy of [3]
57
    pf = (((finalA>>7)^(finalA>>6)^(finalA>>5)^(finalA>>4)^(finalA>>3)^(finalA>>2)^(finalA>>1)^(finalA>>0))&1)^1
58
    nf = (inF>>1) & 1               # Always unchanged
59
 
60
    flags = (sf<<7) | (zf<<6) | (yf<<5) | (hf<<4) | (xf<<3) | (pf<<2) | (nf<<1) | (cf<<0)
61
 
62 8 gdevic
    print ('F:' + ("%0.2X" % inF) + ' A:' + ("%0.2X" % inA) + ' -> ' + ("%0.2X" % finalA) + ' F:' + ("%0.2X" % flags))

powered by: WebSVN 2.1.0

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