C64 .PRG Autostart (cross-assembler)
category: general [glöplog]
Seems like an obvious question to me, yet I can't find the answer anywhere...how is this done? I just want my .prg to run when loaded, without typing "sys2304" or whatever.
I'm using C64Asm until I can get my hands on a real C64.
I'm using C64Asm until I can get my hands on a real C64.
You need a basic header/stub (that displays f.e. "10 sys2304" after loading and listing). Just google for a code snippet or ask at csdb and/or look at some demo/game source, f.e. here.
Jake: Right after you left MSN I actually did find something :). Come and get it.
also you can just feed your binary into a cross-tool cruncher like exomizer, which will reduce size&add sys line.
what has happened to good old sledgehammer2 ? ;)
pucrunch is a good alternative to exomizer when doing crossdev; it accepts files without load address and is very fast.
Cool, already had exomizer, had'nt tried it yet..thanks :)
..And I had thought of the BASIC stub thing, but what tools would I use to create said stub .prg and make it execute when loaded? Should it be at a certain address (like "10" in Tomaes' example), and how could I cross-develop the .prg?
Just add something like this to your ASM-program:
* = $0801
.byte $0c,$08,$0a,$00,$9e,$20,$32,$33,$30,$34,$00,$00,$00
That is the bytes for a basic '10 sys 2304' line
Otherwise most modern cross-assemblers have a built in macro that does this, for example Kick Assembler which I use (and recommend!), you simply do like this:
* = $0801
.byte $0c,$08,$0a,$00,$9e,$20,$32,$33,$30,$34,$00,$00,$00
That is the bytes for a basic '10 sys 2304' line
Otherwise most modern cross-assemblers have a built in macro that does this, for example Kick Assembler which I use (and recommend!), you simply do like this:
Code:
.pc =$0801
:BasicUpstart($0810)
.pc = $0810 "Code"
(rest of code here)
eh, the code tag doesn't like the '$'-characters it seems like, the second example should be like this:
.pc =$0801
:BasicUpstart($0810)
.pc = $0810 "Code"
(rest of code here]
.pc =$0801
:BasicUpstart($0810)
.pc = $0810 "Code"
(rest of code here]
thanks Sdw :D Works perfectly.
One question, how did you get those bytes exactly? did you create a BASIC V2 prog, save it, and take those from a hex editor? I understand the BASIC address being where it is, just not how you got those bytes.
One question, how did you get those bytes exactly? did you create a BASIC V2 prog, save it, and take those from a hex editor? I understand the BASIC address being where it is, just not how you got those bytes.
I just typed in "10 sys 2304" in VICE, then entered the monitor (alt-m) and did a hex dump from $0801 and forward (enter ''m 0801" in the monitor)
oh ok :) perfect, thanks.
This is how I do it using ACME
BASIC_START = $0801
CODE_START = $080d
* = BASIC_START
!byte 12,8,0,0,158
!if CODE_START >= 10000 {!byte 48+((CODE_START/10000)%10)}
!if CODE_START >= 1000 {!byte 48+((CODE_START/1000)%10)}
!if CODE_START >= 100 {!byte 48+((CODE_START/100)%10)}
!if CODE_START >= 10 {!byte 48+((CODE_START/10)%10)}
!byte 48+(CODE_START % 10),0,0,0
* = CODE_START
; start of the main routine
You can change CODE_START to any address and basic autorun will be automatically generated.
Detailed info: First byte (12=$0c) represents the length of the basic code. If the number next to SYS command is a 4 digit number beween 1000-9999 it should be 11 ($0b) instead of 12. But since it works like this with both 4 and 5 digit number, we can forget about perfection.
BASIC_START = $0801
CODE_START = $080d
* = BASIC_START
!byte 12,8,0,0,158
!if CODE_START >= 10000 {!byte 48+((CODE_START/10000)%10)}
!if CODE_START >= 1000 {!byte 48+((CODE_START/1000)%10)}
!if CODE_START >= 100 {!byte 48+((CODE_START/100)%10)}
!if CODE_START >= 10 {!byte 48+((CODE_START/10)%10)}
!byte 48+(CODE_START % 10),0,0,0
* = CODE_START
; start of the main routine
You can change CODE_START to any address and basic autorun will be automatically generated.
Detailed info: First byte (12=$0c) represents the length of the basic code. If the number next to SYS command is a 4 digit number beween 1000-9999 it should be 11 ($0b) instead of 12. But since it works like this with both 4 and 5 digit number, we can forget about perfection.
imho using a cross packer is better for two reasons:
- no need to fuck around to get the start addy
- the unpacked binary can use almost all 64k (unless vice's autostart featured doesnt support that, I dont know, but the built in loader can not load over $d000)
- no need to fuck around to get the start addy
- the unpacked binary can use almost all 64k (unless vice's autostart featured doesnt support that, I dont know, but the built in loader can not load over $d000)
one more: the final binary will have to be packed anyway ;)
test test:
Code:
$0810
...ok that's weird
Here is an excerpt from a tutorial i once wrote:
----
We do want a basic-header, and writing them in assembly is just plain ugly.
This is our basic-header,called basicheader.bas:
2004 sys32768
You need VICE's petcat to produce an Object:
petcat -w2 <basicheader.bas >basicheader.obj
----
The Tutorial then continues to describe how to use Makefile to automatically generate the basic stub
http://k2devel.sourceforge.net/doc_k2asm.html#example_3
----
We do want a basic-header, and writing them in assembly is just plain ugly.
This is our basic-header,called basicheader.bas:
2004 sys32768
You need VICE's petcat to produce an Object:
petcat -w2 <basicheader.bas >basicheader.obj
----
The Tutorial then continues to describe how to use Makefile to automatically generate the basic stub
http://k2devel.sourceforge.net/doc_k2asm.html#example_3
there, fixed it for ya.