BASLOAD Usage Examples

Get technical support from the community & developers with specific X16 programs if you can't find the solution elsewhere
(for general non-support related chat about programs please comment directly under the program in the software library)
Post Reply
voidstar
Posts: 445
Joined: Thu Apr 15, 2021 8:05 am

BASLOAD Usage Examples

Post by voidstar »

Here is a video showing usage of BASLOAD with a few examples. These examples are brief program I use when I can't find a lookup table related to keyboard scan-codes or video display codes. Meant to keep the examples simple, since the main point was just demoing the overall workflow of BASLOAD as used in the Commander X16 hardware.

https://www.youtube.com/watch?v=BC8ccp8HrIM

In X16 EDIT, use CTRL+O to OUTPUT (save) your file.

In CMDR-DOS (BASIC prompt), use SHIFT+HOME to clear the screen.

Remember that in CMDR-DOS, it doesn't work based on buffering what you recently just typed. Rather, when you press ENTER, it works by interpreting the whole line that you are currently on. So, if there is a bunch of left over "garbage" on that line (such as from a prior program runtime), you may want to cursor (arrow keys) around to a blank line, or just clear the screen entirely (SHIFT+HOME).



Other references:

BASLOAD manual:
https://github.com/stefan-b-jakobsson/b ... manual.pdf

X16 EDIT manual:
https://github.com/stefan-b-jakobsson/x ... manual.pdf

X16 BASIC Technical Reference (for notes on each of the supported BASIC keywords):
https://github.com/X16Community/x16-doc ... 20BASIC.md


SAMPLE1: This sample queries for a single keypress by the user. If a key is pressed, it shows the corresponding numeric value of that key. Often it is faster to just re-type this program from brain-memory rather than looking up the numeric table of all the keys. This helps for things like the key code for the F1-F10 keys (which aren't in numeric order) or other special keys (like the arrow keys, DEL, etc). You can then use these same codes in a more extensive program later. For example "IF A = 133 THEN ..." (where 133 corresponds to F1, but if you forget that, then this quick program can help verify that). Press the PAUSE/BREAK or CTRL+C key to stop the program and return to the CMDR-DOS BASIC prompt. You can also output the key code in other formats, such as by adding HEX$(A) or CHR$($80);CHR$(A) after the "PRINT A".

Code: Select all

ASK.AGAIN:
GET A$
A = ASC(A$)
IF A <> 0 THEN PRINT A
GOTO ASK.AGAIN

SAMPLE 2: In contrast to keyboard codes, this program shows "screen codes" (or display-codes). As inherited from the original Commodore (CBM) PET, the symbols on the text-mode display use a different set of symbols than the keyboard matrix. There are some benefits to understanding that difference, mainly in that you can generally get better performance by working directly with screen-codes rather than having the System ROM do a translation of character-codes. This sample demonstrates that by exercising the TILE keyword versus the LOCATE and PRINT keywords. You can adjust to different SCREEN modes, just be aware that TILE and LOCATE will give an error if you try to move outside of the current screen resolution. And note that CHR$($80);CHR$(i) is a special provision to print characters "verbatim" (as-is) rather than interpreted (some PETSCII codes are control-codes that get interpreted as special actions, like moving the cursor or changing colors, etc).

Code: Select all

SCREEN 9
COLOR 1,6
CLS

X=2
Y=2

FOR I = 0 TO 255

  TILE X,Y,I

  LOCATE Y+10,X
  PRINT CHR$($80);CHR$(I);

  X=X+1
  IF X > 35 THEN X=2:Y=Y+1

NEXT I


SAMPLE3: This example expands on SAMPLE2, with two additions. First, the BASLOAD features of #SYMFILE, #REM, and #AUTONUM are demonstrated. In general, SYMFILE should always appears first if it is used. SYMFILE is a feature where BASLOAD will write to a file during its parsing a list of all your original variables and labels, and the corresponding X16 BASIC 2-character variables (or the line number of the branch labels). The REM and AUTONUM setting also help preserve much of what your original BASIC program would look like as a regular X16 BASIC listing. Second, the sample program is extended to use the TI variable for simple delta-time management (to show the number of jiffies the main loop of the program uses). You can adjust the program (for example REM or comment out the TILE line) and see the impact to the number of jiffies. Use PAUSE/BREAK or CTRL+C to end the program and return back to CMDR-DOS BASIC prompt.

Code: Select all

#SYMFILE "@:SAMPLE3.SYM"
#REM 1
#AUTONUM 10

SCREEN 9 : REM SET SCREEN RESOLUTION

GO.AGAIN:
X=2
Y=2
START.TIME=TI
FOR I = 0 TO 255

  TILE X,Y,I

  LOCATE Y+10,X
  PRINT CHR$($80);CHR$(I);

  X=X+1
  IF X > 35 THEN X=2:Y=Y+1

NEXT I

FOR I = 1 TO 38:TILE I,21,160
LOCATE 22,1:PRINT TI-START.TIME
GOTO GO.AGAIN

SAMPLE 4: In addition to keyboard codes and screen codes, another table that I often forget is the color-chart. This sample produces that table, using both the COLOR keyword and also the 4th argument on the TILE command, just to demonstrate those alternative ways of controlling the color of content on the text-mode screen. This sample also shows how nested-loops are possible in BASIC.

Code: Select all

COLOR 1,6
SCREEN 1

FOR BG = 0 TO 15
  FOR FG = 0 TO 15

    COLOR FG,BG
    LOCATE BG+2,FG*4+2
    PRINT HEX$(FG*16+BG);

    TILE FG*4+2+1,BG+2-1,160,FG*16+BG

  NEXT FG
NEXT BG

COLOR 1,6
LOCATE 20,1
Last edited by voidstar on Tue Jul 23, 2024 6:26 am, edited 7 times in total.
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD Usage Examples

Post by Stefan »

Great video showing off how to use X16 Edit and BASLOAD!
voidstar
Posts: 445
Joined: Thu Apr 15, 2021 8:05 am

Re: BASLOAD Usage Examples

Post by voidstar »

Thanks, I've wanted to do a proper tutorial on it for many months now, but still can't get the time to setup for a full narrated walk-through. So, I've left this one as Unlisted for now - as I think a brief example like this might help some folks get started in the right direction.

I did use the CTRL+F (toolbox) but forgot to include that in the video. I don't think it is really described in the X16 EDIT manual? But for others here, to summarize that:

You can do CTRL+F in EDIT, then press B to "activate" (or invoke) ROM BASLOAD. The file has to be saved, so that it knows what file parameter to pass to BASLOAD. The status will just say "SUCCESS", which means that if you then exit EDIT and do LIST - your BASLOAD program will be tokenized within the memory used by X16 BASIC (as if you had run BASLOAD yourself). This is a good way to make sure your BASLOAD text is at least syntax-valid (by the status of SUCCESS coming back, or else the error {and line number!} get returned and displayed in EDIT). Slick integration of these two features :D


And someday, integrating something like an on-system ROM assembler in this way would be a great addition! That was the plan for calling it a toolbox, to expand the integration to multiple on-system dev environments.

My only tiny nit is I wish TOOLBOX was CTRL+T or CTRL+B instead of CTRL+F haha :D Or, if I'm in TOOLBOX (after CTRL+F), if I could do CTRL+B in addition to B (this way I can just hold CTRL at the corner and then quickly mash F+B without lifting CTRL - I know, it's a small thing, but it'd save at least 20 jiffies :) ).
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD Usage Examples

Post by Stefan »

I’ll see if I can fix those things in the editor.
Post Reply