Subversion Repositories Kolibri OS

Rev

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

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