Editing a .PRG file

Modding and Technical Issues

Moderator: Moderators

Post Reply
GameOn
Vic 20 Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:58 am
Location: Oslo, Norway

Editing a .PRG file

Post by GameOn »

I have a real Vic 20 (both NTSC and PAL) which I do use in an video game exhibition so we can show off games on real hardware. It has an SD2IEC attached to make loading of game (currently one) easier.

We show off Matrix as it is probably the best game on the system and one of the best and original shoot em ups from the early 80s.

However matrix has the "feature" of being able to adjust the screen using the joystick, however this does mean that it is too easy to have a messed up screen which requires trying to die several times before it can be fixed and a few visitors think the game is faulty...

Using the vice monitor I looked up memory that accessed the joystick ports, then backtracked to find the routine entry point so I could find out the routine that accessed it. Thankfully there were only two and found the screen shift routine at $3963 and by looking at it, it was easy to do a JMP $3985 and have three pokes to disable the routine.

Loaded the game, added the pokes and the screen remained static. Normally to load the game I use

1OPEN1,8,15,"CD:MATRIX.PRG":CLOSE1:LOAD"*",8:RUN
RUN

And it goes off and loads the game and then runs it, I was hoping putting the pokes after the load would make it work but it doesn't do the pokes.

So my question is, is there a piece of software or something I can do on the Vic 20 itself so I can edit those three locations and then save the PRG file again so I can make the game static? I have looked at diskmaster and D64 editor the like and although I can view the file there doesn't seem to be an easy way to edit them.
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Re: Editing a .PRG file

Post by Boray »

You have a directory that is called matrix.prg? That's a bit strange.

You should be able to do this:

load "game",8

do the pokes

save "altered game",8

and next time, just

load "altered game",8

instead.
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
eslapion
ultimate expander
Posts: 5037
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Re: Editing a .PRG file

Post by eslapion »

@GameOn
What I don't understand is why you try to modify a file you placed on your SD2IEC using a PC on the Commodore side.

Just open the D64 with DirMaster, export the file to be modified then use any PC binary editor (I use WinHEX) then re-import the file in the D64.

If you absolutely want to do the mod on the VIC-20 side, the right tool is VICMON or HESMON.
Be normal.
User avatar
Mike
Herr VC
Posts: 5131
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Editing a .PRG file

Post by Mike »

GameOn wrote:

Code: Select all

1OPEN1,8,15,"CD:MATRIX.PRG":CLOSE1:LOAD"*",8:RUN
RUN
That's most probably one of the more whacked incantations to start up a game that I've seen in the later time.

Either "matrix.prg" actually *is* a *.d64 with wrong extension, or it is really only that executable. In the latter case, the LOAD command only happens to work by chance, because the file is located as first file in the directory (and the CD command being ignored).

Furthermore, after the LOAD command the instruction flow is interrupted, both in direct mode and program mode: in direct mode, LOAD ignores everything that was written after it, clears the variables, sets the pointer to the start of variables (a.k.a. "end of program"), and finally puts you into the READY prompt. In program mode, the interpreter restarts execution from the start of the (newly loaded!) program (again ignoring what was written after the LOAD command), but does *not* set the pointer to the start of variables, and does *not* clear the variables.

If the program loaded with that construction is longer than the one that loaded it, the start of variables will be located within the program's body, confusing or crashing the BASIC interpreter as soon as a variable is being searched. It just happens to "work" here, because MATRIX, wherever on SD it is located, and by whatever means it is being navigated to, is a machine-code program with a BASIC stub (containing a SYS), which doesn't really care about that misplaced pointer in 45/46.

This kind of things is usually done in direct mode, with PRINTed out commands and simulated key presses. For your application, the game is patched on-the-fly like thus:

Code: Select all

1 PRINT"{CLR}LOAD"CHR$(34)"MATRIX.PRG"CHR$(34)","MID$(STR$(PEEK(186)),2)
2 PRINT"{5 DOWN}POKE14691,76:POKE14692,133:POKE14693,57:RUN"
3 POKE631,19:POKE632,13:POKE633,13:POKE198,3
I've put this boot loader under the name "M+.PRG" in a *.zip archive (download), together with the original MATRIX.PRG executable.

Just decompress these two programs into the root of your SD card. Then all you need to do after reset or power on is LOAD"M+.PRG",8 followed by RUN.
GameOn
Vic 20 Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:58 am
Location: Oslo, Norway

Re: Editing a .PRG file

Post by GameOn »

mike - It was a .d64, although it only contained .prg file. I have not really looked at the SD2IEC interface that much, just that when I first bought it the instructions pointed at using OPEN1,8,15,"CD:file.D64":CLOSE1:LOAD"*",8 to load the game, it worked so I left it at that. The interface was an internal one and as the machine only has one game on it, the SD card is fitted internally to make use for non technical people easier to deal with.

Thank you for the explanation, I must admit I was never a big Vic 20 fan (and grew up with Sinclair machines) but I have enjoyed looking at the hardware of the machine.

Your little program works a treat, going on your explanation, I do use

1 LOAD "M+.PRG",8
RUN

and it autoloads, which is nice. :)

Thanks once again.

Eslapion - As above, the SD2IEC interface is internal so I didn't want to have to open up the machine and I wanted to use the simplest way to edit the file.

Boray - Already tried that, it basically saved the 10 SYS 8192 and not much else.
User avatar
Mike
Herr VC
Posts: 5131
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Editing a .PRG file

Post by Mike »

GameOn wrote:

Code: Select all

1 LOAD "M+.PRG",8
RUN
Is there any specific reason for your urge to embed the LOAD command into yet another program?
and it autoloads, which is nice. :)
No, it doesn't.

M+.PRG works as batch program, which spares you to enter the LOAD command for the original MATRIX.PRG, the POKEs to modify it, and another RUN to run the then-modified game. You still have to run M+.PRG with a RUN command anyway after it has been loaded ...

... for which it is entirely sufficient to use LOAD in direct mode, without preceding line number, as command.

Unless you really know what you are doing, putting a LOAD command into a program is just going to make you trouble *), and at the best it is just - like in the case here - redundant.



*) as I've already explained in my preceding post
GameOn
Vic 20 Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:58 am
Location: Oslo, Norway

Re: Editing a .PRG file

Post by GameOn »

Basically, the Vic 20 is in a unit which needs to be opened by removing two bolts. It is one unit but part of 130 other games, so the less work that can be done the better.

Typing in just

LOAD "M+.PRG",8

Will load the program you wrote but once it loads the READY prompt turns up and then you have to type RUN

Sticking the 1 in front of it, means as soon as RUN is typed in the unit can be closed up and other units can be switched on, as your program runs automatically. It's only 5 to 10 seconds extra time, but it really does help.
User avatar
Mike
Herr VC
Posts: 5131
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Editing a .PRG file

Post by Mike »

You are just lucky, that your method "works" here - i.e. you can get away with a particularly unfit way of auto-starting a program.

If M+.PRG was a BASIC program with variables, your procedure would fail, simple as that.


However, there's a proper way to do the autostart in a way as you intend, and which will also work in a broader range of circumstances.

Write LOAD"M+.PRG",8: (with the colon ":" after 8), then hold Shift, and press the key labeled "RUN STOP".

You'll see another LOAD being printed after the ":" (which is going to be ignored), the whole line is entered, the load then proceeds and when it is finished, the VIC-20 will automatically write RUN, execute that command, and run the program.

There you have your auto-start.
GameOn
Vic 20 Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:58 am
Location: Oslo, Norway

Re: Editing a .PRG file

Post by GameOn »

In the grand scheme of things, I am unlikely to run anything more then Matrix, so what ever works is good.

Thank you for the explanation and a way to autorun something. :) I'll give that a try tomorrow
Post Reply