OSDN Git Service

[VM][FM7][FM8][WIP] Add support of bubble-casette.This is not working yet.
[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 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 };
37
38 typedef struct {
39         _TCHAR filename[16];
40         pair_t size;
41         paiir_t offset;
42         uint8_t misc[8];
43 } bbl_header_t;
44
45 class BUBBLECASETTE: public DEVICE {
46 protected:
47         EMU *p_emu;
48         VM *p_vm;
49
50         FILEIO* fio;
51         
52         bool is_wrote;
53         // FD10(RW)
54         uint8_t datareg;
55         // FD11(RW)
56         uint8_t cmdreg;
57
58         // FD12(RO) : Positive logic
59         bool cmd_error;  // bit7 : Command error
60         bool stat_tdra;  // bit6: Ready to write.
61         bool stat_rda;   // bit5: Ready to read.
62         bool stat_error; // bit 1
63         bool stat_busy;  // bit 0
64
65         // FD13(RO): Maybe positive
66         bool eject_error;         // bit7
67         bool povr_error;          // bit5 : Page over
68         bool crc_error;           // bit4
69         bool transfer_error;      // bit3
70         bool bad_loop_over_error; // bit2
71         bool no_marker_error;     // bit1
72         bool undefined_cmd_error; // bit0
73
74         //FD14-FD15: Page address register
75         pair_t page_address; // 16bit, Big ENDIAN
76         // FD16-FD17: Page Count Resister
77         pair_t page_count;   // 16bit, Big ENDIAN
78 private:
79         bool read_access;
80         bool write_access;
81         int bubble_type[16];
82         bbl_header_t bbl_header[16];
83         uint8_t bubble_data[16][0x20000]; // MAX 128KB, normally 32KB at FM-8.
84         _TCHAR image_path[_MAX_PATH];
85         bool bubble_inserted;
86 public:
87         BUBBLECASETTE(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu);
88         ~BUBBLECASETTE();
89
90         void initialize();
91         void reset();
92         void release();
93
94         uint32_t read_data8(uint32_t addr);
95         void write_data8(uint32_t addr, uint32_t data);
96         
97         uint32_t read_signal(int id);
98         void write_signal(int id, uint32_t data, uint32_t mask);
99         
100         void event_callback(int event_id, int err);
101         void save_state(FILEIO* state_fio);
102         bool load_state(FILEIO* state_fio);
103         const _TCHAR *get_device_name()
104         {
105                 return _T("FM Bubble Casette");
106         }
107         bool insert_bubble(_TCHAR* file_path);
108         void close_bubble();
109         bool is_bubble_inserted()
110         {
111                 return bubble_inserted;
112         }
113         bool get_access_lamp()
114         {
115                 return (read_access | write_access);
116         }
117
118 };
119 #endif