OSDN Git Service

[VM][STATE] Use namespace {VMNAME} to separate per VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / tk80bs / tk80bs.h
1 /*
2         NEC TK-80BS (COMPO BS/80) Emulator 'eTK-80BS'
3         NEC TK-80 Emulator 'eTK-80'
4         NEC TK-85 Emulator 'eTK-85'
5
6         Author : Takeda.Toshiya
7         Date   : 2008.08.26 -
8
9         [ virtual machine ]
10 */
11
12 #ifndef _TK80BS_H_
13 #define _TK80BS_H_
14
15 #if defined(_TK80BS)
16 #define DEVICE_NAME             "NEC TK-80BS"
17 #define CONFIG_NAME             "tk80bs"
18 #elif defined(_TK80)
19 #define DEVICE_NAME             "NEC TK-80"
20 #define CONFIG_NAME             "tk80"
21 #elif defined(_TK85)
22 #define DEVICE_NAME             "NEC TK-85"
23 #define CONFIG_NAME             "tk85"
24 #endif
25
26 // device informations for virtual machine
27 #if defined(_TK80BS)
28 #define FRAMES_PER_SEC          59.9
29 #define LINES_PER_FRAME         262
30 #elif defined(_TK80) || defined(_TK85)
31 #define FRAMES_PER_SEC          30
32 #define LINES_PER_FRAME         256
33 #endif
34 #if defined(_TK80BS) || defined(_TK80)
35 #define CPU_CLOCKS              2048000
36 #define SCREEN_WIDTH            784
37 #define SCREEN_HEIGHT           428
38 #define HAS_I8080
39 #elif defined(_TK85)
40 #define CPU_CLOCKS              2457600
41 #define SCREEN_WIDTH            784
42 #define SCREEN_HEIGHT           534
43 #define HAS_I8085
44 #endif
45 #define I8255_AUTO_HAND_SHAKE
46
47 #define MEMORY_ADDR_MAX         0x10000
48 #define MEMORY_BANK_SIZE        0x200
49 #define IO_ADDR_MAX             0x10000
50
51 // device informations for win32
52 #define ONE_BOARD_MICRO_COMPUTER
53 #if defined(_TK80BS) || defined(_TK80)
54 #define MAX_BUTTONS             25
55 #elif defined(_TK85)
56 #define MAX_BUTTONS             26
57 #endif
58 #if defined(_TK80) || defined(_TK85)
59 #define MAX_DRAW_RANGES         8
60 #endif
61 #if defined(_TK80BS)
62 #define USE_BOOT_MODE           2
63 #endif
64 #define USE_DIPSWITCH
65 #define DIPSWITCH_DEFAULT       0
66 #if defined(_TK80BS)
67 #define USE_TAPE                        2
68 #else
69 #define USE_TAPE                        1
70 #endif
71 #define USE_TAPE_BUTTON
72 #define USE_BINARY_FILE         1
73 #define NOTIFY_KEY_DOWN
74 #define USE_KEY_LOCKED
75 #define USE_ALT_F10_KEY
76 #define USE_AUTO_KEY            5
77 #define USE_AUTO_KEY_RELEASE    6
78 #define USE_AUTO_KEY_NO_CAPS
79 #define USE_AUTO_KEY_NUMPAD
80 #define USE_SOUND_VOLUME        4
81 #define USE_DEBUGGER
82 #define USE_STATE
83 #define USE_CPU_I8080
84
85 #include "../../common.h"
86 #include "../../fileio.h"
87 #include "../vm_template.h"
88
89 #ifdef USE_SOUND_VOLUME
90 static const _TCHAR *sound_device_caption[] = {
91         _T("Beep #1"), _T("Beep #2"), _T("CMT (Signal)"), _T("Noise (CMT)"),
92 };
93 #endif
94
95 #if defined(_TK80BS) || defined(_TK80)
96 #define BUTTON_SPACE_X  46
97 #define BUTTON_SPACE_Y  46
98 #define BUTTON_SIZE_X   40
99 #define BUTTON_SIZE_Y   40
100 #define BUTTON_POS_X1   523
101 #define BUTTON_POS_X2   (BUTTON_POS_X1 + BUTTON_SPACE_X * 4)
102 #define BUTTON_POS_Y1   374
103 #define BUTTON_POS_Y2   190
104
105 #define LED_SPACE_X     36
106 #define LED_SIZE_X      33
107 #define LED_SIZE_Y      46
108 #define LED_POS_X1      461
109 #define LED_POS_X2      618
110 #define LED_POS_Y       28
111 #else
112 #define BUTTON_SPACE_X  47
113 #define BUTTON_SPACE_Y  47
114 #define BUTTON_SIZE_X   44
115 #define BUTTON_SIZE_Y   44
116 #define BUTTON_POS_X1   536
117 #define BUTTON_POS_X2   729
118 #define BUTTON_POS_Y1   488
119 #define BUTTON_POS_Y2   296
120
121 #define LED_SPACE_X     39
122 #define LED_SIZE_X      29
123 #define LED_SIZE_Y      39
124 #define LED_POS_X1      446
125 #define LED_POS_X2      607
126 #define LED_POS_Y       130
127 #endif
128
129 const struct {
130         int x, y;
131         int width, height;
132         int code;
133 } vm_buttons[] = {
134         // virtual key codes 0x80-0x8f and 0x98-0x9f are not used in pc keyboard
135         {BUTTON_POS_X1 + BUTTON_SPACE_X * 0, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 0, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x80},   // 0
136         {BUTTON_POS_X1 + BUTTON_SPACE_X * 1, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 0, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x81},   // 1
137         {BUTTON_POS_X1 + BUTTON_SPACE_X * 2, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 0, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x82},   // 2
138         {BUTTON_POS_X1 + BUTTON_SPACE_X * 3, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 0, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x83},   // 3
139         {BUTTON_POS_X1 + BUTTON_SPACE_X * 0, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 1, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x84},   // 4
140         {BUTTON_POS_X1 + BUTTON_SPACE_X * 1, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 1, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x85},   // 5
141         {BUTTON_POS_X1 + BUTTON_SPACE_X * 2, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 1, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x86},   // 6
142         {BUTTON_POS_X1 + BUTTON_SPACE_X * 3, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 1, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x87},   // 7
143         {BUTTON_POS_X1 + BUTTON_SPACE_X * 0, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 2, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x88},   // 8
144         {BUTTON_POS_X1 + BUTTON_SPACE_X * 1, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 2, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x89},   // 9
145         {BUTTON_POS_X1 + BUTTON_SPACE_X * 2, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 2, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x8a},   // A
146         {BUTTON_POS_X1 + BUTTON_SPACE_X * 3, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 2, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x8b},   // B
147         {BUTTON_POS_X1 + BUTTON_SPACE_X * 0, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 3, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x8c},   // C
148         {BUTTON_POS_X1 + BUTTON_SPACE_X * 1, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 3, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x8d},   // D
149         {BUTTON_POS_X1 + BUTTON_SPACE_X * 2, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 3, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x8e},   // E
150         {BUTTON_POS_X1 + BUTTON_SPACE_X * 3, BUTTON_POS_Y1 - BUTTON_SPACE_Y * 3, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x8f},   // F
151         {BUTTON_POS_X1 + BUTTON_SPACE_X * 0, BUTTON_POS_Y2                     , BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x98},   // RET
152         {BUTTON_POS_X1 + BUTTON_SPACE_X * 1, BUTTON_POS_Y2                     , BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x99},   // RUN
153         {BUTTON_POS_X1 + BUTTON_SPACE_X * 2, BUTTON_POS_Y2                     , BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x9a},   // STORE DATA
154         {BUTTON_POS_X1 + BUTTON_SPACE_X * 3, BUTTON_POS_Y2                     , BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x9b},   // LOAD DATA
155 #if defined(_TK80BS) || defined(_TK80)
156         {BUTTON_POS_X2                     , BUTTON_POS_Y2                     , BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x00},   // RESET
157 #elif defined(_TK85)
158         {BUTTON_POS_X2                     , BUTTON_POS_Y2                     , BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x97},   // MON
159 #endif
160         {BUTTON_POS_X2                     , BUTTON_POS_Y1 - BUTTON_SPACE_Y * 3, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x9c},   // ADRS SET
161         {BUTTON_POS_X2                     , BUTTON_POS_Y1 - BUTTON_SPACE_Y * 2, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x9d},   // READ INCR
162         {BUTTON_POS_X2                     , BUTTON_POS_Y1 - BUTTON_SPACE_Y * 1, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x9e},   // READ DECR
163         {BUTTON_POS_X2                     , BUTTON_POS_Y1 - BUTTON_SPACE_Y * 0, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0x9f},   // WRITE INCR
164 #if defined(_TK85)
165         {727                               , 237                               , 29           , 29           , 0x00},   // RESET
166 #endif
167 };
168 const struct {
169         int x, y;
170         int width, height;
171 } vm_ranges[] = {
172         {LED_POS_X1 + LED_SPACE_X * 0, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y}, // 7-seg LEDs
173         {LED_POS_X1 + LED_SPACE_X * 1, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
174         {LED_POS_X1 + LED_SPACE_X * 2, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
175         {LED_POS_X1 + LED_SPACE_X * 3, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
176         {LED_POS_X2 + LED_SPACE_X * 0, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
177         {LED_POS_X2 + LED_SPACE_X * 1, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
178         {LED_POS_X2 + LED_SPACE_X * 2, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
179         {LED_POS_X2 + LED_SPACE_X * 3, LED_POS_Y, LED_SIZE_X, LED_SIZE_Y},
180 #if defined(_TK80BS)
181         {4, 158, 512, 256}, // CRT
182 #endif
183 };
184
185 class EMU;
186 class DEVICE;
187 class EVENT;
188
189 class DATAREC;
190 class I8080;
191 #if defined(_TK80BS)
192 class I8251;
193 class IO;
194 #endif
195 class I8255;
196 class PCM1BIT;
197
198 namespace TK80 {
199 #if defined(_TK80BS)
200         class CMT;
201 #endif
202         //class MEMORY;
203         class DISPLAY;
204         class KEYBOARD;
205         class MEMBUS;
206 }
207
208 class VM : public VM_TEMPLATE
209 {
210 protected:
211         //EMU* emu;
212         
213         // devices
214         //EVENT* event;
215         
216         DATAREC* drec;
217         I8080* cpu;
218 #if defined(_TK80BS)
219         I8251* sio_b;
220         I8255* pio_b;
221         IO* memio;
222 #endif
223         I8255* pio_t;
224 //      TK80::MEMORY* memory;
225         PCM1BIT* pcm0;
226         PCM1BIT* pcm1;
227         
228 #if defined(_TK80BS)
229         TK80::CMT* cmt;
230 #endif
231         TK80::DISPLAY* display;
232         TK80::KEYBOARD* keyboard;
233         TK80::MEMBUS* memory;
234         
235         // memory
236         uint8_t mon[0x800];
237         uint8_t ext[0x7000];
238         uint8_t ram[0x5000];    // with TK-M20K
239 #if defined(_TK80BS)
240         uint8_t basic[0x2000];
241         uint8_t bsmon[0x1000];
242         uint8_t vram[0x200];
243         
244         int boot_mode;
245 #endif
246         
247 public:
248         // ----------------------------------------
249         // initialize
250         // ----------------------------------------
251         
252         VM(EMU* parent_emu);
253         ~VM();
254         
255         // ----------------------------------------
256         // for emulation class
257         // ----------------------------------------
258         
259         // drive virtual machine
260         void reset();
261         void run();
262         
263 #ifdef USE_DEBUGGER
264         // debugger
265         DEVICE *get_cpu(int index);
266 #endif
267         
268         // draw screen
269         void draw_screen();
270 #if defined(_TK80BS)
271         int max_draw_ranges();
272 #endif
273         
274         // sound generation
275         void initialize_sound(int rate, int samples);
276         uint16_t* create_sound(int* extra_frames);
277         int get_sound_buffer_ptr();
278 #ifdef USE_SOUND_VOLUME
279         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
280 #endif
281         
282         // notify key
283         void key_down(int code, bool repeat);
284         void key_up(int code);
285         bool get_caps_locked();
286         bool get_kana_locked();
287         
288         // user interface
289         void load_binary(int drv, const _TCHAR* file_path);
290         void save_binary(int drv, const _TCHAR* file_path);
291         void play_tape(int drv, const _TCHAR* file_path);
292         void rec_tape(int drv, const _TCHAR* file_path);
293         void close_tape(int drv);
294         bool is_tape_inserted(int drv);
295         bool is_tape_playing(int drv);
296         bool is_tape_recording(int drv);
297         int get_tape_position(int drv);
298         const _TCHAR* get_tape_message(int drv);
299         void push_play(int drv);
300         void push_stop(int drv);
301         void push_fast_forward(int drv);
302         void push_fast_rewind(int drv);
303         void push_apss_forward(int drv) {}
304         void push_apss_rewind(int drv) {}
305         bool is_frame_skippable();
306         
307         void update_config();
308         bool process_state(FILEIO* state_fio, bool loading);
309         
310         // ----------------------------------------
311         // for each device
312         // ----------------------------------------
313         
314         // devices
315         DEVICE* get_device(int id);
316         //DEVICE* dummy;
317         //DEVICE* first_device;
318         //DEVICE* last_device;
319         
320 #if defined(_TK80BS)
321         int draw_ranges;
322 #endif
323 };
324
325 #endif