Subversion Repositories Kolibri OS

Rev

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

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