corrections before continuing

This commit is contained in:
sejo 2021-07-31 12:09:51 -05:00
parent 30b85ff3eb
commit 31188a1949
1 changed files with 30 additions and 30 deletions

View File

@ -1,4 +1,4 @@
# uxn tutorial: day 3, the keyboard/controller
# uxn tutorial: day 3, conditional jumpts and the keyboard/controller
this is the third section of the <(uxn tutorial)>! ( currently in construction )
@ -8,7 +8,7 @@ we also talk about logic and stack manipulation instructions in uxntal.
# the controller device
the controller device allows us to read inputs from the keyboard in the case of uxnemu, and/or from the controller buttons in the case of uxn ports for handheld consoles.
the controller device in the varvara computer allows us to read inputs from the keyboard and/or from controller buttons.
the definition of its ports would look as follows in a typical uxntal program for the varvara computer:
@ -43,9 +43,9 @@ the key byte stores the ascii code of the keyboard key that is being pressed at
a vector refers to an address in main memory where uxn is assigned to jump to when a specific event happens.
in the case of the controller vector, this specific event would be whenever a key is pressed or released.
in the case of the controller vector, this specific event consists in whenever a key is pressed or released.
for example, the following line of code would assign the absolute address of the label on-controller to the controller vector:
the following line of code would assign the absolute address of the label on-controller to the controller vector:
```
;on-controller .Controller/vector DEO2
@ -110,7 +110,7 @@ BRK
how do we take different actions depending on the key that was pressed?
first of all, we have to let our program know which key was pressed, so let's take a look at some uxntal instructions that will help us with that!
first of all, we have to let our program know which key was pressed. in order to achieve that, let's take a look at some uxntal instructions that will help us!
# comparison and logic instructions
@ -135,7 +135,7 @@ EQU2, NEQ2, GTH2 and LTH2 will work in the same way, but comparing shorts instea
## logic instructions
uxntal has three bitwise logic instructions, that can work as logic operators with the results given by the comparison instructions we discussed above:
uxntal has three bitwise logic instructions, that can work as logic operators that have as operands the results given by the comparison instructions we discussed above:
* AND: perform a bitwise AND with the top two elements of the stack, and push down the result ( a b -- a&b )
* ORA: perform a bitwise OR with the top two elements of the stack, and push down the result ( a b -- a|b )
@ -182,7 +182,7 @@ the following code will push a flag down into the stack if the key byte is eithe
```
.Controller/key DEI ( read key )
LIT '1 EQU ( is it '1'? push flag into the stack )
.Controller/key DEI ( ready key )
.Controller/key DEI ( read key )
LIT 'a EQU ( is it 'a'? push flag into the stack )
ORA ( apply an OR to the flags in the stack, and push the result in the stack )
```
@ -205,10 +205,10 @@ for example, the folowing code will push a flag corresponding to the key being g
```
.Controller/key DEI ( read key )
#20 LTH ( is it less than 20? push flag into the stack )
#01 EOR ( invert flag and push the result into the stack )
#01 EOR ( invert leftmost bit of the flag and push the result into the stack )
```
when the original flag is true, which means that the value is less than 20, the EOR will invert it and make it false: the value is not greater than or equal to 20:
when the original flag is true, which means that the value is less than 20, the EOR will invert it and make it false: the value is NOT greater than or equal to 20:
```
0000 0001 ( true )
@ -217,7 +217,7 @@ EOR 0000 0001 ( mask )
0000 0000 ( false )
```
when the original flag is false, which means that the value is not less than 20, the EOR will invert it and make it true: the value is greater than or equal to 20:
when the original flag is false, which means that the value is NOT less than 20, the EOR will invert it and make it true: the value is greater than or equal to 20:
```
0000 0000 ( false )
@ -239,7 +239,7 @@ let's introduce another set of new instructions to have uxn break its linear flo
in the byte mode, the addresses that these instructions take are one byte long.
these addresses are relative and signed: they indicate how many bytes have to be skipped, either forward (positive) or backwards (negative). the range for these relative addresses is from -128 to 127 inclusive.
these byte-long addresses are relative and signed: they indicate how many bytes have to be skipped in main memory from the current position of the program counter, either forward (positive) or backwards (negative). the range for these relative addresses is from -128 to 127 inclusive.
in short mode, the addresses that these instructions take are absolute (i.e. two-bytes long), but the value that JCN takes in order to decide is still a byte.
@ -257,7 +257,7 @@ in the previous days we talked already about some of them; this is a recap of th
in order to define labels, we use:
* label definition: @label
* sublabel definition: &sublabel
* sublabel definition: &sublabel (this sublabel will correspond to the last previous label)
and finally, to refer to labels within our uxntal code, we have the following cases:
@ -279,22 +279,22 @@ the following on-controller subroutine, illustrates the use of jumps, drawing ou
,&end JMP ( otherwise, jump to the end )
&draw-sprite
( set x,y coordinates )
#0008 .Screen/x DEO2
#0008 .Screen/y DEO2
( set x,y coordinates )
#0008 .Screen/x DEO2
#0008 .Screen/y DEO2
( set sprite address )
;square .Screen/addr DEO2
( set sprite address )
;square .Screen/addr DEO2
( draw sprite in the background )
( using color 1 for the outline )
#21 .Screen/color DEO
( draw sprite in the background )
( using color 1 for the outline )
#21 .Screen/color DEO
&end
BRK
```
note the use of sublabels "inside" on-controller.
note the use of sublabels "inside" (after) on-controller.
also note how the expression ,&sublabel corresponds to the relative address that is needed in order to jump to that location in the code, either using JCN or JMP.
@ -324,21 +324,21 @@ the following code illustrates the use of many conditions: the color of the spri
BRK
&color-1
( draw sprite in the background )
( using color 1 for the outline )
#21 .Screen/color DEO
( draw sprite in the background )
( using color 1 for the outline )
#21 .Screen/color DEO
BRK
&color-2
( draw sprite in the background )
( using color 2 for the outline )
#22 .Screen/color DEO
( draw sprite in the background )
( using color 2 for the outline )
#22 .Screen/color DEO
BRK
&color-3
( draw sprite in the background )
( using color 3 for the outline )
#23 .Screen/color DEO
( draw sprite in the background )
( using color 3 for the outline )
#23 .Screen/color DEO
BRK
BRK
```