OSDN Git Service

[VM] TRY:Use namespace {VMNAME} to separate around VMs. This feature still apply...
[csp-qt/common_source_project-fm7.git] / source / src / vm / bubcom80 / bubblecasette.h
1 /*
2  * BUBBLE CASETTE for FM-8/7? [bubblecasette.h]
3  *
4  * Author: K.Ohta <whatisthis.sowhat _at_ gmail.com>
5  * License: GPLv2
6  * History:
7  *   Mar 22, 2016 : Initial
8  *
9  */
10
11 #ifndef _VM_FM_BUBBLECASETTE_H_
12 #define _VM_FM_BUBBLECASETTE_H_
13
14 #include "../vm.h"
15 #include "../device.h"
16 #include "../../common.h"
17
18 class FILEIO;
19
20 namespace BUBCOM80 {
21 enum {
22         BUBBLE_DATA_REG = 0,
23         BUBBLE_CMD_REG,
24         BUBBLE_STATUS_REG,
25         BUBBLE_ERROR_REG,
26         BUBBLE_PAGE_ADDR_HI,
27         BUBBLE_PAGE_ADDR_LO,
28         BUBBLE_PAGE_COUNT_HI,
29         BUBBLE_PAGE_COUNT_LO,
30 };
31
32 enum {
33         BUBBLE_TYPE_32KB = 0,
34         BUBBLE_TYPE_128KB = 1,
35         BUBBLE_TYPE_B77,
36         BUBBLE_TYPE_64KB,
37 };
38
39 typedef struct {
40         _TCHAR filename[16];
41         pair_t size;
42         pair_t offset;
43         uint8_t misc[8];
44 } bbl_header_t;
45
46 class BUBBLECASETTE: public DEVICE
47 {
48 protected:
49         FILEIO* fio;
50         
51         bool is_wrote;
52         bool is_b77;
53         bool header_changed; // if change header: e.g:change write protection flag.
54         bool read_access;
55         bool write_access;
56         
57         uint8_t offset_reg;
58         // FD10(RW)
59         uint8_t data_reg;
60         // FD11(RW)
61         uint8_t cmd_reg;
62         
63         // FD12(RO) : Positive logic
64         bool cmd_error;  // bit7 : Command error
65         bool stat_tdra;  // bit6: Ready to write.
66         bool stat_rda;   // bit5: Ready to read.
67         bool not_ready;  // bit4: Not Ready(Slot empty).
68         // bit3 : NOOP
69         bool write_protect; // bit2
70         bool stat_error; // bit 1
71         bool stat_busy;  // bit 0
72         
73         // FD13(RO): Maybe positive
74         bool eject_error;         // bit7
75         bool povr_error;          // bit5 : Page over
76         bool crc_error;           // bit4
77         bool transfer_error;      // bit3
78         bool bad_loop_over_error; // bit2
79         bool no_marker_error;     // bit1
80         bool undefined_cmd_error; // bit0
81         
82         //FD14-FD15: Page address register
83         pair_t page_address; // 16bit, Big ENDIAN
84         // FD16-FD17: Page Count Resister
85         pair_t page_count;   // 16bit, Big ENDIAN
86         
87 private:
88         bool bubble_inserted;
89         int bubble_type;
90         int media_num;
91         bbl_header_t bbl_header;
92         uint32_t media_offset;
93         uint32_t media_offset_new;
94         uint32_t media_size;
95         uint32_t file_length;
96         
97         uint8_t bubble_data[0x20000]; // MAX 128KB, normally 32KB at FM-8.
98         _TCHAR image_path[_MAX_PATH];
99         
100         void bubble_command(uint8_t cmd);
101         bool read_header(void);
102         void write_header(void);
103         bool read_one_page(void);
104         bool write_one_page(void);
105         
106 public:
107         BUBBLECASETTE(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
108         {
109                 fio = NULL;
110                 memset(image_path, 0x00, _MAX_PATH * sizeof(_TCHAR));
111                 bubble_type = -1;
112                 memset(&bbl_header, 0x00, sizeof(bbl_header_t));
113                 memset(bubble_data, 0x00, 0x20000);
114                 bubble_inserted = false;
115                 read_access = write_access = false;
116                 set_device_name(_T("Bubble Cassette"));
117         }
118         ~BUBBLECASETTE() {}
119         
120         // common functions
121         void initialize();
122         void reset();
123         
124         uint32_t read_io8(uint32_t addr);
125         void write_io8(uint32_t addr, uint32_t data);
126         
127         uint32_t read_signal(int id);
128         void write_signal(int id, uint32_t data, uint32_t mask);
129         void event_callback(int event_id, int err);
130         bool process_state(FILEIO* state_fio, bool loading);
131         
132         // unique functions
133         void open(_TCHAR* file_path, int bank);
134         void close();
135         bool is_bubble_inserted()
136         {
137                 return bubble_inserted;
138         }
139         bool is_bubble_protected()
140         {
141                 return write_protect;
142         }
143         void set_bubble_protect(bool flag)
144         {
145                 if(write_protect != flag) {
146                         write_protect = flag;
147                         header_changed = true;
148                 }
149         }
150         bool get_access_lamp()
151         {
152                 return (read_access | write_access);
153         }
154 };
155 }
156
157 #endif