Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Can't the LOAD command be used in a basic program?
2007-04-18 20:22
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Can't the LOAD command be used in a basic program?

1 LOAD"ROUTINE",8,1
2 SYS 49152
RUN

Ends up in a endless loop, so I guess it doesn't do what I expect it to do...

(This may seem stupid, but it would be very handy for me when crossdeving for the DTV, as I need to load the files from 64HDD all the time, with this I could just do "run" to load the lastest routine from disk and execute)
2007-04-18 20:25
tlr

Registered: Sep 2003
Posts: 1790
Quote: 1 LOAD"ROUTINE",8,1
2 SYS 49152
RUN

Ends up in a endless loop, so I guess it doesn't do what I expect it to do...

(This may seem stupid, but it would be very handy for me when crossdeving for the DTV, as I need to load the files from 64HDD all the time, with this I could just do "run" to load the lastest routine from disk and execute)


Load will restart the program after loading. Do this:
1 IF A=0 THEN A=1:LOAD"ROUTINE",8,1
2 SYS 49152
RUN

2007-04-18 20:29
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Works like a charm, thanks!
2007-04-18 21:04
Turtle
Account closed

Registered: Jan 2002
Posts: 70
I never understood why this works, but it does. Or at least I forgot it just like so many other things...
2007-04-18 21:53
insane

Registered: Nov 2006
Posts: 10
This works because loading a program "restarts" the basic-interpreter but not the variables. Anybody up for a more scientific explanation?
2007-04-19 07:03
Devia

Registered: Oct 2004
Posts: 401
sounds about scientific enough..

on first run A=0, so BASIC will set A=1 and then load the proggy and restart the BASIC prog, but NOT reset the A var, so on second run A=1 and the THEN part will not be executed, thus jumping to line 2 to do the SYS

..now that just might sound even more confusing ,-)
2007-04-19 07:29
Oswald

Registered: Apr 2002
Posts: 5094
Devia, you havent explained anything, just retold that was told already, and made yourself look really stupid.
2007-04-19 07:56
WVL

Registered: Mar 2002
Posts: 902
oswald, you old grumpy bear you <3

2007-04-19 08:01
Oswald

Registered: Apr 2002
Posts: 5094
:PPP right I am...

devia, I was ofcourse way too rude, just please dont explain one of the most simplest basic programs in the universe.

the key was that the program restarts, but there's no variable reset. An in depth ROM dissecting explanation on this would be welcome.
2007-04-19 09:05
Devia

Registered: Oct 2004
Posts: 401
I was actually just trying to illustrate that no further "scientific" explanation was necessary. Thus the "confusion" note at the end of the post. - Still providing a more thorough explanation for the few people who might find it a bit illogical that a simple LOAD statement will actually "restart" the interpreter and maybe are having some problems grasping what that actually means for the provided example.
Guess I didn't account for the Oswald-factor, tho.
And no, you're not rude as I sort of called for it - Just grumpy and honest. :)
2007-04-19 09:07
JackAsser

Registered: Jun 2002
Posts: 2014
"with this I could just do "run" to load the lastest routine from disk and execute"

Does this imply that a new RUN actually resets all basic vars to 0?

I.e.

RUN => Reset vars and restart program
LOAD => Only restarts program

?

/Andreas
2007-04-19 09:11
Oswald

Registered: Apr 2002
Posts: 5094
Jack, right.
2007-04-19 09:11
WVL

Registered: Mar 2002
Posts: 902
Quote: "with this I could just do "run" to load the lastest routine from disk and execute"

Does this imply that a new RUN actually resets all basic vars to 0?

I.e.

RUN => Reset vars and restart program
LOAD => Only restarts program

?

/Andreas


yes. you can get around it with CONT i think.. (of maybe you had to use GOTO, can't remember)
2007-04-19 09:17
Oswald

Registered: Apr 2002
Posts: 5094
I have coded a lot in basic, and I dont remember ever finding that cont does its job. It ended up always in "?cant continue". To go a bit off topic, you could do some nice tricks with basic. For example you could print new program lines on the screen, then fill the keyboard buffer with some 'returns'. Then put the cursor at the right place exit the program, and let the system and the 'returns' in the keybuffer add the new lines to your program, which were ended with a run 'linenumber'. ;) worked like a charm for generating DATA lines automagically.
2007-04-19 09:24
enthusi

Registered: May 2004
Posts: 677
not THAT much harder to poke them into memory, including the data-token and the new basic-end.
2007-04-19 09:37
Graham
Account closed

Registered: Dec 2002
Posts: 990
@Oswald: You cannot continue if the BASIC-program has been changed. If you just change variables or just LIST etc you can continue.
2007-04-19 12:54
TDJ

Registered: Dec 2001
Posts: 1879
Quote: :PPP right I am...

devia, I was ofcourse way too rude, just please dont explain one of the most simplest basic programs in the universe.

the key was that the program restarts, but there's no variable reset. An in depth ROM dissecting explanation on this would be welcome.


One of the 'most simplest' (sic)? There's not even a "Hello wolrd" in there!
2007-04-19 14:23
enthusi

Registered: May 2004
Posts: 677
this one is so much nicer :)

0 poke55,138:poke56,228:clr
1 a$="ibm"
2 b$="macintosh"
3 print a$;"+";b$;"=";a$+b$
2007-04-19 15:11
Mace

Registered: May 2002
Posts: 1799
Hahaha, this one is cool! :)
2007-04-19 19:09
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Yeah, that was an unexpected program behavior. Cool! Now how does it work??
2007-04-19 20:04
AüMTRöN

Registered: Sep 2003
Posts: 44
I'm not completely sure how it works, but $37/38 (highest addr used by basic) is being set to $e48a. If you look at the ROM below $e48a it has the string "COMMODORE 64" (part of the startup text). I also think the length of the string "IBM"+"MACINTOSH" has something to do with it.

Anyone? :)
2007-04-19 20:05
Frantic

Registered: Mar 2003
Posts: 1648
hmm..? :)
2007-04-19 20:39
iAN CooG

Registered: May 2002
Posts: 3197
Quote: I'm not completely sure how it works, but $37/38 (highest addr used by basic) is being set to $e48a. If you look at the ROM below $e48a it has the string "COMMODORE 64" (part of the startup text). I also think the length of the string "IBM"+"MACINTOSH" has something to do with it.

Anyone? :)


It's simple, the temp var that would contain "IBMMACINTOSH" is being built in the RAM under the ROM, and when retrieved for display it prints the string in ROM at the same address. Normally temp vars are allocated from $9fff down to $0801.
2007-04-19 20:46
AüMTRöN

Registered: Sep 2003
Posts: 44
Aha! Makes sense :)
2007-04-20 09:53
Oswald

Registered: Apr 2002
Posts: 5094
now lets get back to topic, and some1 please explain why does the basic prg restart after using load, and why aren't the variables resetted.
2007-04-20 10:45
Devia

Registered: Oct 2004
Posts: 401
With danger of sounding very stupid, I quote the C64 Programmers Reference Guide:

"The LOAD closes all open files and, if it is used in direct mode, it performs a CLR (clear) before reading the program. If LOAD is executed from within a program, the program is RUN. This means that you can use LOAD to "chain" several programs together. None of the variables are cleared during a chain operation."

It would appear that LOAD in non-direct mode was intended only for breaking apart large BASIC programs.
I wonder if there is some smart POKE/SYS combo one could do to not make it RUN after loading, but navigating through the BASIC ROM quickly gets quite tiresome...
2007-04-20 11:35
Mace

Registered: May 2002
Posts: 1799
I think I found it...

At the end of the loading routine, at $E1B5, there's a JSR to $A68E. There the current character pointer is set to the first BASIC line. So when ending the LOAD command, the next command to be executed is the first one in the first BASIC line.

So, Devia, there's no way around it.
Both in direct and in basic mode, this routine is called.
In direct mode it's JSR'ed a bit earlier, together with the printing of "ready".
2007-04-20 12:14
Devia

Registered: Oct 2004
Posts: 401
Well, then you CAN do it..

10 POKE43,28
20 LOAD"FILE",8,1
30 POKE43,1
40 SYS4096

If you change the filename in the above, you just have to adjust the first POKE, in this case 28, to match the starting address of line 30

2007-04-20 13:05
Mace

Registered: May 2002
Posts: 1799
Devia, yeah, that works :)
So with some effort, it might be possible to calculate the pointers by using the value of 122 and 123 ($7A, $7B).

That would enable you to write a universal routine that works on any location within a basic program.
2007-04-20 14:10
Devia

Registered: Oct 2004
Posts: 401
something like:

10 POKE43,PEEK(123)+26+04
20 LOAD"CODE",8,1
30 SYS4096
40 POKE43,1

- where the '04' in line 10 just needs to be adjusted to the filename length.
Line 40 is not really necessary unless you want to be able to LIST/RUN/SAVE the program again.
..and it wouldn't work if line 10-30 crossed a page boundary of course.
2007-04-20 14:32
Mace

Registered: May 2002
Posts: 1799
Quote:
Line 40 is not really necessary unless you want to be able to LIST/RUN/SAVE the program again.

What if there's a GOTO ro GOSUB to lines prior to this LOAD part?

You could also scan for the POKE 43,1 (tokenised) around the calculated address to see where the line is exactly.
2007-04-20 19:23
iAN CooG

Registered: May 2002
Posts: 3197
quoting some FAQ file found on the net:

#9. To load a program from BASIC without re-run problems or tricky
variable/ongoto statements....

poke147,0
sys57812 "filename",8,1
sys62631

here's another method for data files:

following will work to read in everything except the first two bytes:

1000 SYS 57812 "NAME,S",8,0:REM SET PARAMETERS FOR LOAD
1010 POKE 193,L%:POKE 194,H%
1020 POKE 147,0:SYS 62631

L% is the low byte of the load address, and H% is the high byte, e.g.
H%= INT(address/256): L%=address-256*H%

POKEing a 0 into 147 performs a load; a 1 would perform a verify.
2007-04-20 21:34
Mace

Registered: May 2002
Posts: 1799
Quote:
1000 SYS 57812 "NAME,S",8,0:REM SET PARAMETERS FOR LOAD
1010 POKE 193,L%:POKE 194,H%
1020 POKE 147,0:SYS 62631

Why "name,s"....? What does the S do?
2007-04-20 21:47
tlr

Registered: Sep 2003
Posts: 1790
Quote: Quote:
1000 SYS 57812 "NAME,S",8,0:REM SET PARAMETERS FOR LOAD
1010 POKE 193,L%:POKE 194,H%
1020 POKE 147,0:SYS 62631

Why "name,s"....? What does the S do?


It loads a SEQ file instead of the default PRG.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Sychamis
apprentix
iceout/Avatar/HF
Perplex/Offence
Guests online: 105
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.066 sec.