Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
3
;; Kolibri OS - based on source code Menuet OS, but not 100% compatible.
4
;;
5
;; See file COPYING or GNU.TXT for details with these additional details:
6
;;     - All code written in 32 bit x86 assembly language
7
;;     - No external code (eg. bios) at process execution time
8
;;
9
;;
10
;;   Compile with last version FASM
11
;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 me_root 13
include "kglobals.inc"
1 ha 14
include "lang.inc"
15
 
16
WinMapAddress           equ     0x460000
17
display_data       = 0x460000
18
 
19
max_processes      equ   255
20
 
21
window_data        equ   0x0000
22
tss_data           equ   0xD20000
23
;tss_step           equ   (128+2048) ; tss & i/o - 16384 ports, * 256=557056
24
tss_step           equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
25
draw_data          equ   0xC00000
26
sysint_stack_data  equ   0xC03000
27
 
28
 
29
twdw               equ   (0x3000-window_data)
30
 
31
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32
;;
33
;;   Included files:
34
;;
35
;;   Kernel16.inc
36
;;    - Booteng.inc   English text for bootup
37
;;    - Bootcode.inc  Hardware setup
38
;;    - Pci16.inc     PCI functions
39
;;
40
;;   Kernel32.inc
41
;;    - Sys32.inc     Process management
42
;;    - Shutdown.inc  Shutdown and restart
43
;;    - Fat32.inc     Read / write hd
44
;;    - Vesa12.inc    Vesa 1.2 driver
45
;;    - Vesa20.inc    Vesa 2.0 driver
46
;;    - Vga.inc       VGA driver
47
;;    - Stack.inc     Network interface
48
;;    - Mouse.inc     Mouse pointer
49
;;    - Scincode.inc  Window skinning
50
;;    - Pci32.inc     PCI functions
51
;;
52
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53
 
54
 
55
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56
;;                                                                      ;;
57
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
58
;;                                                                      ;;
59
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60
 
61
use16
82 halyavin 62
                  org   0x0
1 ha 63
                  jmp   start_of_code
64
 
65
; mike.dld {
90 mario79 66
        org $+0x10000
1 ha 67
db 0
68
dd servetable-0x10000
69
draw_line       dd __sys_draw_line
70
disable_mouse   dd __sys_disable_mouse
71
draw_pointer    dd __sys_draw_pointer
114 mikedld 72
;//mike.dld, 2006-08-02 [
73
;drawbar         dd __sys_drawbar
74
drawbar         dd __sys_drawbar.forced
75
;//mike.dld, 2006-08-02 ]
1 ha 76
putpixel        dd __sys_putpixel
77
; } mike.dld
78
 
97 mario79 79
version           db    'Kolibri OS  version 0.5.8.1      ',13,10,13,10,0
1 ha 80
                  ;dd    endofcode-0x10000
81
 
82
                  ;db   'Boot02'
83
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
84
include "boot/preboot.inc"
85
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
86
 
87
preboot_lfb       db    0
88
preboot_bootlog   db    0
89
 
90
 
91
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92
;;                                                                      ;;
93
;;                      16 BIT INCLUDED FILES                           ;;
94
;;                                                                      ;;
95
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96
 
7 me_root 97
include "kernel16.inc"
1 ha 98
 
99
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100
;;                                                                      ;;
101
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
102
;;                                                                      ;;
103
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104
 
3 halyavin 105
os_data        =  os_data_l-gdts    ; GDTs
106
os_code        =  os_code_l-gdts
1 ha 107
int_code       equ  int_code_l-gdts
108
int_data       equ  int_data_l-gdts
109
tss0sys        equ  tss0sys_l-gdts
110
graph_data     equ  3+graph_data_l-gdts
111
tss0           equ  tss0_l-gdts
112
app_code       equ  3+app_code_l-gdts
113
app_data       equ  3+app_data_l-gdts
114
 
115
 
116
 
117
; CR0 Flags - Protected mode and Paging
118
 
119
        mov     ecx,0x00000001
120
        ;and     ebx,65535
121
        ;cmp     ebx,00100000000000000b ; lfb -> paging
122
        ;jb      no_paging
123
        ;mov     ax,0x0000
124
        ;mov     es,ax
125
        ;mov     al,[es:0x901E]
126
        ;cmp     al,1
127
        ;je      no_paging
128
        ;or      ecx, 0x80000000
129
       ;no_paging:
130
 
131
; Enabling 32 bit protected mode
132
 
133
        sidt    [cs:old_ints_h-0x10000]
134
 
135
        cli                             ; disable all irqs
136
        cld
137
        mov     al,255                  ; mask all irqs
138
        out     0xa1,al
139
        out     0x21,al
140
   l.5: in      al, 0x64                ; Enable A20
141
        test    al, 2
142
        jnz     l.5
143
        mov     al, 0xD1
144
        out     0x64, al
145
   l.6: in      al, 0x64
146
        test    al, 2
147
        jnz     l.6
148
        mov     al, 0xDF
149
        out     0x60, al
150
        lgdt    [cs:gdts-0x10000]       ; Load GDT
151
        mov     eax, cr0                ; Turn on paging // protected mode
152
        or      eax, ecx
153
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
154
        mov     cr0, eax
77 diamond 155
        jmp     $+2
82 halyavin 156
org $+0x10000
1 ha 157
        mov     ax,os_data              ; Selector for os
158
        mov     ds,ax
159
        mov     es,ax
160
        mov     fs,ax
161
        mov     gs,ax
162
        mov     ss,ax
12 halyavin 163
        mov     esp,0x3ec00             ; Set stack
1 ha 164
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
165
 
166
use32
167
 
168
iglobal
169
  boot_memdetect    db   'Determining amount of memory',0
170
  boot_fonts        db   'Fonts loaded',0
171
  boot_tss          db   'Setting TSSs',0
172
  boot_cpuid        db   'Reading CPUIDs',0
173
  boot_devices      db   'Detecting devices',0
174
  boot_timer        db   'Setting timer',0
175
  boot_irqs         db   'Reprogramming IRQs',0
176
  boot_setmouse     db   'Setting mouse',0
177
  boot_windefs      db   'Setting window defaults',0
178
  boot_bgr          db   'Calculating background',0
179
  boot_resirqports  db   'Reserving IRQs & ports',0
180
  boot_setrports    db   'Setting addresses for IRQs',0
181
  boot_setostask    db   'Setting OS task',0
182
  boot_allirqs      db   'Unmasking all IRQs',0
183
  boot_tsc          db   'Reading TSC',0
184
  boot_pal_ega      db   'Setting EGA/CGA 320x200 palette',0
185
  boot_pal_vga      db   'Setting VGA 640x480 palette',0
186
  boot_mtrr         db   'Setting MTRR',0
187
  boot_tasking      db   'All set - press ESC to start',0
188
endg
189
 
190
iglobal
191
  boot_y dd 10
192
endg
193
 
194
boot_log:
195
         pushad
196
 
197
         mov   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:
97 mario79 2238
  db 0,5,8,1  ; version 0.5.8.1
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
 
114 mikedld 2991
        call    set_window_clientbox
2992
 
1 ha 2993
    ; check flag (?)
114 mikedld 2994
    cmp   [edi+WDATA.fl_wdrawn],1
1 ha 2995
    jz    newd
2996
 
2997
    push  eax
2998
    mov   eax,[timer_ticks] ;[0xfdf0]
2999
    add   eax,100
3000
    mov   [new_window_starting],eax
3001
    pop   eax
3002
 
114 mikedld 3003
    mov   word[edi+WDATA.box.width],ax
3004
    mov   word[edi+WDATA.box.height],bx
3005
    sar   eax,16
3006
    sar   ebx,16
3007
    mov   word[edi+WDATA.box.left],ax
3008
    mov   word[edi+WDATA.box.top],bx
1 ha 3009
 
3010
 
3011
    call  check_window_position
3012
 
3013
 
3014
    push  ecx esi edi               ; save for window fullscreen/resize
114 mikedld 3015
    ;mov   esi,edi
3016
 
3017
        mov     cl,[edi+WDATA.fl_wstyle]
3018
 
1 ha 3019
    sub   edi,window_data
114 mikedld 3020
    shl   edi,3
115 poddubny 3021
    add   edi,0x80000
114 mikedld 3022
 
3023
        and     cl,0x0F
115 poddubny 3024
        mov     [edi+APPDATA.wnd_caption],0
114 mikedld 3025
        cmp     cl,3
3026
        jne     @f
115 poddubny 3027
        mov     [edi+APPDATA.wnd_caption],esi
114 mikedld 3028
    @@: mov     esi,[esp+0]
3029
 
115 poddubny 3030
    add   edi, APPDATA.saved_box
1 ha 3031
    mov   ecx,4
3032
    cld
3033
    rep   movsd
3034
    pop   edi esi ecx
3035
 
3036
    push  eax ebx ecx edx
3037
;;;    mov   eax, 1
3038
;;;    call  delay_hs
115 poddubny 3039
    mov   eax, [edi+WDATA.box.left]
3040
    mov   ebx, [edi+WDATA.box.top]
3041
    mov   ecx, [edi+WDATA.box.width]
3042
    mov   edx, [edi+WDATA.box.height]
1 ha 3043
    add   ecx, eax
3044
    add   edx, ebx
3045
    call  calculatescreen
3046
    pop   edx ecx ebx eax
3047
 
3048
    mov   [0xf400],byte 0           ; empty keyboard buffer
3049
    mov   [0xf500],byte 0           ; empty button buffer
3050
 
3051
  newd:
115 poddubny 3052
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
1 ha 3053
    mov   edx,edi
3054
 
3055
    ret
3056
 
114 mikedld 3057
syscall_windowsettings:
1 ha 3058
 
114 mikedld 3059
  .set_window_caption:
3060
        dec     eax     ; subfunction #1 - set window caption
3061
        jnz     .get_window_caption
3062
 
3063
        ; NOTE: only window owner thread can set its caption,
3064
        ;       so there's no parameter for PID/TID
3065
 
3066
        mov     edi,[0x3000]
3067
        shl     edi,5
3068
 
3069
        ; have to check if caption is within application memory limit
3070
        ; check is trivial, and if application resizes its memory,
3071
        ;   caption still can become over bounds
3072
        mov     ecx,[edi*8+0x80000+APPDATA.mem_size]
3073
        add     ecx,255 ; max caption length
3074
        cmp     ebx,ecx
3075
        ja      .exit_fail
3076
 
3077
        mov     [edi*8+0x80000+APPDATA.wnd_caption],ebx
3078
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3079
 
3080
        call    draw_window_caption
3081
 
3082
        xor     eax,eax ; eax = 0 (success)
3083
        ret
3084
 
3085
  .get_window_caption:
3086
        dec     eax     ; subfunction #2 - get window caption
3087
        jnz     .exit_fail
3088
 
3089
        ; not implemented yet
3090
 
3091
  .exit_fail:
3092
        xor     eax,eax
3093
        inc     eax     ; eax = 1 (fail)
3094
        ret
3095
 
3096
 
1 ha 3097
sys_window_move:
3098
 
115 poddubny 3099
        mov     edi,[0x3000]
49 mikedld 3100
        shl     edi,5
3101
        add     edi,window_data
1 ha 3102
 
49 mikedld 3103
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3104
        jnz     .window_move_return
1 ha 3105
 
115 poddubny 3106
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3107
        push    dword [edi + WDATA.box.top]
3108
        push    dword [edi + WDATA.box.width]
3109
        push    dword [edi + WDATA.box.height]
1 ha 3110
 
49 mikedld 3111
        cmp   eax,-1                  ; set new position and size
3112
        je    .no_x_reposition
115 poddubny 3113
        mov     [edi + WDATA.box.left], eax
49 mikedld 3114
      .no_x_reposition:
3115
        cmp   ebx,-1
3116
        je    .no_y_reposition
115 poddubny 3117
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3118
      .no_y_reposition:
1 ha 3119
 
49 mikedld 3120
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3121
        jnz     .no_y_resizing
1 ha 3122
 
49 mikedld 3123
        cmp   ecx,-1
3124
        je    .no_x_resizing
115 poddubny 3125
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3126
      .no_x_resizing:
3127
        cmp   edx,-1
3128
        je    .no_y_resizing
115 poddubny 3129
        mov     [edi + WDATA.box.height], edx
49 mikedld 3130
      .no_y_resizing:
1 ha 3131
 
49 mikedld 3132
        call  check_window_position
1 ha 3133
 
49 mikedld 3134
        pushad                       ; save for window fullscreen/resize
3135
        mov   esi,edi
3136
        sub   edi,window_data
3137
        shr   edi,5
3138
        shl   edi,8
115 poddubny 3139
        add   edi, 0x80000 + APPDATA.saved_box
49 mikedld 3140
        mov   ecx,4
3141
        cld
3142
        rep   movsd
3143
        popad
3144
 
3145
        pushad                       ; calculcate screen at new position
115 poddubny 3146
        mov   eax, [edi + WDATA.box.left]
3147
        mov   ebx, [edi + WDATA.box.top]
3148
        mov   ecx, [edi + WDATA.box.width]
3149
        mov   edx, [edi + WDATA.box.height]
3150
        add   ecx, eax
3151
        add   edx, ebx
49 mikedld 3152
        call  calculatescreen
3153
        popad
3154
 
3155
        pop   edx                   ; calculcate screen at old position
3156
        pop   ecx
3157
        pop   ebx
3158
        pop   eax
3159
        add   ecx,eax
3160
        add   edx,ebx
3161
        mov   [dlx],eax             ; save for drawlimits
3162
        mov   [dly],ebx
3163
        mov   [dlxe],ecx
3164
        mov   [dlye],edx
3165
        call  calculatescreen
3166
 
115 poddubny 3167
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3168
 
3169
        mov   eax,edi               ; redraw screen at old position
3170
        xor   esi,esi
3171
        call  redrawscreen
3172
 
3173
        mov   [0xfff5],byte 0 ; mouse pointer
3174
        mov   [0xfff4],byte 0 ; no mouse under
3175
        mov   [0xfb44],byte 0 ; react to mouse up/down
3176
 
3177
        mov   ecx,10          ; wait 1/10 second
3178
      .wmrl3:
3179
        call  [draw_pointer]
3180
        mov   eax,1
3181
        call  delay_hs
3182
        loop  .wmrl3
3183
 
3184
        mov   [window_move_pr],0
3185
 
3186
      .window_move_return:
3187
 
1 ha 3188
        ret
3189
 
67 diamond 3190
;type_background_1:
3191
;    cmp   [0xfff0],byte 0               ; background update ?
3192
;    jz    temp_nobackgr
3193
;    mov   [0xfff0],byte 2
3194
;    call  change_task
3195
;    mov   [draw_data+32+0],dword 0
3196
;    mov   [draw_data+32+4],dword 0
3197
;    mov   eax,[0xfe00]
3198
;    mov   ebx,[0xfe04]
3199
;    mov   [draw_data+32+8],eax
3200
;    mov   [draw_data+32+12],ebx
3201
;    call  drawbackground
3202
;    mov   [0xfff0],byte 0
3203
;    mov   [0xfff4],byte 0
3204
;temp_nobackgr:
3205
;    ret
41 mikedld 3206
 
1 ha 3207
uglobal
3208
  window_move_pr   dd  0x0
3209
  window_move_eax  dd  0x0
3210
  window_move_ebx  dd  0x0
3211
  window_move_ecx  dd  0x0
3212
  window_move_edx  dd  0x0
3213
endg
3214
 
3215
;ok - 100% work
3216
;nt - not tested
3217
;---------------------------------------------------------------------------------------------
3218
;eax
3219
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3220
;1 - change task. Ret nothing. Block. ok.
3221
;2 - performance control
3222
; ebx
3223
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3224
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3225
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3226
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3227
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3228
;eax
3229
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3230
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3231
;---------------------------------------------------------------------------------------------
3232
sys_sheduler: ;noname & halyavin
3233
    cmp eax,0
3234
    je shed_counter
3235
    cmp eax,2
3236
    je perf_control
3237
    cmp eax,3
3238
    je rdmsr_instr
3239
    cmp eax,4
3240
    je wrmsr_instr
3241
    cmp eax,1
3242
    jne not_supported
3243
    call change_task ;delay,0
3244
ret
3245
shed_counter:
3246
    mov eax,[context_counter]
3247
    mov [esp+36],eax
3248
not_supported:
3249
ret
3250
perf_control:
3251
    inc eax ;now eax=3
3252
    cmp ebx,eax
3253
    je cache_disable
3254
    dec eax
3255
    cmp ebx,eax
3256
    je cache_enable
3257
    dec eax
3258
    cmp ebx,eax
3259
    je is_cache_enabled
3260
    dec eax
3261
    cmp ebx,eax
3262
    je modify_pce
3263
ret
3264
 
3265
rdmsr_instr:
3266
;now counter in ecx
3267
;(edx:eax) esi:edi => edx:esi
3268
mov eax,esi
3269
rdmsr
3270
mov [esp+36],eax
3271
mov [esp+24],edx ;ret in ebx?
3272
ret
3273
 
3274
wrmsr_instr:
3275
;now counter in ecx
3276
;(edx:eax) esi:edi => edx:esi
3277
mov eax,esi
3278
wrmsr
3279
mov [esp+36],eax
3280
mov [esp+24],edx ;ret in ebx?
3281
ret
3282
 
3283
cache_disable:
3284
       mov eax,cr0
3285
       or  eax,01100000000000000000000000000000b
3286
       mov cr0,eax
3287
       wbinvd ;set MESI
3288
ret
3289
 
3290
cache_enable:
3291
       mov eax,cr0
3292
       and eax,10011111111111111111111111111111b
3293
       mov cr0,eax
3294
ret
3295
 
3296
is_cache_enabled:
3297
       mov eax,cr0
3298
       mov ebx,eax
3299
       and eax,01100000000000000000000000000000b
3300
       jz cache_disabled
3301
       mov [esp+36],ebx
3302
cache_disabled:
3303
       mov dword [esp+36],eax ;0
3304
ret
3305
 
3306
modify_pce:
3307
       mov eax,cr4
3308
;       mov ebx,0
3309
;       or  bx,100000000b ;pce
3310
;       xor eax,ebx ;invert pce
17 me_root 3311
       bts eax,8 ;pce=cr4[8]
1 ha 3312
       mov cr4,eax
3313
       mov [esp+36],eax
3314
ret
3315
;---------------------------------------------------------------------------------------------
3316
 
3317
 
3318
; check if pixel is allowed to be drawn
3319
 
3320
checkpixel:
21 poddubny 3321
        push eax edx
1 ha 3322
 
3323
        mov  edx,[0xfe00]     ; screen x size
3324
        inc  edx
21 poddubny 3325
        imul edx, ebx
1 ha 3326
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3327
 
21 poddubny 3328
        xor  ecx, ecx
105 poddubny 3329
        mov  eax, [0x3000]
3330
        cmp  al, dl
21 poddubny 3331
        setne cl
1 ha 3332
 
21 poddubny 3333
        pop  edx eax
1 ha 3334
        ret
3335
 
3336
uglobal
3337
  mouse_active  db  0
3338
endg
3339
iglobal
143 diamond 3340
  cpustring db '/RD/1/CPU',0
1 ha 3341
endg
3342
 
67 diamond 3343
uglobal
76 mario79 3344
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3345
endg
1 ha 3346
 
3347
align 4
3348
; check misc
3349
 
3350
checkmisc:
3351
 
3352
    cmp   [ctrl_alt_del], 1
3353
    jne   nocpustart
143 diamond 3354
    mov   ebp, cpustring
3355
    lea   esi,[ebp+6]
41 mikedld 3356
    xor   ebx,ebx               ; no parameters
40 halyavin 3357
    xor   edx,edx               ; no flags
143 diamond 3358
    call  fs_RamdiskExecute.flags
1 ha 3359
    mov   [ctrl_alt_del], 0
3360
  nocpustart:
3361
    cmp   [mouse_active], 1
3362
    jne   mouse_not_active
3363
    mov   [mouse_active], 0
3364
    xor   edi, edi
3365
    mov   ecx, [0x3004]
3366
   set_mouse_event:
3367
    add   edi, 256
115 poddubny 3368
    or    [edi+0x80000+APPDATA.event_mask], dword 00100000b
1 ha 3369
    loop  set_mouse_event
3370
  mouse_not_active:
3371
 
3372
 
3373
    cmp   [0xfff0],byte 0               ; background update ?
3374
    jz    nobackgr
76 mario79 3375
    cmp    [background_defined], 0
3376
    jz    nobackgr
1 ha 3377
    mov   [0xfff0],byte 2
3378
    call  change_task
117 mario79 3379
    mov   [draw_data+32 + RECT.left],dword 0
3380
    mov   [draw_data+32 + RECT.top],dword 0
1 ha 3381
    mov   eax,[0xfe00]
3382
    mov   ebx,[0xfe04]
117 mario79 3383
    mov   [draw_data+32 + RECT.right],eax
3384
    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3385
    call  drawbackground
3386
    mov   [0xfff0],byte 0
3387
    mov   [0xfff4],byte 0
3388
 
3389
  nobackgr:
3390
 
3391
 
3392
    ; system shutdown request
3393
 
3394
    cmp  [0xFF00],byte 0
3395
    je   noshutdown
3396
 
3397
    mov  edx,[shutdown_processes]
3398
    sub  dl,2
3399
 
3400
    cmp  [0xff00],dl
3401
    jne  no_mark_system_shutdown
3402
 
3403
    mov   edx,0x3040
3404
    movzx ecx,byte [0xff00]
3405
    add   ecx,5
3406
  markz:
115 poddubny 3407
    mov   [edx+TASKDATA.state],byte 3
1 ha 3408
    add   edx,0x20
3409
    loop  markz
3410
 
3411
  no_mark_system_shutdown:
3412
 
3413
    call [disable_mouse]
3414
 
3415
    dec  byte [0xff00]
3416
 
3417
    cmp  [0xff00],byte 0
3418
    je   system_shutdown
3419
 
3420
  noshutdown:
3421
 
3422
 
3423
    mov   eax,[0x3004]                  ; termination
115 poddubny 3424
    mov   ebx,0x3020+TASKDATA.state
1 ha 3425
    mov   esi,1
3426
 
3427
  newct:
3428
    mov   cl,[ebx]
3429
    cmp   cl,byte 3
3430
    jz    terminate
3431
    cmp   cl,byte 4
3432
    jz    terminate
3433
 
3434
    add   ebx,0x20
3435
    inc   esi
3436
    dec   eax
3437
    jnz   newct
3438
 
3439
    ret
3440
 
3441
 
3442
 
3443
 
3444
; redraw screen
3445
 
3446
redrawscreen:
3447
 
3448
; eax , if process window_data base is eax, do not set flag/limits
3449
 
3450
         pushad
3451
         push  eax
3452
 
3453
;;;         mov   eax,2
3454
;;;         call  delay_hs
3455
 
3456
         ;mov   ecx,0               ; redraw flags for apps
3457
         xor   ecx,ecx
3458
       newdw2:
3459
 
3460
         inc   ecx
3461
         push  ecx
3462
 
3463
         mov   eax,ecx
3464
         shl   eax,5
3465
         add   eax,window_data
3466
 
3467
         cmp   eax,[esp+4]
3468
         je    not_this_task
3469
                                   ; check if window in redraw area
3470
         mov   edi,eax
3471
 
3472
         cmp   ecx,1               ; limit for background
3473
         jz    bgli
3474
 
115 poddubny 3475
         mov   eax, [edi + WDATA.box.left]
3476
         mov   ebx, [edi + WDATA.box.top]
3477
         mov   ecx, [edi + WDATA.box.width]
3478
         mov   edx, [edi + WDATA.box.height]
3479
         add   ecx, eax
3480
         add   edx, ebx
1 ha 3481
 
3482
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3483
         cmp   ecx,ebx
3484
         jb    ricino
3485
 
3486
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3487
         cmp   ecx,eax
3488
         jb    ricino
3489
 
115 poddubny 3490
         mov   eax, [edi + WDATA.box.left]
3491
         mov   ebx, [edi + WDATA.box.top]
3492
         mov   ecx, [edi + WDATA.box.width]
3493
         mov   edx, [edi + WDATA.box.height]
3494
         add   ecx, eax
3495
         add   edx, ebx
117 mario79 3496
 
1 ha 3497
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3498
         cmp   edx,eax
3499
         jb    ricino
3500
 
3501
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3502
         cmp   ecx,eax
3503
         jb    ricino
3504
 
3505
        bgli:
3506
 
3507
         cmp   edi,esi
3508
         jz    ricino
3509
 
3510
         mov   eax,edi
3511
         add   eax,draw_data-window_data
3512
 
3513
         mov   ebx,[dlx]          ; set limits
115 poddubny 3514
         mov   [eax + RECT.left], ebx
1 ha 3515
         mov   ebx,[dly]
115 poddubny 3516
         mov   [eax + RECT.top], ebx
1 ha 3517
         mov   ebx,[dlxe]
115 poddubny 3518
         mov   [eax + RECT.right], ebx
1 ha 3519
         mov   ebx,[dlye]
115 poddubny 3520
         mov   [eax + RECT.bottom], ebx
1 ha 3521
 
3522
         sub   eax,draw_data-window_data
3523
 
3524
         cmp   ecx,1
3525
         jne   nobgrd
3526
         cmp   esi,1
3527
         je    newdw8
3528
         call  drawbackground
3529
 
3530
       newdw8:
3531
       nobgrd:
3532
 
115 poddubny 3533
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3534
 
3535
       ricino:
3536
 
3537
       not_this_task:
3538
 
3539
         pop   ecx
3540
 
3541
         cmp   ecx,[0x3004]
3542
         jle   newdw2
3543
 
3544
         pop  eax
3545
         popad
3546
 
3547
         ret
3548
 
3549
calculatebackground:   ; background
3550
 
3551
        ; all black
3552
 
3553
        mov   [display_data-8],dword 4      ; size x
3554
        mov   [display_data-4],dword 2      ; size y
3555
 
3556
        mov   edi, 0x300000                 ; set background to black
3557
        xor   eax, eax
3558
        mov   ecx, 0x0fff00 / 4
3559
        cld
3560
        rep   stosd
3561
 
3562
        mov   edi,display_data              ; set os to use all pixels
3563
        mov   eax,0x01010101
3564
        mov   ecx,0x1fff00 / 4
3565
        rep   stosd
3566
 
3567
        mov   byte [0xFFF0], 0              ; do not draw background!
3568
 
3569
        ret
3570
 
3571
uglobal
3572
  imax    dd 0x0
3573
endg
3574
 
3575
 
3576
 
3577
delay_ms:     ; delay in 1/1000 sec
3578
 
3579
 
3580
        push  eax
3581
        push  ecx
3582
 
3583
        mov   ecx,esi
3584
        ; 
3585
        imul  ecx, 33941
3586
        shr   ecx, 9
3587
        ; 
3588
 
3589
        in    al,0x61
3590
        and   al,0x10
3591
        mov   ah,al
3592
        cld
3593
 
3594
 cnt1:  in    al,0x61
3595
        and   al,0x10
3596
        cmp   al,ah
3597
        jz    cnt1
3598
 
3599
        mov   ah,al
3600
        loop  cnt1
3601
 
3602
        pop   ecx
3603
        pop   eax
3604
 
3605
        ret
3606
 
3607
 
3608
set_app_param:
3609
        push edi
3610
 
3611
        mov  edi,[0x3010]
115 poddubny 3612
        mov  [edi+TASKDATA.event_mask],eax
1 ha 3613
 
3614
        pop  edi
3615
        ret
3616
 
3617
 
3618
 
3619
delay_hs:     ; delay in 1/100 secs
3620
        push  eax
3621
        push  ecx
3622
        push  edx
3623
 
115 poddubny 3624
        mov   edx,[timer_ticks]
1 ha 3625
        add   edx,eax
3626
 
3627
      newtic:
115 poddubny 3628
        mov   ecx,[timer_ticks]
1 ha 3629
        cmp   edx,ecx
3630
        jbe   zerodelay
3631
 
3632
        call  change_task
3633
 
3634
        jmp   newtic
3635
 
3636
      zerodelay:
3637
        pop   edx
3638
        pop   ecx
3639
        pop   eax
3640
 
3641
        ret
3642
 
3643
 
3644
memmove:       ; memory move in bytes
3645
 
3646
; eax = from
3647
; ebx = to
3648
; ecx = no of bytes
3649
    test ecx, ecx
3650
    jle  .ret
3651
 
3652
 
3653
    push esi edi ecx
3654
 
3655
    mov  edi, ebx
3656
    mov  esi, eax
3657
 
3658
    test ecx, not 11b
3659
    jz   @f
3660
 
3661
    push ecx
3662
    shr  ecx, 2
3663
    rep  movsd
3664
    pop  ecx
3665
    and  ecx, 11b
3666
    jz   .finish
3667
  @@:
3668
    rep  movsb
3669
 
3670
  .finish:
3671
    pop  ecx edi esi
3672
  .ret:
3673
    ret
3674
 
3675
 
75 diamond 3676
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3677
;align 4
1 ha 3678
;
75 diamond 3679
;read_floppy_file:
1 ha 3680
;
75 diamond 3681
;; as input
3682
;;
3683
;; eax pointer to file
3684
;; ebx file lenght
3685
;; ecx start 512 byte block number
3686
;; edx number of blocks to read
3687
;; esi pointer to return/work area (atleast 20 000 bytes)
3688
;;
3689
;;
3690
;; on return
3691
;;
3692
;; eax = 0 command succesful
3693
;;       1 no fd base and/or partition defined
3694
;;       2 yet unsupported FS
3695
;;       3 unknown FS
3696
;;       4 partition not defined at hd
3697
;;       5 file not found
3698
;; ebx = size of file
1 ha 3699
;
75 diamond 3700
;     mov   edi,[0x3010]
3701
;     add   edi,0x10
3702
;     add   esi,[edi]
3703
;     add   eax,[edi]
1 ha 3704
;
75 diamond 3705
;     pushad
3706
;     mov  edi,esi
3707
;     add  edi,1024
3708
;     mov  esi,0x100000+19*512
3709
;     sub  ecx,1
3710
;     shl  ecx,9
3711
;     add  esi,ecx
3712
;     shl  edx,9
3713
;     mov  ecx,edx
3714
;     cld
3715
;     rep  movsb
3716
;     popad
3717
;
3718
;     mov   [esp+36],eax
3719
;     mov   [esp+24],ebx
3720
;     ret
1 ha 3721
 
3722
 
3723
 
3724
align 4
3725
 
3726
sys_programirq:
3727
 
3728
    mov   edi,[0x3010]
115 poddubny 3729
    add   eax,[edi+TASKDATA.mem_start]
1 ha 3730
 
75 diamond 3731
    cmp   ebx,16
3732
    jae   .not_owner
1 ha 3733
    mov   edi,[0x3010]
115 poddubny 3734
    mov   edi,[edi+TASKDATA.pid]
75 diamond 3735
    cmp   edi,[irq_owner+ebx*4]
1 ha 3736
    je    spril1
75 diamond 3737
.not_owner:
1 ha 3738
    mov   [esp+36],dword 1
3739
    ret
3740
  spril1:
3741
 
3742
    mov   esi,eax
3743
    shl   ebx,6
3744
    add   ebx,irq00read
3745
    mov   edi,ebx
3746
    mov   ecx,16
3747
    cld
3748
    rep   movsd
3749
    mov   [esp+36],dword 0
3750
    ret
3751
 
3752
 
3753
align 4
3754
 
3755
get_irq_data:
75 diamond 3756
     cmp   eax,16
3757
     jae   .not_owner
1 ha 3758
     mov   edx,eax           ; check for correct owner
3759
     shl   edx,2
3760
     add   edx,irq_owner
3761
     mov   edx,[edx]
3762
     mov   edi,[0x3010]
115 poddubny 3763
     mov   edi,[edi+TASKDATA.pid]
1 ha 3764
     cmp   edx,edi
3765
     je    gidril1
75 diamond 3766
.not_owner:
3767
     mov   [esp+32],dword 2     ; ecx=2
1 ha 3768
     ret
3769
 
3770
  gidril1:
3771
 
3772
     mov   ebx,eax
3773
     shl   ebx,12
3774
     add   ebx,0x2e0000
3775
     mov   eax,[ebx]
3776
     mov   ecx,1
3777
     test  eax,eax
3778
     jz    gid1
3779
 
3780
     dec   eax
3781
     mov   esi,ebx
3782
     mov   [ebx],eax
3783
     movzx ebx,byte [ebx+0x10]
3784
     add   esi,0x10
3785
     mov   edi,esi
3786
     inc   esi
3787
     mov   ecx,4000 / 4
3788
     cld
3789
     rep   movsd
75 diamond 3790
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
1 ha 3791
   gid1:
3792
     mov   [esp+36],eax
3793
     mov   [esp+32],ecx
3794
     mov   [esp+24],ebx
3795
     ret
3796
 
3797
 
3798
set_io_access_rights:
3799
 
3800
     pushad
3801
 
3802
     mov   edi,[0x3000]
3803
     imul  edi,tss_step
3804
     add   edi,tss_data+128
3805
;     add   edi,128
3806
 
3807
     mov   ecx,eax
3808
     and   ecx,7    ; offset in byte
3809
 
3810
     shr   eax,3    ; number of byte
3811
     add   edi,eax
3812
 
3813
     mov   ebx,1
3814
     shl   ebx,cl
3815
 
3816
     cmp   ebp,0                ; enable access - ebp = 0
3817
     jne   siar1
3818
 
3819
     not   ebx
3820
     and   [edi],byte bl
3821
 
3822
     popad
3823
 
3824
     ret
3825
 
3826
   siar1:
3827
 
3828
     or    [edi],byte bl        ; disable access - ebp = 1
3829
 
3830
     popad
3831
 
3832
     ret
3833
 
3834
 
3835
 
3836
 
3837
 
3838
r_f_port_area:
3839
 
3840
     test  eax, eax
3841
     jnz   free_port_area
3842
;     je    r_port_area
3843
;     jmp   free_port_area
3844
 
3845
;   r_port_area:
3846
 
3847
     pushad
3848
 
3849
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 3850
     ja    rpal1
3851
     cmp   ecx,65536
3852
     jae   rpal1
1 ha 3853
     mov   esi,[0x2d0000]
75 diamond 3854
     test  esi,esi            ; no reserved areas ?
1 ha 3855
     je    rpal2
3856
     cmp   esi,255            ; max reserved
75 diamond 3857
     jae   rpal1
1 ha 3858
   rpal3:
3859
     mov   edi,esi
3860
     shl   edi,4
3861
     add   edi,0x2d0000
3862
     cmp   ebx,[edi+8]
75 diamond 3863
     ja    rpal4
1 ha 3864
     cmp   ecx,[edi+4]
3865
     jae   rpal1
3866
;     jb    rpal4
3867
;     jmp   rpal1
3868
   rpal4:
3869
 
3870
     dec   esi
3871
     jnz   rpal3
3872
     jmp   rpal2
3873
   rpal1:
3874
     popad
3875
     mov   eax,1
3876
     ret
3877
 
3878
   rpal2:
3879
     popad
3880
 
3881
 
3882
     ; enable port access at port IO map
3883
     cli
3884
     pushad                        ; start enable io map
3885
 
3886
     cmp   ecx,65536 ;16384
3887
     jae   no_unmask_io ; jge
3888
 
3889
     mov   eax,ebx
3890
 
3891
   new_port_access:
3892
 
3893
     pushad
3894
 
75 diamond 3895
     xor   ebp,ebp                ; enable - eax = port
1 ha 3896
     call  set_io_access_rights
3897
 
3898
     popad
3899
 
3900
     inc   eax
3901
     cmp   eax,ecx
3902
     jbe   new_port_access
3903
 
3904
   no_unmask_io:
3905
 
3906
     popad                         ; end enable io map
3907
     sti
3908
 
3909
     mov   edi,[0x2d0000]
3910
     add   edi,1
3911
     mov   [0x2d0000],edi
3912
     shl   edi,4
3913
     add   edi,0x2d0000
3914
     mov   esi,[0x3010]
115 poddubny 3915
     mov   esi,[esi+TASKDATA.pid]
1 ha 3916
     mov   [edi],esi
3917
     mov   [edi+4],ebx
3918
     mov   [edi+8],ecx
3919
 
3920
     xor   eax, eax
3921
     ret
3922
 
3923
 
3924
 
3925
 
3926
free_port_area:
3927
 
3928
     pushad
3929
 
3930
     mov   esi,[0x2d0000]     ; no reserved areas ?
75 diamond 3931
     test  esi,esi
1 ha 3932
     je    frpal2
3933
     mov   edx,[0x3010]
115 poddubny 3934
     mov   edx,[edx+TASKDATA.pid]
1 ha 3935
   frpal3:
3936
     mov   edi,esi
3937
     shl   edi,4
3938
     add   edi,0x2d0000
3939
     cmp   edx,[edi]
3940
     jne   frpal4
3941
     cmp   ebx,[edi+4]
3942
     jne   frpal4
3943
     cmp   ecx,[edi+8]
3944
     jne   frpal4
3945
     jmp   frpal1
3946
   frpal4:
3947
     dec   esi
3948
     jnz   frpal3
3949
   frpal2:
3950
     popad
3951
     mov   eax,1
3952
     ret
3953
   frpal1:
3954
     mov   ecx,256
3955
     sub   ecx,esi
3956
     shl   ecx,4
3957
     mov   esi,edi
3958
     add   esi,16
3959
     cld
3960
     rep   movsb
3961
 
3962
     dec   dword [0x2d0000]
3963
 
3964
     popad
3965
 
3966
 
3967
     ; disable port access at port IO map
3968
 
3969
     pushad                        ; start disable io map
3970
 
3971
     cmp   ecx,65536 ;16384
3972
     jge   no_mask_io
3973
 
3974
     mov   eax,ebx
3975
 
3976
   new_port_access_disable:
3977
 
3978
     pushad
3979
 
3980
     mov   ebp,1                  ; disable - eax = port
3981
     call  set_io_access_rights
3982
 
3983
     popad
3984
 
3985
     inc   eax
3986
     cmp   eax,ecx
3987
     jbe   new_port_access_disable
3988
 
3989
   no_mask_io:
3990
 
3991
     popad                         ; end disable io map
3992
 
3993
     xor   eax, eax
3994
     ret
3995
 
3996
 
3997
reserve_free_irq:
3998
 
75 diamond 3999
     mov   ecx, 1
4000
     cmp   ebx, 16
4001
     jae   fril1
4002
     test  eax,eax
1 ha 4003
     jz    reserve_irq
4004
 
75 diamond 4005
     lea   edi,[irq_owner+ebx*4]
1 ha 4006
     mov   edx,[edi]
4007
     mov   eax,[0x3010]
115 poddubny 4008
     cmp   edx,[eax+TASKDATA.pid]
1 ha 4009
     jne   fril1
75 diamond 4010
     dec   ecx
4011
     mov   [edi],ecx
1 ha 4012
   fril1:
4013
     mov   [esp+36],ecx ; return in eax
4014
     ret
4015
 
4016
  reserve_irq:
4017
 
75 diamond 4018
     lea   edi,[irq_owner+ebx*4]
4019
     cmp   dword [edi], 0
4020
     jnz   ril1
1 ha 4021
 
4022
     mov   edx,[0x3010]
115 poddubny 4023
     mov   edx,[edx+TASKDATA.pid]
1 ha 4024
     mov   [edi],edx
75 diamond 4025
     dec   ecx
1 ha 4026
   ril1:
4027
     mov   [esp+36],ecx ; return in eax
4028
     ret
4029
 
4030
 
4031
 
4032
drawbackground:
33 mario79 4033
       inc   [mouse_pause]
1 ha 4034
       cmp   [0xfe0c],word 0x12
117 mario79 4035
       je   dbrv20
1 ha 4036
     dbrv12:
4037
       cmp  [0xfe0c],word 0100000000000000b
4038
       jge  dbrv20
4039
       cmp  [0xfe0c],word 0x13
4040
       je   dbrv20
4041
       call  vesa12_drawbackground
33 mario79 4042
       dec   [mouse_pause]
36 mario79 4043
       call   [draw_pointer]
1 ha 4044
       ret
4045
     dbrv20:
4046
       cmp   [display_data-12],dword 1
4047
       jne   bgrstr
4048
       call  vesa20_drawbackground_tiled
33 mario79 4049
       dec   [mouse_pause]
36 mario79 4050
       call   [draw_pointer]
1 ha 4051
       ret
4052
     bgrstr:
4053
       call  vesa20_drawbackground_stretch
33 mario79 4054
       dec   [mouse_pause]
36 mario79 4055
       call   [draw_pointer]
1 ha 4056
       ret
4057
 
75 diamond 4058
align 4
1 ha 4059
 
75 diamond 4060
syscall_putimage:                       ; PutImage
33 mario79 4061
 
75 diamond 4062
     mov   edx,ecx
4063
     mov   ecx,ebx
4064
        lea     ebx, [eax+std_application_base_address]
4065
 
1 ha 4066
sys_putimage:
53 mikedld 4067
     test  ecx,0x80008000
4068
     jnz   .exit
4069
     test  ecx,0x0000FFFF
4070
     jz    .exit
4071
     test  ecx,0xFFFF0000
4072
     jnz   @f
4073
  .exit:
4074
     ret
4075
 @@:
114 mikedld 4076
        mov     edi,[0x3000]
4077
        shl     edi,8
4078
        add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.top]
4079
        rol     edx,16
4080
        add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.left]
4081
        rol     edx,16
4082
  .forced:
117 mario79 4083
;        mov     eax, vga_putimage
75 diamond 4084
        cmp     [0xfe0c], word 0x12
117 mario79 4085
        jz      @f   ;.doit
75 diamond 4086
        mov     eax, vesa12_putimage
4087
        cmp     [0xfe0c], word 0100000000000000b
4088
        jae     @f
4089
        cmp     [0xfe0c], word 0x13
4090
        jnz     .doit
4091
@@:
4092
        mov     eax, vesa20_putimage
4093
.doit:
119 mario79 4094
        inc     [mouse_pause]
75 diamond 4095
        call    eax
119 mario79 4096
        dec     [mouse_pause]
75 diamond 4097
        jmp     [draw_pointer]
1 ha 4098
 
4099
; eax x beginning
4100
; ebx y beginning
4101
; ecx x end
4102
; edx y end
4103
; edi color
4104
 
4105
__sys_drawbar:
114 mikedld 4106
        mov     esi,[0x3000]
4107
        shl     esi,8
4108
        add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
4109
        add     ecx,[esi+0x80000+APPDATA.wnd_clientbox.left]
4110
        add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
4111
        add     edx,[esi+0x80000+APPDATA.wnd_clientbox.top]
4112
  .forced:
33 mario79 4113
    inc   [mouse_pause]
4114
    cmp   [0xfe0c],word 0x12
117 mario79 4115
    je   dbv20
1 ha 4116
   sdbv20:
4117
    cmp  [0xfe0c],word 0100000000000000b
4118
    jge  dbv20
4119
    cmp  [0xfe0c],word 0x13
4120
    je   dbv20
4121
    call vesa12_drawbar
33 mario79 4122
    dec   [mouse_pause]
36 mario79 4123
    call   [draw_pointer]
1 ha 4124
    ret
4125
  dbv20:
4126
    call vesa20_drawbar
33 mario79 4127
    dec   [mouse_pause]
36 mario79 4128
    call   [draw_pointer]
1 ha 4129
    ret
4130
 
4131
 
4132
 
4133
kb_read:
4134
 
4135
        push    ecx edx
4136
 
98 mario79 4137
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4138
      kr_loop:
4139
        in      al,0x64
4140
        test    al,1
4141
        jnz     kr_ready
4142
        loop    kr_loop
4143
        mov     ah,1
4144
        jmp     kr_exit
4145
      kr_ready:
4146
        push    ecx
4147
        mov     ecx,32
4148
      kr_delay:
4149
        loop    kr_delay
4150
        pop     ecx
4151
        in      al,0x60
4152
        xor     ah,ah
4153
      kr_exit:
4154
 
4155
        pop     edx ecx
4156
 
4157
        ret
4158
 
4159
 
4160
kb_write:
4161
 
4162
        push    ecx edx
4163
 
4164
        mov     dl,al
98 mario79 4165
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4166
      kw_loop1:
4167
        in      al,0x64
4168
        test    al,0x20
4169
        jz      kw_ok1
4170
        loop    kw_loop1
4171
        mov     ah,1
4172
        jmp     kw_exit
4173
      kw_ok1:
4174
        in      al,0x60
98 mario79 4175
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4176
      kw_loop:
4177
        in      al,0x64
4178
        test    al,2
4179
        jz      kw_ok
4180
        loop    kw_loop
4181
        mov     ah,1
4182
        jmp     kw_exit
4183
      kw_ok:
4184
        mov     al,dl
4185
        out     0x60,al
98 mario79 4186
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4187
      kw_loop3:
4188
        in      al,0x64
4189
        test    al,2
4190
        jz      kw_ok3
4191
        loop    kw_loop3
4192
        mov     ah,1
4193
        jmp     kw_exit
4194
      kw_ok3:
4195
        mov     ah,8
4196
      kw_loop4:
98 mario79 4197
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4198
      kw_loop5:
4199
        in      al,0x64
4200
        test    al,1
4201
        jnz     kw_ok4
4202
        loop    kw_loop5
4203
        dec     ah
4204
        jnz     kw_loop4
4205
      kw_ok4:
4206
        xor     ah,ah
4207
      kw_exit:
4208
 
4209
        pop     edx ecx
4210
 
4211
        ret
4212
 
4213
 
4214
kb_cmd:
4215
 
98 mario79 4216
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4217
      c_wait:
4218
        in      al,0x64
4219
        test    al,2
4220
        jz      c_send
4221
        loop    c_wait
4222
        jmp     c_error
4223
      c_send:
4224
        mov     al,bl
4225
        out     0x64,al
98 mario79 4226
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4227
      c_accept:
4228
        in      al,0x64
4229
        test    al,2
4230
        jz      c_ok
4231
        loop    c_accept
4232
      c_error:
4233
        mov     ah,1
4234
        jmp     c_exit
4235
      c_ok:
4236
        xor     ah,ah
4237
      c_exit:
4238
        ret
4239
 
4240
 
4241
setmouse:  ; set mousepicture -pointer
4242
           ; ps2 mouse enable
4243
 
4244
     mov     [0xf200],dword mousepointer
4245
 
4246
     cli
33 mario79 4247
;     mov     bl,0xa8                 ; enable mouse cmd
4248
;     call    kb_cmd
4249
;     call    kb_read                 ; read status
4250
;     mov     bl,0x20                 ; get command byte
4251
;     call    kb_cmd
4252
;     call    kb_read
4253
;     or      al,3                    ; enable interrupt
4254
;     mov     bl,0x60                 ; write command
4255
;     push    eax
4256
;     call    kb_cmd
4257
;     pop     eax
4258
;     call    kb_write
4259
;     mov     bl,0xd4                 ; for mouse
4260
;     call    kb_cmd
4261
;     mov     al,0xf4                 ; enable mouse device
4262
;     call    kb_write
4263
;     call    kb_read           ; read status return
1 ha 4264
 
4265
     ; com1 mouse enable
4266
 
4267
     mov   bx,0x3f8 ; combase
4268
 
4269
     mov   dx,bx
4270
     add   dx,3
4271
     mov   al,0x80
4272
     out   dx,al
4273
 
4274
     mov   dx,bx
4275
     add   dx,1
4276
     mov   al,0
4277
     out   dx,al
4278
 
4279
     mov   dx,bx
4280
     add   dx,0
4281
     mov   al,0x30*2    ; 0x30 / 4
4282
     out   dx,al
4283
 
4284
     mov   dx,bx
4285
     add   dx,3
4286
     mov   al,2         ; 3
4287
     out   dx,al
4288
 
4289
     mov   dx,bx
4290
     add   dx,4
4291
     mov   al,0xb
4292
     out   dx,al
4293
 
4294
     mov   dx,bx
4295
     add   dx,1
4296
     mov   al,1
4297
     out   dx,al
4298
 
4299
 
4300
     ; com2 mouse enable
4301
 
4302
     mov   bx,0x2f8 ; combase
4303
 
4304
     mov   dx,bx
4305
     add   dx,3
4306
     mov   al,0x80
4307
     out   dx,al
4308
 
4309
     mov   dx,bx
4310
     add   dx,1
4311
     mov   al,0
4312
     out   dx,al
4313
 
4314
     mov   dx,bx
4315
     add   dx,0
4316
     mov   al,0x30*2
4317
     out   dx,al
4318
 
4319
     mov   dx,bx
4320
     add   dx,3
4321
     mov   al,2
4322
     out   dx,al
4323
 
4324
     mov   dx,bx
4325
     add   dx,4
4326
     mov   al,0xb
4327
     out   dx,al
4328
 
4329
     mov   dx,bx
4330
     add   dx,1
4331
     mov   al,1
4332
     out   dx,al
4333
 
4334
     ret
4335
 
4336
 
4337
_rdtsc:
4338
 
4339
     mov   edx,[cpuid_1+3*4]
4340
     test  edx,00010000b
4341
     jz    ret_rdtsc
4342
     rdtsc
4343
     ret
4344
   ret_rdtsc:
4345
     mov   edx,0xffffffff
4346
     mov   eax,0xffffffff
4347
     ret
4348
 
4349
 
4350
 
4351
rerouteirqs:
4352
 
4353
        cli
4354
 
4355
        mov     al,0x11         ;  icw4, edge triggered
4356
        out     0x20,al
4357
        call    pic_delay
4358
        out     0xA0,al
4359
        call    pic_delay
4360
 
4361
        mov     al,0x20         ;  generate 0x20 +
4362
        out     0x21,al
4363
        call    pic_delay
4364
        mov     al,0x28         ;  generate 0x28 +
4365
        out     0xA1,al
4366
        call    pic_delay
4367
 
4368
        mov     al,0x04         ;  slave at irq2
4369
        out     0x21,al
4370
        call    pic_delay
4371
        mov     al,0x02         ;  at irq9
4372
        out     0xA1,al
4373
        call    pic_delay
4374
 
4375
        mov     al,0x01         ;  8086 mode
4376
        out     0x21,al
4377
        call    pic_delay
4378
        out     0xA1,al
4379
        call    pic_delay
4380
 
4381
        mov     al,255          ; mask all irq's
4382
        out     0xA1,al
4383
        call    pic_delay
4384
        out     0x21,al
4385
        call    pic_delay
4386
 
4387
        mov     ecx,0x1000
4388
        cld
4389
picl1:  call    pic_delay
4390
        loop    picl1
4391
 
4392
        mov     al,255          ; mask all irq's
4393
        out     0xA1,al
4394
        call    pic_delay
4395
        out     0x21,al
4396
        call    pic_delay
4397
 
4398
        cli
4399
 
4400
        ret
4401
 
4402
 
4403
pic_delay:
4404
 
4405
        jmp     pdl1
4406
pdl1:   ret
4407
 
4408
 
4409
sys_msg_board_str:
4410
 
4411
     pushad
4412
   @@:
4413
     cmp    [esi],byte 0
4414
     je     @f
4415
     mov    eax,1
4416
     movzx  ebx,byte [esi]
4417
     call   sys_msg_board
4418
     inc    esi
4419
     jmp    @b
4420
   @@:
4421
     popad
4422
     ret
4423
 
4424
uglobal
4425
  msg_board_data: times 512 db 0
4426
  msg_board_count dd 0x0
4427
endg
4428
 
4429
sys_msg_board:
4430
 
4431
; eax=1 : write :  bl byte to write
4432
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4433
 
4434
     mov  ecx,[msg_board_count]
4435
     cmp  eax, 1
4436
     jne  smbl1
4437
 
4438
 
4439
     mov  [msg_board_data+ecx],bl
4440
     inc  ecx
4441
     and  ecx, 511
4442
     mov  [msg_board_count], ecx
4443
     mov  [check_idle_semaphore], 5
4444
     ret
4445
   smbl1:
4446
 
4447
     cmp   eax, 2
4448
     jne   smbl2
4449
     test  ecx, ecx
4450
     jz    smbl21
4451
;     mov   edi, msg_board_data
4452
;     mov   esi, msg_board_data+1
4453
;     movzx eax, byte [edi]
4454
     mov   eax, msg_board_data+1
4455
     mov   ebx, msg_board_data
4456
     movzx edx, byte [ebx]
4457
     call  memmove
4458
;     push  ecx
4459
;     shr   ecx, 2
4460
;     cld
4461
;     rep   movsd
4462
;     pop   ecx
4463
;     and   ecx, 3
4464
;     rep   movsb
4465
     dec   [msg_board_count]
4466
     mov   [esp+36], edx ;eax
4467
     mov   [esp+24], dword 1
4468
     ret
4469
   smbl21:
4470
     mov   [esp+36], ecx
4471
     mov   [esp+24], ecx
4472
 
4473
   smbl2:
4474
     ret
4475
 
4476
 
4477
 
4478
sys_trace:
4479
 
4480
     test eax, eax                  ; get event data
4481
     jnz  no_get_sys_events
4482
 
4483
     mov  esi,save_syscall_data     ; data
4484
     mov  edi,[0x3010]
115 poddubny 4485
     mov  edi,[edi+TASKDATA.mem_start]
1 ha 4486
     add  edi,ebx
4487
     cld
4488
     rep  movsb
4489
 
4490
     mov  [esp+24],dword 0
4491
     mov  eax,[save_syscall_count]  ; count
4492
     mov  [esp+36],eax
4493
     ret
4494
 
4495
   no_get_sys_events:
4496
 
4497
     ret
4498
 
4499
 
4500
sys_process_def:
92 diamond 4501
        mov     edi, [0x3000]
1 ha 4502
 
92 diamond 4503
        dec     eax             ; 1 = set keyboard mode
1 ha 4504
     jne   no_set_keyboard_setup
4505
 
4506
     shl   edi,8
115 poddubny 4507
     mov   [edi+0x80000 + APPDATA.keyboard_mode],bl
1 ha 4508
 
4509
     ret
4510
 
4511
   no_set_keyboard_setup:
4512
 
92 diamond 4513
        dec     eax             ; 2 = get keyboard mode
1 ha 4514
     jne   no_get_keyboard_setup
4515
 
4516
     shl   edi,8
115 poddubny 4517
     movzx eax, byte [0x80000+edi + APPDATA.keyboard_mode]
1 ha 4518
 
4519
     mov   [esp+36],eax
4520
 
4521
     ret
4522
 
4523
   no_get_keyboard_setup:
4524
 
92 diamond 4525
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4526
     jne   no_get_keyboard_cas
4527
 
4528
;     xor   eax,eax
4529
;     movzx eax,byte [shift]
4530
;     movzx ebx,byte [ctrl]
4531
;     shl   ebx,2
4532
;     add   eax,ebx
4533
;     movzx ebx,byte [alt]
4534
;     shl   ebx,3
4535
;     add   eax,ebx
4536
 
4537
 ;// mike.dld [
4538
     mov   eax, [kb_state]
4539
 ;// mike.dld ]
4540
 
4541
     mov   [esp+36],eax
4542
 
4543
     ret
4544
 
4545
   no_get_keyboard_cas:
4546
 
92 diamond 4547
        dec     eax
4548
        jnz     no_add_keyboard_hotkey
1 ha 4549
 
92 diamond 4550
        mov     eax, hotkey_list
4551
@@:
4552
        cmp     dword [eax+8], 0
4553
        jz      .found_free
4554
        add     eax, 16
4555
        cmp     eax, hotkey_list+16*256
4556
        jb      @b
4557
        mov     dword [esp+36], 1
4558
        ret
4559
.found_free:
4560
        mov     [eax+8], edi
4561
        mov     [eax+4], ecx
4562
        movzx   ebx, bl
4563
        lea     ebx, [hotkey_scancodes+ebx*4]
4564
        mov     ecx, [ebx]
4565
        mov     [eax], ecx
4566
        mov     [ebx], eax
4567
        mov     [eax+12], ebx
4568
        jecxz   @f
4569
        mov     [ecx+12], eax
4570
@@:
4571
        and     dword [esp+36], 0
4572
        ret
4573
 
4574
no_add_keyboard_hotkey:
4575
 
4576
        dec     eax
4577
        jnz     no_del_keyboard_hotkey
4578
 
4579
        movzx   ebx, bl
4580
        lea     ebx, [hotkey_scancodes+ebx*4]
4581
        mov     eax, [ebx]
4582
.scan:
4583
        test    eax, eax
4584
        jz      .notfound
4585
        cmp     [eax+8], edi
4586
        jnz     .next
4587
        cmp     [eax+4], ecx
4588
        jz      .found
4589
.next:
4590
        mov     eax, [eax]
4591
        jmp     .scan
4592
.notfound:
4593
        mov     dword [esp+36], 1
4594
        ret
4595
.found:
4596
        mov     ecx, [eax]
4597
        jecxz   @f
4598
        mov     edx, [eax+12]
4599
        mov     [ecx+12], edx
4600
@@:
4601
        mov     ecx, [eax+12]
4602
        mov     edx, [eax]
4603
        mov     [ecx], edx
4604
        xor     edx, edx
4605
        mov     [eax+4], edx
4606
        mov     [eax+8], edx
4607
        mov     [eax+12], edx
4608
        mov     [eax], edx
4609
        mov     [esp+36], edx
4610
        ret
4611
 
4612
no_del_keyboard_hotkey:
1 ha 4613
     ret
4614
 
4615
 
4616
sys_ipc:
4617
     cmp  eax,1                      ; DEFINE IPC MEMORY
4618
     jne  no_ipc_def
4619
     mov  edi,[0x3000]
4620
     shl  edi,8
4621
     add  edi,0x80000
115 poddubny 4622
     mov  [edi + APPDATA.ipc_start], ebx
4623
     mov  [edi + APPDATA.ipc_size], ecx
1 ha 4624
     mov  [esp+36],dword 0
4625
     ret
4626
   no_ipc_def:
4627
 
4628
     cmp  eax,2                      ; SEND IPC MESSAGE
4629
     jne  no_ipc_send
4630
     mov  esi,1
4631
     mov  edi,0x3020
4632
    ipcs1:
115 poddubny 4633
     cmp  [edi+TASKDATA.pid], ebx
1 ha 4634
     je   ipcs2
4635
     add  edi,0x20
4636
     inc  esi
4637
     cmp  esi,[0x3004]
4638
     jbe  ipcs1
4639
     mov  [esp+36],dword 4
4640
     ret
4641
    ipcs2:
4642
 
4643
     cli
4644
 
4645
     push esi
4646
     mov  eax,esi
4647
     shl  eax,8
115 poddubny 4648
     mov  ebx,[eax+0x80000 + APPDATA.ipc_start]
1 ha 4649
     test ebx,ebx                  ; ipc area not defined ?
4650
     je   ipc_err1
4651
 
115 poddubny 4652
     add  ebx,[eax+0x80000 + APPDATA.ipc_size]
1 ha 4653
     mov  eax,esi
4654
     shl  eax,5
115 poddubny 4655
     add  ebx,[eax+0x3000 + TASKDATA.mem_start]    ; ebx <- max data position
1 ha 4656
 
4657
     mov  eax,esi                  ; to
4658
     shl  esi,8
4659
     add  esi,0x80000
115 poddubny 4660
     mov  edi,[esi+APPDATA.ipc_start]
1 ha 4661
     shl  eax,5
4662
     add  eax,0x3000
115 poddubny 4663
     add  edi,[eax+TASKDATA.mem_start]
1 ha 4664
 
4665
     cmp  [edi],byte 0             ; overrun ?
4666
     jne  ipc_err2
4667
 
4668
     mov  ebp,edi
4669
     add  edi,[edi+4]
4670
     add  edi,8
4671
 
4672
     mov  esi,ecx                  ; from
4673
     mov  eax,[0x3010]
115 poddubny 4674
     mov  eax,[eax+TASKDATA.mem_start]
1 ha 4675
     add  esi,eax
4676
 
4677
     mov  ecx,edx                  ; size
4678
 
4679
     mov  eax,edi
4680
     add  eax,ecx
4681
     cmp  eax,ebx
75 diamond 4682
     jg   ipc_err3                 ; not enough room ?
1 ha 4683
 
4684
     push ecx
4685
 
4686
     mov  eax,[0x3010]
115 poddubny 4687
     mov  eax,[eax+TASKDATA.pid]
1 ha 4688
     mov  [edi-8],eax
4689
     mov  [edi-4],ecx
4690
     cld
4691
     rep  movsb
4692
 
4693
     pop  ecx
4694
     add  ecx,8
4695
 
4696
     mov  edi,ebp                  ; increase memory position
4697
     add  dword [edi+4],ecx
4698
 
4699
     mov  edi,[esp]
4700
     shl  edi,8
115 poddubny 4701
     or   dword [edi+0x80000+APPDATA.event_mask],dword 01000000b ; ipc message
1 ha 4702
 
4703
     cmp  [check_idle_semaphore],dword 20
4704
     jge  ipc_no_cis
4705
     mov  [check_idle_semaphore],5
4706
   ipc_no_cis:
4707
 
4708
     xor  eax, eax
4709
 
4710
    ipc_err:
4711
     add  esp,4
4712
     mov  [esp+36],eax
4713
     sti
4714
     ret
4715
 
4716
    ipc_err1:
4717
     add  esp,4
4718
     mov  [esp+36],dword 1
4719
     sti
4720
     ret
4721
    ipc_err2:
4722
     add  esp,4
4723
     mov  [esp+36],dword 2
4724
     sti
4725
     ret
4726
    ipc_err3:
4727
     add  esp,4
4728
     mov  [esp+36],dword 3
4729
     sti
4730
     ret
4731
 
4732
   no_ipc_send:
4733
 
4734
     mov  [esp+36],dword -1
4735
     ret
4736
 
4737
 
4738
align 4
4739
 
4740
sys_gs:                         ; direct screen access
4741
 
4742
     cmp  eax,1                 ; resolution
4743
     jne  no_gs1
4744
     mov  eax,[0xfe00]
4745
     shl  eax,16
4746
     mov  ax,[0xfe04]
4747
     add  eax,0x00010001
4748
     mov  [esp+36],eax
4749
     ret
4750
   no_gs1:
4751
 
4752
     cmp   eax,2                ; bits per pixel
4753
     jne   no_gs2
4754
     movzx eax,byte [0xfbf1]
4755
     mov   [esp+36],eax
4756
     ret
4757
   no_gs2:
4758
 
4759
     cmp   eax,3                ; bytes per scanline
4760
     jne   no_gs3
4761
     mov   eax,[0xfe08]
4762
     mov   [esp+36],eax
4763
     ret
4764
   no_gs3:
4765
 
4766
     mov  [esp+36],dword -1
4767
     ret
4768
 
4769
 
4770
align 4 ; PCI functions
4771
 
4772
sys_pci:
4773
 
4774
     call  pci_api
4775
     mov   [esp+36],eax
4776
     ret
4777
 
4778
 
4779
align 4  ;  system functions
4780
 
4781
syscall_setpixel:                       ; SetPixel
4782
 
4783
 
4784
     mov   edx,[0x3010]
115 poddubny 4785
     add   eax,[edx-twdw+WDATA.box.left]
4786
     add   ebx,[edx-twdw+WDATA.box.top]
114 mikedld 4787
        mov     edi,[0x3000]
4788
        shl     edi,8
4789
        add     eax,[edi+0x80000+APPDATA.wnd_clientbox.left]
4790
        add     ebx,[edi+0x80000+APPDATA.wnd_clientbox.top]
112 poddubny 4791
     xor   edi,edi ; no force
114 mikedld 4792
;     mov   edi,1
112 poddubny 4793
     call  [disable_mouse]
1 ha 4794
     jmp   [putpixel]
4795
 
4796
align 4
4797
 
4798
syscall_writetext:                      ; WriteText
4799
 
4800
     mov   edi,[0x3010]
115 poddubny 4801
     mov   ebp,[edi-twdw+WDATA.box.left]
139 diamond 4802
        push    esi
114 mikedld 4803
        mov     esi,[0x3000]
4804
        shl     esi,8
4805
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
1 ha 4806
     shl   ebp,16
115 poddubny 4807
     add   ebp,[edi-twdw+WDATA.box.top]
114 mikedld 4808
        add     bp,word[esi+0x80000+APPDATA.wnd_clientbox.top]
139 diamond 4809
        pop     esi
117 mario79 4810
     add   ecx,[edi+TASKDATA.mem_start]
1 ha 4811
     add   eax,ebp
4812
     xor   edi,edi
4813
     jmp   dtext
4814
 
4815
align 4
4816
 
4817
syscall_openramdiskfile:                ; OpenRamdiskFile
4818
 
4819
 
4820
     mov   edi,[0x3010]
115 poddubny 4821
     add   edi, TASKDATA.mem_start
1 ha 4822
     add   eax,[edi]
4823
     add   edx,[edi]
4824
     mov   esi,12
4825
     call  fileread
4826
     mov   [esp+36],ebx
4827
     ret
4828
 
4829
align 4
4830
 
4831
syscall_drawrect:                       ; DrawRect
4832
 
4833
     mov   edi,ecx
52 mikedld 4834
     and   edi,0x80FFFFFF
1 ha 4835
     test  ax,ax
4836
     je    drectr
4837
     test  bx,bx
4838
     je    drectr
4839
     movzx ecx,ax
4840
     shr   eax,16
4841
     movzx edx,bx
4842
     shr   ebx,16
114 mikedld 4843
        mov     esi,[0x3000]
4844
        shl     esi,8
4845
        add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
4846
        add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
1 ha 4847
     add   ecx,eax
4848
     add   edx,ebx
4849
     jmp   [drawbar]
4850
    drectr:
4851
     ret
4852
 
4853
align 4
4854
 
4855
syscall_getscreensize:                  ; GetScreenSize
4856
 
4857
     movzx eax,word[0xfe00]
4858
     shl   eax,16
4859
     mov   ax,[0xfe04]
4860
     mov   [esp+36],eax
4861
     ret
4862
 
4863
align 4
4864
 
4865
syscall_startapp:                       ; StartApp
4866
     mov   edi,[0x3010]
115 poddubny 4867
     add   edi, TASKDATA.mem_start
1 ha 4868
     add   eax,[edi]
4869
     test  ebx,ebx
4870
     jz    noapppar
4871
     add   ebx,[edi]
4872
   noapppar:
4873
;     call  start_application_fl
41 mikedld 4874
     xor   edx,edx      ; compatibility - flags=0
1 ha 4875
     call   new_start_application_fl
4876
     mov   [esp+36],eax
4877
     ret
4878
 
41 mikedld 4879
 
1 ha 4880
align 4
4881
 
4882
syscall_cdaudio:                        ; CD
4883
 
4884
     call  sys_cd_audio
4885
     mov   [esp+36],eax
4886
     ret
4887
 
75 diamond 4888
;  ReadHd and StartHdApp functions are obsolete. Use 58 or 70 functions instead.
4889
;align 4
4890
;
4891
;syscall_readhd:                         ; ReadHd
4892
;
4893
;     mov   edi,[0x3010]
4894
;     add   edi,0x10
4895
;     add   esi,[edi]
4896
;     add   eax,[edi]
4897
;     call  read_hd_file
4898
;     mov   [esp+36],eax
4899
;     mov   [esp+24],ebx
4900
;     ret
1 ha 4901
 
75 diamond 4902
;align 4
4903
;
4904
;syscall_starthdapp:                     ; StartHdApp
4905
;
4906
;     mov   edi,[0x3010]
4907
;     add   edi,0x10
4908
;     add   eax,[edi]
4909
;     add   ecx,[edi]
4910
;     xor   ebp,ebp
4911
;     xor   edx,edx      ; compatibility - flags=0
4912
;     call  start_application_hd
4913
;     mov   [esp+36],eax
4914
;     ret
1 ha 4915
 
4916
align 4
4917
 
4918
syscall_delramdiskfile:                 ; DelRamdiskFile
4919
 
4920
     mov   edi,[0x3010]
115 poddubny 4921
     add   edi, TASKDATA.mem_start
1 ha 4922
     add   eax,[edi]
4923
     call  filedelete
4924
     mov   [esp+36],eax
4925
     ret
4926
 
4927
align 4
4928
 
4929
syscall_writeramdiskfile:               ; WriteRamdiskFile
4930
 
4931
     mov   edi,[0x3010]
115 poddubny 4932
     add   edi, TASKDATA.mem_start
1 ha 4933
     add   eax,[edi]
4934
     add   ebx,[edi]
4935
     call  filesave
4936
     mov   [esp+36],eax
4937
     ret
4938
 
4939
align 4
4940
 
4941
syscall_getpixel:                       ; GetPixel
4942
     mov   ecx,[0xfe00]
4943
     inc   ecx
4944
     xor   edx,edx
4945
     div   ecx
4946
     mov   ebx,edx
4947
     xchg  eax,ebx
4948
     call  dword [0xe024]
4949
     mov   [esp+36],ecx
4950
     ret
4951
 
4952
align 4
4953
 
4954
syscall_readstring:                     ; ReadString
4955
 
4956
     mov   edi,[0x3010]
115 poddubny 4957
     add   edi, TASKDATA.mem_start
1 ha 4958
     add   eax,[edi]
4959
     call  read_string
4960
     mov   [esp+36],eax
4961
     ret
4962
 
4963
align 4
4964
 
4965
syscall_drawline:                       ; DrawLine
4966
 
4967
     mov   edi,[0x3010]
115 poddubny 4968
     movzx edx,word[edi-twdw+WDATA.box.left]
1 ha 4969
     mov   ebp,edx
114 mikedld 4970
        mov     esi,[0x3000]
4971
        shl     esi,8
4972
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
4973
        add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.left]
1 ha 4974
     shl   edx,16
4975
     add   ebp,edx
115 poddubny 4976
     movzx edx,word[edi-twdw+WDATA.box.top]
1 ha 4977
     add   eax,ebp
4978
     mov   ebp,edx
114 mikedld 4979
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.top]
4980
        add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.top]
1 ha 4981
     shl   edx,16
4982
     xor   edi,edi
4983
     add   edx,ebp
4984
     add   ebx,edx
4985
     jmp   [draw_line]
4986
 
4987
align 4
4988
 
4989
syscall_getirqowner:                    ; GetIrqOwner
75 diamond 4990
     cmp   eax,16
4991
     jae   .err
1 ha 4992
     shl   eax,2
4993
     add   eax,irq_owner
4994
     mov   eax,[eax]
4995
     mov   [esp+36],eax
4996
     ret
75 diamond 4997
.err:
4998
     or    dword [esp+36], -1
4999
     ret
1 ha 5000
 
5001
align 4
5002
 
5003
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5004
 
5005
     call  r_f_port_area
5006
     mov   [esp+36],eax
5007
     ret
5008
 
5009
align 4
5010
 
5011
syscall_threads:                        ; CreateThreads
5012
 
5013
     call  sys_threads
5014
     mov   [esp+36],eax
5015
     ret
5016
 
5017
align 4
5018
 
5019
stack_driver_stat:
5020
 
5021
     call  app_stack_handler            ; Stack status
5022
 
5023
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5024
;     call  change_task                 ; between sent packet
5025
 
5026
     mov   [esp+36],eax
5027
     ret
5028
 
5029
align 4
5030
 
5031
socket:                                 ; Socket interface
5032
     call  app_socket_handler
5033
 
5034
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5035
;     call  change_task                 ; between sent packet
5036
 
5037
     mov   [esp+36],eax
5038
     mov   [esp+24],ebx
5039
     ret
5040
 
5041
align 4
5042
 
5043
user_events:                            ; User event times
5044
 
5045
     mov   eax,0x12345678
5046
     mov   [esp+36],eax
5047
 
5048
     ret
5049
 
5050
align 4
5051
 
5052
read_from_hd:                           ; Read from hd - fn not in use
5053
 
5054
     mov   edi,[0x3010]
115 poddubny 5055
     add   edi,TASKDATA.mem_start
1 ha 5056
     add   eax,[edi]
5057
     add   ecx,[edi]
5058
     add   edx,[edi]
5059
     call  file_read
5060
 
5061
     mov   [esp+36],eax
5062
     mov   [esp+24],ebx
5063
 
5064
     ret
5065
 
5066
 
5067
align 4
5068
 
5069
write_to_hd:                            ; Write a file to hd
5070
 
5071
     mov   edi,[0x3010]
115 poddubny 5072
     add   edi,TASKDATA.mem_start
1 ha 5073
     add   eax,[edi]
5074
     add   ecx,[edi]
5075
     add   edx,[edi]
5076
     call  file_write
5077
     ret
5078
 
75 diamond 5079
;  Sysfunction 57, delete_from_hd, is obsolete. Use 58 or 70 functions instead.
5080
;align 4
5081
;
5082
;delete_from_hd:                         ; Delete a file from hd
5083
;
5084
;     mov   edi,[0x3010]
5085
;     add   edi,0x10
5086
;     add   eax,[edi]
5087
;     add   ecx,[edi]
5088
;     call  file_delete
5089
;     ret
5090
;
1 ha 5091
 
76 mario79 5092
; --------------- APM ---------------------
5093
apm_entry    dp    0
5094
apm_vf        dd    0
1 ha 5095
align 4
76 mario79 5096
sys_apm:
5097
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5098
    jne    @f
78 diamond 5099
    or    [esp + 56], byte 1    ; error
76 mario79 5100
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
5101
    ret
5102
 
5103
@@:    xchg    eax, ecx
5104
    xchg    ebx, ecx
5105
 
5106
    cmp    al, 3
5107
    ja    @f
78 diamond 5108
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5109
    mov    eax, [apm_vf]
5110
    mov    [esp + 36], eax
5111
    shr    eax, 16
5112
    mov    [esp + 32], eax
5113
    ret
78 diamond 5114
 
76 mario79 5115
@@:    call    pword [apm_entry]    ; call APM BIOS
5116
    mov    [esp + 8 ], edi
5117
    mov    [esp + 12], esi
5118
    mov    [esp + 24], ebx
5119
    mov    [esp + 28], edx
5120
    mov    [esp + 32], ecx
5121
    mov    [esp + 36], eax
5122
    setc    al
78 diamond 5123
    and    [esp + 56], byte 0xfe
5124
    or    [esp + 56], al
76 mario79 5125
    ret
5126
; -----------------------------------------
1 ha 5127
 
76 mario79 5128
align 4
5129
 
1 ha 5130
undefined_syscall:                      ; Undefined system call
5131
 
5132
     mov   [esp+36],dword -1
5133
     ret
5134
 
5135
 
5136
;clear_busy_flag_at_caller:
5137
 
5138
;      push  edi
5139
 
5140
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
5141
;      imul  edi,8
5142
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
5143
 
5144
;      pop   edi
5145
 
5146
;      ret
5147
 
5148
 
5149
 
5150
 
5151
keymap:
5152
 
5153
     db   '6',27
5154
     db   '1234567890-=',8,9
5155
     db   'qwertyuiop[]',13
5156
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
5157
     db   '@234567890123',180,178,184,'6',176,'7'
5158
     db   179,'8',181,177,183,185,182
5159
     db   'AB
5160
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5161
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5162
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5163
 
5164
 
5165
keymap_shift:
5166
 
5167
     db   '6',27
5168
     db   '!@#$%^&*()_+',8,9
5169
     db   'QWERTYUIOP{}',13
5170
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
5171
     db   '@234567890123',180,178,184,'6',176,'7'
5172
     db   179,'8',181,177,183,185,182
5173
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
5174
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5175
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5176
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5177
 
5178
 
5179
keymap_alt:
5180
 
5181
     db   ' ',27
5182
     db   ' @ $  {[]}\ ',8,9
5183
     db   '            ',13
5184
     db   '             ',0,'           ',0,'4',0,' '
5185
     db   '             ',180,178,184,'6',176,'7'
5186
     db   179,'8',181,177,183,185,182
5187
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
5188
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5189
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5190
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5191
 
5192
 
5193
; device irq owners
5194
uglobal
5195
irq_owner:       ; process id
5196
 
5197
     dd   0x0
5198
     dd   0x0
5199
     dd   0x0
5200
     dd   0x0
5201
     dd   0x0
5202
     dd   0x0
5203
     dd   0x0
5204
     dd   0x0
5205
     dd   0x0
5206
     dd   0x0
5207
     dd   0x0
5208
     dd   0x0
5209
     dd   0x0
5210
     dd   0x0
5211
     dd   0x0
5212
     dd   0x0
5213
endg
5214
 
5215
 
5216
; on irq read ports
5217
uglobal
5218
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5219
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5220
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5221
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5222
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5223
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5224
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5225
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5226
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5227
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5228
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5229
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5230
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5231
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5232
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5233
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5234
endg
5235
 
5236
; status
5237
uglobal
5238
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5239
  application_table_status    dd 0x0  ; 0 - free : other - pid
5240
endg
5241
 
5242
; device addresses
5243
uglobal
5244
  mididp     dd 0x0
5245
  midisp     dd 0x0
5246
 
5247
  cdbase     dd 0x0
5248
  cdid       dd 0x0
5249
 
5250
  hdbase              dd   0x0  ; for boot 0x1f0
5251
  hdid                dd   0x0
5252
  hdpos               dd   0x0  ; for boot 0x1
5253
  fat32part           dd   0x0  ; for boot 0x1
5254
 
5255
  ;part2_ld            dd   0x0
5256
 
102 poddubny 5257
;* start code - Mario79
33 mario79 5258
mouse_pause         dd   0
36 mario79 5259
MouseTickCounter    dd   0
33 mario79 5260
ps2_mouse_detected  db   0
5261
com1_mouse_detected db   0
5262
com2_mouse_detected db   0
102 poddubny 5263
;* end code - Mario79
1 ha 5264
 
5265
wraw_bacground_select db 0
5266
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5267
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5268
 
5269
  sb16       dd 0x0
5270
  wss        dd 0x0
5271
 
5272
  buttontype         dd 0x0
5273
  windowtypechanged  dd 0x0
5274
endg
5275
 
5276
iglobal
5277
  keyboard   dd 0x1
5278
  sound_dma  dd 0x1
5279
  syslang    dd 0x1
5280
endg
5281
 
5282
IncludeIGlobals
5283
endofcode:
5284
IncludeUGlobals
5285
uglobals_size = $ - endofcode
41 mikedld 5286
diff16 "end of kernel code",0,$
1 ha 5287