Subversion Repositories Kolibri OS

Rev

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