Subversion Repositories Kolibri OS

Rev

Rev 243 | Rev 265 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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