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

📄 dc.c

📁 DC的SEGA_GG模拟器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    //return fs_write((unsigned int)stream, ptr, size*nmemb)/size;
}

int fseek(FILE *stream, long offset, int whence)
{
    return fs_seek((unsigned int)stream, offset, whence);
}*/

void exittomenu()
{
	(*(void(**)())0x8c0000e0)(1);
}

/****************************************************/
/******************** DCPIMAGE.C ********************/
/******************** DCPIMAGE.C ********************/
/****************************************************/

#include "dcp/dcp_image.h"

#define dcp565(r, g, b) ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);

struct dbp_hdr 
{
	char   version[2];        /* version code of DBP file, currently 1A */
	char   creationdate[8];   /* filecreationdate (format mmddyyyy)     */
	char   creator[48];       /* copyright notification                 */
	char   xmax1;             /* byte 1 of width of picture             */
	char   xmax2;             /* byte 2 of width of picture             */
	char   xmax3;             /* byte 3 of width of picture             */
	char   ymax1;             /* byte 1 of height of picture            */
	char   ymax2;             /* byte 2 of height of picture            */
	char   ymax3;             /* byte 3 of height of picture            */
};

int shift_add(char c, int r)
{
  int result = r;
  result *= 10;
  result += (int)c - (int)'0';
  return result;
}

int _dcp_load(uint8 * _dcp_file, uint8 *_pic_buffer, int _compression)
{
        int z;

        if (_compression==1) {
                z=rnc_unpack(_pic_buffer,_dcp_file);
        }

        return(0);
}

int dcp_load(uint8 * dcp_file, uint8 *pic_buffer) {
        return(_dcp_load(dcp_file,pic_buffer,1));
}

int dbp_load(uint8 * dcp_file, uint8 *pic_buffer) {
        return(_dcp_load(dcp_file,pic_buffer,0));
}

int display_dbp(uint8 *_pic_buffer) {
        return(display_dcp(_pic_buffer));
}

int display_dcp(uint8 *__pic_buffer) {
	int x;
	int y;
	int r;
	int g;
	int b;
	int xmax;
	int ymax;
        int xpos=0;
        int ypos=0;
	struct dbp_hdr dbphdr;

    poly_hdr_t poly;

        draw_background();

return 0;

    ta_poly_hdr_col(&poly, TA_TRANSLUCENT);

    ta_begin_render();


    ta_commit_eol();

    ta_commit_poly_hdr(&poly);

    ta_commit_eol();

    ta_finish_frame();
        return 0;


        //memcpy(&dbphdr, __pic_buffer, sizeof(dbphdr)); __pic_buffer += sizeof(dbphdr);
	xmax=0;
	ymax=0;
	xmax = shift_add(dbphdr.xmax1,0);
	xmax = shift_add(dbphdr.xmax2,xmax);
	xmax = shift_add(dbphdr.xmax3,xmax);
	ymax = shift_add(dbphdr.ymax1,0);
	ymax = shift_add(dbphdr.ymax2,ymax);
	ymax = shift_add(dbphdr.ymax3,ymax);

        xmax = 640;
        ymax = 480;
        //xmax=512;
        //ymax=512;

        //--- display picture on specified location ---
	y = 0;
	while (y !=ymax) 
		{
		x = 0;
		y++;
		while (x !=xmax) 
			{
			x++;
                        r = *__pic_buffer++;
                        g = *__pic_buffer++;
                        b = *__pic_buffer++;
                        if ((x!=1) && (x!=xmax) && (y!=1) && (y!=ymax)) {
                                 guitxrtmp[(x+xpos) + (640*(y+ypos))] = dcp565(r,g,b);
				 }
			}
		}
        ta_begin_render();
        gui_txr_display(1.0f, &polys);
        ta_commit_eol();
        disc_blank();
        ta_commit_eol();
        ta_finish_frame();

        return(0);
}


void draw_background() {
	vertex_ot_t	v;
	poly_hdr_t	hdr;

        ta_poly_hdr_txr(&hdr, TA_OPAQUE, TA_RGB565, 1024, 512, bkg_tex, TA_NO_FILTER);
	ta_commit_poly_hdr(&hdr);

	/* - -
	   + - */
	v.flags = TA_VERTEX_NORMAL;
        v.x = 0.0f;
        v.y = 512.0f;
	v.z = 1.0f;
        v.u = 0.0f; v.v = 1.0f;
        v.a = 1.0f; v.r = v.g = v.b = 1.0f;
	v.oa = v.or = v.og = v.ob = 0.0f;
	ta_commit_vertex(&v, sizeof(v));

	/* + -
	   - - */
	v.y = 0.0f;
	v.v = 0.0f;
	ta_commit_vertex(&v, sizeof(v));

	/* - -
	   - + */
        v.x = 1024.0f;
        v.y = 512.0f;
        v.u = 1.0f; v.v = 1.0f;
	ta_commit_vertex(&v, sizeof(v));

	/* - +
	   - - */
	v.flags = TA_VERTEX_EOL;
        v.y = 0.0f; v.v = 0.0f;
	ta_commit_vertex(&v, sizeof(v));

}

/* myf0nt.c */
unsigned int font_tex;
void font_init(void)
{
    unsigned char font[4096];
    int i,x,y,c;
    unsigned int fd;
    unsigned short *tex;

    fd = fs_open("/rd/8x16.bin", O_RDONLY);
    fs_read(fd, font, 4096);
    fs_close(fd);

    font_tex = ta_txr_allocate(256*128*2);
    tex = ta_txr_map(font_tex);
    
    c = 0;
    for(y = 0; y < 128 ; y+=16)
        for(x = 0; x < 256 ; x+=8) {
            for(i = 0; i < 16; i++) {
                tex[x + (y+i) * 512 + 0] = 0xffff * ((font[c+i] & 0x80)>>7);
                tex[x + (y+i) * 512 + 1] = 0xffff * ((font[c+i] & 0x40)>>6);
                tex[x + (y+i) * 512 + 2] = 0xffff * ((font[c+i] & 0x20)>>5);
                tex[x + (y+i) * 512 + 3] = 0xffff * ((font[c+i] & 0x10)>>4);
                tex[x + (y+i) * 512 + 4] = 0xffff * ((font[c+i] & 0x08)>>3);
                tex[x + (y+i) * 512 + 5] = 0xffff * ((font[c+i] & 0x04)>>2);
                tex[x + (y+i) * 512 + 6] = 0xffff * ((font[c+i] & 0x02)>>1);
                tex[x + (y+i) * 512 + 7] = 0xffff * (font[c+i] & 0x01);
            }
            c+=16;
        }
}

void draw_color_rect(int x, int y, int w, int h, float a, float r, float g, float b, float z, int trans)
{
    vertex_oc_t vert;
    poly_hdr_t poly;

    if (!trans)
        ta_poly_hdr_col(&poly, TA_OPAQUE);
    else
        ta_poly_hdr_col(&poly, TA_TRANSLUCENT);
    ta_commit_poly_hdr(&poly);

    vert.flags = TA_VERTEX_NORMAL;
    vert.x = x;
    vert.y = y+h-1;
    vert.z = z;
    vert.a = a;
    vert.r = r;
    vert.g = g;
    vert.b = b;
    ta_commit_vertex(&vert, sizeof(vert));

    vert.y = y;
    ta_commit_vertex(&vert, sizeof(vert));

    vert.x = x+w-1;
    vert.y = y+h-1;
    ta_commit_vertex(&vert, sizeof(vert));
	
    vert.flags = TA_VERTEX_EOL;
    vert.y = y;
    ta_commit_vertex(&vert, sizeof(vert));
}

void draw_char(float x1, float y1, float z1, float a, float r, float g, float b, int c, float xs, float ys) {
    vertex_ot_t     vert;
    int             ix, iy;
    float           u1, v1, u2, v2;
    
    ix = (c % 32) * 8;
    iy = (c / 32) * 16;
    u1 = (float)(ix) / 512.0f;
    v1 = (float)(iy) / 512.0f;
    u2 = (ix+8.0f) / 512.0f;
    v2 = (iy+16.0f) / 512.0f;
    
    vert.flags = TA_VERTEX_NORMAL;
    vert.x = x1;
    vert.y = y1 + 16.0f * ys;
    vert.z = z1;
    vert.u = u1;
    vert.v = v2;
    vert.dummy1 = vert.dummy2 = 0;
    vert.a = a;
    vert.r = r;
    vert.g = g;
    vert.b = b;
    vert.oa = vert.or = vert.og = vert.ob = 0.0f;
    ta_commit_vertex(&vert, sizeof(vert));
    
    vert.x = x1;
    vert.y = y1;
    vert.u = u1;
    vert.v = v1;
    ta_commit_vertex(&vert, sizeof(vert));
    
    vert.x = x1 + 8.0f * xs;
    vert.y = y1 + 16.0f * ys;
    vert.u = u2;
    vert.v = v2;
    ta_commit_vertex(&vert, sizeof(vert));
    
    vert.flags = TA_VERTEX_EOL;
    vert.x = x1 + 8.0f * xs;
    vert.y = y1;
    vert.u = u2;
    vert.v = v1;
    ta_commit_vertex(&vert, sizeof(vert));
}

void draw_string(float x, float y, float z, float a, float r, float g, float b, char *str, float xs, float ys) {
  poly_hdr_t poly;
  //ta_poly_hdr_txr(&poly, TA_TRANSLUCENT, TA_ARGB1555, 512, 512, font_tex, TA_BILINEAR_FILTER);
  ta_poly_hdr_txr(&poly, TA_TRANSLUCENT, TA_RGB565, 512, 512, font_tex, TA_BILINEAR_FILTER);
  //ta_poly_hdr_txr(&poly, TA_TRANSLUCENT, TA_ARGB1555, 256, 256, font_tex, TA_BILINEAR_FILTER);
  ta_commit_poly_hdr(&poly);
  
  while (*str) {
    draw_char(x, y, z, a, r, g, b, *str++, xs, ys);
        x+=8*xs;
  }
}

void draw_string_center(float y, float z, float a, float r, float g, float b, char *str, float xs, float ys)
{
    draw_string((640.0f - strlen(str)*8*xs)/2, y, z, a, r, g, b, str, xs, ys);
}

/* void pal();
 *
 *   some very good code thanks to PAL-enforcer
 *
 */

void pal() {
	register uint32 val = *(uint32 *)0xa05f80d8;
	register uint32 val2 = (val>>16) & 0x03ff;

	/* acknowledge break */
	*(uint32 *)0xff200020 |= (1<<14) | (1<<15);

	if ((val2 > 500) && (val2 < 550))  {
		/* NTSC, interlace */
		val = (624<<16) | 863;	/* set PAL, interlace */
        } else if ((val2 > 210) && (val2 < 300)) {
		/* NTSC, non-interlace */
		val = (312<<16) | 863;	/* set PAL, non-interlace */
	} else {
		goto alldone;
	}

	*(uint32 *)0xff200008 = 0;
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	__asm__("nop");
	*(uint32 *)0xa05f80d8 = val;
	*(uint32 *)0xff200008 = (2<<4) | (2<<2);

alldone:
	__asm__("rte");
	__asm__("nop");
        return;
}

/********************* OSD.C *********************/

int osd_fseek(FILE *stream, long offset, int whence)
{
  fs_seek((unsigned int)stream, offset, whence);
  return 0;
}
long osd_ftell(FILE *stream)
{
  return fs_tell((unsigned int)stream);
}

/********************* UNZIP.C ************************/
#include <stdio.h>
//#include <stdlib.h>
#include "shared.h"
#include "unzip.h"
//#include "mame.h"

//#include <string.h>
//#include <ctype.h>
//#include <assert.h>
#include "zlib.h"

#ifndef toupper
#define toupper(c)  ( (c)-'a'+'A' )
#endif

/* public globals */
int	gUnzipQuiet = 0;		/* flag controls error messages */


#define ERROR_CORRUPT "The zipfile seems to be corrupt, please check it"
#define ERROR_FILESYSTEM "Your filesystem seems to be corrupt, please check it"
#define ERROR_UNSUPPORTED "The format of this zipfile is not supported, please recompress it"

#define INFLATE_INPUT_BUFFER_MAX 16384
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif


void logerror (char *fmt, ...) {
	va_list		args;
	char		pbuf[2048];
	va_start(args, fmt);
	vsprintf(pbuf, fmt, args);
	va_end(args);
        printf(pbuf);
        return;
}

/* Print a error message */
void errormsg(const char* extmsg, const char* usermsg, const char* zipname) {
	/* Output to the user with no internal detail */
	if (!gUnzipQuiet)
		printf("Error in zipfile %s\n%s\n", zipname, usermsg);
	/* Output to log file with all informations */
        logerror("Error in zipfile %s: %s\n", zipname, extmsg);
}

/* -------------------------------------------------------------------------
   Unzip support
 ------------------------------------------------------------------------- */

/* Use these to avoid structure padding and byte-ordering problems */
static UINT16 read_word (char *buf) {
   unsigned char *ubuf = (unsigned char *) buf;

   return ((UINT16)ubuf[1] << 8) | (UINT16)ubuf[0];
}

/* Use these to avoid structure padding and byte-ordering problems */
static UINT32 read_dword (char *buf) {
   unsigned char *ubuf = (unsigned char *) buf;

   return ((UINT32)ubuf[3] << 24) | ((UINT32)ubuf[2] << 16) | ((UINT32)ubuf[1] << 8) | (UINT32)ubuf[0];
}

/* Locate end-of-central-dir sig in buffer and return offset
   out:
	*offset offset of cent dir start in buffer
   return:
	==0 not found
	!=0 found, *offset valid
*/
static int ecd_find_sig (char *buffer, int buflen, int *offset)
{
	static char ecdsig[] = { 'P', 'K', 0x05, 0x06 };
	int i;
	for (i=buflen-22; i>=0; i--) {
		if (memcmp(buffer+i, ecdsig, 4) == 0) {
			*offset = i;
			return 1;
		}
	}
	return 0;
}

/* Read ecd data in zip structure
   in:
     zip->fp, zip->length zip file
   out:
  

⌨️ 快捷键说明

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