Subversion Repositories Kolibri OS

Rev

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