Difference between revisions of "Malical"

From Casio Universal Wiki
Jump to: navigation, search
(2. Variable, the expression)
(Elaborated on extension requirements for filename, clarified what TEST.mcl does)
 
(25 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{MsgBox needsKnowledge}}
 
 
 
__TOC__
 
__TOC__
  
 
==What is Malical?==
 
==What is Malical?==
Malical is a powerful language for [[:Category:Fx9860 Series|casio fx9860 series]] that combines the facility of the [[Casio Basic]] with the speed and robustness of [[C_language|C/Asm]].
+
Malical is a powerful language for the [[:Category:Fx9860 Series|casio fx9860 series]] that combines the simplicity of [[Casio Basic]] with the speed and robustness of [[C_language|C/Asm]].
  
The currently malical version is 2.5, but the developers, [http://www.casio-scene.com/member.php?10224-diameter Diameter] and [http://www.casio-scene.com/member.php?10220-wudy-f89 Wudy.F89] are working in a new update (3.0) with more functions!
+
The current Malical version is 2.5, but the developers, Diameter and Wudy.F89 were working on a new update (3.0) in 2012 with more functions!
  
===Vantages of using Malical===
+
===Advantages of using Malical===
This language is more faster than [[LuaFx]], and you can program OnCalc. Other vantage face to [[LuaFX]] is that the malical program files do not need to be compiled!
+
This language is faster than [[LuaFx]], and you can program directly on the calculator. Another advantage when compared to [[LuaFX]] is that Malical program files do not need to be compiled!
  
Furthermore this language has the speed and robustness of [[C_language|C/Asm]] but is more easy to learn! You can use some tipical SDK functions like print mini, overclock, rtc, ... using this language!
+
Furthermore this language has the speed and robustness of [[C_language|C/Asm]] but is easier to learn! You can use some typical SDK functions like print mini, overclock, rtc, ... using this language!
  
 
==Getting Started==
 
==Getting Started==
You can download the latest malical build [http://www.casio-scene.com/downloads.php?do=file&id=397 here], and you can discuss about this project in [http://www.casio-scene.com/showthread.php?1397-Malical-2-5-Powerful-alternative-to-Casio-Basic this forum topic].
+
You can download the latest Malical build [http://www.casiopeia.net/forum/downloads.php?view=detail&df_id=25 here] <!-- old link [http://www.casio-scene.com/downloads.php?do=file&id=397 here] -->, and you can discuss this project in [http://www.casio-scene.com/showthread.php?1397-Malical-2-5-Powerful-alternative-to-Casio-Basic this forum topic] (dead link until I find a new version).
  
===Install Malical on Calc===
+
===Install Malical on the calculator===
Please connect the calculator to the computer, and drag and drop the the file MALICAL2.G1A, to the FA-124 like the image below:<br/>
+
First, connect the calculator to the computer, make sure the Add-ins icon is selected, and drag and drop the the file MALICAL2.G1A to the FA-124 like the image below:<br/>
 
[[File:Mal-fa124.png]]<br/>
 
[[File:Mal-fa124.png]]<br/>
 
Then copy MALICAL2.G1A to your 9860 calculator.
 
Then copy MALICAL2.G1A to your 9860 calculator.
  
In order to edit Malical Source files(*.mcl) on your fx9860 calc, you need download [http://www.casio-scene.com/downloads.php?do=file&id=119 EDIT.G1A].
+
In order to edit Malical Source files(*.mcl) on your fx9860 calc, you need to download [http://www.casiopeia.net/forum/downloads.php?view=detail&df_id=68 this copy of EDIT.G1A]
Of course, you can edit the source files on the computer, it is plain text.
+
<!-- old dead link [http://www.casio-scene.com/downloads.php?do=file&id=119 EDIT.G1A]. -->
 +
You can also edit the source files on the computer as they are plain text.
  
After the installation is complete, you should see the following interface:<br/>
+
After the installation is complete, you should see the add-ins in the menu:<br/>
 
[[File:Malical-c-menu.png]]
 
[[File:Malical-c-menu.png]]
  
===Making a Hello world!===
+
===Making a Hello world! program===
Please open the [http://www.casio-scene.com/downloads.php?do=file&id=119 EDIT] to create a new document in Storage Mem with the extension .MCL (<span style="color:red">'''Warning'''</span>: You should not create this file in Main Mem).<br/>
+
Open the EDIT application, and create a new document in Storage Memory with the extension .mcl, making sure the extension is lowercase. (<span style="color:red">'''Warning'''</span>: You should not create this file in Main Memory as Malical won't find it. You should also <span style="color:red">not</span> use uppercase for the extension, as Malical won't recognise an uppercase extension in the filename).<br/>
 
[[File:Edit-mcl.png]]<br/>
 
[[File:Edit-mcl.png]]<br/>
And write this code in the file:<br/>
+
Enter the following code into the file:<br/>
 
<pre>
 
<pre>
 
::main
 
::main
Line 39: Line 38:
 
</pre>
 
</pre>
  
 
+
(P.S.: you can reduce the font size of the editor, to allow you to view more code. Set the font size, and optionally turn off wordwrap, as shown below.)
(PS: the edit can adjust the font size, and small print on the screen for you can see more code, it is recommended to use small print, set the font size optn other Word the wrap also recommended the election off, as shown below)
 
  
 
[[File:Edit-settings.png]]
 
[[File:Edit-settings.png]]
  
Input as follows
+
Once your screen looks like this:
  
 
[[File:Test.mcl.png]]
 
[[File:Test.mcl.png]]
  
Exit Edit and open Malical:
+
you can save the file, exit Edit and open Malical:
  
 
[[File:Malical-prog-list-test.png]]
 
[[File:Malical-prog-list-test.png]]
  
Run the program and calc will display the following screen:
+
Run the program, the calculator will display the following screen:
  
 
[[File:Malical-hello-world.png]]
 
[[File:Malical-hello-world.png]]
  
Press the exe to exit!
+
Press the EXE key to exit!
 
   
 
   
First in TEST.MCL we define the main function (each Malical are the main function as a starting point), use the locate function (used for positioning the string output location), the print function (output string) and waitkey function ( of which 30004 exe key code). If you do not waitkey, the program will flash off (can be removed to try). waitkey the role, the program waits until the user presses the 30004 on behalf of the keys.
+
First in TEST.mcl we define a main function (each Malical program uses the main function as a starting point), use the locate function (used to position the string output location on the screen), the print function (output a string) and waitkey function (waits for the keycode, in this case "30004" stands for the EXE key code). If you do not use waitkey, the program will exit immediately <!-- flash off -->( the line containing waitkey can be removed to demonstrate) and the program output will disappear and be replaced by the calculator's main menu. If using waitkey, the program waits until the user presses the EXE key.
  
==2. Variable, the expression==
+
==The "Var" statement==
Malical, '''var''' <'''variable table''' ...> (for example: var [a] [b] [c]) to declare a variable. (Some language) Malical variable type, the only type of the value of the variable. During operation variable can be assigned to any type of value. Variables declared outside the function is a global variable can be shared, global declared within the function can only be used during the function call. The value of the type:'''NIL, STRING, NUMBER, ARRAY'''.
+
Malical uses the keyword '''var''' <'''variable table''' ...> (for example: var [a] [b] [c]) to declare a variable. (Some language) Malical variable type, the only type of the value of the variable. During operation variable can be assigned to any type of value. Variables declared outside the function are global variables that can be accessed by all functions, variables declared within a function can only be used during that function call. Values have the following types:'''NIL, STRING, NUMBER, ARRAY'''.
  
 
===NIL type===
 
===NIL type===
Line 69: Line 67:
 
===STRING type===
 
===STRING type===
 
String.  
 
String.  
Example: "Hello World!", "12332132adasd  
+
Example: "Hello World!", "12332132adasd <br/>
Supported operators: + ==  
+
Supported operators: + ==
  
 
===NUMBER type===
 
===NUMBER type===
Floating-point number  
+
Floating-point number  
Example: 0.1321、3.1415926
+
Example: 0.1321, 3.1415926
Supported operators:+ - * / ^ %(Modulo) == > >= < <= and、or、not
+
Supported operators:+ - * / ^ %(Modulo) == > >= < <= and, or, not
  
 
===ARRAY type===
 
===ARRAY type===
 
Data collection (array), in which each element value can be any type.
 
Data collection (array), in which each element value can be any type.
Array using the subscript ("[" "]") access. {'''Value table'''...} construct.<br/>
+
Arrays use the subscript ("[" "]") to access individual variables. {'''Value table'''...} to construct.<br/>
 
Example:
 
Example:
 
<pre>var [a]
 
<pre>var [a]
Line 87: Line 85:
 
</pre>
 
</pre>
  
Malical in the assignment operator "="  
+
Malical's assignment operator "="  
 
Example: a = 1
 
Example: a = 1
 
a = a+1
 
a = a+1
 
a = a^2
 
a = a^2
a = {} (A is an array, but there is not any element, use the array manipulation functions (such as the push) before such assignment).
+
a = {} (A is an array, but there is not any element, use the array manipulation functions (such as push) before such assignment).
 +
 
 +
==Control structures==
 +
Malical offers two control structures:
 +
===IF statement===
 +
<pre>if expr
 +
    stmt
 +
[else
 +
stmt]
 +
end
 +
</pre>
 +
The return value of expr must be a number (0 for false, non-zero is true). The else part is optional.
 +
 
 +
===WHILE statements===
 +
<pre>while expr
 +
    stmt
 +
end
 +
com
 +
</pre>
 +
 
 +
The requirements of the if statement
 +
 
 +
===Functions===
 +
Defined functions in the following ways in Malical
 +
<pre>:: <Function name> <parameter list>
 +
<Statement>
 +
:: End </pre>
 +
 
 +
Such as:
 +
<pre>:: double [x]
 +
return x*2
 +
:: End</pre>
 +
 
 +
Return which return a value, if not followed by the expression, then do not return any value, but will end the execution of the function.
 +
<br/><br/>
 +
<div style="font-size:17pt;color:red;">Library function is introduced to see in the [[Malical library]].</div>
 +
 
 +
==Examples to explain==
 +
This exemples are available in the Malical.rar package.
 +
 
 +
Many of these examples the procedure can be extended, such as clock can do better Aspect (clockwise bold, with numbers, etc.), functions in a multi-point. The procedure of drawing a line can be expanded to draw a rectangle, circle. The periodic table of elements can be coupled with the Find function. Look forward to more of your work!
 +
 
 +
===Get a key key code (key.mcl)===
 +
Programming to use the key code can use this program for, pay attention to the 1 key. Press to return to a code directly, press shift and then return to the list of code, according to the alpha and then press return 'u' code. s hift-alpha open letter lock and return the letter code.
 +
  Printnum the introduction of detailed function in library.doc
 +
 
 +
===Square root (sqrt.mcl)===
 +
The third line, if val [gets, [1] [1]], can only enter a number, if you use eval [gets [1] [1]] can enter the expression. (Eg, input 229-8, val return 229, the eval returns 221) waitkey the role of the previous example.
 +
 
 +
===Circle (circle.mcl)===
 +
Draw a circle to waitkey.
 +
 
 +
===Character output (Chinese.mcl)===
 +
Shows usage showap (show array picture), showap specific instructions to see the library. Note that the image initialization can not be too long and will be a system error. Push function + multiple arrays can be used to implement the initialization of the big picture
 +
 
 +
===Mouse (mouse.mcl)===
 +
With memory, you can write the program: the beginning of the loop, all rub now painting, the loop ends, see the following detailed line drawing program.
 +
 
 +
===Drawing a line (draw.mcl)===
 +
1,2,3,4,6,7,8,9 a large range to move the cursor up and down a small area over 5 to determine the endpoint of a line segment
 +
L ineset storage four parameters of each straight line. The cycle began painting mouse detection button, rub the whole, with a re-draw the line, the loop ends.
 +
 
 +
===Clock (clock.mcl)===
 +
Achieve a clock. AC key launch, +, - adjust the hour / minute tune.
 +
Half if the getkey, the program is running stuck use the iskeydown here can solve the problem, and can hold the shells, do not click about. Iskeydown general use in the game. Note that this time the menu to return to the main menu is useless to write the if iskeydown menu button code] ....
 +
 
 +
===Overclocking (cpuspeed.mcl)===
 +
The F1 ~ the F6 key codes is continuous, so
 +
<pre>while (key < 30009 or key > 30014)
 +
key = getkey
 +
end
 +
cpuspeed[(key-30008)%5] </pre>
 +
 +
The cpuspeed Results Shao See the end of the library.
 +
Note 2 times overclocking can not be directly four times, first the reset. (Or stuck)
 +
 
 +
===Decomposition quality factor (fact.mcl)===
 +
There is a characteristic of L, ocate before the locate [1] [1], for example the cursor to 1,1, then the print ["256"], the cursor will automatically move to 1,4, which can bring great convenience to the output.
 +
 
 +
===3D mapping (3dfun.mcl)===
 +
Do menu can refer to this program
 +
 
 +
===Of the periodic table (periodic.mcl)===
 +
Show the usage savedisp and rcldisp, program initialization, in order to use savedisp save 5 pages (including 3 main interface, each one of the lanthanide and actinide) are operating in the Memory Lane, so screen has been displayed the initialing ..., then when needed with rcldisp show, so to avoid the repeated drawing speed, reducing programming complexity. The suffix _spe function is the operation of lanthanide and actinide.
 +
 
 +
==Other==
 +
===A comment, statement===
 +
Pound sign "#" followed by the code is a comment, malical interpretation ignores
 +
malical requires line of a statement, but you can write a statement after the semicolon ';' and then took over a statement, which can make the code more compact: If
 +
 
 +
<pre>a = 0;b = 1
 +
if a > 5; a = 2 * a; end</pre>
 +
 
 +
===Set strong retreat===
 +
If you perform the following procedures, then the malical would have been executed can not exit, and can only be reset or pull the battery.
 +
 
 +
<pre>::main
 +
var [i]
 +
i = 0
 +
while i < 5
 +
end
 +
::end</pre>
 +
 
 +
Forgot to play i = i + 1 is the common programming, the so malical options one can set a strong back.
 +
Write one of the set ac_break function in vitro, ac + optn strong back can be pressed when the program runs, the following
 +
 
 +
'''set ac_break'''
 +
<pre>::main
 +
var [i]
 +
i = 0
 +
while i < 5
 +
end
 +
::end
 +
# You can also write here
 +
</pre>
 +
 +
But this option is enabled speed will be slowed down, so you can open in the programming, written after delete command.
 +
 
 +
===Attention===
 +
1. Malical does not allow variables, or Correspondence name and library functions or keywords the same, such as the following statement is illegal
 +
var [if][line][print][return][type]
 +
Sometimes prompt the wrong number of the func parameter may be the name of a library function when the variable name to use.
 +
<br/><br/>
 +
2 malical encountered negative system error, such as 8 is wrong, to be written as 0-8.
 +
<br/><br/>
 +
3.malical source file a statement by not more than 512 characters
 +
<br/><br/>
 +
4. On the memory
 +
There is no memory prog written procedures, such as line 1,1,5,5. Prog implementation of this statement to a point a point of painting line, slow.
 +
Malical execution to line 1,1,5,5, is painted in memory of this line, but did not appear on the screen when you run into the refresh memory function, displayed along the entire memory to the screen , speed faster.
 +
 +
functions are in the malical memory operations, including allclr, savedisp.
 +
Function to refresh the memory function the getkey, waitkey, putdisp.
 +
 +
Such as painting animation, drawing a, 2. Wipe, 3. Draw a 4. Wipe.
 +
Between 1 and 2, 3 and 4 is necessary to refresh the memory, or on the screen can not see anything
 +
<br/><br/>
 +
5. Questions and suggestions
 +
Visit the malical forum topic for give your suggestions. This is the alfa documentation release, under construction!

Latest revision as of 08:42, September 4, 2015

What is Malical?

Malical is a powerful language for the casio fx9860 series that combines the simplicity of Casio Basic with the speed and robustness of C/Asm.

The current Malical version is 2.5, but the developers, Diameter and Wudy.F89 were working on a new update (3.0) in 2012 with more functions!

Advantages of using Malical

This language is faster than LuaFx, and you can program directly on the calculator. Another advantage when compared to LuaFX is that Malical program files do not need to be compiled!

Furthermore this language has the speed and robustness of C/Asm but is easier to learn! You can use some typical SDK functions like print mini, overclock, rtc, ... using this language!

Getting Started

You can download the latest Malical build here , and you can discuss this project in this forum topic (dead link until I find a new version).

Install Malical on the calculator

First, connect the calculator to the computer, make sure the Add-ins icon is selected, and drag and drop the the file MALICAL2.G1A to the FA-124 like the image below:
Mal-fa124.png
Then copy MALICAL2.G1A to your 9860 calculator.

In order to edit Malical Source files(*.mcl) on your fx9860 calc, you need to download this copy of EDIT.G1A You can also edit the source files on the computer as they are plain text.

After the installation is complete, you should see the add-ins in the menu:
Malical-c-menu.png

Making a Hello world! program

Open the EDIT application, and create a new document in Storage Memory with the extension .mcl, making sure the extension is lowercase. (Warning: You should not create this file in Main Memory as Malical won't find it. You should also not use uppercase for the extension, as Malical won't recognise an uppercase extension in the filename).
Edit-mcl.png
Enter the following code into the file:

::main
locate[1][1]
print ["Hello world!"]
waitkey[30004]
::end

(P.S.: you can reduce the font size of the editor, to allow you to view more code. Set the font size, and optionally turn off wordwrap, as shown below.)

Edit-settings.png

Once your screen looks like this:

Test.mcl.png

you can save the file, exit Edit and open Malical:

Malical-prog-list-test.png

Run the program, the calculator will display the following screen:

Malical-hello-world.png

Press the EXE key to exit!

First in TEST.mcl we define a main function (each Malical program uses the main function as a starting point), use the locate function (used to position the string output location on the screen), the print function (output a string) and waitkey function (waits for the keycode, in this case "30004" stands for the EXE key code). If you do not use waitkey, the program will exit immediately ( the line containing waitkey can be removed to demonstrate) and the program output will disappear and be replaced by the calculator's main menu. If using waitkey, the program waits until the user presses the EXE key.

The "Var" statement

Malical uses the keyword var <variable table ...> (for example: var [a] [b] [c]) to declare a variable. (Some language) Malical variable type, the only type of the value of the variable. During operation variable can be assigned to any type of value. Variables declared outside the function are global variables that can be accessed by all functions, variables declared within a function can only be used during that function call. Values have the following types:NIL, STRING, NUMBER, ARRAY.

NIL type

Malical using nil represents a null value nil is the unique value of NIL type

STRING type

String. Example: "Hello World!", "12332132adasd
Supported operators: + ==

NUMBER type

Floating-point number Example: 0.1321, 3.1415926 Supported operators:+ - * / ^ %(Modulo) == > >= < <= and, or, not

ARRAY type

Data collection (array), in which each element value can be any type. Arrays use the subscript ("[" "]") to access individual variables. {Value table...} to construct.
Example:

var [a]
a = {[1][2][{}][ "mailcal"]}
print [a[0]] 
# Output 1.000000

Malical's assignment operator "=" Example: a = 1 a = a+1 a = a^2 a = {} (A is an array, but there is not any element, use the array manipulation functions (such as push) before such assignment).

Control structures

Malical offers two control structures:

IF statement

if expr
    stmt
[else
stmt]
end

The return value of expr must be a number (0 for false, non-zero is true). The else part is optional.

WHILE statements

while expr
    stmt
end
com

The requirements of the if statement

Functions

Defined functions in the following ways in Malical

:: <Function name> <parameter list> 
<Statement> 
:: End 

Such as:

:: double [x] 
return x*2 
:: End

Return which return a value, if not followed by the expression, then do not return any value, but will end the execution of the function.

Library function is introduced to see in the Malical library.

Examples to explain

This exemples are available in the Malical.rar package.

Many of these examples the procedure can be extended, such as clock can do better Aspect (clockwise bold, with numbers, etc.), functions in a multi-point. The procedure of drawing a line can be expanded to draw a rectangle, circle. The periodic table of elements can be coupled with the Find function. Look forward to more of your work!

Get a key key code (key.mcl)

Programming to use the key code can use this program for, pay attention to the 1 key. Press to return to a code directly, press shift and then return to the list of code, according to the alpha and then press return 'u' code. s hift-alpha open letter lock and return the letter code.

  Printnum the introduction of detailed function in library.doc

Square root (sqrt.mcl)

The third line, if val [gets, [1] [1]], can only enter a number, if you use eval [gets [1] [1]] can enter the expression. (Eg, input 229-8, val return 229, the eval returns 221) waitkey the role of the previous example.

Circle (circle.mcl)

Draw a circle to waitkey.

Character output (Chinese.mcl)

Shows usage showap (show array picture), showap specific instructions to see the library. Note that the image initialization can not be too long and will be a system error. Push function + multiple arrays can be used to implement the initialization of the big picture

Mouse (mouse.mcl)

With memory, you can write the program: the beginning of the loop, all rub now painting, the loop ends, see the following detailed line drawing program.

Drawing a line (draw.mcl)

1,2,3,4,6,7,8,9 a large range to move the cursor up and down a small area over 5 to determine the endpoint of a line segment L ineset storage four parameters of each straight line. The cycle began painting mouse detection button, rub the whole, with a re-draw the line, the loop ends.

Clock (clock.mcl)

Achieve a clock. AC key launch, +, - adjust the hour / minute tune. Half if the getkey, the program is running stuck use the iskeydown here can solve the problem, and can hold the shells, do not click about. Iskeydown general use in the game. Note that this time the menu to return to the main menu is useless to write the if iskeydown menu button code] ....

Overclocking (cpuspeed.mcl)

The F1 ~ the F6 key codes is continuous, so

while (key < 30009 or key > 30014)
 key = getkey
 	end
cpuspeed[(key-30008)%5] 

The cpuspeed Results Shao See the end of the library. Note 2 times overclocking can not be directly four times, first the reset. (Or stuck)

Decomposition quality factor (fact.mcl)

There is a characteristic of L, ocate before the locate [1] [1], for example the cursor to 1,1, then the print ["256"], the cursor will automatically move to 1,4, which can bring great convenience to the output.

3D mapping (3dfun.mcl)

Do menu can refer to this program

Of the periodic table (periodic.mcl)

Show the usage savedisp and rcldisp, program initialization, in order to use savedisp save 5 pages (including 3 main interface, each one of the lanthanide and actinide) are operating in the Memory Lane, so screen has been displayed the initialing ..., then when needed with rcldisp show, so to avoid the repeated drawing speed, reducing programming complexity. The suffix _spe function is the operation of lanthanide and actinide.

Other

A comment, statement

Pound sign "#" followed by the code is a comment, malical interpretation ignores malical requires line of a statement, but you can write a statement after the semicolon ';' and then took over a statement, which can make the code more compact: If

a = 0;b = 1
if a > 5; a = 2 * a; end

Set strong retreat

If you perform the following procedures, then the malical would have been executed can not exit, and can only be reset or pull the battery.

::main
var [i]
i = 0
while i < 5 
end
::end

Forgot to play i = i + 1 is the common programming, the so malical options one can set a strong back. Write one of the set ac_break function in vitro, ac + optn strong back can be pressed when the program runs, the following

set ac_break

::main
var [i]
i = 0	
while i < 5 
end
::end
# You can also write here 

But this option is enabled speed will be slowed down, so you can open in the programming, written after delete command.

Attention

1. Malical does not allow variables, or Correspondence name and library functions or keywords the same, such as the following statement is illegal var [if][line][print][return][type] Sometimes prompt the wrong number of the func parameter may be the name of a library function when the variable name to use.

2 malical encountered negative system error, such as 8 is wrong, to be written as 0-8.

3.malical source file a statement by not more than 512 characters

4. On the memory There is no memory prog written procedures, such as line 1,1,5,5. Prog implementation of this statement to a point a point of painting line, slow. Malical execution to line 1,1,5,5, is painted in memory of this line, but did not appear on the screen when you run into the refresh memory function, displayed along the entire memory to the screen , speed faster.

functions are in the malical memory operations, including allclr, savedisp. Function to refresh the memory function the getkey, waitkey, putdisp.

Such as painting animation, drawing a, 2. Wipe, 3. Draw a 4. Wipe. Between 1 and 2, 3 and 4 is necessary to refresh the memory, or on the screen can not see anything

5. Questions and suggestions Visit the malical forum topic for give your suggestions. This is the alfa documentation release, under construction!