Subversion Repositories Kolibri OS

Rev

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

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