Commit 262a4b12 authored by Sergio Costas's avatar Sergio Costas

Moved the keyboard to its own class

parent 26b0f047
......@@ -7,8 +7,8 @@ CPPFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -O2 -D D_SOUND_PULSE
LDFLAGS += `pkg-config --libs sdl libpulse-simple alsa`
fbzx: cargador.o cmdline.o computer.o emulator.o llscreen.o llsound.o menus.o microdrive.o osd.o screen.o signals.o spk_ay.o tape.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o
$(LN) -o fbzx cargador.o cmdline.o computer.o emulator.o llscreen.o llsound.o menus.o microdrive.o osd.o screen.o signals.o spk_ay.o tape.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o $(LDFLAGS)
fbzx: cargador.o cmdline.o computer.o emulator.o keyboard.o llscreen.o llsound.o menus.o microdrive.o osd.o screen.o signals.o spk_ay.o tape.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o
$(LN) -o fbzx cargador.o cmdline.o computer.o emulator.o keyboard.o llscreen.o llsound.o menus.o microdrive.o osd.o screen.o signals.o spk_ay.o tape.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o $(LDFLAGS)
Z80free.o: z80free/Z80free.c z80free/Z80free.h
$(CC) -o Z80free.o z80free/Z80free.c
......@@ -34,25 +34,28 @@ Z80free_codesDDCB.o: z80free/Z80free_codesDDCB.c z80free/Z80free.h
Z80free_codesFDCB.o: z80free/Z80free_codesFDCB.c z80free/Z80free.h
$(CC) -o Z80free_codesFDCB.o z80free/Z80free_codesFDCB.c
cargador.o: cargador.cpp emulator.hh screen.hh osd.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh cargador.hh
cargador.o: cargador.cpp keyboard.hh emulator.hh screen.hh osd.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh cargador.hh
$(CPP) $(CPPFLAGS) -o cargador.o cargador.cpp
cmdline.o: cmdline.cpp cmdline.hh
$(CPP) $(CPPFLAGS) -o cmdline.o cmdline.cpp
computer.o: computer.cpp z80free/Z80free.h llsound.hh computer.hh screen.hh signals.hh llscreen.hh tape.hh emulator.hh osd.hh spk_ay.hh microdrive.hh menus.hh
computer.o: computer.cpp z80free/Z80free.h llsound.hh keyboard.hh computer.hh screen.hh signals.hh llscreen.hh tape.hh emulator.hh osd.hh spk_ay.hh microdrive.hh menus.hh
$(CPP) $(CPPFLAGS) -o computer.o computer.cpp
emulator.o: emulator.cpp llsound.hh cmdline.hh computer.hh screen.hh signals.hh llscreen.hh z80free/Z80free.h tape.hh emulator.hh osd.hh microdrive.hh menus.hh cargador.hh
emulator.o: emulator.cpp keyboard.hh llsound.hh cmdline.hh computer.hh screen.hh signals.hh llscreen.hh z80free/Z80free.h tape.hh emulator.hh osd.hh microdrive.hh menus.hh cargador.hh
$(CPP) $(CPPFLAGS) -o emulator.o emulator.cpp
keyboard.o: keyboard.cpp keyboard.hh
$(CPP) $(CPPFLAGS) -o keyboard.o keyboard.cpp
llscreen.o: llscreen.cpp osd.hh font.h llscreen.hh
$(CPP) $(CPPFLAGS) -o llscreen.o llscreen.cpp
llsound.o: llsound.cpp emulator.hh screen.hh osd.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh llsound.hh
$(CPP) $(CPPFLAGS) -o llsound.o llsound.cpp
menus.o: menus.cpp llsound.hh llscreen.hh menus.hh tape.hh signals.hh emulator.hh screen.hh osd.hh z80free/Z80free.h computer.hh cargador.hh
menus.o: menus.cpp keyboard.hh llsound.hh llscreen.hh menus.hh tape.hh signals.hh emulator.hh screen.hh osd.hh z80free/Z80free.h computer.hh cargador.hh
$(CPP) $(CPPFLAGS) -o menus.o menus.cpp
microdrive.o: microdrive.cpp osd.hh emulator.hh screen.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh microdrive.hh
......@@ -61,7 +64,7 @@ microdrive.o: microdrive.cpp osd.hh emulator.hh screen.hh z80free/Z80free.h comp
osd.o: osd.cpp osd.hh
$(CPP) $(CPPFLAGS) -o osd.o osd.cpp
screen.o: screen.cpp computer.hh screen.hh signals.hh llscreen.hh z80free/Z80free.h tape.hh emulator.hh osd.hh
screen.o: screen.cpp keyboard.hh computer.hh screen.hh signals.hh llscreen.hh z80free/Z80free.h tape.hh emulator.hh osd.hh
$(CPP) $(CPPFLAGS) -o screen.o screen.cpp
signals.o: signals.cpp signals.hh
......
......@@ -24,6 +24,7 @@
#include <string.h>
#include "computer.hh"
#include "emulator.hh"
#include "keyboard.hh"
void uncompress_z80(FILE *fichero,int length,unsigned char *memo) {
......@@ -109,7 +110,7 @@ int save_z80(char *filename) {
value=procesador.IM;
if(ordenador->issue==2)
value|=4;
switch (ordenador->joystick) {
switch (keyboard->joystick) {
case 1:
value|=64;
break;
......@@ -587,7 +588,7 @@ void load_snap(struct z80snapshot *snap) {
break;
}
ordenador->joystick=snap->joystick;
keyboard->joystick=snap->joystick;
procesador.Rm.br.A=snap->A;
procesador.Rm.br.F=snap->F;
......
This diff is collapsed.
......@@ -51,18 +51,6 @@ public:
bool contended_zone; // 0-> no contention; 1-> contention possible
int cicles_counter; // counts how many pixel clock cicles passed since las interrupt
// keyboard private global variables
unsigned char s8,s9,s10,s11,s12,s13,s14,s15;
unsigned char k8,k9,k10,k11,k12,k13,k14,k15;
unsigned char readed;
unsigned char tab_extended;
unsigned char esc_again;
// kempston joystick private global variables
unsigned char js,jk;
// Linux joystick private global variables
unsigned char updown,leftright;
......@@ -90,7 +78,6 @@ public:
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 port254;
......@@ -139,7 +126,6 @@ public:
void do_contention();
};
void read_keyboard(SDL_Event *pevento2);
void fill_audio(void *udata,Uint8 *,int);
void ResetComputer();
......
......@@ -33,6 +33,7 @@
#include "computer.hh"
#include "cmdline.hh"
#include "llsound.hh"
#include "keyboard.hh"
char debug_var=1;
......@@ -200,7 +201,7 @@ 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,"joystick=%c%c",48+keyboard->joystick,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",object->dblscan ? '1' : '0',10);
......@@ -292,7 +293,7 @@ void load_config(struct computer *object) {
object->issue=issue;
}
if (joystick<4) {
object->joystick=joystick;
keyboard->joystick=joystick;
}
if (ay_emul<2) {
object->ay_emul=ay_emul;
......@@ -347,6 +348,7 @@ int main(int argc,char *argv[]) {
llsound = new LLSound(sound_type);
OOTape = new Tape();
keyboard = new Keyboard();
ordenador = new computer();
load_config(ordenador);
......@@ -491,7 +493,7 @@ int main(int argc,char *argv[]) {
ordenador->mdr_paged = 2;
if(ordenador->interr==1) {
read_keyboard (NULL); // read the physical keyboard
keyboard->read_keyboard (NULL); // read the physical keyboard
Z80free_INT(&procesador,ordenador->bus_empty());
ordenador->interr=0;
}
......
/*
* keyboard.cpp
*
* Created on: 27/03/2015
* Author: raster
*/
#include "keyboard.hh"
#include "computer.hh"
#include "llsound.hh"
#include "menus.hh"
class Keyboard *keyboard;
Keyboard::Keyboard() {
this->s8 = this->s9 = this->s10 = this->s11 = this->s12 = this->s13 = this->s14 = this->s15 = 0xFF;
this->tab_extended = false;
this->esc_again = false;
this->js = 0x00;
this->readed = 0;
this->joystick = 0;
}
void Keyboard::reset() {
this->s8|=0x1F;
this->s9|=0x1F;
this->s10|=0x1F;
this->s11|=0x1F;
this->s12|=0x1F;
this->s13|=0x1F;
this->s14|=0x1F;
this->s15|=0x1F;
this->js=0;
}
// Read the keyboard and stores the flags
void Keyboard::read_keyboard (SDL_Event *pevento2) {
unsigned int temporal_io;
SDL_Event evento,evento2,*pevento;
Sint16 valor;
Uint8 eje;
if (pevento2==NULL) {
pevento=&evento;
if (!SDL_PollEvent (&evento))
return;
} else {
pevento=pevento2;
}
if (pevento->type==SDL_QUIT) {
salir = 0;
return;
}
if (pevento->type==SDL_JOYBUTTONDOWN) {
pevento->type=SDL_KEYDOWN;
pevento->key.keysym.sym=SDLK_MENU; // emulate pressing the MENU key
}
if (pevento->type==SDL_JOYBUTTONUP) {
pevento->type=SDL_KEYUP;
pevento->key.keysym.sym=SDLK_MENU; // emulate depressing the MENU key
}
if (pevento->type==SDL_JOYAXISMOTION) {
eje=pevento->jaxis.axis;
valor=pevento->jaxis.value;
evento2.type=SDL_KEYUP;
if ((valor<16384)&&(valor>-16384)) { // JoyStick centered
pevento->type=SDL_KEYUP;
if (eje==1) {
evento2.key.keysym.sym=SDLK_DOWN;
pevento->key.keysym.sym=SDLK_UP; // pull up both keys
read_keyboard(&evento2);
}
if (eje==0) {
evento2.key.keysym.sym=SDLK_LEFT;
pevento->key.keysym.sym=SDLK_RIGHT;
read_keyboard(&evento2);
}
} else { // JoyStick moved
if (eje==0) {
if (valor>=0) {
evento2.key.keysym.sym=SDLK_LEFT; // pull up LEFT
read_keyboard(&evento2);
pevento->key.keysym.sym=SDLK_RIGHT; // and press RIGHT
} else {
evento2.key.keysym.sym=SDLK_RIGHT; // pull up RIGHT
read_keyboard(&evento2);
pevento->key.keysym.sym=SDLK_LEFT; // and press LEFT
}
}
if (eje==1) {
if (valor<0) {
evento2.key.keysym.sym=SDLK_DOWN; // pull up DOWN
pevento->key.keysym.sym=SDLK_UP; // and press UP
read_keyboard(&evento2);
} else {
evento2.key.keysym.sym=SDLK_UP; // pull up UP
pevento->key.keysym.sym=SDLK_DOWN; // and press DOWN
read_keyboard(&evento2);
}
}
pevento->type=SDL_KEYDOWN;
}
}
if ((pevento->type != SDL_KEYDOWN) && (pevento->type != SDL_KEYUP))
return;
this->k8 = this->k9 = this->k10 = this->k11 =
this->k12 = this->k13 = this->k14 =
this->k15 = 0;
this->jk = 0;
temporal_io = (unsigned int) pevento->key.keysym.sym;
if ((pevento->type==SDL_KEYUP)&&(temporal_io==SDLK_TAB)) {
if (!this->tab_extended) {
this->tab_extended = true;
osd->set_message("Function Key mode on",2000);
return;
} else {
this->tab_extended = false;
osd->clear_message();
return;
}
}
if ((pevento->type==SDL_KEYDOWN)&&(this->tab_extended))
return;
if ((pevento->type==SDL_KEYUP)&&(this->tab_extended)) {
this->tab_extended = false;
osd->clear_message();
switch(temporal_io) {
case SDLK_1:
temporal_io=SDLK_F1;
break;
case SDLK_2:
temporal_io=SDLK_F2;
break;
case SDLK_3:
temporal_io=SDLK_F3;
break;
case SDLK_4:
temporal_io=SDLK_F4;
break;
case SDLK_5:
temporal_io=SDLK_F5;
break;
case SDLK_6:
temporal_io=SDLK_F6;
break;
case SDLK_7:
temporal_io=SDLK_F7;
break;
case SDLK_8:
temporal_io=SDLK_F8;
break;
case SDLK_9:
temporal_io=SDLK_F9;
break;
case SDLK_0:
temporal_io=SDLK_F10;
break;
case SDLK_o:
temporal_io=SDLK_F11;
break;
case SDLK_p:
temporal_io=SDLK_F12;
break;
}
}
if (pevento->type == SDL_KEYUP)
switch (temporal_io) {
case SDLK_ESCAPE: // to exit from the emulator
if (!this->esc_again) {
this->esc_again = true;
osd->set_message("ESC again to exit",2000);
} else
salir = 0;
return;
break;
case SDLK_F1:
help_menu (); // shows the help menu
break;
case SDLK_F2:
case SDLK_F3:
case SDLK_F4:
case SDLK_F7:
case SDLK_F8:
launch_menu(temporal_io);
break;
case SDLK_F5: // STOP tape
OOTape->set_pause(true);
break;
case SDLK_F6: // PLAY tape
OOTape->set_pause(false);
break;
case SDLK_F9:
llscreen->fullscreen_switch();
break;
case SDLK_F10: // Reset emulator
ResetComputer ();
OOTape->set_pause(true);
OOTape->rewind();
break;
case SDLK_F11: // lower volume
llsound->decrease_volume();
break;
case SDLK_F12: // upper volume
llsound->increase_volume();
break;
}
// reorder joystick if screen is rotated
if(ordenador->zaurus_mini==2) {
switch(temporal_io) {
case SDLK_UP:
temporal_io=SDLK_LEFT;
break;
case SDLK_LEFT:
temporal_io=SDLK_DOWN;
break;
case SDLK_DOWN:
temporal_io=SDLK_RIGHT;
break;
case SDLK_RIGHT:
temporal_io=SDLK_UP;
break;
}
}
// test for joystick
switch (temporal_io) {
case SDLK_UP:
switch (this->joystick) {
case 0: // cursor
temporal_io = SDLK_7;
break;
case 1:
this->jk = 8;
break;
case 2: // sinclair 1
temporal_io = SDLK_4;
break;
case 3: // sinclair 2
temporal_io = SDLK_9;
break;
}
break;
case SDLK_DOWN:
switch (this->joystick) {
case 0: // cursor
temporal_io = SDLK_6;
break;
case 1:
this->jk = 4;
break;
case 2: // sinclair 1
temporal_io = SDLK_3;
break;
case 3: // sinclair 2
temporal_io = SDLK_8;
break;
}
break;
case SDLK_RIGHT:
switch (this->joystick) {
case 0: // cursor
temporal_io = SDLK_8;
break;
case 1:
this->jk = 1;
break;
case 2: // sinclair 1
temporal_io = SDLK_1;
break;
case 3: // sinclair 2
temporal_io = SDLK_6;
break;
}
break;
case SDLK_LEFT:
switch (this->joystick) {
case 0: // cursor
temporal_io = SDLK_5;
break;
case 1:
this->jk = 2;
break;
case 2: // sinclair 1
temporal_io = SDLK_2;
break;
case 3: // sinclair 2
temporal_io = SDLK_7;
break;
}
break;
case SDLK_RALT:
case SDLK_RMETA:
case SDLK_LMETA:
case SDLK_RSUPER:
case SDLK_LSUPER:
case SDLK_MENU:
switch (this->joystick) {
case 0: // cursor
temporal_io = SDLK_0;
break;
case 1:
this->jk = 16;
break;
case 2: // sinclair 1
temporal_io = SDLK_5;
break;
case 3: // sinclair 2
temporal_io = SDLK_0;
break;
}
break;
}
switch (temporal_io) {
case SDLK_SPACE:
this->k15 = 1;
break;
case SDLK_RCTRL:
case SDLK_LCTRL:
this->k15 = 2;
break;
case SDLK_m:
this->k15 = 4;
break;
case SDLK_n:
this->k15 = 8;
break;
case SDLK_b:
this->k15 = 16;
break;
case SDLK_RETURN:
this->k14 = 1;
break;
case SDLK_l:
this->k14 = 2;
break;
case SDLK_k:
this->k14 = 4;
break;
case SDLK_j:
this->k14 = 8;
break;
case SDLK_h:
this->k14 = 16;
break;
case SDLK_p:
this->k13 = 1;
break;
case SDLK_o:
this->k13 = 2;
break;
case SDLK_i:
this->k13 = 4;
break;
case SDLK_u:
this->k13 = 8;
break;
case SDLK_y:
this->k13 = 16;
break;
case SDLK_0:
this->k12 = 1;
break;
case SDLK_9:
this->k12 = 2;
break;
case SDLK_8:
this->k12 = 4;
break;
case SDLK_7:
this->k12 = 8;
break;
case SDLK_6:
this->k12 = 16;
break;
case SDLK_1:
this->k11 = 1;
break;
case SDLK_2:
this->k11 = 2;
break;
case SDLK_3:
this->k11 = 4;
break;
case SDLK_4:
this->k11 = 8;
break;
case SDLK_5:
this->k11 = 16;
break;
case SDLK_q:
this->k10 = 1;
break;
case SDLK_w:
this->k10 = 2;
break;
case SDLK_e:
this->k10 = 4;
break;
case SDLK_r:
this->k10 = 8;
break;
case SDLK_t:
this->k10 = 16;
break;
case SDLK_a:
this->k9 = 1;
break;
case SDLK_s:
this->k9 = 2;
break;
case SDLK_d:
this->k9 = 4;
break;
case SDLK_f:
this->k9 = 8;
break;
case SDLK_g:
this->k9 = 16;
break;
case SDLK_RSHIFT:
case SDLK_LSHIFT:
this->k8 = 1;
break;
case SDLK_z:
this->k8 = 2;
break;
case SDLK_x:
this->k8 = 4;
break;
case SDLK_c:
this->k8 = 8;
break;
case SDLK_v:
this->k8 = 16;
break;
case SDLK_BACKSPACE:
this->k12 = 1;
this->k8 = 1;
break;
case SDLK_PERIOD:
this->k15 = 6;
break;
case SDLK_COMMA:
this->k15 = 10;
break;
}
if (pevento->type == SDL_KEYUP) {
this->s8 |= this->k8;
this->s9 |= this->k9;
this->s10 |= this->k10;
this->s11 |= this->k11;
this->s12 |= this->k12;
this->s13 |= this->k13;
this->s14 |= this->k14;
this->s15 |= this->k15;
this->js &= (this->jk ^ 255);
} else {
this->s8 &= (this->k8 ^ 255);
this->s9 &= (this->k9 ^ 255);
this->s10 &= (this->k10 ^ 255);
this->s11 &= (this->k11 ^ 255);
this->s12 &= (this->k12 ^ 255);
this->s13 &= (this->k13 ^ 255);
this->s14 &= (this->k14 ^ 255);
this->s15 &= (this->k15 ^ 255);
this->js |= this->jk;
}
return;
}
/*
* keyboard.hh
*
* Created on: 27/03/2015
* Author: raster
*/
#ifndef SRC_KEYBOARD_HH_
#define SRC_KEYBOARD_HH_
#include <inttypes.h>
#include <SDL/SDL.h>
class Keyboard {
// keyboard private global variables
uint8_t k8,k9,k10,k11,k12,k13,k14,k15;
uint8_t readed;
// kempston joystick private global variables
uint8_t jk;
public:
Keyboard();
void reset();
void read_keyboard(SDL_Event *);
uint8_t s8,s9,s10,s11,s12,s13,s14,s15;
uint8_t js;
uint8_t joystick; // 0=cursor, 1=kempston, 2=sinclair1, 3=sinclair2
bool tab_extended;
bool esc_again;