Megacd bios jumping

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

Post Reply
Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Megacd bios jumping

Post by Fonzie » Tue Feb 13, 2007 12:48 pm

Hi :D its again me :P


In the process of implementing a "jump" log to GensKmod (not me, Kaneda), I wanted to know if there is a fixed ram area where appear the "current" function number.

I mean, each time the user jump to the bios, does the bios write the function number (d0) somewhere?

I vaguely remember the function number is written somewhere but i cannot recall where I read that.

If someone recall :) don't hesitate :D

Pfew... My english is more and more bad... I wonder what's happen.
Sorry.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Feb 13, 2007 2:07 pm

all of this because Starcream allows hook on read/write memory but not program section

so I tried to mod i_jsr but Starscream is really hard to understand :(
I tried to add a call to my function but everything explode since x86 registers are lost with this call...

and I discovered sub68k_context.pc != sub68k_readPC( ), which I don't understand!


Stef, if you have any hint :(

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Feb 13, 2007 2:40 pm

sub68k_context.pc contains "Fetch Region pointer + PC value" then you can directly do :
mov eax, [sub68k_context.pc]
to fetch/read the current intruction. This is done for speed reason of course. If you want the real PC value, use ReadPC or unbase pc : sub68k_context.pc - sub68k_context.basePC

I'm not sur about the sub68k_context.basePC variable name since i'm doing it from head :p

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Feb 13, 2007 2:42 pm

basePC is for the 32X not the 68k :(

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Feb 13, 2007 3:04 pm

32X SH2 cores uses the same type of based PC.
Well, i just had a look in starscream source, here's register value at "alive" (in execution) time :
- esi = based pc
- ebp = fetch base

If you want only the pc value you have to do that :
mov eax, esi ; get based pc
sub eax, ebx ; unbase it --> eax = pc value

hope it helps you :)

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Feb 13, 2007 3:18 pm

so it means my PC value is wrong for a long time (on main 68k part)
thanks for the hint, and now understand better some stuff on Starscream (like the code below)

can you help me on this too

Code: Select all

mov ecx,esi
sub ecx,ebp
mov esi,edx
call _SpyCDBiosCall
it's the code of the jsr + my call
this code is executed the first time but freeze Gens after that..
I suspect the call to the C function SpyCDBiosCall to mod the x86 register :(
can you confirm this and if yes, how can i backup reg/call/restore reg?
(movem ? push ?)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Feb 13, 2007 3:50 pm

KanedaFr wrote:so it means my PC value is wrong for a long time (on main 68k part)
thanks for the hint, and now understand better some stuff on Starscream (like the code below)

can you help me on this too

Code: Select all

mov ecx,esi
sub ecx,ebp
mov esi,edx
call _SpyCDBiosCall
it's the code of the jsr + my call
this code is executed the first time but freeze Gens after that..
I suspect the call to the C function SpyCDBiosCall to mod the x86 register :(
can you confirm this and if yes, how can i backup reg/call/restore reg?
(movem ? push ?)
Seems your _SpyCDBiosCall is using fastcall convention (ecx and edx as parameters).
I do understand you're putting PC in ecx, but what the "mov esi, edx" is supposed to do ? by doing that, you're just erasing the current pc...
Also when you do a function call, you lost your eax, ecx, edx registers values so push them if needed :)

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Feb 13, 2007 3:56 pm

the first 3 lines are the original 'jsr xxx' emulation stuff
I just add the call _Spy....

I found this
http://nasm.sourceforge.net/doc/html/na ... tion-8.1.2 but they talk about save.restore inside the callee function...
does it mean VC isn't making a clean function ? ;)


and this http://www.delorie.com/djgpp/doc/ug/asm/calling.html
talk about
Expect the registers %eax, %ecx, and %edx, as well as the floating-point stack, to have changed. Standard library functions may modify the %gs register, and the _far* functions may modify %fs. Other registers will be preserved.

Post Reply