Subversion Repositories Kolibri OS

Rev

Rev 946 | Rev 1103 | 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: 1018 $
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
 
795 shurf 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
816 Lrz 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
795 shurf 140
 
1 ha 141
;=========================================================================
142
;
143
;                           16 BIT CODE
144
;
145
;=========================================================================
146
 
713 Lrz 147
include 'bootvesa.inc'                 ;Include source for boot vesa
1 ha 148
 
149
start_of_code:
514 diamond 150
        cld
29 halyavin 151
; \begin{diamond}[02.12.2005]
514 diamond 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
29 halyavin 157
@@:
158
; \end{diamond}[02.12.2005]
1 ha 159
 
514 diamond 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]
488 spraid 167
no_hd_load:
168
 
29 halyavin 169
; set up stack
514 diamond 170
        mov     ax, 3000h
171
        mov     ss, ax
172
        mov     sp, 0EC00h
29 halyavin 173
; set up segment registers
514 diamond 174
        push    cs
175
        pop     ds
176
        push    cs
177
        pop     es
1 ha 178
 
29 halyavin 179
; set videomode
514 diamond 180
        mov     ax, 3
181
        int     0x10
1 ha 182
 
134 diamond 183
if lang eq ru
1 ha 184
 ; Load & set russian VGA font (RU.INC)
514 diamond 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
1 ha 191
 
514 diamond 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
1 ha 198
 ; End set VGA russian font
274 kaitz 199
else if lang eq et
514 diamond 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
134 diamond 206
end if
1 ha 207
 
29 halyavin 208
; draw frames
514 diamond 209
        push    0xb800
210
        pop     es
211
        xor     di, di
212
        mov     ah, 1*16+15
465 serge 213
 
29 halyavin 214
; draw top
514 diamond 215
        mov     si, d80x25_top
216
        mov     cx, d80x25_top_num * 80
29 halyavin 217
@@:
514 diamond 218
        lodsb
219
        stosw
220
        loop    @b
29 halyavin 221
; draw spaces
514 diamond 222
        mov     si, space_msg
223
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
29 halyavin 224
dfl1:
514 diamond 225
        push    si
226
        mov     cx, 80
29 halyavin 227
@@:
514 diamond 228
        lodsb
229
        stosw
230
        loop    @b
231
        pop     si
232
        dec     dx
233
        jnz     dfl1
29 halyavin 234
; draw bottom
514 diamond 235
        mov     si, d80x25_bottom
236
        mov     cx, d80x25_bottom_num * 80
29 halyavin 237
@@:
514 diamond 238
        lodsb
239
        stosw
240
        loop    @b
1 ha 241
 
514 diamond 242
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
1 ha 243
 
514 diamond 244
        _setcursor d80x25_top_num,0
1 ha 245
 
246
 
247
; TEST FOR 386+
248
 
514 diamond 249
        mov     bx, 0x4000
1 ha 250
        pushf
251
        pop     ax
514 diamond 252
        mov     dx, ax
253
        xor     ax, bx
1 ha 254
        push    ax
255
        popf
256
        pushf
257
        pop     ax
514 diamond 258
        and     ax, bx
259
        and     dx, bx
260
        cmp     ax, dx
1 ha 261
        jnz     cpugood
514 diamond 262
        mov     si, not386
40 halyavin 263
sayerr:
1 ha 264
        call    print
265
        jmp     $
266
     cpugood:
267
 
514 diamond 268
        push    0
465 serge 269
        popf
270
        sti
271
 
29 halyavin 272
; set up esp
514 diamond 273
        movzx   esp, sp
1 ha 274
 
160 diamond 275
        push    0
276
        pop     es
277
        and     word [es:0x9031], 0
164 serge 278
; \begin{Mario79}
279
; find HDD IDE DMA PCI device
160 diamond 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
514 diamond 292
        xor     si, si  ; device index = 0
160 diamond 293
        int     0x1A
294
        jnc     .found
187 diamond 295
; b) class 1, subclass 1, programming interface 0x8A
160 diamond 296
        mov     ax, 0xB103
187 diamond 297
        mov     ecx, 1*10000h + 1*100h + 0x8A
514 diamond 298
        xor     si, si  ; device index = 0
160 diamond 299
        int     0x1A
300
        jnc     .found
187 diamond 301
; c) class 1, subclass 1, programming interface 0x85
160 diamond 302
        mov     ax, 0xB103
187 diamond 303
        mov     ecx, 1*10000h + 1*100h + 0x85
514 diamond 304
        xor     si, si
160 diamond 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:
164 serge 316
; \end{Mario79}
160 diamond 317
 
514 diamond 318
        mov     al, 0xf6        ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
319
        out     0x60, al
320
        xor     cx, cx
1 ha 321
wait_loop:       ; variant 2
322
; reading state of port of 8042 controller
514 diamond 323
        in      al, 64h
324
        and     al, 00000010b  ; ready flag
164 serge 325
; wait until 8042 controller is ready
1 ha 326
        loopnz  wait_loop
327
 
713 Lrz 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 mario79 345
; --------------- APM ---------------------
514 diamond 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
164 serge 355
 
514 diamond 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
        ; ------------------
164 serge 365
 
514 diamond 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
465 serge 372
 
514 diamond 373
        mov     [es:0x9040], ebx
374
        mov     [es:0x9050], ax
375
        mov     [es:0x9052], cx
376
        mov     [es:0x9054], dx
465 serge 377
 
76 mario79 378
apm_end:
437 diamond 379
        _setcursor d80x25_top_num, 0
76 mario79 380
 
713 Lrz 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
737 diamond 388
        push    0
389
        pop     es
713 Lrz 390
 
391
noloaderblock:
1 ha 392
; DISPLAY VESA INFORMATION
713 Lrz 393
         call    print_vesa_info
394
         call    calc_vmodes_table
395
         call    check_first_parm  ;check and enable cursor_pos
1 ha 396
 
29 halyavin 397
; \begin{diamond}[30.11.2005]
398
cfgmanager:
399
; settings:
400
; a) preboot_graph = graphical mode
401
;    preboot_gprobe = probe this mode?
713 Lrz 402
; b) preboot_dma  = use DMA access?
29 halyavin 403
; c) preboot_vrrm = use VRR?
404
; d) preboot_device = from what boot?
713 Lrz 405
 
29 halyavin 406
; determine default settings
514 diamond 407
        mov     [.bSettingsChanged], 0
713 Lrz 408
 
409
;.preboot_gr_end:
726 diamond 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:
1018 diamond 426
; following 4 lines set variables to 1 if its current value is 0
726 diamond 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
1018 diamond 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
@@:
29 halyavin 436
; notify user
713 Lrz 437
        _setcursor 5,2
438
 
514 diamond 439
        mov     si, linef
713 Lrz 440
        call    printplain
514 diamond 441
        mov     si, start_msg
442
        call    print
443
        mov     si, time_msg
444
        call    print
29 halyavin 445
; get start time
514 diamond 446
        call    .gettime
447
        mov     [.starttime], eax
448
        mov     word [.timer], .newtimer
449
        mov     word [.timer+2], cs
29 halyavin 450
.printcfg:
946 lrz 451
 
514 diamond 452
        _setcursor 9,0
453
        mov     si, current_cfg_msg
454
        call    print
455
        mov     si, curvideo_msg
456
        call    print
713 Lrz 457
 
458
            call    draw_current_vmode
459
 
709 diamond 460
        mov     si, usebd_msg
461
        cmp     [preboot_biosdisk], 1
462
        call    .say_on_off
514 diamond 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]
545 spraid 469
        and     eax, 7
514 diamond 470
        mov     si, [preboot_device_msgs+eax*2]
471
        call    printplain
726 diamond 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
29 halyavin 496
.wait:
514 diamond 497
        _setcursor 25,0         ; out of screen
34 halyavin 498
; set timer interrupt handler
514 diamond 499
        cli
500
        push    0
501
        pop     es
713 Lrz 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
514 diamond 510
        sti
29 halyavin 511
; wait for keypressed
713 Lrz 512
        xor     ax,ax
514 diamond 513
        int     16h
514
        push    ax
29 halyavin 515
; restore timer interrupt
713 Lrz 516
;        push    0
517
;        pop     es
514 diamond 518
        mov     eax, [.oldtimer]
519
        mov     [es:8*4], eax
520
        mov     [.timer], eax
946 lrz 521
 
514 diamond 522
        _setcursor 7,0
523
        mov     si, space_msg
524
        call    printplain
726 diamond 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
514 diamond 540
        pop     ax
29 halyavin 541
; switch on key
514 diamond 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'
726 diamond 552
        jnz     .show_remarks
514 diamond 553
        _setcursor 15,0
554
        mov     si, bdev
555
        call    print
545 spraid 556
        mov     bx, '14'
514 diamond 557
        call    getkey
558
        mov     [preboot_device], al
559
        _setcursor 13,0
29 halyavin 560
.d:
514 diamond 561
        mov     [.bSettingsChanged], 1
713 Lrz 562
        call    clear_vmodes_table             ;clear vmodes_table
514 diamond 563
        jmp    .printcfg
29 halyavin 564
.change_a:
713 Lrz 565
.loops:
566
        call    draw_vmodes_table
816 Lrz 567
        _setcursor 25,0         ; out of screen
713 Lrz 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
730 diamond 582
        jne     .pgup
713 Lrz 583
        cmp     word[es:si+10],-1
584
        je      .loops
585
        add     word [cursor_pos],size_of_step
586
        jmp     .loops
587
 
730 diamond 588
.pgup:  cmp     ah,0x49                 ; page up
589
        jne     .pgdn
731 diamond 590
        sub     si, size_of_step*long_v_table
730 diamond 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]
731 diamond 597
        sub     si, size_of_step*long_v_table
730 diamond 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]
731 diamond 608
        add     si, size_of_step*long_v_table
730 diamond 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]
731 diamond 616
        sub     ax, size_of_step*long_v_table
617
        add     si, size_of_step*long_v_table
730 diamond 618
        cmp     si, ax
619
        jb      @f
620
        mov     si, ax
621
@@:
622
        mov     word [home_cursor], si
623
        jmp     .loops
624
 
713 Lrz 625
.enter: cmp     al,0x0D;x,0x1C0D               ; enter
626
        jne     .loops
627
        push    word [cursor_pos]
746 Lrz 628
        pop     bp
629
        push    word [es:bp]
630
        pop     word [x_save]
631
        push    word [es:bp+2]
632
        pop     word [y_save]
816 Lrz 633
        push    word [es:bp+6]
749 Lrz 634
        pop     word [number_vm]
746 Lrz 635
        mov     word [preboot_graph],bp           ;save choose
636
 
514 diamond 637
        jmp    .d
713 Lrz 638
 
29 halyavin 639
.change_b:
514 diamond 640
        _setcursor 15,0
709 diamond 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
514 diamond 647
        call    print
709 diamond 648
        mov     bx, '12'
514 diamond 649
        call    getkey
709 diamond 650
        mov     [preboot_biosdisk], al
514 diamond 651
        _setcursor 11,0
652
        jmp     .d
29 halyavin 653
.change_c:
514 diamond 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
713 Lrz 662
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 halyavin 663
.say_on_off:
514 diamond 664
        pushf
665
        call    print
666
        mov     si, on_msg
667
        popf
668
        jz      @f
669
        mov     si, off_msg
670
@@:     jmp     printplain
40 halyavin 671
; novesa and vervesa strings are not used at the moment of executing this code
672
virtual at novesa
29 halyavin 673
.oldtimer dd ?
674
.starttime dd ?
675
.bSettingsChanged db ?
34 halyavin 676
.timer dd ?
40 halyavin 677
end virtual
143 diamond 678
.loader_block dd -1
29 halyavin 679
.gettime:
514 diamond 680
        mov     ah, 0
681
        int     1Ah
682
        xchg    ax, cx
683
        shl     eax, 10h
684
        xchg    ax, dx
685
        ret
29 halyavin 686
.newtimer:
514 diamond 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
29 halyavin 702
if lang eq ru
703
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
514 diamond 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
274 kaitz 712
else if lang eq et
514 diamond 713
        cmp     al, 1
714
        ja      @f
715
        mov     [time_str+9], ' '
716
        mov     [time_str+10],' '
381 serge 717
@@:
29 halyavin 718
else
719
; wait 5/4/3/2 seconds, 1 second
514 diamond 720
        cmp     al, 1
721
        mov     cl, 's'
722
        ja      @f
723
        mov     cl, ' '
724
@@:     mov     [time_str+9], cl
29 halyavin 725
end if
514 diamond 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
29 halyavin 735
.timergo:
514 diamond 736
        push    0
737
        pop     es
738
        mov     eax, [.oldtimer]
739
        mov     [es:8*4], eax
740
        mov     sp, 0EC00h
29 halyavin 741
.continue:
514 diamond 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
29 halyavin 764
.waityn:
514 diamond 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
946 lrz 774
 
514 diamond 775
        pop     eax
776
        push    cs
777
        push    .cont
778
        push    eax
946 lrz 779
        retf                          ;call back
29 halyavin 780
.loadc:
514 diamond 781
        pop     eax
29 halyavin 782
.cont:
514 diamond 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
29 halyavin 790
.load:
791
; \end{diamond}[02.12.2005]
1 ha 792
 
793
; ASK GRAPHICS MODE
794
 
713 Lrz 795
        call    set_vmode
1 ha 796
 
797
; GRAPHICS ACCELERATION
346 diamond 798
; force yes
799
        mov     [es:0x901C], byte 1
1 ha 800
 
514 diamond 801
; DMA ACCESS TO HD
1 ha 802
 
514 diamond 803
        mov     al, [preboot_dma]
804
        mov     [es:0x901F], al
346 diamond 805
 
1 ha 806
; VRR_M USE
807
 
465 serge 808
        mov     al,[preboot_vrrm]
514 diamond 809
        mov     [es:0x9030], al
810
        mov     [es:0x901E], byte 1
1 ha 811
 
812
; BOOT DEVICE
813
 
514 diamond 814
        mov     al, [preboot_device]
40 halyavin 815
        dec     al
514 diamond 816
        mov     [boot_dev], al
1 ha 817
 
818
; READ DISKETTE TO MEMORY
819
 
465 serge 820
;        cmp     [boot_dev],0
1 ha 821
        jne     no_sys_on_floppy
465 serge 822
        mov     si,diskload
1 ha 823
        call    print
514 diamond 824
        xor     ax, ax            ; reset drive
825
        xor     dx, dx
1 ha 826
        int     0x13
709 diamond 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
795 shurf 850
 
851
; TODO: !!!! read only first sector and set variables !!!!!
852
; ...
853
; TODO: !!! then read flippy image track by track
854
 
816 Lrz 855
        mov     cx, 0x0001      ; startcyl,startsector
709 diamond 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
134 diamond 894
; now load floppy image to memory
895
; at first load boot sector and first FAT table
795 shurf 896
 
897
; read only first sector and fill variables
816 Lrz 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
795 shurf 903
; fill the necessary parameters to work with a floppy
816 Lrz 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
925 Lrz 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
 
795 shurf 924
; count of clusters in FAT12 ((size_of_FAT*2)/3)
925 Lrz 925
;        mov     ax, word [BPB_FATSz16]
926
;        mov     cx, word [BPB_BytsPerSec]
927
;end  18.11.2008
816 Lrz 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
795 shurf 934
 
935
; load first FAT table
816 Lrz 936
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
134 diamond 937
        xor     dx, dx          ; starthead,drive
795 shurf 938
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
939
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
134 diamond 940
        call    boot_read_floppy
816 Lrz 941
        mov     bx, 0xB000
795 shurf 942
 
134 diamond 943
; and copy them to extended memory
465 serge 944
        mov     si, movedesc
816 Lrz 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
 
134 diamond 955
        push    es
956
        push    ds
957
        pop     es
958
        mov     ah, 0x87
959
        int     0x15
816 Lrz 960
        pop     es
76 mario79 961
        test    ah, ah
134 diamond 962
        jz      @f
963
sayerr_floppy:
964
        mov     dx, 0x3f2
965
        mov     al, 0
966
        out     dx, al
465 serge 967
        mov     si, memmovefailed
134 diamond 968
        jmp     sayerr_plain
969
@@:
816 Lrz 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
795 shurf 973
        add     dword [si+8*3+2], eax
974
 
975
; copy first FAT to second copy
976
; TODO: BPB_NumFATs !!!!!
816 Lrz 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
795 shurf 985
 
986
        push    es
987
        push    ds
988
        pop     es
134 diamond 989
        mov     ah, 0x87
990
        int     0x15
991
        pop     es
992
        test    ah, ah
993
        jnz     sayerr_floppy
816 Lrz 994
 
995
        mov     ax, cx
996
        shl     ax, 1
997
        and     eax, 0ffffh             ; ax - count of bytes in FAT
795 shurf 998
        add     dword [si+8*3+2], eax
816 Lrz 999
 
795 shurf 1000
; reading RootDir
1001
; TODO: BPB_NumFATs
816 Lrz 1002
        add     bx, ax
1003
        add     bx, 100h
1004
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1005
        push    bx
795 shurf 1006
 
816 Lrz 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
795 shurf 1013
 
816 Lrz 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
795 shurf 1019
 
816 Lrz 1020
        mov     word [FirstDataSector], ax
1021
        pop     bx
1022
        push    bx
1023
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1024
 
795 shurf 1025
; read RootDir
816 Lrz 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
795 shurf 1031
; copy RootDir
816 Lrz 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
795 shurf 1041
        mov     ah, 0x87
1042
        int     0x15
816 Lrz 1043
        pop     es
795 shurf 1044
 
816 Lrz 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
795 shurf 1049
 
1050
; Reading data clusters from floppy
816 Lrz 1051
        mov     byte [si+8*2+3], bh
1052
        push    bx
795 shurf 1053
 
816 Lrz 1054
        mov     di, 2                   ; First data cluster
134 diamond 1055
.read_loop:
816 Lrz 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
134 diamond 1061
.even:
816 Lrz 1062
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
795 shurf 1063
 
134 diamond 1064
@@:
816 Lrz 1065
        jz      .skip
795 shurf 1066
; read cluster di
1067
;.read:
816 Lrz 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
76 mario79 1081
        push    es
1082
        push    ds
1 ha 1083
        pop     es
134 diamond 1084
        pusha
795 shurf 1085
;
816 Lrz 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)
795 shurf 1092
;
816 Lrz 1093
        mov     ah, 0x87
1094
        int     0x15                            ; copy data
134 diamond 1095
        test    ah, ah
1 ha 1096
        popa
134 diamond 1097
        pop     es
1098
        jnz     sayerr_floppy
795 shurf 1099
; skip cluster di
134 diamond 1100
.skip:
816 Lrz 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
795 shurf 1107
 
816 Lrz 1108
        mov     ax, word [end_of_FAT]   ; max cluster number
134 diamond 1109
        pusha
1110
; draw percentage
795 shurf 1111
; total clusters: ax
1112
; read clusters: di
816 Lrz 1113
        xchg    ax, di
134 diamond 1114
        mov     cx, 100
1115
        mul     cx
816 Lrz 1116
        div     di
134 diamond 1117
        aam
1118
        xchg    al, ah
1119
        add     ax, '00'
465 serge 1120
        mov     si, pros
134 diamond 1121
        cmp     [si], ax
1122
        jz      @f
1123
        mov     [si], ax
1 ha 1124
        call    printplain
134 diamond 1125
@@:
1 ha 1126
        popa
134 diamond 1127
        inc     di
816 Lrz 1128
        cmp     di, word [end_of_FAT]   ; max number of cluster
134 diamond 1129
        jnz     .read_loop
816 Lrz 1130
        pop     bx                      ; clear stack
134 diamond 1131
 
709 diamond 1132
ok_sys_on_floppy:
514 diamond 1133
        mov     si, backspace2
1 ha 1134
        call    printplain
514 diamond 1135
        mov     si, okt
1 ha 1136
        call    printplain
514 diamond 1137
no_sys_on_floppy:
1138
        xor     ax, ax          ; reset drive
1139
        xor     dx, dx
1 ha 1140
        int     0x13
514 diamond 1141
        mov     dx, 0x3f2       ; floppy motor off
1142
        mov     al, 0
1143
        out     dx, al
1 ha 1144
 
1145
 
1146
; SET GRAPHICS
1147
 
514 diamond 1148
        xor     ax, ax
1149
        mov     es, ax
164 serge 1150
 
514 diamond 1151
        mov     ax, [es:0x9008]         ; vga & 320x200
1152
        mov     bx, ax
1153
        cmp     ax, 0x13
1 ha 1154
        je      setgr
514 diamond 1155
        cmp     ax, 0x12
1 ha 1156
        je      setgr
514 diamond 1157
        mov     ax, 0x4f02              ; Vesa
412 serge 1158
setgr:
1 ha 1159
        int     0x10
514 diamond 1160
        test    ah, ah
1161
        mov     si, fatalsel
713 Lrz 1162
        jnz     v_mode_error
1 ha 1163
; set mode 0x12 graphics registers:
514 diamond 1164
        cmp     bx, 0x12
1 ha 1165
        jne     gmok2
1166
 
514 diamond 1167
        mov     al, 0x05
1168
        mov     dx, 0x03ce
40 halyavin 1169
        push    dx
514 diamond 1170
        out     dx, al      ; select GDC mode register
1171
        mov     al, 0x02
1172
        inc     dx
1173
        out     dx, al      ; set write mode 2
1 ha 1174
 
514 diamond 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
1 ha 1181
 
514 diamond 1182
        mov     al, 0x08
1183
        pop     dx
1184
        out     dx, al      ; select GDC bit mask register
1 ha 1185
                           ; for writes to 0x03cf
412 serge 1186
gmok2:
76 mario79 1187
        push    ds
514 diamond 1188
        pop     es