Subversion Repositories Kolibri OS

Rev

Rev 749 | Rev 816 | 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: 795 $
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
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
 
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
 
397
 
29 halyavin 398
; \begin{diamond}[30.11.2005]
399
cfgmanager:
400
; settings:
401
; a) preboot_graph = graphical mode
402
;    preboot_gprobe = probe this mode?
713 Lrz 403
; b) preboot_dma  = use DMA access?
29 halyavin 404
; c) preboot_vrrm = use VRR?
405
; d) preboot_device = from what boot?
713 Lrz 406
 
29 halyavin 407
; determine default settings
514 diamond 408
        mov     [.bSettingsChanged], 0
713 Lrz 409
 
410
;.preboot_gr_end:
726 diamond 411
        mov     di, preboot_device
412
; if image in memory is present and [preboot_device] is uninitialized,
413
; set it to use this preloaded image
414
        cmp     byte [di], 0
415
        jnz     .preboot_device_inited
416
        cmp     [.loader_block], -1
417
        jz      @f
418
        les     bx, [.loader_block]
419
        test    byte [es:bx+1], 1
420
        jz      @f
421
        mov     byte [di], 3
422
        jmp     .preboot_device_inited
423
@@:
424
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
425
        mov     byte [di], 1
426
.preboot_device_inited:
713 Lrz 427
; following 6 lines set variables to 1 if its current value is 0
726 diamond 428
        cmp     byte [di+preboot_dma-preboot_device], 1
429
        adc     byte [di+preboot_dma-preboot_device], 0
430
        cmp     byte [di+preboot_biosdisk-preboot_device], 1
431
        adc     byte [di+preboot_biosdisk-preboot_device], 0
432
        cmp     byte [di+preboot_vrrm-preboot_device], 1
433
        adc     byte [di+preboot_vrrm-preboot_device], 0
29 halyavin 434
; notify user
713 Lrz 435
        _setcursor 5,2
436
 
514 diamond 437
        mov     si, linef
713 Lrz 438
        call    printplain
514 diamond 439
        mov     si, start_msg
440
        call    print
441
        mov     si, time_msg
442
        call    print
29 halyavin 443
; get start time
514 diamond 444
        call    .gettime
445
        mov     [.starttime], eax
446
        mov     word [.timer], .newtimer
447
        mov     word [.timer+2], cs
29 halyavin 448
.printcfg:
514 diamond 449
        _setcursor 9,0
450
        mov     si, current_cfg_msg
451
        call    print
452
        mov     si, curvideo_msg
453
        call    print
713 Lrz 454
 
455
            call    draw_current_vmode
456
 
709 diamond 457
        mov     si, usebd_msg
458
        cmp     [preboot_biosdisk], 1
459
        call    .say_on_off
514 diamond 460
        mov     si, vrrm_msg
461
        cmp     [preboot_vrrm], 1
462
        call    .say_on_off
463
        mov     si, preboot_device_msg
464
        call    print
465
        mov     al, [preboot_device]
545 spraid 466
        and     eax, 7
514 diamond 467
        mov     si, [preboot_device_msgs+eax*2]
468
        call    printplain
726 diamond 469
.show_remarks:
470
; show remarks in gray color
471
        mov     di, ((21-num_remarks)*80 + 2)*2
472
        push    0xB800
473
        pop     es
474
        mov     cx, num_remarks
475
        mov     si, remarks
476
.write_remarks:
477
        lodsw
478
        push    si
479
        xchg    ax, si
480
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
481
        push    di
482
.write_remark:
483
        lodsb
484
        test    al, al
485
        jz      @f
486
        stosw
487
        jmp     .write_remark
488
@@:
489
        pop     di
490
        pop     si
491
        add     di, 80*2
492
        loop    .write_remarks
29 halyavin 493
.wait:
514 diamond 494
        _setcursor 25,0         ; out of screen
34 halyavin 495
; set timer interrupt handler
514 diamond 496
        cli
497
        push    0
498
        pop     es
713 Lrz 499
        push    dword [es:8*4]
500
        pop     dword [.oldtimer]
501
        push    dword [.timer]
502
        pop     dword [es:8*4]
503
;        mov     eax, [es:8*4]
504
;        mov     [.oldtimer], eax
505
;        mov     eax, [.timer]
506
;        mov     [es:8*4], eax
514 diamond 507
        sti
29 halyavin 508
; wait for keypressed
713 Lrz 509
        xor     ax,ax
514 diamond 510
        int     16h
511
        push    ax
29 halyavin 512
; restore timer interrupt
713 Lrz 513
;        push    0
514
;        pop     es
514 diamond 515
        mov     eax, [.oldtimer]
516
        mov     [es:8*4], eax
517
        mov     [.timer], eax
518
        _setcursor 7,0
519
        mov     si, space_msg
520
        call    printplain
726 diamond 521
; clear remarks and restore normal attributes
522
        push    es
523
        mov     di, ((21-num_remarks)*80 + 2)*2
524
        push    0xB800
525
        pop     es
526
        mov     cx, num_remarks
527
        mov     ax, ' ' + (1*16 + 15)*100h
528
@@:
529
        push    cx
530
        mov     cx, 76
531
        rep     stosw
532
        pop     cx
533
        add     di, 4*2
534
        loop    @b
535
        pop     es
514 diamond 536
        pop     ax
29 halyavin 537
; switch on key
514 diamond 538
        cmp     al, 13
539
        jz      .continue
540
        or      al, 20h
541
        cmp     al, 'a'
542
        jz      .change_a
543
        cmp     al, 'b'
544
        jz      .change_b
545
        cmp     al, 'c'
546
        jz      .change_c
547
        cmp     al, 'd'
726 diamond 548
        jnz     .show_remarks
514 diamond 549
        _setcursor 15,0
550
        mov     si, bdev
551
        call    print
545 spraid 552
        mov     bx, '14'
514 diamond 553
        call    getkey
554
        mov     [preboot_device], al
555
        _setcursor 13,0
29 halyavin 556
.d:
514 diamond 557
        mov     [.bSettingsChanged], 1
713 Lrz 558
        call    clear_vmodes_table             ;clear vmodes_table
514 diamond 559
        jmp    .printcfg
29 halyavin 560
.change_a:
713 Lrz 561
.loops:
562
        call    draw_vmodes_table
563
 
564
        xor     ax,ax
565
        int     0x16
566
;        call    clear_table_cursor             ;clear current position of cursor
567
 
568
        mov     si,word [cursor_pos]
569
 
570
        cmp     ah,0x48;x,0x48E0               ; up
571
        jne     .down
572
        cmp     si,modes_table
573
        jbe     .loops
574
        sub     word [cursor_pos],size_of_step
575
        jmp     .loops
576
 
577
.down:  cmp     ah,0x50;x,0x50E0               ; down
730 diamond 578
        jne     .pgup
713 Lrz 579
        cmp     word[es:si+10],-1
580
        je      .loops
581
        add     word [cursor_pos],size_of_step
582
        jmp     .loops
583
 
730 diamond 584
.pgup:  cmp     ah,0x49                 ; page up
585
        jne     .pgdn
731 diamond 586
        sub     si, size_of_step*long_v_table
730 diamond 587
        cmp     si, modes_table
588
        jae     @f
589
        mov     si, modes_table
590
@@:
591
        mov     word [cursor_pos], si
592
        mov     si, word [home_cursor]
731 diamond 593
        sub     si, size_of_step*long_v_table
730 diamond 594
        cmp     si, modes_table
595
        jae     @f
596
        mov     si, modes_table
597
@@:
598
        mov     word [home_cursor], si
599
        jmp     .loops
600
 
601
.pgdn:  cmp     ah,0x51                 ; page down
602
        jne     .enter
603
        mov     ax, [end_cursor]
731 diamond 604
        add     si, size_of_step*long_v_table
730 diamond 605
        cmp     si, ax
606
        jb      @f
607
        mov     si, ax
608
        sub     si, size_of_step
609
@@:
610
        mov     word [cursor_pos], si
611
        mov     si, word [home_cursor]
731 diamond 612
        sub     ax, size_of_step*long_v_table
613
        add     si, size_of_step*long_v_table
730 diamond 614
        cmp     si, ax
615
        jb      @f
616
        mov     si, ax
617
@@:
618
        mov     word [home_cursor], si
619
        jmp     .loops
620
 
713 Lrz 621
.enter: cmp     al,0x0D;x,0x1C0D               ; enter
622
        jne     .loops
623
        push    word [cursor_pos]
746 Lrz 624
        pop     bp
625
        push    word [es:bp]
626
        pop     word [x_save]
627
        push    word [es:bp+2]
628
        pop     word [y_save]
749 Lrz 629
	push	word [es:bp+6]
630
        pop     word [number_vm]
746 Lrz 631
        mov     word [preboot_graph],bp           ;save choose
632
 
514 diamond 633
        jmp    .d
713 Lrz 634
 
29 halyavin 635
.change_b:
514 diamond 636
        _setcursor 15,0
709 diamond 637
;        mov     si, ask_dma
638
;        call    print
639
;        mov     bx, '13'
640
;        call    getkey
641
;        mov     [preboot_dma], al
642
        mov     si, ask_bd
514 diamond 643
        call    print
709 diamond 644
        mov     bx, '12'
514 diamond 645
        call    getkey
709 diamond 646
        mov     [preboot_biosdisk], al
514 diamond 647
        _setcursor 11,0
648
        jmp     .d
29 halyavin 649
.change_c:
514 diamond 650
        _setcursor 15,0
651
        mov     si, vrrmprint
652
        call    print
653
        mov     bx, '12'
654
        call    getkey
655
        mov     [preboot_vrrm], al
656
        _setcursor 12,0
657
        jmp     .d
713 Lrz 658
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 halyavin 659
.say_on_off:
514 diamond 660
        pushf
661
        call    print
662
        mov     si, on_msg
663
        popf
664
        jz      @f
665
        mov     si, off_msg
666
@@:     jmp     printplain
40 halyavin 667
; novesa and vervesa strings are not used at the moment of executing this code
668
virtual at novesa
29 halyavin 669
.oldtimer dd ?
670
.starttime dd ?
671
.bSettingsChanged db ?
34 halyavin 672
.timer dd ?
40 halyavin 673
end virtual
143 diamond 674
.loader_block dd -1
29 halyavin 675
.gettime:
514 diamond 676
        mov     ah, 0
677
        int     1Ah
678
        xchg    ax, cx
679
        shl     eax, 10h
680
        xchg    ax, dx
681
        ret
29 halyavin 682
.newtimer:
514 diamond 683
        push    ds
684
        push    cs
685
        pop     ds
686
        pushf
687
        call    [.oldtimer]
688
        pushad
689
        call    .gettime
690
        sub     eax, [.starttime]
691
        sub     ax, 18*5
692
        jae     .timergo
693
        neg     ax
694
        add     ax, 18-1
695
        mov     bx, 18
696
        xor     dx, dx
697
        div     bx
29 halyavin 698
if lang eq ru
699
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
514 diamond 700
        cmp     al, 5
701
        mov     cl, ' '
702
        jae     @f
703
        cmp     al, 1
704
        mov     cl, 'ã'
705
        jz      @f
706
        mov     cl, 'ë'
707
@@:     mov     [time_str+9], cl
274 kaitz 708
else if lang eq et
514 diamond 709
        cmp     al, 1
710
        ja      @f
711
        mov     [time_str+9], ' '
712
        mov     [time_str+10],' '
381 serge 713
@@:
29 halyavin 714
else
715
; wait 5/4/3/2 seconds, 1 second
514 diamond 716
        cmp     al, 1
717
        mov     cl, 's'
718
        ja      @f
719
        mov     cl, ' '
720
@@:     mov     [time_str+9], cl
29 halyavin 721
end if
514 diamond 722
        add     al, '0'
723
        mov     [time_str+1], al
724
        mov     si, time_msg
725
        _setcursor 7,0
726
        call    print
727
        _setcursor 25,0
728
        popad
729
        pop     ds
730
        iret
29 halyavin 731
.timergo:
514 diamond 732
        push    0
733
        pop     es
734
        mov     eax, [.oldtimer]
735
        mov     [es:8*4], eax
736
        mov     sp, 0EC00h
29 halyavin 737
.continue:
514 diamond 738
        sti
739
        _setcursor 6,0
740
        mov     si, space_msg
741
        call    printplain
742
        call    printplain
743
        _setcursor 6,0
744
        mov     si, loading_msg
745
        call    print
746
        _setcursor 15,0
747
        cmp     [.bSettingsChanged], 0
748
        jz      .load
749
        cmp     [.loader_block], -1
750
        jz      .load
751
        les     bx, [.loader_block]
752
        mov     eax, [es:bx+3]
753
        push    ds
754
        pop     es
755
        test    eax, eax
756
        jz      .load
757
        push    eax
758
        mov     si, save_quest
759
        call    print
29 halyavin 760
.waityn:
514 diamond 761
        mov     ah, 0
762
        int     16h
763
        or      al, 20h
764
        cmp     al, 'n'
765
        jz      .loadc
766
        cmp     al, 'y'
767
        jnz     .waityn
768
        call    putchar
769
        mov     byte [space_msg+80], 186
770
        pop     eax
771
        push    cs
772
        push    .cont
773
        push    eax
774
        retf
29 halyavin 775
.loadc:
514 diamond 776
        pop     eax
29 halyavin 777
.cont:
514 diamond 778
        push    cs
779
        pop     ds
780
        mov     si, space_msg
781
        mov     byte [si+80], 0
782
        _setcursor 15,0
783
        call    printplain
784
        _setcursor 15,0
29 halyavin 785
.load:
786
; \end{diamond}[02.12.2005]
1 ha 787
 
788
; ASK GRAPHICS MODE
789
 
713 Lrz 790
        call    set_vmode
1 ha 791
 
792
; GRAPHICS ACCELERATION
346 diamond 793
; force yes
794
        mov     [es:0x901C], byte 1
1 ha 795
 
514 diamond 796
; DMA ACCESS TO HD
1 ha 797
 
514 diamond 798
        mov     al, [preboot_dma]
799
        mov     [es:0x901F], al
346 diamond 800
 
1 ha 801
; VRR_M USE
802
 
465 serge 803
        mov     al,[preboot_vrrm]
514 diamond 804
        mov     [es:0x9030], al
805
        mov     [es:0x901E], byte 1
1 ha 806
 
807
; BOOT DEVICE
808
 
514 diamond 809
        mov     al, [preboot_device]
40 halyavin 810
        dec     al
514 diamond 811
        mov     [boot_dev], al
1 ha 812
 
813
; READ DISKETTE TO MEMORY
814
 
465 serge 815
;        cmp     [boot_dev],0
1 ha 816
        jne     no_sys_on_floppy
465 serge 817
        mov     si,diskload
1 ha 818
        call    print
514 diamond 819
        xor     ax, ax            ; reset drive
820
        xor     dx, dx
1 ha 821
        int     0x13
709 diamond 822
; do we boot from CD-ROM?
823
        mov     ah, 41h
824
        mov     bx, 55AAh
825
        xor     dx, dx
826
        int     0x13
827
        jc      .nocd
828
        cmp     bx, 0AA55h
829
        jnz     .nocd
830
        mov     ah, 48h
831
        push    ds
832
        push    es
833
        pop     ds
834
        mov     si, 0xa000
835
        mov     word [si], 30
836
        int     0x13
837
        pop     ds
838
        jc      .nocd
839
        push    ds
840
        lds     si, [es:si+26]
841
        test    byte [ds:si+10], 40h
842
        pop     ds
843
        jz      .nocd
844
; yes - read all floppy by 18 sectors
795 shurf 845
 
846
; TODO: !!!! read only first sector and set variables !!!!!
847
; ...
848
; TODO: !!! then read flippy image track by track
849
 
850
	mov     cx, 0x0001      ; startcyl,startsector
709 diamond 851
.a1:
852
        push    cx dx
853
        mov     al, 18
854
        mov     bx, 0xa000
855
        call    boot_read_floppy
856
        mov     si, movedesc
857
        push    es
858
        push    ds
859
        pop     es
860
        mov     cx, 256*18
861
        mov     ah, 0x87
862
        int     0x15
863
        pop     es
864
        pop     dx cx
865
        test    ah, ah
866
        jnz     sayerr_floppy
867
        add     dword [si+8*3+2], 512*18
868
        inc     dh
869
        cmp     dh, 2
870
        jnz     .a1
871
        mov     dh, 0
872
        inc     ch
873
        cmp     ch, 80
874
        jae     ok_sys_on_floppy
875
        pusha
876
        mov     al, ch
877
        shr     ch, 2
878
        add     al, ch
879
        aam
880
        xchg    al, ah
881
        add     ax, '00'
882
        mov     si, pros
883
        mov     [si], ax
884
        call    printplain
885
        popa
886
        jmp     .a1
887
.nocd:
888
; no - read only used sectors from floppy
134 diamond 889
; now load floppy image to memory
890
; at first load boot sector and first FAT table
795 shurf 891
 
892
; read only first sector and fill variables
893
	mov	cx, 0x0001	; first logical sector
894
	xor	dx, dx		; head = 0, drive = 0 (a:)
895
	mov	al, 1		; read one sector
896
	mov	bx, 0xB000	; es:bx -> data area
897
	call	boot_read_floppy
898
; fill the necessary parameters to work with a floppy
899
	mov	ax, word [es:bx+24]
900
	mov	word [BPB_SecPerTrk], ax
901
	mov	ax, word [es:bx+26]
902
	mov	word [BPB_NumHeads], ax
903
	mov	ax, word [es:bx+22]
904
	mov	word [BPB_FATSz16], ax
905
	mov	ax, word [es:bx+17]
906
	mov	word [BPB_RootEntCnt], ax
907
	mov	ax, word [es:bx+11]
908
	mov	word [BPB_BytsPerSec], ax
909
	mov	ax, word [es:bx+14]
910
	mov	word [BPB_RsvdSecCnt], ax
911
	mov	ax, word [es:bx+19]
912
	mov	word [BPB_TotSec16], ax
913
	mov	al, byte [es:bx+13]
914
	mov	byte [BPB_SecPerClus], al
915
	mov	al, byte [es:bx+16]
916
	mov	byte [BPB_NumFATs], al
917
; count of clusters in FAT12 ((size_of_FAT*2)/3)
918
	mov	ax, word [BPB_FATSz16]
919
	mov	cx, word [BPB_BytsPerSec]
920
	xor	dx, dx
921
	mul	cx
922
	shl	ax, 1
923
	mov	cx, 3
924
	div	cx		; now ax - number of clusters in FAT12
925
	mov	word [end_of_FAT], ax
926
 
927
; load first FAT table
928
	mov     cx, 0x0002      ; startcyl,startsector		; TODO!!!!!
134 diamond 929
        xor     dx, dx          ; starthead,drive
795 shurf 930
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
931
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
134 diamond 932
        call    boot_read_floppy
795 shurf 933
	mov	bx, 0xB000
934
 
134 diamond 935
; and copy them to extended memory
465 serge 936
        mov     si, movedesc
795 shurf 937
        mov     [si+8*2+3], bh		; from
938
 
939
	mov	ax, word [BPB_BytsPerSec]
940
	shr	ax, 1			; words per sector
941
	mov	cx, word [BPB_RsvdSecCnt]
942
	add	cx, word [BPB_FATSz16]
943
	mul	cx
944
	push	ax			; save to stack count of words in boot+FAT
945
	xchg	ax, cx
946
 
134 diamond 947
        push    es
948
        push    ds
949
        pop     es
950
        mov     ah, 0x87
951
        int     0x15
795 shurf 952
	pop	es
76 mario79 953
        test    ah, ah
134 diamond 954
        jz      @f
955
sayerr_floppy:
956
        mov     dx, 0x3f2
957
        mov     al, 0
958
        out     dx, al
465 serge 959
        mov     si, memmovefailed
134 diamond 960
        jmp     sayerr_plain
961
@@:
795 shurf 962
	pop	ax			; restore from stack count of words in boot+FAT
963
	shl	ax, 1			; make bytes count from count of words
964
	and	eax, 0ffffh
965
        add     dword [si+8*3+2], eax
966
 
967
; copy first FAT to second copy
968
; TODO: BPB_NumFATs !!!!!
969
	add	bx, word [BPB_BytsPerSec]	; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
970
        mov     byte [si+8*2+3], bh	; bx - begin of FAT
971
 
972
	mov	ax, word [BPB_BytsPerSec]
973
	shr	ax, 1			; words per sector
974
	mov	cx, word [BPB_FATSz16]
975
	mul	cx
976
	mov	cx, ax			; cx - count of words in FAT
977
 
978
        push    es
979
        push    ds
980
        pop     es
134 diamond 981
        mov     ah, 0x87
982
        int     0x15
983
        pop     es
984
        test    ah, ah
985
        jnz     sayerr_floppy
795 shurf 986
 
987
	mov	ax, cx
988
	shl	ax, 1
989
	and	eax, 0ffffh		; ax - count of bytes in FAT
990
        add     dword [si+8*3+2], eax
991
 
992
; reading RootDir
993
; TODO: BPB_NumFATs
994
	add	bx, ax
995
	add	bx, 100h
996
	and	bx, 0ff00h			; bx - place in buffer to write RootDir
997
	push	bx
998
 
999
	mov	bx, word [BPB_BytsPerSec]
1000
	shr	bx, 5				; divide bx by 32
1001
	mov	ax, word [BPB_RootEntCnt]
1002
	xor	dx, dx
1003
	div	bx
1004
	push	ax				; ax - count of RootDir sectors
1005
 
1006
	mov	ax, word [BPB_FATSz16]
1007
	xor	cx, cx
1008
	mov	cl, byte [BPB_NumFATs]
1009
	mul	cx
1010
	add	ax, word [BPB_RsvdSecCnt]	; ax - first sector of RootDir
1011
 
1012
	mov	word [FirstDataSector], ax
1013
	pop	bx
1014
	push	bx
1015
	add	word [FirstDataSector], bx	; Begin of data region of floppy
1016
 
1017
; read RootDir
1018
	call	conv_abs_to_THS
1019
	pop	ax
1020
	pop	bx				; place in buffer to write
1021
	push	ax
1022
        call    boot_read_floppy		; read RootDir into buffer
1023
; copy RootDir
1024
	mov	byte [si+8*2+3], bh		; from buffer
1025
	pop	ax				; ax = count of RootDir sectors
1026
	mov	cx, word [BPB_BytsPerSec]
1027
	mul	cx
1028
	shr	ax, 1
1029
	mov	cx, ax				; count of words to copy
1030
	push	es
1031
	push	ds
1032
	pop	es
1033
        mov     ah, 0x87
1034
        int     0x15
1035
	pop	es
1036
 
1037
	mov	ax, cx
1038
	shl	ax, 1
1039
	and	eax, 0ffffh		; ax - count of bytes in RootDir
1040
        add     dword [si+8*3+2], eax	; add count of bytes copied
1041
 
1042
; Reading data clusters from floppy
1043
	mov	byte [si+8*2+3], bh
1044
	push	bx
1045
 
1046
	mov	di, 2			; First data cluster
134 diamond 1047
.read_loop:
795 shurf 1048
	mov	bx, di
1049
	shr	bx, 1			; bx+di = di*1.5
1050
	jnc	.even
1051
	test	word [es:bx+di+0xB200], 0xFFF0	; TODO: may not be 0xB200 !!!
1052
	jmp	@f
134 diamond 1053
.even:
795 shurf 1054
	test	word [es:bx+di+0xB200], 0xFFF	; TODO: may not be 0xB200 !!!
1055
 
134 diamond 1056
@@:
795 shurf 1057
	jz	.skip
1058
; read cluster di
1059
;.read:
1060
	;conv cluster di to abs. sector ax
1061
	; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1062
	mov	ax, di
1063
	sub	ax, 2
1064
	xor	bx, bx
1065
	mov	bl, byte [BPB_SecPerClus]
1066
	mul	bx
1067
	add	ax, word [FirstDataSector]
1068
	call	conv_abs_to_THS
1069
	pop	bx
1070
	push	bx
1071
	mov	al, byte [BPB_SecPerClus]	; number of sectors in cluster
1072
	call	boot_read_floppy
76 mario79 1073
        push    es
1074
        push    ds
1 ha 1075
        pop     es
134 diamond 1076
        pusha
795 shurf 1077
;
1078
	mov	ax, word [BPB_BytsPerSec]
1079
	xor	cx, cx
1080
	mov	cl, byte [BPB_SecPerClus]
1081
	mul	cx
1082
	shr	ax, 1				; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1083
	mov	cx, ax				; number of words to copy (count words in cluster)
1084
;
1085
	mov     ah, 0x87
1086
        int     0x15				; copy data
134 diamond 1087
        test    ah, ah
1 ha 1088
        popa
134 diamond 1089
        pop     es
1090
        jnz     sayerr_floppy
795 shurf 1091
; skip cluster di
134 diamond 1092
.skip:
795 shurf 1093
	mov	ax, word [BPB_BytsPerSec]
1094
	xor	cx, cx
1095
	mov	cl, byte [BPB_SecPerClus]
1096
	mul	cx
1097
	and	eax, 0ffffh		; ax - count of bytes in cluster
1098
	add	dword [si+8*3+2], eax
1099
 
1100
	mov	ax, word [end_of_FAT]	; max cluster number
134 diamond 1101
        pusha
1102
; draw percentage
795 shurf 1103
; total clusters: ax
1104
; read clusters: di
1105
	xchg	ax, di
134 diamond 1106
        mov     cx, 100
1107
        mul     cx
795 shurf 1108
	div	di
134 diamond 1109
        aam
1110
        xchg    al, ah
1111
        add     ax, '00'
465 serge 1112
        mov     si, pros
134 diamond 1113
        cmp     [si], ax
1114
        jz      @f
1115
        mov     [si], ax
1 ha 1116
        call    printplain
134 diamond 1117
@@:
1 ha 1118
        popa
134 diamond 1119
        inc     di
795 shurf 1120
	cmp	di, word [end_of_FAT]	; max number of cluster
134 diamond 1121
        jnz     .read_loop
795 shurf 1122
	pop	bx			; clear stack
134 diamond 1123
 
709 diamond 1124
ok_sys_on_floppy:
514 diamond 1125
        mov     si, backspace2
1 ha 1126
        call    printplain
514 diamond 1127
        mov     si, okt
1 ha 1128
        call    printplain
514 diamond 1129
no_sys_on_floppy:
1130
        xor     ax, ax          ; reset drive
1131
        xor     dx, dx
1 ha 1132
        int     0x13
514 diamond 1133
        mov     dx, 0x3f2       ; floppy motor off
1134
        mov     al, 0
1135
        out     dx, al
1 ha 1136
 
1137
 
1138
; SET GRAPHICS
1139
 
514 diamond 1140
        xor     ax, ax
1141
        mov     es, ax
164 serge 1142
 
514 diamond 1143
        mov     ax, [es:0x9008]         ; vga & 320x200
1144
        mov     bx, ax
1145
        cmp     ax, 0x13
1 ha 1146
        je      setgr
514 diamond 1147
        cmp     ax, 0x12
1 ha 1148
        je      setgr
514 diamond 1149
        mov     ax, 0x4f02              ; Vesa
412 serge 1150
setgr:
1 ha 1151
        int     0x10
514 diamond 1152
        test    ah, ah
1153
        mov     si, fatalsel
713 Lrz 1154
        jnz     v_mode_error
1 ha 1155
; set mode 0x12 graphics registers:
514 diamond 1156
        cmp     bx, 0x12
1 ha 1157
        jne     gmok2
1158
 
514 diamond 1159
        mov     al, 0x05
1160
        mov     dx, 0x03ce
40 halyavin 1161
        push    dx
514 diamond 1162
        out     dx, al      ; select GDC mode register
1163
        mov     al, 0x02
1164
        inc     dx
1165
        out     dx, al      ; set write mode 2
1 ha 1166
 
514 diamond 1167
        mov     al, 0x02
1168
        mov     dx, 0x03c4
1169
        out     dx, al      ; select VGA sequencer map mask register
1170
        mov     al, 0x0f
1171
        inc     dx
1172
        out     dx, al      ; set mask for all planes 0-3
1 ha 1173
 
514 diamond 1174
        mov     al, 0x08
1175
        pop     dx
1176
        out     dx, al      ; select GDC bit mask register
1 ha 1177
                           ; for writes to 0x03cf
412 serge 1178
gmok2:
76 mario79 1179
        push    ds
514 diamond 1180
        pop     es