Subversion Repositories Kolibri OS

Rev

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