Subversion Repositories Kolibri OS

Rev

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