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 > out of memory when loading a basic prg
2010-12-16 04:22
Lobogris
Account closed

Registered: Oct 2010
Posts: 22
out of memory when loading a basic prg

Hi! if I load my basic program from disc, normally with LOAD"GAME",8 in direct mode, my program loads, I make RUN and it works OK, without problems.

...But when I try to load this file from another basic program or with a ML routine (using KERNAL LOAD routine), and I try to execute it with RUN, I get an OUT OF MEMORY ERROR at (random line with correct basic syntax line),
then the list gets corrupted and sometimes I get a Jam in vice.

Why LOAD works well in direct mode and not if called through kernal or invoking the LOAD command from another (Loader) basic program?

In other words: What does exactly LOAD in direct mode? (that Kernal Load doesn't)

I am completely lost about this problem. What can I do to solve this?
2010-12-16 07:48
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
nvm
2010-12-16 10:38
Krill

Registered: Apr 2002
Posts: 2980
So you have a program at $0801+ and it loads another program to the same memory region, overwriting itself and screwing up anything before, at, and after the LOAD command?
2010-12-16 12:07
chatGPZ

Registered: Dec 2001
Posts: 11386
loading in program mode doesnt clear the basic variables.... afaik :)
2010-12-16 12:44
Danzig

Registered: Jun 2002
Posts: 440
for basic: that is why printing load and run command on screen, settings the cursor to the right position and filling keyboard-buffer with RETURN was invented :P

for ml-code: groepaz ist right, that was always a common way to load ml-subroutines for basicprograms. set variable a=0, if a=0 set a=1 and load ml1. that reruns the program -> if a=1 set a=2 and load ml2. that reruns the program, and so on.
2010-12-16 14:05
Fungus

Registered: Sep 2002
Posts: 686
When loading basic from ML programs (usually up high in memory) you need to handle some of the basic workspace variables in zeropage after the load is completed.

You need to set top of mem, end address, bottom of variable workspace etc, then prepare to and run the program from the basic rom. There's a few subroutines in the basic rom for doing the latter.

I've had to crack a few basic/ml hybrid games and this kind of stuff needs to be done in order to get it to work. Rostam vs Esfandiar comes to mind... you can look in that crack to see what I did.

Just keep your copy of mapping the 64 handy to check which variables and rom routines I used do.
2010-12-16 22:15
Lobogris
Account closed

Registered: Oct 2010
Posts: 22
Quoting Krill
So you have a program at $0801+ and it loads another program to the same memory region, overwriting itself and screwing up anything before, at, and after the LOAD command?

exactly.

I am thinking of making a loader in ml (or in basic) puting all bytes one by one to avoid the kernal load complete block. I hope it works.
All i need is to put another basic program starting at $0801, overwriting the little loader basic prog that started too at $0801.

Thanks @Fungus I'll see that crack of Rostam vs Esfandiar.

@Danzig :"printing load and run command on screen, settings the cursor to the right position and filling keyboard-buffer with RETURN was invented :P"

That's a nice trick. I will try that too, because in direct mode LOAD works fine...thanks.

about the variables I use that thing too:
10 if a=0 then a=a+1:load "charset.64c",8,1
20 if a=1 then a=a+1:load "mlroutines.obj",8,1
30 if a=2 then a=a+1:load "koala.koa",8,1

but that only serves for loading all your data in memory at start of basic program, because load in program mode, restarts to the first line of basic and runs again, and again... variables are not affected. But if vars were affected (for example you need a CLR in first line after correcting some pointers) you can use PEEK(mem)=0, C=C+1,POKE MEM,C,LOAD...

To avoid this mess there is an alternative:
10 poke 147,0:sys 57812"charset.64c",8,1:sys 62631
etc.
in this case, you can load any data in whatever line you desire (not at start of the program)

But none of this ways of loading worked to load a basic prg from another basic program...
2010-12-17 00:10
Krill

Registered: Apr 2002
Posts: 2980
Just make sure the loading file and the loaded file don't overlap. You can change the basic start ($2b/c) to another location and run the program loaded there. You may need to manipule some other pointers, too (like top of mem at $37/8 if you load up to the end of BASIC mem at $a000 (plus allowing some scratch space for variables), refer to Fungus's comment). But why all that hassle for BASIC? It's not exactly fast to run interpreted languages on the C64. :)
2010-12-17 00:36
Lobogris
Account closed

Registered: Oct 2010
Posts: 22
Quote: Just make sure the loading file and the loaded file don't overlap. You can change the basic start ($2b/c) to another location and run the program loaded there. You may need to manipule some other pointers, too (like top of mem at $37/8 if you load up to the end of BASIC mem at $a000 (plus allowing some scratch space for variables), refer to Fungus's comment). But why all that hassle for BASIC? It's not exactly fast to run interpreted languages on the C64. :)

the loader only contains a few basic lines to load the main game basic program, it doesnt overlap nothing. I will do the loader in ML only or maybe a basic program, that is not important here.

Well, I make this because its a colaboration for a person that is making a game in basic. It's a simple (sci fi) adventure with selectable answers and bitmaps. I don't like to mess up with basic too :D but the author doesn't understand ML yet.
Maybe I will make all the game again with kickass if all of this things are hard to do, but... the game is already almost done, and it will be a lot of extra work. For the next game I hope he has learned ML :D


In the main game I put the top mem of Basic to the start of all the bitmap buffers and ML routines. The end of the basic program is near $8000. I had all my ML and extra data put starting at $4800, now that basic prog has grown to about $8000 I will need to relocate all my code & data...

Charset (I use only 2k lower case chars) and screen ram are at $C000.

I wonder if I will have space for my ML and data in the new starting location. What a mess working with basic, :D

Thanks for your help Krill.

2010-12-18 00:05
Lobogris
Account closed

Registered: Oct 2010
Posts: 22
Ok I did:

10 print "{shft+clrhome}"
15 print "load"+chr$(34)+"game"+chr$(34)+",8"
20 poke 198,4:poke631,145:poke632,145:poke633,145:poke634,13

This prints the string containing LOAD"game",8
and fills the keyboard buffer with 4 forced keypresses (198,4), that are 3 CRSRS UP (ascii 145) and RETURN (ascii 13)

run
load"game",8

searching for game
loading
ready.

Loads the game I type run <return> and all is working perfectly... The only problem here, is the program loaded is not autoexecuted... (and I know that adding :run to the string won't work)

So... what should I do here to autoexecute the game once loaded?
Edit: Uhmmmm maybe putting RUN and return in the buffer ?
I'll try that now!
2010-12-18 00:17
Lobogris
Account closed

Registered: Oct 2010
Posts: 22
30 poke 635,asc("r"):poke 636,asc("u"):poke 637,asc("n"):poke 638,13

Oh yes that worked !

Thanks for your help ;)
[SOLVED]


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
Acidchild/Padua
Xiny6581/Dees Produc..
CopAss/Leader
Fulgore/Excess/TREX
csabanw
Krill/Plush
ΛΛdZ
zscs
rexbeng
Guests online: 110
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 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (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.271 sec.