home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / devel5 / glovdelh.asm < prev    next >
Encoding:
Assembly Source File  |  1993-05-09  |  4.5 KB  |  278 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.      ATTRIBUTION:  If you use any part of this source code or the libraries
  17.      in your projects, you must give attribution to REND386, Dave Stampe,
  18.      and Bernie Roehl in your documentation, source code, and at startup
  19.      of your program.  Let's keep the freeware ball rolling!
  20.         $
  21.  
  22.         .MODEL large
  23.  
  24. EXTRN    _glove_in_port        ; GLOVE INTERFACE SPECS
  25. EXTRN    _glove_out_port         ; SET UP IN C CODE
  26.  
  27. EXTRN    _glove_none_mask
  28. EXTRN    _glove_data_mask
  29. EXTRN    _glove_latch_mask
  30. EXTRN    _glove_clock_mask
  31. EXTRN    _glove_clock_latch
  32.  
  33. EXTRN    _glove_bit_delay
  34.  
  35. EXTRN    _port_image
  36. EXTRN _glove_write_mask
  37.  
  38.         .CODE
  39.  
  40. ; bit delay macro for byte read, line toggle
  41.  
  42. bitdelay macro
  43.     local _localloop
  44.     mov    cx,_glove_bit_delay
  45. _localloop:
  46.     in    al,41h
  47.     loop    _localloop
  48. endm
  49.  
  50.  
  51.  
  52.  ;
  53.  ; int timed_glove_delay(int count);  /* returns time in 1.1925 MHZ ticks */
  54.  ;                                    /* to perform <count> delay steps   */
  55.  ;                      /* call with timer at 18.2 Hz rate  */
  56.  
  57.         PUBLIC    _timed_glove_delay
  58.  
  59. count equ [bp+6]
  60.  
  61. _timed_glove_delay    proc    far
  62.  
  63.     push    bp
  64.     mov    bp,sp
  65.     push    cx
  66.     push    dx
  67.     mov    cx,count
  68.     pushf
  69.     cli
  70.  
  71.     mov    al,00
  72.     out    43h,al        ; latch counter
  73.     nop
  74.     nop
  75.     in    al,40h          ; read count
  76.     mov    ah,al
  77.     in    al,40h
  78.     xchg    al,ah
  79.     mov    bx,ax
  80.  
  81. caloop: in      al,41h          ; do delay
  82.     loop    caloop
  83.  
  84.     mov    al,00
  85.     out    43h,al          ; read new count
  86.     nop
  87.     nop
  88.     in    al,40h
  89.     mov    ah,al
  90.     in    al,40h
  91.     xchg    al,ah
  92.     sub    ax,bx           ; assumes default, count rollover at 65536
  93.     neg    ax
  94.  
  95.     popf
  96.     pop    dx
  97.     pop    cx
  98.     mov    sp,bp
  99.     pop    bp
  100.     ret
  101.  
  102. _timed_glove_delay    endp
  103.  
  104.  
  105.  ;
  106.  ; int glove_delay(int count);    /* performs <count> delay steps   */
  107.  ;
  108.  
  109.         PUBLIC    _glove_delay
  110.  
  111. count equ [bp+6]
  112.  
  113. _glove_delay    proc    far
  114.  
  115.     push    bp
  116.     mov    bp,sp
  117.     push    cx
  118.     push    dx
  119.     mov    cx,count
  120.  
  121. gdel:    in    al,41h
  122.     loop    gdel
  123.  
  124.     pop    dx
  125.     pop    cx
  126.     mov    sp,bp
  127.     pop    bp
  128.     ret
  129.  
  130. _glove_delay    endp
  131.  
  132.  
  133.  
  134.  ;
  135.  ; int get_glove_byte();    /* reads a byte from glove */
  136.  ;
  137.  
  138.         PUBLIC    _get_glove_byte
  139.  
  140. _get_glove_byte    proc    far
  141.  
  142.     push    bp
  143.     mov    bp,sp
  144.     push    si
  145.     push    cx
  146.     push    dx
  147.  
  148.     mov    dx,_glove_out_port
  149.     mov    si,_glove_in_port
  150.  
  151.     mov    ax,_glove_clock_mask    ; preset lines
  152.     pushf
  153.     cli
  154.     mov    ah,BYTE PTR _glove_write_mask
  155.     not    ah
  156.     and    ah,BYTE PTR _port_image
  157.     or    al,ah
  158.     mov    BYTE PTR _port_image,al
  159.     out    dx,al                   ; output data
  160.     popf
  161.     bitdelay
  162.  
  163.     mov    ax,_glove_clock_latch
  164.     pushf
  165.     cli
  166.     mov    ah,BYTE PTR _glove_write_mask
  167.     not    ah
  168.     and    ah,BYTE PTR _port_image
  169.     or    al,ah
  170.     mov    BYTE PTR _port_image,al
  171.     out    dx,al                   ; output data
  172.     popf
  173.     bitdelay
  174.  
  175.     mov    ax,_glove_clock_mask
  176.     pushf
  177.     cli
  178.     mov    ah,BYTE PTR _glove_write_mask
  179.     not    ah
  180.     and    ah,BYTE PTR _port_image
  181.     or    al,ah
  182.     mov    BYTE PTR _port_image,al
  183.     out    dx,al                   ; output data
  184.     popf
  185.     bitdelay
  186.  
  187.     mov    bx,8000h                ; clear accumulator
  188.  
  189. bitloop:
  190.     xchg    si,dx                   ; add bit to accumulator
  191.     in    al,dx
  192.     xchg    si,dx
  193.     test    al,BYTE PTR _glove_data_mask
  194.     jz    z0
  195.     or    bl,bh
  196. z0:                                     ; next bit
  197.     shr    bh,1
  198.     jz    endbyte
  199.  
  200.     mov    ax,_glove_none_mask     ; pulse clock line
  201.     pushf
  202.     cli
  203.     mov    ah,BYTE PTR _glove_write_mask
  204.     not    ah
  205.     and    ah,BYTE PTR _port_image
  206.     or    al,ah
  207.     mov    BYTE PTR _port_image,al
  208.     out    dx,al                   ; output data
  209.     popf
  210.     bitdelay
  211.  
  212.     mov    ax,_glove_clock_mask
  213.     pushf
  214.     cli
  215.     mov    ah,BYTE PTR _glove_write_mask
  216.     not    ah
  217.     and    ah,BYTE PTR _port_image
  218.     or    al,ah
  219.     mov    BYTE PTR _port_image,al
  220.     out    dx,al                   ; output data
  221.     popf
  222.     bitdelay
  223.     jmp    bitloop
  224.  
  225. endbyte:
  226.     mov    ax,bx
  227.     xor    ah,ah
  228.     pop    dx
  229.     pop    cx
  230.     pop    si
  231.     mov    sp,bp
  232.     pop    bp
  233.     ret
  234.  
  235. _get_glove_byte    endp
  236.  
  237.  
  238.  ;
  239.  ; void set_glove_bits(int data);   /* sets glove clock, data lines */
  240.  ;                                  /* and does a bit delay         */
  241.  
  242.         PUBLIC    _set_glove_bits
  243.  
  244. bits equ [bp+6]
  245.  
  246. _set_glove_bits    proc    far
  247.  
  248.     push    bp
  249.     mov    bp,sp
  250.     push    dx
  251.     mov    dx,_glove_out_port
  252.     mov    ax,bits
  253.  
  254.     pushf
  255.     cli
  256.     and    al,BYTE PTR _glove_write_mask
  257.     mov    ah,BYTE PTR _glove_write_mask
  258.     not    ah
  259.     and    ah,BYTE PTR _port_image
  260.     or    al,ah
  261.     mov    BYTE PTR _port_image,al
  262.     out    dx,al                   ; output data
  263.     popf
  264.  
  265.     push    cx
  266.     bitdelay
  267.     pop    cx
  268.  
  269.     pop    dx
  270.     mov    sp,bp
  271.     pop    bp
  272.     ret
  273.  
  274. _set_glove_bits    endp
  275.  
  276.         end
  277.  
  278.