Subversion Repositories Kolibri OS

Rev

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