Code:NextBasic Snippets: Difference between revisions
From SpecNext Wiki
No edit summary |
No edit summary |
||
| (14 intermediate revisions by 3 users not shown) | |||
| Line 2: | Line 2: | ||
'''NextBasic Snippets | '''NextBasic Snippets | ||
''' | ''' | ||
A collection of short, specific, commonly used functions usable in a wide variety of software. Snippets should be "side effect" free (no unintended consequences) and, where applicable, contain an explanation of any "Magic numbers" or obscure routines used. | |||
To read a file of any type or size to any bank this will load myfile.bin to bank 22 (8kbs): | To read a file of any type or size to any bank this will load myfile.bin to bank 22 (8kbs): | ||
| Line 13: | Line 15: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
OPEN #4, "myfile" | OPEN #4, "myfile" | ||
DIM #4 TO | DIM #4 TO a | ||
fsize= | fsize=a | ||
CLOSE #4 | CLOSE #4 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 50: | Line 41: | ||
Get the current CORE version | Get the current CORE version | ||
<syntaxhighlight> | <syntaxhighlight> | ||
10 DEFPROC | 10 DEFPROC CoreVersion() | ||
20 | 20 %i=% REG 1: LET m=%i>>4: LET ml=%i&@00001111 | ||
30 | 30 i=% REG 14: LET i= IN 9531: PRINT INK 2;"Current core :";m;".";ml;".";i | ||
40 ENDPROC | 40 ENDPROC | ||
</syntaxhighlight> | |||
Get Next version running | |||
<syntaxhighlight> | |||
.nextver v | |||
print "Current Next OS:";v | |||
if v<2.07 then print "Think about upgrading your distro" | |||
</syntaxhighlight> | |||
Capture the output from a dotcommand | |||
<syntaxhighlight> | |||
10 DIM v$(768) | |||
20 OPEN #2, "v>v$" | |||
30 .http :; this will send the help text to v$ | |||
40 CLOSE #2 | |||
50 PRINT "*";v$;"*" | |||
</syntaxhighlight> | |||
Menu selection with NEXT #0 | |||
<syntaxhighlight> | |||
10 PRINT "Menu Selection" | |||
20 PRINT "1. Stop" | |||
30 PRINT "2. Border 2" | |||
40 NEXT #0 TO k | |||
50 IF k= CODE "1" THEN PRINT "STOP" : STOP | |||
60 IF k= CODE "2" THEN PRINT "BORDER 2" : BORDER 2: STOP | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 01:47, 12 December 2024
NextBasic Snippets
A collection of short, specific, commonly used functions usable in a wide variety of software. Snippets should be "side effect" free (no unintended consequences) and, where applicable, contain an explanation of any "Magic numbers" or obscure routines used.
To read a file of any type or size to any bank this will load myfile.bin to bank 22 (8kbs):
.extract myfile.bin -mb 22To get the filesize of a file in to var fsize:
OPEN #4, "myfile"
DIM #4 TO a
fsize=a
CLOSE #4Scroll screen up without prompt
poke 23692,255: print at 20,0;"Scroll my screen"
for s=1 to 20: print at 21,31;" ": next sSelect a file type to use by browsing the SD
.browse -t pt3 m$
If m$<>"" then .$ playpt3 m$Change the font width to X pixels when printing
10 LAYER 1,1 : CLS
20 PRINT CHR$ 30+CHR$ 5 : REM 5 pixels wide
30 PRINT "HELLO"Get the current CORE version
10 DEFPROC CoreVersion()
20 %i=% REG 1: LET m=%i>>4: LET ml=%i&@00001111
30 i=% REG 14: LET i= IN 9531: PRINT INK 2;"Current core :";m;".";ml;".";i
40 ENDPROCGet Next version running
.nextver v
print "Current Next OS:";v
if v<2.07 then print "Think about upgrading your distro"Capture the output from a dotcommand
10 DIM v$(768)
20 OPEN #2, "v>v$"
30 .http :; this will send the help text to v$
40 CLOSE #2
50 PRINT "*";v$;"*"Menu selection with NEXT #0
10 PRINT "Menu Selection"
20 PRINT "1. Stop"
30 PRINT "2. Border 2"
40 NEXT #0 TO k
50 IF k= CODE "1" THEN PRINT "STOP" : STOP
60 IF k= CODE "2" THEN PRINT "BORDER 2" : BORDER 2: STOP