Commit 5fc0b17b authored by Sergio Costas's avatar Sergio Costas

Added support for signals and the observer pattern

Added llscreen files
parent 0d2fdccb
...@@ -7,8 +7,8 @@ CPPFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -O2 -D D_SOUND_PULSE ...@@ -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` LDFLAGS += `pkg-config --libs sdl libpulse-simple alsa`
fbzx: cargador.o computer.o emulator.o llscreen.o menus.o microdrive.o sound.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 fbzx: cargador.o computer.o emulator.o llscreen.o menus.o microdrive.o signals.o sound.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 computer.o emulator.o llscreen.o menus.o microdrive.o sound.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) $(LN) -o fbzx cargador.o computer.o emulator.o llscreen.o menus.o microdrive.o signals.o sound.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 Z80free.o: z80free/Z80free.c z80free/Z80free.h
$(CC) -o Z80free.o z80free/Z80free.c $(CC) -o Z80free.o z80free/Z80free.c
...@@ -34,30 +34,33 @@ Z80free_codesDDCB.o: z80free/Z80free_codesDDCB.c z80free/Z80free.h ...@@ -34,30 +34,33 @@ Z80free_codesDDCB.o: z80free/Z80free_codesDDCB.c z80free/Z80free.h
Z80free_codesFDCB.o: z80free/Z80free_codesFDCB.c z80free/Z80free.h Z80free_codesFDCB.o: z80free/Z80free_codesFDCB.c z80free/Z80free.h
$(CC) -o Z80free_codesFDCB.o z80free/Z80free_codesFDCB.c $(CC) -o Z80free_codesFDCB.o z80free/Z80free_codesFDCB.c
cargador.o: cargador.cpp emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh cargador.hh cargador.o: cargador.cpp emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.hh cargador.hh
$(CPP) $(CPPFLAGS) -o cargador.o cargador.cpp $(CPP) $(CPPFLAGS) -o cargador.o cargador.cpp
computer.o: computer.cpp z80free/Z80free.h computer.hh llscreen.hh emulator.hh tape.hh spk_ay.hh sound.hh microdrive.hh menus.hh computer.o: computer.cpp z80free/Z80free.h computer.hh llscreen.hh emulator.hh tape.hh signals.hh spk_ay.hh sound.hh microdrive.hh menus.hh
$(CPP) $(CPPFLAGS) -o computer.o computer.cpp $(CPP) $(CPPFLAGS) -o computer.o computer.cpp
emulator.o: emulator.cpp sound.hh microdrive.hh z80free/Z80free.h menus.hh llscreen.hh emulator.hh computer.hh tape.hh cargador.hh emulator.o: emulator.cpp sound.hh microdrive.hh z80free/Z80free.h menus.hh llscreen.hh emulator.hh computer.hh tape.hh signals.hh cargador.hh
$(CPP) $(CPPFLAGS) -o emulator.o emulator.cpp $(CPP) $(CPPFLAGS) -o emulator.o emulator.cpp
llscreen.o: llscreen.cpp font.h llscreen.hh emulator.hh z80free/Z80free.h computer.hh tape.hh llscreen.o: llscreen.cpp font.h llscreen.hh emulator.hh z80free/Z80free.h computer.hh tape.hh signals.hh
$(CPP) $(CPPFLAGS) -o llscreen.o llscreen.cpp $(CPP) $(CPPFLAGS) -o llscreen.o llscreen.cpp
menus.o: menus.cpp llscreen.hh emulator.hh z80free/Z80free.h computer.hh tape.hh menus.hh cargador.hh menus.o: menus.cpp llscreen.hh emulator.hh z80free/Z80free.h computer.hh tape.hh signals.hh menus.hh cargador.hh
$(CPP) $(CPPFLAGS) -o menus.o menus.cpp $(CPP) $(CPPFLAGS) -o menus.o menus.cpp
microdrive.o: microdrive.cpp emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh microdrive.hh microdrive.o: microdrive.cpp emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.hh microdrive.hh
$(CPP) $(CPPFLAGS) -o microdrive.o microdrive.cpp $(CPP) $(CPPFLAGS) -o microdrive.o microdrive.cpp
sound.o: sound.cpp sound.hh emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.o: signals.cpp signals.hh
$(CPP) $(CPPFLAGS) -o signals.o signals.cpp
sound.o: sound.cpp sound.hh emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.hh
$(CPP) $(CPPFLAGS) -o sound.o sound.cpp $(CPP) $(CPPFLAGS) -o sound.o sound.cpp
spk_ay.o: spk_ay.cpp sound.hh emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh spk_ay.o: spk_ay.cpp sound.hh emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.hh
$(CPP) $(CPPFLAGS) -o spk_ay.o spk_ay.cpp $(CPP) $(CPPFLAGS) -o spk_ay.o spk_ay.cpp
tape.o: tape.cpp z80free/Z80free.h tape.hh emulator.hh computer.hh llscreen.hh tape.o: tape.cpp z80free/Z80free.h tape.hh signals.hh emulator.hh computer.hh llscreen.hh
$(CPP) $(CPPFLAGS) -o tape.o tape.cpp $(CPP) $(CPPFLAGS) -o tape.o tape.cpp
...@@ -34,6 +34,33 @@ ...@@ -34,6 +34,33 @@
#include "computer.hh" #include "computer.hh"
#include "z80free/Z80free.h" #include "z80free/Z80free.h"
computer::computer() {
this->OOTape.register_signal("pause_tape",this);
this->OOTape.register_signal("pause_tape_48k",this);
this->OOTape.register_signal("tape_paused",this);
}
computer::~computer() {
}
bool computer::callback_receiver(string signal_received, class Signals *object) {
if (signal_received == "pause_tape") {
this->OOTape.set_pause(true);
return true;
}
if (signal_received == "pause_tape_48k") {
if ((this->mode128k == 0) || ((ordenador.mport1 & 0x20) != 0)) {
this->OOTape.set_pause(true);
}
return true;
}
if (signal_received == "tape_paused") {
this->osd_text = "Tape paused";
this->osd_time = 100;
}
return true;
}
/* Returns the bus value when reading a port without a periferial */ /* Returns the bus value when reading a port without a periferial */
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "tape.hh" #include "tape.hh"
#include "z80free/Z80free.h" #include "z80free/Z80free.h"
#include "llscreen.hh" #include "llscreen.hh"
#include "signals.hh"
// #define MUT // #define MUT
...@@ -36,8 +37,8 @@ enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2, ...@@ -36,8 +37,8 @@ enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2,
enum taptypes {TAP_TAP, TAP_TZX}; enum taptypes {TAP_TAP, TAP_TZX};
struct computer { class computer : public Signals {
public:
unsigned int temporal_io; unsigned int temporal_io;
// screen private global variables // screen private global variables
...@@ -172,6 +173,10 @@ struct computer { ...@@ -172,6 +173,10 @@ struct computer {
unsigned char other_ret; // 0=no change; 1=memory returns RET (201) unsigned char other_ret; // 0=no change; 1=memory returns RET (201)
unsigned char turbo; unsigned char turbo;
computer();
~computer();
bool callback_receiver(string, class Signals *);
}; };
void computer_init(); void computer_init();
......
This diff is collapsed.
/*
* Copyright 2003-2015 (C) Raster Software Vigo (Sergio Costas)
* This file is part of FBZX
*
* FBZX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* FBZX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __LLSCREEN_H_
#define __LLSCREEN_H_
#include <inttypes.h>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include "emulator.hh"
using namespace std;
extern struct Charset charset;
#define MIN_WIDTH 4
class LLScreen {
uint8_t *memory;
uint32_t width;
uint8_t printchar(uint8_t character, int16_t x, int16_t y, uint8_t color, uint8_t back);
public:
bool joystick;
bool mustlock;
uint32_t bpp;
SDL_Surface *llscreen;
uint32_t cheight;
uint32_t lines_in_screen;
LLScreen(int16_t resx, int16_t resy, uint8_t depth, bool fullscreen, bool dblbuffer, bool hwsurface);
~LLScreen();
void print_string(string message, int16_t x, int16_t y, uint8_t ink, uint8_t paper);
void set_paletes(bool);
void paint_one_pixel(unsigned char *colour,unsigned char *address);
void fullscreen_switch();
void set_palete_entry(uint8_t entry, byte Value);
void clear_screen();
void paint_picture(string filename);
void do_flip();
};
extern LLScreen *llscreen;
#endif
/*
* signals.cpp
*
* Created on: 25/03/2015
* Author: raster
*/
#include "signals.hh"
Signals::Signals() {
}
Signals::~Signals() {
// Unsubscribe from all the emiters
std::list<class Signals *>::iterator iter;
for (iter = this->subscribed.begin(); iter != this->subscribed.end(); ++iter) {
(*iter)->unregister_signal("",this);
}
}
void Signals::send_signal(std::string signal_name) {
std::map<string,class Signals *>::iterator iter;
for(iter = this->signal_list.find(signal_name); iter != this->signal_list.end(); ++iter) {
if (!((*iter).second->callback_receiver(signal_name,this))) {
break;
}
}
}
void Signals::register_signal(std::string signal_name, class Signals *receiver) {
std::map<string,class Signals *>::iterator iter;
for(iter = this->signal_list.find(signal_name); iter != this->signal_list.end(); ++iter) {
if ((*iter).second == receiver) {
return; // this signal is already connected to the receiver
}
}
this->signal_list.insert(std::pair<string,class Signals *>(signal_name,receiver));
}
void Signals::unregister_signal(std::string signal_name, class Signals *receiver) {
std::map<string,class Signals *>::iterator iter;
if (signal_name != "") {
for(iter = this->signal_list.find(signal_name); iter != this->signal_list.end(); ++iter) {
if ((*iter).second == receiver) {
this->signal_list.erase(iter);
return;
}
}
} else {
for(iter = this->signal_list.begin(); iter != this->signal_list.end(); ++iter) {
if ((*iter).second == receiver) {
this->signal_list.erase(iter);
return;
}
}
}
}
bool Signals::callback_receiver(std::string signal_name, class Signals *sender) {
return true;
}
/*
* signals.hh
*
* Created on: 25/03/2015
* Author: raster
*/
#ifndef SRC_SIGNALS_HH_
#define SRC_SIGNALS_HH_
using namespace std;
#include <map>
#include <list>
#include <string>
class Signals {
private:
/**
* Contains the list of signals, and the objects that want to receive them
*/
std::map<std::string,class Signals * > signal_list;
/**
* Contains the list of objects to whom this object registered signals to receive.
* Useful when destoying the object, to unregister all the signals automagically.
*/
std::list<class Signals *> subscribed;
protected:
void send_signal(std::string signal_name);
public:
Signals();
virtual ~Signals();
/**
* The callback that receives the signals being emited
* @param signal_name The signal that has been emited
* @param sender The object that sent the signal
* @return TRUE to continue sending signals to other objects registered to it; FALSE to stop propagating the signal
*/
virtual bool callback_receiver(std::string signal_name, class Signals *sender);
/**
* Registers itself to receive a signal from an object
* @param signal_name The signal to receive
* @param receiver The object who sends the signal
*/
void register_signal(std::string signal_name, class Signals *receiver);
/**
* Unregisters itself from receiving a signal from an object
* @param signal_name The signal to receive. Empty string to unregister all signals in this object
* @param receiver The object who sends the signal
*/
void unregister_signal(std::string signal_name, class Signals *receiver);
};
#endif /* SRC_SIGNALS_HH_ */
...@@ -980,6 +980,9 @@ void Tape::rewind() { ...@@ -980,6 +980,9 @@ void Tape::rewind() {
void Tape::set_pause(bool pause) { void Tape::set_pause(bool pause) {
this->paused = pause; this->paused = pause;
if (pause) {
this->send_signal("tape_paused");
}
} }
bool Tape::get_pause() { bool Tape::get_pause() {
......
...@@ -31,6 +31,7 @@ using namespace std; ...@@ -31,6 +31,7 @@ using namespace std;
#include "computer.hh" #include "computer.hh"
#include "emulator.hh" #include "emulator.hh"
#include "signals.hh"
#ifndef SRC_TAPE_HPP_ #ifndef SRC_TAPE_HPP_
#define SRC_TAPE_HPP_ #define SRC_TAPE_HPP_
...@@ -50,7 +51,7 @@ typedef void (TapeSignal::*signal_pause) (bool); ...@@ -50,7 +51,7 @@ typedef void (TapeSignal::*signal_pause) (bool);
enum FastLoadReturn {FASTLOAD_OK, FASTLOAD_NO_BLOCK, FASTLOAD_NO_TAPE, FASTLOAD_NO_FLAG, FASTLOAD_END_TAPE}; enum FastLoadReturn {FASTLOAD_OK, FASTLOAD_NO_BLOCK, FASTLOAD_NO_TAPE, FASTLOAD_NO_FLAG, FASTLOAD_END_TAPE};
class Tape { class Tape : public Signals {
class TapeBlock *blocks; class TapeBlock *blocks;
class TapeBlock *current_block; class TapeBlock *current_block;
......
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