1 /***********************************************************************
2 * �ե�����̾���桿����
3 ************************************************************************/
4 #include "getconf.h"
5
6 char file_disk[2][QUASI88_MAX_FILENAME]; /*�ǥ�����������ե�����̾*/
7 int image_disk[2]; /*������ֹ�0��31,-1�ϼ�ư*/
8 int readonly_disk[2]; /*��ɥ����dz����ʤ鿿*/
9
10 char file_tape[2][QUASI88_MAX_FILENAME]; /* �ơ��������ϤΥե�����̾ */
11 char file_prn[QUASI88_MAX_FILENAME]; /* �ѥ�����ϤΥե�����̾ */
12 char file_sin[QUASI88_MAX_FILENAME]; /* ���ꥢ����ϤΥե�����̾ */
13 char file_sout[QUASI88_MAX_FILENAME]; /* ���ꥢ�����ϤΥե�����̾ */
14
15 int file_coding = 0; /* �ե�����̾�δ��������� */
16 int filename_synchronize = TRUE; /* �ե�����̾��ƱĴ������ */
17
18
19
20 static char *assemble_filename(const char *imagename,
21 const char *basedir,
22 const char *suffix);
23
24 /*----------------------------------------------------------------------
25 * �ѿ� file_XXX[] �����ꤵ��Ƥ���ե�����٤Ƴ�����
26 * �̾�ϡ��ե�������ݤ� file_XXX[] �����ꤹ��Τ�����
27 * �ʲ��ξ��ϡ���� file_XXX[] �����ꤵ��Ƥ��ޤäƤ���Τǡ�
28 * ���δؿ���ƤӽФ�ɬ�פ����롣
29 *
30 * ����ư�� �ĥ��ץ����� file_XXX[] �����ꤵ���
31 * �����ơ��ȥ��ɻ����ѿ� file_XXX[] ����������롣
32 * (��ư���Υ��ץ����ǥ��ơ��ȥ��ɤ�������Ʊ��)
33 *
34 * ���ơ��ȥ��ɻ��ϡ� stateload �ˤ��ơ��ƤӽФ���
35 *----------------------------------------------------------------------*/
imagefile_all_open(int stateload)36 static void imagefile_all_open(int stateload)
37 {
38 int err0 = TRUE;
39 int err1 = TRUE;
40 int err2 = TRUE;
41 int err3 = TRUE;
42
43 if (stateload == FALSE) {
44 int i;
45 for (i=0; i<NR_DRIVE; i++) {
46 memset(file_disk[i], 0, QUASI88_MAX_FILENAME);
47 if (config_image.d[i]) {
48 strcpy(file_disk[i], config_image.d[i]);
49 }
50 image_disk[i] = config_image.n[i];
51 readonly_disk[i] = config_image.ro[i];
52 }
53
54 for (i=0; i<NR_TAPE; i++) {
55 memset(file_tape[i], 0, QUASI88_MAX_FILENAME);
56 if (config_image.t[i]) {
57 strcpy(file_tape[i], config_image.t[i]);
58 }
59 }
60 }
61 /* ���ơ��ȥ��ɻ��ϡ� file_XXX ������Ѥ� */
62 /* �����ʲ��ϸ��ߥ��ơ��ȥ����֤��Ƥ��ʤ��Τǡ�̵�������� */
63 {
64 memset(file_prn, 0, QUASI88_MAX_FILENAME);
65 if (config_image.prn) {
66 strcpy(file_prn, config_image.prn);
67 }
68
69 memset(file_sin, 0, QUASI88_MAX_FILENAME);
70 if (config_image.sin) {
71 strcpy(file_sin, config_image.sin);
72 }
73
74 memset(file_sout, 0, QUASI88_MAX_FILENAME);
75 if (config_image.sout) {
76 strcpy(file_sout, config_image.sout);
77 }
78 }
79
80
81 if (file_disk[0][0] && /* �ɥ饤��1,2 �Ȥ⥤�������Ѥߤξ�� */
82 file_disk[1][0]) { /* % quasi88 file file */
83 /* % quasi88 file m m */
84 /* % quasi88 file n file */
85 /* % quasi88 file file m */
86 /* % quasi88 file n file m */
87 int same = (strcmp(file_disk[0], file_disk[1]) == 0) ? TRUE : FALSE;
88
89 err0 = disk_insert(DRIVE_1, /* �ɥ饤�� 1 �å� */
90 file_disk[0],
91 (image_disk[0] < 0) ? 0 : image_disk[0],
92 readonly_disk[0]);
93
94 if (same) { /* Ʊ��ե�����ξ��� */
95
96 if (err0 == FALSE) { /* 1: �� 2: ž�� */
97 err1 = disk_insert_A_to_B(DRIVE_1, DRIVE_2,
98 (image_disk[1] < 0) ? 0
99 : image_disk[1]);
100 }
101
102 } else { /* �̥ե�����ξ��� */
103
104 err1 = disk_insert(DRIVE_2, /* �ɥ饤��2 ���å� */
105 file_disk[1],
106 (image_disk[1] < 0) ? 0 : image_disk[1],
107 readonly_disk[1]);
108 }
109
110 /* ξ�ɥ饤�֤�Ʊ���ե����� ���� ��������꼫ư�ξ��ν��� */
111 if (err0 == FALSE &&
112 err1 == FALSE &&
113 drive[DRIVE_1].fp == drive[DRIVE_2].fp &&
114 image_disk[0] < 0 && image_disk[1] < 0) {
115 disk_change_image(DRIVE_2, 1); /* 2: �� �����2�� */
116 }
117
118 } else if (file_disk[0][0]) {/* �ɥ饤��1 ���� ���������Ѥߤξ�� */
119 /* % quasi88 file */
120 /* % quasi88 file num */
121 err0 = disk_insert(DRIVE_1,
122 file_disk[0],
123 (image_disk[0] < 0) ? 0 : image_disk[0],
124 readonly_disk[0]);
125
126 if (err0 == FALSE) {
127 if (image_disk[0] < 0 && /* ������ֹ����ʤ��ʤ� */
128 disk_image_num(DRIVE_1) >= 2) { /* �ɥ饤��2�ˤ⥻�å� */
129
130 err1 = disk_insert_A_to_B(DRIVE_1, DRIVE_2, 1);
131 if (err1 == FALSE) {
132 memcpy(file_disk[1], file_disk[0], QUASI88_MAX_FILENAME);
133 }
134 }
135 }
136
137 } else if (file_disk[1][0]) {/* �ɥ饤��2 ���� ���������Ѥߤξ�� */
138 /* % quasi88 noexist file */
139 err1 = disk_insert(DRIVE_2,
140 file_disk[1],
141 (image_disk[1] < 0) ? 0 : image_disk[1],
142 readonly_disk[1]);
143 }
144
145
146
147 /* �����ץʤ��ä�(����ʤ��ä�)���ϡ��ե�����̾�ꥢ */
148 if (err0) memset(file_disk[ 0 ], 0, QUASI88_MAX_FILENAME);
149 if (err1) memset(file_disk[ 1 ], 0, QUASI88_MAX_FILENAME);
150
151
152 /* ����¾�Υ�����ե�����⥻�å� */
153 if (file_tape[CLOAD][0]) { err2 = sio_open_tapeload(file_tape[CLOAD]); }
154 if (file_tape[CSAVE][0]) { err3 = sio_open_tapesave(file_tape[CSAVE]); }
155 if (file_sin[0]) { sio_open_serialin(file_sin); }
156 if (file_sout[0]) { sio_open_serialout(file_sout); }
157 if (file_prn[0]) { printer_open(file_prn); }
158 /* �����ϡ����ơ��ȥ��ɤǤ�SEEK���Ƥʤ����ɤ����褦�� */
159
160
161 /* �ե�����̾�ˤ��碌�ơ����ʥåץ���åȥե�����̾������ */
162 if (filename_synchronize) {
163 if (err0 == FALSE || err1 == FALSE /*|| err2 == FALSE*/) {
164 if (stateload == FALSE) {
165 filename_init_state(TRUE);
166 }
167 filename_init_snap(TRUE);
168 filename_init_wav(TRUE);
169 }
170 }
171
172
173 if (verbose_proc) {
174 int i;
175 for (i=0; i<2; i++) {
176 if (disk_image_exist(i)) {
177 printf("DRIVE %d: <= %s [%d]\n", i+1,
178 file_disk[i], disk_image_selected(i)+1);
179 } else {
180 printf("DRIVE %d: <= (empty)\n", i+1);
181 }
182 }
183 }
184 }
185
imagefile_all_close(void)186 static void imagefile_all_close(void)
187 {
188 disk_eject(0); memset(file_disk[0], 0, QUASI88_MAX_FILENAME);
189 disk_eject(1); memset(file_disk[1], 0, QUASI88_MAX_FILENAME);
190
191 sio_close_tapeload(); memset(file_tape[CLOAD], 0, QUASI88_MAX_FILENAME);
192 sio_close_tapesave(); memset(file_tape[CSAVE], 0, QUASI88_MAX_FILENAME);
193 sio_close_serialin(); memset(file_sin, 0, QUASI88_MAX_FILENAME);
194 sio_close_serialout(); memset(file_sout, 0, QUASI88_MAX_FILENAME);
195 printer_close(); memset(file_prn, 0, QUASI88_MAX_FILENAME);
196
197 #if 0 /* �Ĥ�����ϡ��ե�����̾Ʊ���Ϲ�θ���� �� ��? */
198 if (filename_synchronize) {
199 filename_init_state(TRUE);
200 filename_init_snap(TRUE);
201 filename_init_wav(TRUE);
202 }
203 #endif
204 }
205
206
207
208
209 /***********************************************************************
210 *
211 *
212 ************************************************************************/
filename_get_disk(int drv)213 const char *filename_get_disk(int drv)
214 {
215 if (file_disk[drv][0] != '\0') return file_disk[drv];
216 else return NULL;
217 }
filename_get_tape(int mode)218 const char *filename_get_tape(int mode)
219 {
220 if (file_tape[mode][0] != '\0') return file_tape[mode];
221 else return NULL;
222 }
filename_get_prn(void)223 const char *filename_get_prn(void)
224 {
225 if (file_prn[0] != '\0') return file_prn;
226 else return NULL;
227 }
filename_get_sin(void)228 const char *filename_get_sin(void)
229 {
230 if (file_sin[0] != '\0') return file_sin;
231 else return NULL;
232 }
filename_get_sout(void)233 const char *filename_get_sout(void)
234 {
235 if (file_sout[0] != '\0') return file_sout;
236 else return NULL;
237 }
238
239 /* ����ɥ饤�֤ʤ���ȿ�Хɥ饤�֤˥ǥ�����������С����Υե�����̾��
240 �ʤ���С��ǥ������ѥǥ��쥯�ȥ���֤� */
filename_get_disk_or_dir(int drv)241 const char *filename_get_disk_or_dir(int drv)
242 {
243 const char *p;
244
245 if (file_disk[drv ][0] != '\0') p = file_disk[drv ];
246 else if (file_disk[drv^1][0] != '\0') p = file_disk[drv^1];
247 else {
248 p = osd_dir_disk();
249 if (p == NULL) p = osd_dir_cwd();
250 }
251
252 return p;
253 }
254 /* ���ꤵ�줿��ʬ�Υơ��פ����åȤ���Ƥ���С����Υե�����̾��
255 �ʤ���С��ơ����ѥǥ��쥯�ȥ���֤� */
filename_get_tape_or_dir(int mode)256 const char *filename_get_tape_or_dir(int mode)
257 {
258 const char *p;
259
260 if (file_tape[ mode ][0] != '\0') p = file_tape[ mode ];
261 else {
262 p = osd_dir_tape();
263 if (p == NULL) p = osd_dir_cwd();
264 }
265
266 return p;
267 }
268
filename_get_disk_name(int drv)269 const char *filename_get_disk_name(int drv)
270 {
271 char dir[ OSD_MAX_FILENAME ];
272 static char file[ OSD_MAX_FILENAME ];
273
274 if (file_disk[drv][0]) {
275 if (osd_path_split(file_disk[drv], dir, file, OSD_MAX_FILENAME)) {
276 return file;
277 }
278 }
279 return NULL;
280 }
filename_get_tape_name(int mode)281 const char *filename_get_tape_name(int mode)
282 {
283 char dir[ OSD_MAX_FILENAME ];
284 static char file[ OSD_MAX_FILENAME ];
285
286 if (file_tape[mode][0]) {
287 if (osd_path_split(file_tape[mode], dir, file, OSD_MAX_FILENAME)) {
288 return file;
289 }
290 }
291 return NULL;
292 }
293
294
295
296
297
298
299
300
301
302
303
304
305
306 /***********************************************************************
307 * ���ơ��ȥե����롢���ʥåץ���åȥե�����Υե�����̾�ˡ�
308 * ���ʸ����åȤ��롣
309 *
310 * ���� set_default
311 * ���ʤ顢����ͤåȤ��롣
312 * ���ʤ顢������ե�����̾�˱������ͤåȤ��롣
313 ************************************************************************/
314
filename_init_state(int synchronize)315 void filename_init_state(int synchronize)
316 {
317 char *s, *buf;
318 const char *dir;
319
320 dir = osd_dir_state();
321 if (dir == NULL) dir = osd_dir_cwd();
322
323 memset(file_state, 0, QUASI88_MAX_FILENAME);
324
325 if (synchronize) {
326 if (file_disk[0][0] != '\0') s = file_disk[0];
327 else if (file_disk[1][0] != '\0') s = file_disk[1];
328 /* else if (file_tape[CLOAD][0] != '\0') s = file_tape[CLOAD];*/
329 /* else if (file_tape[CSAVE][0] != '\0') s = file_tape[CSAVE];*/
330 else s = STATE_FILENAME;
331 } else {
332 s = STATE_FILENAME;
333 }
334
335 buf = assemble_filename(s, dir, STATE_SUFFIX);
336
337 if (buf) {
338 if (strlen(buf) < QUASI88_MAX_FILENAME) {
339 strcpy(file_state, buf);
340 return;
341 }
342 }
343
344 /* ����ǥ��顼�ˤʤä��顢Ŭ�����ͤå� */
345 strcpy(file_state, STATE_FILENAME STATE_SUFFIX);
346 }
347
348
349
filename_init_snap(int synchronize)350 void filename_init_snap(int synchronize)
351 {
352 char *s, *buf;
353 const char *dir;
354
355 dir = osd_dir_snap();
356 if (dir == NULL) dir = osd_dir_cwd();
357
358 memset(file_snap, 0, QUASI88_MAX_FILENAME);
359
360 if (synchronize) {
361 if (file_disk[0][0] != '\0') s = file_disk[0];
362 else if (file_disk[1][0] != '\0') s = file_disk[1];
363 /* else if (file_tape[CLOAD][0] != '\0') s = file_tape[CLOAD];*/
364 /* else if (file_tape[CSAVE][0] != '\0') s = file_tape[CSAVE];*/
365 else s = SNAPSHOT_FILENAME;
366 } else {
367 s = SNAPSHOT_FILENAME;
368 }
369
370 buf = assemble_filename(s, dir, "");
371
372 if (buf) {
373 if (strlen(buf) < QUASI88_MAX_FILENAME) {
374 strcpy(file_snap, buf);
375 return;
376 }
377 }
378
379 /* ����ǥ��顼�ˤʤä��顢Ŭ�����ͤå� */
380 strcpy(file_snap, SNAPSHOT_FILENAME);
381 }
382
383
384
filename_init_wav(int synchronize)385 void filename_init_wav(int synchronize)
386 {
387 char *s, *buf;
388 const char *dir;
389
390 dir = osd_dir_snap();
391 if (dir == NULL) dir = osd_dir_cwd();
392
393 memset(file_wav, 0, QUASI88_MAX_FILENAME);
394
395 if (synchronize) {
396 if (file_disk[0][0] != '\0') s = file_disk[0];
397 else if (file_disk[1][0] != '\0') s = file_disk[1];
398 /* else if (file_tape[CLOAD][0] != '\0') s = file_tape[CLOAD];*/
399 /* else if (file_tape[CSAVE][0] != '\0') s = file_tape[CSAVE];*/
400 else s = WAVEOUT_FILENAME;
401 } else {
402 s = WAVEOUT_FILENAME;
403 }
404
405 buf = assemble_filename(s, dir, "");
406
407 if (buf) {
408 if (strlen(buf) < QUASI88_MAX_FILENAME) {
409 strcpy(file_wav, buf);
410 return;
411 }
412 }
413
414 /* ����ǥ��顼�ˤʤä��顢Ŭ�����ͤå� */
415 strcpy(file_wav, WAVEOUT_FILENAME);
416 }
417
418
419
420
421 /***********************************************************************
422 * �Ƽ�ե�����Υե�ѥ������
423 * �����ν����ʵ������¸�ܰ�¸�ˤ���ӡ�
424 * �Ƽ�����ν��� (�����¸��) ����ƤӽФ���롦�����ϥ�
425 *
426 * ����� �ǥ����������̾�Ρ��ե�ѥ������
427 * ����� ROM�����̾�Ρ� �ե�ѥ������
428 * ����� ��������ե�����̾�Ρ��ե�ѥ������
429 * ����� ��������ե�����̾�Ρ��ե�ѥ������
430 *
431 * �������ϡ� char * (malloc���줿�ΰ�)�����Ի��� NULL
432 ************************************************************************/
433
434 /*
435 * ���륤����Υե�����̾ imagename �Υǥ��쥯�ȥ����ȳ�ĥ������
436 * ���������١���̾����Ф���
437 * basedir �� �١���̾ �� suffix ���礷���ե�����̾���֤���
438 *
439 * ��)
440 * imagename �� /my/disk/dir/GAMEDISK.d88
441 * ^^^^^^^^ ������Ф��ơ�
442 * basedir �� /new/dir �����
443 * suffix �� .dat ����äĤ���
444 * �֤��� �� /new/dir/GAMEDISK.dat ������֤�
445 *
446 * �����֤äƤ����ΰ�ϡ���Ū���ΰ�ʤΤ���� !
447 */
assemble_filename(const char * imagename,const char * basedir,const char * suffix)448 static char *assemble_filename(const char *imagename,
449 const char *basedir,
450 const char *suffix)
451 {
452 static char buf[ OSD_MAX_FILENAME ];
453 char file[ OSD_MAX_FILENAME ];
454
455 if (osd_path_split(imagename, buf, file, OSD_MAX_FILENAME)) {
456
457 size_t len = strlen(file);
458
459 if (len >= 4) {
460 if (strcmp(&file[ len-4 ], ".d88") == 0 ||
461 strcmp(&file[ len-4 ], ".D88") == 0 ||
462 strcmp(&file[ len-4 ], ".t88") == 0 ||
463 strcmp(&file[ len-4 ], ".T88") == 0 ||
464 strcmp(&file[ len-4 ], ".cmt") == 0 ||
465 strcmp(&file[ len-4 ], ".CMT") == 0) {
466
467 file[ len-4 ] = '\0';
468 }
469 }
470
471 if (strlen(file) + strlen(suffix) + 1 < OSD_MAX_FILENAME) {
472
473 strcat(file, suffix);
474
475 if (osd_path_join(basedir, file, buf, OSD_MAX_FILENAME)) {
476 return buf;
477 }
478 }
479 }
480
481 return NULL;
482 }
483
484 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
485 /*
486 * �ǥ�����������ե�����Υե�����̾���������
487 * ���� filename ��Ϳ����줿�ǥ�����������ե�����̾��
488 * �䴰���ơ��ǽ�Ū�ʥե�����̾�֤������Υե�����̾�� malloc ���줿
489 * �ΰ�ʤΤǡ�ɬ�פ˱����ƸƤӽФ����� free ���뤳�ȡ�
490 */
filename_alloc_diskname(const char * filename)491 char *filename_alloc_diskname(const char *filename)
492 {
493 char *p;
494 char dir [ OSD_MAX_FILENAME ];
495 char file[ OSD_MAX_FILENAME ];
496 const char *base;
497 OSD_FILE *fp;
498 int step;
499
500 /* filename �� dir �� file ��ʬ���� */
501
502 if (osd_path_split(filename, dir, file, OSD_MAX_FILENAME)) {
503
504 if (dir[0] == '\0') {
505 /* dir �������Ĥޤ� filename �˥ѥ��ζ��ڤ꤬�ޤޤ�ʤ� */
506
507 step = 0; /* dir_disk + filename �� �ե�����̵ͭ��Ƚ�� */
508
509 } else {
510 /* filename �˥ѥ����ڤ꤬�ޤޤ�� */
511
512 step = 1; /* dir_cwd + filename �� �ե�����̵ͭ������å� */
513 /* (filename�����Хѥ��ʤ顢 filename */
514 /* ���Τ�Τǥե�����̵ͭ�����å��Ȥʤ�) */
515 }
516
517 } else {
518 return NULL;
519 }
520
521
522 /* step 0 �� step 1 �ν�ˡ��ե�����̵ͭ�����å� */
523
524 for ( ; step < 2; step ++) {
525
526 if (step == 0) base = osd_dir_disk();
527 else base = osd_dir_cwd();
528
529 if (base == NULL) continue;
530
531 if (osd_path_join(base, filename, file, OSD_MAX_FILENAME) == FALSE) {
532 return NULL;
533 }
534
535 /* �ºݤ� open �Ǥ��뤫������å����� */
536 fp = osd_fopen(FTYPE_DISK, file, "rb");
537 if (fp) {
538 osd_fclose(fp);
539
540 p = (char *)malloc(strlen(file) + 1);
541 if (p) {
542 strcpy(p, file);
543 return p;
544 }
545 break;
546 }
547 }
548
549 return NULL;
550 }
551
552
553
554
555
filename_alloc_romname(const char * filename)556 char *filename_alloc_romname(const char *filename)
557 {
558 char *p;
559 char buf[ OSD_MAX_FILENAME ];
560 OSD_FILE *fp;
561 int step;
562 const char *dir = osd_dir_rom();
563
564 /* step 0 �� filename�����뤫�����å� */
565 /* step 1 �� dir_rom �ˡ� filename �����뤫�����å� */
566
567 for( step=0; step<2; step++ ){
568
569 if( step==0 ){
570
571 if( OSD_MAX_FILENAME <= strlen(filename) ) return NULL;
572 strcpy( buf, filename );
573
574 }else{
575
576 if( dir == NULL ||
577 osd_path_join( dir, filename, buf, OSD_MAX_FILENAME ) == FALSE ){
578
579 return NULL;
580 }
581 }
582
583 /* �ºݤ� open �Ǥ��뤫������å����� */
584 fp = osd_fopen( FTYPE_ROM, buf, "rb" );
585 if( fp ){
586 osd_fclose( fp );
587
588 p = (char *)malloc( strlen(buf) + 1 );
589 if( p ){
590 strcpy( p, buf );
591 return p;
592 }
593 break;
594 }
595 }
596 return NULL;
597 }
598
599
600
601
602
filename_alloc_global_cfgname(void)603 char *filename_alloc_global_cfgname(void)
604 {
605 const char *dir = osd_dir_gcfg();
606 const char *file = CONFIG_FILENAME CONFIG_SUFFIX;
607 char *p;
608 char buf[ OSD_MAX_FILENAME ];
609
610 if (dir == NULL ||
611 osd_path_join(dir, file, buf, OSD_MAX_FILENAME) == FALSE) {
612
613 return NULL;
614 }
615
616 p = (char *)malloc(strlen(buf) + 1);
617 if (p) {
618 strcpy(p, buf);
619 }
620 return p;
621 }
622
filename_alloc_local_cfgname(const char * imagename)623 char *filename_alloc_local_cfgname(const char *imagename)
624 {
625 char *p = NULL;
626 char *buf;
627 const char *dir = osd_dir_lcfg();
628
629 if (dir == NULL) return NULL;
630
631 buf = assemble_filename(imagename, dir, CONFIG_SUFFIX);
632
633 if (buf) {
634 p = (char *)malloc(strlen(buf) + 1);
635 if (p) {
636 strcpy(p, buf);
637 }
638 }
639 return p;
640 }
641
642
643
644
filename_alloc_keyboard_cfgname(void)645 char *filename_alloc_keyboard_cfgname(void)
646 {
647 const char *dir = osd_dir_gcfg();
648 const char *file = KEYCONF_FILENAME CONFIG_SUFFIX;
649 char *p;
650 char buf[ OSD_MAX_FILENAME ];
651
652
653 if( dir == NULL ||
654 osd_path_join( dir, file, buf, OSD_MAX_FILENAME ) == FALSE )
655
656 return NULL;
657
658 p = (char *)malloc( strlen(buf) + 1 );
659 if( p ){
660 strcpy( p, buf );
661 return p;
662 }
663
664 return NULL;
665 }
666