1 /** \file   src/imagecontents.h
2  * \brief   Extract the directory listing from disk/tape images - header
3  */
4 
5 /*
6  * imagecontents.h - Extract the directory from disk/tape images.
7  *
8  * Written by
9  *  Ettore Perazzoli <ettore@comm2000.it>
10  *  Andreas Boose <viceteam@t-online.de>
11  *
12  * This file is part of VICE, the Versatile Commodore Emulator.
13  * See README for copyright notice.
14  *
15  *  This program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2 of the License, or
18  *  (at your option) any later version.
19  *
20  *  This program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with this program; if not, write to the Free Software
27  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28  *  02111-1307  USA.
29  *
30  */
31 
32 #ifndef VICE_IMAGE_CONTENTS_H
33 #define VICE_IMAGE_CONTENTS_H
34 
35 #include "types.h"
36 
37 #define IMAGE_CONTENTS_NAME_LEN         16  /**< standard length of container
38                                                  names, such as D64 */
39 #define IMAGE_CONTENTS_NAME_T64_LEN     24  /**< length of a T64 container
40                                                  name */
41 #define IMAGE_CONTENTS_ID_LEN           5   /**< length of a disk ID */
42 #define IMAGE_CONTENTS_FILE_NAME_LEN    16  /**< lenght of a PETSCII filename */
43 #define IMAGE_CONTENTS_TYPE_LEN         5   /**< file type and flags, eg:
44                                                  '*PRG<' */
45 
46 /** \brief  Object containing a directory listing entry
47  */
48 struct image_contents_file_list_s {
49     uint8_t name[IMAGE_CONTENTS_FILE_NAME_LEN + 1];    /**< PETSCII file name */
50     uint8_t type[IMAGE_CONTENTS_TYPE_LEN + 1];         /**< PETSCII file type and
51                                                          'flags' */
52 
53     unsigned int size;  /**< size of the file */
54 
55     struct image_contents_file_list_s *prev, *next; /**< linked list pointers */
56 };
57 typedef struct image_contents_file_list_s image_contents_file_list_t;
58 
59 
60 /** \brief  Image contents object
61  *
62  * Contains a disk/tape name, and ID, number of blocks free (if available)
63  * and a list of directory entries
64  */
65 struct image_contents_s {
66     uint8_t name[IMAGE_CONTENTS_NAME_T64_LEN + 1]; /**< disk/tape name in PETSCII */
67     uint8_t id[IMAGE_CONTENTS_ID_LEN + 1];         /**< disk ID */
68     int blocks_free;   /**< blocks free: -1: No free space information.  */
69     image_contents_file_list_t *file_list;  /**< list of directory entries */
70 };
71 typedef struct image_contents_s image_contents_t;
72 typedef image_contents_t *(*read_contents_func_type)(const char *);
73 
74 /** \brief  Screencode object for displaying directory entries
75  */
76 struct image_contents_screencode_s {
77     uint8_t *line; /**< screencode data */
78     unsigned int length;    /**< length of the line */
79     struct image_contents_screencode_s *next;   /**< pointer to next node */
80 };
81 typedef struct image_contents_screencode_s image_contents_screencode_t;
82 
83 /* ------------------------------------------------------------------------- */
84 
85 extern void image_contents_destroy(image_contents_t *contents);
86 extern image_contents_t *image_contents_new(void);
87 
88 extern image_contents_screencode_t *image_contents_to_screencode (image_contents_t *contents);
89 extern void image_contents_screencode_destroy(image_contents_screencode_t *c);
90 
91 /* These must be the same as the CONVERT_TO_* defines in charset.h, as
92    they are used interchangeably, although their meaning is not identical */
93 #define IMAGE_CONTENTS_STRING_PETSCII 0  /**< return string in PETSCII form */
94 #define IMAGE_CONTENTS_STRING_ASCII   1  /**< convert string to ASCII */
95 #define IMAGE_CONTENTS_STRING_UTF8    2  /**< convert string to UTF-8 */
96 
97 extern char *image_contents_to_string(image_contents_t * contents, char out_charset);
98 extern char *image_contents_file_to_string(image_contents_file_list_t * p, char out_charset);
99 extern char *image_contents_filename_to_string(image_contents_file_list_t * p, char out_charset);
100 extern char *image_contents_filetype_to_string(image_contents_file_list_t * p, char out_charset);
101 extern char *image_contents_filename_by_number(image_contents_t *contents,
102                                                unsigned int file_index);
103 
104 extern image_contents_t *diskcontents_iec_read(unsigned int unit);
105 
106 #endif
107