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 > guide how a *.prg file is structured
2013-11-07 09:48
MrXaliasH

Registered: Oct 2013
Posts: 11
guide how a *.prg file is structured

Hi guys,

while working on a cross platform tool I stumbled over the problem, how to generate a prg file with this application directly.

Until now I still use the way to generate a asm file to import into an assembler (CBM prg Studio for me).

I looked at the generated prg file but got some problems in understanding why it is like it is. Of course I know that I have to use the opcodes instead of the mnemonics and I know about how addresses should be encoded (LSB,MSB), how jumps work etc...

But what i don't understand is, what is the best way to optimize the size of the prg file.

For example:
I have a screen, which I want to display.
ScreenRAM is located at $4000, ColorRAM at $4400, code to copy it to its destination at $0C00
The jump to the code is located at normal basic start ($0801)

But in the generated prg file this structure is messed up and I can't see any logic in it. So I didn't find a algorithm yet how to "pack" my code into a prg file like it is done there.

So there is my question:
Is there anywhere a guide/tutorial/document, which describes how a prg file should/could/shall be "structured"?

Thanx for your help in advance
Holger
2013-11-07 09:59
JackAsser

Registered: Jun 2002
Posts: 2014
A prg file is just a memory dump with the two first bytes stating where to start. The rest is just binary data in linear memory. It's nothing like an object file or so like you seem to assume.

Normally you simply save the memory as is and crunch it, but sometimes it's more appropriate to manually have all data blocks after each other and a simple routine to spread them out in run time.
2013-11-07 11:57
MrXaliasH

Registered: Oct 2013
Posts: 11
OK, maybe it was explained a bit complicated :D

Now it makes sense when i look at the prg file generated by the CBM prg Studio.

Thanx for pointing me into the right direction.
2013-11-07 12:43
algorithm

Registered: May 2002
Posts: 705
Like JackAsser mentioned, the PRG file is merely a raw dump with the first two bytes indicating the load address.

Perhaps you were asking how a prg file is structured that has a sys line that autoruns when the run command is executed?
2013-11-07 14:03
MrXaliasH

Registered: Oct 2013
Posts: 11
@algorithm:
I think its just like this: first two Bytes: $01,$08
then the SYS call and after that, maybe with some offset (filled with $00) the data/code
Of course the SYS call should point to a address where code is loaded to.

Is that correct?
2013-11-07 14:17
Oswald

Registered: Apr 2002
Posts: 5094
http://csdb.dk/forums/?roomid=11&topicid=99062#99086

secondly, you can simple use a command line PC tool, which generates a packed executable for you in prg file, sys included (google for: exomizer, pucrunch)
2013-11-07 14:28
MrXaliasH

Registered: Oct 2013
Posts: 11
Thanx Oswald for the tools, they will be usefull if the generated prg file gets bigger.
At the moment there is still enough left (if my assumtion that with loading a file to $0801 the whole RAM to $9FFF can be used for the file).
2013-11-07 15:54
Oswald

Registered: Apr 2002
Posts: 5094
you can load fine until $d000, because all cpu writes to rom, are turned into writes to ram by wiring.
2013-11-07 19:34
MrXaliasH

Registered: Oct 2013
Posts: 11
Thanx again Oswald for this valueable information :D
2013-12-05 02:12
theWizard
Account closed

Registered: Jul 2007
Posts: 109
eg

$00,$10
[data to load]

loader reads first 2 bytes ( in this case $1000 dec 4096 ) that tells the loader where to put the rest of the data then the data after the first 2 bytes is loaded to $1000.

basically thats the prg file structure.

first 2 bytes tell it where to load then data gets put wherever its told to go.
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
csabanw
JackAsser/Booze Design
Jammer
Flex/Artline Designs
Guests online: 100
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 NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

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