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: 404
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: 1989
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: 404
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
Apollyon/ALD
Didi/Laxity
Acidchild/Padua
Avalanche/Atlantis
Krill/Plush
MAT64
csio/monarchy c+4
v3to/Oxyron^PriorArt
MCM/ONSLAUGHT
mutetus/Ald ^ Ons
Guests online: 129
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.8)
4 Acidchild  (9.7)
5 Starlight  (9.6)

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