Commit 19c4daea authored by Sergio Costas's avatar Sergio Costas

Added first support for kempston mouse

Added TZX block number 30
parent 0caa921d
......@@ -29,7 +29,7 @@ install:
cp data/keymap.bmp $(PREFIX2)/share/fbzx
cp data/fbzx.desktop $(PREFIX2)/share/applications
cp data/fbzx.svg $(PREFIX2)/share/pixmaps
cp AMSTRAD CAPABILITIES COPYING FAQ README README.TZX VERSIONS $(PREFIX2)/share/doc/fbzx/
cp AMSTRAD CAPABILITIES COPYING FAQ README README.TZX VERSIONS.md $(PREFIX2)/share/doc/fbzx/
cp fbzx.appdata.xml $(PREFIX2)/share/appdata/
chmod 644 $(PREFIX2)/share/fbzx/*
chmod 644 $(PREFIX2)/share/doc/fbzx/*
......
......@@ -7,8 +7,8 @@ CPPFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -D D_SOUND_PULSE -D D
LDFLAGS += `pkg-config --libs sdl libpulse-simple alsa`
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)
fbzx: cargador.o cmdline.o computer.o emulator.o keyboard.o llscreen.o llsound.o menus.o microdrive.o mouse.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 mouse.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
......@@ -40,10 +40,10 @@ cargador.o: cargador.cpp spk_ay.hh keyboard.hh emulator.hh screen.hh osd.hh z80f
cmdline.o: cmdline.cpp cmdline.hh
$(CPP) $(CPPFLAGS) -o cmdline.o cmdline.cpp
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
computer.o: computer.cpp z80free/Z80free.h llsound.hh mouse.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 spk_ay.hh 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
emulator.o: emulator.cpp mouse.hh z80free/Z80free.h spk_ay.hh keyboard.hh llsound.hh cmdline.hh computer.hh screen.hh signals.hh llscreen.hh tape.hh emulator.hh osd.hh microdrive.hh menus.hh cargador.hh
$(CPP) $(CPPFLAGS) -o emulator.o emulator.cpp
keyboard.o: keyboard.cpp menus.hh llscreen.hh llsound.hh computer.hh screen.hh signals.hh z80free/Z80free.h tape.hh emulator.hh osd.hh keyboard.hh
......@@ -61,6 +61,9 @@ menus.o: menus.cpp spk_ay.hh microdrive.hh z80free/Z80free.h keyboard.hh llsound
microdrive.o: microdrive.cpp osd.hh emulator.hh screen.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh microdrive.hh
$(CPP) $(CPPFLAGS) -o microdrive.o microdrive.cpp
mouse.o: mouse.cpp osd.hh keyboard.hh emulator.hh screen.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh mouse.hh
$(CPP) $(CPPFLAGS) -o mouse.o mouse.cpp
osd.o: osd.cpp osd.hh
$(CPP) $(CPPFLAGS) -o osd.o osd.cpp
......
......@@ -32,6 +32,7 @@
#include "tape.hh"
#include "computer.hh"
#include "keyboard.hh"
#include "mouse.hh"
#include "llsound.hh"
#include "z80free/Z80free.h"
......@@ -109,6 +110,7 @@ void computer::emulate (int tstados) {
spk_ay->play_sound (tstados);
OOTape->play(tstados);
microdrive->emulate(tstados);
mouse->emulate(tstados);
if (!OOTape->get_pause()) {
if (OOTape->read_signal() != 0) {
......@@ -179,6 +181,7 @@ void ResetComputer () {
keyboard->reset();
screen->reset(ordenador->mode128k);
microdrive->reset();
mouse->reset();
}
void Z80free_Wr (word Addr, byte Value) {
......@@ -386,6 +389,15 @@ byte Z80free_In (word Port) {
if (keyboard->joystick == 1) {
return (keyboard->js);
} else {
if(((Port&0xFF00) == 0xFA00) && (mouse->enabled)) {
return(mouse->button);
}
if(((Port&0xFF00) == 0xFB00) && (mouse->enabled)) {
return(mouse->x);
}
if(((Port&0xFF00) == 0xFF00) && (mouse->enabled)) {
return(mouse->y);
}
return 0; // if Kempston is not selected, emulate it, but always 0
}
}
......@@ -398,8 +410,9 @@ byte Z80free_In (word Port) {
if(((Port & 0x0018) != 0x0018) && (microdrive->mdr_active))
return(microdrive->in(Port));
pines=ordenador->bus_empty();
return (pines);
}
......@@ -35,6 +35,7 @@
#include "llsound.hh"
#include "keyboard.hh"
#include "spk_ay.hh"
#include "mouse.hh"
bool debug_var = false;
......@@ -372,6 +373,7 @@ int main(int argc,char *argv[]) {
ordenador = new computer();
microdrive = new Microdrive();
spk_ay = new SPK_AY();
mouse = new Mouse();
load_config();
......
......@@ -24,6 +24,11 @@ Keyboard::Keyboard() {
this->readed = 0;
this->joystick = 0;
this->mouse_x = 0;
this->mouse_y = 0;
this->mouse_left = false;
this->mouse_right = false;
this->mouse_center = false;
}
void Keyboard::reset() {
......@@ -39,7 +44,7 @@ void Keyboard::reset() {
this->js=0;
}
// Read the keyboard and stores the flags
// Read the keyboard and mouse, and stores the flags
void Keyboard::read_keyboard (SDL_Event *pevento2) {
......@@ -61,6 +66,40 @@ void Keyboard::read_keyboard (SDL_Event *pevento2) {
return;
}
if (pevento->type==SDL_MOUSEMOTION) {
this->mouse_x += pevento->motion.xrel;
this->mouse_y += pevento->motion.yrel;
return;
}
if (pevento->type==SDL_MOUSEBUTTONDOWN) {
switch (pevento->button.button) {
case SDL_BUTTON_LEFT:
this->mouse_left = true;
break;
case SDL_BUTTON_MIDDLE:
this->mouse_center = true;
break;
case SDL_BUTTON_RIGHT:
this->mouse_right = true;
break;
}
}
if (pevento->type==SDL_MOUSEBUTTONUP) {
switch (pevento->button.button) {
case SDL_BUTTON_LEFT:
this->mouse_left = false;
break;
case SDL_BUTTON_MIDDLE:
this->mouse_center = false;
break;
case SDL_BUTTON_RIGHT:
this->mouse_right = false;
break;
}
}
if (pevento->type==SDL_JOYBUTTONDOWN) {
pevento->type=SDL_KEYDOWN;
pevento->key.keysym.sym=SDLK_MENU; // emulate pressing the MENU key
......
......@@ -30,6 +30,11 @@ public:
uint8_t s8,s9,s10,s11,s12,s13,s14,s15;
uint8_t js;
uint8_t joystick; // 0=cursor, 1=kempston, 2=sinclair1, 3=sinclair2
int32_t mouse_x;
int32_t mouse_y;
bool mouse_left;
bool mouse_center;
bool mouse_right;
bool tab_extended;
bool esc_again;
};
......
......@@ -77,6 +77,7 @@ LLScreen::LLScreen(int16_t resx,int16_t resy,uint8_t depth,bool fullscreen,bool
exit(1);
}
this->set_mouse();
this->bpp = this->llscreen->format->BytesPerPixel;
this->width = this->llscreen->w;
this->memory = (unsigned char *)this->llscreen->pixels;
......@@ -91,9 +92,9 @@ LLScreen::LLScreen(int16_t resx,int16_t resy,uint8_t depth,bool fullscreen,bool
// we filter all the events, except keyboard events
SDL_EventState(SDL_ACTIVEEVENT,SDL_IGNORE);
SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE);
SDL_EventState(SDL_MOUSEBUTTONDOWN,SDL_IGNORE);
SDL_EventState(SDL_MOUSEBUTTONUP,SDL_IGNORE);
SDL_EventState(SDL_MOUSEMOTION,SDL_ENABLE);
SDL_EventState(SDL_MOUSEBUTTONDOWN,SDL_ENABLE);
SDL_EventState(SDL_MOUSEBUTTONUP,SDL_ENABLE);
SDL_EventState(SDL_JOYAXISMOTION,SDL_ENABLE);
SDL_EventState(SDL_JOYBALLMOTION,SDL_ENABLE);
SDL_EventState(SDL_JOYHATMOTION,SDL_ENABLE);
......@@ -226,6 +227,18 @@ void LLScreen::fullscreen_switch() {
flags |= SDL_FULLSCREEN;
this->llscreen = SDL_SetVideoMode(this->llscreen->w, this->llscreen->h, this->llscreen->format->BitsPerPixel,flags);
this->set_mouse();
}
void LLScreen::set_mouse() {
Uint32 flags = this->llscreen->flags;
if ( flags & SDL_FULLSCREEN ) {
SDL_WM_GrabInput(SDL_GRAB_ON);
} else {
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
}
void LLScreen::set_paletes(bool bw) {
......
......@@ -57,6 +57,7 @@ public:
void set_paletes(bool);
void paint_one_pixel(uint8_t value,unsigned char *address);
void fullscreen_switch();
void set_mouse();
void set_palete_entry(uint8_t entry, uint8_t Value, bool bw);
uint8_t get_palete_entry(uint8_t entry);
void clear_screen();
......
#include "mouse.hh"
#include "computer.hh"
#include "emulator.hh"
#include "keyboard.hh"
#include "osd.hh"
#include <stdio.h>
class Mouse *mouse;
void Mouse::reset() {
this->posx = keyboard->mouse_x;
this->posy = keyboard->mouse_y;
this->x = 0;
this->y = 0;
this->button = 255;
this->enabled = true;
}
Mouse::Mouse() {
this->reset();
}
void Mouse::emulate(int tstates) {
unsigned int diffx = keyboard->mouse_x - this->posx;
unsigned int diffy = keyboard->mouse_y - this->posy;
this->posx = keyboard->mouse_x;
this->posy = keyboard->mouse_y;
if (diffx < 2) {
diffx=0;
}
if (diffy < 2) {
diffy=0;
}
this->x += diffx;
this->y -= diffy;
this->button = 255;
if (keyboard->mouse_right) {
this->button -= 1;
}
if (keyboard->mouse_left) {
this->button -= 2;
}
if (keyboard->mouse_center) {
this->button -= 4;
}
}
#ifndef SRC_MOUSE_HH_
#define SRC_MOUSE_HH_
#include "z80free/Z80free.h"
#include <inttypes.h>
#include <SDL/SDL.h>
class Mouse {
int posx;
int posy;
public:
byte x;
byte y;
byte button;
bool enabled;
Mouse();
void reset();
void emulate(int);
byte in(word);
};
extern class Mouse *mouse;
#endif
......@@ -1242,6 +1242,61 @@ public:
}
};
class TextBlock : public TapeBlock {
uint8_t *data;
uint8_t size;
public:
TextBlock() {
this->data = NULL;
this->size = 0;
this->has_data = false;
}
~TextBlock() {
if (this->data != NULL) {
delete[](this->data);
}
}
bool save_block(ofstream *file) {
if (this->write_8bit(file,0x30)) { // block ID
return true;
}
if (this->write_8bit(file, this->size)) {
return true;
}
file->write((char*)this->data,this->size);
if (this->next == NULL) {
return false;
} else {
return this->next->save_block(file);
}
}
bool load_block(ifstream *file) {
size_t retval;
if (this->read_8bit(file,this->size)) {
return true;
}
this->data = new uint8_t[this->size];
file->read((char*)this->data,this->size);
if (file->eof()) {
return true;
}
return false;
}
bool next_bit() {
return false;
}
};
Tape::Tape() {
this->blocks = NULL;
this->current_block = NULL;
......@@ -1369,6 +1424,7 @@ bool Tape::load_tzx(string filename) {
break;
case 0x20: // Pause block
block = new PauseBlock(this);
printf("Pause block\n");
break;
case 0x21: // group start
block = new GroupStartBlock();
......@@ -1382,6 +1438,9 @@ bool Tape::load_tzx(string filename) {
case 0x25: // Loop End
block = new EndLoopBlock();
break;
case 0x30: // Text block
block = new TextBlock();
break;
case 0x32: // Archive Info block
block = new InfoBlock();
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment