Subversion Repositories Kolibri OS

Rev

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