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 / fm7 / 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 #ifndef _VM_FM_BUBBLECASETTE_H_
11 #define _VM_FM_BUBBLECASETTE_H_
12
13
14 #include "device.h"
15 #include "common.h"
16
17 class EMU;
18 class VM;
19 class FILEIO;
20
21 namespace FM7 {
22         
23 enum {
24         BUBBLE_DATA_REG = 0,
25         BUBBLE_CMD_REG,
26         BUBBLE_STATUS_REG,
27         BUBBLE_ERROR_REG,
28         BUBBLE_PAGE_ADDR_HI,
29         BUBBLE_PAGE_ADDR_LO,
30         BUBBLE_PAGE_COUNT_HI,
31         BUBBLE_PAGE_COUNT_LO,
32 };
33
34 enum {
35         BUBBLE_TYPE_32KB = 0,
36         BUBBLE_TYPE_128KB = 1,
37         BUBBLE_TYPE_B77,
38 };
39
40 typedef struct {
41         _TCHAR filename[16];
42         pair_t size;
43         pair_t offset;
44         uint8_t misc[8];
45 } bbl_header_t;
46
47 class BUBBLECASETTE: public DEVICE {
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 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 public:
105         BUBBLECASETTE(VM_TEMPLATE* parent_vm, EMU* parent_emu);
106         ~BUBBLECASETTE();
107
108         void initialize();
109         void reset();
110
111         uint32_t read_data8(uint32_t addr);
112         void write_data8(uint32_t addr, uint32_t data);
113         
114         uint32_t read_signal(int id);
115         void write_signal(int id, uint32_t data, uint32_t mask);
116         bool open(_TCHAR* file_path, int bank);
117         void close();
118         void event_callback(int event_id, int err);
119         bool process_state(FILEIO *state_fio, bool loading);
120         
121         bool is_bubble_inserted()
122         {
123                 return bubble_inserted;
124         }
125         bool is_bubble_protected()
126         {
127                 return write_protect;
128         }
129         void set_bubble_protect(bool flag)
130         {
131                 if(write_protect != flag) {
132                         write_protect = flag;
133                         header_changed = true;
134                 }
135         }
136         bool get_access_lamp()
137         {
138                 return (read_access | write_access);
139         }
140
141 };
142
143 }
144
145 #endif