Subversion Repositories Kolibri OS

Rev

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