1 /************************************************************************/
2 /* */
3 /* PC8801 �ᥤ���ƥ�(����¦) */
4 /* */
5 /************************************************************************/
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11
12 #include "quasi88.h"
13 #include "initval.h"
14 #include "pc88main.h"
15
16 #include "pc88cpu.h"
17 #include "crtcdmac.h"
18 #include "screen.h"
19 #include "intr.h"
20 #include "keyboard.h"
21 #include "memory.h"
22 #include "pio.h"
23 #include "soundbd.h"
24 #include "fdc.h" /* disk_ex_drv */
25
26 #include "event.h"
27 #include "emu.h"
28 #include "drive.h"
29 #include "snddrv.h"
30 #include "suspend.h"
31 #include "status.h"
32
33
34
35 static OSD_FILE *fp_so = NULL; /* ���ꥢ�������fp */
36 static OSD_FILE *fp_si = NULL; /* ������fp */
37 static OSD_FILE *fp_to = NULL; /* �ơ������� fp */
38 static OSD_FILE *fp_ti = NULL; /* ������ fp */
39 static OSD_FILE *fp_prn= NULL; /* �ץ������fp */
40
41
42
43
44 int boot_basic =DEFAULT_BASIC; /* ��ư���� BASIC�⡼�� */
45 int boot_dipsw =DEFAULT_DIPSW; /* ��ư���Υǥ��å����� */
46 int boot_from_rom =DEFAULT_BOOT; /* ��ư�ǥХ��������� */
47 int boot_clock_4mhz=DEFAULT_CLOCK; /* ��ư���� CPU����å� */
48
49 int monitor_15k =0x00; /* 15k ��˥��� 2:Yes 0:No */
50
51 z80arch z80main_cpu; /* Z80 CPU ( main system ) */
52
53 int high_mode; /* ��®�⡼�� 1:Yes 0:No */
54
55
56 static byte dipsw_1; /* IN[30] �ǥ��åץ����å� 1 */
57 static byte dipsw_2; /* IN[31] �ǥ��åץ����å� 2 */
58 static byte ctrl_boot; /* IN[40] �ǥ������֡��Ⱦ��� */
59 static byte cpu_clock; /* IN[6E] CPU ����å� */
60
61 int memory_bank; /* OUT[5C-5F] IN[5C] �����*/
62
63 static byte common_out_data; /* OUT[10] PRT/���� */
64 byte misc_ctrl; /* I/O[32] �Ƽ�Ctrl */
65 byte ALU1_ctrl; /* OUT[34] ALU Ctrl 1 */
66 byte ALU2_ctrl; /* OUT[35] ALU Ctrl 2 */
67 byte ctrl_signal; /* OUT[40] ����ȥ��뿮���������¸*/
68 byte baudrate_sw = DEFAULT_BAUDRATE; /* I/O[6F] �ܡ��졼�� */
69 word window_offset; /* I/O[70] WINDOW ���ե��å� */
70 byte ext_rom_bank; /* I/O[71] ��ĥROM BANK */
71 byte ext_ram_ctrl; /* I/O[E2] ��ĥRAM���� */
72 byte ext_ram_bank; /* I/O[E3] ��ĥRAM���쥯�� */
73
74 static pair kanji1_addr; /* OUT[E8-E9] ����ROM(��1) ADDR */
75 static pair kanji2_addr; /* OUT[EC-ED] ����ROM(��2) ADDR */
76
77 byte jisho_rom_bank; /* OUT[F0] ����ROM���쥯�� */
78 byte jisho_rom_ctrl; /* OUT[F1] ����ROM�� */
79
80
81 int calendar_stop = FALSE; /* ������ߥե饰 */
82 static char calendar_data[7] = /* ��������� (ǯ�����˻�ʬ��)*/
83 { 85, 0, 1, 0, 0, 0, 0, };
84
85
86 int cmt_speed = 0; /* �ơ���®��(BPS)�� 0�ϼ�ư */
87 int cmt_intr = TRUE; /* ���ǡ��ơ����ɹ��˳������ */
88 int cmt_wait = TRUE; /* ���ǡ��ơ����ɹ��������Ȥ��� */
89
90
91 int highspeed_mode = FALSE; /* ���ǡ���® BASIC �������� */
92
93
94 int use_siomouse = FALSE; /* ���ǡ����ꥢ��ޥ������� */
95
96
97 /* �ʲ��ϥơ��ץ�����Υե������¸����ʤΤǡ����ơ��ȥ����֤��ʤ� */
98
99 static int cmt_is_t88; /* ����T88������CMT */
100 static int cmt_block_size; /* �ǡ���������Υ�����(T88) */
101 static long cmt_size; /* ����������� */
102 static int cmt_EOF = FALSE; /* ���ǡ��ơ������� EOF */
103 static int com_EOF = FALSE; /* ���ǡ����ꥢ������ EOF */
104 static long com_size; /* ����������� */
105
106
107 static byte sio_in_data( void ); /* IN[20] RS232C���� (�ǡ���) */
108 static byte sio_in_status( void ); /* IN[21] RS232C���� (����) */
109 static byte in_ctrl_signal( void ); /* IN[40] ����ȥ��뿮������ */
110
111 static void sio_out_data( byte ); /* OUT[20] RS232C���� (�ǡ���) */
112 static void sio_out_command( byte ); /* OUT[21] RS232C���� (���ޥ��)*/
113 static void out_ctrl_signal( byte ); /* OUT[40] ����ȥ��뿮����� */
114
115 static void sio_tape_highspeed_load( void );
116 static void sio_set_intr_base( void );
117 static void sio_check_cmt_error( void );
118
119 #define sio_tape_readable() (fp_ti && !cmt_EOF) /* �ơ����ɹ��ġ� */
120 #define sio_tape_writable() (fp_to) /* �ơ�����ġ� */
121 #define sio_serial_readable() (fp_si && !com_EOF) /* ���ꥢ���ɹ��ġ� */
122 #define sio_serial_writable() (fp_so) /* ���ꥢ�����ġ� */
123
124
125 /************************************************************************/
126 /* ���ꥦ������ */
127 /************************************************************************/
128 /*
129 * �ޤ��������б�����Τ���ˤʤꤽ���Ǥ������Ȥꤢ����
130 *
131 * ��®�⡼�ɤǤ� M1 �������� (�ե��å���� 1���ơ���? )
132 * ��®�⡼�ɤǤ� DMA�Υ������� ( 1�Х���9���ơ���? �� VSYNC��? )
133 * ��®�⡼�ɤǡ���®RAM�Ǥ� M1 �������� (�ե��å���� 1���ơ���? )
134 * ���֥����ƥ�Ǥ� M1 �������� (�ե��å���� 1���ơ���? )
135 *
136 * �������Ŭ��������Ƥߤ뤳�Ȥˤ��ޤ���
137 */
138
139 #define DMA_WAIT (9)
140
141 static int mem_wait_highram = FALSE;
142
143
144 /************************************************************************/
145 /* PCG-8100 */
146 /************************************************************************/
147 static int pcg_data;
148 static int pcg_addr;
149
pcg_out_data(byte data)150 static void pcg_out_data( byte data )
151 {
152 pcg_data = data;
153 }
154
pcg_out_addr_low(byte addr)155 static void pcg_out_addr_low( byte addr )
156 {
157 pcg_addr = (pcg_addr & 0xff00) | addr;
158 }
159
pcg_out_addr_high(byte addr)160 static void pcg_out_addr_high( byte addr )
161 {
162 byte src;
163
164 pcg_addr = (pcg_addr & 0x00ff) | ((int)addr << 8);
165
166 if( addr & 0x10 ){ /* exec */
167
168 if( addr & 0x20 ){ src = font_mem[ 0x400 + (pcg_addr&0x3ff) ]; } /* copy */
169 else { src = pcg_data; } /* store */
170
171 font_pcg[ 0x400 + (pcg_addr&0x3ff) ] = src;
172 }
173 }
174
175
176
177 /************************************************************************/
178 /* ��® BASIC �⡼�� */
179 /************************************************************************/
180 /*
181 * ��® BASIC �����ϡ�peach��ˤ������ޤ�����
182 */
183
184 static word ret_addr = 0xffff;
185 static int hs_icount = 0;
186
187 int highspeed_flag = FALSE; /* ���ߡ���®BASIC ������ */
188 static int highspeed_n88rom = FALSE; /* MAIN-ROM ����������� */
189 /* (���λ�����®BASIC ������ǽ) */
190
191 /* ��® BASIC �⡼�ɤ�����Ȥ��Υ��ɥ쥹 (BIOS��¸����?) */
192 word highspeed_routine[] = {
193 0x6e9a, /* PSET */
194 0x6eae, /* LINE */
195 0x6eca, /* ROLL */
196 0x6ece, /* CIRCLE */
197 0x6eda, /* PAINT */
198 0x7198, /* GET@ */
199 0x71a6, /* PUT@ */
200 EndofBasicAddr
201 };
202
203
204 /************************************************************************/
205 /* ���ꥢ������ */
206 /* special thanks ����줵�� */
207 /* peach ���� */
208 /************************************************************************/
209 /*
210 �ᥤ�����ϥХ��ڤ��ؤ��ˤ�äơ��ʲ��Τ褦�˥ޥåԥ���롣
211
212 0000 +------++------+ +------+ +------+
213 | || | | | | |+
214 | || | | | | ||
215 | || MAIN | |N- | | EXT ||
216 | || ROM | | BASIC| | RAM ||
217 | || | | ROM | | ||
218 6000 + ++ ++------++------++------++------++ + | (x4) ||
219 | || ||Ext.0 ||Ext.1 ||Ext.2 ||Ext.3 || | | ||
220 8000 + MAIN ++------++------++------++------++------++------+ +------+|
221 | RAM ||Window| +------+
222 8400 + ++------+
223 | |
224 | |
225 C000 + + +------++------++------+ +------+
226 | | | || || | | |+
227 | | | VRAM || VRAM || VRAM | | ���� ||
228 F000 + ++------+| B || R || G | | ROM ||
229 | || High || || || | | (x32)||
230 FFFF +------++------++------++------++------+ +------+|
231 +------+
232 �Ĥޤꡢ�礭��ʬ����ȡ��ʲ���6�ĤΥ��ꥢ��ʬ�����롣
233
234 0000H��5FFFH MAIN RAM / MAIN ROM / N-BASIC ROM / ��ĥRAM
235 6000H��7FFFH MAIN RAM / MAIN ROM / ��ĥROM / N-BASIC ROM / ��ĥRAM
236 8000H��83FFH MAIN RAM / ������ɥ�
237 8400H��BFFFH MAIN RAM
238 C000H��EFFFH MAIN RAM / VRAM / ����ROM
239 F000H��FFFFH MAIN RAM / ��®RAM / VRAM / ����ROM
240
241 �Х��ڤ��ؤ���Ԥʤä����ˡ��ơ��Υ��ꥢ���ɤΥХ˳�����Ƥ�줿�Τ�
242 ������å������ºݤΥ��ꥢ�������Ϥ��γ�����ƾ���ˤ��Ԥʤ���
243
244
245 ��)
246 H�⡼�ɤˤ����Ƥϡ� 0xf000 �� 0xffff ���Ϥ�ʲ��Τ褦�˥��ߥ�졼�Ȥ��롣
247
248 ��®RAM�� main_ram[ 0xf000 �� 0xffff ] ��Ȥ�
249 �ᥤ��RAM�� main_high_ram[ 0x0000 �� 0x0fff ] ��Ȥ�
250
251 ����ˤ�ꡢ�ƥ�����ɽ�������Ͼ�� main_ram �Ȥ���Ф褤���Ȥˤʤ롣
252 */
253
254
255 static byte *read_mem_0000_5fff; /* �ᥤ����� ��ɥݥ��� */
256 static byte *read_mem_6000_7fff;
257 static byte *read_mem_8000_83ff;
258 static byte *read_mem_c000_efff;
259 static byte *read_mem_f000_ffff;
260
261 static byte *write_mem_0000_7fff; /* �ᥤ����� �饤�ȥݥ��� */
262 static byte *write_mem_8000_83ff;
263 static byte *write_mem_c000_efff;
264 static byte *write_mem_f000_ffff;
265
266 /*------------------------------------------------------*/
267 /* address : 0x0000 �� 0x7fff �� ���������� */
268 /* ext_ram_ctrl, ext_ram_bank, grph_ctrl, */
269 /* ext_rom_bank, misc_ctrl �ˤ���Ѳ� */
270 /*------------------------------------------------------*/
271 #if 1
main_memory_mapping_0000_7fff(void)272 INLINE void main_memory_mapping_0000_7fff( void )
273 {
274 highspeed_n88rom = FALSE; /* �ǥե���� */
275
276 switch( ext_ram_ctrl ){
277
278 case 0x00: /* ��ĥRAM RW�Բ� */
279 if( grph_ctrl&GRPH_CTRL_64RAM ){ /* 64KB RAM mode */
280 read_mem_0000_5fff = &main_ram[ 0x0000 ];
281 read_mem_6000_7fff = &main_ram[ 0x6000 ];
282 write_mem_0000_7fff = &main_ram[ 0x0000 ];
283 }else{ /* ROM/RAM mode */
284 if( grph_ctrl&GRPH_CTRL_N ){ /* N BASIC */
285 read_mem_0000_5fff = &main_rom_n[ 0x0000 ];
286 read_mem_6000_7fff = &main_rom_n[ 0x6000 ];
287 }else{ /*N88 BASIC*/
288 read_mem_0000_5fff = &main_rom[ 0x0000 ];
289 if( ext_rom_bank&EXT_ROM_NOT ){ /* �̾�ROM */
290 read_mem_6000_7fff = &main_rom[ 0x6000 ];
291 highspeed_n88rom = TRUE;
292 }else{ /* ��ĥROM */
293 read_mem_6000_7fff = &main_rom_ext[ misc_ctrl&MISC_CTRL_EBANK ][0];
294 }
295 }
296 write_mem_0000_7fff = &main_ram[ 0x0000 ];
297 }
298 break;
299
300 case 0x01: /* ��ĥRAM R�� W�Բ� */
301 if( ext_ram_bank < use_extram*4 ){
302 read_mem_0000_5fff = &ext_ram[ ext_ram_bank ][ 0x0000 ];
303 read_mem_6000_7fff = &ext_ram[ ext_ram_bank ][ 0x6000 ];
304 }else{
305 read_mem_0000_5fff = dummy_rom;
306 read_mem_6000_7fff = dummy_rom;
307 }
308 write_mem_0000_7fff = &main_ram[ 0x0000 ];
309 break;
310
311 case 0x10: /* ��ĥRAM R�Բ� W�� */
312 /* buf fix by peach (thanks!) */
313 if( grph_ctrl&GRPH_CTRL_64RAM ){ /* 64KB RAM mode */
314 read_mem_0000_5fff = &main_ram[ 0x0000 ];
315 read_mem_6000_7fff = &main_ram[ 0x6000 ];
316 }else{ /* ROM/RAM mode */
317 if( grph_ctrl&GRPH_CTRL_N ){ /* N BASIC */
318 read_mem_0000_5fff = &main_rom_n[ 0x0000 ];
319 read_mem_6000_7fff = &main_rom_n[ 0x6000 ];
320 }else{ /*N88 BASIC*/
321 read_mem_0000_5fff = &main_rom[ 0x0000 ];
322 if( ext_rom_bank&EXT_ROM_NOT ){ /* �̾�ROM */
323 read_mem_6000_7fff = &main_rom[ 0x6000 ];
324 highspeed_n88rom = TRUE;
325 }else{ /* ��ĥROM */
326 read_mem_6000_7fff = &main_rom_ext[ misc_ctrl&MISC_CTRL_EBANK ][0];
327 }
328 }
329 }
330 if( ext_ram_bank < use_extram*4 ){
331 write_mem_0000_7fff = &ext_ram[ ext_ram_bank ][ 0x0000 ];
332 }else{
333 write_mem_0000_7fff = dummy_ram;
334 }
335 break;
336
337 case 0x11: /* ��ĥRAM RW�� */
338 if( ext_ram_bank < use_extram*4 ){
339 read_mem_0000_5fff = &ext_ram[ ext_ram_bank ][ 0x0000 ];
340 read_mem_6000_7fff = &ext_ram[ ext_ram_bank ][ 0x6000 ];
341 write_mem_0000_7fff = &ext_ram[ ext_ram_bank ][ 0x0000 ];
342 }else{
343 read_mem_0000_5fff = dummy_rom;
344 read_mem_6000_7fff = dummy_rom;
345 write_mem_0000_7fff = dummy_ram;
346 }
347 break;
348 }
349 }
350
351 #else /* ���������ä��ꤵ����ۤ��������� */
352
main_memory_mapping_0000_7fff(void)353 INLINE void main_memory_mapping_0000_7fff( void )
354 {
355 highspeed_n88rom = FALSE; /* �ǥե���� */
356
357 /* ��ɤϡ����ꤷ���Х˱��������꤫�� */
358
359 /* buf fix by peach (thanks!) */
360 if( grph_ctrl&GRPH_CTRL_64RAM ){ /* 64KB RAM mode */
361 read_mem_0000_5fff = &main_ram[ 0x0000 ];
362 read_mem_6000_7fff = &main_ram[ 0x6000 ];
363 }else{ /* ROM/RAM mode */
364 if( grph_ctrl&GRPH_CTRL_N ){ /* N BASIC */
365 read_mem_0000_5fff = &main_rom_n[ 0x0000 ];
366 read_mem_6000_7fff = &main_rom_n[ 0x6000 ];
367 }else{ /*N88 BASIC*/
368 read_mem_0000_5fff = &main_rom[ 0x0000 ];
369 if( ext_rom_bank&EXT_ROM_NOT ){ /* �̾�ROM */
370 read_mem_6000_7fff = &main_rom[ 0x6000 ];
371 highspeed_n88rom = TRUE;
372 }else{ /* ��ĥROM */
373 read_mem_6000_7fff = &main_rom_ext[ misc_ctrl&MISC_CTRL_EBANK ][0];
374 }
375 }
376 }
377
378 /* �饤�Ȥϡ���˥ᥤ��RAM �� */
379
380 write_mem_0000_7fff = &main_ram[ 0x0000 ];
381
382
383
384 /* ��ĥRAM�ؤΥ����������꤬����С���ĥRAM���ɡ��饤�Ȥ��� */
385
386 if( ext_ram_ctrl & 0x01 ){ /* ��ĥRAM R�� */
387 if( ext_ram_bank < use_extram*4 ){
388 read_mem_0000_5fff = &ext_ram[ ext_ram_bank ][ 0x0000 ];
389 read_mem_6000_7fff = &ext_ram[ ext_ram_bank ][ 0x6000 ];
390 }
391 }
392
393 if( ext_ram_ctrl & 0x10 ){ /* ��ĥRAM W�� */
394 if( ext_ram_bank < use_extram*4 ){
395 write_mem_0000_7fff = &ext_ram[ ext_ram_bank ][ 0x0000 ];
396 }
397 }
398 }
399 #endif
400
401
402 /*------------------------------------------------------*/
403 /* address : 0x8000 �� 0x83ff �� ���������� */
404 /* grph_ctrl, window_offset �ˤ���Ѳ� */
405 /*------------------------------------------------------*/
main_memory_mapping_8000_83ff(void)406 INLINE void main_memory_mapping_8000_83ff( void )
407 {
408 if( grph_ctrl & ( GRPH_CTRL_64RAM | GRPH_CTRL_N ) ){
409 read_mem_8000_83ff = &main_ram[ 0x8000 ];
410 write_mem_8000_83ff = &main_ram[ 0x8000 ];
411 }else{
412 if( high_mode ){
413 if( window_offset <= 0xf000 - 0x400 ){
414 read_mem_8000_83ff = &main_ram[ window_offset ];
415 write_mem_8000_83ff = &main_ram[ window_offset ];
416 }else if( 0xf000 <= window_offset && window_offset <= 0x10000 - 0x400 ){
417 read_mem_8000_83ff = &main_high_ram[ window_offset - 0xf000 ];
418 write_mem_8000_83ff = &main_high_ram[ window_offset - 0xf000 ];
419 }else{
420 read_mem_8000_83ff = NULL;
421 write_mem_8000_83ff = NULL;
422 }
423 }else{
424 read_mem_8000_83ff = &main_ram[ window_offset ];
425 write_mem_8000_83ff = &main_ram[ window_offset ];
426 }
427 }
428 }
429
430
431 /*------------------------------------------------------*/
432 /* address : 0xc000 �� 0xffff �� ���������� */
433 /* jisho_rom_ctrl, jisho_rom_bank, */
434 /* misc_ctrl �ˤ���Ѳ� */
435 /*------------------------------------------------------*/
main_memory_mapping_c000_ffff(void)436 INLINE void main_memory_mapping_c000_ffff( void )
437 {
438 mem_wait_highram = FALSE;
439
440 if( jisho_rom_ctrl ){
441 read_mem_c000_efff = &main_ram[ 0xc000 ];
442 if( high_mode && (misc_ctrl&MISC_CTRL_TEXT_MAIN) ){
443 read_mem_f000_ffff = &main_high_ram[ 0x0000 ];
444 mem_wait_highram = TRUE;
445 }else{
446 read_mem_f000_ffff = &main_ram[ 0xf000 ];
447 }
448 }else{
449 read_mem_c000_efff = &jisho_rom[ jisho_rom_bank ][ 0x0000 ];
450 read_mem_f000_ffff = &jisho_rom[ jisho_rom_bank ][ 0x3000 ];
451 }
452
453 write_mem_c000_efff = &main_ram[ 0xc000 ];
454 if( high_mode && (misc_ctrl&MISC_CTRL_TEXT_MAIN) ){
455 write_mem_f000_ffff = &main_high_ram[ 0x0000 ];
456 mem_wait_highram = TRUE;
457 }else{
458 write_mem_f000_ffff = &main_ram[ 0xf000 ];
459 }
460 }
461
462
463 /*------------------------------------------------------*/
464 /* address : 0xc000 �� 0xffff �� �ᥤ��VARM�ڤ��ؤ� */
465 /* misc_ctrl, ALU2_ctrl, */
466 /* memory_bank �ˤ���Ѳ� */
467 /*------------------------------------------------------*/
468 static int vram_access_way; /* vram ������������ˡ */
469 enum VramAccessWay{
470 VRAM_ACCESS_BANK,
471 VRAM_ACCESS_ALU,
472 VRAM_NOT_ACCESS,
473 EndofVramAcc
474 };
475
main_memory_vram_mapping(void)476 INLINE void main_memory_vram_mapping( void )
477 {
478 if( misc_ctrl & MISC_CTRL_EVRAM ){ /* ��ĥ���������⡼�� */
479
480 /* ��ɥ饴��ǻ��� (port 35H �����Ϥ���ʤ������) by peach */
481 memory_bank = MEMORY_BANK_MAIN;
482
483 if( ALU2_ctrl & ALU2_CTRL_VACCESS ){ /* VRAM��ĥ�������� */
484 vram_access_way = VRAM_ACCESS_ALU;
485 }else{ /* MAIN RAM�������� */
486 vram_access_way = VRAM_NOT_ACCESS;
487 }
488 }else{ /* ��Ω���������⡼�� */
489 if( memory_bank == MEMORY_BANK_MAIN ){ /* MAIN RAM�������� */
490 vram_access_way = VRAM_NOT_ACCESS;
491 }else{ /* VRAM�������� */
492 vram_access_way = VRAM_ACCESS_BANK;
493 }
494 }
495 }
496
497
498
499
500 /*------------------------------*/
501 /* �̾�Σ֣ң��ͥ�� */
502 /*------------------------------*/
vram_read(word addr)503 INLINE byte vram_read( word addr )
504 {
505 return main_vram[addr][ memory_bank ];
506 }
507
508 /*------------------------------*/
509 /* �̾�Σ֣ң��ͥ饤�� */
510 /*------------------------------*/
vram_write(word addr,byte data)511 INLINE void vram_write( word addr, byte data )
512 {
513 screen_set_dirty_flag(addr);
514
515 main_vram[addr][ memory_bank ] = data;
516 }
517
518 /*------------------------------*/
519 /* ���̣դ���֣ң��ͥ�� */
520 /*------------------------------*/
521 typedef union {
522 bit8 c[4];
523 bit32 l;
524 } ALU_memory;
525
526 static ALU_memory ALU_buf;
527 static ALU_memory ALU_comp;
528
529 #ifdef LSB_FIRST
530 #define set_ALU_comp() \
531 do{ \
532 ALU_comp.l = 0; \
533 if( (ALU2_ctrl&0x01)==0 ) ALU_comp.l |= 0x000000ff; \
534 if( (ALU2_ctrl&0x02)==0 ) ALU_comp.l |= 0x0000ff00; \
535 if( (ALU2_ctrl&0x04)==0 ) ALU_comp.l |= 0x00ff0000; \
536 }while(0)
537 #else
538 #define set_ALU_comp() \
539 do{ \
540 ALU_comp.l = 0; \
541 if( (ALU2_ctrl&0x01)==0 ) ALU_comp.l |= 0xff000000; \
542 if( (ALU2_ctrl&0x02)==0 ) ALU_comp.l |= 0x00ff0000; \
543 if( (ALU2_ctrl&0x04)==0 ) ALU_comp.l |= 0x0000ff00; \
544 }while(0)
545 #endif
546
ALU_read(word addr)547 INLINE byte ALU_read( word addr )
548 {
549 ALU_memory wk;
550
551 ALU_buf.l = (main_vram4)[addr];
552 wk.l = ALU_comp.l ^ ALU_buf.l;
553
554 return wk.c[0] & wk.c[1] & wk.c[2];
555 }
556
557 /*------------------------------*/
558 /* ���̣դ���֣ң��ͥ饤�� */
559 /*------------------------------*/
ALU_write(word addr,byte data)560 INLINE void ALU_write( word addr, byte data )
561 {
562 int i, mode;
563
564 screen_set_dirty_flag(addr);
565
566 switch( ALU2_ctrl&ALU2_CTRL_MODE ){
567
568 case 0x00:
569 mode = ALU1_ctrl;
570 for( i=0; i<3; i++, mode>>=1 ){
571 switch( mode&0x11 ){
572 case 0x00: main_vram[addr][i] &= ~data; break;
573 case 0x01: main_vram[addr][i] |= data; break;
574 case 0x10: main_vram[addr][i] ^= data; break;
575 default: break;
576 }
577 }
578 break;
579
580 case 0x10:
581 (main_vram4)[addr] = ALU_buf.l;
582 break;
583
584 case 0x20:
585 main_vram[addr][0] = ALU_buf.c[1];
586 break;
587
588 default:
589 main_vram[addr][1] = ALU_buf.c[0];
590 break;
591
592 }
593 }
594
595
596 /*----------------------*/
597 /* �ե��å� */
598 /*----------------------*/
599
main_fetch(word addr)600 byte main_fetch( word addr )
601 {
602
603 /* ���ʤ�Ŭ���ʡ����ꥦ�����Ƚ��� */
604
605 if( memory_wait ){
606
607 if( high_mode == FALSE ){ /* ��®�⡼�ɤξ�� */
608
609 z80main_cpu.state0 += 1; /* M1�������륦������ */
610
611 if( dma_wait_count ){ /* DMA�������Ȥ������ */
612 dma_wait_count --; /* ���������IJû����Ƥ��� */
613 z80main_cpu.state0 += DMA_WAIT;
614 }
615
616 }else{ /* ��®�⡼�ɤξ�� */
617
618 if( addr>=0xf000 && mem_wait_highram ){ /* ��®RAM�Υե��å��� */
619 z80main_cpu.state0 += 1; /* M1�������륦������ */
620 }
621 }
622
623 /* VRAM�����������Ȥ���8MHz���Υ������Ȥ⤢�뤱��̤���� */
624 }
625
626
627 /* ��® BASIC �⡼�� */ /* peach���� */
628
629 if (highspeed_mode){
630 if (!(highspeed_flag) && highspeed_n88rom) {
631 int i;
632 for (i = 0; highspeed_routine[i] != EndofBasicAddr; i++) {
633 if (addr == highspeed_routine[i]) {
634 highspeed_flag = TRUE;
635 ret_addr = main_mem_read(z80main_cpu.SP.W) +
636 (main_mem_read(z80main_cpu.SP.W + 1) << 8);
637 hs_icount= z80_state_intchk;
638
639 z80_state_intchk = HS_BASIC_COUNT*2;
640 /*printf("%x %d -> %d -> ",addr,hs_icount,z80_state_intchk);*/
641 break;
642 }
643 }
644 } else if ((highspeed_flag) &&
645 (ret_addr == addr || z80main_cpu.state0 >= HS_BASIC_COUNT)) {
646 ret_addr = 0xffff;
647 /*printf("'%d'\n",z80_state_intchk);*/
648 z80_state_intchk = hs_icount;
649 if (z80main_cpu.state0 > z80_state_intchk) z80main_cpu.state0 = z80_state_intchk;
650 highspeed_flag = FALSE;
651 }
652 }
653
654 /* ������ */
655
656 if ( addr < 0x6000 ) return read_mem_0000_5fff[ addr ];
657 else if( addr < 0x8000 ) return read_mem_6000_7fff[ addr & 0x1fff ];
658 else if( addr < 0x8400 ){
659 if( read_mem_8000_83ff ) return read_mem_8000_83ff[ addr & 0x03ff ];
660 else{
661 addr = (addr & 0x03ff) + window_offset;
662 if( addr < 0xf000 ) return main_ram[ addr ];
663 else return main_high_ram[ addr & 0x0fff ];
664 }
665 }
666 else if( addr < 0xc000 ) return main_ram[ addr ];
667 else{
668 switch( vram_access_way ){
669 case VRAM_ACCESS_ALU: return ALU_read( addr & 0x3fff );
670 case VRAM_ACCESS_BANK: return vram_read( addr & 0x3fff );
671 default:
672 if( addr < 0xf000 ) return read_mem_c000_efff[ addr & 0x3fff ];
673 else return read_mem_f000_ffff[ addr & 0x0fff ];
674 }
675 }
676 }
677
678 /*----------------------*/
679 /* ���ꡦ��� */
680 /*----------------------*/
main_mem_read(word addr)681 byte main_mem_read( word addr )
682 {
683 if ( addr < 0x6000 ) return read_mem_0000_5fff[ addr ];
684 else if( addr < 0x8000 ) return read_mem_6000_7fff[ addr & 0x1fff ];
685 else if( addr < 0x8400 ){
686 if( read_mem_8000_83ff ) return read_mem_8000_83ff[ addr & 0x03ff ];
687 else{
688 addr = (addr & 0x03ff) + window_offset;
689 if( addr < 0xf000 ) return main_ram[ addr ];
690 else return main_high_ram[ addr & 0x0fff ];
691 }
692 }
693 else if( addr < 0xc000 ) return main_ram[ addr ];
694 else{
695 switch( vram_access_way ){
696 case VRAM_ACCESS_ALU: return ALU_read( addr & 0x3fff );
697 case VRAM_ACCESS_BANK: return vram_read( addr & 0x3fff );
698 default:
699 if( addr < 0xf000 ) return read_mem_c000_efff[ addr & 0x3fff ];
700 else return read_mem_f000_ffff[ addr & 0x0fff ];
701 }
702 }
703 }
704
705 /*----------------------*/
706 /* ���ꡦ�饤�� */
707 /*----------------------*/
main_mem_write(word addr,byte data)708 void main_mem_write( word addr, byte data )
709 {
710 if ( addr < 0x8000 ) write_mem_0000_7fff[ addr ] = data;
711 else if( addr < 0x8400 ){
712 if( write_mem_8000_83ff ) write_mem_8000_83ff[ addr & 0x03ff ] = data;
713 else{
714 addr = (addr & 0x03ff) + window_offset;
715 if( addr < 0xf000 ) main_ram[ addr ] = data;
716 else main_high_ram[ addr & 0x0fff ] = data;
717 }
718 }
719 else if( addr < 0xc000 ) main_ram[ addr ] = data;
720 else{
721 switch( vram_access_way ){
722 case VRAM_ACCESS_ALU: ALU_write( addr & 0x3fff, data ); break;
723 case VRAM_ACCESS_BANK: vram_write( addr & 0x3fff, data ); break;
724 default:
725 if( addr < 0xf000 ) write_mem_c000_efff[ addr & 0x3fff ] = data;
726 else write_mem_f000_ffff[ addr & 0x0fff ] = data;
727 }
728 }
729 }
730
731
732
733
734
735 /************************************************************************/
736 /* �ɡ��ϥݡ��ȥ������� */
737 /************************************************************************/
738
739 /*----------------------*/
740 /* �ݡ��ȡ��饤�� */
741 /*----------------------*/
742
main_io_out(byte port,byte data)743 void main_io_out( byte port, byte data )
744 {
745 byte chg;
746 PC88_PALETTE_T new_pal;
747
748 switch( port ){
749
750 /* ��®�ơ��ץ��� / PCG */
751 case 0x00:
752 /*if( use_pcg )*/
753 pcg_out_data( data );
754
755 if( boot_basic != BASIC_N )
756 sio_tape_highspeed_load();
757 return;
758
759 case 0x01:
760 /*if( use_pcg )*/
761 pcg_out_addr_low( data );
762 return;
763
764 case 0x02:
765 /*if( use_pcg )*/
766 pcg_out_addr_high( data );
767 return;
768
769 case 0x0c:
770 case 0x0d:
771 case 0x0e:
772 case 0x0f:
773 /* PCG �Υ�����ɽ��ϤΥݡ��Ȥ餷�� */
774 return;
775
776
777 /* �ץ���ϡ�����������å� ���ϥǡ��� */
778 case 0x10:
779 common_out_data = data;
780 return;
781
782
783 /* RS-232C��CMT ���ϥǡ��� */
784 case 0x20:
785 sio_out_data( data );
786 return;
787
788 /* RS-232C��CMT ���楳�ޥ�� */
789 case 0x21:
790 sio_out_command( data );
791 return;
792
793
794 /* �����ƥॳ��ȥ������ */
795 case 0x30:
796 if( (sys_ctrl^data) & (SYS_CTRL_80) ){ /* SYS_CTRL_MONO ��̵�� */
797 screen_set_dirty_all(); /* (�ƥ����ȤΥ��顼�� */
798 } /* CRTC����ˤƷ���) */
799
800 if( sio_tape_readable() ){
801 if( (sys_ctrl & 0x08) && !(data & 0x08) ) sio_check_cmt_error();
802 }
803
804 /* �����åȥ⡼������졼�� */
805 if ((~sys_ctrl & data) & 0x08) { xmame_dev_sample_motoron(); }
806 if (( sys_ctrl & ~data) & 0x08) { xmame_dev_sample_motoroff(); }
807
808 sys_ctrl = data;
809 sio_set_intr_base();
810 /*
811 printf("CMT %02x, %s: Motor %s: CDS %d\n",data,
812 ((data&0x3)==0)?" 600":( ((data&0x30)==0x10)?" 1200":"RS232"),
813 ((data&8)==0)?"Off":"On ",(data>>2)&1);
814 */
815 return;
816
817 /* ����ե��å�����ȥ������ */
818 case 0x31:
819 chg = grph_ctrl ^ data;
820
821 /* GRPH_CTRL_25 ��̵�� (�ƥ�����25�Ԥ� CRTC����ˤƷ���) */
822 if( chg & (GRPH_CTRL_200|GRPH_CTRL_VDISP|GRPH_CTRL_COLOR) ){
823 screen_set_dirty_all();
824
825 if( chg & GRPH_CTRL_COLOR ){
826 screen_set_dirty_palette();
827 }
828 }
829
830 /* M88 �ǤϤ����ʤäƤ롩 (peach) */
831 /*if (chg & (GRPH_CTRL_64RAM|GRPH_CTRL_N))*/
832 /*grph_ctrl = data & (GRPH_CTRL_64RAM|GRPH_CTRL_N);*/
833 /*else grph_ctrl = data;*/
834
835 grph_ctrl = data;
836 set_text_display();
837 main_memory_mapping_0000_7fff();
838 main_memory_mapping_8000_83ff();
839 return;
840
841 /* �Ƽ����������� */
842 case 0x32:
843 chg = misc_ctrl ^ data;
844 if( chg & MISC_CTRL_ANALOG ){
845 screen_set_dirty_palette();
846 }
847 if( sound_port & SD_PORT_44_45 ){
848 intr_sound_enable = (data & INTERRUPT_MASK_SOUND) ^ INTERRUPT_MASK_SOUND;
849 if( highspeed_flag == FALSE ) CPU_REFRESH_INTERRUPT();
850 /*if( intr_sound_enable == FALSE ) SOUND_flag = FALSE;*/
851 }
852 misc_ctrl = data;
853 main_memory_mapping_0000_7fff();
854 main_memory_mapping_c000_ffff();
855 main_memory_vram_mapping();
856 return;
857
858
859 /* ��ĥVRAM���� */
860 case 0x34:
861 ALU1_ctrl = data;
862 return;
863 case 0x35:
864 ALU2_ctrl = data;
865 set_ALU_comp();
866
867 /* ����ॾ���ɥ饴��,STAR TRADER�ʤɤǻ��� */
868 if (data & ALU2_CTRL_VACCESS) memory_bank = MEMORY_BANK_MAIN;
869 /* bug fix by peach (thanks!) */
870
871 main_memory_vram_mapping();
872 return;
873
874
875 /* ����ȥ��뿮����� */
876 case 0x40:
877 out_ctrl_signal( data );
878 return;
879
880
881 /* ������ɽ��� */
882 case 0x44:
883 if( sound_port & SD_PORT_44_45 ) sound_out_reg( data );
884 return;
885 case 0x45:
886 if( sound_port & SD_PORT_44_45 ) sound_out_data( data );
887 return;
888 case 0x46:
889 if( sound_port & SD_PORT_46_47 ) sound2_out_reg( data );
890 return;
891 case 0x47:
892 if( sound_port & SD_PORT_46_47 ) sound2_out_data( data );
893 return;
894
895
896 /* CRTC���� */
897 case 0x50:
898 crtc_out_parameter( data );
899 /*printf("CRTC PARM %02x\n",data);*/
900 return;
901 case 0x51:
902 crtc_out_command( data );
903 /*printf("CRTC CMD %02x\n",data);*/
904 return;
905
906 /* �طʿ��ʥǥ������*/
907 case 0x52:
908 if( data&0x1 ) new_pal.blue = 7;
909 else new_pal.blue = 0;
910 if( data&0x2 ) new_pal.red = 7;
911 else new_pal.red = 0;
912 if( data&0x4 ) new_pal.green = 7;
913 else new_pal.green = 0;
914
915 if( new_pal.blue != vram_bg_palette.blue ||
916 new_pal.red != vram_bg_palette.red ||
917 new_pal.green != vram_bg_palette.green ){
918 vram_bg_palette.blue = new_pal.blue;
919 vram_bg_palette.red = new_pal.red;
920 vram_bg_palette.green = new_pal.green;
921 screen_set_dirty_palette();
922 }
923 return;
924
925 /* ���̽Ť�碌 */
926 case 0x53:
927 grph_pile = data;
928 set_text_display();
929 screen_set_dirty_all();
930 return;
931
932 /* �ѥ�å����� */
933 case 0x54:
934 if( (data & 0x80) &&
935 (misc_ctrl & MISC_CTRL_ANALOG) ){ /* ���ʥ��⡼�� */
936 if( (data & 0x40) == 0 ){
937 new_pal.blue = (data ) & 0x07;
938 new_pal.red = (data >> 3) & 0x07;
939 new_pal.green = vram_bg_palette.green;
940 }else{
941 new_pal.blue = vram_bg_palette.blue;
942 new_pal.red = vram_bg_palette.red;
943 new_pal.green = (data ) & 0x07;
944 }
945 if( new_pal.blue != vram_bg_palette.blue ||
946 new_pal.red != vram_bg_palette.red ||
947 new_pal.green != vram_bg_palette.green ){
948 vram_bg_palette.blue = new_pal.blue;
949 vram_bg_palette.red = new_pal.red;
950 vram_bg_palette.green = new_pal.green;
951 screen_set_dirty_palette();
952 }
953 return;
954 } /* else no return; (.. continued) */
955 /* FALLTHROUGH */
956 case 0x55:
957 case 0x56:
958 case 0x57:
959 case 0x58:
960 case 0x59:
961 case 0x5a:
962 case 0x5b:
963 /*printf("PAL %02xH %02x\n",port,data );*/
964 if( ! (misc_ctrl&MISC_CTRL_ANALOG) ){ /* �ǥ�����⡼�� */
965
966 if( data&0x1 ) new_pal.blue = 7;
967 else new_pal.blue = 0;
968 if( data&0x2 ) new_pal.red = 7;
969 else new_pal.red = 0;
970 if( data&0x4 ) new_pal.green = 7;
971 else new_pal.green = 0;
972
973 }else{ /* ���ʥ��⡼�� */
974 if( (data & 0x40) == 0 ){
975 new_pal.blue = (data ) & 0x07;
976 new_pal.red = (data >> 3 ) & 0x07;
977 new_pal.green = vram_palette[ port-0x54 ].green;
978 }else{
979 new_pal.green = (data ) & 0x07;
980 new_pal.red = vram_palette[ port-0x54 ].red;
981 new_pal.blue = vram_palette[ port-0x54 ].blue;
982 }
983 }
984
985 if( new_pal.blue != vram_palette[ port-0x54 ].blue ||
986 new_pal.red != vram_palette[ port-0x54 ].red ||
987 new_pal.green != vram_palette[ port-0x54 ].green ){
988 vram_palette[ port-0x54 ].blue = new_pal.blue;
989 vram_palette[ port-0x54 ].red = new_pal.red;
990 vram_palette[ port-0x54 ].green = new_pal.green;
991 screen_set_dirty_palette();
992 }
993 return;
994
995
996 /* ����Х����ؤ� */
997 case 0x5c:
998 memory_bank = MEMORY_BANK_GRAM0;
999 main_memory_vram_mapping();
1000 return;
1001 case 0x5d:
1002 memory_bank = MEMORY_BANK_GRAM1;
1003 main_memory_vram_mapping();
1004 return;
1005 case 0x5e:
1006 memory_bank = MEMORY_BANK_GRAM2;
1007 main_memory_vram_mapping();
1008 return;
1009 case 0x5f:
1010 memory_bank = MEMORY_BANK_MAIN;
1011 main_memory_vram_mapping();
1012 return;
1013
1014 /* DMAC���� */
1015
1016 case 0x60:
1017 case 0x62:
1018 case 0x64:
1019 case 0x66:
1020 dmac_out_address( (port-0x60)/2, data );
1021 /*printf("DMAC %x ADDR %02x\n",(port-0x60)/2,data );*/
1022 return;
1023 case 0x61:
1024 case 0x63:
1025 case 0x65:
1026 case 0x67:
1027 dmac_out_counter( (port-0x61)/2, data );
1028 /*printf("DMAC %x CNTR %02x\n",(port-0x61)/2,data );*/
1029 return;
1030 case 0x68:
1031 dmac_out_mode( data );
1032 /*printf("DMAC MODE %02x\n",data );*/
1033 return;
1034
1035
1036 /* �ܡ��졼�� */
1037 case 0x6f:
1038 if( ROM_VERSION >= '8' ) baudrate_sw = data; /* FH/MH �ʹߤ��б� */
1039 return;
1040
1041
1042 /* Window ���ե��åȥ��ɥ쥹������ */
1043 case 0x70:
1044 window_offset = (word)data << 8;
1045 main_memory_mapping_8000_83ff();
1046 return;
1047
1048 /* ��ĥ ROM �Х� */
1049 case 0x71:
1050 ext_rom_bank = data;
1051 main_memory_mapping_0000_7fff();
1052 return;
1053
1054 /* Window ���ե��åȥ��ɥ쥹 ������� */
1055
1056 case 0x78:
1057 window_offset += 0x100;
1058 main_memory_mapping_8000_83ff();
1059 return;
1060
1061
1062
1063 /* ������ɽ���(���ץ����) */
1064 case 0xa8:
1065 if( sound_port & SD_PORT_A8_AD ){
1066 sound_out_reg( data );
1067 }
1068 return;
1069 case 0xa9:
1070 if( sound_port & SD_PORT_A8_AD ){
1071 sound_out_data( data );
1072 }
1073 return;
1074 case 0xaa:
1075 if( sound_port & SD_PORT_A8_AD ){
1076 intr_sound_enable = (data & INTERRUPT_MASK_SOUND) ^ INTERRUPT_MASK_SOUND;
1077 if( highspeed_flag == FALSE ) CPU_REFRESH_INTERRUPT();
1078 /*if( intr_sound_enable == FALSE ) SOUND_flag = FALSE;*/
1079 }
1080 return;
1081 case 0xac:
1082 if( sound_port & SD_PORT_A8_AD ){
1083 sound2_out_reg( data );
1084 }
1085 return;
1086 case 0xad:
1087 if( sound_port & SD_PORT_A8_AD ){
1088 sound2_out_data( data );
1089 }
1090 return;
1091
1092
1093 /* ��ĥ RAM ���� */
1094 case 0xe2:
1095 if( use_extram ){
1096 ext_ram_ctrl = data & 0x11;
1097 main_memory_mapping_0000_7fff();
1098 }
1099 return;
1100 case 0xe3:
1101 /*printf("OUT E3 <= %02X\n",data);*/
1102 if( use_extram ){
1103 if( linear_ext_ram ){ /* �����ͤ��̤�˥Х��꿶�� */
1104 ext_ram_bank = data;
1105 }else{ /* �µ��äݤ�(?)�Х��꿶�� */
1106 ext_ram_bank = 0xff;
1107 if (use_extram <= 4) { /* 128KB*4�ʲ� */
1108 if ((data & 0x0f) < use_extram * 4) {
1109 ext_ram_bank = data & 0x0f;
1110 }
1111 } else if (use_extram == 8) { /* 1MB */
1112 /* ���� 00-07h, 10-17h, 20-27h, 30-37h �Ȥ��� */
1113 if ((data & 0xc8) == 0x00) {
1114 ext_ram_bank = ((data & 0x30) >> 1) | (data & 0x07);
1115 }
1116 } else if (use_extram <= 10) { /* 1MB + 128KB*2�ʲ� */
1117 /* ���� 08-0Fh, 18-1Fh, 28-2Fh, 38-3Fh �Ȥ��� */
1118 if ((data & 0xc8) == 0x08) {
1119 ext_ram_bank = ((data & 0x30) >> 1) | (data & 0x07);
1120 } else if ((data & 0x0f) < (use_extram - 8) * 4) {
1121 ext_ram_bank = (data & 0x0f) + 0x20;
1122 }
1123 } else if (use_extram == 16) { /* 2MB */
1124 /* ���� 08-0Fh, 18-1Fh, 28-2Fh, 38-3Fh �Ȥ��� */
1125 /* ���� 48-4Fh, 58-5Fh, 68-6Fh, 78-7Fh �Ȥ��� */
1126 if ((data & 0x88) == 0x08) {
1127 ext_ram_bank = ((data & 0x70) >> 1) | (data & 0x07);
1128 }
1129 }
1130 }
1131 main_memory_mapping_0000_7fff();
1132 }
1133 return;
1134
1135
1136 /* �����ߥ�٥������ */
1137 case 0xe4:
1138 intr_priority = data & 0x08;
1139 if( intr_priority ) intr_level = 7;
1140 else intr_level = data & 0x07;
1141 if( highspeed_flag == FALSE ){
1142 CPU_REFRESH_INTERRUPT();
1143
1144 /* 'ASHE�к��ġ� */ /* thanks! peach */
1145 z80main_cpu.skip_intr_chk = TRUE;
1146 }
1147 return;
1148
1149 /* �����ߥޥ��� */
1150 case 0xe6:
1151 intr_sio_enable = data & INTERRUPT_MASK_SIO;
1152 intr_vsync_enable = data & INTERRUPT_MASK_VSYNC;
1153 intr_rtc_enable = data & INTERRUPT_MASK_RTC;
1154
1155 if( intr_sio_enable == FALSE ){RS232C_flag = FALSE; sio_data_clear(); }
1156 if( intr_vsync_enable == FALSE ) VSYNC_flag = FALSE;
1157 if( intr_rtc_enable == FALSE ) RTC_flag = FALSE;
1158
1159 if( highspeed_flag == FALSE ) CPU_REFRESH_INTERRUPT();
1160 return;
1161
1162
1163 /* �����ңϣ� ���ɥ쥹���� */
1164 case 0xe8:
1165 kanji1_addr.B.l = data;
1166 return;
1167 case 0xe9:
1168 kanji1_addr.B.h = data;
1169 return;
1170
1171 case 0xea:
1172 case 0xeb:
1173 return;
1174
1175 case 0xec:
1176 kanji2_addr.B.l = data;
1177 return;
1178 case 0xed:
1179 kanji2_addr.B.h = data;
1180 return;
1181
1182
1183 /* ����ROM������ */
1184
1185 case 0xf0:
1186 if( use_jisho_rom ){
1187 jisho_rom_bank = data & JISHO_BANK;
1188 main_memory_mapping_c000_ffff();
1189 }
1190 return;
1191 case 0xf1:
1192 if( use_jisho_rom ){
1193 jisho_rom_ctrl = data & JISHO_NOT_SELECT;
1194 main_memory_mapping_c000_ffff();
1195 }
1196 return;
1197
1198 /* �Уɣ� */
1199
1200 case 0xfc:
1201 logpio(" %02x-->\n",data);
1202 pio_write_AB( PIO_SIDE_M, PIO_PORT_A, data );
1203 return;
1204 case 0xfd:
1205 logpio(" %02x==>\n",data);
1206 pio_write_AB( PIO_SIDE_M, PIO_PORT_B, data );
1207 return;
1208 case 0xfe:
1209 pio_write_C_direct( PIO_SIDE_M, data );
1210 return;
1211 case 0xff:
1212 if( data & 0x80 ) pio_set_mode( PIO_SIDE_M, data );
1213 else pio_write_C( PIO_SIDE_M, data );
1214 return;
1215
1216
1217
1218
1219 /* ����¾�Υݡ��� */
1220
1221 case 0x90: case 0x91: case 0x92: case 0x93: /* CD-ROM */
1222 case 0x94: case 0x95: case 0x96: case 0x97:
1223 case 0x98: case 0x99: case 0x9a: case 0x9b:
1224 case 0x9c: case 0x9d: case 0x9e: case 0x9f:
1225
1226 case 0xa0: case 0xa1: case 0xa2: case 0xa3: /* MUSIC & NETWORK */
1227
1228 case 0xc2: case 0xc3: /* MUSIC */
1229 case 0xc4: case 0xc5: case 0xc6: case 0xc7:
1230 case 0xc8: case 0xc9: case 0xca: case 0xcb:
1231 case 0xcc: case 0xcd: case 0xce: case 0xcf:
1232
1233 case 0xd0: case 0xd1: case 0xd2: case 0xd3: /* MUSIC & GP-IB*/
1234 case 0xd4: case 0xd5: case 0xd6: case 0xd7:
1235 case 0xd8: /* GP-IB */
1236
1237 case 0xdc: case 0xdd: case 0xde: case 0xdf: /* MODEM */
1238
1239 case 0xb4: case 0xb5: /* VIDEO ART */
1240
1241
1242 case 0xc1: /* ??? Access in N88-BASIC ver 1.8 */
1243 case 0xf3: case 0xf4: case 0xf8:
1244
1245 case 0xe7: /* ??? Access in N-BASIC ver 1.8 */
1246
1247 return;
1248 }
1249
1250
1251 if( verbose_io )printf("OUT data %02X to undecoeded port %02XH\n",data,port);
1252
1253 }
1254
1255 /*----------------------*/
1256 /* �ݡ��ȡ���� */
1257 /*----------------------*/
main_io_in(byte port)1258 byte main_io_in( byte port )
1259 {
1260 switch( port ){
1261
1262 /* �����ܡ��� */
1263 case 0x00:
1264 case 0x01:
1265 case 0x02:
1266 case 0x03:
1267 case 0x04:
1268 case 0x05:
1269 case 0x06:
1270 case 0x07:
1271 case 0x08:
1272 case 0x09:
1273 case 0x0a:
1274 case 0x0b:
1275 case 0x0c:
1276 case 0x0d:
1277 case 0x0e:
1278 case 0x0f:
1279 disk_ex_drv = 0; /* �������Ϥǥꥻ�å� */
1280 #ifdef USE_KEYBOARD_BUG /* peach���� */
1281 {
1282 int i;
1283 byte mkey, mkey_old;
1284
1285 mkey = key_scan[port];
1286 do {
1287 mkey_old = mkey;
1288 for (i = 0; i < 0x10; i++) {
1289 if (i != port && key_scan[i] != 0xff) {
1290 /* [SHIFT],[CTRL],[GRAPH],[����]�ˤ�Ŭ�Ѥ��ʤ� */
1291 if ((i == 0x08 && (mkey | key_scan[i] | 0xf0) != 0xff) ||
1292 (i != 0x08 && (mkey | key_scan[i]) != 0xff))
1293 mkey &= key_scan[i];
1294 }
1295 }
1296 } while (mkey_old != mkey);
1297 return(mkey);
1298 }
1299 #else
1300 return key_scan[ port ];
1301 #endif
1302
1303
1304 /* RS-232C��CMT ���ϥǡ��� */
1305 case 0x20:
1306 return sio_in_data();
1307
1308
1309 /* RS-232C/CMT ���� */
1310 case 0x21:
1311 return sio_in_status();
1312
1313
1314 /* �ǥ��åץ����å����� */
1315
1316 case 0x30:
1317 return dipsw_1 | 0xc0;
1318 case 0x31:
1319 return dipsw_2;
1320
1321 /* �Ƽ��������� */
1322 case 0x32:
1323 return misc_ctrl;
1324
1325 /* ����ȥ��뿮������ */
1326 case 0x40:
1327 return in_ctrl_signal() | 0xc0 | 0x04;
1328 /* return in_ctrl_signal() | 0xc0;*/
1329
1330
1331 /* ����������� */
1332
1333 case 0x44:
1334 if( sound_port & SD_PORT_44_45 ) return sound_in_status( );
1335 else return 0xff;
1336 case 0x45:
1337 if( sound_port & SD_PORT_44_45 ) return sound_in_data( FALSE );
1338 else return 0xff;
1339 case 0x46:
1340 if( sound_port & SD_PORT_46_47 ) return sound2_in_status( );
1341 else return 0xff;
1342 case 0x47:
1343 if( sound_port & SD_PORT_46_47 ) return sound2_in_data( );
1344 else return 0xff;
1345
1346
1347 /* CRTC���� */
1348 case 0x50:
1349 /*printf("READ CRTC parm\n");*/
1350 return crtc_in_parameter( );
1351 case 0x51:
1352 /*printf("READ CRTC stat\n");*/
1353 return crtc_in_status( );
1354
1355
1356 /* ����� */
1357 case 0x5c:
1358 return (1<<memory_bank) | 0xf8;
1359
1360
1361 /* DMAC���� */
1362
1363 case 0x60:
1364 case 0x62:
1365 case 0x64:
1366 case 0x66:
1367 /*printf("READ DMAC addr\n");*/
1368 return dmac_in_address( (port-0x60)/2 );
1369 case 0x61:
1370 case 0x63:
1371 case 0x65:
1372 case 0x67:
1373 /*printf("READ DMAC cntr\n");*/
1374 return dmac_in_counter( (port-0x61)/2 );
1375 case 0x68:
1376 /*printf("READ DMAC stat\n");*/
1377 return dmac_in_status( );
1378
1379
1380 /* CPU ����å� */
1381 case 0x6e:
1382 if( ROM_VERSION >= '8' ) return cpu_clock | 0x10; /* FH/MH �ʹߤ��б� */
1383 else return 0xff;
1384
1385
1386 /* �ܡ��졼�� */
1387 case 0x6f:
1388 if( ROM_VERSION >= '8' ) return baudrate_sw | 0xf0; /* FH/MH �ʹߤ��б� */
1389 else return 0xff;
1390
1391
1392 /* Window ���ե��åȥ��ɥ쥹������ */
1393 case 0x70:
1394 return window_offset >> 8;
1395
1396
1397 /* ��ĥ ROM �Х� */
1398 case 0x71:
1399 return ext_rom_bank;
1400
1401
1402 /* ��ĥ RAM ���� */
1403 case 0xe2:
1404 if( use_extram ) return ~ext_ram_ctrl | 0xee;
1405 return 0xff;
1406 case 0xe3:
1407 if( linear_ext_ram ){ /* �����ͤ��̤�˥Х��꿶�ä� */
1408 if( use_extram &&
1409 (ext_ram_bank < use_extram*4) ) return ext_ram_bank;
1410 return 0xff;
1411 }else{ /* �µ��äݤ�(?)�Х��꿶�ä� */
1412 byte ret = 0xff;
1413 if (use_extram && (ext_ram_bank != 0xff)) {
1414 if (use_extram <= 4) { /* 128KB*4�ʲ� */
1415 ret = (ext_ram_bank | 0xf0);
1416 } else if (use_extram == 8) { /* 1MB */
1417 /* ���� 00-07h, 10-17h, 20-27h, 30-37h �Ȥ��� */
1418 if (ext_ram_bank < 8) {
1419 ret = (ext_ram_bank | 0xf0);
1420 } else {
1421 ret = ((ext_ram_bank & 0x18) << 1) | (ext_ram_bank & 0x07);
1422 }
1423 } else if (use_extram <= 10) { /* 1MB + 128KB*2�ʲ� */
1424 /* ���� 08-0Fh, 18-1Fh, 28-2Fh, 38-3Fh �Ȥ��� */
1425 if (ext_ram_bank < 0x20) {
1426 ret = ((ext_ram_bank & 0x18) << 1) | 0x08 |
1427 (ext_ram_bank & 0x07);
1428 } else {
1429 ret = ((ext_ram_bank - 0x20) | 0xf0);
1430 }
1431 } else if (use_extram == 16) { /* 2MB */
1432 /* ���� 08-0Fh, 18-1Fh, 28-2Fh, 38-3Fh �Ȥ��� */
1433 /* ���� 48-4Fh, 58-5Fh, 68-6Fh, 78-7Fh �Ȥ��� */
1434 ret = ((ext_ram_bank & 0x38) << 1) | 0x08 |
1435 (ext_ram_bank & 0x07);
1436 }
1437 }
1438 /*printf("IN E3 -----> %02X\n",ret);*/
1439 return ret;
1440 }
1441
1442
1443 /* �����������(���ץ����) */
1444 case 0xa8:
1445 if( sound_port & SD_PORT_A8_AD ) return sound_in_status( );
1446 else return 0xff;
1447 case 0xa9:
1448 if( sound_port & SD_PORT_A8_AD ) return sound_in_data( TRUE );
1449 else return 0xff;
1450 case 0xaa:
1451 if( sound_port & SD_PORT_A8_AD ) return intr_sound_enable | 0x7f;
1452 else return 0xff;
1453 case 0xac:
1454 if( sound_port & SD_PORT_A8_AD ) return sound2_in_status( );
1455 else return 0xff;
1456 case 0xad:
1457 if( sound_port & SD_PORT_A8_AD ) return sound2_in_data( );
1458 else return 0xff;
1459
1460
1461
1462 /* �����ңϣ� �ե�������� */
1463 case 0xe8:
1464 return kanji_rom[0][kanji1_addr.W][1];
1465 case 0xe9:
1466 return kanji_rom[0][kanji1_addr.W][0];
1467
1468 case 0xec:
1469 return kanji_rom[1][kanji2_addr.W][1];
1470 case 0xed:
1471 return kanji_rom[1][kanji2_addr.W][0];
1472
1473
1474
1475 /* �Уɣ� */
1476
1477 case 0xfc:
1478 {
1479 byte data = pio_read_AB( PIO_SIDE_M, PIO_PORT_A );
1480 logpio(" %02x<--\n",data);
1481 /* {
1482 static byte debug_pio_halt[4] = { 0,0,0,0 };
1483 debug_pio_halt[0] = debug_pio_halt[1];
1484 debug_pio_halt[1] = debug_pio_halt[2];
1485 debug_pio_halt[2] = debug_pio_halt[3];
1486 debug_pio_halt[3] = data;
1487 if(debug_pio_halt[0]==0x20&&
1488 debug_pio_halt[1]==0x3d&&
1489 debug_pio_halt[2]==0x02&&
1490 debug_pio_halt[3]==0x00) emu_mode=MONITOR;
1491 }*/
1492 return data;
1493 }
1494 case 0xfd:
1495 {
1496 byte data = pio_read_AB( PIO_SIDE_M, PIO_PORT_B );
1497 logpio(" %02x<==\n",data);
1498 return data;
1499 }
1500 case 0xfe:
1501 return pio_read_C( PIO_SIDE_M );
1502
1503
1504
1505
1506 /* ����¾�Υݡ��� */
1507
1508 case 0x90: case 0x91: case 0x92: case 0x93: /* CD-ROM */
1509 case 0x94: case 0x95: case 0x96: case 0x97:
1510 case 0x98: case 0x99: case 0x9a: case 0x9b:
1511 case 0x9c: case 0x9d: case 0x9e: case 0x9f:
1512
1513 case 0xa0: case 0xa1: case 0xa2: case 0xa3: /* MUSIC & NETWORK */
1514
1515 case 0xc2: case 0xc3: /* MUSIC */
1516 case 0xc4: case 0xc5: case 0xc6: case 0xc7:
1517 case 0xc8: case 0xc9: case 0xca: case 0xcb:
1518 case 0xcc: case 0xcd: case 0xce: case 0xcf:
1519
1520 case 0xd0: case 0xd1: case 0xd2: case 0xd3: /* MUSIC & GP-IB*/
1521 case 0xd4: case 0xd5: case 0xd6: case 0xd7:
1522 case 0xd8: /* GP-IB */
1523
1524 case 0xdc: case 0xdd: case 0xde: case 0xdf: /* MODEM */
1525
1526 case 0xb4: case 0xb5: /* VIDEO ART */
1527
1528
1529 case 0xc1: /* ??? Access in N88-BASIC ver 1.8 */
1530 case 0xf3: case 0xf4: case 0xf8:
1531
1532 return 0xff;
1533 #if 0
1534 case 0xf4: /* ??? */
1535 return 0xff;
1536 case 0xf8: /* ??? */
1537 return 0xff;
1538 #endif
1539 }
1540
1541
1542 if( verbose_io )printf("IN from undecoeded port %02XH\n",port);
1543
1544 return 0xff;
1545 }
1546
1547
1548
1549
1550
1551
1552 /*===========================================================================*/
1553 /* ���ꥢ��ݡ��� */
1554 /*===========================================================================*/
1555
1556 static int sio_instruction; /* USART �Υ��ޥ�ɾ��� */
1557 static byte sio_mode; /* USART ������⡼�� */
1558 static byte sio_command; /* USART �Υ��ޥ�� */
1559 static int sio_data_exist; /* �ɹ�̤�� SIO�ǡ���ͭ */
1560 static byte sio_data; /* SIO�ǡ��� */
1561
1562 static int com_X_flow = FALSE; /* ���ǡ�X�ե������� */
1563
1564 static int cmt_dummy_read_cnt = 0; /* ���̤���ѻ��Υ��ߡ� */
1565 static int cmt_skip; /* ̵���ǡ��������ɤ����Ф� */
1566 static int cmt_skip_data; /* �ɤ����Ф�ľ��Υǡ��� */
1567
1568 static long cmt_read_chars = 0; /* �ɤ߹�����¥Х��ȿ� */
1569 static long cmt_stateload_chars = 0; /* ���ơ��ȥ��ɻ��ɹ���*/
1570 static int cmt_stateload_skip = 0; /* ���ơ��ȥ��ɻ� skip */
1571
1572 static int sio_getc( int is_cmt, int *tick );
1573
sio_data_clear(void)1574 void sio_data_clear(void)
1575 {
1576 sio_data_exist = FALSE;
1577 }
1578
1579
1580 /*-------- �����ѥơ��ץ�����ե������ "rb" �dz��� --------*/
1581
sio_open_tapeload(const char * filename)1582 int sio_open_tapeload( const char *filename )
1583 {
1584 sio_close_tapeload();
1585
1586 if( (fp_ti = osd_fopen( FTYPE_TAPE_LOAD, filename, "rb" )) ){
1587
1588 sio_set_intr_base();
1589 return sio_tape_rewind();
1590
1591 }else{
1592 if (quasi88_is_menu() == FALSE)
1593 printf("\n[[[ %s : Tape load image can't open ]]]\n\n", filename );
1594 }
1595 cmt_stateload_chars = 0;
1596 return FALSE;
1597 }
sio_close_tapeload(void)1598 void sio_close_tapeload( void )
1599 {
1600 if( fp_ti ){ osd_fclose( fp_ti ); fp_ti = NULL; }
1601 sio_set_intr_base();
1602
1603 cmt_read_chars = 0;
1604 }
1605
1606 /*-------- �������ѥơ��ץ�����ե������ "ab" �dz��� --------*/
1607
sio_open_tapesave(const char * filename)1608 int sio_open_tapesave( const char *filename )
1609 {
1610 sio_close_tapesave();
1611
1612 if( (fp_to = osd_fopen( FTYPE_TAPE_SAVE, filename, "ab" )) ){
1613
1614 return TRUE;
1615
1616 }else{
1617 if (quasi88_is_menu() == FALSE)
1618 printf("\n[[[ %s : Tape save image can't open ]]]\n\n", filename );
1619 }
1620 return FALSE;
1621 }
sio_close_tapesave(void)1622 void sio_close_tapesave( void )
1623 {
1624 if( fp_to ){ osd_fclose( fp_to ); fp_to = NULL; }
1625 }
1626
1627 /*-------- ���ꥢ�������ѤΥե������ "rb" �dz��� --------*/
1628
sio_open_serialin(const char * filename)1629 int sio_open_serialin( const char *filename )
1630 {
1631 sio_close_serialin();
1632
1633 if( (fp_si = osd_fopen( FTYPE_COM_LOAD, filename, "rb" )) ){
1634
1635 sio_set_intr_base();
1636 com_EOF = FALSE;
1637
1638 if( osd_fseek( fp_si, 0, SEEK_END ) ) goto ERR;
1639 if( (com_size = osd_ftell( fp_si )) < 0 ) goto ERR;
1640 if( osd_fseek( fp_si, 0, SEEK_SET ) ) goto ERR;
1641
1642 return TRUE;
1643 }
1644 ERR:
1645 if( fp_si ){
1646 printf("\n[[[ Serial input image access error ]]]\n\n" );
1647 }else{
1648 if (quasi88_is_menu() == FALSE)
1649 printf("\n[[[ %s : Serial input file can't open ]]]\n\n", filename );
1650 }
1651 sio_close_serialin();
1652
1653 return FALSE;
1654 }
sio_close_serialin(void)1655 void sio_close_serialin( void )
1656 {
1657 if( fp_si ){ osd_fclose( fp_si ); fp_si = NULL; }
1658 sio_set_intr_base();
1659 /* com_X_flow = FALSE; */
1660 }
1661
1662 /*-------- ���ꥢ������ѤΥե������ "ab" �dz��� --------*/
1663
sio_open_serialout(const char * filename)1664 int sio_open_serialout( const char *filename )
1665 {
1666 sio_close_serialout();
1667
1668 if( (fp_so = osd_fopen( FTYPE_COM_SAVE, filename, "ab" )) ){
1669
1670 return TRUE;
1671
1672 }else{
1673 if (quasi88_is_menu() == FALSE)
1674 printf("\n[[[ %s : Serial output file can't open ]]]\n\n", filename );
1675 }
1676 return FALSE;
1677 }
sio_close_serialout(void)1678 void sio_close_serialout( void )
1679 {
1680 if( fp_so ){ osd_fclose( fp_so ); fp_so = NULL; }
1681 }
1682
1683 /*-------- ���ꥢ��ޥ���������/��λ���� --------*/
1684
sio_mouse_init(int initial)1685 void sio_mouse_init(int initial)
1686 {
1687 if (initial) {
1688 init_serial_mouse_data();
1689 }
1690 sio_set_intr_base();
1691 }
1692
1693 /*-------- �����Ƥ���ơ��ץ�������᤹ --------*/
1694
1695 #define T88_HEADER_STR "PC-8801 Tape Image(T88)"
sio_tape_rewind(void)1696 int sio_tape_rewind( void )
1697 {
1698 int size;
1699 char buf[ sizeof(T88_HEADER_STR) ];
1700
1701 cmt_read_chars = 0;
1702
1703 if( fp_ti ){
1704 if( osd_fseek( fp_ti, 0, SEEK_END ) ) goto ERR;
1705 if( (cmt_size = osd_ftell( fp_ti )) < 0 ) goto ERR;
1706
1707 if( osd_fseek( fp_ti, 0, SEEK_SET ) ) goto ERR;
1708
1709 size = osd_fread( buf, sizeof(char), sizeof(buf), fp_ti );
1710 if( size == sizeof(buf) &&
1711 memcmp( buf, T88_HEADER_STR, sizeof(buf) ) == 0 ){ /* T88 */
1712 cmt_is_t88 = TRUE;
1713 cmt_block_size = 0;
1714 cmt_EOF = FALSE;
1715 cmt_skip = 0;
1716 }else{ /* CMT */
1717 cmt_is_t88 = FALSE;
1718 cmt_EOF = FALSE;
1719 cmt_skip = 0;
1720 if( osd_fseek( fp_ti, 0, SEEK_SET ) ) goto ERR;
1721 }
1722
1723 while( cmt_stateload_chars -- ){ /* ���ơ��ȥ��ɻ��ϡ��ơ��������� */
1724 if( sio_getc( TRUE, NULL ) == EOF ){
1725 break;
1726 }
1727 }
1728 cmt_skip = cmt_stateload_skip;
1729 cmt_stateload_chars = 0;
1730
1731 /*printf("%d\n",osd_ftell(fp_ti));*/
1732 return TRUE;
1733 }
1734
1735 ERR:
1736 if( fp_ti ){
1737 printf("\n[[[ Tape image access error ]]]\n\n" );
1738 }
1739 sio_close_tapeload();
1740
1741 cmt_stateload_chars = 0;
1742 return FALSE;
1743 }
1744
1745 /*-------- �����Ƥ���ơ��פθ��߰��֤��֤� (��%�ɤ�����γ�ǧ��) --------*/
1746
sio_tape_pos(long * cur,long * end)1747 int sio_tape_pos( long *cur, long *end )
1748 {
1749 long v;
1750
1751 if( fp_ti ){
1752 if( cmt_EOF ){ /* ��ü�ʤ顢����=0/��ü=0 �ˤ��������֤� */
1753 *cur = 0;
1754 *end = 0;
1755 return TRUE;
1756 }else{ /* ����ʤ顢���֤Ƚ�ü�åȤ������֤� */
1757 v = osd_ftell( fp_ti );
1758 if( v >= 0 ){
1759 *cur = v;
1760 *end = cmt_size;
1761 return TRUE;
1762 }
1763 }
1764 }
1765 *cur = 0; /* �������ϡ�����=0/��ü=0 �ˤ��������֤� */
1766 *end = 0;
1767 return FALSE;
1768 }
1769
sio_com_pos(long * cur,long * end)1770 int sio_com_pos( long *cur, long *end )
1771 {
1772 long v;
1773
1774 if( fp_si ){
1775 if( com_EOF ){ /* ��ü�ʤ顢����=0/��ü=0 �ˤ��������֤� */
1776 *cur = 0;
1777 *end = 0;
1778 return TRUE;
1779 }else{ /* ����ʤ顢���֤Ƚ�ü�åȤ������֤� */
1780 v = osd_ftell( fp_si );
1781 if( v >= 0 ){
1782 *cur = v;
1783 *end = com_size;
1784 return TRUE;
1785 }
1786 }
1787 }
1788 *cur = 0; /* �������ϡ�����=0/��ü=0 �ˤ��������֤� */
1789 *end = 0;
1790 return FALSE;
1791 }
1792
1793
1794
1795
1796
1797 /*
1798 * �����Ƥ���sio���������1ʸ���ɤ߹���
1799 */
sio_getc(int is_cmt,int * tick)1800 static int sio_getc( int is_cmt, int *tick )
1801 {
1802 int i, c, id, size, time;
1803
1804 if( tick ) *tick = 0;
1805
1806 if( is_cmt==FALSE ){ /* ���ꥢ������ */
1807
1808 if (use_siomouse) {
1809 c = get_serial_mouse_data();
1810 return c;
1811 }
1812
1813 if( fp_si==NULL ) return EOF;
1814 if( com_EOF ) return EOF;
1815
1816 c = osd_fgetc( fp_si );
1817 if( c==EOF ){
1818 printf(" (( %s : Serial input file EOF ))\n", file_sin );
1819 status_message( 1, STATUS_WARN_TIME, "Serial input [EOF]" );
1820 com_EOF = TRUE;
1821 }
1822 return c;
1823
1824 }else{ /* �ơ������� */
1825
1826 if( fp_ti==NULL ) return EOF;
1827 if( cmt_EOF ) return EOF;
1828
1829 if( cmt_is_t88 == FALSE ){ /* CMT������ */
1830
1831 c = osd_fgetc( fp_ti );
1832
1833 }else{ /* T88������ */
1834
1835 while( cmt_block_size == 0 ){
1836
1837 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1838 id = c;
1839 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1840 id += c << 8;
1841
1842 if( id==0x0000 ){ /* ����� */
1843 c = EOF; break;
1844 }
1845 else {
1846 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1847 size = c;
1848 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1849 size += c << 8;
1850
1851 if( id == 0x0101 ){ /* �ǡ������� */
1852
1853 if( size < 12 ){ c = EOF; break; }
1854
1855 for( i=0; i<12; i++ ){ /* ���������̵�� */
1856 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1857 }
1858 if( c==EOF ) break;
1859 cmt_block_size = size - 12;
1860
1861 }else{
1862
1863 if( id == 0x0100 || /* �֥���� */
1864 id == 0x0102 || /* ���ڡ������� */
1865 id == 0x0103 ){ /* �ޡ������� */
1866
1867 if( size != 8 ){ c = EOF; break; }
1868
1869 for( i=0; i<4; i++ ){ /* ���ϻ��֤�̵�� */
1870 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1871 }
1872 if( c==EOF ) break;
1873 /* Ĺ�����֤ϼ��� */
1874 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1875 time = c;
1876 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1877 time += c << 8;
1878 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1879 time += c << 16;
1880 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1881 time += c << 24;
1882
1883 if( tick ) *tick += time;
1884
1885 }else{ /* ¾�Υ���(̵��) */
1886
1887 for( i=0; i<size; i++ ){
1888 if( (c=osd_fgetc(fp_ti))==EOF ){ break; }
1889 }
1890 if( c==EOF ) break;
1891
1892 }
1893 }
1894 }
1895 }
1896
1897 cmt_block_size --;
1898 c = osd_fgetc( fp_ti );
1899 }
1900
1901 if( c==EOF ){
1902 cmt_EOF = TRUE;
1903 status_message( 1, STATUS_WARN_TIME, "Tape Read [EOF]");
1904 }else{
1905 cmt_read_chars ++;
1906 }
1907
1908 return c;
1909 }
1910 }
1911
1912 /*
1913 * �ơ��פ��ɤ߹�������˥⡼��OFF���줿�顢�ɤ߹��ߥ��顼ȯ���Ȥ���
1914 * 1�Х����ɤ����Ф����ǡ��������椫�ɤ����� T88 �Ǥʤ��ȥ����å��Ǥ��ʤ���
1915 * ����ʥ����å���ɬ�פʤΤ�����
1916 */
sio_check_cmt_error(void)1917 static void sio_check_cmt_error( void )
1918 {
1919 int c;
1920 if( sio_tape_readable() ){
1921 if( cmt_is_t88 && /* T88 ���ġ��ǡ�������������λ��Τ� */
1922 cmt_skip == 0 &&
1923 cmt_block_size ){
1924 cmt_block_size --;
1925 c = osd_fgetc( fp_ti );
1926
1927 if( verbose_proc )
1928 printf( "Tape read: lost 1 byte\n" );
1929
1930 if( c==EOF ){
1931 cmt_EOF = TRUE;
1932 status_message(1, STATUS_WARN_TIME, "Tape Read [EOF]");
1933 }else{
1934 cmt_read_chars ++;
1935 }
1936 }
1937 }
1938 }
1939
1940
1941
1942
1943
1944
1945 /*
1946 * �����Ƥ���sio�������1ʸ������
1947 */
sio_putc(int is_cmt,int c)1948 static int sio_putc( int is_cmt, int c )
1949 {
1950 OSD_FILE *fp;
1951
1952 if( is_cmt==FALSE ){ fp = fp_so; } /* ���ꥢ����� */
1953 else { fp = fp_to; } /* �ơ����� */
1954
1955 if( fp ){
1956 osd_fputc( c, fp );
1957 osd_fflush( fp );
1958 }
1959 return c;
1960 }
1961
1962
1963 /*
1964 * ��®�ơ��ץ��� �ġ� �ܺ�����������ʵ�ǽ���ä��Τ���
1965 */
sio_tape_highspeed_load(void)1966 static void sio_tape_highspeed_load( void )
1967 {
1968 int c, sum, addr, size;
1969
1970 if( sio_tape_readable()==FALSE ) return;
1971
1972 /* �ޥ����إå���õ�� */
1973
1974 do{ /* 0x3a ���ФƤ���ޤǥ�� */
1975 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
1976 } while( c != 0x3a );
1977 /* ž���襢�ɥ쥹 H */
1978 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
1979 sum = c;
1980 addr = c * 256;
1981 /* ž���襢�ɥ쥹 L */
1982 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
1983 sum += c;
1984 addr += c;
1985 /* �إå������� */
1986 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
1987 sum += c;
1988 if( (sum&0xff) != 0 ){ return; }
1989
1990
1991 /* ���Ȥϥǡ������η����֤� */
1992
1993 while( TRUE ){
1994
1995 do{ /* 0x3a ���ФƤ���ޤǥ�� */
1996 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
1997 } while( c != 0x3a );
1998
1999 /* �ǡ����� */
2000 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
2001 sum = c;
2002 size = c;
2003 if( c==0 ){ /* �ǡ�����==0�ǽ�ü */
2004 return;
2005 }
2006
2007 for( ; size; size -- ){ /* �ǡ�����ʬ��ž�� */
2008
2009 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
2010 sum += c;
2011 main_mem_write( addr, c );
2012 addr ++;
2013 }
2014 /* �ǡ��������� */
2015 if( (c = sio_getc(TRUE,0)) == EOF ){ return; }
2016 sum += c;
2017 if( (sum&0xff) != 0 ){ return; }
2018 }
2019 }
2020
2021
2022
2023 /*
2024 * RS232C���������Υ��å�
2025 */
2026 /* �������ѿ��ϡ����꤫�黻�Ф��� */
2027 static int sio_bps; /* BPS */
2028 static int sio_framesize; /* StartBit + BitĹ + StopBit ��Ŭ���˷� */
2029
sio_set_intr_base(void)2030 static void sio_set_intr_base( void )
2031 {
2032 static const int table[] = {
2033 75, 150, 300, 600, 1200, 2400, 4800, 9600, 19200,
2034 };
2035
2036 /* ������ե����륻�åȺѤ� ���ġ�
2037 ���� Enable ���ġ�
2038 RS232C (I/O 30h:bit5=ON) ����CMT���ĥ⡼��ON (I/O 30h:bit5=OFF,bit3=ON)
2039 �λ��ˡ�����Ū�˳����ߤ�ȯ�������롣���μ���������롣 */
2040
2041 if( (fp_si || fp_ti || use_siomouse) &&
2042 (sio_command & 0x04) &&
2043 ( (sys_ctrl & 0x20) || (sys_ctrl & 0x08) ) ){
2044
2045 if( sys_ctrl & 0x20 ){ /* RS232C ����� */
2046
2047 sio_bps = table[ baudrate_sw ]; /* BPS �� �ܡ��졼������ */
2048 sio_framesize = 10; /* �ե졼��Ĺ��10bit���� */
2049
2050 }else{ /* CMT ����� */
2051
2052 if( cmt_speed == 0 ){ /* �̾�ϡ�*/
2053 if( sys_ctrl & 0x10 ) sio_bps = 1200; /* I/O 30h:bit4=1 �� 1200bps */
2054 else sio_bps = 600; /* =0 �� 600bps */
2055 }else{
2056 sio_bps = cmt_speed; /* ����������Ϥ����� */
2057 }
2058 sio_framesize = 11; /* �ե졼��Ĺ��11bit���� */
2059 }
2060
2061 }else{ /* ���ꥢ���ԲĻ� */
2062 sio_bps = 0;
2063 sio_framesize = 0;
2064 }
2065
2066 interval_work_set_RS232C( sio_bps, sio_framesize );
2067 }
2068
2069
2070 /*
2071 * T88 �ե����ޥå� �� TICK���֤� ���ꥢ������߲���˴�������
2072 *
2073 * �֥�����ڡ������ޡ��������ϡ�1/4800sñ�̤����л��֤����Ҥ��Ƥ��롣
2074 * �ʤΤǡ����֤� n �ξ�硢n/4800�å������Ȥ��Ȥ��������ˤʤ�Ϥ���
2075 * �Ĥޤꡢ ( n / 4800 ) * CPU_CLOCK / rs232c_intr_base ��ʬ��
2076 * RS232C�����ߤ�;ʬ���ԤƤФ��������μ��ϡ��֤��������
2077 * ( n / 4800 ) * ( bps / framesize )
2078 * �ˤʤ롣�ޤ�������ˤ��褫�ʤ�Ŭ���ʥ������ȤǤϤ��뤬��
2079 */
tick_2_intr_skip(int tick)2080 static int tick_2_intr_skip( int tick )
2081 {
2082 if( sio_framesize == 0 ) return 0;
2083
2084 return (tick * sio_bps / 4800 / sio_framesize) + 1;
2085 }
2086
2087
2088
2089 /*
2090 *
2091 */
sio_init(void)2092 static void sio_init( void )
2093 {
2094 sio_instruction = 0;
2095 sio_command = 0;
2096 sio_mode = 0;
2097 sio_data_exist = FALSE;
2098 sio_data = 0; /* ����ͤ�0���Ȥ��륲����εߺѤΤ���� ;_; */
2099
2100 com_X_flow = FALSE;
2101
2102 cmt_dummy_read_cnt = 0;
2103 }
2104 /*
2105 *
2106 */
sio_out_command(byte data)2107 static void sio_out_command( byte data )
2108 {
2109 if( sio_instruction==0 ){ /* �����ꥻ�å�ľ��ϡ� */
2110 sio_mode = data; /* �⡼�ɼ��դ� */
2111 sio_instruction = 1;
2112
2113 }else{ /* ����ʳ��ϥ��ޥ�ɼ��դ� */
2114
2115 if( data & 0x40 ){ /* �����ꥻ�å� */
2116 sio_mode = 0;
2117 sio_instruction = 0;
2118 sio_command = 0x40;
2119 sio_data = 0;
2120 }else{ /* ����¾ */
2121 sio_command = data;
2122 }
2123
2124 if( (sio_command & 0x04) == 0 ){ /* �ꥻ�å�or�����ػ�*/
2125 sio_data_exist = FALSE; /* �ʤ顢������� */
2126 RS232C_flag = FALSE; /* �ꥢ���� */
2127 }
2128
2129 sio_set_intr_base();
2130 }
2131 /*printf("SIO %02x -> mode:%02x cmd:%02x\n",data,sio_mode,sio_command);*/
2132 }
2133 /*
2134 *
2135 */
sio_out_data(byte data)2136 static void sio_out_data( byte data )
2137 {
2138 int is_cmt;
2139
2140 if( (sio_command & 0x01) ){ /* �������͡��֥� */
2141 if( sys_ctrl & 0x20 ){ /* ���ꥢ����Ϥξ�� */
2142 is_cmt = FALSE;
2143 if ( data==0x11 ){ /* ^Q ���� */
2144 com_X_flow = FALSE;
2145 }else if( data==0x13 ){ /* ^S ���� */
2146 com_X_flow = TRUE;
2147 }
2148 }else{ /* �ơ����Ϥξ�� */
2149 is_cmt = TRUE;
2150 }
2151 sio_putc( is_cmt, data );
2152 }
2153 }
2154 /*
2155 *
2156 */
sio_in_data(void)2157 static byte sio_in_data( void )
2158 {
2159 /*printf("->%02x ",sio_data);fflush(stdout);*/
2160 sio_data_exist = FALSE;
2161 RS232C_flag = FALSE;
2162 return sio_data;
2163 }
2164 /*
2165 *
2166 */
sio_in_status(void)2167 static byte sio_in_status( void )
2168 {
2169 int c;
2170 byte status = 0x80 | 0x04; /* �����Хåե�����ץƥ� */
2171 /* DSR| TxE */
2172
2173 if( sio_command & 0x04 ){ /* ���ߡ��������͡��֥�ξ�� */
2174
2175 if( (sys_ctrl & 0x20)==0 && /* �ơ��פǡ�SIO�����ߤ� */
2176 sio_tape_readable() && /* �Ȥ�ʤ���硢�������ɤ� */
2177 cmt_intr == FALSE ){
2178
2179 cmt_dummy_read_cnt ++; /* IN 21 �� 2��¹Ԥ����٤� */
2180 if( cmt_dummy_read_cnt >= 2 ){
2181 cmt_dummy_read_cnt = 0;
2182
2183 c = sio_getc( TRUE, 0 ); /* �ơ��פ���1ʸ���ɤ� */
2184 /*printf("[%03x]",c&0xfff);fflush(stdout);*/
2185 if( c != EOF ){
2186 sio_data = (byte)c;
2187 sio_data_exist = TRUE;
2188 }
2189 }
2190 }
2191
2192 if( sio_data_exist ){ /* �ǡ���������� */
2193 status |= 0x02; /* ������ǥ� */
2194 /* RxRDY */
2195 }
2196 }
2197
2198 if( sio_command & 0x01 ){ /* ���ߡ��������͡��֥�ξ�� */
2199 if(( (sys_ctrl & 0x20) /*&& sio_serial_writable()*/ ) ||
2200 (!(sys_ctrl & 0x20) && sio_tape_writable() ) ){
2201 status |= 0x01; /* ������ǥ� */
2202 /* TxRDY */
2203 }
2204 }
2205
2206 return status;
2207 }
2208 /*
2209 *
2210 */
sio_term(void)2211 static void sio_term( void )
2212 {
2213 }
2214
2215
2216
2217 /*
2218 * RS-232C ���������߽���
2219 */
sio_intr(void)2220 int sio_intr( void )
2221 {
2222 int c = EOF;
2223 int tick;
2224
2225 if( (sio_command & 0x04) && /* ���ߡ��������͡��֥�� */
2226 ! sio_data_exist ){ /* �ɹ�̤�Υǡ������ʤ���� */
2227
2228 if( sys_ctrl & 0x20 ){ /* ���ꥢ������ */
2229
2230 if( com_X_flow ) return FALSE;
2231 c = sio_getc( FALSE, 0 );
2232
2233 }else{ /* �ơ�������(������ѻ��Τ�)*/
2234 if( cmt_intr ){
2235
2236 if( cmt_skip==0 ){
2237 if( cmt_wait ){
2238 c = sio_getc( TRUE, &tick );
2239 if( tick ){
2240 cmt_skip = tick_2_intr_skip( tick );
2241 if( cmt_skip!=0 ){
2242 cmt_skip_data = c;
2243 c = EOF;
2244 }
2245 }
2246 }else{
2247 c = sio_getc( TRUE, 0 );
2248 }
2249 }else{ /* T88�ξ��ϡ� */
2250 cmt_skip --; /* ̵���ǡ�����ʬ�� */
2251 if( cmt_skip==0 ){ /* �֡������٤����� */
2252 c = cmt_skip_data;
2253 }
2254 }
2255 }
2256 }
2257
2258 if( c!=EOF ){
2259 sio_data = (byte)c;
2260 sio_data_exist = TRUE;
2261 /*printf("<%02x> ",sio_data);fflush(stdout);*/
2262 return TRUE; /* RxRDY������ȯ�� */
2263 }
2264 }
2265 return FALSE;
2266 }
2267
2268
2269
2270 /*
2271 * ���֥����å��ؿ�
2272 */
tape_exist(void)2273 int tape_exist( void )
2274 {
2275 return (fp_ti || fp_to);
2276 }
2277
tape_readable(void)2278 int tape_readable( void )
2279 {
2280 return (fp_ti) ? TRUE : FALSE;
2281 }
2282
tape_writable(void)2283 int tape_writable( void )
2284 {
2285 return (fp_to) ? TRUE : FALSE;
2286 }
2287
tape_reading(void)2288 int tape_reading( void )
2289 {
2290 return( fp_ti &&
2291 (sio_command & 4) &&
2292 ((sys_ctrl & 0x28) == 0x08) );
2293 }
2294
tape_writing(void)2295 int tape_writing( void )
2296 {
2297 return( fp_to &&
2298 (sio_command & 1) &&
2299 ((sys_ctrl & 0x28) == 0x08) );
2300 }
2301
2302
2303
2304 /*===========================================================================*/
2305 /* �ѥ���ݡ��� */
2306 /*===========================================================================*/
2307
printer_open(const char * filename)2308 int printer_open( const char *filename )
2309 {
2310 printer_close();
2311
2312 if( (fp_prn = osd_fopen( FTYPE_PRN, filename, "ab") ) ){
2313
2314 return TRUE;
2315
2316 }else{
2317 if (quasi88_is_menu() == FALSE)
2318 printf("\n[[[ %s : Printer output file can't open ]]]\n\n", filename );
2319 }
2320 return FALSE;
2321 }
printer_close(void)2322 void printer_close( void )
2323 {
2324 if( fp_prn ){ osd_fclose( fp_prn ); fp_prn = NULL; }
2325 }
2326
2327
2328
printer_init(void)2329 void printer_init( void )
2330 {
2331 }
printer_stlobe(void)2332 void printer_stlobe( void )
2333 {
2334 if( fp_prn ){
2335 osd_fputc( common_out_data, fp_prn );
2336 osd_fflush( fp_prn );
2337 }
2338 }
printer_term(void)2339 void printer_term( void )
2340 {
2341 }
2342
2343
2344 /*===========================================================================*/
2345 /* ����������å� */
2346 /*===========================================================================*/
2347
2348 static Uchar shift_reg[7];
2349 static Uchar calendar_cdo;
2350 static int calendar_diff;
2351
get_calendar_work(void)2352 static void get_calendar_work( void )
2353 {
2354 struct tm t;
2355
2356 if( calendar_stop==FALSE ){
2357 time_t now_time;
2358 struct tm *tp;
2359
2360 now_time = time( NULL );
2361 now_time += (time_t)calendar_diff;
2362 tp = localtime( &now_time );
2363 t = *tp;
2364 }else{
2365 t.tm_year = calendar_data[0] + 1900;
2366 t.tm_mon = calendar_data[1];
2367 t.tm_mday = calendar_data[2];
2368 t.tm_wday = calendar_data[3];
2369 t.tm_hour = calendar_data[4];
2370 t.tm_min = calendar_data[5];
2371 t.tm_sec = calendar_data[6];
2372 }
2373
2374 shift_reg[0] = ( t.tm_sec %10 <<4 );
2375 shift_reg[1] = ( t.tm_min %10 <<4 ) | ( t.tm_sec /10 );
2376 shift_reg[2] = ( t.tm_hour%10 <<4 ) | ( t.tm_min /10 );
2377 shift_reg[3] = ( t.tm_mday%10 <<4 ) | ( t.tm_hour/10 );
2378 shift_reg[4] = ( t.tm_wday <<4 ) | ( t.tm_mday/10 );
2379 shift_reg[5] = ( (t.tm_year%100)%10 <<4 ) | ( t.tm_mon+1 );
2380 shift_reg[6] = ( (t.tm_year%100)/10 );
2381 }
set_calendar_work(int x)2382 static void set_calendar_work( int x )
2383 {
2384 #define BCD2INT(b) ((((b)>>4)&0x0f)*10 + ((b)&0x0f))
2385 time_t now_time;
2386 time_t chg_time;
2387 struct tm *tp;
2388 struct tm t;
2389 int i;
2390
2391 static const char *week[]=
2392 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
2393
2394 if(x==0){
2395 if( verbose_io )
2396 printf("Set Clock %02d/%02x(%s) %02x:%02x:%02x\n",
2397 (shift_reg[4]>>4)&0x0f, shift_reg[3], week[ shift_reg[4]&0x07 ],
2398 shift_reg[2], shift_reg[1], shift_reg[0]);
2399
2400 now_time = time( NULL );
2401 now_time += (time_t)calendar_diff;
2402 tp = localtime( &now_time );
2403 t.tm_year = tp->tm_year;
2404
2405 }else{
2406 if( verbose_io )
2407 printf("Set Clock %02x/%02d/%02x(%s) %02x:%02x:%02x\n",
2408 shift_reg[5],
2409 (shift_reg[4]>>4)&0x0f, shift_reg[3], week[ shift_reg[4]&0x07 ],
2410 shift_reg[2], shift_reg[1], shift_reg[0]);
2411
2412 i = BCD2INT( shift_reg[5] );
2413 if( i >= 38 ) t.tm_year = 1900 + i -1900;
2414 else t.tm_year = 2000 + i -1900;
2415 }
2416
2417 t.tm_mon = ((shift_reg[4]>>4)&0x0f) -1;
2418 t.tm_mday = BCD2INT( shift_reg[3] );
2419 t.tm_wday = shift_reg[4]&0x07;
2420 t.tm_hour = BCD2INT( shift_reg[2] );
2421 t.tm_min = BCD2INT( shift_reg[1] );
2422 t.tm_sec = BCD2INT( shift_reg[0] );
2423 t.tm_yday = 0;
2424 t.tm_isdst= 0;
2425
2426 now_time = time( NULL );
2427 chg_time = mktime( &t );
2428
2429 if( now_time != -1 && chg_time != -1 )
2430 calendar_diff = (int)difftime( chg_time, now_time );
2431
2432 #undef BCD2INT
2433 }
2434
2435
calendar_init(void)2436 void calendar_init( void )
2437 {
2438 int i;
2439 for(i=0;i<7;i++) shift_reg[i] = 0;
2440 calendar_cdo = 0;
2441
2442 calendar_diff = 0;
2443 }
2444
calendar_shift_clock(void)2445 void calendar_shift_clock( void )
2446 {
2447 byte x = ( common_out_data>>3 ) & 0x01;
2448
2449 calendar_cdo = shift_reg[0] & 0x01;
2450 shift_reg[0] = ( shift_reg[0]>>1 ) | ( shift_reg[1]<<7 );
2451 shift_reg[1] = ( shift_reg[1]>>1 ) | ( shift_reg[2]<<7 );
2452 shift_reg[2] = ( shift_reg[2]>>1 ) | ( shift_reg[3]<<7 );
2453 shift_reg[3] = ( shift_reg[3]>>1 ) | ( shift_reg[4]<<7 );
2454 shift_reg[4] = ( shift_reg[4]>>1 ) | ( shift_reg[5]<<7 );
2455 shift_reg[5] = ( shift_reg[5]>>1 ) | ( shift_reg[6]<<7 );
2456 shift_reg[6] = ( shift_reg[6]>>1 ) | ( x<<3 );
2457 }
2458
calendar_stlobe(void)2459 void calendar_stlobe( void )
2460 {
2461 switch( common_out_data & 0x7 ){
2462 case 0: /*calendar_init();*/ break; /* ����� */
2463 case 1: calendar_shift_clock(); break; /* ���ե� */
2464 case 2: calendar_shift_clock();
2465 calendar_shift_clock();
2466 calendar_shift_clock();
2467 calendar_shift_clock();
2468 calendar_shift_clock();
2469 calendar_shift_clock();
2470 calendar_shift_clock();
2471 calendar_shift_clock();
2472 calendar_shift_clock();
2473 calendar_shift_clock();
2474 calendar_shift_clock();
2475 calendar_shift_clock();
2476 set_calendar_work(0); break;
2477 case 3: get_calendar_work(); /* ������� */
2478 calendar_shift_clock();
2479 calendar_shift_clock();
2480 calendar_shift_clock();
2481 calendar_shift_clock(); break;
2482 case 4: break;
2483 case 5: break;
2484 case 6: break;
2485 case 7:
2486 switch( shift_reg[6] & 0xf ){
2487
2488 case 0: /*calendar_init();*/ break; /* ����� */
2489 case 1: calendar_shift_clock(); break; /* ���ե� */
2490 case 2: set_calendar_work(1); break; /* �������� */
2491 case 3: get_calendar_work(); break; /* ������� */
2492 case 4: break;
2493 case 5: break;
2494 case 6: break;
2495 case 7: break;
2496 case 8: break;
2497 case 9: break;
2498 case 10: break;
2499 case 11: break;
2500 case 12: break;
2501 case 13: break;
2502 case 14: break;
2503 case 15: /*test_mode();*/ break;
2504 }
2505 break;
2506 }
2507 }
2508
2509
2510 /*===========================================================================*/
2511 /* ����ȥ��뿮�������� */
2512 /*===========================================================================*/
2513
out_ctrl_signal(byte data)2514 void out_ctrl_signal( byte data )
2515 {
2516 byte trg_on = ~ctrl_signal & data;
2517 byte trg_off = ctrl_signal & ~data;
2518
2519 if( trg_on & 0x01 ) printer_stlobe();
2520 if( trg_off & 0x02 ) calendar_stlobe();
2521 if( trg_off & 0x04 ) calendar_shift_clock();
2522
2523 if( data & 0x08 ) set_crtc_sync_bit();
2524 else clr_crtc_sync_bit();
2525
2526 if( (trg_on & (0x80|0x20)) || (trg_off & (0x80|0x20)) ){
2527 xmame_dev_beep_out_data( data );
2528 }
2529
2530 if( trg_on & 0x40 ) keyboard_jop1_strobe();
2531 if( trg_off & 0x40 ) keyboard_jop1_strobe();
2532
2533 ctrl_signal = data;
2534 }
2535
in_ctrl_signal(void)2536 byte in_ctrl_signal( void )
2537 {
2538 return ((ctrl_vrtc << 5 ) |
2539 (calendar_cdo << 4 ) |
2540 ctrl_boot |
2541 monitor_15k );
2542 }
2543
2544
2545
2546
2547
2548
2549
2550
2551 /************************************************************************/
2552 /* ����ν���� (�Ÿ��������Τ�) */
2553 /************************************************************************/
2554 #if 0
2555 void power_on_ram_init( void )
2556 {
2557 int addr, i;
2558 Uchar data;
2559
2560 /* �ᥤ�� RAM ���ü�ʥѥ���������� */
2561
2562 for( addr = 0; addr < 0x10000; addr += 0x100 ){
2563 if( (addr&0x0d00)==0x0100 || (addr&0x0f00)==0x0500 ||
2564 (addr&0x0f00)==0x0a00 || (addr&0x0d00)==0x0c00 ) data = 0xff;
2565 else data = 0x00;
2566
2567 if( addr&0x4000 ) data ^= 0xff;
2568 if( addr&0x8000 ) data ^= 0xff;
2569 if((addr&0xf000)==0xb000 ) data ^= 0xff;
2570 #if 0
2571 if((addr&0xf000)==0xe000 ) data ^= 0xff; /* �Ȥꤢ����ȿž */
2572 /* changed by peach */
2573 #endif
2574
2575 for(i=0;i<4;i++){
2576 memset( &main_ram[ addr + i*64 ], data, 16 );
2577 memset( &main_ram[ addr + i*64 +16 ], data^0xff, 16 );
2578 memset( &main_ram[ addr + i*64 +32 ], data, 16 );
2579 memset( &main_ram[ addr + i*64 +48 ], data^0xff, 16 );
2580 data ^= 0xff;
2581 }
2582 }
2583 if( high_mode ){
2584 for( i=0xf000; i<0x10000; i++ ) main_ram[i] ^= 0xff;
2585 }
2586
2587
2588 /* ��® RAM(��) ���ü�ʥѥ���������� */
2589
2590 memcpy( main_high_ram, &main_ram[0xf000], 0x1000 );
2591 for( addr=0xf000; addr<0x10000; addr++ ) main_ram[addr] ^= 0xff;
2592 }
2593
2594
2595 #else /* FH �ǤϤ��Τ褦�ʵ������뤱�ɡġġ� */
power_on_ram_init(void)2596 void power_on_ram_init( void )
2597 {
2598 int addr, i;
2599 Uchar data;
2600
2601 /* �ᥤ�� RAM ���ü�ʥѥ���������� */
2602
2603 for( addr = 0; addr < 0x4000; addr += 0x100 ){
2604
2605 if( ((addr & 0x0d00) == 0x0100) || /* x100, x300 */
2606 ((addr & 0x0d00) == 0x0c00) ){ /* xc00, xe00 */
2607 data = 0xff;
2608 }else if( ((addr & 0x0f00) == 0x0500) &&
2609 ((addr & 0x2000) == 0x0000) ){ /* 0500, 1500 */
2610 data = 0xff;
2611 }else if( ((addr & 0x0f00) == 0x0a00) &&
2612 ((addr & 0x3000) != 0x0000) ){ /* 1a00, 2a00, 3a00 */
2613 data = 0xff;
2614 }else{
2615 data = 0x00;
2616 }
2617
2618 for(i=0;i<4;i++){
2619 memset( &main_ram[ addr + i*64 ], data, 16 );
2620 memset( &main_ram[ addr + i*64 +16 ], data^0xff, 16 );
2621 memset( &main_ram[ addr + i*64 +32 ], data, 16 );
2622 memset( &main_ram[ addr + i*64 +48 ], data^0xff, 16 );
2623 data ^= 0xff;
2624 }
2625 }
2626
2627 for( addr = 0x4000; addr < 0x8000; addr += 0x100 ){
2628 for( i=0; i<0x100; i++ ){
2629 main_ram[ addr + i ] = main_ram[ addr + i - 0x4000 ] ^ 0xff;
2630 }
2631 }
2632
2633 for( addr = 0x8000; addr < 0x10000; addr += 0x100 ){
2634 memcpy( &main_ram[ addr ], &main_ram[ 0x7f00 - (addr - 0x8000) ], 0x100 );
2635 }
2636
2637 memcpy( &main_high_ram[0], &main_ram[0xf000], 0x1000 );
2638
2639 /*
2640 memset( &main_ram[0x9000], 0x00, 0x100 );
2641 main_ram[0x90ff] = 0xff;
2642 memset( &main_ram[0xbf00], 0x00, 0x100 );
2643 main_ram[0xbfff] = 0xff;
2644 */
2645 for( addr = 0xff00; addr < 0xffff; addr ++ ){
2646 main_ram[ addr ] = 0xff;
2647 }
2648 main_ram[ 0xffff ] = 0x00;
2649
2650 /* ���ͤޤǤˡ��ʲ��Υ��եȤ�RAM�ν���ͤ�ȤäƤ���褦����
2651 �������� : 0xffff �� 0x00 �Ǥ��뤳��
2652 ŷ�Ȥ����θ��2 : 0xfff8��0xffff �� ���Х��Ȥ�OR !=0x00 �Ǥ��뤳��
2653 ŷ�Ȥ����θ�� : �������
2654 */
2655 }
2656 #endif
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667 /************************************************************************/
2668 /* PC88 �ᥤ���ƥ� ����� */
2669 /************************************************************************/
2670
bootup_work_init(void)2671 static void bootup_work_init(void)
2672 {
2673 /* V1�⡼�ɤΥС������ξ������ʲ������ѹ����� */
2674
2675 if (set_version) ROM_VERSION = set_version;
2676 else ROM_VERSION = rom_version;
2677
2678 /* ��ư�ǥХ���(ROM/DISK)̤��λ� */
2679
2680 if (boot_from_rom == BOOT_AUTO) {
2681 if (disk_image_exist(0)) /* �ǥ�������������DISK */
2682 boot_from_rom = FALSE;
2683 else /* ����ʳ��ϡ� ROM */
2684 boot_from_rom = TRUE;
2685 }
2686
2687 /* ��ư���� BASIC�⡼��̤��λ� */
2688
2689 if (boot_basic == BASIC_AUTO) {
2690 if (ROM_VERSION >= '4') /* SR �ʹߤϡ�V2 */
2691 boot_basic = BASIC_V2;
2692 else /* ��������ϡ�V1S */
2693 boot_basic = BASIC_V1S;
2694 }
2695
2696 /* �������(I/II)�Υݡ��Ȥ����� */
2697
2698 if (sound_board == SOUND_II) {
2699
2700 if (ROM_VERSION >= '8') /* FH/MH �ʹߤϡ�44��47H */
2701 sound_port = SD_PORT_44_45 | SD_PORT_46_47;
2702 else if (ROM_VERSION >= '4') /* SR �ʹߤϡ�44��45,A8��ADH */
2703 sound_port = SD_PORT_44_45 | SD_PORT_A8_AD;
2704 else /* ��������ϡ� A8��ADH */
2705 sound_port = SD_PORT_A8_AD;
2706
2707 } else {
2708
2709 if (ROM_VERSION >= '4') /* SR�ʹߤϡ�44��45H */
2710 sound_port = SD_PORT_44_45;
2711 else /* ��������ϡ������� */
2712 /*sound_port = SD_PORT_A8_AD;*/
2713 sound_port = 0; /* �б����ʤ��ʤ� 0 */
2714 }
2715 }
2716
2717
pc88main_init(int init)2718 void pc88main_init( int init )
2719 {
2720 int i;
2721
2722 bootup_work_init();
2723
2724 /* CPU �������� */
2725
2726 if( init == INIT_POWERON || init == INIT_RESET ){
2727
2728 z80_reset( &z80main_cpu );
2729 }
2730
2731 pc88main_bus_setup();
2732
2733 z80main_cpu.intr_update = main_INT_update;
2734 z80main_cpu.intr_ack = main_INT_chk;
2735
2736 z80main_cpu.break_if_halt = FALSE; /* for debug */
2737 z80main_cpu.PC_prev = z80main_cpu.PC; /* dummy for monitor */
2738
2739 #ifdef DEBUGLOG
2740 z80main_cpu.log = TRUE;
2741 #else
2742 z80main_cpu.log = FALSE;
2743 #endif
2744
2745
2746 /* RAM���Ÿ��������ѥ�����ǽ���� */
2747
2748 if( init == INIT_POWERON ){
2749 power_on_ram_init();
2750 }
2751
2752
2753 /* �ե���Ƚ���� */
2754
2755 if( init == INIT_POWERON || init == INIT_RESET ){
2756
2757 memory_reset_font();
2758 }else{
2759 memory_set_font();
2760 }
2761
2762
2763 /* �����ܡ��ɽ���� */
2764
2765 if( init == INIT_POWERON || init == INIT_STATELOAD ){
2766 keyboard_reset();
2767 }
2768
2769
2770
2771 printer_init(); /* PRINTER ���������ʤ� */
2772
2773 if( init == INIT_POWERON || init == INIT_RESET ){
2774
2775 sio_init();
2776
2777 main_INT_init();
2778
2779 crtc_init();
2780 dmac_init();
2781 calendar_init();
2782 keyboard_jop1_reset();
2783 sound_board_init();
2784 pio_init();
2785
2786
2787 dipsw_1 = (boot_dipsw ) & SW_1_MASK;
2788 dipsw_2 = (boot_dipsw>>8) & SW_2_MASK;
2789
2790 switch( boot_basic ){
2791 case BASIC_N:
2792 dipsw_1 &= ~SW_N88;
2793 dipsw_2 |= SW_V1;
2794 dipsw_2 &= ~SW_H;
2795 high_mode = FALSE;
2796 break;
2797 case BASIC_V1S:
2798 dipsw_1 |= SW_N88;
2799 dipsw_2 |= SW_V1;
2800 dipsw_2 &= ~SW_H;
2801 high_mode = FALSE;
2802 break;
2803 case BASIC_V1H:
2804 dipsw_1 |= SW_N88;
2805 dipsw_2 |= SW_V1;
2806 dipsw_2 |= SW_H;
2807 high_mode = TRUE;
2808 break;
2809 case BASIC_V2:
2810 dipsw_1 |= SW_N88;
2811 dipsw_2 &= ~SW_V1;
2812 dipsw_2 |= SW_H;
2813 high_mode = TRUE;
2814 break;
2815 }
2816
2817 ctrl_boot = (boot_from_rom) ? SW_ROMBOOT : 0;
2818 memory_bank = MEMORY_BANK_MAIN;
2819 cpu_clock = (boot_clock_4mhz) ? SW_4MHZ : 0;
2820
2821 sys_ctrl = 0x31;
2822 grph_ctrl = 0x31;
2823 misc_ctrl = 0x90;
2824 ALU1_ctrl = 0x77;
2825 ALU2_ctrl = 0x00;
2826 ctrl_signal = 0x0f;
2827 grph_pile = 0x00;
2828 /*baudrate_sw = 0;*/
2829 window_offset = 0x0000;
2830 ext_rom_bank = 0xff;
2831
2832 ext_ram_ctrl = 0;
2833 ext_ram_bank = 0;
2834
2835 jisho_rom_ctrl = JISHO_NOT_SELECT;
2836 jisho_rom_bank = 0;
2837
2838 vram_bg_palette.blue = 0;
2839 vram_bg_palette.red = 0;
2840 vram_bg_palette.green = 0;
2841 for( i=0; i<8; i++ ){
2842 vram_palette[ i ].blue = (i&1) ? 7 : 0;
2843 vram_palette[ i ].red = (i&2) ? 7 : 0;
2844 vram_palette[ i ].green = (i&4) ? 7 : 0;
2845 }
2846
2847 intr_level = 7;
2848 intr_priority = 0;
2849 intr_sio_enable = 0x00;
2850 intr_vsync_enable = 0x00;
2851 intr_rtc_enable = 0x00;
2852 }
2853
2854 main_memory_mapping_0000_7fff();
2855 main_memory_mapping_8000_83ff();
2856 main_memory_mapping_c000_ffff();
2857 main_memory_vram_mapping();
2858
2859
2860 /* CRTC/DMAC��Ϣ�ˤ������ */
2861 set_text_display();
2862 frameskip_blink_reset();
2863
2864 /* ���ꥢ��ޥ�������� */
2865 if (use_siomouse) {
2866 sio_mouse_init(TRUE);
2867 }
2868
2869 /* ������ɤˤĤ��ơ����� */
2870 if( init == INIT_STATELOAD ){
2871 sound_output_after_stateload();
2872 }
2873
2874 }
2875
2876
2877 /************************************************************************/
2878 /* PC88 �ᥤ���ƥ� ��λ */
2879 /************************************************************************/
pc88main_term(void)2880 void pc88main_term( void )
2881 {
2882 printer_term();
2883 sio_term();
2884 }
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895 /************************************************************************/
2896 /* �֥졼���ݥ���ȴ�Ϣ */
2897 /************************************************************************/
check_break_point(int type,word addr,byte data,char * str)2898 INLINE void check_break_point( int type, word addr, byte data, char *str )
2899 {
2900 int i;
2901
2902 if (quasi88_is_monitor()) return; /* ��˥����⡼�ɻ��ϥ��롼 */
2903 for( i=0; i<NR_BP; i++ ){
2904 if( break_point[BP_MAIN][i].type == type &&
2905 break_point[BP_MAIN][i].addr == addr ){
2906 printf( "*** Break at %04x *** "
2907 "( MAIN - #%d [ %s %04XH , data = %02XH ]\n",
2908 z80main_cpu.PC.W, i+1, str, addr, data );
2909 quasi88_debug();
2910 break;
2911 }
2912 }
2913 }
2914
main_fetch_with_BP(word addr)2915 byte main_fetch_with_BP( word addr )
2916 {
2917 byte data = main_fetch( addr );
2918 check_break_point( BP_READ, addr, data, "FETCH from" );
2919 return data;
2920 }
2921
main_mem_read_with_BP(word addr)2922 byte main_mem_read_with_BP( word addr )
2923 {
2924 byte data = main_mem_read( addr );
2925 check_break_point( BP_READ, addr, data, "READ from" );
2926 return data;
2927 }
2928
main_mem_write_with_BP(word addr,byte data)2929 void main_mem_write_with_BP( word addr, byte data )
2930 {
2931 main_mem_write( addr, data );
2932 check_break_point( BP_WRITE, addr, data, "WRITE to" );
2933 }
2934
main_io_in_with_BP(byte port)2935 byte main_io_in_with_BP( byte port )
2936 {
2937 byte data = main_io_in( port );
2938 check_break_point( BP_IN, port, data, "IN from" );
2939 return data;
2940 }
2941
main_io_out_with_BP(byte port,byte data)2942 void main_io_out_with_BP( byte port, byte data )
2943 {
2944 main_io_out( port, data );
2945 check_break_point( BP_OUT, port, data, "OUT to" );
2946 }
2947
2948
2949
2950 /************************************************************************/
2951 /* */
2952 /************************************************************************/
pc88main_bus_setup(void)2953 void pc88main_bus_setup( void )
2954 {
2955 #ifdef USE_MONITOR
2956
2957 int i, buf[4];
2958 for( i=0; i<4; i++ ) buf[i]=0;
2959 for( i=0; i<NR_BP; i++ ){
2960 switch( break_point[BP_MAIN][i].type ){
2961 case BP_READ: buf[0]++; break;
2962 case BP_WRITE: buf[1]++; break;
2963 case BP_IN: buf[2]++; break;
2964 case BP_OUT: buf[3]++; break;
2965 }
2966 }
2967
2968 if( memory_wait || highspeed_mode ){
2969 if( buf[0] ) z80main_cpu.fetch = main_fetch_with_BP;
2970 else z80main_cpu.fetch = main_fetch;
2971 }else{
2972 if( buf[0] ) z80main_cpu.fetch = main_mem_read_with_BP;
2973 else z80main_cpu.fetch = main_mem_read;
2974 }
2975
2976 if( buf[0] ) z80main_cpu.mem_read = main_mem_read_with_BP;
2977 else z80main_cpu.mem_read = main_mem_read;
2978
2979 if( buf[1] ) z80main_cpu.mem_write = main_mem_write_with_BP;
2980 else z80main_cpu.mem_write = main_mem_write;
2981
2982 if( buf[2] ) z80main_cpu.io_read = main_io_in_with_BP;
2983 else z80main_cpu.io_read = main_io_in;
2984
2985 if( buf[3] ) z80main_cpu.io_write = main_io_out_with_BP;
2986 else z80main_cpu.io_write = main_io_out;
2987
2988 #else
2989
2990 if( memory_wait || highspeed_mode ){
2991 z80main_cpu.fetch = main_fetch;
2992 }else{
2993 z80main_cpu.fetch = main_mem_read;
2994 }
2995 z80main_cpu.mem_read = main_mem_read;
2996 z80main_cpu.mem_write = main_mem_write;
2997 z80main_cpu.io_read = main_io_in;
2998 z80main_cpu.io_write = main_io_out;
2999
3000 #endif
3001 }
3002
3003
3004
3005
3006 /***********************************************************************
3007 * ���ơ��ȥ��ɡ����ơ��ȥ�����
3008 ************************************************************************/
3009
3010 #define SID "MAIN"
3011 #define SID2 "MAI2"
3012
3013 static T_SUSPEND_W suspend_pc88main_work[]=
3014 {
3015 { TYPE_STR, &file_tape[0][0], },
3016 { TYPE_STR, &file_tape[1][0], },
3017
3018 { TYPE_INT, &boot_basic, },
3019 { TYPE_INT, &boot_dipsw, },
3020 { TYPE_INT, &boot_from_rom, },
3021 { TYPE_INT, &boot_clock_4mhz, },
3022 { TYPE_INT, &monitor_15k, },
3023
3024 { TYPE_PAIR, &z80main_cpu.AF, },
3025 { TYPE_PAIR, &z80main_cpu.BC, },
3026 { TYPE_PAIR, &z80main_cpu.DE, },
3027 { TYPE_PAIR, &z80main_cpu.HL, },
3028 { TYPE_PAIR, &z80main_cpu.IX, },
3029 { TYPE_PAIR, &z80main_cpu.IY, },
3030 { TYPE_PAIR, &z80main_cpu.PC, },
3031 { TYPE_PAIR, &z80main_cpu.SP, },
3032 { TYPE_PAIR, &z80main_cpu.AF1, },
3033 { TYPE_PAIR, &z80main_cpu.BC1, },
3034 { TYPE_PAIR, &z80main_cpu.DE1, },
3035 { TYPE_PAIR, &z80main_cpu.HL1, },
3036 { TYPE_BYTE, &z80main_cpu.I, },
3037 { TYPE_BYTE, &z80main_cpu.R, },
3038 { TYPE_BYTE, &z80main_cpu.R_saved, },
3039 { TYPE_CHAR, &z80main_cpu.IFF, },
3040 { TYPE_CHAR, &z80main_cpu.IFF2, },
3041 { TYPE_CHAR, &z80main_cpu.IM, },
3042 { TYPE_CHAR, &z80main_cpu.HALT, },
3043 { TYPE_INT, &z80main_cpu.INT_active,},
3044 { TYPE_INT, &z80main_cpu.icount, },
3045 { TYPE_INT, &z80main_cpu.state0, },
3046 { TYPE_INT, &z80main_cpu.skip_intr_chk, },
3047 { TYPE_CHAR, &z80main_cpu.log, },
3048 { TYPE_CHAR, &z80main_cpu.break_if_halt, },
3049
3050 { TYPE_INT, &high_mode, },
3051
3052 { TYPE_BYTE, &dipsw_1, },
3053 { TYPE_BYTE, &dipsw_2, },
3054 { TYPE_BYTE, &ctrl_boot, },
3055 { TYPE_INT, &memory_bank, },
3056 { TYPE_BYTE, &cpu_clock, },
3057
3058 { TYPE_BYTE, &common_out_data, },
3059 { TYPE_BYTE, &misc_ctrl, },
3060 { TYPE_BYTE, &ALU1_ctrl, },
3061 { TYPE_BYTE, &ALU2_ctrl, },
3062 { TYPE_BYTE, &ctrl_signal, },
3063 { TYPE_BYTE, &baudrate_sw, },
3064 { TYPE_WORD, &window_offset, },
3065 { TYPE_BYTE, &ext_rom_bank, },
3066 { TYPE_BYTE, &ext_ram_ctrl, },
3067 { TYPE_BYTE, &ext_ram_bank, },
3068
3069 { TYPE_PAIR, &kanji1_addr, },
3070 { TYPE_PAIR, &kanji2_addr, },
3071
3072 { TYPE_BYTE, &jisho_rom_bank, },
3073 { TYPE_BYTE, &jisho_rom_ctrl, },
3074
3075 { TYPE_INT, &calendar_stop, },
3076 { TYPE_CHAR, &calendar_data[0], },
3077 { TYPE_CHAR, &calendar_data[1], },
3078 { TYPE_CHAR, &calendar_data[2], },
3079 { TYPE_CHAR, &calendar_data[3], },
3080 { TYPE_CHAR, &calendar_data[4], },
3081 { TYPE_CHAR, &calendar_data[5], },
3082 { TYPE_CHAR, &calendar_data[6], },
3083
3084 { TYPE_INT, &cmt_speed, },
3085 { TYPE_INT, &cmt_intr, },
3086 { TYPE_INT, &cmt_wait, },
3087
3088 { TYPE_INT, &highspeed_mode, },
3089 { TYPE_INT, &memory_wait, },
3090
3091 { TYPE_INT, &ALU_buf.l, }, /* TYPE_CHAR, ALU_buf.c[0]-[3] ? */
3092 { TYPE_INT, &ALU_comp.l, }, /* TYPE_CHAR, ALU_comp.c[0]-[3] ? */
3093
3094 { TYPE_INT, &pcg_data, },
3095 { TYPE_INT, &pcg_addr, },
3096
3097 { TYPE_INT, &sio_instruction, },
3098 { TYPE_BYTE, &sio_mode, },
3099 { TYPE_BYTE, &sio_command, },
3100 { TYPE_INT, &sio_data_exist, },
3101 { TYPE_BYTE, &sio_data, },
3102
3103 { TYPE_INT, &com_X_flow, },
3104
3105 { TYPE_INT, &cmt_dummy_read_cnt, },
3106 { TYPE_INT, &cmt_skip, },
3107 { TYPE_INT, &cmt_skip_data, },
3108
3109 { TYPE_LONG, &cmt_read_chars, },
3110
3111 { TYPE_CHAR, &shift_reg[0], },
3112 { TYPE_CHAR, &shift_reg[1], },
3113 { TYPE_CHAR, &shift_reg[2], },
3114 { TYPE_CHAR, &shift_reg[3], },
3115 { TYPE_CHAR, &shift_reg[4], },
3116 { TYPE_CHAR, &shift_reg[5], },
3117 { TYPE_CHAR, &shift_reg[6], },
3118 { TYPE_CHAR, &calendar_cdo, },
3119 { TYPE_INT, &calendar_diff, },
3120
3121 { TYPE_END, 0 },
3122 };
3123
3124 static T_SUSPEND_W suspend_pc88main_work2[]=
3125 {
3126 { TYPE_INT, &use_siomouse, },
3127 { TYPE_END, 0 },
3128 };
3129
3130
statesave_pc88main(void)3131 int statesave_pc88main( void )
3132 {
3133 /*if( fp_ti ) printf("%d\n",osd_ftell(fp_ti));*/
3134
3135 if( statesave_table( SID, suspend_pc88main_work ) != STATE_OK ) return FALSE;
3136
3137 if( statesave_table(SID2, suspend_pc88main_work2) != STATE_OK ) return FALSE;
3138
3139 return TRUE;
3140 }
3141
stateload_pc88main(void)3142 int stateload_pc88main( void )
3143 {
3144 if( stateload_table( SID, suspend_pc88main_work ) != STATE_OK ) return FALSE;
3145
3146 if( stateload_table(SID2, suspend_pc88main_work2) != STATE_OK ) {
3147
3148 /* ��С������ʤ顢�ߤΤ��� */
3149
3150 printf( "stateload : Statefile is old. (ver 0.6.0, 1, 2 or 3?)\n" );
3151
3152 use_siomouse = FALSE;
3153 }
3154
3155
3156 cmt_stateload_chars = cmt_read_chars;
3157 cmt_read_chars = 0;
3158
3159 cmt_stateload_skip = cmt_skip;
3160
3161 return TRUE;
3162 }
3163