Previous 15994 Revisions Next

r4437 Friday 27th March, 2009 at 18:25:25 UTC by Miodrag Milanović
[CASTOOL] Cassette tool, from any format to WAV
[docs]messnew.txt
[src/mess]mess.mak
[src/mess/tools/castool]castool.mak* main.c* stubs.c*

src/mess/tools/castool/stubs.c
r0r4437
1#include "driver.h"
2#include <ctype.h>
3#include <stdarg.h>
4 
5/* Variables to hold the status of various game options */
6static FILE *errorlog;
7 
8const game_driver *const drivers[1];
9int rompath_extra;
10int history_filename;
11int mameinfo_filename;
12 
13void CLIB_DECL logerror(const char *text,...)
14{
15   va_list arg;
16   va_start(arg,text);
17   if (errorlog)
18      vfprintf(errorlog,text,arg);
19   va_end(arg);
20}
21 
22/* ----------------------------------------------------------------------- */
23/* total hack */
24 
25file_error mame_fopen(const char *searchpath, const char *filename, UINT32 openflags, mame_file **file)
26{
27   char buffer[2048];
28   snprintf(buffer, sizeof(buffer), "crc/%s", filename);
29   *file = (mame_file *) fopen(buffer, "r");
30   return FILERR_NONE;
31}
32 
33char *mame_fgets(char *s, int n, mame_file *file)
34{
35   return fgets(s, n, (FILE *) file);
36}
37 
38UINT32 mame_fwrite(mame_file *file, const void *buffer, UINT32 length)
39{
40   return fwrite(buffer, 1, length, (FILE *) file);
41}
42 
43void mame_fclose(mame_file *file)
44{
45   fclose((FILE *) file);
46}
47 
48int CLIB_DECL mame_fprintf(mame_file *f, const char *fmt, ...)
49{
50   int rc;
51   va_list va;
52   va_start(va, fmt);
53   rc = vfprintf(stderr, fmt, va);
54   va_end(va);
55   return rc;
56}
57 
58void mame_printf_error(const char *format, ...)
59{
60}
61 
62void mame_printf_warning(const char *format, ...)
63{
64}
65 
66void mame_printf_info(const char *format, ...)
67{
68}
69 
70void mame_printf_debug(const char *format, ...)
71{
72}
73 
74 
75 
76/***************************************************************************
77    TYPE DEFINITIONS
78***************************************************************************/
79 
80enum _memory_block_overlap
81{
82   OVERLAP_NONE,
83   OVERLAP_PARTIAL,
84   OVERLAP_FULL
85};
86typedef enum _memory_block_overlap memory_block_overlap;
87 
88 
89 
90/***************************************************************************
91    GLOBAL VARIABLES
92***************************************************************************/
93 
94/* pool list */
95static object_pool *pools[64];
96 
97/* resource tracking */
98int resource_tracking_tag = 0;
99 
100 
101 
102/***************************************************************************
103    PROTOTYPES
104***************************************************************************/
105 
106static void astring_destructor(void *object, size_t size);
107static void bitmap_destructor(void *object, size_t size);
108 
109 
110/***************************************************************************
111    CORE IMPLEMENTATION
112***************************************************************************/
113 
114/*-------------------------------------------------
115    init_resource_tracking - initialize the
116    resource tracking system
117-------------------------------------------------*/
118 
119void init_resource_tracking(void)
120{
121   resource_tracking_tag = 0;
122}
123 
124 
125/*-------------------------------------------------
126    exit_resource_tracking - tear down the
127    resource tracking system
128-------------------------------------------------*/
129 
130void exit_resource_tracking(void)
131{
132   while (resource_tracking_tag != 0)
133      end_resource_tracking();
134}
135 
136 
137/*-------------------------------------------------
138    memory_error - report a memory error
139-------------------------------------------------*/
140 
141static void memory_error(const char *message)
142{
143   fatalerror("%s", message);
144}
145 
146 
147/*-------------------------------------------------
148    begin_resource_tracking - start tracking
149    resources
150-------------------------------------------------*/
151 
152void begin_resource_tracking(void)
153{
154   object_pool *new_pool;
155 
156   /* sanity check */
157   assert_always(resource_tracking_tag < ARRAY_LENGTH(pools), "Too many memory pools");
158 
159   /* create a new pool */
160   new_pool = pool_alloc(memory_error);
161   if (!new_pool)
162      fatalerror("Failed to allocate new memory pool");
163   pools[resource_tracking_tag] = new_pool;
164 
165   /* add resource types */
166   pool_type_register(new_pool, OBJTYPE_ASTRING, "String", astring_destructor);
167   pool_type_register(new_pool, OBJTYPE_BITMAP, "Bitmap", bitmap_destructor);
168   //pool_type_register(new_pool, OBJTYPE_TIMER, "Timer", timer_destructor);
169   //pool_type_register(new_pool, OBJTYPE_STATEREG, "Save State Registration", state_destructor);
170 
171   /* increment the tag counter */
172   resource_tracking_tag++;
173}
174 
175 
176/*-------------------------------------------------
177    end_resource_tracking - stop tracking
178    resources
179-------------------------------------------------*/
180 
181void end_resource_tracking(void)
182{
183   /* decrement the tag counter */
184   resource_tracking_tag--;
185 
186   /* free the memory pool */
187   pool_free(pools[resource_tracking_tag]);
188   pools[resource_tracking_tag] = NULL;
189}
190 
191 
192/*-------------------------------------------------
193    current_pool - identifies the current memory
194    pool
195-------------------------------------------------*/
196 
197static object_pool *current_pool(void)
198{
199   object_pool *pool;
200   assert_always((resource_tracking_tag > 0) && (resource_tracking_tag <= ARRAY_LENGTH(pools)), "Invalid resource_tracking_tag");
201   pool = pools[resource_tracking_tag - 1];
202   assert_always(pool != NULL, "current_pool() is NULL");
203   return pool;
204}
205 
206 
207/*-------------------------------------------------
208    restrack_register_object - registers an
209    object with the current pool
210-------------------------------------------------*/
211 
212void *restrack_register_object(object_type type, void *ptr, size_t size, const char *file, int line)
213{
214   return pool_object_add_file_line(current_pool(), type, ptr, size, file, line);
215}
216 
217 
218/*-------------------------------------------------
219    auto_malloc_file_line - allocate auto-
220    freeing memory
221-------------------------------------------------*/
222 
223void *auto_malloc_file_line(size_t size, const char *file, int line)
224{
225   void *result = pool_malloc_file_line(current_pool(), size, file, line);
226#ifdef MAME_DEBUG
227   rand_memory(result, size);
228#endif
229   return result;
230}
231 
232 
233/*-------------------------------------------------
234    auto_realloc_file_line - reallocate auto-
235    freeing memory
236-------------------------------------------------*/
237 
238void *auto_realloc_file_line(void *ptr, size_t size, const char *file, int line)
239{
240   object_pool *pool = current_pool();
241   if (ptr != NULL)
242   {
243      int tag = resource_tracking_tag;
244      for (; tag > 0; tag--)
245      {
246         pool = pools[tag - 1];
247         if (pool_object_exists(pool, OBJTYPE_MEMORY, ptr))
248            break;
249      }
250      assert_always(tag > 0, "Failed to find alloc in pool");
251   }
252 
253   return pool_realloc_file_line(pool, ptr, size, file, line);
254}
255 
256 
257/*-------------------------------------------------
258    auto_strdup_file_line - allocate auto-freeing
259    string
260-------------------------------------------------*/
261 
262char *auto_strdup_file_line(const char *str, const char *file, int line)
263{
264   return pool_strdup_file_line(current_pool(), str, file, line);
265}
266 
267 
268/*-------------------------------------------------
269    auto_strdup_allow_null_file_line - allocate
270    auto-freeing string if str is null
271-------------------------------------------------*/
272 
273char *auto_strdup_allow_null_file_line(const char *str, const char *file, int line)
274{
275   return (str != NULL) ? auto_strdup_file_line(str, file, line) : NULL;
276}
277 
278 
279/*-------------------------------------------------
280    auto_astring_alloc_file_line - allocate
281    auto-freeing astring
282-------------------------------------------------*/
283 
284astring *auto_astring_alloc_file_line(const char *file, int line)
285{
286   return (astring *)restrack_register_object(OBJTYPE_ASTRING, astring_alloc(), 0, file, line);
287}
288 
289 
290 
291/*-------------------------------------------------
292    astring_destructor - destructor for astring
293    objects
294-------------------------------------------------*/
295 
296static void astring_destructor(void *object, size_t size)
297{
298   astring_free((astring *)object);
299}
300 
301 
302/*-------------------------------------------------
303    bitmap_destructor - destructor for bitmap
304    objects
305-------------------------------------------------*/
306 
307static void bitmap_destructor(void *object, size_t size)
308{
309   bitmap_free((bitmap_t *)object);
310}
311 
312 
src/mess/tools/castool/main.c
r0r4437
1/***************************************************************************
2 
3   main.c
4 
5   Castool command line front end
6   
7   27/03/2009 Initial version by Miodrag Milanovic
8 
9***************************************************************************/
10 
11#include <stdio.h>
12#include <string.h>
13#include <ctype.h>
14#include <stdlib.h>
15#include <time.h>
16#include <assert.h>
17 
18#include "mame.h"
19#include "mess.h"
20#include "fileio.h"
21#ifdef WIN32
22#include "winutils.h"
23#endif
24 
25#include "devices/cassette.h"
26 
27#include "formats/a26_cas.h" 
28#include "formats/apf_apt.h" 
29#include "formats/cbm_tap.h" 
30#include "formats/cgen_cas.h" 
31#include "formats/coco_cas.h" 
32#include "formats/csw_cas.h" 
33#include "formats/fmsx_cas.h" 
34#include "formats/gtp_cas.h" 
35#include "formats/jupi_tap.h" 
36#include "formats/kim1_cas.h" 
37#include "formats/lviv_lvt.h" 
38#include "formats/mz_cas.h" 
39#include "formats/orao_cas.h" 
40#include "formats/oric_tap.h" 
41#include "formats/pmd_pmd.h" 
42#include "formats/primoptp.h" 
43#include "formats/rk_cas.h" 
44#include "formats/sord_cas.h" 
45#include "formats/svi_cas.h" 
46#include "formats/trs_cas.h" 
47#include "formats/tzx_cas.h" 
48#include "formats/uef_cas.h" 
49#include "formats/vt_cas.h" 
50#include "formats/zx81_p.h" 
51 
52struct SupportedCassetteFormats
53{
54   const char *name;
55   const struct CassetteFormat * const *formats;
56   const char *desc;
57};
58 
59const struct SupportedCassetteFormats formats[] = {   
60   {"a26", a26_cassette_formats               ,"Atari 2600"},
61   {"apf", apf_cassette_formats               ,"APF Imagination Machine"},
62   {"cbm", cbm_cassette_formats               ,"Commodore"},
63   {"cgenie", cgenie_cassette_formats         ,"Colour Genie"},
64   {"coco", coco_cassette_formats             ,"TRS-80 Radio Shack Color Computer Family"},
65   {"csw", csw_cassette_formats               ,"Compressed Square Wave"},
66   {"bbc", bbc_cassette_formats               ,"BBC"},
67   {"fmxs", fmsx_cassette_formats             ,"MSX"},
68   {"gtp", gtp_cassette_formats               ,"Galaksija"},
69   {"jupiter", jupiter_cassette_formats       ,"Jupiter"},
70   {"kim1", kim1_cassette_formats             ,"KIM-1"},
71   {"lviv", lviv_lvt_format                   ,"Lviv"},
72   {"mz", mz700_cassette_formats              ,"Sharp MZ"},
73   {"orao", orao_cassette_formats             ,"Orao"},
74   {"oric", oric_cassette_formats             ,"Oric"},
75   {"pmd85", pmd85_pmd_format                 ,"PMD-85"},
76   {"primo", primo_ptp_format                 ,"Primo"},
77   {"rku", rku_cassette_formats               ,"UT-88"},
78   {"rk8", rk8_cassette_formats               ,"Mikro-80"},
79   {"rks", rks_cassette_formats               ,"Specialist"},
80   {"rko", rko_cassette_formats               ,"Orion"},
81   {"rkr", rkr_cassette_formats               ,"Radio-86RK"},
82   {"rka", rka_cassette_formats               ,"Apogee"},
83   {"rkm", rkm_cassette_formats               ,"Mikrosha"},
84   {"rkp", rkp_cassette_formats               ,"Partner"},
85   {"sord5m", sordm5_cassette_formats         ,"Sord-5M"},
86   {"svi", svi_cassette_formats               ,"SVI"},
87   {"trs80l2", trs80l2_cassette_formats       ,"TRS-80 Level 2"},
88   {"tzx", tzx_cassette_formats               ,"ZX Spectrum"},
89   {"cdt", cdt_cassette_formats               ,"Amstrad CPC"},
90   {"uef", uef_cassette_formats               ,"Acorn Electron"},
91   {"vtech1", vtech1_cassette_formats         ,"Video Technology Laser 110-310"},
92   {"vtech2", vtech2_cassette_formats         ,"Video Technology Laser 350-700"},
93   {"zx81_p", zx81_p_format                   ,"Sinclair ZX81"},
94   {"zx80_o", zx80_o_format                   ,"Sinclair ZX80"},
95   {NULL,NULL,NULL}
96};   
97 
98 
99const char *get_extension(const char *name)
100{
101   const char *s;
102   s = name;
103   if (s != NULL)
104      s = strrchr(s, '.');
105   return s ? s+1 : NULL;
106}
107 
108void display_usage(void)
109{
110   fprintf(stderr, "Usage: \n");
111   fprintf(stderr, "      castool.exe convert <format> <inputfile> <outputfile.wav>\n");
112}
113 
114void display_formats(void)
115{
116   int i,j;
117   fprintf(stderr, "Supported formats:\n\n");
118   for (i = 0; formats[i].name; i++) {
119      fprintf(stderr, "%10s - %s\n",formats[i].name,formats[i].desc);
120      for (j = 1; formats[i].formats[j]; j++) {
121         fprintf(stderr, "%15s %s\n","",formats[i].formats[j]->extensions);
122      }
123   }
124}
125 
126#ifdef WIN32
127int CLIB_DECL utf8_main(int argc, char *argv[])
128#else
129int CLIB_DECL main(int argc, char *argv[])
130#endif
131{   
132   int i;
133   int found =0;
134   const struct CassetteFormat * const *selected_formats;
135   cassette_image *cassette;
136   FILE *f;
137#ifdef WIN32
138   win_expand_wildcards(&argc, &argv);
139#endif /* WIN32 */
140 
141 
142   init_resource_tracking();   
143   begin_resource_tracking();
144 
145   if (argc > 1)
146   {
147      if (!mame_stricmp("convert", argv[1]))
148      {
149         // convert command
150         if (argc!=5) {
151            fprintf(stderr, "Wrong parameter number.\n\n");
152            display_usage();
153            return -1;
154         } else {
155            for (i = 0; formats[i].name; i++) {
156               if (mame_stricmp(formats[i].name,argv[2])==0) {
157                  selected_formats = formats[i].formats;
158                  found = 1;
159               }               
160            }
161            if (found==0) {
162               fprintf(stderr, "Wrong format name.\n\n");
163               display_usage();
164               fprintf(stderr, "\n");
165               display_formats();
166               return -1;               
167            }             
168             
169            f = fopen(argv[3], "rb");   
170            if (!f) {
171               fprintf(stderr, "File %s not found.\n",argv[3]);
172               return -1;
173            }
174   
175            if (cassette_open_choices(f, &stdio_ioprocs, get_extension(argv[3]), selected_formats, CASSETTE_FLAG_READONLY, &cassette))   {
176               fprintf(stderr, "Invalid format of input file.\n");               
177               return -1;
178            }
179         
180            cassette_dump(cassette,argv[4]);
181            cassette_close(cassette);
182            goto theend;
183         }
184      }
185   } 
186 
187   /* Usage */
188   fprintf(stderr, "castool - Generic cassette manipulation tool for use with MESS\n\n");
189   display_usage();
190   fprintf(stderr, "\n");
191   display_formats();
192   fprintf(stderr, "\nExample usage:\n");
193   fprintf(stderr, "        castool.exe tzx game.tzx game.wav\n\n");   
194 
195theend :
196   /* clean up our tracked resources */
197   exit_resource_tracking();
198 
199   return 0;
200}
src/mess/tools/castool/castool.mak
r0r4437
1###########################################################################
2#
3#   castool.mak
4#
5#   MESS castool makefile
6#
7###########################################################################
8 
9 
10# castool executable name
11CASTOOL = castool$(EXE)
12 
13# add path to castool headers
14CFLAGS += -I$(SRC)/$(TARGET)/tools/castool
15 
16# castool directories
17CASTOOLOBJ = $(MESSOBJ)/tools/castool
18 
19 
20 
21#-------------------------------------------------
22# castool objects
23#-------------------------------------------------
24 
25OBJDIRS += \
26   $(CASTOOLOBJ)
27 
28LIBCASTOOL = $(OBJ)/libcastool.a
29 
30# castool lib objects
31CASTOOL_LIB_OBJS =                  \
32   $(OBJ)/version.o               \
33   $(EMUOBJ)/mamecore.o            \
34   $(MESSOBJ)/tagpool.o            \
35   $(MESSOBJ)/utils.o               \
36   $(MESSOBJ)/tagpool.o            \
37   $(MESSOBJ)/opresolv.o            \
38   $(MESS_FORMATS)/a26_cas.o           \
39   $(MESS_FORMATS)/apf_apt.o           \
40   $(MESS_FORMATS)/cbm_tap.o           \
41   $(MESS_FORMATS)/cgen_cas.o          \
42   $(MESS_FORMATS)/coco_cas.o          \
43   $(MESS_FORMATS)/csw_cas.o           \
44   $(MESS_FORMATS)/fmsx_cas.o          \
45   $(MESS_FORMATS)/gtp_cas.o           \
46   $(MESS_FORMATS)/jupi_tap.o          \
47   $(MESS_FORMATS)/kim1_cas.o          \
48   $(MESS_FORMATS)/lviv_lvt.o          \
49   $(MESS_FORMATS)/mz_cas.o            \
50   $(MESS_FORMATS)/orao_cas.o          \
51   $(MESS_FORMATS)/oric_tap.o          \
52   $(MESS_FORMATS)/pmd_pmd.o           \
53   $(MESS_FORMATS)/primoptp.o          \
54   $(MESS_FORMATS)/rk_cas.o            \
55   $(MESS_FORMATS)/sord_cas.o          \
56   $(MESS_FORMATS)/svi_cas.o           \
57   $(MESS_FORMATS)/trs_cas.o           \
58   $(MESS_FORMATS)/tzx_cas.o           \
59   $(MESS_FORMATS)/uef_cas.o           \
60   $(MESS_FORMATS)/vt_cas.o            \
61   $(MESS_FORMATS)/zx81_p.o          \
62   $(MESS_FORMATS)/ioprocs.o         \
63   $(MESS_FORMATS)/cassimg.o         \
64   $(MESS_FORMATS)/wavfile.o         \
65   
66 
67$(LIBCASTOOL): $(CASTOOL_LIB_OBJS)
68 
69CASTOOL_OBJS = \
70   $(CASTOOLOBJ)/main.o \
71   $(CASTOOLOBJ)/stubs.o \
72   $(MESSOBJ)/toolerr.o
73 
74 
75 
76#-------------------------------------------------
77# rules to build the castool executable
78#-------------------------------------------------
79 
80$(CASTOOL): $(CASTOOL_OBJS) $(LIBCASTOOL) $(LIBUTIL) $(EXPAT) $(ZLIB) $(LIBOCORE)
81   @echo Linking $@...
82   $(LD) $(LDFLAGS) $^ $(LIBS) -o $@
src/mess/mess.mak
r4436r4437
1515# uncomment next line to build imgtool
1616BUILD_IMGTOOL = 1
1717
18# uncomment next line to build castool
19BUILD_CASTOOL = 1
20
1821# uncomment next line to build wimgtool
1922BUILD_WIMGTOOL = 1
2023
r4436r4437
14491452TOOLS += $(IMGTOOL)
14501453endif
14511454
1455ifdef BUILD_CASTOOL
1456include $(MESSSRC)/tools/castool/castool.mak
1457TOOLS += $(CASTOOL)
1458endif
1459
14521460ifdef BUILD_MESSTEST
14531461include $(MESSSRC)/tools/messtest/messtest.mak
14541462TOOLS += $(MESSTEST)
docs/messnew.txt
r4436r4437
3232- The core is based on MAME 0.130u1.  This incorporates all features of the
3333  update to this core.  [MAME team]
3434
35- New tool added (castool) for cassette to wav conversion [Miodrag Milanovic]
3536
36
37370.130
3838
3939New System Drivers Supported (in no particular order):

Previous 15994 Revisions Next


© 1998-2018 The MESS Team