MESS Emulator debugging Script

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
Okie
Interested
Posts: 37
Joined: Wed Jun 30, 2021 7:31 pm
Location: United States Of America

MESS Emulator debugging Script

Post by Okie » Sun Aug 15, 2021 11:53 pm

I thought this might be interesting to share for debugging the SEGa Genesis. I was tinkering with the Emulator Mess and was thinking how can I trace lines / or break, only when the instruction is jsr. I got thinking...

I realized JSR binary form is this format:

0100 | 1110 | 10 Mode Mode | Mode Registr Register Regiser|

Mode are bits for the Mode Register are bits for the register

I realized that there are only so few combinations. What I realized was:


0100 1110 (0x4E) is always the highest byte.

The Next bytes is next... bit 7 and 6 are 10. bit 5 and 4 are only a few combinations for JSR. This makes this bytes upper nyble have only a few combinations:
1001 (0x9)
1010 (0xA)
1011 (0xB)


So, for the instruction to be some form of JSR: ( Relating to said instructions binary form )


1. The first byte is 0x4E

Condition is b@(pc) == 4E

2. The next bytes upper two bits ( bits 7 and 6 ) are 0010 or 0x2

So to get these upper two bits

First I isolate the upper nyble of this second byte like so

b@(pc + 1) >> 4

To extend on this, I want to isolate just the upper two bits of this so I do

(b@(pc + 1) >> 4) >> 2

So I used the expressions that MESS allows to set a watchpoint for the entier ROM (say 0FFFFF) , to break only when these two conditions are met like so:

wpset 0,0fffff, rw,b@(pc) == 4E && ((b@(pc+1))>> 4 >>2) == 2

This could easily be applied to other instructions as well :).
What do ya'll think how it could be applied. Is there easier ways to search for a certain code in assembly ( say you are doing a dissasembly ) like a main game loop and its array where you jsr Arrray(pc,d0) in sonic the hedgehog mainloops?
You can also set it to print program counter address every time the instruction is JSR to a text file.

Okie
Interested
Posts: 37
Joined: Wed Jun 30, 2021 7:31 pm
Location: United States Of America

Re: MESS Emulator debugging Script

Post by Okie » Wed Aug 18, 2021 2:25 pm

Any thoughts on it? Is there easier approaches find a main game loop that may be one of only a few common main loop Structures used in assembly games on Megadrive

Jmp gamearray(pc,d0)

gamearray:
Bra title
Bra level
Bra credits
Jsr

Post Reply