Subversion Repositories Kolibri OS

Rev

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