[41] | 1 | ; File name : Dialog.asm |
---|
| 2 | ; Project name : Assembly Library |
---|
| 3 | ; Created date : 6.8.2010 |
---|
[52] | 4 | ; Last update : 12.10.2010 |
---|
[41] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Common functions for many dialogs. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
| 12 | ; Dialog_DisplayWithDialogInputInDSSIandHandlerInBX |
---|
| 13 | ; Parameters: |
---|
| 14 | ; BX: Offset to menu event handler |
---|
| 15 | ; DX:AX: Optional user data |
---|
| 16 | ; DS:SI: Ptr to DIALOG_INPUT |
---|
| 17 | ; SS:BP: Ptr to parent MENU |
---|
| 18 | ; Returns: |
---|
| 19 | ; AX: Selected item |
---|
| 20 | ; Corrupts registers: |
---|
| 21 | ; BX, CX, DX, SI, DI |
---|
| 22 | ;-------------------------------------------------------------------- |
---|
| 23 | ALIGN JUMP_ALIGN |
---|
| 24 | Dialog_DisplayWithDialogInputInDSSIandHandlerInBX: |
---|
| 25 | push es |
---|
| 26 | push ds |
---|
| 27 | mov di, bp ; Backup parent MENU |
---|
[50] | 28 | mov cx, DIALOG_size |
---|
| 29 | eENTER_STRUCT cx |
---|
[41] | 30 | |
---|
[46] | 31 | call Memory_ZeroSSBPwithSizeInCX |
---|
[41] | 32 | mov [bp+DIALOG.fpDialogIO], si |
---|
| 33 | mov [bp+DIALOG.fpDialogIO+2], ds |
---|
| 34 | mov [bp+DIALOG.pParentMenu], di |
---|
| 35 | |
---|
| 36 | call MenuInit_EnterMenuWithHandlerInBXandUserDataInDXAX |
---|
| 37 | call Dialog_RemoveFromScreenByRedrawingParentMenu |
---|
| 38 | call Keyboard_RemoveAllKeystrokesFromBuffer |
---|
| 39 | |
---|
[52] | 40 | mov ax, [bp+MENUINIT.wHighlightedItem] |
---|
[41] | 41 | eLEAVE_STRUCT DIALOG_size |
---|
| 42 | pop ds |
---|
| 43 | pop es |
---|
| 44 | ret |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | ;-------------------------------------------------------------------- |
---|
| 48 | ; Dialog_EventNotHandled |
---|
| 49 | ; Parameters: |
---|
| 50 | ; BX: Menu event (anything from MENUEVENT struct) |
---|
| 51 | ; SS:BP: Ptr to DIALOG |
---|
| 52 | ; Returns: |
---|
| 53 | ; CF: Cleared since event not processed |
---|
| 54 | ; Corrupts registers: |
---|
| 55 | ; Nothing |
---|
| 56 | ;-------------------------------------------------------------------- |
---|
| 57 | ALIGN JUMP_ALIGN |
---|
| 58 | Dialog_EventNotHandled: |
---|
| 59 | clc |
---|
| 60 | ret |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | ;-------------------------------------------------------------------- |
---|
| 64 | ; Dialog_EventAnyThatClosesDialog |
---|
| 65 | ; Parameters: |
---|
| 66 | ; SS:BP: Ptr to DIALOG |
---|
| 67 | ; Returns: |
---|
| 68 | ; CF: Set since event processed |
---|
| 69 | ; Corrupts registers: |
---|
| 70 | ; Nothing |
---|
| 71 | ;-------------------------------------------------------------------- |
---|
| 72 | ALIGN JUMP_ALIGN |
---|
| 73 | Dialog_EventAnyThatClosesDialog: |
---|
| 74 | call MenuInit_CloseMenuWindow |
---|
| 75 | stc |
---|
| 76 | ret |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | ;-------------------------------------------------------------------- |
---|
[52] | 80 | ; Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX |
---|
[41] | 81 | ; Parameters: |
---|
[52] | 82 | ; AX: Index of highlighted item |
---|
[41] | 83 | ; DS:SI: Ptr to MENUINIT struct to initialize |
---|
| 84 | ; SS:BP: Ptr to DIALOG |
---|
| 85 | ; Returns: |
---|
| 86 | ; DS:SI: Ptr to initialized MENUINIT struct |
---|
| 87 | ; CF: Set since event processed |
---|
| 88 | ;-------------------------------------------------------------------- |
---|
| 89 | ALIGN JUMP_ALIGN |
---|
[52] | 90 | Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX: |
---|
[41] | 91 | les di, [bp+DIALOG.fpDialogIO] |
---|
| 92 | mov WORD [es:di+DIALOG_INPUT.fszItems], g_szSingleItem |
---|
| 93 | mov [es:di+DIALOG_INPUT.fszItems+2], cs |
---|
[52] | 94 | ; Fall to Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX |
---|
[41] | 95 | |
---|
| 96 | ;-------------------------------------------------------------------- |
---|
[52] | 97 | ; Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX |
---|
[41] | 98 | ; Parameters: |
---|
[52] | 99 | ; AX: Index of highlighted item |
---|
[41] | 100 | ; DS:SI: Ptr to MENUINIT struct to initialize |
---|
| 101 | ; SS:BP: Ptr to DIALOG |
---|
| 102 | ; Returns: |
---|
| 103 | ; DS:SI: Ptr to initialized MENUINIT struct |
---|
| 104 | ; CF: Set since event processed |
---|
| 105 | ;-------------------------------------------------------------------- |
---|
| 106 | ALIGN JUMP_ALIGN |
---|
[52] | 107 | Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX: |
---|
| 108 | mov [bp+MENUINIT.wHighlightedItem], ax |
---|
[41] | 109 | les di, [bp+DIALOG.fpDialogIO] |
---|
| 110 | call .GetWidthBasedOnParentMenuToAL |
---|
| 111 | mov [bp+MENUINIT.bWidth], al |
---|
| 112 | |
---|
| 113 | lds si, [es:di+DIALOG_INPUT.fszTitle] |
---|
[52] | 114 | call ItemLineSplitter_GetLinesToAXforStringInDSSI |
---|
[41] | 115 | mov [bp+MENUINIT.bTitleLines], al |
---|
| 116 | |
---|
| 117 | lds si, [es:di+DIALOG_INPUT.fszItems] |
---|
[52] | 118 | call ItemLineSplitter_GetLinesToAXforStringInDSSI |
---|
[41] | 119 | mov [bp+MENUINIT.wItems], ax |
---|
| 120 | |
---|
| 121 | lds si, [es:di+DIALOG_INPUT.fszInfo] |
---|
[52] | 122 | call ItemLineSplitter_GetLinesToAXforStringInDSSI |
---|
[41] | 123 | mov [bp+MENUINIT.bInfoLines], al |
---|
| 124 | |
---|
| 125 | call .GetHeightToAH ; Line counts are required |
---|
| 126 | mov [bp+MENUINIT.bHeight], ah |
---|
| 127 | stc |
---|
| 128 | ret |
---|
| 129 | |
---|
| 130 | ;-------------------------------------------------------------------- |
---|
| 131 | ; .GetWidthBasedOnParentMenuToAL |
---|
| 132 | ; Parameters: |
---|
| 133 | ; SS:BP: Ptr to DIALOG |
---|
| 134 | ; Returns: |
---|
| 135 | ; AX: Width for dialog |
---|
| 136 | ; Corrupts registers: |
---|
| 137 | ; BX |
---|
| 138 | ;-------------------------------------------------------------------- |
---|
| 139 | ALIGN JUMP_ALIGN |
---|
| 140 | .GetWidthBasedOnParentMenuToAL: |
---|
| 141 | mov bx, [bp+DIALOG.pParentMenu] |
---|
| 142 | mov al, [ss:bx+MENUINIT.bWidth] |
---|
| 143 | sub al, DIALOG_DELTA_WIDTH_FROM_PARENT |
---|
| 144 | MIN_U al, DIALOG_MAX_WIDTH |
---|
| 145 | ret |
---|
| 146 | |
---|
| 147 | ;-------------------------------------------------------------------- |
---|
| 148 | ; .GetHeightToAH |
---|
| 149 | ; Parameters: |
---|
| 150 | ; SS:BP: Ptr to DIALOG |
---|
| 151 | ; Returns: |
---|
| 152 | ; AH: Height for dialog |
---|
| 153 | ; Corrupts registers: |
---|
| 154 | ; AL, BX, DI |
---|
| 155 | ;-------------------------------------------------------------------- |
---|
| 156 | ALIGN JUMP_ALIGN |
---|
| 157 | .GetHeightToAH: |
---|
| 158 | CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH |
---|
| 159 | xchg bx, ax |
---|
| 160 | mov ah, [bp+MENUINIT.bTitleLines] |
---|
| 161 | add ah, [bp+MENUINIT.wItems] |
---|
| 162 | add ah, [bp+MENUINIT.bInfoLines] |
---|
| 163 | add ah, BYTE MENU_VERTICAL_BORDER_LINES |
---|
| 164 | MIN_U ah, bh |
---|
| 165 | MIN_U ah, DIALOG_MAX_HEIGHT |
---|
| 166 | ret |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | ;-------------------------------------------------------------------- |
---|
| 170 | ; Dialog_EventRefreshTitle |
---|
| 171 | ; Dialog_EventRefreshInformation |
---|
| 172 | ; Parameters: |
---|
| 173 | ; SS:BP: Ptr to DIALOG |
---|
| 174 | ; Returns: |
---|
| 175 | ; CF: Set since event processed |
---|
| 176 | ;-------------------------------------------------------------------- |
---|
| 177 | ALIGN JUMP_ALIGN |
---|
| 178 | Dialog_EventRefreshTitle: |
---|
| 179 | lds si, [bp+DIALOG.fpDialogIO] |
---|
[52] | 180 | lds si, [si+DIALOG_INPUT.fszTitle] |
---|
| 181 | jmp SHORT PrintTitleOrInfoLine |
---|
[41] | 182 | |
---|
| 183 | ALIGN JUMP_ALIGN |
---|
| 184 | Dialog_EventRefreshInformation: |
---|
| 185 | lds si, [bp+DIALOG.fpDialogIO] |
---|
[52] | 186 | lds si, [si+DIALOG_INPUT.fszInfo] |
---|
| 187 | ; Fall to PrintTitleOrInfoLine |
---|
[41] | 188 | |
---|
| 189 | ALIGN JUMP_ALIGN |
---|
[52] | 190 | PrintTitleOrInfoLine: |
---|
| 191 | mov bx, ds |
---|
| 192 | CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromBXSI |
---|
[41] | 193 | stc |
---|
| 194 | ret |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | ;-------------------------------------------------------------------- |
---|
| 198 | ; Dialog_EventRefreshItemFromCX |
---|
| 199 | ; Parameters: |
---|
| 200 | ; CX: Item to refresh |
---|
| 201 | ; SS:BP: Ptr to DIALOG |
---|
| 202 | ; Returns: |
---|
| 203 | ; CF: Set since event processed |
---|
| 204 | ;-------------------------------------------------------------------- |
---|
| 205 | ALIGN JUMP_ALIGN |
---|
| 206 | Dialog_EventRefreshItemFromCX: |
---|
| 207 | lds si, [bp+DIALOG.fpDialogIO] |
---|
[52] | 208 | lds si, [si+DIALOG_INPUT.fszItems] |
---|
| 209 | call ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX |
---|
| 210 | jnc SHORT .LineNotFound |
---|
| 211 | |
---|
| 212 | mov bx, ds |
---|
| 213 | CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX |
---|
| 214 | .LineNotFound: |
---|
[41] | 215 | stc |
---|
| 216 | ret |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | ;-------------------------------------------------------------------- |
---|
| 220 | ; Dialog_RemoveFromScreenByRedrawingParentMenu |
---|
| 221 | ; Parameters: |
---|
| 222 | ; SS:BP: Ptr to DIALOG |
---|
| 223 | ; Returns: |
---|
| 224 | ; Nothing |
---|
| 225 | ; Corrupts: |
---|
| 226 | ; AX, BX, CX, DX, SI, DI |
---|
| 227 | ;-------------------------------------------------------------------- |
---|
| 228 | ALIGN JUMP_ALIGN |
---|
| 229 | Dialog_RemoveFromScreenByRedrawingParentMenu: |
---|
| 230 | mov si, [bp+DIALOG.pParentMenu] ; SS:SI points to parent MENU |
---|
| 231 | call .ResetSelectionTimeoutFromParentMenuInSSSI |
---|
| 232 | call .GetParentTitleBorderCoordinatesToDX |
---|
| 233 | call MenuLocation_GetTitleBordersTopLeftCoordinatesToAX |
---|
| 234 | cmp ah, dh ; Dialog taller than parent? |
---|
| 235 | jb SHORT .RedrawDialogAreaAndWholeParentWindow |
---|
| 236 | jmp SHORT .RedrawWholeParentWindow |
---|
| 237 | |
---|
| 238 | ;-------------------------------------------------------------------- |
---|
| 239 | ; .ResetSelectionTimeoutFromParentMenuInSSSI |
---|
| 240 | ; Parameters: |
---|
| 241 | ; SS:SI: Ptr to parent MENU |
---|
| 242 | ; Returns: |
---|
| 243 | ; Nothing |
---|
| 244 | ; Corrupts: |
---|
| 245 | ; AX, BX |
---|
| 246 | ;-------------------------------------------------------------------- |
---|
| 247 | ALIGN JUMP_ALIGN |
---|
| 248 | .ResetSelectionTimeoutFromParentMenuInSSSI: |
---|
| 249 | xchg bp, si |
---|
| 250 | call MenuTime_RestartSelectionTimeout ; Restart timeout for parent MENU |
---|
| 251 | xchg si, bp |
---|
| 252 | ret |
---|
| 253 | |
---|
| 254 | ;-------------------------------------------------------------------- |
---|
| 255 | ; .GetParentTitleBorderCoordinatesToDX |
---|
| 256 | ; Parameters: |
---|
| 257 | ; SS:SI: Ptr to parent MENU |
---|
| 258 | ; SS:BP: Ptr to DIALOG |
---|
| 259 | ; Returns: |
---|
| 260 | ; DL: Parent border column (X) |
---|
| 261 | ; DH: Parent border row (Y) |
---|
| 262 | ; Corrupts: |
---|
| 263 | ; AX |
---|
| 264 | ;-------------------------------------------------------------------- |
---|
| 265 | ALIGN JUMP_ALIGN |
---|
| 266 | .GetParentTitleBorderCoordinatesToDX: |
---|
| 267 | xchg si, bp |
---|
| 268 | call MenuLocation_GetTitleBordersTopLeftCoordinatesToAX |
---|
| 269 | xchg bp, si |
---|
| 270 | xchg dx, ax |
---|
| 271 | ret |
---|
| 272 | |
---|
| 273 | ;-------------------------------------------------------------------- |
---|
| 274 | ; .RedrawDialogAreaAndWholeParentWindow |
---|
| 275 | ; .RedrawWholeParentWindow |
---|
| 276 | ; Parameters: |
---|
| 277 | ; SS:SI: Ptr to parent MENU |
---|
| 278 | ; SS:BP: Ptr to DIALOG |
---|
| 279 | ; Returns: |
---|
| 280 | ; Nothing |
---|
| 281 | ; Corrupts: |
---|
| 282 | ; AX, BX, CX, DX, SI, DI |
---|
| 283 | ;-------------------------------------------------------------------- |
---|
| 284 | ALIGN JUMP_ALIGN |
---|
| 285 | .RedrawDialogAreaAndWholeParentWindow: |
---|
[48] | 286 | push si |
---|
| 287 | call MenuBorders_AdjustDisplayContextForDrawingBorders |
---|
| 288 | pop si |
---|
[44] | 289 | mov al, SCREEN_BACKGROUND_ATTRIBUTE |
---|
[41] | 290 | CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL |
---|
| 291 | mov ax, [bp+MENUINIT.wWidthAndHeight] |
---|
| 292 | CALL_DISPLAY_LIBRARY ClearAreaWithHeightInAHandWidthInAL |
---|
| 293 | ; Fall to .RedrawWholeParentWindow |
---|
| 294 | |
---|
| 295 | ALIGN JUMP_ALIGN |
---|
| 296 | .RedrawWholeParentWindow: |
---|
| 297 | push bp |
---|
| 298 | mov bp, si |
---|
| 299 | call MenuInit_RefreshMenuWindow |
---|
| 300 | pop bp |
---|
| 301 | ret |
---|