Added smb and usb support; changed buzzer sound emulation

This commit is contained in:
fabio.olimpieri 2012-05-12 12:39:49 +00:00
parent 2023bc539e
commit f9acf58de0
6 changed files with 288 additions and 60 deletions

View File

@ -137,6 +137,12 @@ void computer_init () {
ordenador.key = SDL_GetKeyState(NULL); ordenador.key = SDL_GetKeyState(NULL);
ordenador.joybuttonkey[0][0]=SDLK_LALT; //Fire button to wiimote1 button A ordenador.joybuttonkey[0][0]=SDLK_LALT; //Fire button to wiimote1 button A
ordenador.joybuttonkey[1][0]=SDLK_LALT; //Fire button to wiimote1 button A ordenador.joybuttonkey[1][0]=SDLK_LALT; //Fire button to wiimote1 button A
ordenador.port=0; //PORT SD
ordenador.smb_enable=0;
strcpy (ordenador.SmbUser,"User");
strcpy (ordenador.SmbPwd, "Password");
strcpy (ordenador.SmbShare, "Share");
strcpy (ordenador.SmbIp, "192.168.0.1");
} }

View File

@ -207,6 +207,13 @@ struct computer {
unsigned int joybuttonkey[2][22]; unsigned int joybuttonkey[2][22];
unsigned char joypad_as_joystick[2]; unsigned char joypad_as_joystick[2];
unsigned char rumble[2]; unsigned char rumble[2];
unsigned char port; //SD, USB or SMB
unsigned char smb_enable;
unsigned char SmbUser[32];
unsigned char SmbPwd[32];
unsigned char SmbShare[32];
unsigned char SmbIp[32];
}; };
void computer_init(); void computer_init();

View File

@ -42,6 +42,9 @@
#ifdef GEKKO #ifdef GEKKO
#include <gccore.h> #include <gccore.h>
#include <fat.h> #include <fat.h>
#include <ogc/usbstorage.h>
#include <network.h>
#include <smb.h>
#endif #endif
#ifdef DEBUG #ifdef DEBUG
@ -69,6 +72,108 @@ unsigned int jump_frames,curr_frames;
char *filenames[5]; char *filenames[5];
static SDL_Surface *image; static SDL_Surface *image;
bool usbismount = false;
bool networkisinit = false;
bool smbismount = false;
#if defined(GEKKO)
/****************************************************************************
* Mount SMB Share
****************************************************************************/
bool ConnectShare ()
{
if(smbismount)
return true;
printf("user: %s\n", ordenador.SmbUser);
printf("pass: %s\n", ordenador.SmbPwd);
printf("share: %s\n", ordenador.SmbShare);
printf("ip: %s\n", ordenador.SmbIp);
int a;
for (a=0;a<3;a++)
if(smbInit(ordenador.SmbUser, ordenador.SmbPwd,ordenador.SmbShare, ordenador.SmbIp))
{smbismount = true; break;}
if(!smbismount) printf("Failed to connect to SMB share\n");
else {
printf("Established connection to SMB share\n");
}
return smbismount;
}
void CloseShare()
{
if(smbismount) {
printf("Disconnected from SMB share\n");
smbClose("smb");
}
smbismount = false;
}
/****************************************************************************
* init and deinit USB device functions
****************************************************************************/
bool InitUSB()
{
printf("Initializing USB FAT subsytem ...\n");
fatUnmount("usb:");
// This should wake up the drive
bool isMounted = fatMountSimple("usb", &__io_usbstorage);
bool isInserted = __io_usbstorage.isInserted();
if (!isInserted)
{
printf("USB device not found\n");
return false;
}
// USB Drive may be "sleeeeping"
// We need to try Mounting a few times to wake it up
int retry = 10;
while (retry && !isMounted)
{
sleep(1);
isMounted = fatMountSimple("usb", &__io_usbstorage);
retry--;
}
if (isMounted)
printf("USB FAT subsytem initialized\n");
else
printf("Impossible to initialize USB FAT subsytem\n");
return isMounted;
}
void DeInitUSB()
{
fatUnmount("usb:");
__io_usbstorage.shutdown();
}
bool InitNetwork()
{
char myIP[16];
memset(myIP, 0, sizeof(myIP));
printf("Getting IP address via DHCP...\n");
if (if_config(myIP, NULL, NULL, true) < 0) {
printf("No DHCP reply\n");
return false;
}
printf("Got an address: %s\n",myIP);
return true;
}
#endif
int load_zxspectrum_picture() int load_zxspectrum_picture()
{ {
@ -421,6 +526,7 @@ void save_config(struct computer *object) {
fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10); fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10);
fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10); fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10);
fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10); fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10);
fprintf(fconfig,"port=%c%c",48+object->port,10);
for (joy_n=0; joy_n<2; joy_n++) for (joy_n=0; joy_n<2; joy_n++)
@ -431,14 +537,83 @@ void save_config(struct computer *object) {
} }
void load_config_smb(struct computer *object) {
char line[1024],carac,done;
int pos;
FILE *fconfig;
unsigned char smb_enable=0;
fconfig = fopen("/fbzx-wii/fbzx.smb","r");
if (fconfig==NULL) {
return;
}
done=1;
pos=0;
line[0]=0;
while(!feof(fconfig)) {
if (done) {
line[0]=0;
pos=0;
done=0;
}
if (0!=fread(&carac,1,1,fconfig)) {
if ((carac!=13)&&(carac!=10)) {
line[pos]=carac;
if (pos<1023) {
pos++;
}
continue;
}
}
done=1;
line[pos]=0;
if (line[0]=='#') { // comment
continue;
}
if (!strncmp(line,"smb_enable=",11)) {
smb_enable=line[11]-'0';
continue;
}
if (!strncmp(line,"user=",5)) {
if (line[5])
strcpy (object->SmbUser,line+5);
continue;
}
if (!strncmp(line,"password=",9)) {
if (line[9])
strcpy (object->SmbPwd,line+9);
continue;
}
if (!strncmp(line,"share_name=",11)) {
if (line[11])
strcpy (object->SmbShare,line+11);
continue;
}
if (!strncmp(line,"smb_ip=",7)) {
if (line[7])
strcpy (object->SmbIp,line+7);
continue;
}
if (smb_enable<2) {
object->smb_enable=smb_enable;}
}
fclose(fconfig);
}
void load_config(struct computer *object) { void load_config(struct computer *object) {
char config_path[1024]; char config_path[1024];
char line[1024],carac,done; char line[1024],carac,done;
int length,pos, key_sdl=0;; int length,pos, key_sdl=0;
FILE *fconfig; FILE *fconfig;
unsigned char volume=16,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255, unsigned char volume=16,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255,
dblscan=255,bw=255, tap_fast=0, joypad1=0, joypad2=0, rumble1=0, rumble2=0, joy_n=0, key_n=0; dblscan=255,bw=255, tap_fast=0, joypad1=0, joypad2=0, rumble1=0, rumble2=0, joy_n=0, key_n=0, port=0;
strcpy(config_path,getenv("HOME")); strcpy(config_path,getenv("HOME"));
length=strlen(config_path); length=strlen(config_path);
@ -470,7 +645,7 @@ void load_config(struct computer *object) {
} }
done=1; done=1;
line[pos]=0; line[pos]=0;
if (line[0]=='#') { // coment if (line[0]=='#') { // comment
continue; continue;
} }
if (!strncmp(line,"mode=",5)) { if (!strncmp(line,"mode=",5)) {
@ -530,6 +705,10 @@ void load_config(struct computer *object) {
rumble2=line[8]-'0'; rumble2=line[8]-'0';
continue; continue;
} }
if (!strncmp(line,"port=",5)) {
port=line[5]-'0';
continue;
}
if (!strncmp(line,"joybutton_",10)) { if (!strncmp(line,"joybutton_",10)) {
sscanf(line, "joybutton_%c_%c=%3d",&joy_n ,&key_n, &key_sdl); sscanf(line, "joybutton_%c_%c=%3d",&joy_n ,&key_n, &key_sdl);
if ((joy_n<50) && (joy_n>47) && (key_n<119) && (key_n>96)) if ((joy_n<50) && (joy_n>47) && (key_n<119) && (key_n>96))
@ -581,6 +760,9 @@ void load_config(struct computer *object) {
if (rumble2<2) { if (rumble2<2) {
object->rumble[1]=rumble2; object->rumble[1]=rumble2;
} }
if (port<3) {
object->port=port;
}
fclose(fconfig); fclose(fconfig);
} }
@ -621,13 +803,12 @@ int main(int argc,char *argv[]) {
//initialize libfat library //initialize libfat library
if (!fatInitDefault()) if (!fatInitDefault())
{ {
printf("Couldn't initialize SD fat subsytem\n\n"); printf("Couldn't initialize SD fat subsytem\n");
exit(0); exit(0);
} }
else else
printf("SD FAT subsytem initialized\n\n"); printf("SD FAT subsytem initialized\n");
#endif #endif
@ -774,7 +955,18 @@ int main(int argc,char *argv[]) {
menu_init(ordenador.screen); menu_init(ordenador.screen);
//Load the splash screen //Load the splash screen
if (load_zxspectrum_picture()) {sleep(1); SDL_FreeSurface (image);} if (load_zxspectrum_picture()) SDL_FreeSurface (image);
#ifdef GEKKO
usbismount = InitUSB();
load_config_smb(&ordenador);
if (ordenador.smb_enable) networkisinit = InitNetwork();
if (networkisinit && ordenador.smb_enable) ConnectShare();
#endif
// assign initial values for PATH variables // assign initial values for PATH variables
@ -790,6 +982,17 @@ int main(int argc,char *argv[]) {
strcat(path_mdrs,"microdrives"); strcat(path_mdrs,"microdrives");
strcat(path_scr,"scr"); strcat(path_scr,"scr");
#ifdef GEKKO
if ((ordenador.port==1)&&usbismount) {
strcpy(path_snaps,"usb:/");
strcpy(path_taps,"usb:/");
}
if ((ordenador.port==2)&&smbismount) {
strcpy(path_snaps,"smb:/");
strcpy(path_taps,"smb:/");
}
#endif
ordenador.current_tap[0]=0; ordenador.current_tap[0]=0;
// assign random values to the memory before start execution // assign random values to the memory before start execution
@ -910,6 +1113,8 @@ int main(int argc,char *argv[]) {
} }
#ifdef GEKKO #ifdef GEKKO
if (smbismount) CloseShare ();
DeInitUSB();
fatUnmount(0); fatUnmount(0);
#endif #endif

View File

@ -38,7 +38,7 @@
#define ID_BUTTON_OFFSET 0 #define ID_BUTTON_OFFSET 0
#define ID_AXIS_OFFSET 32 #define ID_AXIS_OFFSET 32
//extern int usbismount, smbismount; per ora extern int usbismount, smbismount;
#ifdef DEBUG #ifdef DEBUG
extern FILE *fdebug; extern FILE *fdebug;
@ -127,6 +127,9 @@ static const char *tools_messages[] = {
/*04*/ "Load SCR", /*04*/ "Load SCR",
/*05*/ " ", /*05*/ " ",
/*06*/ "Insert poke", /*06*/ "Insert poke",
/*07*/ " ",
/*08*/ "Port",
/*09*/ "^|sd|usb|smb",
NULL NULL
}; };
@ -137,10 +140,10 @@ static const char *help_messages[] = {
/*03*/ "#2buttons in the 'Wiimote' menu and", /*03*/ "#2buttons in the 'Wiimote' menu and",
/*04*/ "#2change emulation options in the Settings menu.", /*04*/ "#2change emulation options in the Settings menu.",
/*05*/ "#2 ", /*05*/ "#2 ",
/*06*/ "#2 ", /*06*/ "#2The easiest way to play a game is to load",
/*07*/ "#2 ", /*07*/ "#2a snapshot (.z80 and .sna files).",
/*08*/ "#2 ", /*08*/ "#2You can also insert a tape file (.tap and .tzx)",
/*09*/ "#2 ", /*09*/ "#2and then load the file in the tape menu.",
/*10*/ "#2 ", /*10*/ "#2 ",
/*11*/ "#2More information is available on the wiki:", /*11*/ "#2More information is available on the wiki:",
/*12*/ "#2 http://wiibrew.org/wiki/FBZX_Wii", /*12*/ "#2 http://wiibrew.org/wiki/FBZX_Wii",
@ -181,7 +184,8 @@ static void insert_tape()
fclose(ordenador.tap_file); fclose(ordenador.tap_file);
} }
ordenador.tap_file=fopen(filename,"r+"); // read and write if (!strncmp(filename,"smb:",4)) ordenador.tap_file=fopen(filename,"r"); //tinysmb does not work with r+
else ordenador.tap_file=fopen(filename,"r+"); // read and write
ordenador.tape_write = 0; // by default, can't record ordenador.tape_write = 0; // by default, can't record
@ -684,15 +688,59 @@ static void save_scr()
} }
} }
static void set_port(int which)
{
int length;
switch (which)
{
case 0: //PORT_SD
strcpy(path_snaps,getenv("HOME"));
length=strlen(path_snaps);
if ((length>0)&&(path_snaps[length-1]!='/'))
strcat(path_snaps,"/");
strcpy(path_taps,path_snaps);
strcat(path_snaps,"snapshots");
strcat(path_taps,"tapes");
ordenador.port = which;
break;
case 1: //PORT_USB
if (usbismount) {
strcpy(path_snaps,"usb:/");
strcpy(path_taps,"usb:/");
ordenador.port = which;}
else
msgInfo("USB is not mounted",3000,NULL);
break;
case 2: //PORT_SMB
if (smbismount) {
strcpy(path_snaps,"smb:/");
strcpy(path_taps,"smb:/");
ordenador.port = which;}
else
msgInfo("SMB is not mounted",3000,NULL);
break;
default:
break;
}
}
static void tools() static void tools()
{ {
int opt ; int opt ;
int submenus[1];
memset(submenus, 0, sizeof(submenus));
submenus[0] = ordenador.port;
opt = menu_select_title("Tools menu", opt = menu_select_title("Tools menu",
tools_messages, NULL); tools_messages, submenus);
if (opt < 0) if (opt < 0)
return; return;
set_port(submenus[0]);
switch(opt) switch(opt)
{ {
case 0: // Show keyboard case 0: // Show keyboard
@ -714,39 +762,6 @@ static void tools()
} }
/*
static void set_Port(int which)
{
switch (which)
{
case PORT_SD:
prefs_set_attr ("floppy_path", strdup_path_expand (TARGET_FLOPPY_PATH));
changed_prefs.Port = which;
currprefs.Port = changed_prefs.Port;
break;
case PORT_USB:
if (usbismount) {
prefs_set_attr ("floppy_path", strdup_path_expand (TARGET_USB_PATH));
changed_prefs.Port = which;
currprefs.Port = changed_prefs.Port;}
else
msgInfo("USB is not mounted",3000,NULL);
break;
case PORT_SMB:
if (smbismount) {
prefs_set_attr ("floppy_path", strdup_path_expand (TARGET_SMB_PATH));
changed_prefs.Port = which;
currprefs.Port = changed_prefs.Port;}
else
msgInfo("SMB is not mounted",3000,NULL);
break;
default:
break;
}
}
*/
void virtual_keyboard(void) void virtual_keyboard(void)
{ {
int key_code; int key_code;

View File

@ -696,7 +696,8 @@ void select_tapfile() {
fclose(ordenador.tap_file); fclose(ordenador.tap_file);
} }
ordenador.tap_file=fopen(filename,"r+"); // read and write if (!strncmp(filename,"smb:",4)) ordenador.tap_file=fopen(filename,"r"); //tinysmb does not work with r+
else ordenador.tap_file=fopen(filename,"r+"); // read and write
ordenador.tape_write = 0; // by default, can't record ordenador.tape_write = 0; // by default, can't record
if(ordenador.tap_file==NULL) if(ordenador.tap_file==NULL)
retorno=-1; retorno=-1;

View File

@ -291,17 +291,11 @@ inline void play_sound (unsigned int tstados) {
if (sound_type!=1) //!SOUND_OSS if (sound_type!=1) //!SOUND_OSS
for (bucle = 0; bucle < ordenador.increment; bucle++) { for (bucle = 0; bucle < ordenador.increment; bucle++) {
sample_v = ordenador.sample1b[bucle]; sample_v = ordenador.sample1b[bucle];
if ((ordenador.sound_bit) && (sample_v)) { if ((ordenador.sound_bit) && (sample_v))
ordenador.sound_current_value+=(ordenador.tst_sample/8);
if(ordenador.sound_current_value>ordenador.volume*4)
ordenador.sound_current_value=ordenador.volume*4; ordenador.sound_current_value=ordenador.volume*4;
} else { else ordenador.sound_current_value=0;
if(ordenador.sound_current_value>=(ordenador.tst_sample/8))
ordenador.sound_current_value-=((ordenador.tst_sample)/8);
else
ordenador.sound_current_value = 0;
}
value = ordenador.sound_current_value; value = ordenador.sound_current_value;
if (ordenador.ay_emul) { // if emulation is ON, emulate it if (ordenador.ay_emul) { // if emulation is ON, emulate it
if ((ordenador.ayval_a) && (sample_v) if ((ordenador.ayval_a) && (sample_v)
&& (!(ordenador.ay_registers[7] & 0x01))) && (!(ordenador.ay_registers[7] & 0x01)))