Change multipart game to load from disk rather than tape.

Basic and Machine Language

Moderator: Moderators

User avatar
Mayhem
High Bidder
Posts: 3027
Joined: Mon May 24, 2004 7:03 am
Website: http://www.mayhem64.co.uk
Location: London

Re: Change multipart game to load from disk rather than tape

Post by Mayhem »

POKE 632,131 you mean? As Tokra noted above, it's the equivalent of Shift Run/Stop.
Lie with passion and be forever damned...
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: Change multipart game to load from disk rather than tape

Post by vicist »

It looks ok.

I think you have understood that it is similar to make this work like 'crazy climber'.
You have applied the same logic and therefore it should work.

tokra has already explained what the pokes do earlier in this thread.

I recommend that you download a copy of the Vic-20 programmers reference guide from Bombjack's excellent repository of Commodore material.

http://www.bombjack.org/commodore/commo ... inting.pdf
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Change multipart game to load from disk rather than tape

Post by Mike »

Last question first. ;)
Dr-D wrote:Is there a website somewhere that'll tell me what the different POKE commands do?
When it comes to a good place to ask questions about the VIC-20 and get answers, you're most probably alread at the right place here. :)

Before the 'net, we all had to learn from either doing (I'll come to this soon) or reading a good book about the topic. In the latter case, you'll find DLH's Commodore Archive being the source of all good bits.
It seems to be working but is it actually right? What does POKE631,131 do?
It's a Good Thing™ to avoid Cargo Cult. :mrgreen:

A good measure of the first principle ("doing"), is to strip the code off everything that doesn't seem to be directly related to the function in question, until a minimal 'working' program is produced. In our case, that'd be:

Code: Select all

1 PRINT"{CLR}";:POKE631,19:POKE632,131:POKE198,2
... with {CLR} meaning to hold Shift and press HOME, which within quotes shows an inverse heart and when executed will CLeaR the screen.

This program will print "LOAD" in the top-left corner, followed by "PRESS PLAY ON TAPE". If you then load any program from tape, it will be automatically started by a "RUN" command.

You won't have to type in these commands by yourself. "Somehow", they are stored. Stored in something which is called "keyboard buffer". This keyboard buffer normally takes care of keypresses, which could not immediately processed by the running program. In our case though, we do something different: we pre-fill the keyboard buffer with something not really typed in. But nonetheless, the editor behaves as if some keys actually *had* been pressed during the program execution. The program itself didn't "use" them, instead they come into effect as soon as the program exits into direct mode.

The keyboard buffer is located in the 10 addresses from 631 to 640, and the number of stored keypresses is stored in address 198. This is for example information which could be gathered from any of those books alongside "Inside the VIC-20" or the like. POKE198,2 means there are two stored keypresses in the buffer.

The first key code is 19. This is the code for {HOME} which sends the cursor to the top-left corner but doesn't clear the screen.

The second key code is 131. Now this is a special case. It corresponds to the shifted action of the STOP key. The top line of the STOP key reads - RUN. In case of the VIC-20, this actually means: load the next program from tape and automatically run it. Other CBMs possibly load the first program from disk. When the editor finds this code in the buffer, it automatically expands it to 'type' LOAD [RETURN] RUN [RETURN], which leads exactly to the action described above.

Now for the end of this slightly longer story. To make this work with a disk drive on #8, you'll have to fabricate a load with file name and 8 as device address. PRINT"{CLR}" therefore is replaced with:

Code: Select all

PRINT"{CLR}LOAD"CHR$(34)"<name of part 2>"CHR$(34)",8"
... where those CHR$(34)s print the quotes around the file name, so the LOAD command appears with the correct syntax on screen. The "LOAD" within the PRINT command can be replaced by four spaces, as the key code 131 will later put LOAD there on the screen by itself. Leaving it as is does do no harm though (the original "LOAD" will just be overtyped) and should make it clearer what this PRINT is for.

This time, when the program exits to direct mode, it will again print "READY." on screen. Then the key code 19 will put the cursor in the top-left position, right where the "L" (or the first space) of the printed command is placed. After printing LOAD the cursor is over the first quote.

When now [RETURN] is pressed on your behalf it doesn't matter that the command on screen wasn't typed in by you, rather just its presence on screen is what counts. The complete line is sent to the interpreter and executed - and loads the named program from disk.

Finally, RUN is typed for you and executed and starts the loaded program.

Oh, and welcome to Denial! :D

Michael
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

I've got 4 of the 6 games loading and running correctly from disk now by adding the file name search string and adjusting the POKE commands. I can't get DEFENDER or PSYCHO SHOPPER working. With PSYCHO SHOPPER when I load the second file and try to save it to either tape or disk it gives me an OUT OF MEMORY error. It requires an 8K expander and I get the ?OUT OF MEMORY ERROR with both an 8K and 16K memory expander. Is this some type of copy protection feature that is preventing me from saving it?

Here is the code for DEFENDER:

Code: Select all

20 READZ:IFZ<0THEN1000
30 FORI=ZTOZ+7:READD:POKEI,D:NEXTI
40 GOTO 20
1000 POKE198,5:POKE631,131
Lines 50 - 72 are all DATA statements
Last edited by Dr-D on Tue Feb 24, 2015 3:57 pm, edited 1 time in total.
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

Mayhem wrote:POKE 632,131 you mean? As Tokra noted above, it's the equivalent of Shift Run/Stop.
Nope, the DEFENDER program has POKE 631,131 which is why I asked because it wasn't 632,131.
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Change multipart game to load from disk rather than tape

Post by Mike »

With POKE631,131 only the RUN action is performed. By itself, and for tape, it works without issues when it is executed in the line after the "READY." prompt. Though, POKE198,5 *has* a Cargo Cult smell, and executes 4 undefines key presses after code 131.

In your listing of DEFENDER, the semicolon after "Z+7" is a typo?

When the second part of DEFENDER fills up the entire RAM, there is not any place anymore to store the file name at the end of memory when the SAVE command of BASIC is used. With files in machine language, the commands LOAD and SAVE of BASIC cannot sensibly be used to copy them (the LOAD command can 'corrupt' the loaded data as the BASIC line re-linker is executed, and SAVE bails out when the loaded data straddles the boundaries of the RAM range allocated for BASIC programs).

Please type in this line after you have loaded the second part, and report the result:

Code: Select all

PRINTPEEK(45)+256*PEEK(46)
Also, do you actually get a BASIC listing when you LIST the second part?
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

Yes it was a typo. I fixed it.
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

Mike wrote:With POKE631,131 only the RUN action is performed. By itself, and for tape, it works without issues when it is executed in the line after the "READY." prompt. Though, POKE198,5 *has* a Cargo Cult smell, and executes 4 undefines key presses after code 131.

In your listing of DEFENDER, the semicolon after "Z+7" is a typo?

When the second part of DEFENDER fills up the entire RAM, there is not any place anymore to store the file name at the end of memory when the SAVE command of BASIC is used. With files in machine language, the commands LOAD and SAVE of BASIC cannot sensibly be used to copy them (the LOAD command can 'corrupt' the loaded data as the BASIC line re-linker is executed, and SAVE bails out when the loaded data straddles the boundaries of the RAM range allocated for BASIC programs).

Please type in this line after you have loaded the second part, and report the result:

Code: Select all

PRINTPEEK(45)+256*PEEK(46)
Also, do you actually get a BASIC listing when you LIST the second part?
Yes I get the BASIC listing.

Result for 1st part: 4602
Result for 2nd part: 61 6144
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

The game doesn't even appear to work anyway. I just loaded it from the tape and the game screen comes up and but there is no response from any key or the joystick and once the timer runs out it tells you to press fire on the joystick to play again but it doesn't do anything. I know the joystick and the fire buttons work as it works on all the other games that make use of the joystick.
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

I removed lines 20, 30 and 40 and got it to load the second part of Defender from the disk after adding line 500 and changing line 1000.
REMOVED

Code: Select all

20 READZ:IFZ<0THEN1000
30 FORI=ZTOZ+7:READD:POKEI,D:NEXTI
40 GOTO 20
ADDED

Code: Select all

500 PRINT"{CLR}    "CHR$(34)"DEFENDER"CHR$(34)",8"
CHANGED 1000 POKE198,5:POKE631,131 TO

Code: Select all

1000 POKE631,19:POKE632,131:POKE198,2
Now I mentioned in my original post that I'm not a programmer and I'm not one by occupation but I actually did used to tinker around with my VIC-20 making simple little programs and I did take a programming course in 1994 and learned BASIC, Visual BASIC and C/C++. What I learned from than course more than anything was the interaction of software with hardware and that I don't have the patience to be a programmer although I have made a few simple ones. That being said lines 20, 30 and 40 look completely useless to me and I can't see any conceivable purpose for them. If there is a purpose hopefully someone can explain it to me. The first line of the program is 20 so there's nothing before that. So I accomplished getting the program to load from disk but once it's loaded you can't actually do anything with it, lol.
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: Change multipart game to load from disk rather than tape

Post by vicist »

Code: Select all

20 READZ:IFZ<0THEN1000
30 FORI=ZTOZ+7:READD:POKEI,D:NEXTI
40 GOTO 20
This is a loop that reads in the data from the data statements in lines 50 - 72.

Line 20 reads the address where the data should go.
Line 30 pokes the data into the address found in line 20 (chunks of 8 so likely user graphics).
Line 40 restarts the loop to get the next address. If the data read is less than 0, then it branches off to line 1000 where it loads the next part.
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

Thanks for the explanation. When I removed lines 20, 30 and 40 from the program it didn't appear to make any difference at all when I ran the program, it does exactly the same thing with or without those lines. If I load and run the second part of the program by itself then the graphics aren't there so those DATA statements are obviously graphics as you mentioned. So after adding line 500, changing line 1000 and changing line 20 to point to line 500 it loads from the disk the way it should. Now if I can find the time and patience I'll poke around the code of the second part and see if I can't make the program actually do something which I can only assume was the original intention.
vicist wrote:

Code: Select all

20 READZ:IFZ<0THEN1000
30 FORI=ZTOZ+7:READD:POKEI,D:NEXTI
40 GOTO 20
This is a loop that reads in the data from the data statements in lines 50 - 72.

Line 20 reads the address where the data should go.
Line 30 pokes the data into the address found in line 20 (chunks of 8 so likely user graphics).
Line 40 restarts the loop to get the next address. If the data read is less than 0, then it branches off to line 1000 where it loads the next part.
Dr-D
Vic 20 Drifter
Posts: 29
Joined: Wed Feb 18, 2015 12:34 pm

Re: Change multipart game to load from disk rather than tape

Post by Dr-D »

Is there any way to get the files off a VIC-20 floppy onto a Windows or Linux PC? Some kinda of an adapter to hookup and read the 1541 drive? Are the VIC-20 files just plain ASCII files or binary format?
wimoos
Vic 20 Afficionado
Posts: 346
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Change multipart game to load from disk rather than tape

Post by wimoos »

In my setup I use 64HDD. You need a special XA1541 cable to connect the VIC to the (DB25) parallel port of a PC.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: Change multipart game to load from disk rather than tape

Post by vicist »

I guessed as much right from the start of this thread that you are in the position I was in when I joined this forum a few years ago. I had a Vic, tape deck, disk drive, and a bunch of tapes and carts. Back in the 80's I was transferring my tapes to disk in much the same way as you are trying to do now.

Nowadays, there are easier ways of doing this.

I recommend you start by looking up a device called sd2iec.

This is, in effect, a tiny disk drive that uses a sd card as the media instead of a floppy.
Most of the tapes you want to transfer to disk are already on the internet in one form or another. You can download these files (.prg ) to the sd card, plug it into the sd2iec device, connect this to your vic and almost all the games ever written for the vic are at your fingertips.
If you have written any programs yourself that you would like to preserve, just daisychain the device with your real 1541 and copy the files direct to your sd card. :)

There are several variations of this device so look around this forum to get an idea of what's available.
Last edited by vicist on Fri Feb 27, 2015 3:28 am, edited 1 time in total.
Post Reply