# BASIC Loader

BASIC .TAP loader

This shows the source for the BASIC .TAP loader for use with the zasm assembler.

To compile run the following commands in a Linux shell to download the sources and compile the loader:

1wget https://area51.dev/sinclair/spectrum/reference/include/zasm/headers.z80
2wget https://area51.dev/sinclair/asm/loaders/tap/loader.z80
3zasm loader.z80

The commands do the following:

1. Download headers.z80 which contains the definitions for the Spectrum BASIC tokens we require.
2. Download loader.z80 which is the source shown below.
3. Compiles our loader generating loader.tap.

The generated loader.tap can now be used with your own .TAP file as long as it loads at address 24000 and its entry point is also at that same address.

All you need to do is concatenate both .TAP files with loader.tap first. The Hello World example shows how this is done.

Links to the required files are shown in the resources panel at the top right of this page.

; *************************************************************************** ; Load a machine code program using the TAP format ; ; Author: Peter Mount, Area51.dev & Contributors ; URL: https://area51.dev/sinclair/asm/loaders/tap/ ; *************************************************************************** ; fill byte is 0x00 ; #code has an additional argument: the sync byte for the block. ; The assembler calculates and appends checksum byte to each segment. ; ; Note: If a segment is appended without an explicit address, ; then the sync byte and the checksum byte of the preceding segment are not ; counted when calculating the start address of this segment. #target tap ; Include Spectrum headers from http://localhost:1313/sinclair/spectrum/reference/include/zasm/headers/ #include "headers.z80" ; *************************************************************************** ; Header block containing the block name and the size of the BASIC program ; *************************************************************************** #code PROG_HEADER,0,17,0 defb 0 ; Indicates a Basic program defb "mloader " ; the block name, 10 bytes long defw variables_end-0 ; length of block = length of basic program plus variables defw 10 ; line number for auto-start, 0x8000 if none defw program_end-0 ; length of the basic program without variables ; *************************************************************************** ; Data block containing a simple BASIC program: ; ; 10 CLEAR 23999 ; Set end of Basic memory ; 20 LOAD "" CODE 24000 ; Load next file to the free memory ; 30 RANDOMIZE USR 24000 ; Execute the loaded code ; ; This will when run mark memory from 24000 (0x5DC0) to be unavailable to ; BASIC and everything above that point is then usable by the machine code ; program who's entry point is address 24000 (0x5DC0). ; *************************************************************************** #code PROG_DATA,0,*,0xff ; 10 CLEAR 23999 defb 0,10 ; line number defb end10-($+1) ; line length defb 0 ; statement number defb BAS_CLEAR ; token CLEAR defm "23999",$0e0000bf5d00 ; number 23999, ascii & internal format end10: defb $0d ; line end marker ; 20 LOAD "" CODE 24000 defb 0,20 ; line number defb end20-($+1) ; line length defb 0 ; statement number defb BAS_LOAD,'"','"',BAS_CODE ; token LOAD, 2 quotes, token CODE defm "24000",$0e0000c05d00 ; number 24000, ascii & internal format end20: defb$0d ; line end marker ; 30 RANDOMIZE USR 24000 defb 0,30 ; line number defb end30-($+1) ; line length defb 0 ; statement number defb BAS_RANDOMIZE, BAS_USR ; token RANDOMIZE, token USR defm "24000",$0e0000c05d00 ; number 24000, ascii & internal format end30: defb \$0d ; line end marker program_end: ; ZX Spectrum Basic variables variables_end: