Subversion Repositories Kolibri OS

Rev

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

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