Subversion Repositories Kolibri OS

Rev

Rev 76 | Rev 103 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 76 Rev 82
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                        ;;
2
;;                                                        ;;
3
;;  BOOTCODE.INC                                          ;;
3
;;  BOOTCODE.INC                                          ;;
4
;;                                                        ;;
4
;;                                                        ;;
5
;;  KolibriOS 16-bit loader,                              ;;
5
;;  KolibriOS 16-bit loader,                              ;;
6
;;                        based on bootcode for MenuetOS  ;;
6
;;                        based on bootcode for MenuetOS  ;;
7
;;                                                        ;;
7
;;                                                        ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
9
 
10
 
10
 
11
 
11
 
12
;==========================================================================
12
;==========================================================================
13
;
13
;
14
;                           16 BIT FUNCTIONS
14
;                           16 BIT FUNCTIONS
15
;
15
;
16
;==========================================================================
16
;==========================================================================
17
 
17
 
18
putchar:
18
putchar:
19
; in: al=character
19
; in: al=character
20
    mov    ah, 0Eh
20
    mov    ah, 0Eh
21
    mov    bh, 0
21
    mov    bh, 0
22
    int    10h
22
    int    10h
23
    ret
23
    ret
24
 
24
 
25
print:
25
print:
26
; in: si->string
26
; in: si->string
27
    mov    al, 186
27
    mov    al, 186
28
    call    putchar
28
    call    putchar
29
    mov    al, ' '
29
    mov    al, ' '
30
    call    putchar
30
    call    putchar
31
 
31
 
32
printplain:
32
printplain:
33
; in: si->string
33
; in: si->string
34
    pusha
34
    pusha
35
    lodsb
35
    lodsb
36
@@:
36
@@:
37
    call    putchar
37
    call    putchar
38
    lodsb
38
    lodsb
39
    cmp    al, 0
39
    cmp    al, 0
40
    jnz    @b
40
    jnz    @b
41
    popa
41
    popa
42
    ret
42
    ret
43
 
43
 
44
; Now int 16 is used for keyboard support.
44
; Now int 16 is used for keyboard support.
45
; This is shorter, simpler and more reliable.
45
; This is shorter, simpler and more reliable.
46
if 0
46
if 0
47
getkey:      push  ecx
47
getkey:      push  ecx
48
             push  edx
48
             push  edx
49
             add   ebx,0x0101
49
             add   ebx,0x0101
50
             xor   eax,eax
50
             xor   eax,eax
51
 
51
 
52
           gk1:
52
           gk1:
53
             in    al,0x60
53
             in    al,0x60
54
             mov   cl,al
54
             mov   cl,al
55
           gk0:
55
           gk0:
56
             in    al,0x60
56
             in    al,0x60
57
             cmp   al,cl
57
             cmp   al,cl
58
             je    gk0
58
             je    gk0
59
             cmp   ax,11
59
             cmp   ax,11
60
             jg    gk0
60
             jg    gk0
61
             gk0_1:
61
             gk0_1:
62
             mov   cl,al
62
             mov   cl,al
63
 
63
 
64
;             add   al,47
64
;             add   al,47
65
;             mov   [ds:keyinbs-0x10000],al
65
;             mov   [ds:keyinbs-0x10000],al
66
;             mov   si,keyinbs-0x10000
66
;             mov   si,keyinbs-0x10000
67
;             call  printplain
67
;             call  printplain
68
 
68
 
69
           gk12:
69
           gk12:
70
             in    al,0x60
70
             in    al,0x60
71
             cmp   al,cl
71
             cmp   al,cl
72
             je    gk12
72
             je    gk12
73
             cmp   ax,240
73
             cmp   ax,240
74
             jne   gk13
74
             jne   gk13
75
             mov   al,cl
75
             mov   al,cl
76
             jmp   gk14
76
             jmp   gk14
77
           gk13:
77
           gk13:
78
             add   cl,128
78
             add   cl,128
79
             cmp   al,cl
79
             cmp   al,cl
80
             jne   gk1
80
             jne   gk1
81
             sub   al,128
81
             sub   al,128
82
           gk14:
82
           gk14:
83
 
83
 
84
             movzx edx,bl
84
             movzx edx,bl
85
             cmp   eax,edx
85
             cmp   eax,edx
86
             jb    gk1
86
             jb    gk1
87
             movzx edx,bh
87
             movzx edx,bh
88
             cmp   eax,edx
88
             cmp   eax,edx
89
             jg    gk1
89
             jg    gk1
90
             test  ebx,0x010000
90
             test  ebx,0x010000
91
             jnz   gk3
91
             jnz   gk3
92
             mov   cx,0x1000
92
             mov   cx,0x1000
93
             mov   dx,cx
93
             mov   dx,cx
94
             add   eax,47
94
             add   eax,47
95
             mov   cx,ax
95
             mov   cx,ax
96
             cmp   cx,58
96
             cmp   cx,58
97
             jb    gk_nozero
97
             jb    gk_nozero
98
             sub   cx,10
98
             sub   cx,10
99
           gk_nozero:
99
           gk_nozero:
100
             mov   [ds:keyin-0x10000],cl
100
             mov   [ds:keyin-0x10000],cl
101
             mov   si,keyin-0x10000
101
             mov   si,keyin-0x10000
102
             call  printplain
102
             call  printplain
103
           gk3:
103
           gk3:
104
             sub   eax,48
104
             sub   eax,48
105
             pop   edx
105
             pop   edx
106
             pop   ecx
106
             pop   ecx
107
             ret
107
             ret
108
end if
108
end if
109
 
109
 
110
getkey:
110
getkey:
111
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
111
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
112
; in: bx=range
112
; in: bx=range
113
; out: ax=digit (1..9, 10 for 0)
113
; out: ax=digit (1..9, 10 for 0)
114
    mov    ah, 0
114
    mov    ah, 0
115
    int    16h
115
    int    16h
116
    cmp    al, bl
116
    cmp    al, bl
117
    jb    getkey
117
    jb    getkey
118
    cmp    al, bh
118
    cmp    al, bh
119
    ja    getkey
119
    ja    getkey
120
    push    ax
120
    push    ax
121
    call    putchar
121
    call    putchar
122
    pop    ax
122
    pop    ax
123
    and    ax, 0Fh
123
    and    ax, 0Fh
124
    jnz    @f
124
    jnz    @f
125
    mov    al, 10
125
    mov    al, 10
126
@@:
126
@@:
127
    ret
127
    ret
128
 
128
 
129
setcursor:
129
setcursor:
130
; in: dl=column, dh=row
130
; in: dl=column, dh=row
131
    mov    ah, 2
131
    mov    ah, 2
132
    mov    bh, 0
132
    mov    bh, 0
133
    int    10h
133
    int    10h
134
    ret
134
    ret
135
 
135
 
136
macro _setcursor row,column
136
macro _setcursor row,column
137
{
137
{
138
    mov    dx, row*256 + column
138
    mov    dx, row*256 + column
139
    call    setcursor
139
    call    setcursor
140
}
140
}
141
 
141
 
142
pagetable_set:
142
pagetable_set:
143
    or    al, 7
143
    or    al, 7
144
@@:
144
@@:
145
    stosd
145
    stosd
146
    add    eax, 1000h
146
    add    eax, 1000h
147
    loop    @b
147
    loop    @b
148
    ret
148
    ret
149
 
149
 
150
; 16-bit data
150
; 16-bit data
151
; videomodes table
151
; videomodes table
-
 
152
		org $+0x10000
152
gr_table:
153
gr_table:
153
    dw      0x112+0100000000000000b ,  640 ,  480        ; 1
154
    dw      0x112+0100000000000000b ,  640 ,  480        ; 1
154
    dw      0x115+0100000000000000b ,  800 ,  600        ; 2
155
    dw      0x115+0100000000000000b ,  800 ,  600        ; 2
155
    dw      0x118+0100000000000000b , 1024 ,  768        ; 3
156
    dw      0x118+0100000000000000b , 1024 ,  768        ; 3
156
    dw      0x11B+0100000000000000b , 1280 , 1024        ; 4
157
    dw      0x11B+0100000000000000b , 1280 , 1024        ; 4
157
    dw      0x112 ,  640 , 480                ; 5
158
    dw      0x112 ,  640 , 480                ; 5
158
    dw      0x115 ,  800 , 600                ; 6
159
    dw      0x115 ,  800 , 600                ; 6
159
    dw      0x118 , 1024 , 768                ; 7
160
    dw      0x118 , 1024 , 768                ; 7
160
    dw      0x11B , 1280 ,1024                ; 8
161
    dw      0x11B , 1280 ,1024                ; 8
161
    dw    0x13, 320, 200                    ; 9
162
    dw    0x13, 320, 200                    ; 9
162
    dw    0x12, 640, 480                    ; 0
163
    dw    0x12, 640, 480                    ; 0
163
 
164
 
164
; table for move to extended memory (int 15h, ah=87h)
165
; table for move to extended memory (int 15h, ah=87h)
165
       movedesc:
166
       movedesc:
166
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
167
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
167
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
168
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
168
 
169
 
169
        db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
170
        db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
170
        db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
171
        db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
171
 
172
 
172
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
173
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
173
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
174
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
174
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
175
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
175
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
176
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
-
 
177
        	org $-0x10000
176
 
178
 
177
;=========================================================================
179
;=========================================================================
178
;
180
;
179
;                           16 BIT CODE
181
;                           16 BIT CODE
180
;
182
;
181
;=========================================================================
183
;=========================================================================
182
 
184
 
183
 
185
 
184
start_of_code:
186
start_of_code:
185
    cld
187
    cld
186
; \begin{diamond}[02.12.2005]
188
; \begin{diamond}[02.12.2005]
187
    cmp    ax, 'KL'
189
    cmp    ax, 'KL'
188
    jnz    @f
190
    jnz    @f
189
    mov    word [cs:cfgmanager.loader_block-0x10000], si
191
    mov    word [cs:cfgmanager.loader_block-0x10000], si
190
    mov    word [cs:cfgmanager.loader_block+2-0x10000], ds
192
    mov    word [cs:cfgmanager.loader_block+2-0x10000], ds
191
@@:
193
@@:
192
; \end{diamond}[02.12.2005]
194
; \end{diamond}[02.12.2005]
193
 
195
 
194
; set up stack
196
; set up stack
195
    mov    ax, 3000h
197
    mov    ax, 3000h
196
    mov    ss, ax
198
    mov    ss, ax
197
    mov    sp, 0EC00h
199
    mov    sp, 0EC00h
198
; set up segment registers
200
; set up segment registers
199
    push    cs
201
    push    cs
200
    pop    ds
202
    pop    ds
201
    push    cs
203
    push    cs
202
    pop    es
204
    pop    es
203
 
205
 
204
; set videomode
206
; set videomode
205
    mov    ax, 3
207
    mov    ax, 3
206
        int  0x10
208
        int  0x10
207
 
209
 
208
 ; Load & set russian VGA font (RU.INC)
210
 ; Load & set russian VGA font (RU.INC)
209
        mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
211
        mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
210
          mov  bx,1000h            ; 768 bytes
212
          mov  bx,1000h            ; 768 bytes
211
          mov  cx,30h              ; 48 symbols
213
          mov  cx,30h              ; 48 symbols
212
          mov  dx,80h              ; 128 - position of first symbol
214
          mov  dx,80h              ; 128 - position of first symbol
213
        mov  ax,1100h
215
        mov  ax,1100h
214
          int  10h
216
          int  10h
215
 
217
 
216
        mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
218
        mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
217
        mov  bx,1000h            ; 512 bytes
219
        mov  bx,1000h            ; 512 bytes
218
        mov  cx,20h              ; 32 symbols
220
        mov  cx,20h              ; 32 symbols
219
        mov  dx,0E0h             ; 224 - position of first symbol
221
        mov  dx,0E0h             ; 224 - position of first symbol
220
        mov  ax,1100h
222
        mov  ax,1100h
221
          int  10h
223
          int  10h
222
 ; End set VGA russian font
224
 ; End set VGA russian font
223
 
225
 
224
; draw frames
226
; draw frames
225
    push    0xb800
227
    push    0xb800
226
    pop    es
228
    pop    es
227
    xor    di, di
229
    xor    di, di
228
;        mov  si,d80x25-0x10000
230
;        mov  si,d80x25-0x10000
229
;        mov  cx,80*25
231
;        mov  cx,80*25
230
;        mov  ah,1*16+15
232
;        mov  ah,1*16+15
231
;       dfl1:
233
;       dfl1:
232
;        lodsb
234
;        lodsb
233
;        stosw
235
;        stosw
234
;        loop dfl1
236
;        loop dfl1
235
    mov    ah, 1*16+15
237
    mov    ah, 1*16+15
236
; draw top
238
; draw top
237
    mov    si, d80x25_top - 0x10000
239
    mov    si, d80x25_top - 0x10000
238
    mov    cx, d80x25_top_num * 80
240
    mov    cx, d80x25_top_num * 80
239
@@:
241
@@:
240
    lodsb
242
    lodsb
241
    stosw
243
    stosw
242
    loop    @b
244
    loop    @b
243
; draw spaces
245
; draw spaces
244
    mov    si, space_msg - 0x10000
246
    mov    si, space_msg - 0x10000
245
    mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
247
    mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
246
dfl1:
248
dfl1:
247
    push    cx
249
    push    cx
248
    push    si
250
    push    si
249
    mov    cx, 80
251
    mov    cx, 80
250
@@:
252
@@:
251
    lodsb
253
    lodsb
252
    stosw
254
    stosw
253
    loop    @b
255
    loop    @b
254
    pop    si
256
    pop    si
255
    pop    cx
257
    pop    cx
256
    loop    dfl1
258
    loop    dfl1
257
; draw bottom
259
; draw bottom
258
    mov    si, d80x25_bottom - 0x10000
260
    mov    si, d80x25_bottom - 0x10000
259
    mov    cx, d80x25_bottom_num * 80
261
    mov    cx, d80x25_bottom_num * 80
260
@@:
262
@@:
261
    lodsb
263
    lodsb
262
    stosw
264
    stosw
263
    loop    @b
265
    loop    @b
264
 
266
 
265
    mov    byte [space_msg-0x10000+80], 0    ; now space_msg is null terminated
267
    mov    byte [space_msg-0x10000+80], 0    ; now space_msg is null terminated
266
 
268
 
267
    _setcursor d80x25_top_num,0
269
    _setcursor d80x25_top_num,0
268
 
270
 
269
 
271
 
270
; TEST FOR 386+
272
; TEST FOR 386+
271
 
273
 
272
    mov    bx, 0x4000
274
    mov    bx, 0x4000
273
        pushf
275
        pushf
274
        pop     ax
276
        pop     ax
275
        mov     dx,ax
277
        mov     dx,ax
276
        xor     ax,bx
278
        xor     ax,bx
277
        push    ax
279
        push    ax
278
        popf
280
        popf
279
        pushf
281
        pushf
280
        pop     ax
282
        pop     ax
281
        and     ax,bx
283
        and     ax,bx
282
        and     dx,bx
284
        and     dx,bx
283
        cmp     ax,dx
285
        cmp     ax,dx
284
        jnz     cpugood
286
        jnz     cpugood
285
        mov     si,not386-0x10000
287
        mov     si,not386-0x10000
286
sayerr:
288
sayerr:
287
        call    print
289
        call    print
288
        jmp     $
290
        jmp     $
289
     cpugood:
291
     cpugood:
290
 
292
 
291
; set up esp
293
; set up esp
292
    movzx    esp, sp
294
    movzx    esp, sp
293
 
295
 
294
; FLUSH 8042 KEYBOARD CONTROLLER
296
; FLUSH 8042 KEYBOARD CONTROLLER
295
 
297
 
296
;// mike.dld [
298
;// mike.dld [
297
 ;       mov     al,0xED
299
 ;       mov     al,0xED
298
 ;       out     0x60,al
300
 ;       out     0x60,al
299
 ;       or      cx,-1
301
 ;       or      cx,-1
300
 ;     @@:
302
 ;     @@:
301
 ;       in      al,0x64
303
 ;       in      al,0x64
302
 ;       test    al,2
304
 ;       test    al,2
303
 ;       jz      @f
305
 ;       jz      @f
304
 ;       loop    @b
306
 ;       loop    @b
305
 ;     @@:
307
 ;     @@:
306
 ;       mov     al,0
308
 ;       mov     al,0
307
 ;       out     0x60,al
309
 ;       out     0x60,al
308
 ;       or      cx,-1
310
 ;       or      cx,-1
309
 ;     @@:
311
 ;     @@:
310
 ;       in      al,0x64
312
 ;       in      al,0x64
311
 ;       test    al,2
313
 ;       test    al,2
312
 ;       jz      @f
314
 ;       jz      @f
313
 ;       loop    @b
315
 ;       loop    @b
314
 ;     @@:
316
 ;     @@:
315
;// mike.dld ]
317
;// mike.dld ]
316
 
318
 
317
;       mov     ecx,10000
319
;       mov     ecx,10000
318
;      fl1:
320
;      fl1:
319
;       in      al,0x64
321
;       in      al,0x64
320
;       loop    fl1
322
;       loop    fl1
321
;       test    al,1
323
;       test    al,1
322
;       jz      fl2
324
;       jz      fl2
323
;       in      al,0x60
325
;       in      al,0x60
324
;       jmp     fl1
326
;       jmp     fl1
325
;      fl2:
327
;      fl2:
326
 
328
 
327
;****************************************************************
329
;****************************************************************
328
; The function is modified Mario79
330
; The function is modified Mario79
329
;*****************************************************************
331
;*****************************************************************
330
; wait_kbd:        ; variant 1
332
; wait_kbd:        ; variant 1
331
;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
333
;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
332
; test_kbd:
334
; test_kbd:
333
;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
335
;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
334
;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
336
;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
335
;       loopnz   test_kbd
337
;       loopnz   test_kbd
336
 
338
 
337
    mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
339
    mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
338
    out   0x60,al
340
    out   0x60,al
339
    xor   cx,cx
341
    xor   cx,cx
340
wait_loop:       ; variant 2
342
wait_loop:       ; variant 2
341
; reading state of port of 8042 controller
343
; reading state of port of 8042 controller
342
        in      al,64h 
344
        in      al,64h 
343
        and     al,00000010b  ; ready flag
345
        and     al,00000010b  ; ready flag
344
; wait until 8042 controller is ready 
346
; wait until 8042 controller is ready 
345
        loopnz  wait_loop
347
        loopnz  wait_loop
346
 
348
 
347
; --------------- APM ---------------------
349
; --------------- APM ---------------------
348
    push    0
350
    push    0
349
    pop    es
351
    pop    es
350
    mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
352
    mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
351
    mov    ax, 0x5300
353
    mov    ax, 0x5300
352
    xor    bx, bx
354
    xor    bx, bx
353
    int    0x15
355
    int    0x15
354
    jc    apm_end                ; APM not found
356
    jc    apm_end                ; APM not found
355
    test    cx, 2
357
    test    cx, 2
356
    jz    apm_end                ; APM 32-bit protected-mode interface not supported
358
    jz    apm_end                ; APM 32-bit protected-mode interface not supported
357
    mov    [es : 0x9044], ax        ; Save APM Version
359
    mov    [es : 0x9044], ax        ; Save APM Version
358
    mov    [es : 0x9046], cx        ; Save APM flags
360
    mov    [es : 0x9046], cx        ; Save APM flags
359
    
361
    
360
    ; Write APM ver ----
362
    ; Write APM ver ----
361
    jmp    @f
-
 
362
msg_apm:db    ' APM x.x ', 0
-
 
363
@@:    and    ax, 0xf0f
363
    and    ax, 0xf0f
364
    add    ax, '00'
364
    add    ax, '00'
365
    mov    [msg_apm - 0x10000 + 5], ah
-
 
366
    mov    [msg_apm - 0x10000 + 7], al
-
 
367
    _setcursor 0, 3
-
 
368
    mov    si, msg_apm - 0x10000
365
    mov    si, msg_apm - 0x10000
-
 
366
    mov    [si + 5], ah
-
 
367
    mov    [si + 7], al
-
 
368
    _setcursor 0, 3
369
    call    printplain
369
    call    printplain
370
    _setcursor d80x25_top_num,0
370
    _setcursor d80x25_top_num,0
371
    ; ------------------
371
    ; ------------------
372
    
372
    
373
    mov    ax, 0x5304            ; Disconnect interface
373
    mov    ax, 0x5304            ; Disconnect interface
374
    xor    bx, bx
374
    xor    bx, bx
375
    int    0x15
375
    int    0x15
376
    mov    ax, 0x5303            ; Connect 32 bit mode interface
376
    mov    ax, 0x5303            ; Connect 32 bit mode interface
377
    xor    bx, bx
377
    xor    bx, bx
378
    int    0x15
378
    int    0x15
379
    ; init selectors
379
    ; init selectors
380
    movzx    eax, ax ; real-mode segment base address of protected-mode 32-bit code segment
380
    movzx    eax, ax ; real-mode segment base address of protected-mode 32-bit code segment
381
    shl    eax, 4
381
    shl    eax, 4
382
    mov    [apm_code_32 - 0x10000 + 2], ax
382
    mov    [apm_code_32 - 0x10000 + 2], ax
383
    shr    eax, 16
383
    shr    eax, 16
384
    mov    [apm_code_32 - 0x10000 + 4], al
384
    mov    [apm_code_32 - 0x10000 + 4], al
385
    movzx    ecx, cx ; real-mode segment base address of protected-mode 16-bit code segment
385
    movzx    ecx, cx ; real-mode segment base address of protected-mode 16-bit code segment
386
    shl    ecx, 4
386
    shl    ecx, 4
387
    mov    [apm_code_16 - 0x10000 + 2], cx
387
    mov    [apm_code_16 - 0x10000 + 2], cx
388
    shr    ecx, 16
388
    shr    ecx, 16
389
    mov    [apm_code_16 - 0x10000 + 4], cl
389
    mov    [apm_code_16 - 0x10000 + 4], cl
390
    movzx    edx, dx ; real-mode segment base address of protected-mode 16-bit data segment
390
    movzx    edx, dx ; real-mode segment base address of protected-mode 16-bit data segment
391
    shl    edx, 4
391
    shl    edx, 4
392
    mov    [apm_data_16 - 0x10000 + 2], dx
392
    mov    [apm_data_16 - 0x10000 + 2], dx
393
    shr    edx, 16
393
    shr    edx, 16
394
    mov    [apm_data_16 - 0x10000 + 4], dl
394
    mov    [apm_data_16 - 0x10000 + 4], dl
395
    mov    [es : 0x9040], ebx              ; offset of APM entry point
395
    mov    [es : 0x9040], ebx              ; offset of APM entry point
396
apm_end:
396
apm_end:
397
; -----------------------------------------        
397
; -----------------------------------------        
398
 
398
 
399
; DISPLAY VESA INFORMATION
399
; DISPLAY VESA INFORMATION
400
 
400
 
401
    push    0
401
    push    0
402
    pop    es
402
    pop    es
403
        mov     ax,0x4f00
403
        mov     ax,0x4f00
404
        mov     di,0xa000
404
        mov     di,0xa000
405
        int     0x10
405
        int     0x10
406
        cmp     ax,0x004f
406
        cmp     ax,0x004f
407
        mov    si, novesa-0x10000
407
        mov    si, novesa-0x10000
408
        jnz    @f
408
        jnz    @f
409
        mov     ax,[es:di+4]
409
        mov     ax,[es:di+4]
410
        add     ax,'0'*256+'0'
410
        add     ax,'0'*256+'0'
411
        mov    si,vervesa-0x10000
411
        mov    si,vervesa-0x10000
412
        mov     [si+vervesa_off], ah
412
        mov     [si+vervesa_off], ah
413
        mov     [si+vervesa_off+2], al
413
        mov     [si+vervesa_off+2], al
414
@@:     call    print
414
@@:     call    print
415
 
415
 
416
; \begin{diamond}[30.11.2005]
416
; \begin{diamond}[30.11.2005]
417
cfgmanager:
417
cfgmanager:
418
; settings:
418
; settings:
419
; a) preboot_graph = graphical mode
419
; a) preboot_graph = graphical mode
420
;    preboot_gprobe = probe this mode?
420
;    preboot_gprobe = probe this mode?
421
; b) preboot_mtrr = use hardware acceleration?
421
; b) preboot_mtrr = use hardware acceleration?
422
; c) preboot_vrrm = use VRR?
422
; c) preboot_vrrm = use VRR?
423
; d) preboot_device = from what boot?
423
; d) preboot_device = from what boot?
424
    mov    di, preboot_graph-0x10000
424
    mov    di, preboot_graph-0x10000
425
; check bootloader block
425
; check bootloader block
426
    cmp    [.loader_block-0x10000], 0
426
    cmp    [.loader_block-0x10000], 0
427
    jz    .noloaderblock
427
    jz    .noloaderblock
428
    les    bx, [.loader_block-0x10000]
428
    les    bx, [.loader_block-0x10000]
429
    cmp    byte [es:bx], 1
429
    cmp    byte [es:bx], 1
430
    mov    si, loader_block_error-0x10000
430
    mov    si, loader_block_error-0x10000
431
    jnz    sayerr
431
    jnz    sayerr
432
    test    byte [es:bx+1], 1
432
    test    byte [es:bx+1], 1
433
    jz    @f
433
    jz    @f
434
; image in memory present
434
; image in memory present
435
    cmp    [di+preboot_device-preboot_graph], 0
435
    cmp    [di+preboot_device-preboot_graph], 0
436
    jnz    @f
436
    jnz    @f
437
    mov    [di+preboot_device-preboot_graph], 3
437
    mov    [di+preboot_device-preboot_graph], 3
438
@@:
438
@@:
439
.noloaderblock:
439
.noloaderblock:
440
; determine default settings
440
; determine default settings
441
    mov    [.bSettingsChanged-0x10000], 0
441
    mov    [.bSettingsChanged-0x10000], 0
442
    cmp    byte [di], 0
442
    cmp    byte [di], 0
443
    jnz    .preboot_gr_end
443
    jnz    .preboot_gr_end
444
    mov    [di+preboot_gprobe-preboot_graph], 0
444
    mov    [di+preboot_gprobe-preboot_graph], 0
445
    mov    al, [vervesa+vervesa_off-0x10000]
445
    mov    al, [vervesa+vervesa_off-0x10000]
446
    cmp    al, 'x'
446
    cmp    al, 'x'
447
    jz    .novesa
447
    jz    .novesa
448
    cmp    al, '1'
448
    cmp    al, '1'
449
    jz    .vesa12
449
    jz    .vesa12
450
    mov    [di+preboot_gprobe-preboot_graph], 2
450
    mov    [di+preboot_gprobe-preboot_graph], 2
451
    mov    al, 3
451
    mov    al, 3
452
    jmp    @f
452
    jmp    @f
453
.vesa12:
453
.vesa12:
454
    mov    al, 7
454
    mov    al, 7
455
    jmp    @f
455
    jmp    @f
456
.novesa:
456
.novesa:
457
    mov    al, 10
457
    mov    al, 10
458
@@:
458
@@:
459
    mov    [di], al
459
    mov    [di], al
460
.preboot_gr_end:
460
.preboot_gr_end:
461
    cmp    [di+preboot_mtrr-preboot_graph], 1
461
    cmp    [di+preboot_mtrr-preboot_graph], 1
462
    adc    [di+preboot_mtrr-preboot_graph], 0
462
    adc    [di+preboot_mtrr-preboot_graph], 0
463
    cmp    [di+preboot_vrrm-preboot_graph], 1
463
    cmp    [di+preboot_vrrm-preboot_graph], 1
464
    adc    [di+preboot_vrrm-preboot_graph], 0
464
    adc    [di+preboot_vrrm-preboot_graph], 0
465
    cmp    [di+preboot_device-preboot_graph], 1
465
    cmp    [di+preboot_device-preboot_graph], 1
466
    adc    [di+preboot_device-preboot_graph], 0
466
    adc    [di+preboot_device-preboot_graph], 0
467
; notify user
467
; notify user
468
    mov    si, linef-0x10000
468
    mov    si, linef-0x10000
469
    call    print
469
    call    print
470
    mov    si, start_msg-0x10000
470
    mov    si, start_msg-0x10000
471
    call    print
471
    call    print
472
    mov    si, time_msg-0x10000
472
    mov    si, time_msg-0x10000
473
    call    print
473
    call    print
474
; get start time
474
; get start time
475
    call    .gettime
475
    call    .gettime
476
    mov    [.starttime-0x10000], eax
476
    mov    [.starttime-0x10000], eax
477
    mov    word [.timer-0x10000], .newtimer-0x10000
477
    mov    word [.timer-0x10000], .newtimer
478
    mov    word [.timer-0x10000+2], cs
478
    mov    word [.timer-0x10000+2], cs
479
.printcfg:
479
.printcfg:
480
    _setcursor 9,0
480
    _setcursor 9,0
481
    mov    si, current_cfg_msg-0x10000
481
    mov    si, current_cfg_msg-0x10000
482
    call    print
482
    call    print
483
    mov    si, curvideo_msg-0x10000
483
    mov    si, curvideo_msg-0x10000
484
    call    print
484
    call    print
485
    mov    al, [preboot_graph-0x10000]
485
    mov    al, [preboot_graph-0x10000]
486
    cmp    al, 8
486
    cmp    al, 8
487
    ja    .pnovesa
487
    ja    .pnovesa
488
    mov    dl, al
488
    mov    dl, al
489
    and    eax, 3
489
    and    eax, 3
490
    mov    si, [modes_msg-0x10000+eax*2]
490
    mov    si, [modes_msg-0x10000+eax*2]
491
    call    printplain
491
    call    printplain
492
    mov    si, modevesa20-0x10000
492
    mov    si, modevesa20-0x10000
493
    cmp    dl, 4
493
    cmp    dl, 4
494
    jbe    @f
494
    jbe    @f
495
    mov    si, modevesa12-0x10000
495
    mov    si, modevesa12-0x10000
496
@@:
496
@@:
497
    call    printplain
497
    call    printplain
498
    cmp    dl, 4
498
    cmp    dl, 4
499
    ja    .x
499
    ja    .x
500
    mov    si, probeno_msg-0x10000
500
    mov    si, probeno_msg-0x10000
501
    cmp    [preboot_gprobe-0x10000], 2
501
    cmp    [preboot_gprobe-0x10000], 2
502
    jnz    @f
502
    jnz    @f
503
    mov    si, probeok_msg-0x10000
503
    mov    si, probeok_msg-0x10000
504
@@:
504
@@:
505
    call    printplain
505
    call    printplain
506
.x:
506
.x:
507
    jmp    .c
507
    jmp    .c
508
.pnovesa:
508
.pnovesa:
509
    cmp    al, 9
509
    cmp    al, 9
510
    mov    si, mode9-0x10000
510
    mov    si, mode9-0x10000
511
    jz    @b
511
    jz    @b
512
    mov    si, mode10-0x10000
512
    mov    si, mode10-0x10000
513
    jmp    @b
513
    jmp    @b
514
.c:
514
.c:
515
    mov    si, linef-0x10000
515
    mov    si, linef-0x10000
516
    call    printplain
516
    call    printplain
517
    mov    si, mtrr_msg-0x10000
517
    mov    si, mtrr_msg-0x10000
518
    cmp    [preboot_mtrr-0x10000], 1
518
    cmp    [preboot_mtrr-0x10000], 1
519
    call    .say_on_off
519
    call    .say_on_off
520
    mov    si, vrrm_msg-0x10000
520
    mov    si, vrrm_msg-0x10000
521
    cmp    [preboot_vrrm-0x10000], 1
521
    cmp    [preboot_vrrm-0x10000], 1
522
    call    .say_on_off
522
    call    .say_on_off
523
    mov    si, preboot_device_msg-0x10000
523
    mov    si, preboot_device_msg-0x10000
524
    call    print
524
    call    print
525
    mov    al, [preboot_device-0x10000]
525
    mov    al, [preboot_device-0x10000]
526
    and    eax, 3
526
    and    eax, 3
527
    mov    si, [preboot_device_msgs-0x10000+eax*2]
527
    mov    si, [preboot_device_msgs-0x10000+eax*2]
528
    call    printplain
528
    call    printplain
529
.wait:
529
.wait:
530
    _setcursor 25,0        ; out of screen
530
    _setcursor 25,0        ; out of screen
531
; set timer interrupt handler
531
; set timer interrupt handler
532
    cli
532
    cli
533
    push    0
533
    push    0
534
    pop    es
534
    pop    es
535
    mov    eax, [es:8*4]
535
    mov    eax, [es:8*4]
536
    mov    [.oldtimer-0x10000], eax
536
    mov    [.oldtimer-0x10000], eax
537
    mov    eax, [.timer-0x10000]
537
    mov    eax, [.timer-0x10000]
538
    mov    [es:8*4], eax
538
    mov    [es:8*4], eax
539
    sti
539
    sti
540
; wait for keypressed
540
; wait for keypressed
541
    mov    ah, 0
541
    mov    ah, 0
542
    int    16h
542
    int    16h
543
    push    ax
543
    push    ax
544
; restore timer interrupt
544
; restore timer interrupt
545
    push    0
545
    push    0
546
    pop    es
546
    pop    es
547
    mov    eax, [.oldtimer-0x10000]
547
    mov    eax, [.oldtimer-0x10000]
548
    mov    [es:8*4], eax
548
    mov    [es:8*4], eax
549
    mov    [.timer-0x10000], eax
549
    mov    [.timer-0x10000], eax
550
    _setcursor 7,0
550
    _setcursor 7,0
551
    mov    si, space_msg-0x10000
551
    mov    si, space_msg-0x10000
552
    call    printplain
552
    call    printplain
553
    pop    ax
553
    pop    ax
554
; switch on key
554
; switch on key
555
    cmp    al, 13
555
    cmp    al, 13
556
    jz    .continue
556
    jz    .continue
557
    or    al, 20h
557
    or    al, 20h
558
    cmp    al, 'a'
558
    cmp    al, 'a'
559
    jz    .change_a
559
    jz    .change_a
560
    cmp    al, 'b'
560
    cmp    al, 'b'
561
    jz    .change_b
561
    jz    .change_b
562
    cmp    al, 'c'
562
    cmp    al, 'c'
563
    jz    .change_c
563
    jz    .change_c
564
    cmp    al, 'd'
564
    cmp    al, 'd'
565
    jnz    .wait
565
    jnz    .wait
566
    _setcursor 15,0
566
    _setcursor 15,0
567
    mov     si,bdev-0x10000
567
    mov     si,bdev-0x10000
568
    call    print
568
    call    print
569
    mov     bx,'13'
569
    mov     bx,'13'
570
    call    getkey
570
    call    getkey
571
    mov    [preboot_device-0x10000], al
571
    mov    [preboot_device-0x10000], al
572
    _setcursor 13,0
572
    _setcursor 13,0
573
.d:
573
.d:
574
    mov    [.bSettingsChanged-0x10000], 1
574
    mov    [.bSettingsChanged-0x10000], 1
575
    mov    si, space_msg-0x10000
575
    mov    si, space_msg-0x10000
576
    call    printplain
576
    call    printplain
577
    _setcursor 15,0
577
    _setcursor 15,0
578
    mov    cx, 6
578
    mov    cx, 6
579
@@:
579
@@:
580
    call    printplain
580
    call    printplain
581
    loop    @b
581
    loop    @b
582
    jmp    .printcfg
582
    jmp    .printcfg
583
.change_a:
583
.change_a:
584
    _setcursor 15,0
584
    _setcursor 15,0
585
    mov    si, gr_mode-0x10000
585
    mov    si, gr_mode-0x10000
586
    call    printplain
586
    call    printplain
587
    mov     bx, '09'
587
    mov     bx, '09'
588
    call    getkey
588
    call    getkey
589
    mov    [preboot_graph-0x10000], al
589
    mov    [preboot_graph-0x10000], al
590
    cmp    al, 4
590
    cmp    al, 4
591
    ja    @f
591
    ja    @f
592
    mov    si, probetext-0x10000
592
    mov    si, probetext-0x10000
593
    call    printplain
593
    call    printplain
594
    mov    bx, '12'
594
    mov    bx, '12'
595
    call    getkey
595
    call    getkey
596
    mov    [preboot_gprobe-0x10000], al
596
    mov    [preboot_gprobe-0x10000], al
597
@@:
597
@@:
598
    _setcursor 10,0
598
    _setcursor 10,0
599
    jmp    .d
599
    jmp    .d
600
.change_b:
600
.change_b:
601
    _setcursor 15,0
601
    _setcursor 15,0
602
    mov    si, gr_acc-0x10000
602
    mov    si, gr_acc-0x10000
603
    call    print
603
    call    print
604
    mov    bx, '12'
604
    mov    bx, '12'
605
    call    getkey
605
    call    getkey
606
    mov    [preboot_mtrr-0x10000], al
606
    mov    [preboot_mtrr-0x10000], al
607
    _setcursor 11,0
607
    _setcursor 11,0
608
    jmp    .d
608
    jmp    .d
609
.change_c:
609
.change_c:
610
    _setcursor 15,0
610
    _setcursor 15,0
611
    mov    si, vrrmprint-0x10000
611
    mov    si, vrrmprint-0x10000
612
    call    print
612
    call    print
613
    mov    bx, '12'
613
    mov    bx, '12'
614
    call    getkey
614
    call    getkey
615
    mov    [preboot_vrrm-0x10000], al
615
    mov    [preboot_vrrm-0x10000], al
616
    _setcursor 12,0
616
    _setcursor 12,0
617
    jmp    .d
617
    jmp    .d
618
.say_on_off:
618
.say_on_off:
619
    pushf
619
    pushf
620
    call    print
620
    call    print
621
    mov    si, on_msg-0x10000
621
    mov    si, on_msg-0x10000
622
    popf
622
    popf
623
    jz    @f
623
    jz    @f
624
    mov    si, off_msg-0x10000
624
    mov    si, off_msg-0x10000
625
@@:    call    printplain
625
@@:    call    printplain
626
    ret
626
    ret
627
; novesa and vervesa strings are not used at the moment of executing this code
627
; novesa and vervesa strings are not used at the moment of executing this code
628
virtual at novesa
628
virtual at novesa
629
.oldtimer dd ?
629
.oldtimer dd ?
630
.starttime dd ?
630
.starttime dd ?
631
.bSettingsChanged db ?
631
.bSettingsChanged db ?
632
.timer dd ?
632
.timer dd ?
633
end virtual
633
end virtual
-
 
634
	org $+0x10000
634
.loader_block dd 0
635
.loader_block dd 0
-
 
636
	org $-0x10000
635
.gettime:
637
.gettime:
636
    mov    ah, 0
638
    mov    ah, 0
637
    int    1Ah
639
    int    1Ah
638
    xchg    ax, cx
640
    xchg    ax, cx
639
    shl    eax, 10h
641
    shl    eax, 10h
640
    xchg    ax, dx
642
    xchg    ax, dx
641
    ret
643
    ret
642
.newtimer:
644
.newtimer:
643
    push    ds
645
    push    ds
644
    push    cs
646
    push    cs
645
    pop    ds
647
    pop    ds
646
    pushf
648
    pushf
647
    call    [.oldtimer-0x10000]
649
    call    [.oldtimer-0x10000]
648
    pushad
650
    pushad
649
    call    .gettime
651
    call    .gettime
650
    sub    eax, [.starttime-0x10000]
652
    sub    eax, [.starttime-0x10000]
651
    sub    ax, 18*5
653
    sub    ax, 18*5
652
    jae    .timergo
654
    jae    .timergo
653
    neg    ax
655
    neg    ax
654
    add    ax, 18-1
656
    add    ax, 18-1
655
    mov    bx, 18
657
    mov    bx, 18
656
    xor    dx, dx
658
    xor    dx, dx
657
    div    bx
659
    div    bx
658
if lang eq ru
660
if lang eq ru
659
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
661
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
660
    cmp    al, 5
662
    cmp    al, 5
661
    mov    cl, ' '
663
    mov    cl, ' '
662
    jae    @f
664
    jae    @f
663
    cmp    al, 1
665
    cmp    al, 1
664
    mov    cl, 'ã'
666
    mov    cl, 'ã'
665
    jz    @f
667
    jz    @f
666
    mov    cl, 'ë'
668
    mov    cl, 'ë'
667
@@:    mov    [time_str+9-0x10000], cl
669
@@:    mov    [time_str+9-0x10000], cl
668
else
670
else
669
; wait 5/4/3/2 seconds, 1 second
671
; wait 5/4/3/2 seconds, 1 second
670
    cmp    al, 1
672
    cmp    al, 1
671
    mov    cl, 's'
673
    mov    cl, 's'
672
    ja    @f
674
    ja    @f
673
    mov    cl, ' '
675
    mov    cl, ' '
674
@@:    mov    [time_str+9-0x10000], cl
676
@@:    mov    [time_str+9-0x10000], cl
675
end if
677
end if
676
    add    al, '0'
678
    add    al, '0'
677
    mov    [time_str+1-0x10000], al
679
    mov    [time_str+1-0x10000], al
678
    mov    si, time_msg-0x10000
680
    mov    si, time_msg-0x10000
679
    _setcursor 7,0
681
    _setcursor 7,0
680
    call    print
682
    call    print
681
    _setcursor 25,0
683
    _setcursor 25,0
682
    popad
684
    popad
683
    pop    ds
685
    pop    ds
684
    iret
686
    iret
685
.timergo:
687
.timergo:
686
    push    0
688
    push    0
687
    pop    es
689
    pop    es
688
    mov    eax, [.oldtimer-0x10000]
690
    mov    eax, [.oldtimer-0x10000]
689
    mov    [es:8*4], eax
691
    mov    [es:8*4], eax
690
    mov    sp, 0EC00h
692
    mov    sp, 0EC00h
691
.continue:
693
.continue:
692
    sti
694
    sti
693
    _setcursor 6,0
695
    _setcursor 6,0
694
    mov    si, space_msg-0x10000
696
    mov    si, space_msg-0x10000
695
    call    printplain
697
    call    printplain
696
    call    printplain
698
    call    printplain
697
    _setcursor 6,0
699
    _setcursor 6,0
698
    mov    si, loading_msg-0x10000
700
    mov    si, loading_msg-0x10000
699
    call    print
701
    call    print
700
    _setcursor 15,0
702
    _setcursor 15,0
701
    cmp    [.bSettingsChanged-0x10000], 0
703
    cmp    [.bSettingsChanged-0x10000], 0
702
    jz    .load
704
    jz    .load
703
    cmp    [.loader_block-0x10000], 0
705
    cmp    [.loader_block-0x10000], 0
704
    jz    .load
706
    jz    .load
705
    les    bx, [.loader_block-0x10000]
707
    les    bx, [.loader_block-0x10000]
706
    mov    eax, [es:bx+3]
708
    mov    eax, [es:bx+3]
707
    push    ds
709
    push    ds
708
    pop    es
710
    pop    es
709
    test    eax, eax
711
    test    eax, eax
710
    jz    .load
712
    jz    .load
711
    push    eax
713
    push    eax
712
    mov    si, save_quest-0x10000
714
    mov    si, save_quest-0x10000
713
    call    print
715
    call    print
714
.waityn:
716
.waityn:
715
    mov    ah, 0
717
    mov    ah, 0
716
    int    16h
718
    int    16h
717
    or    al, 20h
719
    or    al, 20h
718
    cmp    al, 'n'
720
    cmp    al, 'n'
719
    jz    .loadc
721
    jz    .loadc
720
    cmp    al, 'y'
722
    cmp    al, 'y'
721
    jnz    .waityn
723
    jnz    .waityn
722
    call    putchar
724
    call    putchar
723
    mov    byte [space_msg-0x10000+80], 186
725
    mov    byte [space_msg-0x10000+80], 186
724
    pop    eax
726
    pop    eax
725
    push    cs
727
    push    cs
726
    push    .cont-0x10000
728
    push    .cont
727
    push    eax
729
    push    eax
728
    retf
730
    retf
729
.loadc:
731
.loadc:
730
    pop    eax
732
    pop    eax
731
.cont:
733
.cont:
732
    push    cs
734
    push    cs
733
    pop    ds
735
    pop    ds
734
    mov    si, space_msg-0x10000
736
    mov    si, space_msg-0x10000
735
    mov    byte [si+80], 0
737
    mov    byte [si+80], 0
736
    _setcursor 15,0
738
    _setcursor 15,0
737
    call    printplain
739
    call    printplain
738
    _setcursor 15,0
740
    _setcursor 15,0
739
.load:
741
.load:
740
; \end{diamond}[02.12.2005]
742
; \end{diamond}[02.12.2005]
741
 
743
 
742
; ASK GRAPHICS MODE
744
; ASK GRAPHICS MODE
743
 
745
 
744
    movzx    ax, [preboot_graph-0x10000]
746
    movzx    ax, [preboot_graph-0x10000]
745
    push    0
747
    push    0
746
    pop    es
748
    pop    es
747
; address is gr_table+6*(ax-1)-0x10000
749
; address is gr_table+6*(ax-1)-0x10000
748
        add    ax, ax
750
        add    ax, ax
749
        lea    si, [gr_table-0x10000 + eax + eax*2 - 6]
751
        lea    si, [gr_table-0x10000 + eax + eax*2 - 6]
750
        mov     bx,[si+0]
752
        mov     bx,[si+0]
751
        mov     cx,[si+2]
753
        mov     cx,[si+2]
752
        mov     dx,[si+4]
754
        mov     dx,[si+4]
753
        cmp    al, 9*2
755
        cmp    al, 9*2
754
        mov    al, 32    ; BPP
756
        mov    al, 32    ; BPP
755
        jb    @f
757
        jb    @f
756
        mov    [es:0x9000], al
758
        mov    [es:0x9000], al
757
        mov    dword [es:0x9018], 0x800000
759
        mov    dword [es:0x9018], 0x800000
758
       @@:
760
       @@:
759
        mov     [es:0x9008],bx
761
        mov     [es:0x9008],bx
760
        mov     [es:0x900A],cx
762
        mov     [es:0x900A],cx
761
        mov     [es:0x900C],dx
763
        mov     [es:0x900C],dx
762
        test    bh, bh
764
        test    bh, bh
763
        jz    nov
765
        jz    nov
764
 
766
 
765
; USE DEFAULTS OR PROBE
767
; USE DEFAULTS OR PROBE
766
 
768
 
767
; bx - mode : cx - x size : dx - y size
769
; bx - mode : cx - x size : dx - y size
768
    cmp    [preboot_gprobe-0x10000], 1
770
    cmp    [preboot_gprobe-0x10000], 1
769
    jz    noprobe
771
    jz    noprobe
770
 
772
 
771
        mov     bx,0x100
773
        mov     bx,0x100
772
     newprobe:
774
     newprobe:
773
        inc     bx
775
        inc     bx
774
        cmp     bx,0x17f
776
        cmp     bx,0x17f
775
        mov    si,prnotfnd-0x10000
777
        mov    si,prnotfnd-0x10000
776
        jz    sayerr
778
        jz    sayerr
777
 
779
 
778
     probemore:
780
     probemore:
779
         push    cx
781
         push    cx
780
        mov     ax,0x4f01
782
        mov     ax,0x4f01
781
        mov     cx,bx
783
        mov     cx,bx
782
        and     cx,0xfff
784
        and     cx,0xfff
783
        mov     di,0xa000
785
        mov     di,0xa000
784
        int     0x10
786
        int     0x10
785
        pop    cx
787
        pop    cx
786
 
788
 
787
    test    byte [es:di], 80h    ; lfb?
789
    test    byte [es:di], 80h    ; lfb?
788
    jz    newprobe
790
    jz    newprobe
789
    cmp    [es:di+0x12], cx    ; x size?
791
    cmp    [es:di+0x12], cx    ; x size?
790
    jnz    newprobe
792
    jnz    newprobe
791
    cmp    [es:di+0x14], dx    ; y size?
793
    cmp    [es:di+0x14], dx    ; y size?
792
    jnz    newprobe
794
    jnz    newprobe
793
    cmp    byte [es:di+0x19], 32 ;24
795
    cmp    byte [es:di+0x19], 32 ;24
794
    jb    newprobe
796
    jb    newprobe
795
 
797
 
796
;       add     bx,0100000000000000b
798
;       add     bx,0100000000000000b
797
    or    bh, 40h
799
    or    bh, 40h
798
        mov     [es:0x9008],bx
800
        mov     [es:0x9008],bx
799
 
801
 
800
     noprobe:
802
     noprobe:
801
 
803
 
802
 
804
 
803
; FIND VESA 2.0 LFB & BPP
805
; FIND VESA 2.0 LFB & BPP
804
 
806
 
805
        mov     ax,0x4f01
807
        mov     ax,0x4f01
806
        mov     cx,bx
808
        mov     cx,bx
807
        and     cx,0xfff
809
        and     cx,0xfff
808
        mov     di,0xa000
810
        mov     di,0xa000
809
        int     0x10
811
        int     0x10
810
        ; LFB
812
        ; LFB
811
        mov     eax,[es:di+0x28]
813
        mov     eax,[es:di+0x28]
812
        mov     [es:0x9018],eax
814
        mov     [es:0x9018],eax
813
        ; ---- vbe voodoo
815
        ; ---- vbe voodoo
814
        BytesPerScanLine equ 0x10
816
        BytesPerScanLine equ 0x10
815
        mov ax, [es:di+BytesPerScanLine]
817
        mov ax, [es:di+BytesPerScanLine]
816
        mov [es:0x9001],ax
818
        mov [es:0x9001],ax
817
        ; BPP
819
        ; BPP
818
        mov     al,byte [es:di+0x19]
820
        mov     al,byte [es:di+0x19]
819
        mov     [es:0x9000],al
821
        mov     [es:0x9000],al
820
       nov:
822
       nov:
821
        cmp     al,24
823
        cmp     al,24
822
        mov    si,bt24-0x10000
824
        mov    si,bt24-0x10000
823
        jz    bppl
825
        jz    bppl
824
        cmp     al,32
826
        cmp     al,32
825
        mov     si,bt32-0x10000
827
        mov     si,bt32-0x10000
826
        jz     bppl
828
        jz     bppl
827
        mov     si,btns-0x10000
829
        mov     si,btns-0x10000
828
        jmp    sayerr
830
        jmp    sayerr
829
       bppl:
831
       bppl:
830
        call    print
832
        call    print
831
 
833
 
832
 
834
 
833
; FIND VESA 1.2 PM BANK SWITCH ADDRESS
835
; FIND VESA 1.2 PM BANK SWITCH ADDRESS
834
 
836
 
835
    push    es
837
    push    es
836
        mov     ax,0x4f0A
838
        mov     ax,0x4f0A
837
        xor    bx, bx
839
        xor    bx, bx
838
        int     0x10
840
        int     0x10
839
        xor     eax,eax
841
        xor     eax,eax
840
        mov     ax,es
842
        mov     ax,es
841
        shl     eax,4
843
        shl     eax,4
842
        movzx   ebx,di
844
        movzx   ebx,di
843
        add     eax,ebx
845
        add     eax,ebx
844
        mov     bx,[es:di]
846
        mov     bx,[es:di]
845
        add     eax,ebx
847
        add     eax,ebx
846
        pop     es
848
        pop     es
847
        mov     [es:0x9014],eax
849
        mov     [es:0x9014],eax
848
 
850
 
849
 
851
 
850
; GRAPHICS ACCELERATION
852
; GRAPHICS ACCELERATION
851
 
853
 
852
        mov     al, [preboot_mtrr-0x10000]
854
        mov     al, [preboot_mtrr-0x10000]
853
        mov     [es:0x901C],al
855
        mov     [es:0x901C],al
854
 
856
 
855
; VRR_M USE
857
; VRR_M USE
856
 
858
 
857
        mov     al,[preboot_vrrm-0x10000]
859
        mov     al,[preboot_vrrm-0x10000]
858
        mov     [es:0x9030],al
860
        mov     [es:0x9030],al
859
 
861
 
860
 
862
 
861
; MEMORY MODEL
863
; MEMORY MODEL
862
 
864
 
863
;        movzx   eax,byte [es:preboot_memory-0x10000]
865
;        movzx   eax,byte [es:preboot_memory-0x10000]
864
;        cmp     eax,0
866
;        cmp     eax,0
865
;        jne     pre_mem
867
;        jne     pre_mem
866
;;;;;;;;;;;;;;;;;;;;;;;;;
868
;;;;;;;;;;;;;;;;;;;;;;;;;
867
; mario79 - memory size ;
869
; mario79 - memory size ;
868
;;;;;;;;;;;;;;;;;;;;;;;;;
870
;;;;;;;;;;;;;;;;;;;;;;;;;
869
;           mov ax,0E801h
871
;           mov ax,0E801h
870
;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
872
;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
871
;           xor cx, cx
873
;           xor cx, cx
872
;           xor dx, dx
874
;           xor dx, dx
873
;           int 0x15
875
;           int 0x15
874
;           movzx ebx, dx ;bx
876
;           movzx ebx, dx ;bx
875
;           movzx eax, cx ;ax
877
;           movzx eax, cx ;ax
876
;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
878
;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
877
;           add   eax,ebx
879
;           add   eax,ebx
878
;           add eax, 1000h ;440h
880
;           add eax, 1000h ;440h
879
;           cmp eax,40000h ; 256?
881
;           cmp eax,40000h ; 256?
880
;           jge mem_256_z
882
;           jge mem_256_z
881
;           cmp eax,20000h ; 128?
883
;           cmp eax,20000h ; 128?
882
;           jge mem_128_z
884
;           jge mem_128_z
883
;           cmp eax,10000h ; 64?
885
;           cmp eax,10000h ; 64?
884
;           jge mem_64_z
886
;           jge mem_64_z
885
;           cmp eax,8000h ; 32?
887
;           cmp eax,8000h ; 32?
886
;           jge mem_32_z
888
;           jge mem_32_z
887
;           jmp mem_16_z
889
;           jmp mem_16_z
888
;
890
;
889
;mem_256_z: mov     si,memokz256-0x10000
891
;mem_256_z: mov     si,memokz256-0x10000
890
;           call    printplain
892
;           call    printplain
891
;           mov eax,5
893
;           mov eax,5
892
;           jmp pre_mem
894
;           jmp pre_mem
893
;mem_128_z: mov     si,memokz128-0x10000
895
;mem_128_z: mov     si,memokz128-0x10000
894
;           call    printplain
896
;           call    printplain
895
;           mov eax,4
897
;           mov eax,4
896
;           jmp pre_mem
898
;           jmp pre_mem
897
;mem_64_z:  mov     si,memokz64-0x10000
899
;mem_64_z:  mov     si,memokz64-0x10000
898
;           call    printplain
900
;           call    printplain
899
;           mov eax,3
901
;           mov eax,3
900
;           jmp pre_mem
902
;           jmp pre_mem
901
;mem_32_z:  mov     si,memokz32-0x10000
903
;mem_32_z:  mov     si,memokz32-0x10000
902
;           call    printplain
904
;           call    printplain
903
;           mov eax,2
905
;           mov eax,2
904
;           jmp pre_mem
906
;           jmp pre_mem
905
;mem_16_z:  mov     si,memokz16-0x10000
907
;mem_16_z:  mov     si,memokz16-0x10000
906
;           call    printplain
908
;           call    printplain
907
;           mov eax,1
909
;           mov eax,1
908
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
910
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
909
;      pre_mem:
911
;      pre_mem:
910
;        push    word 0x0000
912
;        push    word 0x0000
911
;        pop     es
913
;        pop     es
912
;        mov     [es:0x9030],al
914
;        mov     [es:0x9030],al
913
;        push    word 0x1000
915
;        push    word 0x1000
914
;        pop     es
916
;        pop     es
915
;        mov     si,linef-0x10000
917
;        mov     si,linef-0x10000
916
;        call    printplain
918
;        call    printplain
917
 
919
 
918
 
920
 
919
 
921
 
920
 
922
 
921
; DIRECT WRITE TO LFB, PAGING DISABLED
923
; DIRECT WRITE TO LFB, PAGING DISABLED
922
 
924
 
923
;        movzx   eax,byte [es:preboot_lfb-0x10000]
925
;        movzx   eax,byte [es:preboot_lfb-0x10000]
924
;        mov     eax,1                             ; paging disabled
926
;        mov     eax,1                             ; paging disabled
925
;        cmp     eax,0
927
;        cmp     eax,0
926
;        jne     pre_lfb
928
;        jne     pre_lfb
927
;        mov     si,gr_direct-0x10000
929
;        mov     si,gr_direct-0x10000
928
;        call    printplain
930
;        call    printplain
929
;        mov     ebx,'12'
931
;        mov     ebx,'12'
930
;        call    getkey
932
;        call    getkey
931
;      pre_lfb:
933
;      pre_lfb:
932
;        push    word 0x0000
934
;        push    word 0x0000
933
;        pop     es
935
;        pop     es
934
;        mov     [es:0x901E],al
936
;        mov     [es:0x901E],al
935
;        mov     ax,0x1000
937
;        mov     ax,0x1000
936
;        mov     es,ax
938
;        mov     es,ax
937
;        mov     si,linef-0x10000
939
;        mov     si,linef-0x10000
938
;        call    printplain
940
;        call    printplain
939
        mov     [es:0x901E],byte 1
941
        mov     [es:0x901E],byte 1
940
 
942
 
941
 
943
 
942
 
944
 
943
; BOOT DEVICE
945
; BOOT DEVICE
944
 
946
 
945
    mov    al, [preboot_device-0x10000]
947
    mov    al, [preboot_device-0x10000]
946
        dec     al
948
        dec     al
947
        mov     [boot_dev-0x10000],al
949
        mov     [boot_dev-0x10000],al
948
 
950
 
949
; READ DISKETTE TO MEMORY
951
; READ DISKETTE TO MEMORY
950
 
952
 
951
;        cmp     [boot_dev-0x10000],0
953
;        cmp     [boot_dev-0x10000],0
952
        jne     no_sys_on_floppy
954
        jne     no_sys_on_floppy
953
        mov     si,diskload-0x10000
955
        mov     si,diskload-0x10000
954
        call    print
956
        call    print
955
        xor    ax, ax            ; reset drive
957
        xor    ax, ax            ; reset drive
956
        xor    dx, dx
958
        xor    dx, dx
957
        int     0x13
959
        int     0x13
958
        mov     cx,0x0001               ; startcyl,startsector
960
        mov     cx,0x0001               ; startcyl,startsector
959
        xor    dx, dx            ; starthead,drive
961
        xor    dx, dx            ; starthead,drive
960
        push    word 80*2               ; read no of sect
962
        push    word 80*2               ; read no of sect
961
       reads:
963
       reads:
962
        pusha
964
        pusha
963
        xor     si,si
965
        xor     si,si
964
       newread:
966
       newread:
965
        mov     bx,0xa000               ; es:bx -> data area
967
        mov     bx,0xa000               ; es:bx -> data area
966
        mov     ax,0x0200+18            ; read, no of sectors to read
968
        mov     ax,0x0200+18            ; read, no of sectors to read
967
        int     0x13
969
        int     0x13
968
        test    ah, ah
970
        test    ah, ah
969
        jz      goodread
971
        jz      goodread
970
        inc    si
972
        inc    si
971
        cmp     si,10
973
        cmp     si,10
972
        jnz     newread
974
        jnz     newread
973
        mov     si,badsect-0x10000
975
        mov     si,badsect-0x10000
974
sayerr_plain:
976
sayerr_plain:
975
        call    printplain
977
        call    printplain
976
        jmp     $
978
        jmp     $
977
       goodread:
979
       goodread:
978
        ; move -> 1mb
980
        ; move -> 1mb
979
        mov     si,movedesc-0x10000
981
        mov     si,movedesc-0x10000
980
        push    es
982
        push    es
981
        push    ds
983
        push    ds
982
        pop     es
984
        pop     es
983
        mov     cx,256*18
985
        mov     cx,256*18
984
        mov     ah,0x87
986
        mov     ah,0x87
985
        int     0x15
987
        int     0x15
986
        pop    es
988
        pop    es
987
 
989
 
988
        test    ah,ah                  ; was the move successfull ?
990
        test    ah,ah                  ; was the move successfull ?
989
        je      goodmove
991
        je      goodmove
990
        mov     dx,0x3f2              ; floppy motor off
992
        mov     dx,0x3f2              ; floppy motor off
991
        mov     al,0
993
        mov     al,0
992
        out     dx,al
994
        out     dx,al
993
        mov     si,memmovefailed-0x10000
995
        mov     si,memmovefailed-0x10000
994
        jmp    sayerr_plain
996
        jmp    sayerr_plain
995
      goodmove:
997
      goodmove:
996
 
998
 
997
    add    dword [movedesc-0x10000+0x18+2], 512*18
999
    add    dword [movedesc-0x10000+0x18+2], 512*18
998
        popa
1000
        popa
999
        inc     dh
1001
        inc     dh
1000
        cmp     dh,2
1002
        cmp     dh,2
1001
        jnz     bb2
1003
        jnz     bb2
1002
        mov     dh,0
1004
        mov     dh,0
1003
        inc     ch
1005
        inc     ch
1004
        pusha                        ; print prosentage
1006
        pusha                        ; print prosentage
1005
        mov     si,pros-0x10000
1007
        mov     si,pros-0x10000
1006
    shr    ch, 2
1008
    shr    ch, 2
1007
    mov    al, '5'
1009
    mov    al, '5'
1008
    test    ch, 1
1010
    test    ch, 1
1009
    jnz    @f
1011
    jnz    @f
1010
    mov    al, '0'
1012
    mov    al, '0'
1011
@@:
1013
@@:
1012
    mov    [si+1], al
1014
    mov    [si+1], al
1013
    shr    ch, 1
1015
    shr    ch, 1
1014
    add    ch, '0'
1016
    add    ch, '0'
1015
    mov    [si], ch
1017
    mov    [si], ch
1016
        call    printplain
1018
        call    printplain
1017
        popa
1019
        popa
1018
       bb2:
1020
       bb2:
1019
        pop     ax
1021
        pop     ax
1020
        dec     ax
1022
        dec     ax
1021
        push    ax
1023
        push    ax
1022
        jnz     reads
1024
        jnz     reads
1023
       readdone:
1025
       readdone:
1024
        pop     ax
1026
        pop     ax
1025
        mov     si,backspace2-0x10000
1027
        mov     si,backspace2-0x10000
1026
        call    printplain
1028
        call    printplain
1027
        mov     si,okt-0x10000
1029
        mov     si,okt-0x10000
1028
        call    printplain
1030
        call    printplain
1029
       no_sys_on_floppy:
1031
       no_sys_on_floppy:
1030
        xor    ax, ax        ; reset drive
1032
        xor    ax, ax        ; reset drive
1031
        xor    dx, dx
1033
        xor    dx, dx
1032
        int     0x13
1034
        int     0x13
1033
       mov dx,0x3f2 ; floppy motor off
1035
       mov dx,0x3f2 ; floppy motor off
1034
       mov al,0
1036
       mov al,0
1035
       out dx,al
1037
       out dx,al
1036
 
1038
 
1037
    push    es
1039
    push    es
1038
; PAGE TABLE
1040
; PAGE TABLE
1039
 
1041
 
1040
    push    dword [es:0x9018]
1042
    push    dword [es:0x9018]
1041
 
1043
 
1042
        map_mem equ 64                ; amount of memory to map
1044
        map_mem equ 64                ; amount of memory to map
1043
 
1045
 
1044
        push    0x6000
1046
        push    0x6000
1045
        pop    es                    ; es:di = 6000:0
1047
        pop    es                    ; es:di = 6000:0
1046
        xor     di,di
1048
        xor     di,di
1047
        mov     cx,256*map_mem         ; Map (mapmem) M
1049
        mov     cx,256*map_mem         ; Map (mapmem) M
1048
;        mov     eax,7
1050
;        mov     eax,7
1049
;       pt2:
1051
;       pt2:
1050
;        cmp     cx,256*(map_mem-8)     ; 8 M map to LFB
1052
;        cmp     cx,256*(map_mem-8)     ; 8 M map to LFB
1051
;        jnz     pt3
1053
;        jnz     pt3
1052
;        pop     eax
1054
;        pop     eax
1053
;        add     eax,7
1055
;        add     eax,7
1054
;       pt3:
1056
;       pt3:
1055
;        cmp     cx,256*(map_mem-12)    ; 12 M back to linear = physical
1057
;        cmp     cx,256*(map_mem-12)    ; 12 M back to linear = physical
1056
;        jnz     pt4
1058
;        jnz     pt4
1057
;        mov     eax,12*0x100000 + 7
1059
;        mov     eax,12*0x100000 + 7
1058
;       pt4:
1060
;       pt4:
1059
;        stosd
1061
;        stosd
1060
;        add     eax,4096
1062
;        add     eax,4096
1061
;        loop    pt2
1063
;        loop    pt2
1062
; initialize as identity mapping
1064
; initialize as identity mapping
1063
    xor    eax, eax
1065
    xor    eax, eax
1064
    call    pagetable_set
1066
    call    pagetable_set
1065
; 8M..12M map to LFB
1067
; 8M..12M map to LFB
1066
    pop    eax
1068
    pop    eax
1067
;    mov    cx, 256*4
1069
;    mov    cx, 256*4
1068
    mov    ch, 4
1070
    mov    ch, 4
1069
    mov    di, 2000h
1071
    mov    di, 2000h
1070
    call    pagetable_set
1072
    call    pagetable_set
1071
 
1073
 
1072
    push    0x7100
1074
    push    0x7100
1073
    pop    es
1075
    pop    es
1074
        xor     di,di
1076
        xor     di,di
1075
        mov     eax,8*0x100000
1077
        mov     eax,8*0x100000
1076
        mov     cx,256*4
1078
        mov     cx,256*4
1077
        call    pagetable_set
1079
        call    pagetable_set
1078
        
1080
        
1079
; 4 KB PAGE DIRECTORY
1081
; 4 KB PAGE DIRECTORY
1080
 
1082
 
1081
    push    0x7F00
1083
    push    0x7F00
1082
    pop    es                ; es:di = 7F00:0
1084
    pop    es                ; es:di = 7F00:0
1083
        xor     di, di
1085
        xor     di, di
1084
        mov     cx, 64 / 4
1086
        mov     cx, 64 / 4
1085
        mov     eax, 0x60007            ; for 0 M
1087
        mov     eax, 0x60007            ; for 0 M
1086
        call    pagetable_set
1088
        call    pagetable_set
1087
        mov     dword [es:0x800],0x71007   ;map region 0x80000000-0x803FFFFF to 0x800000-0xCFFFFF
1089
        mov     dword [es:0x800],0x71007   ;map region 0x80000000-0x803FFFFF to 0x800000-0xCFFFFF
1088
        xor     si,si
1090
        xor     si,si
1089
        mov     di,second_base_address shr 20
1091
        mov     di,second_base_address shr 20
1090
        mov     cx,64/2
1092
        mov     cx,64/2
1091
        rep     movs word [es:di], [es:si]
1093
        rep     movs word [es:di], [es:si]
1092
       
1094
       
1093
        mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
1095
        mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
1094
        mov     cr3, eax
1096
        mov     cr3, eax
1095
 
1097
 
1096
; SET GRAPHICS
1098
; SET GRAPHICS
1097
 
1099
 
1098
    pop    es
1100
    pop    es
1099
        mov     ax,[es:0x9008]        ; vga & 320x200
1101
        mov     ax,[es:0x9008]        ; vga & 320x200
1100
        mov    bx, ax
1102
        mov    bx, ax
1101
        cmp     ax,0x13
1103
        cmp     ax,0x13
1102
        je      setgr
1104
        je      setgr
1103
        cmp     ax,0x12
1105
        cmp     ax,0x12
1104
        je      setgr
1106
        je      setgr
1105
        mov     ax,0x4f02            ; Vesa
1107
        mov     ax,0x4f02            ; Vesa
1106
       setgr:
1108
       setgr:
1107
        int     0x10
1109
        int     0x10
1108
        test    ah,ah
1110
        test    ah,ah
1109
        mov    si, fatalsel-0x10000
1111
        mov    si, fatalsel-0x10000
1110
        jnz    sayerr
1112
        jnz    sayerr
1111
; set mode 0x12 graphics registers:
1113
; set mode 0x12 graphics registers:
1112
        cmp     bx,0x12
1114
        cmp     bx,0x12
1113
        jne     gmok2
1115
        jne     gmok2
1114
 
1116
 
1115
        mov     al,0x05
1117
        mov     al,0x05
1116
        mov     dx,0x03ce
1118
        mov     dx,0x03ce
1117
        push    dx
1119
        push    dx
1118
        out     dx,al      ; select GDC mode register
1120
        out     dx,al      ; select GDC mode register
1119
        mov     al,0x02
1121
        mov     al,0x02
1120
        inc    dx
1122
        inc    dx
1121
        out     dx,al      ; set write mode 2
1123
        out     dx,al      ; set write mode 2
1122
 
1124
 
1123
        mov     al,0x02
1125
        mov     al,0x02
1124
        mov     dx,0x03c4
1126
        mov     dx,0x03c4
1125
        out     dx,al      ; select VGA sequencer map mask register
1127
        out     dx,al      ; select VGA sequencer map mask register
1126
        mov     al,0x0f
1128
        mov     al,0x0f
1127
        inc    dx
1129
        inc    dx
1128
        out     dx,al      ; set mask for all planes 0-3
1130
        out     dx,al      ; set mask for all planes 0-3
1129
 
1131
 
1130
        mov     al,0x08
1132
        mov     al,0x08
1131
        pop    dx
1133
        pop    dx
1132
        out     dx,al      ; select GDC bit mask register
1134
        out     dx,al      ; select GDC bit mask register
1133
                           ; for writes to 0x03cf
1135
                           ; for writes to 0x03cf
1134
 
1136
 
1135
       gmok2:
1137
       gmok2:
1136
        push    ds
1138
        push    ds
1137
        pop    es
1139
        pop    es