## ############################################################################
##
## I abandon this attempt to run original f/w of HP Voyager calculators
## with a Nut CPU simulated using MicroPhyton. Actual trigger is the lack
## of translate() like Python. I do not have the desire to develop a new
## process to convert lit display segments to ASCII as shown.
##
## I'll continue the project using 'C', 'C whatsoever', IDK yet.
## 'Rust' under Wokwi only possible using VS Code, see https://wokwi.com/rust
## Continuation: https://wokwi.com/projects/474285553622381569
##
## ############################################################################
##
## Note:
## This was my 2nd Wokwi excursion. It's the continuation of the 1st but using MicroPython.
## fst was https://wokwi.com/projects/474285553622381569
##
## Voyager in a Tin (working title)
## This is first of a kind in several aspects:
## - it's my first IoT project
## - it's my first attempt to use MicroPython
## - it's my first attempt to use MicroPython under Wokwi
## - it's the first clone of an ancient HP Voyager pocket calculator with WiFi
## - it's the first ancient HP pocket calculator build into a 'Rapunzel' mint tin
## The Voyager series includes also the HP12C Financial Calculator, well known since decades
## The nudge:
## I was triggered to start this project by the ATS Mini Radio and its wireless features,
## see ... esp32-si4732.github.io/ats-mini/index.html
## The goal:
## Since long I'm interessted in "emulators" (which in fact are simulations) of HP pocket calculators.
## Besides those running under Windows, Linux, MacOS, ..., there exist also some clones, but up to now
## none using WiFi. With it I'd like to enable copy and paste, access to data and programs (R/W and R/O),
## exchange of the calculator's ROM (what means changing the model), maybe also version updates.
## This project includes help/suggestions/code from
## - Koepel, working wiring of the display
## - Koepel, how to use MicroPython
## - AnonEngineering, wiring of the TCA8418 chip
## - Maverick, simulation of the TCA8418
## - robinblood created with AI support an HP10C simulator
## see https://wokwi.com/projects/476496384464737281
## Role model regarding tin box packaging: youtu.be/xNvaoZqZ404
## Role models regarding Voyager clones:
## - www.swissmicros.com/en/products/dm11l
## - paxerlabs.com/voyager/
import time
from os import listdir
import binascii
time.sleep(0.1) # Wait for USB to become ready (not my style)
print("--Prgm started---------------------------------------------------------")
# print("Files found: {}".format(listdir()))
# print("Reading f/w hp11p.csv", end='\n')
# with open('hp11p.csv', 'r') as file:
print("Reading f/w hp10c.csv", end='\n')
with open('hp10c.csv', 'r') as file:
ROM = [int(line, 16) for line in file] # items and index (0-based) are decimal
# print(ROM)
if sum(ROM) % 1023 == 1:
print("Chksm Ok")
else:
print("Chksm is not Ok.")
print(">> Use Ctrl+c to end prgm <<")
# how may I quit this program self-acting?
while (True):
time.sleep(5)
# select would be nice
romsz = 6144
dtype = 0
kdbdl = 11 # /* key debounce delay for Voyagers */
if ROM[93] == 96:
print("ROM of a 10C", end='\n')
romsz = 4096
dtype = 1 # display of 10C differs from rest
elif ROM[5117] == 96:
print("ROM of a 11C", end='\n')
elif ROM[94] == 96:
print("ROM of a 12C", end='\n')
elif ROM[5046] == 96:
print("ROM of a 15C", end='\n')
romsz = "2bd"
elif ROM[4237] == 96:
print("ROM of a 16C", end='\n')
else:
print("ROM file of a Voyager?")
print(">> Use Ctrl+c to end prgm <<")
# how may I quit this program self-acting?
while (True):
time.sleep(5)
nutra = True
if nutra:
print("Run w/ trace")
## Init RAM and CPU registers
Rnul = "00000000000000" # use nibbles instead of bytes(7)
RAM = [Rnul] * 256 # a tad more than the role models
NUT_A = Rnul
NUT_B = Rnul
NUT_C = Rnul
NUT_M = Rnul
NUT_N = Rnul
NUT_FO = "00"
NUT_G = "00"
NUT_ST = "0000"
selpt = 0
Pt = [0] * 2 # P, Q
dcf = ["VOID"] * romsz # only once per session
cry = 1 # wkup from deep sleep
cmd = "" # this is not REXX
crx = 0
rtn = [0] * 4 # RTN stack
ti = 3, 4, 5, 10, 8, 6, 11, 23, 2, 9, 7, 13, 1, 12, 0 # 23 is invalid
# Time Enable Modifier
# Pt X WPT ALL PQ XS M S -- mod 0, 2, and 4 = f(Pt)
TEMa = [0, 11, 0, 0, 0, 11, 1, 0]
TEMo = [0, 14, 14, 14, 0, 12, 11, 0]
key = '18' # /* ON key pressed */
kdc = kdbdl # /* key debounce counter */
xmode = 0 # /* start in dec mode */
dpoff = 1
flg = [0] * 14
fladi = 1
selram = 0
x2b = '0000', '0001', '0010', '0011', \
'0100', '0101', '0110', '0111', \
'1000', '1001', '1010', '1011', \
'1100', '1101', '1110', '1111'
vtr = b" zzzzzzuzzzzzz.," + \
"zzzzzzzzrzzCzzzz" + \
"-zrzzzNozzzzzzhb" + \
"zzzzzzzzzzFEz5z6" + \
"izzz1zzzzzzzzzzz" + \
"zzzz7zzznzzzzzz0" + \
"zzzzzzzduzzz4zzz" + \
"zzz2z3zzzzPzz9A8"
vtr += vtr # Transliteration table must be of length 256
## Subroutines
def diref(): # display refresh
# print("R.A R.9", RAM[10], RAM[9])
dilin1 = ""
dilin2 = ""
if dtype == 1:
teval = ''
for nb in RAM[10]:
teval += x2b[int(nb, 16)]
# print('teval', teval)
# print("a2b", binascii.a2b_hex(RAM[10]))
# print("unhexlify", binascii.unhexlify(RAM[10]))
vodis = teval[10:16] + teval[ 8:10] + teval[ 6: 8] + \
teval[38:44] + teval[ 4: 6] + teval[ 2: 4] + \
teval[44:50] + teval[ : 2] + teval[30:32] + \
teval[24:30] + teval[36:38] + teval[22:24] + \
teval[16:22] + teval[34:36] + teval[32:34]
teval = ''
for nb in RAM[9]:
teval += x2b[int(nb, 16)]
vodis += teval[ : 6] + teval[48:50] + teval[ 6: 8] + \
teval[ 8:14] + teval[46:48] + \
teval[14:22] + teval[44:46] + teval[38:40] + \
teval[22:28] + teval[40:44] + \
teval[28:34] + teval[36:38] + teval[34:36]
# print("vodis", vodis)
while len(vodis) > 0:
teval = vodis[:10]
vodis = vodis[10:]
binary = teval[4:6] + teval[2:4] + teval[:2] + teval[6:7]
# print("bin", binary)
# dilin1 += str(binascii.unhexlify(f'{int('0' + binary, 2):02X}')) -- I give up
dilin1 += f'{int('0' + binary, 2):02X}'
if teval[8:] == '10':
dilin1 += '0E'
if teval[8:] == '11':
dilin1 += '0F'
print("dilin.1", dilin1)
print("dilin.1", binascii.unhexlify(dilin1).translate(vtr))
else:
while True: # temporary stopgap
print("dtype 0 pending.")
time.sleep(5)
return()
def wfnxkp(): # wfnxkp - sho display and wait for key
global dipen
if dipen == 1: # display update pending?
diref()
while True: # temporary stopgap until wfnxkp() works
time.sleep(5)
print("Clocks stopped.")
return()
def dcdfw(): # decode cmd
wiq = ROM[pc]
cl = wiq % 4 # reminder is class
if cl == 2: # ordered by occurence
dcf[pc] = cl, wiq // 32, (wiq // 4) % 8
elif cl == 0:
dcf[pc] = cl, (wiq // 4) % 16, wiq // 64
if dcf[pc] == (0, 12, 4):
dcf[pc] = "LC", f"{ROM[pc+1]:03X}"
elif cl == 3:
dist = max(wiq // 8, 1)
if dist > 63:
dist -= 128
dcf[pc] = cl, ".", pc + dist - 1, (wiq // 4) % 2
else:
w1 = wiq // 4
wiq = ROM[pc+1]
if (wiq % 4) // 2 == 0:
xqgo = "XQ"
else:
xqgo = "GO"
dcf[pc] = cl, xqgo, 256 * (wiq // 4) + w1 - 1, wiq % 2
return()
# end of def dcdfw
def purtn(teval): # /* push PC on RTN stack */
rtn[3] = rtn[2]
rtn[2] = rtn[1]
rtn[1] = rtn[0]
rtn[0] = teval
return()
def rtnx(): # /* drop RTN stack */
global pc
pc = rtn[0] - 1
poprtn()
return()
def poprtn(): # /* pop RTN stack */
rtn[0] = rtn[1]
rtn[1] = rtn[2]
rtn[2] = rtn[3]
rtn[3] = 0
return()
###
## Class 0
# Subclass 0
def CL0_0(mod):
global preco
if mod == 0:
if preco == 'XQ': # on Voyagers??
rtnx()
elif preco == 'POWOFF': # 2nd word of shutdown
print("Clocks stopped.")
# print("R.A", bytes.fromhex(ROM[10]))
# print("R.9", bytes.fromhex(ROM[9]))
wfnxkp() # wait for next key press
else:
pass
else:
nonono() # no bank switching, no HP-IL, no "user exits"
return()
# Subclass 1
def CL0_1(mod):
global NUT_ST
if mod == 15:
NUT_ST = NUT_ST[:2] + "00"
fladi = 1
elif mod == 7:
pass # should not come here
else:
flg[ti[mod]] = 0
# clear corresponding bit in NUT_ST
print("NUT_ST, nuval", NUT_ST, f"{2**ti[mod]:04X}")
teval = int(NUT_ST, 16) & (int('FFFF', 16) ^ int(f"{2**ti[mod]:04X}", 16))
NUT_ST = f"{teval:04X}"
print(NUT_ST)
if nutra:
print("ST", NUT_ST)
return()
# Subclass 2
def CL0_2(mod):
global kdc, key, NUT_ST # how comes other work but not this one?
if mod == 15:
if kdc > 0:
kdc -= 1
else:
key = '00' # two digits for C=KEY
if nutra:
print("key", key)
# kfl = 0 # idk, maybe for key while CPU is running
elif mod == 7:
pass # to come here is in fact a programming error
else:
flg[ti[mod]] = 1
# set corresponding bit in NUT_ST
print(NUT_ST, f"{2**ti[mod]:04X}")
NUT_ST = int(NUT_ST, 16) | 2**ti[mod]
NUT_ST = f'{NUT_ST:04X}'
if nutra:
print("ST", NUT_ST)
return()
# Subclass 3
def CL0_3(mod):
global crx, key
if mod == 15: # as of yet no key while CPU is running
if key != '00':
crx = 1
elif mod == 7:
pass # to come here is a programming error
else:
if flg[ti[mod]] == 1:
crx = 1
if crx == 1:
print("CARRY")
return()
# Subclass 4
def CL0_4(mod):
global NUT_C
NUT_C = NUT_C[:13 - Pt[selpt]] + f"{mod:01X}" + NUT_C[14 - Pt[selpt]:]
Pt[selpt] = (Pt[selpt] + 13) % 14
if nutra:
print("C, selpt, Pt", NUT_C, selpt, Pt[selpt])
return()
# Subclass 5
def CL0_5(mod):
if mod == 15:
Pt[selpt] = (Pt[selpt] + 13) % 14
elif mod == 7:
pass
else:
if Pt[selpt] == ti[mod]:
crx = 1
if nutra:
print("CARRY")
return()
# Subclass 6
def CL0_6(mod):
global NUT_C
# Note: simulation of NUT.G manipulation is simplified, does not comply with the role model
if mod == 1:
teval = NUT_C + NUT_C
NUT_G = teval[26 - Pt[selpt]:29 - Pt[selpt]]
if nutra:
print("G", NUT_G)
elif mod == 2:
if Pt[selpt] < 13:
NUT_C = NUT_C[:12 - Pt[selpt]] + NUT_G + NUT_C[13 - Pt[selpt]:]
else:
NUT_C = NUT_G[1] + NUT_C[1:13] + NUT_G[0]
if nutra:
print("C", NUT_C)
elif mod == 3:
teval = NUT_C + NUT_C
teval = teval[26 - Pt[selpt]:29 - Pt[selpt]]
if Pt[selpt] < 13:
NUT_C = NUT_C[:12 - Pt[selpt]] + NUT_G + NUT_C[13 - Pt[selpt]:]
else:
NUT_C = NUT_G[1] + NUT_C[1:13] + NUT_G[0]
NUT_G = teval
if nutra:
print("C, G", NUT_C, NUT_G)
elif mod == 5:
NUT_M = NUT_C
if nutra:
print("M", NUT_M)
elif mod == 6:
NUT_C = NUT_M
if nutra:
print("C", NUT_C)
elif mod == 7:
teval = NUT_C
NUT_C = NUT_M
NUT_M = teval
if nutra:
print("C. M", NUT_C, NUT_M)
elif mod == 9:
NUT_FO = NUT_ST[2:]
if nutra:
print("Fo", NUT_FO)
elif mod == 10:
NUT_ST = NUT_ST[:2] + NUT_FO
fladi = 1
if nutra:
print("ST", NUT_ST)
elif mod == 11:
teval = NUT_FO
NUT_FO = NUT_ST[2:]
NUT_ST = NUT_ST[:2] + teval
fladi = 1
if nutra:
print("ST, Fo", NUT_ST, NUT_FO)
elif mod == 13:
NUT_ST = NUT_ST[:2] + NUT_C[12:]
fladi = 1
if nutra:
print("ST", NUT_ST)
elif mod == 14:
NUT_C = NUT_C[:12] + NUT_ST[2:]
if nutra:
print("C", NUT_C)
elif mod == 15:
teval = NUT_C[12:]
NUT_C = NUT_C[:12] + NUT_ST[2:]
NUT_ST = NUT_ST[:2] + teval
fladi = 1
if nutra:
print("C, ST", NUT_C, NUT_ST)
return()
# Subclass 7
def CL0_7(mod):
if mod == 15:
Pt[selpt] = (Pt[selpt] + 1) % 14
elif mod == 7:
pass # to come here is a programming error
else:
Pt[selpt] = ti[mod]
if nutra:
print("selpt, Pt", selpt, Pt[selpt])
return()
# Subclass 8
def CL0_8(mod):
global xmode, NUT_C, dpoff, cmd, dipen
if mod == 0:
poprtn()
elif mod == 1:
cmd = 'POWOFF'
if nutra:
if dpoff == 1:
print("deep sleep")
else:
print("light sleep")
elif mod == 2:
selpt = 0 # P
if nutra:
print("ptsel: P")
elif mod == 3:
selpt = 1 # Q
if nutra:
print("ptsel: Q")
elif mod == 4:
if pt[0] == pt[1]:
crx = 1
if nutra:
print("Carry")
elif mod == 5:
pass # wmic??
elif mod == 6:
NUT_A = Rnul
NUT_B = Rnul
NUT_C = Rnul
if nutra:
print("A, B, C", NUT_A, NUT_B, NUT_C)
elif mod == 7:
pc = int(NUT_C[7:10], 16) - 1
if nutra:
print("PC", f'{pc+1:04X}')
elif mod == 8:
NUT_C = NUT_C[:9] + f'{key:02}' + NUT_C[11:]
if nutra:
print("C", NUT_C)
elif mod == 9:
xmode = 1
if nutra:
print("HEX")
elif mod == 10:
xmode = 0
if nutra:
print("DEC")
elif mod == 11:
if dpoff == 0 and dipen < 0:
dipen = didel
dpoff = 1
elif mod == 12:
# if dpoff , mdl > 1 then,
# curva = SysPostEventSem(bvd) /* stop "blinking" */
dpoff = 1 - dpoff
dipen = 1
elif mod == 13 and cry == 0:
pass
elif mod == 14 and cry == 1:
pass
else:
rtnx()
return()
# Subclass 10
def CL0_10(mod):
global selram, dipen
selram = (selram // 16) * 16 + mod
RAM[selram] = NUT_C # now trigger RAM-tv
print("RAM(" + str(selram) + ")", RAM[selram])
if selram == 9 | selram == 10:
if dpoff == 0 and dipen < 0:
dipen = didel
return()
# Subclass 12
def CL0_12(mod):
global NUT_C, selram, dipen
# if mod == 0: # blinking display, Voyagers only
if mod == 1:
NUT_N = NUT_C
if nutra:
print("N", NUT_N)
elif mod == 2:
NUT_C = NUT_N
if nutra:
print("C", NUT_C)
elif mod == 3:
teval = NUT_N
NUT_N = NUT_C
NUT_C = teval
if nutra:
print("C, N", NUT_C, NUT_N)
elif mod == 5:
purtn(int(NUT_C[7:11], 16))
elif mod == 6:
NUT_C = NUT_C[:8] + f"{RTN[0]:04X}" + NUT_C[12:]
poprtn()
if nutra:
print("C", NUT_C)
elif mod == 7: # delay patch
time.sleep(1.2)
pc += 1
elif mod == 8:
pc = (pc // 256) * 256 + int(key, 16)
if nutra:
print("PC", f'{pc:04X}')
elif mod == 9:
selram = int(NUT_C[11:], 16) % 256 # @0..FF in this simulation
if nutra:
print("selram", f'{selram:03X}')
elif mod == 11:
# if selram == 25 | selram == 26: # 15C only
RAM[selram] = NUT_C # now trigger RAM-tv
if selram == 9 | selram == 10:
if dpoff == 0 and dipen < 0:
dipen = didel
elif mod == 12:
teval = int(NUT_C[7:11], 16)
NUT_C = NUT_C[:11] + f"{ROM[teval]:03X}"
if nutra:
print("C", NUT_C)
elif mod == 13:
teval = int(NUT_C, 16) | int(NUT_A, 16)
NUT_C = f"{teval:0>14X}"
if nutra:
print("C", NUT_C)
elif mod == 14:
teval = int(NUT_C, 16) & int(NUT_A, 16)
NUT_C = f"{teval:0(14)X}"
if nutra:
print("C", NUT_C)
else:
selper = NUT_C[12:] # on Voyagers???
return()
# Subclass 14
def CL0_14(mod):
global selram, NUT_C
if mod > 0:
selram = (selram // 16) * 16 + mod
NUT_C = RAM[selram]
if nutra:
print("C", NUT_C)
return()
# Subclass 15
def CL0_15(mod):
global NUT_C
if mod == 7 | mod == 15 | ti[mod] == 0:
pass
else:
teval = NUT_C + NUT_C
NUT_C = teval[14 - ti[mod]:28 - ti[mod]]
if nutra:
print("C", NUT_C)
return()
## Class 2
# subroutines for Class 2 first
def c2dec(teval, mod): # decrement
global crx
if xmode == 1:
max = "F"
else:
max = 9
split = list(teval)
crx = 1
ba = TEMo[mod] - 1
while ba >= TEMa[mod]: # do ba = TEMo.mod to TEMa.mod by -1
teval = int(split[ba], 16)
if teval == 0:
if crx == 1:
split[ba] = max
else:
teval -= crx
crx = 0
if teval > 9 and xmode == 0:
teval -= 6
if ba == TEMa[mod]:
crx = 1
split[ba] = f"{teval:01X}"
if xmode == 1:
ba = 0 # leave
ba -= 1
return("".join(split))
def c2inc(teval, mod): # increment
global crx
max = 10 + 6 * xmode
split = list(teval)
# print("split", split)
crx = 1
i = TEMo[mod] - 1
while i >= TEMa[mod]:
# print("i, split(i)", i, split[i])
teval = int(split[i], 16) + crx
crx = teval // max
split[i] = f'{teval % max:01X}'
if crx == 0 and xmode == 1: # /* force hex to dec, see P6RTN in VASM listing */
i = 0 # leave
i -= 1
return("".join(split))
def c2nez(teval, mod):
# global mod # despite this -- NameError: name 'mod' isn't defined
global crx
split = list(teval)
i = TEMa[mod]
while i <= TEMo[mod]:
if int(split[i], 16) != 0:
crx = 1
i = TEMo[mod]
i += 1
return()
def c2add(wr, ws, mod):
# global mod wuud?? -- NameError: name 'mod' isn't defined
global crx
max = 10 + 6 * xmode
splwr = list(wr)
splws = list(ws)
i = TEMo[mod] - 1
while i >= TEMa[mod]:
teval = int(splwr[i], 16) + int(splws[i], 16) + crx
if teval >= max:
teval -= max
crx = 1
else:
crx = 0
splwr[i] = f'{teval:01X}'
i -= 1
return("".join(splwr))
def CL2(cmd, mod):
global NUT_A, NUT_B, NUT_C, crx, TEMa, TEMo
if mod == 0: # @Pt
TEMa[0] = 13 - Pt[selpt]
TEMo[0] = TEMa[0] + 1
elif mod == 2: # WPt
TEMa[2] = 13 - Pt[selpt]
elif mod == 4: # PQ
if Pt[0] > Pt[1]:
TEMa[4] = 0
else:
TEMa[4] = 13 - Pt[1]
TEMo[4] = 14 - Pt[0]
# no otherwise, rest is invariable and set
if cmd < 16:
if cmd < 8:
if cmd == 0: # A=0
### Test-test-test
NUT_A = NUT_A[:TEMa[mod]] \
+ f"{'0':0{TEMo[mod]-TEMa[mod]}}" \
+ NUT_A[TEMo[mod]:]
if nutra:
print("A", NUT_A)
elif cmd == 1: # B=0
NUT_B = NUT_B[:TEMa[mod]] \
+ f"{'0':0{TEMo[mod]-TEMa[mod]}}" \
+ NUT_B[TEMo[mod]:]
if nutra:
print("B", NUT_B)
elif cmd == 2: # C=0
print("C p1", NUT_C[:TEMa[mod]])
print("0 p2", f"{'0':0{TEMo[mod]-TEMa[mod]}}")
print("C p3", NUT_C[TEMo[mod]:])
NUT_C = NUT_C[:TEMa[mod]] \
+ f"{'0':0{TEMo[mod]-TEMa[mod]}}" \
+ NUT_C[TEMo[mod]:]
if nutra:
print("C", NUT_C)
elif cmd == 3: # A<>B
teval = NUT_A[TEMa[mod]:TEMo[mod]]
NUT_A = NUT_A[:TEMa[mod]] + NUT_B[TEMa[mod]:TEMo[mod]] + NUT_A[TEMo[mod]:]
NUT_B = NUT_B[:TEMa[mod]] + teval + NUT_B[TEMo[mod]:]
if nutra:
print("A, B", NUT_A, NUT_B)
elif cmd == 4: # B=A
NUT_B = NUT_B[:TEMa[mod]] + NUT_A[TEMa[mod]:TEMo[mod]] + NUT_B[TEMo[mod]:]
if nutra:
print("B", NUT_B)
elif cmd == 5: # A<>C
teval = NUT_A[TEMa[mod]:TEMo[mod]]
NUT_A = NUT_A[:TEMa[mod]] + NUT_C[TEMa[mod]:TEMo[mod]] + NUT_A[TEMo[mod]:]
NUT_C = NUT_C[:TEMa[mod]] + teval + NUT_C[TEMo[mod]:]
if nutra:
print("A, C", NUT_A, NUT_C)
elif cmd == 6: # C=B
NUT_C = NUT_C[:TEMa[mod]] + NUT_B[TEMa[mod]:TEMo[mod]] + NUT_C[TEMo[mod]:]
if nutra:
print("C", NUT_C)
else: # B<>C
teval = NUT_B[TEMa[mod]:TEMo[mod]]
NUT_B = NUT_B[:TEMa[mod]] + NUT_C[TEMa[mod]:TEMo[mod]] + NUT_B[TEMo[mod]:]
NUT_C = NUT_C[:TEMa[mod]] + teval + NUT_C[TEMo[mod]:]
if nutra:
print("B, C", NUT_B, NUT_C)
else:
if cmd == 8: # A=C
NUT_A = NUT_A[:TEMa[mod]] + NUT_C[TEMa[mod]:TEMo[mod]] + NUT_A[TEMo[mod]:]
elif cmd == 9: # A+=B
NUT_A = c2add(NUT_A, NUT_B, mod)
elif cmd == 10: # A+=C
NUT_A = c2add(NUT_A, NUT_C, mod)
elif cmd == 11: # A+=1
NUT_A = c2inc(NUT_A, mod)
elif cmd == 12: # A-=B
NUT_A = c2sub("A", "B")
elif cmd == 13: # A-=1
NUT_A = c2dec(NUT_A, mod)
elif cmd == 14: # A-=C
NUT_A = c2sub("A", "C")
else: # C+=C
NUT_C = c2add(NUT_C, NUT_C, mod)
if nutra:
if cmd == 15:
print("C", NUT_C)
else:
print("A", NUT_A)
else:
if cmd < 24:
if cmd == 16: # C+=A
NUT_C = c2add(NUT_C, NUT_A, mod)
elif cmd == 17: # C+=1
NUT_C = c2inc(NUT_C, mod)
elif cmd == 18: # C=A-C
NUT_C = c2sub("A", "C")
elif cmd == 19: # C-=1
NUT_C = c2dec(NUT_C, mod)
elif cmd == 20: # C=-C
c2nez(NUT_C, mod)
if crx == 1:
max = 9 + xmode * 6
split = list(NUT_C)
nixbix = 1
i = TEMo[mod]
while i > TEMa[mod]: # do i = TEMo.mod to TEMa.mod by -1
teval = max - int(split[i], 16) + nixbix
nixbix = 1
if teval > max:
teval = 0
else:
nixbix = 0
split[i] = hex(teval)
i -= 1
NUT_C = "".join(split)
elif cmd == 21: # C=-C-l
max = 9 + xmode * 6
split = list(NUT_C)
i = TEMa[mod]
while i < TEMo[mod]: # do i = TEMa.mod to TEMo.mod
split[i] = f'{max - int(split[i], 16):01X}'
i += 1
NUT_C = "".join(split)
crx = 1
elif cmd == 22: # ?B≠0
c2nez(NUT_B, mod)
else: # ?C≠O
c2nez(NUT_C, mod)
if nutra:
if cmd == 22:
print("B, crx", NUT_B, crx)
else:
print("C", NUT_C)
else:
if cmd == 24: # ?A<C
c2qlt("C")
if nutra:
print("A, C", NUT_A, NUT_C)
elif cmd == 25: # ?A<B
c2qlt("B")
if nutra:
print("A, B", NUT_A, NUT_B)
elif cmd == 26: # ?A≠0
c2nez(NUT_A, mod)
if nutra:
print("A", NUT_A)
elif cmd == 27: # ?A≠C
if NUT_A[TEMa[mod]:TEMo[mod]] != NUT_C[TEMa[mod]:TEMo[mod]]:
crx = 1
if nutra:
print("A, C", NUT_A, NUT_C)
elif cmd == 28: # ASR
c2sr("A")
if nutra:
print("A", NUT_A)
elif cmd == 29: # BSR
c2sr("B")
if nutra:
print("B", NUT_B)
elif cmd == 30: # CSR
c2sr("C")
if nutra:
print("C", NUT_C)
else:
split = list(NUT_A)
if TEMa[mod] != TEMo[mod]:
i = TEMa[mod]
while i < TEMo[mod] - 1:
split[i] = split[i+1]
i += 1
split[TEMo[mod]] = "0"
NUT_A = "".join(split)
if nutra:
print("A", NUT_A)
return()
## /*****************************************/
## /* main running loop */
## /*****************************************/
## First try in MPY
pc = 0 # program counter when starting clocks
while (True):
if dcf[pc] == "VOID":
dcdfw()
print(f"{pc:04X}", f"{ROM[pc]:03X}", dcf[pc])
dcd = dcf[pc]
preco = cmd
cmd = dcd[1]
if dcd[0] == 2: # cases sequenced by occurrence
CL2(cmd, dcd[2]) # class 2 (sub, mod)
elif dcd[0] == 0:
eval(f"CL0_{dcd[1]}({dcd[2]})") # CL0_sub(mod)
elif dcd[0] == 3:
print("Cl3 - cry", cry)
if dcd[3] == cry:
pc = dcd[2]
elif dcd[0] == 1:
if dcd[3] == cry:
if cmd == 'XQ':
purtn(pc+2)
pc = dcd[2]
else:
cmd = ""
pc += 1
else: # LC
NUT_C = NUT_C[:11] + dcd[1] # [:11] is _not_ length, it's Python
if nutra:
print("C", NUT_C)
pc += 1
cry = crx # carry flip-flop
crx = 0
pc += 1
quit()Loading
xiao-esp32-c6
xiao-esp32-c6
Box
Lid
Box
Lid