1 /*
2  * machine.h - Interface to machine-specific implementations.
3  *
4  * Written by
5  *  Ettore Perazzoli <ettore@comm2000.it>
6  *  Andreas Boose <viceteam@t-online.de>
7  *
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #ifndef VICE_MACHINE_H
29 #define VICE_MACHINE_H
30 
31 #include "types.h"
32 
33 /* The following stuff must be defined once per every emulated CBM machine.  */
34 
35 /* Name of the machine.  */
36 extern const char machine_name[];
37 
38 /* A little handier way to identify the machine: */
39 #define VICE_MACHINE_NONE      0
40 #define VICE_MACHINE_C64       1
41 #define VICE_MACHINE_C128      2
42 #define VICE_MACHINE_VIC20     3
43 #define VICE_MACHINE_PET       4
44 #define VICE_MACHINE_CBM5x0    5
45 #define VICE_MACHINE_CBM6x0    6
46 #define VICE_MACHINE_PLUS4     7
47 #define VICE_MACHINE_C64DTV    8
48 #define VICE_MACHINE_C64SC     9
49 #define VICE_MACHINE_VSID      10
50 #define VICE_MACHINE_SCPU64    11
51 #define VICE_MACHINE_C1541     12
52 #define VICE_MACHINE_PETCAT    13
53 
54 /* Sync factors (changed to positive 2016-11-07, BW)  */
55 #define MACHINE_SYNC_PAL     1
56 #define MACHINE_SYNC_NTSC    2
57 #define MACHINE_SYNC_NTSCOLD 3
58 #define MACHINE_SYNC_PALN    4
59 
60 struct machine_timing_s {
61     unsigned int cycles_per_line;
62     long cycles_per_rfsh;
63     long cycles_per_sec;
64     unsigned int power_freq;   /* mains power frequency in hz */
65     double rfsh_per_sec;
66     unsigned int screen_lines;
67 };
68 typedef struct machine_timing_s machine_timing_t;
69 
70 extern int machine_class;
71 extern
72 #ifdef __OS2__
73 const
74 #endif
75 int console_mode;
76 extern int video_disabled_mode;
77 
78 #define MACHINE_JAM_ACTION_DIALOG       0
79 #define MACHINE_JAM_ACTION_CONTINUE     1
80 #define MACHINE_JAM_ACTION_MONITOR      2
81 #define MACHINE_JAM_ACTION_RESET        3
82 #define MACHINE_JAM_ACTION_HARD_RESET   4
83 #define MACHINE_JAM_ACTION_QUIT         5
84 #define MACHINE_NUM_JAM_ACTIONS         6
85 
86 /* Initialize the machine's resources.  */
87 extern int machine_common_resources_init(void);
88 extern int machine_resources_init(void);
89 extern void machine_common_resources_shutdown(void);
90 extern void machine_resources_shutdown(void);
91 
92 /* Initialize the machine's command-line options.  */
93 extern int machine_common_cmdline_options_init(void);
94 extern int machine_cmdline_options_init(void);
95 
96 /* Initialize the machine.  */
97 extern void machine_setup_context(void);
98 extern int machine_init(void);
99 extern int machine_specific_init(void);
100 extern void machine_early_init(void);
101 
102 /* Initialize the main CPU of the machine.  */
103 extern void machine_maincpu_init(void);
104 
105 /* Reset the machine.  */
106 #define MACHINE_RESET_MODE_SOFT 0
107 #define MACHINE_RESET_MODE_HARD 1
108 extern void machine_trigger_reset(const unsigned int reset_mode);
109 extern void machine_reset(void);
110 extern void machine_specific_reset(void);
111 extern void machine_reset_event_playback(CLOCK offset, void *data);
112 
113 /* Power-up the machine.  */
114 extern void machine_specific_powerup(void);
115 
116 /* Shutdown the emachine.  */
117 extern void machine_shutdown(void);
118 extern void machine_specific_shutdown(void);
119 
120 /* Set the state of the RESTORE key (!=0 means pressed) */
121 extern void machine_set_restore_key(int v);
122 
123 /* returns 1 if key is present */
124 extern int machine_has_restore_key(void);
125 
126 /* Get the number of CPU cylces per second.  This is used in various parts.  */
127 extern long machine_get_cycles_per_second(void);
128 
129 /* Get the number of CPU cylces per frame. */
130 extern long machine_get_cycles_per_frame(void);
131 
132 /* Set the screen refresh rate, as this is variable in the CRTC.  */
133 extern void machine_set_cycles_per_frame(long cpf);
134 
135 /* Get current line and cycle. */
136 extern void machine_get_line_cycle(unsigned int *line, unsigned int *cycle, int *half_cycle);
137 
138 struct snapshot_stream_s;
139 
140 /* Write a snapshot to stream (file or memory).  */
141 extern int machine_write_snapshot_to_stream(struct snapshot_stream_s *stream, int save_roms, int save_disks,
142                                    int event_mode);
143 
144 /* Read a snapshot from stream (file or memory).  */
145 extern int machine_read_snapshot_from_stream(struct snapshot_stream_s *stream, int event_mode);
146 
147 /* Write a snapshot.  */
148 extern int machine_write_snapshot(const char *name, int save_roms,
149                                   int save_disks, int even_mode);
150 
151 /* Read a snapshot.  */
152 extern int machine_read_snapshot(const char *name, int even_mode);
153 
154 /* handle pending interrupts - needed by libsid.a.  */
155 extern void machine_handle_pending_alarms(int num_write_cycles);
156 
157 /* Autodetect PSID file.  */
158 extern int machine_autodetect_psid(const char *name);
159 extern void machine_play_psid(int tune);
160 
161 /* Check the base address for the second sid chip.  */
162 extern int machine_sid2_check_range(unsigned int sid2_adr);
163 
164 /* Check the base address for the third sid chip.  */
165 extern int machine_sid3_check_range(unsigned int sid3_adr);
166 
167 /* Check the base address for the fourth sid chip.  */
168 extern int machine_sid4_check_range(unsigned int sid4_adr);
169 
170 /* Change the timing parameters of the maching (for example PAL/NTSC).  */
171 extern void machine_change_timing(int timeval, int border_mode);
172 
173 /* Get screenshot data.  */
174 struct screenshot_s;
175 struct video_canvas_s;
176 struct canvas_refresh_s;
177 extern int machine_screenshot(struct screenshot_s *screenshot,
178                               struct video_canvas_s *canvas);
179 extern int machine_canvas_async_refresh(struct canvas_refresh_s *ref,
180                                         struct video_canvas_s *canvas);
181 
182 #define JAM_NONE       0
183 #define JAM_RESET      1
184 #define JAM_HARD_RESET 2
185 #define JAM_MONITOR    3
186 unsigned int machine_jam(const char *format, ...);
187 
188 /* Update memory pointers if memory mapping has changed. */
189 extern void machine_update_memory_ptrs(void);
190 
191 extern int machine_keymap_index;
192 extern char *machine_keymap_file_list[];
193 extern int machine_num_keyboard_mappings(void);
194 
195 struct image_contents_s;
196 extern struct image_contents_s *machine_diskcontents_bus_read(unsigned int unit);
197 
198 /* Romset handling.  */
199 extern void machine_romset_init(void);
200 extern int machine_romset_file_load(const char *filename);
201 extern int machine_romset_file_save(const char *filename);
202 extern char *machine_romset_file_list(void);
203 extern int machine_romset_archive_item_create(const char *romset_name);
204 
205 extern uint8_t machine_tape_type_default(void);
206 extern uint8_t machine_tape_behaviour(void);
207 
208 /* Check if address is in RAM (for autostart) */
209 extern int machine_addr_in_ram(unsigned int addr);
210 
211 /* Get "real" name for machine. May differ from machine_name.  */
212 extern const char *machine_get_name(void);
213 
214 /* Get keymap res name with range checking */
215 extern char *machine_get_keymap_res_name(int val);
216 
217 /* mapping info for GUIs */
218 typedef struct {
219     char *name;
220     int type;
221     unsigned int flags;
222 } kbdtype_info_t;
223 
224 extern int machine_get_num_keyboard_types(void);
225 extern kbdtype_info_t *machine_get_keyboard_info_list(void);
226 
227 extern int machine_get_keyboard_type(void);
228 extern char *machine_get_keyboard_type_name(int type);
229 
230 extern int machine_register_userport(void);
231 
232 #endif
233