[57] | 1 | ; Project name : XTIDE Universal BIOS Configurator v2 |
---|
| 2 | ; Description : Functions for accessing file and flash buffers. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. |
---|
| 7 | ; |
---|
| 8 | ; This program is free software; you can redistribute it and/or modify |
---|
| 9 | ; it under the terms of the GNU General Public License as published by |
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ; (at your option) any later version. |
---|
| 12 | ; |
---|
| 13 | ; This program is distributed in the hope that it will be useful, |
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ; GNU General Public License for more details. |
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
| 19 | |
---|
[57] | 20 | ; Section containing code |
---|
| 21 | SECTION .text |
---|
| 22 | |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ; Buffers_Clear |
---|
| 25 | ; Parameters: |
---|
| 26 | ; Nothing |
---|
| 27 | ; Returns: |
---|
| 28 | ; Nothing |
---|
| 29 | ; Corrupts registers: |
---|
| 30 | ; AX, CX, DI, ES |
---|
| 31 | ;-------------------------------------------------------------------- |
---|
| 32 | ALIGN JUMP_ALIGN |
---|
| 33 | Buffers_Clear: |
---|
| 34 | call Buffers_GetFileBufferToESDI |
---|
| 35 | mov cx, ROMVARS_size |
---|
| 36 | jmp Memory_ZeroESDIwithSizeInCX |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | ;-------------------------------------------------------------------- |
---|
| 40 | ; Buffers_IsXtideUniversalBiosLoaded |
---|
| 41 | ; Parameters: |
---|
| 42 | ; Nothing |
---|
| 43 | ; Returns: |
---|
| 44 | ; ZF: Set if supported version of XTIDE Universal BIOS is loaded |
---|
| 45 | ; Cleared no file or some other file is loaded |
---|
| 46 | ; Corrupts registers: |
---|
| 47 | ; CX, SI, DI, ES |
---|
| 48 | ;-------------------------------------------------------------------- |
---|
| 49 | ALIGN JUMP_ALIGN |
---|
| 50 | Buffers_IsXtideUniversalBiosLoaded: |
---|
| 51 | test WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED |
---|
| 52 | jz SHORT .NoFileOrBiosLoaded |
---|
| 53 | |
---|
| 54 | call Buffers_GetFileBufferToESDI |
---|
[68] | 55 | jmp SHORT Buffers_IsXtideUniversalBiosSignatureInESDI |
---|
[57] | 56 | .NoFileOrBiosLoaded: |
---|
| 57 | or cl, 1 ; Clear ZF |
---|
| 58 | ret |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | ;-------------------------------------------------------------------- |
---|
| 62 | ; Buffers_IsXtideUniversalBiosSignatureInESDI |
---|
| 63 | ; Parameters: |
---|
| 64 | ; ES:DI: Ptr to possible XTIDE Universal BIOS location |
---|
| 65 | ; Returns: |
---|
| 66 | ; ZF: Set if supported version of XTIDE Universal BIOS is loaded |
---|
| 67 | ; Cleared no file or some other file is loaded |
---|
| 68 | ; Corrupts registers: |
---|
| 69 | ; CX, SI |
---|
| 70 | ;-------------------------------------------------------------------- |
---|
| 71 | ALIGN JUMP_ALIGN |
---|
| 72 | Buffers_IsXtideUniversalBiosSignatureInESDI: |
---|
| 73 | push di |
---|
| 74 | |
---|
| 75 | mov si, g_szXtideUniversalBiosSignature |
---|
| 76 | add di, BYTE ROMVARS.rgbSign |
---|
| 77 | mov cx, XTIDE_SIGNATURE_LENGTH / 2 |
---|
| 78 | cld |
---|
| 79 | eSEG_STR repe, cs, cmpsw |
---|
| 80 | |
---|
| 81 | pop di |
---|
| 82 | ret |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | ;-------------------------------------------------------------------- |
---|
[145] | 86 | ; Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration |
---|
[57] | 87 | ; Parameters: |
---|
| 88 | ; AX: EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED) |
---|
[68] | 89 | ; DX:CX: EEPROM size in bytes |
---|
[57] | 90 | ; Returns: |
---|
| 91 | ; Nothing |
---|
| 92 | ; Corrupts registers: |
---|
[68] | 93 | ; AX, CX, DX |
---|
[57] | 94 | ;-------------------------------------------------------------------- |
---|
| 95 | ALIGN JUMP_ALIGN |
---|
[68] | 96 | Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration: |
---|
[57] | 97 | and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED) |
---|
| 98 | or WORD [cs:g_cfgVars+CFGVARS.wFlags], ax |
---|
[68] | 99 | shr dx, 1 |
---|
| 100 | rcr cx, 1 |
---|
[144] | 101 | adc cx, BYTE 0 ; Round up to next WORD |
---|
[65] | 102 | mov [cs:g_cfgVars+CFGVARS.wImageSizeInWords], cx |
---|
[57] | 103 | ret |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | ;-------------------------------------------------------------------- |
---|
| 107 | ; Buffers_SetUnsavedChanges |
---|
| 108 | ; Buffers_ClearUnsavedChanges |
---|
| 109 | ; Parameters: |
---|
| 110 | ; SS:BP: Menu handle |
---|
| 111 | ; Returns: |
---|
| 112 | ; Nothing |
---|
| 113 | ; Corrupts registers: |
---|
| 114 | ; Nothing |
---|
| 115 | ;-------------------------------------------------------------------- |
---|
| 116 | ALIGN JUMP_ALIGN |
---|
| 117 | Buffers_SetUnsavedChanges: |
---|
[371] | 118 | or WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED |
---|
[57] | 119 | ret |
---|
| 120 | |
---|
| 121 | ALIGN JUMP_ALIGN |
---|
| 122 | Buffers_ClearUnsavedChanges: |
---|
[371] | 123 | and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED |
---|
[57] | 124 | ret |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | ;-------------------------------------------------------------------- |
---|
[59] | 128 | ; Buffers_SaveChangesIfFileLoaded |
---|
| 129 | ; Parameters: |
---|
| 130 | ; Nothing |
---|
| 131 | ; Returns: |
---|
| 132 | ; Nothing |
---|
| 133 | ; Corrupts registers: |
---|
| 134 | ; AX, BX, CX, SI, DI |
---|
| 135 | ;-------------------------------------------------------------------- |
---|
| 136 | ALIGN JUMP_ALIGN |
---|
| 137 | Buffers_SaveChangesIfFileLoaded: |
---|
| 138 | mov ax, [cs:g_cfgVars+CFGVARS.wFlags] |
---|
| 139 | and ax, BYTE (FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED) |
---|
| 140 | cmp ax, BYTE (FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED) |
---|
| 141 | jne SHORT .NothingToSave |
---|
| 142 | call Dialogs_DisplaySaveChangesDialog |
---|
| 143 | jnz SHORT .NothingToSave |
---|
| 144 | jmp BiosFile_SaveUnsavedChanges |
---|
| 145 | ALIGN JUMP_ALIGN |
---|
| 146 | .NothingToSave: |
---|
| 147 | ret |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | ;-------------------------------------------------------------------- |
---|
[65] | 151 | ; Buffers_AppendZeroesIfNeeded |
---|
| 152 | ; Parameters: |
---|
| 153 | ; Nothing |
---|
| 154 | ; Returns: |
---|
| 155 | ; Nothing |
---|
| 156 | ; Corrupts registers: |
---|
| 157 | ; AX, CX, DI |
---|
| 158 | ;-------------------------------------------------------------------- |
---|
| 159 | ALIGN JUMP_ALIGN |
---|
| 160 | Buffers_AppendZeroesIfNeeded: |
---|
| 161 | push es |
---|
| 162 | |
---|
[293] | 163 | eMOVZX di, [cs:g_cfgVars+CFGVARS.bEepromType] |
---|
[65] | 164 | mov cx, [cs:di+g_rgwEepromTypeToSizeInWords] |
---|
| 165 | sub cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] ; CX = WORDs to append |
---|
| 166 | jle SHORT .NoNeedToAppendZeroes |
---|
| 167 | |
---|
| 168 | call Buffers_GetFileBufferToESDI |
---|
| 169 | mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] |
---|
| 170 | shl ax, 1 |
---|
| 171 | add di, ax ; ES:DI now point first unused image byte |
---|
| 172 | xor ax, ax |
---|
| 173 | cld |
---|
| 174 | rep stosw |
---|
| 175 | ALIGN JUMP_ALIGN |
---|
| 176 | .NoNeedToAppendZeroes: |
---|
| 177 | pop es |
---|
| 178 | ret |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | ;-------------------------------------------------------------------- |
---|
[57] | 182 | ; Buffers_GenerateChecksum |
---|
| 183 | ; Parameters: |
---|
| 184 | ; Nothing |
---|
| 185 | ; Returns: |
---|
| 186 | ; Nothing |
---|
| 187 | ; Corrupts registers: |
---|
| 188 | ; AX, BX, CX, DI |
---|
| 189 | ;-------------------------------------------------------------------- |
---|
| 190 | ALIGN JUMP_ALIGN |
---|
| 191 | Buffers_GenerateChecksum: |
---|
| 192 | push es |
---|
| 193 | |
---|
| 194 | call Buffers_GetFileBufferToESDI |
---|
[118] | 195 | mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] |
---|
| 196 | call EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX |
---|
[65] | 197 | shl cx, 1 ; Words to bytes |
---|
[57] | 198 | dec cx ; Leave space for checksum byte |
---|
| 199 | xor ax, ax |
---|
| 200 | ALIGN JUMP_ALIGN |
---|
| 201 | .SumNextByte: |
---|
| 202 | add al, [es:di] |
---|
| 203 | inc di |
---|
| 204 | loop .SumNextByte |
---|
| 205 | neg al |
---|
| 206 | mov [es:di], al |
---|
| 207 | |
---|
| 208 | pop es |
---|
| 209 | ret |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | ;-------------------------------------------------------------------- |
---|
[59] | 213 | ; Buffers_GetRomvarsFlagsToAX |
---|
| 214 | ; Parameters: |
---|
| 215 | ; Nothing |
---|
| 216 | ; Returns: |
---|
| 217 | ; AX: ROMVARS.wFlags |
---|
| 218 | ; Corrupts registers: |
---|
| 219 | ; BX |
---|
| 220 | ;-------------------------------------------------------------------- |
---|
| 221 | ALIGN JUMP_ALIGN |
---|
| 222 | Buffers_GetRomvarsFlagsToAX: |
---|
| 223 | mov bx, ROMVARS.wFlags |
---|
| 224 | ; Fall to Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
| 225 | |
---|
| 226 | ;-------------------------------------------------------------------- |
---|
[57] | 227 | ; Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
| 228 | ; Parameters: |
---|
| 229 | ; BX: ROMVARS offset |
---|
| 230 | ; Returns: |
---|
| 231 | ; AX: Value |
---|
| 232 | ; Corrupts registers: |
---|
| 233 | ; Nothing |
---|
| 234 | ;-------------------------------------------------------------------- |
---|
| 235 | ALIGN JUMP_ALIGN |
---|
| 236 | Buffers_GetRomvarsValueToAXfromOffsetInBX: |
---|
| 237 | push es |
---|
| 238 | push di |
---|
| 239 | call Buffers_GetFileBufferToESDI |
---|
| 240 | mov ax, [es:bx+di] |
---|
| 241 | pop di |
---|
| 242 | pop es |
---|
| 243 | ret |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | ;-------------------------------------------------------------------- |
---|
[204] | 247 | ; Buffers_GetIdeControllerCountToCX |
---|
| 248 | ; Parameters: |
---|
| 249 | ; SS:BP: Menu handle |
---|
| 250 | ; Returns: |
---|
| 251 | ; CX: Number of IDE controllers to configure |
---|
| 252 | ; ES:DI: Ptr to file buffer |
---|
| 253 | ; Corrupts registers: |
---|
| 254 | ; AX |
---|
| 255 | ;-------------------------------------------------------------------- |
---|
| 256 | ALIGN JUMP_ALIGN |
---|
| 257 | Buffers_GetIdeControllerCountToCX: |
---|
| 258 | call Buffers_GetFileBufferToESDI |
---|
| 259 | mov al, [es:di+ROMVARS.bIdeCnt] |
---|
| 260 | |
---|
| 261 | ; Limit controller count for lite mode |
---|
| 262 | test BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE |
---|
| 263 | jnz SHORT .ReturnControllerCountInCX |
---|
| 264 | MIN_U al, MAX_LITE_MODE_CONTROLLERS |
---|
| 265 | |
---|
| 266 | .ReturnControllerCountInCX: |
---|
| 267 | cbw ; A maximum of 127 controllers should be sufficient |
---|
| 268 | xchg cx, ax |
---|
| 269 | ret |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | ;-------------------------------------------------------------------- |
---|
[57] | 273 | ; Buffers_GetFileBufferToESDI |
---|
[65] | 274 | ; Buffers_GetFlashComparisonBufferToESDI |
---|
[57] | 275 | ; Buffers_GetFileDialogItemBufferToESDI |
---|
| 276 | ; Parameters: |
---|
| 277 | ; Nothing |
---|
| 278 | ; Returns: |
---|
| 279 | ; ES:DI: Ptr to file buffer |
---|
| 280 | ; Corrupts registers: |
---|
| 281 | ; Nothing |
---|
| 282 | ;-------------------------------------------------------------------- |
---|
| 283 | ALIGN JUMP_ALIGN |
---|
[65] | 284 | Buffers_GetFlashComparisonBufferToESDI: |
---|
[57] | 285 | Buffers_GetFileDialogItemBufferToESDI: |
---|
[59] | 286 | call Buffers_GetFileBufferToESDI |
---|
| 287 | push di |
---|
| 288 | mov di, es |
---|
| 289 | add di, 1000h ; Third 64k page |
---|
| 290 | mov es, di |
---|
| 291 | pop di |
---|
| 292 | ret |
---|
[65] | 293 | ALIGN JUMP_ALIGN |
---|
[57] | 294 | Buffers_GetFileBufferToESDI: |
---|
| 295 | mov di, cs |
---|
| 296 | add di, 1000h ; Change to next 64k page |
---|
| 297 | mov es, di |
---|
| 298 | xor di, di ; Ptr now in ES:DI |
---|
| 299 | ret |
---|