OSDN Git Service

[VM][I286] Save cpustate without StateBuffer().
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz700 / floppy.cpp
1 /*
2         SHARP MZ-800 Emulator 'EmuZ-800'
3         SHARP MZ-1500 Emulator 'EmuZ-1500'
4
5         Author : Takeda.Toshiya
6         Date   : 2011.05.16-
7
8         [ floppy ]
9 */
10
11 #include "floppy.h"
12 #include "../mb8877.h"
13
14 #define EVENT_MOTOR_ON  0
15 #define EVENT_MOTOR_OFF 1
16
17 void FLOPPY::initialize()
18 {
19         prev_dc = 0;
20         motor_on = false;
21         
22         // always motor on (temporary)
23 //      d_fdc->write_signal(SIG_MB8877_MOTOR, 1, 1);
24 }
25
26 void FLOPPY::reset()
27 {
28         register_id = -1;
29         irq_enabled = false;
30 }
31
32 void FLOPPY::write_io8(uint32_t addr, uint32_t data)
33 {
34         switch(addr & 0xff) {
35         case 0xdc:
36                 // drive reg
37                 if(data & 4) {
38                         d_fdc->write_signal(SIG_MB8877_DRIVEREG, data, 3);
39                 }
40                 // motor on/off
41                 if(!(prev_dc & 0x80) && (data & 0x80)) {
42                         // L -> H
43                         if(register_id != -1) {
44                                 cancel_event(this, register_id);
45                                 register_id = -1;
46                         }
47                         if(!motor_on) {
48                                 register_event(this, EVENT_MOTOR_ON, 560000, false, &register_id);
49                         }
50                 } else if((prev_dc & 0x80) && !(data & 0x80)) {
51                         // H -> L
52                         if(register_id != -1) {
53                                 cancel_event(this, register_id);
54                                 register_id = -1;
55                         }
56                         if(motor_on) {
57                                 register_event(this, EVENT_MOTOR_OFF, 1500000, false, &register_id);
58                         }
59                 }
60                 prev_dc = data;
61                 break;
62         case 0xdd:
63                 // side reg
64                 d_fdc->write_signal(SIG_MB8877_SIDEREG, data, 1);
65                 break;
66         case 0xde:
67                 // ???
68                 break;
69         case 0xdf:
70                 // irq enable
71                 irq_enabled = ((data & 1) != 0);
72                 break;
73         }
74 }
75
76 void FLOPPY::event_callback(int event_id, int err)
77 {
78         if(event_id == EVENT_MOTOR_ON) {
79                 d_fdc->write_signal(SIG_MB8877_MOTOR, 1, 1);
80                 motor_on = true;
81         } else if(event_id == EVENT_MOTOR_OFF) {
82                 d_fdc->write_signal(SIG_MB8877_MOTOR, 0, 0);
83                 motor_on = false;
84         }
85         register_id = -1;
86 }
87
88 void FLOPPY::write_signal(int id, uint32_t data, uint32_t mask)
89 {
90         if(id == SIG_FLOPPY_DRQ) {
91                 if(irq_enabled && (data & mask) != 0) {
92                         d_cpu->set_intr_line(true, true, 0);
93                 }
94         }
95 }
96
97 #define STATE_VERSION   1
98
99 bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
100 {
101         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
102                 return false;
103         }
104         if(!state_fio->StateCheckInt32(this_device_id)) {
105                 return false;
106         }
107         state_fio->StateUint32(prev_dc);
108         state_fio->StateInt32(register_id);
109         state_fio->StateBool(motor_on);
110         state_fio->StateBool(irq_enabled);
111         return true;
112 }