Subversion Repositories Kolibri OS

Rev

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