Added second joystick, added ZXSpectrum splash screen

This commit is contained in:
fabio.olimpieri 2012-04-20 21:35:00 +00:00
parent 449ed4a2da
commit d9d9f5392b
7 changed files with 105 additions and 65 deletions

View File

@ -121,6 +121,7 @@ dist: $(BUILD)
cp fbzx.dol $@/apps/fbzx-wii/boot.dol
cp spectrum-roms/* $@/fbzx-wii/spectrum-roms
cp keymap.bmp $@/fbzx-wii/fbzx
cp ZXSpectrum48k.png $@/fbzx-wii/fbzx
cp AMSTRAD CAPABILITIES COPYING FAQ README README.TZX VERSIONS $@/apps/fbzx-wii/doc
touch $@/fbzx-wii/tapes/dummy
touch $@/fbzx-wii/snapshots/dummy

BIN
ZXSpectrum48k.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

View File

@ -118,7 +118,7 @@ int save_z80(char *filename) {
value=procesador.IM;
if(ordenador.issue==2)
value|=4;
switch (ordenador.joystick) {
switch (ordenador.joystick[0]) { //Only one Joystick in Z80 file
case 1:
value|=64;
break;
@ -562,7 +562,7 @@ void load_snap(struct z80snapshot *snap) {
break;
}
ordenador.joystick=snap->joystick;
ordenador.joystick[0]=snap->joystick; //Only one Joystick in Z80 file
procesador.Rm.br.A=snap->A;
procesador.Rm.br.F=snap->F;

View File

@ -80,7 +80,8 @@ void computer_init () {
ordenador.port254 = 0;
ordenador.issue = 3;
ordenador.mode128k = 0;
ordenador.joystick = 0;
ordenador.joystick[0] = 2; //Sinclair 1
ordenador.joystick[1] = 3; //Sinclair 2
ordenador.tape_readed = 0;
ordenador.pause = 1; // tape stop
@ -699,13 +700,21 @@ inline void read_keyboard () {
static int countdown;
enum joystate_x {JOY_CENTER_X, JOY_LEFT, JOY_RIGHT};
enum joystate_y {JOY_CENTER_Y, JOY_UP, JOY_DOWN};
int joy_axis_x,joy_axis_y, joy_fire;
int joy_axis_x[2],joy_axis_y[2], loop;
ordenador.k8 = ordenador.k9 = ordenador.k10 = ordenador.k11 =
ordenador.k12 = ordenador.k13 = ordenador.k14 =
ordenador.k15 = 0;
ordenador.jk = 0;
pevento=&evento;
SDL_PollEvent (&evento);
if (pevento->type==SDL_QUIT) {
salir = 0;
return;
}
if (ordenador.kbd_buffer_pointer)
{
if (countdown)
@ -742,30 +751,23 @@ inline void read_keyboard () {
}
}
pevento=&evento;
SDL_PollEvent (&evento);
if (pevento->type==SDL_QUIT) {
salir = 0;
return;
}
SDL_JoystickUpdate();
joy_axis_x = SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 0);
joy_axis_y = SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 1);
joy_fire = SDL_JoystickGetButton(ordenador.joystick_sdl[0], 0); //Wii button A
for(loop=0;loop<ordenador.joystick_number;loop++)
{
joy_axis_x[loop] = SDL_JoystickGetAxis(ordenador.joystick_sdl[loop], 0);
joy_axis_y[loop] = SDL_JoystickGetAxis(ordenador.joystick_sdl[loop], 1);
ordenador.joy_fire[loop] = SDL_JoystickGetButton(ordenador.joystick_sdl[loop], 0); //Wii button A
if (SDL_JoystickGetButton(ordenador.joystick_sdl[0], 6)) help_menu ();
if (SDL_JoystickGetButton(ordenador.joystick_sdl[loop], 6)) help_menu (); //Wii button Home
if (joy_axis_x > 16384) ordenador.joy_axis_x_state[0] = JOY_RIGHT;
else if (joy_axis_x < -16384) ordenador.joy_axis_x_state[0] = JOY_LEFT;
else ordenador.joy_axis_x_state[0] = JOY_CENTER_X;
if (joy_axis_y > 16384) ordenador.joy_axis_y_state[0] = JOY_DOWN;
else if (joy_axis_y < -16384) ordenador.joy_axis_y_state[0] = JOY_UP;
else ordenador.joy_axis_y_state[0] = JOY_CENTER_Y;
if (joy_axis_x[loop] > 16384) ordenador.joy_axis_x_state[loop] = JOY_RIGHT;
else if (joy_axis_x[loop] < -16384) ordenador.joy_axis_x_state[loop] = JOY_LEFT;
else ordenador.joy_axis_x_state[loop] = JOY_CENTER_X;
if (joy_axis_y[loop] > 16384) ordenador.joy_axis_y_state[loop] = JOY_DOWN;
else if (joy_axis_y[loop] < -16384) ordenador.joy_axis_y_state[loop] = JOY_UP;
else ordenador.joy_axis_y_state[loop] = JOY_CENTER_Y;
}
temporal_io = (unsigned int) pevento->key.keysym.sym;
/*
@ -906,38 +908,39 @@ inline void read_keyboard () {
break;
}
}
switch (ordenador.joystick) {
for(loop=0;loop<ordenador.joystick_number;loop++)
{
switch (ordenador.joystick[loop]) {
case 0: // cursor
if (ordenador.joy_axis_y_state[0] == JOY_UP) ordenador.k12|= 8;
if (ordenador.joy_axis_y_state[0] == JOY_DOWN) ordenador.k12|= 16;
if (ordenador.joy_axis_x_state[0] == JOY_RIGHT)ordenador.k12|= 4;
if (ordenador.joy_axis_x_state[0] == JOY_LEFT) ordenador.k11|= 16;
if (joy_fire) ordenador.k12|= 1;
if (ordenador.joy_axis_y_state[loop] == JOY_UP) ordenador.k12|= 8;
if (ordenador.joy_axis_y_state[loop] == JOY_DOWN) ordenador.k12|= 16;
if (ordenador.joy_axis_x_state[loop] == JOY_RIGHT)ordenador.k12|= 4;
if (ordenador.joy_axis_x_state[loop] == JOY_LEFT) ordenador.k11|= 16;
if (ordenador.joy_fire[loop]) ordenador.k12|= 1;
break;
case 1: //Kempston
if (ordenador.joy_axis_y_state[0] == JOY_UP) ordenador.jk|= 8;
if (ordenador.joy_axis_y_state[0] == JOY_DOWN) ordenador.jk|= 4;
if (ordenador.joy_axis_x_state[0] == JOY_RIGHT) ordenador.jk|= 1;
if (ordenador.joy_axis_x_state[0] == JOY_LEFT) ordenador.jk|= 2;
if (joy_fire) ordenador.jk = 16;
if (ordenador.joy_axis_y_state[loop] == JOY_UP) ordenador.jk|= 8;
if (ordenador.joy_axis_y_state[loop] == JOY_DOWN) ordenador.jk|= 4;
if (ordenador.joy_axis_x_state[loop] == JOY_RIGHT) ordenador.jk|= 1;
if (ordenador.joy_axis_x_state[loop] == JOY_LEFT) ordenador.jk|= 2;
if (ordenador.joy_fire[loop]) ordenador.jk |= 16;
break;
case 2: // sinclair 1
if (ordenador.joy_axis_y_state[0] == JOY_UP) ordenador.k11|= 8;
if (ordenador.joy_axis_y_state[0] == JOY_DOWN)ordenador.k11|= 4;
if (ordenador.joy_axis_x_state[0] == JOY_RIGHT)ordenador.k11|= 2;
if (ordenador.joy_axis_x_state[0] == JOY_LEFT) ordenador.k11|= 1;
if (joy_fire) ordenador.k11|= 16;
if (ordenador.joy_axis_y_state[loop] == JOY_UP) ordenador.k11|= 8;
if (ordenador.joy_axis_y_state[loop] == JOY_DOWN)ordenador.k11|= 4;
if (ordenador.joy_axis_x_state[loop] == JOY_RIGHT)ordenador.k11|= 2;
if (ordenador.joy_axis_x_state[loop] == JOY_LEFT) ordenador.k11|= 1;
if (ordenador.joy_fire[loop]) ordenador.k11|= 16;
break;
case 3: // sinclair 2
if (ordenador.joy_axis_y_state[0] == JOY_UP) ordenador.k12|= 2;
if (ordenador.joy_axis_y_state[0] == JOY_DOWN)ordenador.k12|= 4;
if (ordenador.joy_axis_x_state[0] == JOY_RIGHT)ordenador.k12|= 8;
if (ordenador.joy_axis_x_state[0] == JOY_LEFT) ordenador.k12|= 16;
if (joy_fire) ordenador.k12|= 1;
if (ordenador.joy_axis_y_state[loop] == JOY_UP) ordenador.k12|= 2;
if (ordenador.joy_axis_y_state[loop] == JOY_DOWN)ordenador.k12|= 4;
if (ordenador.joy_axis_x_state[loop] == JOY_RIGHT)ordenador.k12|= 8;
if (ordenador.joy_axis_x_state[loop] == JOY_LEFT) ordenador.k12|= 16;
if (ordenador.joy_fire[loop]) ordenador.k12|= 1;
break;
}
@ -1320,7 +1323,7 @@ byte Z80free_In (register word Port) {
// Joystick
if (!(temporal_io & 0x0020)) {
if (ordenador.joystick == 1) {
if ((ordenador.joystick[0] == 1)||(ordenador.joystick[1] == 1)) {
return (ordenador.js);
} else {
return 0; // if Kempston is not selected, emulate it, but always 0

View File

@ -125,7 +125,7 @@ struct computer {
unsigned char bus_value;
unsigned char issue; // 2= 48K issue 2, 3= 48K issue 3
unsigned char mode128k; // 0=48K, 1=128K, 2=+2, 3=+3
unsigned char joystick; // 0=cursor, 1=kempston, 2=sinclair1, 3=sinclair2
unsigned char joystick[2]; // 0=cursor, 1=kempston, 2=sinclair1, 3=sinclair2
unsigned char port254;
@ -195,9 +195,11 @@ struct computer {
unsigned char turbo;
unsigned int kbd_buffer_pointer;
unsigned char *key;
unsigned char joystick_number;
SDL_Joystick *joystick_sdl[2];
int joy_axis_x_state[2];
int joy_axis_y_state[2];
unsigned char joy_axis_x_state[2];
unsigned char joy_axis_y_state[2];
unsigned char joy_fire[2];
};
void computer_init();

View File

@ -32,6 +32,7 @@
#include <string.h>
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include<SDL/SDL_image.h>
#include "sound.h"
#include "tape.h"
#include "microdrive.h"
@ -64,6 +65,28 @@ unsigned int colors[80];
unsigned int jump_frames,curr_frames;
char *filenames[5];
int load_zxspectrum_picture()
{
SDL_Surface *image;
SDL_Rect dest;
image=IMG_Load("/fbzx-wii/fbzx/ZXSpectrum48k.png");
if (image == NULL) {printf("Impossible to load image\n"); return 0;}
SDL_BlitSurface(image, NULL, ordenador.screen, NULL);
if (ordenador.mustlock) {
SDL_UnlockSurface (ordenador.screen);
SDL_Flip (ordenador.screen);
SDL_LockSurface (ordenador.screen);
} else {
SDL_Flip (ordenador.screen);
}
return 1;
}
void SDL_Fullscreen_Switch()
{
Uint32 flags = screen->flags;
@ -219,7 +242,7 @@ void load_rom(char type) {
void init_screen(int resx,int resy,int depth,int fullscreen,int dblbuffer,int hwsurface) {
int retorno,bucle,bucle2,valores,ret2,joystick_number;
int retorno,bucle,bucle2,valores,ret2;
unsigned char value;
//if (sound_type!=3)
@ -239,9 +262,10 @@ void init_screen(int resx,int resy,int depth,int fullscreen,int dblbuffer,int hw
ordenador.use_js=1;
if(SDL_NumJoysticks()>0){
// Open joystick
joystick_number = SDL_NumJoysticks();
if (joystick_number>2) joystick_number = 2; //Open max 2 joysticks
for (bucle=0;bucle<joystick_number;bucle++) {
ordenador.joystick_number = SDL_NumJoysticks();
if (ordenador.joystick_number>2) ordenador.joystick_number = 2; //Open max 2 joysticks
printf("Try to open %d joysticks \n", ordenador.joystick_number);
for (bucle=0;bucle<ordenador.joystick_number;bucle++) {
ordenador.joystick_sdl [bucle] = SDL_JoystickOpen(bucle);
if (NULL==ordenador.joystick_sdl [bucle]) {
printf("Can't open joystick %d\n",bucle);
@ -382,7 +406,8 @@ void save_config(struct computer *object) {
}
fprintf(fconfig,"mode=%c%c",48+object->mode128k,10);
fprintf(fconfig,"issue=%c%c",48+object->issue,10);
fprintf(fconfig,"joystick=%c%c",48+object->joystick,10);
fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10);
fprintf(fconfig,"joystick2=%c%c",48+object->joystick[1],10);
fprintf(fconfig,"ay_sound=%c%c",48+object->ay_emul,10);
fprintf(fconfig,"interface1=%c%c",48+object->mdr_active,10);
fprintf(fconfig,"doublescan=%c%c",48+object->dblscan,10);
@ -397,7 +422,7 @@ void load_config(struct computer *object) {
char line[1024],carac,done;
int length,pos;
FILE *fconfig;
unsigned char volume=255,mode128k=255,issue=255,joystick=255,ay_emul=255,mdr_active=255,dblscan=255,bw=255;
unsigned char volume=255,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255,dblscan=255,bw=255;
strcpy(config_path,getenv("HOME"));
length=strlen(config_path);
@ -441,8 +466,12 @@ void load_config(struct computer *object) {
issue=line[6]-'0';
continue;
}
if (!strncmp(line,"joystick=",9)) {
joystick=line[9]-'0';
if (!strncmp(line,"joystick1=",9)) {
joystick1=line[9]-'0';
continue;
}
if (!strncmp(line,"joystick2=",9)) {
joystick2=line[9]-'0';
continue;
}
if (!strncmp(line,"ay_sound=",9)) {
@ -473,8 +502,11 @@ void load_config(struct computer *object) {
if (issue<4) {
object->issue=issue;
}
if (joystick<4) {
object->joystick=joystick;
if (joystick1<4) {
object->joystick[0]=joystick1;
}
if (joystick2<4) {
object->joystick[1]=joystick2;
}
if (ay_emul<2) {
object->ay_emul=ay_emul;
@ -690,6 +722,8 @@ int main(int argc,char *argv[]) {
ordenador.current_tap[0]=0;
if (load_zxspectrum_picture()) sleep(5);
// assign random values to the memory before start execution
printf("Reset memory\n");

View File

@ -114,7 +114,7 @@ void settings_menu() {
print_string(fbuffer,texto,-1,45,14,0,ancho);
switch(ordenador.joystick) {
switch(ordenador.joystick[0]) {
case 0:
sprintf(texto,"Joystick emulation: Cursor");
break;
@ -253,16 +253,16 @@ void settings_menu() {
ResetComputer();
break;
case SDLK_7:
ordenador.joystick=0;
ordenador.joystick[0]=0;
break;
case SDLK_8:
ordenador.joystick=1;
ordenador.joystick[0]=1;
break;
case SDLK_9:
ordenador.joystick=2;
ordenador.joystick[0]=2;
break;
case SDLK_0:
ordenador.joystick=3;
ordenador.joystick[0]=3;
break;
case SDLK_i:
if(ordenador.mode128k!=3) {