Subversion Repositories Kolibri OS

Rev

Rev 188 | Rev 200 | 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
 
147 diamond 81
version           db    'Kolibri OS  version 0.6.0.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
1 ha 231
  char       db  'CHAR    MT '
232
  char2      db  'CHAR2   MT '
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
 
526
        mov   eax,char
527
        mov   esi,12
528
        xor   ebx,ebx
12 halyavin 529
        mov   ecx,2560;26000
530
        mov   edx,0x3F600;0x37000
1 ha 531
        call  fileread
532
 
533
        mov   eax,char2
534
        mov   esi,12
535
        xor   ebx,ebx
12 halyavin 536
        mov   ecx,2560;26000
537
        mov   edx,0x3EC00;0x30000
1 ha 538
        call  fileread
539
 
540
        mov   esi,boot_fonts
541
        call  boot_log
542
 
543
; PRINT AMOUNT OF MEMORY
544
        mov     esi, boot_memdetect
545
        call    boot_log
546
 
547
        movzx   ecx, word [boot_y]
548
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
549
        sub     ecx, 10
550
        mov     edx, 0xFFFFFF
164 serge 551
        mov     ebx, [MEM_AMOUNT]
1 ha 552
        shr     ebx, 20
553
        mov     edi, 1
554
        mov     eax, 0x00040000
555
        call    display_number
41 mikedld 556
 
1 ha 557
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
558
 
559
        mov   esi,boot_irqs
560
        call  boot_log
561
        call  rerouteirqs
562
 
563
        mov    esi,boot_tss
564
        call   boot_log
565
 
566
; BUILD SCHEDULER
567
 
568
        call   build_scheduler ; sys32.inc
569
 
570
; LOAD IDT
13 poddubny 571
        lidt   [cs:idtreg]
1 ha 572
 
41 mikedld 573
;The CPU to this moment should be already in PM,
574
;and bit MP of the register cr0 should be installed in 1.
164 serge 575
;finit ;reset of the FPU (finit, instead of fninit)
576
;fsetpm ;enable PM of the FPU
577
;finit ;reset the registers, contents which are still equal RM
41 mikedld 578
;Now FPU too in PM
1 ha 579
; DETECT DEVICES
580
 
581
        mov    esi,boot_devices
582
        call   boot_log
583
        call   detect_devices
584
 
585
 ; TIMER SET TO 1/100 S
586
 
587
        mov   esi,boot_timer
588
        call  boot_log
589
        mov   al,0x34              ; set to 100Hz
590
        out   0x43,al
591
        mov   al,0x9b              ; lsb    1193180 / 1193
592
        out   0x40,al
593
        mov   al,0x2e              ; msb
594
        out   0x40,al
595
 
596
; SET MOUSE
597
 
598
        mov   esi,boot_setmouse
599
        call  boot_log
600
        call  setmouse
601
 
602
; SET PRELIMINARY WINDOW STACK AND POSITIONS
603
 
604
        mov   esi,boot_windefs
605
        call  boot_log
606
        call  setwindowdefaults
607
 
608
; SET BACKGROUND DEFAULTS
609
 
610
        mov   esi,boot_bgr
611
        call  boot_log
612
        call  calculatebackground
613
 
614
; RESERVE SYSTEM IRQ'S JA PORT'S
615
 
616
        mov   esi,boot_resirqports
617
        call  boot_log
618
        call  reserve_irqs_ports
619
 
620
; SET PORTS FOR IRQ HANDLERS
621
 
622
        mov  esi,boot_setrports
623
        call boot_log
624
        call setirqreadports
625
 
626
; SET UP OS TASK
627
 
628
        mov  esi,boot_setostask
629
        call boot_log
630
        ; name for OS/IDLE process
117 mario79 631
        mov  dword [0x80000+256+APPDATA.app_name],   dword 'OS/I'
632
        mov  dword [0x80000+256+APPDATA.app_name+4], dword 'DLE '
164 serge 633
        mov eax, [fpu_data]
634
        mov  dword [0x80000+APPDATA.fpu_state], eax
635
        mov  dword [0x80000+APPDATA.fpu_handler], 0
636
        mov  dword [0x80000+APPDATA.sse_handler], 0
637
 
638
        add eax, 112
639
        bt [cpu_caps], CAPS_FXSR
640
        jnc .no_sse
641
        add eax, 512-112
642
.no_sse:
643
        mov  dword [0x80000+256+APPDATA.fpu_state], eax
644
        mov  dword [0x80000+256+APPDATA.fpu_handler], 0
645
        mov  dword [0x80000+256+APPDATA.sse_handler], 0
1 ha 646
        ; task list
115 poddubny 647
        mov  [0x3020+TASKDATA.wnd_number], 1 ; on screen number
648
        mov  [0x3020+TASKDATA.pid], 1        ; process id number
649
        mov  [0x3020+TASKDATA.mem_start], 0  ; process base address
1 ha 650
 
651
        ; set default flags & stacks
652
        mov  [l.eflags],dword 0x11202 ; sti and resume
653
        mov  [l.ss0], os_data
654
        ; osloop - TSS
655
        mov  eax,cr3
656
        mov  [l.cr3],eax
657
        mov  [l.eip],osloop
13 poddubny 658
        mov  [l.esp],sysint_stack_data + 4096*2 ; uses slot 1 stack
1 ha 659
        mov  [l.cs],os_code
660
        mov  [l.ss],os_data
661
        mov  [l.ds],os_data
662
        mov  [l.es],os_data
663
        mov  [l.fs],os_data
664
        mov  [l.gs],os_data
665
        ; move tss to tss_data+tss_step
666
        mov  esi,tss_sceleton
667
        mov  edi,tss_data+tss_step
668
        mov  ecx,120/4
669
        cld
670
        rep  movsd
671
 
672
        mov  ax,tss0
673
        ltr  ax
674
 
675
; READ TSC / SECOND
676
 
677
        mov   esi,boot_tsc
678
        call  boot_log
679
        call  _rdtsc
680
        mov   ecx,eax
681
        mov   esi,250               ; wait 1/4 a second
682
        call  delay_ms
683
        call  _rdtsc
684
        sub   eax,ecx
685
        shl   eax,2
686
        mov   [0xf600],eax          ; save tsc / sec
172 serge 687
        mov ebx, 1000000
688
        div ebx
689
        mov [stall_mcs], eax
1 ha 690
 
691
; SET VARIABLES
692
 
693
        call  set_variables
694
 
695
; STACK AND FDC
696
 
697
        call  stack_init
698
        call  fdc_init
699
 
700
; PALETTE FOR 320x200 and 640x480 16 col
701
 
702
        cmp   [0xfe0c],word 0x12
703
        jne   no_pal_vga
704
        mov   esi,boot_pal_vga
705
        call  boot_log
706
        call  paletteVGA
707
      no_pal_vga:
708
 
709
        cmp   [0xfe0c],word 0x13
710
        jne   no_pal_ega
711
        mov   esi,boot_pal_ega
712
        call  boot_log
713
        call  palette320x200
714
      no_pal_ega:
715
 
716
; LOAD DEFAULT SKIN
717
 
49 mikedld 718
        mov     esi,_skin_file_default
719
        mov     edi,_skin_file
720
        movsd
721
        movsd
722
        movsd
723
        call    load_skin
1 ha 724
 
725
; LOAD FIRST APPLICATION
21 poddubny 726
        mov   [0x3000],dword 1
727
        mov   [0x3004],dword 1
1 ha 728
        cli
143 diamond 729
        cmp   byte [0x2f0000+0x9030],1
1 ha 730
        jne   no_load_vrr_m
143 diamond 731
        mov   ebp,vrr_m
732
        lea   esi,[ebp+6]       ; skip '/rd/1/'
41 mikedld 733
        xor   ebx,ebx                   ; no parameters
40 halyavin 734
        xor   edx,edx                   ; no flags
143 diamond 735
        call  fs_RamdiskExecute.flags
21 poddubny 736
        cmp   eax,2                  ; if vrr_m app found (PID=2)
1 ha 737
        je    first_app_found
41 mikedld 738
 
21 poddubny 739
    no_load_vrr_m:
143 diamond 740
        mov   ebp,firstapp
741
        lea   esi,[ebp+6]
40 halyavin 742
        xor   ebx,ebx                   ; no parameters
743
        xor   edx,edx                   ; no flags
143 diamond 744
        call  fs_RamdiskExecute.flags
1 ha 745
 
21 poddubny 746
        cmp   eax,2                  ; continue if a process has been loaded
1 ha 747
        je    first_app_found
21 poddubny 748
        mov   eax, 0xDEADBEEF        ; otherwise halt
749
        hlt
1 ha 750
      first_app_found:
751
        cli
752
 
21 poddubny 753
        ;mov   [0x3004],dword 2
754
        mov   [0x3000],dword 1       ; set OS task fisrt
1 ha 755
 
756
 
21 poddubny 757
; SET KEYBOARD PARAMETERS
758
        mov   al, 0xf6         ; reset keyboard, scan enabled
1 ha 759
        call  kb_write
760
 
21 poddubny 761
        ; wait until 8042 is ready
33 mario79 762
;        xor ecx,ecx
763
;      @@:
41 mikedld 764
;        in     al,64h
33 mario79 765
;        and    al,00000010b
766
;        loopnz @b
767
        call  Wait8042BufferEmpty
1 ha 768
 
769
       ; mov   al, 0xED       ; svetodiody - only for testing!
770
       ; call  kb_write
771
       ; call  kb_read
772
       ; mov   al, 111b
773
       ; call  kb_write
774
       ; call  kb_read
41 mikedld 775
 
1 ha 776
        mov   al, 0xF3       ; set repeat rate & delay
777
        call  kb_write
778
        call  kb_read
92 diamond 779
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
1 ha 780
        call  kb_write
781
        call  kb_read
782
     ;// mike.dld [
783
        call  set_lights
784
     ;// mike.dld ]
785
 
21 poddubny 786
; START MULTITASKING
1 ha 787
 
21 poddubny 788
        mov   esi,boot_tasking
789
        call  boot_log
790
 
791
        mov   [0xe000],byte 1        ; multitasking enabled
792
 
1 ha 793
; UNMASK ALL IRQ'S
794
 
795
        mov   esi,boot_allirqs
796
        call  boot_log
41 mikedld 797
 
1 ha 798
        cli                          ;guarantee forbidance of interrupts.
799
        mov   al,0                   ; unmask all irq's
800
        out   0xA1,al
801
        out   0x21,al
802
 
803
        mov   ecx,32
804
 
805
     ready_for_irqs:
806
 
807
        mov   al,0x20                ; ready for irqs
808
        out   0x20,al
809
        out   0xa0,al
810
 
811
        loop  ready_for_irqs         ; flush the queue
812
 
164 serge 813
        stdcall attach_int_handler, dword 1, irq1
814
 
1 ha 815
;        mov    [dma_hdd],1
160 diamond 816
        cmp     [IDEContrRegsBaseAddr], 0
817
        setnz   [dma_hdd]
1 ha 818
 
819
        sti
820
        jmp   $                      ; wait here for timer to take control
821
 
822
        ; Fly :)
823
 
824
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
825
;                                                                    ;
33 mario79 826
;                    MAIN OS LOOP START                              ;
1 ha 827
;                                                                    ;
828
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
829
align 32
830
osloop:
831
 
832
        call   [draw_pointer]
833
        call   checkbuttons
834
        call   checkwindows
49 mikedld 835
;       call   check_window_move_request
1 ha 836
        call   checkmisc
117 mario79 837
        call   checkVga_N13
1 ha 838
        call   stack_handler
839
        call   checkidle
840
        call   check_fdd_motor_status
841
        jmp    osloop
33 mario79 842
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
843
;                                                                    ;
844
;                      MAIN OS LOOP END                              ;
845
;                                                                    ;
846
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 847
 
848
checkidle:
849
        pushad
850
 
851
        cmp  [check_idle_semaphore],0
852
        jne  no_idle_state
853
 
854
        call change_task
855
        mov  eax,[idlemem]
856
        mov  ebx,[timer_ticks] ;[0xfdf0]
857
        cmp  eax,ebx
858
        jnz  idle_exit
859
        call _rdtsc
860
        mov  ecx,eax
861
      idle_loop:
862
        hlt
863
        cmp  [check_idle_semaphore],0
864
        jne  idle_loop_exit
865
        mov  eax,[timer_ticks] ;[0xfdf0]
866
        cmp  ebx,eax
867
        jz   idle_loop
868
      idle_loop_exit:
869
        mov  [idlemem],eax
870
        call _rdtsc
871
        sub  eax,ecx
872
        mov  ebx,[idleuse]
873
        add  ebx,eax
874
        mov  [idleuse],ebx
875
 
876
        popad
877
        ret
878
 
879
      idle_exit:
880
 
881
        mov  ebx,[timer_ticks] ;[0xfdf0]
882
        mov  [idlemem],ebx
883
        call change_task
884
 
885
        popad
886
        ret
887
 
888
      no_idle_state:
889
 
890
        dec  [check_idle_semaphore]
891
 
892
        mov  ebx,[timer_ticks] ;[0xfdf0]
893
        mov  [idlemem],ebx
894
        call change_task
895
 
896
        popad
897
        ret
898
 
899
uglobal
900
  idlemem               dd   0x0
901
  idleuse               dd   0x0
902
  idleusesec            dd   0x0
903
  check_idle_semaphore  dd   0x0
904
endg
905
 
906
 
907
 
908
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
909
;                                                                      ;
910
;                   INCLUDED SYSTEM FILES                              ;
911
;                                                                      ;
912
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
913
 
914
 
7 me_root 915
include "kernel32.inc"
1 ha 916
 
917
 
918
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
919
;                                                                      ;
920
;                       KERNEL FUNCTIONS                               ;
921
;                                                                      ;
922
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
923
 
924
reserve_irqs_ports:
925
 
926
        pushad
927
 
928
        mov  [irq_owner+4*0],byte 1    ; timer
929
        mov  [irq_owner+4*1],byte 1    ; keyboard
930
        mov  [irq_owner+4*5],byte 1    ; sound blaster
931
        mov  [irq_owner+4*6],byte 1    ; floppy diskette
932
        mov  [irq_owner+4*13],byte 1   ; math co-pros
933
        mov  [irq_owner+4*14],byte 1   ; ide I
934
        mov  [irq_owner+4*15],byte 1   ; ide II
58 mario79 935
;        movzx eax,byte [0xf604]        ; mouse irq
936
;        dec   eax
937
;        add   eax,mouseirqtable
938
;        movzx eax,byte [eax]
939
;        shl   eax,2
940
;        mov   [irq_owner+eax],byte 1
1 ha 941
 
942
 
943
                                       ; RESERVE PORTS
944
        mov   edi,1                    ; 0x00-0xff
945
        mov   [0x2d0000],edi
946
        shl   edi,4
947
        mov   [0x2d0000+edi+0],dword 1
948
        mov   [0x2d0000+edi+4],dword 0x0
949
        mov   [0x2d0000+edi+8],dword 0xff
58 mario79 950
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
951
;        jne   ripl1
952
;        inc   dword [0x2d0000]
953
;        mov   edi,[0x2d0000]
954
;        shl   edi,4
955
;        mov   [0x2d0000+edi+0],dword 1
956
;        mov   [0x2d0000+edi+4],dword 0x3f0
957
;        mov   [0x2d0000+edi+8],dword 0x3ff
958
;      ripl1:
959
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
960
;        jne   ripl2
961
;        inc   dword [0x2d0000]
962
;        mov   edi,[0x2d0000]
963
;        shl   edi,4
964
;        mov   [0x2d0000+edi+0],dword 1
965
;        mov   [0x2d0000+edi+4],dword 0x2f0
966
;        mov   [0x2d0000+edi+8],dword 0x2ff
967
;      ripl2:
1 ha 968
 
969
        popad
970
        ret
971
 
972
iglobal
973
mouseirqtable   db  12    ; ps2
974
                db  4     ; com1
975
                db  3     ; com2
976
endg
977
 
978
setirqreadports:
979
 
980
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
981
        mov   [irq12read+4],dword 0                  ; end of port list
982
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
983
        mov   [irq04read+4],dword 0                  ; end of port list
984
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
985
        mov   [irq03read+4],dword 0                  ; end of port list
986
 
987
        ret
988
 
989
iglobal
990
  process_number dd 0x1
991
endg
992
 
993
set_variables:
994
 
995
        mov   ecx,0x100                       ; flush port 0x60
996
.fl60:  in    al,0x60
997
        loop  .fl60
998
        mov   [0xfcff],byte 0                 ; mouse buffer
999
        mov   [0xf400],byte 0                 ; keyboard buffer
1000
        mov   [0xf500],byte 0                 ; button buffer
1001
;        mov   [0xfb0a],dword 100*65536+100    ; mouse x/y
1002
 
1003
        push  eax
1004
        mov   ax,[0x2f0000+0x900c]
1005
        shr   ax,1
1006
        shl   eax,16
1007
        mov   ax,[0x2f0000+0x900A]
1008
        shr   ax,1
1009
        mov   [0xfb0a],eax
1010
        pop   eax
41 mikedld 1011
 
1 ha 1012
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1013
        mov   [display_data-12],dword 1       ; tiled background
1014
        mov   [0xfe88],dword 0x2C0000         ; address of button list
1015
 
1016
     ;!! IP 04.02.2005:
1017
        mov   [next_usage_update], 100
1018
        mov   byte [0xFFFF], 0 ; change task if possible
1019
 
1020
        ret
1021
 
1022
;* mouse centered - start code- Mario79
1023
mouse_centered:
1024
        push  eax
1025
        mov   eax,[0xFE00]
1026
        shr   eax,1
1027
        mov   [0xFB0A],ax
1028
        mov   eax,[0xFE04]
1029
        shr   eax,1
1030
        mov   [0xFB0C],ax
1031
        pop   eax
1032
        ret
1033
;* mouse centered - end code- Mario79
1034
 
1035
align 4
1036
 
1037
sys_outport:
1038
 
1039
    mov   edi,ebx          ; separate flag for read / write
1040
    and   ebx,65535
1041
 
1042
    mov   ecx,[0x2d0000]
1043
    test  ecx,ecx
1044
    jne   sopl8
1045
    mov   [esp+36],dword 1
1046
    ret
1047
 
1048
  sopl8:
1049
    mov   edx,[0x3010]
1050
    mov   edx,[edx+0x4]
1051
    and   ebx,65535
1052
    cld
1053
  sopl1:
1054
 
1055
    mov   esi,ecx
1056
    shl   esi,4
1057
    add   esi,0x2d0000
1058
    cmp   edx,[esi+0]
1059
    jne   sopl2
1060
    cmp   ebx,[esi+4]
1061
    jb    sopl2
1062
    cmp   ebx,[esi+8]
1063
    jg    sopl2
1064
    jmp   sopl3
1065
 
1066
  sopl2:
1067
 
1068
    dec   ecx
1069
    jnz   sopl1
1070
    mov   [esp+36],dword 1
1071
    ret
1072
 
1073
  sopl3:
1074
 
1075
    test  edi,0x80000000 ; read ?
1076
    jnz   sopl4
1077
 
1078
    mov   dx,bx          ; write
1079
    out   dx,al
1080
    mov   [esp+36],dword 0
1081
    ret
1082
 
1083
  sopl4:
1084
 
1085
    mov   dx,bx          ; read
1086
    in    al,dx
1087
    and   eax,0xff
1088
    mov   [esp+36],dword 0
1089
    mov   [esp+24],eax
1090
    ret
1091
 
1092
 
1093
 
1094
align 4
1095
sys_sb16:
1096
 
1097
     cmp  word [sb16],word 0
1098
     jnz  sb16l1
1099
     mov  [esp+36],dword 1
1100
     ret
1101
   sb16l1:
1102
     mov  [esp+36],dword 0
1103
     cmp  eax,1    ; set volume - main
1104
     jnz  sb16l2
1105
     mov  dx,word [sb16]
1106
     add  dx,4
1107
     mov  al,0x22
1108
     out  dx,al
1109
     mov  esi,1
1110
     call delay_ms
1111
     mov  eax,ebx
1112
     inc  edx
1113
     out  dx,al
1114
     ret
1115
   sb16l2:
1116
 
1117
     cmp  eax,2    ; set volume - cd
1118
     jnz  sb16l3
1119
     mov  dx,word [sb16]
1120
     add  dx,4
1121
     mov  al,0x28
1122
     out  dx,al
1123
     mov  esi,1
1124
     call delay_ms
1125
     mov  eax,ebx
1126
     add  edx,1
1127
     out  dx,al
1128
     ret
1129
   sb16l3:
1130
      mov  [esp+36],dword 2
1131
      ret
1132
 
1133
 
1134
align 4
1135
 
1136
sys_sb16II:
1137
 
1138
     cmp  word [sb16],word 0
1139
     jnz  IIsb16l1
1140
     mov  [esp+36],dword 1
1141
     ret
1142
   IIsb16l1:
1143
 
1144
     cmp  eax,1    ; set volume - main
1145
     jnz  IIsb16l2
1146
     ; L
1147
     mov  dx,word [sb16]
1148
     add  dx,4
1149
     mov  al,0x30
1150
     out  dx,al
1151
     mov  eax,ebx
1152
     inc  edx
1153
     out  dx,al
1154
     ; R
1155
     mov  dx,word [sb16]
1156
     add  dx,4
1157
     mov  al,0x31
1158
     out  dx,al
1159
     mov  eax,ebx
1160
     inc  edx
1161
     out  dx,al
1162
     mov  [esp+36],dword 0
1163
     ret
1164
   IIsb16l2:
1165
 
1166
     cmp  eax,2    ; set volume - cd
1167
     jnz  IIsb16l3
1168
     ; L
1169
     mov  dx,word [sb16]
1170
     add  dx,4
1171
     mov  al,0x36
1172
     out  dx,al
1173
     mov  eax,ebx
1174
     inc  edx
1175
     out  dx,al
1176
     ; R
1177
     mov  dx,word [sb16]
1178
     add  dx,4
1179
     mov  al,0x37
1180
     out  dx,al
1181
     mov  eax,ebx
1182
     inc  edx
1183
     out  dx,al
1184
     mov  [esp+36],dword 0
1185
     ret
1186
   IIsb16l3:
1187
 
1188
     mov  [esp+36],dword 2
1189
     ret
1190
 
1191
 
1192
align 4
1193
 
1194
sys_wss:
1195
 
1196
     cmp  word [wss],word 0
1197
     jnz  wssl1
1198
     mov  [esp+36],dword 1
1199
     ret
1200
   wssl1:
1201
 
1202
     cmp  eax,1    ; set volume - main
1203
     jnz  wssl2
1204
     mov  [esp+36],dword 0
1205
     ret
1206
   wssl2:
1207
 
1208
     cmp  eax,2    ; set volume - cd
1209
     jnz  wssl3
1210
     ; L
1211
     mov  dx,word [wss]
1212
     add  dx,4
1213
     mov  al,0x2
1214
     out  dx,al
1215
     mov  esi,1
1216
     call delay_ms
1217
     mov  eax,ebx
1218
     inc  edx
1219
     out  dx,al
1220
     ; R
1221
     mov  dx,word [wss]
1222
     add  dx,4
1223
     mov  al,0x3
1224
     out  dx,al
1225
     mov  esi,1
1226
     call delay_ms
1227
     mov  eax,ebx
1228
     inc  edx
1229
     out  dx,al
1230
     mov  [esp+36],dword 0
1231
     ret
1232
   wssl3:
1233
     mov   [esp+36],dword 2
1234
     ret
1235
 
1236
display_number:
1237
 
1238
; eax = print type, al=0 -> ebx is number
1239
;                   al=1 -> ebx is pointer
1240
;                   ah=0 -> display decimal
1241
;                   ah=1 -> display hexadecimal
1242
;                   ah=2 -> display binary
1243
;                   eax bits 16-21 = number of digits to display (0-32)
1244
;                   eax bits 22-31 = reserved
1245
;
1246
; ebx = number or pointer
1247
; ecx = x shl 16 + y
1248
; edx = color
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:
147 diamond 2191
  db 0,6,0,0  ; version 0.6.0.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
3024
        mov     ecx,[edi*8+0x80000+APPDATA.mem_size]
3025
        add     ecx,255 ; max caption length
3026
        cmp     ebx,ecx
3027
        ja      .exit_fail
3028
 
3029
        mov     [edi*8+0x80000+APPDATA.wnd_caption],ebx
3030
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3031
 
3032
        call    draw_window_caption
3033
 
3034
        xor     eax,eax ; eax = 0 (success)
3035
        ret
3036
 
3037
  .get_window_caption:
3038
        dec     eax     ; subfunction #2 - get window caption
3039
        jnz     .exit_fail
3040
 
3041
        ; not implemented yet
3042
 
3043
  .exit_fail:
3044
        xor     eax,eax
3045
        inc     eax     ; eax = 1 (fail)
3046
        ret
3047
 
3048
 
1 ha 3049
sys_window_move:
3050
 
115 poddubny 3051
        mov     edi,[0x3000]
49 mikedld 3052
        shl     edi,5
3053
        add     edi,window_data
1 ha 3054
 
49 mikedld 3055
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3056
        jnz     .window_move_return
1 ha 3057
 
115 poddubny 3058
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3059
        push    dword [edi + WDATA.box.top]
3060
        push    dword [edi + WDATA.box.width]
3061
        push    dword [edi + WDATA.box.height]
1 ha 3062
 
49 mikedld 3063
        cmp   eax,-1                  ; set new position and size
3064
        je    .no_x_reposition
115 poddubny 3065
        mov     [edi + WDATA.box.left], eax
49 mikedld 3066
      .no_x_reposition:
3067
        cmp   ebx,-1
3068
        je    .no_y_reposition
115 poddubny 3069
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3070
      .no_y_reposition:
1 ha 3071
 
49 mikedld 3072
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3073
        jnz     .no_y_resizing
1 ha 3074
 
49 mikedld 3075
        cmp   ecx,-1
3076
        je    .no_x_resizing
115 poddubny 3077
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3078
      .no_x_resizing:
3079
        cmp   edx,-1
3080
        je    .no_y_resizing
115 poddubny 3081
        mov     [edi + WDATA.box.height], edx
49 mikedld 3082
      .no_y_resizing:
1 ha 3083
 
49 mikedld 3084
        call  check_window_position
150 diamond 3085
        call  set_window_clientbox
1 ha 3086
 
49 mikedld 3087
        pushad                       ; save for window fullscreen/resize
3088
        mov   esi,edi
3089
        sub   edi,window_data
3090
        shr   edi,5
3091
        shl   edi,8
115 poddubny 3092
        add   edi, 0x80000 + APPDATA.saved_box
49 mikedld 3093
        mov   ecx,4
3094
        cld
3095
        rep   movsd
3096
        popad
3097
 
3098
        pushad                       ; calculcate screen at new position
115 poddubny 3099
        mov   eax, [edi + WDATA.box.left]
3100
        mov   ebx, [edi + WDATA.box.top]
3101
        mov   ecx, [edi + WDATA.box.width]
3102
        mov   edx, [edi + WDATA.box.height]
164 serge 3103
        add   ecx,eax
3104
        add   edx,ebx
49 mikedld 3105
        call  calculatescreen
3106
        popad
3107
 
3108
        pop   edx                   ; calculcate screen at old position
3109
        pop   ecx
3110
        pop   ebx
3111
        pop   eax
3112
        add   ecx,eax
3113
        add   edx,ebx
3114
        mov   [dlx],eax             ; save for drawlimits
3115
        mov   [dly],ebx
3116
        mov   [dlxe],ecx
3117
        mov   [dlye],edx
3118
        call  calculatescreen
3119
 
115 poddubny 3120
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3121
 
3122
        mov   eax,edi               ; redraw screen at old position
3123
        xor   esi,esi
3124
        call  redrawscreen
3125
 
3126
        mov   [0xfff5],byte 0 ; mouse pointer
3127
        mov   [0xfff4],byte 0 ; no mouse under
3128
        mov   [0xfb44],byte 0 ; react to mouse up/down
3129
 
3130
        mov   ecx,10          ; wait 1/10 second
3131
      .wmrl3:
3132
        call  [draw_pointer]
3133
        mov   eax,1
3134
        call  delay_hs
3135
        loop  .wmrl3
3136
 
3137
        mov   [window_move_pr],0
3138
 
3139
      .window_move_return:
3140
 
1 ha 3141
        ret
3142
 
67 diamond 3143
;type_background_1:
3144
;    cmp   [0xfff0],byte 0               ; background update ?
3145
;    jz    temp_nobackgr
3146
;    mov   [0xfff0],byte 2
3147
;    call  change_task
3148
;    mov   [draw_data+32+0],dword 0
3149
;    mov   [draw_data+32+4],dword 0
3150
;    mov   eax,[0xfe00]
3151
;    mov   ebx,[0xfe04]
3152
;    mov   [draw_data+32+8],eax
3153
;    mov   [draw_data+32+12],ebx
3154
;    call  drawbackground
3155
;    mov   [0xfff0],byte 0
3156
;    mov   [0xfff4],byte 0
3157
;temp_nobackgr:
3158
;    ret
41 mikedld 3159
 
1 ha 3160
uglobal
3161
  window_move_pr   dd  0x0
3162
  window_move_eax  dd  0x0
3163
  window_move_ebx  dd  0x0
3164
  window_move_ecx  dd  0x0
3165
  window_move_edx  dd  0x0
3166
endg
3167
 
3168
;ok - 100% work
3169
;nt - not tested
3170
;---------------------------------------------------------------------------------------------
3171
;eax
3172
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3173
;1 - change task. Ret nothing. Block. ok.
3174
;2 - performance control
3175
; ebx
3176
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3177
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3178
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3179
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3180
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3181
;eax
3182
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3183
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3184
;---------------------------------------------------------------------------------------------
3185
sys_sheduler: ;noname & halyavin
3186
    cmp eax,0
3187
    je shed_counter
3188
    cmp eax,2
3189
    je perf_control
3190
    cmp eax,3
3191
    je rdmsr_instr
3192
    cmp eax,4
3193
    je wrmsr_instr
3194
    cmp eax,1
3195
    jne not_supported
3196
    call change_task ;delay,0
3197
ret
3198
shed_counter:
3199
    mov eax,[context_counter]
3200
    mov [esp+36],eax
3201
not_supported:
3202
ret
3203
perf_control:
3204
    inc eax ;now eax=3
3205
    cmp ebx,eax
3206
    je cache_disable
3207
    dec eax
3208
    cmp ebx,eax
3209
    je cache_enable
3210
    dec eax
3211
    cmp ebx,eax
3212
    je is_cache_enabled
3213
    dec eax
3214
    cmp ebx,eax
3215
    je modify_pce
3216
ret
3217
 
3218
rdmsr_instr:
3219
;now counter in ecx
3220
;(edx:eax) esi:edi => edx:esi
3221
mov eax,esi
3222
rdmsr
3223
mov [esp+36],eax
3224
mov [esp+24],edx ;ret in ebx?
3225
ret
3226
 
3227
wrmsr_instr:
3228
;now counter in ecx
3229
;(edx:eax) esi:edi => edx:esi
3230
mov eax,esi
3231
wrmsr
3232
mov [esp+36],eax
3233
mov [esp+24],edx ;ret in ebx?
3234
ret
3235
 
3236
cache_disable:
3237
       mov eax,cr0
3238
       or  eax,01100000000000000000000000000000b
3239
       mov cr0,eax
3240
       wbinvd ;set MESI
3241
ret
3242
 
3243
cache_enable:
3244
       mov eax,cr0
3245
       and eax,10011111111111111111111111111111b
3246
       mov cr0,eax
3247
ret
3248
 
3249
is_cache_enabled:
3250
       mov eax,cr0
3251
       mov ebx,eax
3252
       and eax,01100000000000000000000000000000b
3253
       jz cache_disabled
3254
       mov [esp+36],ebx
3255
cache_disabled:
3256
       mov dword [esp+36],eax ;0
3257
ret
3258
 
3259
modify_pce:
3260
       mov eax,cr4
3261
;       mov ebx,0
3262
;       or  bx,100000000b ;pce
3263
;       xor eax,ebx ;invert pce
17 me_root 3264
       bts eax,8 ;pce=cr4[8]
1 ha 3265
       mov cr4,eax
3266
       mov [esp+36],eax
3267
ret
3268
;---------------------------------------------------------------------------------------------
3269
 
3270
 
3271
; check if pixel is allowed to be drawn
3272
 
3273
checkpixel:
21 poddubny 3274
        push eax edx
1 ha 3275
 
3276
        mov  edx,[0xfe00]     ; screen x size
3277
        inc  edx
21 poddubny 3278
        imul edx, ebx
1 ha 3279
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3280
 
21 poddubny 3281
        xor  ecx, ecx
105 poddubny 3282
        mov  eax, [0x3000]
3283
        cmp  al, dl
21 poddubny 3284
        setne cl
1 ha 3285
 
21 poddubny 3286
        pop  edx eax
1 ha 3287
        ret
3288
 
3289
uglobal
3290
  mouse_active  db  0
3291
endg
3292
iglobal
143 diamond 3293
  cpustring db '/RD/1/CPU',0
1 ha 3294
endg
3295
 
67 diamond 3296
uglobal
76 mario79 3297
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3298
endg
1 ha 3299
 
3300
align 4
3301
; check misc
3302
 
3303
checkmisc:
3304
 
3305
    cmp   [ctrl_alt_del], 1
3306
    jne   nocpustart
143 diamond 3307
    mov   ebp, cpustring
3308
    lea   esi,[ebp+6]
41 mikedld 3309
    xor   ebx,ebx               ; no parameters
40 halyavin 3310
    xor   edx,edx               ; no flags
143 diamond 3311
    call  fs_RamdiskExecute.flags
1 ha 3312
    mov   [ctrl_alt_del], 0
3313
  nocpustart:
3314
    cmp   [mouse_active], 1
3315
    jne   mouse_not_active
3316
    mov   [mouse_active], 0
3317
    xor   edi, edi
3318
    mov   ecx, [0x3004]
3319
   set_mouse_event:
3320
    add   edi, 256
115 poddubny 3321
    or    [edi+0x80000+APPDATA.event_mask], dword 00100000b
1 ha 3322
    loop  set_mouse_event
3323
  mouse_not_active:
3324
 
3325
 
3326
    cmp   [0xfff0],byte 0               ; background update ?
3327
    jz    nobackgr
76 mario79 3328
    cmp    [background_defined], 0
3329
    jz    nobackgr
1 ha 3330
    mov   [0xfff0],byte 2
3331
    call  change_task
164 serge 3332
	mov   [draw_data+32 + RECT.left],dword 0
3333
	mov   [draw_data+32 + RECT.top],dword 0
1 ha 3334
    mov   eax,[0xfe00]
3335
    mov   ebx,[0xfe04]
164 serge 3336
	mov   [draw_data+32 + RECT.right],eax
3337
	mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3338
    call  drawbackground
3339
    mov   [0xfff0],byte 0
3340
    mov   [0xfff4],byte 0
3341
 
3342
  nobackgr:
3343
 
3344
 
3345
    ; system shutdown request
3346
 
3347
    cmp  [0xFF00],byte 0
3348
    je   noshutdown
3349
 
3350
    mov  edx,[shutdown_processes]
3351
    sub  dl,2
3352
 
3353
    cmp  [0xff00],dl
3354
    jne  no_mark_system_shutdown
3355
 
3356
    mov   edx,0x3040
3357
    movzx ecx,byte [0xff00]
3358
    add   ecx,5
3359
  markz:
115 poddubny 3360
    mov   [edx+TASKDATA.state],byte 3
1 ha 3361
    add   edx,0x20
3362
    loop  markz
3363
 
3364
  no_mark_system_shutdown:
3365
 
3366
    call [disable_mouse]
3367
 
3368
    dec  byte [0xff00]
3369
 
3370
    cmp  [0xff00],byte 0
3371
    je   system_shutdown
3372
 
3373
  noshutdown:
3374
 
3375
 
3376
    mov   eax,[0x3004]                  ; termination
115 poddubny 3377
    mov   ebx,0x3020+TASKDATA.state
1 ha 3378
    mov   esi,1
3379
 
3380
  newct:
3381
    mov   cl,[ebx]
3382
    cmp   cl,byte 3
3383
    jz    terminate
3384
    cmp   cl,byte 4
3385
    jz    terminate
3386
 
3387
    add   ebx,0x20
3388
    inc   esi
3389
    dec   eax
3390
    jnz   newct
3391
 
3392
    ret
3393
 
3394
 
3395
 
3396
 
3397
; redraw screen
3398
 
3399
redrawscreen:
3400
 
3401
; eax , if process window_data base is eax, do not set flag/limits
3402
 
3403
         pushad
3404
         push  eax
3405
 
3406
;;;         mov   eax,2
3407
;;;         call  delay_hs
3408
 
3409
         ;mov   ecx,0               ; redraw flags for apps
3410
         xor   ecx,ecx
3411
       newdw2:
3412
 
3413
         inc   ecx
3414
         push  ecx
3415
 
3416
         mov   eax,ecx
3417
         shl   eax,5
3418
         add   eax,window_data
3419
 
3420
         cmp   eax,[esp+4]
3421
         je    not_this_task
3422
                                   ; check if window in redraw area
3423
         mov   edi,eax
3424
 
3425
         cmp   ecx,1               ; limit for background
3426
         jz    bgli
3427
 
115 poddubny 3428
         mov   eax, [edi + WDATA.box.left]
3429
         mov   ebx, [edi + WDATA.box.top]
3430
         mov   ecx, [edi + WDATA.box.width]
3431
         mov   edx, [edi + WDATA.box.height]
164 serge 3432
         add   ecx,eax
3433
         add   edx,ebx
1 ha 3434
 
3435
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3436
         cmp   ecx,ebx
3437
         jb    ricino
3438
 
3439
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3440
         cmp   ecx,eax
3441
         jb    ricino
3442
 
115 poddubny 3443
         mov   eax, [edi + WDATA.box.left]
3444
         mov   ebx, [edi + WDATA.box.top]
3445
         mov   ecx, [edi + WDATA.box.width]
3446
         mov   edx, [edi + WDATA.box.height]
3447
         add   ecx, eax
3448
         add   edx, ebx
164 serge 3449
 
1 ha 3450
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3451
         cmp   edx,eax
3452
         jb    ricino
3453
 
3454
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3455
         cmp   ecx,eax
3456
         jb    ricino
3457
 
3458
        bgli:
3459
 
3460
         cmp   edi,esi
3461
         jz    ricino
3462
 
3463
         mov   eax,edi
3464
         add   eax,draw_data-window_data
3465
 
3466
         mov   ebx,[dlx]          ; set limits
115 poddubny 3467
         mov   [eax + RECT.left], ebx
1 ha 3468
         mov   ebx,[dly]
115 poddubny 3469
         mov   [eax + RECT.top], ebx
1 ha 3470
         mov   ebx,[dlxe]
115 poddubny 3471
         mov   [eax + RECT.right], ebx
1 ha 3472
         mov   ebx,[dlye]
115 poddubny 3473
         mov   [eax + RECT.bottom], ebx
1 ha 3474
 
3475
         sub   eax,draw_data-window_data
3476
 
3477
         cmp   ecx,1
3478
         jne   nobgrd
3479
         cmp   esi,1
3480
         je    newdw8
3481
         call  drawbackground
3482
 
3483
       newdw8:
3484
       nobgrd:
3485
 
115 poddubny 3486
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3487
 
3488
       ricino:
3489
 
3490
       not_this_task:
3491
 
3492
         pop   ecx
3493
 
3494
         cmp   ecx,[0x3004]
3495
         jle   newdw2
3496
 
3497
         pop  eax
3498
         popad
3499
 
3500
         ret
3501
 
3502
calculatebackground:   ; background
3503
 
3504
        ; all black
3505
 
3506
        mov   [display_data-8],dword 4      ; size x
3507
        mov   [display_data-4],dword 2      ; size y
3508
 
3509
        mov   edi, 0x300000                 ; set background to black
3510
        xor   eax, eax
3511
        mov   ecx, 0x0fff00 / 4
3512
        cld
3513
        rep   stosd
3514
 
3515
        mov   edi,display_data              ; set os to use all pixels
3516
        mov   eax,0x01010101
3517
        mov   ecx,0x1fff00 / 4
3518
        rep   stosd
3519
 
3520
        mov   byte [0xFFF0], 0              ; do not draw background!
3521
 
3522
        ret
3523
 
3524
uglobal
3525
  imax    dd 0x0
3526
endg
3527
 
3528
 
3529
 
3530
delay_ms:     ; delay in 1/1000 sec
3531
 
3532
 
3533
        push  eax
3534
        push  ecx
3535
 
3536
        mov   ecx,esi
3537
        ; 
3538
        imul  ecx, 33941
3539
        shr   ecx, 9
3540
        ; 
3541
 
3542
        in    al,0x61
3543
        and   al,0x10
3544
        mov   ah,al
3545
        cld
3546
 
3547
 cnt1:  in    al,0x61
3548
        and   al,0x10
3549
        cmp   al,ah
3550
        jz    cnt1
3551
 
3552
        mov   ah,al
3553
        loop  cnt1
3554
 
3555
        pop   ecx
3556
        pop   eax
3557
 
3558
        ret
3559
 
3560
 
3561
set_app_param:
3562
        push edi
3563
 
3564
        mov  edi,[0x3010]
115 poddubny 3565
        mov  [edi+TASKDATA.event_mask],eax
1 ha 3566
 
3567
        pop  edi
3568
        ret
3569
 
3570
 
3571
 
3572
delay_hs:     ; delay in 1/100 secs
3573
        push  eax
3574
        push  ecx
3575
        push  edx
3576
 
115 poddubny 3577
        mov   edx,[timer_ticks]
1 ha 3578
        add   edx,eax
3579
 
3580
      newtic:
115 poddubny 3581
        mov   ecx,[timer_ticks]
1 ha 3582
        cmp   edx,ecx
3583
        jbe   zerodelay
3584
 
3585
        call  change_task
3586
 
3587
        jmp   newtic
3588
 
3589
      zerodelay:
3590
        pop   edx
3591
        pop   ecx
3592
        pop   eax
3593
 
3594
        ret
3595
 
3596
 
3597
memmove:       ; memory move in bytes
3598
 
3599
; eax = from
3600
; ebx = to
3601
; ecx = no of bytes
3602
    test ecx, ecx
3603
    jle  .ret
3604
 
3605
 
3606
    push esi edi ecx
3607
 
3608
    mov  edi, ebx
3609
    mov  esi, eax
3610
 
3611
    test ecx, not 11b
3612
    jz   @f
3613
 
3614
    push ecx
3615
    shr  ecx, 2
3616
    rep  movsd
3617
    pop  ecx
3618
    and  ecx, 11b
3619
    jz   .finish
3620
  @@:
3621
    rep  movsb
3622
 
3623
  .finish:
3624
    pop  ecx edi esi
3625
  .ret:
3626
    ret
3627
 
3628
 
75 diamond 3629
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3630
;align 4
1 ha 3631
;
75 diamond 3632
;read_floppy_file:
1 ha 3633
;
75 diamond 3634
;; as input
3635
;;
3636
;; eax pointer to file
3637
;; ebx file lenght
3638
;; ecx start 512 byte block number
3639
;; edx number of blocks to read
3640
;; esi pointer to return/work area (atleast 20 000 bytes)
3641
;;
3642
;;
3643
;; on return
3644
;;
3645
;; eax = 0 command succesful
3646
;;       1 no fd base and/or partition defined
3647
;;       2 yet unsupported FS
3648
;;       3 unknown FS
3649
;;       4 partition not defined at hd
3650
;;       5 file not found
3651
;; ebx = size of file
1 ha 3652
;
75 diamond 3653
;     mov   edi,[0x3010]
3654
;     add   edi,0x10
3655
;     add   esi,[edi]
3656
;     add   eax,[edi]
1 ha 3657
;
75 diamond 3658
;     pushad
3659
;     mov  edi,esi
3660
;     add  edi,1024
3661
;     mov  esi,0x100000+19*512
3662
;     sub  ecx,1
3663
;     shl  ecx,9
3664
;     add  esi,ecx
3665
;     shl  edx,9
3666
;     mov  ecx,edx
3667
;     cld
3668
;     rep  movsb
3669
;     popad
3670
;
3671
;     mov   [esp+36],eax
3672
;     mov   [esp+24],ebx
3673
;     ret
1 ha 3674
 
3675
 
3676
 
3677
align 4
3678
 
3679
sys_programirq:
3680
 
3681
    mov   edi,[0x3010]
115 poddubny 3682
    add   eax,[edi+TASKDATA.mem_start]
1 ha 3683
 
75 diamond 3684
    cmp   ebx,16
3685
    jae   .not_owner
1 ha 3686
    mov   edi,[0x3010]
115 poddubny 3687
    mov   edi,[edi+TASKDATA.pid]
75 diamond 3688
    cmp   edi,[irq_owner+ebx*4]
1 ha 3689
    je    spril1
75 diamond 3690
.not_owner:
1 ha 3691
    mov   [esp+36],dword 1
3692
    ret
3693
  spril1:
3694
 
3695
    mov   esi,eax
3696
    shl   ebx,6
3697
    add   ebx,irq00read
3698
    mov   edi,ebx
3699
    mov   ecx,16
3700
    cld
3701
    rep   movsd
3702
    mov   [esp+36],dword 0
3703
    ret
3704
 
3705
 
3706
align 4
3707
 
3708
get_irq_data:
75 diamond 3709
     cmp   eax,16
3710
     jae   .not_owner
1 ha 3711
     mov   edx,eax           ; check for correct owner
3712
     shl   edx,2
3713
     add   edx,irq_owner
3714
     mov   edx,[edx]
3715
     mov   edi,[0x3010]
115 poddubny 3716
     mov   edi,[edi+TASKDATA.pid]
1 ha 3717
     cmp   edx,edi
3718
     je    gidril1
75 diamond 3719
.not_owner:
3720
     mov   [esp+32],dword 2     ; ecx=2
1 ha 3721
     ret
3722
 
3723
  gidril1:
3724
 
3725
     mov   ebx,eax
3726
     shl   ebx,12
3727
     add   ebx,0x2e0000
3728
     mov   eax,[ebx]
3729
     mov   ecx,1
3730
     test  eax,eax
3731
     jz    gid1
3732
 
3733
     dec   eax
3734
     mov   esi,ebx
3735
     mov   [ebx],eax
3736
     movzx ebx,byte [ebx+0x10]
3737
     add   esi,0x10
3738
     mov   edi,esi
3739
     inc   esi
3740
     mov   ecx,4000 / 4
3741
     cld
3742
     rep   movsd
75 diamond 3743
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
1 ha 3744
   gid1:
3745
     mov   [esp+36],eax
3746
     mov   [esp+32],ecx
3747
     mov   [esp+24],ebx
3748
     ret
3749
 
3750
 
3751
set_io_access_rights:
3752
 
3753
     pushad
3754
 
3755
     mov   edi,[0x3000]
3756
     imul  edi,tss_step
3757
     add   edi,tss_data+128
3758
;     add   edi,128
3759
 
3760
     mov   ecx,eax
3761
     and   ecx,7    ; offset in byte
3762
 
3763
     shr   eax,3    ; number of byte
3764
     add   edi,eax
3765
 
3766
     mov   ebx,1
3767
     shl   ebx,cl
3768
 
3769
     cmp   ebp,0                ; enable access - ebp = 0
3770
     jne   siar1
3771
 
3772
     not   ebx
3773
     and   [edi],byte bl
3774
 
3775
     popad
3776
 
3777
     ret
3778
 
3779
   siar1:
3780
 
3781
     or    [edi],byte bl        ; disable access - ebp = 1
3782
 
3783
     popad
3784
 
3785
     ret
3786
 
3787
 
3788
 
3789
 
3790
 
3791
r_f_port_area:
3792
 
3793
     test  eax, eax
3794
     jnz   free_port_area
3795
;     je    r_port_area
3796
;     jmp   free_port_area
3797
 
3798
;   r_port_area:
3799
 
3800
     pushad
3801
 
3802
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 3803
     ja    rpal1
3804
     cmp   ecx,65536
3805
     jae   rpal1
1 ha 3806
     mov   esi,[0x2d0000]
75 diamond 3807
     test  esi,esi            ; no reserved areas ?
1 ha 3808
     je    rpal2
3809
     cmp   esi,255            ; max reserved
75 diamond 3810
     jae   rpal1
1 ha 3811
   rpal3:
3812
     mov   edi,esi
3813
     shl   edi,4
3814
     add   edi,0x2d0000
3815
     cmp   ebx,[edi+8]
75 diamond 3816
     ja    rpal4
1 ha 3817
     cmp   ecx,[edi+4]
3818
     jae   rpal1
3819
;     jb    rpal4
3820
;     jmp   rpal1
3821
   rpal4:
3822
 
3823
     dec   esi
3824
     jnz   rpal3
3825
     jmp   rpal2
3826
   rpal1:
3827
     popad
3828
     mov   eax,1
3829
     ret
3830
 
3831
   rpal2:
3832
     popad
3833
 
3834
 
3835
     ; enable port access at port IO map
3836
     cli
3837
     pushad                        ; start enable io map
3838
 
3839
     cmp   ecx,65536 ;16384
3840
     jae   no_unmask_io ; jge
3841
 
3842
     mov   eax,ebx
3843
 
3844
   new_port_access:
3845
 
3846
     pushad
3847
 
75 diamond 3848
     xor   ebp,ebp                ; enable - eax = port
1 ha 3849
     call  set_io_access_rights
3850
 
3851
     popad
3852
 
3853
     inc   eax
3854
     cmp   eax,ecx
3855
     jbe   new_port_access
3856
 
3857
   no_unmask_io:
3858
 
3859
     popad                         ; end enable io map
3860
     sti
3861
 
3862
     mov   edi,[0x2d0000]
3863
     add   edi,1
3864
     mov   [0x2d0000],edi
3865
     shl   edi,4
3866
     add   edi,0x2d0000
3867
     mov   esi,[0x3010]
115 poddubny 3868
     mov   esi,[esi+TASKDATA.pid]
1 ha 3869
     mov   [edi],esi
3870
     mov   [edi+4],ebx
3871
     mov   [edi+8],ecx
3872
 
3873
     xor   eax, eax
3874
     ret
3875
 
3876
 
3877
 
3878
 
3879
free_port_area:
3880
 
3881
     pushad
3882
 
3883
     mov   esi,[0x2d0000]     ; no reserved areas ?
75 diamond 3884
     test  esi,esi
1 ha 3885
     je    frpal2
3886
     mov   edx,[0x3010]
115 poddubny 3887
     mov   edx,[edx+TASKDATA.pid]
1 ha 3888
   frpal3:
3889
     mov   edi,esi
3890
     shl   edi,4
3891
     add   edi,0x2d0000
3892
     cmp   edx,[edi]
3893
     jne   frpal4
3894
     cmp   ebx,[edi+4]
3895
     jne   frpal4
3896
     cmp   ecx,[edi+8]
3897
     jne   frpal4
3898
     jmp   frpal1
3899
   frpal4:
3900
     dec   esi
3901
     jnz   frpal3
3902
   frpal2:
3903
     popad
3904
     mov   eax,1
3905
     ret
3906
   frpal1:
3907
     mov   ecx,256
3908
     sub   ecx,esi
3909
     shl   ecx,4
3910
     mov   esi,edi
3911
     add   esi,16
3912
     cld
3913
     rep   movsb
3914
 
3915
     dec   dword [0x2d0000]
3916
 
3917
     popad
3918
 
3919
 
3920
     ; disable port access at port IO map
3921
 
3922
     pushad                        ; start disable io map
3923
 
3924
     cmp   ecx,65536 ;16384
3925
     jge   no_mask_io
3926
 
3927
     mov   eax,ebx
3928
 
3929
   new_port_access_disable:
3930
 
3931
     pushad
3932
 
3933
     mov   ebp,1                  ; disable - eax = port
3934
     call  set_io_access_rights
3935
 
3936
     popad
3937
 
3938
     inc   eax
3939
     cmp   eax,ecx
3940
     jbe   new_port_access_disable
3941
 
3942
   no_mask_io:
3943
 
3944
     popad                         ; end disable io map
3945
 
3946
     xor   eax, eax
3947
     ret
3948
 
3949
 
3950
reserve_free_irq:
3951
 
75 diamond 3952
     mov   ecx, 1
3953
     cmp   ebx, 16
3954
     jae   fril1
3955
     test  eax,eax
1 ha 3956
     jz    reserve_irq
3957
 
75 diamond 3958
     lea   edi,[irq_owner+ebx*4]
1 ha 3959
     mov   edx,[edi]
3960
     mov   eax,[0x3010]
115 poddubny 3961
     cmp   edx,[eax+TASKDATA.pid]
1 ha 3962
     jne   fril1
75 diamond 3963
     dec   ecx
3964
     mov   [edi],ecx
1 ha 3965
   fril1:
3966
     mov   [esp+36],ecx ; return in eax
3967
     ret
3968
 
3969
  reserve_irq:
3970
 
75 diamond 3971
     lea   edi,[irq_owner+ebx*4]
3972
     cmp   dword [edi], 0
3973
     jnz   ril1
1 ha 3974
 
3975
     mov   edx,[0x3010]
115 poddubny 3976
     mov   edx,[edx+TASKDATA.pid]
1 ha 3977
     mov   [edi],edx
75 diamond 3978
     dec   ecx
1 ha 3979
   ril1:
3980
     mov   [esp+36],ecx ; return in eax
3981
     ret
3982
 
3983
 
3984
 
3985
drawbackground:
33 mario79 3986
       inc   [mouse_pause]
1 ha 3987
       cmp   [0xfe0c],word 0x12
117 mario79 3988
       je   dbrv20
1 ha 3989
     dbrv12:
3990
       cmp  [0xfe0c],word 0100000000000000b
3991
       jge  dbrv20
3992
       cmp  [0xfe0c],word 0x13
3993
       je   dbrv20
3994
       call  vesa12_drawbackground
33 mario79 3995
       dec   [mouse_pause]
36 mario79 3996
       call   [draw_pointer]
1 ha 3997
       ret
3998
     dbrv20:
3999
       cmp   [display_data-12],dword 1
4000
       jne   bgrstr
4001
       call  vesa20_drawbackground_tiled
33 mario79 4002
       dec   [mouse_pause]
36 mario79 4003
       call   [draw_pointer]
1 ha 4004
       ret
4005
     bgrstr:
4006
       call  vesa20_drawbackground_stretch
33 mario79 4007
       dec   [mouse_pause]
36 mario79 4008
       call   [draw_pointer]
1 ha 4009
       ret
4010
 
75 diamond 4011
align 4
1 ha 4012
 
75 diamond 4013
syscall_putimage:                       ; PutImage
33 mario79 4014
 
75 diamond 4015
     mov   edx,ecx
4016
     mov   ecx,ebx
4017
        lea     ebx, [eax+std_application_base_address]
4018
 
1 ha 4019
sys_putimage:
53 mikedld 4020
     test  ecx,0x80008000
4021
     jnz   .exit
4022
     test  ecx,0x0000FFFF
4023
     jz    .exit
4024
     test  ecx,0xFFFF0000
4025
     jnz   @f
4026
  .exit:
4027
     ret
4028
 @@:
114 mikedld 4029
        mov     edi,[0x3000]
4030
        shl     edi,8
4031
        add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.top]
4032
        rol     edx,16
4033
        add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.left]
4034
        rol     edx,16
4035
  .forced:
117 mario79 4036
;        mov     eax, vga_putimage
75 diamond 4037
        cmp     [0xfe0c], word 0x12
117 mario79 4038
        jz      @f   ;.doit
75 diamond 4039
        mov     eax, vesa12_putimage
4040
        cmp     [0xfe0c], word 0100000000000000b
4041
        jae     @f
4042
        cmp     [0xfe0c], word 0x13
4043
        jnz     .doit
4044
@@:
4045
        mov     eax, vesa20_putimage
4046
.doit:
119 mario79 4047
        inc     [mouse_pause]
75 diamond 4048
        call    eax
119 mario79 4049
        dec     [mouse_pause]
75 diamond 4050
        jmp     [draw_pointer]
1 ha 4051
 
4052
; eax x beginning
4053
; ebx y beginning
4054
; ecx x end
4055
; edx y end
4056
; edi color
4057
 
4058
__sys_drawbar:
114 mikedld 4059
        mov     esi,[0x3000]
4060
        shl     esi,8
4061
        add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
4062
        add     ecx,[esi+0x80000+APPDATA.wnd_clientbox.left]
4063
        add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
4064
        add     edx,[esi+0x80000+APPDATA.wnd_clientbox.top]
4065
  .forced:
33 mario79 4066
    inc   [mouse_pause]
4067
    cmp   [0xfe0c],word 0x12
117 mario79 4068
    je   dbv20
1 ha 4069
   sdbv20:
4070
    cmp  [0xfe0c],word 0100000000000000b
4071
    jge  dbv20
4072
    cmp  [0xfe0c],word 0x13
4073
    je   dbv20
4074
    call vesa12_drawbar
33 mario79 4075
    dec   [mouse_pause]
36 mario79 4076
    call   [draw_pointer]
1 ha 4077
    ret
4078
  dbv20:
4079
    call vesa20_drawbar
33 mario79 4080
    dec   [mouse_pause]
36 mario79 4081
    call   [draw_pointer]
1 ha 4082
    ret
4083
 
4084
 
4085
 
4086
kb_read:
4087
 
4088
        push    ecx edx
4089
 
164 serge 4090
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4091
      kr_loop:
4092
        in      al,0x64
4093
        test    al,1
4094
        jnz     kr_ready
4095
        loop    kr_loop
4096
        mov     ah,1
4097
        jmp     kr_exit
4098
      kr_ready:
4099
        push    ecx
4100
        mov     ecx,32
4101
      kr_delay:
4102
        loop    kr_delay
4103
        pop     ecx
4104
        in      al,0x60
4105
        xor     ah,ah
4106
      kr_exit:
4107
 
4108
        pop     edx ecx
4109
 
4110
        ret
4111
 
4112
 
4113
kb_write:
4114
 
4115
        push    ecx edx
4116
 
4117
        mov     dl,al
98 mario79 4118
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4119
      kw_loop1:
4120
        in      al,0x64
4121
        test    al,0x20
4122
        jz      kw_ok1
4123
        loop    kw_loop1
4124
        mov     ah,1
4125
        jmp     kw_exit
4126
      kw_ok1:
4127
        in      al,0x60
98 mario79 4128
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4129
      kw_loop:
4130
        in      al,0x64
4131
        test    al,2
4132
        jz      kw_ok
4133
        loop    kw_loop
4134
        mov     ah,1
4135
        jmp     kw_exit
4136
      kw_ok:
4137
        mov     al,dl
4138
        out     0x60,al
98 mario79 4139
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4140
      kw_loop3:
4141
        in      al,0x64
4142
        test    al,2
4143
        jz      kw_ok3
4144
        loop    kw_loop3
4145
        mov     ah,1
4146
        jmp     kw_exit
4147
      kw_ok3:
4148
        mov     ah,8
4149
      kw_loop4:
98 mario79 4150
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4151
      kw_loop5:
4152
        in      al,0x64
4153
        test    al,1
4154
        jnz     kw_ok4
4155
        loop    kw_loop5
4156
        dec     ah
4157
        jnz     kw_loop4
4158
      kw_ok4:
4159
        xor     ah,ah
4160
      kw_exit:
4161
 
4162
        pop     edx ecx
4163
 
4164
        ret
4165
 
4166
 
4167
kb_cmd:
4168
 
98 mario79 4169
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4170
      c_wait:
4171
        in      al,0x64
4172
        test    al,2
4173
        jz      c_send
4174
        loop    c_wait
4175
        jmp     c_error
4176
      c_send:
4177
        mov     al,bl
4178
        out     0x64,al
98 mario79 4179
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4180
      c_accept:
4181
        in      al,0x64
4182
        test    al,2
4183
        jz      c_ok
4184
        loop    c_accept
4185
      c_error:
4186
        mov     ah,1
4187
        jmp     c_exit
4188
      c_ok:
4189
        xor     ah,ah
4190
      c_exit:
4191
        ret
4192
 
4193
 
4194
setmouse:  ; set mousepicture -pointer
4195
           ; ps2 mouse enable
4196
 
4197
     mov     [0xf200],dword mousepointer
4198
 
4199
     cli
33 mario79 4200
;     mov     bl,0xa8                 ; enable mouse cmd
4201
;     call    kb_cmd
4202
;     call    kb_read                 ; read status
4203
;     mov     bl,0x20                 ; get command byte
4204
;     call    kb_cmd
4205
;     call    kb_read
4206
;     or      al,3                    ; enable interrupt
4207
;     mov     bl,0x60                 ; write command
4208
;     push    eax
4209
;     call    kb_cmd
4210
;     pop     eax
4211
;     call    kb_write
4212
;     mov     bl,0xd4                 ; for mouse
4213
;     call    kb_cmd
4214
;     mov     al,0xf4                 ; enable mouse device
4215
;     call    kb_write
4216
;     call    kb_read           ; read status return
1 ha 4217
 
4218
     ; com1 mouse enable
4219
 
4220
     mov   bx,0x3f8 ; combase
4221
 
4222
     mov   dx,bx
4223
     add   dx,3
4224
     mov   al,0x80
4225
     out   dx,al
4226
 
4227
     mov   dx,bx
4228
     add   dx,1
4229
     mov   al,0
4230
     out   dx,al
4231
 
4232
     mov   dx,bx
4233
     add   dx,0
4234
     mov   al,0x30*2    ; 0x30 / 4
4235
     out   dx,al
4236
 
4237
     mov   dx,bx
4238
     add   dx,3
4239
     mov   al,2         ; 3
4240
     out   dx,al
4241
 
4242
     mov   dx,bx
4243
     add   dx,4
4244
     mov   al,0xb
4245
     out   dx,al
4246
 
4247
     mov   dx,bx
4248
     add   dx,1
4249
     mov   al,1
4250
     out   dx,al
4251
 
4252
 
4253
     ; com2 mouse enable
4254
 
4255
     mov   bx,0x2f8 ; combase
4256
 
4257
     mov   dx,bx
4258
     add   dx,3
4259
     mov   al,0x80
4260
     out   dx,al
4261
 
4262
     mov   dx,bx
4263
     add   dx,1
4264
     mov   al,0
4265
     out   dx,al
4266
 
4267
     mov   dx,bx
4268
     add   dx,0
4269
     mov   al,0x30*2
4270
     out   dx,al
4271
 
4272
     mov   dx,bx
4273
     add   dx,3
4274
     mov   al,2
4275
     out   dx,al
4276
 
4277
     mov   dx,bx
4278
     add   dx,4
4279
     mov   al,0xb
4280
     out   dx,al
4281
 
4282
     mov   dx,bx
4283
     add   dx,1
4284
     mov   al,1
4285
     out   dx,al
4286
 
4287
     ret
4288
 
4289
 
4290
_rdtsc:
164 serge 4291
     bt [cpu_caps], CAPS_TSC
4292
     jnc ret_rdtsc
1 ha 4293
     rdtsc
4294
     ret
4295
   ret_rdtsc:
4296
     mov   edx,0xffffffff
4297
     mov   eax,0xffffffff
4298
     ret
4299
 
4300
 
4301
 
4302
rerouteirqs:
4303
 
4304
        cli
4305
 
4306
        mov     al,0x11         ;  icw4, edge triggered
4307
        out     0x20,al
4308
        call    pic_delay
4309
        out     0xA0,al
4310
        call    pic_delay
4311
 
4312
        mov     al,0x20         ;  generate 0x20 +
4313
        out     0x21,al
4314
        call    pic_delay
4315
        mov     al,0x28         ;  generate 0x28 +
4316
        out     0xA1,al
4317
        call    pic_delay
4318
 
4319
        mov     al,0x04         ;  slave at irq2
4320
        out     0x21,al
4321
        call    pic_delay
4322
        mov     al,0x02         ;  at irq9
4323
        out     0xA1,al
4324
        call    pic_delay
4325
 
4326
        mov     al,0x01         ;  8086 mode
4327
        out     0x21,al
4328
        call    pic_delay
4329
        out     0xA1,al
4330
        call    pic_delay
4331
 
4332
        mov     al,255          ; mask all irq's
4333
        out     0xA1,al
4334
        call    pic_delay
4335
        out     0x21,al
4336
        call    pic_delay
4337
 
4338
        mov     ecx,0x1000
4339
        cld
4340
picl1:  call    pic_delay
4341
        loop    picl1
4342
 
4343
        mov     al,255          ; mask all irq's
4344
        out     0xA1,al
4345
        call    pic_delay
4346
        out     0x21,al
4347
        call    pic_delay
4348
 
4349
        cli
4350
 
4351
        ret
4352
 
4353
 
4354
pic_delay:
4355
 
4356
        jmp     pdl1
4357
pdl1:   ret
4358
 
4359
 
4360
sys_msg_board_str:
4361
 
4362
     pushad
4363
   @@:
4364
     cmp    [esi],byte 0
4365
     je     @f
4366
     mov    eax,1
4367
     movzx  ebx,byte [esi]
4368
     call   sys_msg_board
4369
     inc    esi
4370
     jmp    @b
4371
   @@:
4372
     popad
4373
     ret
4374
 
4375
uglobal
4376
  msg_board_data: times 512 db 0
4377
  msg_board_count dd 0x0
4378
endg
4379
 
4380
sys_msg_board:
4381
 
4382
; eax=1 : write :  bl byte to write
4383
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4384
 
4385
     mov  ecx,[msg_board_count]
4386
     cmp  eax, 1
4387
     jne  smbl1
4388
 
4389
 
4390
     mov  [msg_board_data+ecx],bl
4391
     inc  ecx
4392
     and  ecx, 511
4393
     mov  [msg_board_count], ecx
4394
     mov  [check_idle_semaphore], 5
4395
     ret
4396
   smbl1:
4397
 
4398
     cmp   eax, 2
4399
     jne   smbl2
4400
     test  ecx, ecx
4401
     jz    smbl21
4402
;     mov   edi, msg_board_data
4403
;     mov   esi, msg_board_data+1
4404
;     movzx eax, byte [edi]
4405
     mov   eax, msg_board_data+1
4406
     mov   ebx, msg_board_data
4407
     movzx edx, byte [ebx]
4408
     call  memmove
4409
;     push  ecx
4410
;     shr   ecx, 2
4411
;     cld
4412
;     rep   movsd
4413
;     pop   ecx
4414
;     and   ecx, 3
4415
;     rep   movsb
4416
     dec   [msg_board_count]
4417
     mov   [esp+36], edx ;eax
4418
     mov   [esp+24], dword 1
4419
     ret
4420
   smbl21:
4421
     mov   [esp+36], ecx
4422
     mov   [esp+24], ecx
4423
 
4424
   smbl2:
4425
     ret
4426
 
4427
 
4428
 
4429
sys_trace:
4430
 
4431
     test eax, eax                  ; get event data
4432
     jnz  no_get_sys_events
4433
 
4434
     mov  esi,save_syscall_data     ; data
4435
     mov  edi,[0x3010]
115 poddubny 4436
     mov  edi,[edi+TASKDATA.mem_start]
1 ha 4437
     add  edi,ebx
4438
     cld
4439
     rep  movsb
4440
 
4441
     mov  [esp+24],dword 0
4442
     mov  eax,[save_syscall_count]  ; count
4443
     mov  [esp+36],eax
4444
     ret
4445
 
4446
   no_get_sys_events:
4447
 
4448
     ret
4449
 
4450
 
4451
sys_process_def:
92 diamond 4452
        mov     edi, [0x3000]
1 ha 4453
 
92 diamond 4454
        dec     eax             ; 1 = set keyboard mode
1 ha 4455
     jne   no_set_keyboard_setup
4456
 
4457
     shl   edi,8
115 poddubny 4458
     mov   [edi+0x80000 + APPDATA.keyboard_mode],bl
1 ha 4459
 
4460
     ret
4461
 
4462
   no_set_keyboard_setup:
4463
 
92 diamond 4464
        dec     eax             ; 2 = get keyboard mode
1 ha 4465
     jne   no_get_keyboard_setup
4466
 
4467
     shl   edi,8
115 poddubny 4468
     movzx eax, byte [0x80000+edi + APPDATA.keyboard_mode]
1 ha 4469
 
4470
     mov   [esp+36],eax
4471
 
4472
     ret
4473
 
4474
   no_get_keyboard_setup:
4475
 
92 diamond 4476
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4477
     jne   no_get_keyboard_cas
4478
 
4479
;     xor   eax,eax
4480
;     movzx eax,byte [shift]
4481
;     movzx ebx,byte [ctrl]
4482
;     shl   ebx,2
4483
;     add   eax,ebx
4484
;     movzx ebx,byte [alt]
4485
;     shl   ebx,3
4486
;     add   eax,ebx
4487
 
4488
 ;// mike.dld [
4489
     mov   eax, [kb_state]
4490
 ;// mike.dld ]
4491
 
4492
     mov   [esp+36],eax
4493
 
4494
     ret
4495
 
4496
   no_get_keyboard_cas:
4497
 
92 diamond 4498
        dec     eax
4499
        jnz     no_add_keyboard_hotkey
1 ha 4500
 
92 diamond 4501
        mov     eax, hotkey_list
4502
@@:
4503
        cmp     dword [eax+8], 0
4504
        jz      .found_free
4505
        add     eax, 16
4506
        cmp     eax, hotkey_list+16*256
4507
        jb      @b
4508
        mov     dword [esp+36], 1
4509
        ret
4510
.found_free:
4511
        mov     [eax+8], edi
4512
        mov     [eax+4], ecx
4513
        movzx   ebx, bl
4514
        lea     ebx, [hotkey_scancodes+ebx*4]
4515
        mov     ecx, [ebx]
4516
        mov     [eax], ecx
4517
        mov     [ebx], eax
4518
        mov     [eax+12], ebx
4519
        jecxz   @f
4520
        mov     [ecx+12], eax
4521
@@:
4522
        and     dword [esp+36], 0
4523
        ret
4524
 
4525
no_add_keyboard_hotkey:
4526
 
4527
        dec     eax
4528
        jnz     no_del_keyboard_hotkey
4529
 
4530
        movzx   ebx, bl
4531
        lea     ebx, [hotkey_scancodes+ebx*4]
4532
        mov     eax, [ebx]
4533
.scan:
4534
        test    eax, eax
4535
        jz      .notfound
4536
        cmp     [eax+8], edi
4537
        jnz     .next
4538
        cmp     [eax+4], ecx
4539
        jz      .found
4540
.next:
4541
        mov     eax, [eax]
4542
        jmp     .scan
4543
.notfound:
4544
        mov     dword [esp+36], 1
4545
        ret
4546
.found:
4547
        mov     ecx, [eax]
4548
        jecxz   @f
4549
        mov     edx, [eax+12]
4550
        mov     [ecx+12], edx
4551
@@:
4552
        mov     ecx, [eax+12]
4553
        mov     edx, [eax]
4554
        mov     [ecx], edx
4555
        xor     edx, edx
4556
        mov     [eax+4], edx
4557
        mov     [eax+8], edx
4558
        mov     [eax+12], edx
4559
        mov     [eax], edx
4560
        mov     [esp+36], edx
4561
        ret
4562
 
4563
no_del_keyboard_hotkey:
1 ha 4564
     ret
4565
 
4566
 
4567
align 4
4568
 
4569
sys_gs:                         ; direct screen access
4570
 
4571
     cmp  eax,1                 ; resolution
4572
     jne  no_gs1
4573
     mov  eax,[0xfe00]
4574
     shl  eax,16
4575
     mov  ax,[0xfe04]
4576
     add  eax,0x00010001
4577
     mov  [esp+36],eax
4578
     ret
4579
   no_gs1:
4580
 
4581
     cmp   eax,2                ; bits per pixel
4582
     jne   no_gs2
4583
     movzx eax,byte [0xfbf1]
4584
     mov   [esp+36],eax
4585
     ret
4586
   no_gs2:
4587
 
4588
     cmp   eax,3                ; bytes per scanline
4589
     jne   no_gs3
4590
     mov   eax,[0xfe08]
4591
     mov   [esp+36],eax
4592
     ret
4593
   no_gs3:
4594
 
4595
     mov  [esp+36],dword -1
4596
     ret
4597
 
4598
 
4599
align 4 ; PCI functions
4600
 
4601
sys_pci:
4602
 
4603
     call  pci_api
4604
     mov   [esp+36],eax
4605
     ret
4606
 
4607
 
4608
align 4  ;  system functions
4609
 
4610
syscall_setpixel:                       ; SetPixel
4611
 
4612
 
4613
     mov   edx,[0x3010]
115 poddubny 4614
     add   eax,[edx-twdw+WDATA.box.left]
4615
     add   ebx,[edx-twdw+WDATA.box.top]
114 mikedld 4616
        mov     edi,[0x3000]
4617
        shl     edi,8
4618
        add     eax,[edi+0x80000+APPDATA.wnd_clientbox.left]
4619
        add     ebx,[edi+0x80000+APPDATA.wnd_clientbox.top]
112 poddubny 4620
     xor   edi,edi ; no force
114 mikedld 4621
;     mov   edi,1
112 poddubny 4622
     call  [disable_mouse]
1 ha 4623
     jmp   [putpixel]
4624
 
4625
align 4
4626
 
4627
syscall_writetext:                      ; WriteText
4628
 
4629
     mov   edi,[0x3010]
115 poddubny 4630
     mov   ebp,[edi-twdw+WDATA.box.left]
139 diamond 4631
        push    esi
114 mikedld 4632
        mov     esi,[0x3000]
4633
        shl     esi,8
4634
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
1 ha 4635
     shl   ebp,16
115 poddubny 4636
     add   ebp,[edi-twdw+WDATA.box.top]
114 mikedld 4637
        add     bp,word[esi+0x80000+APPDATA.wnd_clientbox.top]
139 diamond 4638
        pop     esi
117 mario79 4639
     add   ecx,[edi+TASKDATA.mem_start]
1 ha 4640
     add   eax,ebp
4641
     xor   edi,edi
4642
     jmp   dtext
4643
 
4644
align 4
4645
 
4646
syscall_openramdiskfile:                ; OpenRamdiskFile
4647
 
4648
 
4649
     mov   edi,[0x3010]
164 serge 4650
     add   edi,TASKDATA.mem_start
1 ha 4651
     add   eax,[edi]
4652
     add   edx,[edi]
4653
     mov   esi,12
4654
     call  fileread
4655
     mov   [esp+36],ebx
4656
     ret
4657
 
4658
align 4
4659
 
4660
syscall_drawrect:                       ; DrawRect
4661
 
4662
     mov   edi,ecx
52 mikedld 4663
     and   edi,0x80FFFFFF
1 ha 4664
     test  ax,ax
4665
     je    drectr
4666
     test  bx,bx
4667
     je    drectr
4668
     movzx ecx,ax
4669
     shr   eax,16
4670
     movzx edx,bx
4671
     shr   ebx,16
114 mikedld 4672
        mov     esi,[0x3000]
4673
        shl     esi,8
4674
        add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
4675
        add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
1 ha 4676
     add   ecx,eax
4677
     add   edx,ebx
4678
     jmp   [drawbar]
4679
    drectr:
4680
     ret
4681
 
4682
align 4
4683
 
4684
syscall_getscreensize:                  ; GetScreenSize
4685
 
4686
     movzx eax,word[0xfe00]
4687
     shl   eax,16
4688
     mov   ax,[0xfe04]
4689
     mov   [esp+36],eax
4690
     ret
4691
 
4692
align 4
4693
 
4694
syscall_cdaudio:                        ; CD
4695
 
4696
     call  sys_cd_audio
4697
     mov   [esp+36],eax
4698
     ret
4699
 
4700
align 4
4701
 
4702
syscall_delramdiskfile:                 ; DelRamdiskFile
4703
 
4704
     mov   edi,[0x3010]
164 serge 4705
     add   edi,TASKDATA.mem_start
1 ha 4706
     add   eax,[edi]
4707
     call  filedelete
4708
     mov   [esp+36],eax
4709
     ret
4710
 
4711
align 4
4712
 
4713
syscall_writeramdiskfile:               ; WriteRamdiskFile
4714
 
4715
     mov   edi,[0x3010]
164 serge 4716
     add   edi,TASKDATA.mem_start
1 ha 4717
     add   eax,[edi]
4718
     add   ebx,[edi]
4719
     call  filesave
4720
     mov   [esp+36],eax
4721
     ret
4722
 
4723
align 4
4724
 
4725
syscall_getpixel:                       ; GetPixel
4726
     mov   ecx,[0xfe00]
4727
     inc   ecx
4728
     xor   edx,edx
4729
     div   ecx
4730
     mov   ebx,edx
4731
     xchg  eax,ebx
4732
     call  dword [0xe024]
4733
     mov   [esp+36],ecx
4734
     ret
4735
 
4736
align 4
4737
 
4738
syscall_readstring:                     ; ReadString
4739
 
4740
     mov   edi,[0x3010]
164 serge 4741
     add   edi,TASKDATA.mem_start
1 ha 4742
     add   eax,[edi]
4743
     call  read_string
4744
     mov   [esp+36],eax
4745
     ret
4746
 
4747
align 4
4748
 
4749
syscall_drawline:                       ; DrawLine
4750
 
4751
     mov   edi,[0x3010]
115 poddubny 4752
     movzx edx,word[edi-twdw+WDATA.box.left]
1 ha 4753
     mov   ebp,edx
114 mikedld 4754
        mov     esi,[0x3000]
4755
        shl     esi,8
4756
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
4757
        add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.left]
1 ha 4758
     shl   edx,16
4759
     add   ebp,edx
115 poddubny 4760
     movzx edx,word[edi-twdw+WDATA.box.top]
1 ha 4761
     add   eax,ebp
4762
     mov   ebp,edx
114 mikedld 4763
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.top]
4764
        add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.top]
1 ha 4765
     shl   edx,16
4766
     xor   edi,edi
4767
     add   edx,ebp
4768
     add   ebx,edx
4769
     jmp   [draw_line]
4770
 
4771
align 4
4772
 
4773
syscall_getirqowner:                    ; GetIrqOwner
75 diamond 4774
     cmp   eax,16
4775
     jae   .err
1 ha 4776
     shl   eax,2
4777
     add   eax,irq_owner
4778
     mov   eax,[eax]
4779
     mov   [esp+36],eax
4780
     ret
75 diamond 4781
.err:
4782
     or    dword [esp+36], -1
4783
     ret
1 ha 4784
 
4785
align 4
4786
 
4787
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4788
 
4789
     call  r_f_port_area
4790
     mov   [esp+36],eax
4791
     ret
4792
 
4793
align 4
4794
 
4795
syscall_threads:                        ; CreateThreads
4796
 
4797
     call  sys_threads
4798
     mov   [esp+36],eax
4799
     ret
4800
 
4801
align 4
4802
 
4803
stack_driver_stat:
4804
 
4805
     call  app_stack_handler            ; Stack status
4806
 
4807
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4808
;     call  change_task                 ; between sent packet
4809
 
4810
     mov   [esp+36],eax
4811
     ret
4812
 
4813
align 4
4814
 
4815
socket:                                 ; Socket interface
4816
     call  app_socket_handler
4817
 
4818
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4819
;     call  change_task                 ; between sent packet
4820
 
4821
     mov   [esp+36],eax
4822
     mov   [esp+24],ebx
4823
     ret
4824
 
4825
align 4
4826
 
4827
user_events:                            ; User event times
4828
 
4829
     mov   eax,0x12345678
4830
     mov   [esp+36],eax
4831
 
4832
     ret
4833
 
4834
align 4
4835
 
4836
read_from_hd:                           ; Read from hd - fn not in use
4837
 
4838
     mov   edi,[0x3010]
115 poddubny 4839
     add   edi,TASKDATA.mem_start
1 ha 4840
     add   eax,[edi]
4841
     add   ecx,[edi]
4842
     add   edx,[edi]
4843
     call  file_read
4844
 
4845
     mov   [esp+36],eax
4846
     mov   [esp+24],ebx
4847
 
4848
     ret
4849
 
4850
 
4851
align 4
4852
 
4853
write_to_hd:                            ; Write a file to hd
4854
 
4855
     mov   edi,[0x3010]
115 poddubny 4856
     add   edi,TASKDATA.mem_start
1 ha 4857
     add   eax,[edi]
4858
     add   ecx,[edi]
4859
     add   edx,[edi]
4860
     call  file_write
4861
     ret
4862
 
75 diamond 4863
;  Sysfunction 57, delete_from_hd, is obsolete. Use 58 or 70 functions instead.
4864
;align 4
4865
;
4866
;delete_from_hd:                         ; Delete a file from hd
4867
;
4868
;     mov   edi,[0x3010]
4869
;     add   edi,0x10
4870
;     add   eax,[edi]
4871
;     add   ecx,[edi]
4872
;     call  file_delete
4873
;     ret
4874
;
1 ha 4875
 
76 mario79 4876
; --------------- APM ---------------------
4877
apm_entry    dp    0
4878
apm_vf        dd    0
1 ha 4879
align 4
76 mario79 4880
sys_apm:
4881
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
4882
    jne    @f
78 diamond 4883
    or    [esp + 56], byte 1    ; error
76 mario79 4884
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
4885
    ret
164 serge 4886
 
76 mario79 4887
@@:    xchg    eax, ecx
4888
    xchg    ebx, ecx
164 serge 4889
 
76 mario79 4890
    cmp    al, 3
4891
    ja    @f
78 diamond 4892
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 4893
    mov    eax, [apm_vf]
4894
    mov    [esp + 36], eax
4895
    shr    eax, 16
4896
    mov    [esp + 32], eax
4897
    ret
78 diamond 4898
 
76 mario79 4899
@@:    call    pword [apm_entry]    ; call APM BIOS
4900
    mov    [esp + 8 ], edi
4901
    mov    [esp + 12], esi
4902
    mov    [esp + 24], ebx
4903
    mov    [esp + 28], edx
4904
    mov    [esp + 32], ecx
4905
    mov    [esp + 36], eax
4906
    setc    al
78 diamond 4907
    and    [esp + 56], byte 0xfe
4908
    or    [esp + 56], al
76 mario79 4909
    ret
4910
; -----------------------------------------
1 ha 4911
 
76 mario79 4912
align 4
4913
 
1 ha 4914
undefined_syscall:                      ; Undefined system call
4915
 
4916
     mov   [esp+36],dword -1
4917
     ret
4918
 
4919
 
4920
;clear_busy_flag_at_caller:
4921
 
4922
;      push  edi
4923
 
4924
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
4925
;      imul  edi,8
4926
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
4927
 
4928
;      pop   edi
4929
 
4930
;      ret
4931
 
4932
 
4933
 
4934
 
4935
keymap:
4936
 
4937
     db   '6',27
4938
     db   '1234567890-=',8,9
4939
     db   'qwertyuiop[]',13
4940
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
4941
     db   '@234567890123',180,178,184,'6',176,'7'
4942
     db   179,'8',181,177,183,185,182
4943
     db   'AB
4944
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4945
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4946
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4947
 
4948
 
4949
keymap_shift:
4950
 
4951
     db   '6',27
4952
     db   '!@#$%^&*()_+',8,9
4953
     db   'QWERTYUIOP{}',13
4954
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
4955
     db   '@234567890123',180,178,184,'6',176,'7'
4956
     db   179,'8',181,177,183,185,182
4957
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
4958
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4959
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4960
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4961
 
4962
 
4963
keymap_alt:
4964
 
4965
     db   ' ',27
4966
     db   ' @ $  {[]}\ ',8,9
4967
     db   '            ',13
4968
     db   '             ',0,'           ',0,'4',0,' '
4969
     db   '             ',180,178,184,'6',176,'7'
4970
     db   179,'8',181,177,183,185,182
4971
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
4972
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4973
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4974
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4975
 
4976
 
4977
; device irq owners
4978
uglobal
4979
irq_owner:       ; process id
4980
 
4981
     dd   0x0
4982
     dd   0x0
4983
     dd   0x0
4984
     dd   0x0
4985
     dd   0x0
4986
     dd   0x0
4987
     dd   0x0
4988
     dd   0x0
4989
     dd   0x0
4990
     dd   0x0
4991
     dd   0x0
4992
     dd   0x0
4993
     dd   0x0
4994
     dd   0x0
4995
     dd   0x0
4996
     dd   0x0
4997
endg
4998
 
4999
 
5000
; on irq read ports
5001
uglobal
5002
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5003
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5004
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5005
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5006
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5007
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5008
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5009
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5010
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5011
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5012
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5013
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5014
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5015
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5016
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5017
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5018
endg
5019
 
5020
; status
5021
uglobal
5022
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5023
  application_table_status    dd 0x0  ; 0 - free : other - pid
5024
endg
5025
 
5026
; device addresses
5027
uglobal
5028
  mididp     dd 0x0
5029
  midisp     dd 0x0
5030
 
5031
  cdbase     dd 0x0
5032
  cdid       dd 0x0
5033
 
5034
  hdbase              dd   0x0  ; for boot 0x1f0
5035
  hdid                dd   0x0
5036
  hdpos               dd   0x0  ; for boot 0x1
5037
  fat32part           dd   0x0  ; for boot 0x1
5038
 
5039
  ;part2_ld            dd   0x0
5040
 
102 poddubny 5041
;* start code - Mario79
33 mario79 5042
mouse_pause         dd   0
36 mario79 5043
MouseTickCounter    dd   0
33 mario79 5044
ps2_mouse_detected  db   0
5045
com1_mouse_detected db   0
5046
com2_mouse_detected db   0
102 poddubny 5047
;* end code - Mario79
1 ha 5048
 
5049
wraw_bacground_select db 0
5050
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5051
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5052
 
5053
  sb16       dd 0x0
5054
  wss        dd 0x0
5055
 
5056
  buttontype         dd 0x0
5057
  windowtypechanged  dd 0x0
164 serge 5058
 
5059
align 4
5060
  pg_data  PG_DATA
5061
  heap_test   dd ?
5062
  cpu_caps    dd 4 dup(0)
1 ha 5063
endg
5064
 
5065
iglobal
5066
  keyboard   dd 0x1
5067
  sound_dma  dd 0x1
5068
  syslang    dd 0x1
5069
endg
5070
 
5071
IncludeIGlobals
5072
endofcode:
5073
IncludeUGlobals
5074
uglobals_size = $ - endofcode
41 mikedld 5075
diff16 "end of kernel code",0,$
1 ha 5076