Annotation of os2sdk/demos/examples/iopl/ioplsub.asm, revision 1.1.1.1

1.1       root        1:        TITLE    CURSOR
                      2: 
                      3: ;      This file exports the function _GetCurLoc which gets the location
                      4: ;      of the cursor on the CRT screen.
                      5: ;
                      6: ;      This routine illustrates the use of the DosPortAccess() call.  This
                      7: ;      call is supposed to give the IOPL segment access to ports and CLI/STI
                      8: ;      instructions. In fact, on the PC/AT (80286) there is no enforcement.
                      9: ;      This call is provided for future compatibility with the 80386.
                     10: ;      At present, the use of DosPortAccess() from an IOPL segment is not
                     11: ;      supported (the calls are commented out here) but will be in the future.
                     12: ;      The form and placement of these calls is indicated here as a guide
                     13: ;      to future usage.
                     14: ;
                     15: ;      One thing to beware of: if you disable interrupts (CLI) they may be
                     16: ;      re-enabled for you by the operating system.  This will occur if you
                     17: ;      generate a fault of some sort.  The easiest example is a segment not
                     18: ;      present fault.  When the segment is loaded and your code starts to
                     19: ;      execute the interrupts will be enabled.  The solution is simple: don't
                     20: ;      load any selectors within the CLI/STI code.
                     21: ;
                     22: ;      Any other fault will cause your process to be booted (i.e. GP fault).
                     23: ;
                     24:        .286p
                     25: 
                     26: _TEXT2 SEGMENT  BYTE PUBLIC 'CODE'
                     27: _TEXT2 ENDS
                     28: _DATA  SEGMENT  WORD PUBLIC 'DATA'
                     29: _DATA  ENDS
                     30: CONST  SEGMENT  WORD PUBLIC 'CONST'
                     31: CONST  ENDS
                     32: _BSS   SEGMENT  WORD PUBLIC 'BSS'
                     33: _BSS   ENDS
                     34: 
                     35: DGROUP GROUP   CONST,  _BSS,   _DATA
                     36: 
                     37: ;       EXTRN   DOSPORTACCESS:FAR
                     38: 
                     39:        ASSUME  CS: _TEXT2, DS: DGROUP, SS: DGROUP, ES: DGROUP
                     40: 
                     41: _TEXT2    SEGMENT
                     42: 
                     43:        PORT1           EQU     3D4h
                     44:        PORT2           EQU     3D5h
                     45:        CURSOR_H        EQU     14      ; cursor location HIGH register
                     46:        CURSOR_L        EQU     15      ; cursor location LOW register
                     47:        ACCESSREQ       EQU     0       ; request access to port(s)
                     48:        ACCESSREL       EQU     1       ; release access to port(s)
                     49: 
                     50: ;**    _GetCurLoc - gets cursor location on the CRT screen
                     51: ;
                     52: ;      ENTRY   NONE
                     53: ;
                     54: ;      EXIT    (AX) = cursor location
                     55: ;
                     56: ;      USES    AX, BX, DX
                     57: 
                     58:        PUBLIC  _GetCurLoc              ; gets cursor location on CRT screen
                     59: 
                     60: _GetCurLoc     PROC    FAR
                     61: 
                     62: ;       push    0               ; RESERVED WORD
                     63: ;       push    ACCESSREQ       ; request access to port(s)
                     64: ;       push    PORT1
                     65: ;       push    PORT2
                     66: ;       call    DOSPORTACCESS   ; request access to ports PORT1, PORT2
                     67: 
                     68:        mov     ax,CURSOR_H     ; address of register we want to read from
                     69:        call    ReadLoc         ; gets cursor location (H) in AL
                     70:        mov     bh,al           ; (BH) = cursor location (H)
                     71: 
                     72:        mov     ax,CURSOR_L     ; address of register we want to read from
                     73:        call    ReadLoc         ; gets cursor location (L) in AL
                     74:        mov     ah,bh           ; (AH) = cursor location (H)
                     75: 
                     76:        push    ax              ; save cursor location
                     77: ;       push    0               ; RESERVED WORD
                     78: ;       push    ACCESSREL       ; release access to port(s)
                     79: ;       push    PORT1
                     80: ;       push    PORT2
                     81: ;       call    DOSPORTACCESS   ; release access to ports PORT1, PORT2
                     82:        pop     ax              ; restore cursor location
                     83: 
                     84:        ret
                     85: _GetCurLoc     ENDP
                     86: 
                     87: ;*     ReadLoc - reads cursor location on the CRT screen
                     88: ;
                     89: ;      ENTRY   (AX) = address of register to read from
                     90: ;
                     91: ;      EXIT    (AL) = cursor location read
                     92: ;
                     93: ;      USES    AX,DX
                     94: 
                     95: ReadLoc        PROC    NEAR
                     96:        cli
                     97:        mov     dx,PORT1        ; set address we want to output to
                     98:        out     dx,al
                     99:        jmp     $+2             ; PC/AT IO delay
                    100:        mov     dx,PORT2        ; set address we want to read from
                    101:        in      al,dx           ; read cursor location
                    102:        sti
                    103:        ret
                    104: ReadLoc        ENDP
                    105: 
                    106: _TEXT2 ENDS
                    107: 
                    108: END

unix.superglobalmegacorp.com

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