Annotation of src/joystick.asm, revision 1.1

1.1     ! root        1: .386p
        !             2: .model small
        !             3: 
        !             4:  MaxJoyValue = 5000
        !             5: 
        !             6: .DATA
        !             7: 
        !             8: _Joy_xb db ?
        !             9: _Joy_yb db ?
        !            10: _Joy_xs db ?
        !            11: _Joy_ys db ?
        !            12: _Joy_x  dw ?
        !            13: _Joy_y  dw ?
        !            14: 
        !            15: PUBLIC _Joy_xb
        !            16: PUBLIC _Joy_yb
        !            17: PUBLIC _Joy_xs
        !            18: PUBLIC _Joy_ys
        !            19: PUBLIC _Joy_x
        !            20: PUBLIC _Joy_y
        !            21: 
        !            22: .CODE
        !            23: 
        !            24: ALIGN  4
        !            25: 
        !            26: ;=================
        !            27: ;
        !            28: ; JoyStick_Vals
        !            29: ;
        !            30: ;=================
        !            31: 
        !            32: PROC   JoyStick_Vals_
        !            33: PUBLIC JoyStick_Vals_
        !            34: 
        !            35: 
        !            36: ; Read the absolute joystick values
        !            37: 
        !            38:    pushf                ; Save some registers
        !            39:    push  ebp
        !            40:    cli                  ; Make sure an interrupt doesn't screw the timings
        !            41: 
        !            42:    mov   dx, 0201h
        !            43:    in    al, dx
        !            44:    out   dx, al         ; Clear the resistors
        !            45: 
        !            46:    mov   ah, BYTE PTR [_Joy_xb]   ; Get masks into registers
        !            47:    mov   ch, BYTE PTR [_Joy_yb]
        !            48: 
        !            49:    xor   si, si         ; Clear count registers
        !            50:    xor   di, di
        !            51:    xor   bh, bh         ; Clear high byte of bx for later
        !            52: 
        !            53:    mov   ebp, MaxJoyValue
        !            54: 
        !            55:    @@LOOP:
        !            56:    in    al, dx         ; Get bits indicating whether all are finished
        !            57: 
        !            58:    dec   ebp             ; Check bounding register
        !            59:    jz    done           ; We have a silly value - abort
        !            60: 
        !            61:    mov   bl, al         ; Duplicate the bits
        !            62:    and   bl, ah         ; Mask off useless bits (in [xb])
        !            63:    add   si, bx         ; Possibly increment count register
        !            64:    mov   cl, bl         ; Save for testing later
        !            65: 
        !            66:    mov   bl, al
        !            67:    and   bl, ch         ; [yb]
        !            68:    add   di, bx
        !            69: 
        !            70:    add   cl, bl
        !            71:    jnz   @@LOOP         ; If both bits were 0, drop out
        !            72: 
        !            73:    done:
        !            74: 
        !            75:    mov   cl, [_Joy_xs]  ; Get the number of bits to shift
        !            76:    shr   si, cl         ;  and shift the count that many times
        !            77: 
        !            78:    mov   cl, [_Joy_ys]
        !            79:    shr   di, cl
        !            80: 
        !            81:    mov   [_Joy_x], si   ; Store the values into the variables
        !            82:    mov   [_Joy_y], di
        !            83: 
        !            84:    pop   ebp
        !            85:    popf                 ; Restore the registers
        !            86: 
        !            87:    ret
        !            88: 
        !            89:    ENDP  JoyStick_Vals_
        !            90: 
        !            91:    END
        !            92: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.