How to add a basic program to a TAP file.

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
MustardTiger
Microbot
Posts: 122
Joined: Tue May 02, 2023 8:05 pm

How to add a basic program to a TAP file.

Post by MustardTiger »

I'm using sjasmplus to write some assembler programs and saving binary code and screens is straight forward in sjasmplus. The docs also state you can write a BAS file to the TAP file but I don't understand how to create the basic code in my asm files. I just need a simple BAS file to load the screen, bins and rand usr to start the mcode.

Does it need to be the raw binary data that represents the basic tokens etc in DB instructions? The only way I can see of getting that data is to write BASIC on a speccy and save to a TAP file, then extract the binary data with a hex editor or python script. Seems like a lot of hassle, wondering if there's an easier way?
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: How to add a basic program to a TAP file.

Post by ParadigmShifter »

I use this but I would like a better way too, since the CLEAR address is hard coded (in 2 places, the actual number is the 5 byte float following the string "32767", the string doesn't get used by the interpreter, can be anything), and it takes up space in the ASM (although I don't save actually save the basic code at the end). So it only works with ORGADDR 32768 atm.

It is useful in that you don't need to use a batch file or any tap editing utility as an extra step though, so it's handy for rapid development.
If you want a LOAD "" SCREEN$ you have to find out what the tokens are and add that though :/

Code: Select all

ORGADDR EQU 32768
        ORG ORGADDR
        
main:
        
        ; code and data

	DEVICE ZXSPECTRUM48

CODE_AND_DATA_LEN EQU $-ORGADDR

	DISPLAY "Code and data total length: ", /D, CODE_AND_DATA_LEN

basic_loader:
  db $00,$0a,$0e,$00,$20,$fd,"32767",$0e,$00,$00,$ff,$7f,$00,$0d     ; 10 CLEAR 32767
  db $00,$14,$07,$00,$20,$ef,$22,$22,$20,$af,$0d                     ; 20 LOAD "" CODE
  db $00,$1e,$0f,$00,$20,$f9,$c0,"32768",$0e,$00,$00,$00,$80,$00,$0d ; 30 RANDOMIZE USR 32768
basic_loader_end:

    EMPTYTAP "output.tap"
	SAVETAP "output.tap", BASIC, "WooWooGame", basic_loader, basic_loader_end - basic_loader, 10
    SAVETAP "output.tap", CODE, "WooWooCode", main, CODE_AND_DATA_LEN
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: How to add a basic program to a TAP file.

Post by catmeows »

Are you aware of the fact that tap files can be concated ?
Proud owner of Didaktik M
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: How to add a basic program to a TAP file.

Post by ParadigmShifter »

I know there is a util to do that but I couldn't find a way to do that in sjasmplus or using the TAP browser in Spin, I am looking for a better way though.

OP is also using sjasmplus.
User avatar
MustardTiger
Microbot
Posts: 122
Joined: Tue May 02, 2023 8:05 pm

Re: How to add a basic program to a TAP file.

Post by MustardTiger »

Thanks for the example code. I can see what values I need to copy from memory into the DB statements now.

I just did a test, wrote my basic in ZX Spin and used the memory debugger to find the bytes. Made a test TAP file and it works perfectly.

:D

Code: Select all

loaderstart
	db $00,$0a,$0d,$00,$fd,$33,$32,$37,$36,$37,$0e,$00,$00,$ff,$7f,$00,$0d		;10 CLEAR 32767
	db $00,$14,$05,$00,$ef,$22,$22,$aa,$0d						;20 LOAD "" SCREEN$
	db $00,$1e,$05,$00,$ef,$22,$22,$af,$0d						;30 LOAD "" CODE
	db $00,$28,$0e,$00,$f9,$c0,$34,$30,$39,$36,$30,$0e,$00,$00,$00,$a0,$00,$0d	;40 RANDOMIZE USR 40960
loaderend
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: How to add a basic program to a TAP file.

Post by ParadigmShifter »

What sysvar do you peek to find the address of the basic program? What is it terminated by or does it have a length somewhere?

I don't mind putting the basic tokens in the code since I can easily put it in a buffer which will be overwritten at runtime so the extra space is not an issue really.
User avatar
+3code
Manic Miner
Posts: 434
Joined: Sat Mar 19, 2022 7:40 am

Re: How to add a basic program to a TAP file.

Post by +3code »

As catmeows has said, you can go to the CMD and type:
copy /b tape1.tap + tape2.tap mytape.tap
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: How to add a basic program to a TAP file.

Post by ParadigmShifter »

Oh right that's pretty simple lol ;)

Still probably needs a batch file (which I should use I guess) :)

EDIT: That method is probably the best then since you can provide a variety of basic loaders and use different options/commands/batch files to build various tap files (so 1 that doesn't have a screen$ for faster loading/development testing) and one which does.

Is there an easy way to set the baud rate on a TAP file without a utility (since Alessandro Grusso's turboloaders only provide a load routine rather than a save routine)?
User avatar
MustardTiger
Microbot
Posts: 122
Joined: Tue May 02, 2023 8:05 pm

Re: How to add a basic program to a TAP file.

Post by MustardTiger »

ParadigmShifter wrote: Thu Dec 07, 2023 6:55 pm What sysvar do you peek to find the address of the basic program? What is it terminated by or does it have a length somewhere?

I don't mind putting the basic tokens in the code since I can easily put it in a buffer which will be overwritten at runtime so the extra space is not an issue really.
Oh, my method was not scientific at all. I just looked at the memory around 5b00 and above for the 00 0a for the 10 of the first line and copied until the 0d on the last line, given that's the data you had in your example.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: How to add a basic program to a TAP file.

Post by catmeows »

+3code wrote: Thu Dec 07, 2023 6:56 pm As catmeows has said, you can go to the CMD and type:
copy /b tape1.tap + tape2.tap mytape.tap
Right, sorry, I was typing from phone so I kept it short.
Proud owner of Didaktik M
User avatar
patters
Manic Miner
Posts: 471
Joined: Thu Apr 11, 2019 1:06 am

Re: How to add a basic program to a TAP file.

Post by patters »

https://github.com/patters-match/artill ... ake_tap.sh

This is how I built the loader and loading screen for my game - might be useful for someone. Took me a lot of trial and error to get working smoothly.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: How to add a basic program to a TAP file.

Post by Jbizzel »

Basin has a really good tape editor. It's what I use to edit and build tap files.
Post Reply