Subversion Repositories Kolibri OS

Rev

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