~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to backends/platform/gp2x/gp2x-hw.cpp

  • Committer: Package Import Robot
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-11-05 10:29:43 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20111105102943-zfm3dhlvy5b01u7v
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ScummVM - Graphic Adventure Engine
2
 
 *
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.
6
 
 *
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.
11
 
 
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.
16
 
 
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.
20
 
 *
21
 
 * $URL$
22
 
 * $Id$
23
 
 *
24
 
 */
25
 
 
26
 
/*
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.
30
 
 *
31
 
 */
32
 
 
33
 
// Disable symbol overrides so that we can use system headers.
34
 
#define FORBIDDEN_SYMBOL_ALLOW_ALL
35
 
 
36
 
#include "gp2x-common.h"
37
 
 
38
 
#include "gp2x-hw.h"
39
 
#include "gp2x-mem.h"
40
 
 
41
 
// Linux includes to let us goof about with the system in a 'standard' way.
42
 
#include <fcntl.h>
43
 
#include <pthread.h>
44
 
#include <signal.h>
45
 
#include <stdlib.h>
46
 
#include <stdio.h>
47
 
#include <string.h>
48
 
#include <sys/mman.h>
49
 
#include <sys/ioctl.h>
50
 
#include <sys/soundcard.h>
51
 
#include <sys/time.h>
52
 
#include <unistd.h>
53
 
 
54
 
extern "C" {
55
 
static unsigned long gp2x_dev[8]={0,0,0,0,0,0,0,0};//, gp2x_ticks_per_second;
56
 
}
57
 
 
58
 
namespace GP2X_HW {
59
 
 
60
 
enum {
61
 
        VOLUME_NOCHG                    = 0,
62
 
        VOLUME_DOWN                             = 1,
63
 
        VOLUME_UP                               = 2,
64
 
        VOLUME_CHANGE_RATE              = 8,
65
 
        VOLUME_MIN                              = 0,
66
 
        VOLUME_INITIAL                  = 60,
67
 
        VOLUME_MAX                              = 100
68
 
};
69
 
 
70
 
int volumeLevel = VOLUME_INITIAL;
71
 
 
72
 
/* system registers */
73
 
static struct
74
 
{
75
 
        unsigned short SYSCLKENREG,SYSCSETREG,FPLLVSETREG,DUALINT920,DUALINT940,DUALCTRL940;
76
 
}
77
 
system_reg;
78
 
 
79
 
static unsigned short dispclockdiv;
80
 
 
81
 
static volatile unsigned short *MEM_REG;
82
 
 
83
 
#define SYS_CLK_FREQ 7372800
84
 
 
85
 
void deviceInit() {
86
 
        // Open devices
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);
90
 
}
91
 
 
92
 
void deviceDeinit() {
93
 
        // Close devices
94
 
        {
95
 
                int i;
96
 
                for (i=0;i<8;i++)
97
 
                {
98
 
                        if (gp2x_dev[i])
99
 
                        {
100
 
                                close(gp2x_dev[i]);
101
 
                        }
102
 
                }
103
 
        }
104
 
 
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;
112
 
 
113
 
        unpatchMMU();
114
 
}
115
 
 
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;
120
 
    } else {
121
 
        if(direction == VOLUME_UP)   volumeLevel += VOLUME_CHANGE_RATE;
122
 
        if(direction == VOLUME_DOWN) volumeLevel -= VOLUME_CHANGE_RATE;
123
 
    }
124
 
 
125
 
    if (volumeLevel < VOLUME_MIN) volumeLevel = VOLUME_MIN;
126
 
    if (volumeLevel > VOLUME_MAX) volumeLevel = VOLUME_MAX;
127
 
 
128
 
    unsigned long soundDev = open("/dev/mixer", O_RDWR);
129
 
 
130
 
    if(soundDev) {
131
 
        int vol = ((volumeLevel << 8) | volumeLevel);
132
 
        ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
133
 
        close(soundDev);
134
 
    }
135
 
}
136
 
 
137
 
void setCpuspeed(unsigned int mhz)
138
 
{
139
 
        set_FCLK(mhz);
140
 
        set_DCLK_Div(0);
141
 
        set_920_Div(0);
142
 
}
143
 
 
144
 
int getBattLevel() {
145
 
    int devbatt;
146
 
    unsigned short currentval=0;
147
 
    devbatt = open("/dev/batt", O_RDONLY);
148
 
    read (devbatt, &currentval, 2);
149
 
    close (devbatt);
150
 
    return (currentval);
151
 
}
152
 
 
153
 
void set_display_clock_div(unsigned div)
154
 
{
155
 
        div=((div & 63) | 64)<<8;
156
 
        MEM_REG[0x924>>1]=(MEM_REG[0x924>>1] & ~(255<<8)) | div;
157
 
}
158
 
 
159
 
 
160
 
void set_FCLK(unsigned MHZ)
161
 
{
162
 
        unsigned v;
163
 
        unsigned mdiv,pdiv=3,scale=0;
164
 
        MHZ*=1000000;
165
 
        mdiv=(MHZ*pdiv)/SYS_CLK_FREQ;
166
 
        mdiv=((mdiv-8)<<8) & 0xff00;
167
 
        pdiv=((pdiv-2)<<2) & 0xfc;
168
 
        scale&=3;
169
 
        v=mdiv | pdiv | scale;
170
 
        MEM_REG[0x910>>1]=v;
171
 
}
172
 
 
173
 
 
174
 
void set_920_Div(unsigned short div)
175
 
{
176
 
        unsigned short v;
177
 
        v = MEM_REG[0x91c>>1] & (~0x3);
178
 
        MEM_REG[0x91c>>1] = (div & 0x7) | v;
179
 
}
180
 
 
181
 
 
182
 
void set_DCLK_Div( unsigned short div )
183
 
{
184
 
        unsigned short v;
185
 
        v = (unsigned short)( MEM_REG[0x91c>>1] & (~(0x7 << 6)) );
186
 
        MEM_REG[0x91c>>1] = ((div & 0x7) << 6) | v;
187
 
}
188
 
 
189
 
 
190
 
void Disable_940(void)
191
 
{
192
 
        MEM_REG[0x3B42>>1];
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;
197
 
}
198
 
 
199
 
void gp2x_video_wait_vsync(void)
200
 
{
201
 
        MEM_REG[0x2846>>1]=(MEM_REG[0x2846>>1] | 0x20) & ~2;
202
 
        while (!(MEM_REG[0x2846>>1] & 2));
203
 
}
204
 
 
205
 
} /* namespace GP2X_HW */
206
 
 
207
 
namespace GPH {
208
 
 
209
 
enum {
210
 
        /* Touchscreen TapMode */
211
 
        TAPMODE_LEFT            = 0,
212
 
        TAPMODE_RIGHT           = 1,
213
 
        TAPMODE_HOVER           = 2
214
 
};
215
 
 
216
 
int tapmodeLevel = TAPMODE_LEFT;
217
 
 
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;
225
 
        } else {
226
 
                tapmodeLevel = TAPMODE_LEFT;
227
 
    }
228
 
}
229
 
 
230
 
 
231
 
} /* namespace GPH */