📄 dc.c
字号:
memset(&bitmap, 0, sizeof(t_bitmap));
bitmap.width = 256;
bitmap.height = 192;
bitmap.depth = 8;
bitmap.pitch = (bitmap.width * (bitmap.depth >> 3));
bitmap.data = (unsigned char *)&bitmap_data[0];
serial_printf(" DONE.\r\n");
mcont = maple_controller_addr();
if (!mcont) {
screenprintf(20,"Please insert a controller.",1);
serial_printf("Please insert a controller.\r\n");
while(!mcont){
mcont = maple_controller_addr();
}
return;
}
serial_printf("Controller detected.\r\n");
init_splash();
init_pressstart();
init_redblob();
init_mehnu();
clearscr(640,480); /* get rid of the text outputted to screen (if any) */
}
#ifndef NTSC
void Command_pal()
{
unsigned long * reg_vid_enc = (unsigned long *)0xa05f80D0;
unsigned long * reg_vid_size = (unsigned long *)0xa05f80D8;
uint32 vsize_lace = (624 << 16);
uint32 vsize = (312 << 16);
uint32 hsize = 863;
uint32 video_size=0;
if( current_display_mode == DISPLAY_HIRES )
{
video_size = (vsize_lace | hsize);
}
else
{
video_size = (vsize | hsize);
}
*(reg_vid_enc) &= 0xffffff3f; //clear any content from videomode
*(reg_vid_enc) |= 0x00000040; //set videomode to PAL
*(reg_vid_size) = video_size; //set videosize
dc_type = DC_TYPE_PAL;
return;
}
#endif
void trash_machine(void)
{
clearscr(640,480);
screenprintf(20,"Thankyou for using SMS Plus! for the Dreamcast",1);
serial_printf("Thankyou for using SMS Plus! for the Dreamcast\r\n");
sleep(2000);
exittomenu();
for(;;); /* loop forever till power down, just incase exittomenu failed */
}
void update_video(void)
{
int x, y, c, r, g, b;
/* Width and height of viewport */
//int w = (cart.type ? 160 : 256);
//int h = (cart.type ? 144 : 192);
int w = 160;
int h = 144;
/* Offset in framebuffer */
// int dx = (cart.type ? 48 : 0);
// int dy = (cart.type ? 48 : 24);
int dx = 0;
int dy = 0;
/* Offset in display bitmap */
int sx = (cart.type ? 48 : 0);
int sy = (cart.type ? 24 : 0);
for(y = 0; y < h; y += 1)
{
/* Point to current line of bitmap */
// char *p = &bitmap.data[((sy + y) * bitmap.width) + (sx)];
for(x = 0; x < w; x += 1)
{
/* Strip priority and sprite marker bits */
// c = (p[x] & PIXEL_MASK);
/* Look-up color components for given pixel */
r = bitmap.pal.color[c][0];
g = bitmap.pal.color[c][1];
b = bitmap.pal.color[c][2];
/* Write to framebuffer */
putpixel(dx + x, dy + y, r, g, b);
// serial_printf("x: %s , y: %s , r: %s , g: %s , b: %s\n",dx+x,dy+y,r,g,b);
}
}
}
/* Show how many frames have been rendered */
void display_fcount() {
if (show_dcfr == 1) {
//bfont_draw(vram_s+10*s_width+10, s_width, frame_count);
bfont_draw(vram_s+300*s_width+20, s_width, frame_count);
}
}
/* Updates the Controller's input */
int update_input() {
uint8 mmcont;
cont_cond_t mcond;
// cont_cond_t cond;
mmcont = maple_controller_addr();
cont_get_cond(mmcont, &mcond);
memset(&input, 0, sizeof(t_input));
/* increase frame skip with the right trigger */
if (mcond.rtrig) {
if (frame_skip > 29) {
frame_skip=30; /* dont let frame skip get too high */
} else {
frame_skip++; //add_msg("Frame skip disabled");
}
serial_printf("Increased frameskip to: %d\r\n", frame_skip);
return(0);
}
/* decrease frame skip with the right trigger */
if(mcond.ltrig) {
if (frame_skip == 0) {
frame_skip=0; /* unable to make frame skip -1 */
} else {
frame_skip=frame_skip-1;
}
serial_printf("Decreased frameskip to: %d\r\n", frame_skip);
return(0);
}
/* enable/disable number of frames rendered */
if(!(mcond.buttons & CONT_X)) {
if (show_dcfr == 0) {
serial_printf("Displaying number of frames rendered on screen\r\n");
show_dcfr = 1;
} else if (show_dcfr == 1) {
serial_printf("Disabled the display of the number of frames rendered on screen\r\n");
show_dcfr = 0;
}
return(0);
}
/* exit if Y button pressed */
if(!(mcond.buttons & CONT_Y)) exit_flag = 1;
/* general controllers */
if(!(mcond.buttons & CONT_START)) input.system |= (cart.type) ? INPUT_START : INPUT_PAUSE;
if(!(mcond.buttons & CONT_DPAD_UP)) input.pad[0] |= INPUT_UP;
else
if(!(mcond.buttons & CONT_DPAD_DOWN)) input.pad[0] |= INPUT_DOWN;
if(!(mcond.buttons & CONT_DPAD_LEFT)) input.pad[0] |= INPUT_LEFT;
else
if(!(mcond.buttons & CONT_DPAD_RIGHT)) input.pad[0] |= INPUT_RIGHT;
if(!(mcond.buttons & CONT_B)) input.pad[0] |= INPUT_BUTTON2;
if(!(mcond.buttons & CONT_A)) input.pad[0] |= INPUT_BUTTON1;
/* no controller 2 support yet... sorry. */
/* if(pad2_mask & (1 << 12)) input.pad[1] |= INPUT_UP;
else
if(pad2_mask & (1 << 14)) input.pad[1] |= INPUT_DOWN;
if(pad2_mask & (1 << 15)) input.pad[1] |= INPUT_LEFT;
else
if(pad2_mask & (1 << 13)) input.pad[1] |= INPUT_RIGHT;
if(pad2_mask & (1 << 7)) input.pad[1] |= INPUT_BUTTON2;
if(pad2_mask & (1 << 6)) input.pad[1] |= INPUT_BUTTON1; */
return(0);
}
/* SRAM routines */
void system_load_sram()
{
load_sram();
}
void system_save_sram()
{
save_sram();
}
void load_sram()
{
/* TODO: implement loading sram at */
}
void save_sram()
{
/* TODO: implement saving sram */
}
/* Load a game image to run
* later change to int load_rom(char *filename); when GUI implemented
*/
void load_rom(void)
{
int size;
//char path[0x100];
char *filename;
FILE *fd = (FILE *) NULL;
filename = "/GAME.SMS";
serial_printf("Loading %s .......\r\n", filename);
fd = fopen(filename, "rb");
if (!fd) {
screenprintf(20,"The ROM you selected was not found on this CD.",1);
sleep(500);
serial_printf("\r\n [ FAILED ] .. please insert CD with GAME.SMS\r\n");
for (;;) {
fd = fopen(filename, "rb");
if (fd) break;
/* keep look for ROM till found, when GUI coded
must remove tihs, and simply put return NULL or some thing */
}
clearscr(640,480);
}
/*
cart.rom = &base_rom[0];
size = iso_read(fd, cart.rom, ROM_SIZE); */
/* seek to EOF and get size */
serial_printf("Seeking EOF... ", filename);
//fseek(((FILE*) fd), 0, SEEK_END);
fseek(fd, 0, SEEK_END);
serial_printf("DONE.\r\n", filename);
serial_printf("Performing ftell... ", filename);
size = ftell(fd);
serial_printf("DONE.\r\n", filename);
serial_printf("Seeking SEEK_SET... ", filename);
fseek(fd, 0, SEEK_SET);
serial_printf("DONE.\r\n", filename);
/* Don't load games smaller than 32k */
if(size < 32000) {
fclose(fd);
screenprintf(20,"The ROM you selected is INVALID, it must be",1);
sleep(500);
screenprintf(45,"larger than 32k... can not continue.",1);
sleep(60*1000); /* wait for 1min */
serial_printf(" [ FAILED ] .... %s must be LARGER THAN 32k\r\nThe ROM you selected is only '%d' bytes", filename, size);
for(;;);
}
/* Skip ROM 512byte header if present */
if((size / 512) & 1) {
serial_printf(" [ 512byte header found ] ... ");
size -= 512;
fseek(fd, 512, SEEK_SET);
}
cart.pages = (size / 0x4000);
cart.rom = malloc(size);
// fread(cart.rom, size, 1, ((FILE*) fd));
fread((char *) cart.rom, size, 1, fd);
fclose(fd);
serial_printf(" [ DONE ] (ROM LOADED)\r\n");
#ifdef DCDEBUG
serial_printf("Loaded file %s, %d bytes.\r\n", filename, size);
#endif
cart.type = 0;
/* if(strcmp(strrchr(path, '.'), ".gg") == 0)
{
cart.type = 1;
} */
/*********************************************************
* right now we only use .SMS roms, when GUI coded, must *
* re-implement this feature.. *
********************************************************/
}
/* write some text to the screen (use just for errors, notices, etc) */
int screenprintf(int xpos, char *text, int type) {
if (type == 0) {
bfont_draw_str(vram_s+xpos*s_width+20, s_width, text);
} else {
bfont_draw_twriter(vram_s+xpos*s_width+20, s_width, text);
}
return(0);
}
/* draw text on screen, typewriter style */
void bfont_draw_twriter(uint16 *buffer, int bufwidth, char *str) {
while (*str) {
bfont_draw(buffer += 12, bufwidth, *str++);
sleep(100); /* sleep for 1/2 second */
}
}
/* put a pixel on to the screen */
void putpixel(int x, int y, int r, int g, int b)
{
// vram_s[x+(s_width*y)] = RGB565(r,g,b);
vram_s[y*640+x] = RGB565(r,g,b);
}
/* clear the screen */
void clearscr(int xres, int yres) {
int x, y;
for(x = 0; x < xres; x++)
for(y = 0; y < yres; y++)
vram_s[xres*y + x] = 0;
}
/* Clear a rectangluar region of the framebuffer */
void fb_rect(int x, int y, int w, int h, int r, int g, int b)
{
// vram_s[x+(s_width*h)] = RGB565(r,g,b);
for(; x < w; x++)
for(; y < h; y++)
vram_s[w*y + x] = RGB565(r,g,b);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -