ZX Spectrum BASIC Code
This is less of a tutorial to learn to program in BASIC. I hope to collect some clippings of code here as crib sheets or demonstrations of implementation techniques. These code crib sheets are intended to enable quick implementations of programs more specific to your needs. The listings will be on this page as some people still enjoy "type-ins", but I will provide TAP/DSK files too.
Most of the code will be Licensed under GNU GPL v3.0. Hopefully, this will encourage developments and improvements to be shared openly without being converted to proprietary code. The outset of the licensing style is that source code is shared along with any binaries this license also applies to derived works.
Most of the code will be Licensed under GNU GPL v3.0. Hopefully, this will encourage developments and improvements to be shared openly without being converted to proprietary code. The outset of the licensing style is that source code is shared along with any binaries this license also applies to derived works.
9-Iron Tool kit
|
|
9 item MENU - 9iMIntended for loading other programs from the same storage device. The menu system wraps a call to LOAD "FILENAME.XXX". To load machine code programs, a separate BASIC load is still needed. It is possible to connect multiple 9iM basic programs to create a series of menus/submenus. Traversing between 9iM menus invokes a LOAD, losing data in memory and incurring loading delays.
Using 9iM to build a menu The process involves editing the Arrays section, then saving out a copy of the BASIC with SAVE "name.9im" LINE 1. There are 3 subroutines for performing the file save work (explained later). Edit the following Arrays by inserting the required information between the "" on each line. Line 45 c$ is the name of the menu. Shown on screen and is used to name the file so limited to 8 characters. (Does not require file extension this is added by the SAVE call) Lines 50 - 60 a$ these array elements used for the menu labels. They are set to 20 characters initially. The array length changes affect the screen layout, so be careful if you do. Lines 70 - 80 b$ used for the actual filenames to load. Remember these files are expected to be on the same storage device (Drive letter). You specify the files in their full 8.3 formats. These 3 arrays configure the menu. The Arrays a$ and b$ contain 10 items, not 9. The thought was that 9 items would be available, and the 10th could be used to load a further menu or exit program. It is possible to use all 10 menu positions to load 10 other menus, mooting the design decision. The final step is to save the edited BASIC code to the file system. You could do this with SAVE "filename.xxx" line 1 manually. Alternatively, use one of the 3 subroutines provided to ensure accuracy. They can be run using a GOTO call with the line number. It is worth checking the default storage device is selected as expected, do this with LOAD "A:" (or another letter). Line 9501 this is intended to save a version of the BASIC when working on the template code. It saves a file to the currently selected storage device as SAVE "9IM_V#.bas". # replaced with the version number stored on line 9401 (Version subroutine). Line 9511 creates a self-executing copy of the BASIC as a menu. Using the value in c$ for the filename and prefixing .9im. The method to use when not loading the created menu on boot. Line 9521 save the BASIC as a self-executing DISK file. With +3DOS the Spectrum Loader menu checks a disk for a "DISK" file and executes it automatically. You can only have one of these on a disk! Use this option for creating a master menu for a disk. Should you accidentally save over a DISK file, check for DISK.BAK the previous version. COPY "DISK.BAK" TO "DISK" to recover your original file. |
9iM Listing
|
9 item BASIC - 9iB9iB (9 item BASIC), for creating a menu for short BASIC programs stored in the menu program. 9iB is aimed to provide a fast scratchpad for housing routines with a menu. The program borrows heavily from the concepts used in 9iM, replacing the LOAD with GO SUB calls. Each subroutine has 498 lines available. Link to the menu with a GO SUB and marked out with a REM and RETURN. Place you BASIC code between the REM and RETURN pair with a label in a$. Subroutines are provided to save out the code quickly and easily. 9iB is intended for programs which are too small for efficient use of a 9iM entry. Conversely is 498 lines isn't enough for the code, you should probably consider 9iM menu to load the code or have the subroutine load the program. Using GOTO or GOSUB to expand the code into other line numbers is also possible.
To create a 9iB menu, configure the Arrays. Line 45 c$ is the name of the menu. Shown on screen and is used to name the file so limited to 8 characters. (Does not require file extension) Lines 50 - 59 a$(1 to 9) these array elements are the menu labels. They are set to 20 characters initially. Changes to the array size affect the screen layout (be careful!). Line 65 a$(10) is a unique array element as its setup as a LOAD. By default, it is set up to "exit" by loading the DISK file. Use this entry to attach another 9iB menu or 9iM menu. Line 75 b$ is the file name loaded when the 10th (exit) item is selected. Once the arrays have been configured add in your code for each GO SUB. The Call table at line 510 maps the array items to the allocated code blocks. Items selected in the menu call the relevant code block with a GOSUB call and end with a RETURN. Upon returning the menu program is re-run from LINE 1, resetting the arrays and re-drawing the screen. If your code is outputting results to the screen, consider a PAUSE before the RETURN call. Your code is sharing resources with the master template, DO NOT USE a$ b$ c$ k$! There is no memory protection; it is not an operating system! It is possible to pass data between subroutines; it is just a single program. You may find this a useful feature or deeply infuriating when it happens unexpectedly. Line 9501 this is intended to save a version of the BASIC when working on the template code. Thus it saves a file to the currently selected storage device as SAVE "9IB_V#.bas". # is replaced using number stored on line 9401 (Version subroutine). Line 9511 creates a self-executing copy of the BASIC as a menu. c$ is the filename and prefixed with .9ib. It is used to create menus that you plan to load from somewhere else. Line 9521 save the BASIC as a self-executing DISK file. With +3DOS the Spectrum Loader menu checks a disk for a DISK file and execute it automatically. You can only have one of these on a disk! Use to make the master menu on a disk. Should you accidentally over save a DISK file, check for DISK.BAK the previous version. You can COPY "DISK.BAK" TO "DISK" to recover your original file. |
9iB Listing
|