📄 dc.c
字号:
else
if(!(SecondCont.buttons & CONT_DPAD_RIGHT)) input.pad[1] |= INPUT_RIGHT;
if(!(SecondCont.buttons & CONT_B)) input.pad[1] |= INPUT_BUTTON2;
if(!(SecondCont.buttons & CONT_A)) input.pad[1] |= INPUT_BUTTON1;
return(0);
}
int getKeys () {
int key;
kbd_poll(mkeyb1);
key = kbd_get_key();
return key;
}
inline cont_cond_t getButtons (int port) {
cont_cond_t cond;
if (port == 0) {
cont_get_cond (mcont1, &cond);
} else {
cont_get_cond (mcont2, &cond);
}
return cond;
}
/* SRAM routines */
void system_load_sram() {
return;
}
void system_save_sram() {
return;
}
void load_sram() {
return;
}
void save_sram() {
return;
}
/* Save States */
void load_state() {
return;
}
void novmu();
//uint8 SaveSTATE[0x10000];
void save_state() {
uint16 block_number;
uint8 temp_mem[200];
uint8 *free_mem = (uint8 *)temp_mem;
uint8 addr = maple_first_vmu();
uint8 *SaveSTATE;
int statesize=0;
if (!addr) {
novmu();
printf("No VMU was found\r\n");
return;
}
vmu_display(saving_vmu_icon);
thd_sleep(100);
SaveSTATE = malloc(100000); // 100kb should be enough
system_save_state(SaveSTATE,statesize);
if(statesize>13000) {
dc_print("State is over 13kb, can't save");
free(SaveSTATE);
return;
}
block_number = check_vmu_for_game(ROM.file);
/* found the game in SaveRAM */
if (block_number != 0) {
uint8 temp_buf[13000];
uint8 *vmu_file = (uint8 *)temp_buf;
//uint8 free_blocks = check_free_blocks (free_mem);
int i;
dc_print("Saving Game...");
create_vmu_header (vmu_file, ROM.file, "SMSPlus! Save State", 8576);
for (i=640; i<1024; i++) {
vmu_file[i] = 0;
}
for (i=0; i<13000; i++) {
vmu_file[i + 1024] = SaveSTATE[i];
}
do_crc(vmu_file, 13000);
upload_data_by_block (vmu_file, (uint32)block_number, 32);
} else {
uint8 free_blocks = check_free_blocks (free_mem);
uint8 temp_buf[13000];
uint8 *vmu_file = (uint8 *)temp_buf;
uint8 first_free_block;
int i;
if (free_blocks < 32) {
dc_print("You need 32 free blocks to Save");
thd_sleep(5000);
return;
}
dc_print("Saving Game...");
create_vmu_header(vmu_file, ROM.file, "SMSPlus! Save State", 13000);
/* filler */
for (i=640; i<1024; i++) {
vmu_file[i] = 0;
}
for (i=0; i<13000; i++) {
vmu_file[i + 1024] = SaveSTATE[i];
}
do_crc (vmu_file, 13000);
first_free_block = find_first_free_block(free_mem);
update_fat (free_mem, 32);
upload_vmu_data (vmu_file, free_mem, 32);
update_vmu_dir (first_free_block, ROM.file, 32);
}
free(SaveSTATE);
thd_sleep(100);
printf("BLAH BLAH\r\n");
vmu_display(vmu_icon);
printf("BLAH BLAH\r\n");
}
#define ZIP_FILE 0
#define PLAIN_FILE 1
#include "unzip.h"
int load_rom(char *fd_fname)
{
int size;
//FILE *fd = (FILE *) NULL;
int fd , zyn , dump_size;
byte *dump_cart;
char *ifn;
ifn=(char *)malloc(256);
strcpy(ifn,fd_fname);
if(strcmp(&ifn[strlen(ifn)-3],"zip")==0) {
printf("sms_debug: zip file\r\n");
zyn = ZIP_FILE;
cart.zip = 1;
} else {
printf("sms_debug: plain file\r\n");
zyn = PLAIN_FILE;
cart.zip = 0;
}
if(ROM.file) {
free(ROM.file);
}
ROM.file=malloc(1024);
if (zyn == ZIP_FILE) {
f = (FakeFileHandle *) malloc (sizeof (FakeFileHandle));
if( !f ) {
printf("load_rom: failed to malloc FakeFileHandle\r\n");
free(ifn);
return 0;
}
memset (f, 0, sizeof (FakeFileHandle));
f->filename=malloc(1024);
if (!f->filename) {
printf("load_rom: failed to malloc f->filename\r\n");
free(f); free(ifn);
return 0;
}
if(load_zipped_file(ifn,"BUBBLE~1.SMS",&f->data,&f->length,f->filename)==0)
{
// printf("found in zipped file!\r\n");
f->type=kZippedFile;
cart.crc=crc32 (0L, f->data, f->length);
strcpy(ROM.file,f->filename);
ROM.size=f->length;
//cart.crc = f->crc;
//printf("crc: %08lx\r\n",cart.crc);
cart.pages = (f->length / 0x4000);
cart.rom = malloc(f->length);
if (!cart.rom) { printf("cart.rom malloc error #02\r\n"); free(ifn); return 0; }
cart.type = 0;
ss_select = ss_mastersystem;
ss_select_w = ss_mastersystem_w;
frame_skip = max_skip;
memcpy(cart.rom, f->data, f->length);
if((strcmp(&f->filename[strlen(f->filename)-2],"GG")==0) || (strcmp(&f->filename[strlen(f->filename)-2],"gg")==0)) {
cart.type = 1;
ss_select = ss_gamegear;
ss_select_w = ss_gamegear_w;
frame_skip = min_skip;
} else {
printf("master system rom detected\r\n");
}
return 1;
} else {
free(f);
return 0;
}
}
#ifdef _MP3_SUPPORT_
if(strcmp(&ifn[strlen(ifn)-3],"mp3")==0) {
char *argv[] = {
"/cd/austin~1.mp3",
"/cd/austin~1.mp3"
};
prcs_load_and_exec("/rd/mp3play.klf",2,argv);
free(ifn);
return 3;
}
#endif
fd = fs_open(ifn, O_RDONLY);
if (fd == 0) {
fs_close(fd);
display_dcp(splash);
dc_print("The ROM you selected was not found on this CD.");
thd_sleep(100);
free(ifn);
return 0;
}
fs_seek(fd, 0, SEEK_END);
size = fs_tell(fd);
fs_seek(fd, 0, SEEK_SET);
/*if(size < 32000) {
fclose(fd);
free(ifn);
display_dcp(splash);
screenprintf(100,"The ROM you selected is INVALID, it must be",1);
screenprintf(125,"larger than 32k... can not continue.",1);
thd_sleep(5000);
return 0;
}*/
if((size / 512) & 1) {
size -= 512;
fs_seek(fd, 512, SEEK_SET);
}
cart.pages = (size / 0x4000);
cart.rom = malloc(size);
if(!cart.rom) { printf("cart.rom malloc error #03\r\n"); free(cart.rom); free(ifn); return 0; }
fs_read(fd, cart.rom, size);
fs_close(fd);
strcpy(ROM.file,ifn);
ROM.size=size;
dump_cart = malloc(size);
thd_sleep(10);
dump_size = size;
memcpy(dump_cart,cart.rom,dump_size);
cart.crc = crc32(0, dump_cart, dump_size);
thd_sleep(10);
free(dump_cart);
cart.type = 0;
ss_select = ss_mastersystem;
ss_select_w = ss_mastersystem_w;
frame_skip = max_skip;
if((strcmp(&ifn[strlen(ifn)-2],"gg")==0) || (strcmp(&ifn[strlen(ifn)-2],"GG")==0)) {
cart.type = 1;
ss_select = ss_gamegear;
ss_select_w = ss_gamegear_w;
frame_skip = min_skip;
}
free(ifn);
return 1;
}
int screenprintf(int xpos, char *text, int type) {
if (type == 0) {
bfont_draw_str(vram_s+xpos*SCREEN_W+20, SCREEN_W, 1, text);
} else {
bfont_draw_twriter(vram_s+xpos*SCREEN_W+20, SCREEN_W, text);
}
return(0);
}
void bfont_draw_twriter(uint16 *buffer, int bufwidth, char *str) {
while (*str) {
bfont_draw(buffer += 12, bufwidth, 1, *str++);
thd_sleep(100); /* sleep for 100 ms */
}
}
void putpixel(int x, int y, int r, int g, int b) {
vram_s[y*SCREEN_W+x] = RGB565(r,g,b);
}
void clearscr(int xres, int yres) {
int x, y;
for(x=0; x<xres; x++)
for(y=0; y<yres; y++)
txrtmp[xres*y + x] = RGB565(0,0,0);
for(x=0; x<xres; x++)
for(y=0; y<yres; y++)
guitxrtmp[xres*y + x] = RGB565(0,0,0);
return;
}
void fb_rect(int x, int y, int w, int h, int r, int g, int b)
{
for(; x < w; x++)
for(; y < h; y++)
vram_s[w*y + x] = RGB565(r,g,b);
}
/* Draws an entire string using the loaded font. */
void sdraw_string(int x1, int y1, unsigned short color, char *str) {
while (*str) {
sdraw_char(x1, y1, color, *str);
x1 += 8; str++;
}
}
/* Draws a single character using the loaded font. Assumes a
PM_RGB565 display mode. The original only supported 640x480
mode. This now supports the current resolution. */
void sdraw_char(int x1, int y1, unsigned short color, int ch) {
int offs = ch * ffont_height;
unsigned short * out = vram_s + y1 * SCREEN_W + x1;
int x, y;
for (y=0; y<ffont_height; y++) {
int mask = 0x80;
for (x=0; x<8; x++) {
unsigned short pixel = 0;
if (ffont_bm[offs] & mask) {
pixel = color;
out[x] = pixel;
}
mask >>= 1;
}
out += SCREEN_W; offs++;
}
}
/* You must call this function to setup a font to use for
the rest of the drawing functions. The font should be composed
of 256 bitmapped 8-pixel-wide rows (1 byte per row). */
void sfont_set(unsigned char * fbm, int fh) {
ffont_height = fh;
ffont_bm = fbm;
}
/* KF 05-31-2001 added snd_memset routine from kos-0.90 */
/*void snd_memset(uint32 toi, unsigned long what, int length) {
uint32 *to = (uint32 *)(0xa0800000 + toi);
int i;
if (length % 4)
length = (length/4)+1;
else
length = length/4;
for (i=0; i<length; i++) {
*to++ = what;
if (i && !(i % 8)) snd_ram_write_wait();
}
}*/
/* store queue stuff, thanks joey and regex */
void doPrestore(uint32 addr)
{
asm("pref @r4");
}
/* store queues */
void sqmemcpy(void *dest, void *src)
{
int i,j;
volatile unsigned long *regs = (unsigned long *)0xff000038;
unsigned long formattedAddr;
uint32 *pSQ;
regs[0] = regs[1] = ((unsigned long)dest >> 24);
pSQ = ((uint32*) 0xe0000000);
formattedAddr = 0xe0000000 | (((unsigned long)dest) &= 0x03FFFFFF);
for (i = 0; i < 13; i++)
{
if ((i % 2) == 0)
{ /* SQ0 */
for (j = 0; j < 8; j++)
{
pSQ[j] = ((uint32 *)src)[(i*8) + j];
}
doPrestore(formattedAddr);
}
else
{ /* SQ1 */
for (j = 0; j < 8; j++)
{
pSQ[j + 8] = ((uint32 *)src)[(i*8) + j];
}
doPrestore(formattedAddr);
}
formattedAddr += 32;
}
}
/****************************************************/
/******************** MISCFUNC.C ********************/
/******************** MISCFUNC.C ********************/
/****************************************************/
/*
FILE * fopen(const char *path, const char *mode)
{
if (mode[0] == 'r')
return (FILE *)fs_open(path, O_RDONLY);
if (mode[0] == 'w')
return (FILE *)fs_open(path, O_WRONLY);
}
int fclose(FILE *stream)
{
fs_close((unsigned int)stream);
return 0;
}
unsigned int fread(void *ptr, unsigned int size, unsigned int nmemb, FILE *stream)
{
return fs_read((unsigned int)stream, ptr, size*nmemb)/size;
}
unsigned int ftell (FILE *stream) {
return fs_tell((unsigned int)stream);
}
unsigned int fwrite(void *ptr, unsigned int size, unsigned int nmemb, FILE *stream) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -