Subversion Repositories Kolibri OS

Rev

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