Subversion Repositories Kolibri OS

Rev

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