OSDN Git Service

1c56d2d4172aa6a22ba0a28a4f60b05dd0466cd1
[csp-qt/common_source_project-fm7.git] / source / src / vm / x1 / display.h
1 /*
2         SHARP X1 Emulator 'eX1'
3         SHARP X1twin Emulator 'eX1twin'
4         SHARP X1turbo Emulator 'eX1turbo'
5         SHARP X1turboZ Emulator 'eX1turboZ'
6
7         Author : Takeda.Toshiya
8         Date   : 2009.03.14-
9
10         [ display ]
11 */
12
13 #ifndef _DISPLAY_H_
14 #define _DISPLAY_H_
15
16 #include "../vm.h"
17 #include "../../emu.h"
18 #include "../device.h"
19
20 #define SIG_DISPLAY_VBLANK              0
21 #define SIG_DISPLAY_COLUMN40            1
22 #define SIG_DISPLAY_DETECT_VBLANK       2
23 #define SIG_DISPLAY_DISP                3
24
25 class HD46505;
26
27 namespace X1 {
28
29 class DISPLAY : public DEVICE
30 {
31 private:
32 #ifdef _X1TURBO_FEATURE
33         DEVICE *d_cpu;
34 #endif
35         HD46505 *d_crtc;
36         uint8_t* regs;
37         __DECL_ALIGNED(16) uint8_t vram_t[0x800];
38         __DECL_ALIGNED(16) uint8_t vram_a[0x800];
39 #ifdef _X1TURBO_FEATURE
40         __DECL_ALIGNED(16) uint8_t vram_k[0x800];
41 #endif
42         uint8_t* vram_ptr;
43         __DECL_ALIGNED(8) uint8_t pcg_b[256][8];
44         __DECL_ALIGNED(8) uint8_t pcg_r[256][8];
45         __DECL_ALIGNED(8) uint8_t pcg_g[256][8];
46 #ifdef _X1TURBO_FEATURE
47         __DECL_ALIGNED(16) uint8_t gaiji_b[128][16];
48         __DECL_ALIGNED(16) uint8_t gaiji_r[128][16];
49         __DECL_ALIGNED(16) uint8_t gaiji_g[128][16];
50 #endif
51         __DECL_ALIGNED(16) uint8_t font[0x800];
52         __DECL_ALIGNED(16) uint8_t kanji[0x4bc00];
53         
54         uint8_t cur_code, cur_line;
55         
56         int kaddr, kofs, kflag;
57         uint8_t* kanji_ptr;
58         
59         uint8_t pal[3];
60         uint8_t priority;
61         __DECL_ALIGNED(32) uint8_t pri[8][8];   // pri[cg][txt]
62         uint8_t dr_priority;
63         
64         bool column40;
65 #ifdef _X1TURBO_FEATURE
66         uint8_t mode1, mode2;
67         bool hireso;
68 #endif
69 #ifdef _X1TURBOZ
70         uint8_t zmode1;
71         uint8_t zpriority;
72         uint8_t zadjust;
73         uint8_t zmosaic;
74         uint8_t zchromakey;
75         uint8_t zscroll;
76         uint8_t zmode2;
77         uint8_t ztpal[8];
78         uint8_t dr_zpriority;
79
80         __DECL_ALIGNED(32) struct {
81                 uint8_t b, r, g;
82         } zpal[4096];
83         int zpal_num;
84 #endif
85         
86 #ifdef _X1TURBO_FEATURE
87         __DECL_ALIGNED(32) uint8_t text[400][640];
88         __DECL_ALIGNED(32) uint8_t cg[400][640];
89         __DECL_ALIGNED(32) uint8_t pri_line[400][8][8];
90
91         __DECL_ALIGNED(32) uint8_t dr_text[400][640];
92         __DECL_ALIGNED(32) uint8_t dr_cg[400][640];
93         __DECL_ALIGNED(32) uint8_t dr_pri_line[400][8][8];
94 #else
95         __DECL_ALIGNED(32) uint8_t text[200][640+8];
96         __DECL_ALIGNED(32) uint8_t cg[200][640];
97         __DECL_ALIGNED(32) uint8_t pri_line[200][8][8];
98
99         __DECL_ALIGNED(32) uint8_t dr_text[200][640+8];
100         __DECL_ALIGNED(32) uint8_t dr_cg[200][640];
101         __DECL_ALIGNED(32) uint8_t dr_pri_line[200][8][8];
102 #endif
103 #ifdef _X1TURBOZ
104         bool zpalette_changed;
105         __DECL_ALIGNED(32) uint16_t zcg[2][400][640];
106         __DECL_ALIGNED(16) bool aen_line[400];
107         __DECL_ALIGNED(32) scrntype_t zpalette_tmp[8+8+4096];
108         __DECL_ALIGNED(32) scrntype_t zpalette_pc[8+8+4096];    // 0-7:text, 8-15:cg, 16-:4096cg
109
110         __DECL_ALIGNED(32) uint16_t dr_zcg[2][400][640];
111         __DECL_ALIGNED(16) bool dr_aen_line[400];
112         __DECL_ALIGNED(32) scrntype_t dr_zpalette_pc[8+8+4096]; // 0-7:text, 8-15:cg, 16-:4096cg
113 #endif
114         __DECL_ALIGNED(16) scrntype_t palette_pc[8+8];          // 0-7:text, 8-15:cg
115         __DECL_ALIGNED(16) scrntype_t dr_palette_pc[8+8];               // 0-7:text, 8-15:cg
116         bool prev_vert_double;
117         int raster, cblink;
118         
119         int ch_height; // HD46505
120         int hz_total, hz_disp, vt_disp;
121         int st_addr;
122         uint32_t vblank_clock;
123         int cur_vline;
124         bool cur_blank;
125         
126         void update_crtc();
127         void update_pal();
128         uint8_t __FASTCALL get_cur_font(uint32_t addr);
129         void __FASTCALL get_cur_pcg(uint32_t addr);
130         void __FASTCALL get_cur_code_line();
131         
132         void __FASTCALL draw_line(int v);
133         void __FASTCALL draw_text(int y);
134         void __FASTCALL draw_cg(int line, int plane);
135         
136 #ifdef _X1TURBOZ
137         int __FASTCALL get_zpal_num(uint32_t addr, uint32_t data);
138         void update_zpalette();
139         scrntype_t __FASTCALL get_zpriority(uint8_t text, uint16_t cg0, uint16_t cg1);
140 #endif
141         
142         // kanji rom (from X1EMU by KM)
143         void __FASTCALL write_kanji(uint32_t addr, uint32_t data);
144         uint32_t __FASTCALL read_kanji(uint32_t addr);
145         
146         uint16_t __FASTCALL jis2adr_x1(uint16_t jis);
147         uint32_t __FASTCALL adr2knj_x1(uint16_t adr);
148 #ifdef _X1TURBO_FEATURE
149         uint32_t __FASTCALL adr2knj_x1t(uint16_t adr);
150 #endif
151         uint32_t __FASTCALL jis2knj(uint16_t jis);
152         uint16_t __FASTCALL jis2sjis(uint16_t jis);
153
154         int tmp_kanji_ptr;
155
156         __DECL_ALIGNED(16) _bit_trans_table_t bit_trans_table_b0;
157         __DECL_ALIGNED(16) _bit_trans_table_t bit_trans_table_r0;
158         __DECL_ALIGNED(16) _bit_trans_table_t bit_trans_table_g0;
159 public:
160         DISPLAY(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
161         {
162                 set_device_name(_T("Display"));
163         }
164         ~DISPLAY() {}
165         
166         // common functions
167         void initialize();
168         void reset();
169         void __FASTCALL write_io8(uint32_t addr, uint32_t data);
170         uint32_t __FASTCALL read_io8(uint32_t addr);
171         void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
172         void event_frame();
173         void event_vline(int v, int clock);
174 #ifdef _X1TURBO_FEATURE
175         void __FASTCALL event_callback(int event_id, int err);
176 #endif
177         bool process_state(FILEIO* state_fio, bool loading);
178         
179         // unique functions
180 #ifdef _X1TURBO_FEATURE
181         void set_context_cpu(DEVICE* device)
182         {
183                 d_cpu = device;
184         }
185 #endif
186         void set_context_crtc(HD46505* device)
187         {
188                 d_crtc = device;
189         }
190         void set_vram_ptr(uint8_t* ptr)
191         {
192                 vram_ptr = ptr;
193         }
194         void set_regs_ptr(uint8_t* ptr)
195         {
196                 regs = ptr;
197         }
198         void draw_screen();
199 };
200
201 }
202 #endif
203