Subversion Repositories Kolibri OS

Rev

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

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