Goldensunboy
Random nobody
Level: 8
   

Posts: 5/9
EXP: 1976 For next: 211
Since: 08-30-07
From: Georgia
Since last post: 14.0 years Last activity: 13.9 years
|
|
I couldn't quite make heads or tails of the readme, because I only know a minimal amount of 65816 ASM. I know enough to make neat features in SMW, but still - not much ASM knowledge is required for that.
I wanted to know if someone could tell me how to define a different destination address for JMP's in TRASM. I will usually work on a text document called Code.asm, then drag the file over TRASM.EXE to produce a code.bin file. I then copy the code as a hex string in code.bin, then paste it over a destination in SMW called by LevelASM.
My problem is, a code I'm currently working on is very large, and branches simply aren't long enough to jump between certain places in the code. I have to use JMP's to move long distances through the code, but when I compile Code.asm with TRASM, it will reference the JMP's to their destination, relative to the beginning of Code.bin. When I paste Code.bin into my SMW hack, I then have to manually (and painstakingly) find and redirect each JMP relative to the ROM bank. When I made Bowser's Puzzle Challenge, I had to redirect a few JMP's with the Rubik's Cube every time I compiled the code to test it, but with this code I'm currently working on there are simply too many; manually fixing each one will be too tedious.
See, it turns out something like this... (rough example, but it works)
Code.bin~
$00:0000: LDA $57 [AD 57 00]
$00:0003: CMP #$00 [C9 00]
$00:0005: BNE END [D0 2A]
$00:0007: JMP CODE [4C 38 00] <-References code at $00:0038
$00:000A: ...
$00:0035: ...
$00:0037: "END" RTL [6B]
$00:0038: CODE
Pasted to LevelASM location in SMW.smc~
$07:157C: LDA $57 [AD 57 00]
$07:157F: CMP #$00 [C9 00]
$07:1581: BNE END [D0 2A]
$07:1583: JMP CODE [4C 38 00] <-References $07:0038, not $07:15B4
$07:1586: ...
$07:15B1: ...
$07:15B3: "END" RTL [6B]
$07:15B4: CODE
I'm looking for a way to, say, in the above scenario, tell TRASM to compile it so JMP's are written as if the first byte in Code.bin was at location $07:157C instead of $00:0000. Possibly some short line at the beginning fo the Code.asm file? Or is it something that must be done with actions in Command Prompt? Thanks, help would be greatly appreciated.  |
Post 193/1311 ( 41 days),
online 1 day ago
|
|
 I don't know about TRASM specificaly, but assemblers usually have a "org" instruction that tells the address, which would be what you need:
;offset would start at $0000 here
org $157C ;offset is now $157C (but still $0000 in the assembled output)
JMP aaa ;'aaa' = $157F
aaa:
LDA $57
...
____________________
|
#64 |
|
Goldensunboy
Random nobody
Level: 8
   

Posts: 6/9
EXP: 1976 For next: 211
Since: 08-30-07
From: Georgia
Since last post: 14.0 years Last activity: 13.9 years
|
|
Thanks for the help! TRASM did mention "ORG" in the readme on syntax, but I had no clue what it was for.
So, if I stick "ORG $157C" at the beginning of Code.asm (which would eventually be pasted to $07:157C), the JMP's would be calculated as if the starting address of Code.asm was at $XX:157C? It would turn "JMP CODE" (CODE at $00:0038) to "JMP [$00:15B4]"? |
smkdan
User
Level: 12
   
Posts: 15/21
EXP: 7067 For next: 854
Since: 07-28-07
Since last post: 13.0 years Last activity: 13.2 years
|
|
| ORG will do the job here, but it'll also change the place in the .bin you'll have to grab it from, since ORG affects where it writes to the file. xkas has a "base" command that changes how labels are calculate with changing where it is placed in ROM, so you could org 0 to place it at the start of the file and base $[address in ROM where you're inserting]. I don't know if TRASM has an equivalent (MUST you use TRASM? In the 14 years since it's release we've had much better alternatives), but if it doesn't you have to manually grab the data out of the output. |
Goldensunboy
Random nobody
Level: 8
   

Posts: 7/9
EXP: 1976 For next: 211
Since: 08-30-07
From: Georgia
Since last post: 14.0 years Last activity: 13.9 years
|
| Posted on 05-14-08 05:59:06 AM (last edited by Goldensunboy at 05-14-08 02:59 AM) |
Link | Quote
| |
I'm simply using TRASM because it's quick and easy to use, and it's convenient that it comes with Sprite Tool. My ROM has to be in the same folder as Sprite Tool anyway, so I just edit and compile my code there. (my next ASM mini-hack, probably finished in a week or two, will use at least 2 custom sprites to get the elements working properly) ORG $D000 did the trick, because my code was really starting at $1E: D000 in the ROM... TRASM is at least compiling the JMP's correctly now, and I'm working on the code again.
And thanks, I didn't know TRASM was outdated. I will look for a more recent version once I have this current ASM mini-hack finished. |
Post 195/1311 ( 41 days),
online 1 day ago
|
| Posted on 05-14-08 05:59:18 AM (last edited by Acmlm at 05-14-08 03:02 AM) |
Link | Quote
| |
 I use ca65 (for 6502 though, but apparently it does 65816 as well), which has another way to do this, using segments ... it gets a little more complicated to use, but it goes like this:
.cfg MEMORY
{
memtest: start=$8000, size=$4000, file="test.bin", fill=yes, fillval=$FF;
}
SEGMENTS
{
test: load=memtest, type=ro;
}
.asm .setcpu "65816"
.segment "test"
code goes here
commandline for assembling ca65 test.asm -o test.o
ld65 -C test.cfg test.o
This would output a "test.bin" of size $4000, with offsets counting from $8000, and unused space filled with FF's ... of course you wouldn't need the fixed size here, but something like this (using multiple segments) is quite useful when assembling a ROM with multiple banks, or even the NES's vectors (always at $FFFA) 
____________________
|
#64 |
|
Goldensunboy
Random nobody
Level: 8
   

Posts: 8/9
EXP: 1976 For next: 211
Since: 08-30-07
From: Georgia
Since last post: 14.0 years Last activity: 13.9 years
|
|
Well, I've got another problem. With the code I'm working on, I'm trying to set up a small system that counts by branching in a loop until a certain point, but even though it seemed as if I put it together properly, Geiger's SNES9X debugger gave me this:
$14/A36A DA .. | PHX ........... | A:0709 X:00B3 Y:00E8 P:envMXdiZC
$14/A36B 8A .. | TXA ........... | A:0709 X:00B3 Y:00E8 P:envMXdiZC
$14/A36C A2 00 | LDX #$00 ...... | A:07B3 X:00B3 Y:00E8 P:eNvMXdizC
$14/A36E C9 0D | CMP #$0D ...... | A:07B3 X:0000 Y:00E8 P:envMXdiZC
$14/A370 30 06 | BMI $06 [$A378] | A:07B3 X:0000 Y:00E8 P:eNvMXdizC <- ????????
$14/A378 2A .. | ROL A ......... | A:07B3 X:0000 Y:00E8 P:eNvMXdizC
I started off by pushing X (this routine is a JSR from a branch loop using X to count, so I wanted it to be safe), then I transfer X to the accumulator and store a #$00 to X.
I then compare A with #$0D and try to branch into another routine if A is smaller than #$0D, but even though it's larger, it branches anyway for some reason. Err, help? I would think it has something to do with that P:eNvMXdixC stuff, but I have no clue what any of that is, besides the carry flag. |
smkdan
User
Level: 12
   
Posts: 16/21
EXP: 7067 For next: 854
Since: 07-28-07
Since last post: 13.0 years Last activity: 13.2 years
|
|
Don't use BMI / BPL for greater or less than comparison, use BCC and BCS. BMI works using the 'N' flag (which is set here) which comes from the high bit of the result, which is set in this case.
LDA #$F0
CMP #$F1
BCC WillAlwaysBranch
|
Goldensunboy
Random nobody
Level: 8
   

Posts: 9/9
EXP: 1976 For next: 211
Since: 08-30-07
From: Georgia
Since last post: 14.0 years Last activity: 13.9 years
|
| Posted on 05-20-08 09:03:34 AM (last edited by Goldensunboy at 05-24-08 11:58 PM) |
Link | Quote
| |
Thanks for the help you've given me so far Acmlm and smkdan, this topic sure has strayed quite far from its original intent.
I have yet another problem... I was running a modified form of a sprite-spawning code mikeyk gave me on incarnation 3, and it was giving me all sorts of problems. I spotted most of them by tracing and fixing it up, but something started happening that I couldn't find; it was crashing the game. I logged the CPU to find this, which seemed utterly bizarre to me:
$1E/D38A C9 08 .. .. | CMP #$08 ............. | A:0002 X:00B3 Y:0008 P:eNvMXdizc
$1E/D38C F0 09 .. .. | BEQ $09 [$D397] ...... | A:0002 X:00B3 Y:0008 P:eNvMXdizc
$1E/D38E A9 0F .. .. | LDA #$0F ............. | A:0002 X:00B3 Y:0008 P:eNvMXdizc
$1E/D390 8F 03 FF 7F | STA $7FFF03 [$7F:FF03] | A:000F X:00B3 Y:0008 P:envMXdizc
$1E/D394 4C 05 D0 .. | JMP $D005 [$00:D005] . | A:000F X:00B3 Y:0008 P:envMXdizc <- $1E:D005???
$14/8DFC B5 9E .. .. | LDA $9E,x [$00:00A6] . | A:0000 X:0008 Y:00E8 P:envMXdiZC
$14/8DFE 6B .. .. .. | RTL .................. | A:0036 X:0008 Y:00E8 P:envMXdizC
Isn't "$1E:D394 | JMP $D005" supposed to jump to $1E:D005, instead of $14:8DFC? I can see why it crashed; it's supposed to jump to an address that finished some pushes/pulls, and the unfinished pulls screw up the stack pointer for returns because this is jumping somewhere random in the rom. (come to think of it, the messed up stack doesn't even matter since it's jumping somewhere random anyway in the first place)
So it seems that logging the CPU alone doesn't log every individual opcode... I will continue to look into my routine's problem. |
Sukasa

Level: 123
   
Posts: 340/4326
EXP: 20935572 For next: 295694
Since: 07-07-07
Since last post: 1.1 years Last activity: 1.1 years
|
|
 | Profile | Send PM | Real Life Comics
p2pnet.net
My Site | You ran a trace? Try this instead:
Set an execution breakpoint on 1ED005, then when you hit that line, spam-click the 'step into' button, then copy the code out of the textbox and post it here.
____________________
|   |
|
|