1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/****************************************************************************\
* *
* Copyright by Casimo, 2013 *
* *
* This file is part of fxMaze. *
* *
* fxMaze is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* fxMaze is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with fxMaze. If not, see <http://www.gnu.org/licenses/>. *
* *
\****************************************************************************/
// Thanks to SimonLothar, cfxm and all the other hackers!
#include "global.h"
#include "hardware.h"
// here are some functions for direct hardware access
// they are splitted to support different calculators
char *vram, *vram2;
// backlight funcions: on, off, switch, check
// if it's unknown hardware we should do nothing
void BacklightOn()
{
if(!IsEmulator)
{
switch(getCalc())
{
case UNKNOWN: return;
case fx9860G_SLIM: (*(volatile struct st_port *)0xA4000126).DR.BIT.B5 = 1; break;
case fx9860GII: (*(volatile struct st_port *)0xA400012C).DR.BIT.B7 = 1; break;
case fx9860GII_2: (*(volatile struct st_port *)0xA4050138).DR.BIT.B4 = 1; break;
}
}
}
void BacklightOff()
{
if(!IsEmulator)
{
switch(getCalc())
{
case UNKNOWN: return;
case fx9860G_SLIM: (*(volatile struct st_port *)0xA4000126).DR.BIT.B5 = 0; break;
case fx9860GII: (*(volatile struct st_port *)0xA400012C).DR.BIT.B7 = 0; break;
case fx9860GII_2: (*(volatile struct st_port *)0xA4050138).DR.BIT.B4 = 0; break;
}
}
}
void BacklightChange()
{
if(!IsEmulator)
{
switch(getCalc())
{
case UNKNOWN: return;
case fx9860G_SLIM: (*(volatile struct st_port *)0xA4000126).DR.BIT.B5 = (*(volatile struct st_port *)0xA4000126).DR.BIT.B5 == 0; break;
case fx9860GII: (*(volatile struct st_port *)0xA400012C).DR.BIT.B7 = (*(volatile struct st_port *)0xA400012C).DR.BIT.B7 == 0; break;
case fx9860GII_2: (*(volatile struct st_port *)0xA4050138).DR.BIT.B4 = (*(volatile struct st_port *)0xA4050138).DR.BIT.B4 == 0; break;
}
}
}
int BacklightIsOn()
{
if(!IsEmulator)
{
switch(getCalc())
{
case UNKNOWN: return 0;
case fx9860G_SLIM: return (*(volatile struct st_port *)0xA4000126).DR.BIT.B5; break;
case fx9860GII: return (*(volatile struct st_port *)0xA400012C).DR.BIT.B7; break;
case fx9860GII_2: return (*(volatile struct st_port *)0xA4050138).DR.BIT.B4; break;
}
}
}
// change contrast only for known calcs
void set_contrast(int contrast)
{
if(!getCalc() == UNKNOWN && !IsEmulator)
{
char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000;
*LCD_register_selector = 6;
*LCD_data_register = contrast;
}
}
// update the display, if secure; otherwise use syscalls (sloooow!)
void display_vram()
{
if(getCalc() == UNKNOWN && !IsEmulator)
{
Bdisp_PutDisp_DD();
}
else
{
char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000, *mvram;
int i, j;
mvram = vram;
for(i=0 ; i<64 ; i++)
{
*LCD_register_selector = 4;
*LCD_data_register = i|192;
*LCD_register_selector = 4;
*LCD_data_register = 0;
*LCD_register_selector = 7;
for(j=0 ; j<16 ; j++) *LCD_data_register = *mvram++;
}
}
}
// clear video ram
void clear_vram()
{
int i, end;
int *pointer_long, mvram;
char *pointer_byte;
mvram = (int)vram;
end = 4-mvram&3;
pointer_byte = (char*)mvram;
for(i=0 ; i<end ; i++) pointer_byte[i] = 0;
pointer_long = (int*) (mvram+end);
for(i=0 ; i<255 ; i++) pointer_long[i] = 0;
pointer_byte += 1020+end;
end = mvram&3;
for(i=0 ; i<end ; i++) pointer_byte[i] = 0;
}
// if possible, let it restart after going to the main menu
short*APP_EnableRestart()
{
if(getCalc() != UNKNOWN && !IsEmulator)
{
unsigned int ea;
unsigned int j;
short*pEnableRestartFlag;
ea = *(unsigned int*)0x8001007C;
ea += 0x0490*4;
if ( ea < 0x8001007C ) return 0;
if ( ea > 0x81000000 ) return 0;
ea = *(unsigned int*)( ea );
if ( ea < 0x8001007C ) return 0;
if ( ea > 0x81000000 ) return 0;
j = *(unsigned char*)( ea + 1 );
j *= 4;
ea = ( ea + j + 4 ) & 0xFFFFFFFC;
if ( ea < 0x8001007C ) return 0;
if ( ea > 0x81000000 ) return 0;
pEnableRestartFlag = (short*)(*( unsigned int*)( ea ) + 8 );
if ( ( (unsigned int)pEnableRestartFlag & 0xFF000000 ) != 0x88000000 ) return 0;
if ( pEnableRestartFlag ) *pEnableRestartFlag = 1;
return pEnableRestartFlag;
}
return NULL;
}
// return the model
int getCalc(void)
{
static int hardware = UNKNOWN;
if(hardware == UNKNOWN)
{
char v1, v2;
short v3, v4;
// check for calculator hardware type
if ( *(unsigned int*)0x80000300 == 0x80005D7C ){
if ( *(unsigned char*)0xA4000128 & 0x08 ){
hardware = fx9860G;
}
else{
hardware = fx9860G_SLIM;
}
}
else {
GlibGetOSVersionInfo( &v1, &v2, &v3, &v4 );
if ( ( v1 == 2 ) && ( v2 == 2 ) ){
hardware = fx9860GII_2;
}
else if ( ( *(unsigned int*)0x80000304 & 0x00FF0000 ) == 0x00AA0000 ){
// GII
hardware = fx9860GII;
}
else if ( ( *(unsigned int*)0x80000304 & 0x00FF0000 ) == 0x00550000 ){
// GII (French)
hardware = fx9860GII;
}
}
}
return hardware;
}
|