Commit 106a699c authored by Sergio Costas's avatar Sergio Costas

Moved OSD system to its own class

parent 69e14d96
......@@ -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 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 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)
fbzx: cargador.o computer.o emulator.o llscreen.o menus.o microdrive.o osd.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 osd.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
$(CC) -o Z80free.o z80free/Z80free.c
......@@ -34,33 +34,36 @@ 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 z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.hh cargador.hh
cargador.o: cargador.cpp emulator.hh osd.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh cargador.hh
$(CPP) $(CPPFLAGS) -o cargador.o cargador.cpp
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
computer.o: computer.cpp z80free/Z80free.h computer.hh signals.hh llscreen.hh emulator.hh osd.hh tape.hh spk_ay.hh sound.hh microdrive.hh menus.hh
$(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 signals.hh cargador.hh
emulator.o: emulator.cpp sound.hh microdrive.hh z80free/Z80free.h menus.hh llscreen.hh emulator.hh osd.hh computer.hh signals.hh tape.hh cargador.hh
$(CPP) $(CPPFLAGS) -o emulator.o emulator.cpp
llscreen.o: llscreen.cpp font.h llscreen.hh emulator.hh z80free/Z80free.h computer.hh tape.hh signals.hh
llscreen.o: llscreen.cpp osd.hh font.h llscreen.hh emulator.hh z80free/Z80free.h computer.hh signals.hh tape.hh
$(CPP) $(CPPFLAGS) -o llscreen.o llscreen.cpp
menus.o: menus.cpp llscreen.hh emulator.hh z80free/Z80free.h computer.hh tape.hh signals.hh menus.hh cargador.hh
menus.o: menus.cpp llscreen.hh emulator.hh osd.hh z80free/Z80free.h computer.hh signals.hh tape.hh menus.hh cargador.hh
$(CPP) $(CPPFLAGS) -o menus.o menus.cpp
microdrive.o: microdrive.cpp emulator.hh z80free/Z80free.h computer.hh llscreen.hh tape.hh signals.hh microdrive.hh
microdrive.o: microdrive.cpp osd.hh emulator.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh microdrive.hh
$(CPP) $(CPPFLAGS) -o microdrive.o microdrive.cpp
osd.o: osd.cpp osd.hh
$(CPP) $(CPPFLAGS) -o osd.o osd.cpp
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
sound.o: sound.cpp sound.hh emulator.hh osd.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh
$(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 signals.hh
spk_ay.o: spk_ay.cpp sound.hh emulator.hh osd.hh z80free/Z80free.h computer.hh signals.hh llscreen.hh tape.hh
$(CPP) $(CPPFLAGS) -o spk_ay.o spk_ay.cpp
tape.o: tape.cpp z80free/Z80free.h tape.hh signals.hh emulator.hh computer.hh llscreen.hh
tape.o: tape.cpp z80free/Z80free.h tape.hh signals.hh emulator.hh osd.hh computer.hh llscreen.hh
$(CPP) $(CPPFLAGS) -o tape.o tape.cpp
......@@ -56,8 +56,7 @@ bool computer::callback_receiver(string signal_received, class Signals *object)
return true;
}
if (signal_received == "tape_paused") {
this->osd_text = "Tape paused";
this->osd_time = 100;
osd.set_message("Tape paused",2000);
}
return true;
}
......@@ -110,9 +109,6 @@ void computer_init () {
ordenador.tape_fast_load = true; // fast load by default
ordenador.osd_text = "";
ordenador.osd_time = 0;
ordenador.other_ret = 0;
ordenador.s8 = ordenador.s9 = ordenador.s10 = ordenador.s11 =
......@@ -419,16 +415,14 @@ void show_screen (int tstados) {
if ((ordenador.currline > ordenador.pixalto)&&(ordenador.currpix>=64)) {
ordenador.currpix=64;
if (ordenador.osd_time) {
ordenador.osd_time--;
if (ordenador.osd_time==0) {
ordenador.tab_extended=0;
ordenador.esc_again=0;
}
if (ordenador.osd_time) {
llscreen->print_string(ordenador.osd_text, -1,-1, 12, 0);
}
if (osd.get_time() != 0) {
uint8_t lines;
string text;
text = osd.get_text(lines);
llscreen->print_string(text, -1,-lines, 12, 0);
} else {
ordenador.tab_extended=0;
ordenador.esc_again=0;
}
llscreen->do_flip();
......@@ -578,12 +572,11 @@ void read_keyboard (SDL_Event *pevento2) {
if ((pevento->type==SDL_KEYUP)&&(temporal_io==SDLK_TAB)) {
if (ordenador.tab_extended==0) {
ordenador.tab_extended=1;
ordenador.osd_text = "Function Key mode on";
ordenador.osd_time=100;
osd.set_message("Function Key mode on",2000);
return;
} else {
ordenador.tab_extended=0;
ordenador.osd_time=0;
osd.clear_message();
return;
}
}
......@@ -593,7 +586,9 @@ void read_keyboard (SDL_Event *pevento2) {
if ((pevento->type==SDL_KEYUP)&&(ordenador.tab_extended==1)) {
ordenador.tab_extended=0;
ordenador.osd_time=0;
osd.clear_message();
switch(temporal_io) {
case SDLK_1:
temporal_io=SDLK_F1;
......@@ -640,8 +635,7 @@ void read_keyboard (SDL_Event *pevento2) {
case SDLK_ESCAPE: // to exit from the emulator
if (ordenador.esc_again==0) {
ordenador.esc_again=1;
ordenador.osd_text = "ESC again to exit";
ordenador.osd_time=100;
osd.set_message("ESC again to exit",2000);
} else
salir = 0;
return;
......@@ -683,8 +677,7 @@ void read_keyboard (SDL_Event *pevento2) {
{
std::ostringstream stringStream;
stringStream << " Volume: " << ordenador.volume/4 << " ";
ordenador.osd_text = stringStream.str();
ordenador.osd_time = 50;
osd.set_message(stringStream.str(),1000);
}
break;
......@@ -693,8 +686,7 @@ void read_keyboard (SDL_Event *pevento2) {
{
std::ostringstream stringStream;
stringStream << " Volume: " << ordenador.volume/4 << " ";
ordenador.osd_text = stringStream.str();
ordenador.osd_time = 50;
osd.set_message(stringStream.str(),1000);
}
break;
}
......
......@@ -152,11 +152,6 @@ public:
byte mdr_old_STATUS; // to detect an edge in COM CLK
unsigned char mdr_modified; // if a sector is stored, this change to know that it must be stored in the file
// OSD global variables
string osd_text;
unsigned int osd_time;
// pagination global variables
unsigned char mport1,mport2; // ports for memory management (128K and +3)
......
......@@ -37,7 +37,8 @@
char debug_var=1;
Z80FREE procesador;
struct computer ordenador;
class computer ordenador;
class OSD osd;
//SDL_Surface *screen;
char salir,sound_aborted;
unsigned char *sound[NUM_SNDBUF];
......@@ -573,8 +574,7 @@ int main(int argc,char *argv[]) {
llscreen->clear_screen();
if (sound_aborted==1) {
ordenador.osd_text = "Running without sound (read the FAQ)";
ordenador.osd_time=100;
osd.set_message("Running without sound (read the FAQ)",2000);
}
printf("Modo: %d\n",ordenador.mode128k);
......@@ -582,8 +582,7 @@ int main(int argc,char *argv[]) {
load_main_game(gamefile);
printf("Modo: %d\n",ordenador.mode128k);
ordenador.osd_text = "Press F1 for help";
ordenador.osd_time=200;
osd.set_message("Press F1 for help",4000);
printf("BPP: %d\n",llscreen->bpp);
while(salir) {
......@@ -606,8 +605,7 @@ int main(int argc,char *argv[]) {
if(ordenador.current_tap != "") {
do_fast_load();
} else {
ordenador.osd_text = "No TAP/TZX file selected";
ordenador.osd_time=50;
osd.set_message("No TAP/TZX file selected",1000);
}
}
......@@ -679,22 +677,19 @@ void do_fast_load() {
procesador.Rm.br.F &= (~F_C); // Load error
procesador.Rm.wr.IX += procesador.Rm.wr.DE;
procesador.Rm.wr.DE = 0;
ordenador.osd_text = "No tape selected";
ordenador.osd_time = 100;
osd.set_message("No tape selected",2000);
return;
break;
case FASTLOAD_NO_BLOCK:
ordenador.other_ret = 0; // next instruction must NOT be RET
ordenador.osd_text = "Can't do fast load. Press F6 to play";
ordenador.osd_time = 100;
osd.set_message("Can't do fast load. Press F6 to play",2000);
return;
break;
case FASTLOAD_END_TAPE:
procesador.Rm.br.F &= (~F_C); // Load error
procesador.Rm.wr.IX += procesador.Rm.wr.DE;
procesador.Rm.wr.DE = 0;
ordenador.osd_text = "End of tape. Rewind it.";
ordenador.osd_time = 100;
osd.set_message("End of tape. Rewind it.",2000);
return;
case FASTLOAD_OK:
counter = 0;
......
......@@ -19,6 +19,7 @@
#include "computer.hh"
#include "z80free/Z80free.h"
#include "osd.hh"
#ifndef emulator_h
#define emulator_h
......@@ -28,7 +29,8 @@
extern char debug_var;
extern Z80FREE procesador;
extern struct computer ordenador;
extern class computer ordenador;
extern class OSD osd;
extern unsigned char *sound[NUM_SNDBUF];
extern char path_snaps[2049];
extern char path_taps[2049];
......
......@@ -20,6 +20,7 @@
#include <string.h>
#include "llscreen.hh"
#include "font.h"
#include "osd.hh"
LLScreen *llscreen = NULL;
......@@ -428,8 +429,7 @@ void LLScreen::paint_picture(string filename) {
this->clear_screen();
fichero=myfopen((char *)filename.c_str(),"r");
if (fichero==NULL) {
ordenador.osd_text = "Keymap picture not found";
ordenador.osd_time=100;
osd.set_message("Keymap picture not found",2000);
return;
}
if (ordenador.zaurus_mini==0) {
......
......@@ -579,8 +579,6 @@ void taps_menu() {
fin=0;
ordenador.OOTape.set_pause(true);
ordenador.OOTape.rewind();
ordenador.osd_text = "Tape rewinded";
ordenador.osd_time=50;
break;
case SDLK_3:
ordenador.OOTape.set_pause(true);
......@@ -1412,7 +1410,7 @@ void load_scrfile() {
return;
}
ordenador.osd_text = "";
osd.clear_message();
fichero=fopen(filename,"rb");
retorno=0;
if (!fichero) {
......
......@@ -20,6 +20,7 @@
#include "microdrive.hh"
#include "computer.hh"
#include "emulator.hh"
#include "osd.hh"
byte basura;
......@@ -130,8 +131,7 @@ void microdrive_out(word Port,byte Value) {
if(ordenador.mdr_modified) { // if the cartridge has been modified, we store it in hard disk
ordenador.mdr_file=fopen(ordenador.mdr_current_mdr,"wb"); // create for write
if(ordenador.mdr_file==NULL) {
ordenador.osd_text = "Can't store the cartridge";
ordenador.osd_time=150;
osd.set_message("Can't store the cartridge",3000);
} else {
fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge
fclose(ordenador.mdr_file);
......
/*
* osd.cpp
*
* Created on: 26/03/2015
* Author: raster
*/
#include "osd.hh"
OSD::OSD() {
this->time = 0;
this->lines = 0;
this->text = "";
}
void OSD::set_message(string text, uint32_t ms) {
this->text = text;
this->lines = 1;
for(int loop=0;loop< text.length(); loop++) {
if (text[loop] == '\n') {
this->lines++;
}
}
this->time = ms/200; // set it to number of frames
}
uint32_t OSD::get_time() {
return (this->time--);
}
string OSD::get_text(uint8_t &lines) {
lines = this->lines;
return this->text;
}
void OSD::clear_message() {
this->time = 0;
}
/*
* osd.hh
*
* Created on: 26/03/2015
* Author: raster
*/
#ifndef SRC_OSD_HH_
#define SRC_OSD_HH_
using namespace std;
#include <string>
#include <stdint.h>
class OSD {
string text;
uint8_t lines;
uint32_t time;
public:
OSD();
void set_message(string, uint32_t);
uint32_t get_time();
string get_text(uint8_t &);
void clear_message();
};
#endif /* SRC_OSD_HH_ */
......@@ -1085,6 +1085,7 @@ void Tape::rewind() {
this->current_block->reset();
}
this->block_accesed = false;
osd.set_message("Tape rewinded",1000);
}
void Tape::set_pause(bool pause) {
......
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