OSDN Git Service

[VM][STATE] Apply new framework to some VMs.
[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 bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
77 {
78         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
79                 return false;
80         }
81         if(!state_fio->StateCheckInt32(this_device_id)) {
82                 return false;
83         }
84         state_fio->StateBool(intr);
85         state_fio->StateBool(supported);
86         return true;
87 }