source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm @ 371

Last change on this file since 371 was 371, checked in by gregli@…, 12 years ago

Small changes. 1) Changes biosdrvs.com to output CR+LF instead of LF+CR, consistent with DOS/Windows, but I did not update the Assembly Library as this would break the Configurator; 2) Put a C/C++ section in Version.inc for the serial server; 3) Configurator defaults the EEPROM address after scanning for a EEPROM in memory (as it does for loading the BIOS from ROM); 4) Added a command to the Configurator main menu to save chages to the file from which it was loaded (if it was loaded form a file), which is symmetric with the Load command and more discoverable than exiting DOS and then being prompted (which is still there too, if changes are unsaved).

File size: 7.6 KB
Line 
1; Project name  :   XTIDE Universal BIOS Configurator v2
2; Description   :   Functions for accessing file and flash buffers.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Buffers_Clear
9;   Parameters:
10;       Nothing
11;   Returns:
12;       Nothing
13;   Corrupts registers:
14;       AX, CX, DI, ES
15;--------------------------------------------------------------------
16ALIGN JUMP_ALIGN
17Buffers_Clear:
18    call    Buffers_GetFileBufferToESDI
19    mov     cx, ROMVARS_size
20    jmp     Memory_ZeroESDIwithSizeInCX
21
22
23;--------------------------------------------------------------------
24; Buffers_IsXtideUniversalBiosLoaded
25;   Parameters:
26;       Nothing
27;   Returns:
28;       ZF:     Set if supported version of XTIDE Universal BIOS is loaded
29;               Cleared no file or some other file is loaded
30;   Corrupts registers:
31;       CX, SI, DI, ES
32;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34Buffers_IsXtideUniversalBiosLoaded:
35    test    WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED
36    jz      SHORT .NoFileOrBiosLoaded
37
38    call    Buffers_GetFileBufferToESDI
39    jmp     SHORT Buffers_IsXtideUniversalBiosSignatureInESDI
40.NoFileOrBiosLoaded:
41    or      cl, 1       ; Clear ZF
42    ret
43
44
45;--------------------------------------------------------------------
46; Buffers_IsXtideUniversalBiosSignatureInESDI
47;   Parameters:
48;       ES:DI:  Ptr to possible XTIDE Universal BIOS location
49;   Returns:
50;       ZF:     Set if supported version of XTIDE Universal BIOS is loaded
51;               Cleared no file or some other file is loaded
52;   Corrupts registers:
53;       CX, SI
54;--------------------------------------------------------------------
55ALIGN JUMP_ALIGN
56Buffers_IsXtideUniversalBiosSignatureInESDI:
57    push    di
58
59    mov     si, g_szXtideUniversalBiosSignature
60    add     di, BYTE ROMVARS.rgbSign
61    mov     cx, XTIDE_SIGNATURE_LENGTH / 2
62    cld
63    eSEG_STR repe, cs, cmpsw
64
65    pop     di
66    ret
67
68
69;--------------------------------------------------------------------
70; Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration
71;   Parameters:
72;       AX:     EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED)
73;       DX:CX:  EEPROM size in bytes
74;   Returns:
75;       Nothing
76;   Corrupts registers:
77;       AX, CX, DX
78;--------------------------------------------------------------------
79ALIGN JUMP_ALIGN
80Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration:
81    and     WORD [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED)
82    or      WORD [cs:g_cfgVars+CFGVARS.wFlags], ax
83    shr     dx, 1
84    rcr     cx, 1
85    adc     cx, BYTE 0      ; Round up to next WORD
86    mov     [cs:g_cfgVars+CFGVARS.wImageSizeInWords], cx
87    ret
88
89
90;--------------------------------------------------------------------
91; Buffers_SetUnsavedChanges
92; Buffers_ClearUnsavedChanges
93;   Parameters:
94;       SS:BP:  Menu handle
95;   Returns:
96;       Nothing
97;   Corrupts registers:
98;       Nothing
99;--------------------------------------------------------------------
100ALIGN JUMP_ALIGN
101Buffers_SetUnsavedChanges:
102    or      WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED
103    ret
104
105ALIGN JUMP_ALIGN
106Buffers_ClearUnsavedChanges:
107    and     WORD [cs:g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED
108    ret
109
110
111;--------------------------------------------------------------------
112; Buffers_SaveChangesIfFileLoaded
113;   Parameters:
114;       Nothing
115;   Returns:
116;       Nothing
117;   Corrupts registers:
118;       AX, BX, CX, SI, DI
119;--------------------------------------------------------------------
120ALIGN JUMP_ALIGN
121Buffers_SaveChangesIfFileLoaded:
122    mov     ax, [cs:g_cfgVars+CFGVARS.wFlags]
123    and     ax, BYTE (FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED)
124    cmp     ax, BYTE (FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED)
125    jne     SHORT .NothingToSave
126    call    Dialogs_DisplaySaveChangesDialog
127    jnz     SHORT .NothingToSave
128    jmp     BiosFile_SaveUnsavedChanges
129ALIGN JUMP_ALIGN
130.NothingToSave:
131    ret
132
133
134;--------------------------------------------------------------------
135; Buffers_AppendZeroesIfNeeded
136;   Parameters:
137;       Nothing
138;   Returns:
139;       Nothing
140;   Corrupts registers:
141;       AX, CX, DI
142;--------------------------------------------------------------------
143ALIGN JUMP_ALIGN
144Buffers_AppendZeroesIfNeeded:
145    push    es
146
147    eMOVZX  di, [cs:g_cfgVars+CFGVARS.bEepromType]
148    mov     cx, [cs:di+g_rgwEepromTypeToSizeInWords]
149    sub     cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]    ; CX = WORDs to append
150    jle     SHORT .NoNeedToAppendZeroes
151
152    call    Buffers_GetFileBufferToESDI
153    mov     ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
154    shl     ax, 1
155    add     di, ax          ; ES:DI now point first unused image byte
156    xor     ax, ax
157    cld
158    rep stosw
159ALIGN JUMP_ALIGN
160.NoNeedToAppendZeroes:
161    pop     es
162    ret
163
164
165;--------------------------------------------------------------------
166; Buffers_GenerateChecksum
167;   Parameters:
168;       Nothing
169;   Returns:
170;       Nothing
171;   Corrupts registers:
172;       AX, BX, CX, DI
173;--------------------------------------------------------------------
174ALIGN JUMP_ALIGN
175Buffers_GenerateChecksum:
176    push    es
177
178    call    Buffers_GetFileBufferToESDI
179    mov     ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
180    call    EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX
181    shl     cx, 1           ; Words to bytes
182    dec     cx              ; Leave space for checksum byte
183    xor     ax, ax
184ALIGN JUMP_ALIGN
185.SumNextByte:
186    add     al, [es:di]
187    inc     di
188    loop    .SumNextByte
189    neg     al
190    mov     [es:di], al
191
192    pop     es
193    ret
194
195
196;--------------------------------------------------------------------
197; Buffers_GetRomvarsFlagsToAX
198;   Parameters:
199;       Nothing
200;   Returns:
201;       AX:     ROMVARS.wFlags
202;   Corrupts registers:
203;       BX
204;--------------------------------------------------------------------
205ALIGN JUMP_ALIGN
206Buffers_GetRomvarsFlagsToAX:
207    mov     bx, ROMVARS.wFlags
208    ; Fall to Buffers_GetRomvarsValueToAXfromOffsetInBX
209
210;--------------------------------------------------------------------
211; Buffers_GetRomvarsValueToAXfromOffsetInBX
212;   Parameters:
213;       BX:     ROMVARS offset
214;   Returns:
215;       AX:     Value
216;   Corrupts registers:
217;       Nothing
218;--------------------------------------------------------------------
219ALIGN JUMP_ALIGN
220Buffers_GetRomvarsValueToAXfromOffsetInBX:
221    push    es
222    push    di
223    call    Buffers_GetFileBufferToESDI
224    mov     ax, [es:bx+di]
225    pop     di
226    pop     es
227    ret
228
229
230;--------------------------------------------------------------------
231; Buffers_GetIdeControllerCountToCX
232;   Parameters:
233;       SS:BP:  Menu handle
234;   Returns:
235;       CX:     Number of IDE controllers to configure
236;       ES:DI:  Ptr to file buffer
237;   Corrupts registers:
238;       AX
239;--------------------------------------------------------------------
240ALIGN JUMP_ALIGN
241Buffers_GetIdeControllerCountToCX:
242    call    Buffers_GetFileBufferToESDI
243    mov     al, [es:di+ROMVARS.bIdeCnt]
244
245    ; Limit controller count for lite mode
246    test    BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
247    jnz     SHORT .ReturnControllerCountInCX
248    MIN_U   al, MAX_LITE_MODE_CONTROLLERS
249
250.ReturnControllerCountInCX:
251    cbw     ; A maximum of 127 controllers should be sufficient
252    xchg    cx, ax
253    ret
254
255
256;--------------------------------------------------------------------
257; Buffers_GetFileBufferToESDI
258; Buffers_GetFlashComparisonBufferToESDI
259; Buffers_GetFileDialogItemBufferToESDI
260;   Parameters:
261;       Nothing
262;   Returns:
263;       ES:DI:  Ptr to file buffer
264;   Corrupts registers:
265;       Nothing
266;--------------------------------------------------------------------
267ALIGN JUMP_ALIGN
268Buffers_GetFlashComparisonBufferToESDI:
269Buffers_GetFileDialogItemBufferToESDI:
270    call    Buffers_GetFileBufferToESDI
271    push    di
272    mov     di, es
273    add     di, 1000h       ; Third 64k page
274    mov     es, di
275    pop     di
276    ret
277ALIGN JUMP_ALIGN
278Buffers_GetFileBufferToESDI:
279    mov     di, cs
280    add     di, 1000h       ; Change to next 64k page
281    mov     es, di
282    xor     di, di          ; Ptr now in ES:DI
283    ret
Note: See TracBrowser for help on using the repository browser.