Subversion Repositories Kolibri OS

Rev

Rev 221 | Rev 224 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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