OSDN Git Service

[VM][Qt][General][CMAKE] Merge upstream 2016-03-01, phase 2. Expect to build and...
[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
4         Author : Takeda.Toshiya
5         Date   : 2008.08.26 -
6
7         [ virtual machine ]
8 */
9
10 #ifndef _TK80BS_H_
11 #define _TK80BS_H_
12
13 #define DEVICE_NAME             "NEC TK-80BS"
14 #define CONFIG_NAME             "tk80bs"
15
16 // device informations for virtual machine
17 #define FRAMES_PER_SEC          59.9
18 #define LINES_PER_FRAME         262
19 #define CPU_CLOCKS              2048000
20 #define HAS_I8080
21 #define I8255_AUTO_HAND_SHAKE
22 #define SCREEN_WIDTH            784
23 #define SCREEN_HEIGHT           428
24 #define MEMORY_ADDR_MAX         0x10000
25 #define MEMORY_BANK_SIZE        0x200
26 #define IO_ADDR_MAX             0x10000
27
28 // device informations for win32
29 #define ONE_BOARD_MICRO_COMPUTER
30 #define MAX_BUTTONS             25
31 //#define MAX_DRAW_RANGES               9
32 #define USE_BOOT_MODE           2
33 //#define USE_DIPSWITCH
34 //#define DIPSWITCH_DEFAULT     0
35 #define USE_TAPE
36 #define TAPE_BINARY_ONLY
37 #define USE_BINARY_FILE1
38 #define NOTIFY_KEY_DOWN
39 #define USE_ALT_F10_KEY
40 #define USE_AUTO_KEY            5
41 #define USE_AUTO_KEY_RELEASE    6
42 #define USE_AUTO_KEY_NO_CAPS
43 #define USE_SOUND_VOLUME        2
44 #define USE_DEBUGGER
45 #define USE_STATE
46
47 #include "../../common.h"
48 #include "../../fileio.h"
49
50 #ifdef USE_SOUND_VOLUME
51 static const _TCHAR *sound_device_caption[] = {
52         _T("Beep #1"), _T("Beep #2"),
53 };
54 #endif
55
56 const struct {
57         const _TCHAR* caption;
58         int x, y;
59         int width, height;
60         int font_size;
61         int code;
62 } vm_buttons[] = {
63         // virtual key codes 0x80-0x8f and 0x98-0x9f are not used in pc keyboard
64         {_T("0"),               523 + 46 * 0, 190 + 46 * 4, 40, 40, 20, 0x80},
65         {_T("1"),               523 + 46 * 1, 190 + 46 * 4, 40, 40, 20, 0x81},
66         {_T("2"),               523 + 46 * 2, 190 + 46 * 4, 40, 40, 20, 0x82},
67         {_T("3"),               523 + 46 * 3, 190 + 46 * 4, 40, 40, 20, 0x83},
68         {_T("4"),               523 + 46 * 0, 190 + 46 * 3, 40, 40, 20, 0x84},
69         {_T("5"),               523 + 46 * 1, 190 + 46 * 3, 40, 40, 20, 0x85},
70         {_T("6"),               523 + 46 * 2, 190 + 46 * 3, 40, 40, 20, 0x86},
71         {_T("7"),               523 + 46 * 3, 190 + 46 * 3, 40, 40, 20, 0x87},
72         {_T("8"),               523 + 46 * 0, 190 + 46 * 2, 40, 40, 20, 0x88},
73         {_T("9"),               523 + 46 * 1, 190 + 46 * 2, 40, 40, 20, 0x89},
74         {_T("A"),               523 + 46 * 2, 190 + 46 * 2, 40, 40, 20, 0x8a},
75         {_T("B"),               523 + 46 * 3, 190 + 46 * 2, 40, 40, 20, 0x8b},
76         {_T("C"),               523 + 46 * 0, 190 + 46 * 1, 40, 40, 20, 0x8c},
77         {_T("D"),               523 + 46 * 1, 190 + 46 * 1, 40, 40, 20, 0x8d},
78         {_T("E"),               523 + 46 * 2, 190 + 46 * 1, 40, 40, 20, 0x8e},
79         {_T("F"),               523 + 46 * 3, 190 + 46 * 1, 40, 40, 20, 0x8f},
80         {_T("RET"),             523 + 46 * 0, 190 + 46 * 0, 40, 40, 9,  0x98},
81         {_T("RUN"),             523 + 46 * 1, 190 + 46 * 0, 40, 40, 9,  0x99},
82         {_T("STORE\nDATA"),     523 + 46 * 2, 190 + 46 * 0, 40, 40, 9,  0x9a},
83         {_T("LOAD\nDATA"),      523 + 46 * 3, 190 + 46 * 0, 40, 40, 9,  0x9b},
84         {_T("RESET"),           523 + 46 * 4, 190 + 46 * 0, 40, 40, 9,  0x00},
85         {_T("ADRS\nSET"),       523 + 46 * 4, 190 + 46 * 1, 40, 40, 9,  0x9c},
86         {_T("READ\nINCR"),      523 + 46 * 4, 190 + 46 * 2, 40, 40, 9,  0x9d},
87         {_T("READ\nDECR"),      523 + 46 * 4, 190 + 46 * 3, 40, 40, 9,  0x9e},
88         {_T("WRITE\nINCR"),     523 + 46 * 4, 190 + 46 * 4, 40, 40, 9,  0x9f},
89 };
90 const struct {
91         int x, y;
92         int width, height;
93 } vm_ranges[] = {
94         {461 + 36 * 0, 28, 33, 46}, // 7-seg LEDs
95         {461 + 36 * 1, 28, 33, 46},
96         {461 + 36 * 2, 28, 33, 46},
97         {461 + 36 * 3, 28, 33, 46},
98         {618 + 36 * 0, 28, 33, 46},
99         {618 + 36 * 1, 28, 33, 46},
100         {618 + 36 * 2, 28, 33, 46},
101         {618 + 36 * 3, 28, 33, 46},
102         {4, 158, 512, 256}, // CRT
103 };
104
105 class EMU;
106 class DEVICE;
107 class EVENT;
108
109 class I8251;
110 class I8255;
111 class IO;
112 class MEMORY;
113 class PCM1BIT;
114 class I8080;
115
116 class CMT;
117 class DISPLAY;
118 class KEYBOARD;
119
120 class VM
121 {
122 protected:
123         EMU* emu;
124         
125         // devices
126         EVENT* event;
127         
128         I8251* sio_b;
129         I8255* pio_b;
130         I8255* pio_t;
131         IO* memio;
132         MEMORY* memory;
133         PCM1BIT* pcm0;
134         PCM1BIT* pcm1;
135         I8080* cpu;
136         
137         CMT* cmt;
138         DISPLAY* display;
139         KEYBOARD* keyboard;
140         
141         // memory
142         uint8_t mon[0x800];
143         uint8_t ext[0x7000];
144         uint8_t basic[0x2000];
145         uint8_t bsmon[0x1000];
146         uint8_t ram[0x5000];    // with TK-M20K
147         uint8_t vram[0x200];
148         
149         int boot_mode;
150         
151 public:
152         // ----------------------------------------
153         // initialize
154         // ----------------------------------------
155         
156         VM(EMU* parent_emu);
157         ~VM();
158         
159         // ----------------------------------------
160         // for emulation class
161         // ----------------------------------------
162         
163         // drive virtual machine
164         void reset();
165         void run();
166         
167 #ifdef USE_DEBUGGER
168         // debugger
169         DEVICE *get_cpu(int index);
170 #endif
171         
172         // draw screen
173         void draw_screen();
174         int max_draw_ranges();
175         
176         // sound generation
177         void initialize_sound(int rate, int samples);
178         uint16_t* create_sound(int* extra_frames);
179         int get_sound_buffer_ptr();
180 #ifdef USE_SOUND_VOLUME
181         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
182 #endif
183         
184         // notify key
185         void key_down(int code, bool repeat);
186         void key_up(int code);
187         
188         // user interface
189         void load_binary(int drv, const _TCHAR* file_path);
190         void save_binary(int drv, const _TCHAR* file_path);
191         void play_tape(const _TCHAR* file_path);
192         void rec_tape(const _TCHAR* file_path);
193         void close_tape();
194         bool is_tape_inserted();
195         bool is_frame_skippable();
196         
197         void update_config();
198         void save_state(FILEIO* state_fio);
199         bool load_state(FILEIO* state_fio);
200         
201         // ----------------------------------------
202         // for each device
203         // ----------------------------------------
204         
205         // devices
206         DEVICE* get_device(int id);
207         DEVICE* dummy;
208         DEVICE* first_device;
209         DEVICE* last_device;
210         
211         int draw_ranges;
212 };
213
214 #endif