source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm @ 376

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

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