Commit 9501953f authored by Sergio Costas's avatar Sergio Costas

Removed unused tape variables

parent b50c9dc1
......@@ -80,8 +80,7 @@ void computer_init () {
ordenador.mode128k = 0;
ordenador.joystick = 0;
ordenador.tape_fast_load = 1; // fast load by default
ordenador.tap_file = NULL;
ordenador.tape_fast_load = true; // fast load by default
ordenador.osd_text[0] = 0;
ordenador.osd_time = 0;
......
......@@ -33,6 +33,7 @@ extern char salir;
enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2, TZX_PURE_TONE,
TZX_SEQ_PULSES, TAP_FINAL_BIT, TAP_PAUSE3};
enum taptypes {TAP_TAP, TAP_TZX};
struct computer {
......@@ -130,10 +131,10 @@ struct computer {
// tape global variables
FILE *tap_file;
unsigned char tape_fast_load; // 0 normal load; 1 fast load
char current_tap[2049];
unsigned char tape_write; // 0 can't write; 1 can write
string current_tap;
bool tape_write; // FALSE can't write; TRUE can write
bool tape_fast_load; // FALSE normal load; TRUE fast load
Tape OOTape; // Tape object
// Microdrive global variables
FILE *mdr_file; // Current microdrive file
......@@ -171,8 +172,6 @@ struct computer {
unsigned char other_ret; // 0=no change; 1=memory returns RET (201)
unsigned char turbo;
Tape OOTape;
};
void computer_init();
......
......@@ -219,8 +219,6 @@ void end_system() {
delete(llscreen);
if(ordenador.tap_file!=NULL)
fclose(ordenador.tap_file);
}
void load_main_game(char *nombre) {
......@@ -239,7 +237,7 @@ void load_main_game(char *nombre) {
}
if ((0==strcasecmp(".tap",puntero))||(0==strcasecmp(".tzx",puntero))) {
strcpy(ordenador.current_tap,nombre);
ordenador.current_tap = nombre;
ordenador.OOTape.load_file(nombre);
return;
}
......@@ -532,7 +530,7 @@ int main(int argc,char *argv[]) {
strcat(path_snaps,"/");
strcpy(path_taps,path_snaps);
strcpy(path_mdrs,path_snaps);
ordenador.current_tap[0]=0;
ordenador.current_tap = "";
// assign random values to the memory before start execution
......@@ -542,7 +540,6 @@ int main(int argc,char *argv[]) {
ordenador.memoria[bucle]=(unsigned char) rand();
printf("Memory resetted\n");
ordenador.tap_file=NULL;
printf("Modo: %d\n",ordenador.mode128k);
// we filter all the events, except keyboard events
......@@ -605,11 +602,11 @@ int main(int argc,char *argv[]) {
/* if PC is 0x0556, a call to LD_BYTES has been made, so if
FAST_LOAD is 1, we must load the block in memory and return */
if((!ordenador.mdr_paged) && (PC==0x0556) && (ordenador.tape_fast_load==1) && (ordenador.page48k == 1)) {
if(ordenador.tap_file!=NULL) {
if((!ordenador.mdr_paged) && (PC==0x0556) && (ordenador.tape_fast_load) && (ordenador.page48k == 1)) {
if(ordenador.current_tap != "") {
do_fast_load();
} else {
sprintf(ordenador.osd_text,"No TAP file selected");
sprintf(ordenador.osd_text,"No TAP/TZX file selected");
ordenador.osd_time=50;
}
}
......
......@@ -24,9 +24,10 @@
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include "z80free/Z80free.h"
#include <iostream>
#include <SDL/SDL.h>
#include "z80free/Z80free.h"
#include "cargador.hh"
#include "computer.hh"
#include "emulator.hh"
......@@ -551,7 +552,7 @@ void taps_menu() {
llscreen->print_string("ESC: \001\017return to emulator",14,16,12,0);
llscreen->print_string("Current TAP/TZX file is:",-1,19,12,0);
llscreen->print_string(ordenador.current_tap,-1,320,20,0);
llscreen->print_string(ordenador.current_tap,-1,20,15,0);
print_copy();
......@@ -583,10 +584,10 @@ void taps_menu() {
break;
case SDLK_3:
ordenador.OOTape.set_pause(true);
ordenador.tape_fast_load = 1-ordenador.tape_fast_load;
ordenador.tape_fast_load = ordenador.tape_fast_load ? false : true;
break;
case SDLK_4:
ordenador.tape_write=1-ordenador.tape_write;
ordenador.tape_write = ordenador.tape_write ? false : true;
break;
case SDLK_5:
create_tapfile();
......@@ -617,43 +618,25 @@ void select_tapfile() {
return;
}
if(ordenador.tap_file!=NULL) {
fclose(ordenador.tap_file);
}
ordenador.tap_file=fopen(filename,"r+"); // read and write
ordenador.tape_write = 0; // by default, can't record
if(ordenador.tap_file==NULL)
retorno=-1;
else
retorno=0;
llscreen->clear_screen();
strcpy(ordenador.current_tap,filename);
ordenador.tape_write = false; // by default, can't record
ordenador.current_tap = filename;
free(filename);
switch(retorno) {
case 0: // all right
break;
case -1:
if (ordenador.OOTape.load_file(ordenador.current_tap)) {
llscreen->print_string("Error: Can't load that file",-1,-4,10,0);
llscreen->print_string("Press any key",-1,-3,10,0);
ordenador.current_tap[0]=0;
ordenador.current_tap = "";
wait_key();
break;
}
ordenador.OOTape.load_file(ordenador.current_tap);
llscreen->clear_screen();
}
void create_tapfile() {
int retorno;
char nombre2[1024];
struct stat tmpstat;
llscreen->clear_screen();
......@@ -671,35 +654,34 @@ void create_tapfile() {
if(retorno==2) // abort
return;
if(ordenador.tap_file!=NULL)
fclose(ordenador.tap_file);
ordenador.tap_file=fopen(nombre2,"r"); // test if it exists
if(ordenador.tap_file==NULL)
retorno=0;
else
retorno=-1;
if(!retorno) {
ordenador.tap_file=fopen(nombre2,"a+"); // create for read and write
if(ordenador.tap_file==NULL)
retorno=-2;
else
retorno=0;
if (-1 == stat(nombre2,&tmpstat)) {
// File not exists. Good.
FILE *tmp = fopen(nombre2,"a+"); // create for read and write
if(tmp == NULL) {
retorno = -2;
} else {
fclose(tmp);
retorno = 0;
}
} else {
retorno = -1;
}
ordenador.tape_write=1; // allow to write
strcpy(ordenador.current_tap,nombre2);
switch(retorno) {
case 0:
ordenador.tape_write = true; // allow to write
ordenador.current_tap = nombre2;
break;
case -1:
llscreen->print_string("File already exists",-1,5,10,0);
ordenador.current_tap[0]=0;
ordenador.current_tap = "";
ordenador.tape_write = false;
wait_key();
break;
case -2:
llscreen->print_string("Can't create file",-1,5,10,0);
ordenador.current_tap[0]=0;
ordenador.current_tap = "";
ordenador.tape_write = false;
wait_key();
break;
}
......
......@@ -394,12 +394,13 @@ void Tape::delete_blocks() {
this->block_accesed = false;
}
bool Tape::load_file(char *filename) {
bool Tape::load_file(string filename) {
char char_id[10];
this->delete_blocks();
this->paused = true;
FILE *file = fopen(filename,"rb");
FILE *file = fopen(filename.c_str(),"rb");
if (file == NULL) {
return true; // error while opening the file
}
......@@ -454,21 +455,21 @@ bool Tape::read_24bit(FILE *file, uint32_t &value) {
return false;
}
bool Tape::load_tap(char *filename) {
bool Tape::load_tap(string filename) {
FILE *file;
uint8_t data[65536];
uint16_t size;
size_t retval;
file = fopen(filename,"rb");
file = fopen(filename.c_str(),"rb");
if (file == NULL) {
return true; // error while opening the file
}
do {
// read block size
if (this->read_16bit(file,size)) {
return true;
return false;
}
retval = fread (data, size, 1, file);
if (retval != 1) {
......@@ -476,21 +477,21 @@ bool Tape::load_tap(char *filename) {
return (true); // end-of-file and error
}
this->add_block(new FullBlock(data,size,1000));
} while(true);
} while(!feof(file));
fclose(file);
this->current_block = this->blocks;
return false;
}
bool Tape::load_tzx(char *filename) {
bool Tape::load_tzx(string filename) {
FILE *file;
uint8_t block_type;
uint8_t tmpdata[10];
size_t retval;
file = fopen(filename,"rb");
file = fopen(filename.c_str(),"rb");
if (file == NULL) {
return true; // error while opening the file
}
......
......@@ -24,6 +24,8 @@
* Author: raster
*/
using namespace std;
#include <string>
#include <inttypes.h>
#include <stdio.h>
......@@ -57,8 +59,8 @@ class Tape {
void add_block(class TapeBlock *);
void delete_blocks();
bool load_tap(char *);
bool load_tzx(char *);
bool load_tap(string);
bool load_tzx(string);
bool tzx_standard_block(FILE *);
bool tzx_turbo_block(FILE *);
bool tzx_tone_block(FILE *);
......@@ -79,7 +81,7 @@ public:
* @param filename The full path to the file
* @return TRUE if there was an error; FALSE if the file was loaded fine
*/
bool load_file(char *filename);
bool load_file(string);
/**
* Pauses or releases the tape emulation
* @param pause TRUE to pause the tape, FALSE to release it
......
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