OSDN Git Service

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