home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / REND386 / JIREND / GLOVDELH.ASM < prev    next >
Assembly Source File  |  1992-08-06  |  4KB  |  273 lines

  1.     TITLE    GLOVEDEL - Powerglove timing and i/o support
  2.     NAME    GLOVEDEL
  3.  
  4.     ; SPECIAL VERSION FOR COMBO HMD/GLOVE/SEGA UNIT
  5.  
  6.     COMMENT    $
  7.  
  8.     Name:        GLOVEDEL
  9.  
  10.         Written and (c) by Dave Stampe 24/4/92
  11.         Not for commercial use, so get permission
  12.         before marketing code using this stuff!
  13.         For private PD use only.
  14.  
  15.         $
  16.  
  17.         .MODEL large
  18.  
  19. EXTRN    _glove_in_port        ; GLOVE INTERFACE SPECS
  20. EXTRN    _glove_out_port         ; SET UP IN C CODE
  21.  
  22. EXTRN    _glove_none_mask
  23. EXTRN    _glove_data_mask
  24. EXTRN    _glove_latch_mask
  25. EXTRN    _glove_clock_mask
  26. EXTRN    _glove_clock_latch
  27.  
  28. EXTRN    _glove_bit_delay
  29.  
  30. EXTRN    _port_image
  31. EXTRN _glove_write_mask
  32.  
  33.         .CODE
  34.  
  35. ; bit delay macro for byte read, line toggle
  36.  
  37. bitdelay macro
  38.     local _localloop
  39.     mov    cx,_glove_bit_delay
  40. _localloop:
  41.     in    al,40h
  42.     loop    _localloop
  43. endm
  44.  
  45.  
  46.  
  47.  ;
  48.  ; int timed_glove_delay(int count);  /* returns time in 1.1925 MHZ ticks */
  49.  ;                                    /* to perform <count> delay steps   */
  50.  ;                      /* call with timer at 18.2 Hz rate  */
  51.  
  52.         PUBLIC    _timed_glove_delay
  53.  
  54. count equ [bp+6]
  55.  
  56. _timed_glove_delay    proc    far
  57.  
  58.     push    bp
  59.     mov    bp,sp
  60.     push    cx
  61.     push    dx
  62.     mov    cx,count
  63.     pushf
  64.     cli
  65.  
  66.     mov    al,00
  67.     out    43h,al        ; latch counter
  68.     nop
  69.     nop
  70.     in    al,40h          ; read count
  71.     mov    ah,al
  72.     in    al,40h
  73.     xchg    al,ah
  74.     mov    bx,ax
  75.  
  76. caloop: in      al,40h          ; do delay
  77.     loop    caloop
  78.  
  79.     mov    al,00
  80.     out    43h,al          ; read new count
  81.     nop
  82.     nop
  83.     in    al,40h
  84.     mov    ah,al
  85.     in    al,40h
  86.     xchg    al,ah
  87.     sub    ax,bx           ; assumes default, count rollover at 65536
  88.     neg    ax
  89.  
  90.     popf
  91.     pop    dx
  92.     pop    cx
  93.     mov    sp,bp
  94.     pop    bp
  95.     ret
  96.  
  97. _timed_glove_delay    endp
  98.  
  99.  
  100.  ;
  101.  ; int glove_delay(int count);    /* performs <count> delay steps   */
  102.  ;
  103.  
  104.         PUBLIC    _glove_delay
  105.  
  106. count equ [bp+6]
  107.  
  108. _glove_delay    proc    far
  109.  
  110.     push    bp
  111.     mov    bp,sp
  112.     push    cx
  113.     push    dx
  114.     mov    cx,count
  115.  
  116. gdel:    in    al,40h
  117.     loop    gdel
  118.  
  119.     pop    dx
  120.     pop    cx
  121.     mov    sp,bp
  122.     pop    bp
  123.     ret
  124.  
  125. _glove_delay    endp
  126.  
  127.  
  128.  
  129.  ;
  130.  ; int get_glove_byte();    /* reads a byte from glove */
  131.  ;
  132.  
  133.         PUBLIC    _get_glove_byte
  134.  
  135. _get_glove_byte    proc    far
  136.  
  137.     push    bp
  138.     mov    bp,sp
  139.     push    si
  140.     push    cx
  141.     push    dx
  142.  
  143.     mov    dx,_glove_out_port
  144.     mov    si,_glove_in_port
  145.  
  146.     mov    ax,_glove_clock_mask    ; preset lines
  147.     pushf
  148.     cli
  149.     mov    ah,BYTE PTR _glove_write_mask
  150.     not    ah
  151.     and    ah,BYTE PTR _port_image
  152.     or    al,ah
  153.     mov    BYTE PTR _port_image,al
  154.     out    dx,al                   ; output data
  155.     popf
  156.     bitdelay
  157.  
  158.     mov    ax,_glove_clock_latch
  159.     pushf
  160.     cli
  161.     mov    ah,BYTE PTR _glove_write_mask
  162.     not    ah
  163.     and    ah,BYTE PTR _port_image
  164.     or    al,ah
  165.     mov    BYTE PTR _port_image,al
  166.     out    dx,al                   ; output data
  167.     popf
  168.     bitdelay
  169.  
  170.     mov    ax,_glove_clock_mask
  171.     pushf
  172.     cli
  173.     mov    ah,BYTE PTR _glove_write_mask
  174.     not    ah
  175.     and    ah,BYTE PTR _port_image
  176.     or    al,ah
  177.     mov    BYTE PTR _port_image,al
  178.     out    dx,al                   ; output data
  179.     popf
  180.     bitdelay
  181.  
  182.     mov    bx,8000h                ; clear accumulator
  183.  
  184. bitloop:
  185.     xchg    si,dx                   ; add bit to accumulator
  186.     in    al,dx
  187.     xchg    si,dx
  188.     test    al,BYTE PTR _glove_data_mask
  189.     jz    z0
  190.     or    bl,bh
  191. z0:                                     ; next bit
  192.     shr    bh,1
  193.     jz    endbyte
  194.  
  195.     mov    ax,_glove_none_mask     ; pulse clock line
  196.     pushf
  197.     cli
  198.     mov    ah,BYTE PTR _glove_write_mask
  199.     not    ah
  200.     and    ah,BYTE PTR _port_image
  201.     or    al,ah
  202.     mov    BYTE PTR _port_image,al
  203.     out    dx,al                   ; output data
  204.     popf
  205.     bitdelay
  206.  
  207.     mov    ax,_glove_clock_mask
  208.     pushf
  209.     cli
  210.     mov    ah,BYTE PTR _glove_write_mask
  211.     not    ah
  212.     and    ah,BYTE PTR _port_image
  213.     or    al,ah
  214.     mov    BYTE PTR _port_image,al
  215.     out    dx,al                   ; output data
  216.     popf
  217.     bitdelay
  218.     jmp    bitloop
  219.  
  220. endbyte:
  221.     mov    ax,bx
  222.     xor    ah,ah
  223.     pop    dx
  224.     pop    cx
  225.     pop    si
  226.     mov    sp,bp
  227.     pop    bp
  228.     ret
  229.  
  230. _get_glove_byte    endp
  231.  
  232.  
  233.  ;
  234.  ; void set_glove_bits(int data);   /* sets glove clock, data lines */
  235.  ;                                  /* and does a bit delay         */
  236.  
  237.         PUBLIC    _set_glove_bits
  238.  
  239. bits equ [bp+6]
  240.  
  241. _set_glove_bits    proc    far
  242.  
  243.     push    bp
  244.     mov    bp,sp
  245.     push    dx
  246.     mov    dx,_glove_out_port
  247.     mov    ax,bits
  248.  
  249.     pushf
  250.     cli
  251.     and    al,BYTE PTR _glove_write_mask
  252.     mov    ah,BYTE PTR _glove_write_mask
  253.     not    ah
  254.     and    ah,BYTE PTR _port_image
  255.     or    al,ah
  256.     mov    BYTE PTR _port_image,al
  257.     out    dx,al                   ; output data
  258.     popf
  259.  
  260.     push    cx
  261.     bitdelay
  262.     pop    cx
  263.  
  264.     pop    dx
  265.     mov    sp,bp
  266.     pop    bp
  267.     ret
  268.  
  269. _set_glove_bits    endp
  270.  
  271.         end
  272.  
  273.