test
This commit is contained in:
commit
0b03fc66c1
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1 @@
|
|||
/bin/
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>B2C</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/b2c/B2C.java=UTF-8
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,12 @@
|
|||
//------------------------------------------------------------------
|
||||
// Addin-Application header control file, created with the CASIO SDK
|
||||
//------------------------------------------------------------------
|
||||
[OUTPUT] : "%PROG_NAME%.G1A"
|
||||
[BINDATA] : "FXADDINror.bin"
|
||||
[DISPNAME] : "%PROG_NAME%"
|
||||
[APPNAME] : "@%PROG_NAME%"
|
||||
[VERSION] : "01.00.0000"
|
||||
[APL_ICON] : "MainIcon.bmp"
|
||||
[MODULE_NUM] : 0
|
||||
[MOD1_TITLE] : "%PROG_NAME%"
|
||||
[MOD1_ICON] : "eActivityIcon.bmp"
|
|
@ -0,0 +1,611 @@
|
|||
BCDvar *B2C_add(BCDvar *buffer, BCDvar *a, BCDvar *b) {
|
||||
int expA, expB, expDiff, carry = 0, tempadd, biggerExp_int;
|
||||
unsigned char tempByte = 0;
|
||||
int result[15] = {0};
|
||||
BCDvar *smallerExp, *biggerExp;
|
||||
|
||||
//Determine if these numbers are negative
|
||||
//If both are negative, add their opposites
|
||||
//Ex: (-4)+(-3) -> -(4+3)
|
||||
if ((*a)[0] > 0x30 && (*b)[0] > 0x30) {
|
||||
BCDvar a2,b2;
|
||||
memcpy(a2, *a, 9);
|
||||
memcpy(b2, *b, 9);
|
||||
a2[0] -= 0x50;
|
||||
b2[0] -= 0x50;
|
||||
B2C_add(buffer, &a2, &b2);
|
||||
(*buffer)[0] += 0x50;
|
||||
return buffer;
|
||||
}
|
||||
//If one of them is negative, substract them
|
||||
//Ex: (-4)+3 -> 3-4
|
||||
if ((*a)[0] > 0x30) {
|
||||
BCDvar a2;
|
||||
memcpy(a2, *a, 9);
|
||||
a2[0] -= 0x50;
|
||||
return B2C_sub(buffer, b, &a2);
|
||||
}
|
||||
if ((*b)[0] > 0x30) {
|
||||
BCDvar b2;
|
||||
memcpy(b2, *b, 9);
|
||||
b2[0] -= 0x50;
|
||||
return B2C_sub(buffer, a, &b2);
|
||||
}
|
||||
|
||||
//First determine which number has a bigger exponent
|
||||
expA = ((*a)[0]>>4) * 100 + ((*a)[0]&0x0F) * 10 + ((*a)[1]>>4) - 100;
|
||||
expB = ((*b)[0]>>4) * 100 + ((*b)[0]&0x0F) * 10 + ((*b)[1]>>4) - 100;
|
||||
if (expA > expB) {
|
||||
smallerExp = b;
|
||||
biggerExp = a;
|
||||
expDiff = expA-expB;
|
||||
biggerExp_int = expA;
|
||||
} else {
|
||||
smallerExp = a;
|
||||
biggerExp = b;
|
||||
expDiff = expB-expA;
|
||||
biggerExp_int = expB;
|
||||
}
|
||||
|
||||
//Add the number with the smallest exponent to the one with the biggest
|
||||
for (i = 14; i >= 0; i--) {
|
||||
tempadd = 0;
|
||||
if (i >= expDiff) tempadd += getDigit(smallerExp, i-expDiff);
|
||||
tempadd += getDigit(biggerExp, i) + carry;
|
||||
if (tempadd >= 10) {
|
||||
result[i] = tempadd-10;
|
||||
carry = 1;
|
||||
} else {
|
||||
result[i] = tempadd;
|
||||
carry = 0;
|
||||
}
|
||||
//locate(i+1, 3); printChar(carry+'0');
|
||||
//locate(i+1, 4); printChar(tempadd+'0');
|
||||
}
|
||||
//Increment exponent if necessary
|
||||
if (carry == 1) {
|
||||
biggerExp_int++;
|
||||
}
|
||||
biggerExp_int += 100;
|
||||
//locate(1,6); printChar(biggerExp_int);
|
||||
//locate(3,6); printChar(expA+'0');
|
||||
//locate(5,6); printChar(expB+'0');
|
||||
//Put exponent in buffer
|
||||
(*buffer)[0] = (biggerExp_int/100 << 4) + (biggerExp_int%100)/10;
|
||||
tempByte = (biggerExp_int%10 << 4) + carry;
|
||||
if (carry == 1) {
|
||||
(*buffer)[1] = tempByte;
|
||||
}
|
||||
//Put result in buffer
|
||||
for (i=0; i < 15-carry; i++) {
|
||||
if ((i+carry)%2) {
|
||||
tempByte = result[i] << 4;
|
||||
|
||||
} else {
|
||||
(*buffer)[(i+carry+1)/2+1] = tempByte + result[i];
|
||||
|
||||
}
|
||||
}
|
||||
//locate(1,2); printBCDvarBytes(buffer);
|
||||
//locate(1,1);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
BCDvar *B2C_sub(BCDvar *buffer, BCDvar *a, BCDvar *b) {
|
||||
//Substract a positive number B from a positive number A (A-B).
|
||||
//A must be greater than B for the algorithm to function.
|
||||
//However this function does the necessary checks so A and B can be any reals.
|
||||
int expA, expB, expDiff, carry = 0, tempsub;
|
||||
unsigned char tempByte;
|
||||
int result[15] = {0};
|
||||
//Check for special cases
|
||||
//a > 0 and b < 0 -> a+(-b)
|
||||
//Ex: 3-(-4) -> 3+4
|
||||
if ((*a)[0] < 0x30 && (*b)[0] > 0x30) {
|
||||
BCDvar b2;
|
||||
memcpy(b2, b, 9);
|
||||
b2[0] -= 0x50;
|
||||
return B2C_add(buffer, a, &b2);
|
||||
}
|
||||
//a < 0 and b > 0 -> -(a+b)
|
||||
//Ex: (-4)-3 -> -(4+3)
|
||||
if ((*a)[0] > 0x30 && (*b)[0] < 0x30) {
|
||||
BCDvar a2;
|
||||
memcpy(a2, a, 9);
|
||||
a2[0] -= 0x50;
|
||||
B2C_add(buffer, &a2, b);
|
||||
(*buffer)[0] += 0x50;
|
||||
return buffer;
|
||||
}
|
||||
//a < 0 and b < 0 -> b-a
|
||||
//Ex: (-4)-(-3) -> 3-4
|
||||
if ((*a)[0] > 0x30 && (*b)[0] > 0x30) {
|
||||
BCDvar a2, b2;
|
||||
memcpy(a2, a, 9);
|
||||
memcpy(b2, b, 9);
|
||||
a2[0] -= 0x50;
|
||||
b2[0] -= 0x50;
|
||||
return B2C_sub(buffer, &a2, &b2);
|
||||
}
|
||||
//if a < b sub b-a
|
||||
if (B2C_greaterThan(b, a)) {
|
||||
return B2C_sub(buffer, b, a);
|
||||
}
|
||||
|
||||
//Determine the exponent difference; A is always the biggest number
|
||||
expA = ((*a)[0]>>4) * 100 + ((*a)[0]&0x0F) * 10 + ((*a)[1]>>4);
|
||||
expB = ((*b)[0]>>4) * 100 + ((*b)[0]&0x0F) * 10 + ((*b)[1]>>4);
|
||||
expDiff = expA-expB;
|
||||
|
||||
//Substract
|
||||
for (i = 14; i >= 0; i--) {
|
||||
tempsub = getDigit(a, i) - carry;
|
||||
if (i >= expDiff) tempsub -= getDigit(b, i-expDiff);
|
||||
if (tempsub < 0) {
|
||||
tempsub += 10;
|
||||
carry = 1;
|
||||
} else {
|
||||
carry = 0;
|
||||
}
|
||||
result[i] = tempsub;
|
||||
}
|
||||
|
||||
//Determine new exponent, reuse the var expA and expDiff
|
||||
//For example: 34-32 (3.4e1 - 3.2e1) will yield 2 (0.2e1) which must be converted to 2e0
|
||||
for (i = 0; result[i] == 0 && i < 15; i++) {
|
||||
expA--;
|
||||
}
|
||||
expDiff = i;
|
||||
|
||||
//Put exponent in buffer
|
||||
(*buffer)[0] = (expA/100 << 4) + (expA%100)/10;
|
||||
tempByte = (expA%10 << 4);
|
||||
|
||||
//Put result in buffer
|
||||
for (i = 0; i < 15; i++) {
|
||||
if (i%2) {
|
||||
tempByte = (i < 15-expDiff ? result[i+expDiff] << 4 : 0);
|
||||
} else {
|
||||
(*buffer)[(i+1)/2+1] = tempByte + (i < 15-expDiff ? result[i+expDiff] : 0);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
}
|
||||
|
||||
int B2C_greaterThan(BCDvar *a, BCDvar *b) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BCDvar *B2C_not(BCDvar *a) {
|
||||
if ((*a)[1])
|
||||
return &_0_;
|
||||
return &_1_;
|
||||
}
|
||||
unsigned char* B2C_convToStr(BCDvar *nb) {
|
||||
bcdToStr(nb, stringBuffer);
|
||||
return stringBuffer;
|
||||
}
|
||||
void B2C_setListRow(unsigned int nbList, unsigned int row, BCDvar *value) {
|
||||
//TODO: handle complex numbers
|
||||
unsigned short nbElements = 0;
|
||||
char listName[] = "0LIST\0\0";
|
||||
listName[0] = getSetupEntry(SETUP_LISTFILE) + '0';
|
||||
if (nbList >= 10) {
|
||||
listName[5] = nbList/10 + '0';
|
||||
listName[6] = nbList%10 + '0';
|
||||
} else {
|
||||
listName[5] = nbList + '0';
|
||||
}
|
||||
//Three possible cases: the list exists and the row isn't a new one, list exists and the row
|
||||
//has to be added, list doesn't exist and has to be created
|
||||
|
||||
//First case: list has to be created
|
||||
if (getItemData("main", listName, 8, 2, &nbElements)) { //most likely an error "file does not exist" - it can be another error but doing checks is time consuming
|
||||
unsigned char listContent[28] = {0,0,0,0,0,0,0,0, 0,1, 0,0,0,0,0,0};
|
||||
memcpy(listContent+16, value, 12);
|
||||
putInternalItem(DIR_LIST, listName, 28, listContent);
|
||||
} else {
|
||||
//Second case: row has to be added
|
||||
if (row > nbElements) {
|
||||
//char str[2] = {0};
|
||||
unsigned short existingListElements;
|
||||
unsigned int existingListLength;
|
||||
unsigned char* buffer;
|
||||
getItemSize("main", listName, &existingListLength);
|
||||
buffer = calloc(existingListLength+12, 1);
|
||||
|
||||
//Copy existing list data
|
||||
getItemData("main", listName, 0, existingListLength, buffer);
|
||||
|
||||
//Increase number of elements
|
||||
memcpy(buffer+8, &existingListElements, 2);
|
||||
existingListElements++;
|
||||
memcpy(&existingListElements, buffer+8, 2);
|
||||
|
||||
//Put the new value in the buffer
|
||||
memcpy(buffer+existingListLength, value, 12);
|
||||
deleteInternalItem(DIR_LIST, listName);
|
||||
putInternalItem(DIR_LIST, listName, existingListLength+12, buffer);
|
||||
free(buffer);
|
||||
|
||||
} else if (1) {
|
||||
overwriteItemData("main", listName, 12, value, 4+12*row);
|
||||
|
||||
//DO NOT REMOVE THIS CONDITION OR ANYTHING INSIDE IT; THE DEMON INSIDE THIS FUNCTION WILL NOT APPROVE
|
||||
} else {
|
||||
locate(1,6);
|
||||
Print("test");
|
||||
locate(23,2);
|
||||
Print(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
void B2C_setDimList(unsigned int nbList, unsigned short nbElements) {
|
||||
unsigned char* content = calloc(12*nbElements+LIST_START, 1);
|
||||
char listName[] = "0LIST\0\0";
|
||||
listName[0] = getSetupEntry(SETUP_LISTFILE) + '0';
|
||||
if (nbList >= 10) {
|
||||
listName[5] = nbList/10 + '0';
|
||||
listName[6] = nbList%10 + '0';
|
||||
} else {
|
||||
listName[5] = nbList + '0';
|
||||
}
|
||||
content[8] = nbElements>>8;
|
||||
content[9] = nbElements&0xFF;
|
||||
deleteInternalItem(DIR_LIST, listName);
|
||||
putInternalItem(DIR_LIST, listName, 12*nbElements+LIST_START, content);
|
||||
free(content);
|
||||
}
|
||||
/*
|
||||
List B2C_newList(int nbElements, ...) {
|
||||
List list;
|
||||
va_list vaList;
|
||||
list.nbElements = nbElements;
|
||||
list.data = calloc(nbElements+1, sizeof(BCDvar));
|
||||
va_start(vaList, nbElements);
|
||||
list.data[0] = _0_;
|
||||
for (i = 1; i <= nbElements; i++) {
|
||||
list.data[i] = va_arg(vaList, BCDvar);
|
||||
}
|
||||
va_end(vaList);
|
||||
return list;
|
||||
}
|
||||
*/
|
||||
void B2C_setDimMat(unsigned char matrix, unsigned short y, unsigned short x) {
|
||||
unsigned char* content = calloc(12*y*x + MAT_START, 1);
|
||||
char matName[] = "MAT_ \0\0";
|
||||
matName[4] = matrix;
|
||||
memcpy(content+8, &y, 2);
|
||||
memcpy(content+10, &x, 2);
|
||||
deleteInternalItem(DIR_MAT, matName);
|
||||
putInternalItem(DIR_MAT, matName, 12*y*x+MAT_START, content);
|
||||
free(content);
|
||||
}
|
||||
void B2C_setMat(unsigned char matrix, unsigned int y, unsigned int x, BCDvar *value) {
|
||||
char matName[] = "MAT_ \0\0";
|
||||
unsigned short matWidth;
|
||||
matName[4] = matrix;
|
||||
getItemData("main", matName, 10, 2, &matWidth);
|
||||
overwriteItemData("main", matName, 12, value, MAT_START+12*((y-1)*matWidth+(x-1)));
|
||||
}
|
||||
unsigned int B2C_convToUInt(BCDvar *nb) {
|
||||
unsigned int result = 0;
|
||||
//gets the 3rd digit of the exponent - that means it doesn't work for Uints > 10^10
|
||||
//however this function is intended for locate, matrixes, lists, etc so it isn't needed
|
||||
int power = ((*nb)[1]>>4) + 1;
|
||||
for (i = 1; i <= power; i++) {
|
||||
if (i%2) {
|
||||
result += ((*nb)[i/2+1]&0xF) * pow(10, power-i);
|
||||
} else {
|
||||
result += ((*nb)[i/2+1]>>4) * pow(10, power-i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int B2C_convToInt(BCDvar *nb) {
|
||||
//(almost) copy of B2C_convToUInt, any changes made here must be reflected in the other function
|
||||
int result = 0;
|
||||
int power = ((*nb)[1]>>4) + 1;
|
||||
for (i = 1; i <= power; i++) {
|
||||
if (i%2) {
|
||||
result += ((*nb)[i/2+1]&0xF) * pow(10, power-i);
|
||||
} else {
|
||||
result += ((*nb)[i/2+1]>>4) * pow(10, power-i);
|
||||
}
|
||||
}
|
||||
if ((*nb)[0] > 0x30) { //exponent is higher than 300 so number is negative
|
||||
result = -result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
BCDvar *B2C_Getkey() {
|
||||
if (!prgmGetkey(&getkeyBuffer)) {
|
||||
B2C_exit(NO_ERROR);
|
||||
}
|
||||
return &getkeyBuffer;
|
||||
}
|
||||
#ifdef USES_INTERRUPTION_TIMER
|
||||
void exitTimerHandler() {
|
||||
/*short menuCode = 0x0308;
|
||||
putMatrixCode(&menuCode);*/
|
||||
if (IsKeyDown(KEY_CTRL_AC)) {
|
||||
KillTimer(INTERRUPTION_TIMER);
|
||||
B2C_exit(NO_ERROR);
|
||||
} else {
|
||||
SetTimer(INTERRUPTION_TIMER, 50, exitTimerHandler);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void B2C_exit(int exitCode) {
|
||||
/*installTimer(6, (void*)&timerHandler, 1);
|
||||
startTimer(6);
|
||||
GetKey(&key);
|
||||
uninstallTimer(6);*/
|
||||
short menuCode = 0x0308;
|
||||
PopUpWin(4);
|
||||
|
||||
switch(exitCode) {
|
||||
case NO_ERROR:
|
||||
locate(5,3); Print((unsigned char*)"Interruption");
|
||||
break;
|
||||
case MEMORY_ERROR:
|
||||
locate(4,3); Print((unsigned char*)"Erreur m""\xE6""\x0A""moire");
|
||||
break;
|
||||
}
|
||||
locate(4,5); Print((unsigned char*)"Appuyer:[EXIT]");
|
||||
while (1) {
|
||||
putMatrixCode(&menuCode);
|
||||
do {
|
||||
GetKey(&key);
|
||||
} while (key != KEY_CTRL_EXIT);
|
||||
}
|
||||
}
|
||||
|
||||
BCDvar *B2C_ranInt(BCDvar *a, BCDvar *b) {
|
||||
return &_1_;
|
||||
/*BCDvar result;
|
||||
//A + Int (Ran# * (B - A + 1))
|
||||
const char *function = "A""\x89""\xA6""(""\xC1""\xA9""(B""\x99""A""\x89""1))";
|
||||
setAlphaVar('A', &a);
|
||||
setAlphaVar('B', &b);
|
||||
calcExp(&function, dummyOpCode, &result, 1);
|
||||
return result;*/
|
||||
}
|
||||
|
||||
BCDvar *B2C_getAlphaVar(unsigned char var) {
|
||||
getAlphaVar(var, alphaVarBuffer);
|
||||
return &alphaVarBuffer;
|
||||
}
|
||||
|
||||
BCDvar *B2C_calcExp(unsigned char* exp) {
|
||||
calcExp(&exp, dummyOpCode, &expressionBuffer, 1);
|
||||
return &expressionBuffer;
|
||||
}
|
||||
void B2C_setAlphaVar(unsigned char var, BCDvar *value) {
|
||||
setAlphaVar(var, *value);
|
||||
}
|
||||
void B2C_setStr(Str *value, int isString, int strNum) {
|
||||
free(strings[strNum].data);
|
||||
strings[strNum].length = value->length;
|
||||
strings[strNum].data = malloc((value->length+2)*2);
|
||||
strings[strNum].data[(value->length+1)*2] = 0x00;
|
||||
memcpy(strings[strNum].data + 2, value->data + 2, value->length * 2);
|
||||
free_str(value);
|
||||
}
|
||||
unsigned char* B2C_strToCharArray(Str *str, int isString) {
|
||||
int j = 0;
|
||||
//Initialize the buffer
|
||||
memset(stringBuffer, 0x00, 256);
|
||||
//Goes through the string, starting at 2
|
||||
for (i = 2; i <= (str->length+1) * 2; i++) {
|
||||
//Skip null bytes
|
||||
if (str->data[i]) {
|
||||
stringBuffer[j] = str->data[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
free_str(str);
|
||||
return stringBuffer;
|
||||
}
|
||||
Str *B2C_charArrayToStr(unsigned char* charArray) {
|
||||
int strPos = 2;
|
||||
Str *result = malloc(sizeof(Str));
|
||||
result->data = calloc(strlen(charArray)+1, 2);
|
||||
result->length = 0;
|
||||
for (i = 0; charArray[i]; i++) {
|
||||
if (!(strPos%2) &&
|
||||
charArray[i] != 0xE5 &&
|
||||
charArray[i] != 0xE6 &&
|
||||
charArray[i] != 0xE7 &&
|
||||
charArray[i] != 0xF7 &&
|
||||
charArray[i] != 0xF9 &&
|
||||
charArray[i] != 0x7F) {
|
||||
strPos++;
|
||||
}
|
||||
result->data[strPos] = charArray[i];
|
||||
strPos++;
|
||||
}
|
||||
result->length = (strPos-2)/2;
|
||||
return result;
|
||||
}
|
||||
BCDvar *B2C_strCmp(Str *str1, Str *str2, int isString1, int isString2) {
|
||||
unsigned char str_1[256] = {0}, str_2[256] = {0};
|
||||
int j = 0, isString;
|
||||
//Can't use strToCharArray because the buffer can't be used twice
|
||||
for (i = 2; i <= (str1->length+1) * 2; i++) {
|
||||
//Skip null bytes
|
||||
if (str1->data[i]) {
|
||||
str_1[j] = str1->data[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
for (i = 2; i <= (str2->length+1) * 2; i++) {
|
||||
//Skip null bytes
|
||||
if (str2->data[i]) {
|
||||
str_2[j] = str2->data[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
isString = isString1;
|
||||
//Can't use strcmp() because it must return -1, 0 or 1
|
||||
//so just implement strcmp while adapting free_str to free both str1 and str2
|
||||
for (i = 0; str_1[i] || str_2[i]; i++) {
|
||||
if (str_1[i] < str_2[i]) {
|
||||
free_str(str1);
|
||||
isString = isString2;
|
||||
free_str(str2);
|
||||
return &__1_;
|
||||
} else if (str_1[i] > str_2[i]) {
|
||||
free_str(str1);
|
||||
isString = isString2;
|
||||
free_str(str2);
|
||||
return &_1_;
|
||||
}
|
||||
}
|
||||
free_str(str1);
|
||||
isString = isString2;
|
||||
free_str(str2);
|
||||
return &_0_;
|
||||
}
|
||||
Str *B2C_strInv(Str *str, int isString) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
result->data = malloc(2*(str->length+1));
|
||||
result->length = str->length;
|
||||
for (i = 2*str->length; i >= 2; i -= 2) {
|
||||
memcpy(result->data + 2*str->length-i, str->data + i, 2);
|
||||
}
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strJoin(Str *str1, Str *str2, int isString1, int isString2) {
|
||||
int isString = isString1;
|
||||
Str *result = malloc(sizeof(Str));
|
||||
result->data = malloc(2*(str1->length + str2->length + 1));
|
||||
result->length = str1->length + str2->length;
|
||||
memcpy(result->data + 2, str1->data + 2, str1->length * 2);
|
||||
memcpy(result->data + 2 + str1->length * 2, str2->data + 2, str2->length * 2);
|
||||
free_str(str1);
|
||||
isString = isString2;
|
||||
free_str(str2);
|
||||
return result;
|
||||
}
|
||||
BCDvar *B2C_strLen(Str *str, int isString) {
|
||||
unsigned char length[4] = {0};
|
||||
BCDvar *result;
|
||||
sprintf(length, "%d", str->length);
|
||||
result = B2C_calcExp(length);
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strMid(Str *str, int isString, int start, int offset) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
if (!offset) {
|
||||
offset = str->length-start;
|
||||
}
|
||||
result->data = malloc((offset+2) * 2);
|
||||
//Set null byte at the end
|
||||
result->data[(offset+1) * 2] = 0x00;
|
||||
result->length = offset;
|
||||
//Copy the substring
|
||||
memcpy(result->data + 2, str->data + start*2, 2*offset);
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_charAt(Str *str, int isString, int charPos) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
result->data = malloc(3*2);
|
||||
result->data[2*2] = 0x00;
|
||||
result->length = 1;
|
||||
memcpy(result->data+2, str->data+charPos*2, 2);
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strUpr(Str *str, int isString) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
unsigned short currentChar;
|
||||
result->data = malloc((str->length+2) * 2);
|
||||
result->data[str->length+1] = 0x00;
|
||||
memcpy(result->data+2, str->data+2, str->length * 2);
|
||||
result->length = str->length;
|
||||
for (i = 3; i <= result->length*2; i+=2) {
|
||||
if (result->data[i] >= 'a' && result->data[i] <= 'z') {
|
||||
result->data[i] -= 32;
|
||||
}
|
||||
}
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strLwr(Str *str, int isString) { //(almost) copy of B2C_strUpr - any changes made here must be reflected in strUpr
|
||||
Str *result = malloc(sizeof(Str));
|
||||
unsigned short currentChar;
|
||||
result->data = malloc((str->length+2) * 2);
|
||||
result->data[str->length+1] = 0x00;
|
||||
memcpy(result->data+2, str->data+2, str->length * 2);
|
||||
result->length = str->length;
|
||||
for (i = 3; i <= result->length*2; i+=2) {
|
||||
if (result->data[i] >= 'A' && result->data[i] <= 'Z') {
|
||||
result->data[i] += 32;
|
||||
}
|
||||
}
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strRight(Str *str, int isString, int offset) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
|
||||
result->data = malloc((offset+2)*2);
|
||||
result->data[(offset+1)*2] = 0x00;
|
||||
result->length = offset;
|
||||
memcpy(result->data+2, str->data + (str->length - offset + 1)*2, offset * 2);
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strLeft(Str *str, int isString, int offset) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
result->data = malloc((offset+2)*2);
|
||||
result->data[(offset+1)*2] = 0x00;
|
||||
result->length = offset;
|
||||
memcpy(result->data+2, str->data + 2, offset * 2);
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
Str *B2C_strRotate(Str *str, int isString, int offset) {
|
||||
Str *result = malloc(sizeof(Str));
|
||||
result->length = str->length;
|
||||
result->data = malloc((str->length+1)*2);
|
||||
offset %= str->length;
|
||||
if (offset > 0) {
|
||||
memcpy(result->data+2, str->data+2+2*offset, (str->length-offset)*2);
|
||||
memcpy(result->data+2+2*(str->length-offset), str->data+2, offset*2);
|
||||
} else {
|
||||
memcpy(result->data+2, str->data+2+2*(str->length+offset), -offset*2);
|
||||
memcpy(result->data+2+2*-offset, str->data+2, (str->length+offset)*2);
|
||||
}
|
||||
free_str(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
//Debug function; is not used with converted programs
|
||||
void printBCDvarBytes(BCDvar *var) {
|
||||
unsigned char str[2] = {0};
|
||||
for (i = 0; i < 18; i++) {
|
||||
if (i%2) {
|
||||
str[0] = '0'+((*var)[i/2]&0x0F);
|
||||
} else {
|
||||
str[0] = '0'+((*var)[i/2]>>4);
|
||||
}
|
||||
if (str[0] > '9') {
|
||||
str[0] += 'A'-'9'-1;
|
||||
}
|
||||
Print(str);
|
||||
}
|
||||
}
|
||||
|
||||
void printChar(unsigned char c) {
|
||||
unsigned char str[2] = {0};
|
||||
str[0] = c;
|
||||
Print(str);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
[DLSimProject]
|
||||
Name=%PROG_NAME%
|
||||
Version=1.00.0000
|
||||
Model=:fx-9860G.dlm
|
||||
SourcePath=SRC
|
||||
MemoryPath=INIT
|
||||
MemCardPath=SDCard
|
||||
|
||||
[Program1]
|
||||
Program=%PROG_NAME%.G1A
|
||||
Debug=Debug\FXADDINror.dbg
|
||||
LoadAddress=80000000:90100000
|
||||
|
||||
[Files]
|
||||
SourceFile=:main.c
|
||||
SourceFile=:MonochromeLib.c
|
||||
SourceFile=:syscalls.src
|
Binary file not shown.
After Width: | Height: | Size: 138 B |
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,151 @@
|
|||
/*************************************************************/
|
||||
/** MonochromeLib - monochrome graphic library for fx-9860G **/
|
||||
/** MonochromeLib is free software **/
|
||||
/** **/
|
||||
/** @author Pierre "PierrotLL" Le Gall **/
|
||||
/** @contact legallpierre89@gmail.com **/
|
||||
/** **/
|
||||
/** @file MonochromeLib.h **/
|
||||
/** Include header for MonochromeLib **/
|
||||
/** **/
|
||||
/** @date 11-22-2011 **/
|
||||
/*************************************************************/
|
||||
|
||||
#ifndef MONOCHROMELIB
|
||||
#define MONOCHROMELIB
|
||||
|
||||
/****************************************************/
|
||||
/** uncomment #define of functions you want to use **/
|
||||
/****************************************************/
|
||||
|
||||
// #define ML_ALL //Auto define all functions
|
||||
|
||||
#define ML_CLEAR_VRAM
|
||||
#define ML_CLEAR_SCREEN
|
||||
#define ML_DISPLAY_VRAM
|
||||
|
||||
// #define ML_SET_CONTRAST
|
||||
// #define ML_GET_CONTRAST
|
||||
|
||||
#define ML_PIXEL
|
||||
// #define ML_POINT
|
||||
// #define ML_PIXEL_TEST
|
||||
|
||||
#define ML_LINE
|
||||
#define ML_HORIZONTAL_LINE
|
||||
#define ML_VERTICAL_LINE
|
||||
|
||||
#define ML_RECTANGLE
|
||||
|
||||
// #define ML_POLYGON
|
||||
// #define ML_FILLED_POLYGON
|
||||
|
||||
// #define ML_CIRCLE
|
||||
// #define ML_FILLED_CIRCLE
|
||||
|
||||
// #define ML_ELLIPSE
|
||||
// #define ML_ELLIPSE_IN_RECT
|
||||
// #define ML_FILLED_ELLIPSE
|
||||
// #define ML_FILLED_ELLIPSE_IN_RECT
|
||||
|
||||
// #define ML_HORIZONTAL_SCROLL
|
||||
// #define ML_VERTICAL_SCROLL
|
||||
|
||||
// #define ML_BMP_OR
|
||||
// #define ML_BMP_AND
|
||||
// #define ML_BMP_XOR
|
||||
// #define ML_BMP_OR_CL
|
||||
// #define ML_BMP_AND_CL
|
||||
// #define ML_BMP_XOR_CL
|
||||
|
||||
// #define ML_BMP_8_OR
|
||||
// #define ML_BMP_8_AND
|
||||
// #define ML_BMP_8_XOR
|
||||
// #define ML_BMP_8_OR_CL
|
||||
// #define ML_BMP_8_AND_CL
|
||||
// #define ML_BMP_8_XOR_CL
|
||||
|
||||
// #define ML_BMP_16_OR
|
||||
// #define ML_BMP_16_AND
|
||||
// #define ML_BMP_16_XOR
|
||||
// #define ML_BMP_16_OR_CL
|
||||
// #define ML_BMP_16_AND_CL
|
||||
// #define ML_BMP_16_XOR_CL
|
||||
|
||||
|
||||
/**************************/
|
||||
/** Functions prototypes **/
|
||||
/**************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ML_SCREEN_WIDTH 128
|
||||
#define ML_SCREEN_HEIGHT 64
|
||||
|
||||
#define ML_CONTRAST_MIN 130
|
||||
#define ML_CONTRAST_NORMAL 168
|
||||
#define ML_CONTRAST_MAX 190
|
||||
typedef enum {ML_TRANSPARENT=-1, ML_WHITE, ML_BLACK, ML_XOR, ML_CHECKER} ML_Color;
|
||||
|
||||
char* ML_vram_adress();
|
||||
|
||||
void ML_clear_vram();
|
||||
void ML_clear_screen();
|
||||
void ML_display_vram();
|
||||
|
||||
void ML_set_contrast(unsigned char contrast);
|
||||
unsigned char ML_get_contrast();
|
||||
|
||||
void ML_pixel(int x, int y, ML_Color color);
|
||||
void ML_point(int x, int y, int width, ML_Color color);
|
||||
ML_Color ML_pixel_test(int x, int y);
|
||||
|
||||
void ML_line(int x1, int y1, int x2, int y2, ML_Color color);
|
||||
void ML_horizontal_line(int y, int x1, int x2, ML_Color color);
|
||||
void ML_vertical_line(int x, int y1, int y2, ML_Color color);
|
||||
|
||||
void ML_rectangle(int x1, int y1, int x2, int y2, int border_width, ML_Color border_color, ML_Color fill_color);
|
||||
|
||||
void ML_polygon(const int *x, const int *y, int nb_vertices, ML_Color color);
|
||||
void ML_filled_polygon(const int *x, const int *y, int nb_vertices, ML_Color color);
|
||||
|
||||
void ML_circle(int x, int y, int radius, ML_Color color);
|
||||
void ML_filled_circle(int x, int y, int radius, ML_Color color);
|
||||
|
||||
void ML_ellipse(int x, int y, int radius1, int radius2, ML_Color color);
|
||||
void ML_ellipse_in_rect(int x1, int y1, int x2, int y2, ML_Color color);
|
||||
void ML_filled_ellipse(int x, int y, int radius1, int radius2, ML_Color color);
|
||||
void ML_filled_ellipse_in_rect(int x, int y, int radius1, int radius2, ML_Color color);
|
||||
|
||||
void ML_horizontal_scroll(int scroll);
|
||||
void ML_vertical_scroll(int scroll);
|
||||
|
||||
void ML_bmp_or(const unsigned char *bmp, int x, int y, int width, int height);
|
||||
void ML_bmp_and(const unsigned char *bmp, int x, int y, int width, int height);
|
||||
void ML_bmp_xor(const unsigned char *bmp, int x, int y, int width, int height);
|
||||
void ML_bmp_or_cl(const unsigned char *bmp, int x, int y, int width, int height);
|
||||
void ML_bmp_and_cl(const unsigned char *bmp, int x, int y, int width, int height);
|
||||
void ML_bmp_xor_cl(const unsigned char *bmp, int x, int y, int width, int height);
|
||||
|
||||
void ML_bmp_8_or(const unsigned char *bmp, int x, int y);
|
||||
void ML_bmp_8_and(const unsigned char *bmp, int x, int y);
|
||||
void ML_bmp_8_xor(const unsigned char *bmp, int x, int y);
|
||||
void ML_bmp_8_or_cl(const unsigned char *bmp, int x, int y);
|
||||
void ML_bmp_8_and_cl(const unsigned char *bmp, int x, int y);
|
||||
void ML_bmp_8_xor_cl(const unsigned char *bmp, int x, int y);
|
||||
|
||||
void ML_bmp_16_or(const unsigned short *bmp, int x, int y);
|
||||
void ML_bmp_16_and(const unsigned short *bmp, int x, int y);
|
||||
void ML_bmp_16_xor(const unsigned short *bmp, int x, int y);
|
||||
void ML_bmp_16_or_cl(const unsigned short *bmp, int x, int y);
|
||||
void ML_bmp_16_and_cl(const unsigned short *bmp, int x, int y);
|
||||
void ML_bmp_16_xor_cl(const unsigned short *bmp, int x, int y);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif //MONOCHROMELIB
|
|
@ -0,0 +1,214 @@
|
|||
package b2c;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/* TODO 's:
|
||||
*
|
||||
* put each program in a separate file <program>.c
|
||||
* generate .g1w
|
||||
*
|
||||
*/
|
||||
|
||||
public class B2C {
|
||||
|
||||
final static boolean debugMode = true;
|
||||
|
||||
static String path = "C:\\Users\\Catherine\\Documents\\CASIO\\fx-9860G SDK\\TestB2C\\";
|
||||
static String pathToG1M = "C:\\Users\\Catherine\\Desktop\\test.g1m";
|
||||
static String mainProgramName = "TEST";
|
||||
static boolean isRealTimeGame = true;
|
||||
static boolean assureOS1Compatibility = true;
|
||||
static boolean usesAcOnTimer = true;
|
||||
static String main_c;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (!debugMode) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Enter the path to the .g1m file:");
|
||||
while (true) {
|
||||
pathToG1M = ""+sc.nextLine().charAt(0);
|
||||
if (new File(pathToG1M).isFile()) {
|
||||
break;
|
||||
} else {
|
||||
System.out.println("File not found.");
|
||||
}
|
||||
}
|
||||
pathToG1M = pathToG1M.replaceAll("\\\\", "/");
|
||||
System.out.println("Enter the name of the main program.\nReplace 'r' with \"radius\", 'θ' by \"theta\" and non-ASCII characters by '_'.");
|
||||
mainProgramName = Parser.parseProgName(sc.nextLine());
|
||||
String programName = pathToG1M.substring(pathToG1M.lastIndexOf('/')+1, pathToG1M.lastIndexOf('.'));
|
||||
path = System.getProperty("user.home") + "\\Documents\\CASIO\\fx-9860G SDK\\"
|
||||
+ programName + System.getProperty("file.separator");
|
||||
System.out.println("Enter the destination path. Write \"default\" to set to:\n" + path);
|
||||
String destinationPath = sc.nextLine();
|
||||
if (!destinationPath.equals("default")) {
|
||||
path = destinationPath;
|
||||
}
|
||||
new File(path).mkdir();
|
||||
|
||||
//TODO create custom image
|
||||
try {
|
||||
Files.copy(new File(B2C.class.getClassLoader().getResource("MainIcon.bmp").getPath().substring(1)).toPath(),
|
||||
new File(path + "/MainIcon.bmp").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
IO.writeToFile(new File(path + File.separator + programName + ".g1w"),
|
||||
IO.readFromRelativeFile("Default.g1w").replaceAll("%PROG_NAME%", programName), true);
|
||||
IO.writeToFile(new File(path + File.separator + "AddinInfo.txt"),
|
||||
IO.readFromRelativeFile("AddinInfo.txt").replaceAll("%PROG_NAME%", programName), true);
|
||||
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
//Add some constants for functions
|
||||
Constants.add("0");
|
||||
Constants.add("1");
|
||||
Constants.add("-1");
|
||||
/*Constants.add("53123523");
|
||||
Constants.add("0.3");
|
||||
Constants.add("2.304");
|
||||
Constants.add("-1");
|
||||
Constants.add("0.0456");
|
||||
Constants.add("-0.00786");*/
|
||||
|
||||
main_c =
|
||||
"#include <stdlib.h>\n" +
|
||||
"#include <stdarg.h>\n" +
|
||||
"#include <math.h>\n" +
|
||||
"#include <limits.h>\n" +
|
||||
"#include <string.h>\n" +
|
||||
"#include \"fxlib.h\"\n" +
|
||||
"#include \"main.h\"\n\n" +
|
||||
"unsigned int key;\n" +
|
||||
"int i;\n"+
|
||||
"BCDvar var[28] = {0}; //A-Z, r, theta\n"+
|
||||
"BCDvar Ans;\n" +
|
||||
"Str strings[20];\n" +
|
||||
"Mat mat[26]; //Important thing: matrixes are (height, width) not (width, height)\n" +
|
||||
"char dummyOpCode[2] = {5, 8};\n" +
|
||||
"//These are buffers for syscalls that do not return a value.\n" +
|
||||
"BCDvar alphaVarBuffer;\n" +
|
||||
"BCDvar expressionBuffer;\n" +
|
||||
"BCDvar getkeyBuffer;\n" +
|
||||
"unsigned char stringBuffer[256] = {0};\n";
|
||||
/*"const BCDvar ZERO = {0};\n";
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
main_c += "const BCDvar " + Parser.consts.get(i) + " = {0x10, 0x0" + i + "};\n";
|
||||
}*/
|
||||
main_c+="\nint AddIn_main(int isAppli, unsigned short OptionNum) {\n" +
|
||||
"\t//Initialize strings\n" +
|
||||
"\tfor (i = 0; i < 20; i++) {\n" +
|
||||
"\t\tstrings[i].length = 0;\n" +
|
||||
"\t}\n" +
|
||||
"\t#ifdef USES_INTERRUPTION_TIMER\n" +
|
||||
"\t//Timer allowing AC/ON to be pressed at any moment\n" +
|
||||
"\tSetTimer(INTERRUPTION_TIMER, 50, exitTimerHandler);\n" +
|
||||
"\t#endif\n" +
|
||||
"\tprog_"+mainProgramName+"();\n\n" +
|
||||
"\tdo {\n" +
|
||||
"\t\tGetKey(&key);\n" +
|
||||
"\t} while (key != KEY_CTRL_EXE && key != KEY_CTRL_AC);\n" +
|
||||
"\treturn 1;\n" +
|
||||
"}\n\n";
|
||||
|
||||
main_c += IO.readFromFile(pathToG1M);
|
||||
|
||||
System.out.println("Result:\n-------------\n"+main_c);
|
||||
|
||||
//pragma stuff
|
||||
main_c += "\n\n#pragma section _BR_Size\nunsigned long BR_Size;\n#pragma section\n\n"
|
||||
+ "#pragma section _TOP\n"
|
||||
+ "int InitializeSystem(int isAppli, unsigned short OptionNum) {"
|
||||
+ "\n\treturn INIT_ADDIN_APPLICATION(isAppli, OptionNum);\n}\n"
|
||||
+ "#pragma section\n";
|
||||
|
||||
//GetKey handling
|
||||
/*if (isRealTimeGame) {
|
||||
main_c = main_c.replaceAll(
|
||||
"(do \\{\\n+([\\t ]+)?([\\w\\[\\]])+? \\= )Getkey_Temp(\\(\\);\n([\\t ]+)?} while \\()",
|
||||
"$1Getkey_Block$4"
|
||||
);
|
||||
main_c = main_c.replaceAll("Getkey_Temp\\(\\);", "Getkey_NoBlock();");
|
||||
} else {
|
||||
main_c = main_c.replaceAll("Getkey_Temp\\(\\);", "Getkey_Block();");
|
||||
}*/
|
||||
|
||||
|
||||
main_c += Functions.getFunctions();
|
||||
|
||||
IO.writeToFile(new File(path + "/main.c"), main_c, true);
|
||||
|
||||
//Syscalls asm file
|
||||
|
||||
/*writeToFile(new File(path + "syscalls.src"),
|
||||
"\t.SECTION P,CODE,ALIGN=4\n\n"
|
||||
+ "\t.MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop\n\n"
|
||||
+ "\t.export \\SYSCALLNAME'\n"
|
||||
+ "\\SYSCALLNAME'\n"
|
||||
+ "\tmov.l #h'\\FUNO, r0\n"
|
||||
+ "\tmov.l #H'80010070, r2\n"
|
||||
+ "\tjmp @r2\n"
|
||||
+ "\t\\TAIL'\n"
|
||||
+ "\t.ENDM\n\n"
|
||||
+ "\tSYSCALL "
|
||||
, true);*/
|
||||
Syscalls.addSyscall("bcdToStr", "4F0");
|
||||
Syscalls.addSyscall("intToBCD", "5A6");
|
||||
Syscalls.addSyscall("calcExp", "645");
|
||||
Syscalls.addSyscall("getAlphaVar", "4DF");
|
||||
Syscalls.addSyscall("setAlphaVar", "4E0");
|
||||
Syscalls.addSyscall("prgmGetkey", "6C4");
|
||||
Syscalls.addSyscall("putMatrixCode", "24F");
|
||||
//Syscalls.addSyscall("installTimer", "118");
|
||||
//Syscalls.addSyscall("startTimer", "11A");
|
||||
//Syscalls.addSyscall("uninstallTimer", "119");
|
||||
Syscalls.addSyscall("putInternalItem", "82A");
|
||||
Syscalls.addSyscall("deleteInternalItem", "835");
|
||||
Syscalls.addSyscall("openItem", "83B");
|
||||
Syscalls.addSyscall("getItemData", "372");
|
||||
Syscalls.addSyscall("getItemSize", "840");
|
||||
Syscalls.addSyscall("overwriteItemData", "830");
|
||||
Syscalls.addSyscall("setSetupEntry", "4DD");
|
||||
Syscalls.addSyscall("getSetupEntry", "4DC");
|
||||
Syscalls.createSyscallFile();
|
||||
|
||||
String[] externalLibs = {"MonochromeLib.c", "MonochromeLib.h", "memory.c", "memory.h"};
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
IO.writeToFile(new File(path+externalLibs[i]), IO.readFromRelativeFile(externalLibs[i]), true);
|
||||
}
|
||||
Header.addDefine("FALSE 0");
|
||||
Header.addDefine("TRUE 1");
|
||||
Header.addDefine("NO_ERROR 0");
|
||||
Header.addDefine("MEMORY_ERROR 1");
|
||||
Header.addDefine("INTERRUPTION_TIMER 2");
|
||||
if (usesAcOnTimer) {
|
||||
Header.addDefine("USES_INTERRUPTION_TIMER");
|
||||
}
|
||||
Header.addDefine("DIR_PROG 0x01");
|
||||
Header.addDefine("DIR_LIST 0x05");
|
||||
Header.addDefine("DIR_MAT 0x06");
|
||||
Header.addDefine("DIR_PICT 0x07");
|
||||
Header.addDefine("DIR_CAPT 0x0A");
|
||||
|
||||
Header.addDefine("LIST_START 0x10");
|
||||
Header.addDefine("MAT_START 0x10");
|
||||
|
||||
Header.addDefine("SETUP_LISTFILE 0x2E");
|
||||
|
||||
Header.addDefine("free_str(x) if(!isString){free(x->data); free(x);}");
|
||||
Header.addDefine("getDigit(BCDvar, i) (((i)%2) ? (*(BCDvar))[((i)+1)/2+1]>>4 : (*(BCDvar))[((i)+1)/2+1]&0x0F)");
|
||||
Header.create();
|
||||
|
||||
System.out.println("Parsing done in " + (System.currentTimeMillis()-startTime) + " ms.");
|
||||
if (!assureOS1Compatibility) {
|
||||
System.out.println("WARNING: This program uses OS 2 functions. It won't run properly on the SDK emulator!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package b2c;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Constants {
|
||||
|
||||
static ArrayList<Double> consts = new ArrayList<Double>();
|
||||
|
||||
/**
|
||||
* This method is to optimise the speed of B2C by pre-calculating constants.
|
||||
* Only send to this method integer and double constants. For now, it won't calculate
|
||||
* special things like 1e5, 1/3, etc.
|
||||
*/
|
||||
public static void add(String constant) {
|
||||
constant = constant.replaceAll("\\x99", "-");
|
||||
System.out.println(constant);
|
||||
if (constant.startsWith(".")) {
|
||||
constant = "0" + constant;
|
||||
}
|
||||
if (consts.contains(Double.valueOf(constant))) {
|
||||
return;
|
||||
}
|
||||
consts.add(Double.valueOf(constant));
|
||||
//Calculate the bytes of the constant
|
||||
//Note: can't convert to double due to precision loss
|
||||
//To fix this, we remove the decimal point to convert to integer and keep the exponent
|
||||
|
||||
int exponent = 100; //exponent is 100-indexed in casio's system
|
||||
|
||||
if (constant.indexOf(".") >= 0) {
|
||||
//Remove trailing zeroes that have, in this case, no significance
|
||||
constant = constant.replaceAll("0+$", "");
|
||||
|
||||
//The exponent is modified by the number of significant digits after the decimal part
|
||||
exponent -= constant.length() - (constant.indexOf(".")+1);
|
||||
}
|
||||
|
||||
//Convert integer to scientific notation using StackOverflow magic
|
||||
//First number apparently means the number of significant digits (including exponent)
|
||||
//Second number is the number of digits after the decimal point (not including exponent)
|
||||
System.out.println(constant);
|
||||
|
||||
String sciNotation = String.format("%18.14e", Double.valueOf(constant.replaceAll("\\.", ""))).replace(",", ".");
|
||||
|
||||
|
||||
String mantissa = sciNotation.substring(0, sciNotation.indexOf("e")).replaceAll("\\.", "");
|
||||
System.out.println(mantissa);
|
||||
exponent += Integer.valueOf(sciNotation.substring(sciNotation.indexOf('e')+1));
|
||||
|
||||
//Can't use Integer.valueOf(mantissa) because it might be over 2^32
|
||||
if (mantissa.startsWith("-")) {
|
||||
exponent += 500;
|
||||
mantissa = mantissa.substring(1);
|
||||
}
|
||||
|
||||
String bcdNotation = (exponent < 100 ? "0" : "") + String.valueOf(exponent) + mantissa;
|
||||
if (bcdNotation.contains(".") || bcdNotation.contains("-") || bcdNotation.length() != 18) {
|
||||
Parser.error("Error in BCD conversion of " + constant + " which gave " + bcdNotation);
|
||||
}
|
||||
System.out.println("Result= "+bcdNotation);
|
||||
//Replace groups of 2 digits by "0x##, " and remove the last comma+space
|
||||
System.out.println(bcdNotation);
|
||||
bcdNotation = bcdNotation.replaceAll("(.{2})", "0x$1, ").replaceAll(", $", "");
|
||||
System.out.println(bcdNotation);
|
||||
Header.addGlobal("const BCDvar " + Constants.getVarNotation(constant) + " = {" + bcdNotation + "};\n");
|
||||
}
|
||||
|
||||
public static String getVarNotation(String nb) {
|
||||
return "_"+nb.replaceAll("\\.|\\-|\\x99", "_")+"_";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
package b2c;
|
||||
|
||||
//This class contains all B2C functions.
|
||||
|
||||
public class Functions {
|
||||
|
||||
static String functions = "\n//B2C functions\n\n";
|
||||
|
||||
//This is for automatically generated methods; for unique methods, write them manually in the local B2CFunctions.c file.
|
||||
public static void addFunctions() {
|
||||
/*
|
||||
//Calculation functions
|
||||
String[] operators = {
|
||||
"7F\"\"\\xB4",
|
||||
"10", // <=
|
||||
"11", // !=
|
||||
"12", // >=
|
||||
"3D", // =
|
||||
"3C", // <
|
||||
"3E", // >
|
||||
"A8", // ^
|
||||
"A9", // *
|
||||
"B9", // /
|
||||
"89", // +
|
||||
"99" // -
|
||||
};
|
||||
String[] calcFunctions = {
|
||||
"xor",
|
||||
"lessOrEqualThan",
|
||||
"notEqualTo",
|
||||
"greaterOrEqualThan",
|
||||
"equalTo",
|
||||
"lessThan",
|
||||
"greaterThan",
|
||||
"pow",
|
||||
"mult",
|
||||
"div",
|
||||
"add",
|
||||
"sub",
|
||||
};
|
||||
for (int i = 0; i < operators.length; i++) {
|
||||
functions += addMethod(
|
||||
"BCDvar B2C_" + calcFunctions[i] + "(BCDvar a, BCDvar b) {\n" +
|
||||
"\tBCDvar result;\n" +
|
||||
"\tconst char *function = \"A\\x" + operators[i] + "\"\"B\";\n" +
|
||||
"\tsetAlphaVar('A', &a);\n" +
|
||||
"\tsetAlphaVar('B', &b);\n" +
|
||||
"\tcalcExp(&function" +
|
||||
//_"+calcFunctions[i] +
|
||||
", dummyOpCode, &result, 1);\n" +
|
||||
"\treturn result;\n}\n");
|
||||
//Header.addGlobal("char *function_"+calcFunctions[i]+" = \"A\"\"\\x" + operators[i] + "\"\"B\";\n");
|
||||
|
||||
}
|
||||
String[] logicalOperators = {
|
||||
"&&", "and",
|
||||
"||", "or",
|
||||
};
|
||||
for (int i = 0; i < logicalOperators.length; i+=2) {
|
||||
functions += addMethod(
|
||||
"BCDvar B2C_" + logicalOperators[i+1] + "(BCDvar a, BCDvar b) {\n" +
|
||||
"\tif (a.bytes[1] " + logicalOperators[i] + " b.bytes[1]) {\n" +
|
||||
"\t\treturn _1_;\n" +
|
||||
"\t}\n" +
|
||||
"\treturn _0_;\n}\n"
|
||||
);
|
||||
}
|
||||
*/
|
||||
/*functions += addMethod(
|
||||
"BCDvar B2C_not(BCDvar a) {\n" +
|
||||
"\tif (a.bytes[1])\n" +
|
||||
"\t\treturn ZERO;" +
|
||||
"\treturn ONE;\n}\n"
|
||||
);
|
||||
|
||||
functions += addMethod(
|
||||
"char* B2C_convToStr(BCDvar nb) {\n" +
|
||||
"\tchar* result = calloc(15, 1);\n" +
|
||||
"\tbcdToStr(&nb, result);\n" +
|
||||
"\treturn result;\n}\n");
|
||||
|
||||
functions += addMethod(
|
||||
"BCDvar B2C_convToBCD(char* str) {\n" +
|
||||
"\tBCDvar result;\n" +
|
||||
"\tcalcExp(&str, dummyOpCode, &result, 1);\n" +
|
||||
"\treturn result;\n}\n");
|
||||
|
||||
functions += addMethod(
|
||||
"void B2C_setListRow(int nbList, int row, BCDvar value) {\n" +
|
||||
"\tif (row > list[nbList].nbElements) {\n" +
|
||||
"\t\tBCDvar *tempPtr = realloc(list[nbList].data, (list[nbList].nbElements+1)*sizeof(BCDvar));\n" +
|
||||
"\t\tif (tempPtr == NULL) {\n" +
|
||||
"\t\t\tfree(list[nbList].data);\n" +
|
||||
"\t\t\tB2C_stop();\n\t\t}\n" +
|
||||
"\t\tlist[nbList].data = tempPtr;\n" +
|
||||
"\t\tlist[nbList].nbElements++;\n\t}\n" +
|
||||
"\tlist[nbList].data[row] = value;\n}\n"
|
||||
);
|
||||
functions += addMethod(
|
||||
"void B2C_setDimList(int nbList, int nbElements) {\n" +
|
||||
"\tfree(list[nbList].data);\n" +
|
||||
"\tlist[nbList].data = calloc(nbElements+1, sizeof(BCDvar));\n}\n"
|
||||
);
|
||||
|
||||
functions += addMethod(
|
||||
"List B2C_newList(int nbElements, ...) {\n" +
|
||||
"\tList list;\n" +
|
||||
"\tva_list vaList;\n" +
|
||||
"\tlist.nbElements = nbElements;\n" +
|
||||
"\tlist.data = calloc(nbElements+1, sizeof(BCDvar));\n" +
|
||||
"\tva_start(vaList, nbElements);\n" +
|
||||
"\tlist.data[0] = ZERO;\n" +
|
||||
"\tfor (i = 1; i <= nbElements; i++) {\n" +
|
||||
"\t\tlist.data[i] = va_arg(vaList, BCDvar);\n" +
|
||||
"\t}\n" +
|
||||
"\tva_end(vaList);\n" +
|
||||
"\treturn list;\n}\n"
|
||||
);
|
||||
|
||||
//TODO: add method which takes (matrix, height, width) as argument, could lead to a faster conversion than initializing a list
|
||||
functions += addMethod(
|
||||
"void B2C_setDimMat(int matrix, List list) {\n" +
|
||||
"\tif (mat[matrix].data) free(mat[matrix].data);\n" +
|
||||
"\tmat[matrix].data = calloc((B2C_convToUInt(list.data[2])+1)*(B2C_convToUInt(list.data[1])+1), sizeof(BCDvar));\n" +
|
||||
"\tmat[matrix].width = B2C_convToUInt(list.data[1]);\n" +
|
||||
"\tmat[matrix].height = B2C_convToUInt(list.data[2]);\n" +
|
||||
"}\n"
|
||||
);
|
||||
|
||||
functions += addMethod(
|
||||
"int B2C_convToUInt(BCDvar nb) {\n" +
|
||||
"\tint result = 0;\n" +
|
||||
"\tint power = (nb.bytes[1]>>4) + 1;\n" +
|
||||
"\tfor (i = 1; i <= power; i++) {\n" +
|
||||
"\t\tif (i%2) {\n" +
|
||||
"\t\t\tresult += (nb.bytes[i/2+1]&0xF) * pow(10, power-i);\n" +
|
||||
"\t\t} else {\n" +
|
||||
"\t\t\tresult += (nb.bytes[i/2+1]>>4) * pow(10, power-i);\n" +
|
||||
"\t\t}\n" +
|
||||
"\t}\n" +
|
||||
"\treturn result;\n}\n"
|
||||
);
|
||||
|
||||
functions += addMethod(
|
||||
"BCDvar B2C_Getkey() {\n" +
|
||||
"\tBCDvar result;\n" +
|
||||
"\tif (!prgmGetkey(&result)) {\n" +
|
||||
"\t\tB2C_stop();\n" +
|
||||
"\t}\n" +
|
||||
"\treturn result;\n}\n"
|
||||
);
|
||||
|
||||
functions += addMethod(
|
||||
"void timerHandler() {\n" +
|
||||
"\tshort menuCode = 0x0308;\n" +
|
||||
"\tputMatrixCode(&menuCode);" +
|
||||
"\n}\n"
|
||||
);
|
||||
|
||||
functions += addMethod(
|
||||
"void B2C_stop() {\n" +
|
||||
"\tinstallTimer(6, (void*)&timerHandler, 1);\n" +
|
||||
"\tstartTimer(6);\n" +
|
||||
"\tGetKey(&key);\n" +
|
||||
"\tuninstallTimer(6);\n" +
|
||||
"\tPopUpWin(4);\n" +
|
||||
"\tlocate(5,3); Print(\"Interruption\");\n" +
|
||||
"\tlocate(4,5); Print(\"Appuyer:[MENU]\");\n" +
|
||||
"\twhile(1)\n" +
|
||||
"\t\tGetKey(&key);\n" +
|
||||
"\n}\n"
|
||||
);
|
||||
|
||||
//TODO actually randomize
|
||||
functions += addMethod(
|
||||
"BCDvar B2C_ranInt(int a, int b) {\n" +
|
||||
"\treturn ONE;\n}\n"
|
||||
);*/
|
||||
}
|
||||
|
||||
public static String getFunctions() {
|
||||
addFunctions();
|
||||
String functionsBuffer = IO.readFromRelativeFile("B2CFunctions.c");
|
||||
Integer[] functionsPositions = Parser.parseBrackets(functionsBuffer);
|
||||
|
||||
//System.out.println(functionsBuffer.substring(0, functionsPositions[2]));
|
||||
functions += addMethod(functionsBuffer.substring(0, functionsPositions[3]+1));
|
||||
for (int i = 3; i < functionsPositions.length-4; i+=4) {
|
||||
//System.out.println(functionsBuffer.substring(functionsPositions[i], functionsPositions[i+4]));
|
||||
functions += addMethod(functionsBuffer.substring(functionsPositions[i]+1, functionsPositions[i+4]+1));
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
|
||||
//Automatically generates the prototypes for the given method.
|
||||
public static String addMethod(String method) {
|
||||
|
||||
//This should normally get the method name.
|
||||
//String methodName = method.substring(method.substring(0, method.indexOf('(')).indexOf(' '), method.indexOf('('));
|
||||
Header.addPrototype(method.substring(0, method.indexOf('{')).trim() + ";\n");
|
||||
return method;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package b2c;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class G1MParser {
|
||||
|
||||
|
||||
public static String convert(String content) {
|
||||
if (content.isEmpty()) return "";
|
||||
|
||||
String currentProgram = Parser.parseProgName(content.substring(0, 8)); //content.substring(60,68);
|
||||
System.out.println("Program name: " + currentProgram);
|
||||
Header.addPrototype("void prog_"+currentProgram+"();\n");
|
||||
//System.out.println("Instructions : " + content.substring(86));
|
||||
content = content.substring(26);
|
||||
int lastCarriageReturn = -1;
|
||||
Parser.instructions.clear();
|
||||
Parser.instructionNumber = 0;
|
||||
Parser.nbBuffers = 0;
|
||||
|
||||
|
||||
//Divides the instructions
|
||||
for (int i = 0; i < content.length(); i++) {
|
||||
if (content.charAt(i) == '\r') {
|
||||
Parser.instructions.add(content.substring(lastCarriageReturn+1, i));
|
||||
lastCarriageReturn = i;
|
||||
}
|
||||
if (Parser.isMultibytePrefix(content.charAt(i))) {
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
Parser.instructions.add(content.substring(lastCarriageReturn+1));
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
/* Due to the functions returning BCDvar* and not BCDvar,
|
||||
* there must be buffers in which the functions return.
|
||||
* To avoid creating a buffer at each function call,
|
||||
* as many buffers are created as functions calls in an instruction.
|
||||
*/
|
||||
int nbBuffers = 0;
|
||||
do {
|
||||
Parser.nbBuffers = 0;
|
||||
result.append(Parser.tabs + Parser.parse(Parser.instructions.get(Parser.instructionNumber), Parser.WHOLE_INSTRUCTION) + "\n");
|
||||
Parser.instructionNumber++;
|
||||
if (nbBuffers < Parser.nbBuffers) {
|
||||
nbBuffers = Parser.nbBuffers;
|
||||
}
|
||||
} while (Parser.instructionNumber < Parser.instructions.size());
|
||||
|
||||
//Add buffers
|
||||
String buffers = "\tBCDvar ";
|
||||
for (int i = 0; i < nbBuffers; i++) {
|
||||
buffers += "buffer" + i;
|
||||
if (i+1 < nbBuffers) buffers += ", ";
|
||||
}
|
||||
buffers += ";\n";
|
||||
if (nbBuffers > 0) result.insert(0, buffers);
|
||||
result.insert(0, "void prog_"+currentProgram+"() {\n");
|
||||
//result = Parser.autoreplace(result);
|
||||
result.append("}");
|
||||
System.out.println("nb buffers = " + nbBuffers);
|
||||
System.out.println(Parser.nbBuffers);
|
||||
return result.toString();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package b2c;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Header {
|
||||
|
||||
static String headerDefines = "";
|
||||
static String headerPrototypes = "";
|
||||
static String headerGlobals = "";
|
||||
String headerVars = "";
|
||||
|
||||
public static void addDefine(String content) {
|
||||
headerDefines += "#define "+content+"\n";
|
||||
}
|
||||
|
||||
public static void addPrototype(String prototype) {
|
||||
headerPrototypes += prototype;
|
||||
}
|
||||
|
||||
public static void addGlobal(String global) {
|
||||
headerGlobals += global;
|
||||
}
|
||||
|
||||
public static void create() {
|
||||
|
||||
String header =
|
||||
"#ifndef MAIN_H\n" +
|
||||
"#define MAIN_H\n\n" +
|
||||
headerDefines + "\n\n" +
|
||||
"typedef unsigned char BCDvar[24]; //this defines BCDvar as an array of 24 unsigned chars\n" +
|
||||
"typedef struct {\n" +
|
||||
"\t//int nbElements;\n" +
|
||||
"\tBCDvar *data;\n" +
|
||||
"} List;\n\n" +
|
||||
"typedef struct {\n" +
|
||||
"\t//int width;\n" +
|
||||
"\t//int height;\n" +
|
||||
"\tBCDvar *data;\n" +
|
||||
"} Mat;\n\n" +
|
||||
//"typedef unsigned short Fontchar;\n" +
|
||||
"typedef struct {\n" +
|
||||
"\tint length;\n" +
|
||||
"\tunsigned char* data;\n" +
|
||||
"} Str;\n\n" +
|
||||
"typedef struct {\n" +
|
||||
"\tunsigned char data[4];\n" +
|
||||
"} SmallStr;\n\n" +
|
||||
headerPrototypes + "\n" +
|
||||
headerGlobals +
|
||||
"\n#endif //MAIN_H";
|
||||
IO.writeToFile(new File(B2C.path + "/main.h"), header, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package b2c;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class IO {
|
||||
public static void writeToFile(File file, String content, boolean deleteFile) {
|
||||
try {
|
||||
if (deleteFile) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile(), true));
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String readFromRelativeFile(String fileName) {
|
||||
byte[] encoded = null;
|
||||
try {
|
||||
//For some reason it appends a '/' to the beginning of the string, making the file path invalid
|
||||
String relativePath = B2C.class.getClassLoader().getResource(fileName).getPath().substring(1);
|
||||
encoded = Files.readAllBytes(Paths.get(relativePath));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String result = null;
|
||||
try {
|
||||
result = new String(encoded, "Cp1252");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String readFromFile(String path) {
|
||||
/*String content = "";
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "Cp1252"))) {
|
||||
content = br.
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
String content = "";
|
||||
byte[] encoded;
|
||||
try {
|
||||
encoded = Files.readAllBytes(Paths.get(path));
|
||||
content = new String(encoded, "Cp1252");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//remove header
|
||||
content = content.substring(32);
|
||||
|
||||
//due to unicode encoding, some characters get encoded as others
|
||||
|
||||
content = content.replaceAll("\\u2020", new String(new char[]{0x86}));
|
||||
content = content.replaceAll("\\u2021", new String(new char[]{0x87}));
|
||||
content = content.replaceAll("\\u02C6", new String(new char[]{0x88}));
|
||||
content = content.replaceAll("\\u2030", new String(new char[]{0x89}));
|
||||
content = content.replaceAll("\\uFFFD", new String(new char[]{0x8F}));
|
||||
content = content.replaceAll("\\u2019", new String(new char[]{0x92}));
|
||||
content = content.replaceAll("\\u201D", new String(new char[]{0x94}));
|
||||
content = content.replaceAll("\\u2122", new String(new char[]{0x99}));
|
||||
content = content.replaceAll("\\u0161", new String(new char[]{0x9A}));
|
||||
content = content.replaceAll("\\u203A", new String(new char[]{0x9B}));
|
||||
//TODO actually parse the g1m
|
||||
String[] programs = content.split("PROGRAM[\\s\\S]{13}system[\\s\\S]{2}");
|
||||
|
||||
String result = "";
|
||||
for (int i = 1; i < programs.length; i++) {
|
||||
String str = programs[i];
|
||||
|
||||
//removes \0 's at the end of the file
|
||||
result += "\n" + G1MParser.convert(str.substring(0, str.indexOf("\0", str.length()-4)));
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
|||
package b2c;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Syscalls {
|
||||
|
||||
//Not much to explain here. Look at a generated file to get an idea of what this does
|
||||
|
||||
static String syscallContent = "";
|
||||
static ArrayList<String> syscalls = new ArrayList<String>();
|
||||
static ArrayList<String> syscallIDs = new ArrayList<String>();
|
||||
|
||||
public static void addSyscall(String syscall, String syscallID) {
|
||||
syscalls.add(syscall);
|
||||
syscallIDs.add(syscallID);
|
||||
}
|
||||
|
||||
public static void createSyscallFile() {
|
||||
for (int i = 0; i < syscalls.size(); i++) {
|
||||
syscallContent += "\t.export\t_" + syscalls.get(i) + "\n";
|
||||
}
|
||||
for (int i = 0; i < syscalls.size(); i++) {
|
||||
syscallContent +=
|
||||
"\n_" + syscalls.get(i) + ":\n" +
|
||||
"\tmov.l\tsyscall_table, r2\n" +
|
||||
"\tmov.l\t_" + syscalls.get(i) + "_code, r0\n" +
|
||||
"\tjmp\t@r2\n" +
|
||||
"\tnop\n" +
|
||||
"_" + syscalls.get(i) + "_code:\n" +
|
||||
"\t.data.l\tH'" + syscallIDs.get(i) + "\n";
|
||||
}
|
||||
syscallContent +=
|
||||
"\nsyscall_table:\n" +
|
||||
"\t.data.l\tH'80010070\n\n" +
|
||||
"\t.end";
|
||||
IO.writeToFile(new File(B2C.path + "/syscalls.src"), syscallContent, true); //TODO change to false when all syscalls are added
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,291 @@
|
|||
/****************************************************************/
|
||||
/* */
|
||||
/* Memory */
|
||||
/* */
|
||||
/* Description: Fonctions de manipulation de la memoire */
|
||||
/* Auteur: LePhenixNoir */
|
||||
/* Version: 3.0 */
|
||||
/* Date: 11.06.2014 */
|
||||
/* Fichier: memory.c - Code des fonctions */
|
||||
/* */
|
||||
/****************************************************************/
|
||||
|
||||
#ifndef __FXLIB_H__
|
||||
#include "fxlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef _STDLIB
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef _STRING
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
int memory_errors = 0;
|
||||
|
||||
void memory_seterrors(int e)
|
||||
{
|
||||
memory_errors = (e!=0);
|
||||
}
|
||||
|
||||
void memory_error(char *from, char *func, int val)
|
||||
{
|
||||
unsigned int key;
|
||||
char info[20];
|
||||
if(!memory_errors) return;
|
||||
|
||||
sprintf(info,"%d",val);
|
||||
PopUpWin(6);
|
||||
|
||||
locate(4,2); Print((unsigned char *)"Memory ERROR !!");
|
||||
locate(3,4); Print((unsigned char *)"FROM:");
|
||||
locate(8,4); Print((unsigned char *)from);
|
||||
locate(3,5); Print((unsigned char *)"FUNC:");
|
||||
locate(8,5); Print((unsigned char *)func);
|
||||
locate(3,6); Print((unsigned char *)"INFO:");
|
||||
locate(8,6); Print((unsigned char *)info);
|
||||
locate(3,7); Print((unsigned char *)"META:");
|
||||
locate(8,7);
|
||||
|
||||
switch(val)
|
||||
{
|
||||
case 1: Print((unsigned char *)"NotEnoughRAM"); break;
|
||||
case -1: Print((unsigned char *)"Nonexisting"); break;
|
||||
case -5: Print((unsigned char *)"WrongDevice"); break;
|
||||
case -8: Print((unsigned char *)"AccessDenied"); break;
|
||||
case -14: Print((unsigned char *)"ReadOnly"); break;
|
||||
case -31: Print((unsigned char *)"DeviceError"); break;
|
||||
case -35: Print((unsigned char *)"NotEmpty"); break;
|
||||
default: Print((unsigned char *)"Other"); break;
|
||||
}
|
||||
GetKey(&key);
|
||||
}
|
||||
|
||||
FONTCHARACTER *memory_char2font(char *adresse)
|
||||
{
|
||||
FONTCHARACTER *adr;
|
||||
int i;
|
||||
|
||||
adr = calloc((strlen(adresse)+1),sizeof(FONTCHARACTER));
|
||||
for(i=0;i<strlen(adresse);i++) *(adr+i) = *(adresse+i);
|
||||
return adr;
|
||||
}
|
||||
|
||||
int memory_createfile(char *adresse, int size)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
int i = Bfile_CreateFile(adr,size);
|
||||
if(i<0) memory_error("createfile()","CreateFile()",i);
|
||||
|
||||
free(adr);
|
||||
return i;
|
||||
}
|
||||
|
||||
int memory_createdir(char *adresse)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
int i = Bfile_CreateDirectory(adr);
|
||||
if(i<0) memory_error("createdir()","CreateDir.()",i);
|
||||
|
||||
free(adr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int memory_openfile(char *adresse, int mode)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
int i = Bfile_OpenFile(adr,mode);
|
||||
if(i<0) memory_error("openfile()","OpenFile()",i);
|
||||
|
||||
free(adr);
|
||||
return i;
|
||||
}
|
||||
|
||||
int memory_deletefile(char *adresse)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
int i = Bfile_DeleteFile(adr);
|
||||
if(i<0) memory_error("deletefil.()","DeleteFil.()",i);
|
||||
|
||||
free(adr);
|
||||
return i;
|
||||
}
|
||||
|
||||
char **memory_alloc(int l)
|
||||
{
|
||||
char **p = calloc(l,sizeof(char *));
|
||||
int i; for(i=0;i<l;i++) *(p+i) = calloc(20,1);
|
||||
return p;
|
||||
}
|
||||
|
||||
void memory_free(char **p, int l)
|
||||
{
|
||||
int i; for(i=0;i<l;i++) free(*(p+i));
|
||||
free(p);
|
||||
}
|
||||
|
||||
int memory_find(char *adresse, char **files, int max)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
FONTCHARACTER found[30];
|
||||
FILE_INFO fileInfo;
|
||||
int searchHandle,i=1,j,x;
|
||||
|
||||
if(x = Bfile_FindFirst(adr,&searchHandle,found,&fileInfo)) return 0;
|
||||
for(j=0;j<14 && *(found+j);j++) *(*files+j) = *(found+j);
|
||||
|
||||
while(Bfile_FindNext(searchHandle,found,&fileInfo)==0 && i<max) {
|
||||
for(j=0;j<14 && *(found+j);j++) *(*(files+i)+j) = *(found+j);
|
||||
i++; }
|
||||
|
||||
Bfile_FindClose(searchHandle);
|
||||
free(adr);
|
||||
return i;
|
||||
}
|
||||
|
||||
int memory_exists(char *adresse)
|
||||
{
|
||||
char *file[1];
|
||||
int x;
|
||||
|
||||
*file = malloc(14); **file=0;
|
||||
x = memory_find(adresse,file,1);
|
||||
free(*file);
|
||||
|
||||
return x!=0;
|
||||
}
|
||||
|
||||
void *memory_load(char *adresse)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
int handle, x, size;
|
||||
void *p;
|
||||
|
||||
if((handle=Bfile_OpenFile(adr,_OPENMODE_READ))<0) { memory_error("load()","OpenFile()",handle); return NULL; }
|
||||
size = Bfile_GetFileSize(handle)+1;
|
||||
p = calloc(size,1);
|
||||
|
||||
if(!p) {
|
||||
memory_error("load()","malloc()",1);
|
||||
Bfile_CloseFile(handle); free(adr); return NULL; }
|
||||
if((x=Bfile_ReadFile(handle,p,size,0))<0) {
|
||||
memory_error("load()","ReadFile()",x);
|
||||
Bfile_CloseFile(handle); free(adr); return NULL; }
|
||||
|
||||
Bfile_CloseFile(handle);
|
||||
free(adr);
|
||||
return p;
|
||||
}
|
||||
|
||||
int memory_save(char *adresse, void *data, int l)
|
||||
{
|
||||
FONTCHARACTER *adr = memory_char2font(adresse);
|
||||
int x=0, handle;
|
||||
|
||||
if(memory_exists(adresse)) x = Bfile_DeleteFile(adr);
|
||||
if(x<0) { memory_error("save()","DeleteFile()",x); free(adr); return x; }
|
||||
x = Bfile_CreateFile(adr,l+1);
|
||||
if(x<0) { memory_error("save()","CreateFile()",x); free(adr); return x; }
|
||||
handle = Bfile_OpenFile(adr,0x02);
|
||||
if(handle<0) { memory_error("save()","OpenFile()",handle); free(adr); return handle; }
|
||||
x = memory_writefile(handle,data,l);
|
||||
if(x<0) { memory_error("save()","WriteFile()",x); free(adr); return x; }
|
||||
memory_closefile(handle);
|
||||
|
||||
free(adr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int memory_user_select(char **files, int n, int extension, int exit)
|
||||
{
|
||||
const unsigned char icons[7][32] = {
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x4,0x80,0x4,0x80,0x2,0x80,0x2,0x40,0x2,0x40,0x2,0x40,0x2,0x40,0x2,0x40,0x1,0x40,0x1,0x20,0x1,0x20,0xf,0x23,0xf0,0x3c,0x0 },
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x4,0x80,0x74,0x87,0x82,0x98,0x2,0x40,0x2,0x40,0x3a,0x43,0xc2,0x5c,0x2,0x40,0x39,0x43,0xc1,0x2c,0x1,0x20,0xf,0x23,0xf0,0x3c,0x0 },
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x74,0x87,0x94,0xb8,0x12,0xa0,0xa,0x63,0x8a,0x52,0x8a,0x54,0x4a,0x54,0x66,0x54,0x25,0x48,0x1d,0x29,0xe1,0x2e,0xf,0x23,0xf0,0x3c,0x0 },
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x4,0x87,0xc4,0x88,0x22,0x8c,0x62,0x4b,0xa2,0x44,0x42,0x42,0x82,0x42,0x82,0x42,0x81,0x44,0x41,0x2f,0xe1,0x20,0xf,0x23,0xf0,0x3c,0x0 },
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x4,0x87,0xe4,0x88,0x12,0x88,0x12,0x48,0x12,0x47,0xe2,0x44,0x22,0x44,0x22,0x44,0x21,0x44,0x21,0x23,0xc1,0x20,0xf,0x23,0xf0,0x3c,0x0 },
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x4,0x80,0x64,0x87,0xb2,0x98,0x52,0x51,0xb2,0x57,0x52,0x51,0xd2,0x4b,0xa,0x48,0x19,0x49,0xe1,0x2e,0x1,0x20,0xf,0x23,0xf0,0x3c,0x0 },
|
||||
{ 0x0,0x3c,0xf,0xc4,0xf0,0x4,0x80,0xe4,0x9c,0xa2,0x90,0xa2,0x58,0xe2,0x50,0x2,0x40,0x12,0x4a,0x2a,0x4a,0x39,0x4e,0x29,0x22,0x1,0x20,0xf,0x23,0xf0,0x3c,0x0 } };
|
||||
char *exts[19] = { ".txt", ".c", ".h", ".cpp", ".hpp", ".bmp",".jpg",".png",".gif", ".sav", ".g1m",".g2m",".g1r",".g2r", ".g1e",".g2e",".g1a", ".hex",".bin" };
|
||||
unsigned char indexs[19] = { 1,1,1,1,1, 2,2,2,2, 3, 4,4,4,4, 5,5,5, 6,6 };
|
||||
unsigned char *icoind = malloc(n);
|
||||
unsigned int key;
|
||||
|
||||
int i,j,k,t;
|
||||
int p=0, offset=0;
|
||||
|
||||
if(!icoind) { memory_error("user_sele.()","malloc()",1); return -2; }
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(t=-1,j=0;*(*(files+i)+j);j++) if(*(*(files+i)+j) == '.') t = j;
|
||||
icoind[i] = (t==-1?1:0);
|
||||
for(k=0;k<19;k++)
|
||||
if(!strcmp(*(files+i)+t,exts[k])) { icoind[i]=indexs[k]; break; }
|
||||
if(!extension && t+1) *(*(files+i)+t) = 0;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
Bdisp_AllClr_VRAM();
|
||||
|
||||
for(t=0;t<(n>3?3:n);t++)
|
||||
{
|
||||
if(icoind[offset+i]!=255) for(i=0;i<32;i++) {
|
||||
k = icons[icoind[offset+t]][i];
|
||||
for(j=0;j<8;j++) {
|
||||
if(k&1) Bdisp_SetPoint_VRAM(11-j+8*(i&1),20*t+4+(i>>1),1);
|
||||
k >>= 1; } }
|
||||
PrintXY(24,20*t+9,(const unsigned char *)*(files+offset+t),0);
|
||||
}
|
||||
Bdisp_DrawLineVRAM(2,20*p+3,2,20*p+20);
|
||||
Bdisp_DrawLineVRAM(3,20*p+2,99,20*p+2);
|
||||
Bdisp_DrawLineVRAM(3,20*p+21,99,20*p+21);
|
||||
Bdisp_DrawLineVRAM(100,20*p+3,100,20*p+20);
|
||||
if(offset>0) PrintXY(114,6,(const unsigned char *)"\346\234",0);
|
||||
if(offset+3<n) PrintXY(114,51,(const unsigned char *)"\346\235",0);
|
||||
|
||||
while(1)
|
||||
{
|
||||
GetKey(&key);
|
||||
if(key==30002 && exit) { free(icoind); return -1; }
|
||||
if(key==30004) break;
|
||||
if(key==30018 && (offset||p)) { if(p==2) p--; else if(offset) offset--; else p--; break; }
|
||||
if(key==30023 && (offset+p+1<n)) { if(p==0) p++; else if(offset+3<n) offset++; else p++; break; }
|
||||
}
|
||||
|
||||
if(key==30004) break;
|
||||
}
|
||||
|
||||
free(icoind);
|
||||
return offset+p;
|
||||
}
|
||||
|
||||
void *memory_user_autoload(char *prefix, char *selector, int l, int extension, int exit)
|
||||
{
|
||||
char **files = memory_alloc(l);
|
||||
char *adr = malloc(strlen(prefix)+strlen(selector)+1);
|
||||
void *data;
|
||||
int x;
|
||||
|
||||
sprintf(adr,"%s%s",prefix,selector);
|
||||
x = memory_find(adr,files,l);
|
||||
free(adr);
|
||||
x = memory_user_select(files,x,extension,exit);
|
||||
|
||||
adr = malloc(strlen(prefix)+strlen(files[x])+1);
|
||||
sprintf(adr,"%s%s",prefix,files[x]);
|
||||
data = memory_load(adr);
|
||||
|
||||
free(adr);
|
||||
memory_free(files,l);
|
||||
return data;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/****************************************************************/
|
||||
/* */
|
||||
/* Memory */
|
||||
/* */
|
||||
/* Description: Fonctions de manipulation de la memoire */
|
||||
/* Auteur: LePhenixNoir */
|
||||
/* Version: 3.0 */
|
||||
/* Date: 11.06.2014 */
|
||||
/* Fichier: memory.h - Fichier d'en-tete */
|
||||
/* */
|
||||
/****************************************************************/
|
||||
|
||||
#ifndef __MEMORY_H__
|
||||
#define __MEMORY_H__
|
||||
|
||||
|
||||
#define memory_closefile(h) Bfile_CloseFile(h)
|
||||
#define memory_writefile(h,c,l) Bfile_WriteFile(h,c,l)
|
||||
#define memory_readfile(h,b,s,p) Bfile_ReadFile(h,b,s,p)
|
||||
#define memory_seekfile(h,p) Bfile_SeekFile(h,p)
|
||||
#define memory_filesize(h) Bfile_GetFileSize(h)
|
||||
unsigned short *memory_char2font (char *);
|
||||
|
||||
void memory_seterrors (int);
|
||||
void memory_error (char *,char *,int);
|
||||
|
||||
int memory_createfile (char *,int);
|
||||
int memory_createdir (char *);
|
||||
int memory_openfile (char *,int);
|
||||
int memory_deletefile (char *);
|
||||
|
||||
char **memory_alloc (int);
|
||||
void memory_free (char **,int);
|
||||
int memory_find (char *,char **,int);
|
||||
int memory_exists (char *);
|
||||
void *memory_load (char *);
|
||||
int memory_save (char *,void *,int);
|
||||
|
||||
int memory_user_select (char **,int,int,int);
|
||||
void *memory_user_autoload (char *,char *,int,int,int);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue