Add copyright message to gles_video
[gpsp.git] / main.h
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
23 typedef enum
24 {
25   TIMER_INACTIVE,
26   TIMER_PRESCALE,
27   TIMER_CASCADE
28 } timer_status_type;
29
30 typedef enum
31 {
32   TIMER_NO_IRQ,
33   TIMER_TRIGGER_IRQ
34 } timer_irq_type;
35
36
37 typedef 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
45 typedef struct
46 {
47   s32 count;
48   u32 reload;
49   u32 prescale;
50   u32 stop_cpu_ticks;
51   fixed8_24 frequency_step;
52   timer_ds_channel_type direct_sound_channels;
53   timer_irq_type irq;
54   timer_status_type status;
55 } timer_type;
56
57 typedef enum
58 {
59   auto_frameskip,
60   manual_frameskip,
61   no_frameskip
62 } frameskip_type;
63
64 extern u32 cpu_ticks;
65 extern u32 frame_ticks;
66 extern u32 execute_cycles;
67 extern frameskip_type current_frameskip_type;
68 extern u32 frameskip_value;
69 extern u32 random_skip;
70 extern u32 global_cycles_per_instruction;
71 extern u32 synchronize_flag;
72 extern u32 skip_next_frame;
73
74 extern u32 cycle_memory_access;
75 extern u32 cycle_pc_relative_access;
76 extern u32 cycle_sp_relative_access;
77 extern u32 cycle_block_memory_access;
78 extern u32 cycle_block_memory_sp_access;
79 extern u32 cycle_block_memory_words;
80 extern u32 cycle_dma16_words;
81 extern u32 cycle_dma32_words;
82 extern u32 flush_ram_count;
83
84 extern u64 base_timestamp;
85
86 extern char main_path[512];
87
88 extern u32 update_backup_flag;
89 extern u32 clock_speed;
90
91 u32 update_gba();
92 void reset_gba();
93 void synchronize();
94 void quit();
95 void delay_us(u32 us_count);
96 void get_ticks_us(u64 *tick_return);
97 void game_name_ext(char *src, char *buffer, char *extension);
98 void main_write_mem_savestate(file_tag_type savestate_file);
99 void main_read_savestate(file_tag_type savestate_file);
100
101
102 #ifdef PSP_BUILD
103
104 u32 file_length(char *filename, s32 dummy);
105
106 #else
107
108 u32 file_length(char *dummy, FILE *fp);
109
110 #endif
111
112 extern u32 real_frame_count;
113 extern u32 virtual_frame_count;
114 extern u32 max_frameskip;
115 extern u32 num_skipped_frames;
116
117 #ifdef IN_MEMORY_C
118
119 extern timer_type timer[4];
120 static u32 prescale_table[] = { 0, 6, 8, 10 };
121
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 =                              \
135      (gbc_sound_buffer_index + buffer_adjust) % BUFFER_SIZE;                  \
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 =                                                   \
166          (u32)(((float)(cpu_ticks - gbc_sound_last_cpu_ticks) *               \
167          sound_frequency) / GBC_BASE_RATE) * 2;                               \
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
185 #endif // IN_MEMORY_C
186
187 void change_ext(const char *src, char *buffer, const char *extension);
188 void make_rpath(char *buff, size_t size, const char *ext);
189
190 void set_clock_speed();
191
192 #endif
193
194