11-21-2018, 08:50 PM
Well, I'm trying this save/load functionalities and at the momment doesn't work.
I'm reading the code (the Thor code is the same code that the libraty.c on ngpc framework, so I think that simply, Thor copy and paste the same code without modifications). I'm resize the rom file to 2Mb with the resize script of Loïc too.
I need help to check and understood this code block.
1. So, as we are talking about, first of all, I need only the offset and de block. By default, the original code put the offset value to 0x1e0000 and block number to 30. Ok..for the momment I leave it with this values. So, the save method has this:
My first doubt in this method is that, the data parameter is passed to the function, but not is used with her own name in any place of this assembly code. Where is used the data parameter on this method?
2. The second method, GetSavedData() do various things:
Well, someone can help me? I'm so lost here.
I'm reading the code (the Thor code is the same code that the libraty.c on ngpc framework, so I think that simply, Thor copy and paste the same code without modifications). I'm resize the rom file to 2Mb with the resize script of Loïc too.
I need help to check and understood this code block.
1. So, as we are talking about, first of all, I need only the offset and de block. By default, the original code put the offset value to 0x1e0000 and block number to 30. Ok..for the momment I leave it with this values. So, the save method has this:
Code:
__ASM("SAVEOFFSET EQU 0x1e0000");
__ASM("BLOCK_NB EQU 30");
//__ASM("SAVEOFFSET EQU 0x1FA000");
//__ASM("BLOCK_NB EQU 0x21");
__ASM("VECT_FLASHWRITE EQU 6");
__ASM("VECT_FLASHERS EQU 8");
__ASM("rWDCR EQU 0x6f");
__ASM("WD_CLR EQU 0x4e");
// Erase block first (mandatory) : 64kb for only 256 bytes
__ASM(" ld ra3,0");
__ASM(" ld rb3,BLOCK_NB");
__ASM(" ld rw3,VECT_FLASHERS");
__ASM(" ld (rWDCR),WD_CLR");
__ASM(" swi 1");
// Then write data
__ASM(" ld ra3,0");
__ASM(" ld rbc3,1"); // 256 bytes
__ASM(" ld xhl,(xsp+4)");
__ASM(" ld xhl3,xhl");
__ASM(" ld xde3,SAVEOFFSET");
__ASM(" ld rw3,VECT_FLASHWRITE");
__ASM(" ld (rWDCR),WD_CLR");
__ASM(" swi 1");
__ASM(" ld (rWDCR),WD_CLR");
My first doubt in this method is that, the data parameter is passed to the function, but not is used with her own name in any place of this assembly code. Where is used the data parameter on this method?
2. The second method, GetSavedData() do various things:
- a. It Create a u32 pointer called ptr, with 0x200000+0x1e0000 value. For me, the problem here is that I don't know what is the real valie of 0x200000+0x1e0000.
- b. It Create a u32 pointer called ptrData, of the data array (I supose that, if I change the value of some index of this data array previously, the ptrData has the value too)
- c. First great doubt, the if statement check if the value of ptr it's equal like 0xcafebabe (MAGIC_NB definition). For what reason the pointer ptr (0x200000+0x1e0000) sould be equals at 0xcafebabe literal? In case of this was equals, fill the array with the data.
- d. In case of the previous point was false, It puts in the first index of array the value of MAGIC_NB and erase all array values with 0.
Code:
void GetSavedData()
{
u32 *ptr = (u32*)(0x200000+0x1e0000);
u32 *ptrData = (u32*)data;
u8 i;
if (*ptr == MAGIC_NB) // Data saved
{
for (i=0;i<64;i++)
ptrData[i] = ptr[i];
}
else // No data
{
ptrData[0] = MAGIC_NB;
for (i=1;i<64;i++)
ptrData[i] = 0;
}
}
Well, someone can help me? I'm so lost here.