Subversion Repositories Kolibri OS

Rev

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