Subversion Repositories Kolibri OS

Rev

Rev 1159 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1159 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;;  BOOTCODE.INC                                                ;;
8
;;                                                              ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
10
;;                        based on bootcode for MenuetOS        ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
$Revision: 1018 $
15
 
16
 
17
;==========================================================================
18
;
19
;                           16 BIT FUNCTIONS
20
;
21
;==========================================================================
22
 
23
 
24
putchar:
25
; in: al=character
26
        mov     ah, 0Eh
27
        mov     bh, 0
28
        int     10h
29
        ret
30
 
31
print:
32
; in: si->string
33
        mov     al, 186
34
        call    putchar
35
        mov     al, ' '
36
        call    putchar
37
 
38
printplain:
39
; in: si->string
40
        pusha
41
        lodsb
42
@@:
43
        call    putchar
44
        lodsb
45
        cmp     al, 0
46
        jnz     @b
47
        popa
48
        ret
49
 
50
getkey:
51
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
52
; in: bx=range
53
; out: ax=digit (1..9, 10 for 0)
54
        mov     ah, 0
55
        int     16h
56
        cmp     al, bl
57
        jb      getkey
58
        cmp     al, bh
59
        ja      getkey
60
        push    ax
61
        call    putchar
62
        pop     ax
63
        and     ax, 0Fh
64
        jnz     @f
65
        mov     al, 10
66
@@:
67
        ret
68
 
69
setcursor:
70
; in: dl=column, dh=row
71
        mov     ah, 2
72
        mov     bh, 0
73
        int     10h
74
        ret
75
 
76
macro _setcursor row,column
77
{
78
        mov     dx, row*256 + column
79
        call    setcursor
80
}
81
 
82
boot_read_floppy:
83
        push    si
84
        xor     si, si
85
        mov     ah, 2   ; read
86
@@:
87
        push    ax
88
        int     0x13
89
        pop     ax
90
        jnc     @f
91
        inc     si
92
        cmp     si, 10
93
        jb      @b
94
        mov     si, badsect
95
sayerr_plain:
96
        call    printplain
97
        jmp     $
98
@@:
99
        pop     si
100
        ret
101
 
102
; convert abs. sector number (AX) to BIOS T:H:S
103
; sector number = (abs.sector%BPB_SecPerTrk)+1
104
; pre.track number = (abs.sector/BPB_SecPerTrk)
105
; head number = pre.track number%BPB_NumHeads
106
; track number = pre.track number/BPB_NumHeads
107
; Return: cl - sector number
108
;         ch - track number
109
;         dl - drive number (0 = a:)
110
;         dh - head number
111
conv_abs_to_THS:
112
        push    bx
113
        mov     bx,word [BPB_SecPerTrk]
114
        xor     dx,dx
115
        div     bx
116
        inc     dx
117
        mov     cl, dl                          ; cl = sector number
118
        mov     bx,word [BPB_NumHeads]
119
        xor     dx,dx
120
        div     bx
121
        ; !!!!!!! ax = track number, dx = head number
122
        mov     ch,al                           ; ch=track number
123
        xchg    dh,dl                           ; dh=head number
124
        mov     dl,0                            ; dl=0 (drive 0 (a:))
125
        pop     bx
126
        retn
127
; needed variables
128
BPB_SecPerTrk   dw      0                       ; sectors per track
129
BPB_NumHeads    dw      0                       ; number of heads
130
BPB_FATSz16     dw      0                       ; size of FAT
131
BPB_RootEntCnt  dw      0                       ; count of root dir. entries
132
BPB_BytsPerSec  dw      0                       ; bytes per sector
133
BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
134
BPB_TotSec16    dw      0                       ; count of the sectors on the volume
135
BPB_SecPerClus  db      0                       ; number of sectors per cluster
136
BPB_NumFATs     db      0                       ; number of FAT tables
137
abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
138
end_of_FAT      dw      0                       ; end of FAT table
139
FirstDataSector dw      0                       ; begin of data
140
 
141
;=========================================================================
142
;
143
;                           16 BIT CODE
144
;
145
;=========================================================================
146
 
147
include 'bootvesa.inc'                 ;Include source for boot vesa
148
 
149
start_of_code:
150
        cld
151
; \begin{diamond}[02.12.2005]
152
; if bootloader sets ax = 'KL', then ds:si points to loader block
153
        cmp     ax, 'KL'
154
        jnz     @f
155
        mov     word [cs:cfgmanager.loader_block], si
156
        mov     word [cs:cfgmanager.loader_block+2], ds
157
@@:
158
; \end{diamond}[02.12.2005]
159
 
160
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
161
; (see comment to bx_from_load)
162
        cmp     cx, 'HA'
163
        jnz     no_hd_load
164
        cmp     dx,'RD'
165
        jnz     no_hd_load
166
        mov     word [cs:bx_from_load], bx              ; {SPraid}[13.03.2007]
167
no_hd_load:
168
 
169
; set up stack
170
        mov     ax, 3000h
171
        mov     ss, ax
172
        mov     sp, 0EC00h
173
; set up segment registers
174
        push    cs
175
        pop     ds
176
        push    cs
177
        pop     es
178
 
179
; set videomode
180
        mov     ax, 3
181
        int     0x10
182
 
183
if lang eq ru
184
 ; Load & set russian VGA font (RU.INC)
185
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
186
        mov     bx, 1000h               ; 768 bytes
187
        mov     cx, 30h                 ; 48 symbols
188
        mov     dx, 80h                 ; 128 - position of first symbol
189
        mov     ax, 1100h
190
        int     10h
191
 
192
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
193
        mov     bx, 1000h               ; 512 bytes
194
        mov     cx, 20h                 ; 32 symbols
195
        mov     dx, 0E0h                ; 224 - position of first symbol
196
        mov     ax, 1100h
197
        int     10h
198
 ; End set VGA russian font
199
else if lang eq et
200
        mov     bp, ET_FNT              ; ET_FNT1
201
        mov     bx, 1000h               ;
202
        mov     cx, 255                 ; 256 symbols
203
        xor     dx, dx                  ; 0 - position of first symbol
204
        mov     ax, 1100h
205
        int     10h
206
end if
207
 
208
; draw frames
209
        push    0xb800
210
        pop     es
211
        xor     di, di
212
        mov     ah, 1*16+15
213
 
214
; draw top
215
        mov     si, d80x25_top
216
        mov     cx, d80x25_top_num * 80
217
@@:
218
        lodsb
219
        stosw
220
        loop    @b
221
; draw spaces
222
        mov     si, space_msg
223
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
224
dfl1:
225
        push    si
226
        mov     cx, 80
227
@@:
228
        lodsb
229
        stosw
230
        loop    @b
231
        pop     si
232
        dec     dx
233
        jnz     dfl1
234
; draw bottom
235
        mov     si, d80x25_bottom
236
        mov     cx, d80x25_bottom_num * 80
237
@@:
238
        lodsb
239
        stosw
240
        loop    @b
241
 
242
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
243
 
244
        _setcursor d80x25_top_num,0
245
 
246
 
247
; TEST FOR 386+
248
 
249
        mov     bx, 0x4000
250
        pushf
251
        pop     ax
252
        mov     dx, ax
253
        xor     ax, bx
254
        push    ax
255
        popf
256
        pushf
257
        pop     ax
258
        and     ax, bx
259
        and     dx, bx
260
        cmp     ax, dx
261
        jnz     cpugood
262
        mov     si, not386
263
sayerr:
264
        call    print
265
        jmp     $
266
     cpugood:
267
 
268
        push    0
269
        popf
270
        sti
271
 
272
; set up esp
273
        movzx   esp, sp
274
 
275
        push    0
276
        pop     es
277
        and     word [es:0x9031], 0
278
; \begin{Mario79}
279
; find HDD IDE DMA PCI device
280
; check for PCI BIOS
281
        mov     ax, 0xB101
282
        int     0x1A
283
        jc      .nopci
284
        cmp     edx, 'PCI '
285
        jnz     .nopci
286
; find PCI class code
287
; class 1 = mass storage
288
; subclass 1 = IDE controller
289
; a) class 1, subclass 1, programming interface 0x80
290
        mov     ax, 0xB103
291
        mov     ecx, 1*10000h + 1*100h + 0x80
292
        xor     si, si  ; device index = 0
293
        int     0x1A
294
        jnc     .found
295
; b) class 1, subclass 1, programming interface 0x8A
296
        mov     ax, 0xB103
297
        mov     ecx, 1*10000h + 1*100h + 0x8A
298
        xor     si, si  ; device index = 0
299
        int     0x1A
300
        jnc     .found
301
; c) class 1, subclass 1, programming interface 0x85
302
        mov     ax, 0xB103
303
        mov     ecx, 1*10000h + 1*100h + 0x85
304
        xor     si, si
305
        int     0x1A
306
        jc      .nopci
307
.found:
308
; get memory base
309
        mov     ax, 0xB10A
310
        mov     di, 0x20        ; memory base is config register at 0x20
311
        int     0x1A
312
        jc      .nopci
313
        and     cx, 0xFFF0      ; clear address decode type
314
        mov     [es:0x9031], cx
315
.nopci:
316
; \end{Mario79}
317
 
318
        mov     al, 0xf6        ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
319
        out     0x60, al
320
        xor     cx, cx
321
wait_loop:       ; variant 2
322
; reading state of port of 8042 controller
323
        in      al, 64h
324
        and     al, 00000010b  ; ready flag
325
; wait until 8042 controller is ready
326
        loopnz  wait_loop
327
 
328
;;;/diamond today   5.02.2008
329
; set keyboard typematic rate & delay
330
        mov     al, 0xf3
331
        out     0x60, al
332
        xor     cx, cx
333
@@:
334
        in      al, 64h
335
        test    al, 2
336
        loopnz  @b
337
        mov     al, 0
338
        out     0x60, al
339
        xor     cx, cx
340
@@:
341
        in      al, 64h
342
        test    al, 2
343
        loopnz  @b
344
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
345
; --------------- APM ---------------------
346
        and     word [es:0x9044], 0     ; ver = 0.0 (APM not found)
347
        mov     ax, 0x5300
348
        xor     bx, bx
349
        int     0x15
350
        jc      apm_end                 ; APM not found
351
        test    cx, 2
352
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
353
        mov     [es:0x9044], ax         ; Save APM Version
354
        mov     [es:0x9046], cx         ; Save APM flags
355
 
356
        ; Write APM ver ----
357
        and     ax, 0xf0f
358
        add     ax, '00'
359
        mov     si, msg_apm
360
        mov     [si + 5], ah
361
        mov     [si + 7], al
362
        _setcursor 0, 3
363
        call    printplain
364
        ; ------------------
365
 
366
        mov     ax, 0x5304              ; Disconnect interface
367
        xor     bx, bx
368
        int     0x15
369
        mov     ax, 0x5303              ; Connect 32 bit mode interface
370
        xor     bx, bx
371
        int     0x15
372
 
373
        mov     [es:0x9040], ebx
374
        mov     [es:0x9050], ax
375
        mov     [es:0x9052], cx
376
        mov     [es:0x9054], dx
377
 
378
apm_end:
379
        _setcursor d80x25_top_num, 0
380
 
381
;CHECK current of code
382
        cmp     [cfgmanager.loader_block], -1
383
        jz      noloaderblock
384
        les     bx, [cfgmanager.loader_block]
385
        cmp     byte [es:bx], 1
386
        mov     si, loader_block_error
387
        jnz     sayerr
388
        push    0
389
        pop     es
390
 
391
noloaderblock:
392
; DISPLAY VESA INFORMATION
393
         call    print_vesa_info
394
         call    calc_vmodes_table
395
         call    check_first_parm  ;check and enable cursor_pos
396
 
397
; \begin{diamond}[30.11.2005]
398
cfgmanager:
399
; settings:
400
; a) preboot_graph = graphical mode
401
;    preboot_gprobe = probe this mode?
402
; b) preboot_dma  = use DMA access?
403
; c) preboot_vrrm = use VRR?
404
; d) preboot_device = from what boot?
405
 
406
; determine default settings
407
        mov     [.bSettingsChanged], 0
408
 
409
;.preboot_gr_end:
410
        mov     di, preboot_device
411
; if image in memory is present and [preboot_device] is uninitialized,
412
; set it to use this preloaded image
413
        cmp     byte [di], 0
414
        jnz     .preboot_device_inited
415
        cmp     [.loader_block], -1
416
        jz      @f
417
        les     bx, [.loader_block]
418
        test    byte [es:bx+1], 1
419
        jz      @f
420
        mov     byte [di], 3
421
        jmp     .preboot_device_inited
422
@@:
423
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
424
        mov     byte [di], 1
425
.preboot_device_inited:
426
; following 4 lines set variables to 1 if its current value is 0
427
        cmp     byte [di+preboot_dma-preboot_device], 1
428
        adc     byte [di+preboot_dma-preboot_device], 0
429
        cmp     byte [di+preboot_biosdisk-preboot_device], 1
430
        adc     byte [di+preboot_biosdisk-preboot_device], 0
431
; default value for VRR is OFF
432
        cmp     byte [di+preboot_vrrm-preboot_device], 0
433
        jnz	@f
434
        mov	byte [di+preboot_vrrm-preboot_device], 2
435
@@:
436
; notify user
437
        _setcursor 5,2
438
 
439
        mov     si, linef
440
        call    printplain
441
        mov     si, start_msg
442
        call    print
443
        mov     si, time_msg
444
        call    print
445
; get start time
446
        call    .gettime
447
        mov     [.starttime], eax
448
        mov     word [.timer], .newtimer
449
        mov     word [.timer+2], cs
450
.printcfg:
451
 
452
        _setcursor 9,0
453
        mov     si, current_cfg_msg
454
        call    print
455
        mov     si, curvideo_msg
456
        call    print
457
 
458
            call    draw_current_vmode
459
 
460
        mov     si, usebd_msg
461
        cmp     [preboot_biosdisk], 1
462
        call    .say_on_off
463
        mov     si, vrrm_msg
464
        cmp     [preboot_vrrm], 1
465
        call    .say_on_off
466
        mov     si, preboot_device_msg
467
        call    print
468
        mov     al, [preboot_device]
469
        and     eax, 7
470
        mov     si, [preboot_device_msgs+eax*2]
471
        call    printplain
472
.show_remarks:
473
; show remarks in gray color
474
        mov     di, ((21-num_remarks)*80 + 2)*2
475
        push    0xB800
476
        pop     es
477
        mov     cx, num_remarks
478
        mov     si, remarks
479
.write_remarks:
480
        lodsw
481
        push    si
482
        xchg    ax, si
483
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
484
        push    di
485
.write_remark:
486
        lodsb
487
        test    al, al
488
        jz      @f
489
        stosw
490
        jmp     .write_remark
491
@@:
492
        pop     di
493
        pop     si
494
        add     di, 80*2
495
        loop    .write_remarks
496
.wait:
497
        _setcursor 25,0         ; out of screen
498
; set timer interrupt handler
499
        cli
500
        push    0
501
        pop     es
502
        push    dword [es:8*4]
503
        pop     dword [.oldtimer]
504
        push    dword [.timer]
505
        pop     dword [es:8*4]
506
;        mov     eax, [es:8*4]
507
;        mov     [.oldtimer], eax
508
;        mov     eax, [.timer]
509
;        mov     [es:8*4], eax
510
        sti
511
; wait for keypressed
512
        xor     ax,ax
513
        int     16h
514
        push    ax
515
; restore timer interrupt
516
;        push    0
517
;        pop     es
518
        mov     eax, [.oldtimer]
519
        mov     [es:8*4], eax
520
        mov     [.timer], eax
521
 
522
        _setcursor 7,0
523
        mov     si, space_msg
524
        call    printplain
525
; clear remarks and restore normal attributes
526
        push    es
527
        mov     di, ((21-num_remarks)*80 + 2)*2
528
        push    0xB800
529
        pop     es
530
        mov     cx, num_remarks
531
        mov     ax, ' ' + (1*16 + 15)*100h
532
@@:
533
        push    cx
534
        mov     cx, 76
535
        rep     stosw
536
        pop     cx
537
        add     di, 4*2
538
        loop    @b
539
        pop     es
540
        pop     ax
541
; switch on key
542
        cmp     al, 13
543
        jz      .continue
544
        or      al, 20h
545
        cmp     al, 'a'
546
        jz      .change_a
547
        cmp     al, 'b'
548
        jz      .change_b
549
        cmp     al, 'c'
550
        jz      .change_c
551
        cmp     al, 'd'
552
        jnz     .show_remarks
553
        _setcursor 15,0
554
        mov     si, bdev
555
        call    print
556
        mov     bx, '14'
557
        call    getkey
558
        mov     [preboot_device], al
559
        _setcursor 13,0
560
.d:
561
        mov     [.bSettingsChanged], 1
562
        call    clear_vmodes_table             ;clear vmodes_table
563
        jmp    .printcfg
564
.change_a:
565
.loops:
566
        call    draw_vmodes_table
567
        _setcursor 25,0         ; out of screen
568
        xor     ax,ax
569
        int     0x16
570
;        call    clear_table_cursor             ;clear current position of cursor
571
 
572
        mov     si,word [cursor_pos]
573
 
574
        cmp     ah,0x48;x,0x48E0               ; up
575
        jne     .down
576
        cmp     si,modes_table
577
        jbe     .loops
578
        sub     word [cursor_pos],size_of_step
579
        jmp     .loops
580
 
581
.down:  cmp     ah,0x50;x,0x50E0               ; down
582
        jne     .pgup
583
        cmp     word[es:si+10],-1
584
        je      .loops
585
        add     word [cursor_pos],size_of_step
586
        jmp     .loops
587
 
588
.pgup:  cmp     ah,0x49                 ; page up
589
        jne     .pgdn
590
        sub     si, size_of_step*long_v_table
591
        cmp     si, modes_table
592
        jae     @f
593
        mov     si, modes_table
594
@@:
595
        mov     word [cursor_pos], si
596
        mov     si, word [home_cursor]
597
        sub     si, size_of_step*long_v_table
598
        cmp     si, modes_table
599
        jae     @f
600
        mov     si, modes_table
601
@@:
602
        mov     word [home_cursor], si
603
        jmp     .loops
604
 
605
.pgdn:  cmp     ah,0x51                 ; page down
606
        jne     .enter
607
        mov     ax, [end_cursor]
608
        add     si, size_of_step*long_v_table
609
        cmp     si, ax
610
        jb      @f
611
        mov     si, ax
612
        sub     si, size_of_step
613
@@:
614
        mov     word [cursor_pos], si
615
        mov     si, word [home_cursor]
616
        sub     ax, size_of_step*long_v_table
617
        add     si, size_of_step*long_v_table
618
        cmp     si, ax
619
        jb      @f
620
        mov     si, ax
621
@@:
622
        mov     word [home_cursor], si
623
        jmp     .loops
624
 
625
.enter: cmp     al,0x0D;x,0x1C0D               ; enter
626
        jne     .loops
627
        push    word [cursor_pos]
628
        pop     bp
629
        push    word [es:bp]
630
        pop     word [x_save]
631
        push    word [es:bp+2]
632
        pop     word [y_save]
633
        push    word [es:bp+6]
634
        pop     word [number_vm]
635
        mov     word [preboot_graph],bp           ;save choose
636
 
637
        jmp    .d
638
 
639
.change_b:
640
        _setcursor 15,0
641
;        mov     si, ask_dma
642
;        call    print
643
;        mov     bx, '13'
644
;        call    getkey
645
;        mov     [preboot_dma], al
646
        mov     si, ask_bd
647
        call    print
648
        mov     bx, '12'
649
        call    getkey
650
        mov     [preboot_biosdisk], al
651
        _setcursor 11,0
652
        jmp     .d
653
.change_c:
654
        _setcursor 15,0
655
        mov     si, vrrmprint
656
        call    print
657
        mov     bx, '12'
658
        call    getkey
659
        mov     [preboot_vrrm], al
660
        _setcursor 12,0
661
        jmp     .d
662
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663
.say_on_off:
664
        pushf
665
        call    print
666
        mov     si, on_msg
667
        popf
668
        jz      @f
669
        mov     si, off_msg
670
@@:     jmp     printplain
671
; novesa and vervesa strings are not used at the moment of executing this code
672
virtual at novesa
673
.oldtimer dd ?
674
.starttime dd ?
675
.bSettingsChanged db ?
676
.timer dd ?
677
end virtual
678
.loader_block dd -1
679
.gettime:
680
        mov     ah, 0
681
        int     1Ah
682
        xchg    ax, cx
683
        shl     eax, 10h
684
        xchg    ax, dx
685
        ret
686
.newtimer:
687
        push    ds
688
        push    cs
689
        pop     ds
690
        pushf
691
        call    [.oldtimer]
692
        pushad
693
        call    .gettime
694
        sub     eax, [.starttime]
695
        sub     ax, 18*5
696
        jae     .timergo
697
        neg     ax
698
        add     ax, 18-1
699
        mov     bx, 18
700
        xor     dx, dx
701
        div     bx
702
if lang eq ru
703
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
704
        cmp     al, 5
705
        mov     cl, ' '
706
        jae     @f
707
        cmp     al, 1
708
        mov     cl, 'ã'
709
        jz      @f
710
        mov     cl, 'ë'
711
@@:     mov     [time_str+9], cl
712
else if lang eq et
713
        cmp     al, 1
714
        ja      @f
715
        mov     [time_str+9], ' '
716
        mov     [time_str+10],' '
717
@@:
718
else
719
; wait 5/4/3/2 seconds, 1 second
720
        cmp     al, 1
721
        mov     cl, 's'
722
        ja      @f
723
        mov     cl, ' '
724
@@:     mov     [time_str+9], cl
725
end if
726
        add     al, '0'
727
        mov     [time_str+1], al
728
        mov     si, time_msg
729
        _setcursor 7,0
730
        call    print
731
        _setcursor 25,0
732
        popad
733
        pop     ds
734
        iret
735
.timergo:
736
        push    0
737
        pop     es
738
        mov     eax, [.oldtimer]
739
        mov     [es:8*4], eax
740
        mov     sp, 0EC00h
741
.continue:
742
        sti
743
        _setcursor 6,0
744
        mov     si, space_msg
745
        call    printplain
746
        call    printplain
747
        _setcursor 6,0
748
        mov     si, loading_msg
749
        call    print
750
        _setcursor 15,0
751
        cmp     [.bSettingsChanged], 0
752
        jz      .load
753
        cmp     [.loader_block], -1
754
        jz      .load
755
        les     bx, [.loader_block]
756
        mov     eax, [es:bx+3]
757
        push    ds
758
        pop     es
759
        test    eax, eax
760
        jz      .load
761
        push    eax
762
        mov     si, save_quest
763
        call    print
764
.waityn:
765
        mov     ah, 0
766
        int     16h
767
        or      al, 20h
768
        cmp     al, 'n'
769
        jz      .loadc
770
        cmp     al, 'y'
771
        jnz     .waityn
772
        call    putchar
773
        mov     byte [space_msg+80], 186
774
 
775
        pop     eax
776
        push    cs
777
        push    .cont
778
        push    eax
779
        retf                          ;call back
780
.loadc:
781
        pop     eax
782
.cont:
783
        push    cs
784
        pop     ds
785
        mov     si, space_msg
786
        mov     byte [si+80], 0
787
        _setcursor 15,0
788
        call    printplain
789
        _setcursor 15,0
790
.load:
791
; \end{diamond}[02.12.2005]
792
 
793
; ASK GRAPHICS MODE
794
 
795
        call    set_vmode
796
 
797
; GRAPHICS ACCELERATION
798
; force yes
799
        mov     [es:0x901C], byte 1
800
 
801
; DMA ACCESS TO HD
802
 
803
        mov     al, [preboot_dma]
804
        mov     [es:0x901F], al
805
 
806
; VRR_M USE
807
 
808
        mov     al,[preboot_vrrm]
809
        mov     [es:0x9030], al
810
        mov     [es:0x901E], byte 1
811
 
812
; BOOT DEVICE
813
 
814
        mov     al, [preboot_device]
815
        dec     al
816
        mov     [boot_dev], al
817
 
818
; READ DISKETTE TO MEMORY
819
 
820
;        cmp     [boot_dev],0
821
        jne     no_sys_on_floppy
822
        mov     si,diskload
823
        call    print
824
        xor     ax, ax            ; reset drive
825
        xor     dx, dx
826
        int     0x13
827
; do we boot from CD-ROM?
828
        mov     ah, 41h
829
        mov     bx, 55AAh
830
        xor     dx, dx
831
        int     0x13
832
        jc      .nocd
833
        cmp     bx, 0AA55h
834
        jnz     .nocd
835
        mov     ah, 48h
836
        push    ds
837
        push    es
838
        pop     ds
839
        mov     si, 0xa000
840
        mov     word [si], 30
841
        int     0x13
842
        pop     ds
843
        jc      .nocd
844
        push    ds
845
        lds     si, [es:si+26]
846
        test    byte [ds:si+10], 40h
847
        pop     ds
848
        jz      .nocd
849
; yes - read all floppy by 18 sectors
850
 
851
; TODO: !!!! read only first sector and set variables !!!!!
852
; ...
853
; TODO: !!! then read flippy image track by track
854
 
855
        mov     cx, 0x0001      ; startcyl,startsector
856
.a1:
857
        push    cx dx
858
        mov     al, 18
859
        mov     bx, 0xa000
860
        call    boot_read_floppy
861
        mov     si, movedesc
862
        push    es
863
        push    ds
864
        pop     es
865
        mov     cx, 256*18
866
        mov     ah, 0x87
867
        int     0x15
868
        pop     es
869
        pop     dx cx
870
        test    ah, ah
871
        jnz     sayerr_floppy
872
        add     dword [si+8*3+2], 512*18
873
        inc     dh
874
        cmp     dh, 2
875
        jnz     .a1
876
        mov     dh, 0
877
        inc     ch
878
        cmp     ch, 80
879
        jae     ok_sys_on_floppy
880
        pusha
881
        mov     al, ch
882
        shr     ch, 2
883
        add     al, ch
884
        aam
885
        xchg    al, ah
886
        add     ax, '00'
887
        mov     si, pros
888
        mov     [si], ax
889
        call    printplain
890
        popa
891
        jmp     .a1
892
.nocd:
893
; no - read only used sectors from floppy
894
; now load floppy image to memory
895
; at first load boot sector and first FAT table
896
 
897
; read only first sector and fill variables
898
        mov     cx, 0x0001      ; first logical sector
899
        xor     dx, dx          ; head = 0, drive = 0 (a:)
900
        mov     al, 1           ; read one sector
901
        mov     bx, 0xB000      ; es:bx -> data area
902
        call    boot_read_floppy
903
; fill the necessary parameters to work with a floppy
904
        mov     ax, word [es:bx+24]
905
        mov     word [BPB_SecPerTrk], ax
906
        mov     ax, word [es:bx+26]
907
        mov     word [BPB_NumHeads], ax
908
        mov     ax, word [es:bx+17]
909
        mov     word [BPB_RootEntCnt], ax
910
        mov     ax, word [es:bx+14]
911
        mov     word [BPB_RsvdSecCnt], ax
912
        mov     ax, word [es:bx+19]
913
        mov     word [BPB_TotSec16], ax
914
        mov     al, byte [es:bx+13]
915
        mov     byte [BPB_SecPerClus], al
916
        mov     al, byte [es:bx+16]
917
        mov     byte [BPB_NumFATs], al
918
; 18.11.2008
919
        mov     ax, word [es:bx+22]
920
        mov     word [BPB_FATSz16], ax
921
        mov     cx, word [es:bx+11]
922
        mov     word [BPB_BytsPerSec], cx
923
 
924
; count of clusters in FAT12 ((size_of_FAT*2)/3)
925
;        mov     ax, word [BPB_FATSz16]
926
;        mov     cx, word [BPB_BytsPerSec]
927
;end  18.11.2008
928
        xor     dx, dx
929
        mul     cx
930
        shl     ax, 1
931
        mov     cx, 3
932
        div     cx              ; now ax - number of clusters in FAT12
933
        mov     word [end_of_FAT], ax
934
 
935
; load first FAT table
936
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
937
        xor     dx, dx          ; starthead,drive
938
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
939
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
940
        call    boot_read_floppy
941
        mov     bx, 0xB000
942
 
943
; and copy them to extended memory
944
        mov     si, movedesc
945
        mov     [si+8*2+3], bh          ; from
946
 
947
        mov     ax, word [BPB_BytsPerSec]
948
        shr     ax, 1                   ; words per sector
949
        mov     cx, word [BPB_RsvdSecCnt]
950
        add     cx, word [BPB_FATSz16]
951
        mul     cx
952
        push    ax                      ; save to stack count of words in boot+FAT
953
        xchg    ax, cx
954
 
955
        push    es
956
        push    ds
957
        pop     es
958
        mov     ah, 0x87
959
        int     0x15
960
        pop     es
961
        test    ah, ah
962
        jz      @f
963
sayerr_floppy:
964
        mov     dx, 0x3f2
965
        mov     al, 0
966
        out     dx, al
967
        mov     si, memmovefailed
968
        jmp     sayerr_plain
969
@@:
970
        pop     ax                      ; restore from stack count of words in boot+FAT
971
        shl     ax, 1                   ; make bytes count from count of words
972
        and     eax, 0ffffh
973
        add     dword [si+8*3+2], eax
974
 
975
; copy first FAT to second copy
976
; TODO: BPB_NumFATs !!!!!
977
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
978
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
979
 
980
        mov     ax, word [BPB_BytsPerSec]
981
        shr     ax, 1                   ; words per sector
982
        mov     cx, word [BPB_FATSz16]
983
        mul     cx
984
        mov     cx, ax                  ; cx - count of words in FAT
985
 
986
        push    es
987
        push    ds
988
        pop     es
989
        mov     ah, 0x87
990
        int     0x15
991
        pop     es
992
        test    ah, ah
993
        jnz     sayerr_floppy
994
 
995
        mov     ax, cx
996
        shl     ax, 1
997
        and     eax, 0ffffh             ; ax - count of bytes in FAT
998
        add     dword [si+8*3+2], eax
999
 
1000
; reading RootDir
1001
; TODO: BPB_NumFATs
1002
        add     bx, ax
1003
        add     bx, 100h
1004
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1005
        push    bx
1006
 
1007
        mov     bx, word [BPB_BytsPerSec]
1008
        shr     bx, 5                           ; divide bx by 32
1009
        mov     ax, word [BPB_RootEntCnt]
1010
        xor     dx, dx
1011
        div     bx
1012
        push    ax                              ; ax - count of RootDir sectors
1013
 
1014
        mov     ax, word [BPB_FATSz16]
1015
        xor     cx, cx
1016
        mov     cl, byte [BPB_NumFATs]
1017
        mul     cx
1018
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
1019
 
1020
        mov     word [FirstDataSector], ax
1021
        pop     bx
1022
        push    bx
1023
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1024
 
1025
; read RootDir
1026
        call    conv_abs_to_THS
1027
        pop     ax
1028
        pop     bx                              ; place in buffer to write
1029
        push    ax
1030
        call    boot_read_floppy                ; read RootDir into buffer
1031
; copy RootDir
1032
        mov     byte [si+8*2+3], bh             ; from buffer
1033
        pop     ax                              ; ax = count of RootDir sectors
1034
        mov     cx, word [BPB_BytsPerSec]
1035
        mul     cx
1036
        shr     ax, 1
1037
        mov     cx, ax                          ; count of words to copy
1038
        push    es
1039
        push    ds
1040
        pop     es
1041
        mov     ah, 0x87
1042
        int     0x15
1043
        pop     es
1044
 
1045
        mov     ax, cx
1046
        shl     ax, 1
1047
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1048
        add     dword [si+8*3+2], eax   ; add count of bytes copied
1049
 
1050
; Reading data clusters from floppy
1051
        mov     byte [si+8*2+3], bh
1052
        push    bx
1053
 
1054
        mov     di, 2                   ; First data cluster
1055
.read_loop:
1056
        mov     bx, di
1057
        shr     bx, 1                   ; bx+di = di*1.5
1058
        jnc     .even
1059
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1060
        jmp     @f
1061
.even:
1062
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
1063
 
1064
@@:
1065
        jz      .skip
1066
; read cluster di
1067
;.read:
1068
        ;conv cluster di to abs. sector ax
1069
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1070
        mov     ax, di
1071
        sub     ax, 2
1072
        xor     bx, bx
1073
        mov     bl, byte [BPB_SecPerClus]
1074
        mul     bx
1075
        add     ax, word [FirstDataSector]
1076
        call    conv_abs_to_THS
1077
        pop     bx
1078
        push    bx
1079
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1080
        call    boot_read_floppy
1081
        push    es
1082
        push    ds
1083
        pop     es
1084
        pusha
1085
;
1086
        mov     ax, word [BPB_BytsPerSec]
1087
        xor     cx, cx
1088
        mov     cl, byte [BPB_SecPerClus]
1089
        mul     cx
1090
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1091
        mov     cx, ax                          ; number of words to copy (count words in cluster)
1092
;
1093
        mov     ah, 0x87
1094
        int     0x15                            ; copy data
1095
        test    ah, ah
1096
        popa
1097
        pop     es
1098
        jnz     sayerr_floppy
1099
; skip cluster di
1100
.skip:
1101
        mov     ax, word [BPB_BytsPerSec]
1102
        xor     cx, cx
1103
        mov     cl, byte [BPB_SecPerClus]
1104
        mul     cx
1105
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1106
        add     dword [si+8*3+2], eax
1107
 
1108
        mov     ax, word [end_of_FAT]   ; max cluster number
1109
        pusha
1110
; draw percentage
1111
; total clusters: ax
1112
; read clusters: di
1113
        xchg    ax, di
1114
        mov     cx, 100
1115
        mul     cx
1116
        div     di
1117
        aam
1118
        xchg    al, ah
1119
        add     ax, '00'
1120
        mov     si, pros
1121
        cmp     [si], ax
1122
        jz      @f
1123
        mov     [si], ax
1124
        call    printplain
1125
@@:
1126
        popa
1127
        inc     di
1128
        cmp     di, word [end_of_FAT]   ; max number of cluster
1129
        jnz     .read_loop
1130
        pop     bx                      ; clear stack
1131
 
1132
ok_sys_on_floppy:
1133
        mov     si, backspace2
1134
        call    printplain
1135
        mov     si, okt
1136
        call    printplain
1137
no_sys_on_floppy:
1138
        xor     ax, ax          ; reset drive
1139
        xor     dx, dx
1140
        int     0x13
1141
        mov     dx, 0x3f2       ; floppy motor off
1142
        mov     al, 0
1143
        out     dx, al
1144
 
1145
 
1146
; SET GRAPHICS
1147
 
1148
        xor     ax, ax
1149
        mov     es, ax
1150
 
1151
        mov     ax, [es:0x9008]         ; vga & 320x200
1152
        mov     bx, ax
1153
        cmp     ax, 0x13
1154
        je      setgr
1155
        cmp     ax, 0x12
1156
        je      setgr
1157
        mov     ax, 0x4f02              ; Vesa
1158
setgr:
1159
        int     0x10
1160
        test    ah, ah
1161
        mov     si, fatalsel
1162
        jnz     v_mode_error
1163
; set mode 0x12 graphics registers:
1164
        cmp     bx, 0x12
1165
        jne     gmok2
1166
 
1167
        mov     al, 0x05
1168
        mov     dx, 0x03ce
1169
        push    dx
1170
        out     dx, al      ; select GDC mode register
1171
        mov     al, 0x02
1172
        inc     dx
1173
        out     dx, al      ; set write mode 2
1174
 
1175
        mov     al, 0x02
1176
        mov     dx, 0x03c4
1177
        out     dx, al      ; select VGA sequencer map mask register
1178
        mov     al, 0x0f
1179
        inc     dx
1180
        out     dx, al      ; set mask for all planes 0-3
1181
 
1182
        mov     al, 0x08
1183
        pop     dx
1184
        out     dx, al      ; select GDC bit mask register
1185
                           ; for writes to 0x03cf
1186
gmok2:
1187
        push    ds
1188
        pop     es