Subversion Repositories Kolibri OS

Rev

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