OSDN Git Service

Merge branch 'master' of github.com:Artanejp/common_source_project-fm7
[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 enum {
21         BUBBLE_DATA_REG = 0,
22         BUBBLE_CMD_REG,
23         BUBBLE_STATUS_REG,
24         BUBBLE_ERROR_REG,
25         BUBBLE_PAGE_ADDR_HI,
26         BUBBLE_PAGE_ADDR_LO,
27         BUBBLE_PAGE_COUNT_HI,
28         BUBBLE_PAGE_COUNT_LO,
29 };
30
31 enum {
32         BUBBLE_TYPE_32KB = 0,
33         BUBBLE_TYPE_128KB = 1,
34         BUBBLE_TYPE_B77,
35         BUBBLE_TYPE_64KB,
36 };
37
38 typedef struct {
39         _TCHAR filename[16];
40         pair_t size;
41         pair_t offset;
42         uint8_t misc[8];
43 } bbl_header_t;
44
45 class BUBBLECASETTE: public DEVICE
46 {
47 protected:
48         FILEIO* fio;
49         
50         bool is_wrote;
51         bool is_b77;
52         bool header_changed; // if change header: e.g:change write protection flag.
53         bool read_access;
54         bool write_access;
55         
56         uint8_t offset_reg;
57         // FD10(RW)
58         uint8_t data_reg;
59         // FD11(RW)
60         uint8_t cmd_reg;
61         
62         // FD12(RO) : Positive logic
63         bool cmd_error;  // bit7 : Command error
64         bool stat_tdra;  // bit6: Ready to write.
65         bool stat_rda;   // bit5: Ready to read.
66         bool not_ready;  // bit4: Not Ready(Slot empty).
67         // bit3 : NOOP
68         bool write_protect; // bit2
69         bool stat_error; // bit 1
70         bool stat_busy;  // bit 0
71         
72         // FD13(RO): Maybe positive
73         bool eject_error;         // bit7
74         bool povr_error;          // bit5 : Page over
75         bool crc_error;           // bit4
76         bool transfer_error;      // bit3
77         bool bad_loop_over_error; // bit2
78         bool no_marker_error;     // bit1
79         bool undefined_cmd_error; // bit0
80         
81         //FD14-FD15: Page address register
82         pair_t page_address; // 16bit, Big ENDIAN
83         // FD16-FD17: Page Count Resister
84         pair_t page_count;   // 16bit, Big ENDIAN
85         
86 private:
87         bool bubble_inserted;
88         int bubble_type;
89         int media_num;
90         bbl_header_t bbl_header;
91         uint32_t media_offset;
92         uint32_t media_offset_new;
93         uint32_t media_size;
94         uint32_t file_length;
95         
96         uint8_t bubble_data[0x20000]; // MAX 128KB, normally 32KB at FM-8.
97         _TCHAR image_path[_MAX_PATH];
98         
99         void bubble_command(uint8_t cmd);
100         bool read_header(void);
101         void write_header(void);
102         bool read_one_page(void);
103         bool write_one_page(void);
104         
105 public:
106         BUBBLECASETTE(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
107         {
108                 fio = NULL;
109                 memset(image_path, 0x00, _MAX_PATH * sizeof(_TCHAR));
110                 bubble_type = -1;
111                 memset(&bbl_header, 0x00, sizeof(bbl_header_t));
112                 memset(bubble_data, 0x00, 0x20000);
113                 bubble_inserted = false;
114                 read_access = write_access = false;
115                 set_device_name(_T("Bubble Cassette"));
116         }
117         ~BUBBLECASETTE() {}
118         
119         // common functions
120         void initialize();
121         void reset();
122         
123         uint32_t read_io8(uint32_t addr);
124         void write_io8(uint32_t addr, uint32_t data);
125         
126         uint32_t read_signal(int id);
127         void write_signal(int id, uint32_t data, uint32_t mask);
128         void event_callback(int event_id, int err);
129         void save_state(FILEIO* state_fio);
130         bool load_state(FILEIO* state_fio);
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 #endif