Tip of the Year: Save your work after MSX crash!

Page 1/2
| 2

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

14-04-2005, 16:51

Ok, I think, that most of you, who have been playing with BASIC (and expetially X-BASIC) have already had this situation:

Program hanged, your MSX does not respond to keyboard and everything to do is to push that reset button... You can usually prevent this by enabling soft reset (POKE &HFBB0,1) but always even that does not work.

At this point people usually remember program named OLD, that is made to save your ass in this kind of situations. Only problem is, that you usually really can't find it when you most need it!!!

I anyway managed to find general solution to this problem that is even easy to remember!

- If there is disk in drive, remove it
- Press that reset button
- Wait BASIC to start
- Put formatted disk into drive.
- Type:

POKE &H8002,128
SAVE"TEMP"
LOAD"TEMP"
SAVE"TEMP",A
LOAD"TEMP"
SAVE"DEARPROG.BAS"
KILL"TEMP"

- Send greetings to NYYRIKKI as he has just saved your work. Smile

Login or register to post comments

By Sonic_aka_T

Enlighted (4130)

Sonic_aka_T's picture

14-04-2005, 19:37

you forgot KILL "DEARPROG.BAS" as the last line Tongue

By Manuel

Ascended (17945)

Manuel's picture

16-04-2005, 17:01

NYYRIKKI, I just needed this trick and therefore I can conclude: it works!! Smile

Can you explain it?

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

17-04-2005, 04:53

Can you explain it?

Sure...

To clear things out, let's take an example program:

10 REM Example program
20 PRINT"Hello world!"

In memory this program is tokenized this way:

#8000 =#00 This byte is always zero. If it is not, program can not run.
#8001-8002 =#8017 This is pointer to start of next line (20)
#8003-8004 =#000A = 10 this is line number
#8005 = #8F This is a token that represents REM command
#8006-8015 = " Example program"
#8016 =#00 This indicates end of line.
#8017-8018 =#802B This is pointer to start of next line
#8019-801A =#0014 = 20 this is line number
#801B = #91 This is a token that represents PRINT command
#801C-8029 = "Hello world!"
#802A =#00 This indicates end of line.
#802B-#802C =#0000 This is pointer to start of next line. Now it is 0 because there is no next line.

When your MSX is rebooted or NEW command is executed, pointer to start of next line in #8001 will be reseted to 0. If we want to restore the program, our problem is, that now we don't know what the next address for start of next line is!

When I was thinking about the tokenized program I was wondering, that how this can work when BASIC is not in default #8000 address? When loading of the data is done, these addresses must be calculated again and I was right. (This has been propably implemented to get BASIC files exchangeable with 16KB RAM machines as well.)

So here is actually what happens, when you execute those commands.

When you save empty program #FF will be put in start of the file to indicate start of tokenized program and BASIC program (this case #8001-8002) will be saved after it. Now we how ever change this address in #8001 to #8000. This number can be actually anything else but 0, but I used #8000 as in #8000 there is word #0000 so, if you use list command, you will not get crap to your screen or in worst case hang your MSX.

Now when this is saved, we will get file with following bytes: #FF,#00,#80
Now when this file is loaded, BASIC does not understand, that the file is so short and address in #8001 will be calculated again using data already in memory as information.

Now when you execute list, you can see the whole program. There is anyway still few problems... BASIC still thinks, that our program is 2 bytes long, so if you execute it, start of the program will be overwritten by variables of the program. Also if you try to save the program as tokenized BASIC program, only 3 bytes will be saved (This time they are anyway correct Smile). Solution is to save the program as ASCII file as then it is converted to text same way as when you use LIST command.

Rest of the steps are used to convert the ASCII file back to tokenized format in order to save disk space and loading time.

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

18-04-2005, 19:38

Ok, here comes a version for people, who don't have a disk drive. This is not as easy to remember, but it is still faster to type, than load OLD program from tape...

Note: Type this in in direct command mode, else you are going to overwrite the program, you are trying to save!!! Please do not add spaces, but this listing is not case sensitive.

POKE&H8002,128:DEFUSR=&HF434:IFUSR(0)THENMAXSB#""""PSETANDBASE

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

19-04-2005, 00:58

Ok, I was a bit too quick with the cassette version... It seems, that it has still some problems with GOTO, GOSUB and variable arrays... I think I still need to learn some more BASIC when I have more time Smile

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

19-04-2005, 11:26

Hmm... I think, CLEAR will init rest of the variable stuff... You can try this one, but I still recommend you to save your work right after running this:

POKE&H8002,128:DEFUSR=&HF434:IFUSR(0)THENMAXSB#""""PSETANDBASEELSECLEAR

By marison

Expert (104)

marison's picture

19-04-2005, 13:37

NYYRIKKI,

This tip works in Windows? It's much more necessarily in that enviroment...

I have needed this some times. In a brazillian book or magazine I've saw this tip 15 years ago, I guess.

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

19-04-2005, 14:50

This tip works in Windows?.
Smile
In a brazillian book or magazine I've saw this tip 15 years ago, I guess.

Which one?

By AuroraMSX

Paragon (1901)

AuroraMSX's picture

19-04-2005, 15:14

Now when you execute list, you can see the whole program. There is anyway still few problems... BASIC still thinks, that our program is 2 bytes long, so if you execute it, start of the program will be overwritten by variables of the program.
The system variable (VARTAB? I don't have the docs at hand Smile) that tells BASIC where the start of the variable area is, will point to #8003 directly following the BASIC code. And therefor, the program gets overwritten.
Also if you try to save the program as tokenized BASIC program, only 3 bytes will be saved (This time they are anyway correct ).

That surprises me, actually. That means that the SAVE routine just writes out the block of memoty between TXTTAB (start of BASIC program) and (VARTAB). I woudl have thought that the save routine writes BASIC lines until it reaches the end of the program (3x #00)...
Solution is to save the program as ASCII file as then it is converted to text same way as when you use LIST command.
... whereas the SAVE,A routine seems to LIST the program to file.
Interesting... Smile

POKE&H8002,128:DEFUSR=&HF434:IFUSR(0)THENMAXSB#""""PSETANDBASE

That MAXSB#""""PSETANDBASE: is that plain old obfuscation Smile or functional code, somehow?

By NYYRIKKI

Enlighted (5776)

NYYRIKKI's picture

19-04-2005, 17:04

That MAXSB#""""PSETANDBASE: is that plain old obfuscation Smile or functional code, somehow?

It's ML. Purpose is to calculate lenght of first line and update VARTAB to end of program.

Page 1/2
| 2