📄 msdos.c
字号:
/* Copyright 2001, ESS Technology, Inc. *//* SCCSID @(#)msdos.c 1.40 04/12/05 *//* * $Log$ *//** VGB: portable GameBoy emulator ***************************//** **//** MSDOS.c **//** **//** This file contains MSDOS-dependent subroutines and **//** drivers. It includes common drivers from Common.h. **//** **//** Copyright (C) Marat Fayzullin 1994-2001 **//** You are not allowed to distribute this software **//** commercially. Please, notify me, if you make any **//** changes to this file. **//*************************************************************/#ifndef ROM_IN_CD#ifndef CD_GAME#include "../common.h"#include "../ioport.h"#include "../util.h"#include "../config.h"#include "../servo.h"#endif /*CD_GAME*/#include "../keydef.h"#include "regcom.h"#ifdef INES#include "nes.h"#endif#ifdef VGB#include "gb.h"#endif#include "libmsdos.h"#ifdef SOUND#include "gbsnd.h"#endif#ifndef CD_GAMEextern unsigned short codeIR;volatile int GB_ir_key;extern int GmScnScale;int gameboy_width = 276;#endif /*CD_GAME*/#define USE_STATIC_COLOR#define WIDTH 256 /* Buffer width */#define HEIGHT 224 /* Buffer height */#ifdef INES#define NES_WIDTH 272#define NES_HEIGHT 240#endifpixel *XBuf; /* From Common.h */#ifdef GAMEBOY#ifndef CD_GAMEvoid GM_init_pad();unsigned int GM_key_process();#ifdef BD_COUNTAC8unsigned char save_aux_mode;#endifvoid GM_init_pad(){#ifdef BD_COUNTAC8 /* Set EAUX10 as normal (not SQCK mode) */ save_aux_mode = DSC_cmd(dsc_aux_modem, 0) & 0xff; DSC_cmd(dsc_aux_mode, save_aux_mode & (~0x2)); SERVO_send_command(8, 0x99109000); /* off A.SEQ */#endif#ifdef LIGHT_GUN CLEAR_GUN_AIM; CLEAR_GUN_FIRE; TRI_GUN_AIM; TRI_GUN_FIRE;#endif CLEAR_GM_LATCH0; SET_GM_CLK0; SET_GM_DATA0; TRI_GM_DATA0;#ifdef GB_TWO_PAD SET_GM_DATA1; TRI_GM_DATA1;#endif}#ifdef LIGHT_GUNint gun_fire = 0;int gun_aim = 0;int gun_interval = 2;#endifvoid GM_gun_aimed(){#ifdef LIGHT_GUN if(gun_fire){ if(GUN_AIM_HIGH && gun_aim >gun_interval) { BIT_SET(BIT_AIM); gun_fire = 0; gun_aim = 0; } else { gun_aim++; BIT_RES(BIT_AIM); } } else { BIT_RES(BIT_AIM); gun_aim = 0; }#endif}void GM_gun_fired(){#ifdef LIGHT_GUN extern int NES_U_Period; BIT_SET(BIT_GUN); if (GUN_FIRE_HIGH/*key0 == ZOOM_IN_KEY*/){ BIT_RES(BIT_GUN); if(NES_U_Period >3) NES_U_Period = 3; gun_fire = 1; } else gun_fire = 0;#endif}extern int gmby_name_id;unsigned int GM_key_process(){ int ii, i; unsigned int tt, ret; ret = tt = 0 ;#ifdef IR_GAMEPAD if(GB_ir_key) { ret = GB_ir_key ; return (ret); }#endif/*For HQ, we will define ESS_NEW_PAD */#ifdef ESS_NEW_PAD /*Below is just for one pad connected physically */ if(!(tt&0xFF)) { SET_GM_LATCH0; risc_sleep_a_bit(60); CLEAR_GM_LATCH0; risc_sleep_a_bit(20); TRI_GM_DATA0; for(ii=1; ii<=8; ii++){ tt <<= 1; CLEAR_GM_CLK0; if(!GM_DATA0_HIGH) tt |= 1; risc_sleep_a_bit(40); SET_GM_CLK0; risc_sleep_a_bit(40); } /* The bit0-bit3 is the direction, since we cannot press */ /* 4 dirctions at the same time. i just use it to make */ /* the joypad not go crazy. */ if((tt&0xF) == 0xF) tt = 0; }#ifdef GB_TWO_PAD /* I just check two pad connection, i think it is because we */ /* just share the same clock pin for two pad, so that the 2nd */ /* pad is connected or not will affect the 1st pad's clock, */ /* for this case i just use two kinds of clock for pad */ /*Below is for TWO pads connected physically */ if(! tt){ SET_GM_LATCH0; risc_sleep_a_bit(300); CLEAR_GM_LATCH0; risc_sleep_a_bit(300); TRI_GM_DATA0; TRI_GM_DATA1; for(ii=1; ii<=8; ii++){ tt <<= 1; CLEAR_GM_CLK0; if(!GM_DATA0_HIGH) tt |= 1; if(!GM_DATA1_HIGH) tt |= 0x100; risc_sleep_a_bit(100); SET_GM_CLK0; risc_sleep_a_bit(100); } if( (tt&0xF) == 0xF ) tt &=0xFF00; if( (tt&0x0F00) == 0x0F00) tt &= 0xFF; }#endif#else /*ESS_HK_PAD, no define ESS_NEW_PAD, by default*//*For custmer, we use the old pad codes. but it seems we should *//*Change to different clock setting for different kind of pad */ SET_GM_LATCH0; risc_sleep_a_bit(62); CLEAR_GM_LATCH0; risc_sleep_a_bit(62);// TRI_GM_DATA0;#ifdef GB_TWO_PAD // TRI_GM_DATA1;#endif for(ii=1; ii<=8; ii++){ tt <<= 1; CLEAR_GM_CLK0; if(!GM_DATA0_HIGH) tt |= 1;#ifdef GB_TWO_PAD if(!GM_DATA1_HIGH) tt |= 0x100;#endif risc_sleep_a_bit(262); SET_GM_CLK0; risc_sleep_a_bit(262); }#endif /*ESS_HK_PAD*/#ifdef VGB if(gmby_name_id == 0x20 ){ if(tt){ ret |= (tt&0x0303); /*RIGHT, LEFT*/ ret |= (tt&0x0404)<<1; /*UP*/ ret |= (tt&0x0808)>>1; /*DOWN*/ ret |= (tt&0x1010)<<3; /*START*/ ret |= (tt&0x2020)<<1; /*SELECT*/ ret |= (tt&0xC0C0)>>2; /*AB*/ } ret = ~ret; if(key0==STOP_KEY || key0==EJECT_KEY) { ret = 0x3F; } if (ret == 0x3f){ DISP_do_blank(); /* do DISP_END_DO_BLANK to bring back screen in play?.c */ } }else#endif { if ( tt ) { /*1st start key should not pressed when function keys are pressed*/ /*Just make sure there is no pause action when playing game */ extern int gun_game; if (gun_game ){ if(((tt&0xFF) != 0x10) && ((tt&0xFF) != 0x30)) tt &= 0xEFEF; } else { if ( (tt&0x1010) == 0x1000 ) tt |= 0x10; if ( (tt&0x2020) == 0x2000 ) tt |= 0x20; } ret |= (tt&0x0101)<<7; /* L */ ret |= (tt&0x0202)<<5; /*R */ ret |= (tt&0x0404)<<3; /*UP*/ ret |= (tt&0x0808)<<1; /*DOWN*/ ret |= (tt&0x1010)>>1; /*START*/ ret |= (tt&0x2020)>>3; /*SELECT*/ ret |= (tt&0xC0C0)>>6; /*AB*/ }#ifdef MARANELLO_A9B8 for(i=0;i<5;i++) VFD_game_scankey() ;#endif if(key0==STOP_KEY || key0==EJECT_KEY){ ret = 0x0C; } if (ret == 0x0c){ DISP_do_blank(); /* do DISP_END_DO_BLANK to bring back screen in play?.c */ } } #ifdef BD_COUNTAC8 if ( (ret&0xff) == 0x0c){ /* Set EAUX10 as SQCK mode */ DSC_cmd(dsc_aux_mode, save_aux_mode); SERVO_send_command(8, 0x9b109000); /* set A.SEQ */ } SET_GM_DATA1;#endif if(((ret&0x0404)==0x0404)||((ret&0x0808)==0x0808)) //去掉付手柄 ret = 0; return ( ret );}#endif#ifdef INESvoid NES_SetColor(byte *xpal,byte N,byte R,byte G,byte B, int *pallete){ VGASetColor(xpal[N]=N+1,R,G,B,pallete);}#endif#endif /*CD_GAME*/#ifdef VGB/** InitMachine() ********************************************//** Allocate resources needed by machine-dependent code. **//*************************************************************/int InitMachine(void){ int I,J; GM_init_pad(); GM_init_disp(); GM_hscale(gameboy_width); VGANewImage(&Img,WIDTH,HEIGHT); XBuf=Img.Data;#ifdef SOUND /* Set up Adlib sound driver */ J=InitSound(1);#endif /* Set up screen mode */ /* Create RR:GGG:BBB static color palette if needed */ return(1);}/** TrashMachine() *******************************************//** Deallocate all resources taken by InitMachine(). **//*************************************************************/void TrashMachine(void){#ifdef SOUND TrashSound();#endif GM_hscale_recover();}/** SetColor() ***********************************************//** Set color N to (R,G,B). **//*************************************************************/void SetColor(int N,int R,int G,int B){ gmby->XPal[N]=(R&0xC0)|((G&0xE0)>>2)|((B&0xE0)>>5);}/** Dummies **************************************************//** Dummy functions (for now). **//*************************************************************/int SIOSend(int V) { return(0); }int SIOReceive(int *V) { return(0); }/** Rumble() *************************************************//** "Pull" or "release" the rumble pack vibrator, depending **//** on the argument value. **//*************************************************************/void Rumble(byte Pull){ Pull=Pull? 0x3F:0x00;#ifndef GAMEBOY outp(0x3C8,0); outp(0x3C9,Pull); outp(0x3C9,Pull); outp(0x3C9,Pull); gm_sys_pal[0] = ((int)Pull<<16)|((int)Pull<<8)|((int)Pull);#else#endif}/** Common.h *************************************************//** Part of the code common for Unix/X and MSDOS drivers. **//*************************************************************/#include "common.h"#endif/*VGB*/#ifdef INESint NES_InitMachine(void){ GM_init_pad(); GM_init_disp();/*=======================================*//* Try to init horizontal scale module *//*=======================================*/ GM_hscale(gameboy_width); VGANewImage(&Img,NES_WIDTH,NES_HEIGHT); XBuf=Img.Data; /* Check if joysticks are present */#ifdef SOUND InitSound(1);#endif return(1);}void NES_TrashMachine(void){#ifdef SOUND TrashSound();#endif GM_hscale_recover();}#include "nescom.h"#endif /*GAMEBOY*/#endif /*ROM_IN_CD*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -