Page 1 of 1

Reset and VRES

Posted: Sat Apr 03, 2021 5:49 am
by ob1
Hello guys.

The 32X doesn't have any reset input.
It does have, though, a VRES interrupt, which is raised when the user presses the reset button on its Genesis.
I am trying to make a proper reset method.
I have tried to clear the register and have set PC = 0, but it doesn't seem to work (I'm testing with Mega Everdrive X3).

Would any of you happen to know what I am supposed to do in the VRES interrupt function ?

Re: Reset and VRES

Posted: Sat Apr 03, 2021 10:56 pm
by TmEE co.(TM)
I imagine you modify stack to have a new return address prior to exiting the interrupt and probably force caches to be flushed too.

Re: Reset and VRES

Posted: Sun Apr 04, 2021 5:14 pm
by ob1
Thank you Tmee for the answer.
Moreover, Chilly Willy posted his toolchain here viewtopic.php?f=7&t=3024, and in particular, there is the file examples/Yeti3D/platform/32X/sh2_crt0.s which states

Code: Select all

main_vres_irq:
        mov.l   mvri_mars_adapter,r1
        mov.w   r0,@(0x14,r1)   /* clear VRES IRQ */
        nop
        nop
        nop
        nop

        mov     #0x0F,r0
        shll2   r0
        shll2   r0
        ldc     r0,sr       /* disallow ints */

        mov.l   mvri_master_stk,r15
        mov.l   mvri_master_vres,r0
        jmp     @r0
        nop

        .align  2
mvri_mars_adapter:
        .long   0x20004000
mvri_master_stk:
        .long   0x0603FC00  /* Cold Start SP */
mvri_master_vres:
        .long   main_reset
and

Code: Select all

main_reset:
! do any master SH2 specific reset code here

        mov.l   slav_st,r0
        mov.l   slav_ok,r1
0:
        mov.l   @r0,r2
        nop
        nop
        cmp/eq  r1,r2
        bf      0b          /* wait for slave */

        ! recopy rom data to sdram

        mov.l   rom_header,r1
        mov.l   @r1,r2      /* src relative to start of rom */
        mov.l   @(4,r1),r3  /* dst relative to start of sdram */
        mov.l   @(8,r1),r4  /* size (longword aligned) */
        mov.l   rom_start,r1
        add     r1,r2
        mov.l   sdram_start,r1
        add     r1,r3
        shlr2   r4          /* number of longs */
        add     #-1,r4
1:
        mov.l   @r2+,r0
        mov.l   r0,@r3
        add     #4,r3
        dt      r4
        bf      1b

        mov.l   main_st,r0
        mov.l   main_ok,r1
        mov.l   r1,@r0      /* tell everyone reset complete */

        mov.l   main_go,r0
        jmp     @r0
        nop