Subversion Repositories Kolibri OS

Rev

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