Subversion Repositories Kolibri OS

Rev

Rev 17 | Rev 21 | 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
 
19 mario79 89
version           db    'Kolibri OS  version 0.5.1.5      ',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:
19 mario79 2260
  db 0,5,1,5  ; version 0.5.1.5
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:
19 mario79 2280
;    pushad
2281
;    cmp  eax,1
2282
;    jne  no_write_all_of_ramdisk
2283
;    call fdc_writeramdisk
2284
;    popad
2285
;    ret
2286
;  no_write_all_of_ramdisk:
2287
;    cmp eax,2
2288
;    jne no_write_part_of_ramdisk
2289
;    call fdc_commitflush
2290
;    popad
2291
;    ret
2292
;  no_write_part_of_ramdisk:
2293
;    cmp  eax,3
2294
;    jne  no_set_fdc
2295
;    call fdc_set
2296
;    popad
2297
;    ret
2298
;  no_set_fdc:
2299
;    cmp  eax,4
2300
;    jne  no_get_fdc
2301
;    popad
2302
;    call fdc_get
2303
;    mov    [esp+36],ecx
2304
;    ret
2305
;  no_get_fdc:
2306
;    popad
2307
;    ret
2308
    cmp eax,1
2309
    jne no_floppy_a_save
2310
    mov   [flp_number],1
2311
    jmp save_image_on_floppy
2312
  no_floppy_a_save:
1 ha 2313
    cmp eax,2
19 mario79 2314
    jne no_floppy_b_save
2315
    mov   [flp_number],2
2316
  save_image_on_floppy:
2317
    call save_image
2318
    mov  [esp+36],dword 0
2319
    cmp  [FDC_Status],0
2320
    je   yes_floppy_save
2321
  no_floppy_b_save:
2322
    mov [esp+36],dword 1
2323
  yes_floppy_save:
1 ha 2324
    ret
2325
 
2326
uglobal
2327
;  bgrchanged  dd  0x0
2328
endg
2329
 
2330
sys_background:
2331
 
2332
    cmp   eax,1                            ; BACKGROUND SIZE
2333
    jnz   nosb1
2334
    cmp   ebx,0
2335
    je    sbgrr
2336
    cmp   ecx,0
2337
    je    sbgrr
2338
    mov   [display_data-8],ebx
2339
    mov   [display_data-4],ecx
2340
;    mov   [bgrchanged],1
2341
  sbgrr:
2342
    ret
2343
  nosb1:
2344
 
2345
    cmp   eax,2                            ; SET PIXEL
2346
    jnz   nosb2
2347
    mov   edx,0x160000-16
2348
    cmp   edx,ebx
2349
    jbe   nosb2
2350
    mov   edx,[ebx]
2351
    and   edx,0xFF000000 ;255*256*256*256
2352
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2353
    add   edx,ecx
2354
    mov   [ebx+0x300000],edx
2355
;    mov   [bgrchanged],1
2356
    ret
2357
  nosb2:
2358
 
2359
    cmp   eax,3                            ; DRAW BACKGROUND
2360
    jnz   nosb3
2361
draw_background_temp:
2362
;    cmp   [bgrchanged],1 ;0
2363
;    je    nosb31
2364
;draw_background_temp:
2365
;    mov   [bgrchanged],1 ;0
2366
    mov   [0xfff0],byte 1
2367
   nosb31:
2368
    ret
2369
  nosb3:
2370
 
2371
    cmp   eax,4                            ; TILED / STRETCHED
2372
    jnz   nosb4
2373
    cmp   ebx,[display_data-12]
2374
    je    nosb41
2375
    mov   [display_data-12],ebx
2376
;    mov   [bgrchanged],1
2377
   nosb41:
2378
    ret
2379
  nosb4:
2380
 
2381
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2382
    jnz   nosb5
2383
  ; bughere
2384
    mov   edi, [0x3010]
2385
    add   ebx, [edi+0x10]
2386
 ;   mov   esi, ebx
2387
 ;   mov   edi, ecx
2388
    mov   eax, ebx
2389
    mov   ebx, ecx
2390
    add   ecx, edx
2391
    cmp   ecx, 0x160000-16
2392
    ja    .fin
2393
 ;   add   edi, 0x300000
2394
    add   ebx, 0x300000
2395
    mov   ecx, edx
2396
    cmp   ecx, 0x160000-16
2397
    ja    .fin
2398
;    mov   [bgrchanged],1
2399
  ;  cld
2400
  ;  rep   movsb
2401
    call  memmove
2402
  .fin:
2403
    ret
2404
  nosb5:
2405
 
2406
    ret
2407
 
2408
 
2409
align 4
2410
 
2411
sys_getbackground:
2412
 
2413
    cmp   eax,1                                  ; SIZE
2414
    jnz   nogb1
2415
    mov   eax,[display_data-8]
2416
    shl   eax,16
2417
    mov   ax,[display_data-4]
2418
    mov   [esp+36],eax
2419
    ret
2420
  nogb1:
2421
 
2422
    cmp   eax,2                                  ; PIXEL
2423
    jnz   nogb2
2424
    mov   edx,0x160000-16
2425
    cmp   edx,ebx
2426
    jbe   nogb2
2427
    mov   eax, [ebx+0x300000]
2428
    and   eax, 0xFFFFFF
2429
    mov   [esp+36],eax
2430
    ret
2431
  nogb2:
2432
 
2433
    cmp   eax,4                                  ; TILED / STRETCHED
2434
    jnz   nogb4
2435
    mov   eax,[display_data-12]
2436
  nogb4:
2437
    mov   [esp+36],eax
2438
    ret
2439
 
2440
 
2441
align 4
2442
 
2443
sys_getkey:
2444
    mov   [esp+36],dword 1
2445
    mov   ebx, [0x3000]                          ; TOP OF WINDOW STACK
2446
    movzx ecx,word [0xC000 + ebx * 2]
2447
    mov   edx,[0x3004]
2448
    cmp   ecx,edx
2449
    jne   .finish
2450
    cmp   [0xf400],byte 0
2451
    je    .finish
2452
    movzx eax,byte [0xf401]
2453
    shl   eax,8
2454
    push  eax
2455
    dec   byte [0xf400]
2456
    and   byte [0xf400],127
2457
    movzx ecx,byte [0xf400]
2458
    add   ecx,2
2459
 ;   mov   esi,0xf402
2460
 ;   mov   edi,0xf401
2461
 ;   cld
2462
 ;  rep   movsb
2463
    mov   eax, 0xF402
2464
    mov   ebx, 0xF401
2465
    call  memmove
2466
    pop   eax
2467
    mov   [last_key_press],eax
2468
 
2469
    mov   eax,[kb_state]
2470
    and   al,110000b
2471
    cmp   al,100000b
2472
    je    .yes_win_key
2473
    cmp   al,10000b
2474
    je    .yes_win_key
2475
    mov   eax,[last_key_press]
2476
    jmp   .no_win_key
2477
;    cmp   ah,232
2478
;    je    .yes_win_key
2479
;    cmp   ah,233
2480
;    jne   .no_win_key
2481
 .yes_win_key:
2482
    mov   eax,1
2483
 .no_win_key:
2484
    mov   [esp+36],eax
2485
 .finish:
2486
    ret
2487
 
2488
 
2489
align 4
2490
 
2491
sys_getbutton:
2492
 
2493
    mov   ebx, [0x3000]                         ; TOP OF WINDOW STACK
2494
    mov   [esp+36],dword 1
2495
    movzx ecx, word [0xC000 + ebx * 2]
2496
    mov   edx, [0x3004] ; less than 256 processes
2497
    cmp   ecx,edx
2498
    jne   .exit
2499
    movzx eax,byte [0xf500]
2500
    test  eax,eax
2501
    jz    .exit
2502
    mov   eax,[0xf501]
2503
    shl   eax,8
2504
    mov   [0xf500],byte 0
2505
    mov   [esp+36],eax
2506
 .exit:
2507
    ret
2508
 
2509
 
2510
align 4
2511
 
2512
sys_cpuusage:
2513
 
2514
;  RETURN:
2515
;
2516
;  +00 dword     process cpu usage
2517
;  +04  word     position in windowing stack
2518
;  +06  word     windowing stack value at current position (cpu nro)
2519
;  +10 12 bytes  name
2520
;  +22 dword     start in mem
2521
;  +26 dword     used mem
2522
;  +30 dword     PID , process idenfification number
2523
;
2524
 
2525
    mov  edi,[0x3010]   ; eax = return area
2526
    add  edi,0x10
2527
    add  eax,[edi]
2528
 
2529
    cmp  ebx,-1         ; who am I ?
2530
    jne  no_who_am_i
2531
    mov  ebx,[0x3000]
2532
  no_who_am_i:
2533
 
2534
    push eax            ; return area
2535
    push ebx            ; process number
2536
 
2537
    push ebx
2538
    push ebx
2539
    push eax
2540
 
2541
    ; return memory usage
2542
 
2543
    xor  edx,edx
2544
    mov  eax,0x20
2545
    mul  ebx
2546
    add  eax,0x3000+0x1c
2547
    mov  ebx,eax
2548
    pop  eax
2549
    mov  ecx,[ebx]
2550
    mov  [eax],ecx
2551
    pop  ebx
2552
;    mov  ebx,[esp]
2553
;    shl  ebx,1
2554
;    add  ebx,0xc000
2555
    mov  cx, [0xC000 + ebx * 2]
2556
    mov  [eax+4],cx
2557
;    mov  ebx,[esp]
2558
;    shl  ebx,1
2559
;    add  ebx,0xc400
2560
    mov  cx, [0xC400 + ebx * 2]
2561
    mov  [eax+6],cx
2562
;    pop  ebx
2563
    push eax
2564
    mov  eax,ebx
2565
    shl  eax,8
2566
    add  eax,0x80000
2567
    pop  ebx
2568
    add  ebx,10
2569
    mov  ecx,11
2570
    call memmove
2571
 
2572
    ; memory usage
2573
 
2574
    xor    eax,eax
2575
    mov    edx,0x100000*16
2576
    pop    ecx                                   ; get gdt of tss
2577
    cmp    ecx,1
2578
    je     os_mem
2579
    shl    ecx,8
2580
    mov    edx,[0x80000+ecx+0x8c]
2581
    mov    eax,std_application_base_address
2582
    ;add    ecx,0x80000+0x88
2583
    ;mov    ecx,[ecx]
2584
;    shl    ecx,3
2585
    ; eax run base -> edx used memory
2586
;    mov    al,[ecx+gdts+ app_code-3 +4]        ;  base  23:16
2587
;    mov    ah,[ecx+gdts+ app_code-3 +7]        ;  base  31:24
2588
;    shl    eax,16
2589
;    mov    ax,[ecx+gdts+ app_code-3 +2]        ;  base  0:15
2590
;    movzx  edx,word [ecx+gdts+ app_code-3 +0]
2591
;    shl    edx,12
2592
 
2593
  os_mem:
2594
    dec    edx
2595
    mov    [ebx+12],eax
2596
    mov    [ebx+16],edx
2597
 
2598
    ; PID (+30)
2599
 
2600
    mov    eax,[esp]
2601
    shl    eax,5
2602
    add    eax,0x3000+0x4
2603
    mov    eax,[eax]
2604
    mov    [ebx+20],eax
2605
 
2606
    ; window position and size
2607
 
2608
    mov    esi,[esp]
2609
    shl    esi,5
2610
    add    esi,window_data
2611
    mov    edi,[esp+4]
2612
    add    edi,34
2613
    mov    ecx,4*4
2614
    cld
2615
    rep    movsb
2616
 
2617
    ; Process state (+50)
2618
 
2619
    mov    eax,[esp]
2620
    shl    eax,5
2621
    add    eax,0x3000+0xa
2622
    mov    eax,[eax]
2623
    mov    [ebx+40],ax
2624
 
2625
 
2626
    pop    ebx
2627
    pop    eax
2628
 
2629
    ; return number of processes
2630
 
2631
    mov    eax,[0x3004]
2632
    mov    [esp+36],eax
2633
    ret
2634
 
2635
 
2636
 
2637
 
2638
align 4
2639
sys_clock:
2640
        cli
2641
  ; Mikhail Lisovin  xx Jan 2005
2642
  @@:   mov   al, 10
2643
        out   0x70, al
2644
        in    al, 0x71
2645
        test  al, al
2646
        jns   @f
2647
        mov   esi, 1
2648
        call  delay_ms
2649
        jmp   @b
2650
  @@:
2651
  ; end Lisovin's fix
2652
 
2653
        xor   al,al           ; seconds
2654
        out   0x70,al
2655
        in    al,0x71
2656
        movzx ecx,al
2657
        mov   al,02           ; minutes
2658
        shl   ecx,16
2659
        out   0x70,al
2660
        in    al,0x71
2661
        movzx edx,al
2662
        mov   al,04           ; hours
2663
        shl   edx,8
2664
        out   0x70,al
2665
        in    al,0x71
2666
        add   ecx,edx
2667
        movzx edx,al
2668
        add   ecx,edx
2669
        sti
2670
        mov   [esp+36],ecx
2671
        ret
2672
 
2673
 
2674
align 4
2675
 
2676
sys_date:
2677
 
2678
        cli
2679
        mov     al,6            ; day of week
2680
        out     0x70,al
2681
        in      al,0x71
2682
        mov     ch,al
2683
        mov     al,7            ; date
2684
        out     0x70,al
2685
        in      al,0x71
2686
        mov     cl,al
2687
        mov     al,8            ; month
2688
        shl     ecx,16
2689
        out     0x70,al
2690
        in      al,0x71
2691
        mov     ch,al
2692
        mov     al,9            ; year
2693
        out     0x70,al
2694
        in      al,0x71
2695
        mov     cl,al
2696
        sti
2697
        mov     [esp+36],ecx
2698
        ret
2699
 
2700
 
2701
; redraw status
2702
 
2703
sys_redrawstat:
2704
 
2705
    cmp  eax,1
2706
    jne  no_widgets_away
2707
 
2708
    ; buttons away
2709
 
2710
    mov   ecx,[0x3000]
2711
 
2712
  sys_newba2:
2713
 
2714
    mov   edi,[0xfe88]
2715
    cmp   [edi],dword 0  ; empty button list ?
2716
    je    end_of_buttons_away
2717
 
2718
    movzx ebx,word [edi]
2719
    inc   ebx
2720
 
2721
    mov   eax,edi
2722
 
2723
  sys_newba:
2724
 
2725
    dec   ebx
2726
    jz    end_of_buttons_away
2727
 
2728
    add   eax,0x10
2729
    cmp   cx,[eax]
2730
    jnz   sys_newba
2731
 
2732
    push  eax ebx ecx
2733
    mov   ecx,ebx
2734
    inc   ecx
2735
    shl   ecx,4
2736
    mov   ebx,eax
2737
    add   eax,0x10
2738
    call  memmove
2739
    dec   dword [edi]
2740
    pop   ecx ebx eax
2741
 
2742
    jmp   sys_newba2
2743
 
2744
  end_of_buttons_away:
2745
 
2746
    ret
2747
 
2748
  no_widgets_away:
2749
 
2750
    cmp   eax,2
2751
    jnz   srl1
2752
 
2753
    mov   edx,[0x3010]      ; return whole screen draw area for this app
2754
    add   edx,draw_data-0x3000
2755
    mov   [edx+0],dword 0
2756
    mov   [edx+4],dword 0
2757
    mov   eax,[0xfe00]
2758
    mov   [edx+8],eax
2759
    mov   eax,[0xfe04]
2760
    mov   [edx+12],eax
2761
 
2762
    mov   edi,[0x3010]
2763
    sub   edi,twdw
2764
    mov   [edi+30],byte 1   ; no new position & buttons from app
2765
 
2766
    call  sys_window_mouse
2767
 
2768
    ret
2769
 
2770
  srl1:
2771
 
2772
    ret
2773
 
2774
 
2775
sys_drawwindow:
2776
 
2777
    mov   edi,ecx
2778
    shr   edi,16+8
2779
    and   edi,15
2780
 
2781
    cmp   edi,0   ; type I    - original style
2782
    jne   nosyswI
2783
    call  sys_set_window
2784
    call  drawwindow_I
2785
    ret
2786
  nosyswI:
2787
 
2788
    cmp   edi,1   ; type II   - only reserve area, no draw
2789
    jne   nosyswII
2790
    call  sys_set_window
2791
    call  sys_window_mouse
2792
    ret
2793
  nosyswII:
2794
 
2795
    cmp   edi,2   ; type III  - new style
2796
    jne   nosyswIII
2797
    call  sys_set_window
2798
    call  drawwindow_III
2799
    ret
2800
  nosyswIII:
2801
 
2802
    cmp   edi,3   ; type IV - skinned window
2803
    jne   nosyswIV
2804
    call  sys_set_window
2805
    call  drawwindow_IV
2806
    ret
2807
  nosyswIV:
2808
 
2809
    ret
2810
 
2811
 
2812
sys_set_window:
2813
 
2814
    mov   edi,[0x3000]
2815
    shl   edi,5
2816
    add   edi,window_data
2817
 
2818
    ; colors
2819
    mov   [edi+16],ecx
2820
    mov   [edi+20],edx
2821
    mov   [edi+24],esi
2822
 
2823
    ; check flag (?)
2824
    cmp   [edi+30],byte 1
2825
    jz    newd
2826
 
2827
    push  eax
2828
    mov   eax,[timer_ticks] ;[0xfdf0]
2829
    add   eax,100
2830
    mov   [new_window_starting],eax
2831
    pop   eax
2832
 
2833
    mov   [edi+8],ax
2834
    mov   [edi+12],bx
2835
    shr   eax,16
2836
    shr   ebx,16
2837
    mov   [edi+00],ax
2838
    mov   [edi+04],bx
2839
 
2840
 
2841
    call  check_window_position
2842
 
2843
 
2844
    push  ecx esi edi               ; save for window fullscreen/resize
2845
    mov   esi,edi
2846
    sub   edi,window_data
2847
    shr   edi,5
2848
    shl   edi,8
2849
    add   edi,0x80000+0x90
2850
    mov   ecx,4
2851
    cld
2852
    rep   movsd
2853
    pop   edi esi ecx
2854
 
2855
    push  eax ebx ecx edx
2856
;;;    mov   eax, 1
2857
;;;    call  delay_hs
2858
    movzx eax, word [edi+00]
2859
    movzx ebx, word [edi+04]
2860
    movzx ecx, word [edi+8]
2861
    movzx edx, word [edi+12]
2862
    add   ecx, eax
2863
    add   edx, ebx
2864
    call  calculatescreen
2865
    pop   edx ecx ebx eax
2866
 
2867
    mov   [0xf400],byte 0           ; empty keyboard buffer
2868
    mov   [0xf500],byte 0           ; empty button buffer
2869
 
2870
  newd:
2871
    mov   [edi+31],byte 0   ; no redraw
2872
    mov   edx,edi
2873
 
2874
    ret
2875
 
2876
 
2877
sys_window_move:
2878
 
2879
        cmp  [window_move_pr],0
2880
        je   mwrl1
2881
 
2882
        mov  [esp+36],dword 1         ; return queue error
2883
 
2884
        ret
2885
 
2886
     mwrl1:
2887
 
2888
        mov   edi,[0x3000]            ; requestor process base
2889
        mov   [window_move_pr],edi
2890
 
2891
        mov   [window_move_eax],eax
2892
        mov   [window_move_ebx],ebx
2893
        mov   [window_move_ecx],ecx
2894
        mov   [window_move_edx],edx
2895
 
2896
        mov   [esp+36],dword 0        ; return success
2897
 
2898
        ret
2899
 
2900
type_background_1:
2901
    cmp   [0xfff0],byte 0               ; background update ?
2902
    jz    temp_nobackgr
2903
    mov   [0xfff0],byte 2
2904
    call  change_task
2905
    mov   [draw_data+32+0],dword 0
2906
    mov   [draw_data+32+4],dword 0
2907
    mov   eax,[0xfe00]
2908
    mov   ebx,[0xfe04]
2909
    mov   [draw_data+32+8],eax
2910
    mov   [draw_data+32+12],ebx
2911
    call  drawbackground
2912
    mov   [0xfff0],byte 0
2913
    mov   [0xfff4],byte 0
2914
temp_nobackgr:
2915
    ret
2916
 
2917
uglobal
2918
  window_move_pr   dd  0x0
2919
  window_move_eax  dd  0x0
2920
  window_move_ebx  dd  0x0
2921
  window_move_ecx  dd  0x0
2922
  window_move_edx  dd  0x0
2923
endg
2924
 
2925
;ok - 100% work
2926
;nt - not tested
2927
;---------------------------------------------------------------------------------------------
2928
;eax
2929
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2930
;1 - change task. Ret nothing. Block. ok.
2931
;2 - performance control
2932
; ebx
2933
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2934
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2935
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2936
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2937
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2938
;eax
2939
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2940
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2941
;---------------------------------------------------------------------------------------------
2942
sys_sheduler: ;noname & halyavin
2943
    cmp eax,0
2944
    je shed_counter
2945
    cmp eax,2
2946
    je perf_control
2947
    cmp eax,3
2948
    je rdmsr_instr
2949
    cmp eax,4
2950
    je wrmsr_instr
2951
    cmp eax,1
2952
    jne not_supported
2953
    call change_task ;delay,0
2954
ret
2955
shed_counter:
2956
    mov eax,[context_counter]
2957
    mov [esp+36],eax
2958
not_supported:
2959
ret
2960
perf_control:
2961
    inc eax ;now eax=3
2962
    cmp ebx,eax
2963
    je cache_disable
2964
    dec eax
2965
    cmp ebx,eax
2966
    je cache_enable
2967
    dec eax
2968
    cmp ebx,eax
2969
    je is_cache_enabled
2970
    dec eax
2971
    cmp ebx,eax
2972
    je modify_pce
2973
ret
2974
 
2975
rdmsr_instr:
2976
;now counter in ecx
2977
;(edx:eax) esi:edi => edx:esi
2978
mov eax,esi
2979
rdmsr
2980
mov [esp+36],eax
2981
mov [esp+24],edx ;ret in ebx?
2982
ret
2983
 
2984
wrmsr_instr:
2985
;now counter in ecx
2986
;(edx:eax) esi:edi => edx:esi
2987
mov eax,esi
2988
wrmsr
2989
mov [esp+36],eax
2990
mov [esp+24],edx ;ret in ebx?
2991
ret
2992
 
2993
cache_disable:
2994
       mov eax,cr0
2995
       or  eax,01100000000000000000000000000000b
2996
       mov cr0,eax
2997
       wbinvd ;set MESI
2998
ret
2999
 
3000
cache_enable:
3001
       mov eax,cr0
3002
       and eax,10011111111111111111111111111111b
3003
       mov cr0,eax
3004
ret
3005
 
3006
is_cache_enabled:
3007
       mov eax,cr0
3008
       mov ebx,eax
3009
       and eax,01100000000000000000000000000000b
3010
       jz cache_disabled
3011
       mov [esp+36],ebx
3012
cache_disabled:
3013
       mov dword [esp+36],eax ;0
3014
ret
3015
 
3016
modify_pce:
3017
       mov eax,cr4
3018
;       mov ebx,0
3019
;       or  bx,100000000b ;pce
3020
;       xor eax,ebx ;invert pce
17 me_root 3021
       bts eax,8 ;pce=cr4[8]
1 ha 3022
       mov cr4,eax
3023
       mov [esp+36],eax
3024
ret
3025
;---------------------------------------------------------------------------------------------
3026
 
3027
; check pixel limits
3028
 
3029
;cplimit:
3030
;        push    edi
3031
 
3032
;        cmp     byte [0xe000], 1      ; Multitasking enabled?
3033
;        jnz     .ret0
3034
;        mov     edi,[0x3010]
3035
;        add     edi, draw_data-0x3000
3036
;        mov     ecx, 1
3037
;        cmp     [edi+0], eax  ; xs
3038
;        ja      .ret1
3039
;        cmp     [edi+4], ebx  ; ys
3040
;        ja      .ret1
3041
;        cmp     eax, [edi+8]   ; xe
3042
;        ja      .ret1
3043
;        cmp     ebx, [edi+12] ; ye
3044
;        ja      .ret1
3045
 
3046
;.ret0:
3047
;        xor     ecx, ecx
3048
;.ret1:
3049
;        pop     edi
3050
;        ret
3051
 
3052
 
3053
; check if pixel is allowed to be drawn
3054
 
3055
checkpixel:
3056
 
3057
        push eax
3058
        push ebx
3059
        push edx
3060
 
3061
;        mov   ecx,[0x3000]  ; process count
3062
;        shl   ecx, 6        ; *64
3063
;        add   ecx,0xc000    ; +window_stack
3064
;        mov   dx,word [ecx] ; window_stack_value
3065
 
3066
;        cmp   dx, word [0x3004] ; is this window active right now?!
3067
;        jz    .ret0
3068
 
3069
;        call  cplimit
3070
;        test  ecx, ecx
3071
;        jnz   .ret1
3072
 
3073
        mov  edx,[0xfe00]     ; screen x size
3074
        inc  edx
3075
        imul  edx, ebx
3076
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3077
;;;        mov  dl,[eax]
3078
 
3079
        mov  eax,[0x3000]
3080
        shl  eax,5
3081
        add  eax,0x3000+0xe
3082
 
3083
        mov  ecx, 1
3084
        cmp  byte [eax], dl
3085
        jnz  .ret1
3086
 
3087
.ret0:
3088
        xor  ecx, ecx
3089
.ret1:
3090
        pop  edx
3091
        pop  ebx
3092
        pop  eax
3093
        ret
3094
 
3095
uglobal
3096
  mouse_active  db  0
3097
endg
3098
iglobal
3099
  cpustring db 'CPU        '
3100
endg
3101
 
3102
 
3103
align 4
3104
; check misc
3105
 
3106
checkmisc:
3107
 
3108
    cmp   [ctrl_alt_del], 1
3109
    jne   nocpustart
3110
    mov   eax, cpustring
3111
    call  start_application_fl
3112
    mov   [ctrl_alt_del], 0
3113
  nocpustart:
3114
    cmp   [mouse_active], 1
3115
    jne   mouse_not_active
3116
    mov   [mouse_active], 0
3117
    xor   edi, edi
3118
    mov   ecx, [0x3004]
3119
   set_mouse_event:
3120
    add   edi, 256
3121
    or    [edi+0x80000+0xA8], dword 00100000b
3122
    loop  set_mouse_event
3123
  mouse_not_active:
3124
 
3125
 
3126
    cmp   [0xfff0],byte 0               ; background update ?
3127
    jz    nobackgr
3128
    mov   [0xfff0],byte 2
3129
    call  change_task
3130
    mov   [draw_data+32+0],dword 0
3131
    mov   [draw_data+32+4],dword 0
3132
    mov   eax,[0xfe00]
3133
    mov   ebx,[0xfe04]
3134
    mov   [draw_data+32+8],eax
3135
    mov   [draw_data+32+12],ebx
3136
    call  drawbackground
3137
    mov   [0xfff0],byte 0
3138
    mov   [0xfff4],byte 0
3139
 
3140
  nobackgr:
3141
 
3142
 
3143
    ; system shutdown request
3144
 
3145
    cmp  [0xFF00],byte 0
3146
    je   noshutdown
3147
 
3148
    mov  edx,[shutdown_processes]
3149
    sub  dl,2
3150
 
3151
    cmp  [0xff00],dl
3152
    jne  no_mark_system_shutdown
3153
 
3154
    mov   edx,0x3040
3155
    movzx ecx,byte [0xff00]
3156
    add   ecx,5
3157
  markz:
3158
    mov   [edx+0xa],byte 3
3159
    add   edx,0x20
3160
    loop  markz
3161
 
3162
  no_mark_system_shutdown:
3163
 
3164
    call [disable_mouse]
3165
 
3166
    dec  byte [0xff00]
3167
 
3168
    cmp  [0xff00],byte 0
3169
    je   system_shutdown
3170
 
3171
  noshutdown:
3172
 
3173
 
3174
    mov   eax,[0x3004]                  ; termination
3175
    mov   ebx,0x3020+0xa
3176
    mov   esi,1
3177
 
3178
  newct:
3179
    mov   cl,[ebx]
3180
    cmp   cl,byte 3
3181
    jz    terminate
3182
    cmp   cl,byte 4
3183
    jz    terminate
3184
 
3185
    add   ebx,0x20
3186
    inc   esi
3187
    dec   eax
3188
    jnz   newct
3189
 
3190
    ret
3191
 
3192
 
3193
 
3194
 
3195
; redraw screen
3196
 
3197
redrawscreen:
3198
 
3199
; eax , if process window_data base is eax, do not set flag/limits
3200
 
3201
         pushad
3202
         push  eax
3203
 
3204
;;;         mov   eax,2
3205
;;;         call  delay_hs
3206
 
3207
         ;mov   ecx,0               ; redraw flags for apps
3208
         xor   ecx,ecx
3209
       newdw2:
3210
 
3211
         inc   ecx
3212
         push  ecx
3213
 
3214
         mov   eax,ecx
3215
         shl   eax,5
3216
         add   eax,window_data
3217
 
3218
         cmp   eax,[esp+4]
3219
         je    not_this_task
3220
                                   ; check if window in redraw area
3221
         mov   edi,eax
3222
 
3223
         cmp   ecx,1               ; limit for background
3224
         jz    bgli
3225
 
3226
         mov   eax,[edi+0]
3227
         mov   ebx,[edi+4]
3228
         mov   ecx,[edi+8]
3229
         mov   edx,[edi+12]
3230
         add   ecx,eax
3231
         add   edx,ebx
3232
 
3233
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3234
         cmp   ecx,ebx
3235
         jb    ricino
3236
 
3237
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3238
         cmp   ecx,eax
3239
         jb    ricino
3240
 
3241
         mov   eax,[edi+0]
3242
         mov   ebx,[edi+4]
3243
         mov   ecx,[edi+8]
3244
         mov   edx,[edi+12]
3245
         add   ecx,eax
3246
         add   edx,ebx
3247
 
3248
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3249
         cmp   edx,eax
3250
         jb    ricino
3251
 
3252
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3253
         cmp   ecx,eax
3254
         jb    ricino
3255
 
3256
        bgli:
3257
 
3258
         cmp   edi,esi
3259
         jz    ricino
3260
 
3261
         mov   eax,edi
3262
         add   eax,draw_data-window_data
3263
 
3264
         mov   ebx,[dlx]          ; set limits
3265
         mov   [eax+0],ebx
3266
         mov   ebx,[dly]
3267
         mov   [eax+4],ebx
3268
         mov   ebx,[dlxe]
3269
         mov   [eax+8],ebx
3270
         mov   ebx,[dlye]
3271
         mov   [eax+12],ebx
3272
 
3273
         sub   eax,draw_data-window_data
3274
 
3275
         cmp   ecx,1
3276
         jne   nobgrd
3277
         cmp   esi,1
3278
         je    newdw8
3279
         call  drawbackground
3280
 
3281
       newdw8:
3282
       nobgrd:
3283
 
3284
         mov   [eax+31],byte 1    ; mark as redraw
3285
 
3286
       ricino:
3287
 
3288
       not_this_task:
3289
 
3290
         pop   ecx
3291
 
3292
         cmp   ecx,[0x3004]
3293
         jle   newdw2
3294
 
3295
         pop  eax
3296
         popad
3297
 
3298
         ret
3299
 
3300
;   check mouse
3301
;
3302
;
3303
;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
3304
;   FB10  ->   FB17   mouse color mem
3305
;   FB21              x move
3306
;   FB22              y move
3307
;   FB30              color temp
3308
;   FB28              high bits temp
3309
;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
3310
;   FC00  ->   FCFE   com1/ps2 buffer
3311
;   FCFF              com1/ps2 buffer count starting from FC00
3312
 
3313
uglobal
3314
  mousecount  dd  0x0
3315
  mousedata   dd  0x0
3316
endg
3317
 
3318
 
3319
check_mouse_data:
3320
 
3321
        pushad
3322
 
3323
        cmp    [0xF604],byte 1
3324
        jne    no_ps2_mouse
3325
        mov    [mousecount],dword 0x2e0000+12*4096
3326
        mov    [mousedata],dword 0x2e0000+12*4096+0x10
3327
        jmp    uusicheckmouse
3328
no_ps2_mouse:
3329
        cmp    [0xF604],byte 2
3330
        jne    no_com1_mouse
3331
        mov    [mousecount],dword 0x2e0000+4*4096
3332
        mov    [mousedata],dword 0x2e0000+4*4096+0x10
3333
        jmp    uusicheckmouse
3334
no_com1_mouse:
3335
        mov    [mousecount],dword 0x2e0000+3*4096
3336
        mov    [mousedata],dword 0x2e0000+3*4096+0x10
3337
 
3338
      uusicheckmouse:
3339
 
3340
        mov    ebx,[mousecount]       ; anything at buffer for mouse
3341
        cmp    dword [ebx], 0         ; !!!
3342
        jz     checkmouseret
3343
 
3344
        ; first byte of comX or ps2 ?
3345
 
3346
        cmp    [0xF604],byte 1
3347
        je     ps2mousefirst
3348
 
3349
        ; ******************************************
3350
        ; *********** COMX mouse driver ************
3351
        ; ******************************************
3352
 
3353
       com1mousefirst:
3354
 
3355
        mov    edi,[mousedata]
3356
        mov    dl,byte [edi] ; first com1 ?
3357
        test   dl,64
3358
        jz     @f
3359
        mov    [0xfb00],byte 0  ; zero mouse block count
3360
       @@:
3361
        xor    ebx,ebx
3362
 
3363
        mov    bl,[0xfb00]
3364
        inc    bl
3365
        mov    [0xfb00],bl
3366
        mov    eax,0xfb00
3367
        add    eax,ebx
3368
        mov    edi,[mousedata]
3369
        mov    dl,byte [edi]
3370
        mov    [eax],byte dl
3371
        cmp    bl,3             ; three ?
3372
        jnz    decm
3373
 
3374
        ; buttons
3375
 
3376
;* change right and left button by places - start code - Mario79
3377
        mov al,[0xfb01]
3378
        mov ah,al
3379
        shr al,3
3380
        and al,2
3381
        shr ah,5
3382
        and ah,1
3383
        add al,ah
3384
;* change right and left button by places - end code - Mario79
3385
 
3386
        mov    [0xfb40],al
3387
 
3388
        ; com1 mouse
3389
        ; x
3390
 
3391
        mov    dl,[0xfb01]        ; x high bits
3392
        movzx  eax,dl
3393
        and    al,3
3394
        shl    al,6
3395
        mov    dl,byte[0xfb02]    ; x low bits
3396
        add    al,dl
3397
        mov    [0xfb21],byte al
3398
        movzx  ebx,word[0xfb0a]
3399
 
3400
        mov    al,byte [0xfb01]   ; + or - ?
3401
        test   al,2
3402
        jz     x_add
3403
 
3404
       x_sub:                      ; x-
3405
        sub    bx,255
3406
        sub    bx,255
3407
       x_add:                      ; x+
3408
        movzx  eax,byte [0xfb21]
3409
        add    bx,ax
3410
        add    bx,ax
3411
        push   ebx
3412
        mov    [0xfb00],byte 0
3413
 
3414
        ; y
3415
 
3416
 
3417
      my_event:
3418
 
3419
        mov    dl,[0xfb01]       ; y high bits
3420
        movzx  eax,dl
3421
        and    al,12
3422
        shl    al,4
3423
        mov    dl,byte[0xfb03]   ; y low bits
3424
        add    al,dl
3425
        mov    [0xfb22],byte al
3426
        movzx  ebx,word[0xfb0c]
3427
 
3428
        mov    al,byte [0xfb01]  ; + or - ?
3429
        test   al,8
3430
        je     y_add
3431
 
3432
      y_sub:                      ; y-
3433
        sub    bx,255
3434
        sub    bx,255
3435
      y_add:                      ; y+
3436
        movzx  eax,byte [0xfb22]
3437
        add    bx,ax
3438
        add    bx,ax
3439
        push   ebx
3440
        mov    [0xfb00],byte 0
3441
        jmp    mdraw
3442
 
3443
        ; end of com1 mouse
3444
 
3445
 
3446
        ; ******************************************
3447
        ; ********  PS2 MOUSE DRIVER  **************
3448
        ; ******************************************
3449
 
3450
      ps2mousefirst:
3451
 
3452
        movzx  edx,byte [0x2E0000+4096*12+0x10]   ; first ps2 ?
3453
        cmp    edx,40
3454
        jne    @f
3455
        mov    [0xfb00],byte 0  ; zero mouse block count
3456
      @@:
3457
 
3458
        movzx  ebx,byte [0xfb00]
3459
        add    ebx,1
3460
        mov    [0xfb00],bl
3461
        mov    eax,0xfb00
3462
        add    eax,ebx
3463
        mov    dl,byte [0x2E0000+4096*12+0x10]
3464
        mov    [eax],byte dl
3465
 
3466
        cmp    bl,3             ; full packet of three bytes ?
3467
        jnz    decm
3468
 
3469
        mov    [0xfb00],byte 0  ; zero mouse block count
3470
 
3471
        ; buttons
3472
 
3473
        movzx  eax,byte [0xfb01]
3474
        and    eax,3
3475
        mov    [0xfb40],al
3476
 
3477
        ; x
3478
 
3479
        movzx  eax,word [0xfb0a]
3480
        movzx  edx,byte [0xfb02]
3481
        cmp    edx,128
3482
        jb     ps2xp
3483
        shl    edx,1
3484
        add    eax,edx
3485
        cmp    eax,512
3486
        jge    ps2xsok
3487
        xor    eax, eax
3488
        jmp    ps2xready
3489
       ps2xsok:
3490
        sub    eax,512
3491
        jmp    ps2xready
3492
       ps2xp:
3493
        shl    edx,1
3494
        add    eax,edx
3495
        jmp    ps2xready
3496
       ps2xready:
3497
        push   eax
3498
 
3499
        ; y
3500
 
3501
        movzx  eax,word [0xfb0c]
3502
        movzx  edx,byte [0xfb03]
3503
        cmp    edx,128
3504
        jb     ps2yp
3505
        add    eax,512
3506
        shl    edx,1
3507
        sub    eax,edx
3508
        jmp    ps2yready
3509
       ps2yp:
3510
        shl    edx,1
3511
        cmp    edx,eax
3512
        jb     ps201
3513
        mov    edx,eax
3514
       ps201:
3515
        sub    eax,edx
3516
        jmp    ps2yready
3517
       ps2yready:
3518
        push   eax
3519
 
3520
        ;jmp    mdraw
3521
 
3522
        ; end of ps2 mouse
3523
 
3524
 
3525
        ; ****************************
3526
        ; ***** CHECK FOR LIMITS *****
3527
        ; ****************************
3528
 
3529
      mdraw:
3530
 
3531
        cmp    [0xfb44],byte 0
3532
        jne    mousedraw4
3533
        cmp    [0xfb40],byte 0
3534
        je     mousedraw4
3535
        mov    [0xfff5],byte 1
3536
 
3537
      mousedraw4:
3538
 
3539
        pop    ebx
3540
        pop    eax
3541
 
3542
        mov    [mouse_active],1
3543
 
3544
;        mov    dx,0                   ; smaller than zero
3545
        xor    dx,dx
3546
        cmp    bx,dx
3547
        jge    mnb11
3548
;        mov    bx,0
3549
        xor    bx,bx
3550
      mnb11:
3551
        mov    [0xfb0c],word bx
3552
 
3553
;        mov    dx,0
3554
        xor    dx,dx
3555
        cmp    ax,dx
3556
        jge    mnb22
3557
;        mov    ax,0
3558
        xor    ax,ax
3559
      mnb22:
3560
        mov    [0xfb0a],word ax
3561
 
3562
        mov    edx,[0xfe04]           ; bigger than maximum
3563
        cmp    ebx,edx
3564
        jb     mnb1
3565
        mov    bx,[0xfe04]
3566
      mnb1:
3567
        mov    [0xfb0c],word bx
3568
 
3569
        mov    edx,[0xfe00]
3570
        cmp    eax,edx
3571
        jb     mnb2
3572
        mov    ax,[0xfe00]
3573
      mnb2:
3574
        mov    [0xfb0a],word ax
3575
 
3576
 
3577
        ; ****   NEXT DATA BYTE FROM MOUSE BUFFER   ****
3578
 
3579
      decm:
3580
 
3581
        mov    edi,[mousecount]         ; decrease counter
3582
        dec    dword [edi]
3583
 
3584
        mov    esi,[mousedata]
3585
        mov    edi,esi
3586
        inc    esi
3587
;        mov    ecx,250
3588
        mov    ecx,[mousecount]
3589
        mov    ecx,[ecx]
3590
        cld
3591
        rep    movsb
3592
 
3593
        jmp    uusicheckmouse
3594
 
3595
      checkmouseret:
3596
 
3597
        cmp    [0xfb44],byte 0
3598
        jne    cmret
3599
 
3600
        cmp    [0xfb40],byte 0
3601
        je     cmret
3602
 
3603
        mov    [0xfff4],byte 0
3604
        mov    [0xfff5],byte 0
3605
 
3606
      cmret:
3607
 
3608
        popad
3609
 
3610
        ret
3611
 
3612
 
3613
draw_mouse_under:
3614
 
3615
        ; return old picture
3616
;        cli
3617
 
3618
        pushad
3619
 
3620
        xor    ecx,ecx
3621
        xor    edx,edx
3622
 
3623
        ;cli    ; !!!****
3624
        align  4
3625
      mres:
3626
 
3627
        movzx  eax,word [0xfb4a]
3628
        movzx  ebx,word [0xfb4c]
3629
 
3630
        add    eax,ecx
3631
        add    ebx,edx
3632
 
3633
        push   ecx
3634
        push   edx
3635
        push   eax
3636
        push   ebx
3637
 
3638
        mov    eax,edx
3639
        shl    eax,6
3640
        shl    ecx,2
3641
        add    eax,ecx
3642
        add    eax,mouseunder
3643
        mov    ecx,[eax]
3644
 
3645
        pop    ebx
3646
        pop    eax
3647
 
3648
        ;;;push   edi
3649
        mov    edi,1 ;force
3650
        call   [putpixel]
3651
        ;;;pop    edi
3652
 
3653
        pop    edx
3654
        pop    ecx
3655
 
3656
        inc    ecx
3657
        cmp    ecx, 16
3658
        jnz    mres
3659
        xor    ecx, ecx
3660
        inc    edx
3661
        cmp    edx, 24
3662
        jnz    mres
3663
        ;sti    ; !!!****
3664
 
3665
        popad
3666
 
3667
;        sti
3668
 
3669
        ret
3670
 
3671
 
3672
save_draw_mouse:
3673
 
3674
        ; save & draw
3675
;        cli
3676
 
3677
        mov    [0xfb4a],ax
3678
        mov    [0xfb4c],bx
3679
        push   eax
3680
        push   ebx
3681
        mov    ecx,0
3682
        mov    edx,0
3683
 
3684
        ;cli ; !!!****
3685
 
3686
      drm:
3687
 
3688
        push   eax
3689
        push   ebx
3690
        push   ecx
3691
        push   edx
3692
 
3693
        ; helloworld
3694
        push   eax ebx ecx
3695
        add    eax,ecx  ; save picture under mouse
3696
        add    ebx,edx
3697
        push   ecx
3698
        call   getpixel
3699
        mov    [0xfb30],ecx
3700
        pop    ecx
3701
        mov    eax,edx
3702
        shl    eax,6
3703
        shl    ecx,2
3704
        add    eax,ecx
3705
        add    eax,mouseunder
3706
        mov    ebx,[0xfb30]
3707
        mov    [eax],ebx
3708
        pop    ecx ebx eax
3709
 
3710
        mov    edi,edx       ; y cycle
3711
        shl    edi,4       ; *16 bytes per row
3712
        add    edi,ecx       ; x cycle
3713
        mov    esi, edi
3714
        add    edi, esi
3715
        add    edi, esi       ; *3
3716
        add    edi,[0xf200]      ; we have our str address
3717
        mov    esi, edi
3718
        add    esi, 16*24*3
3719
        push   ecx
3720
        mov    ecx, [0xfb30]
3721
        call   combine_colors
3722
        mov    [0xfb10], ecx
3723
        pop    ecx
3724
 
3725
 
3726
        pop    edx
3727
        pop    ecx
3728
        pop    ebx
3729
        pop    eax
3730
 
3731
        add    eax,ecx       ; we have x coord+cycle
3732
        add    ebx,edx       ; and y coord+cycle
3733
 
3734
        push   ecx edi
3735
        mov    ecx, [0xfb10]
3736
        mov    edi, 1
3737
        call   [putpixel]
3738
        pop    edi ecx
3739
 
3740
      mnext:
3741
 
3742
        mov    ebx,[esp+0]      ; pure y coord again
3743
        mov    eax,[esp+4]      ; and x
3744
 
3745
        inc    ecx          ; +1 cycle
3746
        cmp    ecx,16       ; if more than 16
3747
        jnz    drm
3748
        xor    ecx, ecx
3749
        inc    edx
3750
        cmp    edx,24
3751
        jnz    drm
3752
 
3753
        pop    ebx
3754
        pop    eax
3755
 
3756
;        sti ; !!!****
3757
 
3758
        ret
3759
 
3760
 
3761
combine_colors:
3762
 
3763
      ; in
3764
      ; ecx - color ( 00 RR GG BB )
3765
      ; edi - ref to new color byte
3766
      ; esi - ref to alpha byte
3767
      ;
3768
      ; out
3769
      ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
3770
 
3771
      push eax
3772
      push ebx
3773
      push edx
3774
      push ecx
3775
      xor ecx, ecx
3776
         ; byte 2
3777
      mov eax, 0xff
3778
      sub al, [esi+0]
3779
      mov ebx, [esp]
3780
      shr ebx, 16
3781
      and ebx, 0xff
3782
      mul ebx
3783
      shr eax, 8
3784
      add ecx, eax
3785
;      xor eax, eax
3786
;      xor ebx, ebx
3787
;      mov al, [edi+0]
3788
;      mov bl, [esi+0]
3789
    movzx eax, byte [edi+0]
3790
    movzx ebx, byte [esi+0]
3791
      mul ebx
3792
      shr eax, 8
3793
      add ecx, eax
3794
      shl ecx, 8
3795
         ; byte 1
3796
      mov eax, 0xff
3797
      sub al, [esi+1]
3798
      mov ebx, [esp]
3799
      shr ebx, 8
3800
      and ebx, 0xff
3801
      mul ebx
3802
      shr eax, 8
3803
      add ecx, eax
3804
;      xor eax, eax
3805
;      xor ebx, ebx
3806
;      mov al, [edi+1]
3807
;      mov bl, [esi+1]
3808
    movzx eax, byte [edi+1]
3809
    movzx ebx, byte [esi+1]
3810
      mul ebx
3811
      shr eax, 8
3812
      add ecx, eax
3813
      shl ecx, 8
3814
         ; byte 2
3815
      mov eax, 0xff
3816
      sub al, [esi+2]
3817
      mov ebx, [esp]
3818
      and ebx, 0xff
3819
      mul ebx
3820
      shr eax, 8
3821
      add ecx, eax
3822
;      xor eax, eax
3823
;      xor ebx, ebx
3824
;      mov al, [edi+2]
3825
;      mov bl, [esi+2]
3826
    movzx eax, byte [edi+2]
3827
    movzx ebx, byte [esi+2]
3828
      mul ebx
3829
      shr eax, 8
3830
      add ecx, eax
3831
 
3832
      pop eax
3833
      pop edx
3834
      pop ebx
3835
      pop eax
3836
      ret
3837
 
3838
 
3839
__sys_disable_mouse:
3840
 
3841
      pushad
3842
 
3843
      cmp  [0x3000],dword 1
3844
      je   disable_m
3845
 
3846
      mov  edx,[0x3000]
3847
      shl  edx,5
3848
      add  edx,window_data
3849
 
3850
      movzx  eax, word [0xfb0a]
3851
      movzx  ebx, word [0xfb0c]
3852
 
3853
      mov  ecx,[0xfe00]
3854
      inc  ecx
3855
      imul  ecx,ebx
3856
      add  ecx,eax
3857
      add  ecx, display_data
3858
 
3859
      movzx eax, byte [edx+twdw+0xe]
3860
 
3861
      movzx ebx, byte [ecx]
3862
      cmp   eax,ebx
3863
      je    yes_mouse_disable
3864
      movzx ebx, byte [ecx+16]
3865
      cmp   eax,ebx
3866
      je    yes_mouse_disable
3867
 
3868
      mov   ebx,[0xfe00]
3869
      inc   ebx
3870
      imul  ebx,10
3871
      add   ecx,ebx
3872
 
3873
      movzx ebx, byte [ecx]
3874
      cmp   eax,ebx
3875
      je    yes_mouse_disable
3876
 
3877
      mov   ebx,[0xfe00]
3878
      inc   ebx
3879
      imul  ebx,10
3880
      add   ecx,ebx
3881
 
3882
      movzx ebx, byte [ecx]
3883
      cmp   eax,ebx
3884
      je    yes_mouse_disable
3885
      movzx ebx, byte [ecx+16]
3886
      cmp   eax,ebx
3887
      je    yes_mouse_disable
3888
 
3889
      jmp   no_mouse_disable
3890
 
3891
    yes_mouse_disable:
3892
 
3893
      mov  edx,[0x3000]
3894
      shl  edx,5
3895
      add  edx,window_data
3896
 
3897
      movzx  eax, word [0xfb0a]
3898
      movzx  ebx, word [0xfb0c]
3899
 
3900
      mov  ecx,[edx+0]   ; mouse inside the area ?
3901
      add  eax,14
3902
      cmp  eax,ecx
3903
      jb   no_mouse_disable
3904
      sub  eax,14
3905
 
3906
      add  ecx,[edx+8]
3907
      cmp  eax,ecx
3908
      jg   no_mouse_disable
3909
 
3910
      mov  ecx,[edx+4]
3911
      add  ebx,20
3912
      cmp  ebx,ecx
3913
      jb   no_mouse_disable
3914
      sub  ebx,20
3915
 
3916
      add  ecx,[edx+12]
3917
      cmp  ebx,ecx
3918
      jg   no_mouse_disable
3919
 
3920
    disable_m:
3921
 
3922
      cmp  dword [0xf204],dword 0
3923
      jne  @f
3924
      call draw_mouse_under
3925
    @@:
3926
 
3927
      mov  [0xf204],dword 1
3928
 
3929
    no_mouse_disable:
3930
 
3931
      popad
3932
 
3933
      ret
3934
 
3935
 
3936
 
3937
__sys_draw_pointer:
3938
        cli
3939
 
3940
        pushad
3941
 
3942
        cmp    dword [0xf204],dword 0  ; mouse visible ?
3943
        je     chms00
3944
 
3945
        dec    dword [0xf204]
3946
 
3947
        cmp    [0xf204],dword 0
3948
        jnz    nodmu2
3949
 
3950
        movzx  ebx,word [0xfb0c]
3951
        movzx  eax,word [0xfb0a]
3952
        call   save_draw_mouse
3953
 
3954
        popad
3955
        sti
3956
        ret
3957
 
3958
      nodmu2:
3959
 
3960
        popad
3961
        sti
3962
        ret
3963
 
3964
      chms00:
3965
 
3966
;        popad
3967
 
3968
;        pushad
3969
 
3970
;        cmp   [0xf204],dword 0
3971
;        jne   nodmp
3972
 
3973
        movzx  ecx,word [0xfb4a]
3974
        movzx  edx,word [0xfb4c]
3975
 
3976
        movzx  ebx,word [0xfb0c]
3977
        movzx  eax,word [0xfb0a]
3978
 
3979
        cmp    eax,ecx
3980
        jne    redrawmouse
3981
 
3982
        cmp    ebx,edx
3983
        jne    redrawmouse
3984
 
3985
        jmp    nodmp
3986
 
3987
      redrawmouse:
3988
 
3989
 
3990
        call   draw_mouse_under
3991
redrawmouse_1:
3992
        call   save_draw_mouse
3993
 
3994
     nodmp:
3995
 
3996
        popad
3997
        sti
3998
        ret
3999
 
4000
 
4001
 
4002
calculatebackground:   ; background
4003
 
4004
        ; all black
4005
 
4006
        mov   [display_data-8],dword 4      ; size x
4007
        mov   [display_data-4],dword 2      ; size y
4008
 
4009
        mov   edi, 0x300000                 ; set background to black
4010
        xor   eax, eax
4011
        mov   ecx, 0x0fff00 / 4
4012
        cld
4013
        rep   stosd
4014
 
4015
        mov   edi,display_data              ; set os to use all pixels
4016
        mov   eax,0x01010101
4017
        mov   ecx,0x1fff00 / 4
4018
        rep   stosd
4019
 
4020
        mov   byte [0xFFF0], 0              ; do not draw background!
4021
 
4022
        ret
4023
 
4024
uglobal
4025
  imax    dd 0x0
4026
endg
4027
 
4028
 
4029
 
4030
delay_ms:     ; delay in 1/1000 sec
4031
 
4032
 
4033
        push  eax
4034
        push  ecx
4035
 
4036
        mov   ecx,esi
4037
        ; 
4038
        imul  ecx, 33941
4039
        shr   ecx, 9
4040
        ; 
4041
 
4042
        in    al,0x61
4043
        and   al,0x10
4044
        mov   ah,al
4045
        cld
4046
 
4047
 cnt1:  in    al,0x61
4048
        and   al,0x10
4049
        cmp   al,ah
4050
        jz    cnt1
4051
 
4052
        mov   ah,al
4053
        loop  cnt1
4054
 
4055
        pop   ecx
4056
        pop   eax
4057
 
4058
        ret
4059
 
4060
 
4061
set_app_param:
4062
        push edi
4063
 
4064
        mov  edi,[0x3010]
4065
        mov  [edi],eax
4066
 
4067
        pop  edi
4068
        ret
4069
 
4070
 
4071
 
4072
delay_hs:     ; delay in 1/100 secs
4073
        push  eax
4074
        push  ecx
4075
        push  edx
4076
 
4077
        mov   edx,[timer_ticks];[0xfdf0]
4078
        add   edx,eax
4079
 
4080
      newtic:
4081
        mov   ecx,[timer_ticks];[0xfdf0]
4082
        cmp   edx,ecx
4083
        jbe   zerodelay
4084
 
4085
        call  change_task
4086
 
4087
        jmp   newtic
4088
 
4089
      zerodelay:
4090
        pop   edx
4091
        pop   ecx
4092
        pop   eax
4093
 
4094
        ret
4095
 
4096
 
4097
memmove:       ; memory move in bytes
4098
 
4099
; eax = from
4100
; ebx = to
4101
; ecx = no of bytes
4102
    test ecx, ecx
4103
    jle  .ret
4104
 
4105
 
4106
    push esi edi ecx
4107
 
4108
    mov  edi, ebx
4109
    mov  esi, eax
4110
 
4111
    test ecx, not 11b
4112
    jz   @f
4113
 
4114
    push ecx
4115
    shr  ecx, 2
4116
    rep  movsd
4117
    pop  ecx
4118
    and  ecx, 11b
4119
    jz   .finish
4120
  @@:
4121
    rep  movsb
4122
 
4123
  .finish:
4124
    pop  ecx edi esi
4125
  .ret:
4126
    ret
4127
 
4128
 
4129
align 4
4130
 
4131
read_floppy_file:
4132
 
4133
; as input
4134
;
4135
; eax pointer to file
4136
; ebx file lenght
4137
; ecx start 512 byte block number
4138
; edx number of blocks to read
4139
; esi pointer to return/work area (atleast 20 000 bytes)
4140
;
4141
;
4142
; on return
4143
;
4144
; eax = 0 command succesful
4145
;       1 no fd base and/or partition defined
4146
;       2 yet unsupported FS
4147
;       3 unknown FS
4148
;       4 partition not defined at hd
4149
;       5 file not found
4150
; ebx = size of file
4151
 
4152
     mov   edi,[0x3010]
4153
     add   edi,0x10
4154
     add   esi,[edi]
4155
     add   eax,[edi]
4156
 
4157
     pushad
4158
     mov  edi,esi
4159
     add  edi,1024
4160
     mov  esi,0x100000+19*512
4161
     sub  ecx,1
4162
     shl  ecx,9
4163
     add  esi,ecx
4164
     shl  edx,9
4165
     mov  ecx,edx
4166
     cld
4167
     rep  movsb
4168
     popad
4169
 
4170
     mov   [esp+36],eax
4171
     mov   [esp+24],ebx
4172
     ret
4173
 
4174
 
4175
 
4176
align 4
4177
 
4178
sys_programirq:
4179
 
4180
    mov   edi,[0x3010]
4181
    add   edi,0x10
4182
    add   eax,[edi]
4183
 
4184
    mov   edx,ebx
4185
    shl   edx,2
4186
    add   edx,irq_owner
4187
    mov   edx,[edx]
4188
    mov   edi,[0x3010]
4189
    mov   edi,[edi+0x4]
4190
    cmp   edx,edi
4191
    je    spril1
4192
    mov   [esp+36],dword 1
4193
    ret
4194
  spril1:
4195
 
4196
    mov   esi,eax
4197
    shl   ebx,6
4198
    add   ebx,irq00read
4199
    mov   edi,ebx
4200
    mov   ecx,16
4201
    cld
4202
    rep   movsd
4203
    mov   [esp+36],dword 0
4204
    ret
4205
 
4206
 
4207
align 4
4208
 
4209
get_irq_data:
4210
 
4211
     mov   edx,eax           ; check for correct owner
4212
     shl   edx,2
4213
     add   edx,irq_owner
4214
     mov   edx,[edx]
4215
     mov   edi,[0x3010]
4216
     mov   edi,[edi+0x4]
4217
     cmp   edx,edi
4218
     je    gidril1
4219
     mov   [esp+36],eax
4220
     mov   [esp+32],dword 2
4221
     mov   [esp+24],ebx
4222
     ret
4223
 
4224
  gidril1:
4225
 
4226
     mov   ebx,eax
4227
     shl   ebx,12
4228
     add   ebx,0x2e0000
4229
     mov   eax,[ebx]
4230
     mov   ecx,1
4231
     test  eax,eax
4232
     jz    gid1
4233
 
4234
     dec   eax
4235
     mov   esi,ebx
4236
     mov   [ebx],eax
4237
     movzx ebx,byte [ebx+0x10]
4238
     add   esi,0x10
4239
     mov   edi,esi
4240
     inc   esi
4241
     mov   ecx,4000 / 4
4242
     cld
4243
     rep   movsd
4244
     xor   ecx,ecx
4245
   gid1:
4246
     mov   [esp+36],eax
4247
     mov   [esp+32],ecx
4248
     mov   [esp+24],ebx
4249
     ret
4250
 
4251
 
4252
set_io_access_rights:
4253
 
4254
     pushad
4255
 
4256
     mov   edi,[0x3000]
4257
     imul  edi,tss_step
4258
     add   edi,tss_data+128
4259
;     add   edi,128
4260
 
4261
     mov   ecx,eax
4262
     and   ecx,7    ; offset in byte
4263
 
4264
     shr   eax,3    ; number of byte
4265
     add   edi,eax
4266
 
4267
     mov   ebx,1
4268
     shl   ebx,cl
4269
 
4270
     cmp   ebp,0                ; enable access - ebp = 0
4271
     jne   siar1
4272
 
4273
     not   ebx
4274
     and   [edi],byte bl
4275
 
4276
     popad
4277
 
4278
     ret
4279
 
4280
   siar1:
4281
 
4282
     or    [edi],byte bl        ; disable access - ebp = 1
4283
 
4284
     popad
4285
 
4286
     ret
4287
 
4288
 
4289
 
4290
 
4291
 
4292
r_f_port_area:
4293
 
4294
     test  eax, eax
4295
     jnz   free_port_area
4296
;     je    r_port_area
4297
;     jmp   free_port_area
4298
 
4299
;   r_port_area:
4300
 
4301
     pushad
4302
 
4303
     cmp   ebx,ecx            ; beginning > end ?
4304
     jg    rpal1
4305
     mov   esi,[0x2d0000]
4306
     cmp   esi,0              ; no reserved areas ?
4307
     je    rpal2
4308
     cmp   esi,255            ; max reserved
4309
     jge   rpal1
4310
   rpal3:
4311
     mov   edi,esi
4312
     shl   edi,4
4313
     add   edi,0x2d0000
4314
     cmp   ebx,[edi+8]
4315
     jg    rpal4
4316
     cmp   ecx,[edi+4]
4317
     jae   rpal1
4318
;     jb    rpal4
4319
;     jmp   rpal1
4320
   rpal4:
4321
 
4322
     dec   esi
4323
     jnz   rpal3
4324
     jmp   rpal2
4325
   rpal1:
4326
     popad
4327
     mov   eax,1
4328
     ret
4329
 
4330
   rpal2:
4331
     popad
4332
 
4333
 
4334
     ; enable port access at port IO map
4335
     cli
4336
     pushad                        ; start enable io map
4337
 
4338
     cmp   ecx,65536 ;16384
4339
     jae   no_unmask_io ; jge
4340
 
4341
     mov   eax,ebx
4342
 
4343
   new_port_access:
4344
 
4345
     pushad
4346
 
4347
     mov   ebp,0                  ; enable - eax = port
4348
     call  set_io_access_rights
4349
 
4350
     popad
4351
 
4352
     inc   eax
4353
     cmp   eax,ecx
4354
     jbe   new_port_access
4355
 
4356
   no_unmask_io:
4357
 
4358
     popad                         ; end enable io map
4359
     sti
4360
 
4361
     mov   edi,[0x2d0000]
4362
     add   edi,1
4363
     mov   [0x2d0000],edi
4364
     shl   edi,4
4365
     add   edi,0x2d0000
4366
     mov   esi,[0x3010]
4367
     mov   esi,[esi+0x4]
4368
     mov   [edi],esi
4369
     mov   [edi+4],ebx
4370
     mov   [edi+8],ecx
4371
 
4372
     xor   eax, eax
4373
     ret
4374
 
4375
 
4376
 
4377
 
4378
free_port_area:
4379
 
4380
     pushad
4381
 
4382
     mov   esi,[0x2d0000]     ; no reserved areas ?
4383
     cmp   esi,0
4384
     je    frpal2
4385
     mov   edx,[0x3010]
4386
     mov   edx,[edx+4]
4387
   frpal3:
4388
     mov   edi,esi
4389
     shl   edi,4
4390
     add   edi,0x2d0000
4391
     cmp   edx,[edi]
4392
     jne   frpal4
4393
     cmp   ebx,[edi+4]
4394
     jne   frpal4
4395
     cmp   ecx,[edi+8]
4396
     jne   frpal4
4397
     jmp   frpal1
4398
   frpal4:
4399
     dec   esi
4400
     jnz   frpal3
4401
   frpal2:
4402
     popad
4403
     mov   eax,1
4404
     ret
4405
   frpal1:
4406
     mov   ecx,256
4407
     sub   ecx,esi
4408
     shl   ecx,4
4409
     mov   esi,edi
4410
     add   esi,16
4411
     cld
4412
     rep   movsb
4413
 
4414
     dec   dword [0x2d0000]
4415
 
4416
     popad
4417
 
4418
 
4419
     ; disable port access at port IO map
4420
 
4421
     pushad                        ; start disable io map
4422
 
4423
     cmp   ecx,65536 ;16384
4424
     jge   no_mask_io
4425
 
4426
     mov   eax,ebx
4427
 
4428
   new_port_access_disable:
4429
 
4430
     pushad
4431
 
4432
     mov   ebp,1                  ; disable - eax = port
4433
     call  set_io_access_rights
4434
 
4435
     popad
4436
 
4437
     inc   eax
4438
     cmp   eax,ecx
4439
     jbe   new_port_access_disable
4440
 
4441
   no_mask_io:
4442
 
4443
     popad                         ; end disable io map
4444
 
4445
     xor   eax, eax
4446
     ret
4447
 
4448
 
4449
reserve_free_irq:
4450
 
4451
     cmp   eax,0
4452
     jz    reserve_irq
4453
 
4454
     mov   edi,ebx
4455
     shl   edi,2
4456
     add   edi,irq_owner
4457
     mov   edx,[edi]
4458
     mov   eax,[0x3010]
4459
     mov   eax,[eax+0x4]
4460
     mov   ecx,1
4461
     cmp   edx,eax
4462
     jne   fril1
4463
     mov   [edi],dword 0
4464
     mov   ecx,0
4465
   fril1:
4466
     mov   [esp+36],ecx ; return in eax
4467
     ret
4468
 
4469
  reserve_irq:
4470
 
4471
     mov   edi,ebx
4472
     shl   edi,2
4473
     add   edi,irq_owner
4474
     mov   edx,[edi]
4475
     mov   ecx,1
4476
     cmp   edx,0
4477
     jne   ril1
4478
 
4479
     mov   edx,[0x3010]
4480
     mov   edx,[edx+0x4]
4481
     mov   [edi],edx
4482
     mov   ecx,0
4483
 
4484
   ril1:
4485
 
4486
     mov   [esp+36],ecx ; return in eax
4487
 
4488
     ret
4489
 
4490
 
4491
 
4492
drawbackground:
4493
 
4494
       cmp   [0xfe0c],word 0x12
4495
       jne   dbrv12
4496
       cmp   [display_data-12],dword 1
4497
       jne   bgrstr12
4498
       call  vga_drawbackground_tiled
4499
       ret
4500
     bgrstr12:
4501
       call  vga_drawbackground_stretch
4502
       ret
4503
     dbrv12:
4504
 
4505
       cmp  [0xfe0c],word 0100000000000000b
4506
       jge  dbrv20
4507
       cmp  [0xfe0c],word 0x13
4508
       je   dbrv20
4509
       call  vesa12_drawbackground
4510
       ret
4511
     dbrv20:
4512
       cmp   [display_data-12],dword 1
4513
       jne   bgrstr
4514
       call  vesa20_drawbackground_tiled
4515
       ret
4516
     bgrstr:
4517
       call  vesa20_drawbackground_stretch
4518
       ret
4519
 
4520
 
4521
sys_putimage:
4522
 
4523
     cmp   [0xfe0c],word 0x12
4524
     jne   spiv20
4525
     call  vga_putimage
4526
     ret
4527
   spiv20:
4528
 
4529
     cmp   [0xfe0c],word 0100000000000000b
4530
     jge   piv20
4531
     cmp   [0xfe0c],word 0x13
4532
     je    piv20
4533
     call  vesa12_putimage
4534
     ret
4535
   piv20:
4536
     call  vesa20_putimage
4537
     ret
4538
 
4539
 
4540
 
4541
; eax x beginning
4542
; ebx y beginning
4543
; ecx x end
4544
; edx y end
4545
; edi color
4546
 
4547
__sys_drawbar:
4548
 
4549
     cmp   [0xfe0c],word 0x12
4550
     jne   sdbv20
4551
     call  vga_drawbar
4552
     ret
4553
   sdbv20:
4554
 
4555
    cmp  [0xfe0c],word 0100000000000000b
4556
    jge  dbv20
4557
    cmp  [0xfe0c],word 0x13
4558
    je   dbv20
4559
    call vesa12_drawbar
4560
    ret
4561
 
4562
  dbv20:
4563
 
4564
    call vesa20_drawbar
4565
    ret
4566
 
4567
 
4568
 
4569
kb_read:
4570
 
4571
        push    ecx edx
4572
 
4573
        mov     ecx,0xffff
4574
      kr_loop:
4575
        in      al,0x64
4576
        test    al,1
4577
        jnz     kr_ready
4578
        loop    kr_loop
4579
        mov     ah,1
4580
        jmp     kr_exit
4581
      kr_ready:
4582
        push    ecx
4583
        mov     ecx,32
4584
      kr_delay:
4585
        loop    kr_delay
4586
        pop     ecx
4587
        in      al,0x60
4588
        xor     ah,ah
4589
      kr_exit:
4590
 
4591
        pop     edx ecx
4592
 
4593
        ret
4594
 
4595
 
4596
kb_write:
4597
 
4598
        push    ecx edx
4599
 
4600
        mov     dl,al
4601
        mov     ecx,0xffff
4602
      kw_loop1:
4603
        in      al,0x64
4604
        test    al,0x20
4605
        jz      kw_ok1
4606
        loop    kw_loop1
4607
        mov     ah,1
4608
        jmp     kw_exit
4609
      kw_ok1:
4610
        in      al,0x60
4611
        mov     ecx,0xffff
4612
      kw_loop:
4613
        in      al,0x64
4614
        test    al,2
4615
        jz      kw_ok
4616
        loop    kw_loop
4617
        mov     ah,1
4618
        jmp     kw_exit
4619
      kw_ok:
4620
        mov     al,dl
4621
        out     0x60,al
4622
        mov     ecx,0xffff
4623
      kw_loop3:
4624
        in      al,0x64
4625
        test    al,2
4626
        jz      kw_ok3
4627
        loop    kw_loop3
4628
        mov     ah,1
4629
        jmp     kw_exit
4630
      kw_ok3:
4631
        mov     ah,8
4632
      kw_loop4:
4633
        mov     ecx,0xffff
4634
      kw_loop5:
4635
        in      al,0x64
4636
        test    al,1
4637
        jnz     kw_ok4
4638
        loop    kw_loop5
4639
        dec     ah
4640
        jnz     kw_loop4
4641
      kw_ok4:
4642
        xor     ah,ah
4643
      kw_exit:
4644
 
4645
        pop     edx ecx
4646
 
4647
        ret
4648
 
4649
 
4650
kb_cmd:
4651
 
4652
        mov     ecx,0xffff
4653
      c_wait:
4654
        in      al,0x64
4655
        test    al,2
4656
        jz      c_send
4657
        loop    c_wait
4658
        jmp     c_error
4659
      c_send:
4660
        mov     al,bl
4661
        out     0x64,al
4662
        mov     ecx,0xffff
4663
      c_accept:
4664
        in      al,0x64
4665
        test    al,2
4666
        jz      c_ok
4667
        loop    c_accept
4668
      c_error:
4669
        mov     ah,1
4670
        jmp     c_exit
4671
      c_ok:
4672
        xor     ah,ah
4673
      c_exit:
4674
        ret
4675
 
4676
 
4677
setmouse:  ; set mousepicture -pointer
4678
           ; ps2 mouse enable
4679
 
4680
     mov     [0xf200],dword mousepointer
4681
 
4682
     cli
4683
     mov     bl,0xa8                 ; enable mouse cmd
4684
     call    kb_cmd
4685
     call    kb_read                 ; read status
4686
 
4687
     mov     bl,0x20                 ; get command byte
4688
     call    kb_cmd
4689
     call    kb_read
4690
     or      al,3                    ; enable interrupt
4691
     mov     bl,0x60                 ; write command
4692
     push    eax
4693
     call    kb_cmd
4694
     pop     eax
4695
     call    kb_write
4696
 
4697
     mov     bl,0xd4                 ; for mouse
4698
     call    kb_cmd
4699
     mov     al,0xf4                 ; enable mouse device
4700
     call    kb_write
4701
     call    kb_read           ; read status return
4702
 
4703
     ; com1 mouse enable
4704
 
4705
     mov   bx,0x3f8 ; combase
4706
 
4707
     mov   dx,bx
4708
     add   dx,3
4709
     mov   al,0x80
4710
     out   dx,al
4711
 
4712
     mov   dx,bx
4713
     add   dx,1
4714
     mov   al,0
4715
     out   dx,al
4716
 
4717
     mov   dx,bx
4718
     add   dx,0
4719
     mov   al,0x30*2    ; 0x30 / 4
4720
     out   dx,al
4721
 
4722
     mov   dx,bx
4723
     add   dx,3
4724
     mov   al,2         ; 3
4725
     out   dx,al
4726
 
4727
     mov   dx,bx
4728
     add   dx,4
4729
     mov   al,0xb
4730
     out   dx,al
4731
 
4732
     mov   dx,bx
4733
     add   dx,1
4734
     mov   al,1
4735
     out   dx,al
4736
 
4737
 
4738
     ; com2 mouse enable
4739
 
4740
     mov   bx,0x2f8 ; combase
4741
 
4742
     mov   dx,bx
4743
     add   dx,3
4744
     mov   al,0x80
4745
     out   dx,al
4746
 
4747
     mov   dx,bx
4748
     add   dx,1
4749
     mov   al,0
4750
     out   dx,al
4751
 
4752
     mov   dx,bx
4753
     add   dx,0
4754
     mov   al,0x30*2
4755
     out   dx,al
4756
 
4757
     mov   dx,bx
4758
     add   dx,3
4759
     mov   al,2
4760
     out   dx,al
4761
 
4762
     mov   dx,bx
4763
     add   dx,4
4764
     mov   al,0xb
4765
     out   dx,al
4766
 
4767
     mov   dx,bx
4768
     add   dx,1
4769
     mov   al,1
4770
     out   dx,al
4771
 
4772
     ret
4773
 
4774
 
4775
_rdtsc:
4776
 
4777
     mov   edx,[cpuid_1+3*4]
4778
     test  edx,00010000b
4779
     jz    ret_rdtsc
4780
     rdtsc
4781
     ret
4782
   ret_rdtsc:
4783
     mov   edx,0xffffffff
4784
     mov   eax,0xffffffff
4785
     ret
4786
 
4787
 
4788
 
4789
rerouteirqs:
4790
 
4791
        cli
4792
 
4793
        mov     al,0x11         ;  icw4, edge triggered
4794
        out     0x20,al
4795
        call    pic_delay
4796
        out     0xA0,al
4797
        call    pic_delay
4798
 
4799
        mov     al,0x20         ;  generate 0x20 +
4800
        out     0x21,al
4801
        call    pic_delay
4802
        mov     al,0x28         ;  generate 0x28 +
4803
        out     0xA1,al
4804
        call    pic_delay
4805
 
4806
        mov     al,0x04         ;  slave at irq2
4807
        out     0x21,al
4808
        call    pic_delay
4809
        mov     al,0x02         ;  at irq9
4810
        out     0xA1,al
4811
        call    pic_delay
4812
 
4813
        mov     al,0x01         ;  8086 mode
4814
        out     0x21,al
4815
        call    pic_delay
4816
        out     0xA1,al
4817
        call    pic_delay
4818
 
4819
        mov     al,255          ; mask all irq's
4820
        out     0xA1,al
4821
        call    pic_delay
4822
        out     0x21,al
4823
        call    pic_delay
4824
 
4825
        mov     ecx,0x1000
4826
        cld
4827
picl1:  call    pic_delay
4828
        loop    picl1
4829
 
4830
        mov     al,255          ; mask all irq's
4831
        out     0xA1,al
4832
        call    pic_delay
4833
        out     0x21,al
4834
        call    pic_delay
4835
 
4836
        cli
4837
 
4838
        ret
4839
 
4840
 
4841
pic_delay:
4842
 
4843
        jmp     pdl1
4844
pdl1:   ret
4845
 
4846
 
4847
sys_msg_board_str:
4848
 
4849
     pushad
4850
   @@:
4851
     cmp    [esi],byte 0
4852
     je     @f
4853
     mov    eax,1
4854
     movzx  ebx,byte [esi]
4855
     call   sys_msg_board
4856
     inc    esi
4857
     jmp    @b
4858
   @@:
4859
     popad
4860
     ret
4861
 
4862
uglobal
4863
  msg_board_data: times 512 db 0
4864
  msg_board_count dd 0x0
4865
endg
4866
 
4867
sys_msg_board:
4868
 
4869
; eax=1 : write :  bl byte to write
4870
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4871
 
4872
     mov  ecx,[msg_board_count]
4873
     cmp  eax, 1
4874
     jne  smbl1
4875
 
4876
 
4877
     mov  [msg_board_data+ecx],bl
4878
     inc  ecx
4879
     and  ecx, 511
4880
     mov  [msg_board_count], ecx
4881
     mov  [check_idle_semaphore], 5
4882
     ret
4883
   smbl1:
4884
 
4885
     cmp   eax, 2
4886
     jne   smbl2
4887
     test  ecx, ecx
4888
     jz    smbl21
4889
;     mov   edi, msg_board_data
4890
;     mov   esi, msg_board_data+1
4891
;     movzx eax, byte [edi]
4892
     mov   eax, msg_board_data+1
4893
     mov   ebx, msg_board_data
4894
     movzx edx, byte [ebx]
4895
     call  memmove
4896
;     push  ecx
4897
;     shr   ecx, 2
4898
;     cld
4899
;     rep   movsd
4900
;     pop   ecx
4901
;     and   ecx, 3
4902
;     rep   movsb
4903
     dec   [msg_board_count]
4904
     mov   [esp+36], edx ;eax
4905
     mov   [esp+24], dword 1
4906
     ret
4907
   smbl21:
4908
     mov   [esp+36], ecx
4909
     mov   [esp+24], ecx
4910
 
4911
   smbl2:
4912
     ret
4913
 
4914
 
4915
 
4916
sys_trace:
4917
 
4918
     test eax, eax                  ; get event data
4919
     jnz  no_get_sys_events
4920
 
4921
     mov  esi,save_syscall_data     ; data
4922
     mov  edi,[0x3010]
4923
     mov  edi,[edi+0x10]
4924
     add  edi,ebx
4925
     cld
4926
     rep  movsb
4927
 
4928
     mov  [esp+24],dword 0
4929
     mov  eax,[save_syscall_count]  ; count
4930
     mov  [esp+36],eax
4931
     ret
4932
 
4933
   no_get_sys_events:
4934
 
4935
     ret
4936
 
4937
 
4938
sys_process_def:
4939
 
4940
     cmp   eax,1                   ; set keyboard mode
4941
     jne   no_set_keyboard_setup
4942
 
4943
     mov   edi,[0x3000]
4944
     shl   edi,8
4945
     add   edi,0x80000+0xB4
4946
     mov   [edi],bl
4947
 
4948
     ret
4949
 
4950
   no_set_keyboard_setup:
4951
 
4952
     cmp   eax,2                   ; get keyboard mode
4953
     jne   no_get_keyboard_setup
4954
 
4955
     mov   edi,[0x3000]
4956
     shl   edi,8
4957
     add   edi,0x80000+0xB4
4958
     movzx eax, byte [edi]
4959
 
4960
     mov   [esp+36],eax
4961
 
4962
     ret
4963
 
4964
   no_get_keyboard_setup:
4965
 
4966
     cmp   eax,3                   ; get keyboard ctrl, alt, shift
4967
     jne   no_get_keyboard_cas
4968
 
4969
;     xor   eax,eax
4970
;     movzx eax,byte [shift]
4971
;     movzx ebx,byte [ctrl]
4972
;     shl   ebx,2
4973
;     add   eax,ebx
4974
;     movzx ebx,byte [alt]
4975
;     shl   ebx,3
4976
;     add   eax,ebx
4977
 
4978
 ;// mike.dld [
4979
     mov   eax, [kb_state]
4980
 ;// mike.dld ]
4981
 
4982
     mov   [esp+36],eax
4983
 
4984
     ret
4985
 
4986
   no_get_keyboard_cas:
4987
 
4988
 
4989
     ret
4990
 
4991
 
4992
sys_ipc:
4993
     cmp  eax,1                      ; DEFINE IPC MEMORY
4994
     jne  no_ipc_def
4995
     mov  edi,[0x3000]
4996
     shl  edi,8
4997
     add  edi,0x80000
4998
     mov  [edi+0xA0],ebx
4999
     mov  [edi+0xA4],ecx
5000
     mov  [esp+36],dword 0
5001
     ret
5002
   no_ipc_def:
5003
 
5004
     cmp  eax,2                      ; SEND IPC MESSAGE
5005
     jne  no_ipc_send
5006
     mov  esi,1
5007
     mov  edi,0x3020
5008
    ipcs1:
5009
     cmp  [edi+4],ebx
5010
     je   ipcs2
5011
     add  edi,0x20
5012
     inc  esi
5013
     cmp  esi,[0x3004]
5014
     jbe  ipcs1
5015
     mov  [esp+36],dword 4
5016
     ret
5017
    ipcs2:
5018
 
5019
     cli
5020
 
5021
     push esi
5022
     mov  eax,esi
5023
     shl  eax,8
5024
     mov  ebx,[eax+0x80000+0xa0]
5025
     test ebx,ebx                  ; ipc area not defined ?
5026
     je   ipc_err1
5027
 
5028
     add  ebx,[eax+0x80000+0xa4]
5029
     mov  eax,esi
5030
     shl  eax,5
5031
     add  ebx,[eax+0x3000+0x10]    ; ebx <- max data position
5032
 
5033
     mov  eax,esi                  ; to
5034
     shl  esi,8
5035
     add  esi,0x80000
5036
     mov  edi,[esi+0xa0]
5037
     shl  eax,5
5038
     add  eax,0x3000
5039
     add  edi,[eax+0x10]
5040
 
5041
     cmp  [edi],byte 0             ; overrun ?
5042
     jne  ipc_err2
5043
 
5044
     mov  ebp,edi
5045
     add  edi,[edi+4]
5046
     add  edi,8
5047
 
5048
     mov  esi,ecx                  ; from
5049
     mov  eax,[0x3010]
5050
     mov  eax,[eax+0x10]
5051
     add  esi,eax
5052
 
5053
     mov  ecx,edx                  ; size
5054
 
5055
     mov  eax,edi
5056
     add  eax,ecx
5057
     cmp  eax,ebx
5058
     jge  ipc_err3                 ; not enough room ?
5059
 
5060
     push ecx
5061
 
5062
     mov  eax,[0x3010]
5063
     mov  eax,[eax+4]
5064
     mov  [edi-8],eax
5065
     mov  [edi-4],ecx
5066
     cld
5067
     rep  movsb
5068
 
5069
     pop  ecx
5070
     add  ecx,8
5071
 
5072
     mov  edi,ebp                  ; increase memory position
5073
     add  dword [edi+4],ecx
5074
 
5075
     mov  edi,[esp]
5076
     shl  edi,8
5077
     or   dword [edi+0x80000+0xA8],dword 01000000b ; ipc message
5078
 
5079
     cmp  [check_idle_semaphore],dword 20
5080
     jge  ipc_no_cis
5081
     mov  [check_idle_semaphore],5
5082
   ipc_no_cis:
5083
 
5084
     xor  eax, eax
5085
 
5086
    ipc_err:
5087
     add  esp,4
5088
     mov  [esp+36],eax
5089
     sti
5090
     ret
5091
 
5092
    ipc_err1:
5093
     add  esp,4
5094
     mov  [esp+36],dword 1
5095
     sti
5096
     ret
5097
    ipc_err2:
5098
     add  esp,4
5099
     mov  [esp+36],dword 2
5100
     sti
5101
     ret
5102
    ipc_err3:
5103
     add  esp,4
5104
     mov  [esp+36],dword 3
5105
     sti
5106
     ret
5107
 
5108
   no_ipc_send:
5109
 
5110
     mov  [esp+36],dword -1
5111
     ret
5112
 
5113
 
5114
align 4
5115
 
5116
sys_gs:                         ; direct screen access
5117
 
5118
     cmp  eax,1                 ; resolution
5119
     jne  no_gs1
5120
     mov  eax,[0xfe00]
5121
     shl  eax,16
5122
     mov  ax,[0xfe04]
5123
     add  eax,0x00010001
5124
     mov  [esp+36],eax
5125
     ret
5126
   no_gs1:
5127
 
5128
     cmp   eax,2                ; bits per pixel
5129
     jne   no_gs2
5130
     movzx eax,byte [0xfbf1]
5131
     mov   [esp+36],eax
5132
     ret
5133
   no_gs2:
5134
 
5135
     cmp   eax,3                ; bytes per scanline
5136
     jne   no_gs3
5137
     mov   eax,[0xfe08]
5138
     mov   [esp+36],eax
5139
     ret
5140
   no_gs3:
5141
 
5142
     mov  [esp+36],dword -1
5143
     ret
5144
 
5145
 
5146
align 4 ; PCI functions
5147
 
5148
sys_pci:
5149
 
5150
     call  pci_api
5151
     mov   [esp+36],eax
5152
     ret
5153
 
5154
 
5155
align 4  ;  system functions
5156
 
5157
syscall_setpixel:                       ; SetPixel
5158
 
5159
 
5160
     mov   edx,[0x3010]
5161
     add   eax,[edx-twdw]
5162
     add   ebx,[edx-twdw+4]
5163
     xor   edi,edi ; no force
5164
     call  [disable_mouse]
5165
     jmp   [putpixel]
5166
 
5167
align 4
5168
 
5169
syscall_writetext:                      ; WriteText
5170
 
5171
     mov   edi,[0x3010]
5172
     mov   ebp,[edi-twdw]
5173
     shl   ebp,16
5174
     add   ebp,[edi-twdw+4]
5175
     add   edi,0x10
5176
     add   ecx,[edi]
5177
     add   eax,ebp
5178
     xor   edi,edi
5179
     jmp   dtext
5180
 
5181
align 4
5182
 
5183
syscall_openramdiskfile:                ; OpenRamdiskFile
5184
 
5185
 
5186
     mov   edi,[0x3010]
5187
     add   edi,0x10
5188
     add   eax,[edi]
5189
     add   edx,[edi]
5190
     mov   esi,12
5191
     call  fileread
5192
     mov   [esp+36],ebx
5193
     ret
5194
 
5195
align 4
5196
 
5197
syscall_putimage:                       ; PutImage
5198
 
5199
     mov   edi,[0x3010]
5200
     add   edi,0x10
5201
     add   eax,[edi]
5202
     mov   edx,ecx
5203
     mov   ecx,ebx
5204
     mov   ebx,eax
5205
     call  sys_putimage
5206
     mov   [esp+36],eax
5207
     ret
5208
 
5209
align 4
5210
 
5211
syscall_drawrect:                       ; DrawRect
5212
 
5213
     mov   edi,ecx
5214
     test  ax,ax
5215
     je    drectr
5216
     test  bx,bx
5217
     je    drectr
5218
     movzx ecx,ax
5219
     shr   eax,16
5220
     movzx edx,bx
5221
     shr   ebx,16
5222
     add   ecx,eax
5223
     add   edx,ebx
5224
     jmp   [drawbar]
5225
    drectr:
5226
     ret
5227
 
5228
align 4
5229
 
5230
syscall_getscreensize:                  ; GetScreenSize
5231
 
5232
     movzx eax,word[0xfe00]
5233
     shl   eax,16
5234
     mov   ax,[0xfe04]
5235
     mov   [esp+36],eax
5236
     ret
5237
 
5238
align 4
5239
 
5240
syscall_system:                         ; System
5241
 
5242
     call  sys_system
5243
     mov   [esp+36],eax
5244
     ret
5245
 
5246
align 4
5247
 
5248
syscall_startapp:                       ; StartApp
5249
     mov   edi,[0x3010]
5250
     add   edi,0x10
5251
     add   eax,[edi]
5252
     test  ebx,ebx
5253
     jz    noapppar
5254
     add   ebx,[edi]
5255
   noapppar:
5256
;     call  start_application_fl
5257
     call   new_start_application_fl
5258
     mov   [esp+36],eax
5259
     ret
5260
 
5261
 
5262
align 4
5263
 
5264
syscall_cdaudio:                        ; CD
5265
 
5266
     call  sys_cd_audio
5267
     mov   [esp+36],eax
5268
     ret
5269
 
5270
align 4
5271
 
5272
syscall_readhd:                         ; ReadHd
5273
 
5274
     mov   edi,[0x3010]
5275
     add   edi,0x10
5276
     add   esi,[edi]
5277
     add   eax,[edi]
5278
     call  read_hd_file
5279
     mov   [esp+36],eax
5280
     mov   [esp+24],ebx
5281
     ret
5282
 
5283
align 4
5284
 
5285
syscall_starthdapp:                     ; StartHdApp
5286
 
5287
     mov   edi,[0x3010]
5288
     add   edi,0x10
5289
     add   eax,[edi]
5290
     add   ecx,[edi]
5291
     mov   ebp,0
5292
     call  start_application_hd
5293
     mov   [esp+36],eax
5294
     ret
5295
 
5296
align 4
5297
 
5298
syscall_delramdiskfile:                 ; DelRamdiskFile
5299
 
5300
     mov   edi,[0x3010]
5301
     add   edi,0x10
5302
     add   eax,[edi]
5303
     call  filedelete
5304
     mov   [esp+36],eax
5305
     ret
5306
 
5307
align 4
5308
 
5309
syscall_writeramdiskfile:               ; WriteRamdiskFile
5310
 
5311
     mov   edi,[0x3010]
5312
     add   edi,0x10
5313
     add   eax,[edi]
5314
     add   ebx,[edi]
5315
     call  filesave
5316
     mov   [esp+36],eax
5317
     ret
5318
 
5319
align 4
5320
 
5321
syscall_getpixel:                       ; GetPixel
5322
 
5323
     mov   ecx,[0xfe00]
5324
     inc   ecx
5325
     xor   edx,edx
5326
     div   ecx
5327
     mov   ebx,edx
5328
     xchg  eax,ebx
5329
     call  dword [0xe024]
5330
     mov   [esp+36],ecx
5331
     ret
5332
 
5333
align 4
5334
 
5335
syscall_readstring:                     ; ReadString
5336
 
5337
     mov   edi,[0x3010]
5338
     add   edi,0x10
5339
     add   eax,[edi]
5340
     call  read_string
5341
     mov   [esp+36],eax
5342
     ret
5343
 
5344
align 4
5345
 
5346
syscall_drawline:                       ; DrawLine
5347
 
5348
     mov   edi,[0x3010]
5349
     movzx edx,word[edi-twdw]
5350
     mov   ebp,edx
5351
     shl   edx,16
5352
     add   ebp,edx
5353
     movzx edx,word[edi-twdw+4]
5354
     add   eax,ebp
5355
     mov   ebp,edx
5356
     shl   edx,16
5357
     xor   edi,edi
5358
     add   edx,ebp
5359
     add   ebx,edx
5360
     jmp   [draw_line]
5361
 
5362
align 4
5363
 
5364
syscall_getirqowner:                    ; GetIrqOwner
5365
 
5366
     shl   eax,2
5367
     add   eax,irq_owner
5368
     mov   eax,[eax]
5369
     mov   [esp+36],eax
5370
     ret
5371
 
5372
align 4
5373
 
5374
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5375
 
5376
     call  r_f_port_area
5377
     mov   [esp+36],eax
5378
     ret
5379
 
14 poddubny 5380
;align 4
1 ha 5381
 
5382
syscall_appints:                        ; AppInts
14 poddubny 5383
;    mov   [esp+36],dword -1
1 ha 5384
     ret
5385
 
5386
align 4
5387
 
5388
syscall_threads:                        ; CreateThreads
5389
 
5390
     call  sys_threads
5391
     mov   [esp+36],eax
5392
     ret
5393
 
5394
align 4
5395
 
5396
stack_driver_stat:
5397
 
5398
     call  app_stack_handler            ; Stack status
5399
 
5400
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5401
;     call  change_task                 ; between sent packet
5402
 
5403
     mov   [esp+36],eax
5404
     ret
5405
 
5406
align 4
5407
 
5408
socket:                                 ; Socket interface
5409
     call  app_socket_handler
5410
 
5411
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5412
;     call  change_task                 ; between sent packet
5413
 
5414
     mov   [esp+36],eax
5415
     mov   [esp+24],ebx
5416
     ret
5417
 
5418
align 4
5419
 
5420
user_events:                            ; User event times
5421
 
5422
     mov   eax,0x12345678
5423
     mov   [esp+36],eax
5424
 
5425
     ret
5426
 
5427
align 4
5428
 
5429
read_from_hd:                           ; Read from hd - fn not in use
5430
 
5431
     mov   edi,[0x3010]
5432
     add   edi,0x10
5433
     add   eax,[edi]
5434
     add   ecx,[edi]
5435
     add   edx,[edi]
5436
     call  file_read
5437
 
5438
     mov   [esp+36],eax
5439
     mov   [esp+24],ebx
5440
 
5441
     ret
5442
 
5443
 
5444
align 4
5445
 
5446
write_to_hd:                            ; Write a file to hd
5447
 
5448
     mov   edi,[0x3010]
5449
     add   edi,0x10
5450
     add   eax,[edi]
5451
     add   ecx,[edi]
5452
     add   edx,[edi]
5453
     call  file_write
5454
     ret
5455
 
5456
align 4
5457
 
5458
delete_from_hd:                         ; Delete a file from hd
5459
 
5460
     mov   edi,[0x3010]
5461
     add   edi,0x10
5462
     add   eax,[edi]
5463
     add   ecx,[edi]
5464
     call  file_delete
5465
     ret
5466
 
5467
 
5468
align 4
5469
 
5470
undefined_syscall:                      ; Undefined system call
5471
 
5472
     mov   [esp+36],dword -1
5473
     ret
5474
 
5475
 
5476
;clear_busy_flag_at_caller:
5477
 
5478
;      push  edi
5479
 
5480
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
5481
;      imul  edi,8
5482
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
5483
 
5484
;      pop   edi
5485
 
5486
;      ret
5487
 
5488
 
5489
 
5490
 
5491
keymap:
5492
 
5493
     db   '6',27
5494
     db   '1234567890-=',8,9
5495
     db   'qwertyuiop[]',13
5496
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
5497
     db   '@234567890123',180,178,184,'6',176,'7'
5498
     db   179,'8',181,177,183,185,182
5499
     db   'AB
5500
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5501
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5502
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5503
 
5504
 
5505
keymap_shift:
5506
 
5507
     db   '6',27
5508
     db   '!@#$%^&*()_+',8,9
5509
     db   'QWERTYUIOP{}',13
5510
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
5511
     db   '@234567890123',180,178,184,'6',176,'7'
5512
     db   179,'8',181,177,183,185,182
5513
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
5514
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5515
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5516
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5517
 
5518
 
5519
keymap_alt:
5520
 
5521
     db   ' ',27
5522
     db   ' @ $  {[]}\ ',8,9
5523
     db   '            ',13
5524
     db   '             ',0,'           ',0,'4',0,' '
5525
     db   '             ',180,178,184,'6',176,'7'
5526
     db   179,'8',181,177,183,185,182
5527
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
5528
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5529
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5530
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5531
 
5532
 
5533
; device irq owners
5534
uglobal
5535
irq_owner:       ; process id
5536
 
5537
     dd   0x0
5538
     dd   0x0
5539
     dd   0x0
5540
     dd   0x0
5541
     dd   0x0
5542
     dd   0x0
5543
     dd   0x0
5544
     dd   0x0
5545
     dd   0x0
5546
     dd   0x0
5547
     dd   0x0
5548
     dd   0x0
5549
     dd   0x0
5550
     dd   0x0
5551
     dd   0x0
5552
     dd   0x0
5553
endg
5554
 
5555
 
5556
; on irq read ports
5557
uglobal
5558
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5559
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5560
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5561
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5562
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5563
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5564
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5565
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5566
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5567
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5568
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5569
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5570
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5571
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5572
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5573
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5574
endg
5575
 
5576
; status
5577
uglobal
5578
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5579
  application_table_status    dd 0x0  ; 0 - free : other - pid
5580
endg
5581
 
5582
; device addresses
5583
uglobal
5584
  mididp     dd 0x0
5585
  midisp     dd 0x0
5586
 
5587
  cdbase     dd 0x0
5588
  cdid       dd 0x0
5589
 
5590
  hdbase              dd   0x0  ; for boot 0x1f0
5591
  hdid                dd   0x0
5592
  hdpos               dd   0x0  ; for boot 0x1
5593
  fat32part           dd   0x0  ; for boot 0x1
5594
 
5595
  ;part2_ld            dd   0x0
5596
 
5597
;* start code - get  process (3) - Mario79
5598
active_process      dd   0
5599
;* end code - get active process (3) - Mario79
5600
 
5601
wraw_bacground_select db 0
5602
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5603
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5604
 
5605
  sb16       dd 0x0
5606
  wss        dd 0x0
5607
 
5608
  buttontype         dd 0x0
5609
  windowtypechanged  dd 0x0
5610
endg
5611
 
5612
iglobal
5613
  keyboard   dd 0x1
5614
  sound_dma  dd 0x1
5615
  syslang    dd 0x1
5616
endg
5617
 
5618
IncludeIGlobals
5619
endofcode:
5620
IncludeUGlobals
5621
uglobals_size = $ - endofcode
5622
diff16 "end of kernel code",$
5623