D-Bug & Automation Forum
D-Bug & Automation Forum >> Coding >> Either a force relocation packer or a routine to relocate
https://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?num=1334222877

Message started by Phill on 12.04.12 at 09:27:56

Title: Either a force relocation packer or a routine to relocate
Post by Phill on 12.04.12 at 09:27:56
I asked this on Atari Forum, but I've come to a dead end.

I'm converting Where Time Stood Still to Amiga, and i'm using the Was (not was) crack as the basis of the version i'm using, but the way he's cracked it means that a lot of memory is wasted which I need to get back so there is enough free chipram to process and display the ST converted screen.

His version is force relocated to $db06, and I need to locate it lower, so I looked at the Pasti image, and that one is relocatable.

On the Amiga we could force executables to relocate to an address of our choosing, and I need to do the same on this game, which will then free up all the ram I need.

So, does any of the packers give the option of force relocating executables on the ST, if not that, has anyone ripped the TOS routines that relocate executables, or have a utility that does it?


Title: Re: Either a force relocation packer or a routine to relocate
Post by ggn on 12.04.12 at 10:18:07
Hi Phill,

assuming that a0 points to the start of the .prg, you can use this code to relocate:

[code]                movem.l D0-A6,-(SP)

                lea     2(A0),A1
                lea     $001C(A0),A0
                move.l  A0,D0

                adda.l  (A1)+,A0        ; text
                adda.l  (A1)+,A0        ; data
                lea     (A0),A3         ; BSS Start
                move.l  (A1)+,D3        ; bss
                adda.l  (A1)+,A0        ; rest  (symboltable)


                move.l  (A0)+,D1        ;relocation info ??
                beq.s   end_relocation  ;nope...
                movea.l D0,A1           ; text start
                adda.l  D1,A1           ;1st adress - long offset
                moveq   #0,D1
                moveq   #1,D2
relo_do:
                add.l   D0,(A1)         ;relocate!
RELO2:
                move.b  (A0)+,D1
                beq.s   end_relocation
                cmp.b   D2,D1
                bne.s   normal_distance
                lea     254(A1),A1
                bra.s   RELO2
normal_distance:
                adda.l  D1,A1
                bra.s   relo_do
end_relocation:[/code]

So I guess you should grab the program from the pasti, load it (or unpack it) at the address you want, relocate it and apply any stuff from Was (not Was) to remove the protection bits or whatnot. Was' version doesn't have any relocate table, so it's pretty risky trying to relocate it yourself.

Hope this helps.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 12.04.12 at 12:01:27
Excellent, thanks for that, will give that a try when I get home.  I'll be able to crack it i'm sure, done a few ST titles in my time ;)

Thanks for that, should finally sort some of the display problems out :)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 12.04.12 at 12:48:21
Hi Galahad

you'll find quite a lot of old cracks are absolute.

Usually (Law might be able to chip in with more specifics) crackers ran the PRG through a monitor then saved it out as a binary file once they'd skipped protections etc. PRG's are relocated automatically when they are loaded into a monitor.

It all depends how Rob saved the file, if he left the relocation table in, it is possible to de-relocate the program.

Anyway I'll have a look at his version when I get in from work.

Did Amiga use a similar way to relocate exe's?

Shw

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 12.04.12 at 14:03:27

Shw wrote on 12.04.12 at 12:48:21:
Hi Galahad

you'll find quite a lot of old cracks are absolute.

Usually (Law might be able to chip in with more specifics) crackers ran the PRG through a monitor then saved it out as a binary file once they'd skipped protections etc. PRG's are relocated automatically when they are loaded into a monitor.

It all depends how Rob saved the file, if he left the relocation table in, it is possible to de-relocate the program.

Anyway I'll have a look at his version when I get in from work.

Did Amiga use a similar way to relocate exe's?

Shw


I don't specifically need to use Was (not was)'s version, as I know I can crack the original and thats files already, its only because i've been working with his version, but his is significantly altered from the original.

I can crack the original, and so long as I can force relocate the program file to a lower memory address, gives me all the room I need and means I don't need to use more than 512k chip ram, because I can then covert the Atari ST screen directly to Amiga in enough memory space (gotta love only 4 bitplanes!!)

I don't think theres any reloc information left in Was (not was)'s crack, but that doesn't bother me because I can start cleanly from the original.

On Amiga, all the reloc information is in the executable, and AmigaDOS sorts out the relocating before executing the program much like the ST does, but on the Amiga, the relocatable information can be quite big and complex.

Quite easy to build your own relocator, or a quick method is to use an absolute cruncher like Defjam, Tetragon or Double Action or anything like that, and then depack again.

I'll try the routine above, assuming it works, it'll solve the problem right away. :)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 14.04.12 at 10:29:03
Me again

Regarding the music.... I helped Mr Styckx convert many ST tunes to his MYST

See aminet "MYST_Data_1.lha"

the music is by Fred Gray, I'm not sure if it's one of the tune we converted, but if not I'm sure I'll be able to convert it to MYST (if my A1200 still boots), basically all it usually involves is redirecting the writes to the YM2149 to set data regs for the Miggy to handle.

Anyway let us know.

Grz
sndh.atari.org Maintainer

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 14.04.12 at 11:50:05

Shw wrote on 14.04.12 at 10:29:03:
Me again

Regarding the music.... I helped Mr Styckx convert many ST tunes to his MYST

See aminet "MYST_Data_1.lha"

the music is by Fred Gray, I'm not sure if it's one of the tune we converted, but if not I'm sure I'll be able to convert it to MYST (if my A1200 still boots), basically all it usually involves is redirecting the writes to the YM2149 to set data regs for the Miggy to handle.

Anyway let us know.

Grz
sndh.atari.org Maintainer



Yeah, be glad of the help, I know nothing of th YM chip, so any pointers will be useful, as i've got zero intentions of Amiga'fying this game other than simply getting it working and running on Amiga.

GGN's reloc routine was just the ticket, now got all the memory space I need for the Amiga screen and copperlist and all going well, all the code needed to actually run it in its original 512k setup.

At the moment i'm doing all the work using WHDLoad, as thats handy for address errors popping up due to accessing ST custom registers.

So sure, any YM related help will be much appreciated.

Its not much of a tune in the game, but its more to do with the sound fx as at key points in the game, certain sound effects trigger that are vital to progressing in the game (knowing when to move etc).


Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 15.04.12 at 19:13:36

Shw wrote on 14.04.12 at 10:29:03:
Me again

Regarding the music.... I helped Mr Styckx convert many ST tunes to his MYST

See aminet "MYST_Data_1.lha"

the music is by Fred Gray, I'm not sure if it's one of the tune we converted, but if not I'm sure I'll be able to convert it to MYST (if my A1200 still boots), basically all it usually involves is redirecting the writes to the YM2149 to set data regs for the Miggy to handle.

Anyway let us know.

Grz
sndh.atari.org Maintainer


Ready for that YM help whenever you can, game is now running on Amiga, all in 512k, so far all in a frame including conversion from ST interleaved to Amiga interleaved.

So far now screen problems with refresh rates, but we'll see what happens when theres more onscreen! ;)


Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 15.04.12 at 21:10:35
Ok. I'll look tomorrow. Aint done any my-st stuff for  7 years so bear with me ;) the driver plays the sound fx too which may be useful

Shw

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 15.04.12 at 23:12:13
http://www.youtube.com/watch?v=_WfBDEzmhdQ&context=C46496f1ADvjVQa1PpcFN8iKyOalxjna22vKYGa1pCrwo8npS_85w=


WIP

Title: Re: Either a force relocation packer or a routine to relocate
Post by ggn on 16.04.12 at 07:11:07
Cool :), although I never got into that game too much tbh.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 16.04.12 at 08:36:12

ggn wrote on 16.04.12 at 07:11:07:
Cool :), although I never got into that game too much tbh.


its being done largely because its one of the easier ones to convert.

Copy protection was a joke, all the files load easily, code is easy to read, its not obfuscated like C assembled code is.

Its also being done to simply remove it from the list of stuff that was never converted.

The big ones that people want are Oids and Sundog, but from my hazy memory they are VERY TOS system intensive games, so they'll take a hell of a lot more work.

Where time stood still has a surprising amount of hardware bashing for its age, with only two TOS accesses plus TOS accesses for fileloading.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Klapauzius on 16.04.12 at 08:42:52

Phill wrote on 16.04.12 at 08:36:12:

The big ones that people want are Oids and Sundog, but from my hazy memory they are VERY TOS system intensive games, so they'll take a hell of a lot more work.


For converting Oids, you could use my version, if you like.
All TOS calls have been replaced with 'TOS emulation' routines to make it independent of the host machine's OS.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 16.04.12 at 08:51:27

Klapauzius wrote on 16.04.12 at 08:42:52:

Phill wrote on 16.04.12 at 08:36:12:

The big ones that people want are Oids and Sundog, but from my hazy memory they are VERY TOS system intensive games, so they'll take a hell of a lot more work.


For converting Oids, you could use my version, if you like.
All TOS calls have been replaced with 'TOS emulation' routines to make it independent of the host machine's OS.


i think i'd like to see that mate, that could be very helpful :)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Klapauzius on 16.04.12 at 09:23:26
The game is here:
http://d-bug.mooo.com/klaz/Old_Games.html#Oids

Give me some time and I'll pm the sources to you.  :)
(at work right now).

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 16.04.12 at 10:17:17

Klapauzius wrote on 16.04.12 at 09:23:26:
The game is here:
http://d-bug.mooo.com/klaz/Old_Games.html#Oids

Give me some time and I'll pm the sources to you.  :)
(at work right now).


Thanks mate, that could be very helpful :)  And of course if this actually succeeds, you'll get a full credit for your part, as will the others with their help so far on Where Time Stood Still.

Still got the mouse code to figure out :(

Title: Re: Either a force relocation packer or a routine to relocate
Post by ggn on 16.04.12 at 10:31:24

Phill wrote on 16.04.12 at 10:17:17:
[quote author=12353829382C23302C2A590 link=1334222876/14#14 date=1334568206]Still got the mouse code to figure out :(


Phill, take a look at the IKBD manual: http://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?num=1280676368

Generally mouse packets come from the IKBD one byte at a time. The address that the ST uses for grabbing IKBD packets is $fffc02.w. The IKBD vector is at $118.w. Usually what happens in games is that they set up $118 to a custom routine, and when a ikbd interrupt occurs, that routine fires.

First thing that those routines do is to fetch a byte from $fffc02.w and figure out what type of packet they're getting. As you see from the ikbd manual, 0xF8-0xFB is relative mouse position records(lsbs determind by mouse button states), so if the routine detects this range, it fetches 2 more bytes that contain the delta x and delta y.

The only exception to the above is if the game programs the mouse to report absolute positions instead of relative, but this is very rarely the case and you can eliminate that by analyzing a couple of mouse packets using steem debug.

Hope this helps, but if you get totally stumped, give us a heads up :)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 16.04.12 at 18:30:59
Ok re-ripping it from scratch.. it's only 5kb :)

do you know how it passes sound fx to the driver ?

just booted up my a1200 for the first time in over a year, will take a while to get into it again :)


Shw

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 18.04.12 at 08:53:50
I'll try and look again tonight. But then I'm in Lisbon until Wednesday

Shw

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 18.04.12 at 19:25:26
Right then helpful chaps, heres the first routine I need help with so I can transpose to Amiga :)

I'm presuming that this is a keyboard check routine.

this one is called three different times, and D0 and D1 are used as parameters before the routine is called, and both are set to the same value.

So we have: $30, $a0 and $fa which I presume (i.e. i'm totally guessing!!) are parameters for different key presses or event checks.

or are they parameters for mouse button presses?

Haven't got a clue!


     lea      $fffffc00.s,a1
     lea      2(a1),a2
w1:      btst      #1,(a1)
     beq.s      w1
     move.b#$14,(a2)
w2:      btst      #1,(a1)
     beq.s      w2
     move.b  #$9,2(a1)
w3:      btst      #1,(a1)
     beq.s      w3
     clr.b      (a2)
w4:      btst      #1,(a1)
     beq.s      w4
     move.b  d0,(a2)
w5:      btst      #1,(a1)
     beq.s      w5
     clr.b      (a2)
w6:      btst      #1,(a1)
     beq.s      w6
     move.bd1,(a2)
w7:      btst      #1,(a1)
     beq.s      w7
     move.b      #$c,(a2)
w8:      btst      #1,(a1)
     beq.s      w8
     move.b      #1,(a2)
w9:      btst      #1,(a1)
     beq.s      w9
     move.b      #1,(a2)
w10:      btst      #1,(a1)
     beq.s      w10
     lsr.b      #1,d1
     lsr.b      #1,d0
     move.b      #$e,(a2)
w11:      btst      #1,(a1)
     beq.s      w11
     clr.b      (a2)
w12:      btst      #1,(a1)
     beq.s      w12
     move.b      d0,(a2)
w13:      btst      #1,(a1)
     beq.s      w13
     clr.b      (a2)
w14:      btst      #1,(a1)
     beq.s      w14
     move.b      d1,(a2)
w15:      btst      #1,(a1)
     beq.s      w15
     rts

Title: Re: Either a force relocation packer or a routine to relocate
Post by Klapauzius on 18.04.12 at 21:37:49
This routine sets up the keyboard controler to report absolute mouse packets. It's not a check routine.

The ikbd in the ST has two ways of reporting mouse actions by the user:

- the usual 'relative' mode, which will report delta values when the mouse is being moved (for example mouse has been moved 2 pixels up, etc.). In the relative mode each mouse action will automatically trigger an interrupt by the ikbd.

and

- the 'absolute' mode which is activated in your routine. This mode will send absolute mouse coordinates, not deltas. Important: in this mode you won't get an automated report when the mouse is moved or a button is pressed.
To get the current mouse position and button status you will have to inquire the mouse state.
This is done by sending a $d byte to the ikbd, which will in turn generate an interrupt by the ikbd.

Like in the code snippet you asked about on Atari-Forum.  ;)

$9 will activate this absolute mouse mode. The next four bytes sent afterwards define coordinate range.

The $c byte + the two bytes following set up the 'scale factor'. This will define how far the mouse must be moved by the user for a increment/decrement in the absolute coordinates to occur.

The $e byte + the rest will load an initial position for the mouse.

Read all about it here:
http://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?num=1280676368
 :)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 18.04.12 at 22:16:12
Galahad

Here's a BETA Amiga conversion of the ST music.

It should play in Eagle/Deli player.

It's not 100% but just gives you proof of concept. Need to tidy up Register #7 of the YM and also add the sound FX.

My first Atari YM to Amiga MY-ST conversion since 1997 :)

I'm back from travels next Thursday.

EDIT - The deli/eagle player is on Aminet but gives us a shout if you need it and I'll cross-dos it from my A1200

Shw
ym.wtss (Attachment deleted)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 18.04.12 at 23:14:01

Klapauzius wrote on 18.04.12 at 21:37:49:
This routine sets up the keyboard controler to report absolute mouse packets. It's not a check routine.

The ikbd in the ST has two ways of reporting mouse actions by the user:

- the usual 'relative' mode, which will report delta values when the mouse is being moved (for example mouse has been moved 2 pixels up, etc.). In the relative mode each mouse action will automatically trigger an interrupt by the ikbd.

and

- the 'absolute' mode which is activated in your routine. This mode will send absolute mouse coordinates, not deltas. Important: in this mode you won't get an automated report when the mouse is moved or a button is pressed.
To get the current mouse position and button status you will have to inquire the mouse state.
This is done by sending a $d byte to the ikbd, which will in turn generate an interrupt by the ikbd.

Like in the code snippet you asked about on Atari-Forum.  ;)

$9 will activate this absolute mouse mode. The next four bytes sent afterwards define coordinate range.

The $c byte + the two bytes following set up the 'scale factor'. This will define how far the mouse must be moved by the user for a increment/decrement in the absolute coordinates to occur.

The $e byte + the rest will load an initial position for the mouse.

Read all about it here:
http://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?num=1280676368
 :)


Thanks for that, so once that routine has been called, the interrupt at $118 then gets activated.

Does that interrupt stay active or does it automatically close when a mouse event has occured?

This is all completely bloody new to me!

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 18.04.12 at 23:44:28
Right, found the keypresses in the $118 interrupt:

F1, F2, Space, ST Help and ST Undo

Now to figure out which part is the mouse crap and obviously how it then processes that data to pass it to the game..... getting there slowly! :)

Another thing, does STEEM automatically remap mouse/joystick to cursor keys?

Title: Re: Either a force relocation packer or a routine to relocate
Post by Klapauzius on 19.04.12 at 10:49:14

Phill wrote on 18.04.12 at 23:14:01:

Does that interrupt stay active or does it automatically close when a mouse event has occured?


It will stay active, but, as mentioned above, the game will always have to poll the mouse state. There will be no automatic mouse report interrupts.
Keys will still be reported automatically via an interrupt.

In the game's ikbd routine, look for the place where the routine checks for an $f7 byte. This is the header byte for an absolute mouse packet. The game should set a flag somewhere to remember that. The next five interrupts following will report the absolute mouse packet proper, byte by byte.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Klapauzius on 19.04.12 at 10:52:30

Phill wrote on 18.04.12 at 23:44:28:
Another thing, does STEEM automatically remap mouse/joystick to cursor keys?


Yeah, I think this is the default setting for the joystick, not for the mouse though.
You can change the joystick settings to anything else, just click on the joystick button under Steem's main window title bar.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 19.04.12 at 12:45:18
Thanks for the help, its much appreciated.

Will convert the keyboard routine to Amiga tonight and then try and work on the mouse stuff.

I take it the routine I posted above is the routine to constantly poll the mouse?

Title: Re: Either a force relocation packer or a routine to relocate
Post by Klapauzius on 19.04.12 at 13:53:19

Phill wrote on 19.04.12 at 12:45:18:
I take it the routine I posted above is the routine to constantly poll the mouse?

No, it's just the setup routine which tells the ikbd to go into absolute mouse mode.
The polling is done by writing $d to $fffffc02 - it's the small routine you posted on AF.
The result of the poll will be deilvered in the ikbd interrupt. The routine pointed to by $118 must handle the results.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 25.04.12 at 19:20:15
I don't suppose the ST ever had anything like RESOURCE on the Amiga did it?  The ability to resource Atari ST executables back to source code?

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 25.04.12 at 21:43:25
back!

yes you need Easyrider v4.0, I find it more powerful than Resource

I'll look for a link

Shw

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 26.04.12 at 05:25:05

Shw wrote on 25.04.12 at 21:43:25:
back!

yes you need Easyrider v4.0, I find it more powerful than Resource

I'll look for a link

Shw


Top bloke :)

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 26.04.12 at 10:48:59
here's Easyrider

it will automatically dis-assemble any file. It will relocate programs using the relocation table which most exe's have at the end of the file. However if you want it to relocate a binary file you'll need to set the load address with Control-V (virtual start) , you then need to use Control-U to change the binary to understandable code. Any probs give me a shout.

Shw
https://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?action=downloadfile;file=easy4.rar ( 78 KB | Downloads )

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 28.04.12 at 12:15:27
Thanks for that, does the job spot on :)

Now, so I can start tracking code down without too much farting about, any chance when someone gets time can you post me a routine that

a). Reads Left mouse button press
b). Reads Right mouse button press


Title: Re: Either a force relocation packer or a routine to relocate
Post by alexh on 16.01.14 at 12:58:23
Nice work remembering how to do the MyST conversion. FYI, WTSS was already ripped in MYST_Data_4.lha under MISC.

Did Phil need the ym.wtss file at all? He's running the ST game code (patched) so presumably he could find the original ST play routine in the code and then redirect writes to the YM register addresses to the MyST emulator's data buffer?

Speaking of which I don't suppose you know how to use the YM2149.bin included in the main MyST archive? There are no examples of how to use it in your Amiga programs.

I've emailed Nicholas but no reply yet.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 21.01.14 at 07:29:33
Yeah I created the ymst for wtss but never heard anything back from Galahad :(

Yeah playing the file on the Amiga is just a matter of patching the 2149 writes

I'm sure the docs and code are on aminet

If not I've got em somewhere.


Title: Re: Either a force relocation packer or a routine to relocate
Post by alexh on 22.01.14 at 22:38:54
The docs on how to use the MyST emulator are not in the aminet archive. just a binary file YM2149.bin

Galahad has three threads open over at eab.abime.net

If you have the docs of how to use MyST that would be awesome. Nicolas said he'd fire up his ST one last time but not for a few weeks.

Anything would be cool.

Title: Re: Either a force relocation packer or a routine to relocate
Post by Phill on 23.01.14 at 10:30:29

Shw wrote on 21.01.14 at 07:29:33:
Yeah I created the ymst for wtss but never heard anything back from Galahad :(

Yeah playing the file on the Amiga is just a matter of patching the 2149 writes

I'm sure the docs and code are on aminet

If not I've got em somewhere.



Sorry dude, went on a bit of a hiatus, after I released Putty Squad, got the bug to continue and made more progress with WTSS in 1 day than I had before, so i've more impetus to get it done now, and a couple of people have it running on Amigas so now i've got to finish it! ;)

Any help would be great, i've still got the tune you ripped, but theres no docs that tell me how to implement the player :(

Title: Re: Either a force relocation packer or a routine to relocate
Post by Shw on 24.01.14 at 12:45:03
Hi

Here is my Where Time Stood Still Amiga player

I've simply copied all the files from my A1200... I'm a bit rusty with the Amiga tho, I couldn't even remember what keys to press to cycle windows!!

Just assemble the source file. Hopefully you'll be able to fathom out how to include it in the game.

Phil

https://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?action=downloadfile;file=ym2149.zip ( 30 KB | Downloads )

D-Bug & Automation Forum » Powered by YaBB 2.6.0!
YaBB Forum Software © 2000-2022. All Rights Reserved.