Subversion Repositories Kolibri OS

Rev

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