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 > Hermit Reloc-aid
2009-11-03 15:51
Hermit

Registered: May 2008
Posts: 208
Hermit Reloc-aid

Dear Mates

Recently I had some tunes to be relocated.

As I couldn't find any appropriate tool to relocate
these old tunes (Galway, Joseph Richard, Hubbard,...),
I had to start writing a universal relocator.

Now it is useful to relocate the tune automatically,
leaving only some minor changes left for the user (coder), like setting pointers used for zeropage-indexed memory-calls.

If anyone need the code, I can upload it or send it as source code or as compiled code. It's NOT a COMPLETE TOOL, as doesn't include any loader/setting parts, settings and load/save can be done within assembler/IDE/monitor..
(I use 64tass cross assembler for fast work + VICE+Final Replay cart-image.)
The name 'Reloc-aid' comes from the fact that it saves much work for you, but doesn't do all the stuff. I had success with it for really old tunes, maybe you'll also have with enough reverse-coding/disassembling knowledge.

I'll tell what the workflow is, to get a tune relocated:
-------------------------------------------------------

-It distinguishes which is data, which is code, which data/code isn't used, and first makes a 'mask' with this information. (This is PASS1, the maskmaker...)
How this works?
Of course it runs the selected subtune, and breaks it at every command with an exactly timed one-shot CIA interrupt (on a non-badline!). I recommend to use VICE in warp+nosound mode here, as it takes a while for the tune to end or loop.
(The maskmaker takes the addressing-mode of command-opcodes from my pre-defined table.) Maskmaker simply ends with RUNSTOP-key.

-At PASS2 it simply changes all the absolute-addressing operands (addresses), even indirect-JMP addresses. This was the easy part, without much interaction needed from user.
(At relocation the mask is copied back to the source-range, and if you set, the unused areas remain zero (!) at target location for better compression later.)
Here I recommend to save the relocated tune and especially the mask to prevent doing PASS1 again.)

-PASS3: However (depending on tune) some pointers left unchanged in memory (used for zeropage-indexed (Y) instructions). These are hard to determine by software (this would need to virtually 'rewind' the CPU), but at least I made a function (follow mode 3) to run the relocated tune again, and stop it at every memory reads/writes that are still addressing memory in the original (source range) place.
At this stop user is prompted about the PC address, command, operand, registers.
The manual work starts with freezing/resetting the machine, and search+modify the pointers in memory. This needs well skilled coding knowledge, who did relocation before know what I mean.
Here the register/pointer info and mask can help a lot (with 'h' command of monitor, you can find self-writing codes or zeropage-pointer modifiers in the mask therefore also in routine).
After eliminating a 'stopping point', you have to start the tune again in this mode, and it will stop again, if the outside-call appears again.
You have to repeat this ('stop'+'search'+'modify'+'restart') process until all remaining (wrong) pointers are corrected by you. I recommend to save/write down the modifications that ended with success.
(Generally I found around 4...20 databytes in tunes that had to be changed manually after PASS2).

Here we are ready, our tune can be used in our proggy.

Appendix :)
-----------
the PASS1 recognises and signs these types into the 'mask' (this is an extract from sourcecode-comment):
;---------
;PASS1 ;write modifying-mask into target area
;mask: 0:will be left at moving, no used code/data here (shrinked parts)

;command/operand bytes (section 1.)
; 1-code/operand byte, that we'll never modify
; 2-absolute operand-bytes pointing into source range, always modify!
; 3-..(indirect operand pointing into source range)
; 4-..operand of immediate addressing command, maybe modified if affects indirect 0pg-pointer

; 5-absolute addressing command-byte, don't modify
; 6-..command-byte for indirect addressing (point 3) , don't modify
; 7-..immediate addressing command-byte , don't modify

;data-bytes
; 8-absolute/absX/absY/indirect addresed databyte, don't modify
; 9-zeropage-indirect X/Y indexed databyte,don't modify
; a-..(pointer-hi databyte, modify)
; b-..(pointer-lo databyte, modify)

;command/operand bytes (section 2.)
; c-zeropage writer command ('L')
; d-operand of zp-writer command ('M')
; e-zp-pointer modifier STA/STX/STY ('N')
; f-self writing code (operand modifier (absolute addressing) command)

If there's interest for this 'aid' (not 'tool') I'll upload it onto my homepage or CSDB (source+binary).
You may ask for it in this topic.

I use it with 64tass & VICE like this:

http://hermitsoft.uw.hu/doc/Hermit-reloc-aid.jpg

----------------------------------------------
Hermit Software Hungary
2009-11-03 20:15
NecroPolo

Registered: Jun 2009
Posts: 231
I must express my gratitude to Hermit for creating this intelligent code in no time to save my project. I could check the final results and the way this code works is stunning. It solved seemingly impossible problems. When the time comes, you will see of what and why.

The actual release that indicated this wonderful code aid will be released soon. Hopefully it will be something that you can enjoy - but this little intelligent tool is that really deserves the attention.

So does Hermit, the man behind. It is not about knowledge, rather about an admirable attitude of solving impossible things.

So, congrats for this cunning piece of code!

Regards,

NP
2009-11-04 09:21
Ninja

Registered: Jan 2002
Posts: 411
I don't want to spoil the enthusiasm here and surely applause for the energy to solve an interesting problem. I just wonder: What's wrong with using a reassembler? Define code section, define data-section, reassemble -> Voila, you can do everything you want with the tune, even optimize the player.
2009-11-04 10:09
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: I don't want to spoil the enthusiasm here and surely applause for the energy to solve an interesting problem. I just wonder: What's wrong with using a reassembler? Define code section, define data-section, reassemble -> Voila, you can do everything you want with the tune, even optimize the player.

Well, this tool actually automatically detects the data section and what is unused. I'd like to see a cross development version of this which uses a simple 6502 emulator to get the write-mask instead.
2009-11-04 10:13
V-12

Registered: Nov 2003
Posts: 206
I've started to relocate music around 2000 and always used Turbo Reassembler to create source code of the tune and next I've been relocating to $1000. Even few my relocations can be found in hvsc, for example /GAMES/G-L/Lode_Runner.sid :)
At that times we needed $1000 tunes for notemakers because we've been swapping heavily :D

Personally it would be hard to code an universal relocator. If you will make it, you are the master :)
Try to beat Tim Follin's player or Jonathan Dunn, you will get confused like hell.
2009-11-04 11:19
Ninja

Registered: Jan 2002
Posts: 411
JA: There is something like this called "siddiag", a HVSC tool. Somebody from HVSC: Is this distributable?
2009-11-04 21:56
Hermit

Registered: May 2008
Posts: 208
Dear guys, it's good to hear some Reassemblers are quite good in separating data from code. It can even help with tunes that has frequent change in code/data.
Unfortunately before writing this 'tool' I couldn't find any disassembler/reassembler that coud help. (At the moment Rosetta is the best I have, and I didn't find the way in it...)
I would be thankful, if some of you could give me a working link for Turbo reassembler, or the others.. I would like to try them for relocation.

(And who knows, in the near future a full automated relocator may come out...;)

The source and the compiled version is now uploaded here at CSDB. Maybe it's worth a try for some of you...

Reloc-aid

Hermit Software Hungary
2009-11-04 23:05
Steppe

Registered: Jan 2002
Posts: 1510
@Ninja: It USED TO be "closed circle ware", but after 10 years and seeing the original author probably doesn't care anymore... hm...

If you just want to determine the memory range a tune uses you can use the modified sidplay2 version included in my Ripping for Dummies tutorial to be found here:#http://hvsc.c64.org/Help/Ripping_For_Dummies.zip

The output is identical to siddiag, only it doesn't determine playtime.

2009-11-05 19:11
Hermit

Registered: May 2008
Posts: 208
Many thanks for the hacked sidplay, Steppe. (It works similarly, also makes a mem-usage mask :)
The PDF is a very useful documentation.

ATTENTION!!

New C64 models use new CIA chip, which switches interrupt-flag one cycle earlier than the old.
Well, as I said, Reloc-aid is using ,well timed oneshot-CIA timer interrupt'. However new C64's CIA isn't 'well timed' in this case because they are 'faster'-therefore they make the IRQ before the command could start-resulting in black screen.
I had to increase the oneshot-timer by 1 (to 9). Now the Reloc-aid works fine also on new C64, I tried it on some..

I uploaded a new zip file with the modified CIA-timing. It works well now on new C64, and it seems also good on the old one!

Here is the direct link:

http://noname.c64.org/csdb/release/download.php?id=106418

Hermit Software Hungary
2009-11-05 19:20
ice00

Registered: Apr 2002
Posts: 54
For Linux people you can even use JC64dis and the given patch for SIDLD that use the same method of Siddiag (it was a courtesy of Michael S. that gave me idea/code behind that program): http://sourceforge.net/projects/jc64/files/binary/last/jc64dis-..

Disassembler is in Java, but SIDLD is a C++ application (don't know a public repository for this after Geocities Sid Page is gone, so only the already-patched Linux executable is available inside the zip).

To be in topic: very good work Hermit!!
2009-11-05 19:39
Hermit

Registered: May 2008
Posts: 208
Hi, ice00

Thanks for giving the link, I found this java application very good for exploring tunes. (I used Rosetta+wine before..)
Now it's running easily in Linux terminal, and it's more suitable for work :)

Hermit Software Hungary
 
... 8 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - Next
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
Dan
Metal Maniac/Dual Crew
McGurk/Coma
Xiny6581/Dees Produc..
csabanw
Morpheus/IPC+C64.COM
E$G/HF ⭐ 7
El Jefe/Slackers^sidD
algorithm
MWR/Visdom
Brataccas/HF
Guests online: 115
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 Layers  (9.6)
2 No Listen  (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 Graphicians
1 Mirage  (9.8)
2 Archmage  (9.7)
3 Pal  (9.6)
4 Carrion  (9.6)
5 Sulevi  (9.6)

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