- Lock addin for Casio FX-CG [***UPDATED***]
- 15 Dec 2014 06:28:52 pm
- Last edited by amazonka on 17 Jul 2016 11:30:45 am; edited 2 times in total
My first add-in for this calculator: Description and
Download zip with add-in and source code files, etc. or
http://www.cemetech.net/scripts/countdown.php?/prizm/programs/Lock.zip&path=archives
Much of the code was possible due to help and examples from the brilliant gbl08ma and many other Cemetechians who posted on this forums before and/or PMed me with help recently: Programmer Nerd, AHelper, KermMartian, flyingfisch, Ashbad, JosJuice and many more.
Icons were done by me based on JosJuice's guidance.
Lock add-in is minimalistic and very Casio OS looking interface to power off and subsequently unlock your Prizm/Casio FX-CG. It locks the calculator using Casio's built-in User Name password as registered under System manager (i.e. MAIN MENU/[MENU]->System/[G]->Next page/[F6]->User Name/[F2]). Even if User Name setup is deleted from the System manager, the latest available password (if ever registered) will still work. This also means no additional setup or files in main or storage memory are needed to store your password, i.e. resetting main and storage memories without wiping add-ins will not effect the add-in. Even deleting User password won't effect the add-in: only user name and org will show in red then. Provided a password was ever registered in System manager the add-in will request it to unlock the calculator and to allow return to the main menu via [MENU] key or alternatively the calculator will power down on any other entries. Tested successfully on Casio FX-CG20 (OS 02.00.0200). On the emulator everything besides powering down works. Have fun and contribute any improvements you may have.
I include the source code below (adapted to compile under Windows without libc errors):
Code:
To install the add-in you can follow the sticky post the following way:
Step 1: unzip Lock.g3a from Archives
Download zip with add-in and source code files, etc. or
http://www.cemetech.net/scripts/countdown.php?/prizm/programs/Lock.zip&path=archives
Much of the code was possible due to help and examples from the brilliant gbl08ma and many other Cemetechians who posted on this forums before and/or PMed me with help recently: Programmer Nerd, AHelper, KermMartian, flyingfisch, Ashbad, JosJuice and many more.
Icons were done by me based on JosJuice's guidance.
Lock add-in is minimalistic and very Casio OS looking interface to power off and subsequently unlock your Prizm/Casio FX-CG. It locks the calculator using Casio's built-in User Name password as registered under System manager (i.e. MAIN MENU/[MENU]->System/[G]->Next page/[F6]->User Name/[F2]). Even if User Name setup is deleted from the System manager, the latest available password (if ever registered) will still work. This also means no additional setup or files in main or storage memory are needed to store your password, i.e. resetting main and storage memories without wiping add-ins will not effect the add-in. Even deleting User password won't effect the add-in: only user name and org will show in red then. Provided a password was ever registered in System manager the add-in will request it to unlock the calculator and to allow return to the main menu via [MENU] key or alternatively the calculator will power down on any other entries. Tested successfully on Casio FX-CG20 (OS 02.00.0200). On the emulator everything besides powering down works. Have fun and contribute any improvements you may have.
I include the source code below (adapted to compile under Windows without libc errors):
Code:
#include <fxcg/display.h>
#include <fxcg/keyboard.h>
char buf[8];
char* pwd = '\0';
int k;
int o;
int v = 1;
/* CODE BY SIMON LOTHAR, AVAILABLE ON "fx_calculators_SuperH_based.chm" version 16 */
// the function assumes, that the RAM-pointer to GetkeyToMainFunctionReturnFlag is loaded
// immediately by a "Move Immediate Data"-instruction
unsigned int SetGetkeyToMainFunctionReturnFlag( unsigned int enabled ) {
int addr, addr2;
// get the pointer to the syscall table
addr = *(unsigned char*)0x80020071; // get displacement
addr++;
addr *= 4;
addr += 0x80020070;
addr = *(unsigned int*)addr;
if ( addr < (int)0x80020070 ) return 0x101;
if ( addr >= (int)0x81000000 ) return 0x102;
// get the pointer to syscall 1E99
addr += 0x1E99*4;
if ( addr < (int)0x80020070 ) return 0x103;
if ( addr >= (int)0x81000000 ) return 0x104;
addr = *(unsigned int*)addr;
if ( addr < (int)0x80020070 ) return 0x105;
if ( addr >= (int)0x81000000 ) return 0x106;
switch ( *(unsigned char*)addr ){
case 0xD0 : // MOV.L @( disp, PC), Rn (REJ09B0317-0400 Rev. 4.00 May 15, 2006 page 216)
case 0xD1 :
case 0xD2 :
case 0xD3 :
case 0xD4 :
case 0xD5 :
case 0xD6 :
case 0xD7 :
case 0xD8 :
addr2 = *(unsigned char*)( addr + 1 ); // get displacement
addr2++;
addr2 *= 4;
addr2 += addr;
addr2 &= ~3;
if ( addr2 < (int)0x80020070 ) return 0x107;
if ( addr2 >= (int)0x81000000 ) return 0x108;
addr = *(unsigned int*)addr2;
if ( ( addr & 0xFF000000 ) != 0x88000000 ) return 0x109;
// finally perform the desired operation and set the flag:
if ( enabled ) *(unsigned char*)addr = 0;
else *(unsigned char*)addr = 3;
break;
default : addr = 0x100;
}
return addr;
}
static void S(char buffer[8]){
v = 0;
int start = 0; // Used for scrolling left and right
int cursor = 0; // Cursor position
buffer[0] = '\0'; // This sets the first character to \0, also represented by "", an empty string
DisplayMBString((unsigned char*)buffer, start, cursor, 2, 6); // Last two parameters are X,Y coords (not in pixels)
PrintXY(10,6," ]", 0, 0);
while(1){
GetKey(&k); // Blocking is GOOD. This gets standard keys processed and, possibly, powers down the CPU while waiting
if (k == KEY_CTRL_F6) {
F(1, 0x018E);//'
F(2, 0x018F);//"
F(3, 0x0190);//~
F(6, 0);
o = 1;
} else if(k == KEY_CTRL_F1 && o == 1) {
k = 39;//'
} else if(k == KEY_CTRL_F2 && o == 1) {
k = KEY_CHAR_DQUATE;
} else if(k == KEY_CTRL_F3 && o == 1) {
k = 126;//~
} else if(k == KEY_CTRL_EXE){// Ok
int i;
i = strcmp(buffer,pwd);
if (i == 0) {//Match
PrintXY(2,6," ********]", 0, 0);
SetGetkeyToMainFunctionReturnFlag(1); //Enable menu return
M(" Complete!"," Press [MENU]", " to unlock");
} else {
M(""," Mismatch", "");
}
}else if(k == KEY_CTRL_EXIT){// Aborted
SetSetupSetting((unsigned int)0x14, 0x84);
S(buf);
}
if(k && k < 30000) {
cursor = EditMBStringChar((unsigned char*)buffer, 8, cursor, k);
DisplayMBString((unsigned char*)buffer, start, cursor, 2, 6);
}else{
EditMBStringCtrl((unsigned char*)buffer, 8, &start, &cursor, &k, 2, 6);
}
PrintXY(10,6," ]", 0, 0);
}
return;
}
void M(char* m1, char* m2, char* m3) {
Cursor_SetFlashOff();
DisplayStatusArea();
MsgBoxPush(4);
PrintCXY(31, 15, (const char*) " Turn OFF:any key ", 0, -1, 0xFFFF, 0x001F, 1, 0);
PrintXY(7,3,m1, 0, 0);
PrintXY(6,4,m2, 0, 0);
PrintXY(7,5,m3, 0, 0);
GetKey(&k);
MsgBoxPop();
v = 1;
main();
}
void main() {
Bkey_SetAllFlags(0x80);
DefineStatusAreaFlags(3, SAF_BATTERY | SAF_ALPHA_SHIFT, 0, 0);
int c;
char* usr;
char* org;
char* flagpointer = (char*)0x80BE0000;
while(*flagpointer == 0x0F) {
if(*(flagpointer+0x2C) != '\0') {
pwd = (flagpointer+0x2C);
usr = (flagpointer+0x18);
org = (flagpointer+0x04);
c = 0;
}
else {//use previous info in red if User Name deleted
c = 4;
}
flagpointer = flagpointer + 0x40;
}
if(pwd == '\0') {
SetSetupSetting((unsigned int)0x14, 0);
DisplayStatusArea();
Bdisp_EnableColor(1);
SetBackGround(7);
PrintXY(1,1," In System Manager", 0x20, 1);
PrintXY(1,2," go Next Page [F6]", 0x20, 0);
PrintXY(1,3," then User Name [F2].", 0x20, 0);
PrintXY(1,4," Edit with [F1] and", 0x20, 0);
PrintXY(1,5," register with [EXE],", 0x20, 0);
PrintXY(1,6," then [F1] and [EXIT]", 0x20, 0);
PrintXY(1,7," to complete.", 0x20, 0);
while (1) {
GetKey(&k);
APP_SYSTEM();
}
} else {
SetGetkeyToMainFunctionReturnFlag(0); //Disable menu return
SetSetupSetting((unsigned int)0x14, 0x84);
DisplayStatusArea();
int iresult;
if (o == 0) {
F(6, 0x018D);
}else{
F(1, 0x018E);//'
F(2, 0x018F);//"
F(3, 0x0190);//~
}
PrintXY_2(0,-1,1,2018,1);//PrintXY(1,1," User Name", 0x20, 1);
PrintXY(1,2," [", 0, 0);
locate_OS(2,2);
PrintLine2(0, 1, usr, 0, -1, 20, c, 7);
PrintXY(21,2," ]", 0, 0);
PrintXY_2(0,-1,3,2019,1);//PrintXY(1,3," Organization", 0x20, 1);
PrintXY(1,4," [", 0, 0);
locate_OS(2,4);
PrintLine2(0, 1, org, 0, -1, 20, c, 7);
PrintXY(21,4," ]", 0, 0);
PrintXY_2(0,-1,5,2020,1);//PrintXY(1,5," Password", 0x20, 1);
PrintXY(1,6," [", 0, 0);
if (v == 1) {
v = 0;
PowerOff(1);
}
S(buf);
}
}
void F(int iF, int iD) {
int iresult;
GetFKeyPtr(iD, &iresult);
FKey_Display(iF-1, (int*)iresult);
}
/* CODE FROM libc/string.c */
int strcmp(const char *s1, const char *s2) {
while (*s1 != 0 && *s2 != 0) {
if (*s1 != *s2)
break;
s1++;
s2++;
}
return *s1 - *s2;
}
To install the add-in you can follow the sticky post the following way:
Step 1: unzip Lock.g3a from Archives
KermMartian wrote:
...
Step 2: Plug your Prizm into your computer with a MiniUSB cable. On the Prizm's screen, a menu will pop up; press F1 to make your Prizm look like a flash drive to your computer.
Step 3: Copy all the .g3* files into your calculator, which will appear as a Removable Drive in My Computer (if you're on Windows) or in the Finder (if you're using a Mac). Any .g3a files should go in the root (main folder) of the drive...
Step 2: Plug your Prizm into your computer with a MiniUSB cable. On the Prizm's screen, a menu will pop up; press F1 to make your Prizm look like a flash drive to your computer.
Step 3: Copy all the .g3* files into your calculator, which will appear as a Removable Drive in My Computer (if you're on Windows) or in the Finder (if you're using a Mac). Any .g3a files should go in the root (main folder) of the drive...