OSDN Git Service

[VM][General] Merge upstream 2016-03-01. (Pahse 1).
[csp-qt/common_source_project-fm7.git] / source / src / vm / pasopia / floppy.cpp
1 /*
2         TOSHIBA PASOPIA Emulator 'EmuPIA'
3
4         Author : Takeda.Toshiya
5         Date   : 2012.03.01 -
6
7         [ floppy ]
8 */
9
10 #include "floppy.h"
11 #include "../upd765a.h"
12
13 void FLOPPY::initialize()
14 {
15         intr = false;
16 }
17
18 void FLOPPY::write_io8(uint32_t addr, uint32_t data)
19 {
20         if(!supported) {
21                 // OA-BASIC without floppy drives
22                 return;
23         }
24         
25         switch(addr & 0xff) {
26         case 0xe0:
27                 // tc off
28                 d_fdc->write_signal(SIG_UPD765A_TC, 0, 1);
29                 break;
30         case 0xe2:
31                 // tc on
32                 d_fdc->write_signal(SIG_UPD765A_TC, 1, 1);
33                 break;
34         case 0xe4:
35         case 0xe5:
36                 d_fdc->write_io8(addr, data);
37                 break;
38         case 0xe6:
39                 // fdc reset
40                 if(data & 0x80) {
41                         d_fdc->reset();
42                 }
43                 // motor on/off
44                 d_fdc->write_signal(SIG_UPD765A_MOTOR, data, 0x40);
45                 break;
46         }
47 }
48
49 uint32_t FLOPPY::read_io8(uint32_t addr)
50 {
51         if(!supported) {
52                 // OA-BASIC without floppy drives
53                 return 0xff;
54         }
55         
56         switch(addr & 0xff) {
57         case 0xe4:
58         case 0xe5:
59                 return d_fdc->read_io8(addr);
60         case 0xe6:
61                 // fdc intr
62                 return intr ? 0x80 : 0;
63         }
64         return 0xff;
65 }
66
67 void FLOPPY::write_signal(int id, uint32_t data, uint32_t mask)
68 {
69         if(id == SIG_FLOPPY_INTR) {
70                 intr = ((data & mask) != 0);
71         }
72 }
73
74 #define STATE_VERSION   1
75
76 void FLOPPY::save_state(FILEIO* state_fio)
77 {
78         state_fio->FputUint32(STATE_VERSION);
79         state_fio->FputInt32(this_device_id);
80         
81         state_fio->FputBool(intr);
82         state_fio->FputBool(supported);
83 }
84
85 bool FLOPPY::load_state(FILEIO* state_fio)
86 {
87         if(state_fio->FgetUint32() != STATE_VERSION) {
88                 return false;
89         }
90         if(state_fio->FgetInt32() != this_device_id) {
91                 return false;
92         }
93         intr = state_fio->FgetBool();
94         supported = state_fio->FgetBool();
95         return true;
96 }
97