Omnimaga

Calculator Community => Casio Calculators => Topic started by: bsl on June 03, 2011, 08:22:23 pm

Title: Prizm: C Addin & CASIO Basic programs works together
Post by: bsl on June 03, 2011, 08:22:23 pm
This is a port of MPoupe's TSR program for the fx-9860 to the Prizm. http://ourl.ca/10095
I had this idea earlier, but wasn't sure where to start:  http://ourl.ca/9185/173872
I added new syscalls to this program, not found in the mini-SDK, but proven to work here.
The program was developed using Simon's mini-SDK, on the cg10-20 Manager emulator and
finally tested on Prizm hardware. [easier to recover from emulator crashes]
The code is almost the same as MPoupe's , but I took out the scrolling screen and
put in the appearing rotating character sequence "/","-","\", ...
You get this on the lower right corner after the program appears to finish, and press and hold one of the navigation keys: UP,DOWN,LEFT,RIGHT
You exit the progran pressing EXIT.
To run again delete TSRDEMO, and activate another addin like Conversion , then back to BASICEXT


This is only a proof of concept, this works the same way n the Prizm as on the fx-9860
The wish list of what to add to this is long.  Adding custom Basic commmands is possible.

Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: Ashbad on June 03, 2011, 08:27:19 pm
Looks interesting :) how exactly does this work?  Is it like an all new BASIC editor/interpreter, or does it just improve upon the current form of BASIC?  Does this have a documentation of commands and the like?
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: bsl on June 03, 2011, 08:33:02 pm
Looks interesting :) how exactly does this work?  Is it like an all new BASIC editor/interpreter, or does it just improve upon the current form of BASIC?  Does this have a documentation of commands and the like?
Nothing yet , but it shows promise - its very early at this point to use this - its just a demo
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: DJ Omnimaga on June 03, 2011, 08:33:14 pm
Wow this looks nice. I unfortunately do not know how that stuff works so I would need program examples with visible code to see how it operates, or documentation of some commands, but this sounds promising. :D
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: bsl on June 03, 2011, 08:40:39 pm
The zip is on the posting just above the first picture. Sorry - It is hard to see and easy to miss.
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: DJ Omnimaga on June 03, 2011, 08:55:47 pm
Oh ok, thanks. :D

That might be useful because a lot of people like BASIC style languages and might not want to learn an entire new language, so they can stick to BASIC while being able to do some extra stuff.
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: JosJuice on June 04, 2011, 03:52:50 am
Looks interesting :) how exactly does this work?  Is it like an all new BASIC editor/interpreter, or does it just improve upon the current form of BASIC?  Does this have a documentation of commands and the like?
It adds functionality to the existing BASIC. The one that's currently posted is just a demo, but the code of it can probably be used to make much more complex stuff.
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: SimonLothar on June 04, 2011, 09:02:30 am
I just downloaded BasicExtension_001.zip and had a look a the source.

It installs a timer-handler and starts the built-in Basic-Interpreter (APP_PRGM). While the BASIC interpreter waits for input, the timer-handler injects keycodes (via PutKey) based on a fixed text, hardcoded in the G3A. The built-in BASIC interpreter receives the keycodes and acts accordingly. But alas, I cannot see, how it should be possible to change the behaviour of the BASIC interpreter this way.
Some years ago, I wrote LOADER for the fx-9860, which followed this scheme to load BASIC-programs from storage memory:
http://www.casiokingdom.org/modules.php?name=Downloads&d_op=viewdownloaddetails&lid=542&title=FX9860G%20LOADER%202.00
If I am not totally mistaken, the upload contains some source and knowhow. But I do not know, if casiokingdom's download area is still operable at all.

If you want to change/extend the BASIC-interpreter, you either have to write a completely new interpreter as G3A (sagarvaze did this some years ago at casiokingdoms) or you have to mod the OS.

@bsl: are you one of the SDK-chums, which have been around at casiokingdoms some years ago? The old syscall-wrapper: long time no see!
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: JosJuice on June 04, 2011, 09:04:53 am
I just downloaded BasicExtension_001.zip and had a look a the source.

It installs a timer-handler and starts the built-in Basic-Interpreter (APP_PRGM). While the BASIC interpreter waits for input, the timer-handler injects keycodes (via PutKey) based on a fixed text, hardcoded in the G3A. The built-in BASIC interpreter receives the keycodes and acts accordingly. But alas, I cannot see, how it should be possible to change the behaviour of the BASIC interpreter this way.
Ah, so that's what it does? It gives key input to the BASIC program? Then it might not be as exciting as I thought at first... But still, nice job.
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: fxdev on June 04, 2011, 09:32:43 am
That's why MPoupe said somewhere this is for demo purposes only.
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: bsl on June 10, 2011, 05:21:55 pm
But alas, I cannot see, how it should be possible to change the behaviour of the BASIC interpreter this way.
If you want to change/extend the BASIC-interpreter, you either have to write a completely new interpreter as G3A (sagarvaze did this some years ago at casiokingdoms) or you have to mod the OS.
MPoupe  outlines on the other link given above how to do this - there is interaction between the interpreter and the C program.
You establish an I/O protocol through Alpha variables to accomplish the custom call.
So you have to write the basic program differently. I think for the time being I will develop it this way .
The first two custom calls will be Asm and Syscall .

I would really like to make this transparent to the Basic coder as you are wondering about and find a syscall to the interpreter,
such as SetBasicErrorHandler to handle and process new calls if it exists ?

@bsl: are you one of the SDK-chums, which have been around at casiokingdoms some years ago? The old syscall-wrapper: long time no see!
It's in MPoupes code, I only started on Casio calcs January 2011. 
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: MPoupe on June 13, 2011, 12:31:09 pm
I just downloaded BasicExtension_001.zip and had a look a the source.

It installs a timer-handler and starts the built-in Basic-Interpreter (APP_PRGM). While the BASIC interpreter waits for input, the timer-handler injects keycodes (via PutKey) based on a fixed text, hardcoded in the G3A. The built-in BASIC interpreter receives the keycodes and acts accordingly. But alas, I cannot see, how it should be possible to change the behaviour of the BASIC interpreter this way.
Some years ago, I wrote LOADER for the fx-9860, which followed this scheme to load BASIC-programs from storage memory:
http://www.casiokingdom.org/modules.php?name=Downloads&d_op=viewdownloaddetails&lid=542&title=FX9860G%20LOADER%202.00
If I am not totally mistaken, the upload contains some source and knowhow. But I do not know, if casiokingdom's download area is still operable at all.

If you want to change/extend the BASIC-interpreter, you either have to write a completely new interpreter as G3A (sagarvaze did this some years ago at casiokingdoms) or you have to mod the OS.

@bsl: are you one of the SDK-chums, which have been around at casiokingdoms some years ago? The old syscall-wrapper: long time no see!
Hello SimonLothar,
I wrote the original TSR demo.
Yes, the source si very simple, I tried to show the concept as simple as possible. This is also the reason why I used the "old syscall-wrapper", this allowed me to use 1 simple source code file:-)
The OS extension is very far from to be ideal. The idea is to communicate from Basic to TSR by agreed variables (e.g. A,B).
The Basic must not use A for any other purposes and must keep it's value to 0 in idle. If basic wants some extra functionality (e.g. load new basic program from the flash), it setups the parameters (set up additional variables (e.g. filename to load to Str 1, filename to save to Str2) and as a last thing set variable A to the appropriate code (value).
TSR periodically check A's value and if it is nonzero, it will execute the requested operation and after then it resets A to 0.
Basic may wait for execution (for synchronous - like operations) - loop until A is zero again.
I write simple example, how it may work at http://ourl.ca/10095/197514
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: SimonLothar on June 13, 2011, 01:19:30 pm
The idea is to communicate from Basic to TSR by agreed variables (e.g. A,B).
Very smart idea!
Do you use one of the free system timers to implement the TSR (if I remember right, the user timers are destroyed if another addin is invoked)?
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: MPoupe on June 14, 2011, 05:48:16 am
Do you use one of the free system timers to implement the TSR (if I remember right, the user timers are destroyed if another addin is invoked)?
No, I used standard SDK timer. Another addin would not only kill my timer, but also unmap my memory area (do the timer handler would be invalid). So I called App_PRGM() (0x09F5 on 9860G, 0x1945 on cg20), which runs as standard procedure (it keep my TSR addin as the current one). I inspired by your loader :-)
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: SimonLothar on June 14, 2011, 06:32:30 am
Do you use 0x04DF and 0x04E0 to get and set the BASIC-variable, which you use to communicate (on 9860G)?
Do you know the corresponding syscall numbers on the fxCG?
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: MPoupe on June 14, 2011, 07:13:07 am
Do you use 0x04DF and 0x04E0 to get and set the BASIC-variable, which you use to communicate (on 9860G)?
Do you know the corresponding syscall numbers on the fxCG?
I don't - I didn't try this on cg. But bsl knows:
const int SysCallWrapper[] = {0xD201422B,0x60F20000,0x80020070};
int (*iSysCallFuncPtr)( int R4, int R5, int R6, int R7, int FNo ) = (  int (*)(int,int,int,int,int))&SysCallWrapper;
#define PutKey(key) (void)(*iSysCallFuncPtr)( key,key<256, 0, 0, 0x0EA9)
#define Alpha_GetData(VarName,Dest) (void)(*iSysCallFuncPtr)( VarName,(int)Dest, 0, 0, 0x0034)
#define Alpha_ClearAll() (void)(*iSysCallFuncPtr)( 0,0, 0, 0, 0x0036)
#define App_PRGM() (void)(*iSysCallFuncPtr)( 0,0, 0, 0, 0x1945)
#define Timer_Start(ID) (int)(*iSysCallFuncPtr)( ID,0, 0, 0, 0x08DB)
#define Timer_Stop(ID) (int)(*iSysCallFuncPtr)( ID,0, 0, 0, 0x08DC)
#define Timer_Install(ID, handler, elapse) (int)(*iSysCallFuncPtr)( ID, (int)handler, elapse, 0, 0x08D9)
#define Timer_Deinstall(ID) (int)(*iSysCallFuncPtr)( ID,0, 0, 0, 0x08DA)
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: bsl on June 14, 2011, 09:57:23 am
Here is another, not in the demo, but necessary to complete communication between Basic and C:
#define Alpha_SetData(VarName,Src) (char)(*iSysCallFuncPtr)( VarName,(int)Src, 0, 0, 0x0035)

Some other untested syscalls, I have found:
Setup_GetEntry 0x0489
Setup_SetEntry 0x048B
Alpha_ClearAllAndAns 0x0A8C
Title: Re: Prizm: C Addin & CASIO Basic programs works together
Post by: SimonLothar on June 14, 2011, 12:28:31 pm
Here is another, not in the demo, but necessary to complete communication between Basic and C:
#define Alpha_SetData(VarName,Src) (void)(*iSysCallFuncPtr)( VarName,(int)Src, 0, 0, 0x0035)

Some other untested syscalls, I have found:
Setup_GetEntry 0x0489
Setup_SetEntry 0x048B
Alpha_ClearAllAndAns 0x0A8C
I added your "Alpha_" findings to my CHM-file (with a proper reference, of course). THX.

But 0x0489 and 0x048B are some BCD-routines, which check a BCD-number's error state.
Setup_GetEntry is 0x0031 and Setup_SetEntry is 0x0032. In the first place I used different names, which was misleading. Sorry.
I changed them to the old naming convention at once.