home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / nor_asm / cursor30.asm < prev    next >
Assembly Source File  |  1989-06-09  |  5KB  |  175 lines

  1. CR    EQU    13            ;Carriage return
  2. LF    EQU    10            ;Line feed
  3.  
  4. .MODEL    SMALL
  5. .CODE
  6.  
  7.     PUBLIC    CLEAR_SCREEN
  8. ;-----------------------------------------------------------------------;
  9. ; This procedure clears the entire screen.                ;
  10. ;-----------------------------------------------------------------------;
  11. CLEAR_SCREEN    PROC
  12.     PUSH    AX
  13.     PUSH    BX
  14.     PUSH    CX
  15.     PUSH    DX
  16.     XOR    AL,AL            ;Blank entire window
  17.     XOR    CX,CX            ;Upper left corner is at (0,0)
  18.     MOV    DH,24            ;Bottom line of screen is line 24
  19.     MOV    DL,79            ;Right side is at column 79
  20.     MOV    BH,7            ;Use normal attribute for blanks
  21.     MOV    AH,6            ;Call for SCROLL-UP function
  22.     INT    10h            ;Clear the window
  23.     POP    DX
  24.     POP    CX
  25.     POP    BX
  26.     POP    AX
  27.     RET
  28. CLEAR_SCREEN    ENDP
  29.  
  30.  
  31.     PUBLIC    GOTO_XY
  32. .DATA
  33.     EXTRN    SCREEN_PTR:WORD        ;Pointer to character under cursor
  34.     EXTRN    SCREEN_X:BYTE, SCREEN_Y:BYTE
  35. .CODE
  36. ;-----------------------------------------------------------------------;
  37. ; This procedure moves the cursor                    ;
  38. ;                                    ;
  39. ; On entry:    DH    Row (Y)                        ;
  40. ;        DL    Column (X)                    ;
  41. ;-----------------------------------------------------------------------;
  42. GOTO_XY        PROC
  43.     PUSH    AX
  44.     PUSH    BX
  45.     MOV    BH,0            ;Display page 0
  46.     MOV    AH,2            ;Call for SET CURSOR POSITION
  47.     INT    10h
  48.  
  49.     MOV    AL,DH            ;Get the row number
  50.     MOV    BL,80            ;Multiply by 80 chars per line
  51.     MUL    BL            ;AX = row * 80
  52.     ADD    AL,DL            ;Add column
  53.     ADC    AH,0            ;AX = row * 80 + column
  54.     SHL    AX,1            ;Convert to a byte offset
  55.     MOV    SCREEN_PTR,AX        ;Save the cursor offset
  56.     MOV    SCREEN_X,DL        ;Save the cursor position
  57.     MOV    SCREEN_Y,DH
  58.     
  59.     POP    BX
  60.     POP    AX
  61.     RET
  62. GOTO_XY        ENDP
  63.  
  64.     PUBLIC    CURSOR_RIGHT
  65. .DATA
  66.     EXTRN    SCREEN_PTR:WORD        ;Pointer to character under cursor
  67.     EXTRN    SCREEN_X:BYTE, SCREEN_Y:BYTE
  68. .CODE
  69. ;-----------------------------------------------------------------------;
  70. ; This procedure moves the cursor one position to the right or to the    ;
  71. ; next line if the cursor was at the end of a line.            ;
  72. ;                                    ;
  73. ; Uses:        SEND_CRLF                        ;
  74. ; Writes:    SCREEN_PTR, SCREEN_X, SCREEN_Y                ;
  75. ;-----------------------------------------------------------------------;
  76. CURSOR_RIGHT    PROC
  77.     INC    SCREEN_PTR        ;Move to next character position (word)
  78.     INC    SCREEN_PTR
  79.     INC    SCREEN_X        ;Move to next column
  80.     CMP    SCREEN_X,79        ;Make sure column <= 79
  81.     JBE    OK
  82.     CALL    SEND_CRLF        ;Go to next line
  83. OK:
  84.     RET
  85. CURSOR_RIGHT    ENDP
  86.  
  87.     PUBLIC    UPDATE_REAL_CURSOR
  88. ;-----------------------------------------------------------------------;
  89. ; This procedure moves the real cursor to the current virtual cursor    ;
  90. ; position.  You'll want to call it just before you wait for keyboard    ;
  91. ; input.                                ;
  92. ;-----------------------------------------------------------------------;
  93. UPDATE_REAL_CURSOR    PROC
  94.     PUSH    DX
  95.     MOV    DL,SCREEN_X        ;Get position of the virtual cursor
  96.     MOV    DH,SCREEN_Y
  97.     CALL    GOTO_XY            ;Move real cursor to this position
  98.     POP    DX
  99.     RET
  100. UPDATE_REAL_CURSOR    ENDP
  101.  
  102.  
  103.     PUBLIC    UPDATE_VIRTUAL_CURSOR
  104. ;-----------------------------------------------------------------------;
  105. ; This procedure updates the position of our virtual cursor to agree    ;
  106. ; with the position of the real cursor.                    ;
  107. ;-----------------------------------------------------------------------;
  108. UPDATE_VIRTUAL_CURSOR    PROC
  109.     PUSH    AX
  110.     PUSH    BX
  111.     PUSH    CX
  112.     PUSH    DX
  113.     MOV    AH,3            ;Ask for the cursor position
  114.     XOR    BH,BH            ;On page 0
  115.     INT    10h            ;Get cursor position into DH, DL
  116.     CALL    GOTO_XY            ;Move virtual cursor to this position
  117.     POP    DX
  118.     POP    CX
  119.     POP    BX
  120.     POP    AX
  121.     RET
  122. UPDATE_VIRTUAL_CURSOR    ENDP
  123.  
  124.  
  125.     PUBLIC    CLEAR_TO_END_OF_LINE
  126. ;-----------------------------------------------------------------------;
  127. ; This procedure clears the line from the current cursor position to    ;
  128. ; the end of that line.                            ;
  129. ;-----------------------------------------------------------------------;
  130. CLEAR_TO_END_OF_LINE    PROC
  131.     PUSH    AX
  132.     PUSH    BX
  133.     PUSH    CX
  134.     PUSH    DX
  135.     MOV    DL,SCREEN_X
  136.     MOV    DH,SCREEN_Y
  137.     MOV    AH,6            ;Set up to clear to end of line
  138.     XOR    AL,AL            ;Clear window
  139.     MOV    CH,DH            ;All on same line
  140.     MOV    CL,DL            ;Start at the cursor position
  141.     MOV    DL,79            ;And stop at the end of the line
  142.     MOV    BH,7            ;Use normal attribute
  143.     INT    10h
  144.     POP    DX
  145.     POP    CX
  146.     POP    BX
  147.     POP    AX
  148.     RET
  149. CLEAR_TO_END_OF_LINE    ENDP
  150.  
  151.     PUBLIC    SEND_CRLF
  152. ;-----------------------------------------------------------------------;
  153. ; This routine just sends a carriage return-line feed pair to the    ;
  154. ; display, using the DOS routines so that scrolling will be handled    ;
  155. ; correctly.                                ;
  156. ;                                    ;
  157. ; Uses:        UPDATE_VIRTUAL_CURSOR                    ;
  158. ;-----------------------------------------------------------------------;
  159. SEND_CRLF    PROC
  160.     PUSH    AX
  161.     PUSH    DX
  162.     MOV    AH,2
  163.     MOV    DL,CR
  164.     INT    21h
  165.     MOV    DL,LF
  166.     INT    21h
  167.     CALL    UPDATE_VIRTUAL_CURSOR    ;Update position of virtual cursor
  168.     POP    DX
  169.     POP    AX
  170.     RET
  171. SEND_CRLF    ENDP
  172.  
  173.  
  174.     END
  175.