[3] | 1 | ; File name : menucrsr.asm
|
---|
| 2 | ; Project name : Menu library
|
---|
| 3 | ; Created date : 10.11.2009
|
---|
| 4 | ; Last update : 17.1.2010
|
---|
| 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : ASM library to menu system.
|
---|
| 7 | ; Contains menu cursor functions.
|
---|
| 8 |
|
---|
| 9 | ;--------------- Equates -----------------------------
|
---|
| 10 |
|
---|
| 11 | W_OFF_CRSR_STR EQU 0102h ; User string cursor offset
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | ;-------------- Private global variables -------------
|
---|
| 15 | ; Section containing initialized data
|
---|
| 16 | ;SECTION .data
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | ;-------------- Public functions ---------------------
|
---|
| 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; Returns X and Y coordinates for menu top left corner.
|
---|
| 25 | ; This function is used for calculating initial coordinates when
|
---|
| 26 | ; initializing menu for first time.
|
---|
| 27 | ; Parameters:
|
---|
| 28 | ; SS:BP: Ptr to MENUVARS
|
---|
| 29 | ; Returns:
|
---|
| 30 | ; DL: X coordinate for centered menu
|
---|
| 31 | ; DH: Y coordinate for centered menu
|
---|
| 32 | ; Corrupts registers:
|
---|
| 33 | ; AX, BX
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
| 35 | ALIGN JUMP_ALIGN
|
---|
| 36 | MenuCrsr_GetCenter:
|
---|
| 37 | mov ah, 0Fh ; Get Current Video Mode
|
---|
| 38 | int 10h
|
---|
| 39 | mov dl, ah ; Copy column count to DL
|
---|
| 40 | sub dl, [bp+MENUVARS.bWidth] ; Subtract menu width from columns
|
---|
| 41 | shr dl, 1 ; Divide by 2 for start X
|
---|
| 42 | mov dh, CNT_SCRN_ROW ; Load row count
|
---|
| 43 | sub dh, [bp+MENUVARS.bHeight] ; Subtract menu height from rows
|
---|
| 44 | shr dh, 1 ; Divide by 2 for start y
|
---|
| 45 | ret
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | ;--------------------------------------------------------------------
|
---|
| 49 | ; Sets cursor to start of menu string.
|
---|
| 50 | ; MenuCrsr_Point1stItem Sets cursor to first menuitem string
|
---|
| 51 | ; MenuCrsr_PointInfo Sets cursor to info string
|
---|
| 52 | ; MenuCrsr_PointTitle Sets cursor to title string
|
---|
| 53 | ; Parameters:
|
---|
| 54 | ; SS:BP: Ptr to MENUVARS
|
---|
| 55 | ; Returns:
|
---|
| 56 | ; Nothing
|
---|
| 57 | ; Corrupts registers:
|
---|
| 58 | ; AX, BX, CX, DX
|
---|
| 59 | ;--------------------------------------------------------------------
|
---|
| 60 | ALIGN JUMP_ALIGN
|
---|
| 61 | MenuCrsr_Point1stItem:
|
---|
| 62 | xor dx, dx ; Zero DX
|
---|
| 63 | call MenuCrsr_PointItemBrdr ; Point to item border (left)
|
---|
| 64 | mov cx, W_OFF_CRSR_STR & 0FFh ; Offset to user string (move X only)
|
---|
| 65 | jmp MenuCrsr_Move ; Move cursor
|
---|
| 66 | ALIGN JUMP_ALIGN
|
---|
| 67 | MenuCrsr_PointInfo:
|
---|
| 68 | xor dx, dx ; Zero DX
|
---|
| 69 | call MenuCrsr_PointNfoBrdr ; Point to Info border (top left)
|
---|
| 70 | mov cx, W_OFF_CRSR_STR ; Movement from border to user str
|
---|
| 71 | jmp MenuCrsr_Move ; Move cursor
|
---|
| 72 | ALIGN JUMP_ALIGN
|
---|
| 73 | MenuCrsr_PointTitle:
|
---|
| 74 | xor dx, dx ; Zero DX
|
---|
| 75 | call MenuCrsr_PointTitleBrdr ; Point to Title border (top left)
|
---|
| 76 | mov cx, W_OFF_CRSR_STR ; Movement from border to user str
|
---|
| 77 | jmp MenuCrsr_Move ; Move cursor
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | ;--------------------------------------------------------------------
|
---|
| 81 | ; Sets cursor to start of wanted menuitem string.
|
---|
| 82 | ;
|
---|
| 83 | ; MenuCrsr_PointNthItem
|
---|
| 84 | ; Parameters:
|
---|
| 85 | ; CX: Menuitem index where to set cursor
|
---|
| 86 | ; SS:BP: Ptr to MENUVARS
|
---|
| 87 | ; Returns:
|
---|
| 88 | ; Nothing
|
---|
| 89 | ; Corrupts registers:
|
---|
| 90 | ; AX, BX, DX
|
---|
| 91 | ;--------------------------------------------------------------------
|
---|
| 92 | ALIGN JUMP_ALIGN
|
---|
| 93 | MenuCrsr_PointNthItem:
|
---|
| 94 | push cx
|
---|
| 95 | push cx
|
---|
| 96 | call MenuCrsr_Point1stItem ; Point to topmost menuitem
|
---|
| 97 | pop cx
|
---|
| 98 | sub cx, [bp+MENUVARS.wItemTop] ; Number of newlines needed
|
---|
| 99 | jcxz .Return
|
---|
| 100 | ALIGN JUMP_ALIGN
|
---|
| 101 | .NewLineLoop:
|
---|
| 102 | call MenuDraw_NewlineStr
|
---|
| 103 | loop .NewLineLoop
|
---|
| 104 | ALIGN JUMP_ALIGN
|
---|
| 105 | .Return:
|
---|
| 106 | pop cx
|
---|
| 107 | ret
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | ;--------------------------------------------------------------------
|
---|
| 111 | ; Sets cursor to start of menu border.
|
---|
| 112 | ; MenuCrsr_PointBelowBrdr Sets cursor to below menu bottom border
|
---|
| 113 | ; MenuCrsr_PointNfoBrdr Sets cursor to top left corner of info borders
|
---|
| 114 | ; MenuCrsr_PointItemBrdr Sets cursor to first menuitem left border
|
---|
| 115 | ; MenuCrsr_PointTitleBrdr Sets cursor to top left corner of title borders
|
---|
| 116 | ; Parameters:
|
---|
| 117 | ; DX: 0
|
---|
| 118 | ; SS:BP: Ptr to MENUVARS
|
---|
| 119 | ; Returns:
|
---|
| 120 | ; Nothing
|
---|
| 121 | ; Corrupts registers:
|
---|
| 122 | ; AX, BX, DX
|
---|
| 123 | ;--------------------------------------------------------------------
|
---|
| 124 | ALIGN JUMP_ALIGN
|
---|
| 125 | MenuCrsr_PointBelowBrdr:
|
---|
| 126 | mov dh, [bp+MENUVARS.bInfoH] ; Load info height without borders
|
---|
| 127 | test dh, dh ; Info displayed?
|
---|
| 128 | jz .BottomOnly ; If not, continue
|
---|
| 129 | inc dh ; Increment Y for top border
|
---|
| 130 | ALIGN JUMP_ALIGN
|
---|
| 131 | .BottomOnly:
|
---|
| 132 | inc dh ; Increment Y for bottom border
|
---|
| 133 | ALIGN JUMP_ALIGN
|
---|
| 134 | MenuCrsr_PointNfoBrdr:
|
---|
| 135 | add dh, [bp+MENUVARS.bVisCnt] ; Load max number of visible menuitems
|
---|
| 136 | ALIGN JUMP_ALIGN
|
---|
| 137 | MenuCrsr_PointItemBrdr:
|
---|
| 138 | inc dh ; Add title top border
|
---|
| 139 | mov al, [bp+MENUVARS.bTitleH] ; Load title height
|
---|
| 140 | add dh, al ; Add title height to DH
|
---|
| 141 | test al, al ; Title visible?
|
---|
| 142 | jz MenuCrsr_PointTitleBrdr ; If not, jump to set cursor
|
---|
| 143 | inc dh ; Title bottom border
|
---|
| 144 | ALIGN JUMP_ALIGN
|
---|
| 145 | MenuCrsr_PointTitleBrdr:
|
---|
| 146 | add dx, [bp+MENUVARS.wInitCrsr] ; Add initial cursor position
|
---|
| 147 | ; Fall to MenuCrsr_SetCursor
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | ;--------------------------------------------------------------------
|
---|
| 151 | ; Sets cursor position in DX.
|
---|
| 152 | ; Parameters:
|
---|
| 153 | ; DL: Cursor X coordinate
|
---|
| 154 | ; DH: Cursor Y coordinate
|
---|
| 155 | ; Returns:
|
---|
| 156 | ; Nothing
|
---|
| 157 | ; Corrupts registers:
|
---|
| 158 | ; AX, BX
|
---|
| 159 | ;--------------------------------------------------------------------
|
---|
| 160 | ALIGN JUMP_ALIGN
|
---|
| 161 | MenuCrsr_SetCursor:
|
---|
| 162 | xor bx, bx ; Zero page
|
---|
| 163 | mov ah, 02h ; Set Cursor Position and Size
|
---|
| 164 | int 10h
|
---|
| 165 | ret
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | ;--------------------------------------------------------------------
|
---|
| 169 | ; Return cursor position in DX.
|
---|
| 170 | ; Parameters:
|
---|
| 171 | ; Nothing
|
---|
| 172 | ; Returns:
|
---|
| 173 | ; CL: Cursor start scan line
|
---|
| 174 | ; CH: Cursor end scan line
|
---|
| 175 | ; DL: Cursor X coordinate
|
---|
| 176 | ; DH: Cursor Y coordinate
|
---|
| 177 | ; Corrupts registers:
|
---|
| 178 | ; AX, BX
|
---|
| 179 | ;--------------------------------------------------------------------
|
---|
| 180 | ALIGN JUMP_ALIGN
|
---|
| 181 | MenuCrsr_GetCursor:
|
---|
| 182 | xor bx, bx ; Zero page
|
---|
| 183 | mov ah, 03h ; Get Cursor Position and Size
|
---|
| 184 | int 10h
|
---|
| 185 | ret
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | ;--------------------------------------------------------------------
|
---|
| 189 | ; Moves cursor from current location.
|
---|
| 190 | ; Parameters:
|
---|
| 191 | ; CL: Cursor X coordinate movement (can be negative)
|
---|
| 192 | ; CH: Cursor Y coordinate movement (can be negative)
|
---|
| 193 | ; Returns:
|
---|
| 194 | ; Nothing
|
---|
| 195 | ; Corrupts registers:
|
---|
| 196 | ; AX, BX, DX
|
---|
| 197 | ;--------------------------------------------------------------------
|
---|
| 198 | ALIGN JUMP_ALIGN
|
---|
| 199 | MenuCrsr_Move:
|
---|
| 200 | push cx
|
---|
| 201 | call MenuCrsr_GetCursor ; Get cursor position to DX
|
---|
| 202 | pop cx
|
---|
| 203 | add dl, cl ; Move X
|
---|
| 204 | add dh, ch ; Move Y
|
---|
| 205 | jmp MenuCrsr_SetCursor
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | ;--------------------------------------------------------------------
|
---|
| 209 | ; Shows cursor that has been hidden.
|
---|
| 210 | ; Parameters:
|
---|
| 211 | ; Nothing
|
---|
| 212 | ; Returns:
|
---|
| 213 | ; Nothing
|
---|
| 214 | ; Corrupts registers:
|
---|
| 215 | ; AX, CX
|
---|
| 216 | ;--------------------------------------------------------------------
|
---|
| 217 | ALIGN JUMP_ALIGN
|
---|
| 218 | MenuCrsr_Show:
|
---|
| 219 | mov cx, 0607h ; Two line cursor near or at the bottom of cell
|
---|
| 220 | jmp MenuCrsr_SetShape
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | ;--------------------------------------------------------------------
|
---|
| 224 | ; Hides cursor.
|
---|
| 225 | ; Parameters:
|
---|
| 226 | ; Nothing
|
---|
| 227 | ; Returns:
|
---|
| 228 | ; Nothing
|
---|
| 229 | ; Corrupts registers:
|
---|
| 230 | ; AX, CX
|
---|
| 231 | ;--------------------------------------------------------------------
|
---|
| 232 | ALIGN JUMP_ALIGN
|
---|
| 233 | MenuCrsr_Hide:
|
---|
| 234 | mov cx, 2000h
|
---|
| 235 | ; Fall to MenuCrsr_SetShape
|
---|
| 236 |
|
---|
| 237 | ;--------------------------------------------------------------------
|
---|
| 238 | ; Sets cursor shape.
|
---|
| 239 | ; Parameters:
|
---|
| 240 | ; CL: Cursor start scan line
|
---|
| 241 | ; CH: Cursor end scan line
|
---|
| 242 | ; Returns:
|
---|
| 243 | ; Nothing
|
---|
| 244 | ; Corrupts registers:
|
---|
| 245 | ; AX
|
---|
| 246 | ;--------------------------------------------------------------------
|
---|
| 247 | ALIGN JUMP_ALIGN
|
---|
| 248 | MenuCrsr_SetShape:
|
---|
| 249 | mov ax, 0103h ; Set Text-Mode Cursor Shape
|
---|
| 250 | ; AL=assumed video mode to prevent lock ups on some BIOSes
|
---|
| 251 | int 10h
|
---|
| 252 | ret
|
---|