[57] | 1 | ; Project name : XTIDE Univeral BIOS Configurator v2 |
---|
| 2 | ; Description : Functions for loading and saving BIOS image file. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. |
---|
| 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. |
---|
| 12 | ; |
---|
| 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 |
---|
| 16 | ; GNU General Public License for more details. |
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
| 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: |
---|
| 35 | push ds |
---|
| 36 | |
---|
[68] | 37 | call .OpenFileForLoadingFromDSSIandGetSizeToDXCX |
---|
[57] | 38 | jc SHORT .DisplayErrorMessage |
---|
[68] | 39 | call .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer |
---|
[57] | 40 | jc SHORT .DisplayErrorMessage |
---|
| 41 | |
---|
| 42 | mov ax, FLG_CFGVARS_FILELOADED |
---|
[68] | 43 | call Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration |
---|
[136] | 44 | call FileIO_CloseUsingHandleFromBX |
---|
[293] | 45 | call DisplayFileLoadedSuccessfully |
---|
[57] | 46 | jmp SHORT .Return |
---|
| 47 | |
---|
| 48 | .DisplayErrorMessage: |
---|
| 49 | call FileIO_CloseUsingHandleFromBX |
---|
| 50 | call DisplayFailedToLoadFile |
---|
| 51 | ALIGN JUMP_ALIGN |
---|
| 52 | .Return: |
---|
| 53 | pop ds |
---|
| 54 | ret |
---|
| 55 | |
---|
| 56 | ;-------------------------------------------------------------------- |
---|
[68] | 57 | ; .OpenFileForLoadingFromDSSIandGetSizeInBytesToDXCX |
---|
[57] | 58 | ; Parameters: |
---|
| 59 | ; DS:SI: Name of file to open |
---|
| 60 | ; Returns: |
---|
[293] | 61 | ; BX: File handle (if successful) |
---|
| 62 | ; DX:CX: File size (if successful) |
---|
| 63 | ; CF: Clear if successful |
---|
[57] | 64 | ; Set if error |
---|
| 65 | ; Corrupts registers: |
---|
[68] | 66 | ; AX |
---|
[57] | 67 | ;-------------------------------------------------------------------- |
---|
| 68 | ALIGN JUMP_ALIGN |
---|
[68] | 69 | .OpenFileForLoadingFromDSSIandGetSizeToDXCX: |
---|
[57] | 70 | mov al, FILE_ACCESS.ReadOnly |
---|
| 71 | call FileIO_OpenWithPathInDSSIandFileAccessInAL |
---|
| 72 | jc SHORT .FileError |
---|
| 73 | call FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition |
---|
| 74 | jc SHORT .FileError |
---|
| 75 | |
---|
[68] | 76 | cmp dx, MAX_EEPROM_SIZE_IN_BYTES >> 16 |
---|
[57] | 77 | ja SHORT .FileTooBig |
---|
[68] | 78 | jb SHORT .FileNotTooBig |
---|
| 79 | cmp ax, MAX_EEPROM_SIZE_IN_BYTES & 0FFFFh |
---|
| 80 | ja SHORT .FileTooBig |
---|
| 81 | .FileNotTooBig: |
---|
[57] | 82 | xchg cx, ax |
---|
| 83 | clc |
---|
| 84 | ret |
---|
| 85 | .FileTooBig: |
---|
| 86 | call DisplayFileTooBig |
---|
| 87 | stc |
---|
| 88 | .FileError: |
---|
| 89 | ret |
---|
| 90 | |
---|
| 91 | ;-------------------------------------------------------------------- |
---|
[68] | 92 | ; .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer |
---|
[57] | 93 | ; Parameters: |
---|
| 94 | ; BX: File Handle |
---|
[68] | 95 | ; DX:CX: File size |
---|
[57] | 96 | ; DS:SI: File name |
---|
| 97 | ; Returns: |
---|
[293] | 98 | ; CF: Clear if successful |
---|
[57] | 99 | ; Set if error |
---|
| 100 | ; Corrupts registers: |
---|
| 101 | ; AX, SI, DI, DS |
---|
| 102 | ;-------------------------------------------------------------------- |
---|
| 103 | ALIGN JUMP_ALIGN |
---|
[68] | 104 | .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer: |
---|
[57] | 105 | push es |
---|
| 106 | |
---|
| 107 | call Buffers_GetFileBufferToESDI |
---|
| 108 | call Registers_ExchangeDSSIwithESDI |
---|
[68] | 109 | call FileIO_ReadDXCXbytesToDSSIusingHandleFromBX |
---|
[181] | 110 | jc SHORT .ReturnError |
---|
[57] | 111 | |
---|
[181] | 112 | ; Store filename to Cfgvars from ESDI |
---|
[57] | 113 | push cx |
---|
| 114 | |
---|
[107] | 115 | call Registers_CopyESDItoDSSI ; File name in DS:SI |
---|
[57] | 116 | push cs |
---|
| 117 | pop es |
---|
| 118 | mov di, g_cfgVars+CFGVARS.szOpenedFile |
---|
| 119 | cld |
---|
| 120 | call String_CopyDSSItoESDIandGetLengthToCX |
---|
[181] | 121 | clc |
---|
[57] | 122 | |
---|
| 123 | pop cx |
---|
[181] | 124 | ALIGN JUMP_ALIGN |
---|
| 125 | .ReturnError: |
---|
[57] | 126 | pop es |
---|
| 127 | ret |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | ;-------------------------------------------------------------------- |
---|
| 131 | ; BiosFile_SaveUnsavedChanges |
---|
| 132 | ; Parameters: |
---|
| 133 | ; SS:BP: Menu handle |
---|
| 134 | ; Returns: |
---|
| 135 | ; Nothing |
---|
| 136 | ; Corrupts registers: |
---|
| 137 | ; AX, BX, CX, SI, DI |
---|
| 138 | ;-------------------------------------------------------------------- |
---|
| 139 | ALIGN JUMP_ALIGN |
---|
| 140 | BiosFile_SaveUnsavedChanges: |
---|
| 141 | push ds |
---|
| 142 | |
---|
| 143 | push cs |
---|
| 144 | pop ds |
---|
| 145 | mov si, g_cfgVars+CFGVARS.szOpenedFile |
---|
| 146 | call BiosFile_SaveRamBufferToFileInDSSI |
---|
| 147 | |
---|
| 148 | pop ds |
---|
| 149 | ret |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | ;-------------------------------------------------------------------- |
---|
| 153 | ; BiosFile_SaveRamBufferToFileInDSSI |
---|
| 154 | ; Parameters: |
---|
| 155 | ; DS:SI: Name of file to save |
---|
| 156 | ; SS:BP: Menu handle |
---|
| 157 | ; Returns: |
---|
| 158 | ; Nothing |
---|
| 159 | ; Corrupts registers: |
---|
| 160 | ; AX, BX, CX, SI, DI |
---|
| 161 | ;-------------------------------------------------------------------- |
---|
| 162 | ALIGN JUMP_ALIGN |
---|
| 163 | BiosFile_SaveRamBufferToFileInDSSI: |
---|
| 164 | push es |
---|
| 165 | push ds |
---|
| 166 | |
---|
| 167 | call Buffers_GenerateChecksum |
---|
| 168 | call Buffers_GetFileBufferToESDI |
---|
[118] | 169 | mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] |
---|
| 170 | call EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX |
---|
[68] | 171 | xor dx, dx |
---|
[65] | 172 | shl cx, 1 |
---|
[181] | 173 | rcl dx, 1 ; WORDs to BYTEs |
---|
[138] | 174 | |
---|
| 175 | mov al, FILE_ACCESS.WriteOnly |
---|
| 176 | call FileIO_OpenWithPathInDSSIandFileAccessInAL |
---|
| 177 | jc SHORT .DisplayErrorMessage |
---|
| 178 | |
---|
| 179 | call Registers_CopyESDItoDSSI |
---|
[68] | 180 | call FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX |
---|
[57] | 181 | jc SHORT .DisplayErrorMessage |
---|
| 182 | |
---|
[136] | 183 | call FileIO_CloseUsingHandleFromBX |
---|
[57] | 184 | call Buffers_ClearUnsavedChanges |
---|
[293] | 185 | call DisplayFileSavedSuccessfully |
---|
[57] | 186 | jmp SHORT .Return |
---|
| 187 | |
---|
| 188 | .DisplayErrorMessage: |
---|
| 189 | call FileIO_CloseUsingHandleFromBX |
---|
| 190 | call DisplayFailedToSaveFile |
---|
| 191 | ALIGN JUMP_ALIGN |
---|
| 192 | .Return: |
---|
| 193 | pop ds |
---|
| 194 | pop es |
---|
| 195 | ret |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | ;-------------------------------------------------------------------- |
---|
[293] | 199 | ; DisplayFileLoadedSuccessfully |
---|
| 200 | ; DisplayFileSavedSuccessfully |
---|
[57] | 201 | ; DisplayFailedToLoadFile |
---|
| 202 | ; DisplayFailedToSaveFile |
---|
| 203 | ; DisplayFileTooBig |
---|
| 204 | ; Parameters: |
---|
| 205 | ; SS:BP: Menu handle |
---|
| 206 | ; Returns: |
---|
| 207 | ; Nothing |
---|
| 208 | ; Corrupts registers: |
---|
| 209 | ; AX, DX |
---|
| 210 | ;-------------------------------------------------------------------- |
---|
| 211 | ALIGN JUMP_ALIGN |
---|
[293] | 212 | DisplayFileLoadedSuccessfully: |
---|
[57] | 213 | mov dx, g_szDlgMainLoadFile |
---|
| 214 | jmp Dialogs_DisplayNotificationFromCSDX |
---|
| 215 | |
---|
| 216 | ALIGN JUMP_ALIGN |
---|
[293] | 217 | DisplayFileSavedSuccessfully: |
---|
[57] | 218 | mov dx, g_szDlgMainSaveFile |
---|
| 219 | jmp Dialogs_DisplayNotificationFromCSDX |
---|
| 220 | |
---|
| 221 | DisplayFailedToLoadFile: |
---|
| 222 | mov dx, g_szDlgMainLoadErr |
---|
| 223 | jmp Dialogs_DisplayErrorFromCSDX |
---|
| 224 | |
---|
| 225 | DisplayFailedToSaveFile: |
---|
| 226 | mov dx, g_szDlgMainSaveErr |
---|
| 227 | jmp Dialogs_DisplayErrorFromCSDX |
---|
| 228 | |
---|
| 229 | DisplayFileTooBig: |
---|
| 230 | mov dx, g_szDlgMainFileTooBig |
---|
| 231 | jmp Dialogs_DisplayErrorFromCSDX |
---|