[41] | 1 | ; File name : DisplayCursor.asm
|
---|
| 2 | ; Project name : Assembly Library
|
---|
| 3 | ; Created date : 26.6.2010
|
---|
| 4 | ; Last update : 15.7.2010
|
---|
| 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Functions for managing display cursor.
|
---|
| 7 |
|
---|
| 8 | ; Section containing code
|
---|
| 9 | SECTION .text
|
---|
| 10 |
|
---|
| 11 | ;--------------------------------------------------------------------
|
---|
| 12 | ; DisplayCursor_SetShapeFromAX
|
---|
| 13 | ; Parameters:
|
---|
| 14 | ; AX: Cursor shape (AH=Start scan line, AL=End scan line)
|
---|
| 15 | ; DS: BDA segment (zero)
|
---|
| 16 | ; Returns:
|
---|
| 17 | ; Nothing
|
---|
| 18 | ; Corrupts registers:
|
---|
| 19 | ; Nothing
|
---|
| 20 | ;--------------------------------------------------------------------
|
---|
| 21 | ALIGN JUMP_ALIGN
|
---|
| 22 | DisplayCursor_SetShapeFromAX:
|
---|
| 23 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], ax
|
---|
| 24 | ret
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | ;--------------------------------------------------------------------
|
---|
| 28 | ; DisplayCursor_SetCoordinatesFromAX
|
---|
| 29 | ; Parameters:
|
---|
| 30 | ; AL: Cursor column (X-coordinate)
|
---|
| 31 | ; AH: Cursor row (Y-coordinate)
|
---|
| 32 | ; DS: BDA segment (zero)
|
---|
| 33 | ; Returns:
|
---|
| 34 | ; DI: Offset to cursor location in video RAM
|
---|
| 35 | ; Corrupts registers:
|
---|
| 36 | ; AX, DX
|
---|
| 37 | ;--------------------------------------------------------------------
|
---|
| 38 | ALIGN JUMP_ALIGN
|
---|
| 39 | DisplayCursor_SetCoordinatesFromAX:
|
---|
| 40 | xchg dx, ax
|
---|
| 41 | call .ConvertOffsetToAXfromCoordinatesInDX
|
---|
| 42 | add ax, [VIDEO_BDA.wPageOffset] ; AX = Video RAM offset
|
---|
| 43 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
|
---|
| 44 | xchg di, ax
|
---|
| 45 | ret
|
---|
| 46 |
|
---|
| 47 | ;--------------------------------------------------------------------
|
---|
| 48 | ; .ConvertOffsetToAXfromCoordinatesInDX
|
---|
| 49 | ; Parameters:
|
---|
| 50 | ; DL: Cursor column (X-coordinate)
|
---|
| 51 | ; DH: Cursor row (Y-coordinate)
|
---|
| 52 | ; DS: BDA segment (zero)
|
---|
| 53 | ; Returns:
|
---|
| 54 | ; AX: Offset to cursor location in selected page
|
---|
| 55 | ; Corrupts registers:
|
---|
| 56 | ; Nothing
|
---|
| 57 | ;--------------------------------------------------------------------
|
---|
| 58 | ALIGN JUMP_ALIGN
|
---|
| 59 | .ConvertOffsetToAXfromCoordinatesInDX:
|
---|
| 60 | mov ax, [VIDEO_BDA.wColumns] ; Column count, 40 or 80
|
---|
| 61 | mul dh ; AX = Column count * row index
|
---|
| 62 | add al, dl ; Add column offset
|
---|
| 63 | adc ah, 0
|
---|
| 64 | shl ax, 1 ; Convert to WORD offset
|
---|
| 65 | ret
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | ;--------------------------------------------------------------------
|
---|
| 69 | ; DisplayCursor_GetSoftwareCoordinatesToAX
|
---|
| 70 | ; Parameters:
|
---|
| 71 | ; AX: Offset to cursor location in selected page
|
---|
| 72 | ; DS: BDA segment (zero)
|
---|
| 73 | ; Returns:
|
---|
| 74 | ; AL: Cursor column (X-coordinate)
|
---|
| 75 | ; AH: Cursor row (Y-coordinate)
|
---|
| 76 | ; Corrupts registers:
|
---|
| 77 | ; Nothing
|
---|
| 78 | ;--------------------------------------------------------------------
|
---|
| 79 | ALIGN JUMP_ALIGN
|
---|
| 80 | DisplayCursor_GetSoftwareCoordinatesToAX:
|
---|
| 81 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
|
---|
| 82 | sub ax, [VIDEO_BDA.wPageOffset]
|
---|
| 83 | shr ax, 1 ; WORD offset to character offset
|
---|
| 84 | div BYTE [VIDEO_BDA.wColumns] ; AL = full rows, AH = column index for last row
|
---|
| 85 | xchg al, ah
|
---|
| 86 | ret
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | ;--------------------------------------------------------------------
|
---|
| 90 | ; DisplayCursor_GetHardwareCoordinatesToAX
|
---|
| 91 | ; Parameters:
|
---|
| 92 | ; DS: BDA segment (zero)
|
---|
| 93 | ; Returns:
|
---|
| 94 | ; AL: Hardware cursor column (X-coordinate)
|
---|
| 95 | ; AH: Hardware cursor row (Y-coordinate)
|
---|
| 96 | ; Corrupts registers:
|
---|
| 97 | ; DX
|
---|
| 98 | ;--------------------------------------------------------------------
|
---|
| 99 | ALIGN JUMP_ALIGN
|
---|
| 100 | DisplayCursor_GetHardwareCoordinatesToAX:
|
---|
| 101 | push cx
|
---|
| 102 | push bx
|
---|
| 103 |
|
---|
| 104 | mov ah, GET_CURSOR_POSITION_AND_SIZE
|
---|
| 105 | mov bh, [VIDEO_BDA.bActivePage]
|
---|
| 106 | int BIOS_VIDEO_INTERRUPT_10h
|
---|
| 107 | xchg ax, dx
|
---|
| 108 |
|
---|
| 109 | pop bx
|
---|
| 110 | pop cx
|
---|
| 111 | ret
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | ;--------------------------------------------------------------------
|
---|
| 115 | ; DisplayCursor_SynchronizeShapeToHardware
|
---|
| 116 | ; Parameters:
|
---|
| 117 | ; DS: BDA segment (zero)
|
---|
| 118 | ; Returns:
|
---|
| 119 | ; Nothing
|
---|
| 120 | ; Corrupts registers:
|
---|
| 121 | ; AX, DX
|
---|
| 122 | ;--------------------------------------------------------------------
|
---|
| 123 | ALIGN JUMP_ALIGN
|
---|
| 124 | DisplayCursor_SynchronizeShapeToHardware:
|
---|
| 125 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape]
|
---|
| 126 | ; Fall to .SetHardwareCursorShapeFromDX
|
---|
| 127 |
|
---|
| 128 | ;--------------------------------------------------------------------
|
---|
| 129 | ; .SetHardwareCursorShapeFromDX
|
---|
| 130 | ; Parameters:
|
---|
| 131 | ; DX: Cursor shape
|
---|
| 132 | ; DS: BDA segment (zero)
|
---|
| 133 | ; Returns:
|
---|
| 134 | ; Nothing
|
---|
| 135 | ; Corrupts registers:
|
---|
| 136 | ; AX
|
---|
| 137 | ;--------------------------------------------------------------------
|
---|
| 138 | .SetHardwareCursorShapeFromDX:
|
---|
| 139 | cmp dx, [VIDEO_BDA.wCursorShape]
|
---|
| 140 | je SHORT .Return ; Return if no changes
|
---|
| 141 | push cx
|
---|
| 142 | mov cx, dx ; BIOS wants cursor shape in CX
|
---|
| 143 | mov al, [VIDEO_BDA.bMode] ; Load video mode to prevent lock ups on some BIOSes
|
---|
| 144 | mov ah, SET_TEXT_MODE_CURSOR_SHAPE
|
---|
| 145 | int BIOS_VIDEO_INTERRUPT_10h
|
---|
| 146 | pop cx
|
---|
| 147 | ALIGN JUMP_ALIGN, ret
|
---|
| 148 | .Return:
|
---|
| 149 | ret
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | ;--------------------------------------------------------------------
|
---|
| 153 | ; DisplayCursor_SynchronizeCoordinatesToHardware
|
---|
| 154 | ; Parameters:
|
---|
| 155 | ; DS: BDA segment (zero)
|
---|
| 156 | ; Returns:
|
---|
| 157 | ; Nothing
|
---|
| 158 | ; Corrupts registers:
|
---|
| 159 | ; AX, DX
|
---|
| 160 | ;--------------------------------------------------------------------
|
---|
| 161 | ALIGN JUMP_ALIGN
|
---|
| 162 | DisplayCursor_SynchronizeCoordinatesToHardware:
|
---|
| 163 | call DisplayCursor_GetSoftwareCoordinatesToAX
|
---|
| 164 | ; Fall to .SetHardwareCursorCoordinatesFromAX
|
---|
| 165 |
|
---|
| 166 | ;--------------------------------------------------------------------
|
---|
| 167 | ; .SetHardwareCursorCoordinatesFromAX
|
---|
| 168 | ; Parameters:
|
---|
| 169 | ; AL: Cursor column (X-coordinate)
|
---|
| 170 | ; AH: Cursor row (Y-coordinate)
|
---|
| 171 | ; DS: BDA segment (zero)
|
---|
| 172 | ; Returns:
|
---|
| 173 | ; Nothing
|
---|
| 174 | ; Corrupts registers:
|
---|
| 175 | ; AX, DX
|
---|
| 176 | ;--------------------------------------------------------------------
|
---|
| 177 | ;ALIGN JUMP_ALIGN
|
---|
| 178 | .SetHardwareCursorCoordinatesFromAX:
|
---|
| 179 | push bx
|
---|
| 180 | xchg dx, ax ; BIOS wants coordinates in DX
|
---|
| 181 | mov ah, SET_CURSOR_POSITION
|
---|
| 182 | mov bh, [VIDEO_BDA.bActivePage]
|
---|
| 183 | int BIOS_VIDEO_INTERRUPT_10h
|
---|
| 184 | pop bx
|
---|
| 185 | ret
|
---|