OSDN Git Service

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