Subversion Repositories Kolibri OS

Rev

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