English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 18 January 2016, 01:17   #1
copse
Registered User
 
Join Date: Jul 2009
Location: Lala Land
Posts: 522
Resource tips

You can refer to a label at a resource address as '\e0$2A890\e' in, for instance, the symbol entry text field you get when you press 'v'. And let's say $2A890 is in A5, and you have an offset you want to handle (e.g. $2000 or -$184). First you need to go to the address the offset corresponds to, and make a label - it doesn't matter what. Then you can refer to the address for the offset and have it automatically pick up the label, and therefore any changes to the label. But it doesn't appear to work unless both addresses have labels.

e.g. $2000(A5) where A5 = $2A890 (with label JTD1_02A890).
  • The actual referenced address is $2C890.
  • Press 'F10' to remember the current position, then 'CTRL+n' and enter $2C890.
  • Press 'SHIFT+KPENTER' and enter a label name, e.g. 'SomePtr'.
  • Press 'RIGHT CURSOR' to return to the original location, and press 'v' and enter as the symbol value '\e0$2C890\e-\e0$2A890\e'.
  • Observe 'SomePtr-JTD1_02A890(A5)' as the operand.

Now you can change these label names at will, and they will be dynamically updated. This is useful when the program doesn't follow the C model of using the same address register globally, which the more general Convert (xx,An) EA functionality would be useful for.

This can be used in data statements, as well as for operand symbols, as well as generally pretty much everything up to and including comments. While the 0 refers to labels, you can use other numbers to refer to symbols and comments.
copse is offline  
Old 18 January 2016, 21:40   #2
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,343
A similar thing can be achieved like this:

If A5 (say) is pointing to SomeLabel and code references offsets relative to that, e.g. move.l ($1234,A5),D0
Move to SomeLabel and press Ctrl-Shift-Alt-1.
Move back to the move.l ($1234,A5),D0 instruction. Press Ctrl-1. That should create a label at SomeLabel+$1234 and replace the $1234 in the instruction disassembly with (LabelName-SomeLabel,A5).

That technique is useful for jump tables too.

You can have three base addresses defined and convert instructions with a different base address (e.g. Ctrl-Shift-Alt-2 and Ctrl-2 set and convert with the second base address). The key presses are equivalent to the *⇒Convert specific EA's⇒Set base #X and *⇒Convert specific EA's⇒Cvert W/base X menu items.

Last edited by mark_k; 18 January 2016 at 21:50.
mark_k is offline  
Old 18 January 2016, 23:15   #3
copse
Registered User
 
Join Date: Jul 2009
Location: Lala Land
Posts: 522
Quote:
Originally Posted by mark_k View Post
A similar thing can be achieved like this:
Hmm, I have a suspicion the macro I wrote to do the above, has been made obsolete by your suggestion. It was quite painstaking, especially since this seems to be a buggy part of Resource v6.06 where it will get itself into states where things don't work in the macro authoring, which work outside of it.

Ouch. Just tested it. It does exactly the same if it creates labels, which I assume it does.

Quote:
0. Store the base address.
S/STRINGS/Define string/B
STORE "$2A890"
1. Remember current cursor position.
C/CURSOR/Remember $002C [F10]
"Push" the current cursor location on ReSource's location stack.
2. Get symbol value from the selected field on the current line to the accumulator.
S/STRINGS/Get/Symbol value $020E
Copy the symbol value from the selected field on the current line to the
accumulator.
3. Add the base offset to the accumulator to get the label address which should be referenced.
... adding a negative offset will fail, so we drop out of the conditional to handle that
... otherwise, we skip the handling
MACROS 1/Directives/Start conditional
... add the base address to the accumulator.
S/STRINGS/Maths functions/Add $022E
STORE "\eB"
You will be asked for a number, to be added to the accumulator. If a carry
results, a macro 'fail' will occur.
MACROS 1/Next macro label/#1
MACROS 1/Directives/End conditional
... Can't add the negative offset, so negate it, and subtract it from the address.
... a) the failed add clobbers the offset with the address
S/STRINGS/Get/Symbol value $020E
... b) negate the offset
S/STRINGS/Maths functions/Negate
... c) store for subtraction in buffer A
S/STRINGS/Swap with buffer/A
... d) put base address in accumulator
S/STRINGS/Math functions/Clear
S/STRINGS/Math functions/Add
STORE "\eB"
... d) subtract offset (buffer A) from base address (accumulator)
S/STRINGS/Maths functions/Subtract
STORE "\eA"
MACROS 1/Set macro label/#1

4. Go to the desired label address.
C/CURSOR/Absolute/Specify offset $01AD [ctl]+[n]
STORE "\e\e"
You will be asked to supply an offset representing how far from the start of
the file, the cursor location should be. The number may be specified in
hexadecimal, decimal, or binary. If hexadecimal, the string must start with
"$", if binary, it must start with "%".3. Make a label if one does not currently exist.
5. Store the accumulator value in buffer A.
S/STRINGS/Swap with buffer/A
6. Create a "shop" label if one does not exist.
MACROS 1/Directives/Start conditional
S/STRINGS/Get/Label $0209
-- Note that this does nothing. It should fail and bail out to the replace label, but I dont't think it does.
If there is a label defined at the cursor location, it will be copied to the
accumulator.
L/LABELS/Create single/Label - fwd ref $0034 [F6]
The current line of code will be searched for references to positions within
the current file. If any are found, ReSource will make a decision on which
type of data is at the position referenced. It will then set the
data type (unless it has already been set), and create a label at that offset
(unless a label has already been defined for that location). This new label
will be immediately used for all references to that location, which of course
includes the reference within the current line. If there are no references,
or there is a reference, but it is outside of the range of the current file,
then this function will do nothing. Normally, this function will only be
used within macros, as the "PROJECT/Disassemble" normally will create all
necessary labels.
MACROS 1/Next macro label/#2
MACROS 1/Directives/End conditional
7. If there is no label we arrived here. So create a generic one OR ask the user.
L/LABELS/Replace single/Label $0184 [F4]
Create a "shop" label at the cursor position. A "shop" label is one that is
9 characters long, begins with "lb", has the data type immediately following,
and ends with the code offset. It may also be of some other length, and end
with ".MSG".
The "data type known" attribute will be set also.
8. Allow skipping replacing the label if there already is one.
MACROS 1/Set macro label/#2
7. Return to last stored location on the stack.
C/CURSOR/Absolute/Previous location $8x3F [leftarrow]
"Pop" the cursor location from the top of the cursor location stack. If the
stack is empty, a macro "fail" will result.
6. Build the symbol to put in the selected field on the current line in the accumulator.
S/STRINGS/Define string/Acm
STORE "\e0"
S/STRINGS/Edit functions/Append $0208
STORE "\eA"
You will be asked to supply a string, which will be appended to (added to the
end of) the accumulator, providing that the resulting string is no longer
than 240 characters
S/STRINGS/Edit functions/Append $0208
STORE "\e-\e0"
S/STRINGS/Edit functions/Append $0208
STORE "\eB"
S/STRINGS/Edit functions/Append $0208
STORE "\e"
7. Put the accumulator as the symbol for the selected field on the current line.
L/LABELS/Create single/Symbol $0359
STORE "\e\e"
You will be asked to supply a string, which will replace one of the numbers
on the current line. A symbol may be created for the first, second, third of
fourth number on the current line.
copse is offline  
Old 19 January 2016, 21:37   #4
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,343
That's quite a complex macro! I never really did much with ReSource macros, apart from automating tedious/repeated things (no conditional/advanced stuff). Maybe developing that macro was a good learning experience, even if you were reinventing the wheel a bit!

Some more comments about the set/convert w/base feature...

You can have up to three bases set at a time. It's not three fixed bases per disassembly though, just three currently-set bases that you can convert with. So if you set base 1 and convert a jump table, later on you can set base 1 to the address of another jump table and convert that too, without the first jump table disassembly getting altered/messed up.

A technique I like to use when disassembling stuff is to add a BSS hunk to the executable before loading it into ReSource. (Maybe I mentioned that in another thread a while ago?)

I use space in the BSS hunk to define structures which the program code uses, then the convert w/base feature to convert structure offsets in the code to something more readable. (I prefer doing that to using a custom symbol base, since in some cases you add structure field names as you proceed with the disassembly, and it's much easier to do that that repeatedly modify/reassemble/reload a custom symbol base.)

For example, let's say a program uses a NewWindow structure. Somewhere in the dummy BSS hunk I might have a label NewWindow. [Okay not a good name for an example, this is mainly for non-standard structures.]

If the code does move.w #123,(2,A0) when A0 points to a NewWindow struct, I'd convert that reference (Ctrl-Shift-Alt-1 at NewWindow label then Ctrl-1) to read move.w #123,(lbWxxxxxx-NewWindow,A0) then rename the auto-generated label to TopEdge, so the disassembly would become move.w #123,(TopEdge-NewWindow,A0).

If later on you rename any of the structure field names, renaming the label will cause all mentions in the disassembly to change to the new name.

A more concrete example. If you're disassembling a SCSI device driver, the driver code might use references relative to its library base, and also to its private unit structure. You could set base 1 to be the library base (label in dummy BSS hunk), and base 2 to be the unit structure (another label in dummy BSS). Then go through the code doing Ctrl-1 and Ctrl-2 where appropriate.

[I hope that made some kind of sense..?]

Last edited by mark_k; 19 January 2016 at 22:28.
mark_k is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Soldering tips Viserion support.Hardware 30 26 July 2013 15:54
Want some A2000 tips 'n tricks! 8bitbubsy support.Hardware 15 24 February 2011 04:30
Amberstar general tips Rixa Retrogaming General Discussion 1 28 August 2010 23:21
Searching magazine tips? Digideus AMR contributions 4 12 March 2008 00:24
..game tips?! poppe Retrogaming General Discussion 4 28 March 2002 20:47

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 14:39.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13354 seconds with 13 queries