Subversion Repositories Kolibri OS

Rev

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