Subversion Repositories Kolibri OS

Rev

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

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