1 /************************************************************************/
2 /* */
3 /* ������� & ROM�ե�������� */
4 /* */
5 /************************************************************************/
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "quasi88.h"
12 #include "initval.h"
13 #include "memory.h"
14 #include "pc88main.h"
15
16 #include "soundbd.h" /* sound_board, sound2_adpcm */
17
18 #include "menu.h" /* menu_lang */
19 #include "file-op.h"
20 #include "suspend.h"
21
22
23
24 int set_version; /* ��ư���ΥС���������ѹ� '0' �� '9' */
25 int rom_version; /* (�ѹ�����) BASIC ROM�С������ */
26
27 int use_extram = DEFAULT_EXTRAM; /* ��ĥRAM�Υ����ɿ� */
28 int use_jisho_rom = DEFAULT_JISHO; /* ����ROM��Ȥ� */
29 int use_built_in_font = FALSE; /* ��¢�ե���Ȥ�Ȥ� */
30 int use_pcg = FALSE; /* PCG-8100���ݡ��� */
31 int font_type = 0; /* �ե���Ȥμ��� */
32 int font_loaded = 0; /* ���ɤ����ե���ȼ� */
33
34 int memory_wait = FALSE; /* ���ꥦ�����Ȥ�̵ͭ */
35
36 char *file_compatrom = NULL; /* P88SR emu ��ROM��Ȥ�*/
37
38 int has_kanji_rom = FALSE; /* ����ROM��̵ͭ */
39
40 int linear_ext_ram = TRUE; /* ��ĥRAM��Ϣ³������ */
41
42
43 /*----------------------------------------------------------------------*/
44 /* ��¢�ե���ȥǡ��� */
45 /*----------------------------------------------------------------------*/
46 #include "font.h"
47
48
49 /*----------------------------------------------------------------------*/
50 /* �������ߡ�ROM (����ROM��̵�����Υ��ߡ�) */
51 /*----------------------------------------------------------------------*/
52 byte kanji_dummy_rom[16][2] =
53 {
54 { 0xaa, 0xaa, }, /* o o o o o o o o */
55 { 0x00, 0x00, }, /* */
56 { 0x80, 0x02, }, /* o o */
57 { 0x00, 0x00, }, /* */
58 { 0x80, 0x02, }, /* o o */
59 { 0x00, 0x00, }, /* */
60 { 0x80, 0x02, }, /* o o */
61 { 0x00, 0x00, }, /* */
62 { 0x80, 0x02, }, /* o o */
63 { 0x00, 0x00, }, /* */
64 { 0x80, 0x02, }, /* o o */
65 { 0x00, 0x00, }, /* */
66 { 0x80, 0x02, }, /* o o */
67 { 0x00, 0x00, }, /* */
68 { 0xaa, 0xaa, }, /* o o o o o o o o */
69 { 0x00, 0x00, }, /* */
70 };
71
72
73 /*----------------------------------------------------------------------*/
74 /* ROM�ե�����̾ */
75 /*----------------------------------------------------------------------*/
76 enum {
77 N88_ROM, EXT0_ROM, EXT1_ROM, EXT2_ROM, EXT3_ROM, N_ROM, SUB_ROM,
78 KNJ1_ROM, KNJ2_ROM, JISHO_ROM, FONT_ROM, FONT2_ROM, FONT3_ROM, ROM_END
79 };
80 static char *rom_list[ ROM_END ][5] =
81 {
82 { "N88.ROM", "n88.rom", 0, 0, 0, },
83 { "N88EXT0.ROM", "n88ext0.rom", "N88_0.ROM", "n88_0.rom", 0, },
84 { "N88EXT1.ROM", "n88ext1.rom", "N88_1.ROM", "n88_1.rom", 0, },
85 { "N88EXT2.ROM", "n88ext2.rom", "N88_2.ROM", "n88_2.rom", 0, },
86 { "N88EXT3.ROM", "n88ext3.rom", "N88_3.ROM", "n88_3.rom", 0, },
87 { "N88N.ROM", "n88n.rom", "N80.ROM", "n80.rom", 0, },
88 { "N88SUB.ROM", "n88sub.rom", "DISK.ROM", "disk.rom", 0, },
89 { "N88KNJ1.ROM", "n88knj1.rom", "KANJI1.ROM", "kanji1.rom", 0, },
90 { "N88KNJ2.ROM", "n88knj2.rom", "KANJI2.ROM", "kanji2.rom", 0, },
91 { "N88JISHO.ROM", "n88jisho.rom", "JISYO.ROM", "jisyo.rom", 0, },
92 { "FONT.ROM", "font.rom", 0, 0, 0, },
93 { "FONT2.ROM", "font2.rom", 0, 0, 0, },
94 { "FONT3.ROM", "font3.rom", 0, 0, 0, },
95 };
96
97
98
99 byte *main_rom; /* �ᥤ�� ROM [0x8000] (32KB) */
100 byte (*main_rom_ext)[0x2000]; /* ��ĥ ROM [4][0x2000](8KB *4) */
101 byte *main_rom_n; /* N-BASIC [0x8000] (32KB) */
102 byte *main_ram; /* �ᥤ�� RAM [0x10000](64KB) */
103 byte *main_high_ram; /* ��® RAM(��)[0x1000] (4KB) */
104 byte (*kanji_rom)[65536][2]; /* �����ңϣ�[2][65536][2] */
105 byte *sub_romram; /* ���� ROM/RAM [0x8000] (32KB) */
106
107 byte (*ext_ram)[0x8000]; /* ��ĥ RAM[4][0x8000](32KB*4��)*/
108 byte (*jisho_rom)[0x4000]; /* ���� ROM[32][0x4000](16KB*32)*/
109
110 bit8 (*main_vram)[4]; /* VRAM[0x4000][4](=G/R/G/pad) */
111 bit8 *font_rom; /* �ե���ȥ����ROM[8*256*2] */
112
113 bit8 *font_pcg; /* �ե���ȥ����ROM(PCG��) */
114 bit8 *font_mem; /* �ե���ȥ����ROM(���� ) */
115 bit8 *font_mem2; /* �ե���ȥ����ROM(����2) */
116 bit8 *font_mem3; /* �ե���ȥ����ROM(����3) */
117
118 byte *dummy_rom; /* ���ߡ�ROM (32KB) */
119 byte *dummy_ram; /* ���ߡ�RAM (32KB) */
120
121
122
123
124
125 /*----------------------------------------------------------------------
126 * ���ꥢ������
127 *----------------------------------------------------------------------*/
128 static int mem_alloc_result;
129
mem_alloc_start(const char * msg)130 static void mem_alloc_start( const char *msg ) /* ������ݳ��� */
131 {
132 if( verbose_proc ){ printf( "%s", msg ); }
133
134 mem_alloc_result = TRUE;
135 }
136
mem_alloc(size_t size)137 static void *mem_alloc( size_t size ) /* ������� */
138 {
139 void *ptr = malloc( size );
140
141 if( ptr == NULL ){
142 mem_alloc_result = FALSE;
143 }
144 return ptr;
145 }
146
mem_alloc_finish(void)147 static int mem_alloc_finish( void ) /* ������ݴ�λ(���Ǽ���) */
148 {
149 if( verbose_proc ){
150 if( mem_alloc_result == FALSE ){ printf( "FAILED\n" ); }
151 else { printf( "OK\n" ); }
152 }
153
154 return mem_alloc_result;
155 }
156
157
158
159 /*----------------------------------------------------------------------
160 * ROM ������ե���������˥���
161 *----------------------------------------------------------------------*/
162
163 /*
164 * �̾��ROM���������
165 * int load_rom( char *filelist[], byte *ptr, int size, int disp_flag )
166 * filelist �� �����ץ�ե�����̾�����Υꥹ��
167 * ptr �� ���Υݥ�����˥��ɤ���
168 * size �� ���ɤ��륵����
169 * disp_flag�� verbose_proc ����ɽ�������å���������
170 * DISP_FNAME �������ե�����̾����ɽ��
171 * "filename ..."
172 * ����ͤ�ߤ�"OK\n"�����ղä���
173 * �ե����뤬�����ʤ��ä��顢
174 * "filename not found"
175 * ɬ�פ˱����� "\n" ���ղä���
176 *
177 * DISP_RESULT �������ե�����̾�ȷ�̤�ɽ��
178 * "filename ... OK\n"
179 * �ե����뤬�����ʤ��ä��顢
180 * "filename not found\n"
181 *
182 * DISP_IF_EXIST �������ե�����̾�ȷ�̤�ɽ��
183 * "filename ..."
184 * ����ͤ�ߤ�"OK\n"�����ղä���
185 * �ե����뤬�����ʤ��ä��顢
186 * �ʤˤ�ɽ�����ʤ���
187 *
188 * ���� �� �ɤ߹�������������ե����뤬�����ʤ��ä��� -1
189 */
190 #define DISP_FNAME (0)
191 #define DISP_RESULT (1)
192 #define DISP_IF_EXIST (2)
193
load_rom(char * filelist[],byte * ptr,int size,int disp)194 static int load_rom( char *filelist[], byte *ptr, int size, int disp )
195 {
196 OSD_FILE *fp;
197 int i=0, load_size = -1;
198 char buf[ OSD_MAX_FILENAME ];
199 const char *dir = osd_dir_rom();
200
201 if( dir ){
202 for( i=0; filelist[i] ; i++ ){
203
204 if( osd_path_join( dir, filelist[i], buf, OSD_MAX_FILENAME )==FALSE )
205 break;
206
207 if( (fp = osd_fopen( FTYPE_ROM, buf, "rb" )) ){
208
209 load_size = osd_fread( ptr, sizeof(byte), size, fp );
210 osd_fclose( fp );
211
212 break;
213 }
214
215 }
216 }
217
218 if( load_size < 0 ){ /* �ե����븫�Ĥ��餺 */
219 memset( ptr, 0xff, size );
220 }else if( load_size < size ){ /* ���Ĥ��ä����ɡ�����������ʤ� */
221 memset( &ptr[load_size], 0xff, size-load_size );
222 }
223
224
225 if( verbose_proc ){
226 if( load_size < 0 ){
227 if( disp == DISP_FNAME ) printf( " %-12s ... ", filelist[0]);
228 if( disp == DISP_RESULT ) printf( " %-12s ... Not Found\n",filelist[0]);
229 }else{
230 printf( " Found %-12s : Load...", filelist[i] );
231 if( disp == DISP_RESULT ){
232 if( load_size == size ){ printf( "OK\n" ); }
233 else { printf( "FAILED\n" ); }
234 }
235 }
236 }
237
238 return load_size;
239 }
240
241
242
243 /*
244 * ��������ROM���������
245 * OSD_FILE *load_compat_rom_open( void )
246 * void load_compat_rom_close( OSD_FILE *fp )
247 * �ե������ / �Ĥ���
248 * int load_compat_rom( byte *ptr, long pos, int size, OSD_FILE *fp )
249 * �ե�����fp ����Ƭ pos�Х����ܤ��� size�Х��Ȥ� ptr�˥��ɡ�
250 * ���ͤϥ��ɤ��������������������Ԥʤ� -1��
251 * �����1�٤Ǥ�����˼��Ԥ����顢 load_compat_rom_success==FALSE �ˤʤ�
252 */
253 static int load_compat_rom_success;
254
load_compat_rom_open(void)255 static OSD_FILE *load_compat_rom_open( void )
256 {
257 OSD_FILE *fp = osd_fopen( FTYPE_ROM, file_compatrom, "rb" );
258
259 if( verbose_proc ){
260 if( fp ){ printf( " Found %-12s : Load...", file_compatrom ); }
261 else { printf( " %-12s ... Not Found\n", file_compatrom ); }
262 }
263
264 if( fp==NULL ) load_compat_rom_success = FALSE;
265 else load_compat_rom_success = TRUE;
266
267 return fp;
268 }
269
load_compat_rom(byte * ptr,long pos,int size,OSD_FILE * fp)270 static int load_compat_rom( byte *ptr, long pos, int size, OSD_FILE *fp )
271 {
272 int load_size = -1;
273
274 if( fp ){
275 if( osd_fseek( fp, pos, SEEK_SET ) == 0 ){
276
277 load_size = osd_fread( ptr, 1, size, fp );
278
279 if( load_size < size ){
280 memset( &ptr[load_size], 0xff, size-load_size );
281 }
282 }
283
284 if( load_size != size ) load_compat_rom_success = FALSE;
285 }
286
287 return load_size;
288 }
289
load_compat_rom_close(OSD_FILE * fp)290 static void load_compat_rom_close( OSD_FILE *fp )
291 {
292 if( fp ) osd_fclose( fp );
293 }
294
295
296
297
298
299
300
301
302
303
304 /****************************************************************************
305 * ���ߥ�졼�����˻��Ѥ������γ��ݤȡ�ROM������Υ���
306 *
307 * peach����ˤ�ꡢM88 �� ROM�ե������Ȥ���褦�˳�ĥ����ޤ���
308 * �� ���θ�������˥������������ޤ�����
309 *****************************************************************************/
310
311 #define FONT_SZ (8*256*1)
312
memory_allocate(void)313 int memory_allocate( void )
314 {
315 int size;
316
317
318 /* ɸ��������� */
319
320 mem_alloc_start( "Allocating memory for standard ROM/RAM..." );
321 {
322 main_rom = (byte *) mem_alloc( sizeof(byte) * 0x8000 );
323 main_rom_ext = (byte(*)[0x2000]) mem_alloc( sizeof(byte) * 0x2000 *4 );
324 main_rom_n = (byte *) mem_alloc( sizeof(byte) * 0x8000 );
325 sub_romram = (byte *) mem_alloc( sizeof(byte) * 0x8000 );
326
327 main_ram = (byte *) mem_alloc( sizeof(byte) * 0x10000 );
328 main_high_ram= (byte *) mem_alloc( sizeof(byte) * 0x1000 );
329 main_vram = (byte(*)[0x4]) mem_alloc( sizeof(byte) * 0x4000 *4 );
330
331 kanji_rom = (byte(*)[65536][2])mem_alloc( sizeof(byte)*2*65536*2 );
332
333 font_pcg = (byte *) mem_alloc( sizeof(byte)*8*256*2 );
334 font_mem = (byte *) mem_alloc( sizeof(byte)*8*256*2 );
335 font_mem2 = (byte *) mem_alloc( sizeof(byte)*8*256*2 );
336 font_mem3 = (byte *) mem_alloc( sizeof(byte)*8*256*2 );
337 }
338 if( mem_alloc_finish()==FALSE ){
339 return 0;
340 }
341
342
343
344
345 /* ROM�������ե����뤫���ɤ߹��� */
346
347 if( file_compatrom == NULL ){ /* �̾��ROM������ե����� */
348
349 load_rom( rom_list[ N88_ROM ], main_rom, 0x8000, DISP_RESULT );
350 load_rom( rom_list[ EXT0_ROM ], main_rom_ext[0], 0x2000, DISP_RESULT );
351 load_rom( rom_list[ EXT1_ROM ], main_rom_ext[1], 0x2000, DISP_RESULT );
352 load_rom( rom_list[ EXT2_ROM ], main_rom_ext[2], 0x2000, DISP_RESULT );
353 load_rom( rom_list[ EXT3_ROM ], main_rom_ext[3], 0x2000, DISP_RESULT );
354 load_rom( rom_list[ N_ROM ], main_rom_n, 0x8000, DISP_RESULT );
355
356 size = load_rom( rom_list[ SUB_ROM ], sub_romram, 0x2000, DISP_FNAME );
357 {
358 if( verbose_proc ){
359 if ( size < 0 ){ printf( "Not Found\n" ); }
360 else if( size == 0x800 ){ printf( "OK(2D-type)\n" ); }
361 else if( size == 0x2000 ){ printf( "OK(2HD-type)\n" ); }
362 else { printf( "FAILED\n"); }
363 }
364 if( size <= 0x800 ){
365 memcpy( &sub_romram[0x0800], &sub_romram[0x0000], 0x0800 );
366 memcpy( &sub_romram[0x1000], &sub_romram[0x0000], 0x1000 );
367 }
368 }
369
370 }else{ /* ������ROM������ե����� */
371
372 OSD_FILE *fp = load_compat_rom_open();
373 if( fp ){
374 load_compat_rom( main_rom, 0, 0x8000, fp );
375 load_compat_rom( main_rom_ext[0], 0x0c000, 0x2000, fp );
376 load_compat_rom( main_rom_ext[1], 0x0e000, 0x2000, fp );
377 load_compat_rom( main_rom_ext[2], 0x10000, 0x2000, fp );
378 load_compat_rom( main_rom_ext[3], 0x12000, 0x2000, fp );
379 load_compat_rom( &main_rom_n[0x6000], 0x08000, 0x2000, fp );
380 load_compat_rom( sub_romram, 0x14000, 0x2000, fp );
381
382 if( load_compat_rom_success == FALSE ){ /* �������Ǽ��Ԥ�����н�λ */
383 if( verbose_proc ){ printf( "FAILED\n"); }
384 }
385 else{ /* �����ʤ� N-BASIC ���� */
386 size = load_compat_rom( main_rom_n, 0x16000, 0x6000, fp );
387 if( verbose_proc ){
388 if ( size == 0 ){ printf( "OK (Without N-BASIC)\n" ); }
389 else if( size == 0x6000 ){ printf( "OK (With N-BASIC)\n" ); }
390 else { printf( "FAILED\n"); }
391 }
392 }
393
394 load_compat_rom_close( fp );
395 }
396 }
397 /* SUB¦ ROM �ߥ顼������RAM���ꥢ */
398 memcpy( &sub_romram[0x2000], &sub_romram[0x0000], 0x2000 );
399 memset( &sub_romram[0x4000], 0xff, 0x4000 );
400
401
402
403 /* ����ROM�������ե����뤫���ɤ߹��� */
404
405 size=load_rom( rom_list[ KNJ1_ROM ], kanji_rom[0][0], 0x20000, DISP_RESULT );
406
407 if( size == 0x20000 ){
408 has_kanji_rom = TRUE;
409 }else{
410 has_kanji_rom = FALSE;
411 menu_lang = MENU_ENGLISH;
412 }
413
414 load_rom( rom_list[ KNJ2_ROM ], kanji_rom[1][0], 0x20000, DISP_RESULT );
415
416
417
418 /* �ե����ROM�������ե����뤫���ɤ߹��� */
419 /* (���ߥ���ե��å�ʸ������¢ʸ�������) */
420
421 if( use_built_in_font ){
422
423 memcpy( &font_mem[0], &built_in_font_ANK[0], 0x100*8 );
424
425 }else{
426
427 size = load_rom( rom_list[ FONT_ROM ], font_mem, FONT_SZ, DISP_FNAME );
428 font_loaded |= 1;
429
430 if( verbose_proc ){
431 if( size == FONT_SZ ){ printf( "OK\n" ); }
432 else{
433 if( size < 0 ){ printf( "Not Found " ); }
434 else { printf( "FAILED "); }
435 if( has_kanji_rom ){ printf( "(Use KANJI-ROM font)\n" ); }
436 else { printf( "(Use built-in font)\n" ); }
437 }
438 }
439
440 if( size != FONT_SZ ){ /* �۾���ϡ�����ROM����¢�ե���Ȥ���� */
441 if( has_kanji_rom ){
442 memcpy( &font_mem[0], &kanji_rom[0][(1<<11)][0], 0x100*8 );
443 }else{
444 memcpy( &font_mem[0], &built_in_font_ANK[0], 0x100*8 );
445 font_loaded &= ~1;
446 }
447 }
448 }
449
450 memcpy( &font_mem[0x100*8], &built_in_font_graph[0], 0x100*8 );
451
452
453
454 /* ��2�ե���ȥ������ե����뤫���ɤ߹��� */
455
456 if( use_built_in_font ){
457
458 memcpy( &font_mem2[0], &built_in_font_ANH[0], 0x100*8 );
459 memcpy( &font_mem2[0x100*8], &built_in_font_graph[0], 0x100*8 );
460
461 }else{
462
463 size = load_rom( rom_list[FONT2_ROM], font_mem2, FONT_SZ*2, DISP_IF_EXIST);
464 font_loaded |= 2;
465
466 if( verbose_proc ){
467 if ( size == -1 ) ;
468 else if( size == FONT_SZ*2 ){ printf( "OK(with semi-graphic-font)\n" ); }
469 else if( size == FONT_SZ ){ printf( "OK\n" ); }
470 else { printf( "FAILED\n" ); }
471 }
472
473 if( size == FONT_SZ*2 ){
474 ;
475 }else{
476 if( size == FONT_SZ ){
477 ;
478 }else{ /* ¸�ߤ��ʤ����ϡ���¢�ե���Ȥ���� */
479 memcpy( &font_mem2[0], &built_in_font_ANH[0], 0x100*8 );
480 font_loaded &= ~2;
481 }
482 memcpy( &font_mem2[0x100*8], &built_in_font_graph[0], 0x100*8 );
483 }
484
485 }
486
487
488 /* ��3�ե���ȥ������ե����뤫���ɤ߹��� */
489
490 if( use_built_in_font ){
491
492 memset( &font_mem3[0], 0, FONT_SZ*2 );
493
494 }else{
495
496 size = load_rom( rom_list[FONT3_ROM], font_mem3, FONT_SZ*2, DISP_IF_EXIST);
497 font_loaded |= 4;
498
499 if( verbose_proc ){
500 if ( size == -1 ) ;
501 else if( size == FONT_SZ*2 ){ printf( "OK(with semi-graphic-font)\n" ); }
502 else if( size == FONT_SZ ){ printf( "OK\n" ); }
503 else { printf( "FAILED\n" ); }
504 }
505
506 if( size == FONT_SZ*2 ){
507 ;
508 }else{
509 if( size == FONT_SZ ){
510 memcpy( &font_mem3[0x100*8], &built_in_font_graph[0], 0x100*8 );
511
512 }else{ /* ¸�ߤ��ʤ����ϡ�Ʃ���ե���Ȥ���� */
513 memset( &font_mem3[0], 0, FONT_SZ*2 );
514 font_loaded &= ~4;
515 }
516 }
517
518 }
519
520
521 /* �ե���Ȥ�ʸ�������� 0 �����Ф˶��� */
522 memset( &font_mem[0], 0, 8 );
523 memset( &font_mem2[0], 0, 8 );
524 memset( &font_mem3[0], 0, 8 );
525
526
527 memory_reset_font();
528
529
530
531 /* ROM�ΥС���������¸ */
532 rom_version = ROM_VERSION;
533
534 /* ���ץ���ʥ�ʥ������� */
535
536 if( memory_allocate_additional()== FALSE ){
537 return 0;
538 }
539
540
541 return 1;
542 }
543
544
545
546 /****************************************************************************
547 *
548 *
549 *****************************************************************************/
550 static int alloced_extram = 0; /* ���ݤ�����ĥRAM�ο� */
551
memory_allocate_additional(void)552 int memory_allocate_additional( void )
553 {
554
555 /* ��ĥ�������� */
556
557 if( use_extram ){
558
559 if (use_extram <= 4 ||
560 BETWEEN(8, use_extram, 10) ||
561 use_extram == 16) {
562 ;
563 } else {
564 linear_ext_ram = TRUE;
565 }
566
567 /* ���ݺѤߥ���������������С����ݤ��ʤ��� */
568 if( ext_ram && alloced_extram < use_extram ){
569 free( ext_ram );
570 ext_ram = NULL;
571 }
572
573 if( ext_ram == NULL ){
574
575 char msg[80];
576 sprintf( msg, "Allocating memory for Extended RAM(%dKB)...",
577 use_extram * 128 );
578
579 mem_alloc_start( msg );
580
581 ext_ram = (byte(*)[0x8000])mem_alloc( sizeof(byte)*0x8000 *4*use_extram);
582
583 if( dummy_rom == NULL )
584 dummy_rom = (byte *) mem_alloc( sizeof(byte) * 0x8000 );
585 if( dummy_ram == NULL )
586 dummy_ram = (byte *) mem_alloc( sizeof(byte) * 0x8000 );
587
588 if( mem_alloc_finish()==FALSE ){
589 return 0;
590 }
591
592 alloced_extram = use_extram;
593 }
594
595 memset( &ext_ram[0][0], 0xff, 0x8000 * 4*use_extram );
596 memset( &dummy_rom[0], 0xff, 0x8000 );
597 }
598
599
600 /* ����ROM�ѥ������� */
601 /* ����ROM�������ե����뤫���ɤ߹��� */
602
603 if( use_jisho_rom ){
604
605 if( jisho_rom == NULL ){
606
607 mem_alloc_start( "Allocating memory for Jisho ROM..." );
608
609 jisho_rom = (byte(*)[0x4000])mem_alloc( sizeof(byte) * 0x4000*32 );
610
611 if( mem_alloc_finish()==FALSE ){
612 return 0;
613 }
614
615 load_rom( rom_list[ JISHO_ROM ], jisho_rom[0], 0x4000*32, DISP_RESULT );
616
617 }
618 }
619
620
621 /* ������ɥܡ���II ADPCM��RAM����� */
622
623 if( sound_board==SOUND_II ){
624
625 if( sound2_adpcm == NULL ){
626
627 mem_alloc_start( "Allocating memory for ADPCM RAM..." );
628
629 sound2_adpcm = (byte *)mem_alloc( sizeof(byte) * 0x40000 );
630
631 if( mem_alloc_finish()==FALSE ){
632 return 0;
633 }
634
635 }
636
637 memset( &sound2_adpcm[0], 0xff, 0x40000 );
638 }
639
640 return 1;
641 }
642
643
644
645
646
647
648
649 /****************************************************************************
650 * �ե���Ƚ����
651 * PCG�ե���ȥǡ������̾�Υե���Ȥǽ����
652 *****************************************************************************/
memory_reset_font(void)653 void memory_reset_font( void )
654 {
655 memcpy( font_pcg, font_mem, sizeof(byte)*8*256*2 );
656
657 memory_set_font();
658 }
659
660
661
662 /****************************************************************************
663 * ���Ѥ���ե���Ȥ����
664 *
665 *****************************************************************************/
memory_set_font(void)666 void memory_set_font( void )
667 {
668 if( use_pcg ){
669 font_rom = font_pcg;
670 }else{
671 if ( font_type == 0 ) font_rom = font_mem;
672 else if( font_type == 1 ) font_rom = font_mem2;
673 else if( font_type == 2 ) font_rom = font_mem3;
674 }
675 }
676
677
678
679 /****************************************************************************
680 * ���ݤ�������β���
681 * ��λ�����ʤ��������ɬ�פ�ʤ����ɡ�
682 *****************************************************************************/
memory_free(void)683 void memory_free( void )
684 {
685 if( main_rom ) free( main_rom );
686 if( main_rom_ext ) free( main_rom_ext );
687 if( main_rom_n ) free( main_rom_n );
688 if( sub_romram) free( sub_romram );
689
690 if( main_ram) free( main_ram );
691 if( main_high_ram )free( main_high_ram );
692 if( main_vram ) free( main_vram );
693
694 if( kanji_rom ) free( kanji_rom );
695
696 if( font_pcg ) free( font_pcg );
697 if( font_mem ) free( font_mem );
698 if( font_mem2 ) free( font_mem2 );
699 if( font_mem3 ) free( font_mem3 );
700
701 if( use_extram ) free( ext_ram );
702 if( use_jisho_rom ) free( jisho_rom );
703 if( sound_board==SOUND_II ) free( sound2_adpcm );
704 }
705
706
707
708
709
710
711
712 /***********************************************************************
713 * ���ơ��ȥ��ɡ����ơ��ȥ�����
714 ************************************************************************/
715
716 #define SID "MEM "
717 #define SID_MAIN "MEM0"
718 #define SID_HIGH "MEM1"
719 #define SID_SUB "MEM2"
720 #define SID_VRAM "MEM3"
721 #define SID_PCG "MEM4"
722 #define SID_ADPCM "MEMA"
723 #define SID_ERAM "MEMB"
724 #define SID2 "MEM5"
725
726 static T_SUSPEND_W suspend_memory_work[]=
727 {
728 { TYPE_INT, &set_version, },
729 { TYPE_INT, &use_extram, },
730 { TYPE_INT, &use_jisho_rom, },
731
732 { TYPE_INT, &use_pcg, },
733
734 { TYPE_END, 0 },
735 };
736
737 static T_SUSPEND_W suspend_memory_work2[]=
738 {
739 { TYPE_INT, &linear_ext_ram, },
740 { TYPE_END, 0 },
741 };
742
743
statesave_memory(void)744 int statesave_memory( void )
745 {
746 if( statesave_table( SID, suspend_memory_work ) != STATE_OK ) return FALSE;
747
748 if( statesave_table( SID2, suspend_memory_work2 ) != STATE_OK ) return FALSE;
749
750 /* �̾���� */
751
752 if( statesave_block( SID_MAIN, main_ram, 0x10000 ) != STATE_OK )
753 return FALSE;
754 if( statesave_block( SID_HIGH, main_high_ram, 0x1000 ) != STATE_OK )
755 return FALSE;
756 if( statesave_block( SID_SUB, &sub_romram[0x4000], 0x4000 ) != STATE_OK )
757 return FALSE;
758 if( statesave_block( SID_VRAM, main_vram, 4*0x4000 ) != STATE_OK )
759 return FALSE;
760 if( statesave_block( SID_PCG, font_pcg, 8*256*2 ) != STATE_OK )
761 return FALSE;
762
763 /* ���ץ���ʥ�ʥ��� */
764
765 if( sound_board==SOUND_II ){
766 if( statesave_block( SID_ADPCM, sound2_adpcm, 0x40000 ) != STATE_OK )
767 return FALSE;
768 }
769 if( use_extram ){
770 if( statesave_block( SID_ERAM, ext_ram, 0x8000*4*use_extram ) != STATE_OK )
771 return FALSE;
772 }
773 return TRUE;
774 }
775
stateload_memory(void)776 int stateload_memory( void )
777 {
778 if( stateload_table( SID, suspend_memory_work ) != STATE_OK ) return FALSE;
779
780 /* ��0.6.3 �ϥ��ơ��ȥ�������¸���ˡ� ROM�С�������ͤ�С���������ѹ���
781 �Ȥ��� ��¸���Ƥ��롣(�Ĥޤꡢ���ץ���� -server X ������֤ˤʤäƤ���)
782 0.6.4�� �Ǥϡ����Τ褦�ʤ��ȤϹԤ�ʤ���(���� ROM �С����������)
783 �ä˸ߴ����˼³��Ϥʤ��Ȼפ����ġ��ʲ���ä���Ф���˰���? */
784 /* if (set_version == rom_version) set_version = 0; */
785
786
787 if( stateload_table( SID2, suspend_memory_work2 ) != STATE_OK ) {
788
789 /* ��С������ʤ顢�ߤΤ��� */
790
791 printf( "stateload : Statefile is old. (ver 0.6.0, 1, 2 or 3?)\n" );
792
793 linear_ext_ram = TRUE;
794 }
795
796
797 /* �̾���� */
798
799 if( stateload_block( SID_MAIN, main_ram, 0x10000 ) != STATE_OK )
800 return FALSE;
801 if( stateload_block( SID_HIGH, main_high_ram, 0x1000 ) != STATE_OK )
802 return FALSE;
803 if( stateload_block( SID_SUB, &sub_romram[0x4000], 0x4000 ) != STATE_OK )
804 return FALSE;
805 if( stateload_block( SID_VRAM, main_vram, 4*0x4000 ) != STATE_OK )
806 return FALSE;
807 if( stateload_block( SID_PCG, font_pcg, 8*256*2 ) != STATE_OK )
808 return FALSE;
809
810 /* ���ץ���ʥ�ʥ��� */
811
812 if( memory_allocate_additional()== FALSE ){
813 return FALSE;
814 }
815 if( sound_board==SOUND_II ){
816 if( stateload_block( SID_ADPCM, sound2_adpcm, 0x40000 ) != STATE_OK )
817 return FALSE;
818 }
819 if( use_extram ){
820 if( stateload_block( SID_ERAM, ext_ram, 0x8000*4*use_extram ) != STATE_OK )
821 return FALSE;
822 }
823 return TRUE;
824 }
825