Difference between revisions of "WSC and FVM"

From Casio Universal Wiki
Jump to: navigation, search
(WSC Functions)
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{MsgBox|title=Hello !|text=New version ('''1.2''') released! If you are using an older version [http://www.casio-scene.com/downloads.php?do=file&id=396 update now]! This page will be improved in next days.|TitleStyle=color:#00FF44;text-decoration:underline;}}
+
{{MsgBox|title=Hello !|text=New version ('''1.3''') will be released in next days, stay tunned.|TitleStyle=color:#00FF44;text-decoration:underline;}}
 
<br/>
 
<br/>
 
==Getting Started==
 
==Getting Started==
Line 16: Line 16:
 
Enter the text:
 
Enter the text:
 
<pre>void main( )
 
<pre>void main( )
 
 
{
 
{
 
+
      printf( “Hello World!\n” );
    printf( “Hello World!\n” );
 
 
 
 
}</pre>
 
}</pre>
  
(PS the edit can adjust the font size (shift-set up to enter the setting interface), use the small print on one screen you can see more code, it is recommended to use the small print, set the font size in the optn other Word the wrap is also recommended to choose the offrecommended settings below)
+
(P.S. EDIT could adjust the font size(shift--set up to enter the setting interface), you can see more code on a screen by using the small font, it is recommended to use the small print,the recommended settings below)
  
 
[[File:Edit-settings.png]]
 
[[File:Edit-settings.png]]
Line 35: Line 32:
 
[[File:Wsc-fvm-compile-file.jpg]]
 
[[File:Wsc-fvm-compile-file.jpg]]
  
If there are no error, the screen output is done, if there are errors you can return to EDIT to modify. Upon completion any key to exit into the FVM, the F1 (run) the implementation of the bytecode. The screen will output hello world. After the implementation of any key to exit.
+
If there are no errors, the screen will output “Done”, if there are some errors, you can go back to EDIT to modify. After compiling, enter FVM, press F1(run) to run the bytecode file. the screen will output “hello world”
  
 
[[File:Wsc-fvm-hello-f.jpg]][[File:Wsc-fvm-run-hello.jpg]]
 
[[File:Wsc-fvm-hello-f.jpg]][[File:Wsc-fvm-run-hello.jpg]]
Line 44: Line 41:
 
+ - * / % += -= *= /= < <= > >= == != && || ! != &
 
+ - * / % += -= *= /= < <= > >= == != && || ! != &
  
Note that the last '&' is the address instead of a bitwise
+
note the last &is geting address but not bitwise and
  
 
===Data type===
 
===Data type===
  
Any number of dimensions in an int a char a float array to point to the basic types of pointer (pointer to the array)
+
int char float mult-dimensions array pointer(can’t point to array) string constant
  
 
===Statement===
 
===Statement===
  
If the else the while for the return the break
+
if else while for return break
  
 
===Notes===
 
===Notes===
  
C style / * ........... * / and C + + style / / ...........
+
C style /*............*/ and C++ style //............
  
 
===The function===
 
===The function===
  
Support recursion, a detailed list of library functions, see library.html
+
supports recursion, a detailed list of library functions, see [[#WSC_Functions|library section]]
  
 
===Preprocessor===
 
===Preprocessor===
Line 67: Line 64:
  
 
==WSC Error reporting==
 
==WSC Error reporting==
Wsc error reporting is not perfect, calculator small screen is not easy to display all error messages.
+
The error reporting of WSC is not perfect,
  
Wsc will be displayed on the screen when the error is detected, the error message, as shown:
+
WSC will displayed the error message when the error is detected, as below:
  
 
[[File:Wsc-error-reporting.jpg]]
 
[[File:Wsc-error-reporting.jpg]]
  
Then press the menu key you can exit to modify the other key to display the next error message.
+
You can press menu key to exit and go back to modify source code. If you press any other key, the next error message will be displayed.
  
 
<font color="red">Note that WSC did not prompt a warning!</font>
 
<font color="red">Note that WSC did not prompt a warning!</font>
  
Any pointers, arrays, in its eyes are the same, any assignment.
+
Any pointers, arrays are the same in its eyes,
 +
 
 +
Any assignment between int, char, float will not generate any errors.
  
int, a char, float, assignment, will not generate any warning messages.
+
A function that return type is not ‘void’ don’t return a value will not generate any errors.
  
 
==Some differences in the WSC with the standard C==
 
==Some differences in the WSC with the standard C==
 +
There ary some differences between the WSC and the standard C.
  
===Does not require the function declaration===
+
===Doesn’t require the function declaration===
  
As long as the function is defined in the file, regardless of location, can call anywhere.
+
As long as the function is defined in the file, regardless of location, you can call anywhere.
  
 
===Only two scopes===
 
===Only two scopes===
  
The entire procedure only two scope, global scope and function within the local scope.
+
The program has only two scopes, global scope and local scope of funcion.
  
 
<pre>void main()
 
<pre>void main()
 
 
{
 
{
 
 
int a;
 
int a;
 
 
{
 
{
 
 
     int a;
 
     int a;
 
 
}
 
}
 
 
}</pre>
 
}</pre>
  
The example program will receive an error message "Variable 'a' redefinition"
+
the example program will recerve an error message “Variable ‘a’ redefinition”
  
 
===int * a, b;===
 
===int * a, b;===
 
+
a and b will both be a pointer.(so, it recommended that written int* a, b; but not int *a, b;);
WSC a and b will be a pointer to int. (It is recommended that written int * a, b; instead of int * a, b;).
 
  
 
===int *p; p++;===
 
===int *p; p++;===
The actual value of p in the ANSI C plus 4 (sizeof (int)), but WSC will only p plus 1.
+
The actual value of p will add 4(i.e. sizeof(int) ) in the ANSI C, but WSC will only let p add 1
  
 
===char s[50] = “asdfjkl”;===
 
===char s[50] = “asdfjkl”;===
Line 118: Line 111:
  
 
===int a[2][2] = { 1, 2, 3, 4 };===
 
===int a[2][2] = { 1, 2, 3, 4 };===
Int a [2] [2] = {1, 2, 3, 4};
+
This initialization is not yet supported, sample sentence is wrong.
  
This initialization is not yet supported, sample sentence is wrong. Multidimensional array initialization must be properly grouped, such as
+
Mult-idimensional array initialization must be grouped properly, such as
  
int a[2][2] = { {1, 2}, {3, 4} }; grouped correctly less some elements correctly, such as
+
int a[2][2] = { {1, 2}, {3, 4} };
  
int a[2][2] = { {1}, {3} }
+
the follow is alse correct:
 +
 
 +
int a[2][2] = { {1}, {3} };
  
 
==Notice & Tips==
 
==Notice & Tips==
  
 
===int a[10];printf( “%d”, a );===
 
===int a[10];printf( “%d”, a );===
The code writer's intent is to obtain the value of a, but as mentioned above, the WSC seen as a type of all pointers, printf library function is overloaded, and the second parameter is a pointer to a function only printf (char *, char *), so the compiler to do a wrong choice, a look has become a char *.
+
The programmer’s intent is to get the value of a. But as mentioned above, all the pointer are the same in WSC, WSC see a as a pointer to char. so some errors occur.
 +
 
 +
a correct way as follw:
  
A correct approach is:
 
 
int a[10]; int t = a; printf( “%d”, t );
 
int a[10]; int t = a; printf( “%d”, t );
  
 
===char ch;scanf( “%c”, &ch );===
 
===char ch;scanf( “%c”, &ch );===
For some reason, such an approach to problems, it is recommended to use getchar ();
+
For some reasons, the statement is wrong, it is recommended to use getchar();
  
 
===Enter the uppercase letters===
 
===Enter the uppercase letters===
Press F6 in the input interface switch case.
+
Press F6 in the input interface, than you can enter the uppercase letters
  
 
===FVM will automatically initialize the random number seed===
 
===FVM will automatically initialize the random number seed===
 
+
Don’t require the programmer calling srand();
Does not require the programmer calling the srand ()
 
  
 
===Enter the uppercase letters===
 
===Enter the uppercase letters===
Line 152: Line 147:
 
<pre>#progma FORCE_BREAK</pre>
 
<pre>#progma FORCE_BREAK</pre>
  
Anywhere in the source code to add the above statement, you can hold down the F1 + F2 + F6 to force quit the program execution.
+
add the statement above in the source code, then you can hold down F1 + F2 + F6 to force quit the running program.
 +
 
 +
===Use a large font in the IO interface===
 +
 
 +
<pre># progma BIG_FONT</pre>
 +
 
 +
The above statement can be added anywhere in the source code
 +
 
 +
===FVM program size limit===
 +
FVM procedure 10kb (not source code, is the f files), if your program is outside this range, use exefvm function
 +
 
 +
===FVM execution environment===
 +
 
 +
The default memory (in this case refers to a static area and stack area) 8kb, you can redefine the following statement
 +
 
 +
<pre>#progma RAM_SIZE 10240 // set to 10240kb = 10kb</pre>
 +
 
 +
The size of the heap area depends on the calculator
 +
 
 +
If you need exefvm other programs, it is recommended call program RAM_SIZE set
  
 
==List of library functions==
 
==List of library functions==
Has now completed most of 9860 to support the c standard functions, the next version will be added to the SDK functions.
+
note printf, sprintf, scanf, sscanf are overloading functions, they don’t have variable argument list
 
 
printf, sprintf, scanf, sscanf is the overloaded function. Note that they do not have a variable argument list
 
  
  
Line 586: Line 598:
 
===WSC Functions===
 
===WSC Functions===
 
To use the following functions and definitions, include '''fxlib.h'''<br/>
 
To use the following functions and definitions, include '''fxlib.h'''<br/>
All the graphing function draw to VRAM, programmer should use putdisp() to put VRAM to Display Driver
+
All the graphing function draw to VRAM, programmer should use putdisp() to put VRAM to Display Driver.<br/>
The range fo abscissa(x) of pointers is from 0 to 127
+
The range fo abscissa(x) of pointers is from 0 to 127.<br/>
The range fo ordinate(y) of pointers is from 0 to 63
+
The range fo ordinate(y) of pointers is from 0 to 63.
  
 
====void allclr( void )====
 
====void allclr( void )====
Line 594: Line 606:
  
 
====void areaclr( int x1, int y1, int x2, int y2 )====
 
====void areaclr( int x1, int y1, int x2, int y2 )====
Clear the specified area
+
Clear the specified area<br/>
 
(x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.
 
(x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.
  
 
====void arearev( int x1, int y1, int x2, int y2 )====
 
====void arearev( int x1, int y1, int x2, int y2 )====
Reverses a specified area
+
Reverses a specified area<br/>
 
(x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.
 
(x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.
  
 
====void putdisp( void )====
 
====void putdisp( void )====
Memory output on the screen.
+
Put all data from VRAM to Display Driver.
  
 
====void setpoint( int x, int y, char kind )====
 
====void setpoint( int x, int y, char kind )====
To the point (x,y) set the kind value determines eye color, 1 is black, 0 for white
+
Set or erase a dot at the specified  position.<br/>
 +
If you set point to 1 then the dot is made black. If you set point to 0 then the dot is cleared.
  
 
====int getpoint( int x, ing y )====
 
====int getpoint( int x, ing y )====
Return to point (x,y) wink, 1 is black, 0 is white
+
Checks a dot at the specified position<br/>
 +
If the dot at the specified position is black then this function returns 1. If the dot at the specified position is white then this function returns 0.
  
 
====void drawline( int x1, int y1, int x2, int y2 )====
 
====void drawline( int x1, int y1, int x2, int y2 )====
Draw a (x1,y1) to (x2,y2) black line
+
Draws a line from (x1, y1) to (x2, y2)
  
 
====void clearline( int x1, int y1, int x2, int y2 )====
 
====void clearline( int x1, int y1, int x2, int y2 )====
Draw a (x1,y1) to (x2,y2) white line
+
Draws a white line from (x1, y1) to (x2, y2)
  
 
====void drawcircle( int x, int y, int r )====
 
====void drawcircle( int x, int y, int r )====
In the (x,y) draw a radius r of the hollow round
+
Draws a circle at (x,y)
  
 
====void fillcircle( int x, int y, int r )====
 
====void fillcircle( int x, int y, int r )====
In the (x,y) draw a radius r of the solid round
+
Draws a filled circle at (x,y)
  
 
====void drawbox( int x1, int y1, int x2, int y2 )====
 
====void drawbox( int x1, int y1, int x2, int y2 )====
Draw a hollow rectangle (x1,y1) is a rectangle the upper left corner, (x2,y2) is a rectangular bottom right corner
+
Draws a box, (x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.
  
 
====void fillbox( int x1, int y1, int x2, int y2 )====
 
====void fillbox( int x1, int y1, int x2, int y2 )====
Draw a solid rectangle (x1,y1) is a rectangle the upper left corner, (x2,y2) is a rectangular bottom right corner
+
Draws a filled box, (x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.
  
 
====void locate( int x, int y )====
 
====void locate( int x, int y )====
Set the output cursor position (x,y) where x is 1~21, the scope of y is 1~8
+
Makes settings for the location of the display cursor<br/>
 +
The range of x is from 1 to 8, the range of y is from 1 to 21 here.
  
 
====void print( char *str )====
 
====void print( char *str )====
Output string at the cursor position
+
Displays a character string at the current position of the display cursor
  
 
====void printxy( int x, int y, char *str, int type )====
 
====void printxy( int x, int y, char *str, int type )====
(x,y) is the location of the output string type value equal to 1,anti-color is equal to 0
+
Displays a character string at the specified position.<br/>
 +
If you set the type  to 0 then the character string is displayed in normal color. If you set the type to 1 then the character string is displayed in reverse color.
  
 
====void printmini( int x, int y, char *str, int type )====
 
====void printmini( int x, int y, char *str, int type )====
(x, y) is the position of the output string (small font). You can see the type of the value in the table below:
+
Displays a small font character string at the specified position.
 +
 
 +
The following definitions are declared for type:
  
 
<table width="300" border="1">
 
<table width="300" border="1">
 
   <tr>
 
   <tr>
 
     <td>MINI_OVER</td>
 
     <td>MINI_OVER</td>
     <td>OVER</td>
+
     <td>Overwrite (fill)</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
Line 651: Line 669:
 
   <tr>
 
   <tr>
 
     <td>MINI_REV</td>
 
     <td>MINI_REV</td>
     <td>Anti-Color</td>
+
     <td>Reverse color</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>MINI_REVOR</td>
 
     <td>MINI_REVOR</td>
     <td>Anti-Color + OR</td>
+
     <td>OR in reverse color</td>
 
   </tr>
 
   </tr>
 
</table>
 
</table>
 +
 +
( printmini( 1, 1, “hello”, MINI_OVER ); )
  
 
====void savedisp( char num )====
 
====void savedisp( char num )====
Memory to maintain a system area of a label num of num values ​​can only be SAVEPAGE1, SAVEPAGE2, SAVEPAGE3
+
Saves a screen image in the system area.<br/>
 +
Num is the ID of the save area. It can only be SAVEPAGE1, SAVEPAGE2 or SAVEPAGE3.<br/>
 +
( savedisp( SAVEPAGE1 ); )
  
 
====void restdisp( char num )====
 
====void restdisp( char num )====
Before with savedisp maintain memory re-set to the memory area
+
Restores a  screen image in the system area.<br/>
 +
Num is the ID of the save area. It can only be SAVEPAGE1, SAVEPAGE2 or SAVEPAGE3.<br/>
 +
( restdisp( SAVEPAGE1 ); )
  
 
====void popupwin( int n )====
 
====void popupwin( int n )====
Pop up a window of n lines, n is in the range of 1 to 5
+
Displays a popup window of the specified size of lines. Also, the inside of the popup window is cleared.<br/>
 +
The range of n is from 1 to 5.
  
 
====int openfile( const char *name, int mode )====
 
====int openfile( const char *name, int mode )====
The name is the file name ([[#File_name_format|File Name Format]])
+
opens an existing file<br/>
 
+
name is the file name ([[#File_name_format|File Name Format]])<br/>
mode define what is the open the way, only the following values
+
mode specifies the action to open. The following definitions are declared for open mode.
  
 
<table width="300" border="1">
 
<table width="300" border="1">
 
   <tr>
 
   <tr>
 
     <td>OPEN_R</td>
 
     <td>OPEN_R</td>
     <td>Reading a file</td>
+
     <td>Read</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>OPEN_W</td>
 
     <td>OPEN_W</td>
     <td>Write files</td>
+
     <td>Write</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>OPEN_RW</td>
 
     <td>OPEN_RW</td>
     <td>Read and write files</td>
+
     <td>Read and write</td>
 
   </tr>
 
   </tr>
 
</table>
 
</table>
If the open is successful, will return to a special file handle (handle), it is a greater than or equal to a value of 0
+
If the function succeeds, the return value specifies a file handle. It is greater than or equal to 0.<br/>
 
+
If the function fails, the return value is an error code. It is a negative value.
If the open fails, it will return an error code, it is negative!
 
  
 
====int readfile( int handle, void *buf, int size, int readpos )====
 
====int readfile( int handle, void *buf, int size, int readpos )====
handle is the openfile the return value
+
handle is the return value of openfile()<br/>
readpos began to read the position, if it is equal to -1, then in the last read to the end position
+
size is the bytes to be read from the file.<br/>
Other parameters and return values ​​are similar with fopen
+
readpos is the starting position to read. If the readpos  parameter is -1, this functi on reads data from the position last read ended. If the  readpos  parameter greater than or equal to 0, this function reads data from the position indicated by the  readpos  parameter.<br/>
 +
If the function succeeds, this function returns the number of bytes actually read. It is greater than or equal to 0.<br/>
 +
If the function fails, the return value is an error code. It is a negative value.
  
 
====int writefile( int handle, void *buf, int size )====
 
====int writefile( int handle, void *buf, int size )====
a handle is the openfile the return value, and other similar fwrite
+
handle is the return value of openfile()<br/>
 +
If the function succeeds, this function returns the number of bytes actually read. It is greater than or equal to 0.<br/>
 +
If the function fails, the return value is an error code. It is a negative value.
  
 
====int seekfile( int handle, int pos )====
 
====int seekfile( int handle, int pos )====
handle the openfile the return value pos specifies the location of the read and write files
+
moves the file pointer of an open file<br/>
 
+
If the function succeeds, this function returns the number of bytes that can continuously be read. It is greater than or equal to 0.<br/>
Returns 0 on success, failure to return a negative number
+
If the function fails, the return value is an error code. It is a negative value.
  
 
====int closefile( int handle )====
 
====int closefile( int handle )====
Close the file
+
closes an open file handle
  
 
====int getfree( int type, int *freebytes )====
 
====int getfree( int type, int *freebytes )====
Read the remaining available memory.
+
retrieves the size of  the free space, in bytes,  of the specified device<br/>
 
+
The following definitions are declared for type.
type can only be the following values:
 
  
 
<table width="300" border="1">
 
<table width="300" border="1">
 
   <tr>
 
   <tr>
 
     <td>MAIN_FREE</td>
 
     <td>MAIN_FREE</td>
     <td>the main memory</td>
+
     <td>main memory</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
Line 726: Line 753:
 
   </tr>
 
   </tr>
 
</table>
 
</table>
 +
( getfree( SD_FREE, &size ); )
  
Equipment the remaining value of the space will be stored in freebytes point to an int value
+
freebytes is the pointer to the size of the free space<br/>
 
+
If the function succeeds, this function returns 0.<br/>
Returns 0 on success. In case of failure it return a negative number
+
If the function fails, the return value is an error code. It is a negative value.
  
 
====int getsize( int handle )====
 
====int getsize( int handle )====
handle is the openfile the return value
+
retrieves the size, in bytes, of the specified file.
 
 
Back to the file size
 
  
 
====int createfile( const char *name, int size )====
 
====int createfile( const char *name, int size )====
Create a name for the file, size for size files ( see file name format )
+
Creates a file ([[#File_name_format|View File Name Format]])<br/>
Returns 0 on success, return a negative number on failure.
+
If the function succeeds, the return value is 0.<br/>
 +
If the function fails, the return value is an error code. It is a negative value.
  
 
====int createdir( const char *name )====
 
====int createdir( const char *name )====
Create a directory with a custom name. The directory name is ( ). ([[#File_name_format|View File Name Format]])
+
Creates a directory ([[#File_name_format|View File Name Format]])<br/>
 +
If the function succeeds, the return value is 0.<br/>
 +
If the function fails, the return value is an error code. It is a negative value.
  
Returns 0 on success, failure return a negative number.
+
====int deletefile( const char *name )====
 +
Delete a file ([[#File_name_format|View File Name Format]])<br/>
 +
If the function succeeds, the return value is 0.<br/>
 +
If the function fails, the return value is an error code. It is a negative value.
  
====int deletefile( const char *name )====
+
====int deletedir( const char *name )====
Delete Files ([[#File_name_format|View File Name Format]])
+
Delete a directory ([[#File_name_format|View File Name Format]])<br/>
 +
If the function succeeds, the return value is 0.<br/>
 +
If the function fails, the return value is an error code. It is a negative value.
 +
 
 +
 
 +
<font color="#FF0000">The following three functions need to used in conjunction, for example, see the example\find.c</font>
 +
 
 +
====int findfirst( char *pathname, int *handle, char *foundname, int *fileinfo )====
 +
pathname is to find the path ([[#File_name_format|View File Name Format]]), you can use the wildcard "*", "\\\\fls0\\*.txt", 、"\\\\fls0\\*"
 +
 
 +
File find handle pointed to by handle int (used the findnext and findclose)
  
Returns 0 on success, failure return a negative number.
+
foundname will be saved to find the name of the file
  
====int deletedir( const char *name )====
+
The fileinfo maintain to find the file information, it should be a size 6 int array (int the fileinfo [6]), information storage location in the table below
Delete the directory ([[#File_name_format|Check the File Name Format]])
 
  
Returns 0 on success, failure return a negative number.
+
(under construction)...
  
 
====int getkey( int *keycode )====
 
====int getkey( int *keycode )====
Get a button, the key code is stored in the keycode point to an int value.
+
Performs a key wait and returns a value indicating the pressed key
If the character key is pressed, returns 1. If the control key is pressed, it returns 0.
+
 
If the key queue is empty, it waits until a key is pressed ([[#Keycode|View Keycode]])
+
 +
If there are no characters in the key buffer, this func tion waits until a character arrives and then returns immediately.<br/>
 +
Even if the menu key pressed, this function does not return menu key code. The system processes the menu key event.<br/>
 +
Off event, Auto Power Off event, and contrast adjustment are also handled by this function. If an off or Auto Power Off event occurs the application will not be notified. Once the calculator is turned back on control is returned to the GetKey function.
 +
 
 +
 +
If a character key was pressed, the return value is 1.<br/>
 +
If a control key was pressed, the return value is 0.
 +
 
 +
([[#Keycode|View key code]])
  
 
====int waitkey( void )====
 
====int waitkey( void )====
Get a button, and return the key coding getkey of a simplified
+
Wait for a key, and return the key code.
If the key queue is empty, it waits until a key is pressed ([[#Keycode|View Keycode]])
+
 
 +
It is a simplify of getkey<br/>
 +
([[#Keycode|View key code]])
  
 
====int iskeydown( int keycode )====
 
====int iskeydown( int keycode )====
Detection keycode is pressed, if you press return 1, otherwise returns 0
+
Checks whether the specified key is pressed.<br/>
If the button queue is empty, this function will not wait.
+
The parameter is a key code of the key that you check. <br/>
 +
When you wait events only by this function, the calculator never turns off. Only use this function when you need to wait for key input to continue.<br/>
 +
If the specified key is pressed, the return value is 1.<br/>
 +
If the specified key is not pressed, the return value is 0.<br/>
 +
([[#Keycode|View key code]])
  
 
====void sleep( int millsecond )====
 
====void sleep( int millsecond )====
Delay millsecond ms
+
Suspends the execution of the current thread for a specified interval.
  
 
----
 
----
Line 778: Line 834:
 
File named 2.txt in the directory book in the Storage Mem is "\\\\fls0\\book\\2.txt"<br/>
 
File named 2.txt in the directory book in the Storage Mem is "\\\\fls0\\book\\2.txt"<br/>
 
File named 2.txt in the root directory of the SD card is "\\\\crd0\\2.txt"<br/>
 
File named 2.txt in the root directory of the SD card is "\\\\crd0\\2.txt"<br/>
Directory book in SD card is "\\\\crd0\\book"<br/>
+
Directory book in SD card is \\\\crd0\\book”<br/>
  
Can not handle files in the Main Mem.
+
In this moment you can’t operate the file in Main Mem
  
 
<font color="#FF0000">Note that the filename is case sensitive!</font>
 
<font color="#FF0000">Note that the filename is case sensitive!</font>
  
You can see some files usage exemple in  \doc\exemple\FILE.c
+
\exemple\FILE.c shows how to operate file
  
 
===Keycode===
 
===Keycode===
fxlib.h defined for several commonly used keys more convenient macro
+
The following definitions are declared for some common key in fxlib.h
  
 
<pre>#define KEY_UP        30018
 
<pre>#define KEY_UP        30018
Line 805: Line 861:
 
#define KEY_F3        30011</pre>
 
#define KEY_F3        30011</pre>
  
You can see other key codes in the \doc\example\KEYCODE.c
+
\example\KEYCODE.c shows how to get the key code of other keys
  
 
==Feedback==
 
==Feedback==
Line 813: Line 869:
  
 
==Changelog==
 
==Changelog==
 +
'''* 2012-07-06 version 1.3'''<br/>
 +
- Add overclocking, RTC functions and perform the function of the FVM program<br/>
 +
(Function names are cpuspeed, readrtc, setrtc, findfirst, findnext, findclose, exefvm, getfvmmsg)<br/>
 +
- Add a bit manipulation functions (for the realization of convenience, make it functional form rather than the operator)<br/>
 +
(Name of the function distribution is bitand, bitor, bitxor, bitnot, shiftl, shiftr)<br/>
 +
- Add the support of the hexadecimal constants<br/>
 +
- Add the font of the IO interface support [[#Use_a_large_font_in_the_IO_interface|See tips]]<br/>
 +
- Optimization of the source code of the FVM (thanks to chuxianbing)<br/>
 +
- Fixed some of the errors of the optimization techniques<br/>
 +
- Canceled automatically initialize the random number seed (time function)<br/>
 +
- Other
 +
 
'''* 21-06-2012 version 1.2'''<br/>
 
'''* 21-06-2012 version 1.2'''<br/>
 
- Add a simple pre-processor (now the #include)<br/>
 
- Add a simple pre-processor (now the #include)<br/>

Latest revision as of 19:49, July 7, 2012

Hello !
New version (1.3) will be released in next days, stay tunned.


Contents

Getting Started

Copy the two files inside the bin folder (WSC.g1a, FVM.g1a) to the calculator. In order to edit the source code on calc, you may need to use the EDITv1.51, of course, you can also edit the source code on the computer, it is plain text.

After the installation is complete, the main menu should be as follows:

Wsc-fvm-installed.jpg

Making a hello world

Open the EDIT, the storage Mem (Warning: Do not use the Main Mem) and create a new document.

Wsc-fvm-hello-c.jpg

Enter the text:

void main( )
{
       printf( “Hello World!\n” );
}

(P.S. EDIT could adjust the font size(shift--set up to enter the setting interface), you can see more code on a screen by using the small font, it is recommended to use the small print,the recommended settings below)

Edit-settings.png

The input is completed as follows:

Wsc-fvm-hello-c-code.jpg

To compile the file, exit, enter the WSC, press the F1 (compile) to compile the source code.

Wsc-fvm-compile-file.jpg

If there are no errors, the screen will output “Done”, if there are some errors, you can go back to EDIT to modify. After compiling, enter FVM, press F1(run) to run the bytecode file. the screen will output “hello world”

Wsc-fvm-hello-f.jpgWsc-fvm-run-hello.jpg

WSC Support the C language features

The operator

+ - * / % += -= *= /= < <= > >= == != && || ! != &

note the last ‘&’ is geting address but not bitwise and

Data type

int char float mult-dimensions array pointer(can’t point to array) string constant

Statement

if else while for return break

Notes

C style /*............*/ and C++ style //............

The function

supports recursion, a detailed list of library functions, see library section

Preprocessor

Simple macro replacement (with parameters) a #define, #include (not a real file contains internal use only)

WSC Error reporting

The error reporting of WSC is not perfect,

WSC will displayed the error message when the error is detected, as below:

Wsc-error-reporting.jpg

You can press menu key to exit and go back to modify source code. If you press any other key, the next error message will be displayed.

Note that WSC did not prompt a warning!

Any pointers, arrays are the same in its eyes,

Any assignment between int, char, float will not generate any errors.

A function that return type is not ‘void’ don’t return a value will not generate any errors.

Some differences in the WSC with the standard C

There ary some differences between the WSC and the standard C.

Doesn’t require the function declaration

As long as the function is defined in the file, regardless of location, you can call anywhere.

Only two scopes

The program has only two scopes, global scope and local scope of funcion.

void main()
{
int a;
{
    int a;
}
}

the example program will recerve an error message “Variable ‘a’ redefinition”

int * a, b;

a and b will both be a pointer.(so, it recommended that written int* a, b; but not int *a, b;);

int *p; p++;

The actual value of p will add 4(i.e. sizeof(int) ) in the ANSI C, but WSC will only let p add 1

char s[50] = “asdfjkl”;

This initialization is not yet supported, sample sentence is wrong.

int a[2][2] = { 1, 2, 3, 4 };

This initialization is not yet supported, sample sentence is wrong.

Mult-idimensional array initialization must be grouped properly, such as

int a[2][2] = { {1, 2}, {3, 4} };

the follow is alse correct:

int a[2][2] = { {1}, {3} };

Notice & Tips

int a[10];printf( “%d”, a );

The programmer’s intent is to get the value of a. But as mentioned above, all the pointer are the same in WSC, WSC see a as a pointer to char. so some errors occur.

a correct way as follw:

int a[10]; int t = a; printf( “%d”, t );

char ch;scanf( “%c”, &ch );

For some reasons, the statement is wrong, it is recommended to use getchar();

Enter the uppercase letters

Press F6 in the input interface, than you can enter the uppercase letters

FVM will automatically initialize the random number seed

Don’t require the programmer calling srand();

Enter the uppercase letters

Press F6 in the input interface switch case

Set up multiple strong back

#progma FORCE_BREAK

add the statement above in the source code, then you can hold down F1 + F2 + F6 to force quit the running program.

Use a large font in the IO interface

# progma BIG_FONT

The above statement can be added anywhere in the source code

FVM program size limit

FVM procedure 10kb (not source code, is the f files), if your program is outside this range, use exefvm function

FVM execution environment

The default memory (in this case refers to a static area and stack area) 8kb, you can redefine the following statement

#progma RAM_SIZE 10240 // set to 10240kb = 10kb

The size of the heap area depends on the calculator

If you need exefvm other programs, it is recommended call program RAM_SIZE set

List of library functions

note printf, sprintf, scanf, sscanf are overloading functions, they don’t have variable argument list


stdio.h

int printf( char *format, int val )

int printf( char *format, float val )

int printf( char *format, char* val )

int sprintf( char *buffer, char *format, int val )

int sprintf( char *buffer, char *format, float val )

int sprintf( char *buffer, char *format, char* val )

int scanf( char *format, int *address )

int scanf( char *format, float *address )

int scanf( char *format, char *address )

int sscanf( char *buffer, char *format, int *address )

int sscanf( char *buffer, char *format, int *address )

int sscanf( char *buffer, char *format, float *address )

int getchar( void )

int putchar( int c )

ctype.h

int isalnum( int c )

int isalpha( int c )

int iscntrl( int c )

int isdigit( int c )

int isgraph( int c )

int islower( int c )

int isprint( int c )

int ispunct( int c )

int isspace( int c )

int isupper( int c )

int tolower( int c )

int toupper( int c )

math.h

float acos( float x )

float asin( float x )

float atan( float x )

float atan2( float x, float y )

float cos( float x )

float sin( float x )

float tan( float x )

float cosh( float x )

float sinh( float x )

float tanh( float x )

float log( float x )

float log10( float x )

float modf( float x, float *y )

float pow( float x, float y )

float sqrt( float x )

float ceil( float x )

float fabs( float x )

float floor( float x )

float fmod( float x, float y )

stdlib.h

float atof( char *str )

int atoi( char *str )

int rand( void )

#define RAND_MAX 32767

void srand( int seed )

void *calloc( int nelem, int elsize )

void *malloc( int size )

void *calloc( void *ptr, int size )

void free( void *ptr )

int abs( int x )

string.h

void memcpy( void *p1, void *p2, int n )

char *strcpy( char *s1, char *s2 )

char *strncpy( char *s1, char *s2, int n )

char *strcat( char *s1, char *s2 )

char *strncat( char *s1, char *s2, int n )

int memcmp( void *p1, void *p2, int n )

int strcmp( char *s1, char *s2 )

int strncmp( char *s1, char *s2, int n )

void *memchr( void *p, int c, int n )

char *strchr( char *s, int c )

int strcspn( char *s1, char *s2 )

char *strpbrk( char *s1, char *s2 )

char *strrchr( char *s, int c )

int strspn( char *s1, char *s2 )

char *strstrr( char *s1, char *s2 )

void memset( void *s, int c, int n )

int strlen( char *s )

void *memmove( void *s1, void *s2, int n )

WSC Functions

To use the following functions and definitions, include fxlib.h
All the graphing function draw to VRAM, programmer should use putdisp() to put VRAM to Display Driver.
The range fo abscissa(x) of pointers is from 0 to 127.
The range fo ordinate(y) of pointers is from 0 to 63.

void allclr( void )

Clear the whole area

void areaclr( int x1, int y1, int x2, int y2 )

Clear the specified area
(x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.

void arearev( int x1, int y1, int x2, int y2 )

Reverses a specified area
(x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.

void putdisp( void )

Put all data from VRAM to Display Driver.

void setpoint( int x, int y, char kind )

Set or erase a dot at the specified position.
If you set point to 1 then the dot is made black. If you set point to 0 then the dot is cleared.

int getpoint( int x, ing y )

Checks a dot at the specified position
If the dot at the specified position is black then this function returns 1. If the dot at the specified position is white then this function returns 0.

void drawline( int x1, int y1, int x2, int y2 )

Draws a line from (x1, y1) to (x2, y2)

void clearline( int x1, int y1, int x2, int y2 )

Draws a white line from (x1, y1) to (x2, y2)

void drawcircle( int x, int y, int r )

Draws a circle at (x,y)

void fillcircle( int x, int y, int r )

Draws a filled circle at (x,y)

void drawbox( int x1, int y1, int x2, int y2 )

Draws a box, (x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.

void fillbox( int x1, int y1, int x2, int y2 )

Draws a filled box, (x1, y1) is the upper-left conner of rectangle. (x2, y2) is the lower-right corner of rectangle.

void locate( int x, int y )

Makes settings for the location of the display cursor
The range of x is from 1 to 8, the range of y is from 1 to 21 here.

void print( char *str )

Displays a character string at the current position of the display cursor

void printxy( int x, int y, char *str, int type )

Displays a character string at the specified position.
If you set the type to 0 then the character string is displayed in normal color. If you set the type to 1 then the character string is displayed in reverse color.

void printmini( int x, int y, char *str, int type )

Displays a small font character string at the specified position.

The following definitions are declared for type:

MINI_OVER Overwrite (fill)
MINI_OR OR
MINI_REV Reverse color
MINI_REVOR OR in reverse color

( printmini( 1, 1, “hello”, MINI_OVER ); )

void savedisp( char num )

Saves a screen image in the system area.
Num is the ID of the save area. It can only be SAVEPAGE1, SAVEPAGE2 or SAVEPAGE3.
( savedisp( SAVEPAGE1 ); )

void restdisp( char num )

Restores a screen image in the system area.
Num is the ID of the save area. It can only be SAVEPAGE1, SAVEPAGE2 or SAVEPAGE3.
( restdisp( SAVEPAGE1 ); )

void popupwin( int n )

Displays a popup window of the specified size of lines. Also, the inside of the popup window is cleared.
The range of n is from 1 to 5.

int openfile( const char *name, int mode )

opens an existing file
name is the file name (File Name Format)
mode specifies the action to open. The following definitions are declared for open mode.

OPEN_R Read
OPEN_W Write
OPEN_RW Read and write

If the function succeeds, the return value specifies a file handle. It is greater than or equal to 0.
If the function fails, the return value is an error code. It is a negative value.

int readfile( int handle, void *buf, int size, int readpos )

handle is the return value of openfile()
size is the bytes to be read from the file.
readpos is the starting position to read. If the readpos parameter is -1, this functi on reads data from the position last read ended. If the readpos parameter greater than or equal to 0, this function reads data from the position indicated by the readpos parameter.
If the function succeeds, this function returns the number of bytes actually read. It is greater than or equal to 0.
If the function fails, the return value is an error code. It is a negative value.

int writefile( int handle, void *buf, int size )

handle is the return value of openfile()
If the function succeeds, this function returns the number of bytes actually read. It is greater than or equal to 0.
If the function fails, the return value is an error code. It is a negative value.

int seekfile( int handle, int pos )

moves the file pointer of an open file
If the function succeeds, this function returns the number of bytes that can continuously be read. It is greater than or equal to 0.
If the function fails, the return value is an error code. It is a negative value.

int closefile( int handle )

closes an open file handle

int getfree( int type, int *freebytes )

retrieves the size of the free space, in bytes, of the specified device
The following definitions are declared for type.

MAIN_FREE main memory
STO_FREE storage memory
SD_FREE sd card

( getfree( SD_FREE, &size ); )

freebytes is the pointer to the size of the free space
If the function succeeds, this function returns 0.
If the function fails, the return value is an error code. It is a negative value.

int getsize( int handle )

retrieves the size, in bytes, of the specified file.

int createfile( const char *name, int size )

Creates a file (View File Name Format)
If the function succeeds, the return value is 0.
If the function fails, the return value is an error code. It is a negative value.

int createdir( const char *name )

Creates a directory (View File Name Format)
If the function succeeds, the return value is 0.
If the function fails, the return value is an error code. It is a negative value.

int deletefile( const char *name )

Delete a file (View File Name Format)
If the function succeeds, the return value is 0.
If the function fails, the return value is an error code. It is a negative value.

int deletedir( const char *name )

Delete a directory (View File Name Format)
If the function succeeds, the return value is 0.
If the function fails, the return value is an error code. It is a negative value.


The following three functions need to used in conjunction, for example, see the example\find.c

int findfirst( char *pathname, int *handle, char *foundname, int *fileinfo )

pathname is to find the path (View File Name Format), you can use the wildcard "*", "\\\\fls0\\*.txt", 、"\\\\fls0\\*"

File find handle pointed to by handle int (used the findnext and findclose)

foundname will be saved to find the name of the file

The fileinfo maintain to find the file information, it should be a size 6 int array (int the fileinfo [6]), information storage location in the table below

(under construction)...

int getkey( int *keycode )

Performs a key wait and returns a value indicating the pressed key


If there are no characters in the key buffer, this func tion waits until a character arrives and then returns immediately.
Even if the menu key pressed, this function does not return menu key code. The system processes the menu key event.
Off event, Auto Power Off event, and contrast adjustment are also handled by this function. If an off or Auto Power Off event occurs the application will not be notified. Once the calculator is turned back on control is returned to the GetKey function.


If a character key was pressed, the return value is 1.
If a control key was pressed, the return value is 0.

(View key code)

int waitkey( void )

Wait for a key, and return the key code.

It is a simplify of getkey
(View key code)

int iskeydown( int keycode )

Checks whether the specified key is pressed.
The parameter is a key code of the key that you check.
When you wait events only by this function, the calculator never turns off. Only use this function when you need to wait for key input to continue.
If the specified key is pressed, the return value is 1.
If the specified key is not pressed, the return value is 0.
(View key code)

void sleep( int millsecond )

Suspends the execution of the current thread for a specified interval.


File name format

A few examples to illustrate the format of the file name:
File named 2.txt in the Storage Mem in the root directory is "\\\\fls0\\2.txt"
File named 2.txt in the directory book in the Storage Mem is "\\\\fls0\\book\\2.txt"
File named 2.txt in the root directory of the SD card is "\\\\crd0\\2.txt"
Directory book in SD card is “\\\\crd0\\book”

In this moment you can’t operate the file in Main Mem

Note that the filename is case sensitive!

\exemple\FILE.c shows how to operate file

Keycode

The following definitions are declared for some common key in fxlib.h

#define KEY_UP         30018
#define KEY_DOWN       30023
#define KEY_LEFT       30020
#define KEY_RIGHT      30021
#define KEY_EXIT       30002
#define KEY_AC         30015
#define KEY_DEL        30025
#define KEY_EXE        30024
#define KEY_SHIFT      30006
#define KEY_ALPHA      30007
#define KEY_MENU       30003
#define KEY_OPTN       30008
#define KEY_F1         30009
#define KEY_F2         30010
#define KEY_F3         30011

\example\KEYCODE.c shows how to get the key code of other keys

Feedback

If you found bugs, or have any suggestions, questions, you can post it at WSC and FVM Thread.

Special thanks to yangsc825 (testing and recommendations), helder7 (English documentation), Kenneth C. Louden ("Compiler Construction Principles and Practice").

Changelog

* 2012-07-06 version 1.3
- Add overclocking, RTC functions and perform the function of the FVM program
(Function names are cpuspeed, readrtc, setrtc, findfirst, findnext, findclose, exefvm, getfvmmsg)
- Add a bit manipulation functions (for the realization of convenience, make it functional form rather than the operator)
(Name of the function distribution is bitand, bitor, bitxor, bitnot, shiftl, shiftr)
- Add the support of the hexadecimal constants
- Add the font of the IO interface support See tips
- Optimization of the source code of the FVM (thanks to chuxianbing)
- Fixed some of the errors of the optimization techniques
- Canceled automatically initialize the random number seed (time function)
- Other

* 21-06-2012 version 1.2
- Add a simple pre-processor (now the #include)
- Add file manipulation and plotting functions
- Add to the bond strength rewind functions
- Add an optimized technology, test data, maximum speed increased by 10%
- Fixed some errors in the parameter passing
- Fix array initialization can only occur once error
- Fixed the error of the multidimensional array address
- Others...

* 07-06-2012 version 1.1
- Add most of 9860 to support the standard C function
- Add a full description of document
- Add multi-dimensional array initialization
- Add transfer the character '\ t'
- Improve the stdio, to support multi-line input, uppercase letters
- Improve the error message, more friendly
- Fixed main, not the return 0 mistakes
- Fixed errors in some of the parameters passed
- Fixed a global variable, function, character constants can not be the same name error
- Repair evaluation stack stack stack error
- Other

* 28-05-2012 version 1.0
- Preview Release