1 /************************************************************************/
2 /* */
3 /* �����ߤΥ��ߥ�졼�� */
4 /* */
5 /************************************************************************/
6
7 #include "quasi88.h"
8 #include "initval.h"
9 #include "intr.h"
10
11 #include "pc88cpu.h"
12 #include "pc88main.h"
13 #include "screen.h"
14 #include "crtcdmac.h"
15 #include "keyboard.h"
16 #include "soundbd.h"
17
18 #include "event.h"
19 #include "emu.h"
20 #include "snddrv.h"
21 #include "wait.h"
22 #include "suspend.h"
23
24
25
26 int intr_level; /* OUT[E4] �����ߥ�٥� */
27 int intr_priority; /* OUT[E4] ������ͥ���� */
28 int intr_sio_enable; /* OUT[E6] �����ߥޥ��� SIO */
29 int intr_vsync_enable; /* OUT[E6] �����ߥޥ��� VSYNC */
30 int intr_rtc_enable; /* OUT[E6] �����ߥޥ��� RTC */
31
32
33
34 double cpu_clock_mhz = DEFAULT_CPU_CLOCK_MHZ; /* MAIN CPU Clock [MHz] */
35 double sound_clock_mhz = DEFAULT_SOUND_CLOCK_MHZ; /* SOUND chip Clock [MHz] */
36 double vsync_freq_hz = DEFAULT_VSYNC_FREQ_HZ; /* VSYNC ������� [Hz] */
37
38 int wait_rate = 100; /* ��������Ĵ�� ��Ψ [%] */
39 int wait_by_sleep = TRUE; /* ��������Ĵ���� sleep ���� */
40
41
42
43 #define CPU_CLOCK_MHZ cpu_clock_mhz
44 #define SOUND_CLOCK_MHZ sound_clock_mhz
45 #define VSYNC_FREQ_HZ vsync_freq_hz
46
47 #if 1 /* VSYNC�����ߤ� VRTC�Υ����ߥ餷�Ƥߤ� */
48
49 /* 0.2�饤�� (30���ơ��Ȥ��餤) �������餹 �ġ� �ʤ㤦�� */
50
51 #define VRTC_TOP (( 47.8 ) /448.0)
52 #define VRTC_DISP (( 400.0 ) /448.0)
53 #define VRTC_BOTTOM (( 0.2 ) /448.0)
54
55 /* 7�饤�餹?? �����㤦�� */
56 /*
57 #define VRTC_TOP ((8 + 33)/448.0)
58 #define VRTC_DISP (( 400 ) /448.0)
59 #define VRTC_BOTTOM (( 7 ) /448.0)
60 */
61
62 #else /* �ʲ����ͤ� ver0.6.0 �����Υ����ߥˤʤ�Ϥ� */
63 #define VRTC_TOP (( 48 ) /448.0)
64 #define VRTC_DISP (( 402 ) /448.0) /* ǰ�Τ��� +2 ;ʬ��*/
65 #define VRTC_BOTTOM (( 0 ) /448.0)
66 #endif
67
68 #define RTC_FREQ_HZ (600)
69
70 #define TIMER_A_CONST (12)
71 #define TIMER_B_CONST (192)
72
73 #define CPU_CLOCK (CPU_CLOCK_MHZ * 1000000)
74
75 /*****************************************************************************/
76
77 int state_of_cpu = 0; /* �ᥤ��CPU�������������ơ��ȿ� */
78 /* VSYNC���ȯ�����˽�������� */
79 /* main_INT_update() �ƽл��˲û� */
80 /* (���δؿ���������˸ƽФ����) */
81 /* */
82 /* VSYNCȯ�����鸽�������˽������� */
83 /* ���ơ��ȿ��ϡ��ʲ��μ��ˤʤ롣*/
84 /* */
85 /* state_of_cpu+z80main_cpu.state0 */
86
87 int state_of_vsync; /* VSYNC 1����������Υ��ơ��ȿ� */
88
89 int no_wait = FALSE; /* �������Ȥʤ� */
90
91 int boost = 1; /* �֡����� */
92 int boost_cnt;
93
94
95 int RS232C_flag = FALSE; /* RS232C */
96 static int rs232c_intr_base;
97 static int rs232c_intr_timer;
98
99 int VSYNC_flag = FALSE; /* VSYNC */
100 static int vsync_intr_base;
101 static int vsync_intr_timer;
102
103 int ctrl_vrtc = 1; /* VRTC (��ľ������:1or3 / ɽ����:2) */
104 static int vrtc_base;
105 static int vrtc_base2;
106 static int vrtc_timer;
107
108 int RTC_flag = FALSE; /* RTC */
109 static int rtc_intr_base;
110 static int rtc_intr_timer;
111
112 int SOUND_flag = FALSE; /* SOUND Timer-A/Timer-B */
113 static int SOUND_level = FALSE;
114 static int SOUND_edge = FALSE;
115 static int sd_A_intr_base;
116 static int sd_A_intr_timer;
117 static int sd_B_intr_base;
118 static int sd_B_intr_timer;
119 static int sd2_BRDY_intr_base;
120 static int sd2_BRDY_intr_timer;
121 static int sd2_EOS_intr_base;
122 static int sd2_EOS_intr_timer;
123
124 static int vsync_count; /* test (��¬��) */
125
126
127
128
129 /*------------------------------------------------------
130 * �����ޡ������ߥ��ߥ�졼�ȤΥ��������
131 * VSYNC / VRTC / RTC ����ϵ�ư���˽����
132 * RS232C / Timer-A / TImer-B �����������˽����
133 *------------------------------------------------------*/
134
135 /*
136 * �����ߥߥ�졼�Ƚ���� �� Z80 �ε�ư���˸Ƥ�
137 */
interval_work_init_generic(void)138 static void interval_work_init_generic( void )
139 {
140 vsync_intr_timer = vsync_intr_base = (int) (CPU_CLOCK / VSYNC_FREQ_HZ);
141 vrtc_timer = vrtc_base = (int) (vsync_intr_base * VRTC_TOP);
142 vrtc_base2 = (int) (vsync_intr_base * VRTC_DISP);
143
144 rtc_intr_timer = rtc_intr_base = (int) (CPU_CLOCK / RTC_FREQ_HZ);
145
146 state_of_vsync = vsync_intr_base;
147 state_of_cpu = 0;
148
149 if( boost < 1 ) boost = 1;
150 boost_cnt = 0;
151 }
152
153
154 /*
155 * RS232C�����ߥ��ߥ�졼�Ƚ���� �� Z80��ư���˸Ƥ�
156 */
interval_work_init_RS232C(void)157 static void interval_work_init_RS232C( void )
158 {
159 interval_work_set_RS232C( 0, 0 );
160 }
161
162 /*
163 * ������ɳ����ߥ��ߥ�졼�Ƚ���� �� Z80��ư���˸Ƥ�
164 */
interval_work_init_TIMER_A(void)165 static void interval_work_init_TIMER_A( void )
166 {
167 interval_work_set_TIMER_A();
168 sd_A_intr_timer = sd_A_intr_base;
169 }
interval_work_init_TIMER_B(void)170 static void interval_work_init_TIMER_B( void )
171 {
172 interval_work_set_TIMER_B();
173 sd_B_intr_timer = sd_B_intr_base;
174 }
175
176
177
178
179 /*
180 * �������ߥ��ߥ�졼�Ƚ���� �� Z80��ư���䡢����å��ѹ����ʤɤ˸Ƥ�
181 */
interval_work_init_all(void)182 void interval_work_init_all( void )
183 {
184 interval_work_init_generic();
185 interval_work_init_RS232C();
186 interval_work_init_TIMER_A();
187 interval_work_init_TIMER_B();
188 }
189
190
191
192 /*
193 * RS232C�����ߥ��ߥ�졼�Ⱥƽ���� �� RS232C���������˸Ƥ�
194 */
interval_work_set_RS232C(int bps,int framesize)195 void interval_work_set_RS232C( int bps, int framesize )
196 {
197 if( bps == 0 || framesize == 0 ){
198 rs232c_intr_base = 0x7fffffff;
199 }else{
200 rs232c_intr_base = CPU_CLOCK / ( (double)bps / (double)framesize );
201 if( rs232c_intr_base < 100 ) rs232c_intr_base = 100;
202 }
203 rs232c_intr_timer = rs232c_intr_base;
204 }
205
206
207
boost_change(int new_val)208 void boost_change( int new_val )
209 {
210 if( new_val < 0 ) new_val = 1;
211
212 if( boost != new_val ){
213 double rate = (double)new_val / boost;
214
215 sd_A_intr_base *= rate;
216 sd_A_intr_timer *= rate;
217 sd_B_intr_base *= rate;
218 sd_B_intr_timer *= rate;
219 boost = new_val;
220 boost_cnt = 0;
221 }
222 }
223
224
225
226 /************************************************************************/
227 /* �����ߤ˴ؤ�� ������ɥ쥸�����������ν��� */
228 /************************************************************************/
229 /*
230 * ������ɤΥ����ޥץꥻ�å��� �ѹ����˸Ƥ�
231 */
interval_work_set_TIMER_A(void)232 void interval_work_set_TIMER_A( void )
233 {
234 sd_A_intr_base = TIMER_A_CONST * sound_prescaler * (1024 - sound_TIMER_A)
235 * ( CPU_CLOCK_MHZ / SOUND_CLOCK_MHZ );
236 sd_A_intr_base *= boost;
237 }
interval_work_set_TIMER_B(void)238 void interval_work_set_TIMER_B( void )
239 {
240 sd_B_intr_base = TIMER_B_CONST * sound_prescaler * (256 - sound_TIMER_B)
241 * ( CPU_CLOCK_MHZ / SOUND_CLOCK_MHZ );
242 sd_B_intr_base *= boost;
243 }
244
245 /*
246 * ������ɤ� �Ƽ�ե饰 ����� �ץꥹ�����顼���ѹ����˸Ƥ�
247 */
248 static int sound_flags_update = 0;
249 static int sound_prescaler_update = 0;
250
change_sound_flags(int port)251 void change_sound_flags( int port )
252 {
253 sound_flags_update = (int)port;
254 if( highspeed_flag == FALSE ) CPU_REFRESH_INTERRUPT();
255 }
change_sound_prescaler(int new_prescaler)256 void change_sound_prescaler( int new_prescaler )
257 {
258 sound_prescaler_update = new_prescaler;
259 if( highspeed_flag == FALSE ) CPU_REFRESH_INTERRUPT();
260 }
261
262
263
264
265 /*
266 * ������ɤΥץꥹ�����顼�͡��Ƽ�ե饰�ѹ����κݤˡ��ե饰���������롣
267 * �����߹�����˸ƤФ�롣
268 */
check_sound_parm_update(void)269 static void check_sound_parm_update( void )
270 {
271 byte data;
272
273 if( sound_prescaler_update ){ /* ʬ�� �ѹ������ä��� */
274 /* �������ͤ� (�ѹ���/�ѹ���)�ܤ��� */
275 /* �������ͤΤĤ��Ĥޤ碌�롣 */
276 sd_A_intr_base = sd_A_intr_base * sound_prescaler_update/sound_prescaler;
277 sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update/sound_prescaler;
278 sd_B_intr_base = sd_B_intr_base * sound_prescaler_update/sound_prescaler;
279 sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update/sound_prescaler;
280 sound_prescaler = sound_prescaler_update;
281 sound_prescaler_update = 0;
282 }
283
284
285 switch( sound_flags_update ){ /* �ե饰�ѹ������ä��顢���� */
286
287 case 0x27: /*---------------- RESET_B/A | ENABLE_B/A | LOAD_B/A */
288 data = sound_reg[0x27];
289
290 /* LOAD��Ω���夬��ˡ����������� */
291 if( (sound_LOAD_A==0) && (data&0x01) ) sd_A_intr_timer = sd_A_intr_base;
292 if( (sound_LOAD_B==0) && (data&0x02) ) sd_B_intr_timer = sd_B_intr_base;
293 sound_LOAD_A = data & 0x01;
294 sound_LOAD_B = data & 0x02;
295
296 /* ENABLE ����¸ */
297 sound_ENABLE_A = ( data & 0x04 ) ? 1 : 0;
298 sound_ENABLE_B = ( data & 0x08 ) ? 1 : 0;
299
300 /* RESET �� 1 �ʤ顢�ե饰���ꥢ */
301 if( data & 0x10 ) sound_FLAG_A = 0;
302 if( data & 0x20 ) sound_FLAG_B = 0;
303 break;
304
305 case 0x29: /*---------------- EN_ZERO/BRDY/EOS/TB/TA */
306 if( sound_board==SOUND_II ){
307 data = sound_reg[0x29];
308 sound2_EN_TA = data & 0x01;
309 sound2_EN_TB = data & 0x02;
310 sound2_EN_EOS = data & 0x04;
311 sound2_EN_BRDY = data & 0x08;
312 sound2_EN_ZERO = data & 0x10;
313 }
314 break;
315
316 case 0x10: /*---------------- IRQ_RET | MSK_ZERO/BRDY/EOS/TB/TA */
317 data = sound2_reg[0x10];
318 if( data & 0x80 ){
319 sound_FLAG_A = 0;
320 sound_FLAG_B = 0;
321 sound2_FLAG_EOS = 0;
322 sound2_FLAG_BRDY = 0;
323 sound2_FLAG_ZERO = 0;
324 }else{
325 sound2_MSK_TA = data & 0x01;
326 sound2_MSK_TB = data & 0x02;
327 sound2_MSK_EOS = data & 0x04;
328 sound2_MSK_BRDY = data & 0x08;
329 sound2_MSK_ZERO = data & 0x10;
330 }
331 break;
332
333 }
334
335 sound_flags_update = 0;
336
337 }
338
339
340 /*
341 * ������ɥܡ���II��Ϣ
342 */
interval_work_set_BDRY(void)343 void interval_work_set_BDRY( void )
344 {
345 sd2_BRDY_intr_base = sound2_intr_base * 2 * ( CPU_CLOCK_MHZ / 4.0 );
346 sd2_BRDY_intr_timer = sd2_BRDY_intr_base;
347
348 /*printf("%d\n",sd2_BRDY_intr_base);*/
349 }
interval_work_set_EOS(int length)350 void interval_work_set_EOS( int length )
351 {
352 sd2_EOS_intr_base = sd2_BRDY_intr_base * length;
353 sd2_EOS_intr_timer = sd2_EOS_intr_base;
354
355 /*printf("%d\n",sd2_EOS_intr_base);*/
356 }
357
358
359
360 /************************************************************************/
361 /* 1/60 sec �γ�������˹Ԥʤ����� */
362 /************************************************************************/
363
364 /* #define ���ȡ�VSYNC���ϻ���ɽ����#undef ����VBLANK ��λ����ɽ�� */
365 #undef DRAW_SCREEN_AT_VSYNC_START
366
vsync(void)367 static void vsync( void )
368 {
369 vsync_count++; /* test (��¬��) */
370
371 if( ++ boost_cnt >= boost ){
372 boost_cnt = 0;
373 }
374
375 if( boost_cnt == 0 ){
376 CPU_BREAKOFF();
377 quasi88_event_flags |= EVENT_AUDIO_UPDATE;
378 #ifdef DRAW_SCREEN_AT_VSYNC_START
379 quasi88_event_flags |= EVENT_FRAME_UPDATE;
380 #endif
381 }
382
383 SET_DMA_WAIT_COUNT(); /* DMA������������å� */
384
385
386 state_of_cpu -= state_of_vsync; /* (== vsync_intr_base) */
387 }
388
quasi88_info_vsync_count(void)389 int quasi88_info_vsync_count(void)
390 {
391 return vsync_count;
392 }
393
394
395
396
397
398
set_INT_active(void)399 static void set_INT_active( void )
400 {
401 if( intr_level==0 ){ /* ��٥����� 0 */
402 z80main_cpu.INT_active = FALSE; /* �����ߤϼ����դ��ʤ� */
403 }
404 else if( intr_level>=1 && /* ��٥����� 1 */
405 /*intr_sio_enable &&*/ RS232C_flag ){ /* RS232S ���� ������ */
406 z80main_cpu.INT_active = TRUE;
407 }
408 else if( intr_level>=2 && /* ��٥����� 2 */
409 /*intr_vsync_enable &&*/ VSYNC_flag ){ /* VSYNC ������ */
410 z80main_cpu.INT_active = TRUE;
411 }
412 else if( intr_level>=3 && /* ��٥����� 3 */
413 /*intr_rtc_enable &&*/ RTC_flag ){ /* 1/600�� RTC ������ */
414 z80main_cpu.INT_active = TRUE;
415 }
416 else if( intr_level>=5 && /* ��٥����� 5 */
417 /*intr_sound_enable &&*/ SOUND_flag ){ /* SOUND TIMER ������ */
418 z80main_cpu.INT_active = TRUE;
419 }
420 else{
421 z80main_cpu.INT_active = FALSE;
422 }
423 }
424
425 /*----------------------------------------------------------------------*/
426 /* �����ߤ��������롣��Ʊ���ˡ����γ����ߤޤǤΡ��Ǿ� state ��� */
427 /* �����ͤϡ�Z80����������λ�Υե饰(TRUE/FALSE) */
428 /*----------------------------------------------------------------------*/
main_INT_update(void)429 void main_INT_update( void )
430 {
431 int SOUND_level_old = SOUND_level;
432 int icount = rtc_intr_base; /* ���γ�����ȯ���ޤǤκǾ�state�� */
433 /* �Ȥꤢ������RTC����μ����ǽ���� */
434
435
436 /* -------- RS232C ������ -------- */
437
438 rs232c_intr_timer -= z80main_cpu.state0;
439 if( rs232c_intr_timer < 0 ){
440 rs232c_intr_timer += rs232c_intr_base;
441 if( sio_intr() ){
442 if( intr_sio_enable )
443 RS232C_flag = TRUE;
444 }
445 }
446 icount = MIN( icount, rs232c_intr_timer );
447
448
449 /* -------- VSYNC ������ -------- */
450
451 state_of_cpu += z80main_cpu.state0;
452
453 vsync_intr_timer -= z80main_cpu.state0;
454 if( vsync_intr_timer < 0 ){
455 vsync_intr_timer += vsync_intr_base;
456
457 vsync(); /* �������ȡ�ɽ�������� */
458 if( intr_vsync_enable )
459 VSYNC_flag = TRUE; /* VSYNC������ */
460
461 ctrl_vrtc = 1;
462 vrtc_timer = vrtc_base + z80main_cpu.state0;
463 }
464 icount = MIN( icount, vsync_intr_timer );
465
466
467 /* -------- VRTC ���� -------- */
468
469 if( ctrl_vrtc == 1 ){ /* VSYNC ���� ������� */
470 vrtc_timer -= z80main_cpu.state0; /* �в�ǡ�ɽ�����֤� */
471 if( vrtc_timer < 0 ){
472 ctrl_vrtc = 2;
473 vrtc_timer += vrtc_base2;
474
475 #ifndef DRAW_SCREEN_AT_VSYNC_START
476 if( boost_cnt == 0 ){
477 CPU_BREAKOFF();
478 quasi88_event_flags |= EVENT_FRAME_UPDATE;
479 }
480 #endif
481 }
482
483 }else if( ctrl_vrtc == 2 ){ /* ɽ�����֤��������� */
484 vrtc_timer -= z80main_cpu.state0; /* �в�ǡ�VBLANK���֤� */
485 if( vrtc_timer < 0 ){
486 ctrl_vrtc = 3;
487 vrtc_timer = 0xffff; /* ǰ�Τ��� */
488 }
489 }
490
491 if( ctrl_vrtc < 3 ) icount = MIN( icount, vrtc_timer );
492
493
494 /* -------- RTC ������ -------- */
495
496 rtc_intr_timer -= z80main_cpu.state0;
497 if( rtc_intr_timer < 0 ){
498 rtc_intr_timer += rtc_intr_base;
499 if( intr_rtc_enable )
500 RTC_flag = TRUE;
501 }
502 icount = MIN( icount, rtc_intr_timer );
503
504
505 /* -------- SOUND TIMER A ������ -------- */
506
507 if( sound_LOAD_A ){
508 sd_A_intr_timer -= z80main_cpu.state0;
509 if( sd_A_intr_timer < 0 ){
510 xmame_dev_sound_timer_over(0);
511 sd_A_intr_timer += sd_A_intr_base;
512 if( sound_ENABLE_A ){
513 if( sound2_MSK_TA ) sound_FLAG_A = 0;
514 else sound_FLAG_A = 1;
515 }
516 }
517 icount = MIN( icount, sd_A_intr_timer );
518 }
519
520
521 /* -------- SOUND TIMER B ������ -------- */
522
523 if( sound_LOAD_B ){
524 sd_B_intr_timer -= z80main_cpu.state0;
525 if( sd_B_intr_timer < 0 ){
526 xmame_dev_sound_timer_over(1);
527 sd_B_intr_timer += sd_B_intr_base;
528 if( sound_ENABLE_B ){
529 if( sound2_MSK_TB ) sound_FLAG_B = 0;
530 else sound_FLAG_B = 1;
531 }
532 }
533 icount = MIN( icount, sd_B_intr_timer );
534 }
535
536 if( sound2_FLAG_PCMBSY ){
537
538 sd2_BRDY_intr_timer -= z80main_cpu.state0;
539 if( sd2_BRDY_intr_timer < 0 ){
540 sd2_BRDY_intr_timer += sd2_BRDY_intr_base;
541 {
542 if( sound2_MSK_BRDY ) sound2_FLAG_BRDY = 0;
543 else sound2_FLAG_BRDY = 1;
544 }
545 }
546 icount = MIN( icount, sd2_BRDY_intr_timer );
547
548 if( sound2_notice_EOS ){
549 sd2_EOS_intr_timer -= z80main_cpu.state0;
550 if( sd2_EOS_intr_timer < 0 ){
551 sd2_EOS_intr_timer += sd2_EOS_intr_base;
552 if( sound2_MSK_EOS ) sound2_FLAG_EOS = 0;
553 else sound2_FLAG_EOS = 1;
554 if( !sound2_repeat ) sound2_FLAG_PCMBSY = 0;
555 sound2_notice_EOS = FALSE;
556 }
557 }
558 icount = MIN( icount, sound2_notice_EOS );
559
560 }
561
562 /* ������ɤΡ������ߤ˴ؤ��쥸�������ѹ�����Ƥʤ�����ǧ */
563 /* ��������Ƥ���ե饰��ľ���ơ�������ɳ����ߤ�̵ͭ��Ƚ�� */
564
565 check_sound_parm_update();
566
567 #if 0 /* ANDOROGYNUS �� BGM ���Ĥ�ʤ� ? */
568 if( ( sound_FLAG_A && sound2_EN_TA ) ||
569 ( sound_FLAG_B && sound2_EN_TB ) ||
570 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
571 ( sound2_FLAG_EOS && sound2_EN_EOS ) ){
572 SOUND_level = TRUE;
573 }else{
574 SOUND_level = FALSE;
575 }
576 if( (SOUND_level_old == FALSE) && SOUND_level ){
577 SOUND_edge = TRUE;
578 }
579 if( SOUND_edge && intr_sound_enable ){
580 SOUND_flag = TRUE;
581 SOUND_edge = FALSE;
582 }
583 #elif 1 /* ����ʤ� OK ? */
584 if( ( ( sound_FLAG_A && sound2_EN_TA ) ||
585 ( sound_FLAG_B && sound2_EN_TB ) ||
586 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
587 ( sound2_FLAG_EOS && sound2_EN_EOS ) ) && intr_sound_enable ){
588 SOUND_level = TRUE;
589 }else{
590 SOUND_level = FALSE;
591 }
592 if( (SOUND_level_old == FALSE) && SOUND_level ){
593 SOUND_flag = TRUE;
594 }
595 #else /* DRAGON ��ư���ʤ� ? */
596 if( ( ( sound_FLAG_A && sound2_EN_TA ) ||
597 ( sound_FLAG_B && sound2_EN_TB ) ||
598 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
599 ( sound2_FLAG_EOS && sound2_EN_EOS ) ) && intr_sound_enable ){
600 SOUND_flag = TRUE;
601 }else{
602 SOUND_flag = FALSE;
603 }
604 #endif
605
606
607 /* ������ȯ�������顢z80->INT_active �˿��åȤ��� */
608
609 set_INT_active();
610
611
612 /* ���γ�����ȯ���ޤǤΡ����ơ��ȿ��å� */
613
614 z80main_cpu.icount = icount;
615
616
617 /* ��˥塼�ؤ����ܤʤɤϡ������dz�ǧ */
618
619 if (quasi88_event_flags & EVENT_MODE_CHANGED) {
620 CPU_BREAKOFF();
621 }
622 }
623
624
625
626
627
628
629 /************************************************************************/
630 /* �ޥ����֥�����ߥ��ߥ�졼�� */
631 /************************************************************************/
632 /*--------------------------------------*/
633 /* ����� (Z80�ꥻ�åȻ��˸Ƥ�) */
634 /*--------------------------------------*/
main_INT_init(void)635 void main_INT_init( void )
636 {
637 RS232C_flag = FALSE;
638 VSYNC_flag = FALSE;
639 RTC_flag = FALSE;
640 SOUND_flag = FALSE;
641 SOUND_level = FALSE;
642 SOUND_edge = FALSE;
643
644 interval_work_init_all();
645 ctrl_vrtc = 1;
646 sio_data_clear();
647
648 /*
649 printf("CPU %f\n",cpu_clock_mhz);
650 printf("SOUND %f\n",sound_clock_mhz);
651 printf("SYNC %f\n",vsync_freq_hz);
652 printf("RS232C %d\n",rs232c_intr_base);
653 printf("VSYNC %d\n",vsync_intr_base);
654 printf("VRTC %d\n",vrtc_base);
655 printf("RTC %d\n",rtc_intr_base);
656 printf("A %d\n",sd_A_intr_base);
657 printf("B %d\n",sd_B_intr_base);
658 */
659 }
660
661 /*----------------------------------------------*/
662 /* �����å� (������Ļ� 1���ƥå���˸ƤФ��) */
663 /* */
664 /* �棱��IM!=2 �λ��ϳ����ߤϤɤ��ʤ롩 */
665 /* �棲��intr_priority �����λ��ϡ� */
666 /* �����߾��֤Ϥɤ��ʤ롩 */
667 /* (������̵��) */
668 /* */
669 /*----------------------------------------------*/
main_INT_chk(void)670 int main_INT_chk( void )
671 {
672 int intr_no = -1;
673
674 /* if( z80main_cpu.IM!=2 ) return -1;*/
675
676
677 if( intr_level==0 ){ /* ��٥����� 0 */
678 { /* �����ߤϼ����դ��ʤ� */
679 intr_no = -1;
680 }
681 }
682 else if( intr_level>=1 && /* ��٥����� 1 */
683 /*intr_sio_enable &&*/ RS232C_flag ){ /* RS232S ���� ������ */
684 RS232C_flag = FALSE;
685 intr_no = 0;
686 }
687 else if( intr_level>=2 && /* ��٥����� 2 */
688 /*intr_vsync_enable &&*/ VSYNC_flag ){ /* VSYNC ������ */
689 VSYNC_flag = FALSE;
690 intr_no = 1;
691 }
692 else if( intr_level>=3 && /* ��٥����� 3 */
693 /*intr_rtc_enable &&*/ RTC_flag ){ /* 1/600�� RTC ������ */
694 RTC_flag = FALSE;
695 intr_no = 2;
696 }
697 else if( intr_level>=5 && /* ��٥����� 5 */
698 /*intr_sound_enable &&*/ SOUND_flag ){ /* SOUND TIMER ������ */
699 SOUND_flag = FALSE;
700 intr_no = 4;
701 }
702
703 /* ���������դ����顢z80->INT_active �˵��åȤ��� */
704 /* (�ޤ�ͭ���ʳ����ߤ��ĤäƤ��顢z80->INT_active �Ͽ�) */
705
706 set_INT_active();
707
708 if( intr_no >= 0 ){
709 intr_level = 0;
710 return intr_no;
711 }else{
712 return -1;
713 }
714 }
715
716
717
718
719
720
721
722
723 /***********************************************************************
724 * ���ơ��ȥ��ɡ����ơ��ȥ�����
725 ************************************************************************/
726 static int wait_by_sleep_dummy;
727 static int wait_sleep_min_us_dummy;
728
729 #define SID "INTR"
730 #define SID2 "INT2"
731 #define SID3 "INT3"
732 #define SID4 "INT4"
733
734 static T_SUSPEND_W suspend_intr_work[]=
735 {
736 { TYPE_INT, &intr_level, },
737 { TYPE_INT, &intr_priority, },
738 { TYPE_INT, &intr_sio_enable, },
739 { TYPE_INT, &intr_vsync_enable, },
740 { TYPE_INT, &intr_rtc_enable, },
741
742 { TYPE_DOUBLE,&cpu_clock_mhz, },
743 { TYPE_DOUBLE,&sound_clock_mhz, },
744 { TYPE_DOUBLE,&vsync_freq_hz, },
745
746 { TYPE_INT, &wait_rate, },
747 { TYPE_INT, &wait_by_sleep_dummy, },
748 { TYPE_LONG, &wait_sleep_min_us_dummy, },
749
750 { TYPE_INT, &state_of_cpu, },
751 { TYPE_INT, &state_of_vsync, },
752
753 { TYPE_INT, &no_wait, },
754
755 { TYPE_INT, &RS232C_flag, },
756 { TYPE_INT, &rs232c_intr_base, },
757 { TYPE_INT, &rs232c_intr_timer, },
758
759 { TYPE_INT, &VSYNC_flag, },
760 { TYPE_INT, &vsync_intr_base, },
761 { TYPE_INT, &vsync_intr_timer, },
762
763 { TYPE_INT, &ctrl_vrtc, },
764 { TYPE_INT, &vrtc_base, },
765 { TYPE_INT, &vrtc_timer, },
766
767 { TYPE_INT, &RTC_flag, },
768 { TYPE_INT, &rtc_intr_base, },
769 { TYPE_INT, &rtc_intr_timer, },
770
771 { TYPE_INT, &SOUND_flag, },
772 { TYPE_INT, &sd_A_intr_base, },
773 { TYPE_INT, &sd_A_intr_timer, },
774 { TYPE_INT, &sd_B_intr_base, },
775 { TYPE_INT, &sd_B_intr_timer, },
776
777 { TYPE_INT, &sound_flags_update, },
778 { TYPE_INT, &sound_prescaler_update,},
779
780 { TYPE_INT, &sd2_BRDY_intr_base, },
781 { TYPE_INT, &sd2_BRDY_intr_timer, },
782 { TYPE_INT, &sd2_EOS_intr_base, },
783 { TYPE_INT, &sd2_EOS_intr_timer, },
784
785 { TYPE_END, 0 },
786 };
787
788 static T_SUSPEND_W suspend_intr_work2[]=
789 {
790 { TYPE_INT, &vrtc_base2, },
791 { TYPE_END, 0 },
792 };
793
794 static T_SUSPEND_W suspend_intr_work3[]=
795 {
796 { TYPE_INT, &SOUND_level, },
797 { TYPE_INT, &SOUND_edge, },
798 { TYPE_END, 0 },
799 };
800
801 static T_SUSPEND_W suspend_intr_work4[]=
802 {
803 { TYPE_INT, &boost, },
804 { TYPE_END, 0 },
805 };
806
807
statesave_intr(void)808 int statesave_intr( void )
809 {
810 if( statesave_table( SID, suspend_intr_work ) != STATE_OK ) return FALSE;
811
812 if( statesave_table( SID2, suspend_intr_work2 ) != STATE_OK ) return FALSE;
813
814 if( statesave_table( SID3, suspend_intr_work3 ) != STATE_OK ) return FALSE;
815
816 if( statesave_table( SID4, suspend_intr_work4 ) != STATE_OK ) return FALSE;
817
818 return TRUE;
819 }
820
stateload_intr(void)821 int stateload_intr( void )
822 {
823 boost_cnt = 0;
824
825 if( stateload_table( SID, suspend_intr_work ) != STATE_OK ) return FALSE;
826
827 if( stateload_table( SID2, suspend_intr_work2 ) != STATE_OK ){
828
829 /* ��С������ʤ顢�ߤΤ��� */
830
831 printf( "stateload : Statefile is old. (ver 0.6.0?)\n" );
832 /* printf( "stateload : Header revision is %d\n", statefile_revision() );*/
833
834 goto NOT_HAVE_SID2;
835
836 }
837
838 if( stateload_table( SID3, suspend_intr_work3 ) != STATE_OK ){
839
840 /* ��С������ʤ顢�ߤΤ��� */
841
842 printf( "stateload : Statefile is old. (ver 0.6.1?)\n" );
843
844 goto NOT_HAVE_SID3;
845
846 }
847
848 if( stateload_table( SID4, suspend_intr_work4 ) != STATE_OK ){
849
850 /* ��С������ʤ顢�ߤΤ��� */
851
852 printf( "stateload : Statefile is old. (ver 0.6.2?)\n" );
853
854 goto NOT_HAVE_SID4;
855
856 }
857
858 return TRUE;
859
860
861
862 NOT_HAVE_SID2:
863 vrtc_base2 = (int) (vsync_intr_base * VRTC_DISP);
864 if( ctrl_vrtc == 0 ) ctrl_vrtc = 2;
865
866
867 NOT_HAVE_SID3:
868 if( ( sound_FLAG_A && sound2_EN_TA ) ||
869 ( sound_FLAG_B && sound2_EN_TB ) ||
870 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
871 ( sound2_FLAG_EOS && sound2_EN_EOS ) ){
872 SOUND_level = TRUE;
873 }else{
874 SOUND_level = FALSE;
875 }
876 SOUND_edge = FALSE;
877
878
879 NOT_HAVE_SID4:
880 boost = 1;
881
882
883 return TRUE;
884 }
885