-
Notifications
You must be signed in to change notification settings - Fork 1
/
setbaud.py
37 lines (32 loc) · 1.17 KB
/
setbaud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Generate baud rate constants
#
# This can't be done in Pasmo, as Pasmo only uses 16 bit maths.
#
# Required baud rate. Set if here.
baud = 3000
# Z80 clock speed
#
#cpuClock = 3500000 # ZX Spectrum 16/48K, ZX80, ZX81
#cpuClock = 3546900 # Spectrum 128K, +2/2A/3
cpuClock = 3523372 # Geometric mean, minimum error on all Spectrums
#cpuClock = 4000000 # Amstrad CPC
# Constants related to boot2.asm
#
loopOverhead = 738 # Fixed loop delay, in T-states
cycleTime = 13 # One loop of a DJNZ delay, in T-states
# Generate baud.asm file
#
outfile = open("setbaud.asm","w")
outfile.write("; This file is autogenerated by setbaud.py\n")
outfile.write("; Do not make changes to this file "
"as they will be erased on the next build.\n")
outfile.write("; Set rate to {} baud\n".format(baud))
outfile.write("BAUD equ {}\n".format(baud))
bitPeriod = cpuClock/baud
sampleTime = bitPeriod * 0.75
maxBaud = cpuClock/(loopOverhead + cycleTime)*0.75
assert sampleTime > (loopOverhead+cycleTime),\
"Baud rate too high. Maximum is {}.".format(maxBaud)
baudLoops = int(round((sampleTime-loopOverhead)/cycleTime))
outfile.write("BAUDLOOPS equ {}\n".format(baudLoops))
outfile.close()