Subversion Repositories Kolibri OS

Rev

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