Subversion Repositories Kolibri OS

Rev

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