If you mean on the Main-CPU side (Genesis), you only want to change the vectors at 0xFFFD00. If you mean the Sub-CPU side (CD), then you want to use the Sub-Processor Int2 entry in the Sub-Processor header table.
The Sub-Processor init code starts with a couple headers.
Code: Select all
.org 0x6000
| Standard MegaCD Sub-CPU Program Header
SPHeader:
.asciz "MAIN SEGAOS"
.word 0x0001,0x0000
.long 0x00000000
.long 0x00000000
.long SPHeaderOffsets-SPHeader
.long 0x00000000
SPHeaderOffsets:
.word SPInit-SPHeaderOffsets
.word SPMain-SPHeaderOffsets
.word SPInt2-SPHeaderOffsets
.word SPNull-SPHeaderOffsets
.word 0x0000
You should use that SPInt2 entry for the Int2 handling on the CD.
Clear your own VBlank vector in SPInit along with any other hardware that needs clearing.
Code: Select all
| Sub-CPU Program Initialization (VBlank not enabled yet)
SPInit:
move.l #0,VBlankHandler /* clear VBlank handler vector */
andi.b #0xE2,0xFF8003 /* Priority Mode = off, 2M mode, Sub-CPU has access */
move.l #0,0xFF8020
move.l #0,0xFF8024
move.l #0,0xFF8028
move.l #0,0xFF802C
move.b #'I,0xFF800F /* clear sub comm port - command = init */
rts
Then in the SPInt2, check if your vector has been set and call it.
Code: Select all
| Sub-CPU Program VBlank (INT02) Service Handler
SPInt2:
tst.l VBlankHandler
bne.b 0f
rts
0:
movem.l d0-d1/a0-a1,-(sp)
move.l VBlankParam,d0
move.l d0,-(sp)
movea.l VBlankHandler,a0
jsr (a0)
addq.l #4,sp
movem.l (sp)+,d0-d1/a0-a1
rts
Note that my example code above is doing a C call to the vblank handler, with a parameter passed to it.
You shouldn't be messing with INT02 in any other manner on the CD!!
On the Genesis side, you should set the vblank handler after all the init code.
Code: Select all
| set vblank int
move.w #0x2700,sr /* interrupts disabled */
lea __vblank(pc),a0
move.l a0,0xFFFD08 /* level 6 redirection vector */
move.w #0x2000,sr /* enable interrupts */
Note - setting the hblank handler requires setting a register in the CD gate array for redirecting it. I won't talk about that unless you really need it.