OSDN Git Service

69ce764a314577f60e25295f49f52bfd81f85073
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz5500 / sysport.cpp
1 /*
2         SHARP MZ-5500 Emulator 'EmuZ-5500'
3
4         Author : Takeda.Toshiya
5         Date   : 2008.04.10 -
6
7         [ system port ]
8 */
9
10 #include "sysport.h"
11 #include "../../fileio.h"
12
13 void SYSPORT::initialize()
14 {
15         rst = 0;
16         register_frame_event(this);
17 }
18
19 void SYSPORT::write_io8(uint32 addr, uint32 data)
20 {
21         switch(addr & 0x3f0) {
22         case 0x70:
23                 // port-c
24                 if(data & 8) {
25                         d_fdc->reset();
26                 }
27 #if defined(_MZ6500) || defined(_MZ6550)
28                 highden = data & 4;
29 #endif
30                 break;
31         case 0x260:
32                 // z80ctc reti
33                 if(data == 0x4d) {
34                         d_ctc->intr_reti();
35                 }
36                 break;
37         }
38 }
39
40 uint32 SYSPORT::read_io8(uint32 addr)
41 {
42         switch(addr & 0x3ff) {
43         case 0x60:
44                 // port-a
45 #if defined(_MZ6500) || defined(_MZ6550)
46                 return 0xfc | (rst ? 0 : 2) | (highden ? 1 : 0);
47 #else
48                 return 0xfd | (rst ? 0 : 2);
49 #endif
50         case 0x240:
51                 // z80ctc vector
52                 return d_ctc->intr_ack();
53         case 0x250:
54                 // z80sio vector
55                 return d_sio->intr_ack();
56         case 0x270:
57                 // port-b
58                 return 0xff;
59         }
60         return 0xff;
61 }
62
63 void SYSPORT::event_frame()
64 {
65         if(rst) {
66                 rst--;
67         }
68 }
69
70 #define STATE_VERSION   1
71
72 void SYSPORT::save_state(FILEIO* state_fio)
73 {
74         state_fio->FputUint32(STATE_VERSION);
75         state_fio->FputInt32(this_device_id);
76         
77         state_fio->FputInt32(rst);
78         state_fio->FputInt32(highden);
79 }
80
81 bool SYSPORT::load_state(FILEIO* state_fio)
82 {
83         if(state_fio->FgetUint32() != STATE_VERSION) {
84                 return false;
85         }
86         if(state_fio->FgetInt32() != this_device_id) {
87                 return false;
88         }
89         rst = state_fio->FgetInt32();
90         highden = state_fio->FgetInt32();
91         return true;
92 }
93