📄 dc.c
字号:
/*
* 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 Steven Harris (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
*
*/
/*
* This is very nasty code, some parts uncommented,
* some are just plain ugly, beware!
*
* we use the TA to stretch it to full screen
* sound is perfect only when 60fps..
* autoframeskip needs to be implemented
*
* - ss_teven
*/
#include <kos.h>
#include "pcx.h"
#include "font.h"
#include "sndstream.h"
#include "draw.h"
#include "dcVideo.h"
#include "dcp/dcp_image.h"
#include "bitmap.h"
#include "font.h"
#include "smsplus.h"
#include "shared.h"
#include "dc.h"
#include "dt.h"
#include "sq.h"
#include "vmu_icon.h"
int sample_rate = 44100;
void* kos_audio_callback(int size);
int osd_start_audio_stream(int stereo);
void osd_stop_audio_stream(void);
int osd_update_audio_stream(INT16 *buffer);
void osd_set_mastervolume(int _attenuation);
int osd_get_mastervolume(void);
void osd_sound_enable(int enable_it);
void osd_opl_control(int chip,int reg);
void osd_opl_write(int chip,int data);
static uint8 mcont1 = 0;
static uint8 mcont2 = 0;
static uint8 mkeyb1 = 0;
static uint8 mvmu1 = 0;
uint8 *splash;
int do_disp(void);
void disclaimer();
/* store queues stuff, thanks joey and regex */
typedef unsigned short zword;
typedef unsigned zdword;
void doPrestore(uint32 addr);
void sqmemcpy(void *dest, void *src);
zword lookupDiv[256];
char *arrow;
char *space;
void draw_string_center(float y, float z, float a, float r, float g, float b, char *str, float xs, float ys);
void draw_stringf(float x, float y, float z, float a, float r, float g, float b, float xs, float ys, char *fmt, ...);
void draw_string(float x, float y, float z, float a, float r, float g, float b, char *str, float xs, float ys);
void draw_char(float x1, float y1, float z1, float a, float r, float g, float b, int c, float xs, float ys);
void draw_color_rect(int x, int y, int w, int h, float a, float r, float g, float b, float z, int trans);
void font_init(void);
long rnc_unpack (void *packed, void *unpacked);
int jjpeg_to_texture(char * filename, unsigned short *tex, int n, int scale);
uint32 texture=0;
uint32 texture_pool = 0x700000; /* Safe space in TA buffer for allocating textures */
uint32 texture_alloc(uint32 size) {
uint32 rv = texture_pool;
/* Align to 8 bytes */
size = (size + 7) & (~7);
texture_pool += size;
return rv;
}
typedef struct {
float x, y, z;
float u, v;
float dx, dy;
} polyplace_t;
polyplace_t polys = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 3.0f, 5.0f };
static uint32 disc_txr;
static uint32 gui_txr;
static void disc_blank();
static void disc_display(polyplace_t *p);
static void gui_txr_display(float fade, polyplace_t *p);
void bkg_init();
void draw_background();
extern uint32 util_texture;
int frameskip=4;
int frameskip_setting=0,time_frameskip=-1,nb_frames=0,frameskip_delay=0;
int use_auto_frameskip=1, use_sound=1, use_antialias=1;
uint16 *txrtmp;
uint16 *guitxrtmp;
/* settings and vmu stuff */
#include "vmu.h"
void load_default_settings();
//save_user_settings(vmu_mem1);
user_settings settings;
t_rom ROM;
typedef struct {
unsigned long int crc;
char *filename;
char *name;
} t_smscrc;
t_smscrc smscrc_list[] = {
{0xE843BA7E, "/rd/E843BA7E.jpg", "Bubble Bobble"},
};
#include "loadjpeg.h"
uint32 bkg_tex;
int bkg_set;
void bkg_init(char *fileload) {
uint16 *tex;
bkg_tex = ta_txr_allocate(1024*512*2);
tex = ta_txr_map(bkg_tex);
memset(tex, 0, 1024*512*2);
jjpeg_to_texture(fileload, tex, 1024, 1);
}
uint32 covertxr;
void draw_jpgcvr();
void jpegcover(char *fileload) {
uint16 *tex;
poly_hdr_t poly;
//float x = 0.0f, y = 0.0f, w = 640.0f, h = 480.0f;
//vertex_ot_t vert;
covertxr = ta_txr_allocate(512*512*2);
tex = ta_txr_map(covertxr);
memset(tex, 0, 512*512*2);
jjpeg_to_texture(fileload, tex, 512, 1);
ta_poly_hdr_col(&poly, TA_TRANSLUCENT);
ta_begin_render(); draw_jpgcvr();
ta_commit_eol();
ta_commit_poly_hdr(&poly); ta_commit_eol();
ta_finish_frame();
}
void draw_jpgcvr() {
float x = 0.0f, y = 0.0f, w = 640.0f, h = 480.0f;
vertex_ot_t vert;
poly_hdr_t poly;
ta_poly_hdr_txr(&poly, TA_OPAQUE, TA_RGB565, 512, 512, covertxr, TA_BILINEAR_FILTER);
ta_commit_poly_hdr(&poly);
vert.flags = TA_VERTEX_NORMAL;
vert.x = x;
vert.y = y+h-1;
vert.z = 5.0f;
vert.a = vert.r = vert.g = vert.b = 1.0f;
vert.oa = vert.or = vert.og = vert.ob = 0.0f;
vert.u = 0.0f; vert.v = 1.0f;
ta_commit_vertex(&vert, sizeof(vert));
vert.y = y;
vert.v = 0.0f;
ta_commit_vertex(&vert, sizeof(vert));
vert.x = x+w-1;
vert.y = y+h-1;
vert.u = 1.0f; vert.v = 1.0f;
ta_commit_vertex(&vert, sizeof(vert));
vert.flags = TA_VERTEX_EOL;
vert.y = y;
vert.v = 0.0f;
ta_commit_vertex(&vert, sizeof(vert));
}
/* Draw a polygon for a shaded box; wow, a nasty looking func =) */
void draw_poly_box(float x1, float y1, float x2, float y2, float z,
float a1, float r1, float g1, float b1,
float a2, float r2, float g2, float b2) {
return;
}
extern uint8 romdisk_boot[];
int main (int argc, char **argv) {
int z=0,y;
snd.enabled = 0;
sms.use_fm = 0;
kos_init_all(IRQ_ENABLE | THD_ENABLE | TA_ENABLE, romdisk_boot);
frame_skip = max_skip;
init_machine();
gui_txr = ta_txr_allocate(1024*512*2);
disc_txr = gui_txr;
/* this should speed some stuff up quite a bit */
for (y = 0; y < 256; y++)
lookupDiv[y] = 256*(y+(y/15));
frame_count = 0;
txrtmp = (uint16*)ta_txr_map(disc_txr);
guitxrtmp = (uint16*)ta_txr_map(gui_txr);
load_default_settings();
while(z==0) z=emuloop();
system_shutdown();
trash_machine();
return (0);
}
int emuloop() {
int x, mm;
/*
//dc_print("this is a TEST");
bfont_draw_str(guitxrtmp + 20*512+20, 512, 0, "this is a TEST");
//disclaimer();
ta_begin_render();
gui_txr_display(1.0f, &polys);
ta_commit_eol();
disc_blank();
ta_commit_eol();
ta_finish_frame();
//ta_txr_release_all();
//thd_sleep(2000);
*/
mm = SELECT_ROM;//MAIN_MENU
while(1) {
x=draw_gui(mm);//SELECT_ROM
if(x==SELECT_ROM) mm = SELECT_ROM;
if(x==MAIN_MENU) mm = MAIN_MENU;
if(x==EXIT_MENU) break;
}
if(x==1) return 0;
if(snd.enabled) {
system_init(44100);
} else {
system_init(0);
}
load_sram();
if(snd.enabled) {
if (kos_stream_init(kos_audio_callback) < 0) {
dc_print("audio stream error");
thd_sleep(1500);
exit_flag = 1;
}
osd_start_audio_stream(1);
}
/* Main emulation loop */
for(;;) {
/* Exit if exit_flag has been set */
if(exit_flag) break;
/* Bump frame count */
frame_count++;
/* Frame skip */
if(frame_count % frame_skip == 0) {
skip_flag = 0;
} else {
skip_flag = 1;
}
/* Get current input */
update_input();
/* Run the system emulation for a frame */
sms_frame(skip_flag);
/* Update the display/audio */
if(snd.enabled)
osd_update_audio_stream(&snd.buffer[0][0]);
if(skip_flag == 0) {
update_video();
disclaimer();
}
}
save_sram();
clearscr(640,480);
thd_sleep(50);
sms_reset();
if(cart.zip) {
free(f->data);
free(f->filename);
free(f);
}
free(cart.rom);
spu_disable();
stream_stop();
exit_flag=0;
thd_sleep(450);
return(0);
}
void load_default_settings() {
settings.frame_skip = 4;
settings.sound_on = TRUE;
settings.save = FALSE;
}
static void gui_txr_display(float fade, polyplace_t *p) {
poly_hdr_t hdr;
vertex_ot_t vert;
if (fade < 0.0f) fade = 0.0f;
//ta_poly_hdr_col(&hdr, TA_OPAQUE);
ta_poly_hdr_txr(&hdr, TA_OPAQUE, TA_RGB565, 512, 512, gui_txr, TA_NO_FILTER);
ta_commit_poly_hdr(&hdr);
vert.flags = TA_VERTEX_NORMAL; //480
vert.x = p->x + 0.0f; vert.y = p->y + 480.0f; vert.z = p->z;
vert.a = 1.0f; //vert.r = 0.0f; vert.g = 0.0f; vert.b = 0.0f;
vert.r = vert.g = vert.b = fade;
vert.u = 0.0f; vert.v = 1.0f;
ta_commit_vertex(&vert, sizeof(vert));
vert.flags = TA_VERTEX_NORMAL;
vert.x = p->x + 0.0f; vert.y = p->y + 0.0f; vert.z = p->z;
vert.a = 1.0f; //vert.r = 0.0f; vert.g = 0.0f; vert.b = 0.0f;
vert.u = 0.0f; vert.v = 0.0f;
ta_commit_vertex(&vert, sizeof(vert));
vert.flags = TA_VERTEX_NORMAL;
//640 //480
vert.x = p->x + 640.0f; vert.y = p->y + 480.0f; vert.z = p->z;
vert.a = 1.0f; //vert.r = 0.0f; vert.g = 0.0f; vert.b = 0.0f;
vert.u = 1.0f; vert.v = 1.0f;
ta_commit_vertex(&vert, sizeof(vert));
vert.flags = TA_VERTEX_EOL;
//640
vert.x = p->x + 640.0f; vert.y = p->y + 0.0f; vert.z = p->z;
vert.a = 1.0f;// vert.r = vert.g = vert.b = fade;//vert.r = 0.0f; vert.g = 0.0f; vert.b = 0.0f;
vert.u = 1.0f; vert.v = 0.0f;
ta_commit_vertex(&vert, sizeof(vert));
}
void dc_dstring (int x, float r, float g, float b, char *fmt, ...) {
va_list args;
char pbuf[2048];
va_start(args, fmt);
vsprintf(pbuf, fmt, args);
va_end(args);
draw_string(170, x, 6.0f, 1.0f, r, g, b, pbuf, 1.5f, 1.5f);
//bfont_draw_str(uitxrtmp + 400*640+20, 640, 0, pbuf);
}
void draw_stringf(float x, float y, float z, float a, float r, float g, float b, float xs, float ys, char *fmt, ...) {
va_list args;
char pbuf[2048];
va_start(args, fmt);
vsprintf(pbuf, fmt, args);
va_end(args);
draw_string(x, y, z, a, r, g, b, pbuf, xs, ys);
}
void list_menu(int a) {
//space , arrow
if (a == 0) {
dc_dstring(200, 0.0f, 0.0f, 0.0f, "%s Load Rom", arrow);
} else {
dc_dstring(200, 0.0f, 0.0f, 0.0f, "%s Load Rom", space);
}
if (a == 1) {
dc_dstring(225, 0.0f, 0.0f, 0.0f, "%s Continue", arrow);
} else {
dc_dstring(225, 0.0f, 0.0f, 0.0f, "%s Continue", space);
}
if (a == 2) {
dc_dstring(250, 0.0f, 0.0f, 0.0f, "%s Options", arrow);
} else {
dc_dstring(250, 0.0f, 0.0f, 0.0f, "%s Options", space);
}
if (a == 3) {
dc_dstring(275, 0.0f, 0.0f, 0.0f, "%s About", arrow);
} else {
dc_dstring(275, 0.0f, 0.0f, 0.0f, "%s About", space);
}
}
int draw_gui(int o) {
//int i, x, y = (480 - 9*24)/2;
int setbrk;
//o=MAIN_MENU;
if(o == MAIN_MENU) {
poly_hdr_t npoly;
int a,b;
//void draw_color_rect(int x, int y, int w, int h, float a, float r, float g, float b, float z, int trans)
for(a=0;a<120;a++) {
poly_hdr_t poly;
ta_poly_hdr_col(&poly, TA_TRANSLUCENT);
ta_begin_render();
draw_background();
ta_commit_eol();
draw_color_rect(165, 190, 150, a, 0.2f, 0.3f, 0.0f, 1.0f, 5.1f, 1);
ta_commit_poly_hdr(&poly);
ta_commit_eol();
ta_finish_frame();
thd_sleep(3);
}
b=0;
setbrk = 0;
while(setbrk == 0) {
cont_cond_t FirstCont;
int FirstKeyb;
ta_poly_hdr_col(&npoly, TA_TRANSLUCENT);
ta_begin_render();
draw_background();
ta_commit_eol();
draw_color_rect(165, 190, 150, a, 0.2f, 0.3f, 0.0f, 1.0f, 5.1f, 1);
list_menu(b);
ta_commit_poly_hdr(&npoly);
ta_commit_eol();
ta_finish_frame();
ta_begin_render();
draw_background();
ta_commit_eol();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -