Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
3
;; Kolibri OS - based on source code Menuet OS, but not 100% compatible.
4
;;
5
;; See file COPYING or GNU.TXT for details with these additional details:
6
;;     - All code written in 32 bit x86 assembly language
7
;;     - No external code (eg. bios) at process execution time
8
;;
9
;;
10
;;   Compile with last version FASM
11
;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 me_root 13
include "kglobals.inc"
1 ha 14
include "lang.inc"
15
 
16
WinMapAddress           equ     0x460000
17
display_data       = 0x460000
18
 
19
max_processes      equ   255
20
 
21
window_data        equ   0x0000
22
tss_data           equ   0xD20000
23
;tss_step           equ   (128+2048) ; tss & i/o - 16384 ports, * 256=557056
24
tss_step           equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
25
draw_data          equ   0xC00000
26
sysint_stack_data  equ   0xC03000
27
 
28
 
29
twdw               equ   (0x3000-window_data)
30
 
31
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32
;;
33
;;   Included files:
34
;;
35
;;   Kernel16.inc
36
;;    - Booteng.inc   English text for bootup
37
;;    - Bootcode.inc  Hardware setup
38
;;    - Pci16.inc     PCI functions
39
;;
40
;;   Kernel32.inc
41
;;    - Sys32.inc     Process management
42
;;    - Shutdown.inc  Shutdown and restart
43
;;    - Fat32.inc     Read / write hd
44
;;    - Vesa12.inc    Vesa 1.2 driver
45
;;    - Vesa20.inc    Vesa 2.0 driver
46
;;    - Vga.inc       VGA driver
47
;;    - Stack.inc     Network interface
48
;;    - Mouse.inc     Mouse pointer
49
;;    - Scincode.inc  Window skinning
50
;;    - Pci32.inc     PCI functions
51
;;
52
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53
 
54
 
55
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56
;;                                                                      ;;
57
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
58
;;                                                                      ;;
59
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60
 
61
use16
62
                  org   0x10000
63
macro diff16 title,l2
64
 {
65
  local s,d,l1
66
  s = l2
67
  display title,': 0x'
68
  repeat 8
69
   d = 48 + s shr ((8-%) shl 2) and $0F
70
   if d > 57
71
    d = d + 65-57-1
72
   end if
73
   display d
74
  end repeat
75
  display 13,10
76
 }
77
                  jmp   start_of_code
78
 
79
; mike.dld {
80
db 0
81
dd servetable-0x10000
82
draw_line       dd __sys_draw_line
83
disable_mouse   dd __sys_disable_mouse
84
draw_pointer    dd __sys_draw_pointer
85
drawbar         dd __sys_drawbar
86
putpixel        dd __sys_putpixel
87
; } mike.dld
88
 
5 halyavin 89
version           db    'Kolibri OS  version 0.5.1.0      ',13,10,13,10,0
1 ha 90
                  ;dd    endofcode-0x10000
91
 
92
                  ;db   'Boot02'
93
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
94
include "boot/preboot.inc"
95
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
96
 
97
preboot_lfb       db    0
98
preboot_bootlog   db    0
99
 
100
 
101
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102
;;                                                                      ;;
103
;;                      16 BIT INCLUDED FILES                           ;;
104
;;                                                                      ;;
105
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106
 
7 me_root 107
include "kernel16.inc"
1 ha 108
 
109
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110
;;                                                                      ;;
111
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
112
;;                                                                      ;;
113
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114
 
3 halyavin 115
os_data        =  os_data_l-gdts    ; GDTs
116
os_code        =  os_code_l-gdts
1 ha 117
int_code       equ  int_code_l-gdts
118
int_data       equ  int_data_l-gdts
119
tss0sys        equ  tss0sys_l-gdts
120
graph_data     equ  3+graph_data_l-gdts
121
tss0           equ  tss0_l-gdts
122
app_code       equ  3+app_code_l-gdts
123
app_data       equ  3+app_data_l-gdts
124
 
125
 
126
 
127
; CR0 Flags - Protected mode and Paging
128
 
129
        mov     ecx,0x00000001
130
        ;and     ebx,65535
131
        ;cmp     ebx,00100000000000000b ; lfb -> paging
132
        ;jb      no_paging
133
        ;mov     ax,0x0000
134
        ;mov     es,ax
135
        ;mov     al,[es:0x901E]
136
        ;cmp     al,1
137
        ;je      no_paging
138
        ;or      ecx, 0x80000000
139
       ;no_paging:
140
 
141
; Enabling 32 bit protected mode
142
 
143
        sidt    [cs:old_ints_h-0x10000]
144
 
145
        cli                             ; disable all irqs
146
        cld
147
        mov     al,255                  ; mask all irqs
148
        out     0xa1,al
149
        out     0x21,al
150
   l.5: in      al, 0x64                ; Enable A20
151
        test    al, 2
152
        jnz     l.5
153
        mov     al, 0xD1
154
        out     0x64, al
155
   l.6: in      al, 0x64
156
        test    al, 2
157
        jnz     l.6
158
        mov     al, 0xDF
159
        out     0x60, al
160
        lgdt    [cs:gdts-0x10000]       ; Load GDT
161
        mov     eax, cr0                ; Turn on paging // protected mode
162
        or      eax, ecx
163
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
164
        mov     cr0, eax
165
        jmp     byte $+2
166
        mov     ax,os_data              ; Selector for os
167
        mov     ds,ax
168
        mov     es,ax
169
        mov     fs,ax
170
        mov     gs,ax
171
        mov     ss,ax
12 halyavin 172
        mov     esp,0x3ec00             ; Set stack
1 ha 173
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
174
 
175
use32
176
 
177
iglobal
178
  boot_memdetect    db   'Determining amount of memory',0
179
  boot_fonts        db   'Fonts loaded',0
180
  boot_tss          db   'Setting TSSs',0
181
  boot_cpuid        db   'Reading CPUIDs',0
182
  boot_devices      db   'Detecting devices',0
183
  boot_timer        db   'Setting timer',0
184
  boot_irqs         db   'Reprogramming IRQs',0
185
  boot_setmouse     db   'Setting mouse',0
186
  boot_windefs      db   'Setting window defaults',0
187
  boot_bgr          db   'Calculating background',0
188
  boot_resirqports  db   'Reserving IRQs & ports',0
189
  boot_setrports    db   'Setting addresses for IRQs',0
190
  boot_setostask    db   'Setting OS task',0
191
  boot_allirqs      db   'Unmasking all IRQs',0
192
  boot_tsc          db   'Reading TSC',0
193
  boot_pal_ega      db   'Setting EGA/CGA 320x200 palette',0
194
  boot_pal_vga      db   'Setting VGA 640x480 palette',0
195
  boot_mtrr         db   'Setting MTRR',0
196
  boot_tasking      db   'All set - press ESC to start',0
197
endg
198
 
199
iglobal
200
  boot_y dd 10
201
endg
202
 
203
boot_log:
204
         pushad
205
 
206
         mov   edx,esi
207
.bll3:   inc   edx
208
         cmp   [edx],byte 0
209
         jne   .bll3
210
         sub   edx,esi
211
         mov   eax,10*65536
212
         mov   ax,word [boot_y]
213
         add   [boot_y],dword 10
214
         mov   ebx,0xffffff
215
         mov   ecx,esi
216
         mov   edi,1
217
         call  dtext
218
 
219
         mov   [novesachecksum],1000
220
         call  checkEgaCga
221
 
222
         cmp   [preboot_blogesc],byte 1
223
         je    .bll2
224
 
225
         cmp   esi,boot_tasking
226
         jne   .bll2
227
         ; begin ealex 04.08.05
228
;         in    al,0x61
229
;         and   al,01111111b
230
;         out   0x61,al
231
         ; end ealex 04.08.05
232
.bll1:   in    al,0x60    ; wait for ESC key press
233
         cmp   al,129
234
         jne   .bll1
235
 
236
.bll2:   popad
237
 
238
         ret
239
 
240
uglobal
241
  cpuid_0    dd  0,0,0,0
242
  cpuid_1    dd  0,0,0,0
243
  cpuid_2    dd  0,0,0,0
244
  cpuid_3    dd  0,0,0,0
245
endg
246
 
247
iglobal
248
  firstapp   db  'LAUNCHER   '
249
  char       db  'CHAR    MT '
250
  char2      db  'CHAR2   MT '
251
  bootpath   db  '/KOLIBRI    '
252
  bootpath2  db  0
253
  vmode      db  'VMODE   MDR'
254
  vrr_m      db  'VRR_M      '
255
endg
256
 
257
 
258
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259
;;                                                                      ;;
260
;;                          32 BIT ENTRY                                ;;
261
;;                                                                      ;;
262
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
263
 
264
align 4
265
 
266
B32:
267
; CLEAR 0x280000-0xF00000
268
 
269
        xor   eax,eax
270
        mov   edi,0x280000
271
        mov   ecx,(0x100000*0xF-0x280000) / 4
272
        cld
273
        rep   stosd
274
; CLEAR 0x80000-0x90000
275
;       xor   eax,eax
276
        mov   edi,0x80000
277
        mov   ecx,(0x90000-0x80000)/4
278
;       cld
279
        rep   stosd
280
 
281
; CLEAR KERNEL UNDEFINED GLOBALS
282
        mov   edi, endofcode
283
        mov   ecx, (uglobals_size/4)+4
284
        rep   stosd
285
 
286
; SAVE & CLEAR 0-0xffff
287
 
288
        mov   esi,0x0000
289
        mov   edi,0x2F0000
290
        mov   ecx,0x10000 / 4
291
        cld
292
        rep   movsd
293
        xor   eax,eax
294
        mov   edi,0
295
        mov   ecx,0x10000 / 4
296
        cld
297
        rep   stosd
298
 
299
; SAVE REAL MODE VARIABLES
300
;        movzx eax,byte [0x2f0000+0x9010]  ; mouse port
301
;        mov   [0xF604],byte 1  ;al
302
        mov   al,[0x2f0000+0x9000]        ; bpp
303
        mov   [0xFBF1],al
304
        movzx eax,word [0x2f0000+0x900A]  ; X max
305
        dec   eax
306
        mov   [0xfe00],eax
307
        movzx eax,word [0x2f0000+0x900C]  ; Y max
308
        dec   eax
309
        mov   [0xfe04],eax
310
        movzx eax,word [0x2f0000+0x9008]  ; screen mode
311
        mov   [0xFE0C],eax
312
        mov   eax,[0x2f0000+0x9014]       ; Vesa 1.2 bnk sw add
313
        mov   [0xE030],eax
314
        mov   [0xfe08],word 640*4         ; Bytes PerScanLine
315
        cmp   [0xFE0C],word 0x13          ; 320x200
316
        je    @f
317
        cmp   [0xFE0C],word 0x12          ; VGA 640x480
318
        je    @f
319
        mov   ax,[0x2f0000+0x9001]        ; for other modes
320
        mov   [0xfe08],ax
321
      @@:
322
 
323
; GRAPHICS ADDRESSES
324
 
325
        ;mov     eax,0x100000*8                    ; LFB address
326
        ;cmp     [0xfe0c],word 0x13
327
        ;je      no_d_lfb
328
        ;cmp     [0xfe0c],word 0x12
329
        ;je      no_d_lfb
330
        ;cmp     [0x2f0000+0x901e],byte 1
331
        ;jne     no_d_lfb
332
        mov     byte [0x2f0000+0x901e],0x0
333
        mov     eax,[0x2f0000+0x9018]
334
      ;no_d_lfb:
335
        mov     [0xfe80],eax
336
 
337
        cmp     [0xfe0c],word 0100000000000000b
338
        jge     setvesa20
339
        cmp     [0xfe0c],word 0x13
340
        je      v20ga32
341
        mov     [0xe020],dword Vesa12_putpixel24  ; Vesa 1.2
342
        mov     [0xe024],dword Vesa12_getpixel24
343
        cmp     [0xfbf1],byte 24
344
        jz      ga24
345
        mov     [0xe020],dword Vesa12_putpixel32
346
        mov     [0xe024],dword Vesa12_getpixel32
347
      ga24:
348
        jmp     v20ga24
349
      setvesa20:
350
        mov     [0xe020],dword Vesa20_putpixel24  ; Vesa 2.0
351
        mov     [0xe024],dword Vesa20_getpixel24
352
        cmp     [0xfbf1],byte 24
353
        jz      v20ga24
354
      v20ga32:
355
        mov     [0xe020],dword Vesa20_putpixel32
356
        mov     [0xe024],dword Vesa20_getpixel32
357
      v20ga24:
358
        cmp     [0xfe0c],word 0x12                ; 16 C VGA 640x480
359
        jne     no_mode_0x12
360
        mov     [0xe020],dword VGA_putpixel
361
        mov     [0xe024],dword Vesa20_getpixel32
362
      no_mode_0x12:
363
 
364
; MEMORY MODEL
365
 
366
;        mov     [0xfe84],dword 0x100000*16        ; apps mem base address
367
;        movzx   ecx,byte [0x2f0000+0x9030]
368
;        dec     ecx
369
;        mov     eax,16*0x100000 ; memory-16
370
;        shl     eax,cl
371
;        mov     [0xfe8c],eax      ; memory for use
372
;        cmp     eax,16*0x100000
373
;        jne     no16mb
374
;        mov     [0xfe84],dword 0xD80000 ; !!! 10 !!!
375
;      no16mb:
376
 
377
; init:
378
;  1) 0xFE84 - applications base
379
;  2) 0xFE8C - total amount of memory
380
 
381
        xor     edi, edi
382
  m_GMS_loop:
383
        add     edi, 0x400000
384
        mov     eax, dword [edi]
385
        mov     dword [edi], 'TEST'
386
        wbinvd
387
        cmp     dword [edi], 'TEST'
388
        jne     m_GMS_exit
389
        cmp     dword [0], 'TEST'
390
        je      m_GMS_exit
391
        mov     dword [es:edi], eax
392
        jmp     m_GMS_loop
393
  m_GMS_exit:
394
        mov     [edi], eax
395
        ; now edi contains the EXACT amount of memory
396
 
397
        mov     eax, 0x100000*16
398
        cmp     edi, eax ;0x100000*16
399
        jb      $                 ; less than 16 Mb
400
 
401
        mov     dword [0xFE84], eax ;0x100000*16
402
        cmp     edi, eax ;0x100000*16
403
        jne     @f
404
        mov     dword [0xFE84], 0xD80000 ; =0x100000*13.5
405
      @@:
406
        mov     dword [0xFE8C], edi
407
 
408
;!!!!!!!!!!!!!!!!!!!!!!!!!!
409
include 'detect/disks.inc'
410
;!!!!!!!!!!!!!!!!!!!!!!!!!!
411
 
412
; CHECK EXTRA REGION
413
; ENABLE PAGING
414
        mov     eax,cr0
415
        or      eax,0x80000000
416
        mov     cr0,eax
417
        jmp     $+2
418
        mov     dword [0xfe80],0x800000
419
 
420
;Set base of graphic segment to linear address of LFB
421
        mov     eax,[0xfe80]                      ; set for gs
422
        mov     [graph_data_l+2],ax
423
        shr     eax,16
424
        mov     [graph_data_l+4],al
425
        mov     [graph_data_l+7],ah
426
 
427
; READ RAMDISK IMAGE FROM HD
428
 
429
;!!!!!!!!!!!!!!!!!!!!!!!
430
include 'boot/rdload.inc'
431
;!!!!!!!!!!!!!!!!!!!!!!!
432
;    mov    [dma_hdd],1
433
; CALCULATE FAT CHAIN FOR RAMDISK
434
 
435
        call  calculatefatchain
436
 
437
; LOAD VMODE DRIVER
438
 
439
;!!!!!!!!!!!!!!!!!!!!!!!
440
include 'vmodeld.inc'
441
;!!!!!!!!!!!!!!!!!!!!!!!
442
 
443
; LOAD FONTS I and II
444
 
445
        mov   [0x3000],dword 1
446
        mov   [0x3004],dword 1
447
        mov   [0x3010],dword 0x3020
448
 
449
        mov   eax,char
450
        mov   esi,12
451
        xor   ebx,ebx
12 halyavin 452
        mov   ecx,2560;26000
453
        mov   edx,0x3F600;0x37000
1 ha 454
        call  fileread
455
 
456
        mov   eax,char2
457
        mov   esi,12
458
        xor   ebx,ebx
12 halyavin 459
        mov   ecx,2560;26000
460
        mov   edx,0x3EC00;0x30000
1 ha 461
        call  fileread
462
 
463
        mov   esi,boot_fonts
464
        call  boot_log
465
 
466
; PRINT AMOUNT OF MEMORY
467
        mov     esi, boot_memdetect
468
        call    boot_log
469
 
470
        movzx   ecx, word [boot_y]
471
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
472
        sub     ecx, 10
473
        mov     edx, 0xFFFFFF
474
        mov     ebx, [0xFE8C]
475
        shr     ebx, 20
476
        mov     edi, 1
477
        mov     eax, 0x00040000
478
        call    display_number
479
 
480
; CHECK EXTENDED REGION
481
;        mov     dword [0x80000000],0x12345678
482
;        cmp     dword [0x80000000],0x12345678
483
;        jz      extended_region_found
484
;        mov     esi,boot_ext_region
485
;        call    boot_log
486
;        jmp     $
487
;extended_region_found:
488
 
489
        call    MEM_Init
490
;add 0x800000-0xc00000 area
491
        cmp     word [0xfe0c],0x13
492
        jle     .less_memory
493
        mov     eax,0x80000000      ;linear address
494
        mov     ebx,0x400000 shr 12 ;size in pages (4Mb)
495
        mov     ecx,0x800000        ;physical address
496
        jmp     .end_first_block
497
.less_memory:
498
        mov     eax,0x80180000      ;linear address
499
        mov     ebx,0x280000 shr 12 ;size in pages (2.5Mb)
500
        mov     ecx,0x980000        ;physical address
501
.end_first_block:
502
        call    MEM_Add_Heap        ;nobody can lock mutex yet
503
 
504
        call    create_general_page_table
505
;add 0x1000000(0xd80000)-end_of_memory area
506
        mov     eax,second_base_address
507
        mov     ebx,[0xfe8c]
508
        mov     ecx,[0xfe84]
509
        sub     ebx,ecx
510
        shr     ebx,12
511
        add     eax,ecx
512
        call    MEM_Add_Heap
513
;init physical memory manager.
514
        call    Init_Physical_Memory_Manager
515
 
516
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
517
 
518
        mov   esi,boot_irqs
519
        call  boot_log
520
        call  rerouteirqs
521
 
522
        mov    esi,boot_tss
523
        call   boot_log
524
 
525
; BUILD SCHEDULER
526
 
527
        call   build_scheduler ; sys32.inc
528
 
529
; LOAD IDT
13 poddubny 530
        lidt   [cs:idtreg]
1 ha 531
 
532
; READ CPUID RESULT
533
 
534
        mov     esi,boot_cpuid
535
        call    boot_log
536
        pushfd                  ; get current flags
537
        pop     eax
538
        mov     ecx,eax
539
        xor     eax,0x00200000  ; attempt to toggle ID bit
540
        push    eax
541
        popfd
542
        pushfd                  ; get new EFLAGS
543
        pop     eax
544
        push    ecx             ; restore original flags
545
        popfd
546
        and     eax,0x00200000  ; if we couldn't toggle ID,
547
        and     ecx,0x00200000  ; then this is i486
548
        cmp     eax,ecx
549
        jz      nopentium
550
        ; It's Pentium or later. Use CPUID
551
        mov     edi,cpuid_0
552
        mov     esi,0
553
      cpuid_new_read:
554
        mov     eax,esi
555
        cpuid
556
        call    cpuid_save
557
        add     edi,4*4
558
        cmp     esi,3
559
        jge     cpuid_done
560
        cmp     esi,[cpuid_0]
561
        jge     cpuid_done
562
        inc     esi
563
        jmp     cpuid_new_read
564
      cpuid_save:
565
        mov     [edi+00],eax
566
        mov     [edi+04],ebx
567
        mov     [edi+8],ecx
568
        mov     [edi+12],edx
569
        ret
570
      cpuid_done:
571
      nopentium:
572
 
573
; CR4 flags - enable fxsave / fxrstore
574
;
575
;        finit
576
;        mov     eax,1
577
;        cpuid
578
;        test    edx,1000000h
579
;        jz      fail_fpu
580
;        mov     eax,cr4
581
;        or      eax,200h        ; Enable fxsave/fxstor
582
;        mov     cr4,eax
583
;     fail_fpu:
584
 
585
; DETECT DEVICES
586
 
587
        mov    esi,boot_devices
588
        call   boot_log
589
        call   detect_devices
590
 
591
 ; TIMER SET TO 1/100 S
592
 
593
        mov   esi,boot_timer
594
        call  boot_log
595
        mov   al,0x34              ; set to 100Hz
596
        out   0x43,al
597
        mov   al,0x9b              ; lsb    1193180 / 1193
598
        out   0x40,al
599
        mov   al,0x2e              ; msb
600
        out   0x40,al
601
 
602
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
603
;include 'detect/commouse.inc'
604
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
605
; SET MOUSE
606
 
607
        mov   esi,boot_setmouse
608
        call  boot_log
609
        call  setmouse
610
 
611
; SET PRELIMINARY WINDOW STACK AND POSITIONS
612
 
613
        mov   esi,boot_windefs
614
        call  boot_log
615
        call  setwindowdefaults
616
 
617
; SET BACKGROUND DEFAULTS
618
 
619
        mov   esi,boot_bgr
620
        call  boot_log
621
        call  calculatebackground
622
 
623
; RESERVE SYSTEM IRQ'S JA PORT'S
624
 
625
        mov   esi,boot_resirqports
626
        call  boot_log
627
        call  reserve_irqs_ports
628
 
629
; SET PORTS FOR IRQ HANDLERS
630
 
631
        mov  esi,boot_setrports
632
        call boot_log
633
        call setirqreadports
634
 
635
; SET UP OS TASK
636
 
637
        mov  esi,boot_setostask
638
        call boot_log
639
        ; name for OS/IDLE process
640
        mov  [0x80000+256+0],dword 'OS/I'
641
        mov  [0x80000+256+4],dword 'DLE '
642
        ; task list
643
        mov  [0x3004],dword 2         ; number of processes
644
        mov  [0x3000],dword 0         ; process count - start with os task
645
        mov  [0x3020+0xE],byte  1     ; on screen number
646
        mov  [0x3020+0x4],dword 1     ; process id number
647
 
648
        ; set default flags & stacks
649
        mov  [l.eflags],dword 0x11202 ; sti and resume
650
        mov  [l.ss0], os_data
651
        ; osloop - TSS
652
        mov  eax,cr3
653
        mov  [l.cr3],eax
654
        mov  [l.eip],osloop
13 poddubny 655
        mov  [l.esp],sysint_stack_data + 4096*2 ; uses slot 1 stack
1 ha 656
        mov  [l.cs],os_code
657
        mov  [l.ss],os_data
658
        mov  [l.ds],os_data
659
        mov  [l.es],os_data
660
        mov  [l.fs],os_data
661
        mov  [l.gs],os_data
662
        ; move tss to tss_data+tss_step
663
        mov  esi,tss_sceleton
664
        mov  edi,tss_data+tss_step
665
        mov  ecx,120/4
666
        cld
667
        rep  movsd
668
 
669
        mov  ax,tss0
670
        ltr  ax
671
 
672
 
673
; READ TSC / SECOND
674
 
675
        mov   esi,boot_tsc
676
        call  boot_log
677
        call  _rdtsc
678
        mov   ecx,eax
679
        mov   esi,250               ; wait 1/4 a second
680
        call  delay_ms
681
        call  _rdtsc
682
        sub   eax,ecx
683
        shl   eax,2
684
        mov   [0xf600],eax          ; save tsc / sec
685
 
686
; SET VARIABLES
687
 
688
        call  set_variables
689
 
690
; STACK AND FDC
691
 
692
        call  stack_init
693
        call  fdc_init
694
 
695
; PALETTE FOR 320x200 and 640x480 16 col
696
 
697
        cmp   [0xfe0c],word 0x12
698
        jne   no_pal_vga
699
        mov   esi,boot_pal_vga
700
        call  boot_log
701
        call  paletteVGA
702
      no_pal_vga:
703
 
704
        cmp   [0xfe0c],word 0x13
705
        jne   no_pal_ega
706
        mov   esi,boot_pal_ega
707
        call  boot_log
708
        call  palette320x200
709
      no_pal_ega:
710
 
711
; LOAD DEFAULT SKIN
712
 
713
        call  load_default_skin
714
 
715
; MTRR'S
716
 
717
        call  enable_mtrr
718
 
719
 
720
; LOAD FIRST APPLICATION
721
        mov   [0x3000],dword 1 ;1
722
        mov   [0x3004],dword 1 ;1
723
        cli
724
        mov   al,[0x2f0000+0x9030]
725
        cmp   al,1
726
        jne   no_load_vrr_m
727
        mov   eax,vrr_m
728
        call  start_application_fl
729
        cmp   eax,2                  ; if no vrr_m app found
730
        je    first_app_found
731
 
732
    no_load_vrr_m:
733
        mov   eax,firstapp
734
        call  start_application_fl
735
 
736
        cmp   eax,2                  ; if no first app found - halt
737
        je    first_app_found
738
        mov   eax, 0xDEADBEEF
739
        hlt    ;jmp   $
740
      first_app_found:
741
        cli
742
 
743
        mov   [0x3004],dword 2
744
        mov   [0x3000],dword 1
745
 
746
 
747
; START MULTITASKING
748
 
749
        mov   esi,boot_tasking
750
        call  boot_log
751
 
752
        mov   [0xe000],byte 1        ; multitasking enabled
753
 
754
    mov   al, 0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
755
        call  kb_write
756
 
757
        mov     ecx,0
758
wait_loop_1:       ; variant 2
759
; ÷èòàåì ïîðò ñîñòîÿíèÿ ïðîöåññîðà 8042
760
        in      al,64h
761
    and     al,00000010b  ; ôëàã ãîòîâíîñòè
762
; îæèäàåì ãîòîâíîñòü ïðîöåññîðà 8042
763
    loopnz  wait_loop_1
764
 
765
; SET KEYBOARD PARAMETERS
766
       ; mov   al, 0xED       ; svetodiody - only for testing!
767
       ; call  kb_write
768
       ; call  kb_read
769
       ; mov   al, 111b
770
       ; call  kb_write
771
       ; call  kb_read
772
 
773
        mov   al, 0xF3       ; set repeat rate & delay
774
        call  kb_write
775
        call  kb_read
776
        mov   al, 00100010b ; 24 500  ;00100100b  ; 20 500
777
        call  kb_write
778
        call  kb_read
779
     ;// mike.dld [
780
        call  set_lights
781
     ;// mike.dld ]
782
 
783
 
784
; UNMASK ALL IRQ'S
785
 
786
        mov   esi,boot_allirqs
787
        call  boot_log
788
 
789
        cli                          ;guarantee forbidance of interrupts.
790
        mov   al,0                   ; unmask all irq's
791
        out   0xA1,al
792
        out   0x21,al
793
 
794
        mov   ecx,32
795
 
796
     ready_for_irqs:
797
 
798
        mov   al,0x20                ; ready for irqs
799
        out   0x20,al
800
        out   0xa0,al
801
 
802
        loop  ready_for_irqs         ; flush the queue
803
 
804
;        mov    [dma_hdd],1
805
 
806
        sti
807
        jmp   $                      ; wait here for timer to take control
808
 
809
        ; Fly :)
810
 
811
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
812
;                                                                    ;
813
;                         MAIN OS LOOP                               ;
814
;                                                                    ;
815
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
816
align 32
817
osloop:
818
 
819
        call   check_mouse_data
820
        call   [draw_pointer]
821
 
822
        call   checkbuttons
823
        call   main_loop_sys_getkey
824
        call   checkwindows
825
        call   check_window_move_request
826
 
827
        call   checkmisc
828
        call   checkEgaCga
829
 
830
        call   stack_handler
831
 
832
        call   checkidle
833
        call   check_fdd_motor_status
834
        jmp    osloop
835
;temp_pointers:
836
; rd 32
837
; seed dd 0x12345678
838
 
839
checkidle:
840
 
841
        pushad
842
 
843
        cmp  [check_idle_semaphore],0
844
        jne  no_idle_state
845
 
846
        call change_task
847
        mov  eax,[idlemem]
848
        mov  ebx,[timer_ticks] ;[0xfdf0]
849
        cmp  eax,ebx
850
        jnz  idle_exit
851
        call _rdtsc
852
        mov  ecx,eax
853
      idle_loop:
854
        hlt
855
        cmp  [check_idle_semaphore],0
856
        jne  idle_loop_exit
857
        mov  eax,[timer_ticks] ;[0xfdf0]
858
        cmp  ebx,eax
859
        jz   idle_loop
860
      idle_loop_exit:
861
        mov  [idlemem],eax
862
        call _rdtsc
863
        sub  eax,ecx
864
        mov  ebx,[idleuse]
865
        add  ebx,eax
866
        mov  [idleuse],ebx
867
 
868
        popad
869
        ret
870
 
871
      idle_exit:
872
 
873
        mov  ebx,[timer_ticks] ;[0xfdf0]
874
        mov  [idlemem],ebx
875
        call change_task
876
 
877
        popad
878
        ret
879
 
880
      no_idle_state:
881
 
882
        dec  [check_idle_semaphore]
883
 
884
        mov  ebx,[timer_ticks] ;[0xfdf0]
885
        mov  [idlemem],ebx
886
        call change_task
887
 
888
        popad
889
        ret
890
 
891
uglobal
892
  idlemem               dd   0x0
893
  idleuse               dd   0x0
894
  idleusesec            dd   0x0
895
  check_idle_semaphore  dd   0x0
896
endg
897
 
898
 
899
 
900
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
901
;                                                                      ;
902
;                   INCLUDED SYSTEM FILES                              ;
903
;                                                                      ;
904
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
905
 
906
 
7 me_root 907
include "kernel32.inc"
1 ha 908
 
909
 
910
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911
;                                                                      ;
912
;                       KERNEL FUNCTIONS                               ;
913
;                                                                      ;
914
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
915
 
916
enable_mtrr:
917
 
918
        pushad
919
 
920
        cmp    [0x2f0000+0x901c],byte 2
921
        je     no_mtrr
922
        mov    eax,[0xFE0C]                ; if no LFB then no MTRR
923
        test   eax,0100000000000000b
924
        jz     no_mtrr
925
        mov    edx,[cpuid_1+3*4]           ; edx - MTRR's supported ?
926
        test   edx,1000000000000b
927
        jz     no_mtrr
928
        call   find_empty_mtrr
929
        cmp    ecx,0
930
        jz     no_mtrr
931
        mov    esi,boot_mtrr               ; 'setting mtrr'
932
        call   boot_log
933
        mov    edx,0x0                     ; LFB , +8 M , write combine
934
        mov    eax,[0x2f9018]
935
        or     eax,1
936
        wrmsr
937
        inc    ecx
938
        mov    edx,0xf
939
        mov    eax,0xff800800
940
        wrmsr
941
        mov    ecx,0x2ff                   ; enable mtrr's
942
        rdmsr
943
        or     eax,100000000000b           ; set
944
        wrmsr
945
     no_mtrr:
946
 
947
        popad
948
        ret
949
 
950
 
951
find_empty_mtrr:  ; 8 pairs checked
952
 
953
        mov    ecx,0x201-2
954
      mtrr_find:
955
        add    ecx,2
956
        cmp    ecx,0x200+8*2
957
        jge    no_free_mtrr
958
        rdmsr
959
        test   eax,0x0800
960
        jnz    mtrr_find
961
        dec    ecx
962
        ret
963
      no_free_mtrr:
964
        mov    ecx,0
965
        ret
966
 
967
reserve_irqs_ports:
968
 
969
        pushad
970
 
971
        mov  [irq_owner+4*0],byte 1    ; timer
972
        mov  [irq_owner+4*1],byte 1    ; keyboard
973
        mov  [irq_owner+4*5],byte 1    ; sound blaster
974
        mov  [irq_owner+4*6],byte 1    ; floppy diskette
975
        mov  [irq_owner+4*13],byte 1   ; math co-pros
976
        mov  [irq_owner+4*14],byte 1   ; ide I
977
        mov  [irq_owner+4*15],byte 1   ; ide II
978
        movzx eax,byte [0xf604]        ; mouse irq
979
        dec   eax
980
        add   eax,mouseirqtable
981
        movzx eax,byte [eax]
982
        shl   eax,2
983
        mov   [irq_owner+eax],byte 1
984
 
985
 
986
                                       ; RESERVE PORTS
987
        mov   edi,1                    ; 0x00-0xff
988
        mov   [0x2d0000],edi
989
        shl   edi,4
990
        mov   [0x2d0000+edi+0],dword 1
991
        mov   [0x2d0000+edi+4],dword 0x0
992
        mov   [0x2d0000+edi+8],dword 0xff
993
        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
994
        jne   ripl1
995
        inc   dword [0x2d0000]
996
        mov   edi,[0x2d0000]
997
        shl   edi,4
998
        mov   [0x2d0000+edi+0],dword 1
999
        mov   [0x2d0000+edi+4],dword 0x3f0
1000
        mov   [0x2d0000+edi+8],dword 0x3ff
1001
      ripl1:
1002
        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1003
        jne   ripl2
1004
        inc   dword [0x2d0000]
1005
        mov   edi,[0x2d0000]
1006
        shl   edi,4
1007
        mov   [0x2d0000+edi+0],dword 1
1008
        mov   [0x2d0000+edi+4],dword 0x2f0
1009
        mov   [0x2d0000+edi+8],dword 0x2ff
1010
      ripl2:
1011
 
1012
        popad
1013
        ret
1014
 
1015
iglobal
1016
mouseirqtable   db  12    ; ps2
1017
                db  4     ; com1
1018
                db  3     ; com2
1019
endg
1020
 
1021
setirqreadports:
1022
 
1023
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1024
        mov   [irq12read+4],dword 0                  ; end of port list
1025
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1026
        mov   [irq04read+4],dword 0                  ; end of port list
1027
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1028
        mov   [irq03read+4],dword 0                  ; end of port list
1029
 
1030
        ret
1031
 
1032
iglobal
1033
  process_number dd 0x1
1034
endg
1035
 
1036
uglobal
1037
  novesachecksum dd 0x0
1038
endg
1039
 
1040
checkEgaCga:
1041
 
1042
        cmp    [0xfe0c],dword 0x13
1043
        je     cnvl
1044
        ret
1045
      cnvl:
1046
 
1047
        pushad
1048
        mov    ecx,[0xfb0a]
1049
        cmp    ecx,[novesachecksum]
1050
        jne    novesal
1051
        popad
1052
        ret
1053
 
1054
      novesal:
1055
        mov    [novesachecksum],ecx
1056
        mov    ecx,0
1057
        movzx  eax,word [0xfb0c]
1058
        cmp    eax,100
1059
        jge    m13l3
1060
        mov    eax,100
1061
      m13l3:
1062
        cmp    eax,480-100
1063
        jbe    m13l4
1064
        mov    eax,480-100
1065
      m13l4:
1066
        sub    eax,100
1067
        imul   eax,640*4
1068
        add    ecx,eax
1069
        movzx  eax,word [0xfb0a]
1070
        cmp    eax,160
1071
        jge    m13l1
1072
        mov    eax,160
1073
      m13l1:
1074
        cmp    eax,640-160
1075
        jbe    m13l2
1076
        mov    eax,640-160
1077
      m13l2:
1078
        sub    eax,160
1079
        shl    eax,2
1080
        add    ecx,eax
1081
        mov    esi,[0xfe80]
1082
        add    esi,ecx
1083
        mov    edi,0xa0000
1084
        mov    edx,200
1085
        mov    ecx,320
1086
        cld
1087
     m13pix:
1088
        lodsd
1089
        push   eax
1090
        mov    ebx,eax
1091
        and    eax,(128+64+32)      ; blue
1092
        shr    eax,5
1093
        and    ebx,(128+64+32)*256  ; green
1094
        shr    ebx,8+2
1095
        add    eax,ebx
1096
        pop    ebx
1097
        and    ebx,(128+64)*256*256 ; red
1098
        shr    ebx,8+8
1099
        add    eax,ebx
1100
        stosb
1101
        loop   m13pix
1102
        mov    ecx,320
1103
        add    esi,4*(640-320)
1104
        dec    edx
1105
        jnz    m13pix
1106
 
1107
        popad
1108
        ret
1109
 
1110
 
1111
palette320x200:
1112
 
1113
       mov   edx,0x3c8
1114
       xor   eax, eax
1115
       out   dx,al
1116
       mov   ecx,256
1117
       mov   edx,0x3c9
1118
       xor   eax,eax
1119
 
1120
     palnew:
1121
       mov   al,0
1122
       test  ah,64
1123
       jz    pallbl1
1124
       add   al,21
1125
     pallbl1:
1126
       test  ah,128
1127
       jz    pallbl2
1128
       add   al,42
1129
     pallbl2:
1130
       out   dx,al
1131
       mov   al,0
1132
       test  ah,8
1133
       jz    pallbl3
1134
       add   al,8
1135
     pallbl3:
1136
       test  ah,16
1137
       jz    pallbl4
1138
       add   al,15
1139
     pallbl4:
1140
       test  ah,32
1141
       jz    pallbl5
1142
       add   al,40
1143
     pallbl5:
1144
       out   dx,al
1145
       mov   al,0
1146
       test  ah,1
1147
       jz    pallbl6
1148
       add   al,8
1149
     pallbl6:
1150
       test  ah,2
1151
       jz    pallbl7
1152
       add   al,15
1153
     pallbl7:
1154
       test  ah,4
1155
       jz    pallbl8
1156
       add   al,40
1157
     pallbl8:
1158
       out   dx,al
1159
       add   ah,1
1160
       loop  palnew
1161
 
1162
       ret
1163
 
1164
set_variables:
1165
 
1166
        mov   ecx,0x100                       ; flush port 0x60
1167
.fl60:  in    al,0x60
1168
        loop  .fl60
1169
        mov   [0xfcff],byte 0                 ; mouse buffer
1170
        mov   [0xf400],byte 0                 ; keyboard buffer
1171
        mov   [0xf500],byte 0                 ; button buffer
1172
;        mov   [0xfb0a],dword 100*65536+100    ; mouse x/y
1173
 
1174
        push  eax
1175
        mov   ax,[0x2f0000+0x900c]
1176
        shr   ax,1
1177
        shl   eax,16
1178
        mov   ax,[0x2f0000+0x900A]
1179
        shr   ax,1
1180
        mov   [0xfb0a],eax
1181
        pop   eax
1182
 
1183
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1184
        mov   [display_data-12],dword 1       ; tiled background
1185
        mov   [0xfe88],dword 0x2C0000         ; address of button list
1186
 
1187
     ;!! IP 04.02.2005:
1188
        mov   [next_usage_update], 100
1189
        mov   byte [0xFFFF], 0 ; change task if possible
1190
 
1191
        ret
1192
 
1193
;* mouse centered - start code- Mario79
1194
mouse_centered:
1195
        push  eax
1196
        mov   eax,[0xFE00]
1197
        shr   eax,1
1198
        mov   [0xFB0A],ax
1199
        mov   eax,[0xFE04]
1200
        shr   eax,1
1201
        mov   [0xFB0C],ax
1202
        pop   eax
1203
        ret
1204
;* mouse centered - end code- Mario79
1205
 
1206
align 4
1207
 
1208
sys_outport:
1209
 
1210
    mov   edi,ebx          ; separate flag for read / write
1211
    and   ebx,65535
1212
 
1213
    mov   ecx,[0x2d0000]
1214
    test  ecx,ecx
1215
    jne   sopl8
1216
    mov   [esp+36],dword 1
1217
    ret
1218
 
1219
  sopl8:
1220
    mov   edx,[0x3010]
1221
    mov   edx,[edx+0x4]
1222
    and   ebx,65535
1223
    cld
1224
  sopl1:
1225
 
1226
    mov   esi,ecx
1227
    shl   esi,4
1228
    add   esi,0x2d0000
1229
    cmp   edx,[esi+0]
1230
    jne   sopl2
1231
    cmp   ebx,[esi+4]
1232
    jb    sopl2
1233
    cmp   ebx,[esi+8]
1234
    jg    sopl2
1235
    jmp   sopl3
1236
 
1237
  sopl2:
1238
 
1239
    dec   ecx
1240
    jnz   sopl1
1241
    mov   [esp+36],dword 1
1242
    ret
1243
 
1244
  sopl3:
1245
 
1246
    test  edi,0x80000000 ; read ?
1247
    jnz   sopl4
1248
 
1249
    mov   dx,bx          ; write
1250
    out   dx,al
1251
    mov   [esp+36],dword 0
1252
    ret
1253
 
1254
  sopl4:
1255
 
1256
    mov   dx,bx          ; read
1257
    in    al,dx
1258
    and   eax,0xff
1259
    mov   [esp+36],dword 0
1260
    mov   [esp+24],eax
1261
    ret
1262
 
1263
 
1264
 
1265
align 4
1266
sys_sb16:
1267
 
1268
     cmp  word [sb16],word 0
1269
     jnz  sb16l1
1270
     mov  [esp+36],dword 1
1271
     ret
1272
   sb16l1:
1273
     mov  [esp+36],dword 0
1274
     cmp  eax,1    ; set volume - main
1275
     jnz  sb16l2
1276
     mov  dx,word [sb16]
1277
     add  dx,4
1278
     mov  al,0x22
1279
     out  dx,al
1280
     mov  esi,1
1281
     call delay_ms
1282
     mov  eax,ebx
1283
     inc  edx
1284
     out  dx,al
1285
     ret
1286
   sb16l2:
1287
 
1288
     cmp  eax,2    ; set volume - cd
1289
     jnz  sb16l3
1290
     mov  dx,word [sb16]
1291
     add  dx,4
1292
     mov  al,0x28
1293
     out  dx,al
1294
     mov  esi,1
1295
     call delay_ms
1296
     mov  eax,ebx
1297
     add  edx,1
1298
     out  dx,al
1299
     ret
1300
   sb16l3:
1301
      mov  [esp+36],dword 2
1302
      ret
1303
 
1304
 
1305
align 4
1306
 
1307
sys_sb16II:
1308
 
1309
     cmp  word [sb16],word 0
1310
     jnz  IIsb16l1
1311
     mov  [esp+36],dword 1
1312
     ret
1313
   IIsb16l1:
1314
 
1315
     cmp  eax,1    ; set volume - main
1316
     jnz  IIsb16l2
1317
     ; L
1318
     mov  dx,word [sb16]
1319
     add  dx,4
1320
     mov  al,0x30
1321
     out  dx,al
1322
     mov  eax,ebx
1323
     inc  edx
1324
     out  dx,al
1325
     ; R
1326
     mov  dx,word [sb16]
1327
     add  dx,4
1328
     mov  al,0x31
1329
     out  dx,al
1330
     mov  eax,ebx
1331
     inc  edx
1332
     out  dx,al
1333
     mov  [esp+36],dword 0
1334
     ret
1335
   IIsb16l2:
1336
 
1337
     cmp  eax,2    ; set volume - cd
1338
     jnz  IIsb16l3
1339
     ; L
1340
     mov  dx,word [sb16]
1341
     add  dx,4
1342
     mov  al,0x36
1343
     out  dx,al
1344
     mov  eax,ebx
1345
     inc  edx
1346
     out  dx,al
1347
     ; R
1348
     mov  dx,word [sb16]
1349
     add  dx,4
1350
     mov  al,0x37
1351
     out  dx,al
1352
     mov  eax,ebx
1353
     inc  edx
1354
     out  dx,al
1355
     mov  [esp+36],dword 0
1356
     ret
1357
   IIsb16l3:
1358
 
1359
     mov  [esp+36],dword 2
1360
     ret
1361
 
1362
 
1363
align 4
1364
 
1365
sys_wss:
1366
 
1367
     cmp  word [wss],word 0
1368
     jnz  wssl1
1369
     mov  [esp+36],dword 1
1370
     ret
1371
   wssl1:
1372
 
1373
     cmp  eax,1    ; set volume - main
1374
     jnz  wssl2
1375
     mov  [esp+36],dword 0
1376
     ret
1377
   wssl2:
1378
 
1379
     cmp  eax,2    ; set volume - cd
1380
     jnz  wssl3
1381
     ; L
1382
     mov  dx,word [wss]
1383
     add  dx,4
1384
     mov  al,0x2
1385
     out  dx,al
1386
     mov  esi,1
1387
     call delay_ms
1388
     mov  eax,ebx
1389
     inc  edx
1390
     out  dx,al
1391
     ; R
1392
     mov  dx,word [wss]
1393
     add  dx,4
1394
     mov  al,0x3
1395
     out  dx,al
1396
     mov  esi,1
1397
     call delay_ms
1398
     mov  eax,ebx
1399
     inc  edx
1400
     out  dx,al
1401
     mov  [esp+36],dword 0
1402
     ret
1403
   wssl3:
1404
     mov   [esp+36],dword 2
1405
     ret
1406
 
1407
display_number:
1408
 
1409
; eax = print type, al=0 -> ebx is number
1410
;                   al=1 -> ebx is pointer
1411
;                   ah=0 -> display decimal
1412
;                   ah=1 -> display hexadecimal
1413
;                   ah=2 -> display binary
1414
;                   eax bits 16-21 = number of digits to display (0-32)
1415
;                   eax bits 22-31 = reserved
1416
;
1417
; ebx = number or pointer
1418
; ecx = x shl 16 + y
1419
; edx = color
1420
 
1421
     cmp   eax,0xffff            ; length > 0 ?
1422
     jge   cont_displ
1423
     ret
1424
   cont_displ:
1425
 
1426
     cmp   eax,60*0x10000        ; length <= 60 ?
1427
     jbe   cont_displ2
1428
     ret
1429
   cont_displ2:
1430
 
1431
     pushad
1432
 
1433
     cmp   al,1                  ; ecx is a pointer ?
1434
     jne   displnl1
1435
     mov   edi,[0x3010]
1436
     mov   edi,[edi+0x10]
1437
     mov   ebx,[edi+ebx]
1438
   displnl1:
1439
     sub   esp,64
1440
 
1441
     cmp   ah,0                  ; DECIMAL
1442
     jne   no_display_desnum
1443
     shr   eax,16
1444
     and   eax,0x2f
1445
     push  eax
1446
     ;mov   edi,[0x3010]
1447
     ;mov   edi,[edi+0x10]
1448
     mov   edi,esp
1449
     add   edi,4+64
1450
     mov   ecx,eax
1451
     mov   eax,ebx
1452
     mov   ebx,10
1453
   d_desnum:
1454
     xor   edx,edx
1455
     div   ebx
1456
     add   dl,48
1457
     mov   [edi],dl
1458
     dec   edi
1459
     loop  d_desnum
1460
     pop   eax
1461
     call  draw_num_text
1462
     add   esp,64
1463
     popad
1464
     ret
1465
   no_display_desnum:
1466
 
1467
     cmp   ah,0x01               ; HEXADECIMAL
1468
     jne   no_display_hexnum
1469
     shr   eax,16
1470
     and   eax,0x2f
1471
     push  eax
1472
     ;mov   edi,[0x3010]
1473
     ;mov   edi,[edi+0x10]
1474
     mov   edi,esp
1475
     add   edi,4+64
1476
     mov   ecx,eax
1477
     mov   eax,ebx
1478
     mov   ebx,16
1479
   d_hexnum:
1480
     xor   edx,edx
1481
     div   ebx
1482
     add   edx,hexletters
1483
     mov   dl,[edx]
1484
     mov   [edi],dl
1485
     dec   edi
1486
     loop  d_hexnum
1487
     pop   eax
1488
     call  draw_num_text
1489
     add   esp,64
1490
     popad
1491
     ret
1492
   no_display_hexnum:
1493
 
1494
     cmp   ah,0x02               ; BINARY
1495
     jne   no_display_binnum
1496
     shr   eax,16
1497
     and   eax,0x2f
1498
     push  eax
1499
     ;mov   edi,[0x3010]
1500
     ;mov   edi,[edi+0x10]
1501
     mov   edi,esp
1502
     add   edi,4+64
1503
     mov   ecx,eax
1504
     mov   eax,ebx
1505
     mov   ebx,2
1506
   d_binnum:
1507
     xor   edx,edx
1508
     div   ebx
1509
     add   dl,48
1510
     mov   [edi],dl
1511
     dec   edi
1512
     loop  d_binnum
1513
     pop   eax
1514
     call  draw_num_text
1515
     add   esp,64
1516
     popad
1517
     ret
1518
   no_display_binnum:
1519
 
1520
     add   esp,64
1521
     popad
1522
     ret
1523
 
1524
 
1525
draw_num_text:
1526
 
1527
     ; dtext
1528
     ;
1529
     ; eax x & y
1530
     ; ebx color
1531
     ; ecx start of text
1532
     ; edx length
1533
     ; edi 1 force
1534
 
1535
     mov   edx,eax
1536
     mov   ecx,65
1537
     sub   ecx,eax
1538
     add   ecx,esp
1539
     add   ecx,4
1540
     mov   eax,[esp+64+32-8+4]
1541
     mov   ebx,[esp+64+32-12+4]
1542
     push  edx                       ; add window start x & y
1543
     push  ebx
1544
     mov   edx,[0x3010]
1545
     mov   ebx,[edx-twdw]
1546
     shl   ebx,16
1547
     add   ebx,[edx-twdw+4]
1548
     add   eax,ebx
1549
     pop   ebx
1550
     pop   edx
1551
     mov   edi,0
1552
     call  dtext
1553
 
1554
     ret
1555
 
1556
 
1557
read_string:
1558
 
1559
    ; eax  read_area
1560
    ; ebx  color of letter
1561
    ; ecx  color of background
1562
    ; edx  number of letters to read
1563
    ; esi  [x start]*65536 + [y_start]
1564
 
1565
    ret
1566
 
1567
 
1568
align 4
1569
 
1570
sys_setup:
1571
 
1572
; 1=roland mpu midi base , base io address
1573
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1574
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1575
; 4=sb16 base , base io address
1576
; 5=system language, 1eng 2fi 3ger 4rus
1577
; 6=wss base , base io address
1578
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1579
; 8=fat32 partition in hd
1580
; 9
1581
; 10 = sound dma channel
1582
; 11 = enable lba read
1583
; 12 = enable pci access
1584
 
1585
 
1586
     mov  [esp+36],dword 0
1587
     cmp  eax,1                      ; MIDI
1588
     jnz  nsyse1
1589
     cmp  ebx,0x100
1590
     jb   nsyse1
1591
     mov  edx,65535
1592
     cmp  edx,ebx
1593
     jb   nsyse1
1594
     mov  [midi_base],bx
1595
     mov  word [mididp],bx
1596
     inc  bx
1597
     mov  word [midisp],bx
1598
     ret
1599
 
1600
midi_base dw 0
1601
 
1602
   nsyse1:
1603
 
1604
     cmp  eax,2                      ; KEYBOARD
1605
     jnz  nsyse2
1606
     cmp  ebx,1
1607
     jnz  kbnobase
1608
     mov  edi,[0x3010]
1609
     add  ecx,[edi+0x10]
1610
     mov  eax,ecx
1611
     mov  ebx,keymap
1612
     mov  ecx,128
1613
     call memmove
1614
     ret
1615
   kbnobase:
1616
     cmp  ebx,2
1617
     jnz  kbnoshift
1618
     mov  edi,[0x3010]
1619
     add  ecx,[edi+0x10]
1620
     mov  eax,ecx
1621
     mov  ebx,keymap_shift
1622
     mov  ecx,128
1623
     call memmove
1624
     ret
1625
   kbnoshift:
1626
     cmp  ebx,3
1627
     jne  kbnoalt
1628
     mov  edi,[0x3010]
1629
     add  ecx,[edi+0x10]
1630
     mov  eax,ecx
1631
     mov  ebx,keymap_alt
1632
     mov  ecx,128
1633
     call memmove
1634
     ret
1635
   kbnoalt:
1636
     cmp  ebx,9
1637
     jnz  kbnocountry
1638
     mov  word [keyboard],cx
1639
     ret
1640
   kbnocountry:
1641
     mov  [esp+36],dword 1
1642
     ret
1643
   nsyse2:
1644
     cmp  eax,3                      ; CD
1645
     jnz  nsyse3
1646
     mov  [cd_base],bl
1647
     cmp  ebx,1
1648
     jnz  noprma
1649
     mov  [cdbase],0x1f0
1650
     mov  [cdid],0xa0
1651
   noprma:
1652
     cmp  ebx,2
1653
     jnz  noprsl
1654
     mov  [cdbase],0x1f0
1655
     mov  [cdid],0xb0
1656
   noprsl:
1657
     cmp  ebx,3
1658
     jnz  nosema
1659
     mov  [cdbase],0x170
1660
     mov  [cdid],0xa0
1661
   nosema:
1662
     cmp  ebx,4
1663
     jnz  nosesl
1664
     mov  [cdbase],0x170
1665
     mov  [cdid],0xb0
1666
   nosesl:
1667
     ret
1668
 
1669
cd_base db 0
1670
 
1671
   nsyse3:
1672
 
1673
     cmp  eax,4                      ; SB
1674
     jnz  nsyse4
1675
     cmp  ebx,0x100
1676
     jb   nsyse4
1677
     mov  edx,65535
1678
     cmp  edx,ebx
1679
     jb   nsyse4
1680
     mov  word [sb16],bx
1681
     ret
1682
   nsyse4:
1683
 
1684
     cmp  eax,5                      ; SYSTEM LANGUAGE
1685
     jnz  nsyse5
1686
     mov  [syslang],ebx
1687
     ret
1688
   nsyse5:
1689
 
1690
     cmp  eax,6                      ; WSS
1691
     jnz  nsyse6
1692
     cmp  ebx,0x100
1693
     jb   nsyse6
1694
     mov  [wss],ebx
1695
     ret
1696
 
1697
wss_temp dd 0
1698
 
1699
   nsyse6:
1700
 
1701
     cmp  eax,7                      ; HD BASE
1702
     jne  nsyse7
1703
     mov  [hd_base],bl
1704
     cmp  ebx,1
1705
     jnz  noprmahd
1706
     mov  [hdbase],0x1f0
1707
     mov  [hdid],0x0
1708
     mov  [hdpos],1
1709
;     call set_FAT32_variables
1710
   noprmahd:
1711
     cmp  ebx,2
1712
     jnz  noprslhd
1713
     mov  [hdbase],0x1f0
1714
     mov  [hdid],0x10
1715
     mov  [hdpos],2
1716
;     call set_FAT32_variables
1717
   noprslhd:
1718
     cmp  ebx,3
1719
     jnz  nosemahd
1720
     mov  [hdbase],0x170
1721
     mov  [hdid],0x0
1722
     mov  [hdpos],3
1723
;     call set_FAT32_variables
1724
   nosemahd:
1725
     cmp  ebx,4
1726
     jnz  noseslhd
1727
     mov  [hdbase],0x170
1728
     mov  [hdid],0x10
1729
     mov  [hdpos],4
1730
;     call set_FAT32_variables
1731
   noseslhd:
1732
     mov   [0xfe10],dword 0
1733
    call  reserve_hd1
1734
    call  clear_hd_cache
1735
    mov   [hd1_status],0        ; free
1736
     ret
1737
 
1738
hd_base db 0
1739
 
1740
   nsyse7:
1741
 
1742
     cmp  eax,8                      ; HD PARTITION
1743
     jne  nsyse8
1744
     mov  [fat32part],ebx
1745
;     call set_FAT32_variables
1746
    call  reserve_hd1
1747
    call  clear_hd_cache
1748
     pusha
1749
     call  choice_necessity_partition_1
1750
     popa
1751
    mov   [hd1_status],0        ; free
1752
     ret
1753
   nsyse8:
1754
 
1755
     cmp  eax,10                     ; SOUND DMA CHANNEL
1756
     jne  no_set_sound_dma
1757
     mov  [sound_dma],ebx
1758
     ret
1759
   no_set_sound_dma:
1760
 
1761
     cmp  eax,11                     ; ENABLE LBA READ
1762
     jne  no_set_lba_read
1763
     and  ebx,1
1764
     mov  [lba_read_enabled],ebx
1765
     ret
1766
   no_set_lba_read:
1767
 
1768
     cmp  eax,12                     ; ENABLE PCI ACCESS
1769
     jne  no_set_pci_access
1770
     and  ebx,1
1771
     mov  [pci_access_enabled],ebx
1772
     ret
1773
   no_set_pci_access:
1774
 
1775
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1776
include 'vmodeint.inc'
1777
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1778
 
1779
     mov  [esp+36],dword -1
1780
     ret
1781
 
1782
 
1783
align 4
1784
 
1785
sys_getsetup:
1786
 
1787
; 1=roland mpu midi base , base io address
1788
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1789
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1790
; 4=sb16 base , base io address
1791
; 5=system language, 1eng 2fi 3ger 4rus
1792
; 6=wss base
1793
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1794
; 8=fat32 partition in hd
1795
; 9=get hs timer tic
1796
 
1797
     cmp  eax,1
1798
     jne  ngsyse1
1799
     movzx eax,[midi_base]
1800
     mov  [esp+36],eax
1801
     ret
1802
   ngsyse1:
1803
 
1804
     cmp  eax,2
1805
     jne  ngsyse2
1806
     cmp  ebx,1
1807
     jnz  kbnobaseret
1808
     mov  edi,[0x3010]
1809
     add  ecx,[edi+0x10]
1810
     mov  ebx,ecx
1811
     mov  eax,keymap
1812
     mov  ecx,128
1813
     call memmove
1814
     ret
1815
   kbnobaseret:
1816
     cmp  ebx,2
1817
     jnz  kbnoshiftret
1818
     mov  edi,[0x3010]
1819
     add  ecx,[edi+0x10]
1820
     mov  ebx,ecx
1821
     mov  eax,keymap_shift
1822
     mov  ecx,128
1823
     call memmove
1824
     ret
1825
   kbnoshiftret:
1826
     cmp  ebx,3
1827
     jne  kbnoaltret
1828
     mov  edi,[0x3010]
1829
     add  ecx,[edi+0x10]
1830
     mov  ebx,ecx
1831
     mov  eax,keymap_alt
1832
     mov  ecx,128
1833
     call memmove
1834
     ret
1835
   kbnoaltret:
1836
     cmp  ebx,9
1837
     jnz  ngsyse2
1838
     movzx eax,word [keyboard]
1839
     mov  [esp+36],eax
1840
     ret
1841
   ngsyse2:
1842
 
1843
     cmp  eax,3
1844
     jnz  ngsyse3
1845
     movzx eax,[cd_base]
1846
     mov  [esp+36],eax
1847
     ret
1848
   ngsyse3:
1849
 
1850
     cmp  eax,4
1851
     jne  ngsyse4
1852
     mov  eax,[sb16]
1853
     mov  [esp+36],eax
1854
     ret
1855
   ngsyse4:
1856
 
1857
     cmp  eax,5
1858
     jnz  ngsyse5
1859
     mov  eax,[syslang]
1860
     mov  [esp+36],eax
1861
     ret
1862
   ngsyse5:
1863
     cmp  eax,6
1864
     jnz  ngsyse6
1865
     mov  eax,[wss]
1866
     mov  [esp+36],eax
1867
     ret
1868
   ngsyse6:
1869
     cmp  eax,7
1870
     jnz  ngsyse7
1871
     movzx eax,[hd_base]
1872
     mov  [esp+36],eax
1873
     ret
1874
   ngsyse7:
1875
     cmp  eax,8
1876
     jnz  ngsyse8
1877
     mov eax,[fat32part]
1878
     mov  [esp+36],eax
1879
     ret
1880
   ngsyse8:
1881
     cmp  eax,9
1882
     jne  ngsyse9
1883
     mov  eax,[timer_ticks] ;[0xfdf0]
1884
     mov  [esp+36],eax
1885
     ret
1886
   ngsyse9:
1887
     cmp  eax,10
1888
     jnz  ngsyse10
1889
     mov eax,[sound_dma]
1890
     mov  [esp+36],eax
1891
     ret
1892
   ngsyse10:
1893
     cmp  eax,11
1894
     jnz  ngsyse11
1895
     mov eax,[lba_read_enabled]
1896
     mov  [esp+36],eax
1897
     ret
1898
   ngsyse11:
1899
     cmp  eax,12
1900
     jnz  ngsyse12
1901
     mov eax,[pci_access_enabled]
1902
     mov  [esp+36],eax
1903
     ret
1904
   ngsyse12:
1905
     mov  [esp+36],dword 1
1906
     ret
1907
 
1908
 
1909
align 4
1910
 
1911
readmousepos:
1912
 
1913
; eax=0 screen relative
1914
; eax=1 window relative
1915
; eax=2 buttons pressed
1916
 
1917
    test eax,eax
1918
    jnz  nosr
1919
    mov  eax,[0xfb0a]
1920
    shl  eax,16
1921
    mov  ax,[0xfb0c]
1922
    mov  [esp+36],eax
1923
    ret
1924
  nosr:
1925
 
1926
    cmp  eax,1
1927
    jnz  nowr
1928
    mov  eax,[0xfb0a]
1929
    shl  eax,16
1930
    mov  ax,[0xfb0c]
1931
    mov  esi,[0x3010]
1932
    sub  esi,twdw
1933
    mov  bx,[esi]
1934
    shl  ebx,16
1935
    mov  bx,[esi+4]
1936
    sub  eax,ebx
1937
    mov  [esp+36],eax
1938
    ret
1939
  nowr:
1940
 
1941
    cmp   eax,2
1942
    jnz   nomb
1943
    movzx eax,byte [0xfb40]
1944
  nomb:
1945
    mov   [esp+36],eax
1946
 
1947
    ret
1948
 
1949
is_input:
1950
 
1951
   push edx
1952
   mov  dx,word [midisp]
1953
   in   al,dx
1954
   and  al,0x80
1955
   pop  edx
1956
   ret
1957
 
1958
 
1959
is_output:
1960
 
1961
   push edx
1962
   mov  dx,word [midisp]
1963
   in   al,dx
1964
   and  al,0x40
1965
   pop  edx
1966
   ret
1967
 
1968
 
1969
get_mpu_in:
1970
 
1971
   push edx
1972
   mov  dx,word [mididp]
1973
   in   al,dx
1974
   pop  edx
1975
   ret
1976
 
1977
 
1978
put_mpu_out:
1979
 
1980
   push edx
1981
   mov  dx,word [mididp]
1982
   out  dx,al
1983
   pop  edx
1984
   ret
1985
 
1986
 
1987
setuart:
1988
 
1989
 su1:
1990
   call is_output
1991
   cmp  al,0
1992
   jnz  su1
1993
   mov  dx,word [midisp]
1994
   mov  al,0xff
1995
   out  dx,al
1996
 su2:
1997
   mov  dx,word [midisp]
1998
   mov  al,0xff
1999
   out  dx,al
2000
   call is_input
2001
   cmp  al,0
2002
   jnz  su2
2003
   call get_mpu_in
2004
   cmp  al,0xfe
2005
   jnz  su2
2006
 su3:
2007
   call is_output
2008
   cmp  al,0
2009
   jnz  su3
2010
   mov  dx,word [midisp]
2011
   mov  al,0x3f
2012
   out  dx,al
2013
 
2014
   ret
2015
 
2016
 
2017
align 4
2018
 
2019
sys_midi:
2020
 
2021
     cmp  [mididp],0
2022
     jnz  sm0
2023
     mov  [esp+36],dword 1
2024
     ret
2025
   sm0:
2026
 
2027
     cmp  eax,1
2028
     mov  [esp+36],dword 0
2029
     jnz  smn1
2030
     call setuart
2031
     ret
2032
   smn1:
2033
 
2034
     cmp  eax,2
2035
     jnz  smn2
2036
   sm10:
2037
     call get_mpu_in
2038
     call is_output
2039
     test al,al
2040
     jnz  sm10
2041
     mov  al,bl
2042
     call put_mpu_out
2043
     ret
2044
   smn2:
2045
 
2046
     ret
2047
 
2048
 
2049
detect_devices:
2050
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2051
include 'detect/commouse.inc'
2052
;include 'detect/dev_fd.inc'
2053
;include 'detect/dev_hdcd.inc'
2054
;include 'detect/sear_par.inc'
2055
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2056
    ret
2057
 
2058
 
2059
sys_end:
2060
 
2061
     mov   eax,[0x3010]
2062
     add   eax,0xa
2063
     mov   [eax],byte 3  ; terminate this program
2064
 
2065
    waitterm:            ; wait here for termination
2066
     mov   eax,5
2067
     call  delay_hs
2068
     jmp   waitterm
2069
 
2070
sys_system:
2071
 
2072
     cmp  eax,1                              ; BOOT
2073
     jnz  nosystemboot
2074
     mov  [0x2f0000+0x9030],byte 0
2075
  for_shutdown_parameter:
2076
     mov  eax,[0x3004]
2077
     add  eax,2
2078
     mov  [shutdown_processes],eax
2079
     mov  [0xFF00],al
2080
     xor  eax, eax
2081
     ret
2082
  uglobal
2083
   shutdown_processes: dd 0x0
2084
  endg
2085
   nosystemboot:
2086
 
2087
     cmp  eax,2                              ; TERMINATE
2088
     jnz  noprocessterminate
2089
     cmp  ebx,2
2090
     jb   noprocessterminate
2091
     mov  edx,[0x3004]
2092
     cmp  ebx,edx
2093
     jg   noprocessterminate
2094
     mov  eax,[0x3004]
2095
     shl  ebx,5
2096
     mov  edx,[ebx+0x3000+4]
2097
     add  ebx,0x3000+0xa
2098
 
2099
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2100
     mov  [ebx],byte 3       ; clear possible i40's
2101
     ;call MEM_Heap_UnLock
2102
 
2103
     cmp  edx,[application_table_status]    ; clear app table stat
2104
     jne  noatsc
2105
     mov  [application_table_status],0
2106
   noatsc:
2107
     ret
2108
   noprocessterminate:
2109
 
2110
     cmp  eax,3                              ; ACTIVATE WINDOW
2111
     jnz  nowindowactivate
2112
     cmp  ebx,2
2113
     jb   nowindowactivate
2114
     cmp  ebx,[0x3004]
2115
     ja   nowindowactivate
2116
     ; edi = position at window_data+
2117
     mov  edi, ebx          ; edi = process number
2118
     ;shl  ebx, 1
2119
     ;add  ebx, 0xc000
2120
     ;mov  esi, [ebx]        ; esi = window stack value
2121
     ;and  esi, 0xffff       ;       word
2122
    movzx esi, word [0xC000 + ebx*2]
2123
     mov  edx, [0x3004] ; edx = number of processes
2124
     cmp  esi, edx
2125
     jz   nowindowactivate ; continue if window_stack_value != number_of_processes
2126
                           ;     i.e. if window is not already active
2127
 
2128
;* start code - get active process (1) - Mario79
2129
     mov  [window_minimize],2
2130
     mov  [active_process],edi
2131
;* end code - get active process (1) - Mario79
2132
 
2133
     mov  [0xff01],edi     ; activate
2134
     xor  eax, eax
2135
     ret
2136
 
2137
   nowindowactivate:
2138
 
2139
     cmp  eax,4                              ; GET IDLETIME
2140
     jnz  nogetidletime
2141
     mov  eax,[idleusesec]
2142
     ret
2143
   nogetidletime:
2144
 
2145
     cmp  eax,5                              ; GET TSC/SEC
2146
     jnz  nogettscsec
2147
     mov  eax,[0xf600]
2148
     ret
2149
   nogettscsec:
2150
 
2151
;  SAVE ramdisk to /hd/1/menuet.img
2152
;!!!!!!!!!!!!!!!!!!!!!!!!
2153
   include 'blkdev/rdsave.inc'
2154
;!!!!!!!!!!!!!!!!!!!!!!!!
2155
;* start code - get active process (2) - Mario79
2156
     cmp  eax,7
2157
     jnz  nogetactiveprocess
2158
     mov  eax,[active_process]
2159
     ret
2160
 nogetactiveprocess:
2161
     cmp  eax,8
2162
     jnz  nosoundflag
2163
     cmp  ebx,1
2164
     jne  nogetsoundflag
2165
     movzx  eax,byte [sound_flag] ; get sound_flag
2166
     ret
2167
 nogetsoundflag:
2168
     cmp  ebx,2
2169
     jnz  nosoundflag
2170
     inc  byte [sound_flag]       ; set sound_flag
2171
     and byte [sound_flag],1      ;
2172
     ret
2173
nosoundflag:
2174
     cmp  eax,9                   ; system shutdown with param
2175
     jnz  noshutdownsystem
2176
     cmp  ebx,1
2177
     jl  exit_for_anyone
2178
     cmp  ebx,4
2179
     jg   exit_for_anyone
2180
     mov  [0x2f0000+0x9030],bl
2181
     jmp  for_shutdown_parameter
2182
noshutdownsystem:
2183
     cmp  eax,10                   ; minimize window
2184
     jnz  nominimizewindow
2185
     mov   [window_minimize],1
2186
 exit_for_anyone:
2187
     ret
2188
nominimizewindow:
2189
     cmp  eax,11           ; get disk info table
2190
     jnz  nogetdiskinfo
2191
     cmp  ebx,1
2192
     jnz  full_table
2193
  small_table:
2194
     call for_all_tables
2195
     mov cx,10
2196
     cld
2197
     rep movsb
2198
     ret
2199
   for_all_tables:
2200
     mov edi,[3010h]
2201
     mov edi,[edi+10h]
2202
     add edi,ecx
2203
     mov esi,0x40000
2204
     xor ecx,ecx
2205
     ret
2206
  full_table:
2207
     cmp  ebx,2
2208
     jnz  exit_for_anyone
2209
     call for_all_tables
2210
     mov cx,16384
2211
     cld
2212
     rep movsd
2213
     ret
2214
nogetdiskinfo:
2215
     cmp  eax,12      ; get all key pressed with ALT
2216
     jnz  nogetkey
2217
     mov   eax,[last_key_press]
2218
     mov   al,[keyboard_mode_sys]
2219
     mov   [esp+36],eax
2220
     mov   [last_key_press],0
2221
 .finish:
2222
     ret
2223
nogetkey:
2224
     cmp  eax,13      ; get kernel ID and version
2225
     jnz  nogetkernel_id
2226
     mov edi,[3010h]
2227
     mov edi,[edi+10h]
2228
     add edi,ebx
2229
     mov esi,version_inf
2230
     mov ecx,version_end-version_inf
2231
     cld
2232
     rep movsb
2233
     ret
2234
nogetkernel_id:
2235
     cmp  eax,14      ; sys wait retrace
2236
     jnz  nosys_wait_retrace
2237
     ;wait retrace functions
2238
 sys_wait_retrace:
2239
     mov edx,0x3da
2240
 WaitRetrace_loop:
2241
     in al,dx
2242
     test al,1000b
2243
     jz WaitRetrace_loop
2244
     mov [esp+36],dword 0
2245
     ret
2246
nosys_wait_retrace:
2247
     cmp  eax,15      ; mouse centered
2248
     jnz  no_mouse_centered
2249
     call  mouse_centered
2250
     mov [esp+36],dword 0
2251
     ret
2252
no_mouse_centered:
2253
;* end  code - get active process (2) - Mario79
2254
     ret
2255
window_minimize db 0
2256
sound_flag      db 0
2257
last_key_press  dd 0
2258
keyboard_mode_sys db 0
2259
 
2260
iglobal
2261
version_inf:
5 halyavin 2262
  db 0,5,1,0  ; version 0.5.1.0
1 ha 2263
  db UID_KOLIBRI
2264
  db 'Kolibri',0
2265
version_end:
2266
endg
2267
 
2268
UID_NONE=0
2269
UID_MENUETOS=1   ;official
2270
UID_KOLIBRI=2    ;russian
2271
 
2272
main_loop_sys_getkey:
2273
    cmp   [0xf400],byte 0
2274
    je    .finish
2275
    movzx eax,byte [0xf401]
2276
    shl   eax,8
2277
    mov   [last_key_press],eax
2278
 .finish:
2279
    ret
2280
 
2281
sys_cachetodiskette:
2282
    pushad
2283
    cmp  eax,1
2284
    jne  no_write_all_of_ramdisk
2285
 
2286
    call fdc_writeramdisk
2287
    popad
2288
    ret
2289
  no_write_all_of_ramdisk:
2290
    cmp eax,2
2291
    jne no_write_part_of_ramdisk
2292
    call fdc_commitflush
2293
    popad
2294
    ret
2295
  no_write_part_of_ramdisk:
2296
    cmp  eax,3
2297
    jne  no_set_fdc
2298
    call fdc_set
2299
    popad
2300
    ret
2301
  no_set_fdc:
2302
    cmp  eax,4
2303
    jne  no_get_fdc
2304
    popad
2305
    call fdc_get
2306
    mov    [esp+36],ecx
2307
    ret
2308
  no_get_fdc:
2309
    popad
2310
    ret
2311
 
2312
uglobal
2313
;  bgrchanged  dd  0x0
2314
endg
2315
 
2316
sys_background:
2317
 
2318
    cmp   eax,1                            ; BACKGROUND SIZE
2319
    jnz   nosb1
2320
    cmp   ebx,0
2321
    je    sbgrr
2322
    cmp   ecx,0
2323
    je    sbgrr
2324
    mov   [display_data-8],ebx
2325
    mov   [display_data-4],ecx
2326
;    mov   [bgrchanged],1
2327
  sbgrr:
2328
    ret
2329
  nosb1:
2330
 
2331
    cmp   eax,2                            ; SET PIXEL
2332
    jnz   nosb2
2333
    mov   edx,0x160000-16
2334
    cmp   edx,ebx
2335
    jbe   nosb2
2336
    mov   edx,[ebx]
2337
    and   edx,0xFF000000 ;255*256*256*256
2338
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2339
    add   edx,ecx
2340
    mov   [ebx+0x300000],edx
2341
;    mov   [bgrchanged],1
2342
    ret
2343
  nosb2:
2344
 
2345
    cmp   eax,3                            ; DRAW BACKGROUND
2346
    jnz   nosb3
2347
draw_background_temp:
2348
;    cmp   [bgrchanged],1 ;0
2349
;    je    nosb31
2350
;draw_background_temp:
2351
;    mov   [bgrchanged],1 ;0
2352
    mov   [0xfff0],byte 1
2353
   nosb31:
2354
    ret
2355
  nosb3:
2356
 
2357
    cmp   eax,4                            ; TILED / STRETCHED
2358
    jnz   nosb4
2359
    cmp   ebx,[display_data-12]
2360
    je    nosb41
2361
    mov   [display_data-12],ebx
2362
;    mov   [bgrchanged],1
2363
   nosb41:
2364
    ret
2365
  nosb4:
2366
 
2367
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2368
    jnz   nosb5
2369
  ; bughere
2370
    mov   edi, [0x3010]
2371
    add   ebx, [edi+0x10]
2372
 ;   mov   esi, ebx
2373
 ;   mov   edi, ecx
2374
    mov   eax, ebx
2375
    mov   ebx, ecx
2376
    add   ecx, edx
2377
    cmp   ecx, 0x160000-16
2378
    ja    .fin
2379
 ;   add   edi, 0x300000
2380
    add   ebx, 0x300000
2381
    mov   ecx, edx
2382
    cmp   ecx, 0x160000-16
2383
    ja    .fin
2384
;    mov   [bgrchanged],1
2385
  ;  cld
2386
  ;  rep   movsb
2387
    call  memmove
2388
  .fin:
2389
    ret
2390
  nosb5:
2391
 
2392
    ret
2393
 
2394
 
2395
align 4
2396
 
2397
sys_getbackground:
2398
 
2399
    cmp   eax,1                                  ; SIZE
2400
    jnz   nogb1
2401
    mov   eax,[display_data-8]
2402
    shl   eax,16
2403
    mov   ax,[display_data-4]
2404
    mov   [esp+36],eax
2405
    ret
2406
  nogb1:
2407
 
2408
    cmp   eax,2                                  ; PIXEL
2409
    jnz   nogb2
2410
    mov   edx,0x160000-16
2411
    cmp   edx,ebx
2412
    jbe   nogb2
2413
    mov   eax, [ebx+0x300000]
2414
    and   eax, 0xFFFFFF
2415
    mov   [esp+36],eax
2416
    ret
2417
  nogb2:
2418
 
2419
    cmp   eax,4                                  ; TILED / STRETCHED
2420
    jnz   nogb4
2421
    mov   eax,[display_data-12]
2422
  nogb4:
2423
    mov   [esp+36],eax
2424
    ret
2425
 
2426
 
2427
align 4
2428
 
2429
sys_getkey:
2430
    mov   [esp+36],dword 1
2431
    mov   ebx, [0x3000]                          ; TOP OF WINDOW STACK
2432
    movzx ecx,word [0xC000 + ebx * 2]
2433
    mov   edx,[0x3004]
2434
    cmp   ecx,edx
2435
    jne   .finish
2436
    cmp   [0xf400],byte 0
2437
    je    .finish
2438
    movzx eax,byte [0xf401]
2439
    shl   eax,8
2440
    push  eax
2441
    dec   byte [0xf400]
2442
    and   byte [0xf400],127
2443
    movzx ecx,byte [0xf400]
2444
    add   ecx,2
2445
 ;   mov   esi,0xf402
2446
 ;   mov   edi,0xf401
2447
 ;   cld
2448
 ;  rep   movsb
2449
    mov   eax, 0xF402
2450
    mov   ebx, 0xF401
2451
    call  memmove
2452
    pop   eax
2453
    mov   [last_key_press],eax
2454
 
2455
    mov   eax,[kb_state]
2456
    and   al,110000b
2457
    cmp   al,100000b
2458
    je    .yes_win_key
2459
    cmp   al,10000b
2460
    je    .yes_win_key
2461
    mov   eax,[last_key_press]
2462
    jmp   .no_win_key
2463
;    cmp   ah,232
2464
;    je    .yes_win_key
2465
;    cmp   ah,233
2466
;    jne   .no_win_key
2467
 .yes_win_key:
2468
    mov   eax,1
2469
 .no_win_key:
2470
    mov   [esp+36],eax
2471
 .finish:
2472
    ret
2473
 
2474
 
2475
align 4
2476
 
2477
sys_getbutton:
2478
 
2479
    mov   ebx, [0x3000]                         ; TOP OF WINDOW STACK
2480
    mov   [esp+36],dword 1
2481
    movzx ecx, word [0xC000 + ebx * 2]
2482
    mov   edx, [0x3004] ; less than 256 processes
2483
    cmp   ecx,edx
2484
    jne   .exit
2485
    movzx eax,byte [0xf500]
2486
    test  eax,eax
2487
    jz    .exit
2488
    mov   eax,[0xf501]
2489
    shl   eax,8
2490
    mov   [0xf500],byte 0
2491
    mov   [esp+36],eax
2492
 .exit:
2493
    ret
2494
 
2495
 
2496
align 4
2497
 
2498
sys_cpuusage:
2499
 
2500
;  RETURN:
2501
;
2502
;  +00 dword     process cpu usage
2503
;  +04  word     position in windowing stack
2504
;  +06  word     windowing stack value at current position (cpu nro)
2505
;  +10 12 bytes  name
2506
;  +22 dword     start in mem
2507
;  +26 dword     used mem
2508
;  +30 dword     PID , process idenfification number
2509
;
2510
 
2511
    mov  edi,[0x3010]   ; eax = return area
2512
    add  edi,0x10
2513
    add  eax,[edi]
2514
 
2515
    cmp  ebx,-1         ; who am I ?
2516
    jne  no_who_am_i
2517
    mov  ebx,[0x3000]
2518
  no_who_am_i:
2519
 
2520
    push eax            ; return area
2521
    push ebx            ; process number
2522
 
2523
    push ebx
2524
    push ebx
2525
    push eax
2526
 
2527
    ; return memory usage
2528
 
2529
    xor  edx,edx
2530
    mov  eax,0x20
2531
    mul  ebx
2532
    add  eax,0x3000+0x1c
2533
    mov  ebx,eax
2534
    pop  eax
2535
    mov  ecx,[ebx]
2536
    mov  [eax],ecx
2537
    pop  ebx
2538
;    mov  ebx,[esp]
2539
;    shl  ebx,1
2540
;    add  ebx,0xc000
2541
    mov  cx, [0xC000 + ebx * 2]
2542
    mov  [eax+4],cx
2543
;    mov  ebx,[esp]
2544
;    shl  ebx,1
2545
;    add  ebx,0xc400
2546
    mov  cx, [0xC400 + ebx * 2]
2547
    mov  [eax+6],cx
2548
;    pop  ebx
2549
    push eax
2550
    mov  eax,ebx
2551
    shl  eax,8
2552
    add  eax,0x80000
2553
    pop  ebx
2554
    add  ebx,10
2555
    mov  ecx,11
2556
    call memmove
2557
 
2558
    ; memory usage
2559
 
2560
    xor    eax,eax
2561
    mov    edx,0x100000*16
2562
    pop    ecx                                   ; get gdt of tss
2563
    cmp    ecx,1
2564
    je     os_mem
2565
    shl    ecx,8
2566
    mov    edx,[0x80000+ecx+0x8c]
2567
    mov    eax,std_application_base_address
2568
    ;add    ecx,0x80000+0x88
2569
    ;mov    ecx,[ecx]
2570
;    shl    ecx,3
2571
    ; eax run base -> edx used memory
2572
;    mov    al,[ecx+gdts+ app_code-3 +4]        ;  base  23:16
2573
;    mov    ah,[ecx+gdts+ app_code-3 +7]        ;  base  31:24
2574
;    shl    eax,16
2575
;    mov    ax,[ecx+gdts+ app_code-3 +2]        ;  base  0:15
2576
;    movzx  edx,word [ecx+gdts+ app_code-3 +0]
2577
;    shl    edx,12
2578
 
2579
  os_mem:
2580
    dec    edx
2581
    mov    [ebx+12],eax
2582
    mov    [ebx+16],edx
2583
 
2584
    ; PID (+30)
2585
 
2586
    mov    eax,[esp]
2587
    shl    eax,5
2588
    add    eax,0x3000+0x4
2589
    mov    eax,[eax]
2590
    mov    [ebx+20],eax
2591
 
2592
    ; window position and size
2593
 
2594
    mov    esi,[esp]
2595
    shl    esi,5
2596
    add    esi,window_data
2597
    mov    edi,[esp+4]
2598
    add    edi,34
2599
    mov    ecx,4*4
2600
    cld
2601
    rep    movsb
2602
 
2603
    ; Process state (+50)
2604
 
2605
    mov    eax,[esp]
2606
    shl    eax,5
2607
    add    eax,0x3000+0xa
2608
    mov    eax,[eax]
2609
    mov    [ebx+40],ax
2610
 
2611
 
2612
    pop    ebx
2613
    pop    eax
2614
 
2615
    ; return number of processes
2616
 
2617
    mov    eax,[0x3004]
2618
    mov    [esp+36],eax
2619
    ret
2620
 
2621
 
2622
 
2623
 
2624
align 4
2625
sys_clock:
2626
        cli
2627
  ; Mikhail Lisovin  xx Jan 2005
2628
  @@:   mov   al, 10
2629
        out   0x70, al
2630
        in    al, 0x71
2631
        test  al, al
2632
        jns   @f
2633
        mov   esi, 1
2634
        call  delay_ms
2635
        jmp   @b
2636
  @@:
2637
  ; end Lisovin's fix
2638
 
2639
        xor   al,al           ; seconds
2640
        out   0x70,al
2641
        in    al,0x71
2642
        movzx ecx,al
2643
        mov   al,02           ; minutes
2644
        shl   ecx,16
2645
        out   0x70,al
2646
        in    al,0x71
2647
        movzx edx,al
2648
        mov   al,04           ; hours
2649
        shl   edx,8
2650
        out   0x70,al
2651
        in    al,0x71
2652
        add   ecx,edx
2653
        movzx edx,al
2654
        add   ecx,edx
2655
        sti
2656
        mov   [esp+36],ecx
2657
        ret
2658
 
2659
 
2660
align 4
2661
 
2662
sys_date:
2663
 
2664
        cli
2665
        mov     al,6            ; day of week
2666
        out     0x70,al
2667
        in      al,0x71
2668
        mov     ch,al
2669
        mov     al,7            ; date
2670
        out     0x70,al
2671
        in      al,0x71
2672
        mov     cl,al
2673
        mov     al,8            ; month
2674
        shl     ecx,16
2675
        out     0x70,al
2676
        in      al,0x71
2677
        mov     ch,al
2678
        mov     al,9            ; year
2679
        out     0x70,al
2680
        in      al,0x71
2681
        mov     cl,al
2682
        sti
2683
        mov     [esp+36],ecx
2684
        ret
2685
 
2686
 
2687
; redraw status
2688
 
2689
sys_redrawstat:
2690
 
2691
    cmp  eax,1
2692
    jne  no_widgets_away
2693
 
2694
    ; buttons away
2695
 
2696
    mov   ecx,[0x3000]
2697
 
2698
  sys_newba2:
2699
 
2700
    mov   edi,[0xfe88]
2701
    cmp   [edi],dword 0  ; empty button list ?
2702
    je    end_of_buttons_away
2703
 
2704
    movzx ebx,word [edi]
2705
    inc   ebx
2706
 
2707
    mov   eax,edi
2708
 
2709
  sys_newba:
2710
 
2711
    dec   ebx
2712
    jz    end_of_buttons_away
2713
 
2714
    add   eax,0x10
2715
    cmp   cx,[eax]
2716
    jnz   sys_newba
2717
 
2718
    push  eax ebx ecx
2719
    mov   ecx,ebx
2720
    inc   ecx
2721
    shl   ecx,4
2722
    mov   ebx,eax
2723
    add   eax,0x10
2724
    call  memmove
2725
    dec   dword [edi]
2726
    pop   ecx ebx eax
2727
 
2728
    jmp   sys_newba2
2729
 
2730
  end_of_buttons_away:
2731
 
2732
    ret
2733
 
2734
  no_widgets_away:
2735
 
2736
    cmp   eax,2
2737
    jnz   srl1
2738
 
2739
    mov   edx,[0x3010]      ; return whole screen draw area for this app
2740
    add   edx,draw_data-0x3000
2741
    mov   [edx+0],dword 0
2742
    mov   [edx+4],dword 0
2743
    mov   eax,[0xfe00]
2744
    mov   [edx+8],eax
2745
    mov   eax,[0xfe04]
2746
    mov   [edx+12],eax
2747
 
2748
    mov   edi,[0x3010]
2749
    sub   edi,twdw
2750
    mov   [edi+30],byte 1   ; no new position & buttons from app
2751
 
2752
    call  sys_window_mouse
2753
 
2754
    ret
2755
 
2756
  srl1:
2757
 
2758
    ret
2759
 
2760
 
2761
sys_drawwindow:
2762
 
2763
    mov   edi,ecx
2764
    shr   edi,16+8
2765
    and   edi,15
2766
 
2767
    cmp   edi,0   ; type I    - original style
2768
    jne   nosyswI
2769
    call  sys_set_window
2770
    call  drawwindow_I
2771
    ret
2772
  nosyswI:
2773
 
2774
    cmp   edi,1   ; type II   - only reserve area, no draw
2775
    jne   nosyswII
2776
    call  sys_set_window
2777
    call  sys_window_mouse
2778
    ret
2779
  nosyswII:
2780
 
2781
    cmp   edi,2   ; type III  - new style
2782
    jne   nosyswIII
2783
    call  sys_set_window
2784
    call  drawwindow_III
2785
    ret
2786
  nosyswIII:
2787
 
2788
    cmp   edi,3   ; type IV - skinned window
2789
    jne   nosyswIV
2790
    call  sys_set_window
2791
    call  drawwindow_IV
2792
    ret
2793
  nosyswIV:
2794
 
2795
    ret
2796
 
2797
 
2798
sys_set_window:
2799
 
2800
    mov   edi,[0x3000]
2801
    shl   edi,5
2802
    add   edi,window_data
2803
 
2804
    ; colors
2805
    mov   [edi+16],ecx
2806
    mov   [edi+20],edx
2807
    mov   [edi+24],esi
2808
 
2809
    ; check flag (?)
2810
    cmp   [edi+30],byte 1
2811
    jz    newd
2812
 
2813
    push  eax
2814
    mov   eax,[timer_ticks] ;[0xfdf0]
2815
    add   eax,100
2816
    mov   [new_window_starting],eax
2817
    pop   eax
2818
 
2819
    mov   [edi+8],ax
2820
    mov   [edi+12],bx
2821
    shr   eax,16
2822
    shr   ebx,16
2823
    mov   [edi+00],ax
2824
    mov   [edi+04],bx
2825
 
2826
 
2827
    call  check_window_position
2828
 
2829
 
2830
    push  ecx esi edi               ; save for window fullscreen/resize
2831
    mov   esi,edi
2832
    sub   edi,window_data
2833
    shr   edi,5
2834
    shl   edi,8
2835
    add   edi,0x80000+0x90
2836
    mov   ecx,4
2837
    cld
2838
    rep   movsd
2839
    pop   edi esi ecx
2840
 
2841
    push  eax ebx ecx edx
2842
;;;    mov   eax, 1
2843
;;;    call  delay_hs
2844
    movzx eax, word [edi+00]
2845
    movzx ebx, word [edi+04]
2846
    movzx ecx, word [edi+8]
2847
    movzx edx, word [edi+12]
2848
    add   ecx, eax
2849
    add   edx, ebx
2850
    call  calculatescreen
2851
    pop   edx ecx ebx eax
2852
 
2853
    mov   [0xf400],byte 0           ; empty keyboard buffer
2854
    mov   [0xf500],byte 0           ; empty button buffer
2855
 
2856
  newd:
2857
    mov   [edi+31],byte 0   ; no redraw
2858
    mov   edx,edi
2859
 
2860
    ret
2861
 
2862
 
2863
sys_window_move:
2864
 
2865
        cmp  [window_move_pr],0
2866
        je   mwrl1
2867
 
2868
        mov  [esp+36],dword 1         ; return queue error
2869
 
2870
        ret
2871
 
2872
     mwrl1:
2873
 
2874
        mov   edi,[0x3000]            ; requestor process base
2875
        mov   [window_move_pr],edi
2876
 
2877
        mov   [window_move_eax],eax
2878
        mov   [window_move_ebx],ebx
2879
        mov   [window_move_ecx],ecx
2880
        mov   [window_move_edx],edx
2881
 
2882
        mov   [esp+36],dword 0        ; return success
2883
 
2884
        ret
2885
 
2886
type_background_1:
2887
    cmp   [0xfff0],byte 0               ; background update ?
2888
    jz    temp_nobackgr
2889
    mov   [0xfff0],byte 2
2890
    call  change_task
2891
    mov   [draw_data+32+0],dword 0
2892
    mov   [draw_data+32+4],dword 0
2893
    mov   eax,[0xfe00]
2894
    mov   ebx,[0xfe04]
2895
    mov   [draw_data+32+8],eax
2896
    mov   [draw_data+32+12],ebx
2897
    call  drawbackground
2898
    mov   [0xfff0],byte 0
2899
    mov   [0xfff4],byte 0
2900
temp_nobackgr:
2901
    ret
2902
 
2903
uglobal
2904
  window_move_pr   dd  0x0
2905
  window_move_eax  dd  0x0
2906
  window_move_ebx  dd  0x0
2907
  window_move_ecx  dd  0x0
2908
  window_move_edx  dd  0x0
2909
endg
2910
 
2911
;ok - 100% work
2912
;nt - not tested
2913
;---------------------------------------------------------------------------------------------
2914
;eax
2915
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2916
;1 - change task. Ret nothing. Block. ok.
2917
;2 - performance control
2918
; ebx
2919
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2920
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2921
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2922
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2923
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2924
;eax
2925
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2926
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2927
;---------------------------------------------------------------------------------------------
2928
sys_sheduler: ;noname & halyavin
2929
    cmp eax,0
2930
    je shed_counter
2931
    cmp eax,2
2932
    je perf_control
2933
    cmp eax,3
2934
    je rdmsr_instr
2935
    cmp eax,4
2936
    je wrmsr_instr
2937
    cmp eax,1
2938
    jne not_supported
2939
    call change_task ;delay,0
2940
ret
2941
shed_counter:
2942
    mov eax,[context_counter]
2943
    mov [esp+36],eax
2944
not_supported:
2945
ret
2946
perf_control:
2947
    inc eax ;now eax=3
2948
    cmp ebx,eax
2949
    je cache_disable
2950
    dec eax
2951
    cmp ebx,eax
2952
    je cache_enable
2953
    dec eax
2954
    cmp ebx,eax
2955
    je is_cache_enabled
2956
    dec eax
2957
    cmp ebx,eax
2958
    je modify_pce
2959
ret
2960
 
2961
rdmsr_instr:
2962
;now counter in ecx
2963
;(edx:eax) esi:edi => edx:esi
2964
mov eax,esi
2965
rdmsr
2966
mov [esp+36],eax
2967
mov [esp+24],edx ;ret in ebx?
2968
ret
2969
 
2970
wrmsr_instr:
2971
;now counter in ecx
2972
;(edx:eax) esi:edi => edx:esi
2973
mov eax,esi
2974
wrmsr
2975
mov [esp+36],eax
2976
mov [esp+24],edx ;ret in ebx?
2977
ret
2978
 
2979
cache_disable:
2980
       mov eax,cr0
2981
       or  eax,01100000000000000000000000000000b
2982
       mov cr0,eax
2983
       wbinvd ;set MESI
2984
ret
2985
 
2986
cache_enable:
2987
       mov eax,cr0
2988
       and eax,10011111111111111111111111111111b
2989
       mov cr0,eax
2990
ret
2991
 
2992
is_cache_enabled:
2993
       mov eax,cr0
2994
       mov ebx,eax
2995
       and eax,01100000000000000000000000000000b
2996
       jz cache_disabled
2997
       mov [esp+36],ebx
2998
cache_disabled:
2999
       mov dword [esp+36],eax ;0
3000
ret
3001
 
3002
modify_pce:
3003
       mov eax,cr4
3004
;       mov ebx,0
3005
;       or  bx,100000000b ;pce
3006
;       xor eax,ebx ;invert pce
3007
       btr eax,8 ;pce=cr4[8]
3008
       mov cr4,eax
3009
       mov [esp+36],eax
3010
ret
3011
;---------------------------------------------------------------------------------------------
3012
 
3013
; check pixel limits
3014
 
3015
;cplimit:
3016
;        push    edi
3017
 
3018
;        cmp     byte [0xe000], 1      ; Multitasking enabled?
3019
;        jnz     .ret0
3020
;        mov     edi,[0x3010]
3021
;        add     edi, draw_data-0x3000
3022
;        mov     ecx, 1
3023
;        cmp     [edi+0], eax  ; xs
3024
;        ja      .ret1
3025
;        cmp     [edi+4], ebx  ; ys
3026
;        ja      .ret1
3027
;        cmp     eax, [edi+8]   ; xe
3028
;        ja      .ret1
3029
;        cmp     ebx, [edi+12] ; ye
3030
;        ja      .ret1
3031
 
3032
;.ret0:
3033
;        xor     ecx, ecx
3034
;.ret1:
3035
;        pop     edi
3036
;        ret
3037
 
3038
 
3039
; check if pixel is allowed to be drawn
3040
 
3041
checkpixel:
3042
 
3043
        push eax
3044
        push ebx
3045
        push edx
3046
 
3047
;        mov   ecx,[0x3000]  ; process count
3048
;        shl   ecx, 6        ; *64
3049
;        add   ecx,0xc000    ; +window_stack
3050
;        mov   dx,word [ecx] ; window_stack_value
3051
 
3052
;        cmp   dx, word [0x3004] ; is this window active right now?!
3053
;        jz    .ret0
3054
 
3055
;        call  cplimit
3056
;        test  ecx, ecx
3057
;        jnz   .ret1
3058
 
3059
        mov  edx,[0xfe00]     ; screen x size
3060
        inc  edx
3061
        imul  edx, ebx
3062
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3063
;;;        mov  dl,[eax]
3064
 
3065
        mov  eax,[0x3000]
3066
        shl  eax,5
3067
        add  eax,0x3000+0xe
3068
 
3069
        mov  ecx, 1
3070
        cmp  byte [eax], dl
3071
        jnz  .ret1
3072
 
3073
.ret0:
3074
        xor  ecx, ecx
3075
.ret1:
3076
        pop  edx
3077
        pop  ebx
3078
        pop  eax
3079
        ret
3080
 
3081
uglobal
3082
  mouse_active  db  0
3083
endg
3084
iglobal
3085
  cpustring db 'CPU        '
3086
endg
3087
 
3088
 
3089
align 4
3090
; check misc
3091
 
3092
checkmisc:
3093
 
3094
    cmp   [ctrl_alt_del], 1
3095
    jne   nocpustart
3096
    mov   eax, cpustring
3097
    call  start_application_fl
3098
    mov   [ctrl_alt_del], 0
3099
  nocpustart:
3100
    cmp   [mouse_active], 1
3101
    jne   mouse_not_active
3102
    mov   [mouse_active], 0
3103
    xor   edi, edi
3104
    mov   ecx, [0x3004]
3105
   set_mouse_event:
3106
    add   edi, 256
3107
    or    [edi+0x80000+0xA8], dword 00100000b
3108
    loop  set_mouse_event
3109
  mouse_not_active:
3110
 
3111
 
3112
    cmp   [0xfff0],byte 0               ; background update ?
3113
    jz    nobackgr
3114
    mov   [0xfff0],byte 2
3115
    call  change_task
3116
    mov   [draw_data+32+0],dword 0
3117
    mov   [draw_data+32+4],dword 0
3118
    mov   eax,[0xfe00]
3119
    mov   ebx,[0xfe04]
3120
    mov   [draw_data+32+8],eax
3121
    mov   [draw_data+32+12],ebx
3122
    call  drawbackground
3123
    mov   [0xfff0],byte 0
3124
    mov   [0xfff4],byte 0
3125
 
3126
  nobackgr:
3127
 
3128
 
3129
    ; system shutdown request
3130
 
3131
    cmp  [0xFF00],byte 0
3132
    je   noshutdown
3133
 
3134
    mov  edx,[shutdown_processes]
3135
    sub  dl,2
3136
 
3137
    cmp  [0xff00],dl
3138
    jne  no_mark_system_shutdown
3139
 
3140
    mov   edx,0x3040
3141
    movzx ecx,byte [0xff00]
3142
    add   ecx,5
3143
  markz:
3144
    mov   [edx+0xa],byte 3
3145
    add   edx,0x20
3146
    loop  markz
3147
 
3148
  no_mark_system_shutdown:
3149
 
3150
    call [disable_mouse]
3151
 
3152
    dec  byte [0xff00]
3153
 
3154
    cmp  [0xff00],byte 0
3155
    je   system_shutdown
3156
 
3157
  noshutdown:
3158
 
3159
 
3160
    mov   eax,[0x3004]                  ; termination
3161
    mov   ebx,0x3020+0xa
3162
    mov   esi,1
3163
 
3164
  newct:
3165
    mov   cl,[ebx]
3166
    cmp   cl,byte 3
3167
    jz    terminate
3168
    cmp   cl,byte 4
3169
    jz    terminate
3170
 
3171
    add   ebx,0x20
3172
    inc   esi
3173
    dec   eax
3174
    jnz   newct
3175
 
3176
    ret
3177
 
3178
 
3179
 
3180
 
3181
; redraw screen
3182
 
3183
redrawscreen:
3184
 
3185
; eax , if process window_data base is eax, do not set flag/limits
3186
 
3187
         pushad
3188
         push  eax
3189
 
3190
;;;         mov   eax,2
3191
;;;         call  delay_hs
3192
 
3193
         ;mov   ecx,0               ; redraw flags for apps
3194
         xor   ecx,ecx
3195
       newdw2:
3196
 
3197
         inc   ecx
3198
         push  ecx
3199
 
3200
         mov   eax,ecx
3201
         shl   eax,5
3202
         add   eax,window_data
3203
 
3204
         cmp   eax,[esp+4]
3205
         je    not_this_task
3206
                                   ; check if window in redraw area
3207
         mov   edi,eax
3208
 
3209
         cmp   ecx,1               ; limit for background
3210
         jz    bgli
3211
 
3212
         mov   eax,[edi+0]
3213
         mov   ebx,[edi+4]
3214
         mov   ecx,[edi+8]
3215
         mov   edx,[edi+12]
3216
         add   ecx,eax
3217
         add   edx,ebx
3218
 
3219
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3220
         cmp   ecx,ebx
3221
         jb    ricino
3222
 
3223
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3224
         cmp   ecx,eax
3225
         jb    ricino
3226
 
3227
         mov   eax,[edi+0]
3228
         mov   ebx,[edi+4]
3229
         mov   ecx,[edi+8]
3230
         mov   edx,[edi+12]
3231
         add   ecx,eax
3232
         add   edx,ebx
3233
 
3234
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3235
         cmp   edx,eax
3236
         jb    ricino
3237
 
3238
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3239
         cmp   ecx,eax
3240
         jb    ricino
3241
 
3242
        bgli:
3243
 
3244
         cmp   edi,esi
3245
         jz    ricino
3246
 
3247
         mov   eax,edi
3248
         add   eax,draw_data-window_data
3249
 
3250
         mov   ebx,[dlx]          ; set limits
3251
         mov   [eax+0],ebx
3252
         mov   ebx,[dly]
3253
         mov   [eax+4],ebx
3254
         mov   ebx,[dlxe]
3255
         mov   [eax+8],ebx
3256
         mov   ebx,[dlye]
3257
         mov   [eax+12],ebx
3258
 
3259
         sub   eax,draw_data-window_data
3260
 
3261
         cmp   ecx,1
3262
         jne   nobgrd
3263
         cmp   esi,1
3264
         je    newdw8
3265
         call  drawbackground
3266
 
3267
       newdw8:
3268
       nobgrd:
3269
 
3270
         mov   [eax+31],byte 1    ; mark as redraw
3271
 
3272
       ricino:
3273
 
3274
       not_this_task:
3275
 
3276
         pop   ecx
3277
 
3278
         cmp   ecx,[0x3004]
3279
         jle   newdw2
3280
;         jg    newdw3
3281
;         jmp   newdw2
3282
 
3283
;       newdw3:
3284
 
3285
         pop  eax
3286
         popad
3287
 
3288
         ret
3289
 
3290
;   check mouse
3291
;
3292
;
3293
;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
3294
;   FB10  ->   FB17   mouse color mem
3295
;   FB21              x move
3296
;   FB22              y move
3297
;   FB30              color temp
3298
;   FB28              high bits temp
3299
;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
3300
;   FC00  ->   FCFE   com1/ps2 buffer
3301
;   FCFF              com1/ps2 buffer count starting from FC00
3302
 
3303
uglobal
3304
  mousecount  dd  0x0
3305
  mousedata   dd  0x0
3306
endg
3307
 
3308
 
3309
check_mouse_data:
3310
 
3311
        pushad
3312
 
3313
        cmp    [0xF604],byte 1
3314
        jne    no_ps2_mouse
3315
        mov    [mousecount],dword 0x2e0000+12*4096
3316
        mov    [mousedata],dword 0x2e0000+12*4096+0x10
3317
        jmp    uusicheckmouse
3318
no_ps2_mouse:
3319
        cmp    [0xF604],byte 2
3320
        jne    no_com1_mouse
3321
        mov    [mousecount],dword 0x2e0000+4*4096
3322
        mov    [mousedata],dword 0x2e0000+4*4096+0x10
3323
        jmp    uusicheckmouse
3324
no_com1_mouse:
3325
        mov    [mousecount],dword 0x2e0000+3*4096
3326
        mov    [mousedata],dword 0x2e0000+3*4096+0x10
3327
 
3328
      uusicheckmouse:
3329
 
3330
        mov    ebx,[mousecount]       ; anything at buffer for mouse
3331
        cmp    dword [ebx], 0         ; !!!
3332
        jz     checkmouseret
3333
 
3334
        ; first byte of comX or ps2 ?
3335
 
3336
        cmp    [0xF604],byte 1
3337
        je     ps2mousefirst
3338
 
3339
        ; ******************************************
3340
        ; *********** COMX mouse driver ************
3341
        ; ******************************************
3342
 
3343
       com1mousefirst:
3344
 
3345
        mov    edi,[mousedata]
3346
        mov    dl,byte [edi] ; first com1 ?
3347
        test   dl,64
3348
        jz     @f
3349
        mov    [0xfb00],byte 0  ; zero mouse block count
3350
       @@:
3351
        xor    ebx,ebx
3352
 
3353
        mov    bl,[0xfb00]
3354
        inc    bl
3355
        mov    [0xfb00],bl
3356
        mov    eax,0xfb00
3357
        add    eax,ebx
3358
        mov    edi,[mousedata]
3359
        mov    dl,byte [edi]
3360
        mov    [eax],byte dl
3361
        cmp    bl,3             ; three ?
3362
        jnz    decm
3363
 
3364
        ; buttons
3365
 
3366
;* change right and left button by places - start code - Mario79
3367
        mov al,[0xfb01]
3368
        mov ah,al
3369
        shr al,3
3370
        and al,2
3371
        shr ah,5
3372
        and ah,1
3373
        add al,ah
3374
;* change right and left button by places - end code - Mario79
3375
 
3376
        mov    [0xfb40],al
3377
 
3378
        ; com1 mouse
3379
        ; x
3380
 
3381
        mov    dl,[0xfb01]        ; x high bits
3382
        movzx  eax,dl
3383
        and    al,3
3384
        shl    al,6
3385
        mov    dl,byte[0xfb02]    ; x low bits
3386
        add    al,dl
3387
        mov    [0xfb21],byte al
3388
        movzx  ebx,word[0xfb0a]
3389
 
3390
        mov    al,byte [0xfb01]   ; + or - ?
3391
        test   al,2
3392
        jz     x_add
3393
 
3394
       x_sub:                      ; x-
3395
        sub    bx,255
3396
        sub    bx,255
3397
       x_add:                      ; x+
3398
        movzx  eax,byte [0xfb21]
3399
        add    bx,ax
3400
        add    bx,ax
3401
        push   ebx
3402
        mov    [0xfb00],byte 0
3403
 
3404
        ; y
3405
 
3406
 
3407
      my_event:
3408
 
3409
        mov    dl,[0xfb01]       ; y high bits
3410
        movzx  eax,dl
3411
        and    al,12
3412
        shl    al,4
3413
        mov    dl,byte[0xfb03]   ; y low bits
3414
        add    al,dl
3415
        mov    [0xfb22],byte al
3416
        movzx  ebx,word[0xfb0c]
3417
 
3418
        mov    al,byte [0xfb01]  ; + or - ?
3419
        test   al,8
3420
        je     y_add
3421
 
3422
      y_sub:                      ; y-
3423
        sub    bx,255
3424
        sub    bx,255
3425
      y_add:                      ; y+
3426
        movzx  eax,byte [0xfb22]
3427
        add    bx,ax
3428
        add    bx,ax
3429
        push   ebx
3430
        mov    [0xfb00],byte 0
3431
        jmp    mdraw
3432
 
3433
        ; end of com1 mouse
3434
 
3435
 
3436
        ; ******************************************
3437
        ; ********  PS2 MOUSE DRIVER  **************
3438
        ; ******************************************
3439
 
3440
      ps2mousefirst:
3441
 
3442
        movzx  edx,byte [0x2E0000+4096*12+0x10]   ; first ps2 ?
3443
        cmp    edx,40
3444
        jne    @f
3445
        mov    [0xfb00],byte 0  ; zero mouse block count
3446
      @@:
3447
 
3448
        movzx  ebx,byte [0xfb00]
3449
        add    ebx,1
3450
        mov    [0xfb00],bl
3451
        mov    eax,0xfb00
3452
        add    eax,ebx
3453
        mov    dl,byte [0x2E0000+4096*12+0x10]
3454
        mov    [eax],byte dl
3455
 
3456
        cmp    bl,3             ; full packet of three bytes ?
3457
        jnz    decm
3458
;        jz     ps2mouse
3459
;        jmp    decm
3460
 
3461
 
3462
;      ps2mouse:
3463
 
3464
        mov    [0xfb00],byte 0  ; zero mouse block count
3465
 
3466
        ; buttons
3467
 
3468
        movzx  eax,byte [0xfb01]
3469
        and    eax,3
3470
        mov    [0xfb40],al
3471
 
3472
        ; x
3473
 
3474
        movzx  eax,word [0xfb0a]
3475
        movzx  edx,byte [0xfb02]
3476
        cmp    edx,128
3477
        jb     ps2xp
3478
        shl    edx,1
3479
        add    eax,edx
3480
        cmp    eax,512
3481
        jge    ps2xsok
3482
        xor    eax, eax
3483
        jmp    ps2xready
3484
       ps2xsok:
3485
        sub    eax,512
3486
        jmp    ps2xready
3487
       ps2xp:
3488
        shl    edx,1
3489
        add    eax,edx
3490
        jmp    ps2xready
3491
       ps2xready:
3492
        push   eax
3493
 
3494
        ; y
3495
 
3496
        movzx  eax,word [0xfb0c]
3497
        movzx  edx,byte [0xfb03]
3498
        cmp    edx,128
3499
        jb     ps2yp
3500
        add    eax,512
3501
        shl    edx,1
3502
        sub    eax,edx
3503
        jmp    ps2yready
3504
       ps2yp:
3505
        shl    edx,1
3506
        cmp    edx,eax
3507
        jb     ps201
3508
        mov    edx,eax
3509
       ps201:
3510
        sub    eax,edx
3511
        jmp    ps2yready
3512
       ps2yready:
3513
        push   eax
3514
 
3515
        ;jmp    mdraw
3516
 
3517
        ; end of ps2 mouse
3518
 
3519
 
3520
        ; ****************************
3521
        ; ***** CHECK FOR LIMITS *****
3522
        ; ****************************
3523
 
3524
      mdraw:
3525
 
3526
        cmp    [0xfb44],byte 0
3527
        jne    mousedraw4
3528
        cmp    [0xfb40],byte 0
3529
        je     mousedraw4
3530
        mov    [0xfff5],byte 1
3531
 
3532
      mousedraw4:
3533
 
3534
        pop    ebx
3535
        pop    eax
3536
 
3537
        mov    [mouse_active],1
3538
 
3539
;        mov    dx,0                   ; smaller than zero
3540
        xor    dx,dx
3541
        cmp    bx,dx
3542
        jge    mnb11
3543
;        mov    bx,0
3544
        xor    bx,bx
3545
      mnb11:
3546
        mov    [0xfb0c],word bx
3547
 
3548
;        mov    dx,0
3549
        xor    dx,dx
3550
        cmp    ax,dx
3551
        jge    mnb22
3552
;        mov    ax,0
3553
        xor    ax,ax
3554
      mnb22:
3555
        mov    [0xfb0a],word ax
3556
 
3557
        mov    edx,[0xfe04]           ; bigger than maximum
3558
        cmp    ebx,edx
3559
        jb     mnb1
3560
        mov    bx,[0xfe04]
3561
      mnb1:
3562
        mov    [0xfb0c],word bx
3563
 
3564
        mov    edx,[0xfe00]
3565
        cmp    eax,edx
3566
        jb     mnb2
3567
        mov    ax,[0xfe00]
3568
      mnb2:
3569
        mov    [0xfb0a],word ax
3570
 
3571
 
3572
        ; ****   NEXT DATA BYTE FROM MOUSE BUFFER   ****
3573
 
3574
      decm:
3575
 
3576
        mov    edi,[mousecount]         ; decrease counter
3577
        dec    dword [edi]
3578
 
3579
        mov    esi,[mousedata]
3580
        mov    edi,esi
3581
        inc    esi
3582
;        mov    ecx,250
3583
        mov    ecx,[mousecount]
3584
        mov    ecx,[ecx]
3585
        cld
3586
        rep    movsb
3587
 
3588
        jmp    uusicheckmouse
3589
 
3590
      checkmouseret:
3591
 
3592
        cmp    [0xfb44],byte 0
3593
        jne    cmret
3594
 
3595
        cmp    [0xfb40],byte 0
3596
        je     cmret
3597
 
3598
        mov    [0xfff4],byte 0
3599
        mov    [0xfff5],byte 0
3600
 
3601
      cmret:
3602
 
3603
        popad
3604
 
3605
        ret
3606
 
3607
 
3608
draw_mouse_under:
3609
 
3610
        ; return old picture
3611
;        cli
3612
 
3613
        pushad
3614
 
3615
        xor    ecx,ecx
3616
        xor    edx,edx
3617
 
3618
        ;cli    ; !!!****
3619
        align  4
3620
      mres:
3621
 
3622
        movzx  eax,word [0xfb4a]
3623
        movzx  ebx,word [0xfb4c]
3624
 
3625
        add    eax,ecx
3626
        add    ebx,edx
3627
 
3628
        push   ecx
3629
        push   edx
3630
        push   eax
3631
        push   ebx
3632
 
3633
        mov    eax,edx
3634
        shl    eax,6
3635
        shl    ecx,2
3636
        add    eax,ecx
3637
        add    eax,mouseunder
3638
        mov    ecx,[eax]
3639
 
3640
        pop    ebx
3641
        pop    eax
3642
 
3643
        ;;;push   edi
3644
        mov    edi,1 ;force
3645
        call   [putpixel]
3646
        ;;;pop    edi
3647
 
3648
        pop    edx
3649
        pop    ecx
3650
 
3651
        inc    ecx
3652
        cmp    ecx, 16
3653
        jnz    mres
3654
        xor    ecx, ecx
3655
        inc    edx
3656
        cmp    edx, 24
3657
        jnz    mres
3658
        ;sti    ; !!!****
3659
 
3660
        popad
3661
 
3662
;        sti
3663
 
3664
        ret
3665
 
3666
 
3667
save_draw_mouse:
3668
 
3669
        ; save & draw
3670
;        cli
3671
 
3672
        mov    [0xfb4a],ax
3673
        mov    [0xfb4c],bx
3674
        push   eax
3675
        push   ebx
3676
        mov    ecx,0
3677
        mov    edx,0
3678
 
3679
        ;cli ; !!!****
3680
 
3681
      drm:
3682
 
3683
        push   eax
3684
        push   ebx
3685
        push   ecx
3686
        push   edx
3687
 
3688
        ; helloworld
3689
        push   eax ebx ecx
3690
        add    eax,ecx  ; save picture under mouse
3691
        add    ebx,edx
3692
        push   ecx
3693
        call   getpixel
3694
        mov    [0xfb30],ecx
3695
        pop    ecx
3696
        mov    eax,edx
3697
        shl    eax,6
3698
        shl    ecx,2
3699
        add    eax,ecx
3700
        add    eax,mouseunder
3701
        mov    ebx,[0xfb30]
3702
        mov    [eax],ebx
3703
        pop    ecx ebx eax
3704
 
3705
        mov    edi,edx       ; y cycle
3706
        shl    edi,4       ; *16 bytes per row
3707
        add    edi,ecx       ; x cycle
3708
        mov    esi, edi
3709
        add    edi, esi
3710
        add    edi, esi       ; *3
3711
        add    edi,[0xf200]      ; we have our str address
3712
        mov    esi, edi
3713
        add    esi, 16*24*3
3714
        push   ecx
3715
        mov    ecx, [0xfb30]
3716
        call   combine_colors
3717
        mov    [0xfb10], ecx
3718
        pop    ecx
3719
 
3720
 
3721
        pop    edx
3722
        pop    ecx
3723
        pop    ebx
3724
        pop    eax
3725
 
3726
        add    eax,ecx       ; we have x coord+cycle
3727
        add    ebx,edx       ; and y coord+cycle
3728
 
3729
        push   ecx edi
3730
        mov    ecx, [0xfb10]
3731
        mov    edi, 1
3732
        call   [putpixel]
3733
        pop    edi ecx
3734
 
3735
      mnext:
3736
 
3737
        mov    ebx,[esp+0]      ; pure y coord again
3738
        mov    eax,[esp+4]      ; and x
3739
 
3740
        inc    ecx          ; +1 cycle
3741
        cmp    ecx,16       ; if more than 16
3742
        jnz    drm
3743
        xor    ecx, ecx
3744
        inc    edx
3745
        cmp    edx,24
3746
        jnz    drm
3747
 
3748
        pop    ebx
3749
        pop    eax
3750
 
3751
;        sti ; !!!****
3752
 
3753
        ret
3754
 
3755
 
3756
combine_colors:
3757
 
3758
      ; in
3759
      ; ecx - color ( 00 RR GG BB )
3760
      ; edi - ref to new color byte
3761
      ; esi - ref to alpha byte
3762
      ;
3763
      ; out
3764
      ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
3765
 
3766
      push eax
3767
      push ebx
3768
      push edx
3769
      push ecx
3770
      xor ecx, ecx
3771
         ; byte 2
3772
      mov eax, 0xff
3773
      sub al, [esi+0]
3774
      mov ebx, [esp]
3775
      shr ebx, 16
3776
      and ebx, 0xff
3777
      mul ebx
3778
      shr eax, 8
3779
      add ecx, eax
3780
;      xor eax, eax
3781
;      xor ebx, ebx
3782
;      mov al, [edi+0]
3783
;      mov bl, [esi+0]
3784
    movzx eax, byte [edi+0]
3785
    movzx ebx, byte [esi+0]
3786
      mul ebx
3787
      shr eax, 8
3788
      add ecx, eax
3789
      shl ecx, 8
3790
         ; byte 1
3791
      mov eax, 0xff
3792
      sub al, [esi+1]
3793
      mov ebx, [esp]
3794
      shr ebx, 8
3795
      and ebx, 0xff
3796
      mul ebx
3797
      shr eax, 8
3798
      add ecx, eax
3799
;      xor eax, eax
3800
;      xor ebx, ebx
3801
;      mov al, [edi+1]
3802
;      mov bl, [esi+1]
3803
    movzx eax, byte [edi+1]
3804
    movzx ebx, byte [esi+1]
3805
      mul ebx
3806
      shr eax, 8
3807
      add ecx, eax
3808
      shl ecx, 8
3809
         ; byte 2
3810
      mov eax, 0xff
3811
      sub al, [esi+2]
3812
      mov ebx, [esp]
3813
      and ebx, 0xff
3814
      mul ebx
3815
      shr eax, 8
3816
      add ecx, eax
3817
;      xor eax, eax
3818
;      xor ebx, ebx
3819
;      mov al, [edi+2]
3820
;      mov bl, [esi+2]
3821
    movzx eax, byte [edi+2]
3822
    movzx ebx, byte [esi+2]
3823
      mul ebx
3824
      shr eax, 8
3825
      add ecx, eax
3826
 
3827
      pop eax
3828
      pop edx
3829
      pop ebx
3830
      pop eax
3831
      ret
3832
 
3833
 
3834
__sys_disable_mouse:
3835
 
3836
      pushad
3837
 
3838
      cmp  [0x3000],dword 1
3839
      je   disable_m
3840
 
3841
      mov  edx,[0x3000]
3842
      shl  edx,5
3843
      add  edx,window_data
3844
 
3845
      movzx  eax, word [0xfb0a]
3846
      movzx  ebx, word [0xfb0c]
3847
 
3848
      mov  ecx,[0xfe00]
3849
      inc  ecx
3850
      imul  ecx,ebx
3851
      add  ecx,eax
3852
      add  ecx, display_data
3853
 
3854
      movzx eax, byte [edx+twdw+0xe]
3855
 
3856
      movzx ebx, byte [ecx]
3857
      cmp   eax,ebx
3858
      je    yes_mouse_disable
3859
      movzx ebx, byte [ecx+16]
3860
      cmp   eax,ebx
3861
      je    yes_mouse_disable
3862
 
3863
      mov   ebx,[0xfe00]
3864
      inc   ebx
3865
      imul  ebx,10
3866
      add   ecx,ebx
3867
 
3868
      movzx ebx, byte [ecx]
3869
      cmp   eax,ebx
3870
      je    yes_mouse_disable
3871
 
3872
      mov   ebx,[0xfe00]
3873
      inc   ebx
3874
      imul  ebx,10
3875
      add   ecx,ebx
3876
 
3877
      movzx ebx, byte [ecx]
3878
      cmp   eax,ebx
3879
      je    yes_mouse_disable
3880
      movzx ebx, byte [ecx+16]
3881
      cmp   eax,ebx
3882
      je    yes_mouse_disable
3883
 
3884
      jmp   no_mouse_disable
3885
 
3886
    yes_mouse_disable:
3887
 
3888
      mov  edx,[0x3000]
3889
      shl  edx,5
3890
      add  edx,window_data
3891
 
3892
      movzx  eax, word [0xfb0a]
3893
      movzx  ebx, word [0xfb0c]
3894
 
3895
      mov  ecx,[edx+0]   ; mouse inside the area ?
3896
      add  eax,14
3897
      cmp  eax,ecx
3898
      jb   no_mouse_disable
3899
      sub  eax,14
3900
 
3901
      add  ecx,[edx+8]
3902
      cmp  eax,ecx
3903
      jg   no_mouse_disable
3904
 
3905
      mov  ecx,[edx+4]
3906
      add  ebx,20
3907
      cmp  ebx,ecx
3908
      jb   no_mouse_disable
3909
      sub  ebx,20
3910
 
3911
      add  ecx,[edx+12]
3912
      cmp  ebx,ecx
3913
      jg   no_mouse_disable
3914
 
3915
    disable_m:
3916
 
3917
      cmp  dword [0xf204],dword 0
3918
      jne  @f
3919
      call draw_mouse_under
3920
    @@:
3921
 
3922
      mov  [0xf204],dword 1
3923
 
3924
    no_mouse_disable:
3925
 
3926
      popad
3927
 
3928
      ret
3929
 
3930
 
3931
 
3932
__sys_draw_pointer:
3933
        cli
3934
 
3935
        pushad
3936
 
3937
        cmp    dword [0xf204],dword 0  ; mouse visible ?
3938
        je     chms00
3939
 
3940
        dec    dword [0xf204]
3941
 
3942
        cmp    [0xf204],dword 0
3943
        jnz    nodmu2
3944
 
3945
        movzx  ebx,word [0xfb0c]
3946
        movzx  eax,word [0xfb0a]
3947
        call   save_draw_mouse
3948
 
3949
        popad
3950
        sti
3951
        ret
3952
 
3953
      nodmu2:
3954
 
3955
        popad
3956
        sti
3957
        ret
3958
 
3959
      chms00:
3960
 
3961
;        popad
3962
 
3963
;        pushad
3964
 
3965
;        cmp   [0xf204],dword 0
3966
;        jne   nodmp
3967
 
3968
        movzx  ecx,word [0xfb4a]
3969
        movzx  edx,word [0xfb4c]
3970
 
3971
        movzx  ebx,word [0xfb0c]
3972
        movzx  eax,word [0xfb0a]
3973
 
3974
        cmp    eax,ecx
3975
        jne    redrawmouse
3976
 
3977
        cmp    ebx,edx
3978
        jne    redrawmouse
3979
 
3980
        jmp    nodmp
3981
 
3982
      redrawmouse:
3983
 
3984
 
3985
        call   draw_mouse_under
3986
redrawmouse_1:
3987
        call   save_draw_mouse
3988
 
3989
     nodmp:
3990
 
3991
        popad
3992
        sti
3993
        ret
3994
 
3995
 
3996
 
3997
calculatebackground:   ; background
3998
 
3999
        ; all black
4000
 
4001
        mov   [display_data-8],dword 4      ; size x
4002
        mov   [display_data-4],dword 2      ; size y
4003
 
4004
        mov   edi, 0x300000                 ; set background to black
4005
        xor   eax, eax
4006
        mov   ecx, 0x0fff00 / 4
4007
        cld
4008
        rep   stosd
4009
 
4010
        mov   edi,display_data              ; set os to use all pixels
4011
        mov   eax,0x01010101
4012
        mov   ecx,0x1fff00 / 4
4013
        rep   stosd
4014
 
4015
        mov   byte [0xFFF0], 0              ; do not draw background!
4016
 
4017
        ret
4018
 
4019
uglobal
4020
  imax    dd 0x0
4021
endg
4022
 
4023
 
4024
 
4025
delay_ms:     ; delay in 1/1000 sec
4026
 
4027
 
4028
        push  eax
4029
        push  ecx
4030
 
4031
        mov   ecx,esi
4032
        ; 
4033
        imul  ecx, 33941
4034
        shr   ecx, 9
4035
        ; 
4036
 
4037
        in    al,0x61
4038
        and   al,0x10
4039
        mov   ah,al
4040
        cld
4041
 
4042
 cnt1:  in    al,0x61
4043
        and   al,0x10
4044
        cmp   al,ah
4045
        jz    cnt1
4046
 
4047
        mov   ah,al
4048
        loop  cnt1
4049
 
4050
        pop   ecx
4051
        pop   eax
4052
 
4053
        ret
4054
 
4055
 
4056
set_app_param:
4057
        push edi
4058
 
4059
        mov  edi,[0x3010]
4060
        mov  [edi],eax
4061
 
4062
        pop  edi
4063
        ret
4064
 
4065
 
4066
 
4067
delay_hs:     ; delay in 1/100 secs
4068
        push  eax
4069
        push  ecx
4070
        push  edx
4071
 
4072
        mov   edx,[timer_ticks];[0xfdf0]
4073
        add   edx,eax
4074
 
4075
      newtic:
4076
        mov   ecx,[timer_ticks];[0xfdf0]
4077
        cmp   edx,ecx
4078
        jbe   zerodelay
4079
 
4080
        call  change_task
4081
 
4082
        jmp   newtic
4083
 
4084
      zerodelay:
4085
        pop   edx
4086
        pop   ecx
4087
        pop   eax
4088
 
4089
        ret
4090
 
4091
 
4092
memmove:       ; memory move in bytes
4093
 
4094
; eax = from
4095
; ebx = to
4096
; ecx = no of bytes
4097
    test ecx, ecx
4098
    jle  .ret
4099
 
4100
 
4101
    push esi edi ecx
4102
 
4103
    mov  edi, ebx
4104
    mov  esi, eax
4105
 
4106
    test ecx, not 11b
4107
    jz   @f
4108
 
4109
    push ecx
4110
    shr  ecx, 2
4111
    rep  movsd
4112
    pop  ecx
4113
    and  ecx, 11b
4114
    jz   .finish
4115
  @@:
4116
    rep  movsb
4117
 
4118
  .finish:
4119
    pop  ecx edi esi
4120
  .ret:
4121
    ret
4122
 
4123
 
4124
align 4
4125
 
4126
read_floppy_file:
4127
 
4128
; as input
4129
;
4130
; eax pointer to file
4131
; ebx file lenght
4132
; ecx start 512 byte block number
4133
; edx number of blocks to read
4134
; esi pointer to return/work area (atleast 20 000 bytes)
4135
;
4136
;
4137
; on return
4138
;
4139
; eax = 0 command succesful
4140
;       1 no fd base and/or partition defined
4141
;       2 yet unsupported FS
4142
;       3 unknown FS
4143
;       4 partition not defined at hd
4144
;       5 file not found
4145
; ebx = size of file
4146
 
4147
     mov   edi,[0x3010]
4148
     add   edi,0x10
4149
     add   esi,[edi]
4150
     add   eax,[edi]
4151
 
4152
     pushad
4153
     mov  edi,esi
4154
     add  edi,1024
4155
     mov  esi,0x100000+19*512
4156
     sub  ecx,1
4157
     shl  ecx,9
4158
     add  esi,ecx
4159
     shl  edx,9
4160
     mov  ecx,edx
4161
     cld
4162
     rep  movsb
4163
     popad
4164
 
4165
     mov   [esp+36],eax
4166
     mov   [esp+24],ebx
4167
     ret
4168
 
4169
 
4170
 
4171
align 4
4172
 
4173
sys_programirq:
4174
 
4175
    mov   edi,[0x3010]
4176
    add   edi,0x10
4177
    add   eax,[edi]
4178
 
4179
    mov   edx,ebx
4180
    shl   edx,2
4181
    add   edx,irq_owner
4182
    mov   edx,[edx]
4183
    mov   edi,[0x3010]
4184
    mov   edi,[edi+0x4]
4185
    cmp   edx,edi
4186
    je    spril1
4187
    mov   [esp+36],dword 1
4188
    ret
4189
  spril1:
4190
 
4191
    mov   esi,eax
4192
    shl   ebx,6
4193
    add   ebx,irq00read
4194
    mov   edi,ebx
4195
    mov   ecx,16
4196
    cld
4197
    rep   movsd
4198
    mov   [esp+36],dword 0
4199
    ret
4200
 
4201
 
4202
align 4
4203
 
4204
get_irq_data:
4205
 
4206
     mov   edx,eax           ; check for correct owner
4207
     shl   edx,2
4208
     add   edx,irq_owner
4209
     mov   edx,[edx]
4210
     mov   edi,[0x3010]
4211
     mov   edi,[edi+0x4]
4212
     cmp   edx,edi
4213
     je    gidril1
4214
     mov   [esp+36],eax
4215
     mov   [esp+32],dword 2
4216
     mov   [esp+24],ebx
4217
     ret
4218
 
4219
  gidril1:
4220
 
4221
     mov   ebx,eax
4222
     shl   ebx,12
4223
     add   ebx,0x2e0000
4224
     mov   eax,[ebx]
4225
     mov   ecx,1
4226
     test  eax,eax
4227
     jz    gid1
4228
 
4229
     dec   eax
4230
     mov   esi,ebx
4231
     mov   [ebx],eax
4232
     movzx ebx,byte [ebx+0x10]
4233
     add   esi,0x10
4234
     mov   edi,esi
4235
     inc   esi
4236
     mov   ecx,4000 / 4
4237
     cld
4238
     rep   movsd
4239
     xor   ecx,ecx
4240
   gid1:
4241
     mov   [esp+36],eax
4242
     mov   [esp+32],ecx
4243
     mov   [esp+24],ebx
4244
     ret
4245
 
4246
 
4247
set_io_access_rights:
4248
 
4249
     pushad
4250
 
4251
     mov   edi,[0x3000]
4252
     imul  edi,tss_step
4253
     add   edi,tss_data+128
4254
;     add   edi,128
4255
 
4256
     mov   ecx,eax
4257
     and   ecx,7    ; offset in byte
4258
 
4259
     shr   eax,3    ; number of byte
4260
     add   edi,eax
4261
 
4262
     mov   ebx,1
4263
     shl   ebx,cl
4264
 
4265
     cmp   ebp,0                ; enable access - ebp = 0
4266
     jne   siar1
4267
 
4268
     not   ebx
4269
     and   [edi],byte bl
4270
 
4271
     popad
4272
 
4273
     ret
4274
 
4275
   siar1:
4276
 
4277
     or    [edi],byte bl        ; disable access - ebp = 1
4278
 
4279
     popad
4280
 
4281
     ret
4282
 
4283
 
4284
 
4285
 
4286
 
4287
r_f_port_area:
4288
 
4289
     test  eax, eax
4290
     jnz   free_port_area
4291
;     je    r_port_area
4292
;     jmp   free_port_area
4293
 
4294
;   r_port_area:
4295
 
4296
     pushad
4297
 
4298
     cmp   ebx,ecx            ; beginning > end ?
4299
     jg    rpal1
4300
     mov   esi,[0x2d0000]
4301
     cmp   esi,0              ; no reserved areas ?
4302
     je    rpal2
4303
     cmp   esi,255            ; max reserved
4304
     jge   rpal1
4305
   rpal3:
4306
     mov   edi,esi
4307
     shl   edi,4
4308
     add   edi,0x2d0000
4309
     cmp   ebx,[edi+8]
4310
     jg    rpal4
4311
     cmp   ecx,[edi+4]
4312
     jae   rpal1
4313
;     jb    rpal4
4314
;     jmp   rpal1
4315
   rpal4:
4316
 
4317
     dec   esi
4318
     jnz   rpal3
4319
     jmp   rpal2
4320
   rpal1:
4321
     popad
4322
     mov   eax,1
4323
     ret
4324
 
4325
   rpal2:
4326
     popad
4327
 
4328
 
4329
     ; enable port access at port IO map
4330
     cli
4331
     pushad                        ; start enable io map
4332
 
4333
     cmp   ecx,65536 ;16384
4334
     jae   no_unmask_io ; jge
4335
 
4336
     mov   eax,ebx
4337
 
4338
   new_port_access:
4339
 
4340
     pushad
4341
 
4342
     mov   ebp,0                  ; enable - eax = port
4343
     call  set_io_access_rights
4344
 
4345
     popad
4346
 
4347
     inc   eax
4348
     cmp   eax,ecx
4349
     jbe   new_port_access
4350
 
4351
   no_unmask_io:
4352
 
4353
     popad                         ; end enable io map
4354
     sti
4355
 
4356
     mov   edi,[0x2d0000]
4357
     add   edi,1
4358
     mov   [0x2d0000],edi
4359
     shl   edi,4
4360
     add   edi,0x2d0000
4361
     mov   esi,[0x3010]
4362
     mov   esi,[esi+0x4]
4363
     mov   [edi],esi
4364
     mov   [edi+4],ebx
4365
     mov   [edi+8],ecx
4366
 
4367
     xor   eax, eax
4368
     ret
4369
 
4370
 
4371
 
4372
 
4373
free_port_area:
4374
 
4375
     pushad
4376
 
4377
     mov   esi,[0x2d0000]     ; no reserved areas ?
4378
     cmp   esi,0
4379
     je    frpal2
4380
     mov   edx,[0x3010]
4381
     mov   edx,[edx+4]
4382
   frpal3:
4383
     mov   edi,esi
4384
     shl   edi,4
4385
     add   edi,0x2d0000
4386
     cmp   edx,[edi]
4387
     jne   frpal4
4388
     cmp   ebx,[edi+4]
4389
     jne   frpal4
4390
     cmp   ecx,[edi+8]
4391
     jne   frpal4
4392
     jmp   frpal1
4393
   frpal4:
4394
     dec   esi
4395
     jnz   frpal3
4396
   frpal2:
4397
     popad
4398
     mov   eax,1
4399
     ret
4400
   frpal1:
4401
     mov   ecx,256
4402
     sub   ecx,esi
4403
     shl   ecx,4
4404
     mov   esi,edi
4405
     add   esi,16
4406
     cld
4407
     rep   movsb
4408
 
4409
     dec   dword [0x2d0000]
4410
 
4411
     popad
4412
 
4413
 
4414
     ; disable port access at port IO map
4415
 
4416
     pushad                        ; start disable io map
4417
 
4418
     cmp   ecx,65536 ;16384
4419
     jge   no_mask_io
4420
 
4421
     mov   eax,ebx
4422
 
4423
   new_port_access_disable:
4424
 
4425
     pushad
4426
 
4427
     mov   ebp,1                  ; disable - eax = port
4428
     call  set_io_access_rights
4429
 
4430
     popad
4431
 
4432
     inc   eax
4433
     cmp   eax,ecx
4434
     jbe   new_port_access_disable
4435
 
4436
   no_mask_io:
4437
 
4438
     popad                         ; end disable io map
4439
 
4440
     xor   eax, eax
4441
     ret
4442
 
4443
 
4444
reserve_free_irq:
4445
 
4446
     cmp   eax,0
4447
     jz    reserve_irq
4448
 
4449
     mov   edi,ebx
4450
     shl   edi,2
4451
     add   edi,irq_owner
4452
     mov   edx,[edi]
4453
     mov   eax,[0x3010]
4454
     mov   eax,[eax+0x4]
4455
     mov   ecx,1
4456
     cmp   edx,eax
4457
     jne   fril1
4458
     mov   [edi],dword 0
4459
     mov   ecx,0
4460
   fril1:
4461
     mov   [esp+36],ecx ; return in eax
4462
     ret
4463
 
4464
  reserve_irq:
4465
 
4466
     mov   edi,ebx
4467
     shl   edi,2
4468
     add   edi,irq_owner
4469
     mov   edx,[edi]
4470
     mov   ecx,1
4471
     cmp   edx,0
4472
     jne   ril1
4473
 
4474
     mov   edx,[0x3010]
4475
     mov   edx,[edx+0x4]
4476
     mov   [edi],edx
4477
     mov   ecx,0
4478
 
4479
   ril1:
4480
 
4481
     mov   [esp+36],ecx ; return in eax
4482
 
4483
     ret
4484
 
4485
 
4486
 
4487
drawbackground:
4488
 
4489
       cmp   [0xfe0c],word 0x12
4490
       jne   dbrv12
4491
       cmp   [display_data-12],dword 1
4492
       jne   bgrstr12
4493
       call  vga_drawbackground_tiled
4494
       ret
4495
     bgrstr12:
4496
       call  vga_drawbackground_stretch
4497
       ret
4498
     dbrv12:
4499
 
4500
       cmp  [0xfe0c],word 0100000000000000b
4501
       jge  dbrv20
4502
       cmp  [0xfe0c],word 0x13
4503
       je   dbrv20
4504
       call  vesa12_drawbackground
4505
       ret
4506
     dbrv20:
4507
       cmp   [display_data-12],dword 1
4508
       jne   bgrstr
4509
       call  vesa20_drawbackground_tiled
4510
       ret
4511
     bgrstr:
4512
       call  vesa20_drawbackground_stretch
4513
       ret
4514
 
4515
 
4516
sys_putimage:
4517
 
4518
     cmp   [0xfe0c],word 0x12
4519
     jne   spiv20
4520
     call  vga_putimage
4521
     ret
4522
   spiv20:
4523
 
4524
     cmp   [0xfe0c],word 0100000000000000b
4525
     jge   piv20
4526
     cmp   [0xfe0c],word 0x13
4527
     je    piv20
4528
     call  vesa12_putimage
4529
     ret
4530
   piv20:
4531
     call  vesa20_putimage
4532
     ret
4533
 
4534
 
4535
 
4536
; eax x beginning
4537
; ebx y beginning
4538
; ecx x end
4539
; edx y end
4540
; edi color
4541
 
4542
__sys_drawbar:
4543
 
4544
     cmp   [0xfe0c],word 0x12
4545
     jne   sdbv20
4546
     call  vga_drawbar
4547
     ret
4548
   sdbv20:
4549
 
4550
    cmp  [0xfe0c],word 0100000000000000b
4551
    jge  dbv20
4552
    cmp  [0xfe0c],word 0x13
4553
    je   dbv20
4554
    call vesa12_drawbar
4555
    ret
4556
 
4557
  dbv20:
4558
 
4559
    call vesa20_drawbar
4560
    ret
4561
 
4562
 
4563
 
4564
kb_read:
4565
 
4566
        push    ecx edx
4567
 
4568
        mov     ecx,0xffff
4569
      kr_loop:
4570
        in      al,0x64
4571
        test    al,1
4572
        jnz     kr_ready
4573
        loop    kr_loop
4574
        mov     ah,1
4575
        jmp     kr_exit
4576
      kr_ready:
4577
        push    ecx
4578
        mov     ecx,32
4579
      kr_delay:
4580
        loop    kr_delay
4581
        pop     ecx
4582
        in      al,0x60
4583
        xor     ah,ah
4584
      kr_exit:
4585
 
4586
        pop     edx ecx
4587
 
4588
        ret
4589
 
4590
 
4591
kb_write:
4592
 
4593
        push    ecx edx
4594
 
4595
        mov     dl,al
4596
        mov     ecx,0xffff
4597
      kw_loop1:
4598
        in      al,0x64
4599
        test    al,0x20
4600
        jz      kw_ok1
4601
        loop    kw_loop1
4602
        mov     ah,1
4603
        jmp     kw_exit
4604
      kw_ok1:
4605
        in      al,0x60
4606
        mov     ecx,0xffff
4607
      kw_loop:
4608
        in      al,0x64
4609
        test    al,2
4610
        jz      kw_ok
4611
        loop    kw_loop
4612
        mov     ah,1
4613
        jmp     kw_exit
4614
      kw_ok:
4615
        mov     al,dl
4616
        out     0x60,al
4617
        mov     ecx,0xffff
4618
      kw_loop3:
4619
        in      al,0x64
4620
        test    al,2
4621
        jz      kw_ok3
4622
        loop    kw_loop3
4623
        mov     ah,1
4624
        jmp     kw_exit
4625
      kw_ok3:
4626
        mov     ah,8
4627
      kw_loop4:
4628
        mov     ecx,0xffff
4629
      kw_loop5:
4630
        in      al,0x64
4631
        test    al,1
4632
        jnz     kw_ok4
4633
        loop    kw_loop5
4634
        dec     ah
4635
        jnz     kw_loop4
4636
      kw_ok4:
4637
        xor     ah,ah
4638
      kw_exit:
4639
 
4640
        pop     edx ecx
4641
 
4642
        ret
4643
 
4644
 
4645
kb_cmd:
4646
 
4647
        mov     ecx,0xffff
4648
      c_wait:
4649
        in      al,0x64
4650
        test    al,2
4651
        jz      c_send
4652
        loop    c_wait
4653
        jmp     c_error
4654
      c_send:
4655
        mov     al,bl
4656
        out     0x64,al
4657
        mov     ecx,0xffff
4658
      c_accept:
4659
        in      al,0x64
4660
        test    al,2
4661
        jz      c_ok
4662
        loop    c_accept
4663
      c_error:
4664
        mov     ah,1
4665
        jmp     c_exit
4666
      c_ok:
4667
        xor     ah,ah
4668
      c_exit:
4669
        ret
4670
 
4671
 
4672
setmouse:  ; set mousepicture -pointer
4673
           ; ps2 mouse enable
4674
 
4675
     mov     [0xf200],dword mousepointer
4676
 
4677
     cli
4678
     mov     bl,0xa8                 ; enable mouse cmd
4679
     call    kb_cmd
4680
     call    kb_read                 ; read status
4681
 
4682
     mov     bl,0x20                 ; get command byte
4683
     call    kb_cmd
4684
     call    kb_read
4685
     or      al,3                    ; enable interrupt
4686
     mov     bl,0x60                 ; write command
4687
     push    eax
4688
     call    kb_cmd
4689
     pop     eax
4690
     call    kb_write
4691
 
4692
     mov     bl,0xd4                 ; for mouse
4693
     call    kb_cmd
4694
     mov     al,0xf4                 ; enable mouse device
4695
     call    kb_write
4696
     call    kb_read           ; read status return
4697
 
4698
     ; com1 mouse enable
4699
 
4700
     mov   bx,0x3f8 ; combase
4701
 
4702
     mov   dx,bx
4703
     add   dx,3
4704
     mov   al,0x80
4705
     out   dx,al
4706
 
4707
     mov   dx,bx
4708
     add   dx,1
4709
     mov   al,0
4710
     out   dx,al
4711
 
4712
     mov   dx,bx
4713
     add   dx,0
4714
     mov   al,0x30*2    ; 0x30 / 4
4715
     out   dx,al
4716
 
4717
     mov   dx,bx
4718
     add   dx,3
4719
     mov   al,2         ; 3
4720
     out   dx,al
4721
 
4722
     mov   dx,bx
4723
     add   dx,4
4724
     mov   al,0xb
4725
     out   dx,al
4726
 
4727
     mov   dx,bx
4728
     add   dx,1
4729
     mov   al,1
4730
     out   dx,al
4731
 
4732
 
4733
     ; com2 mouse enable
4734
 
4735
     mov   bx,0x2f8 ; combase
4736
 
4737
     mov   dx,bx
4738
     add   dx,3
4739
     mov   al,0x80
4740
     out   dx,al
4741
 
4742
     mov   dx,bx
4743
     add   dx,1
4744
     mov   al,0
4745
     out   dx,al
4746
 
4747
     mov   dx,bx
4748
     add   dx,0
4749
     mov   al,0x30*2
4750
     out   dx,al
4751
 
4752
     mov   dx,bx
4753
     add   dx,3
4754
     mov   al,2
4755
     out   dx,al
4756
 
4757
     mov   dx,bx
4758
     add   dx,4
4759
     mov   al,0xb
4760
     out   dx,al
4761
 
4762
     mov   dx,bx
4763
     add   dx,1
4764
     mov   al,1
4765
     out   dx,al
4766
 
4767
     ret
4768
 
4769
 
4770
_rdtsc:
4771
 
4772
     mov   edx,[cpuid_1+3*4]
4773
     test  edx,00010000b
4774
     jz    ret_rdtsc
4775
     rdtsc
4776
     ret
4777
   ret_rdtsc:
4778
     mov   edx,0xffffffff
4779
     mov   eax,0xffffffff
4780
     ret
4781
 
4782
 
4783
 
4784
rerouteirqs:
4785
 
4786
        cli
4787
 
4788
        mov     al,0x11         ;  icw4, edge triggered
4789
        out     0x20,al
4790
        call    pic_delay
4791
        out     0xA0,al
4792
        call    pic_delay
4793
 
4794
        mov     al,0x20         ;  generate 0x20 +
4795
        out     0x21,al
4796
        call    pic_delay
4797
        mov     al,0x28         ;  generate 0x28 +
4798
        out     0xA1,al
4799
        call    pic_delay
4800
 
4801
        mov     al,0x04         ;  slave at irq2
4802
        out     0x21,al
4803
        call    pic_delay
4804
        mov     al,0x02         ;  at irq9
4805
        out     0xA1,al
4806
        call    pic_delay
4807
 
4808
        mov     al,0x01         ;  8086 mode
4809
        out     0x21,al
4810
        call    pic_delay
4811
        out     0xA1,al
4812
        call    pic_delay
4813
 
4814
        mov     al,255          ; mask all irq's
4815
        out     0xA1,al
4816
        call    pic_delay
4817
        out     0x21,al
4818
        call    pic_delay
4819
 
4820
        mov     ecx,0x1000
4821
        cld
4822
picl1:  call    pic_delay
4823
        loop    picl1
4824
 
4825
        mov     al,255          ; mask all irq's
4826
        out     0xA1,al
4827
        call    pic_delay
4828
        out     0x21,al
4829
        call    pic_delay
4830
 
4831
        cli
4832
 
4833
        ret
4834
 
4835
 
4836
pic_delay:
4837
 
4838
        jmp     pdl1
4839
pdl1:   ret
4840
 
4841
 
4842
sys_msg_board_str:
4843
 
4844
     pushad
4845
   @@:
4846
     cmp    [esi],byte 0
4847
     je     @f
4848
     mov    eax,1
4849
     movzx  ebx,byte [esi]
4850
     call   sys_msg_board
4851
     inc    esi
4852
     jmp    @b
4853
   @@:
4854
     popad
4855
     ret
4856
 
4857
uglobal
4858
  msg_board_data: times 512 db 0
4859
  msg_board_count dd 0x0
4860
endg
4861
 
4862
sys_msg_board:
4863
 
4864
; eax=1 : write :  bl byte to write
4865
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4866
 
4867
     mov  ecx,[msg_board_count]
4868
     cmp  eax, 1
4869
     jne  smbl1
4870
 
4871
 
4872
     mov  [msg_board_data+ecx],bl
4873
     inc  ecx
4874
     and  ecx, 511
4875
     mov  [msg_board_count], ecx
4876
     mov  [check_idle_semaphore], 5
4877
     ret
4878
   smbl1:
4879
 
4880
     cmp   eax, 2
4881
     jne   smbl2
4882
     test  ecx, ecx
4883
     jz    smbl21
4884
;     mov   edi, msg_board_data
4885
;     mov   esi, msg_board_data+1
4886
;     movzx eax, byte [edi]
4887
     mov   eax, msg_board_data+1
4888
     mov   ebx, msg_board_data
4889
     movzx edx, byte [ebx]
4890
     call  memmove
4891
;     push  ecx
4892
;     shr   ecx, 2
4893
;     cld
4894
;     rep   movsd
4895
;     pop   ecx
4896
;     and   ecx, 3
4897
;     rep   movsb
4898
     dec   [msg_board_count]
4899
     mov   [esp+36], edx ;eax
4900
     mov   [esp+24], dword 1
4901
     ret
4902
   smbl21:
4903
     mov   [esp+36], ecx
4904
     mov   [esp+24], ecx
4905
 
4906
   smbl2:
4907
     ret
4908
 
4909
 
4910
 
4911
sys_trace:
4912
 
4913
     test eax, eax                  ; get event data
4914
     jnz  no_get_sys_events
4915
 
4916
     mov  esi,save_syscall_data     ; data
4917
     mov  edi,[0x3010]
4918
     mov  edi,[edi+0x10]
4919
     add  edi,ebx
4920
     cld
4921
     rep  movsb
4922
 
4923
     mov  [esp+24],dword 0
4924
     mov  eax,[save_syscall_count]  ; count
4925
     mov  [esp+36],eax
4926
     ret
4927
 
4928
   no_get_sys_events:
4929
 
4930
     ret
4931
 
4932
 
4933
sys_process_def:
4934
 
4935
     cmp   eax,1                   ; set keyboard mode
4936
     jne   no_set_keyboard_setup
4937
 
4938
     mov   edi,[0x3000]
4939
     shl   edi,8
4940
     add   edi,0x80000+0xB4
4941
     mov   [edi],bl
4942
 
4943
     ret
4944
 
4945
   no_set_keyboard_setup:
4946
 
4947
     cmp   eax,2                   ; get keyboard mode
4948
     jne   no_get_keyboard_setup
4949
 
4950
     mov   edi,[0x3000]
4951
     shl   edi,8
4952
     add   edi,0x80000+0xB4
4953
     movzx eax, byte [edi]
4954
 
4955
     mov   [esp+36],eax
4956
 
4957
     ret
4958
 
4959
   no_get_keyboard_setup:
4960
 
4961
     cmp   eax,3                   ; get keyboard ctrl, alt, shift
4962
     jne   no_get_keyboard_cas
4963
 
4964
;     xor   eax,eax
4965
;     movzx eax,byte [shift]
4966
;     movzx ebx,byte [ctrl]
4967
;     shl   ebx,2
4968
;     add   eax,ebx
4969
;     movzx ebx,byte [alt]
4970
;     shl   ebx,3
4971
;     add   eax,ebx
4972
 
4973
 ;// mike.dld [
4974
     mov   eax, [kb_state]
4975
 ;// mike.dld ]
4976
 
4977
     mov   [esp+36],eax
4978
 
4979
     ret
4980
 
4981
   no_get_keyboard_cas:
4982
 
4983
 
4984
     ret
4985
 
4986
 
4987
sys_ipc:
4988
     cmp  eax,1                      ; DEFINE IPC MEMORY
4989
     jne  no_ipc_def
4990
     mov  edi,[0x3000]
4991
     shl  edi,8
4992
     add  edi,0x80000
4993
     mov  [edi+0xA0],ebx
4994
     mov  [edi+0xA4],ecx
4995
     mov  [esp+36],dword 0
4996
     ret
4997
   no_ipc_def:
4998
 
4999
     cmp  eax,2                      ; SEND IPC MESSAGE
5000
     jne  no_ipc_send
5001
     mov  esi,1
5002
     mov  edi,0x3020
5003
    ipcs1:
5004
     cmp  [edi+4],ebx
5005
     je   ipcs2
5006
     add  edi,0x20
5007
     inc  esi
5008
     cmp  esi,[0x3004]
5009
     jbe  ipcs1
5010
     mov  [esp+36],dword 4
5011
     ret
5012
    ipcs2:
5013
 
5014
     cli
5015
 
5016
     push esi
5017
     mov  eax,esi
5018
     shl  eax,8
5019
     mov  ebx,[eax+0x80000+0xa0]
5020
     test ebx,ebx                  ; ipc area not defined ?
5021
     je   ipc_err1
5022
 
5023
     add  ebx,[eax+0x80000+0xa4]
5024
     mov  eax,esi
5025
     shl  eax,5
5026
     add  ebx,[eax+0x3000+0x10]    ; ebx <- max data position
5027
 
5028
     mov  eax,esi                  ; to
5029
     shl  esi,8
5030
     add  esi,0x80000
5031
     mov  edi,[esi+0xa0]
5032
     shl  eax,5
5033
     add  eax,0x3000
5034
     add  edi,[eax+0x10]
5035
 
5036
     cmp  [edi],byte 0             ; overrun ?
5037
     jne  ipc_err2
5038
 
5039
     mov  ebp,edi
5040
     add  edi,[edi+4]
5041
     add  edi,8
5042
 
5043
     mov  esi,ecx                  ; from
5044
     mov  eax,[0x3010]
5045
     mov  eax,[eax+0x10]
5046
     add  esi,eax
5047
 
5048
     mov  ecx,edx                  ; size
5049
 
5050
     mov  eax,edi
5051
     add  eax,ecx
5052
     cmp  eax,ebx
5053
     jge  ipc_err3                 ; not enough room ?
5054
 
5055
     push ecx
5056
 
5057
     mov  eax,[0x3010]
5058
     mov  eax,[eax+4]
5059
     mov  [edi-8],eax
5060
     mov  [edi-4],ecx
5061
     cld
5062
     rep  movsb
5063
 
5064
     pop  ecx
5065
     add  ecx,8
5066
 
5067
     mov  edi,ebp                  ; increase memory position
5068
     add  dword [edi+4],ecx
5069
 
5070
     mov  edi,[esp]
5071
     shl  edi,8
5072
     or   dword [edi+0x80000+0xA8],dword 01000000b ; ipc message
5073
 
5074
     cmp  [check_idle_semaphore],dword 20
5075
     jge  ipc_no_cis
5076
     mov  [check_idle_semaphore],5
5077
   ipc_no_cis:
5078
 
5079
     xor  eax, eax
5080
 
5081
    ipc_err:
5082
     add  esp,4
5083
     mov  [esp+36],eax
5084
     sti
5085
     ret
5086
 
5087
    ipc_err1:
5088
     add  esp,4
5089
     mov  [esp+36],dword 1
5090
     sti
5091
     ret
5092
    ipc_err2:
5093
     add  esp,4
5094
     mov  [esp+36],dword 2
5095
     sti
5096
     ret
5097
    ipc_err3:
5098
     add  esp,4
5099
     mov  [esp+36],dword 3
5100
     sti
5101
     ret
5102
 
5103
   no_ipc_send:
5104
 
5105
     mov  [esp+36],dword -1
5106
     ret
5107
 
5108
 
5109
align 4
5110
 
5111
sys_gs:                         ; direct screen access
5112
 
5113
     cmp  eax,1                 ; resolution
5114
     jne  no_gs1
5115
     mov  eax,[0xfe00]
5116
     shl  eax,16
5117
     mov  ax,[0xfe04]
5118
     add  eax,0x00010001
5119
     mov  [esp+36],eax
5120
     ret
5121
   no_gs1:
5122
 
5123
     cmp   eax,2                ; bits per pixel
5124
     jne   no_gs2
5125
     movzx eax,byte [0xfbf1]
5126
     mov   [esp+36],eax
5127
     ret
5128
   no_gs2:
5129
 
5130
     cmp   eax,3                ; bytes per scanline
5131
     jne   no_gs3
5132
     mov   eax,[0xfe08]
5133
     mov   [esp+36],eax
5134
     ret
5135
   no_gs3:
5136
 
5137
     mov  [esp+36],dword -1
5138
     ret
5139
 
5140
 
5141
align 4 ; PCI functions
5142
 
5143
sys_pci:
5144
 
5145
     call  pci_api
5146
     mov   [esp+36],eax
5147
     ret
5148
 
5149
 
5150
align 4  ;  system functions
5151
 
5152
syscall_setpixel:                       ; SetPixel
5153
 
5154
 
5155
     mov   edx,[0x3010]
5156
     add   eax,[edx-twdw]
5157
     add   ebx,[edx-twdw+4]
5158
     xor   edi,edi ; no force
5159
     call  [disable_mouse]
5160
     jmp   [putpixel]
5161
 
5162
align 4
5163
 
5164
syscall_writetext:                      ; WriteText
5165
 
5166
     mov   edi,[0x3010]
5167
     mov   ebp,[edi-twdw]
5168
     shl   ebp,16
5169
     add   ebp,[edi-twdw+4]
5170
     add   edi,0x10
5171
     add   ecx,[edi]
5172
     add   eax,ebp
5173
     xor   edi,edi
5174
     jmp   dtext
5175
 
5176
align 4
5177
 
5178
syscall_openramdiskfile:                ; OpenRamdiskFile
5179
 
5180
 
5181
     mov   edi,[0x3010]
5182
     add   edi,0x10
5183
     add   eax,[edi]
5184
     add   edx,[edi]
5185
     mov   esi,12
5186
     call  fileread
5187
     mov   [esp+36],ebx
5188
     ret
5189
 
5190
align 4
5191
 
5192
syscall_putimage:                       ; PutImage
5193
 
5194
     mov   edi,[0x3010]
5195
     add   edi,0x10
5196
     add   eax,[edi]
5197
     mov   edx,ecx
5198
     mov   ecx,ebx
5199
     mov   ebx,eax
5200
     call  sys_putimage
5201
     mov   [esp+36],eax
5202
     ret
5203
 
5204
align 4
5205
 
5206
syscall_drawrect:                       ; DrawRect
5207
 
5208
     mov   edi,ecx
5209
     test  ax,ax
5210
     je    drectr
5211
     test  bx,bx
5212
     je    drectr
5213
     movzx ecx,ax
5214
     shr   eax,16
5215
     movzx edx,bx
5216
     shr   ebx,16
5217
     add   ecx,eax
5218
     add   edx,ebx
5219
     jmp   [drawbar]
5220
    drectr:
5221
     ret
5222
 
5223
align 4
5224
 
5225
syscall_getscreensize:                  ; GetScreenSize
5226
 
5227
     movzx eax,word[0xfe00]
5228
     shl   eax,16
5229
     mov   ax,[0xfe04]
5230
     mov   [esp+36],eax
5231
     ret
5232
 
5233
align 4
5234
 
5235
syscall_system:                         ; System
5236
 
5237
     call  sys_system
5238
     mov   [esp+36],eax
5239
     ret
5240
 
5241
align 4
5242
 
5243
syscall_startapp:                       ; StartApp
5244
     mov   edi,[0x3010]
5245
     add   edi,0x10
5246
     add   eax,[edi]
5247
     test  ebx,ebx
5248
     jz    noapppar
5249
     add   ebx,[edi]
5250
   noapppar:
5251
;     call  start_application_fl
5252
     call   new_start_application_fl
5253
     mov   [esp+36],eax
5254
     ret
5255
 
5256
 
5257
align 4
5258
 
5259
syscall_cdaudio:                        ; CD
5260
 
5261
     call  sys_cd_audio
5262
     mov   [esp+36],eax
5263
     ret
5264
 
5265
align 4
5266
 
5267
syscall_readhd:                         ; ReadHd
5268
 
5269
     mov   edi,[0x3010]
5270
     add   edi,0x10
5271
     add   esi,[edi]
5272
     add   eax,[edi]
5273
     call  read_hd_file
5274
     mov   [esp+36],eax
5275
     mov   [esp+24],ebx
5276
     ret
5277
 
5278
align 4
5279
 
5280
syscall_starthdapp:                     ; StartHdApp
5281
 
5282
     mov   edi,[0x3010]
5283
     add   edi,0x10
5284
     add   eax,[edi]
5285
     add   ecx,[edi]
5286
     mov   ebp,0
5287
     call  start_application_hd
5288
     mov   [esp+36],eax
5289
     ret
5290
 
5291
align 4
5292
 
5293
syscall_delramdiskfile:                 ; DelRamdiskFile
5294
 
5295
     mov   edi,[0x3010]
5296
     add   edi,0x10
5297
     add   eax,[edi]
5298
     call  filedelete
5299
     mov   [esp+36],eax
5300
     ret
5301
 
5302
align 4
5303
 
5304
syscall_writeramdiskfile:               ; WriteRamdiskFile
5305
 
5306
     mov   edi,[0x3010]
5307
     add   edi,0x10
5308
     add   eax,[edi]
5309
     add   ebx,[edi]
5310
     call  filesave
5311
     mov   [esp+36],eax
5312
     ret
5313
 
5314
align 4
5315
 
5316
syscall_getpixel:                       ; GetPixel
5317
 
5318
     mov   ecx,[0xfe00]
5319
     inc   ecx
5320
     xor   edx,edx
5321
     div   ecx
5322
     mov   ebx,edx
5323
     xchg  eax,ebx
5324
     call  dword [0xe024]
5325
     mov   [esp+36],ecx
5326
     ret
5327
 
5328
align 4
5329
 
5330
syscall_readstring:                     ; ReadString
5331
 
5332
     mov   edi,[0x3010]
5333
     add   edi,0x10
5334
     add   eax,[edi]
5335
     call  read_string
5336
     mov   [esp+36],eax
5337
     ret
5338
 
5339
align 4
5340
 
5341
syscall_drawline:                       ; DrawLine
5342
 
5343
     mov   edi,[0x3010]
5344
     movzx edx,word[edi-twdw]
5345
     mov   ebp,edx
5346
     shl   edx,16
5347
     add   ebp,edx
5348
     movzx edx,word[edi-twdw+4]
5349
     add   eax,ebp
5350
     mov   ebp,edx
5351
     shl   edx,16
5352
     xor   edi,edi
5353
     add   edx,ebp
5354
     add   ebx,edx
5355
     jmp   [draw_line]
5356
 
5357
align 4
5358
 
5359
syscall_getirqowner:                    ; GetIrqOwner
5360
 
5361
     shl   eax,2
5362
     add   eax,irq_owner
5363
     mov   eax,[eax]
5364
     mov   [esp+36],eax
5365
     ret
5366
 
5367
align 4
5368
 
5369
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5370
 
5371
     call  r_f_port_area
5372
     mov   [esp+36],eax
5373
     ret
5374
 
5375
align 4
5376
 
5377
syscall_appints:                        ; AppInts
5378
 
5379
     test  eax,eax
5380
     jnz   unknown_app_int_fn
5381
     mov   edi,[0x3010]
5382
     mov   [edi+draw_data-0x3000+0x1c],ebx
5383
     ret
5384
   unknown_app_int_fn:
5385
     mov   [esp+36],dword -1
5386
     ret
5387
 
5388
align 4
5389
 
5390
syscall_threads:                        ; CreateThreads
5391
 
5392
     call  sys_threads
5393
     mov   [esp+36],eax
5394
     ret
5395
 
5396
align 4
5397
 
5398
stack_driver_stat:
5399
 
5400
     call  app_stack_handler            ; Stack status
5401
 
5402
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5403
;     call  change_task                 ; between sent packet
5404
 
5405
     mov   [esp+36],eax
5406
     ret
5407
 
5408
align 4
5409
 
5410
socket:                                 ; Socket interface
5411
     call  app_socket_handler
5412
 
5413
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5414
;     call  change_task                 ; between sent packet
5415
 
5416
     mov   [esp+36],eax
5417
     mov   [esp+24],ebx
5418
     ret
5419
 
5420
align 4
5421
 
5422
user_events:                            ; User event times
5423
 
5424
     mov   eax,0x12345678
5425
     mov   [esp+36],eax
5426
 
5427
     ret
5428
 
5429
align 4
5430
 
5431
read_from_hd:                           ; Read from hd - fn not in use
5432
 
5433
     mov   edi,[0x3010]
5434
     add   edi,0x10
5435
     add   eax,[edi]
5436
     add   ecx,[edi]
5437
     add   edx,[edi]
5438
     call  file_read
5439
 
5440
     mov   [esp+36],eax
5441
     mov   [esp+24],ebx
5442
 
5443
     ret
5444
 
5445
 
5446
align 4
5447
 
5448
write_to_hd:                            ; Write a file to hd
5449
 
5450
     mov   edi,[0x3010]
5451
     add   edi,0x10
5452
     add   eax,[edi]
5453
     add   ecx,[edi]
5454
     add   edx,[edi]
5455
     call  file_write
5456
     ret
5457
 
5458
align 4
5459
 
5460
delete_from_hd:                         ; Delete a file from hd
5461
 
5462
     mov   edi,[0x3010]
5463
     add   edi,0x10
5464
     add   eax,[edi]
5465
     add   ecx,[edi]
5466
     call  file_delete
5467
     ret
5468
 
5469
 
5470
align 4
5471
 
5472
undefined_syscall:                      ; Undefined system call
5473
 
5474
     mov   [esp+36],dword -1
5475
     ret
5476
 
5477
 
5478
;clear_busy_flag_at_caller:
5479
 
5480
;      push  edi
5481
 
5482
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
5483
;      imul  edi,8
5484
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
5485
 
5486
;      pop   edi
5487
 
5488
;      ret
5489
 
5490
 
5491
 
5492
 
5493
keymap:
5494
 
5495
     db   '6',27
5496
     db   '1234567890-=',8,9
5497
     db   'qwertyuiop[]',13
5498
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
5499
     db   '@234567890123',180,178,184,'6',176,'7'
5500
     db   179,'8',181,177,183,185,182
5501
     db   'AB
5502
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5503
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5504
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5505
 
5506
 
5507
keymap_shift:
5508
 
5509
     db   '6',27
5510
     db   '!@#$%^&*()_+',8,9
5511
     db   'QWERTYUIOP{}',13
5512
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
5513
     db   '@234567890123',180,178,184,'6',176,'7'
5514
     db   179,'8',181,177,183,185,182
5515
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
5516
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5517
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5518
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5519
 
5520
 
5521
keymap_alt:
5522
 
5523
     db   ' ',27
5524
     db   ' @ $  {[]}\ ',8,9
5525
     db   '            ',13
5526
     db   '             ',0,'           ',0,'4',0,' '
5527
     db   '             ',180,178,184,'6',176,'7'
5528
     db   179,'8',181,177,183,185,182
5529
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
5530
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5531
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5532
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5533
 
5534
 
5535
; device irq owners
5536
uglobal
5537
irq_owner:       ; process id
5538
 
5539
     dd   0x0
5540
     dd   0x0
5541
     dd   0x0
5542
     dd   0x0
5543
     dd   0x0
5544
     dd   0x0
5545
     dd   0x0
5546
     dd   0x0
5547
     dd   0x0
5548
     dd   0x0
5549
     dd   0x0
5550
     dd   0x0
5551
     dd   0x0
5552
     dd   0x0
5553
     dd   0x0
5554
     dd   0x0
5555
endg
5556
 
5557
 
5558
; on irq read ports
5559
uglobal
5560
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5561
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5562
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5563
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5564
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5565
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5566
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5567
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5568
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5569
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5570
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5571
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5572
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5573
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5574
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5575
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5576
endg
5577
 
5578
; status
5579
uglobal
5580
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5581
  application_table_status    dd 0x0  ; 0 - free : other - pid
5582
endg
5583
 
5584
; device addresses
5585
uglobal
5586
  mididp     dd 0x0
5587
  midisp     dd 0x0
5588
 
5589
  cdbase     dd 0x0
5590
  cdid       dd 0x0
5591
 
5592
  hdbase              dd   0x0  ; for boot 0x1f0
5593
  hdid                dd   0x0
5594
  hdpos               dd   0x0  ; for boot 0x1
5595
  fat32part           dd   0x0  ; for boot 0x1
5596
 
5597
  ;part2_ld            dd   0x0
5598
 
5599
;* start code - get  process (3) - Mario79
5600
active_process      dd   0
5601
;* end code - get active process (3) - Mario79
5602
 
5603
wraw_bacground_select db 0
5604
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5605
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5606
 
5607
  sb16       dd 0x0
5608
  wss        dd 0x0
5609
 
5610
  buttontype         dd 0x0
5611
  windowtypechanged  dd 0x0
5612
endg
5613
 
5614
iglobal
5615
  keyboard   dd 0x1
5616
  sound_dma  dd 0x1
5617
  syslang    dd 0x1
5618
endg
5619
 
5620
IncludeIGlobals
5621
endofcode:
5622
IncludeUGlobals
5623
uglobals_size = $ - endofcode
5624
diff16 "end of kernel code",$
5625