Register

Bfile and system errors

Discuss issues related to the Casio Prizm 3rd party development
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: Bfile and system errors

Postby SimonLothar » Tue Jul 16, 2013 10:38 pm

Syscall 0x1DA6 is a one parameter call. It definitly does not heed for a second parameter (which told me the OS!). I just verified it with a test-program. And according to this test-program, it does not seem to heed for the actual filepos implicitly, either. So it seems, that it returns the filesize as it is in any case. If you can reproduce a situation, where this is not so, let me know.

BTW: I published the interfaces in April 2012 (after a lot of investigation). Back then I named syscall 0x1DAB Bfile_FilePos_OS. I thought the name would be appropriate for a function, which returns the file position.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Tue Jul 16, 2013 10:55 pm

Bfile_FilePos_OS was renamed to Bfile_TellFile_OS in libfxcg because usually cstdio (stdio.h) has a function called "tell" which does exactly what this function does. As for 0x1DA6 having two parameters, I don't know who got to that wrong conclusion.

Anyway, I fixed all the Bfile_GetFileSize_OS calls in my code to include just the file handle, and the calculator still reboots sometimes when adding a calendar event/task (it's the same mechanism for both things, only the UI changes).

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: Bfile and system errors

Postby SimonLothar » Wed Jul 17, 2013 4:49 am

gbl08ma wrote:PS: I can post a new compiled version of the add-in which has just the reboot-on-AddEvent problem for you to check, if you want.
Yes. That's reasonable. I'll have a look.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Wed Jul 17, 2013 10:21 am

Here it is:
http://s.lowendshare.com/6/1374052519.356.utilities.g3a
(rename it to utilities.g3a in case the download has a strange filename).

Note that this version doesn't use the Main Memory folder @UTILS2 but yes @UTILS.

I couldn't detect any problem in this version other than the reboot when adding an event (also causes problems in event copying and moving), and some problems in my own file copy routine (but that's not relevant for now). I have also monitored for memory leaks, but everything seems to be OK.

If you want, you can enable a special debug mode of my add-in: on the clock (main) screen, press Shift then zero (Utilities control will appear). Then choose "Debug On". This will enable debug for that session (it's not a persistent setting). Then on most (but not all) screens you can press Shift+Optn to open the Test Mode, or Shift+Var to see the amount of stack used in bytes (since I don't use heap/malloc a lot).

EDIT: I noticed that the reboot usually happens when it is adding an event for the 5th consecutive time (I'm using the tasks GUI to test this, along with the emulator's key-log function to save me the work of having to press the keys each time). It rebooted 6 times when adding the event for the 5th time, and once it rebooted only after the 7th time.
Please note, that the problem only seems to occur when adding an event to a new file (i.e. there were zero events before). Adding events to files which already have them seems to be fine.

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: Bfile and system errors

Postby SimonLothar » Wed Jul 17, 2013 4:05 pm

For a start: I could reproduce the error. 7 events on 17th. No error. Then one event on 24st: reboot.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Wed Jul 17, 2013 4:17 pm

If you delete all events on the 17th, then add a new event, then delete it again, then add a new event, you'll probably find out it will reset too at some point.
It always resets when adding, never when deleting (and I think never when editing too).

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: Bfile and system errors

Postby SimonLothar » Wed Jul 17, 2013 6:10 pm

I just saw, that my version of Bfile_OpenFile (0x1DA3) uses a third parameter (int).
The third parameter has to be set to zero and according to the OS it is used for some, yet unknown purpose. If it is not included in the interface, the value of the third parameter is random and may lead to some unpredictable results.
And the reboots, which I encountered, must have happened inside of Bfile_OpenFile.

----
Another hint: in calendarProvider.cpp line 478 I noticed

goto conversionstart;

this jump leaves a MsgBoxPush() / MsgBoxPop() -frame.

Every MsgBoxPush() must have its closing MsgBoxPop(), otherwise the system tends to crash.
syscall 0x17F7 : void MsgBoxPush( int height );
Displays a box. height might be 1..6. Obviously this call allocates resources. Release these resources with MsgBoxPop! Otherwise the system will crash.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Wed Jul 17, 2013 6:27 pm

I added the third parameter to OpenFile, set it to zero on all the calls to it, and it still rebooted.

As the thing in conversion start with MsgBox, well right now I don't think that code ever runs. It was something I added in the previous version of the add-in when deleting events was really unstable, and somehow it made it to this version thanks to code recycling (much like what Casio did from fx-9860G to Prizm, regarding SD card strings, backup battery and the like :) ). I am going to delete that code anyway.

Here's a build of the add-in with the changes: http://s.lowendshare.com/6/1374082055.243.utilities.g3a

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: Bfile and system errors

Postby SimonLothar » Thu Jul 18, 2013 7:31 am

gbl08ma wrote:I added the third parameter to OpenFile, set it to zero on all the calls to it, and it still rebooted.
Yes. I had a closer look and I have to retract my statement a bit. The third parameter is set to zero by OS-functions, which use syscall 0x1DA3. But 0x1DA3 actually does not use the third parameter in the OSes, which have been published up to now (t. i. up to 1.04). I set this parameter because of security, in case a future OS might use it.
---
Now the next idea:
FILE_HEADER in
#define FILE_HEADER "PCALEVT"
has an odd length (7).
On the fx-9860-calculators writing an odd number to the flash leads to some bad problems. On the Prizm I could not detect any problems with writing an odd count of bytes in a little test-program, yet. Though, the low-level flash-writing routines still work WORD-based. Somehow the Prizm's flash-routines seem to handle the odd-count issue. Perhaps not successful sometimes.

I used the UBC to trace down the problem and the reboot seems to happen around here:
Bfile_WriteFile_OS(hAddFile, FILE_HEADER, strlen(FILE_HEADER));

Just to eliminate this error possibility, could you try to use an even length FILE_HEADER.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Thu Jul 18, 2013 9:39 am

I changed PCALEVT to PCALEVNT (8 bytes) and now it resets even more often, like at the first or second time I try to create a event file from scratch.

But I'll try another thing, which is doing a strcat of the event contents to the header before writing, so that the header never gets written "lonely", and report back.

EDIT: I changed the code to what you see here: https://github.com/gbl08ma/utilities/bl ... ovider.cpp
Unfortunately it uses more RAM for the additional finalcontents buffer, but it works! It no longer rebooted, and I tried with both tasks and calendar events.

Lesson learnt: apparently WriteFile has a problem with writing a small number of bytes, no matter if it's odd or even.

Thanks a lot for your help!

Previous

Return to Casio Prizm SDK

Who is online

Users browsing this forum: No registered users and 14 guests