Subversion Repositories Kolibri OS

Rev

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