home *** CD-ROM | disk | FTP | other *** search
/ Emulator Universe CD / emulatoruniversecd1998.iso / Speccy / Emulators / winemu / SOURCES / TAPE2TAP / PIT.INC < prev    next >
Encoding:
Text File  |  1996-05-10  |  1.9 KB  |  69 lines

  1.  
  2.  ; Pit.inc : Primitives for timing. Indepent from the speed of the
  3.  ;            computer.
  4.  ;
  5.  ; Copyright 1995 Rui Fernando Ferreira Ribeiro.
  6.  ;
  7.  ; This program is free software; you can redistribute it and/or modify
  8.  ; it under the terms of the GNU General Public License as published by
  9.  ; the Free Software Foundation; either version 2 of the License, or
  10.  ; (at your option) any later version.
  11.  ;
  12.  ; This program is distributed in the hope that it will be useful,
  13.  ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  ; GNU General Public License for more details.
  16.  ;
  17.  ; You should have received a copy of the GNU General Public License
  18.  ; along with this program; if not, write to the Free Software
  19.  ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  ;
  21.  
  22.                                         ; some equates
  23.                                         ; *************
  24. LOW_IMP        equ    1200
  25. HI_IMP        equ    2600
  26.  
  27. LOW_SYNC    equ    1200
  28. HI_SYNC        equ    1800
  29.  
  30. TRANSITION      equ     800
  31.  
  32. WAIT_VAL        equ     300
  33. NIMP            equ     50
  34. BAD_HI        equ    4000
  35. BAD_LOW         equ     5
  36.  
  37. READ_PIT    MACRO            ; read PIT (8253) counter 0
  38.         xor    al,al        ; ask to read counter
  39.         out    43h,al        ; PIT control port
  40.         in    al,40h        ; read LSB of counter
  41.         mov    ah,al
  42.         in    al,40h        ; read MSB of counter
  43.         xchg    ah,al
  44.         ENDM
  45.  
  46. INIT_COUNT    MACRO
  47.         READ_PIT
  48.         mov    bp,ax        ; save counter in BP
  49.         ENDM
  50.  
  51. GIVE_COUNT    MACRO            ; return time elapsed since INIT_COUNT
  52. local           end_cnt
  53.         READ_PIT
  54.         sub    ax,bp        ; find difference
  55.                 jns     end_cnt        ; if difference negative
  56.         neg    ax        ; correct value
  57. end_cnt:
  58.         ENDM
  59.  
  60.         ; Initialize the 8253/4 timer
  61. INIT_PIT    MACRO
  62.         mov    al,36h        ; select 0|load_2_bytes|mode3|binary
  63.         out    43h,al
  64.         xor    al,al
  65.         out    40h,al        ; set timer 0 ch 0 freq to 18.2Hz
  66.         out    40h,al        
  67.         ENDM
  68.  
  69. ; EOF: Pit.inc