Subversion Repositories Kolibri OS

Rev

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

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