Tape browser

This commit is contained in:
fabio.olimpieri 2013-03-16 07:58:25 +00:00
parent f945b1c549
commit a342c03cfb
6 changed files with 111 additions and 18 deletions

View File

@ -48,6 +48,9 @@ extern FILE *fdebug;
#endif
#endif
int countdown_buffer;
unsigned char joybutton_matrix[2][322];
void update_npixels()
{
ordenador.npixels= 1;

View File

@ -36,8 +36,8 @@ enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2,
enum taptypes {TAP_TAP, TAP_TZX};
enum block_type {NOBLOCK, PROG, VAR, DATA};
int countdown_buffer;
unsigned char joybutton_matrix[2][322];
extern int countdown_buffer;
extern unsigned char joybutton_matrix[2][322];
struct computer {
@ -180,6 +180,7 @@ struct computer {
unsigned char tape_readed;
unsigned int tape_byte_counter;
unsigned int tape_pause_at_end;
unsigned int tape_position;
FILE *tap_file;
unsigned char tape_fast_load; // 0 normal load; 1 fast load
unsigned char rewind_on_reset;

View File

@ -31,6 +31,7 @@
#include "emulator.h"
#include "VirtualKeyboard.h"
#include "tape.h"
#include "tape_browser.h"
#include "menus.h"
#include "cargador.h"
#include "characters.h"
@ -58,7 +59,7 @@ void clean_screen();
static const char *main_menu_messages[] = {
/*00*/ "Tape",
/*01*/ "^|Insert|Load|Play|Stop|Rewind|Create|Delete",
/*01*/ "^|Insert|Load|Play|Stop|Rewind|Create|Del|Browse",
/*02*/ "Snapshot",
/*03*/ "^|Load|Save|Delete",
/*04*/ "#1---------------------------------------------",
@ -229,6 +230,37 @@ void maybe_load_conf(const char *filename)
}
static void tape_browser()
{
unsigned int tape_position, block_n_int;
const char *row_selected;
char block_n[4];
row_selected = menu_select_browser(ordenador.tape_position);
if (row_selected==NULL) // Aborted
return;
if (row_selected[0]==']') strncpy(block_n, row_selected+1,3);
else strncpy(block_n, row_selected,3);
block_n[3]=0;
block_n_int=atoi(block_n);
if ((block_n_int<0)||(block_n_int >(MAX_BROWSER_ITEM-1))) return;
tape_position=browser_list[block_n_int]->position;
ordenador.tape_current_bit=0;
ordenador.tape_current_mode=TAP_TRASH;
ordenador.next_block= NOBLOCK;
fseek(ordenador.tap_file, tape_position, SEEK_SET);
ordenador.tape_position = tape_position;
free((void*)row_selected);
}
static void insert_tape()
{
unsigned char char_id[11];
@ -292,10 +324,13 @@ static void insert_tape()
if((!strncmp(char_id,"ZXTape!",7)) && (char_id[7]==0x1A)&&(char_id[8]==1)) {
ordenador.tape_file_type = TAP_TZX;
rewind_tape(ordenador.tap_file,1);
browser_tzx(ordenador.tap_file);
} else {
ordenador.tape_file_type = TAP_TAP;
rewind_tape(ordenador.tap_file,1);
browser_tap(ordenador.tap_file);
}
}
static void delete_tape()
@ -471,7 +506,10 @@ static int manage_tape(int which)
break;
case 6: //Delete
delete_tape();
break;
break;
case 7: //Browser
tape_browser();
break;
default:
break;
}

View File

@ -41,6 +41,7 @@
#include "characters.h"
#include "minizip/unzip.h"
#include "tape_browser.h"
#if defined(GEKKO)
# include <wiiuse/wpad.h>
@ -669,7 +670,12 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu, int sel, int font_siz
menu_print_font(screen, 0x40,0x40,0x40,
x_start, y_start + y, msg, font_size, max_string);
else if (p_menu->cur_sel == i) /* Selected - color */
{menu_print_font(screen, 0,200,0,
{
if (msg[0] == ']')
menu_print_font(screen, 0,200,0,
x_start, y_start + y, msg+1, font_size,max_string ); //do not show ']'
else
menu_print_font(screen, 0,200,0,
x_start, y_start + y, msg, font_size,max_string );
selected_file = msg;
}
@ -700,6 +706,10 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu, int sel, int font_siz
break;
}
}
else if (msg[0] == ']')
menu_print_font(screen, 0,0,255,
x_start, y_start + y, msg+1, font_size, max_string);
else /* Otherwise white */
menu_print_font(screen, 0x40,0x40,0x40,
x_start, y_start + y, msg, font_size, max_string);
@ -1279,10 +1289,33 @@ static const char *menu_select_file_internal_zip(char *path,
return write_filename;
}
static const char *menu_select_file_internal(char *dir_path,
int x, int y, int x2, int y2, const char *selected_file, int draw_scr)
const char **get_file_list_browser(unsigned int tape_pos, unsigned int *block_pos)
{
const char **file_list = get_file_list(dir_path);
unsigned int loop;
char **browser_list_menu;
browser_list_menu = (char**)malloc((MAX_BROWSER_ITEM+1) * sizeof(char*));
browser_list_menu[0] = NULL;
for(loop=0;browser_list[loop]!=NULL;loop++)
{
browser_list_menu[loop]=malloc(24+32+8);
if (browser_list[loop]->position==tape_pos)
{
sprintf(browser_list_menu[loop],"]%03d %s %s",loop,browser_list[loop]->block_type, browser_list[loop]->info);
*block_pos=loop;
}
else
sprintf(browser_list_menu[loop],"%03d %s %s",loop,browser_list[loop]->block_type, browser_list[loop]->info);
}
browser_list_menu[loop]=NULL;
return (const char **) browser_list_menu;
}
static const char *menu_select_file_internal(char *dir_path,
int x, int y, int x2, int y2, const char *selected_file, int draw_scr, unsigned int tape_pos)
{
const char **file_list;
char *sel;
char *out;
char *out_zip;
@ -1291,11 +1324,15 @@ static const char *menu_select_file_internal(char *dir_path,
int opt;
int i;
char buf[64];
unsigned int block_pos;
if (strcmp(dir_path,"browser")) file_list = get_file_list(dir_path); else file_list = get_file_list_browser(tape_pos, &block_pos);
if (file_list == NULL)
return NULL;
if (selected_file)
if (!strcmp(dir_path,"browser")) opt = menu_select_sized("Select block", file_list, NULL, block_pos, x, y, x2, y2, NULL, NULL ,16, draw_scr);
else if (selected_file)
{
ptr_selected_file= strrchr(selected_file,'/');
if (ptr_selected_file) ptr_selected_file++;
@ -1317,6 +1354,8 @@ static const char *menu_select_file_internal(char *dir_path,
if (!sel)
return NULL;
if (!strcmp(dir_path,"browser")) return sel;
if (!strcmp(sel,"[..]")) //selected "[..]"
{
free((void*)sel);
@ -1336,7 +1375,7 @@ static const char *menu_select_file_internal(char *dir_path,
/* Remove trailing ] */
sel[len-1] = '\0';
if ((strlen(dir_path) + len) < 2049)
if ((strlen(dir_path) + len) < MAX_PATH_LENGTH)
{
strcat(dir_path, "/");
strcat(dir_path, sel+1);
@ -1367,7 +1406,7 @@ static const char *menu_select_file_internal(char *dir_path,
if(!strcmp(out_zip,"[..]"))
{
free(out_zip);
return menu_select_file_internal (dir_path, x, y, x2, y2, selected_file, draw_scr);
return menu_select_file_internal (dir_path, x, y, x2, y2, selected_file, draw_scr, 0);
}
else return out_zip;
}
@ -1379,9 +1418,16 @@ const char *menu_select_file(char *dir_path,const char *selected_file, int draw_
if (dir_path == NULL)
dir_path = "";
return menu_select_file_internal(dir_path,
0, 20/RATIO, FULL_DISPLAY_X, FULL_DISPLAY_Y - 20/RATIO, selected_file, draw_scr);
0, 20/RATIO, FULL_DISPLAY_X, FULL_DISPLAY_Y - 20/RATIO, selected_file, draw_scr, 0);
}
const char *menu_select_browser(unsigned int tape_pos)
{
return menu_select_file_internal("browser",
0, 20/RATIO, FULL_DISPLAY_X, FULL_DISPLAY_Y - 20/RATIO, NULL, 0, tape_pos);
}
static TTF_Font *read_font(const char *path, int font_size)
{
TTF_Font *out;

View File

@ -53,7 +53,7 @@ void print_font(SDL_Surface *screen, int r, int g, int b, int x, int y, const ch
int menu_select_title(const char *title, const char **pp_msgs, int *p_submenus);
int menu_select(const char **pp_msgs, int *p_submenus);
const char *menu_select_file(char *dir_path,const char *selected_file, int draw_scr);
const char *menu_select_browser(unsigned int tape_pos);
uint32_t menu_wait_key_press();

View File

@ -89,6 +89,7 @@ inline void tape_read_tap (FILE * fichero, int tstados) {
if (!ordenador.tape_stop) {
if (ordenador.tape_current_mode == TAP_TRASH) { // initialize a new block
ordenador.tape_position=ftell(fichero);
retval=fread (&value, 1, 1, fichero);
retval=fread (&value2, 1, 1, fichero); // read block longitude
if (feof (fichero)) {
@ -220,6 +221,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) {
if (ordenador.tape_current_mode == TAP_TRASH) { // initialize a new block
done = 0;
ordenador.tape_position=ftell(fichero);
do {
retval=fread(&value,1,1,fichero); // read block ID
printf("TZX:ID_normal: %X en %ld\n",value,ftell(fichero));
@ -680,10 +682,11 @@ void rewind_tape(FILE *fichero,unsigned char pause) {
unsigned char value;
int retval;
rewind (ordenador.tap_file);
rewind (fichero);
if(ordenador.tape_file_type==TAP_TZX)
for(thebucle=0;thebucle<10;thebucle++)
retval=fread(&value,1,1,ordenador.tap_file); // jump over the header
ordenador.tape_position=ftell(fichero);
ordenador.next_block= NOBLOCK;
ordenador.tape_stop=pause;
ordenador.tape_stop_fast=pause;
@ -743,6 +746,7 @@ void save_file(FILE *fichero) {
procesador.Rm.wr.IX++;
procesador.Rm.wr.IX++;
fseek(fichero,position,SEEK_SET); // put position at end
ordenador.tape_position = position;
if(ordenador.tape_fast_load==1) //if we want fast load, we assume we want fast save too
ordenador.other_ret = 1; // next instruction must be RET
@ -804,7 +808,7 @@ void fastload_block_tap (FILE * fichero) {
ordenador.osd_time = 100;
return;
}
ordenador.tape_position=ftell(fichero);
retval=fread (value, 1, 2, fichero); // read length of current block
if (feof (fichero)) { // end of file?
sprintf (ordenador.osd_text, "Rewind tape");
@ -948,6 +952,7 @@ void fastload_block_tzx (FILE * fichero) {
do {
retorno=0;
ordenador.tape_position=ftell(fichero);
byte_position=ftell(fichero);
retval=fread (&blockid, 1, 1, fichero); //Read id block
if (feof (fichero)) // end of file?
@ -977,8 +982,8 @@ void fastload_block_tzx (FILE * fichero) {
switch(flag_byte)
{
case 0x00: //header
retval=fread (value, 1, 17, fichero);
if (retval!=17) {procesador.Rm.br.F &= (~F_C);return;}
retval=fread (value, 1, 18, fichero);
if (retval!=18) {procesador.Rm.br.F &= (~F_C);return;}
switch(value[0] ) //Type
{
case 0x00: