Here's my segacd.s code, which is loaded at 0x0200000:
Code: Select all
.text
*-------------------------------------------------------
*
* Sega startup code for the GNU Assembler
* Translated from:
* Sega startup code for the Sozobon C compiler
* Written by Paul W. Lee
* Modified from Charles Coty's code
* Modified from Stephane Dallongeville's code
*
*-------------------------------------------------------
.org 0x00000000
_Entry_Point:
move #0x2700,%sr /* interrupts disabled */
lea __stack,%a0
movea.l %a0,%sp /* set stack pointer to top of Work RAM */
* Copy initialized variables from ROM to Work RAM
lea _stext,%a0
adda.l #0x00200000,%a0
lea 0xFF0000,%a1
move.l #_sdata,%d0
lsr.l #1,%d0
subq.w #1,%d0
exec:
move.w (%a0)+,(%a1)+
dbra %d0,exec
* Clear Work RAM (0xFF0000 to 0xFFFCFF)
lea 0xFF0000,%a0
moveq #0,%d0
move.w #0x3F3F,%d1
cram:
move.l %d0,(%a0)+
dbra %d1,cram
* Init z80 ?
lea Table,%a5
movem.w (%a5)+,%d5-%d7
movem.l (%a5)+,%a0-%a4
jmp continue
Table:
dc.w 0x8000,0x3fff,0x0100
dc.l 0xA00000,0xA11100,0xA11200,0xC00000,0xC00004
continue:
* copy interrupt vector (?)
move.l #0xFFFD00, %a1
lea _Bus_Error, %a2
move.l %a2,(%a1)+
lea _Address_Error, %a2
move.l %a2,(%a1)+
lea _Illegal_Instruction, %a2
move.l %a2,(%a1)+
lea _Zero_Divide, %a2
move.l %a2,(%a1)+
lea _Chk_Instruction, %a2
move.l %a2,(%a1)+
lea _Trapv_Instruction, %a2
move.l %a2,(%a1)+
lea _Privilege_Violation, %a2
move.l %a2,(%a1)+
lea _Trace, %a2
move.l %a2,(%a1)+
lea _Line_1010_Emulation, %a2
move.l %a2,(%a1)+
lea _Line_1111_Emulation, %a2
move.l %a2,(%a1)+
lea _Error_Exception, %a2
move.w #0x0c,%d1 /* x 13 */
copyee:
move.l %a2,(%a1)+
dbra %d1,copyee
lea _INT, %a2
move.w #0x02,%d1 /* x 3 */
copyint:
move.l %a2,(%a1)+
dbra %d1,copyint
lea _HBL, %a2
move.l %a2,(%a1)+
lea _INT, %a2
move.l %a2,(%a1)+
lea _VBL, %a2
move.l %a2,(%a1)+
lea _INT, %a2
move.w #0x20,%d1 /* x 33 */
copyint2:
move.l %a2,(%a1)+
dbra %d1,copyint2
*If we restore interrupt state or move it to 0x2300 the whole thing crashes
jmp _start_entry /* call start entry which calls main() */
(original interrupt code follows)
As you can see I tried loading the vector table to the best of my knowledge to address 0xFFFD00, which is supposedly the area it should be loaded to. This of course was just an assumption and my n00bish attempt at doing so. I have dumped the RAM with Gens without doing it and doing it, and if I don't it is simply filled with zeroes.
It makes no difference if I load that, it crashes exactly in the same way. I have not found any solid information on this, or haven't been able to interpret it correctly.
I've also tried loading the stack pointer and the Entry point in there, to make a nice block in RAM from FD00 to FE00 (like that would help).
Here is a screenshot that shows two areas from the VDP RAM, the right side is when the code is compiled and running from the cart and the left part is when using this code.
Uploaded with ImageShack.us
Any help is more than welcome.
As documented in the code above, if I try to store 0x2300 to the SR it crashes, and won't run the rest of the code (as the original sega.s did).