OSDN Git Service

[VM][EVENT] Specify CPU per VM.
[csp-qt/common_source_project-fm7.git] / source / src / vm / familybasic / familybasic.h
1 /*
2         Nintendo Family BASIC Emulator 'eFamilyBASIC'
3
4         Origin : nester
5         Author : Takeda.Toshiya
6         Date   : 2010.08.11-
7
8         [ virtual machine ]
9 */
10
11 #ifndef _FAMILYBASIC_H_
12 #define _FAMILYBASIC_H_
13
14 #define DEVICE_NAME             "Nintendo Family BASIC"
15 #define CONFIG_NAME             "familybasic"
16
17 // device informations for virtual machine
18 #define FRAMES_PER_SEC          59.98
19 //#define LINES_PER_FRAME       262
20 #define LINES_PER_FRAME         525 // 262.5*2
21 #define CPU_CLOCKS              1789772
22 #define SCREEN_WIDTH            256
23 #define SCREEN_HEIGHT           240
24 // pixel aspect should be 8:7
25 #define WINDOW_HEIGHT_ASPECT    210
26 #define HAS_N2A03
27
28 // device informations for win32
29 #define SUPPORT_TV_RENDER
30 #define USE_BOOT_MODE           6
31 #define USE_TAPE1
32 #define USE_ALT_F10_KEY
33 #define USE_AUTO_KEY            5
34 #define USE_AUTO_KEY_RELEASE    6
35 #define USE_AUTO_KEY_NO_CAPS
36 #define USE_SOUND_VOLUME        4
37 #define USE_JOYSTICK
38 #define USE_JOY_BUTTON_CAPTIONS
39 #define USE_DEBUGGER
40 #define USE_STATE
41 #define USE_CPU_N2A03
42
43 #include "../../common.h"
44 #include "../../fileio.h"
45
46 #ifdef USE_SOUND_VOLUME
47 static const _TCHAR *sound_device_caption[] = {
48         _T("APU"), _T("VRC7"), _T("CMT (Signal)"), _T("Noise (CMT)"),
49 };
50 #endif
51
52 #ifdef USE_JOY_BUTTON_CAPTIONS
53 static const _TCHAR *joy_button_captions[] = {
54         _T("Up"),
55         _T("Down"),
56         _T("Left"),
57         _T("Right"),
58         _T("Button #1"),
59         _T("Button #2"),
60         _T("Select"),
61         _T("Start"),
62 };
63 #endif
64
65 typedef struct header_s {
66         uint8_t id[3];  // 'NES'
67         uint8_t ctrl_z; // control-z
68         uint8_t dummy;
69         uint8_t num_8k_vrom_banks;
70         uint8_t flags_1;
71         uint8_t flags_2;
72         uint8_t reserved[8];
73         uint32_t num_16k_rom_banks()
74         {
75                 return (dummy != 0) ? dummy : 256;
76         }
77         uint32_t num_8k_rom_banks()
78         {
79                 return num_16k_rom_banks() * 2;
80         }
81         uint8_t mapper()
82         {
83                 return (flags_1 >> 4) | (flags_2 & 0xf0);
84         }
85 } header_t;
86
87 class EMU;
88 class DEVICE;
89 class EVENT;
90
91 class DATAREC;
92 class N2A03;
93 class YM2413;
94
95 class MEMORY;
96 class APU;
97 class PPU;
98
99 class VM
100 {
101 protected:
102         EMU* emu;
103         
104         // devices
105         EVENT* event;
106         
107         DATAREC* drec;
108         N2A03* cpu;
109         YM2413* opll;
110         
111         MEMORY* memory;
112         APU* apu;
113         PPU* ppu;
114         
115         int boot_mode;
116         
117 public:
118         // ----------------------------------------
119         // initialize
120         // ----------------------------------------
121         
122         VM(EMU* parent_emu);
123         ~VM();
124         
125         // ----------------------------------------
126         // for emulation class
127         // ----------------------------------------
128         
129         // drive virtual machine
130         void reset();
131         void run();
132         
133 #ifdef USE_DEBUGGER
134         // debugger
135         DEVICE *get_cpu(int index);
136 #endif
137         
138         // draw screen
139         void draw_screen();
140         
141         // sound generation
142         void initialize_sound(int rate, int samples);
143         uint16_t* create_sound(int* extra_frames);
144         int get_sound_buffer_ptr();
145 #ifdef USE_SOUND_VOLUME
146         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
147 #endif
148         
149         // user interface
150         void play_tape(int drv, const _TCHAR* file_path);
151         void rec_tape(int drv, const _TCHAR* file_path);
152         void close_tape(int drv);
153         bool is_tape_inserted(int drv);
154         bool is_tape_playing(int drv);
155         bool is_tape_recording(int drv);
156         int get_tape_position(int drv);
157         const _TCHAR* get_tape_message(int drv);
158         bool is_frame_skippable();
159         
160         void update_config();
161         void save_state(FILEIO* state_fio);
162         bool load_state(FILEIO* state_fio);
163         
164         // ----------------------------------------
165         // for each device
166         // ----------------------------------------
167         
168         // devices
169         DEVICE* get_device(int id);
170         DEVICE* dummy;
171         DEVICE* first_device;
172         DEVICE* last_device;
173 };
174
175 #endif