Add copyright message to gles_video
[gpsp.git] / main.h
CommitLineData
2823a4c8 1/* gameplaySP
2 *
3 * Copyright (C) 2006 Exophase <exophase@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef MAIN_H
21#define MAIN_H
22
23typedef enum
24{
25 TIMER_INACTIVE,
26 TIMER_PRESCALE,
27 TIMER_CASCADE
28} timer_status_type;
29
30typedef enum
31{
32 TIMER_NO_IRQ,
33 TIMER_TRIGGER_IRQ
34} timer_irq_type;
35
36
37typedef enum
38{
39 TIMER_DS_CHANNEL_NONE,
40 TIMER_DS_CHANNEL_A,
41 TIMER_DS_CHANNEL_B,
42 TIMER_DS_CHANNEL_BOTH
43} timer_ds_channel_type;
44
45typedef struct
46{
47 s32 count;
48 u32 reload;
49 u32 prescale;
50 u32 stop_cpu_ticks;
2f1c528a 51 fixed8_24 frequency_step;
2823a4c8 52 timer_ds_channel_type direct_sound_channels;
53 timer_irq_type irq;
54 timer_status_type status;
55} timer_type;
56
57typedef enum
58{
59 auto_frameskip,
60 manual_frameskip,
61 no_frameskip
62} frameskip_type;
63
64extern u32 cpu_ticks;
65extern u32 frame_ticks;
66extern u32 execute_cycles;
67extern frameskip_type current_frameskip_type;
68extern u32 frameskip_value;
69extern u32 random_skip;
70extern u32 global_cycles_per_instruction;
71extern u32 synchronize_flag;
72extern u32 skip_next_frame;
73
2823a4c8 74extern u32 cycle_memory_access;
75extern u32 cycle_pc_relative_access;
76extern u32 cycle_sp_relative_access;
77extern u32 cycle_block_memory_access;
78extern u32 cycle_block_memory_sp_access;
79extern u32 cycle_block_memory_words;
80extern u32 cycle_dma16_words;
81extern u32 cycle_dma32_words;
82extern u32 flush_ram_count;
83
84extern u64 base_timestamp;
85
bbba3209 86extern char main_path[512];
2823a4c8 87
88extern u32 update_backup_flag;
89extern u32 clock_speed;
90
91u32 update_gba();
92void reset_gba();
93void synchronize();
94void quit();
95void delay_us(u32 us_count);
96void get_ticks_us(u64 *tick_return);
bbba3209 97void game_name_ext(char *src, char *buffer, char *extension);
2823a4c8 98void main_write_mem_savestate(file_tag_type savestate_file);
99void main_read_savestate(file_tag_type savestate_file);
100
101
102#ifdef PSP_BUILD
103
bbba3209 104u32 file_length(char *filename, s32 dummy);
2823a4c8 105
ee0a3871 106#else
107
bbba3209 108u32 file_length(char *dummy, FILE *fp);
ee0a3871 109
2823a4c8 110#endif
111
2823a4c8 112extern u32 real_frame_count;
113extern u32 virtual_frame_count;
114extern u32 max_frameskip;
115extern u32 num_skipped_frames;
116
bbba3209 117#ifdef IN_MEMORY_C
118
119extern timer_type timer[4];
120static u32 prescale_table[] = { 0, 6, 8, 10 };
121
2823a4c8 122#define count_timer(timer_number) \
123 timer[timer_number].reload = 0x10000 - value; \
124 if(timer_number < 2) \
125 { \
126 u32 timer_reload = \
127 timer[timer_number].reload << timer[timer_number].prescale; \
128 sound_update_frequency_step(timer_number); \
129 } \
130
131#define adjust_sound_buffer(timer_number, channel) \
132 if(timer[timer_number].direct_sound_channels & (0x01 << channel)) \
133 { \
134 direct_sound_channel[channel].buffer_index = \
2f1c528a 135 (gbc_sound_buffer_index + buffer_adjust) % BUFFER_SIZE; \
2823a4c8 136 } \
137
138#define trigger_timer(timer_number) \
139 if(value & 0x80) \
140 { \
141 if(timer[timer_number].status == TIMER_INACTIVE) \
142 { \
143 u32 prescale = prescale_table[value & 0x03]; \
144 u32 timer_reload = timer[timer_number].reload; \
145 \
146 if((value >> 2) & 0x01) \
147 timer[timer_number].status = TIMER_CASCADE; \
148 else \
149 timer[timer_number].status = TIMER_PRESCALE; \
150 \
151 timer[timer_number].prescale = prescale; \
152 timer[timer_number].irq = (value >> 6) & 0x01; \
153 \
154 address16(io_registers, 0x100 + (timer_number * 4)) = \
155 -timer_reload; \
156 \
157 timer_reload <<= prescale; \
158 timer[timer_number].count = timer_reload; \
159 \
160 if(timer_reload < execute_cycles) \
161 execute_cycles = timer_reload; \
162 \
163 if(timer_number < 2) \
164 { \
165 u32 buffer_adjust = \
2f1c528a 166 (u32)(((float)(cpu_ticks - gbc_sound_last_cpu_ticks) * \
167 sound_frequency) / GBC_BASE_RATE) * 2; \
2823a4c8 168 \
169 sound_update_frequency_step(timer_number); \
170 adjust_sound_buffer(timer_number, 0); \
171 adjust_sound_buffer(timer_number, 1); \
172 } \
173 } \
174 } \
175 else \
176 { \
177 if(timer[timer_number].status != TIMER_INACTIVE) \
178 { \
179 timer[timer_number].status = TIMER_INACTIVE; \
180 timer[timer_number].stop_cpu_ticks = cpu_ticks; \
181 } \
182 } \
183 address16(io_registers, 0x102 + (timer_number * 4)) = value; \
184
bbba3209 185#endif // IN_MEMORY_C
186
187void change_ext(const char *src, char *buffer, const char *extension);
d0944fc9 188void make_rpath(char *buff, size_t size, const char *ext);
2823a4c8 189
1d02ca75 190void set_clock_speed();
191
2823a4c8 192#endif
193
194