init repo
This commit is contained in:
commit
90e6151613
3260 files changed
+3745062
No files matched your search
@@ -0,0 +1,3 @@
|
||||
- TinyBASIC scripts.
|
||||
- gt1 ports of previous BASIC programs.
|
||||
- Python3 ported version of sendFile.py (as sendFile3.py).
|
||||
@@ -0,0 +1,74 @@
|
||||
'graph display with clock
|
||||
'(hr:min) using 59.98Hz
|
||||
'counter. UnREM lines 125
|
||||
'and 425 to see seconds
|
||||
'for debugging, adjust I
|
||||
'(1/100 sec/min) and J
|
||||
'(1/100 sec/hour) for
|
||||
'clock finetuning.
|
||||
'Set time with Famicom
|
||||
'A button + arrows,
|
||||
'toggle fixed clock
|
||||
'colour with B button.
|
||||
|
||||
10 poke 14,0:poke 46,1
|
||||
20 A=0:B=0:I=-3:J=8
|
||||
30 K=0:H=0:M=0:S=0
|
||||
40 poke 42,0
|
||||
50 cls:C=rnd(23)+1
|
||||
60 P=rnd(101)+43
|
||||
70 P=P*(rnd(2)+1)
|
||||
80 U=5400:V=0
|
||||
90 for R=0 to 15
|
||||
100 Z=S+(427/256*B)
|
||||
110 if Z<6000 goto 160
|
||||
120 M=M+1:S=S+I-6000
|
||||
125 'Z=Z-6000
|
||||
130 if M<60 goto 160
|
||||
140 M=0:H=H+1:S=S+J
|
||||
150 if H=24 H=0
|
||||
160 T=rnd(128)+2
|
||||
170 if K=0 poke 43,C
|
||||
180 gosub 400
|
||||
190 for X=0to159:L=X/20
|
||||
200 if peek(20)<8 L=L+8
|
||||
210 poke 20,L:Q=peek(17)
|
||||
220 if Q<>255 gosub 500
|
||||
230 Y=72-U/100
|
||||
240 poke Y*256+X,C
|
||||
250 U=U+V:V=V-U/P
|
||||
260 B=peek(14)
|
||||
270 if B<A S=S+427
|
||||
280 A=B:next X:C=C+23
|
||||
290 if C%64=0 C=C+23
|
||||
300 at T,1:?" ";
|
||||
310 next R:goto 50
|
||||
|
||||
400 at T,1
|
||||
410 ?H/10;H%10;":";
|
||||
420 ?M/10;M%10;
|
||||
425 'at2,112:?Z/100;" ";
|
||||
430 return
|
||||
|
||||
500 if Q<>191 goto 530
|
||||
510 K=K+1:if K=64 K=0
|
||||
520 goto 700
|
||||
530 poke 43,63
|
||||
540 if Q<>119 goto 570
|
||||
550 M=M+1:if M>59 M=0
|
||||
560 S=0:goto 650
|
||||
570 if Q<>123 goto 600
|
||||
580 M=M-1:if M<0 M=59
|
||||
590 S=0:goto 650
|
||||
600 if Q<>125 goto 630
|
||||
610 H=H-1:if H<0 H=23
|
||||
620 goto 650
|
||||
630 if Q<>126 goto 650
|
||||
640 H=H+1:if H>23 H=0
|
||||
650 gosub 400:Q=peek(17)
|
||||
660 if Q<>255 goto 540
|
||||
670 if S=0 poke 14,0
|
||||
680 if K>0 goto 700
|
||||
690 poke 43,C:goto 710
|
||||
700 poke 43,K
|
||||
710 gosub 400:return
|
||||
@@ -0,0 +1,96 @@
|
||||
_runtimePath_ "../runtime"
|
||||
_codeRomType_ ROMv2
|
||||
|
||||
' graph display with clock (hr:min) using 59.98Hz counter.
|
||||
' Set time with Famicom A button + arrows.
|
||||
|
||||
const CLOCKC = &h03
|
||||
const MINADJUST = -3 ' adjust (1/100 sec/min) for clock finetuning
|
||||
const HOURADJUST = 8 ' adjust (1/100 sec/hour) for clock finetuning
|
||||
|
||||
def A, B, K, P, U, V, , CONTRL, CLOCKX, HOUR, MINUTE, SECOND
|
||||
|
||||
initialize:
|
||||
init vars @A
|
||||
mode 2
|
||||
set BG_COLOUR, &h00
|
||||
set FG_COLOUR, CLOCKC
|
||||
poke &h0E, 0
|
||||
|
||||
begin:
|
||||
COLOUR = rnd(23) + 1
|
||||
gosub newscreen
|
||||
repeat
|
||||
|
||||
' update clock
|
||||
Z = SECOND + (427 / 256 * B)
|
||||
if Z >= 6000
|
||||
inc MINUTE
|
||||
SECOND = SECOND + MINADJUST - 6000
|
||||
if MINUTE = 60
|
||||
MINUTE = 0
|
||||
inc HOUR
|
||||
SECOND = SECOND + HOURADJUST
|
||||
if HOUR = 24 then HOUR = 0
|
||||
endif
|
||||
gosub newscreen
|
||||
endif
|
||||
|
||||
' add graph
|
||||
for X = 0 to 159
|
||||
Y = 72 - (U / 100)
|
||||
poke Y * 256 + X, COLOUR
|
||||
U = U + V : V = V - U / P
|
||||
B = peek(&h0E)
|
||||
if B < A then SECOND = SECOND + 427
|
||||
A = B
|
||||
next X
|
||||
|
||||
' new graph colour
|
||||
COLOUR = COLOUR + 23
|
||||
if COLOUR mod 64 = 0 then COLOUR = COLOUR + 23
|
||||
|
||||
' set time
|
||||
CONTRL = peek(&h11)
|
||||
if CONTRL <> 255 then gosub settime
|
||||
|
||||
forever
|
||||
|
||||
newscreen:
|
||||
cls
|
||||
CLOCKX = rnd(128) + 2
|
||||
gosub showclock
|
||||
P = rnd(101) + 43 : P = P * (rnd(2) + 1) : U = 5400 : V = 0
|
||||
return
|
||||
|
||||
settime:
|
||||
set FG_COLOUR, &hFF
|
||||
while CONTRL <> 255
|
||||
if CONTRL = 119
|
||||
inc MINUTE
|
||||
if MINUTE > 59 then MINUTE = 0
|
||||
SECOND = 0
|
||||
elseif CONTRL = 123
|
||||
dec MINUTE
|
||||
if MINUTE < 0 then MINUTE = 59
|
||||
SECOND = 0
|
||||
elseif CONTRL = 125
|
||||
dec HOUR
|
||||
if HOUR < 0 then HOUR = 23
|
||||
elseif CONTRL = 126
|
||||
inc HOUR
|
||||
if HOUR > 23 then HOUR = 0
|
||||
endif
|
||||
gosub showclock
|
||||
wait 10
|
||||
CONTRL = peek(&h11)
|
||||
wend
|
||||
if SECOND = 0 then poke &h0E, 0
|
||||
set FG_COLOUR, CLOCKC
|
||||
gosub showclock
|
||||
return
|
||||
|
||||
showclock:
|
||||
at CLOCKX, 1
|
||||
print HOUR / 10 ; HOUR mod 10 ; ":" ; MINUTE / 10 ; MINUTE mod 10
|
||||
return
|
||||
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
1 'calculate primes
|
||||
2 'between 3 and L
|
||||
10 L=10000:mode 2
|
||||
15 poke42,16:poke46,1:cls
|
||||
20 R=0:B(0)=124:B(1)=47
|
||||
25 B(2)=45:B(3)=92:C(0)=0
|
||||
30 C(1)=8:C(2)=4:C(3)=12
|
||||
35 for N=3 to L:poke43,3
|
||||
36 X=0:Y=0:Z=0:poke 14,0
|
||||
40 if N%2=0 goto 75
|
||||
45 for D=2 to N-1
|
||||
46 Y=peek(14)
|
||||
47 if Y<X Z=Z+427
|
||||
50 X=Y:at 2:put B(D%4)
|
||||
55 poke 20,1+(D%2)+C(R)
|
||||
60 if N%D=0 goto 75
|
||||
65 nextD:poke43,63
|
||||
67 S=(Z+(427/256*Y))/100
|
||||
68 at2:?N;" -> ";S;"s"
|
||||
70 R=R+1:if R=4 R=0
|
||||
75 next N:at 2:put 32:?
|
||||
80 poke 43,63:poke 46,0
|
||||
85 mode 1:end
|
||||
@@ -0,0 +1,26 @@
|
||||
10 mode 1
|
||||
15 poke 42,16:poke 46,1
|
||||
20 W(0)=124:W(1)=47
|
||||
25 W(2)=45:W(3)=92
|
||||
30 cls:poke 43,32:C=0
|
||||
35 ?"<q>uit at pause":?
|
||||
40 poke 43,53
|
||||
45 ?"Calculating numbers"
|
||||
50 ?"between 0 and 15":?
|
||||
55 if C=8 goto 30
|
||||
60 C=C+1:poke 43,3
|
||||
65 for T=0 to 128
|
||||
70 at 2:put W(T%4)
|
||||
75 poke 20,rnd(16):next T
|
||||
80 poke 20,0:for T=0 to 3
|
||||
85 B(T)=rnd(2):next T
|
||||
90 N=B(0)+B(1)*2+B(2)*4
|
||||
95 N=N+B(3)*8:poke 43,63
|
||||
100 L=B(3)+B(2)*2+B(1)*4
|
||||
105 L=L+B(0)*8:poke 20,L
|
||||
110 at 2:?N:for T=0 to 50
|
||||
115 K=peek(15)
|
||||
120 if K=113 goto 130
|
||||
125 next T:goto 55
|
||||
130 poke 42,63:poke 43,53
|
||||
135 poke 46,0:cls:end
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env python
|
||||
#-----------------------------------------------------------------------
|
||||
#
|
||||
# sendFile3.py -- Send file to Gigatron through Arduino as interface
|
||||
# for Python 3.x, ported from sendFile.py
|
||||
#
|
||||
# Tested with Python 3.8.0 on Linux (Arch Linux x86_64)
|
||||
# Not tested on other platforms or other Python 3.x releases
|
||||
# NOT backwards compatible with Python 2.x
|
||||
#
|
||||
# From sendFile.py (Python 2.x):
|
||||
# 2018-04-29 (marcelk) Initial version
|
||||
# 2018-05-13 (marcelk) Use application level flow control
|
||||
# 2018-05-29 (rockybulwinkle) Add option to override detected port,
|
||||
# search on /dev/ttyACM* as well, swith to argparse.
|
||||
# 2018-05-30 (marcelk) Enable stdin again. A bit more consistency.
|
||||
# 2018-06-04 (marcelk) Allow timeout while waiting for first prompt
|
||||
# 2018-06-29 (marcelk) Send escaped control bytes to newer Babelfishes
|
||||
# 2018-07-23 (marcelk) Send GTB files into BASIC. Renamed to sendFile.py
|
||||
# 2018-07-28 (marcelk) Remove escaping of control bytes. Workaround FIFOCON bug.
|
||||
#
|
||||
# sendFile3.py:
|
||||
# 2019-12-19 (crouze) Initial port from senFile.py
|
||||
# BASIC truncation result added to stdout
|
||||
#
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import glob
|
||||
import serial # pySerial: http://pyserial.readthedocs.io/en/latest/index.html
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
# One-for-all error handler (don't throw scary stack traces at the user)
|
||||
sys.excepthook = lambda exType, exValue, exTrace: print('%s: %s' % (exType.__name__, exValue))
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Command line arguments
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
parser = argparse.ArgumentParser(description='Send a file into the Gigatron')
|
||||
parser.add_argument('-v', '--verbose', dest='verbose',
|
||||
help='be verbose',
|
||||
action='store_true', default=False)
|
||||
parser.add_argument('-p', '--port', dest='port',
|
||||
help='USB port to Arduino (default is auto-detect)',
|
||||
default=None)
|
||||
parser.add_argument('filename', help='GT1 or GTB file', nargs='?')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Functions
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
def log(prefix, line):
|
||||
if args.verbose:
|
||||
print(prefix, line)
|
||||
|
||||
def sendCommand(cmd=None, timeout=False):
|
||||
"""Send command to Gigatron Adapter Interface and wait for ready prompt"""
|
||||
if cmd:
|
||||
log('>', cmd)
|
||||
ser.write(str.encode(cmd + '\n'))
|
||||
|
||||
# Wait for prompt
|
||||
line = readLine()
|
||||
while not (line is None and timeout):
|
||||
if not line is None:
|
||||
line = line.decode()
|
||||
if line:
|
||||
if line[-1] == '?': # Got prompt
|
||||
break
|
||||
if line.startswith('!'): # Got error
|
||||
raise Exception(line[1:])
|
||||
line = readLine()
|
||||
return line
|
||||
|
||||
def readLine():
|
||||
"""Read line from serial port with optional verbosity"""
|
||||
line = ser.readline()
|
||||
if line:
|
||||
line = line.rstrip() # Remove any trailing newline and spaces
|
||||
log('<', line)
|
||||
else:
|
||||
line = None # Signal that there is a timeout
|
||||
if args.verbose:
|
||||
sys.stdout.write('.')
|
||||
sys.stdout.flush()
|
||||
return line
|
||||
|
||||
def sendGt1(fp):
|
||||
"""Send Gigatron object file"""
|
||||
ask = sendCommand('U')
|
||||
|
||||
while ask[0].isdigit():
|
||||
# Arduino will ask for <n> bytes by sending '<n>?'
|
||||
if ask[0] == '0': # Keep this check for a transition period until end 2018
|
||||
raise Exception('Please update BabelFish.ino sketch on Arduino')
|
||||
n = int(ask[:-1])
|
||||
data = fp.read(n)
|
||||
if len(data) < n:
|
||||
raise Exception('File too short')
|
||||
sys.stdout.write('.')
|
||||
sys.stdout.flush()
|
||||
ser.write(data)
|
||||
ask = sendCommand(None)
|
||||
print()
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Connect to Arduino
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
port = None
|
||||
if not args.port:
|
||||
# Sometimes the Arduino shows up on /dev/tty.usbmodem* or /dev/ttyACM*
|
||||
serPorts = glob.glob('/dev/tty.usbmodem*') + glob.glob('/dev/ttyACM*')
|
||||
if len(serPorts) == 0:
|
||||
raise Exception('No USB device detected')
|
||||
if len(serPorts) > 1:
|
||||
raise Exception('More than one USB device detected: %s' % ' '.join(serPorts))
|
||||
port = serPorts[0]
|
||||
else:
|
||||
port = args.port
|
||||
|
||||
print('Connecting to', port)
|
||||
ser = serial.Serial(port=port, baudrate=115200, timeout=2)
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Send program
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
if args.filename:
|
||||
fp = open(args.filename, 'rb')
|
||||
else:
|
||||
fp = sys.stdin
|
||||
|
||||
sendCommand(timeout=True) # Wait for prompt, but not for too long
|
||||
|
||||
print('Resetting Gigatron')
|
||||
sendCommand('R')
|
||||
|
||||
print('Starting Loader')
|
||||
sendCommand('L')
|
||||
|
||||
if args.filename and args.filename.lower().endswith(('.gt1', '.gt1x')):
|
||||
print('Sending program %s' % repr(args.filename))
|
||||
sendGt1(fp)
|
||||
else:
|
||||
isBasic = args.filename and args.filename.lower().endswith(('.gtb', 'gtbx', '.bas'))
|
||||
if isBasic:
|
||||
print('Loading BASIC')
|
||||
sendCommand('P')
|
||||
sleep(2) # BASIC takes a while on 64K
|
||||
print('Sending text %s' % (repr(args.filename) if args.filename else 'from stdin'))
|
||||
for line in fp:
|
||||
line = line.strip().decode()
|
||||
if len(line) > 25:
|
||||
print("Truncated %s" % repr(line))
|
||||
line = line[0:25]
|
||||
print(" to %s" % repr(line))
|
||||
sendCommand('.' + line)
|
||||
if isBasic:
|
||||
sendCommand('.RUN')
|
||||
|
||||
print('Finished')
|
||||
|
||||
if args.filename:
|
||||
fp.close()
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
#
|
||||
#-----------------------------------------------------------------------
|
||||
Reference in new issue
Block a user