Subversion Repositories Kolibri OS

Rev

Rev 709 | Rev 725 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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