| 1 | /* Parts used from cpuctrl */ |
| 2 | /* cpuctrl for GP2X |
| 3 | Copyright (C) 2005 Hermes/PS2Reality |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (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 |
| 13 | GNU 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 St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include <sys/mman.h> |
| 23 | #include <sys/ioctl.h> |
| 24 | #include <sys/soundcard.h> |
| 25 | #include "../common.h" |
| 26 | #include "gp2x.h" |
| 27 | |
| 28 | extern int main_cpuspeed(int argc, char *argv[]); |
| 29 | extern SDL_Surface* screen; |
| 30 | |
| 31 | u32 gp2x_audio_volume = 74/2; |
| 32 | u32 gpsp_gp2x_dev_audio = 0; |
| 33 | u32 gpsp_gp2x_dev = 0; |
| 34 | |
| 35 | volatile u16 *gpsp_gp2x_memregs; |
| 36 | volatile u32 *gpsp_gp2x_memregl; |
| 37 | unsigned short *gp2x_memregs; |
| 38 | |
| 39 | static volatile u16 *MEM_REG; |
| 40 | |
| 41 | s32 gp2x_load_mmuhack() |
| 42 | { |
| 43 | s32 mmufd = open("/dev/mmuhack", O_RDWR); |
| 44 | |
| 45 | if(mmufd < 0) |
| 46 | { |
| 47 | system("/sbin/insmod mmuhack.o"); |
| 48 | mmufd = open("/dev/mmuhack", O_RDWR); |
| 49 | } |
| 50 | |
| 51 | if(mmufd < 0) |
| 52 | return -1; |
| 53 | |
| 54 | close(mmufd); |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | void gp2x_overclock() |
| 59 | { |
| 60 | gpsp_gp2x_dev = open("/dev/mem", O_RDWR); |
| 61 | gpsp_gp2x_dev_audio = open("/dev/mixer", O_RDWR); |
| 62 | gpsp_gp2x_memregl = |
| 63 | (unsigned long *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 64 | gpsp_gp2x_dev, 0xc0000000); |
| 65 | gpsp_gp2x_memregs = (unsigned short *)gpsp_gp2x_memregl; |
| 66 | |
| 67 | clear_screen(0); |
| 68 | // main_cpuspeed(0, NULL); |
| 69 | gp2x_memregs = (void *)gpsp_gp2x_memregs; |
| 70 | cpuctrl_init(); |
| 71 | gp2x_sound_volume(1); |
| 72 | } |
| 73 | |
| 74 | void gp2x_quit() |
| 75 | { |
| 76 | munmap((void *)gpsp_gp2x_memregl, 0x10000); |
| 77 | close(gpsp_gp2x_dev_audio); |
| 78 | close(gpsp_gp2x_dev); |
| 79 | |
| 80 | chdir("/usr/gp2x"); |
| 81 | execl("gp2xmenu", "gp2xmenu", NULL); |
| 82 | } |
| 83 | |
| 84 | void gp2x_sound_volume(u32 volume_up) |
| 85 | { |
| 86 | u32 volume; |
| 87 | if((volume_up == 0) && (gp2x_audio_volume > 0)) |
| 88 | gp2x_audio_volume--; |
| 89 | |
| 90 | if((volume_up != 0) && (gp2x_audio_volume < 100)) |
| 91 | gp2x_audio_volume++; |
| 92 | |
| 93 | volume = (gp2x_audio_volume * 0x50) / 100; |
| 94 | volume = (gp2x_audio_volume << 8) | gp2x_audio_volume; |
| 95 | ioctl(gpsp_gp2x_dev_audio, SOUND_MIXER_WRITE_PCM, &volume); |
| 96 | } |
| 97 | |