Subversion Repositories Kolibri OS

Rev

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

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