1
0
Fork 0

Compare commits

...

1 Commits

Author SHA1 Message Date
Ismael Venegas Castelló ee1c3d587a Replace JMP*, JCN*, JSR* for !foo, ?foo, foo. 2023-03-26 23:02:11 -06:00
14 changed files with 332 additions and 334 deletions

View File

@ -119,9 +119,9 @@ We will use the learn-uxn website by metasyn, that requires a web browser with j
( simple drawing tool )
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ]
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ]
( init )
|0100
@ -144,7 +144,7 @@ BRK
( read mouse state and compare for left click )
.Mouse/state DEI
#01 EQU ,&draw JCN ( jump when mouse is pressed )
#01 EQU ?&draw ( jump when mouse is pressed )
BRK
&draw ( draw sprite: 4-fg, 5-color1 and alpha )

View File

@ -20,7 +20,7 @@ comencemos con el siguiente programa como plantilla. incluye los datos para un s
( hola-fondo.tal )
( dispositivos )
|00 @Sistema [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|00 @Sistema [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Pantalla [ &vector $2 &ancho $2 &alto $2 &auto $1 &pad $1 &x $2 &y $2 &direc $2 &píxel $1 &sprite $1 ]
( macros )
@ -29,11 +29,10 @@ comencemos con el siguiente programa como plantilla. incluye los datos para un s
( programa principal )
|0100
@configuracion
( establecer los colores del sistema )
#2ce9 .Sistema/r DEO2
#01c0 .Sistema/g DEO2
#2ce5 .Sistema/b DEO2
( establecer los colores del sistema )
#2ce9 .Sistema/r DEO2
#01c0 .Sistema/g DEO2
#2ce5 .Sistema/b DEO2
BRK
@tile-fondo 1122 4488 1122 4488
@ -78,7 +77,7 @@ comprobar si x es menor que el límite, saltando si lo es, sería algo así:
```
.Pantalla/x DEI2
#0108 ( el límite )
LTH2 ,&bucle JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle ( saltar si x es menor que el límite )
```
integrando todo ello, podríamos obtener:
@ -91,7 +90,7 @@ integrando todo ello, podríamos obtener:
#03 .Pantalla/sprite DEO ( dibujar sprite de 1bpp con color 3 y 0 )
.Pantalla/x DEI2 #0008 ADD2 DUP2 ( añadir 8 a x )
.Pantalla/x DEO2 ( almacenar la nueva x )
#0108 LTH2 ,&bucle-x JCN ( salta si x es menor que el límite )
#0108 LTH2 ?&bucle-x ( salta si x es menor que el límite )
```
nótese el uso de DUP2 para evitar releer el valor de x.
@ -151,7 +150,7 @@ nuestra subrutina se vería entonces de la siguiente manera:
.Pantalla/x DEI2 #0008 ADD2 DUP2 ( añadir 8 a x )
.Pantalla/x DEO2 ( guardar la nueva x )
STH2kr ( copiar límite de pret en ptra )
LTH2 ,&bucle-x JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle-x ( saltar si x es menor que el límite )
POP2r ( hacer POP en límite de pret )
RTN
```
@ -183,7 +182,7 @@ lo siguiente muestra nuestro programa en contexto, llenando completamente la pri
;tile-fondo .Pantalla/direc DEO2 ( establecer la dirección del tile )
#0000 ( x inicial )
.Pantalla/ancho DEI2 ( obtener el ancho de la pantalla )
;dibuja-tiles-en-fila JSR2
dibuja-tiles-en-fila
BRK
@dibuja-tiles-en-fila ( x^ ancho^ -- )
@ -197,7 +196,7 @@ BRK
.Pantalla/x DEI2 #0008 ADD2 DUP2 ( añadir 8 a x )
.Pantalla/x DEO2 ( guarda la nueva x )
STH2kr ( copiar límite de pret en ptra )
LTH2 ,&bucle-x JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle-x ( saltar si x es menor que el límite )
POP2r ( sacar el límite de pret )
RTN
@ -233,12 +232,12 @@ el siguiente código se basa en el bucle anterior de x, pero ahora dibuja una fi
( preparar y dibujar fila )
#0000 ( x inicial )
.Pantalla/ancho DEI2 ( obtener el ancho de la pantalla )
;dibuja-tiles-en-fila JSR2
dibuja-tiles-en-fila
.Pantalla/y DEI2 #0008 ADD2 DUP2 ( añade 8 a y )
.Pantalla/y DEO2 ( guardar la nueva y )
#0108 ( poner límite en la parte superior de la pila )
LTH2 ,&bucle-y JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle-y ( saltar si x es menor que el límite )
```
## versión abstracta
@ -322,7 +321,7 @@ en teoría, la primera parte de nuestra subrutina podría verse como:
( recuperar el ancho )
STH2r ( ptra: x^ ancho^ / pret: limite-y^ )
;dibuja-tiles-en-fila JSR2
dibuja-tiles-en-fila
```
el problema es que dentro del bucle, ambas instrucciones STH2r recuperan y consumen los valores de `x` y ancho de la pila de retorno. por tanto, en la siguiente iteración no podríamos volver a utilizarlos, ya que se perderían.
@ -350,7 +349,7 @@ entonces podemos recuperar el ancho y utilizarlo:
```
STH2kr ( ptra: x^ ancho^ / pret: limite-y^ x^ ancho^ )
;dibuja-tiles-en-fila JSR2 ( ptra: / pret: limite-y^ x^ ancho^ )
dibuja-tiles-en-fila ( ptra: / pret: limite-y^ x^ ancho^ )
```
¿qué sigue? añadir 8 a `y` y comprobar si es menor que el límite. la primera parte va sin problemas:
@ -377,7 +376,7 @@ ROT2r ( ptra: y^ limite-y^ / pret: limite-y^ ancho^ x^ )
ahora podemos hacer la comparación y saltar:
```
LTH2 ,&bucle-y JCN ( salta si x es menor que el límite )
LTH2 ?&bucle-y ( salta si x es menor que el límite )
```
después debemos limpiar la pila de retorno:
@ -414,7 +413,7 @@ después de todo esto, nuestra subrutina tendría el siguiente aspecto:
( recuperar el ancho )
SWP2r ( ptra: x^ / pret: limite-y^ x^ ancho^ )
STH2kr ( ptra: x^ ancho^ / pret: limite-y^ x^ ancho^ )
;dibuja-tiles-en-fila JSR2 ( ptra: / pret: limite-y^ x^ ancho^ )
dibuja-tiles-en-fila ( ptra: / pret: limite-y^ x^ ancho^ )
.Pantalla/y DEI2 #0008 ADD2 DUP2 ( añadir 8 a y )
.Pantalla/y DEO2 ( almacenar la nueva y )
@ -427,7 +426,7 @@ después de todo esto, nuestra subrutina tendría el siguiente aspecto:
SWP2r ( ptra: y^ limite-y^ / pret: x^ limite-y^ ancho^ )
ROT2r ( ptra: y^ limite-y^ / pret: limite-y^ ancho^ x^ )
LTH2 ,&bucle-y JCN ( salta si x es menor que el límite )
LTH2 ?&bucle-y ( salta si x es menor que el límite )
POP2r POP2r POP2r ( limpiar la pila de retorno )
RTN
@ -439,7 +438,7 @@ podemos entonces llamarlo de la siguiente manera para obtener un cuadrado de 256
#0008 #0008 ( `x` y `y` )
#0100 #0100 ( ancho y alto )
;tile-fondo
;dibuja-tiles JSR2
dibuja-tiles
```
=> ./img/screenshot_uxn-background-square.png captura de pantalla que muestra un gran cuadrado en la pantalla varvara compuesto por líneas diagonales
@ -498,7 +497,7 @@ nuestro bucle ahora tendría el siguiente aspecto:
,&x LDR2
&ancho LDR2
( dibujar fila )
;dibuja-tiles-en-fila JSR2
dibuja-tiles-en-fila
.Pantalla/y DEI2 #0008 ADD2 DUP2 ( añade 8 a y )
.Pantalla/y DEO2 ( almacenar la nueva y )
@ -506,7 +505,7 @@ nuestro bucle ahora tendría el siguiente aspecto:
( recuperar el límite vertical )
,&limite-y LDR2
LTH2 ,&bucle-y JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle-y ( saltar si x es menor que el límite )
```
¡y eso es todo!
@ -540,7 +539,7 @@ la subrutina completa tendría el siguiente aspecto:
,&x LDR2
,&ancho LDR2
( dibujar fila )
;dibuja-tiles-en-fila JSR2
dibuja-tiles-en-fila
.Pantalla/y DEI2 #0008 ADD2 DUP2 ( añade 8 a y )
.Pantalla/y DEO2 ( almacenar la nueva y )
@ -548,7 +547,7 @@ la subrutina completa tendría el siguiente aspecto:
( recuperar el límite vertical )
,&limite-y LDR2
LTH2 ,&bucle-y JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle-y ( saltar si x es menor que el límite )
RTN
( variables )
@ -577,15 +576,15 @@ por ejemplo:
.Pantalla/ancho DEI2
.Pantalla/alto DEI2 #0010 SUB2
;tile-fondo
;dibuja-tiles JSR2
dibuja-tiles
RTN
```
que podemos llamar simplemente desde nuestra subrutina de iniciación:
```
;dibuja-fondo JSR2
;dibuja-fondo JSR2
dibuja-fondo
dibuja-fondo
```
=> ./img/screenshot_uxn-background-full.png captura de pantalla mostrando la pantalla varvara cubierta de líneas diagonales.

View File

@ -230,7 +230,7 @@ estos son los puertos en formato de lista:
* sprite (1 byte)
hablaremos sobre el corto vector en el {tutorial de uxn día 4} y sobre el byte auto en el {tutorial de uxn día 6}.
## primer plano y plano de fondo
el dispositivo de pantalla tiene dos capas superpuestas del mismo tamaño, el primer plano y el plano de fondo.

View File

@ -325,9 +325,9 @@ la siguiente subrutina en-controlador ilustra el uso de los saltos, dibujando nu
LIT "1 EQU ( ¿es '1'? )
( salta a dibuja-sprite si es el caso )
,&dibuja-sprite JCN
?&dibuja-sprite
,&fin JMP ( si no, salta al final )
!&fin ( si no, salta al final )
&dibuja-sprite
( fijar coordenadas x,y )
@ -365,13 +365,13 @@ el siguiente código ilustra el uso de muchas condiciones: el color del sprite c
;cuadrado .Pantalla/direc DEO2
.Controlador/tecla DEI LIT "1 EQU ( ¿es la tecla '1'? )
,&color-1 JCN ( salta al color-1 si es el caso )
?&color-1 ( salta al color-1 si es el caso )
.Controlador/tecla DEI LIT "2 EQU ( ¿es la tecla '2'? )
,&color-2 JCN ( salta al color-2 si es el caso )
?&color-2 ( salta al color-2 si es el caso )
.Controlador/tecla DEI LIT "3 EQU ( ¿es la tecla '3'? )
,&color-3 JCN ( salta al color-3 si es el caso )
?&color-3 ( salta al color-3 si es el caso )
( en cualquier otro caso, terminar )
BRK
@ -537,13 +537,13 @@ podríamos reescribirlo usando varios DUPs y POPs:
.Controlador/tecla DEI ( leer tecla )
DUP LIT "1 EQU ( ¿es la tecla '1'? )
,&color-1 JCN ( salta al color-1 si es el caso )
?&color-1 ( salta al color-1 si es el caso )
DUP LIT "2 EQU ( ¿es la tecla '2'? )
,&color-2 JCN ( salta al color-2 si es el caso )
?&color-2 ( salta al color-2 si es el caso )
DUP LIT "3 EQU ( ¿es la tecla '3'? )
,&color-3 JCN ( salta al color-3 si es el caso )
?&color-3 ( salta al color-3 si es el caso )
( en cualquier otro caso, termina )
POP
@ -676,11 +676,11 @@ BRK
@en-controlador ( -> )
.Controlador/botón DEI DUP ( leer y duplicar el byte del botón )
#01 AND ( aislar el bit 0, correspondiente a Ctrl )
,&relleno JCN ( si el bit no es 0, saltar al relleno; si es 0, continuar )
?&relleno ( si el bit no es 0, saltar al relleno; si es 0, continuar )
&contorno
#01 .Pantalla/sprite DEO ( dibujar contorno )
,&comprobar-flechas JMP ( continuar con comprobar-flechas )
!&comprobar-flechas ( continuar con comprobar-flechas )
&relleno
#04 .Pantalla/sprite DEO ( dibujar relleno )
@ -688,13 +688,13 @@ BRK
&comprobar-flechas
( usar el byte del botón de la pila )
DUP #10 AND ( aislar el bit 4, correspondiente a Arriba )
,&arriba JCN ( saltar si no es 0 )
?&arriba ( saltar si no es 0 )
DUP #20 AND ( aísla el bit 5, correspondiente a Abajo )
&abajo JCN ( salta si no es 0 )
?&abajo ( salta si no es 0 )
DUP #40 AND ( aislar el bit 6, correspondiente a Izquierda )
,&izquierda JCN ( salta si no es 0 )
?&izquierda ( salta si no es 0 )
DUP #80 AND ( aísla el bit 7, correspondiente a Derecha )
&derecha JCN ( salta si no es 0 )
?&derecha ( salta si no es 0 )
POP BRK

View File

@ -532,19 +532,19 @@ BRK
&verificar-flechas
.Controlador/botón DEI
#40 AND ( aislar el bit 6, correspondiente a la izquierda )
,&izquierda JCN ( saltar si no es 0 )
?&izquierda ( saltar si no es 0 )
.Controlador/botón DEI
#80 AND ( aislar el bit 7, correspondiente a la derecha )
,&derecha JCN ( saltar si no es 0 )
?&derecha ( saltar si no es 0 )
( si no se ha pulsado ninguna de esas teclas, dibujar sin cambios )
,&dibujar JMP
!&dibujar
&izquierda
( disminuir sprite/pos-x )
.sprite/pos-x LDZ2 #0001 SUB2 .sprite/pos-x STZ2
,&dibujar JMP
!&dibujar
&derecha
( incrementar sprite/pos-x )
@ -586,7 +586,7 @@ podríamos comprobar primero si ha alcanzado una cantidad específica, como el a
.sprite/pos-x LDZ2 ( carga x )
.Pantalla/ancho DEI2 #0008 SUB2 ( obtener el ancho de la pantalla menos 8 )
EQU2 ( ¿es x igual a la anchura de la pantalla - 8? )
&continuar JCN
?&continuar
&incremento
( incrementar sprite/pos-x )

View File

@ -111,7 +111,7 @@ BRK
.Ratón/y DEI2 .Pantalla/y DEO2
( salta si se presiona algún botón )
.Ratón/estado DEI ,&presionado JCN
.Ratón/estado DEI ?&presionado
( dibujar sprite usando el color 2 y 0 en el fondo )
#02 .Pantalla/sprite DEO
@ -281,7 +281,7 @@ con lo que ya sabemos, y dependiendo de la posición de dibuja-puntero con respe
```
@en-ratón ( -> )
,dibuja-puntero JMP
!dibuja-puntero
&retorno
( algo más aquí )
@ -292,7 +292,7 @@ o un salto absoluto:
```
@en-ratón ( -> )
;dibuja-puntero JMP2
!dibuja-puntero
&retorno
( algo más aquí )
@ -304,7 +304,7 @@ el detalle esta en que si queremos que ocurra algo más después de dibujar el p
al final de nuestra subrutina dibuja-puntero, necesitaríamos "saltar hacia atrás" así:
```
;en-ratón/retornar JMP2
!en-ratón/retornar
```
funcionaría, pero no es la mejor forma.
@ -325,7 +325,7 @@ por ejemplo, nuestros saltos podrían reescribirse de la siguiente manera. en el
```
@en-ratón ( -> )
,dibuja-puntero JSR
dibuja-puntero
( algo más aquí )
BRK
@ -337,7 +337,7 @@ y en el caso de un salto absoluto:
```
@en-ratón ( -> )
;dibuja-puntero JSR2
dibuja-puntero
( algo más aquí )
BRK
@ -440,7 +440,7 @@ este es el programa hola-puntero.tal, pero utilizando dibuja-puntero como subrut
BRK
@en-ratón ( -> )
;dibuja-puntero JSR2 ( o ,dibuja-puntero JSR )
dibuja-puntero ( o ,dibuja-puntero JSR )
( algo más )
BRK
@ -551,7 +551,7 @@ un signo de intercalación (^) después de un nombre de valor indica que corresp
( duplicar longitud y conteo, comparar y saltar )
DUP2 ( pt: longitud conteo / pr: )
NEQ ( pt: longitud conteo bandera / pr: )
,&bucle JCN ( pt: longitud conteo / pr: )
?&bucle ( pt: longitud conteo / pr: )
POP2 ( pt: / pr: )
RTN
```
@ -564,7 +564,7 @@ para llamar a la subrutina, podrías hacer algo como lo siguiente:
#0008 ( empujar x inicial )
.Pantalla/altura DEI2 MITAD2 ( empujar y )
#ff ( empujar longitud de la línea )
;dibuja-linea-horizontal JSR2 ( llamar subrutina )
dibuja-linea-horizontal ( llamar subrutina )
```
### notas
@ -685,7 +685,7 @@ por ejemplo, en nuestra subrutina dibuja-línea-horizontal, teníamos el siguien
( duplicar longitud y el conteo, comparar y saltar )
DUP2 ( pt: longitud conteo longitud conteo / pr: )
NEQ ( pt: longitud conteo bandera / pr: )
,&bucle JCN ( pt: longitud conteo / pr: )
?&bucle ( pt: longitud conteo / pr: )
```
verás que aquí, como en el caso DIVk anterior, el DUP2 está ahí solo para asegurarse de que la longitud y el recuento no se pierden al realizar NEQ.
@ -695,7 +695,7 @@ por lo tanto, podríamos reemplazar DUP2 NEQ con NEQk:
```
( duplicar la longitud y el conteo, comparar y saltar )
NEQk ( pt: longitud conteo bandera / pr: )
,&bucle JCN ( pt: longitud conteo / pr: )
?&bucle ( pt: longitud conteo / pr: )
```
## el modo mantener y la pila de retorno

View File

@ -89,7 +89,7 @@ comprobar si x es menor que el límite, saltando si lo es, sería algo así:
```
.Pantalla/x DEI2 ( obtener x )
.Pantalla/ancho DEI2 ( obtener el límite )
LTH2 ,&bucle JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle ( saltar si x es menor que el límite )
```
integrando todo ello, podríamos obtener:
@ -104,7 +104,7 @@ integrando todo ello, podríamos obtener:
DUP2 ( duplicar la nueva x )
.Pantalla/x DEO2 ( almacenar nueva x )
.Pantalla/ancho DEI2 ( obtener el límite )
LTH2 ,&bucle-x JCN ( saltar si x es menor que el límite )
LTH2 ?&bucle-x ( saltar si x es menor que el límite )
```
nótese el uso de DUP2 para evitar releer el valor de x.
@ -140,7 +140,7 @@ podemos compararlos en modo mantener para conservar esos valores en la pila y ha
```
GTH2k ( ¿es ese ancho mayor que x?, o también, ¿es x menor que el ancho? )
,&bucle-x JCN ( salta si x es menor que el límite )
?&bucle-x ( salta si x es menor que el límite )
```
cuando terminamos el bucle, tenemos que hacer POP a ambos valores.
@ -158,7 +158,7 @@ usando esta estrategia, obtendríamos el siguiente bucle:
#0008 ADD2 ( incrementar x )
GTH2k ( ¿es ese ancho mayor que x? o también, ¿es x menor que el ancho? )
,&bucle-x JCN ( salta si x es menor que el límite )
?&bucle-x ( salta si x es menor que el límite )
POP2 POP2 ( eliminar x y el límite )
```
@ -200,7 +200,7 @@ lo siguiente muestra nuestro programa en contexto, llenando completamente la pri
#03 .Pantalla/sprite DEO ( dibujar sprite de 1bpp con color 3 y 0 )
#0008 ADD2 ( incrementar x )
GTH2k ( ¿es ese ancho mayor que x? o también, ¿es x menor que el ancho? )
,&bucle-x JCN ( salta si x es menor que el límite )
?&bucle-x ( salta si x es menor que el límite )
POP2 POP2 ( eliminar x y el límite )
BRK
@ -242,7 +242,7 @@ MARGEN-PARED ( establecer `y` inicial )
#0008 ADD2 ( incrementa `y` )
GTH2k ( ¿es ese límite mayor que `y`? o también, ¿es `y` menor que el límite? )
,&bucle-y JCN ( salta si `y` es menor que el límite )
?&bucle-y ( salta si `y` es menor que el límite )
POP2 POP2 ( eliminar `y` y el límite )
```
@ -268,12 +268,12 @@ MARGEN-PARED ( establecer `y` inicial )
#0008 ADD2 ( incrementar x )
GTH2k ( ¿es ese ancho mayor que x? o también, ¿es x menor que el ancho? )
,&bucle-x JCN ( salta si x es menor que el límite )
?&bucle-x ( salta si x es menor que el límite )
POP2 POP2 ( eliminar x y el límite )
#0008 ADD2 ( incrementar y )
GTH2k ( ¿es ese límite mayor que y? o también, ¿es `y` menor que el límite? )
,&bucle-y JCN ( salta si `y` es menor que el límite )
?&bucle-y ( salta si `y` es menor que el límite )
POP2 POP2 ( eliminar `y` y el límite )
```
@ -302,12 +302,12 @@ ahora podemos envolver estos bucles anidados dentro de una subrutina:
#0008 ADD2 ( incrementar x )
GTH2k ( ¿es ese ancho mayor que x? o también, ¿es x menor que el ancho? )
,&bucle-x JCN ( salta si x es menor que el límite )
?&bucle-x ( salta si x es menor que el límite )
POP2 POP2 ( eliminar x y el límite )
#0008 ADD2 ( incrementar y )
GTH2k ( ¿es ese límite mayor que `y`? o también, ¿es `y` menor que el límite? )
,&bucle-y JCN ( salta si `y` es menor que el límite )
?&bucle-y ( salta si `y` es menor que el límite )
POP2 POP2 ( eliminar `y` y el límite )
RTN
```
@ -315,7 +315,7 @@ RTN
que podemos llamar simplemente desde nuestra subrutina de iniciación:
```
;dibuja-fondo JSR2
dibuja-fondo
```
=> ./img/screenshot_uxn-background-full.png captura de pantalla que muestra la pantalla varvara cubierta de líneas diagonales excepto por un margen en la parte superior e inferior.
@ -525,7 +525,7 @@ notemos el uso del modo mantener al final: DEOk enviará el color al puerto de s
ahora que la subrutina está lista podemos llamarla, por ejemplo, de la siguiente manera y conseguir que se dibuje nuestra pala:
```
#0008 #0008 #c5 ;dibuja-pala JSR2
#0008 #0008 #c5 dibuja-pala
```
=> ./img/screenshot_uxn-pong-paddle.png captura de pantalla de la pala dibujada sobre el fondo
@ -596,8 +596,8 @@ para dibujar cada pala, podemos hacer el siguiente procedimiento dentro de nuest
```
( dibujar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA dibuja-pala
```
### el programa hasta ahora
@ -642,7 +642,7 @@ omitiendo la definición de las subrutinas dibuja-fondo y dibuja-pala y como for
;en-cuadro .Pantalla/vector DEO2
( dibujar fondo )
;dibuja-fondo JSR2
dibuja-fondo
( iniciar palas )
MARGEN .izquierda/x STZ2
@ -659,8 +659,8 @@ BRK
@en-cuadro ( -> )
( dibujar pala )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA dibuja-pala
BRK
```
@ -678,16 +678,16 @@ ya tenemos el proceso para dibujar nuestras palas:
```
( dibujar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA dibuja-pala
```
para borrarlos, podemos hacer lo mismo pero usando un byte del sprite correspondiente a borrar el tile en el primer plano:
```
( borrar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-BORRAR ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-BORRAR ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-BORRAR dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-BORRAR dibuja-pala
```
donde COLOR-BORRAR en este caso sería:
@ -718,31 +718,31 @@ todo esto puede ir dentro de su propia subrutina para facilitar la lectura:
( pala izquierda: botones arriba y abajo )
.Controlador/botón DEI
DUP #10 AND ( comprobar bit para arriba )
,&izquierda-arriba JCN
?&izquierda-arriba
DUP #20 AND ( comprobar bit para abajo )
&izquierda-abajo JCN
?&izquierda-abajo
&derecha JMP ( salta si no se ha presionado ninguno de los dos )
!&derecha ( salta si no se ha presionado ninguno de los dos )
&izquierda-arriba
.izquierda/y LDZ2 VEL-PALA SUB2 .izquierda/y STZ2
,&derecha JMP
!&derecha
&izquierda-abajo
.izquierda/y LDZ2 VEL-PALA ADD2 .izquierda/y STZ2
,&derecha JMP
!&derecha
&derecha
( pala derecha: botones ctrl/A y alt/B )
DUP #01 AND ( comprobar bit para A )
,&derecha-arriba JCN
?&derecha-arriba
DUP #02 AND ( comprobar bit para B )
&derecha-abajo JCN
?&derecha-abajo
&fin JMP ( salta si no se ha presionado ninguno de los dos )
!&fin ( salta si no se ha presionado ninguno de los dos )
&derecha-arriba
.derecha/y LDZ2 VEL-PALA SUB2 .derecha/y STZ2
,&fin JMP
!&fin
&derecha-abajo
.derecha/y LDZ2 VEL-PALA ADD2 .derecha/y STZ2
@ -760,15 +760,15 @@ integrando todo, nuestra subrutina en-cuadro se vería como lo siguiente.
```
@en-cuadro ( -> )
( borrar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-BORRAR ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-BORRAR ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-BORRAR dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-BORRAR dibuja-pala
( actualizar palas )
;actualiza-palas JSR2
actualiza-palas
( dibujar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA dibuja-pala
BRK
```
@ -864,7 +864,7 @@ para dibujarla solo tendríamos que hacer:
```
( dibujar pelota )
COLOR-PELOTA ;dibuja-pelota JSR2
COLOR-PELOTA dibuja-pelota
```
=> ./img/screenshot_uxn-pong-paddles-and-ball.png captura de la pantalla mostrando las palas en su posición horizontal pero a diferentes alturas y la pelota completamente centrada en la pantalla.
@ -882,13 +882,13 @@ se vería algo como lo siguiente y podría situarse a lo largo de los procedimie
```
( dentro de en-cuadro )
( borrar pelota )
COLOR-BORRAR ;dibuja-pelota JSR2
COLOR-BORRAR dibuja-pelota
( actualizar pelota )
;actualiza-pelota JSR2
actualiza-pelota
( dibujar pelota )
COLOR-PELOTA ;dibuja-pelota JSR2
COLOR-PELOTA dibuja-pelota
```
ahora vamos a discutir cómo construir esa subrutina actualiza-pelota :)
@ -1084,12 +1084,12 @@ considerando que hay un margen en la parte superior, podemos hacer esta comproba
.pelota/y LDZ2
MARGEN-PARED
LTH2 ( ¿es pelota-y menos que el margen? )
,&establecer-vel-pos JCN
,&verif-pared-inf JMP
?&establecer-vel-pos
!&verif-pared-inf
&establecer-vel-pos
PELOTA-VEL-POS .pelota/vel-y STZ2
&continuar JMP
!&continuar
&verif-pared-inf
```
@ -1108,8 +1108,8 @@ la coordenada `y` de la pared inferior sería la altura de la pantalla, menos el
.Pantalla/alto DEI2
MARGEN-PARED SUB2 ( altura - margen )
GTH2 ( ¿es la pelota-y mayor que la pared-y? )
,&establecer-vel-neg JCN
&continuar JMP
?&establecer-vel-neg
!&continuar
&establecer-vel-neg
PELOTA-VEL-NEG .pelota/vel-y STZ2
@ -1139,20 +1139,20 @@ nuestra subrutina actualiza-pelota tiene el siguiente aspecto hasta el momento:
.pelota/y LDZ2
MARGEN-PARED
LTH2 ( ¿es la pelota-y menor que el margen? )
,&establecer-vel-pos JCN
,&verif-pared-inf JMP
?&establecer-vel-pos
!&verif-pared-inf
&establecer-vel-pos
PELOTA-VEL-POS .pelota/vel-y STZ2
&continuar JMP
!&continuar
&verif-pared-inf
.pelota/y LDZ2 TAM-PELOTA ADD2 ( y + tamaño de la pelota )
.Pantalla/alto DEI2
MARGEN-PARED SUB2 ( altura - margen )
GTH2 ( ¿es la pelota-y mayor que la pared-y? )
,&establecer-vel-neg JCN
&continuar JMP
?&establecer-vel-neg
!&continuar
&establecer-vel-neg
PELOTA-VEL-NEG .pelota/vel-y STZ2
@ -1178,8 +1178,8 @@ para ello, podemos comprobar si x es menor que la suma del margen y el ancho de
.pelota/x LDZ2
MARGEN ANCHO-PALA ADD2
LTH2 ( ¿es la pelota-x menor que el margen + el ancho-de-pala? )
,&x-en-izquierda JCN
,&verif-pala-der JMP
?&x-en-izquierda
!&verif-pala-der
&x-en-izquierda
( ... )
@ -1204,7 +1204,7 @@ si esas dos condiciones se cumplen, entonces podemos establecer una velocidad po
.izquierda/y LDZ2 ALTO-PALA ADD2 LTH2 ( segunda bandera )
STHr ( recupera la primera bandera )
AND ( hacer AND en ambas banderas )
&rebote-izquierda JCN
?&rebote-izquierda
```
donde rebote-izquierda sería:
@ -1212,7 +1212,7 @@ donde rebote-izquierda sería:
```
&rebote-izquierda
PELOTA-VEL-POS .pelota/vel-x STZ2
,&fin JMP
!&fin
```
¿y qué pasa si no se cumplen las dos condiciones a la vez?
@ -1229,20 +1229,20 @@ todo el código x-en-izquierda terminaría pareciendo:
.izquierda/y LDZ2 ALTO-PALA ADD2 LTH2 ( segunda bandera )
STHr ( recupera la primera bandera )
AND ( hacer AND en ambas banderas )
,&rebote-izquierda JCN
?&rebote-izquierda
.pelota/x LDZ2 #0000 NEQ2 ( ¿ha llegado a la pared? )
,&fin JCN
?&fin
&reset-izquierda
( aquí puedes aumentar la puntuación de
la pala derecha )
;reset JSR2
,&fin JMP
reset
!&fin
&rebote-izquierda
PELOTA-VEL-POS .pelota/vel-x STZ2
,&fin JMP
!&fin
&verif-pala-der
```
@ -1267,8 +1267,8 @@ para la pala derecha haremos lo mismo que arriba, pero cambiando las comparacion
.Pantalla/ancho DEI2 MARGEN SUB2 ANCHO-PALA SUB2
( ¿es la coordenada derecha de la pelota mayor que el ancho de la pantalla - margen - ancho-pala? )
GTH2
,&x-en-derecha JCN
&fin JMP
?&x-en-derecha
!&fin
&x-en-derecha
.pelota/y LDZ2 DUP2
@ -1276,21 +1276,21 @@ para la pala derecha haremos lo mismo que arriba, pero cambiando las comparacion
.derecha/y LDZ2 ALTO-PALA ADD2 LTH2 ( segunda bandera )
STHr ( recupera la primera bandera )
AND ( hacer AND en ambas banderas )
,&rebote-derecha JCN
?&rebote-derecha
.pelota/x LDZ2
.Pantalla/ancho DEI2 NEQ2 ( ¿ha llegado a la pared? )
,&fin JCN
?&fin
&reset-derecha
( aquí puedes aumentar la puntuación
de la pala izquierda )
;reset JSR2
,&fin JMP
reset
!&fin
&rebote-derecha
PELOTA-VEL-NEG .pelota/vel-x STZ2
,&fin JMP
!&fin
&fin
RTN
@ -1369,7 +1369,7 @@ aquí está todo el código que hemos escrito hoy:
;en-cuadro .Pantalla/vector DEO2
( dibujar fondo )
;dibuja-fondo JSR2
dibuja-fondo
( iniciar palas )
MARGEN .izquierda/x STZ2
@ -1383,7 +1383,7 @@ aquí está todo el código que hemos escrito hoy:
.derecha/y STZ2
( iniciar pelota )
;reset JSR2
reset
( iniciar velocidad de la pelota )
PELOTA-VEL-NEG .pelota/vel-x STZ2
@ -1397,24 +1397,24 @@ BRK
```
@en-cuadro ( -> )
( borrar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-BORRAR ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-BORRAR ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-BORRAR dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-BORRAR dibuja-pala
( borrar pelota )
COLOR-BORRAR ;dibuja-pelota JSR2
COLOR-BORRAR dibuja-pelota
( actualizar palas )
;actualiza-palas JSR2
actualiza-palas
( actualizar pelota )
;actualiza-pelota JSR2
actualiza-pelota
( dibujar palas )
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA ;dibuja-pala JSR2
.izquierda/x LDZ2 .izquierda/y LDZ2 COLOR-PALA dibuja-pala
.derecha/x LDZ2 .derecha/y LDZ2 COLOR-PALA dibuja-pala
( dibujar pelota )
COLOR-PELOTA ;dibuja-pelota JSR2
COLOR-PELOTA dibuja-pelota
BRK
```
@ -1451,19 +1451,19 @@ RTN
.pelota/y LDZ2
MARGEN-PARED
LTH2 ( ¿es la pelota-y menor que el margen? )
,&establecer-vel-pos JCN
,&verif-pared-inf JMP
?&establecer-vel-pos
!&verif-pared-inf
&establecer-vel-pos
PELOTA-VEL-POS .pelota/vel-y STZ2
,&continuar JMP
!&continuar
&verif-pared-inf
.pelota/y LDZ2 TAM-PELOTA ADD2 ( y + tamaño-pelota )
.Pantalla/alto DEI2 MARGEN-PARED SUB2 ( altura - margen )
GTH2
,&establecer-vel-neg JCN
,&continuar JMP
?&establecer-vel-neg
!&continuar
&establecer-vel-neg
PELOTA-VEL-NEG .pelota/vel-y STZ2
@ -1474,8 +1474,8 @@ RTN
.pelota/x LDZ2
MARGEN ANCHO-PALA ADD2
LTH2 ( ¿es la pelota-x menor que el margen + ancho-pala? )
,&x-en-izquierda JCN
,&verif-pala-der JMP
?&x-en-izquierda
!&verif-pala-der
&x-en-izquierda
.pelota/y LDZ2 DUP2
@ -1483,27 +1483,27 @@ RTN
.izquierda/y LDZ2 ALTO-PALA ADD2 LTH2 ( segunda bandera )
STHr ( recuperar la primera bandera )
AND ( hacer AND en ambas banderas )
,&rebote-izquierda JCN
?&rebote-izquierda
.pelota/x LDZ2 #0000 NEQ2 ( ¿ha llegado a la pared? )
,&fin JCN
?&fin
&reset-izquierda
( aquí puedes añadir un punto a la pala derecha )
;reset JSR2
,&fin JMP
reset
!&fin
&rebote-izquierda
PELOTA-VEL-POS .pelota/vel-x STZ2
,&fin JMP
!&fin
&verif-pala-der
.pelota/x LDZ2 TAM-PELOTA ADD2
.Pantalla/ancho DEI2 MARGEN SUB2 ANCHO-PALA SUB2
( ¿es pelota-x + tamaño-pelota mayor que la anchura de la pantalla - margen - ancho-pala? )
GTH2
,&x-en-derecha JCN
,&fin JMP
?&x-en-derecha
!&fin
&x-en-derecha
.pelota/y LDZ2 DUP2
@ -1511,20 +1511,20 @@ RTN
.derecha/y LDZ2 ALTO-PALA ADD2 LTH2 ( segunda bandera )
STHr ( recuperar la primera bandera )
AND ( hacer AND en ambas banderas )
,&rebote-derecha JCN
?&rebote-derecha
.pelota/x LDZ2
.Pantalla/ancho DEI2 NEQ2 ( ¿ha llegado a la pared? )
,&fin JCN
?&fin
&reset-derecha
( aquí puedes añadir un punto a la pala izquierda )
;reset JSR2
,&fin JMP
reset
!&fin
&rebote-derecha
PELOTA-VEL-NEG .pelota/vel-x STZ2
,&fin JMP
!&fin
&fin
RTN
@ -1562,31 +1562,31 @@ RTN
( pala izquierda: botones arriba 10 y abajo 20 )
.Controlador/botón DEI
DUP #10 AND ( comprobar bit para arriba )
,&izquierda-arriba JCN
?&izquierda-arriba
DUP #20 AND ( comprobar bit para abajo )
,&izquierda-abajo JCN
?&izquierda-abajo
,&derecha JMP ( salta si no se ha presionado ninguno de los dos )
!&derecha ( salta si no se ha presionado ninguno de los dos )
&izquierda-arriba
.izquierda/y LDZ2 VEL-PALA SUB2 .izquierda/y STZ2
,&derecha JMP
!&derecha
&izquierda-abajo
.izquierda/y LDZ2 VEL-PALA ADD2 .izquierda/y STZ2
,&derecha JMP
!&derecha
&derecha
( pala derecha: botones ctrl/A 01 y alt/B 02 )
DUP #01 AND ( comprobar bit para A )
,&derecha-arriba JCN
?&derecha-arriba
DUP #02 AND ( comprobar bit para B )
,&derecha-abajo JCN
?&derecha-abajo
,&fin JMP ( salta si no se ha presionado ninguno de los dos )
!&fin ( salta si no se ha presionado ninguno de los dos )
&derecha-arriba
.derecha/y LDZ2 VEL-PALA SUB2 .derecha/y STZ2
,&fin JMP
!&fin
&derecha-abajo
.derecha/y LDZ2 VEL-PALA ADD2 .derecha/y STZ2
@ -1637,12 +1637,12 @@ RTN
#03 .Pantalla/sprite DEO ( dibujar sprite de 1bpp con color 3 y 0 )
#0008 ADD2 ( incrementar x )
GTH2k ( ¿es la anchura mayor que x? o también, ¿es x menor que la anchura? )
,&bucle-x JCN ( salta si x es menor que el límite )
?&bucle-x ( salta si x es menor que el límite )
POP2 POP2 ( eliminar `x` y el límite )
#0008 ADD2 ( incrementar y )
GTH2k ( ¿es el límite mayor que `y`? o también, ¿es `y` menor que el límite? )
,&bucle-y JCN ( salta si `y` es menor que el límite )
?&bucle-y ( salta si `y` es menor que el límite )
POP2 POP2 ( eliminar `y` y el límite )
RTN
```

View File

@ -58,7 +58,7 @@ podemos usar una estructura como la siguiente, donde el nombre del archivo y la
;archivo/datos .Archivo0/leer DEO2
( comprobar el byte éxito y saltar según corresponda )
Archivo0/éxito DEI2 #0000 EQU2 ,&fallo JCN
Archivo0/éxito DEI2 #0000 EQU2 ?&fallo
&éxito
LIT "Y .Consola/escribe DEO
@ -104,7 +104,7 @@ el siguiente programa escribirá "hola" y una nueva línea (0a) en un archivo ll
;archivo/datos .Archivo0/escribir DEO2
( leer y evaluar el byte éxito )
.Archivo0/éxito DEI2 #0006 NEQ2 ,&fallo JCN
.Archivo0/éxito DEI2 #0006 NEQ2 ?&fallo
&éxito
LIT "Y .Consola/escribe DEO
@ -146,7 +146,7 @@ podríamos adaptar nuestra subrutina anterior para cargar el archivo de temas y
;tema/datos .Archivo0/leer DEO2
( comprobar el byte éxito y saltar según corresponda )
.Archivo0/éxito DEI2 #0006 NEQ2 ,&fallo JCN
.Archivo0/éxito DEI2 #0006 NEQ2 ?&fallo
&éxito
( establecer los colores del sistema a partir de los datos leídos )
@ -184,7 +184,7 @@ y para hacer la operación contraria, podemos leer los colores del sistema en nu
;tema/datos .Archivo0/escribir DEO2
( comprobar el byte de éxito y saltar según corresponda )
.Archivo0/éxito DEI2 #0006 NEQ2 ,&fallo JCN
.Archivo0/éxito DEI2 #0006 NEQ2 ?&fallo
&éxito
( ¿informar el éxito? )

View File

@ -20,8 +20,8 @@ let's start with the following program as a template. it includes the data for a
( hello-background.tal )
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
( macros )
%RTN { JMP2r }
@ -29,11 +29,10 @@ let's start with the following program as a template. it includes the data for a
( main program )
|0100
@setup
( set system colors )
#2ce9 .System/r DEO2
#01c0 .System/g DEO2
#2ce5 .System/b DEO2
( set system colors )
#2ce9 .System/r DEO2
#01c0 .System/g DEO2
#2ce5 .System/b DEO2
BRK
@tile-background 1122 4488 1122 4488
@ -78,7 +77,7 @@ checking if x is less than the limit, jumping if it is, would be something like:
```
.Screen/x DEI2
#0108 ( the limit )
LTH2 ,&loop JCN ( jump if x is less than the limit )
LTH2 ?&loop ( jump if x is less than the limit )
```
integrating all of it, we would be able to get:
@ -91,7 +90,7 @@ integrating all of it, we would be able to get:
#03 .Screen/sprite DEO ( draw 1bpp sprite with color 3 and 0 )
.Screen/x DEI2 #0008 ADD2 DUP2 ( add 8 to x )
.Screen/x DEO2 ( store new x )
#0108 LTH2 ,&loop-x JCN ( jump if x is less than the limit )
#0108 LTH2 ?&loop-x ( jump if x is less than the limit )
```
note the use of DUP2 in order to avoid re-reading the value of x.
@ -151,7 +150,7 @@ our subroutine would then look as follows:
.Screen/x DEI2 #0008 ADD2 DUP2 ( add 8 to x )
.Screen/x DEO2 ( store new x )
STH2kr ( copy limit from rs into ws )
LTH2 ,&loop-x JCN ( jump if x is less than the limit )
LTH2 ?&loop-x ( jump if x is less than the limit )
POP2r ( pop limit from rs )
RTN
```
@ -183,7 +182,7 @@ the following shows our program in context, completely filling the first row of
;tile-background .Screen/addr DEO2 ( set tile address )
#0000 ( initial x )
.Screen/width DEI2 ( get screen width )
;draw-tiles-in-a-row JSR2
draw-tiles-in-a-row
BRK
@draw-tiles-in-a-row ( x^ width^ -- )
@ -197,7 +196,7 @@ BRK
.Screen/x DEI2 #0008 ADD2 DUP2 ( add 8 to x )
.Screen/x DEO2 ( store new x )
STH2kr ( copy limit from rs into ws )
LTH2 ,&loop-x JCN ( jump if x is less than the limit )
LTH2 ?&loop-x ( jump if x is less than the limit )
POP2r ( pop limit from rs )
RTN
@ -233,12 +232,12 @@ the following code is based on the previous x loop, but it now draws a row in a
( prepare and draw row )
#0000 ( initial x )
.Screen/width DEI2 ( get screen width )
;draw-tiles-in-a-row JSR2
draw-tiles-in-a-row
.Screen/y DEI2 #0008 ADD2 DUP2 ( add 8 to y )
.Screen/y DEO2 ( store new y )
#0108 ( put limit in top of the stack )
LTH2 ,&loop-y JCN ( jump if x is less than the limit )
LTH2 ?&loop-y ( jump if x is less than the limit )
```
## abstract version
@ -322,7 +321,7 @@ in theory, the first part of our subroutine could look like:
( retrieve width )
STH2r ( ws: x^ width^ / rs: limit-y^ )
;draw-tiles-in-a-row JSR2
draw-tiles-in-a-row
```
the problem is that inside the loop, both STH2r instructions retrieve and consume the values for x and width from the return stack. therefore, in the next iteration we wouldn't be able to use them again, as they would be lost.
@ -350,7 +349,7 @@ then we can then retrieve the width and use it:
```
STH2kr ( ws: x^ width^ / rs: limit-y^ x^ width^ )
;draw-tiles-in-a-row JSR2 ( ws: / rs: limit-y^ x^ width^ )
draw-tiles-in-a-row ( ws: / rs: limit-y^ x^ width^ )
```
what's next? add 8 to y, and check if it's less than the limit. the first part goes without problems:
@ -377,7 +376,7 @@ ROT2r ( ws: y^ limit-y^ / rs: limit-y^ width^ x^ )
now we can do the comparison and jump:
```
LTH2 ,&loop-y JCN ( jump if x is less than the limit )
LTH2 ?&loop-y ( jump if x is less than the limit )
```
afterwards we should clear the return stack:
@ -414,7 +413,7 @@ after all this, our subroutine would look like the following:
( retrieve width )
SWP2r ( ws: x^ / rs: limit-y^ x^ width^ )
STH2kr ( ws: x^ width^ / rs: limit-y^ x^ width^ )
;draw-tiles-in-a-row JSR2 ( ws: / rs: limit-y^ x^ width^ )
draw-tiles-in-a-row ( ws: / rs: limit-y^ x^ width^ )
.Screen/y DEI2 #0008 ADD2 DUP2 ( add 8 to y )
.Screen/y DEO2 ( store new y )
@ -427,7 +426,7 @@ after all this, our subroutine would look like the following:
SWP2r ( ws: y^ limit-y^ / rs: x^ limit-y^ width^ )
ROT2r ( ws: y^ limit-y^ / rs: limit-y^ width^ x^ )
LTH2 ,&loop-y JCN ( jump if x is less than the limit )
LTH2 ?&loop-y ( jump if x is less than the limit )
POP2r POP2r POP2r ( clear return stack )
RTN
@ -439,7 +438,7 @@ we can then call it like the following in order to get a 256x256 square filled w
#0008 #0008 ( x and y )
#0100 #0100 ( width and height )
;tile-background
;draw-tiles JSR2
draw-tiles
```
=> ./img/screenshot_uxn-background-square.png screenshot showing a big square in the varvara screen composed of diagonal lines
@ -498,7 +497,7 @@ our loop now would look as follows:
,&x LDR2
,&width LDR2
( draw row )
;draw-tiles-in-a-row JSR2
draw-tiles-in-a-row
.Screen/y DEI2 #0008 ADD2 DUP2 ( add 8 to y )
.Screen/y DEO2 ( store new y )
@ -506,7 +505,7 @@ our loop now would look as follows:
( retrieve vertical limit )
,&limit-y LDR2
LTH2 ,&loop-y JCN ( jump if x is less than the limit )
LTH2 ?&loop-y ( jump if x is less than the limit )
```
and that's it!
@ -540,7 +539,7 @@ the complete subroutine would look like the following:
,&x LDR2
,&width LDR2
( draw row )
;draw-tiles-in-a-row JSR2
draw-tiles-in-a-row
.Screen/y DEI2 #0008 ADD2 DUP2 ( add 8 to y )
.Screen/y DEO2 ( store new y )
@ -548,7 +547,7 @@ the complete subroutine would look like the following:
( retrieve vertical limit )
,&limit-y LDR2
LTH2 ,&loop-y JCN ( jump if x is less than the limit )
LTH2 ?&loop-y ( jump if x is less than the limit )
RTN
( variables )
@ -577,14 +576,14 @@ for example:
.Screen/width DEI2
.Screen/height DEI2 #0010 SUB2
;tile-background
;draw-tiles JSR2
draw-tiles
RTN
```
that we can simply call from our initialization subroutine:
```
;draw-background JSR2
draw-background
```
=> ./img/screenshot_uxn-background-full.png screenshot showing the varvara screen covered in diagonal lines.

View File

@ -325,9 +325,9 @@ the following on-controller subroutine illustrates the use of jumps, drawing our
LIT "1 EQU ( is it '1'? )
( jump to draw-sprite if that's the case )
,&draw-sprite JCN
?&draw-sprite
,&end JMP ( otherwise, jump to the end )
!&end ( otherwise, jump to the end )
&draw-sprite
( set x,y coordinates )
@ -365,13 +365,13 @@ the following code illustrates the use of many conditions: the color of the spri
;square .Screen/addr DEO2
.Controller/key DEI LIT "1 EQU ( is the key '1'? )
,&color-1 JCN ( jump to color-1 if that's the case )
?&color-1 ( jump to color-1 if that's the case )
.Controller/key DEI LIT "2 EQU ( is the key '2'? )
,&color-2 JCN ( jump to color-2 if that's the case )
?&color-2 ( jump to color-2 if that's the case )
.Controller/key DEI LIT "3 EQU ( is the key '3'? )
,&color-3 JCN ( jump to color-3 if that's the case )
?&color-3 ( jump to color-3 if that's the case )
( in any other case, finish )
BRK
@ -537,13 +537,13 @@ we could rewrite it using several DUPs and POPs:
.Controller/key DEI ( read key )
DUP LIT "1 EQU ( is the key '1'? )
,&color-1 JCN ( jump to color-1 if that's the case )
?&color-1 ( jump to color-1 if that's the case )
DUP LIT "2 EQU ( is the key '2'? )
,&color-2 JCN ( jump to color-2 if that's the case )
?&color-2 ( jump to color-2 if that's the case )
DUP LIT "3 EQU ( is the key '3'? )
,&color-3 JCN ( jump to color-3 if that's the case )
?&color-3 ( jump to color-3 if that's the case )
( in any other case, finish )
POP
@ -676,11 +676,11 @@ BRK
@on-controller ( -> )
.Controller/button DEI DUP ( read and duplicate button byte )
#01 AND ( isolate bit 0, corresponding to Ctrl )
,&fill JCN ( if the bit is not 0, jump to fill, otherwise continue )
?&fill ( if the bit is not 0, jump to fill, otherwise continue )
&outline
#01 .Screen/sprite DEO ( draw outline )
,&check-arrows JMP ( continue to check-arrows )
!&check-arrows ( continue to check-arrows )
&fill
#04 .Screen/sprite DEO ( draw filled )
@ -688,13 +688,13 @@ BRK
&check-arrows
( use button byte from the stack )
DUP #10 AND ( isolate bit 4, corresponding to Up )
,&up JCN ( jump if not 0 )
?&up ( jump if not 0 )
DUP #20 AND ( isolate bit 5, corresponding to Down )
,&down JCN ( jump if not 0 )
?&down ( jump if not 0 )
DUP #40 AND ( isolate bit 6, corresponding to Left )
,&left JCN ( jump if not 0 )
?&left ( jump if not 0 )
DUP #80 AND ( isolate bit 7, corresponding to Right )
,&right JCN ( jump if not 0 )
?&right ( jump if not 0 )
POP BRK

View File

@ -532,19 +532,19 @@ BRK
&check-arrows
.Controller/button DEI
#40 AND ( isolate bit 6, corresponding to Left )
,&left JCN ( jump if not 0 )
?&left ( jump if not 0 )
.Controller/button DEI
#80 AND ( isolate bit 7, corresponding to Right )
,&right JCN ( jump if not 0 )
?&right ( jump if not 0 )
( if none of those keys were pressed, draw without changes )
,&draw JMP
!&draw
&left
( decrement sprite/pos-x )
.sprite/pos-x LDZ2 #0001 SUB2 .sprite/pos-x STZ2
,&draw JMP
?&draw
&right
( increment sprite/pos-x )
@ -586,7 +586,7 @@ we could check first if it has reached a specific amount, like the width of the
.sprite/pos-x LDZ2 ( load x )
.Screen/width DEI2 #0008 SUB2 ( get screen width minus 8 )
EQU2 ( is x equal to screen width - 8 ? )
,&continue JCN
?&continue
&increment
( increment sprite/pos-x )

View File

@ -111,7 +111,7 @@ BRK
.Mouse/y DEI2 .Screen/y DEO2
( jump if any button is pressed )
.Mouse/state DEI ,&pressed JCN
.Mouse/state DEI ?&pressed
( draw sprite using color 2 and 0 in background )
#02 .Screen/sprite DEO
@ -281,7 +281,7 @@ with what we know already, and depending on the position of draw-pointer with re
```
@on-mouse ( -> )
,draw-pointer JMP
!draw-pointer
&return
( something else here )
@ -292,7 +292,7 @@ or an absolute jump:
```
@on-mouse ( -> )
;draw-pointer JMP2
!draw-pointer
&return
( something else here )
@ -304,7 +304,7 @@ the thing is, if we want something else to happen after drawing the pointer insi
at the end of our draw-pointer subroutine, we'd need to "jump back" like this:
```
;on-mouse/return JMP2
!on-mouse/return
```
it would work, but it's not the best approach.
@ -337,7 +337,7 @@ and in the case of an absolute jump:
```
@on-mouse ( -> )
;draw-pointer JSR2
draw-pointer
( something else here )
BRK
@ -440,7 +440,7 @@ this is the hello-pointer.tal program, but using draw-pointer as a subroutine th
BRK
@on-mouse ( -> )
;draw-pointer JSR2 ( or ,draw-pointer JSR )
draw-pointer ( or ,draw-pointer JSR )
( something else )
BRK
@ -551,7 +551,7 @@ a caret (^) after a value name indicates that it corresponds to a short.
( duplicate length and count, compare, and jump )
DUP2 ( ws: length count length count / rs: )
NEQ ( ws: length count flag / rs: )
,&loop JCN ( ws: length count / rs: )
?&loop ( ws: length count / rs: )
POP2 ( ws: / rs: )
RTN
```
@ -564,7 +564,7 @@ in order to call the subroutine, you could do something like the following:
#0008 ( push initial x )
.Screen/height DEI2 HALF2 ( push y )
#ff ( push length of line )
;draw-horizontal-line JSR2 ( call subroutine )
draw-horizontal-line ( call subroutine )
```
### notes
@ -685,7 +685,7 @@ for example, in our draw-horizontal-line subroutine, we had the following set of
( duplicate length and count, compare, and jump )
DUP2 ( ws: length count length count / rs: )
NEQ ( ws: length count flag / rs: )
,&loop JCN ( ws: length count / rs: )
?&loop ( ws: length count / rs: )
```
you'll see that here, like in the DIVk case above, the DUP2 is there only to make sure that the length and count are not lost when performing NEQ.
@ -695,7 +695,7 @@ we could therefore replace DUP2 NEQ with NEQk:
```
( duplicate length and count, compare, and jump )
NEQk ( ws: length count flag / rs: )
,&loop JCN ( ws: length count / rs: )
?&loop ( ws: length count / rs: )
```
## keep mode and the return stack

View File

@ -89,7 +89,7 @@ checking if x is less than the limit, jumping if it is, would be something like:
```
.Screen/x DEI2 ( get x )
.Screen/width DEI2 ( get the limit )
LTH2 ,&loop JCN ( jump if x is less than the limit )
LTH2 ?&loop ( jump if x is less than the limit )
```
integrating all of it, we would be able to get:
@ -104,7 +104,7 @@ integrating all of it, we would be able to get:
DUP2 ( duplicate new x )
.Screen/x DEO2 ( store new x )
.Screen/width DEI2 ( get the limit )
LTH2 ,&loop-x JCN ( jump if x is less than the limit )
LTH2 ?&loop-x ( jump if x is less than the limit )
```
note the use of DUP2 in order to avoid re-reading the value of x.
@ -140,7 +140,7 @@ we can compare them in keep mode to mantain those values in the stack, and do ou
```
GTH2k ( is the width greater than x? aka is x less than the width ? )
,&loop-x JCN ( jump if x is less than the limit )
?&loop-x ( jump if x is less than the limit )
```
when we are done with the loop, we have to POP both values.
@ -158,7 +158,7 @@ using this strategy, we would get the following loop:
#0008 ADD2 ( increment x )
GTH2k ( is the width greater than x? aka is x less than the width ? )
,&loop-x JCN ( jump if x is less than the limit )
?&loop-x ( jump if x is less than the limit )
POP2 POP2 ( remove x and limit )
```
@ -200,7 +200,7 @@ the following shows our program in context, completely filling the first row of
#03 .Screen/sprite DEO ( draw 1bpp sprite with color 3 and 0 )
#0008 ADD2 ( increment x )
GTH2k ( is the width greater than x? aka is x less than the width ? )
,&loop-x JCN ( jump if x is less than the limit )
?&loop-x ( jump if x is less than the limit )
POP2 POP2 ( remove x and limit )
BRK
@ -242,7 +242,7 @@ WALL-MARGIN ( set initial y )
#0008 ADD2 ( increment y )
GTH2k ( is the limit greater than y? aka is y less than the limit ? )
,&loop-y JCN ( jump if y is less than the limit )
?&loop-y ( jump if y is less than the limit )
POP2 POP2 ( remove y and limit )
```
@ -268,12 +268,12 @@ WALL-MARGIN ( set initial y )
#0008 ADD2 ( increment x )
GTH2k ( is the width greater than x? aka is x less than the width ? )
,&loop-x JCN ( jump if x is less than the limit )
?&loop-x ( jump if x is less than the limit )
POP2 POP2 ( remove x and limit )
#0008 ADD2 ( increment y )
GTH2k ( is the limit greater than y? aka is y less than the limit ? )
,&loop-y JCN ( jump if y is less than the limit )
?&loop-y ( jump if y is less than the limit )
POP2 POP2 ( remove y and limit )
```
@ -302,12 +302,12 @@ now we can just wrap these nested loops inside a subroutine:
#0008 ADD2 ( increment x )
GTH2k ( is the width greater than x? aka is x less than the width ? )
,&loop-x JCN ( jump if x is less than the limit )
?&loop-x ( jump if x is less than the limit )
POP2 POP2 ( remove x and limit )
#0008 ADD2 ( increment y )
GTH2k ( is the limit greater than y? aka is y less than the limit ? )
,&loop-y JCN ( jump if y is less than the limit )
?&loop-y ( jump if y is less than the limit )
POP2 POP2 ( remove y and limit )
RTN
```
@ -315,7 +315,7 @@ RTN
that we can simply call from our initialization subroutine:
```
;draw-background JSR2
draw-background
```
=> ./img/screenshot_uxn-background-full.png screenshot showing the varvara screen covered in diagonal lines except for a margin at the top and bottom.
@ -524,7 +524,7 @@ note the use of the keep mode at the end: DEOk will output the color to the scre
now that the subroutine is ready, we can call it in e.g. the following way and get our paddle drawn:
```
#0008 #0008 #c5 ;draw-paddle JSR2
#0008 #0008 #c5 draw-paddle
```
=> ./img/screenshot_uxn-pong-paddle.png screenshot of the paddle drawn over the background
@ -595,8 +595,8 @@ in order to draw each paddle, we can do the following procedure inside our on-fr
```
( draw paddles )
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR draw-paddle
```
### the program so far
@ -641,7 +641,7 @@ omitting the definition of the draw-background and draw-paddle subroutines, and
;on-frame .Screen/vector DEO2
( draw background )
;draw-background JSR2
draw-background
( initialize paddles )
MARGIN .left/x STZ2
@ -658,8 +658,8 @@ BRK
@on-frame ( -> )
( draw paddles )
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR draw-paddle
BRK
```
@ -677,16 +677,16 @@ we have already the process for drawing our paddles:
```
( draw paddles )
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR draw-paddle
```
in order to clear them, we can do the same but using a sprite byte corresponding to clear the tile in the foreground:
```
( clear paddles )
.left/x LDZ2 .left/y LDZ2 CLEAR-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 CLEAR-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 CLEAR-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 CLEAR-COLOR draw-paddle
```
where CLEAR-COLOR in this case would be:
@ -717,31 +717,31 @@ all of this can go inside its own subroutine for readability purposes:
( left paddle: up and down buttons )
.Controller/button DEI
DUP #10 AND ( check bit for up )
,&left-up JCN
?&left-up
DUP #20 AND ( check bit for down )
,&left-down JCN
?&left-down
,&right JMP ( jump if neither of them were pressed )
!&right ( jump if neither of them were pressed )
&left-up
.left/y LDZ2 PADDLE-SPEED SUB2 .left/y STZ2
,&right JMP
!&right
&left-down
.left/y LDZ2 PADDLE-SPEED ADD2 .left/y STZ2
,&right JMP
!&right
&right
( right paddle: ctrl/A and alt/B buttons )
DUP #01 AND ( check bit for A )
,&right-up JCN
?&right-up
DUP #02 AND ( check bit for B )
,&right-down JCN
?&right-down
,&end JMP ( jump if neither of them were pressed )
!&end ( jump if neither of them were pressed )
&right-up
.right/y LDZ2 PADDLE-SPEED SUB2 .right/y STZ2
,&end JMP
!&end
&right-down
.right/y LDZ2 PADDLE-SPEED ADD2 .right/y STZ2
@ -759,15 +759,15 @@ now we are able to move our paddles!
```
@on-frame ( -> )
( clear paddles )
.left/x LDZ2 .left/y LDZ2 CLEAR-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 CLEAR-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 CLEAR-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 CLEAR-COLOR draw-paddle
( update paddles )
;update-paddles JSR2
update-paddles
( draw paddles )
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR draw-paddle
BRK
```
@ -863,7 +863,7 @@ in order to draw it, we'd just need to do:
```
( draw ball )
BALL-COLOR ;draw-ball JSR2
BALL-COLOR draw-ball
```
=> ./img/screenshot_uxn-pong-paddles-and-ball.png screenshot of the screen showing the paddles in their horizontal position but at different heights, and the ball completely centered in the screen.
@ -881,13 +881,13 @@ it would look something like the following, and it could sit along the equivalen
```
( inside on-frame )
( clear ball )
CLEAR-COLOR ;draw-ball JSR2
CLEAR-COLOR draw-ball
( update ball )
;update-ball JSR2
update-ball
( draw ball )
BALL-COLOR ;draw-ball JSR2
BALL-COLOR draw-ball
```
now let's discuss how to build that update-ball subroutine :)
@ -1083,12 +1083,12 @@ considering that there's a margin at the top, we can do this check as follows:
.ball/y LDZ2
WALL-MARGIN
LTH2 ( is ball-y less than the margin? )
,&set-positive-speed JCN
,&check-bottom-wall JMP
?&set-positive-speed
!&check-bottom-wall
&set-positive-speed
BALL-POSITIVE-SPEED .ball/speed-y STZ2
,&continue JMP
!&continue
&check-bottom-wall
```
@ -1107,8 +1107,8 @@ the y coordinate of the bottom wall would be the height of the screen, less the
.Screen/height DEI2
WALL-MARGIN SUB2 ( height - margin )
GTH2 ( is the ball-y greater than the wall-y? )
,&set-negative-speed JCN
,&continue JMP
?&set-negative-speed
!&continue
&set-negative-speed
BALL-NEGATIVE-SPEED .ball/speed-y STZ2
@ -1138,20 +1138,20 @@ our update-ball subroutine looks like the following right now:
.ball/y LDZ2
WALL-MARGIN
LTH2 ( is ball-y less than the margin? )
,&set-positive-speed JCN
,&check-bottom-wall JMP
?&set-positive-speed
!&check-bottom-wall
&set-positive-speed
BALL-POSITIVE-SPEED .ball/speed-y STZ2
,&continue JMP
!&continue
&check-bottom-wall
.ball/y LDZ2 BALL-SIZE ADD2 ( y + ball size )
.Screen/height DEI2
WALL-MARGIN SUB2 ( height - margin )
GTH2 ( is the ball y greater than the wall y? )
,&set-negative-speed JCN
,&continue JMP
?&set-negative-speed
!&continue
&set-negative-speed
BALL-NEGATIVE-SPEED .ball/speed-y STZ2
@ -1177,8 +1177,8 @@ for this, we can check if x is less than the sum of the margin and paddle width.
.ball/x LDZ2
MARGIN PADDLE-WIDTH ADD2
LTH2 ( is ball-x less than the margin + paddle-width? )
,&x-in-left JCN
,&check-right-paddle JMP
?&x-in-left
!&check-right-paddle
&x-in-left
( ... )
@ -1203,7 +1203,7 @@ if those two conditions are met, then we can set a positive speed for x:
.left/y LDZ2 PADDLE-HEIGHT ADD2 LTH2 ( second flag )
STHr ( retrieve first flag )
AND ( AND the two flags together )
,&bounce-left JCN
?&bounce-left
```
where bounce-left would be:
@ -1211,7 +1211,7 @@ where bounce-left would be:
```
&bounce-left
BALL-POSITIVE-SPEED .ball/speed-x STZ2
,&finish JMP
!&finish
```
and what happens if both conditions are not met at the same time?
@ -1228,20 +1228,20 @@ the whole x-in-left code would end up looking like:
.left/y LDZ2 PADDLE-HEIGHT ADD2 LTH2 ( second flag )
STHr ( retrieve first flag )
AND ( AND the two flags together )
,&bounce-left JCN
?&bounce-left
.ball/x LDZ2 #0000 NEQ2 ( has it reached the wall ? )
,&finish JCN
?&finish
&reset-left
( here you can increase the score of
the right paddle )
;reset JSR2
,&finish JMP
reset
!&finish
&bounce-left
BALL-POSITIVE-SPEED .ball/speed-x STZ2
,&finish JMP
!&finish
&check-right-paddle
```
@ -1265,8 +1265,8 @@ for the right paddle we will do the same as above, but changing the comparisons
.ball/x LDZ2 BALL-SIZE ADD2 ( ball-x + ball-size )
.Screen/width DEI2 MARGIN SUB2 PADDLE-WIDTH SUB2
GTH2 ( is ball's right coordinate greater than the screen width - margin - paddle-width? )
,&x-in-right JCN
,&finish JMP
?&x-in-right
!&finish
&x-in-right
.ball/y LDZ2 DUP2
@ -1274,21 +1274,21 @@ for the right paddle we will do the same as above, but changing the comparisons
.right/y LDZ2 PADDLE-HEIGHT ADD2 LTH2 ( second flag )
STHr ( retrieve first flag )
AND ( AND the two flags together )
,&bounce-right JCN
?&bounce-right
.ball/x LDZ2
.Screen/width DEI2 NEQ2 ( has it reached the wall ? )
,&finish JCN
?&finish
&reset-right
( here you can increase the score
of the left paddle )
;reset JSR2
,&finish JMP
reset
!&finish
&bounce-right
BALL-NEGATIVE-SPEED .ball/speed-x STZ2
,&finish JMP
!&finish
&finish
RTN
@ -1367,7 +1367,7 @@ here's all of the code we wrote today!
;on-frame .Screen/vector DEO2
( draw background )
;draw-background JSR2
draw-background
( initialize paddles )
MARGIN .left/x STZ2
@ -1381,7 +1381,7 @@ here's all of the code we wrote today!
.right/y STZ2
( initialize ball )
;reset JSR2
reset
( initialize ball speed )
BALL-NEGATIVE-SPEED .ball/speed-x STZ2
@ -1395,24 +1395,24 @@ BRK
```
@on-frame ( -> )
( clear paddles )
.left/x LDZ2 .left/y LDZ2 CLEAR-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 CLEAR-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 CLEAR-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 CLEAR-COLOR draw-paddle
( clear ball )
CLEAR-COLOR ;draw-ball JSR2
CLEAR-COLOR draw-ball
( update paddles )
;update-paddles JSR2
update-paddles
( update ball )
;update-ball JSR2
update-ball
( draw paddles )
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR ;draw-paddle JSR2
.left/x LDZ2 .left/y LDZ2 PADDLE-COLOR draw-paddle
.right/x LDZ2 .right/y LDZ2 PADDLE-COLOR draw-paddle
( draw ball )
BALL-COLOR ;draw-ball JSR2
BALL-COLOR draw-ball
BRK
```
@ -1449,19 +1449,19 @@ RTN
.ball/y LDZ2
WALL-MARGIN
LTH2 ( is ball-y less than the margin? )
,&set-positive-speed JCN
,&check-bottom-wall JMP
?&set-positive-speed
!&check-bottom-wall
&set-positive-speed
BALL-POSITIVE-SPEED .ball/speed-y STZ2
,&continue JMP
!&continue
&check-bottom-wall
.ball/y LDZ2 BALL-SIZE ADD2 ( y + ball size )
.Screen/height DEI2 WALL-MARGIN SUB2 ( height - margin )
GTH2
,&set-negative-speed JCN
,&continue JMP
?&set-negative-speed
!&continue
&set-negative-speed
BALL-NEGATIVE-SPEED .ball/speed-y STZ2
@ -1472,8 +1472,8 @@ RTN
.ball/x LDZ2
MARGIN PADDLE-WIDTH ADD2
LTH2 ( is ball-x less than the margin + paddle-width? )
,&x-in-left JCN
,&check-right-paddle JMP
?&x-in-left
!&check-right-paddle
&x-in-left
.ball/y LDZ2 DUP2
@ -1481,26 +1481,26 @@ RTN
.left/y LDZ2 PADDLE-HEIGHT ADD2 LTH2 ( second flag )
STHr ( retrieve first flag )
AND ( AND the two flags together )
,&bounce-left JCN
?&bounce-left
.ball/x LDZ2 #0000 NEQ2 ( has it reached the wall ? )
,&finish JCN
?&finish
&reset-left
( here you can add a point to the right paddle )
;reset JSR2
,&finish JMP
reset
!&finish
&bounce-left
BALL-POSITIVE-SPEED .ball/speed-x STZ2
,&finish JMP
!&finish
&check-right-paddle
.ball/x LDZ2 BALL-SIZE ADD2
.Screen/width DEI2 MARGIN SUB2 PADDLE-WIDTH SUB2
GTH2 ( is ball-x + ball-size greater than the screen width - margin - paddle-width? )
,&x-in-right JCN
,&finish JMP
?&x-in-right
!&finish
&x-in-right
.ball/y LDZ2 DUP2
@ -1508,20 +1508,20 @@ RTN
.right/y LDZ2 PADDLE-HEIGHT ADD2 LTH2 ( second flag )
STHr ( retrieve first flag )
AND ( AND the two flags together )
,&bounce-right JCN
?&bounce-right
.ball/x LDZ2
.Screen/width DEI2 NEQ2 ( has it reached the wall ? )
,&finish JCN
?&finish
&reset-right
( here you can add a point to the left paddle )
;reset JSR2
,&finish JMP
reset
!&finish
&bounce-right
BALL-NEGATIVE-SPEED .ball/speed-x STZ2
,&finish JMP
!&finish
&finish
RTN
@ -1560,31 +1560,31 @@ RTN
( left paddle: up 10 and down 20 buttons )
.Controller/button DEI
DUP #10 AND ( check bit for up )
,&left-up JCN
?&left-up
DUP #20 AND ( check bit for down )
,&left-down JCN
?&left-down
,&right JMP ( jump if neither of them were pressed )
!&right ( jump if neither of them were pressed )
&left-up
.left/y LDZ2 PADDLE-SPEED SUB2 .left/y STZ2
,&right JMP
!&right
&left-down
.left/y LDZ2 PADDLE-SPEED ADD2 .left/y STZ2
,&right JMP
!&right
&right
( right paddle: ctrl/A 01 and alt/B 02 buttons )
DUP #01 AND ( check bit for A )
,&right-up JCN
?&right-up
DUP #02 AND ( check bit for B )
,&right-down JCN
?&right-down
,&end JMP ( jump if neither of them were pressed )
!&end ( jump if neither of them were pressed )
&right-up
.right/y LDZ2 PADDLE-SPEED SUB2 .right/y STZ2
,&end JMP
!&end
&right-down
.right/y LDZ2 PADDLE-SPEED ADD2 .right/y STZ2
@ -1635,12 +1635,12 @@ RTN
#03 .Screen/sprite DEO ( draw 1bpp sprite with color 3 and 0 )
#0008 ADD2 ( increment x )
GTH2k ( is the width greater than x? aka is x less than the width ? )
,&loop-x JCN ( jump if x is less than the limit )
?&loop-x ( jump if x is less than the limit )
POP2 POP2 ( remove x and limit )
#0008 ADD2 ( increment y )
GTH2k ( is the limit greater than y? aka is y less than the limit ? )
,&loop-y JCN ( jump if y is less than the limit )
?&loop-y ( jump if y is less than the limit )
POP2 POP2 ( remove y and limit )
RTN
```

View File

@ -58,7 +58,7 @@ we can use a structure like the following, where the filename and reserved memor
;file/data .File0/read DEO2
( check the success byte and jump accordingly )
.File0/success DEI2 #0000 EQU2 ,&failed JCN
.File0/success DEI2 #0000 EQU2 ?&failed
&success
LIT "Y .Console/write DEO
@ -104,7 +104,7 @@ the following program will write "hello" and a newline (0a) into a file called "
;file/data .File0/write DEO2
( read and evaluate success byte )
.File/success DEI2 #0006 NEQ2 ,&failed JCN
.File/success DEI2 #0006 NEQ2 ?&failed
&success
LIT "Y .Console/write DEO
@ -146,7 +146,7 @@ we could adapt our previous subroutine in order to load the theme file and apply
;theme/data .File0/read DEO2
( check the success byte and jump accordingly )
.File0/success DEI2 #0006 NEQ2 ,&failed JCN
.File0/success DEI2 #0006 NEQ2 ?&failed
&success
( set the system colors from the read data )
@ -184,7 +184,7 @@ and for doing the opposite operation, we can read the system colors into our res
;theme/data .File0/write DEO2
( check the success byte and jump accordingly )
.File0/success DEI2 #0006 NEQ2 ,&failed JCN
.File0/success DEI2 #0006 NEQ2 ?&failed
&success
( report success? )