updated file device(s) and datetime

This commit is contained in:
sejo 2022-04-22 09:17:18 -05:00
parent 67dffd5866
commit ca3fd37cee
3 changed files with 54 additions and 41 deletions

View File

@ -39,7 +39,6 @@ implement the following concepts as {coloring computers}:
# uxn
* update instructions for running uxnemu
* update DateTime and File devices info
# wiki

View File

@ -6,14 +6,19 @@ este debería ser un final ligero y tranquilo de nuestro recorrido, ya que tiene
¡comencemos!
# el dispositivo de archivo
# los dispositivos de archivo
el dispositivo de archivo en el ordenador varvara nos permite leer y escribir en archivos externos.
los dispositivos de archivo en el ordenador varvara nos permiten leer y escribir en archivos externos.
existen dos de ellos que funcionan de una manera idéntica.
## puertos
sus puertos se definen normalmente de la siguiente manera:
```
|a0 @Archivo [ &vector $2 &éxito $2 &estad $2 &borrar $1 &adjuntar $1 &nombre $2 &largo $2 &leer $2 &escribir $2 ]
|a0 @Archivo0 [ &vector $2 &éxito $2 &estad $2 &borrar $1 &adjuntar $1 &nombre $2 &largo $2 &leer $2 &escribir $2 ]
|b0 @Archivo1 [ &vector $2 &éxito $2 &estad $2 &borrar $1 &adjuntar $1 &nombre $2 &largo $2 &leer $2 &escribir $2 ]
```
* el corto vector no se utiliza actualmente
@ -32,6 +37,8 @@ una operación de lectura se inicia cuando se escribe en el corto `leer` y una o
## leer un archivo
en toda la discusión que sigue nos enfocaremos en un solo dispositivo de archivo. como sea, ¡no olvides que para usos más avanzados tienes los dos a tu disposición!
para leer un archivo, necesitamos saber lo siguiente:
* la ruta del archivo, escrita como una cadena de texto etiquetada en la memoria del programa y terminada por un 00 - esta ruta sería relativa a la ubicación donde se ejecuta uxnemu.
@ -44,14 +51,14 @@ podemos usar una estructura como la siguiente, donde el nombre del archivo y la
```
@carga-archivo ( -- )
;archivo/nombre .Archivo/nombre DEO2 ( dirección de la ruta del archivo )
#00ff .Archivo/largo DEO2 ( intentará leer 255 bytes )
;archivo/nombre .Archivo0/nombre DEO2 ( dirección de la ruta del archivo )
#00ff .Archivo0/largo DEO2 ( intentará leer 255 bytes )
( establecer la dirección de los datos a leer y hacer lectura )
;archivo/datos .Archivo/leer DEO2
;archivo/datos .Archivo0/leer DEO2
( comprobar el byte éxito y saltar según corresponda )
Archivo/éxito DEI2 #0000 EQU2 ,&fallo JCN
Archivo0/éxito DEI2 #0000 EQU2 ,&fallo JCN
&éxito
LIT 'Y .Consola/escribe DEO
@ -90,14 +97,14 @@ el siguiente programa escribirá "hola" y una nueva línea (0a) en un archivo ll
```
@guardar-archivo ( -- )
;archivo/nombre .Archivo/nombre DEO2 ( establecer el nombre de archivo )
#0006 .Archivo/largo DEO2 ( intentará escribir 6 bytes )
;archivo/nombre .Archivo0/nombre DEO2 ( establecer el nombre de archivo )
#0006 .Archivo0/largo DEO2 ( intentará escribir 6 bytes )
( establecer la dirección de inicio de los datos y hacer la escritura )
;archivo/datos .Archivo/escribir DEO2
;archivo/datos .Archivo0/escribir DEO2
( leer y evaluar el byte éxito )
.Archivo/éxito DEI2 #0006 NEQ2 ,&fallo JCN
.Archivo0/éxito DEI2 #0006 NEQ2 ,&fallo JCN
&éxito
LIT 'Y .Consola/escribe DEO
@ -132,14 +139,14 @@ podríamos adaptar nuestra subrutina anterior para cargar el archivo de temas y
```
@cargar-tema ( -- )
;tema/nombre .Archivo/nombre DEO2 ( establecer la dirección de la ruta del archivo )
#0006 .Archivo/largo DEO2 ( intentará leer 6 bytes )
;tema/nombre .Archivo0/nombre DEO2 ( establecer la dirección de la ruta del archivo )
#0006 .Archivo0/largo DEO2 ( intentará leer 6 bytes )
( establecer la dirección de los datos a leer y hacer lectura )
;tema/datos .Archivo/leer DEO2
;tema/datos .Archivo0/leer DEO2
( comprobar el byte éxito y saltar según corresponda )
.Archivo/éxito DEI2 #0006 NEQ2 ,&fallo JCN
.Archivo0/éxito DEI2 #0006 NEQ2 ,&fallo JCN
&éxito
( establecer los colores del sistema a partir de los datos leídos )
@ -170,14 +177,14 @@ y para hacer la operación contraria, podemos leer los colores del sistema en nu
.Sistema/g DEI2 ;tema/g STA2
.Sistema/b DEI2 ;tema/b STA2
;tema/nombre .Archivo/nombre DEO2 ( establecer la dirección de la ruta del archivo )
#0006 .Archivo/leer DEO2 ( intentará escribir 6 bytes )
;tema/nombre .Archivo0/nombre DEO2 ( establecer la dirección de la ruta del archivo )
#0006 .Archivo0/leer DEO2 ( intentará escribir 6 bytes )
( establecer la dirección de los datos y hacer la escritura )
;tema/datos .Archivo/escribir DEO2
;tema/datos .Archivo0/escribir DEO2
( comprobar el byte de éxito y saltar según corresponda )
.Archivo/éxito DEI2 #0006 NEQ2 ,&fallo JCN
.Archivo0/éxito DEI2 #0006 NEQ2 ,&fallo JCN
&éxito
( ¿informar el éxito? )
@ -198,7 +205,7 @@ el dispositivo fechahora (o "datetime") puede ser útil para el cronometraje de
tiene varios campos que podemos leer, todos ellos basados en la hora del sistema actual y la zona horaria:
```
|b0 @FechaHora [ &año $2 &mes $1 &día $1 &hora $1 &minuto $1 &segundo $1 &ddls $1 &dda $2 &eshdv $1 ]
|c0 @FechaHora [ &año $2 &mes $1 &día $1 &hora $1 &minuto $1 &segundo $1 &ddls $1 &dda $2 &eshdv $1 ]
```
* el byte año corresponde al número de año de la llamada era común

View File

@ -6,14 +6,19 @@ this should be a light and calm end of our journey, as it has to do less with pr
let's begin!
# the file device
# the file devices
the file device in the varvara computer allows us to read and write to external files.
the file devices in the varvara computer allow us to read and write to external files.
its ports are normally defined as follows:
there are two of them and they work in exactly the same way.
## device ports
their ports are normally defined as follows:
```
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
|a0 @File0 [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
|b0 @File1 [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
```
* the vector short is currently unused
@ -32,6 +37,8 @@ these might seem like a lot of fields to handle, but we'll see that they are not
## reading a file
the following discussion will focus in only one file device. don't forget that for more advanced uses you can take advantage of both!
in order to read a file, we need to know the following:
* the path of the file, written as a labelled string of text in program memory and terminated by a 00 - this path would be relative to the location where uxnemu is ran.
@ -44,14 +51,14 @@ we can use a structure like the following, where the filename and reserved memor
```
@load-file ( -- )
;file/name .File/name DEO2 ( set address of file path )
#00ff .File/length DEO2 ( will attempt to read 255 bytes )
;file/name .File0/name DEO2 ( set address of file path )
#00ff .File0/length DEO2 ( will attempt to read 255 bytes )
( set address for the data to read, and do read )
;file/data .File/read DEO2
;file/data .File0/read DEO2
( check the success byte and jump accordingly )
.File/success DEI2 #0000 EQU2 ,&failed JCN
.File0/success DEI2 #0000 EQU2 ,&failed JCN
&success
LIT 'Y .Console/write DEO
@ -90,11 +97,11 @@ the following program will write "hello" and a newline (0a) into a file called "
```
@save-file ( -- )
;file/name .File/name DEO2 ( set file name )
#0006 .File/length DEO2 ( will attempt to write 6 bytes )
;file/name .File0/name DEO2 ( set file name )
#0006 .File0/length DEO2 ( will attempt to write 6 bytes )
( set data starting address, and do write )
;file/data .File/write DEO2
;file/data .File0/write DEO2
( read and evaluate success byte )
.File/success DEI2 #0006 NEQ2 ,&failed JCN
@ -132,14 +139,14 @@ we could adapt our previous subroutine in order to load the theme file and apply
```
@load-theme ( -- )
;theme/name .File/name DEO2 ( set address of file path )
#0006 .File/length DEO2 ( will attempt to read 6 bytes )
;theme/name .File0/name DEO2 ( set address of file path )
#0006 .File0/length DEO2 ( will attempt to read 6 bytes )
( set address for the data to read, and do read )
;theme/data .File/read DEO2
;theme/data .File0/read DEO2
( check the success byte and jump accordingly )
.File/success DEI2 #0006 NEQ2 ,&failed JCN
.File0/success DEI2 #0006 NEQ2 ,&failed JCN
&success
( set the system colors from the read data )
@ -170,14 +177,14 @@ and for doing the opposite operation, we can read the system colors into our res
.System/g DEI2 ;theme/g STA2
.System/b DEI2 ;theme/b STA2
;theme/name .File/name DEO2 ( set address of file path )
#0006 .File/length DEO2 ( will attempt to write 6 bytes )
;theme/name .File0/name DEO2 ( set address of file path )
#0006 .File0/length DEO2 ( will attempt to write 6 bytes )
( set address for the data and do write )
;theme/data .File/write DEO2
;theme/data .File0/write DEO2
( check the success byte and jump accordingly )
.File/success DEI2 #0006 NEQ2 ,&failed JCN
.File0/success DEI2 #0006 NEQ2 ,&failed JCN
&success
( report success? )
@ -198,7 +205,7 @@ the datetime device can be useful for low precision timing and/or for visualizat
it has several fields that we can read, all of them based on the current system time and timezone:
```
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
|c0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
```
* the year short corresponds to the number of year in the so called common era