What makes a program?
1. Program and Instructions
A program is composed of lines of code, or specifically, instructions in hexadecimal format.
Each line of code consists of five bytes. The first byte is the opcode, while the subsequent 4 bytes are used as four 8-bit operands or parameters labeled P00, P01, P10, and P11.
For example, the 0F opcode signifies program termination regardless of the values of parameters P00 through P11. In some cases, such as instruction 0E for jumping to another line, parameters P10 and P11 are interpreted as merged components of a 16-bit parameter referred as P-1. Similarly, P00 and P01 can be treated as one 16-bit parameter P-0 for certain opcodes. In the code, all elements in a code line are input in hexadecimal.
2. Program Lines
We can freely edit 512 lines of the program, with all line numbers from 0000 to 01FF being valid.
Line jump instructions, either conditional or unconditional, are often used when concepts like IF statements and loops are needed.
The concept of instruction and opcodes used in the JoyKit were inspired from Solaris x86 Assembly Language.
Remark: Not all parameters necessarily participate in the execution of an instruction.
Some specific instructions do not need operands. For instance, end of program instruction 0F, Return instruction 0D, the operands will be ignored.
Sometimes the bits in an OP is interpreted bitwise, or values may not be considered as numbers.
When using delay instruction 02, P-0 and P-1 represent value and unit repectively.
INST_PROG_DELAY | CMD | P-0 | P10 | P11 |
|---|---|---|---|---|
| Delay 1000 ms | 02 | 03E8 | 00 | 00 |
02 03E8 0000
in which hexadecimal value 03E8 of OP-0 equals to 1000 in decimal,while OP-1 0000 determines unit of milliseconds.
Another example is opcode E4 for setting colours of the WS2812B full-colour LED.
E4 00 FF 80 00
Meaning that LED with index 00 is set to orange represented by FF8000.
| R | G | B |
|---|---|---|
FF | 80 | 00 |
The operand values are therefore:
| P00 | P01 | P10 | P11 |
|---|---|---|---|
00 | FF | 80 | 00 |
In the combo key description (such as →+↺️) in this document, the first key (→) is pressed and held, and then the second key (↺) is pressed.