Page 1 of 1

Link at a specific address

Posted: Tue Oct 26, 2010 11:33 am
by KanedaFr
Hi,

I would like to link my code at a specific address.
Ex:

Code: Select all

multipad.s

    .org 0xFFB20
    .globl get_multitap
get_multitap:
    xxxx
When I look at the final rom.bin, the code is at 0x1030F4 (not 0xFFB20)
I also note that in the multipad.o, the code is near 0xFFB20

so, does using .org directive mean "in the objet file" ? I would like the linking process to use this directive....
does someone know how to do this ?

thanks

Posted: Tue Oct 26, 2010 12:00 pm
by HardWareMan
Use assembler. :3

Posted: Tue Oct 26, 2010 12:10 pm
by KanedaFr
I'm trying, I'm trying! :)

Posted: Tue Oct 26, 2010 12:35 pm
by KanedaFr
Wow!
I succeed updating the ld script! (you see HardwareMan, I'm really trying hard! ;) )

Code: Select all

//in md.ld
.multipad 0x000FFB20:
  {
    multipad.o
  } > rom = 0xFF

//in multipad.s
    .section multipad
    .globl get_multitap 
get_multitap: 
    xxxx 

is it the right way ?

Posted: Tue Oct 26, 2010 5:50 pm
by Chilly Willy
There's no "right" way, just ways that work.

Using a section is a decent way of doing it. You could also pad the rom.

Why do you need a specific address in the rom? Perhaps you can change the code to avoid needing a fixed address. That would be the "best" way to handle it.

Posted: Wed Oct 27, 2010 7:23 am
by KanedaFr
I know if not something to do usually.
In fact, I'm trying some hacks on an existing rom so I need be sure I call the already coded functions ;)

thanks anyway

Posted: Wed Oct 27, 2010 7:44 am
by HardWareMan
Hmm. You need to call already coded procedure at specific address? In ASM, you just do: jsr $0FFB20. :3 Try harder to use ASM. :3

Posted: Wed Oct 27, 2010 7:50 am
by KanedaFr
ah ah!
no...
I wrote a function that need to be added at a 0xFFB20 (free space in rom) and call it from an existing function (where I added the jsr $FFB20)
This function is fully written in asm... hopefully lot of you shared pure asm code I used to learn ;)

I know functions wrote on asm are 'address dependant' (ex: thing like bra nearFunc became bra +=4 and not bra $233DD) so I prefer to code it at the correct address while testing so I could copy/paste the final binary from my test rom to hack rom

It's what I did : I successfully added 6 pad support to a 3 pad only game ;)
more coming soon

Posted: Wed Oct 27, 2010 1:58 pm
by GManiac
You should declare you procedure in another section and then set base address of this section during linking. I don't familiar with linker options, all I know is how to assemble files with GNU toolchain. Something like this:

Code: Select all

m68k-elf-as.exe %1 -o %1.out -mcpu=68000 --register-prefix-optional
m68k-elf-ld.exe %1.out -o %1.o -e 0 -Tbss 0 -Tdata 0 -Ttext 0
m68k-elf-objcopy.exe %1.o %1.gen -O binary
Tbss, Tdata, Ttext are segments for linker.

Posted: Mon Dec 06, 2010 2:54 pm
by powerofrecall
KanedaFr wrote:ah ah!
no...
I wrote a function that need to be added at a 0xFFB20 (free space in rom) and call it from an existing function (where I added the jsr $FFB20)
This function is fully written in asm... hopefully lot of you shared pure asm code I used to learn ;)

I know functions wrote on asm are 'address dependant' (ex: thing like bra nearFunc became bra +=4 and not bra $233DD) so I prefer to code it at the correct address while testing so I could copy/paste the final binary from my test rom to hack rom

It's what I did : I successfully added 6 pad support to a 3 pad only game ;)
more coming soon
Please tell me it's Cyborg Justice :)

Posted: Mon Dec 06, 2010 3:20 pm
by KanedaFr
;)
sorry, it's NHL94...but I'm finishing my How to, so you'll be able to do it by yourself ;)

Posted: Mon Dec 13, 2010 10:08 pm
by KanedaFr
If you're interesting to know how I added 6 buttons support to NHL 94 (thanks to some of you!), read my last technical doc.

I hope it will give some ideas to future Genny hackers ;)

Posted: Mon Dec 13, 2010 10:56 pm
by Chilly Willy
Nice hacking tutorial. Just enough detail without getting too bogged down in code.
:D