| 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 | #include "warm.h" |
| 28 | |
| 29 | extern int main_cpuspeed(int argc, char *argv[]); |
| 30 | extern SDL_Surface* screen; |
| 31 | |
| 32 | u32 gp2x_audio_volume = 74/2; |
| 33 | u32 gpsp_gp2x_dev_audio = 0; |
| 34 | u32 gpsp_gp2x_dev = 0; |
| 35 | u32 gpsp_gp2x_gpiodev = 0; |
| 36 | |
| 37 | static volatile u16 *gpsp_gp2x_memregs; |
| 38 | static volatile u32 *gpsp_gp2x_memregl; |
| 39 | unsigned short *gp2x_memregs; |
| 40 | |
| 41 | static volatile u16 *MEM_REG; |
| 42 | |
| 43 | s32 gp2x_load_mmuhack() |
| 44 | { |
| 45 | s32 mmufd = open("/dev/mmuhack", O_RDWR); |
| 46 | |
| 47 | if(mmufd < 0) |
| 48 | { |
| 49 | system("/sbin/insmod mmuhack.o"); |
| 50 | mmufd = open("/dev/mmuhack", O_RDWR); |
| 51 | } |
| 52 | |
| 53 | if(mmufd < 0) |
| 54 | return -1; |
| 55 | |
| 56 | close(mmufd); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | void gp2x_init() |
| 61 | { |
| 62 | gpsp_gp2x_dev = open("/dev/mem", O_RDWR); |
| 63 | gpsp_gp2x_dev_audio = open("/dev/mixer", O_RDWR); |
| 64 | gpsp_gp2x_memregl = |
| 65 | (unsigned long *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 66 | gpsp_gp2x_dev, 0xc0000000); |
| 67 | gpsp_gp2x_memregs = (unsigned short *)gpsp_gp2x_memregl; |
| 68 | #ifdef WIZ_BUILD |
| 69 | gpsp_gp2x_gpiodev = open("/dev/GPIO", O_RDONLY); |
| 70 | #endif |
| 71 | warm_init(); |
| 72 | |
| 73 | clear_screen(0); |
| 74 | // main_cpuspeed(0, NULL); |
| 75 | gp2x_memregs = (void *)gpsp_gp2x_memregs; |
| 76 | cpuctrl_init(); |
| 77 | gp2x_sound_volume(1); |
| 78 | } |
| 79 | |
| 80 | void gp2x_quit() |
| 81 | { |
| 82 | munmap((void *)gpsp_gp2x_memregl, 0x10000); |
| 83 | close(gpsp_gp2x_dev_audio); |
| 84 | close(gpsp_gp2x_dev); |
| 85 | #ifdef WIZ_BUILD |
| 86 | close(gpsp_gp2x_gpiodev); |
| 87 | #endif |
| 88 | |
| 89 | //chdir("/usr/gp2x"); |
| 90 | //execl("gp2xmenu", "gp2xmenu", NULL); |
| 91 | exit(0); |
| 92 | } |
| 93 | |
| 94 | void gp2x_sound_volume(u32 volume_up) |
| 95 | { |
| 96 | u32 volume; |
| 97 | if((volume_up == 0) && (gp2x_audio_volume > 0)) |
| 98 | gp2x_audio_volume--; |
| 99 | |
| 100 | if((volume_up != 0) && (gp2x_audio_volume < 100)) |
| 101 | gp2x_audio_volume++; |
| 102 | |
| 103 | volume = (gp2x_audio_volume * 0x50) / 100; |
| 104 | volume = (gp2x_audio_volume << 8) | gp2x_audio_volume; |
| 105 | ioctl(gpsp_gp2x_dev_audio, SOUND_MIXER_WRITE_PCM, &volume); |
| 106 | } |
| 107 | |
| 108 | u32 gpsp_gp2x_joystick_read(void) |
| 109 | { |
| 110 | #ifdef WIZ_BUILD |
| 111 | u32 value = 0; |
| 112 | read(gpsp_gp2x_gpiodev, &value, 4); |
| 113 | if(value & 0x02) |
| 114 | value |= 0x05; |
| 115 | if(value & 0x08) |
| 116 | value |= 0x14; |
| 117 | if(value & 0x20) |
| 118 | value |= 0x50; |
| 119 | if(value & 0x80) |
| 120 | value |= 0x41; |
| 121 | return value; |
| 122 | #else |
| 123 | u32 value = (gpsp_gp2x_memregs[0x1198 >> 1] & 0x00FF); |
| 124 | |
| 125 | if(value == 0xFD) |
| 126 | value = 0xFA; |
| 127 | if(value == 0xF7) |
| 128 | value = 0xEB; |
| 129 | if(value == 0xDF) |
| 130 | value = 0xAF; |
| 131 | if(value == 0x7F) |
| 132 | value = 0xBE; |
| 133 | |
| 134 | return ~((gpsp_gp2x_memregs[0x1184 >> 1] & 0xFF00) | value | |
| 135 | (gpsp_gp2x_memregs[0x1186 >> 1] << 16)); |
| 136 | #endif |
| 137 | } |
| 138 | |
| 139 | #ifdef WIZ_BUILD |
| 140 | void cpuctrl_init(void) |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | void set_FCLK(u32 MHZ) |
| 145 | { |
| 146 | } |
| 147 | #endif |
| 148 | |