[57] | 1 | ; Project name : XTIDE Universal BIOS Configurator v2 |
---|
| 2 | ; Description : Functions for accessing file and flash buffers. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team. |
---|
[376] | 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. |
---|
[526] | 12 | ; |
---|
[376] | 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 |
---|
[526] | 16 | ; GNU General Public License for more details. |
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
[526] | 18 | ; |
---|
[376] | 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 |
---|
[567] | 45 | ; Cleared if no file or some other file is loaded |
---|
[57] | 46 | ; Corrupts registers: |
---|
| 47 | ; CX, SI, DI, ES |
---|
| 48 | ;-------------------------------------------------------------------- |
---|
| 49 | ALIGN JUMP_ALIGN |
---|
| 50 | Buffers_IsXtideUniversalBiosLoaded: |
---|
[592] | 51 | test BYTE [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED |
---|
[567] | 52 | jnz SHORT .FileOrBiosLoaded |
---|
[592] | 53 | test sp, sp ; Clear ZF |
---|
[57] | 54 | ret |
---|
| 55 | |
---|
[567] | 56 | .FileOrBiosLoaded: |
---|
| 57 | call Buffers_GetFileBufferToESDI |
---|
| 58 | ; Fall to Buffers_IsXtideUniversalBiosSignatureInESDI |
---|
[57] | 59 | |
---|
[567] | 60 | |
---|
[57] | 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 |
---|
[567] | 67 | ; Cleared if no file or some other file is loaded |
---|
[57] | 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 |
---|
[592] | 78 | %ifdef CLD_NEEDED |
---|
[57] | 79 | cld |
---|
[592] | 80 | %endif |
---|
[57] | 81 | eSEG_STR repe, cs, cmpsw |
---|
| 82 | |
---|
| 83 | pop di |
---|
| 84 | ret |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | ;-------------------------------------------------------------------- |
---|
[457] | 88 | ; Buffers_IsXTbuildLoaded |
---|
| 89 | ; Parameters: |
---|
| 90 | ; Nothing |
---|
| 91 | ; Returns: |
---|
| 92 | ; ZF: Set if XT or XT+ build is loaded |
---|
| 93 | ; Cleared if some other (AT, 386) build is loaded |
---|
| 94 | ; Corrupts registers: |
---|
[592] | 95 | ; Nothing |
---|
[457] | 96 | ;-------------------------------------------------------------------- |
---|
| 97 | ALIGN JUMP_ALIGN |
---|
| 98 | Buffers_IsXTbuildLoaded: |
---|
| 99 | %strlen BUILD_TYPE_OFFSET TITLE_STRING_START |
---|
[592] | 100 | push es |
---|
| 101 | push di |
---|
[457] | 102 | call Buffers_GetFileBufferToESDI |
---|
| 103 | cmp WORD [es:di+ROMVARS.szTitle+BUILD_TYPE_OFFSET+1], 'XT' ; +1 is for '(' |
---|
[592] | 104 | pop di |
---|
| 105 | pop es |
---|
[457] | 106 | ret |
---|
| 107 | %undef BUILD_TYPE_OFFSET |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | ;-------------------------------------------------------------------- |
---|
[145] | 111 | ; Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration |
---|
[57] | 112 | ; Parameters: |
---|
[592] | 113 | ; AL: EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED) |
---|
[68] | 114 | ; DX:CX: EEPROM size in bytes |
---|
[57] | 115 | ; Returns: |
---|
| 116 | ; Nothing |
---|
| 117 | ; Corrupts registers: |
---|
[592] | 118 | ; CX, DX |
---|
[57] | 119 | ;-------------------------------------------------------------------- |
---|
| 120 | ALIGN JUMP_ALIGN |
---|
[68] | 121 | Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration: |
---|
[592] | 122 | and BYTE [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED) |
---|
| 123 | or [cs:g_cfgVars+CFGVARS.wFlags], al |
---|
[68] | 124 | shr dx, 1 |
---|
| 125 | rcr cx, 1 |
---|
[144] | 126 | adc cx, BYTE 0 ; Round up to next WORD |
---|
[65] | 127 | mov [cs:g_cfgVars+CFGVARS.wImageSizeInWords], cx |
---|
[57] | 128 | ret |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | ;-------------------------------------------------------------------- |
---|
| 132 | ; Buffers_SetUnsavedChanges |
---|
| 133 | ; Buffers_ClearUnsavedChanges |
---|
| 134 | ; Parameters: |
---|
| 135 | ; SS:BP: Menu handle |
---|
| 136 | ; Returns: |
---|
| 137 | ; Nothing |
---|
| 138 | ; Corrupts registers: |
---|
| 139 | ; Nothing |
---|
| 140 | ;-------------------------------------------------------------------- |
---|
| 141 | ALIGN JUMP_ALIGN |
---|
| 142 | Buffers_SetUnsavedChanges: |
---|
[592] | 143 | or BYTE [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED |
---|
[57] | 144 | ret |
---|
| 145 | |
---|
| 146 | ALIGN JUMP_ALIGN |
---|
| 147 | Buffers_ClearUnsavedChanges: |
---|
[592] | 148 | and BYTE [cs:g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED |
---|
[57] | 149 | ret |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | ;-------------------------------------------------------------------- |
---|
[59] | 153 | ; Buffers_SaveChangesIfFileLoaded |
---|
| 154 | ; Parameters: |
---|
| 155 | ; Nothing |
---|
| 156 | ; Returns: |
---|
| 157 | ; Nothing |
---|
| 158 | ; Corrupts registers: |
---|
| 159 | ; AX, BX, CX, SI, DI |
---|
| 160 | ;-------------------------------------------------------------------- |
---|
| 161 | ALIGN JUMP_ALIGN |
---|
| 162 | Buffers_SaveChangesIfFileLoaded: |
---|
[592] | 163 | mov al, [cs:g_cfgVars+CFGVARS.wFlags] |
---|
| 164 | and al, FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED |
---|
| 165 | jz SHORT .NothingToSave |
---|
| 166 | jpo SHORT .NothingToSave |
---|
| 167 | mov bx, g_szDlgSaveChanges |
---|
| 168 | call Dialogs_DisplayYesNoResponseDialogWithTitleStringInBX |
---|
[59] | 169 | jnz SHORT .NothingToSave |
---|
| 170 | jmp BiosFile_SaveUnsavedChanges |
---|
| 171 | ALIGN JUMP_ALIGN |
---|
| 172 | .NothingToSave: |
---|
| 173 | ret |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | ;-------------------------------------------------------------------- |
---|
[65] | 177 | ; Buffers_AppendZeroesIfNeeded |
---|
| 178 | ; Parameters: |
---|
| 179 | ; Nothing |
---|
| 180 | ; Returns: |
---|
| 181 | ; Nothing |
---|
| 182 | ; Corrupts registers: |
---|
| 183 | ; AX, CX, DI |
---|
| 184 | ;-------------------------------------------------------------------- |
---|
| 185 | ALIGN JUMP_ALIGN |
---|
| 186 | Buffers_AppendZeroesIfNeeded: |
---|
| 187 | push es |
---|
| 188 | |
---|
[293] | 189 | eMOVZX di, [cs:g_cfgVars+CFGVARS.bEepromType] |
---|
[594] | 190 | mov cx, [cs:di+g_rgwEepromTypeToSizeInWords] |
---|
[65] | 191 | sub cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] ; CX = WORDs to append |
---|
[567] | 192 | jbe SHORT .NoNeedToAppendZeroes |
---|
[65] | 193 | |
---|
| 194 | call Buffers_GetFileBufferToESDI |
---|
| 195 | mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] |
---|
[592] | 196 | eSHL_IM ax, 1 |
---|
[65] | 197 | add di, ax ; ES:DI now point first unused image byte |
---|
| 198 | xor ax, ax |
---|
[592] | 199 | %ifdef CLD_NEEDED |
---|
[65] | 200 | cld |
---|
[592] | 201 | %endif |
---|
[65] | 202 | rep stosw |
---|
| 203 | ALIGN JUMP_ALIGN |
---|
| 204 | .NoNeedToAppendZeroes: |
---|
| 205 | pop es |
---|
| 206 | ret |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | ;-------------------------------------------------------------------- |
---|
[57] | 210 | ; Buffers_GenerateChecksum |
---|
| 211 | ; Parameters: |
---|
| 212 | ; Nothing |
---|
| 213 | ; Returns: |
---|
| 214 | ; Nothing |
---|
| 215 | ; Corrupts registers: |
---|
| 216 | ; AX, BX, CX, DI |
---|
| 217 | ;-------------------------------------------------------------------- |
---|
| 218 | ALIGN JUMP_ALIGN |
---|
| 219 | Buffers_GenerateChecksum: |
---|
| 220 | push es |
---|
[484] | 221 | push dx |
---|
[57] | 222 | |
---|
| 223 | call Buffers_GetFileBufferToESDI |
---|
[484] | 224 | call EEPROM_GetXtideUniversalBiosSizeFromESDItoDXCX |
---|
[592] | 225 | %ifdef CLD_NEEDED |
---|
| 226 | cld |
---|
| 227 | %endif |
---|
[589] | 228 | |
---|
| 229 | ; Compatibility fix for 3Com 3C503 cards where the ASIC returns 8080h as the last two bytes of the ROM. |
---|
| 230 | |
---|
| 231 | ; Assume the BIOS size is not 8K, ie generate a normal checksum. |
---|
| 232 | dec cx |
---|
| 233 | mov ax, 100h |
---|
| 234 | cmp cx, 8192 - 1 |
---|
| 235 | jne SHORT .BiosSizeIsNot8K |
---|
| 236 | ; The BIOS size is 8K and therefore a potential candidate for a 3Com 3C503 card. |
---|
[592] | 237 | mov cl, (8192 - 3) & 0FFh |
---|
[589] | 238 | mov ah, 3 |
---|
[57] | 239 | ALIGN JUMP_ALIGN |
---|
[589] | 240 | .BiosSizeIsNot8K: |
---|
[57] | 241 | .SumNextByte: |
---|
| 242 | add al, [es:di] |
---|
| 243 | inc di |
---|
| 244 | loop .SumNextByte |
---|
[592] | 245 | .NextChecksumByte: |
---|
[57] | 246 | neg al |
---|
[592] | 247 | stosb |
---|
[589] | 248 | dec ah |
---|
| 249 | jnz SHORT .NextChecksumByte |
---|
[57] | 250 | |
---|
[484] | 251 | pop dx |
---|
[57] | 252 | pop es |
---|
| 253 | ret |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | ;-------------------------------------------------------------------- |
---|
[59] | 257 | ; Buffers_GetRomvarsFlagsToAX |
---|
| 258 | ; Parameters: |
---|
| 259 | ; Nothing |
---|
| 260 | ; Returns: |
---|
| 261 | ; AX: ROMVARS.wFlags |
---|
| 262 | ; Corrupts registers: |
---|
| 263 | ; BX |
---|
| 264 | ;-------------------------------------------------------------------- |
---|
| 265 | ALIGN JUMP_ALIGN |
---|
| 266 | Buffers_GetRomvarsFlagsToAX: |
---|
| 267 | mov bx, ROMVARS.wFlags |
---|
| 268 | ; Fall to Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
| 269 | |
---|
| 270 | ;-------------------------------------------------------------------- |
---|
[57] | 271 | ; Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
| 272 | ; Parameters: |
---|
| 273 | ; BX: ROMVARS offset |
---|
| 274 | ; Returns: |
---|
| 275 | ; AX: Value |
---|
| 276 | ; Corrupts registers: |
---|
| 277 | ; Nothing |
---|
| 278 | ;-------------------------------------------------------------------- |
---|
| 279 | ALIGN JUMP_ALIGN |
---|
| 280 | Buffers_GetRomvarsValueToAXfromOffsetInBX: |
---|
| 281 | push es |
---|
| 282 | push di |
---|
| 283 | call Buffers_GetFileBufferToESDI |
---|
| 284 | mov ax, [es:bx+di] |
---|
| 285 | pop di |
---|
| 286 | pop es |
---|
| 287 | ret |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | ;-------------------------------------------------------------------- |
---|
[204] | 291 | ; Buffers_GetIdeControllerCountToCX |
---|
| 292 | ; Parameters: |
---|
| 293 | ; SS:BP: Menu handle |
---|
| 294 | ; Returns: |
---|
| 295 | ; CX: Number of IDE controllers to configure |
---|
| 296 | ; ES:DI: Ptr to file buffer |
---|
| 297 | ; Corrupts registers: |
---|
[589] | 298 | ; Nothing |
---|
[204] | 299 | ;-------------------------------------------------------------------- |
---|
| 300 | ALIGN JUMP_ALIGN |
---|
| 301 | Buffers_GetIdeControllerCountToCX: |
---|
[589] | 302 | xor cx, cx |
---|
[204] | 303 | call Buffers_GetFileBufferToESDI |
---|
[589] | 304 | or cl, [es:di+ROMVARS.bIdeCnt] |
---|
| 305 | jnz SHORT .LimitControllerCountForLiteMode |
---|
| 306 | inc cx ; Make sure there is at least one controller |
---|
[204] | 307 | |
---|
[589] | 308 | .LimitControllerCountForLiteMode: |
---|
[204] | 309 | test BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE |
---|
| 310 | jnz SHORT .ReturnControllerCountInCX |
---|
[589] | 311 | MIN_U cl, MAX_LITE_MODE_CONTROLLERS |
---|
[204] | 312 | |
---|
| 313 | .ReturnControllerCountInCX: |
---|
| 314 | ret |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | ;-------------------------------------------------------------------- |
---|
[65] | 318 | ; Buffers_GetFlashComparisonBufferToESDI |
---|
[57] | 319 | ; Buffers_GetFileDialogItemBufferToESDI |
---|
[592] | 320 | ; Buffers_GetFileBufferToESDI |
---|
[57] | 321 | ; Parameters: |
---|
| 322 | ; Nothing |
---|
| 323 | ; Returns: |
---|
| 324 | ; ES:DI: Ptr to file buffer |
---|
| 325 | ; Corrupts registers: |
---|
| 326 | ; Nothing |
---|
| 327 | ;-------------------------------------------------------------------- |
---|
| 328 | ALIGN JUMP_ALIGN |
---|
[65] | 329 | Buffers_GetFlashComparisonBufferToESDI: |
---|
[57] | 330 | Buffers_GetFileDialogItemBufferToESDI: |
---|
[59] | 331 | call Buffers_GetFileBufferToESDI |
---|
| 332 | mov di, es |
---|
[592] | 333 | SKIP2B f |
---|
[57] | 334 | Buffers_GetFileBufferToESDI: |
---|
| 335 | mov di, cs |
---|
| 336 | add di, 1000h ; Change to next 64k page |
---|
| 337 | mov es, di |
---|
| 338 | xor di, di ; Ptr now in ES:DI |
---|
| 339 | ret |
---|