[57] | 1 | ; Project name : XTIDE Univeral BIOS Configurator v2 |
---|
| 2 | ; Description : Functions for managing EEPROM contents. |
---|
| 3 | |
---|
[65] | 4 | ; Section containing initialized data |
---|
| 5 | SECTION .data |
---|
| 6 | |
---|
| 7 | ALIGN WORD_ALIGN |
---|
| 8 | g_rgwEepromTypeToSizeInWords: |
---|
| 9 | dw (2<<10) / 2 ; EEPROM_TYPE.2816_2kiB |
---|
| 10 | dw (8<<10) / 2 |
---|
[159] | 11 | dw (8<<10) / 2 ; EEPROM_TYPE.2864_8kiB_MOD |
---|
[65] | 12 | dw (32<<10) / 2 |
---|
| 13 | dw (64<<10) / 2 |
---|
| 14 | |
---|
| 15 | g_rgwEepromPageToSizeInBytes: |
---|
| 16 | dw 1 ; EEPROM_PAGE.1_byte |
---|
| 17 | dw 2 |
---|
| 18 | dw 4 |
---|
| 19 | dw 8 |
---|
| 20 | dw 16 |
---|
| 21 | dw 32 |
---|
| 22 | dw 64 |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
[57] | 26 | ; Section containing code |
---|
| 27 | SECTION .text |
---|
| 28 | |
---|
| 29 | ;-------------------------------------------------------------------- |
---|
[118] | 30 | ; EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX |
---|
| 31 | ; Parameters: |
---|
| 32 | ; AX: Image size in WORDs |
---|
| 33 | ; Returns: |
---|
| 34 | ; CX: Required EEPROM size in WORDs |
---|
| 35 | ; CF: Set if EEPROM size found |
---|
| 36 | ; Cleared if no valid EEPROM found |
---|
| 37 | ; Corrupts registers: |
---|
| 38 | ; BX |
---|
| 39 | ;-------------------------------------------------------------------- |
---|
| 40 | ALIGN JUMP_ALIGN |
---|
| 41 | EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX: |
---|
| 42 | mov bx, g_rgwEepromTypeToSizeInWords |
---|
| 43 | mov cx, NUMBER_OF_EEPROM_TYPES |
---|
| 44 | ALIGN JUMP_ALIGN |
---|
| 45 | .CheckNextEepromSize: |
---|
| 46 | cmp ax, [cs:bx] |
---|
[138] | 47 | jbe SHORT .ReturnEepromSizeInCX |
---|
[118] | 48 | inc bx |
---|
| 49 | inc bx |
---|
| 50 | loop .CheckNextEepromSize |
---|
[145] | 51 | ret ; Return with CF cleared (none of the supported EEPROMs are large enough) |
---|
[118] | 52 | ALIGN JUMP_ALIGN |
---|
[138] | 53 | .ReturnEepromSizeInCX: |
---|
[118] | 54 | mov cx, [cs:bx] |
---|
| 55 | stc |
---|
| 56 | ret |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | ;-------------------------------------------------------------------- |
---|
[68] | 60 | ; EEPROM_LoadXtideUniversalBiosFromRomToRamBufferAndReturnSizeInDXCX |
---|
[57] | 61 | ; Parameters: |
---|
| 62 | ; Nothing |
---|
| 63 | ; Returns: |
---|
[68] | 64 | ; DX:CX: BIOS size in bytes |
---|
[57] | 65 | ; Corrupts registers: |
---|
| 66 | ; AX, BX, SI, DI |
---|
| 67 | ;-------------------------------------------------------------------- |
---|
| 68 | ALIGN JUMP_ALIGN |
---|
[68] | 69 | EEPROM_LoadXtideUniversalBiosFromRomToRamBufferAndReturnSizeInDXCX: |
---|
[57] | 70 | push es |
---|
| 71 | |
---|
| 72 | call EEPROM_FindXtideUniversalBiosROMtoESDI |
---|
[68] | 73 | call .GetXtideUniversalBiosSizeFromEStoDXCX |
---|
[57] | 74 | xor si, si ; Load from beginning of ROM |
---|
| 75 | call LoadBytesFromRomToRamBuffer |
---|
| 76 | |
---|
[68] | 77 | call .GetXtideUniversalBiosSizeFromEStoDXCX |
---|
[57] | 78 | pop es |
---|
| 79 | ret |
---|
| 80 | |
---|
| 81 | ;-------------------------------------------------------------------- |
---|
[68] | 82 | ; .GetXtideUniversalBiosSizeFromEStoDXCX |
---|
[57] | 83 | ; Parameters: |
---|
| 84 | ; Nothing |
---|
| 85 | ; Returns: |
---|
[68] | 86 | ; DX:CX: Bios size in bytes |
---|
[57] | 87 | ; Corrupts registers: |
---|
[68] | 88 | ; Nothing |
---|
[57] | 89 | ;-------------------------------------------------------------------- |
---|
| 90 | ALIGN JUMP_ALIGN |
---|
[68] | 91 | .GetXtideUniversalBiosSizeFromEStoDXCX: |
---|
| 92 | xor dx, dx |
---|
[293] | 93 | eMOVZX cx, [es:ROMVARS.bRomSize] |
---|
[57] | 94 | eSHL_IM cx, 9 ; *= 512 for byte count |
---|
| 95 | ret |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | ;-------------------------------------------------------------------- |
---|
| 99 | ; EEPROM_LoadOldSettingsFromRomToRamBuffer |
---|
| 100 | ; Parameters: |
---|
| 101 | ; Nothing |
---|
| 102 | ; Returns: |
---|
| 103 | ; CF: Set if EEPROM was found |
---|
| 104 | ; Cleared if EEPROM not found |
---|
| 105 | ; Corrupts registers: |
---|
| 106 | ; AX, BX, CX, SI, DI |
---|
| 107 | ;-------------------------------------------------------------------- |
---|
| 108 | ALIGN JUMP_ALIGN |
---|
| 109 | EEPROM_LoadOldSettingsFromRomToRamBuffer: |
---|
| 110 | mov cx, ROMVARS_size - ROMVARS.wFlags ; Number of bytes to load |
---|
| 111 | mov si, ROMVARS.wFlags ; Offset where to start loading |
---|
| 112 | ; Fall to LoadBytesFromRomToRamBuffer |
---|
| 113 | |
---|
| 114 | ;-------------------------------------------------------------------- |
---|
| 115 | ; LoadBytesFromRomToRamBuffer |
---|
| 116 | ; Parameters: |
---|
| 117 | ; CX: Number of bytes to load from ROM |
---|
| 118 | ; SI: Offset to first byte to load |
---|
| 119 | ; Returns: |
---|
| 120 | ; CF: Set if EEPROM was found |
---|
| 121 | ; Cleared if EEPROM not found |
---|
| 122 | ; Corrupts registers: |
---|
| 123 | ; AX, BX, CX, SI, DI |
---|
| 124 | ;-------------------------------------------------------------------- |
---|
| 125 | ALIGN JUMP_ALIGN |
---|
| 126 | LoadBytesFromRomToRamBuffer: |
---|
| 127 | push es |
---|
| 128 | push ds |
---|
| 129 | |
---|
| 130 | call EEPROM_FindXtideUniversalBiosROMtoESDI |
---|
| 131 | jnc SHORT .XtideUniversalBiosNotFound |
---|
| 132 | push es |
---|
| 133 | pop ds ; DS:SI points to ROM |
---|
| 134 | |
---|
| 135 | call Buffers_GetFileBufferToESDI |
---|
| 136 | mov di, si ; ES:DI points to RAM buffer |
---|
| 137 | |
---|
| 138 | cld |
---|
| 139 | call Memory_CopyCXbytesFromDSSItoESDI |
---|
| 140 | stc |
---|
| 141 | |
---|
| 142 | .XtideUniversalBiosNotFound: |
---|
| 143 | pop ds |
---|
| 144 | pop es |
---|
| 145 | ret |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | ;-------------------------------------------------------------------- |
---|
| 149 | ; EEPROM_FindXtideUniversalBiosROMtoESDI |
---|
| 150 | ; Parameters: |
---|
| 151 | ; Nothing |
---|
| 152 | ; Returns: |
---|
| 153 | ; ES:DI: EEPROM segment |
---|
| 154 | ; CF: Set if EEPROM was found |
---|
| 155 | ; Cleared if EEPROM not found |
---|
| 156 | ; Corrupts registers: |
---|
| 157 | ; AX, BX |
---|
| 158 | ;-------------------------------------------------------------------- |
---|
| 159 | ALIGN JUMP_ALIGN |
---|
| 160 | EEPROM_FindXtideUniversalBiosROMtoESDI: |
---|
| 161 | push si |
---|
| 162 | push cx |
---|
| 163 | |
---|
| 164 | xor di, di ; Zero DI (offset) |
---|
| 165 | mov bx, 0C000h ; First possible ROM segment |
---|
| 166 | ALIGN JUMP_ALIGN |
---|
| 167 | .SegmentLoop: |
---|
| 168 | mov es, bx ; Possible ROM segment to ES |
---|
| 169 | call Buffers_IsXtideUniversalBiosSignatureInESDI |
---|
| 170 | je SHORT .RomFound |
---|
[181] | 171 | add bh, 2 ; Increment by 8kB |
---|
[57] | 172 | jnc SHORT .SegmentLoop ; Loop until segment overflows |
---|
| 173 | clc |
---|
| 174 | jmp SHORT .ReturnWithoutUpdatingCF |
---|
| 175 | ALIGN JUMP_ALIGN |
---|
| 176 | .RomFound: |
---|
| 177 | stc |
---|
| 178 | .ReturnWithoutUpdatingCF: |
---|
| 179 | pop cx |
---|
| 180 | pop si |
---|
| 181 | ret |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | ;-------------------------------------------------------------------- |
---|
[65] | 185 | ; EEPROM_LoadFromRomToRamComparisonBuffer |
---|
[57] | 186 | ; Parameters: |
---|
| 187 | ; Nothing |
---|
| 188 | ; Returns: |
---|
[65] | 189 | ; Nothing |
---|
[57] | 190 | ; Corrupts registers: |
---|
[65] | 191 | ; BX, CX, SI, DI |
---|
[57] | 192 | ;-------------------------------------------------------------------- |
---|
| 193 | ALIGN JUMP_ALIGN |
---|
[65] | 194 | EEPROM_LoadFromRomToRamComparisonBuffer: |
---|
| 195 | push es |
---|
| 196 | push ds |
---|
| 197 | |
---|
| 198 | mov ds, [cs:g_cfgVars+CFGVARS.wEepromSegment] |
---|
| 199 | xor si, si |
---|
| 200 | call Buffers_GetFlashComparisonBufferToESDI |
---|
[293] | 201 | eMOVZX bx, [cs:g_cfgVars+CFGVARS.bEepromType] |
---|
[65] | 202 | mov cx, [cs:bx+g_rgwEepromTypeToSizeInWords] |
---|
| 203 | cld |
---|
| 204 | rep movsw |
---|
| 205 | |
---|
| 206 | pop ds |
---|
| 207 | pop es |
---|
[57] | 208 | ret |
---|