Subversion Repositories Kolibri OS

Rev

Rev 139 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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