void setup(void) { // Initialize Sega VDP VDP_init(); // Configure the screen with to 40 columns VDP_setScreenWidth320(); // Configure background planes to be 64 x 32 cells VDP_setPlanSize(64,32); // Initialize column text output (DMA graphic tiles) col_init(); // Disable interrupts during configuration SYS_disableInts(); // Allow all three interrupts SYS_setInterruptMaskLevel(0); // Set pointers to interrupt service routines SYS_setVIntCallback((_voidCallback *)v_int); SYS_setHIntCallback((_voidCallback *)h_int); // Now we can enable interrupts SYS_enableInts(); // Configure the screen with to 40 columns VDP_setScreenWidth320(); // Configure background planes to be 64 x 32 cells VDP_setPlanSize(64,32); }
// error exception default callback void _errorexception_callback() { VDP_init(); VDP_drawText("EXCEPTION ERROR !", 5, 3); showExceptionDump(5); while(1); }
// privilege violation exception default callback void _privilegeviolation_callback() { VDP_init(); VDP_drawText("PRIVILEGE VIOLATION !", 5, 3); showExceptionDump(5); while(1); }
// TRAPV instruction default callback void _trapvinst_callback() { VDP_init(); VDP_drawText("TRAPV INSTRUCTION EXCEPTION !", 5, 3); showException4WDump(5); while(1); }
// CHK instruction default callback void _chkinst_callback() { VDP_init(); VDP_drawText("CHK INSTRUCTION EXCEPTION !", 5, 10); showException4WDump(12); while(1); }
// division by zero exception default callback void _zerodivide_callback() { VDP_init(); VDP_drawText("DIVIDE BY ZERO !", 10, 3); showExceptionDump(5); while(1); }
// illegal instruction exception default callback void _illegalinst_callback() { VDP_init(); VDP_drawText("ILLEGAL INSTRUCTION !", 7, 3); showException4WDump(5); while(1); }
// address error default callback void _addresserror_callback() { VDP_init(); VDP_drawText("ADDRESS ERROR !", 10, 3); showBusAddressErrorDump(5); while(1); }
static void _init( u16 hard ) { if ( hard == 0 ) // 0 is soft reset { VDP_drawText ( "BUG HUNT", 16, 9 ); VDP_drawText ( "FOR SEGA MEGADRIVE", 11, 11 ); VDP_drawText ( "BY THE AFROMONKEYS, 2015", 8, 13 ); waitMs(3000); // That's weird. // Resetting in SGDK v1.11 invokes JOY_init() that // makes Justifier | Menacer not to be detected if // mouse is on PORT_1 if ( JOY_getPortType(PORT_1) != PORT_TYPE_PAD ) { VDP_drawText ( "PLEASE, REBOOT YOUR SYSTEM", 7, 19 ); while ( 1 ); } _start_entry(); // even more reset } sd_reset(); SYS_assertReset(); // makes gensKmod crash, WTF?! VDP_init(); //JOY_init(); // can cause mouse + justifer issues h_scroll = 0; VDP_setScrollingMode ( HSCROLL_PLANE, VSCROLL_PLANE ); /* The scroll mode never change during the game */ VDP_setPlanSize(64,32); save_init( ); SPR_init(0); /* Sprite Engine INIT */ VDP_setPalette(PAL3, sprpal.data); /* Sprite Palette (never change during the game) */ /* PAD & Mouse (PORT_1) & Lightgun (PORT_2) Support */ _JOYint ( TRUE ); LightgunInit ( PORT_2 ); VINT_SCROLL_FLAG = FALSE; VINT_JOY_UPDATE = FALSE; SYS_setVIntCallback((_voidCallback*) VIntCallback); FIRST_TIME_FLAG = TRUE; }
void _start_entry() { // initiate random number generator randbase = 0xD94B ^ GET_HVCOUNTER; vtimer = 0; // default interrupt callback busErrorCB = _buserror_callback; addressErrorCB = _addresserror_callback; illegalInstCB = _illegalinst_callback; zeroDivideCB = _zerodivide_callback; chkInstCB = _chkinst_callback; trapvInstCB = _trapvinst_callback; privilegeViolationCB = _privilegeviolation_callback; traceCB = _trace_callback; line1x1xCB = _line1x1x_callback; errorExceptionCB = _errorexception_callback; intCB = _int_callback; internalVIntCB = _vint_callback; internalHIntCB = _hint_callback; internalExtIntCB = _extint_callback; internal_reset(); #if (ENABLE_LOGO != 0) { Bitmap *logo = unpackBitmap(&logo_lib, NULL); // correctly unpacked if (logo) { const Palette *logo_pal = logo->palette; // display logo (use BMP mode for that) BMP_init(TRUE, PAL0, FALSE); #if (ZOOMING_LOGO != 0) // init fade in to 30 step u16 step_fade = 30; if (VDP_initFading(logo_pal->index, logo_pal->index + (logo_pal->length - 1), palette_black, logo_pal->data, step_fade)) { // prepare zoom u16 size = 256; // while zoom not completed while(size > 0) { // sort of log decrease if (size > 20) size = size - (size / 6); else if (size > 5) size -= 5; else size = 0; // get new size const u32 w = 256 - size; // adjust palette for fade if (step_fade-- > 0) VDP_doStepFading(FALSE); // zoom logo BMP_loadAndScaleBitmap(logo, 64 + ((256 - w) >> 2), (256 - w) >> 1, w >> 1, w >> 1, FALSE); // flip to screen BMP_flip(0); } // while fade not completed while(step_fade--) VDP_doStepFading(TRUE); } // wait 1 second waitTick(TICKPERSECOND * 1); #else // set palette 0 to black VDP_setPalette(PAL0, palette_black); // don't load the palette immediatly BMP_loadBitmap(logo, 64, 0, FALSE); // flip BMP_flip(0); // fade in logo VDP_fade((PAL0 << 4) + logo_pal->index, (PAL0 << 4) + (logo_pal->index + (logo_pal->length - 1)), palette_black, logo_pal->data, 30, FALSE); // wait 1.5 second waitTick(TICKPERSECOND * 1.5); #endif // fade out logo VDP_fadePalOut(PAL0, 20, 0); // wait 0.5 second waitTick(TICKPERSECOND * 0.5); // shut down bmp mode BMP_end(); // release bitmap memory MEM_free(logo); // reinit vdp before program execution VDP_init(); } }