home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / bios / l.asm < prev    next >
Assembly Source File  |  1998-06-08  |  4KB  |  144 lines

  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  11. PUBLIC joy_read_stick_friendly_
  12.  
  13. joy_read_stick_friendly_:    
  14.         ; ebx = read mask
  15.         ; edi = pointer to event buffer
  16.         ; ecx = timeout value
  17.         ; returns in eax the number of events
  18.  
  19.         mov    RetryCount, 0
  20.         mov    _joy_bogus_reading, 0
  21.  
  22. joy_read_stick_friendly_retry:
  23.         inc    RetryCount
  24.         cmp    RetryCount, 3
  25.         jbe    @f
  26.         mov    _joy_bogus_reading, 1
  27.         inc    _joy_retries
  28.         mov    eax, 0
  29.         ret
  30.  
  31. @@:
  32.         push    ecx
  33.         push    ebx
  34.         push    edi
  35.  
  36.         and    ebx, 01111b        ; Make sure we only check the right values                                        
  37.                         ; number of events we found will be in bh, so this also clears it to zero.
  38.  
  39.         mov     dx, JOY_PORT
  40.  
  41.         cli                ; disable interrupts while reading time...
  42.         call    joy_get_timer        ; Returns counter in EAX
  43.         sti                ; enable interrupts after reading time...
  44.         mov    LastTick, eax
  45.  
  46. waitforstable:    in    al, dx
  47.         and    al, bl
  48.         jz    ready             ; Wait for the port in question to be done reading...
  49.         
  50.         cli                ; disable interrupts while reading time...
  51.         call    joy_get_timer        ; Returns counter in EAX
  52.         sti                ; enable interrupts after reading time...
  53.         xchg    eax, LastTick
  54.         cmp    eax, LastTick
  55.         jb    @f
  56.         sub    eax, LastTick
  57. @@:        ; Higher...
  58.         add    TotalTicks, eax
  59.         cmp    TotalTicks, ecx        ; Timeout at 1/200'th of a second
  60.         jae    ready
  61.         jmp    waitforstable
  62.         
  63. ready:
  64.         cli            
  65.         mov     al, 0ffh
  66.         out     dx, al            ; Start joystick a readin'
  67.  
  68.         call    joy_get_timer        ; Returns counter in EAX
  69.         mov    LastTick, eax
  70.         mov    TotalTicks, 0
  71.         
  72.         mov    [edi], eax        ; Store initial count
  73.         add    edi, 4        
  74.  
  75.     again:    in    al, dx            ; Read Joystick port
  76.         not    al
  77.         and    al, bl            ; Mask off channels we don't want to read
  78.         jnz    flip            ; See if any of the channels flipped
  79.  
  80.         ; none flipped -- check any interrupts...
  81.         mov    al, 0Ah
  82.         out     20h, al
  83.         in    al, 20h        ; Get interrupts pending
  84.         cmp    al, 0
  85.         je    NoInts
  86.  
  87.         ; Need to do an interrupt
  88.         sti
  89.         nop    ; let the interrupt go on...
  90.         cli
  91.         
  92.         ; See if any axis turned
  93.         in    al, dx
  94.         not    al
  95.         and    al, bl
  96.         jz    NoInts
  97.  
  98.         ; At this point, an interrupt occured, making one or more
  99.         ; of the axis values bogus.  So, we will restart this process...
  100.  
  101.         pop    edi
  102.         pop    ebx
  103.         pop    ecx
  104.  
  105.         jmp    joy_read_stick_friendly_retry
  106.  
  107. NoInts:
  108.         call    joy_get_timer        ; Returns counter in EAX
  109.         
  110.         xchg    eax, LastTick
  111.         cmp    eax, LastTick
  112.         jb    @f
  113.         sub    eax, LastTick
  114. @@:        ; Higher...
  115.         add    TotalTicks, eax
  116.         cmp    TotalTicks, ecx        ; Timeout at 1/200'th of a second
  117.         jae    timedout
  118.         jmp    again
  119.  
  120.     flip:    and    eax, 01111b        ; Only care about axis values
  121.         mov    [edi], eax        ; Record what channel(s) flipped
  122.         add    edi, 4    
  123.         xor    bl, al            ; Unmark the channels that just tripped
  124.  
  125.         call    joy_get_timer        ; Returns counter in EAX
  126.         mov    [edi], eax        ; Record the time this channel flipped
  127.         add    edi, 4        
  128.         inc    bh            ; Increment number of events
  129.  
  130.         cmp    bl, 0    
  131.         jne    again            ; If there are more channels to read, keep looping
  132.  
  133.     timedout:
  134.         sti
  135.  
  136.         movzx    eax, bh            ; Return number of events
  137.  
  138.         pop    edi
  139.         pop    ebx
  140.         pop    ecx
  141.  
  142.         ret
  143. 
  144.