Subversion Repositories Kolibri OS

Rev

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