Register

MCS Files, g[12][mr] and on-calc

Discuss issues related to Calculator Hacking/Modding.
Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

MCS Files, g[12][mr] and on-calc

Postby cakeisalie5 » Sat Dec 31, 2016 12:40 pm

Hi! While working on libg1m, I was wondering if I had the correct vision of the thing. I know an MCS file has a group (name), a directory (name), an ID and a filename. I now know that to identify correctly a file format, I need the group and the ID (and this correlates with the fact that files are more or less grouped by the group in G[12][MR] files), and that directories are either objects manipulated by two or more apps ("$GLOBAL", "main") or app-specific files (internal name of the app, e.g. @FINANCE).

But there are some weird things that I don't yet understand: the directory name is not displayed on the main memory listing, and with the data from the G1M I extracted on a reset calculator, sometimes there are directories (like E-CON2 or MAT_VCT) that can only be hardcoded, sometimes groups are in a directory (LIST 1 and LISTFILE 1 being in the LISTFILE directory), Y=DATA is a file when it's a group with several files in the G1M archive... plenty of things going on I really don't understand.

So I was wondering:
- are the files in the G1M archive the same as on the calculator?
- what does the group name really represent, is it only here to identify the files in the G1M file? What is the on-calc equivalent?
- how does the listing work on the calculator?

Thanks in advance! :D
Part of the Planète Casio community (FR) - main author of Cahute

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: MCS Files, g[12][mr] and on-calc

Postby SimonLothar » Sat Dec 31, 2016 6:05 pm

Most items which you can see with "MEMORY/F1:Main Memory" reside in the MCS. The MCS is a RAM-range starting at 88030000. Its directory starts at 88030100. The data-range starts at 88030A30, giving space for 0x93 internal main memory directory entries. Usually the MCS occupies about one 64 KiB RAM-sector. Two important items, which are displayed with "MEMORY/F1:Main Memory", are SETUP and ALPHA MEM. They are locateted elsewhere in the RAM.

If you backup the complete main memory or individual main memory items to some G1M/G2M-file, the resulting file has a different structure compared to the corresponding RAM-structure.

The naming differs, too (in some cases). F. i. "<LISTFILE>" represents the type 0x8A items of the internal MCS-directory "main".
"<STRING>" represents the type 0x85 items of the internal MCS-directory "main".
"<PROGRAM>" items reside in the internal MCS directory "system".

The way of the main memory cannot be described by a few statements. Things are not handled in a unique manner and should be discussed one by one.
I'll be back!

Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

Re: MCS Files, g[12][mr] and on-calc

Postby cakeisalie5 » Sat Dec 31, 2016 7:22 pm

So if I understand well, there is a {on-calc MCS type}/{G1M MCS type, G1M group} correspondance somewhere that serves for the zipping and unzipping of G1M files, and I suppose there is an {on-calc MCS type}/{listing properties (groupable, what group to put in, ...)} correspondance somewhere else that serves for the listing... right? Have you found any related syscall/function? Oo
Part of the Planète Casio community (FR) - main author of Cahute

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: MCS Files, g[12][mr] and on-calc

Postby SimonLothar » Sun Jan 01, 2017 11:44 am

First thing would be the way to retrieve SETUP and ALPHA MEM from RAM.
Setup_GetInfo is syscall 0x03DC.
MCS_GetAlphaMem is syscall 0x0842.

View SETUP and ALPHA MEM: Show
Code: Select all
#define USE_TEXTVIEW 0

typedef struct {
   unsigned char Name1[13];    // will be set to "SETUP.g1m" on return
   unsigned char Name2[9];    // will be set to "$GLOBAL" on return
   unsigned char Name3[10];    // will be set to "SETUP" on return
   void*StartOfSetup;
   unsigned int LengthOfSetup;
   unsigned short unknown; // 0x8038
} TSetupInfo;   

const unsigned char ALPHA_MEM_CODES[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\xCE\xCD\xC0\x00";

// ************************************************
// enumerate the SETUP / ALPHA MEM
int F06_5_Handler(){
#if USE_TEXTVIEW == 1   
TTextView*text;
#endif
char buffer[SIZE001];
char hb[40];
TAlpha bcd;
TSetupInfo SetupInfo;
int idx, x, y;
char*p;

   memset( buffer, 0, SIZE001 );
#if USE_TEXTVIEW == 1      
   text = new TTextView;
   (*text).SetFontsize( szMINI );
   (*text).buffer = buffer;
#endif   

   strcpy( (char*)hb, "SETUP" );
   strcat( buffer, hb );
   strcat( buffer, "\x0D\x0A" );
   
   Setup_GetInfo( 0, 0, &SetupInfo );
   strcat( buffer, (char*)SetupInfo.Name1 );
   strcat( buffer, " " );
   strcat( buffer, (char*)SetupInfo.Name2 );
   strcat( buffer, " " );
   strcat( buffer, (char*)SetupInfo.Name3 );
   strcat( buffer, "\x0D\x0A" );
   
   IntToHexN( (int)SetupInfo.StartOfSetup, (unsigned char*)hb, 8 );
   strcat( buffer, hb );
   strcat( buffer, " " );
   IntToHexN( SetupInfo.LengthOfSetup, (unsigned char*)hb, 2 );
   strcat( buffer, hb );
   strcat( buffer, "\x0D\x0A" );
   
   p = (char*)SetupInfo.StartOfSetup;
   x = 0;
   for ( idx = 0; idx < SetupInfo.LengthOfSetup; idx++ ){
      if ( x > 4 ){
         strcat( buffer, "\x0D\x0A" );
         x = 0;
      }
      IntToHexN( idx, (unsigned char*)hb, 2 );
      strcat( buffer, hb );
      strcat( buffer, ":" );
      IntToHexN( p[idx], (unsigned char*)hb, 2 );
      strcat( buffer, hb );
      strcat( buffer, " " );
      x++;
   }
   strcat( buffer, "\x0D\x0A" );
   
   strcat( buffer, "* * * * * * * * * *\x0D\x0A" );
   strcpy( (char*)hb, "ALPHA MEM" );
   strcat( buffer, hb );
   strcat( buffer, "\x0D\x0A" );

   for ( idx = 0; idx < 0x1D; idx++ ){
      hb[0] = ALPHA_MEM_CODES[ idx ];
      hb[1] = 0;
      strcat( buffer, hb );
      strcat( buffer, ": " );
      
      MCS_GetAlphaMem( ALPHA_MEM_CODES[ idx ], &bcd );   
      IntToHexN( *(int*)(&bcd.r), (unsigned char*)hb, 8 );
      strcat( buffer, hb );
      IntToHexN( *((int*)(&bcd.r)+1), (unsigned char*)hb, 4 );
      strcat( buffer, hb );
      strcat( buffer, " " );
      IntToHexN( *(int*)(&bcd.i), (unsigned char*)hb, 8 );
      strcat( buffer, hb );
      IntToHexN( *((int*)(&bcd.i)+1), (unsigned char*)hb, 4 );
      strcat( buffer, hb );
      strcat( buffer, "\x0D\x0A" );
   }
   
   
// now buffer could be written into a file.   
#if USE_TEXTVIEW == 1      
   (*text).Execute(0);
   delete text;
#endif   

   return 1;
}
I'll be back!

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: MCS Files, g[12][mr] and on-calc

Postby SimonLothar » Sun Jan 01, 2017 6:07 pm

Next thing would be the enumeration of the MCS, the largest part of the main memory:

enumerate MCS: Show
Code: Select all
// ********************* MCS ********************************
#define USE_TEXTVIEW_MCS 1

typedef struct {
   unsigned int adr1;
   unsigned int adr2;
   unsigned int adr3;
   unsigned int adr4;
} TMCSHeader;

typedef struct {
   unsigned char Name[8];
   unsigned int address;
   unsigned short filecount;
   unsigned short unknown;
} TMCSDirDef;

typedef struct {
   unsigned char Name[8];
   unsigned int offset;   // data offset relativ to 0x88030A30
   unsigned int size;      // filesize
   unsigned char type;   // file type
   unsigned char unknown;
   unsigned short dirnum;   
} TMCSFileDef;

// ************************************************
// enumerate the MCS memory
int F06_4_Handler(){
#if defined USE_TEXTVIEW_MCS
TTextView*text;
#endif
char buffer[SIZE001];
char hb[40];
TMCSHeader*pHeader;
TMCSDirDef*pDir;
TMCSFileDef*pFile;
int idx, iFile;

   memset( buffer, 0, SIZE001 );
   
#if defined USE_TEXTVIEW_MCS
   text = new TTextView;
   (*text).SetFontsize( szMINI );
   (*text).buffer = buffer;
#endif   

   strcpy( (char*)hb, "MCS walk" );
   strcat( buffer, hb );
   strcat( buffer, "\x0D\x0A" );
   
   pHeader = (TMCSHeader*)0x88030000;
   
   IntToHexN( (*pHeader).adr1, (unsigned char*)hb, 8 );
   strcat( buffer, hb );
   strcat( buffer, " " );
   
   IntToHexN( (*pHeader).adr2, (unsigned char*)hb, 8 );
   strcat( buffer, hb );
   strcat( buffer, " " );
   
   strcat( buffer, "\x0D\x0A" );
   
   IntToHexN( (*pHeader).adr3, (unsigned char*)hb, 8 );
   strcat( buffer, hb );
   
   strcat( buffer, " " );
   IntToHexN( (*pHeader).adr4, (unsigned char*)hb, 8 );
   strcat( buffer, hb );
   strcat( buffer, " \x0D\x0A" );
   
   strcat( buffer, "* * * * * * * * * *\x0D\x0A" );
   
   for ( idx = 0x92; idx >= 0 ; idx-- ){
      pDir = (TMCSDirDef*)0x88030100+idx;
      if ( (*pDir).Name[0] != 0 ){
         memcpy( hb, (char*)(*pDir).Name, 8 );
         strcat( buffer, hb );
         hb[8] = 0;
         strcat( buffer, " " );
         
         IntToHexN( (*pDir).address, (unsigned char*)hb, 8 );
         strcat( buffer, hb );
         strcat( buffer, " " );
         
         IntToHexN( (*pDir).filecount, (unsigned char*)hb, 4 );
         strcat( buffer, hb );
         strcat( buffer, " " );
         
         IntToHexN( 0x93 - idx, (unsigned char*)hb, 2 );
         strcat( buffer, hb );
         strcat( buffer, " " );
         
         strcat( buffer, "\x0D\x0A" );
         
         for ( iFile = 0; iFile < (*pDir).filecount; iFile++ ){
            pFile = (TMCSFileDef*)(*pDir).address + iFile;
            memcpy( hb, (char*)(*pFile).Name, 8 );
            strcat( buffer, " " );
            strcat( buffer, hb );
            hb[8] = 0;
            strcat( buffer, " " );
            
            IntToHexN( (*pFile).offset + 0x88030A30, (unsigned char*)hb, 8 );
            strcat( buffer, hb );
            strcat( buffer, " " );
            
            IntToHexN( (*pFile).size, (unsigned char*)hb, 4 );
            strcat( buffer, hb );
            strcat( buffer, " " );
            
            IntToHexN( (*pFile).type, (unsigned char*)hb, 2 );
            strcat( buffer, hb );
            
            // dirnum is equal ti 0x93 - idx
/*            
            strcat( buffer, " " );
            IntToHexN( (*pFile).dirnum, (unsigned char*)hb, 2 );
            strcat( buffer, hb );
*/            
            strcat( buffer, "\x0D\x0A" );
         }   
         
      }
   }
   strcat( buffer, "\x0D\x0A" );
   
// now buffer could be written into a file.   

#if defined USE_TEXTVIEW_MCS
   (*text).Execute(0);
   delete text;
#endif   

   return 1;
}
I'll be back!

Return to Calculator Hacking/Modding Discussions

Who is online

Users browsing this forum: No registered users and 26 guests