Subversion Repositories Kolibri OS

Rev

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