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 / multi8 / floppy.cpp
1 /*
2         MITSUBISHI Electric MULTI8 Emulator 'EmuLTI8'
3
4         Author : Takeda.Toshiya
5         Date   : 2006.09.17 -
6
7         [ floppy ]
8 */
9
10 #include "floppy.h"
11 #include "../upd765a.h"
12 #include "../../fileio.h"
13
14 void FLOPPY::write_io8(uint32 addr, uint32 data)
15 {
16         switch(addr & 0xff) {
17         case 0x72:
18                 // data register + dack
19                 d_fdc->write_dma_io8(addr, data);
20                 break;
21         case 0x73:
22                 // motor on/off
23                 d_fdc->write_signal(SIG_UPD765A_MOTOR, data, 1);
24                 break;
25         case 0x74:
26                 // tc on
27                 d_fdc->write_signal(SIG_UPD765A_TC, 1, 1);
28                 break;
29         }
30 }
31
32 uint32 FLOPPY::read_io8(uint32 addr)
33 {
34         switch(addr & 0xff) {
35         case 0x72:
36                 // data register + dack
37                 return d_fdc->read_dma_io8(addr);
38         case 0x73:
39                 return drq ? 0xff : 0x7f;
40         }
41         return 0xff;
42 }
43
44 void FLOPPY::write_signal(int id, uint32 data, uint32 mask)
45 {
46         drq = ((data & mask) != 0);
47 }
48
49 #define STATE_VERSION   1
50
51 void FLOPPY::save_state(FILEIO* state_fio)
52 {
53         state_fio->FputUint32(STATE_VERSION);
54         state_fio->FputInt32(this_device_id);
55         
56         state_fio->FputBool(drq);
57 }
58
59 bool FLOPPY::load_state(FILEIO* state_fio)
60 {
61         if(state_fio->FgetUint32() != STATE_VERSION) {
62                 return false;
63         }
64         if(state_fio->FgetInt32() != this_device_id) {
65                 return false;
66         }
67         drq = state_fio->FgetBool();
68         return true;
69 }
70