[57] | 1 | ; Project name : XTIDE Univeral BIOS Configurator v2 |
---|
| 2 | ; Description : Functions for loading and saving BIOS image file. |
---|
| 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 | ; BiosFile_LoadFileFromDSSItoRamBuffer |
---|
| 25 | ; Parameters: |
---|
| 26 | ; DS:SI: Name of file to open |
---|
| 27 | ; SS:BP: Menu handle |
---|
| 28 | ; Returns: |
---|
| 29 | ; Nothing |
---|
| 30 | ; Corrupts registers: |
---|
| 31 | ; AX, BX, CX, DX, SI, DI |
---|
| 32 | ;-------------------------------------------------------------------- |
---|
| 33 | ALIGN JUMP_ALIGN |
---|
| 34 | BiosFile_LoadFileFromDSSItoRamBuffer: |
---|
[621] | 35 | mov al, FILE_ACCESS.ReadOnly |
---|
| 36 | call FileIO_OpenWithPathInDSSIandFileAccessInAL |
---|
[57] | 37 | jc SHORT .DisplayErrorMessage |
---|
| 38 | |
---|
| 39 | call FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition |
---|
[621] | 40 | jc SHORT .CloseUsingHandleFromBXandDisplayErrorMessage |
---|
[57] | 41 | |
---|
[68] | 42 | cmp dx, MAX_EEPROM_SIZE_IN_BYTES >> 16 |
---|
[589] | 43 | jb SHORT .FileNotTooBig |
---|
[57] | 44 | ja SHORT .FileTooBig |
---|
[621] | 45 | %if (MAX_EEPROM_SIZE_IN_BYTES & 0FFFFh) = 0 |
---|
| 46 | test ax, ax |
---|
| 47 | jnz SHORT .FileTooBig |
---|
| 48 | %else |
---|
[68] | 49 | cmp ax, MAX_EEPROM_SIZE_IN_BYTES & 0FFFFh |
---|
| 50 | ja SHORT .FileTooBig |
---|
[621] | 51 | %endif |
---|
[68] | 52 | .FileNotTooBig: |
---|
[57] | 53 | xchg cx, ax |
---|
[621] | 54 | |
---|
| 55 | call .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer |
---|
| 56 | jc SHORT .CloseUsingHandleFromBXandDisplayErrorMessage |
---|
| 57 | |
---|
| 58 | mov al, FLG_CFGVARS_FILELOADED |
---|
| 59 | call Buffers_NewBiosWithSizeInDXCXandSourceInALhasBeenLoadedForConfiguration |
---|
| 60 | call FileIO_CloseUsingHandleFromBX |
---|
| 61 | jmp SHORT DisplayFileLoadedSuccessfully |
---|
| 62 | |
---|
[57] | 63 | .FileTooBig: |
---|
| 64 | call DisplayFileTooBig |
---|
[621] | 65 | .CloseUsingHandleFromBXandDisplayErrorMessage: |
---|
| 66 | call FileIO_CloseUsingHandleFromBX |
---|
| 67 | .DisplayErrorMessage: |
---|
| 68 | jmp SHORT DisplayFailedToLoadFile |
---|
[57] | 69 | |
---|
[621] | 70 | |
---|
[57] | 71 | ;-------------------------------------------------------------------- |
---|
[68] | 72 | ; .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer |
---|
[57] | 73 | ; Parameters: |
---|
| 74 | ; BX: File Handle |
---|
[68] | 75 | ; DX:CX: File size |
---|
[57] | 76 | ; DS:SI: File name |
---|
| 77 | ; Returns: |
---|
[293] | 78 | ; CF: Clear if successful |
---|
[57] | 79 | ; Set if error |
---|
| 80 | ; Corrupts registers: |
---|
| 81 | ; AX, SI, DI, DS |
---|
| 82 | ;-------------------------------------------------------------------- |
---|
| 83 | ALIGN JUMP_ALIGN |
---|
[68] | 84 | .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer: |
---|
[57] | 85 | push es |
---|
| 86 | |
---|
| 87 | call Buffers_GetFileBufferToESDI |
---|
| 88 | call Registers_ExchangeDSSIwithESDI |
---|
[68] | 89 | call FileIO_ReadDXCXbytesToDSSIusingHandleFromBX |
---|
[181] | 90 | jc SHORT .ReturnError |
---|
[57] | 91 | |
---|
[181] | 92 | ; Store filename to Cfgvars from ESDI |
---|
[57] | 93 | push cx |
---|
| 94 | |
---|
[621] | 95 | call Registers_CopyESDItoDSSI ; File name in DS:SI |
---|
[57] | 96 | push cs |
---|
| 97 | pop es |
---|
| 98 | mov di, g_cfgVars+CFGVARS.szOpenedFile |
---|
[592] | 99 | %ifdef CLD_NEEDED |
---|
[57] | 100 | cld |
---|
[592] | 101 | %endif |
---|
[621] | 102 | call String_CopyDSSItoESDIandGetLengthToCX ; Returns with CF cleared |
---|
[57] | 103 | |
---|
| 104 | pop cx |
---|
[181] | 105 | ALIGN JUMP_ALIGN |
---|
| 106 | .ReturnError: |
---|
[57] | 107 | pop es |
---|
| 108 | ret |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | ;-------------------------------------------------------------------- |
---|
| 112 | ; BiosFile_SaveUnsavedChanges |
---|
| 113 | ; Parameters: |
---|
| 114 | ; SS:BP: Menu handle |
---|
| 115 | ; Returns: |
---|
| 116 | ; Nothing |
---|
| 117 | ; Corrupts registers: |
---|
| 118 | ; AX, BX, CX, SI, DI |
---|
| 119 | ;-------------------------------------------------------------------- |
---|
| 120 | ALIGN JUMP_ALIGN |
---|
| 121 | BiosFile_SaveUnsavedChanges: |
---|
| 122 | push ds |
---|
| 123 | |
---|
| 124 | push cs |
---|
| 125 | pop ds |
---|
| 126 | mov si, g_cfgVars+CFGVARS.szOpenedFile |
---|
| 127 | call BiosFile_SaveRamBufferToFileInDSSI |
---|
| 128 | |
---|
| 129 | pop ds |
---|
| 130 | ret |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | ;-------------------------------------------------------------------- |
---|
| 134 | ; BiosFile_SaveRamBufferToFileInDSSI |
---|
| 135 | ; Parameters: |
---|
| 136 | ; DS:SI: Name of file to save |
---|
| 137 | ; SS:BP: Menu handle |
---|
| 138 | ; Returns: |
---|
| 139 | ; Nothing |
---|
| 140 | ; Corrupts registers: |
---|
| 141 | ; AX, BX, CX, SI, DI |
---|
| 142 | ;-------------------------------------------------------------------- |
---|
| 143 | ALIGN JUMP_ALIGN |
---|
| 144 | BiosFile_SaveRamBufferToFileInDSSI: |
---|
| 145 | push es |
---|
| 146 | |
---|
| 147 | call Buffers_GenerateChecksum |
---|
| 148 | call Buffers_GetFileBufferToESDI |
---|
[484] | 149 | call EEPROM_GetXtideUniversalBiosSizeFromESDItoDXCX |
---|
[138] | 150 | |
---|
| 151 | mov al, FILE_ACCESS.WriteOnly |
---|
| 152 | call FileIO_OpenWithPathInDSSIandFileAccessInAL |
---|
| 153 | jc SHORT .DisplayErrorMessage |
---|
| 154 | |
---|
[621] | 155 | push ds |
---|
[138] | 156 | call Registers_CopyESDItoDSSI |
---|
[68] | 157 | call FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX |
---|
[621] | 158 | pop ds |
---|
| 159 | pushf |
---|
| 160 | call FileIO_CloseUsingHandleFromBX |
---|
| 161 | popf |
---|
[57] | 162 | jc SHORT .DisplayErrorMessage |
---|
| 163 | |
---|
| 164 | call Buffers_ClearUnsavedChanges |
---|
[621] | 165 | pop es |
---|
| 166 | jmp SHORT DisplayFileSavedSuccessfully |
---|
[57] | 167 | |
---|
| 168 | .DisplayErrorMessage: |
---|
| 169 | pop es |
---|
[621] | 170 | jmp SHORT DisplayFailedToSaveFile |
---|
[57] | 171 | |
---|
| 172 | |
---|
| 173 | ;-------------------------------------------------------------------- |
---|
[293] | 174 | ; DisplayFileLoadedSuccessfully |
---|
| 175 | ; DisplayFileSavedSuccessfully |
---|
[57] | 176 | ; DisplayFailedToLoadFile |
---|
| 177 | ; DisplayFailedToSaveFile |
---|
| 178 | ; DisplayFileTooBig |
---|
| 179 | ; Parameters: |
---|
| 180 | ; SS:BP: Menu handle |
---|
| 181 | ; Returns: |
---|
| 182 | ; Nothing |
---|
| 183 | ; Corrupts registers: |
---|
| 184 | ; AX, DX |
---|
| 185 | ;-------------------------------------------------------------------- |
---|
| 186 | ALIGN JUMP_ALIGN |
---|
[293] | 187 | DisplayFileLoadedSuccessfully: |
---|
[57] | 188 | mov dx, g_szDlgMainLoadFile |
---|
| 189 | jmp Dialogs_DisplayNotificationFromCSDX |
---|
| 190 | |
---|
| 191 | ALIGN JUMP_ALIGN |
---|
[293] | 192 | DisplayFileSavedSuccessfully: |
---|
[57] | 193 | mov dx, g_szDlgMainSaveFile |
---|
| 194 | jmp Dialogs_DisplayNotificationFromCSDX |
---|
| 195 | |
---|
| 196 | DisplayFailedToLoadFile: |
---|
| 197 | mov dx, g_szDlgMainLoadErr |
---|
| 198 | jmp Dialogs_DisplayErrorFromCSDX |
---|
| 199 | |
---|
| 200 | DisplayFailedToSaveFile: |
---|
| 201 | mov dx, g_szDlgMainSaveErr |
---|
| 202 | jmp Dialogs_DisplayErrorFromCSDX |
---|
| 203 | |
---|
| 204 | DisplayFileTooBig: |
---|
| 205 | mov dx, g_szDlgMainFileTooBig |
---|
| 206 | jmp Dialogs_DisplayErrorFromCSDX |
---|