Subversion Repositories Kolibri OS

Rev

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