Subversion Repositories Kolibri OS

Rev

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

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