Vistas de página en total

Mostrando entradas con la etiqueta delay. Mostrar todas las entradas
Mostrando entradas con la etiqueta delay. Mostrar todas las entradas

sábado, 10 de agosto de 2013

DELAY

  Esta función se me ha pasado incluirla en su momento, para completar la macro TIME. Por ello la añado ahora.


   Esta función completa la librería Time, añadiendo la función DELAY. Con esta función podremos realizar retardos de tiempo en segundos. Utiliza el reloj del sistema para realizar la espera.



DELAY.ASM
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
.model compact,pascal
.data
ti_min db 0
ti_seg db 0
pausa dw 0
.code
       public _delay

_delay proc near  bx cx, tiempo
     mov ah,2ch
     int 21h
     mov ti_min,cl
     mov ti_seg,dh

        mov al,ti_min
        mov dl,60
        mul dl
        mov dx,ax
        xor ax,ax
        mov al,ti_seg
        add dx,ax
        mov pausa,dx

 espera:
       mov ah,2ch
       int 21h
       mov ti_min,cl
       mov ti_seg,dh
        mov al,ti_min
        mov dl,60
        mul dl
        mov dx,ax
        xor ax,ax
        mov al,ti_seg
        add dx,ax
        mov ax,dx
        sub dx,pausa
        cmp dx,tiempo
        jb espera
        ret
_delay endp

end   _delay

miércoles, 10 de julio de 2013

CABECERA TIME

        Vamos a ver ahora una cabecera que añadirá, junto con sus librerías asociadas, las funciones necesarias para tomar la hora.
      Ahora no hemos añadido a esta cabecera las funciones de fecha. Eso lo podremos hacer más tarde.
   
     En este caso creamos una macro que creará una estructura con el formato de hora, si no ha sido creada antes,  y posteriormente la variable asociada que deseamos. Por lo tanto creamos un tipo de variable time.

     Para empezar, tendremos tres funciones gettime, asctime, y delay. La primera está implementada directamente en la macro y la usaremos en el siguiente blog para crear un pequeño ejercicio impresión de hora y en el siguiente blog crearé un MASTERMIND.

      Luego añadiremos las librerías de asctime y delay.
      Ascitime nos permitirá tomar la hora directamente en formateada en una cadena.
      Delay lo usaremos para crear retardos en los programas.

TIME.MAC
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.

;macro para generar varible hora
time macro nombre
ifndef _time
    _time struc
        ti_hora dw 2 dup (?)
        ti_min dw 2 dup (?)
        ti_seg dw 2 dup (?)
        ti_dec dw 2 dup (?)
    _time ends
endif
     nombre _time ?
endm

;devuelve un número aleatorio en ax
random macro 
    push dx
    mov ah,00
    int 1ah
    mov ax,dx
    pop dx
endm
;obtiene la hora y la comunica a una varialbe con la estructura _time
gettime macro hora
     push cx
     push dx
     mov ah,2ch
     int 21h
     mov byte ptr hora&.ti_hora,ch
     mov byte ptr hora&.ti_min,cl
     mov byte ptr hora&.ti_seg,dh
     mov byte ptr hora&.ti_dec,al
     pop dx
     pop cx
endm
asctime macro cadena
ifndef _asctime
   extrn _asctime:near
endif
        lea ax,cadena
        push ax
        call _asctime
        pop ax
  endm

delay macro tiempo
ifndef _delay
        extrn _delay:near
endif
        mov ax,tiempo
        push ax
        call _delay
        pop ax
 endm