Subversion Repositories Kolibri OS

Rev

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