Subversion Repositories Kolibri OS

Rev

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