Question…
How do I share a basic program here without using an external site?…Brian
Question…
How do I share a basic program here without using an external site?…Brian
You can always paste the source code in a comment, between a line containing just three backticks in a row and another line containing the same, like this:
: hello ( -- ) cr ." Hello, world!" ;
Attached is a HexDump program I’ve been working on. It reads any file and displays it in Hex format. Useful to analyze binary files. Someday I’d like to expand it to a HexEditor.
It originally was created by AI. I fixed the code to work on PicoCalc, then enhanced it.
Enjoy….brian
' =========================================================
' HEXDUMP.BAS - Display a file in hexadecimal format
' Works on PicoMite MMBasic
'
' Created by AI
' Converted & enhanced by Brian Osborne
' =========================================================
Option Explicit
Begin:
Font 1
DIM filename$ = ""
Print "Enter file name to display in hex: "
Input filename$
' Check if file exists
IF NOT mm.info(Exists File filename$) THEN
PRINT "Error: File not found."
END
END IF
OPEN filename$ FOR INPUT AS #1
DIM buffer%(15) ' 16-byte buffer
DIM byteCount%, addr%, rowNum%, myFont%
DIM bytesInRow%, a$, i%
Print "Select desired font size."
Print "Normal, Small or Tiny"
Print "N, S, T ";
myFont%=0
DO
a$=Inkey$
Select Case Asc(a$)
Case 110,78 ' N
myFont%=1
bytesInRow%=8
Case 115, 83 ' S
myFont%=7
bytesInRow%=8
Case 116, 84 ' T
myFont%=8
bytesInRow%=16
End Select
Loop Until myFont%>0
Font myFont% 'Set desired font
Top:
addr% = 0
rowNum%=0
CLS
Select Case myFont%
Case 1, 7 'Normal or Small
Print "FSet Hex Bytes" String$(16," ")"ASCII"
Print String$(4,"-") " " String$(23,"-") " " String$(8,"-")
Case 8 'Tiny
Print "FSet Hex Bytes" String$(41," ") "ASCII"
Print String$(4,"-") " " String$(23,"-") " " String$(23,"-") " " String$(16,"-")
End Select
DO WHILE NOT EOF(#1)
' Start a new row of bytes
byteCount% = 0
' Read a row of bytes into buffer
FOR i% = 0 TO (bytesInRow%-1)
IF EOF(#1) THEN EXIT FOR
buffer%(i%) = ASC(INPUT$(1, #1))
Inc byteCount%
NEXT i%
' Print off-set
PRINT Format$(addr%,"%04g");
PRINT " ";
' Print hex bytes
FOR i% = 0 TO (bytesInRow%-1)
IF i% < byteCount% THEN
If i%=8 And myFont%=8 Then
Print " ";
EndIf
Print Hex$(buffer%(i%),2);
ELSE
PRINT " "; 'blanks if no data
END IF
' 1 blank between each hex pair
PRINT " ";
NEXT i%
' Print ASCII representation
PRINT " ";
FOR i% = 0 TO byteCount% - 1
IF buffer%(i%) >= 32 AND buffer%(i%) <= 126 THEN
PRINT CHR$(buffer%(i%));
ELSE
PRINT ".";
END IF
NEXT i%
' determine if screen is full
' if yes, wait for Enter or Esc
' Enter = start a new screen
' Esc = exit
rowNum% = MM.VPOS / MM.FontHeight
If rowNum% >= (MM.Height-3) Then
?@(0,(320-MM.FontHeight)) "Esc=EXIT Enter=Next Top Switch File";
Do
a$=Inkey$
Select Case Asc(a$)
Case 27 ' Esc=Exit
' ?@(0,0);
END
Case 115, 83 ' Switch File
Close #1
Clear 'All vars
CLS
GoTo Begin
Case 116, 84 ' T
Close #1
OPEN filename$ FOR INPUT AS #1
GoTo Top
Case 13 ' Enter
Exit Do
End Select
Loop
' Display next screen
CLS
EndIf
PRINT ' Move to next row
addr% = addr% + byteCount%
LOOP ' Dump complete file
CLOSE #1
PRINT "End of File"
I have written a program that uses the new V6.02.00a software to display the altitude (height in degrees) and azimuth (angle clockwise from north) of the planets. A planet that is not currently visible has a red (negative) altitude. This makes it easy to find a planet if you know where north is.
You only have to insert your GPS Positin in degrees and your UTC difference in head of the code.
It’s a work in progress.
'Solar System Object Finder
'V1.0 11.02.2026
'Peter Doerwald
'need V6.02.00
OPTION BASE 1
'GPS Koordinates degrees
Dim lat=50.19835 'negative if south
Dim long=7.85702 'negative if west
Dim zone=1 ' Timezone, here UTC+1
Dim utc$
Dim alt,az
Dim stunde%,minute%,sekunde%
Dim tag%,monat%,jahr%
Dim days%(12)=(31,28,31,30,31,30,31,31,30,31,30,31)
Dim solar$(9)=("SUN","MOON","MERCURY","VENUS","MARS","JUPITER","SATURN","URANUS","NEPTUNE")
Dim x%
CLS
Do
calcUTC
Location utc$,lat,long
Text MM.HRES/2, 6, "** Zachzig presents **", "CM", 7, 1, RGB(BLUE)
Text MM.HRES/2, 25, "Solar System Object Finder", "CM", 7, 2, RGB(CYAN)
if MM.INFO$(PLATFORM)="PicoCalc" Then
Text MM.HRES/2, 50, "UTC:"+utc$+" Bat:"+str$(MM.Info(Battery))+"% ", "CM", 1, 1, RGB(GREEN)
else
Text MM.HRES/2, 50, "UTC:"+utc$+" Bat:", "CM", 1, 1, RGB(GREEN)
endif
line 0,90,319,90,1,RGB(yellow)
Text 95, 89,"Altitude", "LB", 2, 1, RGB(WHITE)
Text 210, 89,"Azimuth", "LB", 2, 1, RGB(WHITE)
for x%=1 to 9
Text 0, x%*25+88,solar$(x%), "LB", 2, 1, RGB(YELLOW)
line 0,90+(x%*25),319,90+(x%*25),1,RGB(yellow)
Execute "Astro "+solar$(x%)+" alt,az"
if alt<0 Then
Text 95, x%*25+88,str$(alt,3,4), "LB", 2, 1, RGB(RED)
else
Text 95, x%*25+88,str$(alt,3,4), "LB", 2, 1, RGB(GREEN)
endif
Text 210, x%*25+88,str$(az,3,4), "LB", 2, 1, RGB(GREEN)
next x%
pause 1000
Loop
sub calcUTC
Local stNew%
stunde%=VAL(FIELD$(time$,1,":"))
minute%=VAL(FIELD$(time$,2,":"))
sekunde%=VAL(FIELD$(time$,3,":"))
tag%=VAL(FIELD$(date$,1,"-"))
monat%=VAL(FIELD$(date$,2,"-"))
jahr%=VAL(FIELD$(date$,3,"-"))
stNew%=stunde%-zone
'Korrektur negativ
if (stNew%<0) Then
stNew%=24+stNew%
'korrigiere Datum
tag%=tag%-1
if(tag%<1) Then
monat%=monat%-1
if (monat%<1) Then
monat%=12
jahr%=jahr%-1
endif
' Tage im Vormonat setzen (vereinfacht)
tag%=days%(monat%)
endif
endif
'Korrektur overflow
if (stNew%>23) Then
stNew%=stNew%-24
'korrigiere Datum
tag%=tag%+1
if (tag%>days%(monat%) Then
tag%=1
monat%=monat%+1
if monat$>12 then
monat%=1
jahr%=jahr%+1
endif
endif
endif
utc$=str$(tag%,2,0,"0")+"-"+str$(monat%,2,0,"0")+"-"+str$(jahr%,2,0,"0")
utc$=utc$+" "+str$(stNew%,2,0,"0")+":"+str$(minute%,2,0,"0")+":"+str$(sekunde%,2,0,"0")
END SUB
Nice Tool. I’ll try it asap
'space invaders fractal
Randomize &h12345
Dim integer w(8)
'precalc
For i=0 To 7
b1%=1
b2%=16
v%=i
For j=0 To 2
If (v% And b1%) Then v%=(v% Or b2%)
b1%=b1%+b1%
b2%=b2%/2
Next j
w(i)=v%
'Print i,v%
Next i
CLS
For x1=0 To 39
For y1=0 To 39
Do
co=Rnd()*&hffffff
Loop Until co
For yy=0 To 4
s%=Int(7*Rnd())
b1%=16
s%=w(s%)
For xx=0 To 4
If (s% And b1%) Then
Pixel x1*8+xx,y1*8+yy,co'&hffffff
EndIf
b1%=b1%/2
Next xx
Next yy
Next y1
Next x1
sooo slow. Any idea how t o fast code?
y%=0
Do
Blit 0,1,0,0,320,319
For x=0 To 319
If (x Xor y%) Mod 9 <>0 Then
c=0
Else
c=&hffffff
EndIf
Pixel x,319,c
Next x
y%=y%+1
Loop Until Inkey$=Chr$(27)
Reduce code size as much as possible (as code is interpreted not complied), define variables as integers wherever possible at the start of your code and those inside critical loops first (integers operate faster, those defined first are found quicker). Keep variable names to 4 characters or less. Look at ways of achieving the same output with shorter, simpler code…
Try defining variables such as x, y and c as integers at the start of the program then there’s no need for the % symbols. If you are using the original Pico1 consider a Pico2. Also try increasing clock speed but beware that if you have an issue you’ll have to reflash the Pico (try with a spare Pico). I’m running at 378Mhz on a Pico2 with a ceramic heatsink (no shorts if it detaches).
Option default integer
y=0
Dim px(319),py(319),c(319)
For i=0 To 319
px(i)=i
py(i)=319
Next
FRAMEBUFFER create
FRAMEBUFFER write f
Do
Sprite scroll 0,1
For x=0 To 319
c(x)=Choice((x Xor y) Mod 9,0,&HFFFFFF)
Next
Inc y
Pixel px(),py(),c()
FRAMEBUFFER copy f,n
Loop Until Inkey$=Chr$(27)
'chaos game
CLS
Dim x(4),y(4)
For i=0 To 4
x(i)=160*Cos((54+i*72)*Pi/180)
y(i)=160*Sin((54+i*72)*Pi/180)
Next i
xx=160
yy=160
Randomize &H123456
Do
i=Int(Rnd()*5)
xx=(xx+x(i))/2.5
yy=(yy+y(i))/2.5
Pixel xx+160,yy+160,&Hff0000
Loop Until Inkey$=Chr$(27)
'truchet tile
CLS
DefineFont #8
02410808
03040808 101020c0 c0201010 08080403
End DefineFont
Font 8,1
For i=1 To 1600
Print Chr$(65+Rnd());
Next i
Do While Inkey$="":Loop
Font 1
'Insult megademo/Codebusters
CLS
FRAMEBUFFER create
FRAMEBUFFER LAYER
FRAMEBUFFER WRITE L
Dim integer t(256)
For i=0 To 255
t(i)=Int(64+63*Sin(i*Pi/128))
Next i
Dim a0 As integer
Dim b0 As integer
Dim a As integer
Dim b As integer
For i=0 To 319
y1=Int(80+80*Sin(Pi*i/160))
y2=Int(80+40*Sin(Pi*i/160*1.7))
Line i,y1,i,y2,,&Hffffff)
Next i
FRAMEBUFFER WRITE N
CLS
Do
a=a0
b=b0
For y=0 To 319
h=t(a)+t(b)
Blit FRAMEBUFFER L,f,0,h,0,y,320,1
a=(a+3) And 255
b=(b+2) And 255
Next y
FRAMEBUFFER copy f,n
a0=(a0+3) And 255
b0=(b0+5) And 255
Loop Until Inkey$=Chr$(27)
I love old-school scientific calculators! So you can imagine my disappointment when all I could find were RPN calcs for the PicoCalc. So I whipped up the following in MMBASIC and it was a fun and challenging project for my skill level. Obviously, my phone is just as capable and always at the ready, but this project brought back lots of engineering school memories from back in the early 80s.
how to avoid spaces?
'ZX spectrum spigot, 1860 digits
a=10000
n=6525
Dim r(n)
For i=1 To n
r(i)=2000
Next i
r(n-1)=0
c=0
For k=n-1 To 1 Step -14
d=0
i=k
For j=i To 1 Step -1
d=d+r(j)*a
b=2*j-1
r(j)=d-Int(d/b)*b
d=Int(d/b)
If j>1 Then d=d*(j-1)
Next j
v=c+Int(d/a)
c=d-Int(d/a)*a
If v<10 Then Print "000";:GoTo l270
If v<100 Then Print "00";:GoTo l270
If v<1000 Then Print "0";:GoTo l270
l270:
Print v;
Next k
str$(v,4,0,"0")
right$(str$(v+1000000),4)
format$(v,”%04g”)
Strange. I love old-school scientific calculators too, but that’s exactly why I’m glad to have an RPN calculator to hand.
'parametric cat
CLS
For t!=0 To 2*Pi Step 1/300
x!=0-721/4*Sin(t!)+196/3*Sin(2*t!)-86/3*Sin(3*t!)-131/2*Sin(4*t!)
x!=x!+477/14 *Sin(5 *t!) + 27 *Sin(6 *t!) - 29/2 *Sin(7 *t!) + 68/5 *Sin(8*t!)
x!=x!+1/10 *Sin(9 *t!) + 23/4 *Sin(10 *t!) - 19/2 *Sin(12 *t!) - 85/21 *Sin(13 *t!)
x!=x!+2/3*Sin(14*t!)+27/5*Sin(15*t!)+7/4*Sin(16*t!)+17/9*Sin(17*t!)
x!=x!-4*Sin(18*t!)-1/2*Sin(19*t!)+1/6*Sin(20*t!)+6/7*Sin(21*t!)
x!=x!-1/8*Sin(22*t!)+1/3*Sin(23*t!)+3/2*Sin(24*t!)+13/5*Sin(25*t!)
x!=x!+Sin(26*t!)-2*Sin(27*t!)+3/5*Sin(28*t!)-1/5*Sin(29*t!)
x!=x!+1/5*Sin(30*t!)+(2337*Cos(t!))/8-43/5*Cos(2*t!)+322/5*Cos(3*t!)
x!=x!-117/5*Cos(4*t!)-26/5*Cos(5*t!)-23/3*Cos(6*t!)+143/4*Cos(7*t!)
x!=x!-11/4*Cos(8*t!)-31/3*Cos(9*t!)-13/4*Cos(10*t!)-9/2*Cos(11*t!)
x!=x!+41/20*Cos(12*t!)+8*Cos(13*t!)+2/3*Cos(14*t!)+6*Cos(15*t!)
x!=x!+17/4*Cos(16*t!)-3/2*Cos(17*t!)-29/10*Cos(18*t!)+11/6*Cos(19*t!)
x!=x!+12/5*Cos(20*t!)+3/2*Cos(21*t!)+11/12*Cos(22*t!)-4/5*Cos(23*t!)
x!=x!+Cos(24*t!)+17/8*Cos(25*t!)-7/2*Cos(26*t!)-5/6*Cos(27*t!)
x!=x!-11/10*Cos(28*t!)+1/2*Cos(29*t!)-1/5*Cos(30*t!)
y! = -(637 * Sin(t!)) / 2 - 188 / 5 * Sin(2 * t!) - 11 / 7 * Sin(3 * t!)
y!=y!- 12 / 5 * Sin(4 * t!) + 11 / 3 * Sin(5 * t!) - 37 / 4 * Sin(6 * t!)
y!=y!+ 8 / 3 * Sin(7 * t!) + 65 / 6 * Sin(8 * t!) - 32 / 5 * Sin(9 * t!)
y!=y!- 41 / 4 * Sin(10 * t!) - 38 / 3 * Sin(11 * t!) - 47 / 8 * Sin(12 * t!)
y!=y!+ 5 / 4 * Sin(13 * t!) - 41 / 7 * Sin(14 * t!) - 7 / 3 * Sin(15 * t!)
y!=y!- 13 / 7 * Sin(16 * t!) + 17 / 4 * Sin(17 * t!) - 9 / 4 * Sin(18 * t!)
y!=y!+ 8 / 9 * Sin(19 * t!) + 3 / 5 * Sin(20 * t!) - 2 / 5 * Sin(21 * t!)
y!=y!+ 4 / 3 * Sin(22 * t!) + 1 / 3 * Sin(23 * t!) + 3 / 5 * Sin(24 * t!)
y!=y!- 3 / 5 * Sin(25 * t!) + 6 / 5 * Sin(26 * t!) - 1 / 5 * Sin(27 * t!)
y!=y!+ 10 / 9 * Sin(28 * t!) + 1 / 3 * Sin(29 * t!) - 3 / 4 * Sin(30 * t!)
y!=y!- (125 * Cos(t!)) / 2 - 521 / 9 * Cos(2 * t!) - 359 / 3 * Cos(3 * t!)
y!=y!+ 47 / 3 * Cos(4 * t!) - 33 / 2 * Cos(5 * t!) - 5 / 4 * Cos(6 * t!)
y!=y!+ 31 / 8 * Cos(7 * t!) + 9 / 10 * Cos(8 * t!) - 119 / 4 * Cos(9 * t!)
y!=y!- 17 / 2 * Cos(10 * t!) + 22 / 3 * Cos(11 * t!) + 15 / 4 * Cos(12 * t!)
y!=y!- 5 / 2 * Cos(13 * t!) + 19 / 6 * Cos(14 * t!) + 7 / 4 * Cos(15 * t!)
y!=y!+ 31 / 4 * Cos(16 * t!) - Cos(17 * t!) + 11 / 10 * Cos(18 * t!)
y!=y!- 2 / 3 * Cos(19 * t!) + 13 / 3 * Cos(20 * t!) - 5 / 4 * Cos(21 * t!)
y!=y!+ 2 / 3 * Cos(22 * t!) + 1 / 4 * Cos(23 * t!) + 5 / 6 * Cos(24 * t!)
y!=y!+ 3 / 4 * Cos(26 * t!) - 1 / 2 * Cos(27 * t!) - 1 / 10 * Cos(28 * t!)
y!=y!- 1 / 3 * Cos(29 * t!) - 1 / 19 * Cos(30 * t!)
Pixel x!/3+160,160-y!/3,&HFFFFFF
Next t!
A dumb question but how do I transfer a basic code listing from this thread from my PC to my PicoCalc (after I’ve copied/pasted/saved to notepad++)? I don’t want to have to type it in directly on the PicoCalc. I’m using the RP2040 and the default software that the PicoCalc ships with. Thanks.
Not a dumb question - the only dumb question is the one that you don’t ask.
Save the program that is in Notepad++ as a .TXT file. Then get out of Notepad++ and rename the file to a .BAS file. Next take the SD card out of the PicoCalc, insert it into your PC and copy the .BAS file to the SD card. Finally place the card back into your PicoCalc. Now you will be able to load it from the “B:” drive and run it.
There are other ways, but this works and is pretty easy to describe.
I used TeraTerm and USB-C cable.