Starting execution on the slave SH2

So I want to run some of my code on the slave SH2. I don't care about being able to send commands to it and whatnot, I just want it to enter a specific function that contains an endless loop where it fills up a VDP1 list every frame. Anyway, it's not working properly (neither in Yabause or on a real Saturn). Perhaps someone here has a clue about why?

Code:
#define SMPC_SSHON  1

#define SMPC_SSHOFF 2

#define SMPC_SF ((vu16*)0x20100063)

#define SMPC_COMREG ((vu16*)0x2010001F)

#define SETSINT(_Num_, _Hdr_) ((**(volatile void(**)(uint32, void*))0x6000310)((_Num_), (_Hdr_)))

void SlaveCPUmain();

void InitSlaveCPU()

{

    int i;

    while (*SMPC_SF & 1);

    *SMPC_SF = 1;

    *SMPC_COMREG = SMPC_SSHOFF;

    while (*SMPC_SF & 1);

    for (i=0; i<10; i++);

    SETSINT(0x94, (void*)&SlaveCPUmain);

    *SMPC_SF = 1;

    *SMPC_COMREG = SMPC_SSHON;

    while (*SMPC_SF & 1);

}

void SlaveCPUmain()

{

   for (;;)

   {

      // do stuff

   }

}
 
After the slave CPU is started, it will wait until it finds the value '2RDY' (0x32524459) at 0x6000240. After that it will continue its init sequence and eventually jump via the vector at 0x6000250 (which is the one you're setting in the SETSINT call). However I don't remember if the master CPU's init sequence or some other part of the firmware does it for you, or if you're supposed to do it yourself.

During initialization the slave CPU will store '2RDS' (0x32524453) at 0x6000244, you can use that to check if something has gone wrong (the slave CPU is running from RAM at this point, so it's possible you've written over something you shouldn't have. This bit of the init sequence is found at 0x6000600, for instance.)

ETA: The vector table at the start of ROM sets the slave's stack pointer to 0x6002000, and later on the value at location 0x60002ac will become the new stack pointer unless it's zero (according to my notes, this is where the Stack-S value from the IP area is copied after the header's been loaded from disc). If any of these are not good values, things will go very wrong very fast.
 
Back
Top