OSDN Git Service

[General] Convert sourcecode's CRLF format: DOS(WINDOWS) to Unix, to apply patches...
[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 #include "../../fileio.h"
13
14 void FLOPPY::initialize()
15 {
16         intr = false;
17 }
18
19 void FLOPPY::write_io8(uint32 addr, uint32 data)
20 {
21         if(!supported) {
22                 // OA-BASIC without floppy drives
23                 return;
24         }
25         
26         switch(addr & 0xff) {
27         case 0xe0:
28                 // tc off
29                 d_fdc->write_signal(SIG_UPD765A_TC, 0, 1);
30                 break;
31         case 0xe2:
32                 // tc on
33                 d_fdc->write_signal(SIG_UPD765A_TC, 1, 1);
34                 break;
35         case 0xe4:
36         case 0xe5:
37                 d_fdc->write_io8(addr, data);
38                 break;
39         case 0xe6:
40                 // fdc reset
41                 if(data & 0x80) {
42                         d_fdc->reset();
43                 }
44                 // motor on/off
45                 d_fdc->write_signal(SIG_UPD765A_MOTOR, data, 0x40);
46                 break;
47         }
48 }
49
50 uint32 FLOPPY::read_io8(uint32 addr)
51 {
52         if(!supported) {
53                 // OA-BASIC without floppy drives
54                 return 0xff;
55         }
56         
57         switch(addr & 0xff) {
58         case 0xe4:
59         case 0xe5:
60                 return d_fdc->read_io8(addr);
61         case 0xe6:
62                 // fdc intr
63                 return intr ? 0x80 : 0;
64         }
65         return 0xff;
66 }
67
68 void FLOPPY::write_signal(int id, uint32 data, uint32 mask)
69 {
70         if(id == SIG_FLOPPY_INTR) {
71                 intr = ((data & mask) != 0);
72         }
73 }
74
75 #define STATE_VERSION   1
76
77 void FLOPPY::save_state(FILEIO* state_fio)
78 {
79         state_fio->FputUint32(STATE_VERSION);
80         state_fio->FputInt32(this_device_id);
81         
82         state_fio->FputBool(intr);
83         state_fio->FputBool(supported);
84 }
85
86 bool FLOPPY::load_state(FILEIO* state_fio)
87 {
88         if(state_fio->FgetUint32() != STATE_VERSION) {
89                 return false;
90         }
91         if(state_fio->FgetInt32() != this_device_id) {
92                 return false;
93         }
94         intr = state_fio->FgetBool();
95         supported = state_fio->FgetBool();
96         return true;
97 }
98