Subversion Repositories Kolibri OS

Rev

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