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

Last change on this file since 145 was 145, checked in by krille_n_@…, 13 years ago

Minor size optimizations to all parts of the project (even the old Configurator).
Also added a new 'release' option to the makefiles of both versions of the Configurator. It invokes UPX and makes the Configurator programs ridiculously tiny.

File size: 6.8 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 [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED
103    ret
104
105ALIGN JUMP_ALIGN
106Buffers_ClearUnsavedChanges:
107    and     WORD [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, BYTE [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_GetFileBufferToESDI
232; Buffers_GetFlashComparisonBufferToESDI
233; Buffers_GetFileDialogItemBufferToESDI
234;   Parameters:
235;       Nothing
236;   Returns:
237;       ES:DI:  Ptr to file buffer
238;   Corrupts registers:
239;       Nothing
240;--------------------------------------------------------------------
241ALIGN JUMP_ALIGN
242Buffers_GetFlashComparisonBufferToESDI:
243Buffers_GetFileDialogItemBufferToESDI:
244    call    Buffers_GetFileBufferToESDI
245    push    di
246    mov     di, es
247    add     di, 1000h       ; Third 64k page
248    mov     es, di
249    pop     di
250    ret
251ALIGN JUMP_ALIGN
252Buffers_GetFileBufferToESDI:
253    mov     di, cs
254    add     di, 1000h       ; Change to next 64k page
255    mov     es, di
256    xor     di, di          ; Ptr now in ES:DI
257    ret
Note: See TracBrowser for help on using the repository browser.