Loader

Basic and Machine Language

Moderator: Moderators

Post Reply
edinky
Vic 20 Newbie
Posts: 18
Joined: Sat Apr 07, 2018 10:34 am

Loader

Post by edinky »

I've made a game for the vic 20 "stardrifter"

it runs fine, but i need to work out how to load it properly.

at the moment i have 3 programs.

sd.prg - pokes a character set and prints a screen to display a title screen. then loads "data.prg"

data.prg - pokes the game character set and some assembly in memory. then loads "game.prg"

game.prg - actual game.

i created a .d64 to hold these three programs and emulated a disc drive with a SD2IEC.
when using vic i had to type

Code: Select all

poke 44,28:new
to work with alternative character set. this didn't work on the real vic, so i found something online that works, which i'm inputting first:

Code: Select all

poke43,0:poke44,24:poke6143,0:new
i then load the first prg:

Code: Select all

load"sd.prg",8
the first prg runs fine, but runs into problems after loading "data.prg" - which seem like memory overwrite sort of errors. i'm trying to figure out why, and found that i might need to move the end of variable pointers at the beginning of the loaded program.

Code: Select all

POKE 45,PEEK(174):POKE 46,PEEK(175)
this however doesn't seem to work and results in a slightly different error state. the program loads ok, but the run command gives me a "syntax error"

would anyone have any tips on how to run these programs after each other?

i'm testing using vic 20 with penultimate+ cartidge at 24kb expanded.

i've attached my .bas files and the d64 with built prgs.

if anyone can help i would appreciate a lot, i know members of community have helped me before which was brilliant.

also, i was thinking that i'd love to have the game on tape, with the reverse side of the tape music to be played during gameplay in a regular stereo. for one, i was thinking how do go about saving something like this on tape? i know there are .tap files, but is there a prgs to tap convertor? i havnt found any.
Attachments
SDOutput.zip
(10.58 KiB) Downloaded 26 times
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Loader

Post by srowe »

edinky wrote: Mon Jul 12, 2021 7:21 am also, i was thinking that i'd love to have the game on tape, with the reverse side of the tape music to be played during gameplay in a regular stereo. for one, i was thinking how do go about saving something like this on tape? i know there are .tap files, but is there a prgs to tap convertor? i havnt found any.
You can do this sort of operation with my CBM Shell

https://pypi.org/project/cbmshell/

Code: Select all

attach stardrifter.tap
copy sd.prg 0:SD
copy data.prg 0:DATA
copy game.prg 0:GAME
quit
edinky
Vic 20 Newbie
Posts: 18
Joined: Sat Apr 07, 2018 10:34 am

Re: Loader

Post by edinky »

this looks great. and to put to an actual cassette, do i play the tap file out of my computer and into a tape recorder?
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Loader

Post by chysn »

The chain LOAD is apparently kinda flaky because it doesn't properly set pointers, and is especially problematic when you're moving from a shorter program to a longer one.

There are a couple solutions proposed here viewtopic.php?f=2&t=10085. For tape, if you simply need to load the next program from tape, you can end your program with this (instead of LOAD):

Code: Select all

POKE631,131:POKE198,1
This puts SHIFT+RUN into the keyboard buffer, then sets the keyboard buffer length to 1, which is flushed once the program ends.

If you're loading from disk, on that same thread tokra suggests this:

Code: Select all

990?"{CLR}LOAD"CHR$(34)"PRGNAME"CHR(34)","PEEK(186)
991POKE631,19:POKE632,131:POKE198,2
which prints the LOAD command onto the screen, then puts HOME and SHIFT+RUN into the keyboard buffer.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Loader

Post by Mike »

edinky wrote:[...] i found something online that works, which i'm inputting first:

Code: Select all

poke43,0:poke44,24:poke6143,0:new
If you move the BASIC start by changing the pointer in 43/44 you'll have to put a 0 into the location before that.

The example does that correctly, but normally you'd choose $xx01 for the BASIC start address, so the 0 byte ends up at $xx00. Putting the 0 byte at somewhere $xxFF possibly blocks end of the xx page for any other data.
i then load the first prg:

Code: Select all

load"sd.prg",8
the first prg runs fine, but runs into problems after loading "data.prg" - which seem like memory overwrite sort of errors. i'm trying to figure out why, and found that i might need to move the end of variable pointers at the beginning of the loaded program.
Issuing LOAD from within a program has the semantics that the chained to program still is supposed to have access to the variables of the former program. The start of variables (a.k.a. "end of program") pointer is not altered. If the chained to program is bigger, the original variables are partly overwritten and the BASIC interpreter operates on a destroyed variable space and this can induce all kinds of undefined behaviour.

If access to the old variable values is not important (which is quite likely the case), there are several methods to chain to the next program without aforementioned issue. Most of them use printed LOAD and RUN prompts on screen and simulated entry of those by exercising stored keypresses in the keyboard buffer. Alternatively you can use this method to set 45/46 in the first executed line of the chained-to program ...

Code: Select all

POKE 45,PEEK(174):POKE 46,PEEK(175)
this however doesn't seem to work and results in a slightly different error state. the program loads ok, but the run command gives me a "syntax error"
... and if you add a CLR, this works. CLR is necessary to re-adjust other pointers as well that relate to the variable space.
would anyone have any tips on how to run these programs after each other?
Other than that, a good look at the threads "VIC-20 Memory Layout", "RAM...what to get?" and "How to reinit 16k expansion?" is wholeheartedly recommended.

You might consider to one-file your program, so it contains the character set(s) already at place, without the need to read them off DATA lines. Then the thread "Load Charset Direct to Correct Memory Location" might be of interest.

Greetings,

Michael
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Loader

Post by srowe »

edinky wrote: Mon Jul 12, 2021 8:08 am this looks great. and to put to an actual cassette, do i play the tap file out of my computer and into a tape recorder?
I think there are several options but this is probably the most reliable

https://www.ebay.co.uk/itm/133646857375 ... SwfXhcxE-8
Vic20-Ian
Vic 20 Scientist
Posts: 1214
Joined: Sun Aug 24, 2008 1:58 pm

Re: Loader

Post by Vic20-Ian »

srowe wrote: Mon Jul 12, 2021 8:47 am
edinky wrote: Mon Jul 12, 2021 8:08 am this looks great. and to put to an actual cassette, do i play the tap file out of my computer and into a tape recorder?
I think there are several options but this is probably the most reliable

https://www.ebay.co.uk/itm/133646857375 ... SwfXhcxE-8
I have Remzi's USB gadgets - they work very well.
Vic20-Ian

The best things in life are Vic-20

Upgrade all new gadgets and mobiles to 3583 Bytes Free today! Ready
edinky
Vic 20 Newbie
Posts: 18
Joined: Sat Apr 07, 2018 10:34 am

Re: Loader

Post by edinky »

greetings and thanks for the help everyone!

i tried pushing the load and run commands into the keybuffer, and this loaded the next prg but i still had memory problems.

i also moved the EOP pointers and added the CLR, but still got errors.

however, when i did this:
If you move the BASIC start by changing the pointer in 43/44 you'll have to put a 0 into the location before that.

The example does that correctly, but normally you'd choose $xx01 for the BASIC start address, so the 0 byte ends up at $xx00. Putting the 0 byte at somewhere $xxFF possibly blocks end of the xx page for any other data.
it worked! i wouldnt have ever thought that was it, thanks a million!

i think thats the final technical leap i had to make in order to finish the game, on the final lap now!
Post Reply