Subversion Repositories Kolibri OS

Rev

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

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