Discussion in 'Sega Dreamcast Development and Research' started by fafadou, Jun 10, 2019.

Joined:
Aug 3, 2016
Messages:
594
251
Hi,

I'm sorry to create a thread just for this but everyone can ask some requestion to expert.
Hope the knowldge may be share.

In order to patch a game I need to use the MOVA function In the SH-4 document I find this : I need to use exactly :
0x8C033090 -> mova 0x8C03309C, r0

If I understand well the value in 0x8C03309C will be inject in r0.
My problem is how can I calculate the "i"...
For me I have to do :
(0x8C033090 + 4 ) - 0x8C03309C = -8 #(PC +4 - relative)
8 -> 0000 1000 #On 8 bits length
-8 -> 1111 1000
remove the 2 lowest bits :
1111 10
"and adding the zero-extended 8-bit immediate i multiplied by 4"
So here I don't understand...

Please don't do it for me, But may you can explain to a noob ^^

Many thanks

truemaster1 likes this.
2. ### TriMeshSite Supporter 2013-2017

Joined:
Jul 3, 2008
Messages:
2,376
785
OK, your calculation is nearly right, but you have the sign swapped.

Instruction is at 0x8C033090 - the +4 is to account for the prefetch, so at execution time the PC will be 0x8C033094

Your target address is 0x8C03309C, so calculate 0x8C03309C - 0x8C033094 = target is 8 bytes away

Since the operand if left shifted by two bits (I.E. multiplied by 4), you need to divide the offset by 4, which gives you 2.

So the resulting opcode is C702

Joined:
Aug 3, 2016
Messages:
594
251
Thanks for answered to quickly !!
so remowing the lowest two bits is to divide by 4. Simply ^^

4. ### TriMeshSite Supporter 2013-2017

Joined:
Jul 3, 2008
Messages:
2,376
785
Not quite - the lowest 2 bits are set to zero to ensure the resulting pointer is aligned to a 32 bit word boundary - but in this case, it's not necessary, since the last 2 bits of the address are already zero. So you can effectively just ignore that part.

When you do a left, shift, you multiply the number by 2 for each bit you shift, so
Left shift 1 = multiply by 2
Left shift 2 = multiply by 4
Left shift 3 = multiply by 8
Left shift 4 = multiply by 16

And so on. Right shifts are similar, but equivalent to divides.

Anthony817, fafadou and -=FamilyGuy=- like this.

Joined:
Aug 3, 2016
Messages:
594
251
Thanks for taking time to explain more 6. ### Mrneo240Enthusiastic Member

Joined:
Sep 15, 2017
Messages:
520
624
Whatcha working on?

Joined:
Aug 3, 2016
Messages:
594
251
Here before assembler patch : And after : -=FamilyGuy=- likes this.
8. ### DreamcastIntrepid Member

Joined:
Jul 17, 2007
Messages:
652
117
I'm not seeing much of a difference. Did the patch make the selection marquee wider in the "Objets Soin" window?

Joined:
Aug 3, 2016
Messages:
594