[57] | 1 | ; File name : Buffers.asm |
---|
| 2 | ; Project name : XTIDE Universal BIOS Configurator v2 |
---|
| 3 | ; Created date : 6.10.2010 |
---|
| 4 | ; Last update : 10.10.2010 |
---|
| 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Functions for accessing file and flash buffers. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
| 12 | ; Buffers_Clear |
---|
| 13 | ; Parameters: |
---|
| 14 | ; Nothing |
---|
| 15 | ; Returns: |
---|
| 16 | ; Nothing |
---|
| 17 | ; Corrupts registers: |
---|
| 18 | ; AX, CX, DI, ES |
---|
| 19 | ;-------------------------------------------------------------------- |
---|
| 20 | ALIGN JUMP_ALIGN |
---|
| 21 | Buffers_Clear: |
---|
| 22 | call Buffers_GetFileBufferToESDI |
---|
| 23 | mov cx, ROMVARS_size |
---|
| 24 | jmp Memory_ZeroESDIwithSizeInCX |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | ;-------------------------------------------------------------------- |
---|
| 28 | ; Buffers_IsXtideUniversalBiosLoaded |
---|
| 29 | ; Parameters: |
---|
| 30 | ; Nothing |
---|
| 31 | ; Returns: |
---|
| 32 | ; ZF: Set if supported version of XTIDE Universal BIOS is loaded |
---|
| 33 | ; Cleared no file or some other file is loaded |
---|
| 34 | ; Corrupts registers: |
---|
| 35 | ; CX, SI, DI, ES |
---|
| 36 | ;-------------------------------------------------------------------- |
---|
| 37 | ALIGN JUMP_ALIGN |
---|
| 38 | Buffers_IsXtideUniversalBiosLoaded: |
---|
| 39 | test WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED |
---|
| 40 | jz SHORT .NoFileOrBiosLoaded |
---|
| 41 | |
---|
| 42 | call Buffers_GetFileBufferToESDI |
---|
| 43 | jmp SHORT Buffers_IsXtideUniversalBiosSignatureInESDI |
---|
| 44 | .NoFileOrBiosLoaded: |
---|
| 45 | or cl, 1 ; Clear ZF |
---|
| 46 | ret |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | ;-------------------------------------------------------------------- |
---|
| 50 | ; Buffers_IsXtideUniversalBiosSignatureInESDI |
---|
| 51 | ; Parameters: |
---|
| 52 | ; ES:DI: Ptr to possible XTIDE Universal BIOS location |
---|
| 53 | ; Returns: |
---|
| 54 | ; ZF: Set if supported version of XTIDE Universal BIOS is loaded |
---|
| 55 | ; Cleared no file or some other file is loaded |
---|
| 56 | ; Corrupts registers: |
---|
| 57 | ; CX, SI |
---|
| 58 | ;-------------------------------------------------------------------- |
---|
| 59 | ALIGN JUMP_ALIGN |
---|
| 60 | Buffers_IsXtideUniversalBiosSignatureInESDI: |
---|
| 61 | push di |
---|
| 62 | |
---|
| 63 | mov si, g_szXtideUniversalBiosSignature |
---|
| 64 | add di, BYTE ROMVARS.rgbSign |
---|
| 65 | mov cx, XTIDE_SIGNATURE_LENGTH / 2 |
---|
| 66 | cld |
---|
| 67 | eSEG_STR repe, cs, cmpsw |
---|
| 68 | |
---|
| 69 | pop di |
---|
| 70 | ret |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | ;-------------------------------------------------------------------- |
---|
| 74 | ; Buffers_NewBiosWithSizeInCXandSourceInAXhasBeenLoadedForConfiguration |
---|
| 75 | ; Parameters: |
---|
| 76 | ; AX: EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED) |
---|
| 77 | ; CX: EEPROM size in bytes |
---|
| 78 | ; Returns: |
---|
| 79 | ; Nothing |
---|
| 80 | ; Corrupts registers: |
---|
| 81 | ; AX, BX, CX, DX |
---|
| 82 | ;-------------------------------------------------------------------- |
---|
| 83 | ALIGN JUMP_ALIGN |
---|
| 84 | Buffers_NewBiosWithSizeInCXandSourceInAXhasBeenLoadedForConfiguration: |
---|
| 85 | and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED) |
---|
| 86 | or WORD [cs:g_cfgVars+CFGVARS.wFlags], ax |
---|
| 87 | ; Fall to .AdjustBiosImageSizeToSupportedEepromSize |
---|
| 88 | |
---|
| 89 | ;-------------------------------------------------------------------- |
---|
| 90 | ; .AdjustBiosImageSizeInCXtoSupportedEepromSize |
---|
| 91 | ; Parameters: |
---|
| 92 | ; CX: Size of loaded BIOS image |
---|
| 93 | ; Returns: |
---|
| 94 | ; CX: Size of BIOS image (and EEPROM required) |
---|
| 95 | ; Corrupts registers: |
---|
| 96 | ; AX, BX, DX |
---|
| 97 | ;-------------------------------------------------------------------- |
---|
| 98 | .AdjustBiosImageSizeInCXtoSupportedEepromSize: |
---|
| 99 | mov bx, .rgwSupportedEepromSizes |
---|
| 100 | mov dx, NUMBER_OF_SUPPORTED_EEPROM_SIZES-1 |
---|
| 101 | ALIGN JUMP_ALIGN |
---|
| 102 | .CheckNextEepromSize: |
---|
| 103 | cmp cx, [cs:bx] |
---|
| 104 | je SHORT .StoreImageSizeFromCX |
---|
| 105 | jb SHORT .AppendZeroesToTheEndOfBuffer |
---|
| 106 | inc bx |
---|
| 107 | inc bx |
---|
| 108 | dec dx |
---|
| 109 | jnz SHORT .CheckNextEepromSize |
---|
| 110 | xor cx, cx |
---|
| 111 | jmp SHORT .StoreImageSizeFromCX ; 0 = 65536 |
---|
| 112 | ALIGN WORD_ALIGN |
---|
| 113 | .rgwSupportedEepromSizes: |
---|
| 114 | dw 4<<10 |
---|
| 115 | dw 8<<10 |
---|
| 116 | dw 16<<10 |
---|
| 117 | dw 32<<10 |
---|
| 118 | |
---|
| 119 | ;-------------------------------------------------------------------- |
---|
| 120 | ; .AppendZeroesToTheEndOfBuffer |
---|
| 121 | ; Parameters: |
---|
| 122 | ; CX: Size of loaded BIOS image |
---|
| 123 | ; CS:BX: Ptr to EEPROM size |
---|
| 124 | ; Returns: |
---|
| 125 | ; CX: EEPROM size |
---|
| 126 | ; Corrupts registers: |
---|
| 127 | ; AX |
---|
| 128 | ;-------------------------------------------------------------------- |
---|
| 129 | ALIGN JUMP_ALIGN |
---|
| 130 | .AppendZeroesToTheEndOfBuffer: |
---|
| 131 | push es |
---|
| 132 | push di |
---|
| 133 | |
---|
| 134 | call Buffers_GetFileBufferToESDI |
---|
| 135 | mov ax, [cs:bx] |
---|
| 136 | sub ax, cx ; AX = zeroes to append |
---|
| 137 | xchg ax, cx ; AX = BIOS image size, CX = zeroes to append |
---|
| 138 | add di, ax |
---|
| 139 | call Memory_ZeroESDIwithSizeInCX |
---|
| 140 | mov cx, [cs:bx] |
---|
| 141 | |
---|
| 142 | pop di |
---|
| 143 | pop es |
---|
| 144 | ; Fall to .StoreImageSizeFromCX |
---|
| 145 | |
---|
| 146 | ;-------------------------------------------------------------------- |
---|
| 147 | ; .StoreImageSizeFromCX |
---|
| 148 | ; Parameters: |
---|
| 149 | ; CX: Size of BIOS image (and EEPROM required) |
---|
| 150 | ; Returns: |
---|
| 151 | ; Nothing |
---|
| 152 | ; Corrupts registers: |
---|
| 153 | ; Nothing |
---|
| 154 | ;-------------------------------------------------------------------- |
---|
| 155 | ALIGN JUMP_ALIGN |
---|
| 156 | .StoreImageSizeFromCX: |
---|
| 157 | mov [cs:g_cfgVars+CFGVARS.wImageSize], cx |
---|
| 158 | ret |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | ;-------------------------------------------------------------------- |
---|
| 162 | ; Buffers_SetUnsavedChanges |
---|
| 163 | ; Buffers_ClearUnsavedChanges |
---|
| 164 | ; Parameters: |
---|
| 165 | ; SS:BP: Menu handle |
---|
| 166 | ; Returns: |
---|
| 167 | ; Nothing |
---|
| 168 | ; Corrupts registers: |
---|
| 169 | ; Nothing |
---|
| 170 | ;-------------------------------------------------------------------- |
---|
| 171 | ALIGN JUMP_ALIGN |
---|
| 172 | Buffers_SetUnsavedChanges: |
---|
| 173 | or WORD [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED |
---|
| 174 | ret |
---|
| 175 | |
---|
| 176 | ALIGN JUMP_ALIGN |
---|
| 177 | Buffers_ClearUnsavedChanges: |
---|
| 178 | and WORD [g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED |
---|
| 179 | ret |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | ;-------------------------------------------------------------------- |
---|
| 183 | ; Buffers_GenerateChecksum |
---|
| 184 | ; Parameters: |
---|
| 185 | ; Nothing |
---|
| 186 | ; Returns: |
---|
| 187 | ; Nothing |
---|
| 188 | ; Corrupts registers: |
---|
| 189 | ; AX, BX, CX, DI |
---|
| 190 | ;-------------------------------------------------------------------- |
---|
| 191 | ALIGN JUMP_ALIGN |
---|
| 192 | Buffers_GenerateChecksum: |
---|
| 193 | push es |
---|
| 194 | |
---|
| 195 | call Buffers_GetFileBufferToESDI |
---|
| 196 | mov cx, [cs:g_cfgVars+CFGVARS.wImageSize] |
---|
| 197 | dec cx ; Leave space for checksum byte |
---|
| 198 | xor ax, ax |
---|
| 199 | ALIGN JUMP_ALIGN |
---|
| 200 | .SumNextByte: |
---|
| 201 | add al, [es:di] |
---|
| 202 | inc di |
---|
| 203 | loop .SumNextByte |
---|
| 204 | neg al |
---|
| 205 | mov [es:di], al |
---|
| 206 | |
---|
| 207 | pop es |
---|
| 208 | ret |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | ;-------------------------------------------------------------------- |
---|
| 212 | ; Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
| 213 | ; Parameters: |
---|
| 214 | ; BX: ROMVARS offset |
---|
| 215 | ; Returns: |
---|
| 216 | ; AX: Value |
---|
| 217 | ; Corrupts registers: |
---|
| 218 | ; Nothing |
---|
| 219 | ;-------------------------------------------------------------------- |
---|
| 220 | ALIGN JUMP_ALIGN |
---|
| 221 | Buffers_GetRomvarsValueToAXfromOffsetInBX: |
---|
| 222 | push es |
---|
| 223 | push di |
---|
| 224 | call Buffers_GetFileBufferToESDI |
---|
| 225 | mov ax, [es:bx+di] |
---|
| 226 | pop di |
---|
| 227 | pop es |
---|
| 228 | ret |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | ;-------------------------------------------------------------------- |
---|
| 232 | ; Buffers_GetFileBufferToESDI |
---|
| 233 | ; Buffers_GetFileDialogItemBufferToESDI |
---|
| 234 | ; Parameters: |
---|
| 235 | ; Nothing |
---|
| 236 | ; Returns: |
---|
| 237 | ; ES:DI: Ptr to file buffer |
---|
| 238 | ; Corrupts registers: |
---|
| 239 | ; Nothing |
---|
| 240 | ;-------------------------------------------------------------------- |
---|
| 241 | ALIGN JUMP_ALIGN |
---|
| 242 | Buffers_GetFileDialogItemBufferToESDI: |
---|
| 243 | Buffers_GetFileBufferToESDI: |
---|
| 244 | mov di, cs |
---|
| 245 | add di, 1000h ; Change to next 64k page |
---|
| 246 | mov es, di |
---|
| 247 | xor di, di ; Ptr now in ES:DI |
---|
| 248 | ret |
---|