Subversion Repositories Kolibri OS

Rev

Rev 102 | Rev 105 | 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
 
97 mario79 76
version           db    'Kolibri OS  version 0.5.8.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
103 halyavin 416
 
417
        call    MEM_Init
418
;add 0x800000-0xc00000 area
419
        cmp     word [0xfe0c],0x13
420
        jle     .less_memory
421
        mov     eax,0x800000      ;linear address
422
        mov     ebx,0x400000 shr 12 ;size in pages (4Mb)
423
        mov     ecx,0x800000        ;physical address
424
        jmp     .end_first_block
425
.less_memory:
426
        mov     eax,0x980000      ;linear address
427
        mov     ebx,0x280000 shr 12 ;size in pages (2.5Mb)
428
        mov     ecx,0x980000        ;physical address
429
.end_first_block:
430
        call    MEM_Add_Heap        ;nobody can lock mutex yet
41 mikedld 431
 
103 halyavin 432
        call    create_general_page_table
433
;add 0x1000000(0xd80000)-end_of_memory area
434
        mov     eax,second_base_address
435
        mov     ebx,[0xfe8c]
436
        mov     ecx,[0xfe84]
437
        sub     ebx,ecx
438
        shr     ebx,12
439
        add     eax,ecx
440
        call    MEM_Add_Heap
441
;init physical memory manager.
442
        call    Init_Physical_Memory_Manager
443
 
444
        mov     dword [0xfe80],0x80000000 ;0x800000
445
 
41 mikedld 446
;Set base of graphic segment to linear address of LFB
1 ha 447
        mov     eax,[0xfe80]                      ; set for gs
448
        mov     [graph_data_l+2],ax
449
        shr     eax,16
450
        mov     [graph_data_l+4],al
41 mikedld 451
        mov     [graph_data_l+7],ah
1 ha 452
 
453
; READ RAMDISK IMAGE FROM HD
454
 
455
;!!!!!!!!!!!!!!!!!!!!!!!
456
include 'boot/rdload.inc'
457
;!!!!!!!!!!!!!!!!!!!!!!!
458
;    mov    [dma_hdd],1
459
; CALCULATE FAT CHAIN FOR RAMDISK
460
 
461
        call  calculatefatchain
462
 
463
; LOAD VMODE DRIVER
464
 
465
;!!!!!!!!!!!!!!!!!!!!!!!
466
include 'vmodeld.inc'
467
;!!!!!!!!!!!!!!!!!!!!!!!
468
 
469
; LOAD FONTS I and II
470
 
471
        mov   [0x3000],dword 1
472
        mov   [0x3004],dword 1
473
        mov   [0x3010],dword 0x3020
474
 
475
        mov   eax,char
476
        mov   esi,12
477
        xor   ebx,ebx
12 halyavin 478
        mov   ecx,2560;26000
479
        mov   edx,0x3F600;0x37000
1 ha 480
        call  fileread
481
 
482
        mov   eax,char2
483
        mov   esi,12
484
        xor   ebx,ebx
12 halyavin 485
        mov   ecx,2560;26000
486
        mov   edx,0x3EC00;0x30000
1 ha 487
        call  fileread
488
 
489
        mov   esi,boot_fonts
490
        call  boot_log
491
 
492
; PRINT AMOUNT OF MEMORY
493
        mov     esi, boot_memdetect
494
        call    boot_log
495
 
496
        movzx   ecx, word [boot_y]
497
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
498
        sub     ecx, 10
499
        mov     edx, 0xFFFFFF
500
        mov     ebx, [0xFE8C]
501
        shr     ebx, 20
502
        mov     edi, 1
503
        mov     eax, 0x00040000
504
        call    display_number
41 mikedld 505
 
1 ha 506
; CHECK EXTENDED REGION
507
;        mov     dword [0x80000000],0x12345678
508
;        cmp     dword [0x80000000],0x12345678
509
;        jz      extended_region_found
510
;        mov     esi,boot_ext_region
511
;        call    boot_log
512
;        jmp     $
513
;extended_region_found:
41 mikedld 514
 
1 ha 515
 
41 mikedld 516
 
1 ha 517
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
518
 
519
        mov   esi,boot_irqs
520
        call  boot_log
521
        call  rerouteirqs
522
 
523
        mov    esi,boot_tss
524
        call   boot_log
525
 
526
; BUILD SCHEDULER
527
 
528
        call   build_scheduler ; sys32.inc
529
 
530
; LOAD IDT
13 poddubny 531
        lidt   [cs:idtreg]
1 ha 532
 
533
; READ CPUID RESULT
534
 
535
        mov     esi,boot_cpuid
536
        call    boot_log
537
        pushfd                  ; get current flags
538
        pop     eax
539
        mov     ecx,eax
540
        xor     eax,0x00200000  ; attempt to toggle ID bit
541
        push    eax
542
        popfd
543
        pushfd                  ; get new EFLAGS
544
        pop     eax
545
        push    ecx             ; restore original flags
546
        popfd
547
        and     eax,0x00200000  ; if we couldn't toggle ID,
548
        and     ecx,0x00200000  ; then this is i486
549
        cmp     eax,ecx
550
        jz      nopentium
551
        ; It's Pentium or later. Use CPUID
552
        mov     edi,cpuid_0
553
        mov     esi,0
554
      cpuid_new_read:
555
        mov     eax,esi
556
        cpuid
557
        call    cpuid_save
558
        add     edi,4*4
559
        cmp     esi,3
560
        jge     cpuid_done
561
        cmp     esi,[cpuid_0]
562
        jge     cpuid_done
563
        inc     esi
564
        jmp     cpuid_new_read
565
      cpuid_save:
566
        mov     [edi+00],eax
567
        mov     [edi+04],ebx
568
        mov     [edi+8],ecx
569
        mov     [edi+12],edx
570
        ret
571
      cpuid_done:
572
      nopentium:
573
 
574
; CR4 flags - enable fxsave / fxrstore
575
;
576
;        finit
577
;        mov     eax,1
578
;        cpuid
579
;        test    edx,1000000h
580
;        jz      fail_fpu
581
;        mov     eax,cr4
582
;        or      eax,200h        ; Enable fxsave/fxstor
583
;        mov     cr4,eax
584
;     fail_fpu:
585
 
41 mikedld 586
;The CPU to this moment should be already in PM,
587
;and bit MP of the register cr0 should be installed in 1.
588
finit ;reset of the FPU (finit, instead of fninit)
589
fsetpm ;enable PM of the FPU
590
finit ;reset the registers, contents which are still equal RM
591
;Now FPU too in PM
1 ha 592
; DETECT DEVICES
593
 
594
        mov    esi,boot_devices
595
        call   boot_log
596
        call   detect_devices
597
 
598
 ; TIMER SET TO 1/100 S
599
 
600
        mov   esi,boot_timer
601
        call  boot_log
602
        mov   al,0x34              ; set to 100Hz
603
        out   0x43,al
604
        mov   al,0x9b              ; lsb    1193180 / 1193
605
        out   0x40,al
606
        mov   al,0x2e              ; msb
607
        out   0x40,al
608
 
609
; SET MOUSE
610
 
611
        mov   esi,boot_setmouse
612
        call  boot_log
613
        call  setmouse
614
 
615
; SET PRELIMINARY WINDOW STACK AND POSITIONS
616
 
617
        mov   esi,boot_windefs
618
        call  boot_log
619
        call  setwindowdefaults
620
 
621
; SET BACKGROUND DEFAULTS
622
 
623
        mov   esi,boot_bgr
624
        call  boot_log
625
        call  calculatebackground
626
 
627
; RESERVE SYSTEM IRQ'S JA PORT'S
628
 
629
        mov   esi,boot_resirqports
630
        call  boot_log
631
        call  reserve_irqs_ports
632
 
633
; SET PORTS FOR IRQ HANDLERS
634
 
635
        mov  esi,boot_setrports
636
        call boot_log
637
        call setirqreadports
638
 
639
; SET UP OS TASK
640
 
641
        mov  esi,boot_setostask
642
        call boot_log
643
        ; name for OS/IDLE process
644
        mov  [0x80000+256+0],dword 'OS/I'
645
        mov  [0x80000+256+4],dword 'DLE '
646
        ; task list
647
        mov  [0x3020+0xE],byte  1     ; on screen number
648
        mov  [0x3020+0x4],dword 1     ; process id number
21 poddubny 649
        mov  [0x3020+0x10], dword 0   ; process base address
1 ha 650
 
651
        ; set default flags & stacks
652
        mov  [l.eflags],dword 0x11202 ; sti and resume
653
        mov  [l.ss0], os_data
654
        ; osloop - TSS
655
        mov  eax,cr3
656
        mov  [l.cr3],eax
657
        mov  [l.eip],osloop
13 poddubny 658
        mov  [l.esp],sysint_stack_data + 4096*2 ; uses slot 1 stack
1 ha 659
        mov  [l.cs],os_code
660
        mov  [l.ss],os_data
661
        mov  [l.ds],os_data
662
        mov  [l.es],os_data
663
        mov  [l.fs],os_data
664
        mov  [l.gs],os_data
665
        ; move tss to tss_data+tss_step
666
        mov  esi,tss_sceleton
667
        mov  edi,tss_data+tss_step
668
        mov  ecx,120/4
669
        cld
670
        rep  movsd
671
 
672
        mov  ax,tss0
673
        ltr  ax
674
 
675
 
676
; READ TSC / SECOND
677
 
678
        mov   esi,boot_tsc
679
        call  boot_log
680
        call  _rdtsc
681
        mov   ecx,eax
682
        mov   esi,250               ; wait 1/4 a second
683
        call  delay_ms
684
        call  _rdtsc
685
        sub   eax,ecx
686
        shl   eax,2
687
        mov   [0xf600],eax          ; save tsc / sec
688
 
689
; SET VARIABLES
690
 
691
        call  set_variables
692
 
693
; STACK AND FDC
694
 
695
        call  stack_init
696
        call  fdc_init
697
 
698
; PALETTE FOR 320x200 and 640x480 16 col
699
 
700
        cmp   [0xfe0c],word 0x12
701
        jne   no_pal_vga
702
        mov   esi,boot_pal_vga
703
        call  boot_log
704
        call  paletteVGA
705
      no_pal_vga:
706
 
707
        cmp   [0xfe0c],word 0x13
708
        jne   no_pal_ega
709
        mov   esi,boot_pal_ega
710
        call  boot_log
711
        call  palette320x200
712
      no_pal_ega:
713
 
714
; LOAD DEFAULT SKIN
715
 
49 mikedld 716
        mov     esi,_skin_file_default
717
        mov     edi,_skin_file
718
        movsd
719
        movsd
720
        movsd
721
        call    load_skin
1 ha 722
 
723
; MTRR'S
724
 
725
        call  enable_mtrr
726
 
727
 
728
; LOAD FIRST APPLICATION
21 poddubny 729
        mov   [0x3000],dword 1
730
        mov   [0x3004],dword 1
1 ha 731
        cli
732
        mov   al,[0x2f0000+0x9030]
733
        cmp   al,1
734
        jne   no_load_vrr_m
735
        mov   eax,vrr_m
41 mikedld 736
        xor   ebx,ebx                   ; no parameters
40 halyavin 737
        xor   edx,edx                   ; no flags
1 ha 738
        call  start_application_fl
21 poddubny 739
        cmp   eax,2                  ; if vrr_m app found (PID=2)
1 ha 740
        je    first_app_found
41 mikedld 741
 
21 poddubny 742
    no_load_vrr_m:
1 ha 743
        mov   eax,firstapp
40 halyavin 744
        xor   ebx,ebx                   ; no parameters
745
        xor   edx,edx                   ; no flags
1 ha 746
        call  start_application_fl
747
 
21 poddubny 748
        cmp   eax,2                  ; continue if a process has been loaded
1 ha 749
        je    first_app_found
21 poddubny 750
        mov   eax, 0xDEADBEEF        ; otherwise halt
751
        hlt
1 ha 752
      first_app_found:
753
        cli
754
 
21 poddubny 755
        ;mov   [0x3004],dword 2
756
        mov   [0x3000],dword 1       ; set OS task fisrt
1 ha 757
 
758
 
21 poddubny 759
; SET KEYBOARD PARAMETERS
760
        mov   al, 0xf6         ; reset keyboard, scan enabled
1 ha 761
        call  kb_write
762
 
21 poddubny 763
        ; wait until 8042 is ready
33 mario79 764
;        xor ecx,ecx
765
;      @@:
41 mikedld 766
;        in     al,64h
33 mario79 767
;        and    al,00000010b
768
;        loopnz @b
769
        call  Wait8042BufferEmpty
1 ha 770
 
771
       ; mov   al, 0xED       ; svetodiody - only for testing!
772
       ; call  kb_write
773
       ; call  kb_read
774
       ; mov   al, 111b
775
       ; call  kb_write
776
       ; call  kb_read
41 mikedld 777
 
1 ha 778
        mov   al, 0xF3       ; set repeat rate & delay
779
        call  kb_write
780
        call  kb_read
92 diamond 781
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
1 ha 782
        call  kb_write
783
        call  kb_read
784
     ;// mike.dld [
785
        call  set_lights
786
     ;// mike.dld ]
787
 
21 poddubny 788
; START MULTITASKING
1 ha 789
 
21 poddubny 790
        mov   esi,boot_tasking
791
        call  boot_log
792
 
793
        mov   [0xe000],byte 1        ; multitasking enabled
794
 
1 ha 795
; UNMASK ALL IRQ'S
796
 
797
        mov   esi,boot_allirqs
798
        call  boot_log
41 mikedld 799
 
1 ha 800
        cli                          ;guarantee forbidance of interrupts.
801
        mov   al,0                   ; unmask all irq's
802
        out   0xA1,al
803
        out   0x21,al
804
 
805
        mov   ecx,32
806
 
807
     ready_for_irqs:
808
 
809
        mov   al,0x20                ; ready for irqs
810
        out   0x20,al
811
        out   0xa0,al
812
 
813
        loop  ready_for_irqs         ; flush the queue
814
 
815
;        mov    [dma_hdd],1
816
 
817
        sti
818
        jmp   $                      ; wait here for timer to take control
819
 
820
        ; Fly :)
821
 
822
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
823
;                                                                    ;
33 mario79 824
;                    MAIN OS LOOP START                              ;
1 ha 825
;                                                                    ;
826
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
827
align 32
828
osloop:
829
 
830
        call   [draw_pointer]
831
        call   checkbuttons
832
        call   checkwindows
49 mikedld 833
;       call   check_window_move_request
1 ha 834
        call   checkmisc
835
        call   checkEgaCga
836
        call   stack_handler
837
        call   checkidle
838
        call   check_fdd_motor_status
839
        jmp    osloop
33 mario79 840
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841
;                                                                    ;
842
;                      MAIN OS LOOP END                              ;
843
;                                                                    ;
844
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 845
 
846
checkidle:
847
        pushad
848
 
849
        cmp  [check_idle_semaphore],0
850
        jne  no_idle_state
851
 
852
        call change_task
853
        mov  eax,[idlemem]
854
        mov  ebx,[timer_ticks] ;[0xfdf0]
855
        cmp  eax,ebx
856
        jnz  idle_exit
857
        call _rdtsc
858
        mov  ecx,eax
859
      idle_loop:
860
        hlt
861
        cmp  [check_idle_semaphore],0
862
        jne  idle_loop_exit
863
        mov  eax,[timer_ticks] ;[0xfdf0]
864
        cmp  ebx,eax
865
        jz   idle_loop
866
      idle_loop_exit:
867
        mov  [idlemem],eax
868
        call _rdtsc
869
        sub  eax,ecx
870
        mov  ebx,[idleuse]
871
        add  ebx,eax
872
        mov  [idleuse],ebx
873
 
874
        popad
875
        ret
876
 
877
      idle_exit:
878
 
879
        mov  ebx,[timer_ticks] ;[0xfdf0]
880
        mov  [idlemem],ebx
881
        call change_task
882
 
883
        popad
884
        ret
885
 
886
      no_idle_state:
887
 
888
        dec  [check_idle_semaphore]
889
 
890
        mov  ebx,[timer_ticks] ;[0xfdf0]
891
        mov  [idlemem],ebx
892
        call change_task
893
 
894
        popad
895
        ret
896
 
897
uglobal
898
  idlemem               dd   0x0
899
  idleuse               dd   0x0
900
  idleusesec            dd   0x0
901
  check_idle_semaphore  dd   0x0
902
endg
903
 
904
 
905
 
906
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
907
;                                                                      ;
908
;                   INCLUDED SYSTEM FILES                              ;
909
;                                                                      ;
910
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911
 
912
 
7 me_root 913
include "kernel32.inc"
1 ha 914
 
915
 
916
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917
;                                                                      ;
918
;                       KERNEL FUNCTIONS                               ;
919
;                                                                      ;
920
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
921
 
922
enable_mtrr:
923
 
924
        pushad
925
 
926
        cmp    [0x2f0000+0x901c],byte 2
927
        je     no_mtrr
928
        mov    eax,[0xFE0C]                ; if no LFB then no MTRR
929
        test   eax,0100000000000000b
930
        jz     no_mtrr
931
        mov    edx,[cpuid_1+3*4]           ; edx - MTRR's supported ?
932
        test   edx,1000000000000b
933
        jz     no_mtrr
934
        call   find_empty_mtrr
935
        cmp    ecx,0
936
        jz     no_mtrr
937
        mov    esi,boot_mtrr               ; 'setting mtrr'
938
        call   boot_log
939
        mov    edx,0x0                     ; LFB , +8 M , write combine
940
        mov    eax,[0x2f9018]
941
        or     eax,1
942
        wrmsr
943
        inc    ecx
944
        mov    edx,0xf
945
        mov    eax,0xff800800
946
        wrmsr
947
        mov    ecx,0x2ff                   ; enable mtrr's
948
        rdmsr
949
        or     eax,100000000000b           ; set
950
        wrmsr
951
     no_mtrr:
952
 
953
        popad
954
        ret
955
 
956
 
957
find_empty_mtrr:  ; 8 pairs checked
958
 
959
        mov    ecx,0x201-2
960
      mtrr_find:
961
        add    ecx,2
962
        cmp    ecx,0x200+8*2
963
        jge    no_free_mtrr
964
        rdmsr
965
        test   eax,0x0800
966
        jnz    mtrr_find
967
        dec    ecx
968
        ret
969
      no_free_mtrr:
970
        mov    ecx,0
971
        ret
972
 
973
reserve_irqs_ports:
974
 
975
        pushad
976
 
977
        mov  [irq_owner+4*0],byte 1    ; timer
978
        mov  [irq_owner+4*1],byte 1    ; keyboard
979
        mov  [irq_owner+4*5],byte 1    ; sound blaster
980
        mov  [irq_owner+4*6],byte 1    ; floppy diskette
981
        mov  [irq_owner+4*13],byte 1   ; math co-pros
982
        mov  [irq_owner+4*14],byte 1   ; ide I
983
        mov  [irq_owner+4*15],byte 1   ; ide II
58 mario79 984
;        movzx eax,byte [0xf604]        ; mouse irq
985
;        dec   eax
986
;        add   eax,mouseirqtable
987
;        movzx eax,byte [eax]
988
;        shl   eax,2
989
;        mov   [irq_owner+eax],byte 1
1 ha 990
 
991
 
992
                                       ; RESERVE PORTS
993
        mov   edi,1                    ; 0x00-0xff
994
        mov   [0x2d0000],edi
995
        shl   edi,4
996
        mov   [0x2d0000+edi+0],dword 1
997
        mov   [0x2d0000+edi+4],dword 0x0
998
        mov   [0x2d0000+edi+8],dword 0xff
58 mario79 999
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
1000
;        jne   ripl1
1001
;        inc   dword [0x2d0000]
1002
;        mov   edi,[0x2d0000]
1003
;        shl   edi,4
1004
;        mov   [0x2d0000+edi+0],dword 1
1005
;        mov   [0x2d0000+edi+4],dword 0x3f0
1006
;        mov   [0x2d0000+edi+8],dword 0x3ff
1007
;      ripl1:
1008
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1009
;        jne   ripl2
1010
;        inc   dword [0x2d0000]
1011
;        mov   edi,[0x2d0000]
1012
;        shl   edi,4
1013
;        mov   [0x2d0000+edi+0],dword 1
1014
;        mov   [0x2d0000+edi+4],dword 0x2f0
1015
;        mov   [0x2d0000+edi+8],dword 0x2ff
1016
;      ripl2:
1 ha 1017
 
1018
        popad
1019
        ret
1020
 
1021
iglobal
1022
mouseirqtable   db  12    ; ps2
1023
                db  4     ; com1
1024
                db  3     ; com2
1025
endg
1026
 
1027
setirqreadports:
1028
 
1029
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1030
        mov   [irq12read+4],dword 0                  ; end of port list
1031
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1032
        mov   [irq04read+4],dword 0                  ; end of port list
1033
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1034
        mov   [irq03read+4],dword 0                  ; end of port list
1035
 
1036
        ret
1037
 
1038
iglobal
1039
  process_number dd 0x1
1040
endg
1041
 
1042
uglobal
1043
  novesachecksum dd 0x0
1044
endg
1045
 
1046
checkEgaCga:
1047
 
1048
        cmp    [0xfe0c],dword 0x13
1049
        je     cnvl
1050
        ret
1051
      cnvl:
1052
 
1053
        pushad
33 mario79 1054
;        mov    ecx,[0xfb0a]
1055
;        cmp    ecx,[novesachecksum]
1056
;        jne    novesal
1057
;        popad
1058
;        ret
1 ha 1059
 
1060
      novesal:
33 mario79 1061
;        mov    [novesachecksum],ecx
1 ha 1062
        mov    ecx,0
1063
        movzx  eax,word [0xfb0c]
1064
        cmp    eax,100
1065
        jge    m13l3
1066
        mov    eax,100
1067
      m13l3:
1068
        cmp    eax,480-100
1069
        jbe    m13l4
1070
        mov    eax,480-100
1071
      m13l4:
1072
        sub    eax,100
1073
        imul   eax,640*4
1074
        add    ecx,eax
1075
        movzx  eax,word [0xfb0a]
1076
        cmp    eax,160
1077
        jge    m13l1
1078
        mov    eax,160
1079
      m13l1:
1080
        cmp    eax,640-160
1081
        jbe    m13l2
1082
        mov    eax,640-160
1083
      m13l2:
1084
        sub    eax,160
1085
        shl    eax,2
1086
        add    ecx,eax
1087
        mov    esi,[0xfe80]
1088
        add    esi,ecx
1089
        mov    edi,0xa0000
1090
        mov    edx,200
1091
        mov    ecx,320
1092
        cld
1093
     m13pix:
1094
        lodsd
1095
        push   eax
1096
        mov    ebx,eax
1097
        and    eax,(128+64+32)      ; blue
1098
        shr    eax,5
1099
        and    ebx,(128+64+32)*256  ; green
1100
        shr    ebx,8+2
1101
        add    eax,ebx
1102
        pop    ebx
1103
        and    ebx,(128+64)*256*256 ; red
1104
        shr    ebx,8+8
1105
        add    eax,ebx
1106
        stosb
1107
        loop   m13pix
1108
        mov    ecx,320
1109
        add    esi,4*(640-320)
1110
        dec    edx
1111
        jnz    m13pix
1112
 
1113
        popad
1114
        ret
1115
 
1116
 
1117
palette320x200:
1118
 
1119
       mov   edx,0x3c8
1120
       xor   eax, eax
1121
       out   dx,al
1122
       mov   ecx,256
1123
       mov   edx,0x3c9
1124
       xor   eax,eax
1125
 
1126
     palnew:
1127
       mov   al,0
1128
       test  ah,64
1129
       jz    pallbl1
1130
       add   al,21
1131
     pallbl1:
1132
       test  ah,128
1133
       jz    pallbl2
1134
       add   al,42
1135
     pallbl2:
1136
       out   dx,al
1137
       mov   al,0
1138
       test  ah,8
1139
       jz    pallbl3
1140
       add   al,8
1141
     pallbl3:
1142
       test  ah,16
1143
       jz    pallbl4
1144
       add   al,15
1145
     pallbl4:
1146
       test  ah,32
1147
       jz    pallbl5
1148
       add   al,40
1149
     pallbl5:
1150
       out   dx,al
1151
       mov   al,0
1152
       test  ah,1
1153
       jz    pallbl6
1154
       add   al,8
1155
     pallbl6:
1156
       test  ah,2
1157
       jz    pallbl7
1158
       add   al,15
1159
     pallbl7:
1160
       test  ah,4
1161
       jz    pallbl8
1162
       add   al,40
1163
     pallbl8:
1164
       out   dx,al
1165
       add   ah,1
1166
       loop  palnew
1167
 
1168
       ret
1169
 
1170
set_variables:
1171
 
1172
        mov   ecx,0x100                       ; flush port 0x60
1173
.fl60:  in    al,0x60
1174
        loop  .fl60
1175
        mov   [0xfcff],byte 0                 ; mouse buffer
1176
        mov   [0xf400],byte 0                 ; keyboard buffer
1177
        mov   [0xf500],byte 0                 ; button buffer
1178
;        mov   [0xfb0a],dword 100*65536+100    ; mouse x/y
1179
 
1180
        push  eax
1181
        mov   ax,[0x2f0000+0x900c]
1182
        shr   ax,1
1183
        shl   eax,16
1184
        mov   ax,[0x2f0000+0x900A]
1185
        shr   ax,1
1186
        mov   [0xfb0a],eax
1187
        pop   eax
41 mikedld 1188
 
1 ha 1189
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1190
        mov   [display_data-12],dword 1       ; tiled background
1191
        mov   [0xfe88],dword 0x2C0000         ; address of button list
1192
 
1193
     ;!! IP 04.02.2005:
1194
        mov   [next_usage_update], 100
1195
        mov   byte [0xFFFF], 0 ; change task if possible
1196
 
1197
        ret
1198
 
1199
;* mouse centered - start code- Mario79
1200
mouse_centered:
1201
        push  eax
1202
        mov   eax,[0xFE00]
1203
        shr   eax,1
1204
        mov   [0xFB0A],ax
1205
        mov   eax,[0xFE04]
1206
        shr   eax,1
1207
        mov   [0xFB0C],ax
1208
        pop   eax
1209
        ret
1210
;* mouse centered - end code- Mario79
1211
 
1212
align 4
1213
 
1214
sys_outport:
1215
 
1216
    mov   edi,ebx          ; separate flag for read / write
1217
    and   ebx,65535
1218
 
1219
    mov   ecx,[0x2d0000]
1220
    test  ecx,ecx
1221
    jne   sopl8
1222
    mov   [esp+36],dword 1
1223
    ret
1224
 
1225
  sopl8:
1226
    mov   edx,[0x3010]
1227
    mov   edx,[edx+0x4]
1228
    and   ebx,65535
1229
    cld
1230
  sopl1:
1231
 
1232
    mov   esi,ecx
1233
    shl   esi,4
1234
    add   esi,0x2d0000
1235
    cmp   edx,[esi+0]
1236
    jne   sopl2
1237
    cmp   ebx,[esi+4]
1238
    jb    sopl2
1239
    cmp   ebx,[esi+8]
1240
    jg    sopl2
1241
    jmp   sopl3
1242
 
1243
  sopl2:
1244
 
1245
    dec   ecx
1246
    jnz   sopl1
1247
    mov   [esp+36],dword 1
1248
    ret
1249
 
1250
  sopl3:
1251
 
1252
    test  edi,0x80000000 ; read ?
1253
    jnz   sopl4
1254
 
1255
    mov   dx,bx          ; write
1256
    out   dx,al
1257
    mov   [esp+36],dword 0
1258
    ret
1259
 
1260
  sopl4:
1261
 
1262
    mov   dx,bx          ; read
1263
    in    al,dx
1264
    and   eax,0xff
1265
    mov   [esp+36],dword 0
1266
    mov   [esp+24],eax
1267
    ret
1268
 
1269
 
1270
 
1271
align 4
1272
sys_sb16:
1273
 
1274
     cmp  word [sb16],word 0
1275
     jnz  sb16l1
1276
     mov  [esp+36],dword 1
1277
     ret
1278
   sb16l1:
1279
     mov  [esp+36],dword 0
1280
     cmp  eax,1    ; set volume - main
1281
     jnz  sb16l2
1282
     mov  dx,word [sb16]
1283
     add  dx,4
1284
     mov  al,0x22
1285
     out  dx,al
1286
     mov  esi,1
1287
     call delay_ms
1288
     mov  eax,ebx
1289
     inc  edx
1290
     out  dx,al
1291
     ret
1292
   sb16l2:
1293
 
1294
     cmp  eax,2    ; set volume - cd
1295
     jnz  sb16l3
1296
     mov  dx,word [sb16]
1297
     add  dx,4
1298
     mov  al,0x28
1299
     out  dx,al
1300
     mov  esi,1
1301
     call delay_ms
1302
     mov  eax,ebx
1303
     add  edx,1
1304
     out  dx,al
1305
     ret
1306
   sb16l3:
1307
      mov  [esp+36],dword 2
1308
      ret
1309
 
1310
 
1311
align 4
1312
 
1313
sys_sb16II:
1314
 
1315
     cmp  word [sb16],word 0
1316
     jnz  IIsb16l1
1317
     mov  [esp+36],dword 1
1318
     ret
1319
   IIsb16l1:
1320
 
1321
     cmp  eax,1    ; set volume - main
1322
     jnz  IIsb16l2
1323
     ; L
1324
     mov  dx,word [sb16]
1325
     add  dx,4
1326
     mov  al,0x30
1327
     out  dx,al
1328
     mov  eax,ebx
1329
     inc  edx
1330
     out  dx,al
1331
     ; R
1332
     mov  dx,word [sb16]
1333
     add  dx,4
1334
     mov  al,0x31
1335
     out  dx,al
1336
     mov  eax,ebx
1337
     inc  edx
1338
     out  dx,al
1339
     mov  [esp+36],dword 0
1340
     ret
1341
   IIsb16l2:
1342
 
1343
     cmp  eax,2    ; set volume - cd
1344
     jnz  IIsb16l3
1345
     ; L
1346
     mov  dx,word [sb16]
1347
     add  dx,4
1348
     mov  al,0x36
1349
     out  dx,al
1350
     mov  eax,ebx
1351
     inc  edx
1352
     out  dx,al
1353
     ; R
1354
     mov  dx,word [sb16]
1355
     add  dx,4
1356
     mov  al,0x37
1357
     out  dx,al
1358
     mov  eax,ebx
1359
     inc  edx
1360
     out  dx,al
1361
     mov  [esp+36],dword 0
1362
     ret
1363
   IIsb16l3:
1364
 
1365
     mov  [esp+36],dword 2
1366
     ret
1367
 
1368
 
1369
align 4
1370
 
1371
sys_wss:
1372
 
1373
     cmp  word [wss],word 0
1374
     jnz  wssl1
1375
     mov  [esp+36],dword 1
1376
     ret
1377
   wssl1:
1378
 
1379
     cmp  eax,1    ; set volume - main
1380
     jnz  wssl2
1381
     mov  [esp+36],dword 0
1382
     ret
1383
   wssl2:
1384
 
1385
     cmp  eax,2    ; set volume - cd
1386
     jnz  wssl3
1387
     ; L
1388
     mov  dx,word [wss]
1389
     add  dx,4
1390
     mov  al,0x2
1391
     out  dx,al
1392
     mov  esi,1
1393
     call delay_ms
1394
     mov  eax,ebx
1395
     inc  edx
1396
     out  dx,al
1397
     ; R
1398
     mov  dx,word [wss]
1399
     add  dx,4
1400
     mov  al,0x3
1401
     out  dx,al
1402
     mov  esi,1
1403
     call delay_ms
1404
     mov  eax,ebx
1405
     inc  edx
1406
     out  dx,al
1407
     mov  [esp+36],dword 0
1408
     ret
1409
   wssl3:
1410
     mov   [esp+36],dword 2
1411
     ret
1412
 
1413
display_number:
1414
 
1415
; eax = print type, al=0 -> ebx is number
1416
;                   al=1 -> ebx is pointer
1417
;                   ah=0 -> display decimal
1418
;                   ah=1 -> display hexadecimal
1419
;                   ah=2 -> display binary
1420
;                   eax bits 16-21 = number of digits to display (0-32)
1421
;                   eax bits 22-31 = reserved
1422
;
1423
; ebx = number or pointer
1424
; ecx = x shl 16 + y
1425
; edx = color
1426
 
1427
     cmp   eax,0xffff            ; length > 0 ?
1428
     jge   cont_displ
1429
     ret
1430
   cont_displ:
1431
 
75 diamond 1432
     cmp   eax,61*0x10000        ; length <= 60 ?
1433
     jb    cont_displ2
1 ha 1434
     ret
1435
   cont_displ2:
1436
 
1437
     pushad
1438
 
1439
     cmp   al,1                  ; ecx is a pointer ?
1440
     jne   displnl1
1441
     mov   edi,[0x3010]
1442
     mov   edi,[edi+0x10]
1443
     mov   ebx,[edi+ebx]
1444
   displnl1:
1445
     sub   esp,64
1446
 
1447
     cmp   ah,0                  ; DECIMAL
1448
     jne   no_display_desnum
1449
     shr   eax,16
75 diamond 1450
     and   eax,0x3f
1 ha 1451
     push  eax
1452
     ;mov   edi,[0x3010]
1453
     ;mov   edi,[edi+0x10]
1454
     mov   edi,esp
1455
     add   edi,4+64
1456
     mov   ecx,eax
1457
     mov   eax,ebx
1458
     mov   ebx,10
1459
   d_desnum:
1460
     xor   edx,edx
1461
     div   ebx
1462
     add   dl,48
1463
     mov   [edi],dl
1464
     dec   edi
1465
     loop  d_desnum
1466
     pop   eax
1467
     call  draw_num_text
1468
     add   esp,64
1469
     popad
1470
     ret
1471
   no_display_desnum:
1472
 
1473
     cmp   ah,0x01               ; HEXADECIMAL
1474
     jne   no_display_hexnum
1475
     shr   eax,16
75 diamond 1476
     and   eax,0x3f
1 ha 1477
     push  eax
1478
     ;mov   edi,[0x3010]
1479
     ;mov   edi,[edi+0x10]
1480
     mov   edi,esp
1481
     add   edi,4+64
1482
     mov   ecx,eax
1483
     mov   eax,ebx
1484
     mov   ebx,16
1485
   d_hexnum:
1486
     xor   edx,edx
1487
     div   ebx
1488
     add   edx,hexletters
1489
     mov   dl,[edx]
1490
     mov   [edi],dl
1491
     dec   edi
1492
     loop  d_hexnum
1493
     pop   eax
1494
     call  draw_num_text
1495
     add   esp,64
1496
     popad
1497
     ret
1498
   no_display_hexnum:
1499
 
1500
     cmp   ah,0x02               ; BINARY
1501
     jne   no_display_binnum
1502
     shr   eax,16
75 diamond 1503
     and   eax,0x3f
1 ha 1504
     push  eax
1505
     ;mov   edi,[0x3010]
1506
     ;mov   edi,[edi+0x10]
1507
     mov   edi,esp
1508
     add   edi,4+64
1509
     mov   ecx,eax
1510
     mov   eax,ebx
1511
     mov   ebx,2
1512
   d_binnum:
1513
     xor   edx,edx
1514
     div   ebx
1515
     add   dl,48
1516
     mov   [edi],dl
1517
     dec   edi
1518
     loop  d_binnum
1519
     pop   eax
1520
     call  draw_num_text
1521
     add   esp,64
1522
     popad
1523
     ret
1524
   no_display_binnum:
1525
 
1526
     add   esp,64
1527
     popad
1528
     ret
1529
 
1530
 
1531
draw_num_text:
1532
 
1533
     ; dtext
1534
     ;
1535
     ; eax x & y
1536
     ; ebx color
1537
     ; ecx start of text
1538
     ; edx length
1539
     ; edi 1 force
1540
 
1541
     mov   edx,eax
1542
     mov   ecx,65
1543
     sub   ecx,eax
1544
     add   ecx,esp
1545
     add   ecx,4
1546
     mov   eax,[esp+64+32-8+4]
1547
     mov   ebx,[esp+64+32-12+4]
1548
     push  edx                       ; add window start x & y
1549
     push  ebx
1550
     mov   edx,[0x3010]
1551
     mov   ebx,[edx-twdw]
1552
     shl   ebx,16
1553
     add   ebx,[edx-twdw+4]
1554
     add   eax,ebx
1555
     pop   ebx
1556
     pop   edx
1557
     mov   edi,0
1558
     call  dtext
1559
 
1560
     ret
1561
 
1562
 
1563
read_string:
1564
 
1565
    ; eax  read_area
1566
    ; ebx  color of letter
1567
    ; ecx  color of background
1568
    ; edx  number of letters to read
1569
    ; esi  [x start]*65536 + [y_start]
1570
 
1571
    ret
1572
 
1573
 
1574
align 4
1575
 
1576
sys_setup:
1577
 
1578
; 1=roland mpu midi base , base io address
1579
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1580
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1581
; 4=sb16 base , base io address
1582
; 5=system language, 1eng 2fi 3ger 4rus
1583
; 6=wss base , base io address
1584
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1585
; 8=fat32 partition in hd
1586
; 9
1587
; 10 = sound dma channel
1588
; 11 = enable lba read
1589
; 12 = enable pci access
1590
 
1591
 
1592
     mov  [esp+36],dword 0
1593
     cmp  eax,1                      ; MIDI
1594
     jnz  nsyse1
1595
     cmp  ebx,0x100
1596
     jb   nsyse1
1597
     mov  edx,65535
1598
     cmp  edx,ebx
1599
     jb   nsyse1
1600
     mov  [midi_base],bx
1601
     mov  word [mididp],bx
1602
     inc  bx
1603
     mov  word [midisp],bx
1604
     ret
1605
 
1606
midi_base dw 0
1607
 
1608
   nsyse1:
1609
 
1610
     cmp  eax,2                      ; KEYBOARD
1611
     jnz  nsyse2
1612
     cmp  ebx,1
1613
     jnz  kbnobase
1614
     mov  edi,[0x3010]
1615
     add  ecx,[edi+0x10]
1616
     mov  eax,ecx
1617
     mov  ebx,keymap
1618
     mov  ecx,128
1619
     call memmove
1620
     ret
1621
   kbnobase:
1622
     cmp  ebx,2
1623
     jnz  kbnoshift
1624
     mov  edi,[0x3010]
1625
     add  ecx,[edi+0x10]
1626
     mov  eax,ecx
1627
     mov  ebx,keymap_shift
1628
     mov  ecx,128
1629
     call memmove
1630
     ret
1631
   kbnoshift:
1632
     cmp  ebx,3
1633
     jne  kbnoalt
1634
     mov  edi,[0x3010]
1635
     add  ecx,[edi+0x10]
1636
     mov  eax,ecx
1637
     mov  ebx,keymap_alt
1638
     mov  ecx,128
1639
     call memmove
1640
     ret
1641
   kbnoalt:
1642
     cmp  ebx,9
1643
     jnz  kbnocountry
1644
     mov  word [keyboard],cx
1645
     ret
1646
   kbnocountry:
1647
     mov  [esp+36],dword 1
1648
     ret
1649
   nsyse2:
1650
     cmp  eax,3                      ; CD
1651
     jnz  nsyse3
75 diamond 1652
     test ebx,ebx
1653
     jz   nosesl
1654
     cmp  ebx, 4
1655
     ja   nosesl
1 ha 1656
     mov  [cd_base],bl
1657
     cmp  ebx,1
1658
     jnz  noprma
1659
     mov  [cdbase],0x1f0
1660
     mov  [cdid],0xa0
1661
   noprma:
1662
     cmp  ebx,2
1663
     jnz  noprsl
1664
     mov  [cdbase],0x1f0
1665
     mov  [cdid],0xb0
1666
   noprsl:
1667
     cmp  ebx,3
1668
     jnz  nosema
1669
     mov  [cdbase],0x170
1670
     mov  [cdid],0xa0
1671
   nosema:
1672
     cmp  ebx,4
1673
     jnz  nosesl
1674
     mov  [cdbase],0x170
1675
     mov  [cdid],0xb0
1676
   nosesl:
1677
     ret
1678
 
1679
cd_base db 0
1680
 
1681
   nsyse3:
1682
 
1683
     cmp  eax,4                      ; SB
1684
     jnz  nsyse4
1685
     cmp  ebx,0x100
1686
     jb   nsyse4
1687
     mov  edx,65535
1688
     cmp  edx,ebx
1689
     jb   nsyse4
1690
     mov  word [sb16],bx
1691
     ret
1692
   nsyse4:
1693
 
1694
     cmp  eax,5                      ; SYSTEM LANGUAGE
1695
     jnz  nsyse5
1696
     mov  [syslang],ebx
1697
     ret
1698
   nsyse5:
1699
 
1700
     cmp  eax,6                      ; WSS
1701
     jnz  nsyse6
1702
     cmp  ebx,0x100
1703
     jb   nsyse6
1704
     mov  [wss],ebx
1705
     ret
1706
 
1707
wss_temp dd 0
1708
 
1709
   nsyse6:
1710
 
1711
     cmp  eax,7                      ; HD BASE
1712
     jne  nsyse7
75 diamond 1713
     test ebx,ebx
1714
     jz   nosethd
1715
     cmp  ebx,4
1716
     ja   nosethd
1 ha 1717
     mov  [hd_base],bl
1718
     cmp  ebx,1
1719
     jnz  noprmahd
1720
     mov  [hdbase],0x1f0
1721
     mov  [hdid],0x0
1722
     mov  [hdpos],1
1723
;     call set_FAT32_variables
1724
   noprmahd:
1725
     cmp  ebx,2
1726
     jnz  noprslhd
1727
     mov  [hdbase],0x1f0
1728
     mov  [hdid],0x10
1729
     mov  [hdpos],2
1730
;     call set_FAT32_variables
1731
   noprslhd:
1732
     cmp  ebx,3
1733
     jnz  nosemahd
1734
     mov  [hdbase],0x170
1735
     mov  [hdid],0x0
1736
     mov  [hdpos],3
1737
;     call set_FAT32_variables
1738
   nosemahd:
1739
     cmp  ebx,4
1740
     jnz  noseslhd
1741
     mov  [hdbase],0x170
1742
     mov  [hdid],0x10
1743
     mov  [hdpos],4
1744
;     call set_FAT32_variables
1745
   noseslhd:
1746
     mov   [0xfe10],dword 0
1747
    call  reserve_hd1
1748
    call  clear_hd_cache
1749
    mov   [hd1_status],0        ; free
75 diamond 1750
   nosethd:
1 ha 1751
     ret
1752
 
1753
hd_base db 0
1754
 
1755
   nsyse7:
1756
 
1757
     cmp  eax,8                      ; HD PARTITION
1758
     jne  nsyse8
1759
     mov  [fat32part],ebx
1760
;     call set_FAT32_variables
1761
    call  reserve_hd1
1762
    call  clear_hd_cache
1763
     pusha
1764
     call  choice_necessity_partition_1
1765
     popa
1766
    mov   [hd1_status],0        ; free
1767
     ret
1768
   nsyse8:
1769
 
1770
     cmp  eax,10                     ; SOUND DMA CHANNEL
1771
     jne  no_set_sound_dma
75 diamond 1772
     cmp  ebx,3
1773
     ja   sys_setup_err
1 ha 1774
     mov  [sound_dma],ebx
1775
     ret
1776
   no_set_sound_dma:
1777
 
1778
     cmp  eax,11                     ; ENABLE LBA READ
1779
     jne  no_set_lba_read
1780
     and  ebx,1
1781
     mov  [lba_read_enabled],ebx
1782
     ret
1783
   no_set_lba_read:
1784
 
1785
     cmp  eax,12                     ; ENABLE PCI ACCESS
1786
     jne  no_set_pci_access
1787
     and  ebx,1
1788
     mov  [pci_access_enabled],ebx
1789
     ret
1790
   no_set_pci_access:
1791
 
1792
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1793
include 'vmodeint.inc'
1794
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1795
 
75 diamond 1796
sys_setup_err:
1 ha 1797
     mov  [esp+36],dword -1
1798
     ret
1799
 
1800
 
1801
align 4
1802
 
1803
sys_getsetup:
1804
 
1805
; 1=roland mpu midi base , base io address
1806
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1807
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1808
; 4=sb16 base , base io address
1809
; 5=system language, 1eng 2fi 3ger 4rus
1810
; 6=wss base
1811
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1812
; 8=fat32 partition in hd
1813
; 9=get hs timer tic
1814
 
1815
     cmp  eax,1
1816
     jne  ngsyse1
1817
     movzx eax,[midi_base]
1818
     mov  [esp+36],eax
1819
     ret
1820
   ngsyse1:
1821
 
1822
     cmp  eax,2
1823
     jne  ngsyse2
1824
     cmp  ebx,1
1825
     jnz  kbnobaseret
1826
     mov  edi,[0x3010]
1827
     add  ecx,[edi+0x10]
1828
     mov  ebx,ecx
1829
     mov  eax,keymap
1830
     mov  ecx,128
1831
     call memmove
1832
     ret
1833
   kbnobaseret:
1834
     cmp  ebx,2
1835
     jnz  kbnoshiftret
1836
     mov  edi,[0x3010]
1837
     add  ecx,[edi+0x10]
1838
     mov  ebx,ecx
1839
     mov  eax,keymap_shift
1840
     mov  ecx,128
1841
     call memmove
1842
     ret
1843
   kbnoshiftret:
1844
     cmp  ebx,3
1845
     jne  kbnoaltret
1846
     mov  edi,[0x3010]
1847
     add  ecx,[edi+0x10]
1848
     mov  ebx,ecx
1849
     mov  eax,keymap_alt
1850
     mov  ecx,128
1851
     call memmove
1852
     ret
1853
   kbnoaltret:
1854
     cmp  ebx,9
1855
     jnz  ngsyse2
1856
     movzx eax,word [keyboard]
1857
     mov  [esp+36],eax
1858
     ret
1859
   ngsyse2:
1860
 
1861
     cmp  eax,3
1862
     jnz  ngsyse3
1863
     movzx eax,[cd_base]
1864
     mov  [esp+36],eax
1865
     ret
1866
   ngsyse3:
1867
 
1868
     cmp  eax,4
1869
     jne  ngsyse4
1870
     mov  eax,[sb16]
1871
     mov  [esp+36],eax
1872
     ret
1873
   ngsyse4:
1874
 
1875
     cmp  eax,5
1876
     jnz  ngsyse5
1877
     mov  eax,[syslang]
1878
     mov  [esp+36],eax
1879
     ret
1880
   ngsyse5:
1881
     cmp  eax,6
1882
     jnz  ngsyse6
1883
     mov  eax,[wss]
1884
     mov  [esp+36],eax
1885
     ret
1886
   ngsyse6:
1887
     cmp  eax,7
1888
     jnz  ngsyse7
1889
     movzx eax,[hd_base]
1890
     mov  [esp+36],eax
1891
     ret
1892
   ngsyse7:
1893
     cmp  eax,8
1894
     jnz  ngsyse8
1895
     mov eax,[fat32part]
1896
     mov  [esp+36],eax
1897
     ret
1898
   ngsyse8:
1899
     cmp  eax,9
1900
     jne  ngsyse9
1901
     mov  eax,[timer_ticks] ;[0xfdf0]
1902
     mov  [esp+36],eax
1903
     ret
1904
   ngsyse9:
1905
     cmp  eax,10
1906
     jnz  ngsyse10
1907
     mov eax,[sound_dma]
1908
     mov  [esp+36],eax
1909
     ret
1910
   ngsyse10:
1911
     cmp  eax,11
1912
     jnz  ngsyse11
1913
     mov eax,[lba_read_enabled]
1914
     mov  [esp+36],eax
1915
     ret
1916
   ngsyse11:
1917
     cmp  eax,12
1918
     jnz  ngsyse12
1919
     mov eax,[pci_access_enabled]
1920
     mov  [esp+36],eax
1921
     ret
1922
   ngsyse12:
1923
     mov  [esp+36],dword 1
1924
     ret
1925
 
1926
 
1927
align 4
1928
 
1929
readmousepos:
1930
 
1931
; eax=0 screen relative
1932
; eax=1 window relative
1933
; eax=2 buttons pressed
1934
 
1935
    test eax,eax
1936
    jnz  nosr
1937
    mov  eax,[0xfb0a]
1938
    shl  eax,16
1939
    mov  ax,[0xfb0c]
1940
    mov  [esp+36],eax
1941
    ret
1942
  nosr:
1943
 
1944
    cmp  eax,1
1945
    jnz  nowr
1946
    mov  eax,[0xfb0a]
1947
    shl  eax,16
1948
    mov  ax,[0xfb0c]
1949
    mov  esi,[0x3010]
1950
    sub  esi,twdw
1951
    mov  bx,[esi]
1952
    shl  ebx,16
1953
    mov  bx,[esi+4]
1954
    sub  eax,ebx
1955
    mov  [esp+36],eax
1956
    ret
1957
  nowr:
1958
 
1959
    cmp   eax,2
1960
    jnz   nomb
1961
    movzx eax,byte [0xfb40]
1962
  nomb:
1963
    mov   [esp+36],eax
1964
 
1965
    ret
1966
 
1967
is_input:
1968
 
1969
   push edx
1970
   mov  dx,word [midisp]
1971
   in   al,dx
1972
   and  al,0x80
1973
   pop  edx
1974
   ret
1975
 
1976
 
1977
is_output:
1978
 
1979
   push edx
1980
   mov  dx,word [midisp]
1981
   in   al,dx
1982
   and  al,0x40
1983
   pop  edx
1984
   ret
1985
 
1986
 
1987
get_mpu_in:
1988
 
1989
   push edx
1990
   mov  dx,word [mididp]
1991
   in   al,dx
1992
   pop  edx
1993
   ret
1994
 
1995
 
1996
put_mpu_out:
1997
 
1998
   push edx
1999
   mov  dx,word [mididp]
2000
   out  dx,al
2001
   pop  edx
2002
   ret
2003
 
2004
 
2005
setuart:
2006
 
2007
 su1:
2008
   call is_output
2009
   cmp  al,0
2010
   jnz  su1
2011
   mov  dx,word [midisp]
2012
   mov  al,0xff
2013
   out  dx,al
2014
 su2:
2015
   mov  dx,word [midisp]
2016
   mov  al,0xff
2017
   out  dx,al
2018
   call is_input
2019
   cmp  al,0
2020
   jnz  su2
2021
   call get_mpu_in
2022
   cmp  al,0xfe
2023
   jnz  su2
2024
 su3:
2025
   call is_output
2026
   cmp  al,0
2027
   jnz  su3
2028
   mov  dx,word [midisp]
2029
   mov  al,0x3f
2030
   out  dx,al
2031
 
2032
   ret
2033
 
2034
 
2035
align 4
2036
 
2037
sys_midi:
2038
 
2039
     cmp  [mididp],0
2040
     jnz  sm0
2041
     mov  [esp+36],dword 1
2042
     ret
2043
   sm0:
2044
 
2045
     cmp  eax,1
2046
     mov  [esp+36],dword 0
2047
     jnz  smn1
2048
     call setuart
2049
     ret
2050
   smn1:
2051
 
2052
     cmp  eax,2
2053
     jnz  smn2
2054
   sm10:
2055
     call get_mpu_in
2056
     call is_output
2057
     test al,al
2058
     jnz  sm10
2059
     mov  al,bl
2060
     call put_mpu_out
2061
     ret
2062
   smn2:
2063
 
2064
     ret
2065
 
2066
 
2067
detect_devices:
2068
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2069
include 'detect/commouse.inc'
33 mario79 2070
include 'detect/ps2mouse.inc'
1 ha 2071
;include 'detect/dev_fd.inc'
2072
;include 'detect/dev_hdcd.inc'
2073
;include 'detect/sear_par.inc'
2074
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2075
    ret
2076
 
2077
 
2078
sys_end:
2079
 
2080
     mov   eax,[0x3010]
2081
     add   eax,0xa
2082
     mov   [eax],byte 3  ; terminate this program
41 mikedld 2083
 
1 ha 2084
    waitterm:            ; wait here for termination
2085
     mov   eax,5
2086
     call  delay_hs
2087
     jmp   waitterm
2088
 
75 diamond 2089
iglobal
2090
sys_system_table:
2091
        dd      sysfn_shutdown          ; 1 = system shutdown
2092
        dd      sysfn_terminate         ; 2 = terminate thread
2093
        dd      sysfn_activate          ; 3 = activate window
2094
        dd      sysfn_getidletime       ; 4 = get idle time
2095
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2096
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2097
        dd      sysfn_getactive         ; 7 = get active window
2098
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2099
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
2100
        dd      sysfn_minimize          ; 10 = minimize window
2101
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2102
        dd      sysfn_lastkey           ; 12 = get last pressed key
2103
        dd      sysfn_getversion        ; 13 = get kernel version
2104
        dd      sysfn_waitretrace       ; 14 = wait retrace
2105
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2106
        dd      sysfn_getfreemem        ; 16 = get free memory size
2107
        dd      sysfn_getallmem         ; 17 = get total memory size
85 halyavin 2108
        dd      sysfn_terminate2        ; 18 = terminate thread using PID instead of slot
75 diamond 2109
sysfn_num = ($ - sys_system_table)/4
2110
endg
2111
 
1 ha 2112
sys_system:
75 diamond 2113
        dec     eax
2114
        cmp     eax, sysfn_num
2115
        jae     @f
2116
        jmp     dword [sys_system_table + eax*4]
2117
@@:
2118
        ret
1 ha 2119
 
75 diamond 2120
sysfn_shutdown:         ; 18.1 = BOOT
1 ha 2121
     mov  [0x2f0000+0x9030],byte 0
41 mikedld 2122
  for_shutdown_parameter:
1 ha 2123
     mov  eax,[0x3004]
2124
     add  eax,2
2125
     mov  [shutdown_processes],eax
2126
     mov  [0xFF00],al
75 diamond 2127
     and  dword [esp+36], 0
1 ha 2128
     ret
2129
  uglobal
2130
   shutdown_processes: dd 0x0
2131
  endg
2132
 
75 diamond 2133
sysfn_terminate:        ; 18.2 = TERMINATE
1 ha 2134
     cmp  ebx,2
2135
     jb   noprocessterminate
2136
     mov  edx,[0x3004]
2137
     cmp  ebx,edx
75 diamond 2138
     ja   noprocessterminate
1 ha 2139
     mov  eax,[0x3004]
2140
     shl  ebx,5
2141
     mov  edx,[ebx+0x3000+4]
2142
     add  ebx,0x3000+0xa
75 diamond 2143
     cmp  byte [ebx], 9
2144
     jz   noprocessterminate
41 mikedld 2145
 
1 ha 2146
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2147
     mov  [ebx],byte 3       ; clear possible i40's
2148
     ;call MEM_Heap_UnLock
2149
 
2150
     cmp  edx,[application_table_status]    ; clear app table stat
2151
     jne  noatsc
2152
     mov  [application_table_status],0
2153
   noatsc:
75 diamond 2154
   noprocessterminate:
1 ha 2155
     ret
2156
 
85 halyavin 2157
sysfn_terminate2:
2158
;lock application_table_status mutex
2159
.table_status:
2160
    cli
2161
    cmp    [application_table_status],0
2162
    je     .stf
2163
    sti
2164
    call   change_task
2165
    jmp    .table_status
2166
.stf:
2167
    call   set_application_table_status
2168
    mov    eax,ebx
2169
    call   pid_to_slot
2170
    test   eax,eax
2171
    jz     .not_found
2172
    mov    ebx,eax
2173
    cli
2174
    call   sysfn_terminate
2175
    mov    [application_table_status],0
2176
    sti
2177
    and    dword [esp+36],0
2178
    ret
2179
.not_found:
2180
    mov    [application_table_status],0
2181
    or     dword [esp+36],-1
2182
    ret
2183
 
75 diamond 2184
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
90 mario79 2185
;* start code - get active process (1) - Mario79
2186
     mov  [window_minimize],2
2187
;* end code - get active process (1) - Mario79
1 ha 2188
     cmp  ebx,2
2189
     jb   nowindowactivate
2190
     cmp  ebx,[0x3004]
2191
     ja   nowindowactivate
2192
     ; edi = position at window_data+
2193
     mov  edi, ebx          ; edi = process number
2194
    movzx esi, word [0xC000 + ebx*2]
75 diamond 2195
     cmp  esi, [0x3004] ; number of processes
1 ha 2196
     jz   nowindowactivate ; continue if window_stack_value != number_of_processes
2197
                           ;     i.e. if window is not already active
2198
     mov  [0xff01],edi     ; activate
75 diamond 2199
nowindowactivate:
1 ha 2200
     ret
41 mikedld 2201
 
75 diamond 2202
sysfn_getidletime:              ; 18.4 = GET IDLETIME
1 ha 2203
     mov  eax,[idleusesec]
75 diamond 2204
     mov  [esp+36], eax
1 ha 2205
     ret
2206
 
75 diamond 2207
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
1 ha 2208
     mov  eax,[0xf600]
75 diamond 2209
     mov  [esp+36], eax
1 ha 2210
     ret
2211
 
2212
;  SAVE ramdisk to /hd/1/menuet.img
2213
;!!!!!!!!!!!!!!!!!!!!!!!!
2214
   include 'blkdev/rdsave.inc'
2215
;!!!!!!!!!!!!!!!!!!!!!!!!
75 diamond 2216
 
2217
sysfn_getactive:        ; 18.7 = get active window
102 poddubny 2218
     mov  eax, [0x3004]
2219
   movzx  eax, word [0xC400 + eax*2]
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:
97 mario79 2327
  db 0,5,8,1  ; version 0.5.8.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
 
102 poddubny 2888
    ; parameter for drawwindow_IV
35 halyavin 2889
    push  0
102 poddubny 2890
    mov   edi, [0x3004]
2891
    movzx edi, word [0xC400 + edi*2]
2892
    cmp   edi, [0x3000]
33 mario79 2893
    jne   @f
102 poddubny 2894
    inc   dword [esp]
2895
 @@:
33 mario79 2896
 
2897
    inc   [mouse_pause]
36 mario79 2898
    call  [disable_mouse]
1 ha 2899
    call  sys_set_window
36 mario79 2900
    call  [disable_mouse]
2901
    call  drawwindow_IV
33 mario79 2902
    dec   [mouse_pause]
36 mario79 2903
    call   [draw_pointer]
1 ha 2904
    ret
2905
  nosyswIV:
2906
 
2907
    ret
2908
 
2909
 
2910
sys_set_window:
2911
 
2912
    mov   edi,[0x3000]
2913
    shl   edi,5
2914
    add   edi,window_data
2915
 
2916
    ; colors
2917
    mov   [edi+16],ecx
2918
    mov   [edi+20],edx
2919
    mov   [edi+24],esi
2920
 
2921
    ; check flag (?)
2922
    cmp   [edi+30],byte 1
2923
    jz    newd
2924
 
2925
    push  eax
2926
    mov   eax,[timer_ticks] ;[0xfdf0]
2927
    add   eax,100
2928
    mov   [new_window_starting],eax
2929
    pop   eax
2930
 
2931
    mov   [edi+8],ax
2932
    mov   [edi+12],bx
2933
    shr   eax,16
2934
    shr   ebx,16
2935
    mov   [edi+00],ax
2936
    mov   [edi+04],bx
2937
 
2938
 
2939
    call  check_window_position
2940
 
2941
 
2942
    push  ecx esi edi               ; save for window fullscreen/resize
2943
    mov   esi,edi
2944
    sub   edi,window_data
2945
    shr   edi,5
2946
    shl   edi,8
2947
    add   edi,0x80000+0x90
2948
    mov   ecx,4
2949
    cld
2950
    rep   movsd
2951
    pop   edi esi ecx
2952
 
2953
    push  eax ebx ecx edx
2954
;;;    mov   eax, 1
2955
;;;    call  delay_hs
2956
    movzx eax, word [edi+00]
2957
    movzx ebx, word [edi+04]
2958
    movzx ecx, word [edi+8]
2959
    movzx edx, word [edi+12]
2960
    add   ecx, eax
2961
    add   edx, ebx
2962
    call  calculatescreen
2963
    pop   edx ecx ebx eax
2964
 
2965
    mov   [0xf400],byte 0           ; empty keyboard buffer
2966
    mov   [0xf500],byte 0           ; empty button buffer
2967
 
2968
  newd:
2969
    mov   [edi+31],byte 0   ; no redraw
2970
    mov   edx,edi
2971
 
2972
    ret
2973
 
2974
 
2975
sys_window_move:
2976
 
49 mikedld 2977
        mov     edi,[0x00003000]
2978
        shl     edi,5
2979
        add     edi,window_data
1 ha 2980
 
49 mikedld 2981
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
2982
        jnz     .window_move_return
1 ha 2983
 
49 mikedld 2984
        push  dword [edi+0]           ; save old coordinates
2985
        push  dword [edi+4]
2986
        push  dword [edi+8]
2987
        push  dword [edi+12]
1 ha 2988
 
49 mikedld 2989
        cmp   eax,-1                  ; set new position and size
2990
        je    .no_x_reposition
2991
        mov   [edi+0],eax
2992
      .no_x_reposition:
2993
        cmp   ebx,-1
2994
        je    .no_y_reposition
2995
        mov   [edi+4],ebx
2996
      .no_y_reposition:
1 ha 2997
 
49 mikedld 2998
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
2999
        jnz     .no_y_resizing
1 ha 3000
 
49 mikedld 3001
        cmp   ecx,-1
3002
        je    .no_x_resizing
3003
        mov   [edi+8],ecx
3004
      .no_x_resizing:
3005
        cmp   edx,-1
3006
        je    .no_y_resizing
3007
        mov   [edi+12],edx
3008
      .no_y_resizing:
1 ha 3009
 
49 mikedld 3010
        call  check_window_position
1 ha 3011
 
49 mikedld 3012
        pushad                       ; save for window fullscreen/resize
3013
        mov   esi,edi
3014
        sub   edi,window_data
3015
        shr   edi,5
3016
        shl   edi,8
3017
        add   edi,0x80000+0x90
3018
        mov   ecx,4
3019
        cld
3020
        rep   movsd
3021
        popad
3022
 
3023
        pushad                       ; calculcate screen at new position
3024
        mov   eax,[edi+00]
3025
        mov   ebx,[edi+04]
3026
        mov   ecx,[edi+8]
3027
        mov   edx,[edi+12]
3028
        add   ecx,eax
3029
        add   edx,ebx
3030
        call  calculatescreen
3031
        popad
3032
 
3033
        pop   edx                   ; calculcate screen at old position
3034
        pop   ecx
3035
        pop   ebx
3036
        pop   eax
3037
        add   ecx,eax
3038
        add   edx,ebx
3039
        mov   [dlx],eax             ; save for drawlimits
3040
        mov   [dly],ebx
3041
        mov   [dlxe],ecx
3042
        mov   [dlye],edx
3043
        call  calculatescreen
3044
 
3045
        mov   [edi+31],byte 1       ; flag the process as redraw
3046
 
3047
        mov   eax,edi               ; redraw screen at old position
3048
        xor   esi,esi
3049
        call  redrawscreen
3050
 
3051
        mov   [0xfff5],byte 0 ; mouse pointer
3052
        mov   [0xfff4],byte 0 ; no mouse under
3053
        mov   [0xfb44],byte 0 ; react to mouse up/down
3054
 
3055
        mov   ecx,10          ; wait 1/10 second
3056
      .wmrl3:
3057
        call  [draw_pointer]
3058
        mov   eax,1
3059
        call  delay_hs
3060
        loop  .wmrl3
3061
 
3062
        mov   [window_move_pr],0
3063
 
3064
      .window_move_return:
3065
 
1 ha 3066
        ret
3067
 
67 diamond 3068
;type_background_1:
3069
;    cmp   [0xfff0],byte 0               ; background update ?
3070
;    jz    temp_nobackgr
3071
;    mov   [0xfff0],byte 2
3072
;    call  change_task
3073
;    mov   [draw_data+32+0],dword 0
3074
;    mov   [draw_data+32+4],dword 0
3075
;    mov   eax,[0xfe00]
3076
;    mov   ebx,[0xfe04]
3077
;    mov   [draw_data+32+8],eax
3078
;    mov   [draw_data+32+12],ebx
3079
;    call  drawbackground
3080
;    mov   [0xfff0],byte 0
3081
;    mov   [0xfff4],byte 0
3082
;temp_nobackgr:
3083
;    ret
41 mikedld 3084
 
1 ha 3085
uglobal
3086
  window_move_pr   dd  0x0
3087
  window_move_eax  dd  0x0
3088
  window_move_ebx  dd  0x0
3089
  window_move_ecx  dd  0x0
3090
  window_move_edx  dd  0x0
3091
endg
3092
 
3093
;ok - 100% work
3094
;nt - not tested
3095
;---------------------------------------------------------------------------------------------
3096
;eax
3097
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3098
;1 - change task. Ret nothing. Block. ok.
3099
;2 - performance control
3100
; ebx
3101
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3102
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3103
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3104
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3105
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3106
;eax
3107
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3108
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3109
;---------------------------------------------------------------------------------------------
3110
sys_sheduler: ;noname & halyavin
3111
    cmp eax,0
3112
    je shed_counter
3113
    cmp eax,2
3114
    je perf_control
3115
    cmp eax,3
3116
    je rdmsr_instr
3117
    cmp eax,4
3118
    je wrmsr_instr
3119
    cmp eax,1
3120
    jne not_supported
3121
    call change_task ;delay,0
3122
ret
3123
shed_counter:
3124
    mov eax,[context_counter]
3125
    mov [esp+36],eax
3126
not_supported:
3127
ret
3128
perf_control:
3129
    inc eax ;now eax=3
3130
    cmp ebx,eax
3131
    je cache_disable
3132
    dec eax
3133
    cmp ebx,eax
3134
    je cache_enable
3135
    dec eax
3136
    cmp ebx,eax
3137
    je is_cache_enabled
3138
    dec eax
3139
    cmp ebx,eax
3140
    je modify_pce
3141
ret
3142
 
3143
rdmsr_instr:
3144
;now counter in ecx
3145
;(edx:eax) esi:edi => edx:esi
3146
mov eax,esi
3147
rdmsr
3148
mov [esp+36],eax
3149
mov [esp+24],edx ;ret in ebx?
3150
ret
3151
 
3152
wrmsr_instr:
3153
;now counter in ecx
3154
;(edx:eax) esi:edi => edx:esi
3155
mov eax,esi
3156
wrmsr
3157
mov [esp+36],eax
3158
mov [esp+24],edx ;ret in ebx?
3159
ret
3160
 
3161
cache_disable:
3162
       mov eax,cr0
3163
       or  eax,01100000000000000000000000000000b
3164
       mov cr0,eax
3165
       wbinvd ;set MESI
3166
ret
3167
 
3168
cache_enable:
3169
       mov eax,cr0
3170
       and eax,10011111111111111111111111111111b
3171
       mov cr0,eax
3172
ret
3173
 
3174
is_cache_enabled:
3175
       mov eax,cr0
3176
       mov ebx,eax
3177
       and eax,01100000000000000000000000000000b
3178
       jz cache_disabled
3179
       mov [esp+36],ebx
3180
cache_disabled:
3181
       mov dword [esp+36],eax ;0
3182
ret
3183
 
3184
modify_pce:
3185
       mov eax,cr4
3186
;       mov ebx,0
3187
;       or  bx,100000000b ;pce
3188
;       xor eax,ebx ;invert pce
17 me_root 3189
       bts eax,8 ;pce=cr4[8]
1 ha 3190
       mov cr4,eax
3191
       mov [esp+36],eax
3192
ret
3193
;---------------------------------------------------------------------------------------------
3194
 
3195
 
3196
; check if pixel is allowed to be drawn
3197
 
3198
checkpixel:
21 poddubny 3199
        push eax edx
1 ha 3200
 
3201
        mov  edx,[0xfe00]     ; screen x size
3202
        inc  edx
21 poddubny 3203
        imul edx, ebx
1 ha 3204
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3205
 
21 poddubny 3206
        mov  eax, [0x3010]
1 ha 3207
 
21 poddubny 3208
        xor  ecx, ecx
3209
        cmp  byte [eax+0xe], dl
3210
        setne cl
1 ha 3211
 
21 poddubny 3212
        pop  edx eax
1 ha 3213
        ret
3214
 
3215
uglobal
3216
  mouse_active  db  0
3217
endg
3218
iglobal
3219
  cpustring db 'CPU        '
3220
endg
3221
 
67 diamond 3222
uglobal
76 mario79 3223
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3224
endg
1 ha 3225
 
3226
align 4
3227
; check misc
3228
 
3229
checkmisc:
3230
 
3231
    cmp   [ctrl_alt_del], 1
3232
    jne   nocpustart
3233
    mov   eax, cpustring
41 mikedld 3234
    xor   ebx,ebx               ; no parameters
40 halyavin 3235
    xor   edx,edx               ; no flags
1 ha 3236
    call  start_application_fl
3237
    mov   [ctrl_alt_del], 0
3238
  nocpustart:
3239
    cmp   [mouse_active], 1
3240
    jne   mouse_not_active
3241
    mov   [mouse_active], 0
3242
    xor   edi, edi
3243
    mov   ecx, [0x3004]
3244
   set_mouse_event:
3245
    add   edi, 256
3246
    or    [edi+0x80000+0xA8], dword 00100000b
3247
    loop  set_mouse_event
3248
  mouse_not_active:
3249
 
3250
 
3251
    cmp   [0xfff0],byte 0               ; background update ?
3252
    jz    nobackgr
76 mario79 3253
    cmp    [background_defined], 0
3254
    jz    nobackgr
1 ha 3255
    mov   [0xfff0],byte 2
3256
    call  change_task
3257
    mov   [draw_data+32+0],dword 0
3258
    mov   [draw_data+32+4],dword 0
3259
    mov   eax,[0xfe00]
3260
    mov   ebx,[0xfe04]
3261
    mov   [draw_data+32+8],eax
3262
    mov   [draw_data+32+12],ebx
3263
    call  drawbackground
3264
    mov   [0xfff0],byte 0
3265
    mov   [0xfff4],byte 0
3266
 
3267
  nobackgr:
3268
 
3269
 
3270
    ; system shutdown request
3271
 
3272
    cmp  [0xFF00],byte 0
3273
    je   noshutdown
3274
 
3275
    mov  edx,[shutdown_processes]
3276
    sub  dl,2
3277
 
3278
    cmp  [0xff00],dl
3279
    jne  no_mark_system_shutdown
3280
 
3281
    mov   edx,0x3040
3282
    movzx ecx,byte [0xff00]
3283
    add   ecx,5
3284
  markz:
3285
    mov   [edx+0xa],byte 3
3286
    add   edx,0x20
3287
    loop  markz
3288
 
3289
  no_mark_system_shutdown:
3290
 
3291
    call [disable_mouse]
3292
 
3293
    dec  byte [0xff00]
3294
 
3295
    cmp  [0xff00],byte 0
3296
    je   system_shutdown
3297
 
3298
  noshutdown:
3299
 
3300
 
3301
    mov   eax,[0x3004]                  ; termination
3302
    mov   ebx,0x3020+0xa
3303
    mov   esi,1
3304
 
3305
  newct:
3306
    mov   cl,[ebx]
3307
    cmp   cl,byte 3
3308
    jz    terminate
3309
    cmp   cl,byte 4
3310
    jz    terminate
3311
 
3312
    add   ebx,0x20
3313
    inc   esi
3314
    dec   eax
3315
    jnz   newct
3316
 
3317
    ret
3318
 
3319
 
3320
 
3321
 
3322
; redraw screen
3323
 
3324
redrawscreen:
3325
 
3326
; eax , if process window_data base is eax, do not set flag/limits
3327
 
3328
         pushad
3329
         push  eax
3330
 
3331
;;;         mov   eax,2
3332
;;;         call  delay_hs
3333
 
3334
         ;mov   ecx,0               ; redraw flags for apps
3335
         xor   ecx,ecx
3336
       newdw2:
3337
 
3338
         inc   ecx
3339
         push  ecx
3340
 
3341
         mov   eax,ecx
3342
         shl   eax,5
3343
         add   eax,window_data
3344
 
3345
         cmp   eax,[esp+4]
3346
         je    not_this_task
3347
                                   ; check if window in redraw area
3348
         mov   edi,eax
3349
 
3350
         cmp   ecx,1               ; limit for background
3351
         jz    bgli
3352
 
3353
         mov   eax,[edi+0]
3354
         mov   ebx,[edi+4]
3355
         mov   ecx,[edi+8]
3356
         mov   edx,[edi+12]
3357
         add   ecx,eax
3358
         add   edx,ebx
3359
 
3360
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3361
         cmp   ecx,ebx
3362
         jb    ricino
3363
 
3364
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3365
         cmp   ecx,eax
3366
         jb    ricino
3367
 
3368
         mov   eax,[edi+0]
3369
         mov   ebx,[edi+4]
3370
         mov   ecx,[edi+8]
3371
         mov   edx,[edi+12]
3372
         add   ecx,eax
3373
         add   edx,ebx
3374
 
3375
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3376
         cmp   edx,eax
3377
         jb    ricino
3378
 
3379
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3380
         cmp   ecx,eax
3381
         jb    ricino
3382
 
3383
        bgli:
3384
 
3385
         cmp   edi,esi
3386
         jz    ricino
3387
 
3388
         mov   eax,edi
3389
         add   eax,draw_data-window_data
3390
 
3391
         mov   ebx,[dlx]          ; set limits
3392
         mov   [eax+0],ebx
3393
         mov   ebx,[dly]
3394
         mov   [eax+4],ebx
3395
         mov   ebx,[dlxe]
3396
         mov   [eax+8],ebx
3397
         mov   ebx,[dlye]
3398
         mov   [eax+12],ebx
3399
 
3400
         sub   eax,draw_data-window_data
3401
 
3402
         cmp   ecx,1
3403
         jne   nobgrd
3404
         cmp   esi,1
3405
         je    newdw8
3406
         call  drawbackground
3407
 
3408
       newdw8:
3409
       nobgrd:
3410
 
3411
         mov   [eax+31],byte 1    ; mark as redraw
3412
 
3413
       ricino:
3414
 
3415
       not_this_task:
3416
 
3417
         pop   ecx
3418
 
3419
         cmp   ecx,[0x3004]
3420
         jle   newdw2
3421
 
3422
         pop  eax
3423
         popad
3424
 
3425
         ret
3426
 
3427
calculatebackground:   ; background
3428
 
3429
        ; all black
3430
 
3431
        mov   [display_data-8],dword 4      ; size x
3432
        mov   [display_data-4],dword 2      ; size y
3433
 
3434
        mov   edi, 0x300000                 ; set background to black
3435
        xor   eax, eax
3436
        mov   ecx, 0x0fff00 / 4
3437
        cld
3438
        rep   stosd
3439
 
3440
        mov   edi,display_data              ; set os to use all pixels
3441
        mov   eax,0x01010101
3442
        mov   ecx,0x1fff00 / 4
3443
        rep   stosd
3444
 
3445
        mov   byte [0xFFF0], 0              ; do not draw background!
3446
 
3447
        ret
3448
 
3449
uglobal
3450
  imax    dd 0x0
3451
endg
3452
 
3453
 
3454
 
3455
delay_ms:     ; delay in 1/1000 sec
3456
 
3457
 
3458
        push  eax
3459
        push  ecx
3460
 
3461
        mov   ecx,esi
3462
        ; 
3463
        imul  ecx, 33941
3464
        shr   ecx, 9
3465
        ; 
3466
 
3467
        in    al,0x61
3468
        and   al,0x10
3469
        mov   ah,al
3470
        cld
3471
 
3472
 cnt1:  in    al,0x61
3473
        and   al,0x10
3474
        cmp   al,ah
3475
        jz    cnt1
3476
 
3477
        mov   ah,al
3478
        loop  cnt1
3479
 
3480
        pop   ecx
3481
        pop   eax
3482
 
3483
        ret
3484
 
3485
 
3486
set_app_param:
3487
        push edi
3488
 
3489
        mov  edi,[0x3010]
3490
        mov  [edi],eax
3491
 
3492
        pop  edi
3493
        ret
3494
 
3495
 
3496
 
3497
delay_hs:     ; delay in 1/100 secs
3498
        push  eax
3499
        push  ecx
3500
        push  edx
3501
 
3502
        mov   edx,[timer_ticks];[0xfdf0]
3503
        add   edx,eax
3504
 
3505
      newtic:
3506
        mov   ecx,[timer_ticks];[0xfdf0]
3507
        cmp   edx,ecx
3508
        jbe   zerodelay
3509
 
3510
        call  change_task
3511
 
3512
        jmp   newtic
3513
 
3514
      zerodelay:
3515
        pop   edx
3516
        pop   ecx
3517
        pop   eax
3518
 
3519
        ret
3520
 
3521
 
3522
memmove:       ; memory move in bytes
3523
 
3524
; eax = from
3525
; ebx = to
3526
; ecx = no of bytes
3527
    test ecx, ecx
3528
    jle  .ret
3529
 
3530
 
3531
    push esi edi ecx
3532
 
3533
    mov  edi, ebx
3534
    mov  esi, eax
3535
 
3536
    test ecx, not 11b
3537
    jz   @f
3538
 
3539
    push ecx
3540
    shr  ecx, 2
3541
    rep  movsd
3542
    pop  ecx
3543
    and  ecx, 11b
3544
    jz   .finish
3545
  @@:
3546
    rep  movsb
3547
 
3548
  .finish:
3549
    pop  ecx edi esi
3550
  .ret:
3551
    ret
3552
 
3553
 
75 diamond 3554
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3555
;align 4
1 ha 3556
;
75 diamond 3557
;read_floppy_file:
1 ha 3558
;
75 diamond 3559
;; as input
3560
;;
3561
;; eax pointer to file
3562
;; ebx file lenght
3563
;; ecx start 512 byte block number
3564
;; edx number of blocks to read
3565
;; esi pointer to return/work area (atleast 20 000 bytes)
3566
;;
3567
;;
3568
;; on return
3569
;;
3570
;; eax = 0 command succesful
3571
;;       1 no fd base and/or partition defined
3572
;;       2 yet unsupported FS
3573
;;       3 unknown FS
3574
;;       4 partition not defined at hd
3575
;;       5 file not found
3576
;; ebx = size of file
1 ha 3577
;
75 diamond 3578
;     mov   edi,[0x3010]
3579
;     add   edi,0x10
3580
;     add   esi,[edi]
3581
;     add   eax,[edi]
1 ha 3582
;
75 diamond 3583
;     pushad
3584
;     mov  edi,esi
3585
;     add  edi,1024
3586
;     mov  esi,0x100000+19*512
3587
;     sub  ecx,1
3588
;     shl  ecx,9
3589
;     add  esi,ecx
3590
;     shl  edx,9
3591
;     mov  ecx,edx
3592
;     cld
3593
;     rep  movsb
3594
;     popad
3595
;
3596
;     mov   [esp+36],eax
3597
;     mov   [esp+24],ebx
3598
;     ret
1 ha 3599
 
3600
 
3601
 
3602
align 4
3603
 
3604
sys_programirq:
3605
 
3606
    mov   edi,[0x3010]
3607
    add   edi,0x10
3608
    add   eax,[edi]
3609
 
75 diamond 3610
    cmp   ebx,16
3611
    jae   .not_owner
1 ha 3612
    mov   edi,[0x3010]
3613
    mov   edi,[edi+0x4]
75 diamond 3614
    cmp   edi,[irq_owner+ebx*4]
1 ha 3615
    je    spril1
75 diamond 3616
.not_owner:
1 ha 3617
    mov   [esp+36],dword 1
3618
    ret
3619
  spril1:
3620
 
3621
    mov   esi,eax
3622
    shl   ebx,6
3623
    add   ebx,irq00read
3624
    mov   edi,ebx
3625
    mov   ecx,16
3626
    cld
3627
    rep   movsd
3628
    mov   [esp+36],dword 0
3629
    ret
3630
 
3631
 
3632
align 4
3633
 
3634
get_irq_data:
75 diamond 3635
     cmp   eax,16
3636
     jae   .not_owner
1 ha 3637
     mov   edx,eax           ; check for correct owner
3638
     shl   edx,2
3639
     add   edx,irq_owner
3640
     mov   edx,[edx]
3641
     mov   edi,[0x3010]
3642
     mov   edi,[edi+0x4]
3643
     cmp   edx,edi
3644
     je    gidril1
75 diamond 3645
.not_owner:
3646
     mov   [esp+32],dword 2     ; ecx=2
1 ha 3647
     ret
3648
 
3649
  gidril1:
3650
 
3651
     mov   ebx,eax
3652
     shl   ebx,12
3653
     add   ebx,0x2e0000
3654
     mov   eax,[ebx]
3655
     mov   ecx,1
3656
     test  eax,eax
3657
     jz    gid1
3658
 
3659
     dec   eax
3660
     mov   esi,ebx
3661
     mov   [ebx],eax
3662
     movzx ebx,byte [ebx+0x10]
3663
     add   esi,0x10
3664
     mov   edi,esi
3665
     inc   esi
3666
     mov   ecx,4000 / 4
3667
     cld
3668
     rep   movsd
75 diamond 3669
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
1 ha 3670
   gid1:
3671
     mov   [esp+36],eax
3672
     mov   [esp+32],ecx
3673
     mov   [esp+24],ebx
3674
     ret
3675
 
3676
 
3677
set_io_access_rights:
3678
 
3679
     pushad
3680
 
3681
     mov   edi,[0x3000]
3682
     imul  edi,tss_step
3683
     add   edi,tss_data+128
3684
;     add   edi,128
3685
 
3686
     mov   ecx,eax
3687
     and   ecx,7    ; offset in byte
3688
 
3689
     shr   eax,3    ; number of byte
3690
     add   edi,eax
3691
 
3692
     mov   ebx,1
3693
     shl   ebx,cl
3694
 
3695
     cmp   ebp,0                ; enable access - ebp = 0
3696
     jne   siar1
3697
 
3698
     not   ebx
3699
     and   [edi],byte bl
3700
 
3701
     popad
3702
 
3703
     ret
3704
 
3705
   siar1:
3706
 
3707
     or    [edi],byte bl        ; disable access - ebp = 1
3708
 
3709
     popad
3710
 
3711
     ret
3712
 
3713
 
3714
 
3715
 
3716
 
3717
r_f_port_area:
3718
 
3719
     test  eax, eax
3720
     jnz   free_port_area
3721
;     je    r_port_area
3722
;     jmp   free_port_area
3723
 
3724
;   r_port_area:
3725
 
3726
     pushad
3727
 
3728
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 3729
     ja    rpal1
3730
     cmp   ecx,65536
3731
     jae   rpal1
1 ha 3732
     mov   esi,[0x2d0000]
75 diamond 3733
     test  esi,esi            ; no reserved areas ?
1 ha 3734
     je    rpal2
3735
     cmp   esi,255            ; max reserved
75 diamond 3736
     jae   rpal1
1 ha 3737
   rpal3:
3738
     mov   edi,esi
3739
     shl   edi,4
3740
     add   edi,0x2d0000
3741
     cmp   ebx,[edi+8]
75 diamond 3742
     ja    rpal4
1 ha 3743
     cmp   ecx,[edi+4]
3744
     jae   rpal1
3745
;     jb    rpal4
3746
;     jmp   rpal1
3747
   rpal4:
3748
 
3749
     dec   esi
3750
     jnz   rpal3
3751
     jmp   rpal2
3752
   rpal1:
3753
     popad
3754
     mov   eax,1
3755
     ret
3756
 
3757
   rpal2:
3758
     popad
3759
 
3760
 
3761
     ; enable port access at port IO map
3762
     cli
3763
     pushad                        ; start enable io map
3764
 
3765
     cmp   ecx,65536 ;16384
3766
     jae   no_unmask_io ; jge
3767
 
3768
     mov   eax,ebx
3769
 
3770
   new_port_access:
3771
 
3772
     pushad
3773
 
75 diamond 3774
     xor   ebp,ebp                ; enable - eax = port
1 ha 3775
     call  set_io_access_rights
3776
 
3777
     popad
3778
 
3779
     inc   eax
3780
     cmp   eax,ecx
3781
     jbe   new_port_access
3782
 
3783
   no_unmask_io:
3784
 
3785
     popad                         ; end enable io map
3786
     sti
3787
 
3788
     mov   edi,[0x2d0000]
3789
     add   edi,1
3790
     mov   [0x2d0000],edi
3791
     shl   edi,4
3792
     add   edi,0x2d0000
3793
     mov   esi,[0x3010]
3794
     mov   esi,[esi+0x4]
3795
     mov   [edi],esi
3796
     mov   [edi+4],ebx
3797
     mov   [edi+8],ecx
3798
 
3799
     xor   eax, eax
3800
     ret
3801
 
3802
 
3803
 
3804
 
3805
free_port_area:
3806
 
3807
     pushad
3808
 
3809
     mov   esi,[0x2d0000]     ; no reserved areas ?
75 diamond 3810
     test  esi,esi
1 ha 3811
     je    frpal2
3812
     mov   edx,[0x3010]
3813
     mov   edx,[edx+4]
3814
   frpal3:
3815
     mov   edi,esi
3816
     shl   edi,4
3817
     add   edi,0x2d0000
3818
     cmp   edx,[edi]
3819
     jne   frpal4
3820
     cmp   ebx,[edi+4]
3821
     jne   frpal4
3822
     cmp   ecx,[edi+8]
3823
     jne   frpal4
3824
     jmp   frpal1
3825
   frpal4:
3826
     dec   esi
3827
     jnz   frpal3
3828
   frpal2:
3829
     popad
3830
     mov   eax,1
3831
     ret
3832
   frpal1:
3833
     mov   ecx,256
3834
     sub   ecx,esi
3835
     shl   ecx,4
3836
     mov   esi,edi
3837
     add   esi,16
3838
     cld
3839
     rep   movsb
3840
 
3841
     dec   dword [0x2d0000]
3842
 
3843
     popad
3844
 
3845
 
3846
     ; disable port access at port IO map
3847
 
3848
     pushad                        ; start disable io map
3849
 
3850
     cmp   ecx,65536 ;16384
3851
     jge   no_mask_io
3852
 
3853
     mov   eax,ebx
3854
 
3855
   new_port_access_disable:
3856
 
3857
     pushad
3858
 
3859
     mov   ebp,1                  ; disable - eax = port
3860
     call  set_io_access_rights
3861
 
3862
     popad
3863
 
3864
     inc   eax
3865
     cmp   eax,ecx
3866
     jbe   new_port_access_disable
3867
 
3868
   no_mask_io:
3869
 
3870
     popad                         ; end disable io map
3871
 
3872
     xor   eax, eax
3873
     ret
3874
 
3875
 
3876
reserve_free_irq:
3877
 
75 diamond 3878
     mov   ecx, 1
3879
     cmp   ebx, 16
3880
     jae   fril1
3881
     test  eax,eax
1 ha 3882
     jz    reserve_irq
3883
 
75 diamond 3884
     lea   edi,[irq_owner+ebx*4]
1 ha 3885
     mov   edx,[edi]
3886
     mov   eax,[0x3010]
75 diamond 3887
     cmp   edx,[eax+0x4]
1 ha 3888
     jne   fril1
75 diamond 3889
     dec   ecx
3890
     mov   [edi],ecx
1 ha 3891
   fril1:
3892
     mov   [esp+36],ecx ; return in eax
3893
     ret
3894
 
3895
  reserve_irq:
3896
 
75 diamond 3897
     lea   edi,[irq_owner+ebx*4]
3898
     cmp   dword [edi], 0
3899
     jnz   ril1
1 ha 3900
 
3901
     mov   edx,[0x3010]
3902
     mov   edx,[edx+0x4]
3903
     mov   [edi],edx
75 diamond 3904
     dec   ecx
1 ha 3905
   ril1:
3906
     mov   [esp+36],ecx ; return in eax
3907
     ret
3908
 
3909
 
3910
 
3911
drawbackground:
33 mario79 3912
       inc   [mouse_pause]
1 ha 3913
       cmp   [0xfe0c],word 0x12
3914
       jne   dbrv12
3915
       cmp   [display_data-12],dword 1
3916
       jne   bgrstr12
3917
       call  vga_drawbackground_tiled
33 mario79 3918
       dec   [mouse_pause]
36 mario79 3919
       call   [draw_pointer]
1 ha 3920
       ret
3921
     bgrstr12:
3922
       call  vga_drawbackground_stretch
33 mario79 3923
       dec   [mouse_pause]
36 mario79 3924
       call   [draw_pointer]
1 ha 3925
       ret
3926
     dbrv12:
3927
 
3928
       cmp  [0xfe0c],word 0100000000000000b
3929
       jge  dbrv20
3930
       cmp  [0xfe0c],word 0x13
3931
       je   dbrv20
3932
       call  vesa12_drawbackground
33 mario79 3933
       dec   [mouse_pause]
36 mario79 3934
       call   [draw_pointer]
1 ha 3935
       ret
3936
     dbrv20:
3937
       cmp   [display_data-12],dword 1
3938
       jne   bgrstr
3939
       call  vesa20_drawbackground_tiled
33 mario79 3940
       dec   [mouse_pause]
36 mario79 3941
       call   [draw_pointer]
1 ha 3942
       ret
3943
     bgrstr:
3944
       call  vesa20_drawbackground_stretch
33 mario79 3945
       dec   [mouse_pause]
36 mario79 3946
       call   [draw_pointer]
1 ha 3947
       ret
3948
 
75 diamond 3949
align 4
1 ha 3950
 
75 diamond 3951
syscall_putimage:                       ; PutImage
33 mario79 3952
 
75 diamond 3953
     mov   edx,ecx
3954
     mov   ecx,ebx
3955
        lea     ebx, [eax+std_application_base_address]
3956
 
1 ha 3957
sys_putimage:
53 mikedld 3958
     test  ecx,0x80008000
3959
     jnz   .exit
3960
     test  ecx,0x0000FFFF
3961
     jz    .exit
3962
     test  ecx,0xFFFF0000
3963
     jnz   @f
3964
  .exit:
3965
     ret
3966
 @@:
75 diamond 3967
        mov     eax, vga_putimage
3968
        cmp     [0xfe0c], word 0x12
3969
        jz      .doit
3970
        mov     eax, vesa12_putimage
3971
        cmp     [0xfe0c], word 0100000000000000b
3972
        jae     @f
3973
        cmp     [0xfe0c], word 0x13
3974
        jnz     .doit
3975
@@:
3976
        mov     eax, vesa20_putimage
3977
.doit:
3978
;       inc     [mouse_pause]
3979
        call    eax
3980
;       dec     [mouse_pause]
3981
        jmp     [draw_pointer]
1 ha 3982
 
3983
; eax x beginning
3984
; ebx y beginning
3985
; ecx x end
3986
; edx y end
3987
; edi color
3988
 
3989
__sys_drawbar:
33 mario79 3990
    inc   [mouse_pause]
3991
    cmp   [0xfe0c],word 0x12
3992
    jne   sdbv20
3993
    call  vga_drawbar
3994
    dec   [mouse_pause]
36 mario79 3995
    call   [draw_pointer]
33 mario79 3996
    ret
1 ha 3997
   sdbv20:
3998
    cmp  [0xfe0c],word 0100000000000000b
3999
    jge  dbv20
4000
    cmp  [0xfe0c],word 0x13
4001
    je   dbv20
4002
    call vesa12_drawbar
33 mario79 4003
    dec   [mouse_pause]
36 mario79 4004
    call   [draw_pointer]
1 ha 4005
    ret
4006
  dbv20:
4007
    call vesa20_drawbar
33 mario79 4008
    dec   [mouse_pause]
36 mario79 4009
    call   [draw_pointer]
1 ha 4010
    ret
4011
 
4012
 
4013
 
4014
kb_read:
4015
 
4016
        push    ecx edx
4017
 
98 mario79 4018
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4019
      kr_loop:
4020
        in      al,0x64
4021
        test    al,1
4022
        jnz     kr_ready
4023
        loop    kr_loop
4024
        mov     ah,1
4025
        jmp     kr_exit
4026
      kr_ready:
4027
        push    ecx
4028
        mov     ecx,32
4029
      kr_delay:
4030
        loop    kr_delay
4031
        pop     ecx
4032
        in      al,0x60
4033
        xor     ah,ah
4034
      kr_exit:
4035
 
4036
        pop     edx ecx
4037
 
4038
        ret
4039
 
4040
 
4041
kb_write:
4042
 
4043
        push    ecx edx
4044
 
4045
        mov     dl,al
98 mario79 4046
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4047
      kw_loop1:
4048
        in      al,0x64
4049
        test    al,0x20
4050
        jz      kw_ok1
4051
        loop    kw_loop1
4052
        mov     ah,1
4053
        jmp     kw_exit
4054
      kw_ok1:
4055
        in      al,0x60
98 mario79 4056
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4057
      kw_loop:
4058
        in      al,0x64
4059
        test    al,2
4060
        jz      kw_ok
4061
        loop    kw_loop
4062
        mov     ah,1
4063
        jmp     kw_exit
4064
      kw_ok:
4065
        mov     al,dl
4066
        out     0x60,al
98 mario79 4067
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4068
      kw_loop3:
4069
        in      al,0x64
4070
        test    al,2
4071
        jz      kw_ok3
4072
        loop    kw_loop3
4073
        mov     ah,1
4074
        jmp     kw_exit
4075
      kw_ok3:
4076
        mov     ah,8
4077
      kw_loop4:
98 mario79 4078
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4079
      kw_loop5:
4080
        in      al,0x64
4081
        test    al,1
4082
        jnz     kw_ok4
4083
        loop    kw_loop5
4084
        dec     ah
4085
        jnz     kw_loop4
4086
      kw_ok4:
4087
        xor     ah,ah
4088
      kw_exit:
4089
 
4090
        pop     edx ecx
4091
 
4092
        ret
4093
 
4094
 
4095
kb_cmd:
4096
 
98 mario79 4097
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4098
      c_wait:
4099
        in      al,0x64
4100
        test    al,2
4101
        jz      c_send
4102
        loop    c_wait
4103
        jmp     c_error
4104
      c_send:
4105
        mov     al,bl
4106
        out     0x64,al
98 mario79 4107
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4108
      c_accept:
4109
        in      al,0x64
4110
        test    al,2
4111
        jz      c_ok
4112
        loop    c_accept
4113
      c_error:
4114
        mov     ah,1
4115
        jmp     c_exit
4116
      c_ok:
4117
        xor     ah,ah
4118
      c_exit:
4119
        ret
4120
 
4121
 
4122
setmouse:  ; set mousepicture -pointer
4123
           ; ps2 mouse enable
4124
 
4125
     mov     [0xf200],dword mousepointer
4126
 
4127
     cli
33 mario79 4128
;     mov     bl,0xa8                 ; enable mouse cmd
4129
;     call    kb_cmd
4130
;     call    kb_read                 ; read status
4131
;     mov     bl,0x20                 ; get command byte
4132
;     call    kb_cmd
4133
;     call    kb_read
4134
;     or      al,3                    ; enable interrupt
4135
;     mov     bl,0x60                 ; write command
4136
;     push    eax
4137
;     call    kb_cmd
4138
;     pop     eax
4139
;     call    kb_write
4140
;     mov     bl,0xd4                 ; for mouse
4141
;     call    kb_cmd
4142
;     mov     al,0xf4                 ; enable mouse device
4143
;     call    kb_write
4144
;     call    kb_read           ; read status return
1 ha 4145
 
4146
     ; com1 mouse enable
4147
 
4148
     mov   bx,0x3f8 ; combase
4149
 
4150
     mov   dx,bx
4151
     add   dx,3
4152
     mov   al,0x80
4153
     out   dx,al
4154
 
4155
     mov   dx,bx
4156
     add   dx,1
4157
     mov   al,0
4158
     out   dx,al
4159
 
4160
     mov   dx,bx
4161
     add   dx,0
4162
     mov   al,0x30*2    ; 0x30 / 4
4163
     out   dx,al
4164
 
4165
     mov   dx,bx
4166
     add   dx,3
4167
     mov   al,2         ; 3
4168
     out   dx,al
4169
 
4170
     mov   dx,bx
4171
     add   dx,4
4172
     mov   al,0xb
4173
     out   dx,al
4174
 
4175
     mov   dx,bx
4176
     add   dx,1
4177
     mov   al,1
4178
     out   dx,al
4179
 
4180
 
4181
     ; com2 mouse enable
4182
 
4183
     mov   bx,0x2f8 ; combase
4184
 
4185
     mov   dx,bx
4186
     add   dx,3
4187
     mov   al,0x80
4188
     out   dx,al
4189
 
4190
     mov   dx,bx
4191
     add   dx,1
4192
     mov   al,0
4193
     out   dx,al
4194
 
4195
     mov   dx,bx
4196
     add   dx,0
4197
     mov   al,0x30*2
4198
     out   dx,al
4199
 
4200
     mov   dx,bx
4201
     add   dx,3
4202
     mov   al,2
4203
     out   dx,al
4204
 
4205
     mov   dx,bx
4206
     add   dx,4
4207
     mov   al,0xb
4208
     out   dx,al
4209
 
4210
     mov   dx,bx
4211
     add   dx,1
4212
     mov   al,1
4213
     out   dx,al
4214
 
4215
     ret
4216
 
4217
 
4218
_rdtsc:
4219
 
4220
     mov   edx,[cpuid_1+3*4]
4221
     test  edx,00010000b
4222
     jz    ret_rdtsc
4223
     rdtsc
4224
     ret
4225
   ret_rdtsc:
4226
     mov   edx,0xffffffff
4227
     mov   eax,0xffffffff
4228
     ret
4229
 
4230
 
4231
 
4232
rerouteirqs:
4233
 
4234
        cli
4235
 
4236
        mov     al,0x11         ;  icw4, edge triggered
4237
        out     0x20,al
4238
        call    pic_delay
4239
        out     0xA0,al
4240
        call    pic_delay
4241
 
4242
        mov     al,0x20         ;  generate 0x20 +
4243
        out     0x21,al
4244
        call    pic_delay
4245
        mov     al,0x28         ;  generate 0x28 +
4246
        out     0xA1,al
4247
        call    pic_delay
4248
 
4249
        mov     al,0x04         ;  slave at irq2
4250
        out     0x21,al
4251
        call    pic_delay
4252
        mov     al,0x02         ;  at irq9
4253
        out     0xA1,al
4254
        call    pic_delay
4255
 
4256
        mov     al,0x01         ;  8086 mode
4257
        out     0x21,al
4258
        call    pic_delay
4259
        out     0xA1,al
4260
        call    pic_delay
4261
 
4262
        mov     al,255          ; mask all irq's
4263
        out     0xA1,al
4264
        call    pic_delay
4265
        out     0x21,al
4266
        call    pic_delay
4267
 
4268
        mov     ecx,0x1000
4269
        cld
4270
picl1:  call    pic_delay
4271
        loop    picl1
4272
 
4273
        mov     al,255          ; mask all irq's
4274
        out     0xA1,al
4275
        call    pic_delay
4276
        out     0x21,al
4277
        call    pic_delay
4278
 
4279
        cli
4280
 
4281
        ret
4282
 
4283
 
4284
pic_delay:
4285
 
4286
        jmp     pdl1
4287
pdl1:   ret
4288
 
4289
 
4290
sys_msg_board_str:
4291
 
4292
     pushad
4293
   @@:
4294
     cmp    [esi],byte 0
4295
     je     @f
4296
     mov    eax,1
4297
     movzx  ebx,byte [esi]
4298
     call   sys_msg_board
4299
     inc    esi
4300
     jmp    @b
4301
   @@:
4302
     popad
4303
     ret
4304
 
4305
uglobal
4306
  msg_board_data: times 512 db 0
4307
  msg_board_count dd 0x0
4308
endg
4309
 
4310
sys_msg_board:
4311
 
4312
; eax=1 : write :  bl byte to write
4313
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4314
 
4315
     mov  ecx,[msg_board_count]
4316
     cmp  eax, 1
4317
     jne  smbl1
4318
 
4319
 
4320
     mov  [msg_board_data+ecx],bl
4321
     inc  ecx
4322
     and  ecx, 511
4323
     mov  [msg_board_count], ecx
4324
     mov  [check_idle_semaphore], 5
4325
     ret
4326
   smbl1:
4327
 
4328
     cmp   eax, 2
4329
     jne   smbl2
4330
     test  ecx, ecx
4331
     jz    smbl21
4332
;     mov   edi, msg_board_data
4333
;     mov   esi, msg_board_data+1
4334
;     movzx eax, byte [edi]
4335
     mov   eax, msg_board_data+1
4336
     mov   ebx, msg_board_data
4337
     movzx edx, byte [ebx]
4338
     call  memmove
4339
;     push  ecx
4340
;     shr   ecx, 2
4341
;     cld
4342
;     rep   movsd
4343
;     pop   ecx
4344
;     and   ecx, 3
4345
;     rep   movsb
4346
     dec   [msg_board_count]
4347
     mov   [esp+36], edx ;eax
4348
     mov   [esp+24], dword 1
4349
     ret
4350
   smbl21:
4351
     mov   [esp+36], ecx
4352
     mov   [esp+24], ecx
4353
 
4354
   smbl2:
4355
     ret
4356
 
4357
 
4358
 
4359
sys_trace:
4360
 
4361
     test eax, eax                  ; get event data
4362
     jnz  no_get_sys_events
4363
 
4364
     mov  esi,save_syscall_data     ; data
4365
     mov  edi,[0x3010]
4366
     mov  edi,[edi+0x10]
4367
     add  edi,ebx
4368
     cld
4369
     rep  movsb
4370
 
4371
     mov  [esp+24],dword 0
4372
     mov  eax,[save_syscall_count]  ; count
4373
     mov  [esp+36],eax
4374
     ret
4375
 
4376
   no_get_sys_events:
4377
 
4378
     ret
4379
 
4380
 
4381
sys_process_def:
92 diamond 4382
        mov     edi, [0x3000]
1 ha 4383
 
92 diamond 4384
        dec     eax             ; 1 = set keyboard mode
1 ha 4385
     jne   no_set_keyboard_setup
4386
 
4387
     shl   edi,8
92 diamond 4388
     mov   [edi+0x800B4],bl
1 ha 4389
 
4390
     ret
4391
 
4392
   no_set_keyboard_setup:
4393
 
92 diamond 4394
        dec     eax             ; 2 = get keyboard mode
1 ha 4395
     jne   no_get_keyboard_setup
4396
 
4397
     shl   edi,8
92 diamond 4398
     movzx eax, byte [0x800B4+edi]
1 ha 4399
 
4400
     mov   [esp+36],eax
4401
 
4402
     ret
4403
 
4404
   no_get_keyboard_setup:
4405
 
92 diamond 4406
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4407
     jne   no_get_keyboard_cas
4408
 
4409
;     xor   eax,eax
4410
;     movzx eax,byte [shift]
4411
;     movzx ebx,byte [ctrl]
4412
;     shl   ebx,2
4413
;     add   eax,ebx
4414
;     movzx ebx,byte [alt]
4415
;     shl   ebx,3
4416
;     add   eax,ebx
4417
 
4418
 ;// mike.dld [
4419
     mov   eax, [kb_state]
4420
 ;// mike.dld ]
4421
 
4422
     mov   [esp+36],eax
4423
 
4424
     ret
4425
 
4426
   no_get_keyboard_cas:
4427
 
92 diamond 4428
        dec     eax
4429
        jnz     no_add_keyboard_hotkey
1 ha 4430
 
92 diamond 4431
        mov     eax, hotkey_list
4432
@@:
4433
        cmp     dword [eax+8], 0
4434
        jz      .found_free
4435
        add     eax, 16
4436
        cmp     eax, hotkey_list+16*256
4437
        jb      @b
4438
        mov     dword [esp+36], 1
4439
        ret
4440
.found_free:
4441
        mov     [eax+8], edi
4442
        mov     [eax+4], ecx
4443
        movzx   ebx, bl
4444
        lea     ebx, [hotkey_scancodes+ebx*4]
4445
        mov     ecx, [ebx]
4446
        mov     [eax], ecx
4447
        mov     [ebx], eax
4448
        mov     [eax+12], ebx
4449
        jecxz   @f
4450
        mov     [ecx+12], eax
4451
@@:
4452
        and     dword [esp+36], 0
4453
        ret
4454
 
4455
no_add_keyboard_hotkey:
4456
 
4457
        dec     eax
4458
        jnz     no_del_keyboard_hotkey
4459
 
4460
        movzx   ebx, bl
4461
        lea     ebx, [hotkey_scancodes+ebx*4]
4462
        mov     eax, [ebx]
4463
.scan:
4464
        test    eax, eax
4465
        jz      .notfound
4466
        cmp     [eax+8], edi
4467
        jnz     .next
4468
        cmp     [eax+4], ecx
4469
        jz      .found
4470
.next:
4471
        mov     eax, [eax]
4472
        jmp     .scan
4473
.notfound:
4474
        mov     dword [esp+36], 1
4475
        ret
4476
.found:
4477
        mov     ecx, [eax]
4478
        jecxz   @f
4479
        mov     edx, [eax+12]
4480
        mov     [ecx+12], edx
4481
@@:
4482
        mov     ecx, [eax+12]
4483
        mov     edx, [eax]
4484
        mov     [ecx], edx
4485
        xor     edx, edx
4486
        mov     [eax+4], edx
4487
        mov     [eax+8], edx
4488
        mov     [eax+12], edx
4489
        mov     [eax], edx
4490
        mov     [esp+36], edx
4491
        ret
4492
 
4493
no_del_keyboard_hotkey:
1 ha 4494
     ret
4495
 
4496
 
4497
sys_ipc:
4498
     cmp  eax,1                      ; DEFINE IPC MEMORY
4499
     jne  no_ipc_def
4500
     mov  edi,[0x3000]
4501
     shl  edi,8
4502
     add  edi,0x80000
4503
     mov  [edi+0xA0],ebx
4504
     mov  [edi+0xA4],ecx
4505
     mov  [esp+36],dword 0
4506
     ret
4507
   no_ipc_def:
4508
 
4509
     cmp  eax,2                      ; SEND IPC MESSAGE
4510
     jne  no_ipc_send
4511
     mov  esi,1
4512
     mov  edi,0x3020
4513
    ipcs1:
4514
     cmp  [edi+4],ebx
4515
     je   ipcs2
4516
     add  edi,0x20
4517
     inc  esi
4518
     cmp  esi,[0x3004]
4519
     jbe  ipcs1
4520
     mov  [esp+36],dword 4
4521
     ret
4522
    ipcs2:
4523
 
4524
     cli
4525
 
4526
     push esi
4527
     mov  eax,esi
4528
     shl  eax,8
4529
     mov  ebx,[eax+0x80000+0xa0]
4530
     test ebx,ebx                  ; ipc area not defined ?
4531
     je   ipc_err1
4532
 
4533
     add  ebx,[eax+0x80000+0xa4]
4534
     mov  eax,esi
4535
     shl  eax,5
4536
     add  ebx,[eax+0x3000+0x10]    ; ebx <- max data position
4537
 
4538
     mov  eax,esi                  ; to
4539
     shl  esi,8
4540
     add  esi,0x80000
4541
     mov  edi,[esi+0xa0]
4542
     shl  eax,5
4543
     add  eax,0x3000
4544
     add  edi,[eax+0x10]
4545
 
4546
     cmp  [edi],byte 0             ; overrun ?
4547
     jne  ipc_err2
4548
 
4549
     mov  ebp,edi
4550
     add  edi,[edi+4]
4551
     add  edi,8
4552
 
4553
     mov  esi,ecx                  ; from
4554
     mov  eax,[0x3010]
4555
     mov  eax,[eax+0x10]
4556
     add  esi,eax
4557
 
4558
     mov  ecx,edx                  ; size
4559
 
4560
     mov  eax,edi
4561
     add  eax,ecx
4562
     cmp  eax,ebx
75 diamond 4563
     jg   ipc_err3                 ; not enough room ?
1 ha 4564
 
4565
     push ecx
4566
 
4567
     mov  eax,[0x3010]
4568
     mov  eax,[eax+4]
4569
     mov  [edi-8],eax
4570
     mov  [edi-4],ecx
4571
     cld
4572
     rep  movsb
4573
 
4574
     pop  ecx
4575
     add  ecx,8
4576
 
4577
     mov  edi,ebp                  ; increase memory position
4578
     add  dword [edi+4],ecx
4579
 
4580
     mov  edi,[esp]
4581
     shl  edi,8
4582
     or   dword [edi+0x80000+0xA8],dword 01000000b ; ipc message
4583
 
4584
     cmp  [check_idle_semaphore],dword 20
4585
     jge  ipc_no_cis
4586
     mov  [check_idle_semaphore],5
4587
   ipc_no_cis:
4588
 
4589
     xor  eax, eax
4590
 
4591
    ipc_err:
4592
     add  esp,4
4593
     mov  [esp+36],eax
4594
     sti
4595
     ret
4596
 
4597
    ipc_err1:
4598
     add  esp,4
4599
     mov  [esp+36],dword 1
4600
     sti
4601
     ret
4602
    ipc_err2:
4603
     add  esp,4
4604
     mov  [esp+36],dword 2
4605
     sti
4606
     ret
4607
    ipc_err3:
4608
     add  esp,4
4609
     mov  [esp+36],dword 3
4610
     sti
4611
     ret
4612
 
4613
   no_ipc_send:
4614
 
4615
     mov  [esp+36],dword -1
4616
     ret
4617
 
4618
 
4619
align 4
4620
 
4621
sys_gs:                         ; direct screen access
4622
 
4623
     cmp  eax,1                 ; resolution
4624
     jne  no_gs1
4625
     mov  eax,[0xfe00]
4626
     shl  eax,16
4627
     mov  ax,[0xfe04]
4628
     add  eax,0x00010001
4629
     mov  [esp+36],eax
4630
     ret
4631
   no_gs1:
4632
 
4633
     cmp   eax,2                ; bits per pixel
4634
     jne   no_gs2
4635
     movzx eax,byte [0xfbf1]
4636
     mov   [esp+36],eax
4637
     ret
4638
   no_gs2:
4639
 
4640
     cmp   eax,3                ; bytes per scanline
4641
     jne   no_gs3
4642
     mov   eax,[0xfe08]
4643
     mov   [esp+36],eax
4644
     ret
4645
   no_gs3:
4646
 
4647
     mov  [esp+36],dword -1
4648
     ret
4649
 
4650
 
4651
align 4 ; PCI functions
4652
 
4653
sys_pci:
4654
 
4655
     call  pci_api
4656
     mov   [esp+36],eax
4657
     ret
4658
 
4659
 
4660
align 4  ;  system functions
4661
 
4662
syscall_setpixel:                       ; SetPixel
4663
 
4664
 
4665
     mov   edx,[0x3010]
4666
     add   eax,[edx-twdw]
4667
     add   ebx,[edx-twdw+4]
33 mario79 4668
;     xor   edi,edi ; no force
4669
     mov   edi,1
4670
;     call  [disable_mouse]
1 ha 4671
     jmp   [putpixel]
4672
 
4673
align 4
4674
 
4675
syscall_writetext:                      ; WriteText
4676
 
4677
     mov   edi,[0x3010]
4678
     mov   ebp,[edi-twdw]
4679
     shl   ebp,16
4680
     add   ebp,[edi-twdw+4]
4681
     add   edi,0x10
4682
     add   ecx,[edi]
4683
     add   eax,ebp
4684
     xor   edi,edi
4685
     jmp   dtext
4686
 
4687
align 4
4688
 
4689
syscall_openramdiskfile:                ; OpenRamdiskFile
4690
 
4691
 
4692
     mov   edi,[0x3010]
4693
     add   edi,0x10
4694
     add   eax,[edi]
4695
     add   edx,[edi]
4696
     mov   esi,12
4697
     call  fileread
4698
     mov   [esp+36],ebx
4699
     ret
4700
 
4701
align 4
4702
 
4703
syscall_drawrect:                       ; DrawRect
4704
 
4705
     mov   edi,ecx
52 mikedld 4706
     and   edi,0x80FFFFFF
1 ha 4707
     test  ax,ax
4708
     je    drectr
4709
     test  bx,bx
4710
     je    drectr
4711
     movzx ecx,ax
4712
     shr   eax,16
4713
     movzx edx,bx
4714
     shr   ebx,16
4715
     add   ecx,eax
4716
     add   edx,ebx
4717
     jmp   [drawbar]
4718
    drectr:
4719
     ret
4720
 
4721
align 4
4722
 
4723
syscall_getscreensize:                  ; GetScreenSize
4724
 
4725
     movzx eax,word[0xfe00]
4726
     shl   eax,16
4727
     mov   ax,[0xfe04]
4728
     mov   [esp+36],eax
4729
     ret
4730
 
4731
align 4
4732
 
4733
syscall_startapp:                       ; StartApp
4734
     mov   edi,[0x3010]
4735
     add   edi,0x10
4736
     add   eax,[edi]
4737
     test  ebx,ebx
4738
     jz    noapppar
4739
     add   ebx,[edi]
4740
   noapppar:
4741
;     call  start_application_fl
41 mikedld 4742
     xor   edx,edx      ; compatibility - flags=0
1 ha 4743
     call   new_start_application_fl
4744
     mov   [esp+36],eax
4745
     ret
4746
 
41 mikedld 4747
 
1 ha 4748
align 4
4749
 
4750
syscall_cdaudio:                        ; CD
4751
 
4752
     call  sys_cd_audio
4753
     mov   [esp+36],eax
4754
     ret
4755
 
75 diamond 4756
;  ReadHd and StartHdApp functions are obsolete. Use 58 or 70 functions instead.
4757
;align 4
4758
;
4759
;syscall_readhd:                         ; ReadHd
4760
;
4761
;     mov   edi,[0x3010]
4762
;     add   edi,0x10
4763
;     add   esi,[edi]
4764
;     add   eax,[edi]
4765
;     call  read_hd_file
4766
;     mov   [esp+36],eax
4767
;     mov   [esp+24],ebx
4768
;     ret
1 ha 4769
 
75 diamond 4770
;align 4
4771
;
4772
;syscall_starthdapp:                     ; StartHdApp
4773
;
4774
;     mov   edi,[0x3010]
4775
;     add   edi,0x10
4776
;     add   eax,[edi]
4777
;     add   ecx,[edi]
4778
;     xor   ebp,ebp
4779
;     xor   edx,edx      ; compatibility - flags=0
4780
;     call  start_application_hd
4781
;     mov   [esp+36],eax
4782
;     ret
1 ha 4783
 
4784
align 4
4785
 
4786
syscall_delramdiskfile:                 ; DelRamdiskFile
4787
 
4788
     mov   edi,[0x3010]
4789
     add   edi,0x10
4790
     add   eax,[edi]
4791
     call  filedelete
4792
     mov   [esp+36],eax
4793
     ret
4794
 
4795
align 4
4796
 
4797
syscall_writeramdiskfile:               ; WriteRamdiskFile
4798
 
4799
     mov   edi,[0x3010]
4800
     add   edi,0x10
4801
     add   eax,[edi]
4802
     add   ebx,[edi]
4803
     call  filesave
4804
     mov   [esp+36],eax
4805
     ret
4806
 
4807
align 4
4808
 
4809
syscall_getpixel:                       ; GetPixel
4810
 
4811
     mov   ecx,[0xfe00]
4812
     inc   ecx
4813
     xor   edx,edx
4814
     div   ecx
4815
     mov   ebx,edx
4816
     xchg  eax,ebx
4817
     call  dword [0xe024]
4818
     mov   [esp+36],ecx
4819
     ret
4820
 
4821
align 4
4822
 
4823
syscall_readstring:                     ; ReadString
4824
 
4825
     mov   edi,[0x3010]
4826
     add   edi,0x10
4827
     add   eax,[edi]
4828
     call  read_string
4829
     mov   [esp+36],eax
4830
     ret
4831
 
4832
align 4
4833
 
4834
syscall_drawline:                       ; DrawLine
4835
 
4836
     mov   edi,[0x3010]
4837
     movzx edx,word[edi-twdw]
4838
     mov   ebp,edx
4839
     shl   edx,16
4840
     add   ebp,edx
4841
     movzx edx,word[edi-twdw+4]
4842
     add   eax,ebp
4843
     mov   ebp,edx
4844
     shl   edx,16
4845
     xor   edi,edi
4846
     add   edx,ebp
4847
     add   ebx,edx
4848
     jmp   [draw_line]
4849
 
4850
align 4
4851
 
4852
syscall_getirqowner:                    ; GetIrqOwner
75 diamond 4853
     cmp   eax,16
4854
     jae   .err
1 ha 4855
     shl   eax,2
4856
     add   eax,irq_owner
4857
     mov   eax,[eax]
4858
     mov   [esp+36],eax
4859
     ret
75 diamond 4860
.err:
4861
     or    dword [esp+36], -1
4862
     ret
1 ha 4863
 
4864
align 4
4865
 
4866
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4867
 
4868
     call  r_f_port_area
4869
     mov   [esp+36],eax
4870
     ret
4871
 
4872
align 4
4873
 
4874
syscall_threads:                        ; CreateThreads
4875
 
4876
     call  sys_threads
4877
     mov   [esp+36],eax
4878
     ret
4879
 
4880
align 4
4881
 
4882
stack_driver_stat:
4883
 
4884
     call  app_stack_handler            ; Stack status
4885
 
4886
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4887
;     call  change_task                 ; between sent packet
4888
 
4889
     mov   [esp+36],eax
4890
     ret
4891
 
4892
align 4
4893
 
4894
socket:                                 ; Socket interface
4895
     call  app_socket_handler
4896
 
4897
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4898
;     call  change_task                 ; between sent packet
4899
 
4900
     mov   [esp+36],eax
4901
     mov   [esp+24],ebx
4902
     ret
4903
 
4904
align 4
4905
 
4906
user_events:                            ; User event times
4907
 
4908
     mov   eax,0x12345678
4909
     mov   [esp+36],eax
4910
 
4911
     ret
4912
 
4913
align 4
4914
 
4915
read_from_hd:                           ; Read from hd - fn not in use
4916
 
4917
     mov   edi,[0x3010]
4918
     add   edi,0x10
4919
     add   eax,[edi]
4920
     add   ecx,[edi]
4921
     add   edx,[edi]
4922
     call  file_read
4923
 
4924
     mov   [esp+36],eax
4925
     mov   [esp+24],ebx
4926
 
4927
     ret
4928
 
4929
 
4930
align 4
4931
 
4932
write_to_hd:                            ; Write a file to hd
4933
 
4934
     mov   edi,[0x3010]
4935
     add   edi,0x10
4936
     add   eax,[edi]
4937
     add   ecx,[edi]
4938
     add   edx,[edi]
4939
     call  file_write
4940
     ret
4941
 
75 diamond 4942
;  Sysfunction 57, delete_from_hd, is obsolete. Use 58 or 70 functions instead.
4943
;align 4
4944
;
4945
;delete_from_hd:                         ; Delete a file from hd
4946
;
4947
;     mov   edi,[0x3010]
4948
;     add   edi,0x10
4949
;     add   eax,[edi]
4950
;     add   ecx,[edi]
4951
;     call  file_delete
4952
;     ret
4953
;
1 ha 4954
 
76 mario79 4955
; --------------- APM ---------------------
4956
apm_entry    dp    0
4957
apm_vf        dd    0
1 ha 4958
align 4
76 mario79 4959
sys_apm:
4960
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
4961
    jne    @f
78 diamond 4962
    or    [esp + 56], byte 1    ; error
76 mario79 4963
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
4964
    ret
4965
 
4966
@@:    xchg    eax, ecx
4967
    xchg    ebx, ecx
4968
 
4969
    cmp    al, 3
4970
    ja    @f
78 diamond 4971
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 4972
    mov    eax, [apm_vf]
4973
    mov    [esp + 36], eax
4974
    shr    eax, 16
4975
    mov    [esp + 32], eax
4976
    ret
78 diamond 4977
 
76 mario79 4978
@@:    call    pword [apm_entry]    ; call APM BIOS
4979
    mov    [esp + 8 ], edi
4980
    mov    [esp + 12], esi
4981
    mov    [esp + 24], ebx
4982
    mov    [esp + 28], edx
4983
    mov    [esp + 32], ecx
4984
    mov    [esp + 36], eax
4985
    setc    al
78 diamond 4986
    and    [esp + 56], byte 0xfe
4987
    or    [esp + 56], al
76 mario79 4988
    ret
4989
; -----------------------------------------
1 ha 4990
 
76 mario79 4991
align 4
4992
 
1 ha 4993
undefined_syscall:                      ; Undefined system call
4994
 
4995
     mov   [esp+36],dword -1
4996
     ret
4997
 
4998
 
4999
;clear_busy_flag_at_caller:
5000
 
5001
;      push  edi
5002
 
5003
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
5004
;      imul  edi,8
5005
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
5006
 
5007
;      pop   edi
5008
 
5009
;      ret
5010
 
5011
 
5012
 
5013
 
5014
keymap:
5015
 
5016
     db   '6',27
5017
     db   '1234567890-=',8,9
5018
     db   'qwertyuiop[]',13
5019
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
5020
     db   '@234567890123',180,178,184,'6',176,'7'
5021
     db   179,'8',181,177,183,185,182
5022
     db   'AB
5023
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5024
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5025
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5026
 
5027
 
5028
keymap_shift:
5029
 
5030
     db   '6',27
5031
     db   '!@#$%^&*()_+',8,9
5032
     db   'QWERTYUIOP{}',13
5033
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
5034
     db   '@234567890123',180,178,184,'6',176,'7'
5035
     db   179,'8',181,177,183,185,182
5036
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
5037
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5038
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5039
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5040
 
5041
 
5042
keymap_alt:
5043
 
5044
     db   ' ',27
5045
     db   ' @ $  {[]}\ ',8,9
5046
     db   '            ',13
5047
     db   '             ',0,'           ',0,'4',0,' '
5048
     db   '             ',180,178,184,'6',176,'7'
5049
     db   179,'8',181,177,183,185,182
5050
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
5051
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5052
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5053
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5054
 
5055
 
5056
; device irq owners
5057
uglobal
5058
irq_owner:       ; process id
5059
 
5060
     dd   0x0
5061
     dd   0x0
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
endg
5077
 
5078
 
5079
; on irq read ports
5080
uglobal
5081
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5082
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5083
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5084
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5085
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5086
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5087
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5088
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5089
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5090
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5091
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5092
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5093
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5094
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5095
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5096
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5097
endg
5098
 
5099
; status
5100
uglobal
5101
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5102
  application_table_status    dd 0x0  ; 0 - free : other - pid
5103
endg
5104
 
5105
; device addresses
5106
uglobal
5107
  mididp     dd 0x0
5108
  midisp     dd 0x0
5109
 
5110
  cdbase     dd 0x0
5111
  cdid       dd 0x0
5112
 
5113
  hdbase              dd   0x0  ; for boot 0x1f0
5114
  hdid                dd   0x0
5115
  hdpos               dd   0x0  ; for boot 0x1
5116
  fat32part           dd   0x0  ; for boot 0x1
5117
 
5118
  ;part2_ld            dd   0x0
5119
 
102 poddubny 5120
;* start code - Mario79
33 mario79 5121
mouse_pause         dd   0
36 mario79 5122
MouseTickCounter    dd   0
33 mario79 5123
ps2_mouse_detected  db   0
5124
com1_mouse_detected db   0
5125
com2_mouse_detected db   0
102 poddubny 5126
;* end code - Mario79
1 ha 5127
 
5128
wraw_bacground_select db 0
5129
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5130
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5131
 
5132
  sb16       dd 0x0
5133
  wss        dd 0x0
5134
 
5135
  buttontype         dd 0x0
5136
  windowtypechanged  dd 0x0
5137
endg
5138
 
5139
iglobal
5140
  keyboard   dd 0x1
5141
  sound_dma  dd 0x1
5142
  syslang    dd 0x1
5143
endg
5144
 
5145
IncludeIGlobals
5146
endofcode:
5147
IncludeUGlobals
5148
uglobals_size = $ - endofcode
41 mikedld 5149
diff16 "end of kernel code",0,$
1 ha 5150