SAVEing machine code program

Basic and Machine Language

Moderator: Moderators

Post Reply
mr zetec
Vic 20 Drifter
Posts: 25
Joined: Thu Sep 03, 2009 1:36 pm

SAVEing machine code program

Post by mr zetec »

Hello everyone.
Ok, I know this is going to seem really obvious to you but it's not to me! My problem is I have LOADed a program and I want to SAVE it back to tape, when I LIST it has only one line "10 SYS(1039)". Of course the whole program is in memory but when I SAVE it only SAVEs line 10! I am using a 4032 PET. How can I save the whole 8K program?
Vic20-Ian
Vic 20 Scientist
Posts: 1214
Joined: Sun Aug 24, 2008 1:58 pm

Post by Vic20-Ian »

Hi There

Try

save"my program",1,1 saves code for tape

save"my program",8,1 saves code to disk drive 8
Vic20-Ian

The best things in life are Vic-20

Upgrade all new gadgets and mobiles to 3583 Bytes Free today! Ready
mr zetec
Vic 20 Drifter
Posts: 25
Joined: Thu Sep 03, 2009 1:36 pm

Post by mr zetec »

Thanks for the idea but it still only saves line 10, there is a whole 8K of code that needs to be saved with it. I know I am using a PET, but the PET is very similar to the VIC and the VIC forums are much better.
So, again once I have LOADed a machine code program, how do I SAVE it?
Vic20-Ian
Vic 20 Scientist
Posts: 1214
Joined: Sun Aug 24, 2008 1:58 pm

Post by Vic20-Ian »

After you save ,1,1 or ,8,1 did you load back ,1,1 or ,8,1?
Vic20-Ian

The best things in life are Vic-20

Upgrade all new gadgets and mobiles to 3583 Bytes Free today! Ready
mr zetec
Vic 20 Drifter
Posts: 25
Joined: Thu Sep 03, 2009 1:36 pm

Post by mr zetec »

Here it is in brief:

power on
LOAD; program loads takes a few minutes
SAVE"NAME",1,1; writes to tape normally. Takes a few seconds

Now if I run it it will work at this point

power off then on again
LOAD"NAME",1,1; program loads takes a few seconds
RUN ;nothing happens.
LIST ;lists line 10 only because that is all that is saved!

The problem is the code is not being written to tape, only the one line in BASIC with the SYS(number) is being written. The ,1,1 does not make a difference. If I load and save a BASIC program it is fine.
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

Maybe it is copy protected?
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
Vic20-Ian
Vic 20 Scientist
Posts: 1214
Joined: Sun Aug 24, 2008 1:58 pm

Post by Vic20-Ian »

http://sleepingelephant.com/ipw-web/bul ... p&start=30


The above is a link to a topic on Vic rom code dumping which you could maybe modify to read and write the memory block you want if it is in a rom or something.

Please send some more information about what you are doing as I do not understand why a save command won't store the machine code.

How are you entering this machine code in the first place when you say you can get it to run?

Are you in using Vice emulator or on a real PET?
Vic20-Ian

The best things in life are Vic-20

Upgrade all new gadgets and mobiles to 3583 Bytes Free today! Ready
FD22
Vic 20 Hobbyist
Posts: 148
Joined: Mon Feb 15, 2010 12:31 pm

Post by FD22 »

You can save MC programs through the monitor. On a 4032 PET, you can enter the monitor by typing SYS 4 or SYS 1024 (you need an address with a zero, BRK, in it) which will drop you into the command prompt where you can type S "PROGRAMNAME", device, start-address, end-address+1.

To save the screen to disk on a 4032, use S "0: SCREEN",08,8000,8400.

To save your 8K program to tape, use S "PROGRAM",01,040F,2410 - or S "PROGRAM",01,0400,2401 if you want the BASIC stub as well, and the 8K includes it.
formater
Vic 20 Hobbyist
Posts: 134
Joined: Sat Jul 01, 2006 9:43 am

Post by formater »

Before save your programs, you must poked the memory positions 43,44, 45 and 46 with the correct value for the begin and end of program.

For example, your MC program are placed in memory between the position 5000 and 5192.
divide 5000/256=19.53125 then the rest multiply by 256 .53125x256=136. The same with the other number
divide 5192/256=20.28125 then the rest multiply by 256 .28125x256=72.

You poked 43,19 44,136 45,20 and 46,72 then save the program with save "name",8 for disk and save"name",1 for tape.
For load you must use load"name",8,1 or load"name",1,1

Finally, if the program change this pointers for protection, you can take the values from the tape buffer positions 829, 830, 831 and 832 respectively (only if loaded from a tape of course). The values are put at the begin of the charge, in the moment you see the name of the program loaded, break, and take the values you need.
User avatar
Richardc64
Vic 20 Drifter
Posts: 33
Joined: Mon Feb 01, 2010 3:55 pm

Post by Richardc64 »

You can't just add ",1" after the Device # and expect SAVE to know what range of memory to save: it needs to be told.

For Basic programs, SAVE takes start and end+1 from the start-of-BASIC (location 43/44) and end-of-BASIC (45/46) pointers. You could POKE new values into those location and then SAVE"my program",1,1 but that causes problems if done within a Basic program. Try this, from Chapter 6 of Compute!s Programming the VIC:

1000 sys57809"name",1,1:rem 8,1 for disk
1010 poke193, sl:poke194,sh:rem low byte/high byte of start address
1020 poke174, el,poke175,eh:rem low byte/high byte of end address+1
1030 sys63109

edit: I see two answers were posted while I was typing.
"I am endeavoring, ma'am, to create a mnemonic memory circuit... using stone knives and bearskins." -- Spock to Edith Keeler
mr zetec
Vic 20 Drifter
Posts: 25
Joined: Thu Sep 03, 2009 1:36 pm

Post by mr zetec »

Thank you all so much! I tried FD22's solution just because it seemed easier. I tried loading PET Space Invaders (machine code) then saving and it worked! I was able to back up a few of my failing origionals :D
Post Reply