Subversion Repositories Kolibri OS

Rev

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

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