Subversion Repositories Kolibri OS

Rev

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

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