Subversion Repositories Kolibri OS

Rev

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

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