Subversion Repositories Kolibri OS

Rev

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