Subversion Repositories Kolibri OS

Rev

Rev 428 | Blame | Last modification | View Log | Download | RSS feed

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