1
/* ScummVM - Graphic Adventure Engine
3
* ScummVM is the legal property of its developers, whose names
4
* are too numerous to list here. Please refer to the COPYRIGHT
5
* file distributed with this source distribution.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27
* GP2X: Hardware Stuff.
28
* Thanks to Rlyeh, Snaff, Squidge, Hermes, PS2Reality and RobBrown
29
* for there help with us all getting to grips with this.
33
// Disable symbol overrides so that we can use system headers.
34
#define FORBIDDEN_SYMBOL_ALLOW_ALL
36
#include "gp2x-common.h"
41
// Linux includes to let us goof about with the system in a 'standard' way.
49
#include <sys/ioctl.h>
50
#include <sys/soundcard.h>
55
static unsigned long gp2x_dev[8]={0,0,0,0,0,0,0,0};//, gp2x_ticks_per_second;
64
VOLUME_CHANGE_RATE = 8,
70
int volumeLevel = VOLUME_INITIAL;
72
/* system registers */
75
unsigned short SYSCLKENREG,SYSCSETREG,FPLLVSETREG,DUALINT920,DUALINT940,DUALCTRL940;
79
static unsigned short dispclockdiv;
81
static volatile unsigned short *MEM_REG;
83
#define SYS_CLK_FREQ 7372800
87
if (!gp2x_dev[0]) gp2x_dev[0] = open("/dev/mixer", O_RDWR);
88
if (!gp2x_dev[1]) gp2x_dev[1] = open("/dev/batt", O_RDONLY);
89
if (!gp2x_dev[2]) gp2x_dev[2] = open("/dev/mem", O_RDWR);
105
MEM_REG[0x91c>>1] = system_reg.SYSCSETREG;
106
MEM_REG[0x910>>1] = system_reg.FPLLVSETREG;
107
MEM_REG[0x3B40>>1] = system_reg.DUALINT920;
108
MEM_REG[0x3B42>>1] = system_reg.DUALINT940;
109
MEM_REG[0x3B48>>1] = system_reg.DUALCTRL940;
110
MEM_REG[0x904>>1] = system_reg.SYSCLKENREG;
111
MEM_REG[0x924>>1] = dispclockdiv;
116
void mixerMoveVolume(int direction) {
117
if (volumeLevel <= 10) {
118
if (direction == VOLUME_UP) volumeLevel += VOLUME_CHANGE_RATE/2;
119
if (direction == VOLUME_DOWN) volumeLevel -= VOLUME_CHANGE_RATE/2;
121
if(direction == VOLUME_UP) volumeLevel += VOLUME_CHANGE_RATE;
122
if(direction == VOLUME_DOWN) volumeLevel -= VOLUME_CHANGE_RATE;
125
if (volumeLevel < VOLUME_MIN) volumeLevel = VOLUME_MIN;
126
if (volumeLevel > VOLUME_MAX) volumeLevel = VOLUME_MAX;
128
unsigned long soundDev = open("/dev/mixer", O_RDWR);
131
int vol = ((volumeLevel << 8) | volumeLevel);
132
ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
137
void setCpuspeed(unsigned int mhz)
146
unsigned short currentval=0;
147
devbatt = open("/dev/batt", O_RDONLY);
148
read (devbatt, ¤tval, 2);
153
void set_display_clock_div(unsigned div)
155
div=((div & 63) | 64)<<8;
156
MEM_REG[0x924>>1]=(MEM_REG[0x924>>1] & ~(255<<8)) | div;
160
void set_FCLK(unsigned MHZ)
163
unsigned mdiv,pdiv=3,scale=0;
165
mdiv=(MHZ*pdiv)/SYS_CLK_FREQ;
166
mdiv=((mdiv-8)<<8) & 0xff00;
167
pdiv=((pdiv-2)<<2) & 0xfc;
169
v=mdiv | pdiv | scale;
174
void set_920_Div(unsigned short div)
177
v = MEM_REG[0x91c>>1] & (~0x3);
178
MEM_REG[0x91c>>1] = (div & 0x7) | v;
182
void set_DCLK_Div( unsigned short div )
185
v = (unsigned short)( MEM_REG[0x91c>>1] & (~(0x7 << 6)) );
186
MEM_REG[0x91c>>1] = ((div & 0x7) << 6) | v;
190
void Disable_940(void)
193
MEM_REG[0x3B42>>1]=0;
194
MEM_REG[0x3B46>>1]=0xffff;
195
MEM_REG[0x3B48>>1]|= (1 << 7);
196
MEM_REG[0x904>>1]&=0xfffe;
199
void gp2x_video_wait_vsync(void)
201
MEM_REG[0x2846>>1]=(MEM_REG[0x2846>>1] | 0x20) & ~2;
202
while (!(MEM_REG[0x2846>>1] & 2));
205
} /* namespace GP2X_HW */
210
/* Touchscreen TapMode */
216
int tapmodeLevel = TAPMODE_LEFT;
218
void ToggleTapMode() {
219
if (tapmodeLevel == TAPMODE_LEFT) {
220
tapmodeLevel = TAPMODE_RIGHT;
221
} else if (tapmodeLevel == TAPMODE_RIGHT) {
222
tapmodeLevel = TAPMODE_HOVER;
223
} else if (tapmodeLevel == TAPMODE_HOVER) {
224
tapmodeLevel = TAPMODE_LEFT;
226
tapmodeLevel = TAPMODE_LEFT;
231
} /* namespace GPH */