Subversion Repositories Kolibri OS

Rev

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