Subversion Repositories Kolibri OS

Rev

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

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