Subversion Repositories Kolibri OS

Rev

Rev 13 | Rev 15 | 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
 
3281
         pop  eax
3282
         popad
3283
 
3284
         ret
3285
 
3286
;   check mouse
3287
;
3288
;
3289
;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
3290
;   FB10  ->   FB17   mouse color mem
3291
;   FB21              x move
3292
;   FB22              y move
3293
;   FB30              color temp
3294
;   FB28              high bits temp
3295
;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
3296
;   FC00  ->   FCFE   com1/ps2 buffer
3297
;   FCFF              com1/ps2 buffer count starting from FC00
3298
 
3299
uglobal
3300
  mousecount  dd  0x0
3301
  mousedata   dd  0x0
3302
endg
3303
 
3304
 
3305
check_mouse_data:
3306
 
3307
        pushad
3308
 
3309
        cmp    [0xF604],byte 1
3310
        jne    no_ps2_mouse
3311
        mov    [mousecount],dword 0x2e0000+12*4096
3312
        mov    [mousedata],dword 0x2e0000+12*4096+0x10
3313
        jmp    uusicheckmouse
3314
no_ps2_mouse:
3315
        cmp    [0xF604],byte 2
3316
        jne    no_com1_mouse
3317
        mov    [mousecount],dword 0x2e0000+4*4096
3318
        mov    [mousedata],dword 0x2e0000+4*4096+0x10
3319
        jmp    uusicheckmouse
3320
no_com1_mouse:
3321
        mov    [mousecount],dword 0x2e0000+3*4096
3322
        mov    [mousedata],dword 0x2e0000+3*4096+0x10
3323
 
3324
      uusicheckmouse:
3325
 
3326
        mov    ebx,[mousecount]       ; anything at buffer for mouse
3327
        cmp    dword [ebx], 0         ; !!!
3328
        jz     checkmouseret
3329
 
3330
        ; first byte of comX or ps2 ?
3331
 
3332
        cmp    [0xF604],byte 1
3333
        je     ps2mousefirst
3334
 
3335
        ; ******************************************
3336
        ; *********** COMX mouse driver ************
3337
        ; ******************************************
3338
 
3339
       com1mousefirst:
3340
 
3341
        mov    edi,[mousedata]
3342
        mov    dl,byte [edi] ; first com1 ?
3343
        test   dl,64
3344
        jz     @f
3345
        mov    [0xfb00],byte 0  ; zero mouse block count
3346
       @@:
3347
        xor    ebx,ebx
3348
 
3349
        mov    bl,[0xfb00]
3350
        inc    bl
3351
        mov    [0xfb00],bl
3352
        mov    eax,0xfb00
3353
        add    eax,ebx
3354
        mov    edi,[mousedata]
3355
        mov    dl,byte [edi]
3356
        mov    [eax],byte dl
3357
        cmp    bl,3             ; three ?
3358
        jnz    decm
3359
 
3360
        ; buttons
3361
 
3362
;* change right and left button by places - start code - Mario79
3363
        mov al,[0xfb01]
3364
        mov ah,al
3365
        shr al,3
3366
        and al,2
3367
        shr ah,5
3368
        and ah,1
3369
        add al,ah
3370
;* change right and left button by places - end code - Mario79
3371
 
3372
        mov    [0xfb40],al
3373
 
3374
        ; com1 mouse
3375
        ; x
3376
 
3377
        mov    dl,[0xfb01]        ; x high bits
3378
        movzx  eax,dl
3379
        and    al,3
3380
        shl    al,6
3381
        mov    dl,byte[0xfb02]    ; x low bits
3382
        add    al,dl
3383
        mov    [0xfb21],byte al
3384
        movzx  ebx,word[0xfb0a]
3385
 
3386
        mov    al,byte [0xfb01]   ; + or - ?
3387
        test   al,2
3388
        jz     x_add
3389
 
3390
       x_sub:                      ; x-
3391
        sub    bx,255
3392
        sub    bx,255
3393
       x_add:                      ; x+
3394
        movzx  eax,byte [0xfb21]
3395
        add    bx,ax
3396
        add    bx,ax
3397
        push   ebx
3398
        mov    [0xfb00],byte 0
3399
 
3400
        ; y
3401
 
3402
 
3403
      my_event:
3404
 
3405
        mov    dl,[0xfb01]       ; y high bits
3406
        movzx  eax,dl
3407
        and    al,12
3408
        shl    al,4
3409
        mov    dl,byte[0xfb03]   ; y low bits
3410
        add    al,dl
3411
        mov    [0xfb22],byte al
3412
        movzx  ebx,word[0xfb0c]
3413
 
3414
        mov    al,byte [0xfb01]  ; + or - ?
3415
        test   al,8
3416
        je     y_add
3417
 
3418
      y_sub:                      ; y-
3419
        sub    bx,255
3420
        sub    bx,255
3421
      y_add:                      ; y+
3422
        movzx  eax,byte [0xfb22]
3423
        add    bx,ax
3424
        add    bx,ax
3425
        push   ebx
3426
        mov    [0xfb00],byte 0
3427
        jmp    mdraw
3428
 
3429
        ; end of com1 mouse
3430
 
3431
 
3432
        ; ******************************************
3433
        ; ********  PS2 MOUSE DRIVER  **************
3434
        ; ******************************************
3435
 
3436
      ps2mousefirst:
3437
 
3438
        movzx  edx,byte [0x2E0000+4096*12+0x10]   ; first ps2 ?
3439
        cmp    edx,40
3440
        jne    @f
3441
        mov    [0xfb00],byte 0  ; zero mouse block count
3442
      @@:
3443
 
3444
        movzx  ebx,byte [0xfb00]
3445
        add    ebx,1
3446
        mov    [0xfb00],bl
3447
        mov    eax,0xfb00
3448
        add    eax,ebx
3449
        mov    dl,byte [0x2E0000+4096*12+0x10]
3450
        mov    [eax],byte dl
3451
 
3452
        cmp    bl,3             ; full packet of three bytes ?
3453
        jnz    decm
3454
 
3455
        mov    [0xfb00],byte 0  ; zero mouse block count
3456
 
3457
        ; buttons
3458
 
3459
        movzx  eax,byte [0xfb01]
3460
        and    eax,3
3461
        mov    [0xfb40],al
3462
 
3463
        ; x
3464
 
3465
        movzx  eax,word [0xfb0a]
3466
        movzx  edx,byte [0xfb02]
3467
        cmp    edx,128
3468
        jb     ps2xp
3469
        shl    edx,1
3470
        add    eax,edx
3471
        cmp    eax,512
3472
        jge    ps2xsok
3473
        xor    eax, eax
3474
        jmp    ps2xready
3475
       ps2xsok:
3476
        sub    eax,512
3477
        jmp    ps2xready
3478
       ps2xp:
3479
        shl    edx,1
3480
        add    eax,edx
3481
        jmp    ps2xready
3482
       ps2xready:
3483
        push   eax
3484
 
3485
        ; y
3486
 
3487
        movzx  eax,word [0xfb0c]
3488
        movzx  edx,byte [0xfb03]
3489
        cmp    edx,128
3490
        jb     ps2yp
3491
        add    eax,512
3492
        shl    edx,1
3493
        sub    eax,edx
3494
        jmp    ps2yready
3495
       ps2yp:
3496
        shl    edx,1
3497
        cmp    edx,eax
3498
        jb     ps201
3499
        mov    edx,eax
3500
       ps201:
3501
        sub    eax,edx
3502
        jmp    ps2yready
3503
       ps2yready:
3504
        push   eax
3505
 
3506
        ;jmp    mdraw
3507
 
3508
        ; end of ps2 mouse
3509
 
3510
 
3511
        ; ****************************
3512
        ; ***** CHECK FOR LIMITS *****
3513
        ; ****************************
3514
 
3515
      mdraw:
3516
 
3517
        cmp    [0xfb44],byte 0
3518
        jne    mousedraw4
3519
        cmp    [0xfb40],byte 0
3520
        je     mousedraw4
3521
        mov    [0xfff5],byte 1
3522
 
3523
      mousedraw4:
3524
 
3525
        pop    ebx
3526
        pop    eax
3527
 
3528
        mov    [mouse_active],1
3529
 
3530
;        mov    dx,0                   ; smaller than zero
3531
        xor    dx,dx
3532
        cmp    bx,dx
3533
        jge    mnb11
3534
;        mov    bx,0
3535
        xor    bx,bx
3536
      mnb11:
3537
        mov    [0xfb0c],word bx
3538
 
3539
;        mov    dx,0
3540
        xor    dx,dx
3541
        cmp    ax,dx
3542
        jge    mnb22
3543
;        mov    ax,0
3544
        xor    ax,ax
3545
      mnb22:
3546
        mov    [0xfb0a],word ax
3547
 
3548
        mov    edx,[0xfe04]           ; bigger than maximum
3549
        cmp    ebx,edx
3550
        jb     mnb1
3551
        mov    bx,[0xfe04]
3552
      mnb1:
3553
        mov    [0xfb0c],word bx
3554
 
3555
        mov    edx,[0xfe00]
3556
        cmp    eax,edx
3557
        jb     mnb2
3558
        mov    ax,[0xfe00]
3559
      mnb2:
3560
        mov    [0xfb0a],word ax
3561
 
3562
 
3563
        ; ****   NEXT DATA BYTE FROM MOUSE BUFFER   ****
3564
 
3565
      decm:
3566
 
3567
        mov    edi,[mousecount]         ; decrease counter
3568
        dec    dword [edi]
3569
 
3570
        mov    esi,[mousedata]
3571
        mov    edi,esi
3572
        inc    esi
3573
;        mov    ecx,250
3574
        mov    ecx,[mousecount]
3575
        mov    ecx,[ecx]
3576
        cld
3577
        rep    movsb
3578
 
3579
        jmp    uusicheckmouse
3580
 
3581
      checkmouseret:
3582
 
3583
        cmp    [0xfb44],byte 0
3584
        jne    cmret
3585
 
3586
        cmp    [0xfb40],byte 0
3587
        je     cmret
3588
 
3589
        mov    [0xfff4],byte 0
3590
        mov    [0xfff5],byte 0
3591
 
3592
      cmret:
3593
 
3594
        popad
3595
 
3596
        ret
3597
 
3598
 
3599
draw_mouse_under:
3600
 
3601
        ; return old picture
3602
;        cli
3603
 
3604
        pushad
3605
 
3606
        xor    ecx,ecx
3607
        xor    edx,edx
3608
 
3609
        ;cli    ; !!!****
3610
        align  4
3611
      mres:
3612
 
3613
        movzx  eax,word [0xfb4a]
3614
        movzx  ebx,word [0xfb4c]
3615
 
3616
        add    eax,ecx
3617
        add    ebx,edx
3618
 
3619
        push   ecx
3620
        push   edx
3621
        push   eax
3622
        push   ebx
3623
 
3624
        mov    eax,edx
3625
        shl    eax,6
3626
        shl    ecx,2
3627
        add    eax,ecx
3628
        add    eax,mouseunder
3629
        mov    ecx,[eax]
3630
 
3631
        pop    ebx
3632
        pop    eax
3633
 
3634
        ;;;push   edi
3635
        mov    edi,1 ;force
3636
        call   [putpixel]
3637
        ;;;pop    edi
3638
 
3639
        pop    edx
3640
        pop    ecx
3641
 
3642
        inc    ecx
3643
        cmp    ecx, 16
3644
        jnz    mres
3645
        xor    ecx, ecx
3646
        inc    edx
3647
        cmp    edx, 24
3648
        jnz    mres
3649
        ;sti    ; !!!****
3650
 
3651
        popad
3652
 
3653
;        sti
3654
 
3655
        ret
3656
 
3657
 
3658
save_draw_mouse:
3659
 
3660
        ; save & draw
3661
;        cli
3662
 
3663
        mov    [0xfb4a],ax
3664
        mov    [0xfb4c],bx
3665
        push   eax
3666
        push   ebx
3667
        mov    ecx,0
3668
        mov    edx,0
3669
 
3670
        ;cli ; !!!****
3671
 
3672
      drm:
3673
 
3674
        push   eax
3675
        push   ebx
3676
        push   ecx
3677
        push   edx
3678
 
3679
        ; helloworld
3680
        push   eax ebx ecx
3681
        add    eax,ecx  ; save picture under mouse
3682
        add    ebx,edx
3683
        push   ecx
3684
        call   getpixel
3685
        mov    [0xfb30],ecx
3686
        pop    ecx
3687
        mov    eax,edx
3688
        shl    eax,6
3689
        shl    ecx,2
3690
        add    eax,ecx
3691
        add    eax,mouseunder
3692
        mov    ebx,[0xfb30]
3693
        mov    [eax],ebx
3694
        pop    ecx ebx eax
3695
 
3696
        mov    edi,edx       ; y cycle
3697
        shl    edi,4       ; *16 bytes per row
3698
        add    edi,ecx       ; x cycle
3699
        mov    esi, edi
3700
        add    edi, esi
3701
        add    edi, esi       ; *3
3702
        add    edi,[0xf200]      ; we have our str address
3703
        mov    esi, edi
3704
        add    esi, 16*24*3
3705
        push   ecx
3706
        mov    ecx, [0xfb30]
3707
        call   combine_colors
3708
        mov    [0xfb10], ecx
3709
        pop    ecx
3710
 
3711
 
3712
        pop    edx
3713
        pop    ecx
3714
        pop    ebx
3715
        pop    eax
3716
 
3717
        add    eax,ecx       ; we have x coord+cycle
3718
        add    ebx,edx       ; and y coord+cycle
3719
 
3720
        push   ecx edi
3721
        mov    ecx, [0xfb10]
3722
        mov    edi, 1
3723
        call   [putpixel]
3724
        pop    edi ecx
3725
 
3726
      mnext:
3727
 
3728
        mov    ebx,[esp+0]      ; pure y coord again
3729
        mov    eax,[esp+4]      ; and x
3730
 
3731
        inc    ecx          ; +1 cycle
3732
        cmp    ecx,16       ; if more than 16
3733
        jnz    drm
3734
        xor    ecx, ecx
3735
        inc    edx
3736
        cmp    edx,24
3737
        jnz    drm
3738
 
3739
        pop    ebx
3740
        pop    eax
3741
 
3742
;        sti ; !!!****
3743
 
3744
        ret
3745
 
3746
 
3747
combine_colors:
3748
 
3749
      ; in
3750
      ; ecx - color ( 00 RR GG BB )
3751
      ; edi - ref to new color byte
3752
      ; esi - ref to alpha byte
3753
      ;
3754
      ; out
3755
      ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
3756
 
3757
      push eax
3758
      push ebx
3759
      push edx
3760
      push ecx
3761
      xor ecx, ecx
3762
         ; byte 2
3763
      mov eax, 0xff
3764
      sub al, [esi+0]
3765
      mov ebx, [esp]
3766
      shr ebx, 16
3767
      and ebx, 0xff
3768
      mul ebx
3769
      shr eax, 8
3770
      add ecx, eax
3771
;      xor eax, eax
3772
;      xor ebx, ebx
3773
;      mov al, [edi+0]
3774
;      mov bl, [esi+0]
3775
    movzx eax, byte [edi+0]
3776
    movzx ebx, byte [esi+0]
3777
      mul ebx
3778
      shr eax, 8
3779
      add ecx, eax
3780
      shl ecx, 8
3781
         ; byte 1
3782
      mov eax, 0xff
3783
      sub al, [esi+1]
3784
      mov ebx, [esp]
3785
      shr ebx, 8
3786
      and ebx, 0xff
3787
      mul ebx
3788
      shr eax, 8
3789
      add ecx, eax
3790
;      xor eax, eax
3791
;      xor ebx, ebx
3792
;      mov al, [edi+1]
3793
;      mov bl, [esi+1]
3794
    movzx eax, byte [edi+1]
3795
    movzx ebx, byte [esi+1]
3796
      mul ebx
3797
      shr eax, 8
3798
      add ecx, eax
3799
      shl ecx, 8
3800
         ; byte 2
3801
      mov eax, 0xff
3802
      sub al, [esi+2]
3803
      mov ebx, [esp]
3804
      and ebx, 0xff
3805
      mul ebx
3806
      shr eax, 8
3807
      add ecx, eax
3808
;      xor eax, eax
3809
;      xor ebx, ebx
3810
;      mov al, [edi+2]
3811
;      mov bl, [esi+2]
3812
    movzx eax, byte [edi+2]
3813
    movzx ebx, byte [esi+2]
3814
      mul ebx
3815
      shr eax, 8
3816
      add ecx, eax
3817
 
3818
      pop eax
3819
      pop edx
3820
      pop ebx
3821
      pop eax
3822
      ret
3823
 
3824
 
3825
__sys_disable_mouse:
3826
 
3827
      pushad
3828
 
3829
      cmp  [0x3000],dword 1
3830
      je   disable_m
3831
 
3832
      mov  edx,[0x3000]
3833
      shl  edx,5
3834
      add  edx,window_data
3835
 
3836
      movzx  eax, word [0xfb0a]
3837
      movzx  ebx, word [0xfb0c]
3838
 
3839
      mov  ecx,[0xfe00]
3840
      inc  ecx
3841
      imul  ecx,ebx
3842
      add  ecx,eax
3843
      add  ecx, display_data
3844
 
3845
      movzx eax, byte [edx+twdw+0xe]
3846
 
3847
      movzx ebx, byte [ecx]
3848
      cmp   eax,ebx
3849
      je    yes_mouse_disable
3850
      movzx ebx, byte [ecx+16]
3851
      cmp   eax,ebx
3852
      je    yes_mouse_disable
3853
 
3854
      mov   ebx,[0xfe00]
3855
      inc   ebx
3856
      imul  ebx,10
3857
      add   ecx,ebx
3858
 
3859
      movzx ebx, byte [ecx]
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
      movzx ebx, byte [ecx+16]
3872
      cmp   eax,ebx
3873
      je    yes_mouse_disable
3874
 
3875
      jmp   no_mouse_disable
3876
 
3877
    yes_mouse_disable:
3878
 
3879
      mov  edx,[0x3000]
3880
      shl  edx,5
3881
      add  edx,window_data
3882
 
3883
      movzx  eax, word [0xfb0a]
3884
      movzx  ebx, word [0xfb0c]
3885
 
3886
      mov  ecx,[edx+0]   ; mouse inside the area ?
3887
      add  eax,14
3888
      cmp  eax,ecx
3889
      jb   no_mouse_disable
3890
      sub  eax,14
3891
 
3892
      add  ecx,[edx+8]
3893
      cmp  eax,ecx
3894
      jg   no_mouse_disable
3895
 
3896
      mov  ecx,[edx+4]
3897
      add  ebx,20
3898
      cmp  ebx,ecx
3899
      jb   no_mouse_disable
3900
      sub  ebx,20
3901
 
3902
      add  ecx,[edx+12]
3903
      cmp  ebx,ecx
3904
      jg   no_mouse_disable
3905
 
3906
    disable_m:
3907
 
3908
      cmp  dword [0xf204],dword 0
3909
      jne  @f
3910
      call draw_mouse_under
3911
    @@:
3912
 
3913
      mov  [0xf204],dword 1
3914
 
3915
    no_mouse_disable:
3916
 
3917
      popad
3918
 
3919
      ret
3920
 
3921
 
3922
 
3923
__sys_draw_pointer:
3924
        cli
3925
 
3926
        pushad
3927
 
3928
        cmp    dword [0xf204],dword 0  ; mouse visible ?
3929
        je     chms00
3930
 
3931
        dec    dword [0xf204]
3932
 
3933
        cmp    [0xf204],dword 0
3934
        jnz    nodmu2
3935
 
3936
        movzx  ebx,word [0xfb0c]
3937
        movzx  eax,word [0xfb0a]
3938
        call   save_draw_mouse
3939
 
3940
        popad
3941
        sti
3942
        ret
3943
 
3944
      nodmu2:
3945
 
3946
        popad
3947
        sti
3948
        ret
3949
 
3950
      chms00:
3951
 
3952
;        popad
3953
 
3954
;        pushad
3955
 
3956
;        cmp   [0xf204],dword 0
3957
;        jne   nodmp
3958
 
3959
        movzx  ecx,word [0xfb4a]
3960
        movzx  edx,word [0xfb4c]
3961
 
3962
        movzx  ebx,word [0xfb0c]
3963
        movzx  eax,word [0xfb0a]
3964
 
3965
        cmp    eax,ecx
3966
        jne    redrawmouse
3967
 
3968
        cmp    ebx,edx
3969
        jne    redrawmouse
3970
 
3971
        jmp    nodmp
3972
 
3973
      redrawmouse:
3974
 
3975
 
3976
        call   draw_mouse_under
3977
redrawmouse_1:
3978
        call   save_draw_mouse
3979
 
3980
     nodmp:
3981
 
3982
        popad
3983
        sti
3984
        ret
3985
 
3986
 
3987
 
3988
calculatebackground:   ; background
3989
 
3990
        ; all black
3991
 
3992
        mov   [display_data-8],dword 4      ; size x
3993
        mov   [display_data-4],dword 2      ; size y
3994
 
3995
        mov   edi, 0x300000                 ; set background to black
3996
        xor   eax, eax
3997
        mov   ecx, 0x0fff00 / 4
3998
        cld
3999
        rep   stosd
4000
 
4001
        mov   edi,display_data              ; set os to use all pixels
4002
        mov   eax,0x01010101
4003
        mov   ecx,0x1fff00 / 4
4004
        rep   stosd
4005
 
4006
        mov   byte [0xFFF0], 0              ; do not draw background!
4007
 
4008
        ret
4009
 
4010
uglobal
4011
  imax    dd 0x0
4012
endg
4013
 
4014
 
4015
 
4016
delay_ms:     ; delay in 1/1000 sec
4017
 
4018
 
4019
        push  eax
4020
        push  ecx
4021
 
4022
        mov   ecx,esi
4023
        ; 
4024
        imul  ecx, 33941
4025
        shr   ecx, 9
4026
        ; 
4027
 
4028
        in    al,0x61
4029
        and   al,0x10
4030
        mov   ah,al
4031
        cld
4032
 
4033
 cnt1:  in    al,0x61
4034
        and   al,0x10
4035
        cmp   al,ah
4036
        jz    cnt1
4037
 
4038
        mov   ah,al
4039
        loop  cnt1
4040
 
4041
        pop   ecx
4042
        pop   eax
4043
 
4044
        ret
4045
 
4046
 
4047
set_app_param:
4048
        push edi
4049
 
4050
        mov  edi,[0x3010]
4051
        mov  [edi],eax
4052
 
4053
        pop  edi
4054
        ret
4055
 
4056
 
4057
 
4058
delay_hs:     ; delay in 1/100 secs
4059
        push  eax
4060
        push  ecx
4061
        push  edx
4062
 
4063
        mov   edx,[timer_ticks];[0xfdf0]
4064
        add   edx,eax
4065
 
4066
      newtic:
4067
        mov   ecx,[timer_ticks];[0xfdf0]
4068
        cmp   edx,ecx
4069
        jbe   zerodelay
4070
 
4071
        call  change_task
4072
 
4073
        jmp   newtic
4074
 
4075
      zerodelay:
4076
        pop   edx
4077
        pop   ecx
4078
        pop   eax
4079
 
4080
        ret
4081
 
4082
 
4083
memmove:       ; memory move in bytes
4084
 
4085
; eax = from
4086
; ebx = to
4087
; ecx = no of bytes
4088
    test ecx, ecx
4089
    jle  .ret
4090
 
4091
 
4092
    push esi edi ecx
4093
 
4094
    mov  edi, ebx
4095
    mov  esi, eax
4096
 
4097
    test ecx, not 11b
4098
    jz   @f
4099
 
4100
    push ecx
4101
    shr  ecx, 2
4102
    rep  movsd
4103
    pop  ecx
4104
    and  ecx, 11b
4105
    jz   .finish
4106
  @@:
4107
    rep  movsb
4108
 
4109
  .finish:
4110
    pop  ecx edi esi
4111
  .ret:
4112
    ret
4113
 
4114
 
4115
align 4
4116
 
4117
read_floppy_file:
4118
 
4119
; as input
4120
;
4121
; eax pointer to file
4122
; ebx file lenght
4123
; ecx start 512 byte block number
4124
; edx number of blocks to read
4125
; esi pointer to return/work area (atleast 20 000 bytes)
4126
;
4127
;
4128
; on return
4129
;
4130
; eax = 0 command succesful
4131
;       1 no fd base and/or partition defined
4132
;       2 yet unsupported FS
4133
;       3 unknown FS
4134
;       4 partition not defined at hd
4135
;       5 file not found
4136
; ebx = size of file
4137
 
4138
     mov   edi,[0x3010]
4139
     add   edi,0x10
4140
     add   esi,[edi]
4141
     add   eax,[edi]
4142
 
4143
     pushad
4144
     mov  edi,esi
4145
     add  edi,1024
4146
     mov  esi,0x100000+19*512
4147
     sub  ecx,1
4148
     shl  ecx,9
4149
     add  esi,ecx
4150
     shl  edx,9
4151
     mov  ecx,edx
4152
     cld
4153
     rep  movsb
4154
     popad
4155
 
4156
     mov   [esp+36],eax
4157
     mov   [esp+24],ebx
4158
     ret
4159
 
4160
 
4161
 
4162
align 4
4163
 
4164
sys_programirq:
4165
 
4166
    mov   edi,[0x3010]
4167
    add   edi,0x10
4168
    add   eax,[edi]
4169
 
4170
    mov   edx,ebx
4171
    shl   edx,2
4172
    add   edx,irq_owner
4173
    mov   edx,[edx]
4174
    mov   edi,[0x3010]
4175
    mov   edi,[edi+0x4]
4176
    cmp   edx,edi
4177
    je    spril1
4178
    mov   [esp+36],dword 1
4179
    ret
4180
  spril1:
4181
 
4182
    mov   esi,eax
4183
    shl   ebx,6
4184
    add   ebx,irq00read
4185
    mov   edi,ebx
4186
    mov   ecx,16
4187
    cld
4188
    rep   movsd
4189
    mov   [esp+36],dword 0
4190
    ret
4191
 
4192
 
4193
align 4
4194
 
4195
get_irq_data:
4196
 
4197
     mov   edx,eax           ; check for correct owner
4198
     shl   edx,2
4199
     add   edx,irq_owner
4200
     mov   edx,[edx]
4201
     mov   edi,[0x3010]
4202
     mov   edi,[edi+0x4]
4203
     cmp   edx,edi
4204
     je    gidril1
4205
     mov   [esp+36],eax
4206
     mov   [esp+32],dword 2
4207
     mov   [esp+24],ebx
4208
     ret
4209
 
4210
  gidril1:
4211
 
4212
     mov   ebx,eax
4213
     shl   ebx,12
4214
     add   ebx,0x2e0000
4215
     mov   eax,[ebx]
4216
     mov   ecx,1
4217
     test  eax,eax
4218
     jz    gid1
4219
 
4220
     dec   eax
4221
     mov   esi,ebx
4222
     mov   [ebx],eax
4223
     movzx ebx,byte [ebx+0x10]
4224
     add   esi,0x10
4225
     mov   edi,esi
4226
     inc   esi
4227
     mov   ecx,4000 / 4
4228
     cld
4229
     rep   movsd
4230
     xor   ecx,ecx
4231
   gid1:
4232
     mov   [esp+36],eax
4233
     mov   [esp+32],ecx
4234
     mov   [esp+24],ebx
4235
     ret
4236
 
4237
 
4238
set_io_access_rights:
4239
 
4240
     pushad
4241
 
4242
     mov   edi,[0x3000]
4243
     imul  edi,tss_step
4244
     add   edi,tss_data+128
4245
;     add   edi,128
4246
 
4247
     mov   ecx,eax
4248
     and   ecx,7    ; offset in byte
4249
 
4250
     shr   eax,3    ; number of byte
4251
     add   edi,eax
4252
 
4253
     mov   ebx,1
4254
     shl   ebx,cl
4255
 
4256
     cmp   ebp,0                ; enable access - ebp = 0
4257
     jne   siar1
4258
 
4259
     not   ebx
4260
     and   [edi],byte bl
4261
 
4262
     popad
4263
 
4264
     ret
4265
 
4266
   siar1:
4267
 
4268
     or    [edi],byte bl        ; disable access - ebp = 1
4269
 
4270
     popad
4271
 
4272
     ret
4273
 
4274
 
4275
 
4276
 
4277
 
4278
r_f_port_area:
4279
 
4280
     test  eax, eax
4281
     jnz   free_port_area
4282
;     je    r_port_area
4283
;     jmp   free_port_area
4284
 
4285
;   r_port_area:
4286
 
4287
     pushad
4288
 
4289
     cmp   ebx,ecx            ; beginning > end ?
4290
     jg    rpal1
4291
     mov   esi,[0x2d0000]
4292
     cmp   esi,0              ; no reserved areas ?
4293
     je    rpal2
4294
     cmp   esi,255            ; max reserved
4295
     jge   rpal1
4296
   rpal3:
4297
     mov   edi,esi
4298
     shl   edi,4
4299
     add   edi,0x2d0000
4300
     cmp   ebx,[edi+8]
4301
     jg    rpal4
4302
     cmp   ecx,[edi+4]
4303
     jae   rpal1
4304
;     jb    rpal4
4305
;     jmp   rpal1
4306
   rpal4:
4307
 
4308
     dec   esi
4309
     jnz   rpal3
4310
     jmp   rpal2
4311
   rpal1:
4312
     popad
4313
     mov   eax,1
4314
     ret
4315
 
4316
   rpal2:
4317
     popad
4318
 
4319
 
4320
     ; enable port access at port IO map
4321
     cli
4322
     pushad                        ; start enable io map
4323
 
4324
     cmp   ecx,65536 ;16384
4325
     jae   no_unmask_io ; jge
4326
 
4327
     mov   eax,ebx
4328
 
4329
   new_port_access:
4330
 
4331
     pushad
4332
 
4333
     mov   ebp,0                  ; enable - eax = port
4334
     call  set_io_access_rights
4335
 
4336
     popad
4337
 
4338
     inc   eax
4339
     cmp   eax,ecx
4340
     jbe   new_port_access
4341
 
4342
   no_unmask_io:
4343
 
4344
     popad                         ; end enable io map
4345
     sti
4346
 
4347
     mov   edi,[0x2d0000]
4348
     add   edi,1
4349
     mov   [0x2d0000],edi
4350
     shl   edi,4
4351
     add   edi,0x2d0000
4352
     mov   esi,[0x3010]
4353
     mov   esi,[esi+0x4]
4354
     mov   [edi],esi
4355
     mov   [edi+4],ebx
4356
     mov   [edi+8],ecx
4357
 
4358
     xor   eax, eax
4359
     ret
4360
 
4361
 
4362
 
4363
 
4364
free_port_area:
4365
 
4366
     pushad
4367
 
4368
     mov   esi,[0x2d0000]     ; no reserved areas ?
4369
     cmp   esi,0
4370
     je    frpal2
4371
     mov   edx,[0x3010]
4372
     mov   edx,[edx+4]
4373
   frpal3:
4374
     mov   edi,esi
4375
     shl   edi,4
4376
     add   edi,0x2d0000
4377
     cmp   edx,[edi]
4378
     jne   frpal4
4379
     cmp   ebx,[edi+4]
4380
     jne   frpal4
4381
     cmp   ecx,[edi+8]
4382
     jne   frpal4
4383
     jmp   frpal1
4384
   frpal4:
4385
     dec   esi
4386
     jnz   frpal3
4387
   frpal2:
4388
     popad
4389
     mov   eax,1
4390
     ret
4391
   frpal1:
4392
     mov   ecx,256
4393
     sub   ecx,esi
4394
     shl   ecx,4
4395
     mov   esi,edi
4396
     add   esi,16
4397
     cld
4398
     rep   movsb
4399
 
4400
     dec   dword [0x2d0000]
4401
 
4402
     popad
4403
 
4404
 
4405
     ; disable port access at port IO map
4406
 
4407
     pushad                        ; start disable io map
4408
 
4409
     cmp   ecx,65536 ;16384
4410
     jge   no_mask_io
4411
 
4412
     mov   eax,ebx
4413
 
4414
   new_port_access_disable:
4415
 
4416
     pushad
4417
 
4418
     mov   ebp,1                  ; disable - eax = port
4419
     call  set_io_access_rights
4420
 
4421
     popad
4422
 
4423
     inc   eax
4424
     cmp   eax,ecx
4425
     jbe   new_port_access_disable
4426
 
4427
   no_mask_io:
4428
 
4429
     popad                         ; end disable io map
4430
 
4431
     xor   eax, eax
4432
     ret
4433
 
4434
 
4435
reserve_free_irq:
4436
 
4437
     cmp   eax,0
4438
     jz    reserve_irq
4439
 
4440
     mov   edi,ebx
4441
     shl   edi,2
4442
     add   edi,irq_owner
4443
     mov   edx,[edi]
4444
     mov   eax,[0x3010]
4445
     mov   eax,[eax+0x4]
4446
     mov   ecx,1
4447
     cmp   edx,eax
4448
     jne   fril1
4449
     mov   [edi],dword 0
4450
     mov   ecx,0
4451
   fril1:
4452
     mov   [esp+36],ecx ; return in eax
4453
     ret
4454
 
4455
  reserve_irq:
4456
 
4457
     mov   edi,ebx
4458
     shl   edi,2
4459
     add   edi,irq_owner
4460
     mov   edx,[edi]
4461
     mov   ecx,1
4462
     cmp   edx,0
4463
     jne   ril1
4464
 
4465
     mov   edx,[0x3010]
4466
     mov   edx,[edx+0x4]
4467
     mov   [edi],edx
4468
     mov   ecx,0
4469
 
4470
   ril1:
4471
 
4472
     mov   [esp+36],ecx ; return in eax
4473
 
4474
     ret
4475
 
4476
 
4477
 
4478
drawbackground:
4479
 
4480
       cmp   [0xfe0c],word 0x12
4481
       jne   dbrv12
4482
       cmp   [display_data-12],dword 1
4483
       jne   bgrstr12
4484
       call  vga_drawbackground_tiled
4485
       ret
4486
     bgrstr12:
4487
       call  vga_drawbackground_stretch
4488
       ret
4489
     dbrv12:
4490
 
4491
       cmp  [0xfe0c],word 0100000000000000b
4492
       jge  dbrv20
4493
       cmp  [0xfe0c],word 0x13
4494
       je   dbrv20
4495
       call  vesa12_drawbackground
4496
       ret
4497
     dbrv20:
4498
       cmp   [display_data-12],dword 1
4499
       jne   bgrstr
4500
       call  vesa20_drawbackground_tiled
4501
       ret
4502
     bgrstr:
4503
       call  vesa20_drawbackground_stretch
4504
       ret
4505
 
4506
 
4507
sys_putimage:
4508
 
4509
     cmp   [0xfe0c],word 0x12
4510
     jne   spiv20
4511
     call  vga_putimage
4512
     ret
4513
   spiv20:
4514
 
4515
     cmp   [0xfe0c],word 0100000000000000b
4516
     jge   piv20
4517
     cmp   [0xfe0c],word 0x13
4518
     je    piv20
4519
     call  vesa12_putimage
4520
     ret
4521
   piv20:
4522
     call  vesa20_putimage
4523
     ret
4524
 
4525
 
4526
 
4527
; eax x beginning
4528
; ebx y beginning
4529
; ecx x end
4530
; edx y end
4531
; edi color
4532
 
4533
__sys_drawbar:
4534
 
4535
     cmp   [0xfe0c],word 0x12
4536
     jne   sdbv20
4537
     call  vga_drawbar
4538
     ret
4539
   sdbv20:
4540
 
4541
    cmp  [0xfe0c],word 0100000000000000b
4542
    jge  dbv20
4543
    cmp  [0xfe0c],word 0x13
4544
    je   dbv20
4545
    call vesa12_drawbar
4546
    ret
4547
 
4548
  dbv20:
4549
 
4550
    call vesa20_drawbar
4551
    ret
4552
 
4553
 
4554
 
4555
kb_read:
4556
 
4557
        push    ecx edx
4558
 
4559
        mov     ecx,0xffff
4560
      kr_loop:
4561
        in      al,0x64
4562
        test    al,1
4563
        jnz     kr_ready
4564
        loop    kr_loop
4565
        mov     ah,1
4566
        jmp     kr_exit
4567
      kr_ready:
4568
        push    ecx
4569
        mov     ecx,32
4570
      kr_delay:
4571
        loop    kr_delay
4572
        pop     ecx
4573
        in      al,0x60
4574
        xor     ah,ah
4575
      kr_exit:
4576
 
4577
        pop     edx ecx
4578
 
4579
        ret
4580
 
4581
 
4582
kb_write:
4583
 
4584
        push    ecx edx
4585
 
4586
        mov     dl,al
4587
        mov     ecx,0xffff
4588
      kw_loop1:
4589
        in      al,0x64
4590
        test    al,0x20
4591
        jz      kw_ok1
4592
        loop    kw_loop1
4593
        mov     ah,1
4594
        jmp     kw_exit
4595
      kw_ok1:
4596
        in      al,0x60
4597
        mov     ecx,0xffff
4598
      kw_loop:
4599
        in      al,0x64
4600
        test    al,2
4601
        jz      kw_ok
4602
        loop    kw_loop
4603
        mov     ah,1
4604
        jmp     kw_exit
4605
      kw_ok:
4606
        mov     al,dl
4607
        out     0x60,al
4608
        mov     ecx,0xffff
4609
      kw_loop3:
4610
        in      al,0x64
4611
        test    al,2
4612
        jz      kw_ok3
4613
        loop    kw_loop3
4614
        mov     ah,1
4615
        jmp     kw_exit
4616
      kw_ok3:
4617
        mov     ah,8
4618
      kw_loop4:
4619
        mov     ecx,0xffff
4620
      kw_loop5:
4621
        in      al,0x64
4622
        test    al,1
4623
        jnz     kw_ok4
4624
        loop    kw_loop5
4625
        dec     ah
4626
        jnz     kw_loop4
4627
      kw_ok4:
4628
        xor     ah,ah
4629
      kw_exit:
4630
 
4631
        pop     edx ecx
4632
 
4633
        ret
4634
 
4635
 
4636
kb_cmd:
4637
 
4638
        mov     ecx,0xffff
4639
      c_wait:
4640
        in      al,0x64
4641
        test    al,2
4642
        jz      c_send
4643
        loop    c_wait
4644
        jmp     c_error
4645
      c_send:
4646
        mov     al,bl
4647
        out     0x64,al
4648
        mov     ecx,0xffff
4649
      c_accept:
4650
        in      al,0x64
4651
        test    al,2
4652
        jz      c_ok
4653
        loop    c_accept
4654
      c_error:
4655
        mov     ah,1
4656
        jmp     c_exit
4657
      c_ok:
4658
        xor     ah,ah
4659
      c_exit:
4660
        ret
4661
 
4662
 
4663
setmouse:  ; set mousepicture -pointer
4664
           ; ps2 mouse enable
4665
 
4666
     mov     [0xf200],dword mousepointer
4667
 
4668
     cli
4669
     mov     bl,0xa8                 ; enable mouse cmd
4670
     call    kb_cmd
4671
     call    kb_read                 ; read status
4672
 
4673
     mov     bl,0x20                 ; get command byte
4674
     call    kb_cmd
4675
     call    kb_read
4676
     or      al,3                    ; enable interrupt
4677
     mov     bl,0x60                 ; write command
4678
     push    eax
4679
     call    kb_cmd
4680
     pop     eax
4681
     call    kb_write
4682
 
4683
     mov     bl,0xd4                 ; for mouse
4684
     call    kb_cmd
4685
     mov     al,0xf4                 ; enable mouse device
4686
     call    kb_write
4687
     call    kb_read           ; read status return
4688
 
4689
     ; com1 mouse enable
4690
 
4691
     mov   bx,0x3f8 ; combase
4692
 
4693
     mov   dx,bx
4694
     add   dx,3
4695
     mov   al,0x80
4696
     out   dx,al
4697
 
4698
     mov   dx,bx
4699
     add   dx,1
4700
     mov   al,0
4701
     out   dx,al
4702
 
4703
     mov   dx,bx
4704
     add   dx,0
4705
     mov   al,0x30*2    ; 0x30 / 4
4706
     out   dx,al
4707
 
4708
     mov   dx,bx
4709
     add   dx,3
4710
     mov   al,2         ; 3
4711
     out   dx,al
4712
 
4713
     mov   dx,bx
4714
     add   dx,4
4715
     mov   al,0xb
4716
     out   dx,al
4717
 
4718
     mov   dx,bx
4719
     add   dx,1
4720
     mov   al,1
4721
     out   dx,al
4722
 
4723
 
4724
     ; com2 mouse enable
4725
 
4726
     mov   bx,0x2f8 ; combase
4727
 
4728
     mov   dx,bx
4729
     add   dx,3
4730
     mov   al,0x80
4731
     out   dx,al
4732
 
4733
     mov   dx,bx
4734
     add   dx,1
4735
     mov   al,0
4736
     out   dx,al
4737
 
4738
     mov   dx,bx
4739
     add   dx,0
4740
     mov   al,0x30*2
4741
     out   dx,al
4742
 
4743
     mov   dx,bx
4744
     add   dx,3
4745
     mov   al,2
4746
     out   dx,al
4747
 
4748
     mov   dx,bx
4749
     add   dx,4
4750
     mov   al,0xb
4751
     out   dx,al
4752
 
4753
     mov   dx,bx
4754
     add   dx,1
4755
     mov   al,1
4756
     out   dx,al
4757
 
4758
     ret
4759
 
4760
 
4761
_rdtsc:
4762
 
4763
     mov   edx,[cpuid_1+3*4]
4764
     test  edx,00010000b
4765
     jz    ret_rdtsc
4766
     rdtsc
4767
     ret
4768
   ret_rdtsc:
4769
     mov   edx,0xffffffff
4770
     mov   eax,0xffffffff
4771
     ret
4772
 
4773
 
4774
 
4775
rerouteirqs:
4776
 
4777
        cli
4778
 
4779
        mov     al,0x11         ;  icw4, edge triggered
4780
        out     0x20,al
4781
        call    pic_delay
4782
        out     0xA0,al
4783
        call    pic_delay
4784
 
4785
        mov     al,0x20         ;  generate 0x20 +
4786
        out     0x21,al
4787
        call    pic_delay
4788
        mov     al,0x28         ;  generate 0x28 +
4789
        out     0xA1,al
4790
        call    pic_delay
4791
 
4792
        mov     al,0x04         ;  slave at irq2
4793
        out     0x21,al
4794
        call    pic_delay
4795
        mov     al,0x02         ;  at irq9
4796
        out     0xA1,al
4797
        call    pic_delay
4798
 
4799
        mov     al,0x01         ;  8086 mode
4800
        out     0x21,al
4801
        call    pic_delay
4802
        out     0xA1,al
4803
        call    pic_delay
4804
 
4805
        mov     al,255          ; mask all irq's
4806
        out     0xA1,al
4807
        call    pic_delay
4808
        out     0x21,al
4809
        call    pic_delay
4810
 
4811
        mov     ecx,0x1000
4812
        cld
4813
picl1:  call    pic_delay
4814
        loop    picl1
4815
 
4816
        mov     al,255          ; mask all irq's
4817
        out     0xA1,al
4818
        call    pic_delay
4819
        out     0x21,al
4820
        call    pic_delay
4821
 
4822
        cli
4823
 
4824
        ret
4825
 
4826
 
4827
pic_delay:
4828
 
4829
        jmp     pdl1
4830
pdl1:   ret
4831
 
4832
 
4833
sys_msg_board_str:
4834
 
4835
     pushad
4836
   @@:
4837
     cmp    [esi],byte 0
4838
     je     @f
4839
     mov    eax,1
4840
     movzx  ebx,byte [esi]
4841
     call   sys_msg_board
4842
     inc    esi
4843
     jmp    @b
4844
   @@:
4845
     popad
4846
     ret
4847
 
4848
uglobal
4849
  msg_board_data: times 512 db 0
4850
  msg_board_count dd 0x0
4851
endg
4852
 
4853
sys_msg_board:
4854
 
4855
; eax=1 : write :  bl byte to write
4856
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4857
 
4858
     mov  ecx,[msg_board_count]
4859
     cmp  eax, 1
4860
     jne  smbl1
4861
 
4862
 
4863
     mov  [msg_board_data+ecx],bl
4864
     inc  ecx
4865
     and  ecx, 511
4866
     mov  [msg_board_count], ecx
4867
     mov  [check_idle_semaphore], 5
4868
     ret
4869
   smbl1:
4870
 
4871
     cmp   eax, 2
4872
     jne   smbl2
4873
     test  ecx, ecx
4874
     jz    smbl21
4875
;     mov   edi, msg_board_data
4876
;     mov   esi, msg_board_data+1
4877
;     movzx eax, byte [edi]
4878
     mov   eax, msg_board_data+1
4879
     mov   ebx, msg_board_data
4880
     movzx edx, byte [ebx]
4881
     call  memmove
4882
;     push  ecx
4883
;     shr   ecx, 2
4884
;     cld
4885
;     rep   movsd
4886
;     pop   ecx
4887
;     and   ecx, 3
4888
;     rep   movsb
4889
     dec   [msg_board_count]
4890
     mov   [esp+36], edx ;eax
4891
     mov   [esp+24], dword 1
4892
     ret
4893
   smbl21:
4894
     mov   [esp+36], ecx
4895
     mov   [esp+24], ecx
4896
 
4897
   smbl2:
4898
     ret
4899
 
4900
 
4901
 
4902
sys_trace:
4903
 
4904
     test eax, eax                  ; get event data
4905
     jnz  no_get_sys_events
4906
 
4907
     mov  esi,save_syscall_data     ; data
4908
     mov  edi,[0x3010]
4909
     mov  edi,[edi+0x10]
4910
     add  edi,ebx
4911
     cld
4912
     rep  movsb
4913
 
4914
     mov  [esp+24],dword 0
4915
     mov  eax,[save_syscall_count]  ; count
4916
     mov  [esp+36],eax
4917
     ret
4918
 
4919
   no_get_sys_events:
4920
 
4921
     ret
4922
 
4923
 
4924
sys_process_def:
4925
 
4926
     cmp   eax,1                   ; set keyboard mode
4927
     jne   no_set_keyboard_setup
4928
 
4929
     mov   edi,[0x3000]
4930
     shl   edi,8
4931
     add   edi,0x80000+0xB4
4932
     mov   [edi],bl
4933
 
4934
     ret
4935
 
4936
   no_set_keyboard_setup:
4937
 
4938
     cmp   eax,2                   ; get keyboard mode
4939
     jne   no_get_keyboard_setup
4940
 
4941
     mov   edi,[0x3000]
4942
     shl   edi,8
4943
     add   edi,0x80000+0xB4
4944
     movzx eax, byte [edi]
4945
 
4946
     mov   [esp+36],eax
4947
 
4948
     ret
4949
 
4950
   no_get_keyboard_setup:
4951
 
4952
     cmp   eax,3                   ; get keyboard ctrl, alt, shift
4953
     jne   no_get_keyboard_cas
4954
 
4955
;     xor   eax,eax
4956
;     movzx eax,byte [shift]
4957
;     movzx ebx,byte [ctrl]
4958
;     shl   ebx,2
4959
;     add   eax,ebx
4960
;     movzx ebx,byte [alt]
4961
;     shl   ebx,3
4962
;     add   eax,ebx
4963
 
4964
 ;// mike.dld [
4965
     mov   eax, [kb_state]
4966
 ;// mike.dld ]
4967
 
4968
     mov   [esp+36],eax
4969
 
4970
     ret
4971
 
4972
   no_get_keyboard_cas:
4973
 
4974
 
4975
     ret
4976
 
4977
 
4978
sys_ipc:
4979
     cmp  eax,1                      ; DEFINE IPC MEMORY
4980
     jne  no_ipc_def
4981
     mov  edi,[0x3000]
4982
     shl  edi,8
4983
     add  edi,0x80000
4984
     mov  [edi+0xA0],ebx
4985
     mov  [edi+0xA4],ecx
4986
     mov  [esp+36],dword 0
4987
     ret
4988
   no_ipc_def:
4989
 
4990
     cmp  eax,2                      ; SEND IPC MESSAGE
4991
     jne  no_ipc_send
4992
     mov  esi,1
4993
     mov  edi,0x3020
4994
    ipcs1:
4995
     cmp  [edi+4],ebx
4996
     je   ipcs2
4997
     add  edi,0x20
4998
     inc  esi
4999
     cmp  esi,[0x3004]
5000
     jbe  ipcs1
5001
     mov  [esp+36],dword 4
5002
     ret
5003
    ipcs2:
5004
 
5005
     cli
5006
 
5007
     push esi
5008
     mov  eax,esi
5009
     shl  eax,8
5010
     mov  ebx,[eax+0x80000+0xa0]
5011
     test ebx,ebx                  ; ipc area not defined ?
5012
     je   ipc_err1
5013
 
5014
     add  ebx,[eax+0x80000+0xa4]
5015
     mov  eax,esi
5016
     shl  eax,5
5017
     add  ebx,[eax+0x3000+0x10]    ; ebx <- max data position
5018
 
5019
     mov  eax,esi                  ; to
5020
     shl  esi,8
5021
     add  esi,0x80000
5022
     mov  edi,[esi+0xa0]
5023
     shl  eax,5
5024
     add  eax,0x3000
5025
     add  edi,[eax+0x10]
5026
 
5027
     cmp  [edi],byte 0             ; overrun ?
5028
     jne  ipc_err2
5029
 
5030
     mov  ebp,edi
5031
     add  edi,[edi+4]
5032
     add  edi,8
5033
 
5034
     mov  esi,ecx                  ; from
5035
     mov  eax,[0x3010]
5036
     mov  eax,[eax+0x10]
5037
     add  esi,eax
5038
 
5039
     mov  ecx,edx                  ; size
5040
 
5041
     mov  eax,edi
5042
     add  eax,ecx
5043
     cmp  eax,ebx
5044
     jge  ipc_err3                 ; not enough room ?
5045
 
5046
     push ecx
5047
 
5048
     mov  eax,[0x3010]
5049
     mov  eax,[eax+4]
5050
     mov  [edi-8],eax
5051
     mov  [edi-4],ecx
5052
     cld
5053
     rep  movsb
5054
 
5055
     pop  ecx
5056
     add  ecx,8
5057
 
5058
     mov  edi,ebp                  ; increase memory position
5059
     add  dword [edi+4],ecx
5060
 
5061
     mov  edi,[esp]
5062
     shl  edi,8
5063
     or   dword [edi+0x80000+0xA8],dword 01000000b ; ipc message
5064
 
5065
     cmp  [check_idle_semaphore],dword 20
5066
     jge  ipc_no_cis
5067
     mov  [check_idle_semaphore],5
5068
   ipc_no_cis:
5069
 
5070
     xor  eax, eax
5071
 
5072
    ipc_err:
5073
     add  esp,4
5074
     mov  [esp+36],eax
5075
     sti
5076
     ret
5077
 
5078
    ipc_err1:
5079
     add  esp,4
5080
     mov  [esp+36],dword 1
5081
     sti
5082
     ret
5083
    ipc_err2:
5084
     add  esp,4
5085
     mov  [esp+36],dword 2
5086
     sti
5087
     ret
5088
    ipc_err3:
5089
     add  esp,4
5090
     mov  [esp+36],dword 3
5091
     sti
5092
     ret
5093
 
5094
   no_ipc_send:
5095
 
5096
     mov  [esp+36],dword -1
5097
     ret
5098
 
5099
 
5100
align 4
5101
 
5102
sys_gs:                         ; direct screen access
5103
 
5104
     cmp  eax,1                 ; resolution
5105
     jne  no_gs1
5106
     mov  eax,[0xfe00]
5107
     shl  eax,16
5108
     mov  ax,[0xfe04]
5109
     add  eax,0x00010001
5110
     mov  [esp+36],eax
5111
     ret
5112
   no_gs1:
5113
 
5114
     cmp   eax,2                ; bits per pixel
5115
     jne   no_gs2
5116
     movzx eax,byte [0xfbf1]
5117
     mov   [esp+36],eax
5118
     ret
5119
   no_gs2:
5120
 
5121
     cmp   eax,3                ; bytes per scanline
5122
     jne   no_gs3
5123
     mov   eax,[0xfe08]
5124
     mov   [esp+36],eax
5125
     ret
5126
   no_gs3:
5127
 
5128
     mov  [esp+36],dword -1
5129
     ret
5130
 
5131
 
5132
align 4 ; PCI functions
5133
 
5134
sys_pci:
5135
 
5136
     call  pci_api
5137
     mov   [esp+36],eax
5138
     ret
5139
 
5140
 
5141
align 4  ;  system functions
5142
 
5143
syscall_setpixel:                       ; SetPixel
5144
 
5145
 
5146
     mov   edx,[0x3010]
5147
     add   eax,[edx-twdw]
5148
     add   ebx,[edx-twdw+4]
5149
     xor   edi,edi ; no force
5150
     call  [disable_mouse]
5151
     jmp   [putpixel]
5152
 
5153
align 4
5154
 
5155
syscall_writetext:                      ; WriteText
5156
 
5157
     mov   edi,[0x3010]
5158
     mov   ebp,[edi-twdw]
5159
     shl   ebp,16
5160
     add   ebp,[edi-twdw+4]
5161
     add   edi,0x10
5162
     add   ecx,[edi]
5163
     add   eax,ebp
5164
     xor   edi,edi
5165
     jmp   dtext
5166
 
5167
align 4
5168
 
5169
syscall_openramdiskfile:                ; OpenRamdiskFile
5170
 
5171
 
5172
     mov   edi,[0x3010]
5173
     add   edi,0x10
5174
     add   eax,[edi]
5175
     add   edx,[edi]
5176
     mov   esi,12
5177
     call  fileread
5178
     mov   [esp+36],ebx
5179
     ret
5180
 
5181
align 4
5182
 
5183
syscall_putimage:                       ; PutImage
5184
 
5185
     mov   edi,[0x3010]
5186
     add   edi,0x10
5187
     add   eax,[edi]
5188
     mov   edx,ecx
5189
     mov   ecx,ebx
5190
     mov   ebx,eax
5191
     call  sys_putimage
5192
     mov   [esp+36],eax
5193
     ret
5194
 
5195
align 4
5196
 
5197
syscall_drawrect:                       ; DrawRect
5198
 
5199
     mov   edi,ecx
5200
     test  ax,ax
5201
     je    drectr
5202
     test  bx,bx
5203
     je    drectr
5204
     movzx ecx,ax
5205
     shr   eax,16
5206
     movzx edx,bx
5207
     shr   ebx,16
5208
     add   ecx,eax
5209
     add   edx,ebx
5210
     jmp   [drawbar]
5211
    drectr:
5212
     ret
5213
 
5214
align 4
5215
 
5216
syscall_getscreensize:                  ; GetScreenSize
5217
 
5218
     movzx eax,word[0xfe00]
5219
     shl   eax,16
5220
     mov   ax,[0xfe04]
5221
     mov   [esp+36],eax
5222
     ret
5223
 
5224
align 4
5225
 
5226
syscall_system:                         ; System
5227
 
5228
     call  sys_system
5229
     mov   [esp+36],eax
5230
     ret
5231
 
5232
align 4
5233
 
5234
syscall_startapp:                       ; StartApp
5235
     mov   edi,[0x3010]
5236
     add   edi,0x10
5237
     add   eax,[edi]
5238
     test  ebx,ebx
5239
     jz    noapppar
5240
     add   ebx,[edi]
5241
   noapppar:
5242
;     call  start_application_fl
5243
     call   new_start_application_fl
5244
     mov   [esp+36],eax
5245
     ret
5246
 
5247
 
5248
align 4
5249
 
5250
syscall_cdaudio:                        ; CD
5251
 
5252
     call  sys_cd_audio
5253
     mov   [esp+36],eax
5254
     ret
5255
 
5256
align 4
5257
 
5258
syscall_readhd:                         ; ReadHd
5259
 
5260
     mov   edi,[0x3010]
5261
     add   edi,0x10
5262
     add   esi,[edi]
5263
     add   eax,[edi]
5264
     call  read_hd_file
5265
     mov   [esp+36],eax
5266
     mov   [esp+24],ebx
5267
     ret
5268
 
5269
align 4
5270
 
5271
syscall_starthdapp:                     ; StartHdApp
5272
 
5273
     mov   edi,[0x3010]
5274
     add   edi,0x10
5275
     add   eax,[edi]
5276
     add   ecx,[edi]
5277
     mov   ebp,0
5278
     call  start_application_hd
5279
     mov   [esp+36],eax
5280
     ret
5281
 
5282
align 4
5283
 
5284
syscall_delramdiskfile:                 ; DelRamdiskFile
5285
 
5286
     mov   edi,[0x3010]
5287
     add   edi,0x10
5288
     add   eax,[edi]
5289
     call  filedelete
5290
     mov   [esp+36],eax
5291
     ret
5292
 
5293
align 4
5294
 
5295
syscall_writeramdiskfile:               ; WriteRamdiskFile
5296
 
5297
     mov   edi,[0x3010]
5298
     add   edi,0x10
5299
     add   eax,[edi]
5300
     add   ebx,[edi]
5301
     call  filesave
5302
     mov   [esp+36],eax
5303
     ret
5304
 
5305
align 4
5306
 
5307
syscall_getpixel:                       ; GetPixel
5308
 
5309
     mov   ecx,[0xfe00]
5310
     inc   ecx
5311
     xor   edx,edx
5312
     div   ecx
5313
     mov   ebx,edx
5314
     xchg  eax,ebx
5315
     call  dword [0xe024]
5316
     mov   [esp+36],ecx
5317
     ret
5318
 
5319
align 4
5320
 
5321
syscall_readstring:                     ; ReadString
5322
 
5323
     mov   edi,[0x3010]
5324
     add   edi,0x10
5325
     add   eax,[edi]
5326
     call  read_string
5327
     mov   [esp+36],eax
5328
     ret
5329
 
5330
align 4
5331
 
5332
syscall_drawline:                       ; DrawLine
5333
 
5334
     mov   edi,[0x3010]
5335
     movzx edx,word[edi-twdw]
5336
     mov   ebp,edx
5337
     shl   edx,16
5338
     add   ebp,edx
5339
     movzx edx,word[edi-twdw+4]
5340
     add   eax,ebp
5341
     mov   ebp,edx
5342
     shl   edx,16
5343
     xor   edi,edi
5344
     add   edx,ebp
5345
     add   ebx,edx
5346
     jmp   [draw_line]
5347
 
5348
align 4
5349
 
5350
syscall_getirqowner:                    ; GetIrqOwner
5351
 
5352
     shl   eax,2
5353
     add   eax,irq_owner
5354
     mov   eax,[eax]
5355
     mov   [esp+36],eax
5356
     ret
5357
 
5358
align 4
5359
 
5360
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5361
 
5362
     call  r_f_port_area
5363
     mov   [esp+36],eax
5364
     ret
5365
 
14 poddubny 5366
;align 4
1 ha 5367
 
5368
syscall_appints:                        ; AppInts
14 poddubny 5369
;    mov   [esp+36],dword -1
1 ha 5370
     ret
5371
 
5372
align 4
5373
 
5374
syscall_threads:                        ; CreateThreads
5375
 
5376
     call  sys_threads
5377
     mov   [esp+36],eax
5378
     ret
5379
 
5380
align 4
5381
 
5382
stack_driver_stat:
5383
 
5384
     call  app_stack_handler            ; Stack status
5385
 
5386
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5387
;     call  change_task                 ; between sent packet
5388
 
5389
     mov   [esp+36],eax
5390
     ret
5391
 
5392
align 4
5393
 
5394
socket:                                 ; Socket interface
5395
     call  app_socket_handler
5396
 
5397
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5398
;     call  change_task                 ; between sent packet
5399
 
5400
     mov   [esp+36],eax
5401
     mov   [esp+24],ebx
5402
     ret
5403
 
5404
align 4
5405
 
5406
user_events:                            ; User event times
5407
 
5408
     mov   eax,0x12345678
5409
     mov   [esp+36],eax
5410
 
5411
     ret
5412
 
5413
align 4
5414
 
5415
read_from_hd:                           ; Read from hd - fn not in use
5416
 
5417
     mov   edi,[0x3010]
5418
     add   edi,0x10
5419
     add   eax,[edi]
5420
     add   ecx,[edi]
5421
     add   edx,[edi]
5422
     call  file_read
5423
 
5424
     mov   [esp+36],eax
5425
     mov   [esp+24],ebx
5426
 
5427
     ret
5428
 
5429
 
5430
align 4
5431
 
5432
write_to_hd:                            ; Write a file to hd
5433
 
5434
     mov   edi,[0x3010]
5435
     add   edi,0x10
5436
     add   eax,[edi]
5437
     add   ecx,[edi]
5438
     add   edx,[edi]
5439
     call  file_write
5440
     ret
5441
 
5442
align 4
5443
 
5444
delete_from_hd:                         ; Delete a file from hd
5445
 
5446
     mov   edi,[0x3010]
5447
     add   edi,0x10
5448
     add   eax,[edi]
5449
     add   ecx,[edi]
5450
     call  file_delete
5451
     ret
5452
 
5453
 
5454
align 4
5455
 
5456
undefined_syscall:                      ; Undefined system call
5457
 
5458
     mov   [esp+36],dword -1
5459
     ret
5460
 
5461
 
5462
;clear_busy_flag_at_caller:
5463
 
5464
;      push  edi
5465
 
5466
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
5467
;      imul  edi,8
5468
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
5469
 
5470
;      pop   edi
5471
 
5472
;      ret
5473
 
5474
 
5475
 
5476
 
5477
keymap:
5478
 
5479
     db   '6',27
5480
     db   '1234567890-=',8,9
5481
     db   'qwertyuiop[]',13
5482
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
5483
     db   '@234567890123',180,178,184,'6',176,'7'
5484
     db   179,'8',181,177,183,185,182
5485
     db   'AB
5486
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5487
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5488
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5489
 
5490
 
5491
keymap_shift:
5492
 
5493
     db   '6',27
5494
     db   '!@#$%^&*()_+',8,9
5495
     db   'QWERTYUIOP{}',13
5496
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
5497
     db   '@234567890123',180,178,184,'6',176,'7'
5498
     db   179,'8',181,177,183,185,182
5499
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
5500
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5501
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5502
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5503
 
5504
 
5505
keymap_alt:
5506
 
5507
     db   ' ',27
5508
     db   ' @ $  {[]}\ ',8,9
5509
     db   '            ',13
5510
     db   '             ',0,'           ',0,'4',0,' '
5511
     db   '             ',180,178,184,'6',176,'7'
5512
     db   179,'8',181,177,183,185,182
5513
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
5514
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5515
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5516
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5517
 
5518
 
5519
; device irq owners
5520
uglobal
5521
irq_owner:       ; process id
5522
 
5523
     dd   0x0
5524
     dd   0x0
5525
     dd   0x0
5526
     dd   0x0
5527
     dd   0x0
5528
     dd   0x0
5529
     dd   0x0
5530
     dd   0x0
5531
     dd   0x0
5532
     dd   0x0
5533
     dd   0x0
5534
     dd   0x0
5535
     dd   0x0
5536
     dd   0x0
5537
     dd   0x0
5538
     dd   0x0
5539
endg
5540
 
5541
 
5542
; on irq read ports
5543
uglobal
5544
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5545
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5546
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5547
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5548
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5549
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5550
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5551
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5552
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5553
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5554
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5555
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5556
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5557
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5558
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5559
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5560
endg
5561
 
5562
; status
5563
uglobal
5564
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5565
  application_table_status    dd 0x0  ; 0 - free : other - pid
5566
endg
5567
 
5568
; device addresses
5569
uglobal
5570
  mididp     dd 0x0
5571
  midisp     dd 0x0
5572
 
5573
  cdbase     dd 0x0
5574
  cdid       dd 0x0
5575
 
5576
  hdbase              dd   0x0  ; for boot 0x1f0
5577
  hdid                dd   0x0
5578
  hdpos               dd   0x0  ; for boot 0x1
5579
  fat32part           dd   0x0  ; for boot 0x1
5580
 
5581
  ;part2_ld            dd   0x0
5582
 
5583
;* start code - get  process (3) - Mario79
5584
active_process      dd   0
5585
;* end code - get active process (3) - Mario79
5586
 
5587
wraw_bacground_select db 0
5588
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5589
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5590
 
5591
  sb16       dd 0x0
5592
  wss        dd 0x0
5593
 
5594
  buttontype         dd 0x0
5595
  windowtypechanged  dd 0x0
5596
endg
5597
 
5598
iglobal
5599
  keyboard   dd 0x1
5600
  sound_dma  dd 0x1
5601
  syslang    dd 0x1
5602
endg
5603
 
5604
IncludeIGlobals
5605
endofcode:
5606
IncludeUGlobals
5607
uglobals_size = $ - endofcode
5608
diff16 "end of kernel code",$
5609