⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dc.c

📁 DC的SEGA_GG模拟器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 *
 * SMS Plus! for the Dreamcast (Sega Master System emulator for the Dreamcast)
 * Original code Copyright (C) 1998, 1999, 2000 Charles Mac Donald
 * Dreamcast port Copyright (C) 2001 ss_teven
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 */

#include "shared.h"
#include "dc.h"
#include "dbp_image.h"

//included images
#include "splash.h"
#include "pressstart.h"
#include "mehnu.h"
#include "redblob.h"

#include "dcload-syscall.h"
//#include "dcload-syscalls.h"
#include "dcload-printf.h"



int gui_menu_load();

int dc_main() {

    snd.enabled = 0; /* this prolly still wont work by enabling it */

    init_machine();
    splash_screen();


    gui_menu();
    gui_menu_load();

    load_rom();
    system_init(0);
    load_sram();


    frame_count = 0;

    /* Main emulation loop */
    for(;;) {

        /* we got the exit flag, lets break */
        if(exit_flag) break;

        /* Bump frame count */
        frame_count += 1;

        /* Set skip flag based on frameskip settings */
        if(frame_count % frame_skip == 0)
            skip_flag = 0;
        else
            skip_flag = 1;

        /* Get current input */
        update_input();

        /* Run the SMS emulation for a frame */
        sms_frame(skip_flag);

        /* Update the display if desired */
        if(skip_flag == 0) {
           update_video();
        }

        /* Displays the frame count */
        if(show_dcfr == 1) display_fcount();
    }

    system_shutdown();
    trash_machine();
    return (0);
}


int gui_drawmenu(int choice) {
//   clearscr(640,480);
   int x,y;
      for(x = 256; x < 285; x++)
         for(y = 229; y < 362; y++)
            vram_s[640*y + x] = RGB565(0,0,0);
   dbp_load(p_redblob,256,229);
/*   if (choice==1) { bfont_draw_str(vram_s+140*s_width+130, s_width, "   o    Load game");
   } else { bfont_draw_str(vram_s+140*s_width+130, s_width, "        Load game"); }
   if (choice==2) { bfont_draw_str(vram_s+180*s_width+130, s_width, "   o    Options");
   } else { bfont_draw_str(vram_s+180*s_width+130, s_width, "        Options"); }
   if (choice==3) { bfont_draw_str(vram_s+220*s_width+130, s_width, "   o    Credits");
   } else { bfont_draw_str(vram_s+220*s_width+130, s_width, "        Credits"); }
   if (choice==4) { bfont_draw_str(vram_s+260*s_width+130, s_width, "   o    Exit");
   } else { bfont_draw_str(vram_s+260*s_width+130, s_width, "        Exit"); }
   */
   return(0);
}

int gui_menu() {
   uint8 mmcont;
   cont_cond_t mcond;
   int choice,a=1;

   mmcont = maple_controller_addr();
//   clearscr(640,480);
   dbp_load(p_splash,0,0);
   dbp_load(p_mehnu,292,229);
   gui_drawmenu(1);
   while(1) {
       if(cont_get_cond(mmcont, &mcond)) {
          return;
       }
//!(mcond.buttons  & pbutton)
       while(!a) {
          a=csleep3(60*1000,CONT_DPAD_DOWN,CONT_DPAD_UP,CONT_A);
       }
       if(a==1) {
          choice=choice+1;
       }
       if(a==2) {
          choice=choice-1;
       }
       if(a==3) {
          if (choice==1) {
//            clearscr(640,480);
             break;
          }
          if (choice==2) {
//             screenprintf(500, "Options not yet available",0);
             sleep(4*1000);
          }
          if (choice==3)
             credits();
          if (choice==4)
            exittomenu();
       }
       if (choice==5) { choice=1; }
       if (choice==0) { choice=4; }
       gui_drawmenu(choice);
       a=0;
       sleep(200);
   }
   return(0);
}

int gui_menu_load() {
   return(0);
}

int splash_screen() {
    int w, x, y;

    serial_printf("splash screen ...");
    dbp_load(p_splash,0,0);
    dbp_load(p_pressstart,(s_width/2)-(126/2),s_height/2);

    while(1) {
       w=csleep(1000,CONT_START);
          if (w==1) break;
       for(x = 100; x < 600; x++)
          for(y = 145; y < 300; y++)
             vram_s[640*y + x] = RGB565(255,255,255);
       w=0;
       w=csleep(1000,CONT_START);
          if (w==1) break;
       dbp_load(p_splash,0,0);
       dbp_load(p_pressstart,(s_width/2)-(126/2),s_height/2);
    }

    dbp_load(p_splash,0,0);
    serial_printf("... [ DONE ]\r\n");
    return(0);
}

int credits() {
   int y, x, w=1; char *title;
   clearscr(640,480);
   //title=stradd("SMS Plus! for the Dreamcast v1.0");
   while(1) {
      screenprintf(10+x , "SMS Plus! for the Dreamcast v1.0",w);
      screenprintf(150+x,"       Original Code by Charles Mac Donald",w);
      screenprintf(200+x,"       Ported to the Dreamcast by ss_teven",w);
      screenprintf(440+x,"  Thanks go to (in no specific order):",0);
      screenprintf(490+x,"      All the beta testers,",0);
      screenprintf(520+x,"         Sayten, Surfer PR, Heliophobe",0);
      screenprintf(550+x,"      All the guys in #dcdev and #dcemu",0);
      screenprintf(580+x,"      Dan Potter for Libdream",0);
      screenprintf(610+x,"      All my friends for showing me the real world",0);
      screenprintf(640+x,"      and everyone else who i missed!",0);
      screenprintf(750+x," dont forget to visit devcast.dcemulation.com",0);
      screenprintf(1100+x,"                  SMS Plus                  ",0);

      y=csleep(1000,CONT_A);
      if (y==1)
         break;
      clearscr(640,480);
      //vid_clear(0,0,0);
      x=x-1;
      w=0;
   }
   return(0);
}

/* csleep(int sleep, uint16 pbutton);  okay, now I hated that i
 * couldnt flash a message with it sleeping for 500ms, in that 500ms
 * sleep someone may have pushed a button or something, so what this
 * baby does is sleeps for 1ms and after each 1ms it searches for the
 * controller, and then sleeps for 1ms again, until the designated
 * sleep number is done then it breaks out and returns 0, or if the
 * button is pressed then it breaks out of the loop and returns 1
 */
int csleep(int slp, uint16 pbutton) {
   int s=1,a=0;
   uint8 mmcont;
   cont_cond_t mcond;

   mmcont = maple_controller_addr();
   if (!mmcont) {
      screenprintf(20,"Please plug in a controller!",1);
      while(!mmcont){
         mmcont = maple_controller_addr();
      }
   }
   while(1) {
          s++;
          if(cont_get_cond(mmcont, &mcond)) {
             return;
          }
          if(!(mcond.buttons  & pbutton)) {
             serial_printf("button was pressed\r\n");
             a=1;
             break;
          }
          sleep(1);
          if(s==slp) {
             a=0;
             break;
          }
   }
   return(a);
   return(0);
}

/* This clseep handles 3 buttons being pressed */
int csleep3(int slp, uint16 pbutton1, uint16 pbutton2, uint16 pbutton3) {
    int s,a;
    uint8 mmcont;
    cont_cond_t mcond;
    s = 1;
    mmcont = maple_controller_addr();
    if (!mmcont) {
       screenprintf(20,"Please plug in a controller!",1);
       while(!mmcont){
          mmcont = maple_controller_addr();
       }
    }
    while(1) {
          s++;
          if(cont_get_cond(mmcont, &mcond)) {
             return;
          }
          if(!(mcond.buttons  & pbutton1)) {
             serial_printf("button1 was pressed\r\n");
             a=1;
             break;
          }
          if(!(mcond.buttons  & pbutton2)) {
             serial_printf("button2 was pressed\r\n");
             a=2;
             break;
          }
          if(!(mcond.buttons  & pbutton3)) {
             serial_printf("button3 was pressed\r\n");
             a=3;
             break;
          }
          sleep(1);
          if(s==slp) {
             a=0;
             break;
          }
   }
   return(a);
   return(0);
}

void init_machine(void)
{

    /* Clear framebuffer */
    //fb_rect(0, 0, 0x3FF, 0x1FF, 0x1F, 0x1F, 0x1F);

#ifdef DCDEBUG
    serial_init(57600);
    serial_printf("SMS Plus! for the Dreamcast\r\n  a port by ss_teven\r\n");
#else
    serial_disable();
#endif


#ifdef NTSC
    dc_setup_quiet(DM_640x480, PM_RGB565);
#else
	/* Init video */
        Command_pal();
	/* Init sound */
	snd_init();
	/* Init CD-ROM */
	cdrom_init();
	iso_init();
	/* cd_init(); */
	/* Init input devices (Maple Bus) */
        maple_init(0);
	/* Init timers */
	timer_init();
#endif



#ifdef DCDEBUG
    serial_printf("Graphics mode set: 640x480 (RGB565)\r\n");
#endif


    /* Initialize display bitmap */
    serial_printf("Setting up bitmap ...");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -