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