Subversion Repositories Kolibri OS

Rev

Rev 224 | Rev 233 | 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.            call init_events
  444.  
  445.            mov [dll_map], 0xFFFFFFFF
  446.            mov [srv_map], 0xFFFFFFFF
  447.  
  448.            call alloc_dll
  449.            mov edi, eax
  450.            mov esi, szKernel
  451.            mov ecx, 16
  452.            rep movsb
  453.  
  454.            mov edi, irq_tab
  455.            xor eax, eax
  456.            mov ecx, 16
  457.            rep stosd
  458.  
  459. ;Set base of graphic segment to linear address of LFB
  460.         mov     eax,[LFBAddress]          ; set for gs
  461.         mov     [graph_data_l+2],ax
  462.         shr     eax,16
  463.         mov     [graph_data_l+4],al
  464.         mov     [graph_data_l+7],ah
  465.  
  466. ; READ RAMDISK IMAGE FROM HD
  467.  
  468. ;!!!!!!!!!!!!!!!!!!!!!!!
  469. include 'boot/rdload.inc'
  470. ;!!!!!!!!!!!!!!!!!!!!!!!
  471. ;    mov    [dma_hdd],1
  472. ; CALCULATE FAT CHAIN FOR RAMDISK
  473.  
  474.         call  calculatefatchain
  475.  
  476. ; LOAD VMODE DRIVER
  477.  
  478. ;!!!!!!!!!!!!!!!!!!!!!!!
  479. include 'vmodeld.inc'
  480. ;!!!!!!!!!!!!!!!!!!!!!!!
  481.  
  482. ; LOAD FONTS I and II
  483.  
  484.         mov   [0x3000],dword 1
  485.         mov   [0x3004],dword 1
  486.         mov   [0x3010],dword 0x3020
  487.  
  488.         mov   esi,char
  489.         xor   ebx,ebx
  490.         mov   ecx,2560;26000
  491.         mov   edx,0x3F600;0x37000
  492.         call  fs_RamdiskRead
  493.  
  494.         mov   esi,char2
  495.         xor   ebx,ebx
  496.         mov   ecx,2560;26000
  497.         mov   edx,0x3EC00;0x30000
  498.         call  fs_RamdiskRead
  499.  
  500.         mov   esi,boot_fonts
  501.         call  boot_log
  502.  
  503. ; PRINT AMOUNT OF MEMORY
  504.         mov     esi, boot_memdetect
  505.         call    boot_log
  506.  
  507.         movzx   ecx, word [boot_y]
  508.         or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
  509.         sub     ecx, 10
  510.         mov     edx, 0xFFFFFF
  511.         mov     ebx, [MEM_AMOUNT]
  512.         shr     ebx, 20
  513.         mov     edi, 1
  514.         mov     eax, 0x00040000
  515.         call    display_number_force
  516.  
  517. ; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
  518.  
  519.         mov   esi,boot_irqs
  520.         call  boot_log
  521.         call  rerouteirqs
  522.  
  523.         mov    esi,boot_tss
  524.         call   boot_log
  525.  
  526. ; BUILD SCHEDULER
  527.  
  528.         call   build_scheduler ; sys32.inc
  529.  
  530. ; LOAD IDT
  531.         lidt   [cs:idtreg]
  532.         cli
  533.  
  534.         mov    esi,boot_devices
  535.         call   boot_log
  536.         call   detect_devices
  537.  
  538.  ; TIMER SET TO 1/100 S
  539.  
  540.         mov   esi,boot_timer
  541.         call  boot_log
  542.         mov   al,0x34              ; set to 100Hz
  543.         out   0x43,al
  544.         mov   al,0x9b              ; lsb    1193180 / 1193
  545.         out   0x40,al
  546.         mov   al,0x2e              ; msb
  547.         out   0x40,al
  548.  
  549. ; SET MOUSE
  550.  
  551.         mov   esi,boot_setmouse
  552.         call  boot_log
  553.         call  setmouse
  554.  
  555.         mov  [pci_access_enabled],1
  556.         call init_cursors
  557.  
  558. ; SET PRELIMINARY WINDOW STACK AND POSITIONS
  559.  
  560.         mov   esi,boot_windefs
  561.         call  boot_log
  562.         call  setwindowdefaults
  563.  
  564. ; SET BACKGROUND DEFAULTS
  565.  
  566.         mov   esi,boot_bgr
  567.         call  boot_log
  568.         call  calculatebackground
  569.  
  570. ; RESERVE SYSTEM IRQ'S JA PORT'S
  571.  
  572.         mov   esi,boot_resirqports
  573.         call  boot_log
  574.         call  reserve_irqs_ports
  575.  
  576. ; SET PORTS FOR IRQ HANDLERS
  577.  
  578.         mov  esi,boot_setrports
  579.         call boot_log
  580.         call setirqreadports
  581.  
  582. ; SET UP OS TASK
  583.  
  584.         mov  esi,boot_setostask
  585.         call boot_log
  586.  
  587.         mov eax, [fpu_data]
  588.         mov  dword [0x80000+APPDATA.fpu_state], eax
  589.         mov  dword [0x80000+APPDATA.fpu_handler], 0
  590.         mov  dword [0x80000+APPDATA.sse_handler], 0
  591.  
  592.         ; name for OS/IDLE process
  593.         mov  dword [0x80000+256+APPDATA.app_name],   dword 'OS/I'
  594.         mov  dword [0x80000+256+APPDATA.app_name+4], dword 'DLE '
  595.         mov ebx, [def_cursor]
  596.         mov dword [0x80000+256+APPDATA.cursor], ebx
  597.  
  598.         mov  dword [0x80000+256+APPDATA.fpu_handler], 0
  599.         mov  dword [0x80000+256+APPDATA.sse_handler], 0
  600.  
  601. ;set fpu save area
  602.         mov esi, eax
  603.         bt [cpu_caps], CAPS_SSE
  604.         jnc .no_sse
  605.  
  606.         lea edi, [eax+512]
  607.         mov  dword [PROC_BASE+256+APPDATA.fpu_state], edi
  608.         mov ecx, 512/4
  609.         jmp @F
  610. .no_sse:
  611.         lea edi, [eax+112]
  612.         mov  dword [PROC_BASE+256+APPDATA.fpu_state], edi
  613.         mov ecx, 112/4
  614. @@:
  615.         rep movsd
  616.  
  617.         ; task list
  618.         mov  [0x3020+TASKDATA.wnd_number], 1 ; on screen number
  619.         mov  [0x3020+TASKDATA.pid], 1        ; process id number
  620.         mov  [0x3020+TASKDATA.mem_start], 0  ; process base address
  621.  
  622.         ; 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.      mov  eax,[0x3004]
  1954.      add  eax,2
  1955.      mov  [shutdown_processes],eax
  1956.      mov  [0xFF00],al
  1957.      and  dword [esp+36], 0
  1958.      ret
  1959.   uglobal
  1960.    shutdown_processes: dd 0x0
  1961.   endg
  1962.  
  1963. sysfn_terminate:        ; 18.2 = TERMINATE
  1964.      cmp  ebx,2
  1965.      jb   noprocessterminate
  1966.      mov  edx,[0x3004]
  1967.      cmp  ebx,edx
  1968.      ja   noprocessterminate
  1969.      mov  eax,[0x3004]
  1970.      shl  ebx,5
  1971.      mov  edx,[ebx+0x3000+TASKDATA.pid]
  1972.      add  ebx,0x3000+TASKDATA.state
  1973.      cmp  byte [ebx], 9
  1974.      jz   noprocessterminate
  1975.  
  1976.      ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
  1977.      mov  [ebx],byte 3       ; clear possible i40's
  1978.      ;call MEM_Heap_UnLock
  1979.  
  1980.      cmp  edx,[application_table_status]    ; clear app table stat
  1981.      jne  noatsc
  1982.      mov  [application_table_status],0
  1983.    noatsc:
  1984.    noprocessterminate:
  1985.      ret
  1986.  
  1987. sysfn_terminate2:
  1988. ;lock application_table_status mutex
  1989. .table_status:
  1990.     cli
  1991.     cmp    [application_table_status],0
  1992.     je     .stf
  1993.     sti
  1994.     call   change_task
  1995.     jmp    .table_status
  1996. .stf:
  1997.     call   set_application_table_status
  1998.     mov    eax,ebx
  1999.     call   pid_to_slot
  2000.     test   eax,eax
  2001.     jz     .not_found
  2002.     mov    ebx,eax
  2003.     cli
  2004.     call   sysfn_terminate
  2005.     mov    [application_table_status],0
  2006.     sti
  2007.     and    dword [esp+36],0
  2008.     ret
  2009. .not_found:
  2010.     mov    [application_table_status],0
  2011.     or     dword [esp+36],-1
  2012.     ret
  2013.  
  2014. sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
  2015.      cmp  ebx,2
  2016.      jb   .nowindowactivate
  2017.      cmp  ebx,[0x3004]
  2018.      ja   .nowindowactivate
  2019.  
  2020.      mov   [window_minimize], 2   ; restore window if minimized
  2021.  
  2022.      movzx esi, word [0xC000 + ebx*2]
  2023.      cmp   esi, [0x3004]
  2024.      je    .nowindowactivate ; already active
  2025.  
  2026.      mov   edi, ebx
  2027.      shl   edi, 5
  2028.      add   edi, window_data
  2029.      movzx esi, word [0xC000 + ebx * 2]
  2030.      lea   esi, [0xC400 + esi * 2]
  2031.      call  waredraw
  2032. .nowindowactivate:
  2033.      ret
  2034.  
  2035. sysfn_getidletime:              ; 18.4 = GET IDLETIME
  2036.      mov  eax,[idleusesec]
  2037.      mov  [esp+36], eax
  2038.      ret
  2039.  
  2040. sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
  2041.      mov  eax,[0xf600]
  2042.      mov  [esp+36], eax
  2043.      ret
  2044.  
  2045. ;  SAVE ramdisk to /hd/1/menuet.img
  2046. ;!!!!!!!!!!!!!!!!!!!!!!!!
  2047.    include 'blkdev/rdsave.inc'
  2048. ;!!!!!!!!!!!!!!!!!!!!!!!!
  2049.  
  2050. sysfn_getactive:        ; 18.7 = get active window
  2051.      mov  eax, [0x3004]
  2052.    movzx  eax, word [0xC400 + eax*2]
  2053.      mov  [esp+36],eax
  2054.      ret
  2055.  
  2056. sysfn_sound_flag:       ; 18.8 = get/set sound_flag
  2057.      cmp  ebx,1
  2058.      jne  nogetsoundflag
  2059.      movzx  eax,byte [sound_flag] ; get sound_flag
  2060.      mov  [esp+36],eax
  2061.      ret
  2062.  nogetsoundflag:
  2063.      cmp  ebx,2
  2064.      jnz  nosoundflag
  2065.      xor  byte [sound_flag], 1
  2066.  nosoundflag:
  2067.      ret
  2068.  
  2069. sysfn_shutdown_param:   ; 18.9 = system shutdown with param
  2070.      cmp  ebx,1
  2071.      jl   exit_for_anyone
  2072.      cmp  ebx,4
  2073.      jg   exit_for_anyone
  2074.      mov  [0x2f0000+0x9030],bl
  2075.      jmp  for_shutdown_parameter
  2076.  
  2077. sysfn_minimize:         ; 18.10 = minimize window
  2078.      mov   [window_minimize],1
  2079.  exit_for_anyone:
  2080.      ret
  2081.  
  2082. sysfn_getdiskinfo:      ; 18.11 = get disk info table
  2083.      cmp  ebx,1
  2084.      jnz  full_table
  2085.   small_table:
  2086.      call for_all_tables
  2087.      mov ecx,10
  2088.      cld
  2089.      rep movsb
  2090.      ret
  2091.    for_all_tables:
  2092.      mov edi,[0x3010]
  2093.      mov edi,[edi+TASKDATA.mem_start]
  2094.      add edi,ecx
  2095.      mov esi,0x40000
  2096.      ret
  2097.   full_table:
  2098.      cmp  ebx,2
  2099.      jnz  exit_for_anyone
  2100.      call for_all_tables
  2101.      mov ecx,16384
  2102.      cld
  2103.      rep movsd
  2104.      ret
  2105.  
  2106. sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
  2107.         and     dword [esp+36], 0
  2108.         ret
  2109.  
  2110. sysfn_getversion:       ; 18.13 = get kernel ID and version
  2111.      mov edi,[0x3010]
  2112.      mov edi,[edi+TASKDATA.mem_start]
  2113.      add edi,ebx
  2114.      mov esi,version_inf
  2115.      mov ecx,version_end-version_inf
  2116.      cld
  2117.      rep movsb
  2118.      ret
  2119.  
  2120. sysfn_waitretrace:     ; 18.14 = sys wait retrace
  2121.      ;wait retrace functions
  2122.  sys_wait_retrace:
  2123.      mov edx,0x3da
  2124.  WaitRetrace_loop:
  2125.      in al,dx
  2126.      test al,1000b
  2127.      jz WaitRetrace_loop
  2128.      mov [esp+36],dword 0
  2129.      ret
  2130.  
  2131. sysfn_centermouse:      ; 18.15 = mouse centered
  2132.      call  mouse_centered
  2133.      mov [esp+36],dword 0
  2134.      ret
  2135.  
  2136. sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
  2137.      cmp  ebx,0  ; get mouse speed factor
  2138.      jnz  .set_mouse_acceleration
  2139.      xor  eax,eax
  2140.      mov  ax,[mouse_speed_factor]
  2141.      mov  [esp+36],eax
  2142.      ret
  2143.  .set_mouse_acceleration:
  2144.      cmp  ebx,1  ; set mouse speed factor
  2145.      jnz  .get_mouse_delay
  2146.      mov  [mouse_speed_factor],cx
  2147.      ret
  2148.  .get_mouse_delay:
  2149.      cmp  ebx,2  ; get mouse delay
  2150.      jnz  .set_mouse_delay
  2151.      mov  eax,[mouse_delay]
  2152.      mov  [esp+36],eax
  2153.      ret
  2154.  .set_mouse_delay:
  2155.      cmp  ebx,3  ; set mouse delay
  2156.      jnz  .set_pointer_position
  2157.      mov  [mouse_delay],ecx
  2158.      ret
  2159.  .set_pointer_position:
  2160.      cmp  ebx,4  ; set mouse pointer position
  2161.      jnz  .end
  2162.      mov   [0xFB0C],cx    ;y
  2163.      ror   ecx,16
  2164.      mov   [0xFB0A],cx    ;x
  2165.      rol   ecx,16
  2166.  .end:
  2167.      ret
  2168.  
  2169. sysfn_getfreemem:
  2170.      mov eax, [pg_data.pages_free]
  2171.      shl eax, 2
  2172.      mov [esp+36],eax
  2173.      ret
  2174.  
  2175. sysfn_getallmem:
  2176.      mov  eax,[MEM_AMOUNT]
  2177.      shr eax, 10
  2178.      mov  [esp+36],eax
  2179.      ret
  2180.  
  2181. uglobal
  2182. ;// mike.dld, 2006-29-01 [
  2183. screen_workarea RECT
  2184. ;// mike.dld, 2006-29-01 ]
  2185. window_minimize db 0
  2186. sound_flag      db 0
  2187. endg
  2188.  
  2189. iglobal
  2190. version_inf:
  2191.   db 0,6,3,0  ; version 0.6.3.0
  2192.   db UID_KOLIBRI
  2193.   db 'Kolibri',0
  2194. version_end:
  2195. endg
  2196.  
  2197. UID_NONE=0
  2198. UID_MENUETOS=1   ;official
  2199. UID_KOLIBRI=2    ;russian
  2200.  
  2201. sys_cachetodiskette:
  2202. ;    pushad
  2203. ;    cmp  eax,1
  2204. ;    jne  no_write_all_of_ramdisk
  2205. ;    call fdc_writeramdisk
  2206. ;    popad
  2207. ;    ret
  2208. ;  no_write_all_of_ramdisk:
  2209. ;    cmp eax,2
  2210. ;    jne no_write_part_of_ramdisk
  2211. ;    call fdc_commitflush
  2212. ;    popad
  2213. ;    ret
  2214. ;  no_write_part_of_ramdisk:
  2215. ;    cmp  eax,3
  2216. ;    jne  no_set_fdc
  2217. ;    call fdc_set
  2218. ;    popad
  2219. ;    ret
  2220. ;  no_set_fdc:
  2221. ;    cmp  eax,4
  2222. ;    jne  no_get_fdc
  2223. ;    popad
  2224. ;    call fdc_get
  2225. ;    mov    [esp+36],ecx
  2226. ;    ret
  2227. ;  no_get_fdc:
  2228. ;    popad
  2229. ;    ret
  2230.     cmp eax,1
  2231.     jne no_floppy_a_save
  2232.     mov   [flp_number],1
  2233.     jmp save_image_on_floppy
  2234.   no_floppy_a_save:
  2235.     cmp eax,2
  2236.     jne no_floppy_b_save
  2237.     mov   [flp_number],2
  2238.   save_image_on_floppy:
  2239.     call save_image
  2240.     mov  [esp+36],dword 0
  2241.     cmp  [FDC_Status],0
  2242.     je   yes_floppy_save
  2243.   no_floppy_b_save:
  2244.     mov [esp+36],dword 1
  2245.   yes_floppy_save:
  2246.     ret
  2247.  
  2248. uglobal
  2249. ;  bgrchanged  dd  0x0
  2250. endg
  2251.  
  2252. sys_background:
  2253.  
  2254.     cmp   eax,1                            ; BACKGROUND SIZE
  2255.     jnz   nosb1
  2256.     cmp   ebx,0
  2257.     je    sbgrr
  2258.     cmp   ecx,0
  2259.     je    sbgrr
  2260.     mov   [display_data-8],ebx
  2261.     mov   [display_data-4],ecx
  2262. ;    mov   [bgrchanged],1
  2263.   sbgrr:
  2264.     ret
  2265.   nosb1:
  2266.  
  2267.     cmp   eax,2                            ; SET PIXEL
  2268.     jnz   nosb2
  2269.     mov   edx,0x160000-16
  2270.     cmp   edx,ebx
  2271.     jbe   nosb2
  2272.     mov   edx,[ebx]
  2273.     and   edx,0xFF000000 ;255*256*256*256
  2274.     and   ecx,0x00FFFFFF ;255*256*256+255*256+255
  2275.     add   edx,ecx
  2276.     mov   [ebx+0x300000],edx
  2277. ;    mov   [bgrchanged],1
  2278.     ret
  2279.   nosb2:
  2280.  
  2281.     cmp   eax,3                            ; DRAW BACKGROUND
  2282.     jnz   nosb3
  2283. draw_background_temp:
  2284. ;    cmp   [bgrchanged],1 ;0
  2285. ;    je    nosb31
  2286. ;draw_background_temp:
  2287. ;    mov   [bgrchanged],1 ;0
  2288.     mov   [0xfff0],byte 1
  2289.     mov    [background_defined], 1
  2290.    nosb31:
  2291.     ret
  2292.   nosb3:
  2293.  
  2294.     cmp   eax,4                            ; TILED / STRETCHED
  2295.     jnz   nosb4
  2296.     cmp   ebx,[display_data-12]
  2297.     je    nosb41
  2298.     mov   [display_data-12],ebx
  2299. ;    mov   [bgrchanged],1
  2300.    nosb41:
  2301.     ret
  2302.   nosb4:
  2303.  
  2304.     cmp   eax,5                            ; BLOCK MOVE TO BGR
  2305.     jnz   nosb5
  2306.   ; bughere
  2307.     mov   edi, [0x3010]
  2308.     add   ebx, [edi+TASKDATA.mem_start]
  2309.  ;   mov   esi, ebx
  2310.  ;   mov   edi, ecx
  2311.     mov   eax, ebx
  2312.     mov   ebx, ecx
  2313.     add   ecx, edx
  2314.     cmp   ecx, 0x160000-16
  2315.     ja    .fin
  2316.  ;   add   edi, 0x300000
  2317.     add   ebx, 0x300000
  2318.     mov   ecx, edx
  2319.     cmp   ecx, 0x160000-16
  2320.     ja    .fin
  2321. ;    mov   [bgrchanged],1
  2322.   ;  cld
  2323.   ;  rep   movsb
  2324.     call  memmove
  2325.   .fin:
  2326.     ret
  2327.   nosb5:
  2328.  
  2329.     ret
  2330.  
  2331.  
  2332. align 4
  2333.  
  2334. sys_getbackground:
  2335.  
  2336.     cmp   eax,1                                  ; SIZE
  2337.     jnz   nogb1
  2338.     mov   eax,[display_data-8]
  2339.     shl   eax,16
  2340.     mov   ax,[display_data-4]
  2341.     mov   [esp+36],eax
  2342.     ret
  2343.   nogb1:
  2344.  
  2345.     cmp   eax,2                                  ; PIXEL
  2346.     jnz   nogb2
  2347.     mov   edx,0x160000-16
  2348.     cmp   edx,ebx
  2349.     jbe   nogb2
  2350.     mov   eax, [ebx+0x300000]
  2351.     and   eax, 0xFFFFFF
  2352.     mov   [esp+36],eax
  2353.     ret
  2354.   nogb2:
  2355.  
  2356.     cmp   eax,4                                  ; TILED / STRETCHED
  2357.     jnz   nogb4
  2358.     mov   eax,[display_data-12]
  2359.   nogb4:
  2360.     mov   [esp+36],eax
  2361.     ret
  2362.  
  2363.  
  2364. align 4
  2365.  
  2366. sys_getkey:
  2367.     mov   [esp+36],dword 1
  2368. ; test main buffer
  2369.     mov   ebx, [0x3000]                          ; TOP OF WINDOW STACK
  2370.     movzx ecx,word [0xC000 + ebx * 2]
  2371.     mov   edx,[0x3004]
  2372.     cmp   ecx,edx
  2373.     jne   .finish
  2374.     cmp   [0xf400],byte 0
  2375.     je    .finish
  2376.     movzx eax,byte [0xf401]
  2377.     shl   eax,8
  2378.     push  eax
  2379.     dec   byte [0xf400]
  2380.     and   byte [0xf400],127
  2381.     movzx ecx,byte [0xf400]
  2382.     add   ecx,2
  2383.  ;   mov   esi,0xf402
  2384.  ;   mov   edi,0xf401
  2385.  ;   cld
  2386.  ;  rep   movsb
  2387.     mov   eax, 0xF402
  2388.     mov   ebx, 0xF401
  2389.     call  memmove
  2390.     pop   eax
  2391. .ret_eax:
  2392.     mov   [esp+36],eax
  2393.     ret
  2394.  .finish:
  2395. ; test hotkeys buffer
  2396.         mov     ecx, hotkey_buffer
  2397. @@:
  2398.         cmp     [ecx], ebx
  2399.         jz      .found
  2400.         add     ecx, 8
  2401.         cmp     ecx, hotkey_buffer+120*8
  2402.         jb      @b
  2403.         ret
  2404. .found:
  2405.         mov     ax, [ecx+6]
  2406.         shl     eax, 16
  2407.         mov     ah, [ecx+4]
  2408.         mov     al, 2
  2409.         and     dword [ecx+4], 0
  2410.         and     dword [ecx], 0
  2411.         jmp     .ret_eax
  2412.  
  2413. align 4
  2414.  
  2415. sys_getbutton:
  2416.  
  2417.     mov   ebx, [0x3000]                         ; TOP OF WINDOW STACK
  2418.     mov   [esp+36],dword 1
  2419.     movzx ecx, word [0xC000 + ebx * 2]
  2420.     mov   edx, [0x3004] ; less than 256 processes
  2421.     cmp   ecx,edx
  2422.     jne   .exit
  2423.     movzx eax,byte [0xf500]
  2424.     test  eax,eax
  2425.     jz    .exit
  2426.     mov   eax,[0xf501]
  2427.     shl   eax,8
  2428.     mov   [0xf500],byte 0
  2429.     mov   [esp+36],eax
  2430.  .exit:
  2431.     ret
  2432.  
  2433.  
  2434. align 4
  2435.  
  2436. sys_cpuusage:
  2437.  
  2438. ;  RETURN:
  2439. ;
  2440. ;  +00 dword     process cpu usage
  2441. ;  +04  word     position in windowing stack
  2442. ;  +06  word     windowing stack value at current position (cpu nro)
  2443. ;  +10 12 bytes  name
  2444. ;  +22 dword     start in mem
  2445. ;  +26 dword     used mem
  2446. ;  +30 dword     PID , process idenfification number
  2447. ;
  2448.  
  2449.     mov  edi,[0x3010]   ; eax = return area
  2450.     add  eax,[edi + TASKDATA.mem_start]
  2451.  
  2452.     cmp  ebx,-1         ; who am I ?
  2453.     jne  no_who_am_i
  2454.     mov  ebx,[0x3000]
  2455.   no_who_am_i:
  2456.  
  2457.     push eax            ; return area
  2458.     push ebx            ; process number
  2459.  
  2460.     push ebx
  2461.     push ebx
  2462.     push eax
  2463.  
  2464.     ; return memory usage
  2465.  
  2466.     xor  edx,edx
  2467.     mov  eax,0x20
  2468.     mul  ebx
  2469.     add  eax,0x3000+TASKDATA.cpu_usage
  2470.     mov  ebx,eax
  2471.     pop  eax
  2472.     mov  ecx,[ebx]
  2473.     mov  [eax],ecx
  2474.     pop  ebx
  2475.     mov  cx, [0xC000 + ebx * 2]
  2476.     mov  [eax+4],cx
  2477.     mov  cx, [0xC400 + ebx * 2]
  2478.     mov  [eax+6],cx
  2479.     push eax
  2480.     mov  eax,ebx
  2481.     shl  eax,8
  2482.     add  eax,0x80000+APPDATA.app_name
  2483.     pop  ebx
  2484.     add  ebx,10
  2485.     mov  ecx,11
  2486.     call memmove
  2487.  
  2488.     ; memory usage
  2489.  
  2490.     xor    eax,eax
  2491.     mov    edx,0x100000*16
  2492.     pop    ecx                                   ; get gdt of tss
  2493.     cmp    ecx,1
  2494.     je     os_mem
  2495.     shl    ecx,8
  2496.     mov    edx,[0x80000+ecx+APPDATA.mem_size] ;0x8c
  2497.     mov    eax,std_application_base_address
  2498.     ; eax run base -> edx used memory
  2499.   os_mem:
  2500.     dec    edx
  2501.     mov    [ebx+12],eax
  2502.     mov    [ebx+16],edx
  2503.  
  2504.     ; PID (+30)
  2505.  
  2506.     mov    eax,[esp]
  2507.     shl    eax,5
  2508.     add    eax,0x3000+TASKDATA.pid
  2509.     mov    eax,[eax]
  2510.     mov    [ebx+20],eax
  2511.  
  2512.     ; window position and size
  2513.  
  2514.     mov    esi,[esp]
  2515.     shl    esi,5
  2516.     add    esi,window_data + WDATA.box
  2517.     mov    edi,[esp+4]
  2518.     add    edi,34
  2519.     mov    ecx,4
  2520.     cld
  2521.     rep    movsd
  2522.  
  2523.     ; Process state (+50)
  2524.  
  2525.     mov    eax,[esp]
  2526.     shl    eax,5
  2527.     add    eax,0x3000+TASKDATA.state
  2528.     mov    eax,[eax]
  2529.     mov    [ebx+40],ax
  2530.  
  2531.     ; Window client area box
  2532.  
  2533.     mov    esi,[esp]
  2534.     shl    esi,8
  2535.     add    esi,0x80000+APPDATA.wnd_clientbox
  2536.     lea    edi,[ebx+44]
  2537.     mov    ecx,4
  2538.     rep    movsd
  2539.  
  2540.     ; Window state
  2541.  
  2542.     mov    esi,[esp]
  2543.     shl    esi,5
  2544.     add    esi,window_data + WDATA.box
  2545.     mov    al,[esi+window_data+WDATA.fl_wstate]
  2546.     mov    [edi],al
  2547.  
  2548.     pop    ebx
  2549.     pop    eax
  2550.  
  2551.     ; return number of processes
  2552.  
  2553.     mov    eax,[0x3004]
  2554.     mov    [esp+36],eax
  2555.     ret
  2556.  
  2557.  
  2558.  
  2559.  
  2560. align 4
  2561. sys_clock:
  2562.         cli
  2563.   ; Mikhail Lisovin  xx Jan 2005
  2564.   @@:   mov   al, 10
  2565.         out   0x70, al
  2566.         in    al, 0x71
  2567.         test  al, al
  2568.         jns   @f
  2569.         mov   esi, 1
  2570.         call  delay_ms
  2571.         jmp   @b
  2572.   @@:
  2573.   ; end Lisovin's fix
  2574.  
  2575.         xor   al,al           ; seconds
  2576.         out   0x70,al
  2577.         in    al,0x71
  2578.         movzx ecx,al
  2579.         mov   al,02           ; minutes
  2580.         shl   ecx,16
  2581.         out   0x70,al
  2582.         in    al,0x71
  2583.         movzx edx,al
  2584.         mov   al,04           ; hours
  2585.         shl   edx,8
  2586.         out   0x70,al
  2587.         in    al,0x71
  2588.         add   ecx,edx
  2589.         movzx edx,al
  2590.         add   ecx,edx
  2591.         sti
  2592.         mov   [esp+36],ecx
  2593.         ret
  2594.  
  2595.  
  2596. align 4
  2597.  
  2598. sys_date:
  2599.  
  2600.         cli
  2601.  
  2602.   @@:   mov   al, 10
  2603.         out   0x70, al
  2604.         in    al, 0x71
  2605.         test  al, al
  2606.         jns   @f
  2607.         mov   esi, 1
  2608.         call  delay_ms
  2609.         jmp   @b
  2610.   @@:
  2611.  
  2612.         mov     ch,0
  2613.         mov     al,7            ; date
  2614.         out     0x70,al
  2615.         in      al,0x71
  2616.         mov     cl,al
  2617.         mov     al,8            ; month
  2618.         shl     ecx,16
  2619.         out     0x70,al
  2620.         in      al,0x71
  2621.         mov     ch,al
  2622.         mov     al,9            ; year
  2623.         out     0x70,al
  2624.         in      al,0x71
  2625.         mov     cl,al
  2626.         sti
  2627.         mov     [esp+36],ecx
  2628.         ret
  2629.  
  2630.  
  2631. ; redraw status
  2632.  
  2633. sys_redrawstat:
  2634.  
  2635.     cmp  eax,1
  2636.     jne  no_widgets_away
  2637.  
  2638.     ; buttons away
  2639.  
  2640.     mov   ecx,[0x3000]
  2641.  
  2642.   sys_newba2:
  2643.  
  2644.     mov   edi,[0xfe88]
  2645.     cmp   [edi],dword 0  ; empty button list ?
  2646.     je    end_of_buttons_away
  2647.  
  2648.     movzx ebx,word [edi]
  2649.     inc   ebx
  2650.  
  2651.     mov   eax,edi
  2652.  
  2653.   sys_newba:
  2654.  
  2655.     dec   ebx
  2656.     jz    end_of_buttons_away
  2657.  
  2658.     add   eax,0x10
  2659.     cmp   cx,[eax]
  2660.     jnz   sys_newba
  2661.  
  2662.     push  eax ebx ecx
  2663.     mov   ecx,ebx
  2664.     inc   ecx
  2665.     shl   ecx,4
  2666.     mov   ebx,eax
  2667.     add   eax,0x10
  2668.     call  memmove
  2669.     dec   dword [edi]
  2670.     pop   ecx ebx eax
  2671.  
  2672.     jmp   sys_newba2
  2673.  
  2674.   end_of_buttons_away:
  2675.  
  2676.     ret
  2677.  
  2678.   no_widgets_away:
  2679.  
  2680.     cmp   eax,2
  2681.     jnz   srl1
  2682.  
  2683.     mov   edx,[0x3010]      ; return whole screen draw area for this app
  2684.     add   edx,draw_data-0x3000
  2685.     mov   [edx+RECT.left], 0
  2686.     mov   [edx+RECT.top], 0
  2687.     mov   eax,[0xfe00]
  2688.     mov   [edx+RECT.right],eax
  2689.     mov   eax,[0xfe04]
  2690.     mov   [edx+RECT.bottom],eax
  2691.  
  2692.     mov   edi,[0x3010]
  2693.     or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
  2694.  
  2695.     call  sys_window_mouse
  2696.  
  2697.     ret
  2698.  
  2699.   srl1:
  2700.  
  2701.     ret
  2702.  
  2703.  
  2704. sys_drawwindow:
  2705.  
  2706.     mov   edi,ecx
  2707.     shr   edi,16+8
  2708.     and   edi,15
  2709.  
  2710.     cmp   edi,0   ; type I    - original style
  2711.     jne   nosyswI
  2712.     inc   [mouse_pause]
  2713.     call  [disable_mouse]
  2714.     call  sys_set_window
  2715.     call  [disable_mouse]
  2716.     call  drawwindow_I
  2717.     ;dec   [mouse_pause]
  2718.     ;call   [draw_pointer]
  2719.     ;ret
  2720.     jmp   draw_window_caption.2
  2721.   nosyswI:
  2722.  
  2723.     cmp   edi,1   ; type II   - only reserve area, no draw
  2724.     jne   nosyswII
  2725.     inc   [mouse_pause]
  2726.     call  [disable_mouse]
  2727.     call  sys_set_window
  2728.     call  [disable_mouse]
  2729.     call  sys_window_mouse
  2730.     dec   [mouse_pause]
  2731.     call   [draw_pointer]
  2732.     ret
  2733.   nosyswII:
  2734.  
  2735.     cmp   edi,2   ; type III  - new style
  2736.     jne   nosyswIII
  2737.     inc   [mouse_pause]
  2738.     call  [disable_mouse]
  2739.     call  sys_set_window
  2740.     call  [disable_mouse]
  2741.     call  drawwindow_III
  2742.     ;dec   [mouse_pause]
  2743.     ;call   [draw_pointer]
  2744.     ;ret
  2745.     jmp   draw_window_caption.2
  2746.   nosyswIII:
  2747.  
  2748.     cmp   edi,3   ; type IV - skinned window
  2749.     jne   nosyswIV
  2750.  
  2751.     ; parameter for drawwindow_IV
  2752.     push  0
  2753.     mov   edi, [0x3004]
  2754.     movzx edi, word [0xC400 + edi*2]
  2755.     cmp   edi, [0x3000]
  2756.     jne   @f
  2757.     inc   dword [esp]
  2758.  @@:
  2759.  
  2760.     inc   [mouse_pause]
  2761.     call  [disable_mouse]
  2762.     call  sys_set_window
  2763.     call  [disable_mouse]
  2764.     call  drawwindow_IV
  2765.     ;dec   [mouse_pause]
  2766.     ;call   [draw_pointer]
  2767.     ;ret
  2768.     jmp   draw_window_caption.2
  2769.   nosyswIV:
  2770.  
  2771.     ret
  2772.  
  2773.  
  2774. draw_window_caption:
  2775.         inc     [mouse_pause]
  2776.         call    [disable_mouse]
  2777.  
  2778.         xor     eax,eax
  2779.         mov     edx,[0x3004]
  2780.         movzx   edx,word[0xC400+edx*2]
  2781.         cmp     edx,[0x3000]
  2782.         jne     @f
  2783.         inc     eax
  2784.     @@: mov     edx,[0x3000]
  2785.         shl     edx,5
  2786.         add     edx,window_data
  2787.         movzx   ebx,[edx+WDATA.fl_wstyle]
  2788.         and     bl,0x0F
  2789.         cmp     bl,3
  2790.         jne     .not_style_3
  2791.  
  2792.         push    edx
  2793.         call    drawwindow_IV_caption
  2794.         add     esp,4
  2795.         jmp     .2
  2796.  
  2797.   .not_style_3:
  2798.         cmp     bl,2
  2799.         jne     .not_style_2
  2800.  
  2801.         call    drawwindow_III_caption
  2802.         jmp     .2
  2803.  
  2804.   .not_style_2:
  2805.         cmp     bl,0
  2806.         jne     .2
  2807.  
  2808.         call    drawwindow_I_caption
  2809.  
  2810. ;--------------------------------------------------------------
  2811.   .2:   ;jmp     @f
  2812.         mov     edi,[0x3000]
  2813.         shl     edi,5
  2814.         test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
  2815.         jz      @f
  2816.         mov     ecx,[edi*8+0x80000+APPDATA.wnd_caption]
  2817.         or      ecx,ecx
  2818.         jz      @f
  2819.         add     ecx,[edi+twdw+TASKDATA.mem_start]
  2820.  
  2821.         movzx   eax,[edi+window_data+WDATA.fl_wstyle]
  2822.         and     al,0x0F
  2823.         cmp     al,3
  2824.         jne     .not_skinned
  2825.  
  2826.         mov     ebp,[edi+window_data+WDATA.box.left-2]
  2827.         mov     bp,word[edi+window_data+WDATA.box.top]
  2828.         movzx   eax,word[edi+window_data+WDATA.box.width]
  2829.         sub     ax,[_skinmargins.left]
  2830.         sub     ax,[_skinmargins.right]
  2831.         cwde
  2832.         cdq
  2833.         mov     ebx,6
  2834.         idiv    ebx
  2835.         or      eax,eax
  2836.         js      @f
  2837.         mov     edx,eax
  2838.         mov     eax,dword[_skinmargins.left-2]
  2839.         mov     ax,word[_skinh]
  2840.         sub     ax,[_skinmargins.bottom]
  2841.         sub     ax,[_skinmargins.top]
  2842.         sar     ax,1
  2843.         adc     ax,0
  2844.         add     ax,[_skinmargins.top]
  2845.         add     ax,-3
  2846.         add     eax,ebp
  2847.         jmp     .dodraw
  2848.  
  2849.   .not_skinned:
  2850.         cmp     al,1
  2851.         je      @f
  2852.  
  2853.         mov     ebp,[edi+window_data+WDATA.box.left-2]
  2854.         mov     bp,word[edi+window_data+WDATA.box.top]
  2855.         movzx   eax,word[edi+window_data+WDATA.box.width]
  2856.         sub     eax,16
  2857.         cwde
  2858.         cdq
  2859.         mov     ebx,6
  2860.         idiv    ebx
  2861.         or      eax,eax
  2862.         js      @f
  2863.         mov     edx,eax
  2864.         mov     eax,0x00080007
  2865.         add     eax,ebp
  2866. .dodraw:
  2867.         mov     ebx,[common_colours+16];0x00FFFFFF
  2868.         or      ebx, 0x80000000
  2869.         xor     edi,edi
  2870.         call    dtext
  2871.  
  2872.     @@:
  2873. ;--------------------------------------------------------------
  2874.         dec     [mouse_pause]
  2875.         call    [draw_pointer]
  2876.         ret
  2877.  
  2878. iglobal
  2879. align 4
  2880. window_topleft dd \
  2881.   1, 21,\
  2882.   0,  0,\
  2883.   5, 20,\
  2884.   5,  ?
  2885. endg
  2886.  
  2887. set_window_clientbox:
  2888.         push    eax ecx edi
  2889.  
  2890.         mov     eax,[_skinh]
  2891.         mov     [window_topleft+4*7],eax
  2892.  
  2893.         mov     ecx,edi
  2894.         sub     edi,window_data
  2895.         shl     edi,3
  2896.         test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
  2897.         jz      @f
  2898.  
  2899.         movzx   eax,[ecx+WDATA.fl_wstyle]
  2900.         and     eax,0x0F
  2901.         mov     eax,[eax*8+window_topleft+0]
  2902.         mov     [edi+0x80000+APPDATA.wnd_clientbox.left],eax
  2903.         shl     eax,1
  2904.         neg     eax
  2905.         add     eax,[ecx+WDATA.box.width]
  2906.         mov     [edi+0x80000+APPDATA.wnd_clientbox.width],eax
  2907.  
  2908.         movzx   eax,[ecx+WDATA.fl_wstyle]
  2909.         and     eax,0x0F
  2910.         push    [eax*8+window_topleft+0]
  2911.         mov     eax,[eax*8+window_topleft+4]
  2912.         mov     [edi+0x80000+APPDATA.wnd_clientbox.top],eax
  2913.         neg     eax
  2914.         sub     eax,[esp]
  2915.         add     eax,[ecx+WDATA.box.height]
  2916.         mov     [edi+0x80000+APPDATA.wnd_clientbox.height],eax
  2917.         add     esp,4
  2918.  
  2919.         pop     edi ecx eax
  2920.         ret
  2921.     @@:
  2922.         xor     eax,eax
  2923.         mov     [edi+0x80000+APPDATA.wnd_clientbox.left],eax
  2924.         mov     [edi+0x80000+APPDATA.wnd_clientbox.top],eax
  2925.         mov     eax,[ecx+WDATA.box.width]
  2926.         mov     [edi+0x80000+APPDATA.wnd_clientbox.width],eax
  2927.         mov     eax,[ecx+WDATA.box.height]
  2928.         mov     [edi+0x80000+APPDATA.wnd_clientbox.height],eax
  2929.  
  2930.         pop     edi ecx eax
  2931.         ret
  2932.  
  2933. sys_set_window:
  2934.  
  2935.     mov   edi,[0x3000]
  2936.     shl   edi,5
  2937.     add   edi,window_data
  2938.  
  2939.     ; colors
  2940.     mov   [edi+WDATA.cl_workarea],ecx
  2941.     mov   [edi+WDATA.cl_titlebar],edx
  2942.     mov   [edi+WDATA.cl_frames],esi
  2943.  
  2944.     ; check flag (?)
  2945.     test  [edi+WDATA.fl_wdrawn],1
  2946.     jnz   newd
  2947.  
  2948.     push  eax
  2949.     mov   eax,[timer_ticks] ;[0xfdf0]
  2950.     add   eax,100
  2951.     mov   [new_window_starting],eax
  2952.     pop   eax
  2953.  
  2954.     mov   word[edi+WDATA.box.width],ax
  2955.     mov   word[edi+WDATA.box.height],bx
  2956.     sar   eax,16
  2957.     sar   ebx,16
  2958.     mov   word[edi+WDATA.box.left],ax
  2959.     mov   word[edi+WDATA.box.top],bx
  2960.  
  2961.     call  check_window_position
  2962.  
  2963.     call  set_window_clientbox
  2964.  
  2965.     push  ecx esi edi               ; save for window fullscreen/resize
  2966.     ;mov   esi,edi
  2967.  
  2968.         mov     cl,[edi+WDATA.fl_wstyle]
  2969.  
  2970.     sub   edi,window_data
  2971.     shl   edi,3
  2972.     add   edi,0x80000
  2973.  
  2974.         and     cl,0x0F
  2975.         mov     [edi+APPDATA.wnd_caption],0
  2976.         cmp     cl,3
  2977.         jne     @f
  2978.         mov     [edi+APPDATA.wnd_caption],esi
  2979.     @@: mov     esi,[esp+0]
  2980.  
  2981.     add   edi, APPDATA.saved_box
  2982.         movsd
  2983.         movsd
  2984.         movsd
  2985.         movsd
  2986.     pop   edi esi ecx
  2987.  
  2988.     push  eax ebx ecx edx
  2989. ;;;    mov   eax, 1
  2990. ;;;    call  delay_hs
  2991.     mov   eax, [edi+WDATA.box.left]
  2992.     mov   ebx, [edi+WDATA.box.top]
  2993.     mov   ecx, [edi+WDATA.box.width]
  2994.     mov   edx, [edi+WDATA.box.height]
  2995.     add   ecx, eax
  2996.     add   edx, ebx
  2997.     call  calculatescreen
  2998.     pop   edx ecx ebx eax
  2999.  
  3000.     mov   [0xf400],byte 0           ; empty keyboard buffer
  3001.     mov   [0xf500],byte 0           ; empty button buffer
  3002.  
  3003.   newd:
  3004.     mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
  3005.     mov   edx,edi
  3006.  
  3007.     ret
  3008.  
  3009. syscall_windowsettings:
  3010.  
  3011.   .set_window_caption:
  3012.         dec     eax     ; subfunction #1 - set window caption
  3013.         jnz     .get_window_caption
  3014.  
  3015.         ; NOTE: only window owner thread can set its caption,
  3016.         ;       so there's no parameter for PID/TID
  3017.  
  3018.         mov     edi,[0x3000]
  3019.         shl     edi,5
  3020.  
  3021.         ; have to check if caption is within application memory limit
  3022.         ; check is trivial, and if application resizes its memory,
  3023.         ;   caption still can become over bounds
  3024. ; diamond, 31.10.2006: check removed because with new memory manager
  3025. ; there can be valid data after APPDATA.mem_size bound
  3026. ;        mov     ecx,[edi*8+0x80000+APPDATA.mem_size]
  3027. ;        add     ecx,255 ; max caption length
  3028. ;        cmp     ebx,ecx
  3029. ;        ja      .exit_fail
  3030.  
  3031.         mov     [edi*8+0x80000+APPDATA.wnd_caption],ebx
  3032.         or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
  3033.  
  3034.         call    draw_window_caption
  3035.  
  3036.         xor     eax,eax ; eax = 0 (success)
  3037.         ret
  3038.  
  3039.   .get_window_caption:
  3040.         dec     eax     ; subfunction #2 - get window caption
  3041.         jnz     .exit_fail
  3042.  
  3043.         ; not implemented yet
  3044.  
  3045.   .exit_fail:
  3046.         xor     eax,eax
  3047.         inc     eax     ; eax = 1 (fail)
  3048.         ret
  3049.  
  3050.  
  3051. sys_window_move:
  3052.  
  3053.         mov     edi,[0x3000]
  3054.         shl     edi,5
  3055.         add     edi,window_data
  3056.  
  3057.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  3058.         jnz     .window_move_return
  3059.  
  3060.         push    dword [edi + WDATA.box.left]  ; save old coordinates
  3061.         push    dword [edi + WDATA.box.top]
  3062.         push    dword [edi + WDATA.box.width]
  3063.         push    dword [edi + WDATA.box.height]
  3064.  
  3065.         cmp   eax,-1                  ; set new position and size
  3066.         je    .no_x_reposition
  3067.         mov     [edi + WDATA.box.left], eax
  3068.       .no_x_reposition:
  3069.         cmp   ebx,-1
  3070.         je    .no_y_reposition
  3071.         mov     [edi + WDATA.box.top], ebx
  3072.       .no_y_reposition:
  3073.  
  3074.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  3075.         jnz     .no_y_resizing
  3076.  
  3077.         cmp   ecx,-1
  3078.         je    .no_x_resizing
  3079.         mov     [edi + WDATA.box.width], ecx
  3080.       .no_x_resizing:
  3081.         cmp   edx,-1
  3082.         je    .no_y_resizing
  3083.         mov     [edi + WDATA.box.height], edx
  3084.       .no_y_resizing:
  3085.  
  3086.         call  check_window_position
  3087.         call  set_window_clientbox
  3088.  
  3089.         pushad                       ; save for window fullscreen/resize
  3090.         mov   esi,edi
  3091.         sub   edi,window_data
  3092.         shr   edi,5
  3093.         shl   edi,8
  3094.         add   edi, 0x80000 + APPDATA.saved_box
  3095.         mov   ecx,4
  3096.         cld
  3097.         rep   movsd
  3098.         popad
  3099.  
  3100.         pushad                       ; calculcate screen at new position
  3101.         mov   eax, [edi + WDATA.box.left]
  3102.         mov   ebx, [edi + WDATA.box.top]
  3103.         mov   ecx, [edi + WDATA.box.width]
  3104.         mov   edx, [edi + WDATA.box.height]
  3105.         add   ecx,eax
  3106.         add   edx,ebx
  3107.  
  3108.         call  calculatescreen
  3109.         popad
  3110.  
  3111.         pop   edx                   ; calculcate screen at old position
  3112.         pop   ecx
  3113.         pop   ebx
  3114.         pop   eax
  3115.         add   ecx,eax
  3116.         add   edx,ebx
  3117.         mov   [dlx],eax             ; save for drawlimits
  3118.         mov   [dly],ebx
  3119.         mov   [dlxe],ecx
  3120.         mov   [dlye],edx
  3121.         call  calculatescreen
  3122.  
  3123.         mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
  3124.  
  3125.         mov   eax,edi               ; redraw screen at old position
  3126.         xor   esi,esi
  3127.         call  redrawscreen
  3128.  
  3129.         mov   [0xfff5],byte 0 ; mouse pointer
  3130.         mov   [0xfff4],byte 0 ; no mouse under
  3131.         mov   [0xfb44],byte 0 ; react to mouse up/down
  3132.  
  3133.         mov   ecx,10          ; wait 1/10 second
  3134.       .wmrl3:
  3135.         call  [draw_pointer]
  3136.         mov   eax,1
  3137.         call  delay_hs
  3138.         loop  .wmrl3
  3139.  
  3140.         mov   [window_move_pr],0
  3141.  
  3142.       .window_move_return:
  3143.  
  3144.         ret
  3145.  
  3146. ;type_background_1:
  3147. ;    cmp   [0xfff0],byte 0               ; background update ?
  3148. ;    jz    temp_nobackgr
  3149. ;    mov   [0xfff0],byte 2
  3150. ;    call  change_task
  3151. ;    mov   [draw_data+32+0],dword 0
  3152. ;    mov   [draw_data+32+4],dword 0
  3153. ;    mov   eax,[0xfe00]
  3154. ;    mov   ebx,[0xfe04]
  3155. ;    mov   [draw_data+32+8],eax
  3156. ;    mov   [draw_data+32+12],ebx
  3157. ;    call  drawbackground
  3158. ;    mov   [0xfff0],byte 0
  3159. ;    mov   [0xfff4],byte 0
  3160. ;temp_nobackgr:
  3161. ;    ret
  3162.  
  3163. uglobal
  3164.   window_move_pr   dd  0x0
  3165.   window_move_eax  dd  0x0
  3166.   window_move_ebx  dd  0x0
  3167.   window_move_ecx  dd  0x0
  3168.   window_move_edx  dd  0x0
  3169. endg
  3170.  
  3171. ;ok - 100% work
  3172. ;nt - not tested
  3173. ;---------------------------------------------------------------------------------------------
  3174. ;eax
  3175. ;0 - task switch counter. Ret switch counter in eax. Block. ok.
  3176. ;1 - change task. Ret nothing. Block. ok.
  3177. ;2 - performance control
  3178. ; ebx
  3179. ; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
  3180. ; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
  3181. ; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
  3182. ; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
  3183. ; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
  3184. ;eax
  3185. ;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  3186. ;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  3187. ;---------------------------------------------------------------------------------------------
  3188. sys_sheduler: ;noname & halyavin
  3189.     cmp eax,0
  3190.     je shed_counter
  3191.     cmp eax,2
  3192.     je perf_control
  3193.     cmp eax,3
  3194.     je rdmsr_instr
  3195.     cmp eax,4
  3196.     je wrmsr_instr
  3197.     cmp eax,1
  3198.     jne not_supported
  3199.     call change_task ;delay,0
  3200. ret
  3201. shed_counter:
  3202.     mov eax,[context_counter]
  3203.     mov [esp+36],eax
  3204. not_supported:
  3205. ret
  3206. perf_control:
  3207.     inc eax ;now eax=3
  3208.     cmp ebx,eax
  3209.     je cache_disable
  3210.     dec eax
  3211.     cmp ebx,eax
  3212.     je cache_enable
  3213.     dec eax
  3214.     cmp ebx,eax
  3215.     je is_cache_enabled
  3216.     dec eax
  3217.     cmp ebx,eax
  3218.     je modify_pce
  3219. ret
  3220.  
  3221. rdmsr_instr:
  3222. ;now counter in ecx
  3223. ;(edx:eax) esi:edi => edx:esi
  3224. mov eax,esi
  3225. rdmsr
  3226. mov [esp+36],eax
  3227. mov [esp+24],edx ;ret in ebx?
  3228. ret
  3229.  
  3230. wrmsr_instr:
  3231. ;now counter in ecx
  3232. ;(edx:eax) esi:edi => edx:esi
  3233. mov eax,esi
  3234. wrmsr
  3235. mov [esp+36],eax
  3236. mov [esp+24],edx ;ret in ebx?
  3237. ret
  3238.  
  3239. cache_disable:
  3240.        mov eax,cr0
  3241.        or  eax,01100000000000000000000000000000b
  3242.        mov cr0,eax
  3243.        wbinvd ;set MESI
  3244. ret
  3245.  
  3246. cache_enable:
  3247.        mov eax,cr0
  3248.        and eax,10011111111111111111111111111111b
  3249.        mov cr0,eax
  3250. ret
  3251.  
  3252. is_cache_enabled:
  3253.        mov eax,cr0
  3254.        mov ebx,eax
  3255.        and eax,01100000000000000000000000000000b
  3256.        jz cache_disabled
  3257.        mov [esp+36],ebx
  3258. cache_disabled:
  3259.        mov dword [esp+36],eax ;0
  3260. ret
  3261.  
  3262. modify_pce:
  3263.        mov eax,cr4
  3264. ;       mov ebx,0
  3265. ;       or  bx,100000000b ;pce
  3266. ;       xor eax,ebx ;invert pce
  3267.        bts eax,8 ;pce=cr4[8]
  3268.        mov cr4,eax
  3269.        mov [esp+36],eax
  3270. ret
  3271. ;---------------------------------------------------------------------------------------------
  3272.  
  3273.  
  3274. ; check if pixel is allowed to be drawn
  3275.  
  3276. checkpixel:
  3277.         push eax edx
  3278.  
  3279.         mov  edx,[0xfe00]     ; screen x size
  3280.         inc  edx
  3281.         imul edx, ebx
  3282.         mov  dl, [eax+edx+display_data] ; lea eax, [...]
  3283.  
  3284.         xor  ecx, ecx
  3285.         mov  eax, [CURRENT_TASK]
  3286.         cmp  al, dl
  3287.         setne cl
  3288.  
  3289.         pop  edx eax
  3290.         ret
  3291.  
  3292. uglobal
  3293.   mouse_active  db  0
  3294. endg
  3295. iglobal
  3296.   cpustring db '/RD/1/CPU',0
  3297. endg
  3298.  
  3299. uglobal
  3300. background_defined    db    0    ; diamond, 11.04.2006
  3301. endg
  3302.  
  3303. align 4
  3304. ; check misc
  3305.  
  3306. checkmisc:
  3307.  
  3308.     cmp   [ctrl_alt_del], 1
  3309.     jne   nocpustart
  3310.     mov   ebp, cpustring
  3311.     lea   esi,[ebp+6]
  3312.     xor   ebx,ebx               ; no parameters
  3313.     xor   edx,edx               ; no flags
  3314.     call  fs_RamdiskExecute.flags
  3315.     mov   [ctrl_alt_del], 0
  3316.   nocpustart:
  3317.     cmp   [mouse_active], 1
  3318.     jne   mouse_not_active
  3319.     mov   [mouse_active], 0
  3320.     xor   edi, edi
  3321.     mov   ecx, [0x3004]
  3322.    set_mouse_event:
  3323.     add   edi, 256
  3324.     or    [edi+0x80000+APPDATA.event_mask], dword 00100000b
  3325.     loop  set_mouse_event
  3326.   mouse_not_active:
  3327.  
  3328.  
  3329.     cmp   [0xfff0],byte 0               ; background update ?
  3330.     jz    nobackgr
  3331.     cmp    [background_defined], 0
  3332.     jz    nobackgr
  3333.     mov   [0xfff0],byte 2
  3334.     call  change_task
  3335.         mov   [draw_data+32 + RECT.left],dword 0
  3336.         mov   [draw_data+32 + RECT.top],dword 0
  3337.     mov   eax,[0xfe00]
  3338.     mov   ebx,[0xfe04]
  3339.         mov   [draw_data+32 + RECT.right],eax
  3340.         mov   [draw_data+32 + RECT.bottom],ebx
  3341.     call  drawbackground
  3342.     mov   [0xfff0],byte 0
  3343.     mov   [0xfff4],byte 0
  3344.  
  3345.   nobackgr:
  3346.  
  3347.  
  3348.     ; system shutdown request
  3349.  
  3350.     cmp  [0xFF00],byte 0
  3351.     je   noshutdown
  3352.  
  3353.     mov  edx,[shutdown_processes]
  3354.     sub  dl,2
  3355.  
  3356.     cmp  [0xff00],dl
  3357.     jne  no_mark_system_shutdown
  3358.  
  3359.     mov   edx,0x3040
  3360.     movzx ecx,byte [0xff00]
  3361.     add   ecx,5
  3362.   markz:
  3363.     mov   [edx+TASKDATA.state],byte 3
  3364.     add   edx,0x20
  3365.     loop  markz
  3366.  
  3367.   no_mark_system_shutdown:
  3368.  
  3369.     call [disable_mouse]
  3370.  
  3371.     dec  byte [0xff00]
  3372.  
  3373.     cmp  [0xff00],byte 0
  3374.     je   system_shutdown
  3375.  
  3376.   noshutdown:
  3377.  
  3378.  
  3379.     mov   eax,[0x3004]                  ; termination
  3380.     mov   ebx,0x3020+TASKDATA.state
  3381.     mov   esi,1
  3382.  
  3383.   newct:
  3384.     mov   cl,[ebx]
  3385.     cmp   cl,byte 3
  3386.     jz    terminate
  3387.     cmp   cl,byte 4
  3388.     jz    terminate
  3389.  
  3390.     add   ebx,0x20
  3391.     inc   esi
  3392.     dec   eax
  3393.     jnz   newct
  3394.  
  3395.     ret
  3396.  
  3397.  
  3398.  
  3399.  
  3400. ; redraw screen
  3401.  
  3402. redrawscreen:
  3403.  
  3404. ; eax , if process window_data base is eax, do not set flag/limits
  3405.  
  3406.          pushad
  3407.          push  eax
  3408.  
  3409. ;;;         mov   eax,2
  3410. ;;;         call  delay_hs
  3411.  
  3412.          ;mov   ecx,0               ; redraw flags for apps
  3413.          xor   ecx,ecx
  3414.        newdw2:
  3415.  
  3416.          inc   ecx
  3417.          push  ecx
  3418.  
  3419.          mov   eax,ecx
  3420.          shl   eax,5
  3421.          add   eax,window_data
  3422.  
  3423.          cmp   eax,[esp+4]
  3424.          je    not_this_task
  3425.                                    ; check if window in redraw area
  3426.          mov   edi,eax
  3427.  
  3428.          cmp   ecx,1               ; limit for background
  3429.          jz    bgli
  3430.  
  3431.          mov   eax, [edi + WDATA.box.left]
  3432.          mov   ebx, [edi + WDATA.box.top]
  3433.          mov   ecx, [edi + WDATA.box.width]
  3434.          mov   edx, [edi + WDATA.box.height]
  3435.          add   ecx,eax
  3436.          add   edx,ebx
  3437.  
  3438.          mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
  3439.          cmp   ecx,ebx
  3440.          jb    ricino
  3441.  
  3442.          mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
  3443.          cmp   ecx,eax
  3444.          jb    ricino
  3445.  
  3446.          mov   eax, [edi + WDATA.box.left]
  3447.          mov   ebx, [edi + WDATA.box.top]
  3448.          mov   ecx, [edi + WDATA.box.width]
  3449.          mov   edx, [edi + WDATA.box.height]
  3450.          add   ecx, eax
  3451.          add   edx, ebx
  3452.  
  3453.          mov   eax,[dly]    ; eax = area y start     edx = window y end
  3454.          cmp   edx,eax
  3455.          jb    ricino
  3456.  
  3457.          mov   eax,[dlx]    ; eax = area x start     ecx = window x end
  3458.          cmp   ecx,eax
  3459.          jb    ricino
  3460.  
  3461.         bgli:
  3462.  
  3463.          cmp   edi,esi
  3464.          jz    ricino
  3465.  
  3466.          mov   eax,edi
  3467.          add   eax,draw_data-window_data
  3468.  
  3469.          mov   ebx,[dlx]          ; set limits
  3470.          mov   [eax + RECT.left], ebx
  3471.          mov   ebx,[dly]
  3472.          mov   [eax + RECT.top], ebx
  3473.          mov   ebx,[dlxe]
  3474.          mov   [eax + RECT.right], ebx
  3475.          mov   ebx,[dlye]
  3476.          mov   [eax + RECT.bottom], ebx
  3477.  
  3478.          sub   eax,draw_data-window_data
  3479.  
  3480.          cmp   ecx,1
  3481.          jne   nobgrd
  3482.          cmp   esi,1
  3483.          je    newdw8
  3484.          call  drawbackground
  3485.  
  3486.        newdw8:
  3487.        nobgrd:
  3488.  
  3489.          mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
  3490.  
  3491.        ricino:
  3492.  
  3493.        not_this_task:
  3494.  
  3495.          pop   ecx
  3496.  
  3497.          cmp   ecx,[0x3004]
  3498.          jle   newdw2
  3499.  
  3500.          pop  eax
  3501.          popad
  3502.  
  3503.          ret
  3504.  
  3505. calculatebackground:   ; background
  3506.  
  3507.         ; all black
  3508.  
  3509.         mov   [display_data-8],dword 4      ; size x
  3510.         mov   [display_data-4],dword 2      ; size y
  3511.  
  3512.         mov   edi, 0x300000                 ; set background to black
  3513.         xor   eax, eax
  3514.         mov   ecx, 0x0fff00 / 4
  3515.         cld
  3516.         rep   stosd
  3517.  
  3518.         mov   edi,display_data              ; set os to use all pixels
  3519.         mov   eax,0x01010101
  3520.         mov   ecx,0x1fff00 / 4
  3521.         rep   stosd
  3522.  
  3523.         mov   byte [0xFFF0], 0              ; do not draw background!
  3524.  
  3525.         ret
  3526.  
  3527. uglobal
  3528.   imax    dd 0x0
  3529. endg
  3530.  
  3531.  
  3532.  
  3533. delay_ms:     ; delay in 1/1000 sec
  3534.  
  3535.  
  3536.         push  eax
  3537.         push  ecx
  3538.  
  3539.         mov   ecx,esi
  3540.         ; <CPU clock fix by Sergey Kuzmin aka Wildwest>
  3541.         imul  ecx, 33941
  3542.         shr   ecx, 9
  3543.         ; </CPU clock fix>
  3544.  
  3545.         in    al,0x61
  3546.         and   al,0x10
  3547.         mov   ah,al
  3548.         cld
  3549.  
  3550.  cnt1:  in    al,0x61
  3551.         and   al,0x10
  3552.         cmp   al,ah
  3553.         jz    cnt1
  3554.  
  3555.         mov   ah,al
  3556.         loop  cnt1
  3557.  
  3558.         pop   ecx
  3559.         pop   eax
  3560.  
  3561.         ret
  3562.  
  3563.  
  3564. set_app_param:
  3565.         push edi
  3566.  
  3567.         mov  edi,[0x3010]
  3568.         mov  [edi+TASKDATA.event_mask],eax
  3569.  
  3570.         pop  edi
  3571.         ret
  3572.  
  3573.  
  3574.  
  3575. delay_hs:     ; delay in 1/100 secs
  3576.         push  eax
  3577.         push  ecx
  3578.         push  edx
  3579.  
  3580.         mov   edx,[timer_ticks]
  3581.         add   edx,eax
  3582.  
  3583.       newtic:
  3584.         mov   ecx,[timer_ticks]
  3585.         cmp   edx,ecx
  3586.         jbe   zerodelay
  3587.  
  3588.         call  change_task
  3589.  
  3590.         jmp   newtic
  3591.  
  3592.       zerodelay:
  3593.         pop   edx
  3594.         pop   ecx
  3595.         pop   eax
  3596.  
  3597.         ret
  3598.  
  3599.  
  3600. memmove:       ; memory move in bytes
  3601.  
  3602. ; eax = from
  3603. ; ebx = to
  3604. ; ecx = no of bytes
  3605.     test ecx, ecx
  3606.     jle  .ret
  3607.  
  3608.  
  3609.     push esi edi ecx
  3610.  
  3611.     mov  edi, ebx
  3612.     mov  esi, eax
  3613.  
  3614.     test ecx, not 11b
  3615.     jz   @f
  3616.  
  3617.     push ecx
  3618.     shr  ecx, 2
  3619.     rep  movsd
  3620.     pop  ecx
  3621.     and  ecx, 11b
  3622.     jz   .finish
  3623.   @@:
  3624.     rep  movsb
  3625.  
  3626.   .finish:
  3627.     pop  ecx edi esi
  3628.   .ret:
  3629.     ret
  3630.  
  3631.  
  3632. ; <diamond> Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
  3633. ;align 4
  3634. ;
  3635. ;read_floppy_file:
  3636. ;
  3637. ;; as input
  3638. ;;
  3639. ;; eax pointer to file
  3640. ;; ebx file lenght
  3641. ;; ecx start 512 byte block number
  3642. ;; edx number of blocks to read
  3643. ;; esi pointer to return/work area (atleast 20 000 bytes)
  3644. ;;
  3645. ;;
  3646. ;; on return
  3647. ;;
  3648. ;; eax = 0 command succesful
  3649. ;;       1 no fd base and/or partition defined
  3650. ;;       2 yet unsupported FS
  3651. ;;       3 unknown FS
  3652. ;;       4 partition not defined at hd
  3653. ;;       5 file not found
  3654. ;; ebx = size of file
  3655. ;
  3656. ;     mov   edi,[0x3010]
  3657. ;     add   edi,0x10
  3658. ;     add   esi,[edi]
  3659. ;     add   eax,[edi]
  3660. ;
  3661. ;     pushad
  3662. ;     mov  edi,esi
  3663. ;     add  edi,1024
  3664. ;     mov  esi,0x100000+19*512
  3665. ;     sub  ecx,1
  3666. ;     shl  ecx,9
  3667. ;     add  esi,ecx
  3668. ;     shl  edx,9
  3669. ;     mov  ecx,edx
  3670. ;     cld
  3671. ;     rep  movsb
  3672. ;     popad
  3673. ;
  3674. ;     mov   [esp+36],eax
  3675. ;     mov   [esp+24],ebx
  3676. ;     ret
  3677.  
  3678.  
  3679.  
  3680. align 4
  3681.  
  3682. sys_programirq:
  3683.  
  3684.     mov   edi,[0x3010]
  3685.     add   eax,[edi+TASKDATA.mem_start]
  3686.  
  3687.     cmp   ebx,16
  3688.     jae   .not_owner
  3689.     mov   edi,[0x3010]
  3690.     mov   edi,[edi+TASKDATA.pid]
  3691.     cmp   edi,[irq_owner+ebx*4]
  3692.     je    spril1
  3693. .not_owner:
  3694.     mov   [esp+36],dword 1
  3695.     ret
  3696.   spril1:
  3697.  
  3698.     mov   esi,eax
  3699.     shl   ebx,6
  3700.     add   ebx,irq00read
  3701.     mov   edi,ebx
  3702.     mov   ecx,16
  3703.     cld
  3704.     rep   movsd
  3705.     mov   [esp+36],dword 0
  3706.     ret
  3707.  
  3708.  
  3709. align 4
  3710.  
  3711. get_irq_data:
  3712.      cmp   eax,16
  3713.      jae   .not_owner
  3714.      mov   edx,eax           ; check for correct owner
  3715.      shl   edx,2
  3716.      add   edx,irq_owner
  3717.      mov   edx,[edx]
  3718.      mov   edi,[0x3010]
  3719.      mov   edi,[edi+TASKDATA.pid]
  3720.      cmp   edx,edi
  3721.      je    gidril1
  3722. .not_owner:
  3723.      mov   [esp+32],dword 2     ; ecx=2
  3724.      ret
  3725.  
  3726.   gidril1:
  3727.  
  3728.      mov   ebx,eax
  3729.      shl   ebx,12
  3730.      add   ebx,0x2e0000
  3731.      mov   eax,[ebx]
  3732.      mov   ecx,1
  3733.      test  eax,eax
  3734.      jz    gid1
  3735.  
  3736.      dec   eax
  3737.      mov   esi,ebx
  3738.      mov   [ebx],eax
  3739.      movzx ebx,byte [ebx+0x10]
  3740.      add   esi,0x10
  3741.      mov   edi,esi
  3742.      inc   esi
  3743.      mov   ecx,4000 / 4
  3744.      cld
  3745.      rep   movsd
  3746. ;     xor   ecx,ecx     ; as result of 'rep' ecx=0
  3747.    gid1:
  3748.      mov   [esp+36],eax
  3749.      mov   [esp+32],ecx
  3750.      mov   [esp+24],ebx
  3751.      ret
  3752.  
  3753.  
  3754. set_io_access_rights:
  3755.  
  3756.      pushad
  3757.  
  3758.      mov   edi,[0x3000]
  3759.      imul  edi,tss_step
  3760.      add   edi,tss_data+128
  3761. ;     add   edi,128
  3762.  
  3763.      mov   ecx,eax
  3764.      and   ecx,7    ; offset in byte
  3765.  
  3766.      shr   eax,3    ; number of byte
  3767.      add   edi,eax
  3768.  
  3769.      mov   ebx,1
  3770.      shl   ebx,cl
  3771.  
  3772.      cmp   ebp,0                ; enable access - ebp = 0
  3773.      jne   siar1
  3774.  
  3775.      not   ebx
  3776.      and   [edi],byte bl
  3777.  
  3778.      popad
  3779.  
  3780.      ret
  3781.  
  3782.    siar1:
  3783.  
  3784.      or    [edi],byte bl        ; disable access - ebp = 1
  3785.  
  3786.      popad
  3787.  
  3788.      ret
  3789.  
  3790. r_f_port_area:
  3791.  
  3792.      test  eax, eax
  3793.      jnz   free_port_area
  3794. ;     je    r_port_area
  3795. ;     jmp   free_port_area
  3796.  
  3797. ;   r_port_area:
  3798.  
  3799.      pushad
  3800.  
  3801.      cmp   ebx,ecx            ; beginning > end ?
  3802.      ja    rpal1
  3803.      cmp   ecx,65536
  3804.      jae   rpal1
  3805.      mov   esi,[0x2d0000]
  3806.      test  esi,esi            ; no reserved areas ?
  3807.      je    rpal2
  3808.      cmp   esi,255            ; max reserved
  3809.      jae   rpal1
  3810.    rpal3:
  3811.      mov   edi,esi
  3812.      shl   edi,4
  3813.      add   edi,0x2d0000
  3814.      cmp   ebx,[edi+8]
  3815.      ja    rpal4
  3816.      cmp   ecx,[edi+4]
  3817.      jae   rpal1
  3818. ;     jb    rpal4
  3819. ;     jmp   rpal1
  3820.    rpal4:
  3821.  
  3822.      dec   esi
  3823.      jnz   rpal3
  3824.      jmp   rpal2
  3825.    rpal1:
  3826.      popad
  3827.      mov   eax,1
  3828.      ret
  3829.  
  3830.    rpal2:
  3831.      popad
  3832.  
  3833.  
  3834.      ; enable port access at port IO map
  3835.      cli
  3836.      pushad                        ; start enable io map
  3837.  
  3838.      cmp   ecx,65536 ;16384
  3839.      jae   no_unmask_io ; jge
  3840.  
  3841.      mov   eax,ebx
  3842.  
  3843.    new_port_access:
  3844.  
  3845.      pushad
  3846.  
  3847.      xor   ebp,ebp                ; enable - eax = port
  3848.      call  set_io_access_rights
  3849.  
  3850.      popad
  3851.  
  3852.      inc   eax
  3853.      cmp   eax,ecx
  3854.      jbe   new_port_access
  3855.  
  3856.    no_unmask_io:
  3857.  
  3858.      popad                         ; end enable io map
  3859.      sti
  3860.  
  3861.      mov   edi,[0x2d0000]
  3862.      add   edi,1
  3863.      mov   [0x2d0000],edi
  3864.      shl   edi,4
  3865.      add   edi,0x2d0000
  3866.      mov   esi,[0x3010]
  3867.      mov   esi,[esi+TASKDATA.pid]
  3868.      mov   [edi],esi
  3869.      mov   [edi+4],ebx
  3870.      mov   [edi+8],ecx
  3871.  
  3872.      xor   eax, eax
  3873.      ret
  3874.  
  3875. free_port_area:
  3876.  
  3877.      pushad
  3878.  
  3879.      mov   esi,[0x2d0000]     ; no reserved areas ?
  3880.      test  esi,esi
  3881.      je    frpal2
  3882.      mov   edx,[0x3010]
  3883.      mov   edx,[edx+TASKDATA.pid]
  3884.    frpal3:
  3885.      mov   edi,esi
  3886.      shl   edi,4
  3887.      add   edi,0x2d0000
  3888.      cmp   edx,[edi]
  3889.      jne   frpal4
  3890.      cmp   ebx,[edi+4]
  3891.      jne   frpal4
  3892.      cmp   ecx,[edi+8]
  3893.      jne   frpal4
  3894.      jmp   frpal1
  3895.    frpal4:
  3896.      dec   esi
  3897.      jnz   frpal3
  3898.    frpal2:
  3899.      popad
  3900.      mov   eax,1
  3901.      ret
  3902.    frpal1:
  3903.      mov   ecx,256
  3904.      sub   ecx,esi
  3905.      shl   ecx,4
  3906.      mov   esi,edi
  3907.      add   esi,16
  3908.      cld
  3909.      rep   movsb
  3910.  
  3911.      dec   dword [0x2d0000]
  3912.  
  3913.      popad
  3914.  
  3915.  
  3916.      ; disable port access at port IO map
  3917.  
  3918.      pushad                        ; start disable io map
  3919.  
  3920.      cmp   ecx,65536 ;16384
  3921.      jge   no_mask_io
  3922.  
  3923.      mov   eax,ebx
  3924.  
  3925.    new_port_access_disable:
  3926.  
  3927.      pushad
  3928.  
  3929.      mov   ebp,1                  ; disable - eax = port
  3930.      call  set_io_access_rights
  3931.  
  3932.      popad
  3933.  
  3934.      inc   eax
  3935.      cmp   eax,ecx
  3936.      jbe   new_port_access_disable
  3937.  
  3938.    no_mask_io:
  3939.  
  3940.      popad                         ; end disable io map
  3941.  
  3942.      xor   eax, eax
  3943.      ret
  3944.  
  3945.  
  3946. reserve_free_irq:
  3947.  
  3948.      mov   ecx, 1
  3949.      cmp   ebx, 16
  3950.      jae   fril1
  3951.      test  eax,eax
  3952.      jz    reserve_irq
  3953.  
  3954.      lea   edi,[irq_owner+ebx*4]
  3955.      mov   edx,[edi]
  3956.      mov   eax,[0x3010]
  3957.      cmp   edx,[eax+TASKDATA.pid]
  3958.      jne   fril1
  3959.      dec   ecx
  3960.      mov   [edi],ecx
  3961.    fril1:
  3962.      mov   [esp+36],ecx ; return in eax
  3963.      ret
  3964.  
  3965.   reserve_irq:
  3966.  
  3967.      lea   edi,[irq_owner+ebx*4]
  3968.      cmp   dword [edi], 0
  3969.      jnz   ril1
  3970.  
  3971.      mov   edx,[0x3010]
  3972.      mov   edx,[edx+TASKDATA.pid]
  3973.      mov   [edi],edx
  3974.      dec   ecx
  3975.    ril1:
  3976.      mov   [esp+36],ecx ; return in eax
  3977.      ret
  3978.  
  3979. drawbackground:
  3980.        inc   [mouse_pause]
  3981.        cmp   [0xfe0c],word 0x12
  3982.        je   dbrv20
  3983.      dbrv12:
  3984.        cmp  [0xfe0c],word 0100000000000000b
  3985.        jge  dbrv20
  3986.        cmp  [0xfe0c],word 0x13
  3987.        je   dbrv20
  3988.        call  vesa12_drawbackground
  3989.        dec   [mouse_pause]
  3990.        call   [draw_pointer]
  3991.        ret
  3992.      dbrv20:
  3993.        cmp   [display_data-12],dword 1
  3994.        jne   bgrstr
  3995.        call  vesa20_drawbackground_tiled
  3996.        dec   [mouse_pause]
  3997.        call   [draw_pointer]
  3998.        ret
  3999.      bgrstr:
  4000.        call  vesa20_drawbackground_stretch
  4001.        dec   [mouse_pause]
  4002.        call   [draw_pointer]
  4003.        ret
  4004.  
  4005. align 4
  4006.  
  4007. syscall_putimage:                       ; PutImage
  4008.  
  4009.      mov   edx,ecx
  4010.      mov   ecx,ebx
  4011.         lea     ebx, [eax+std_application_base_address]
  4012.  
  4013. sys_putimage:
  4014.      test  ecx,0x80008000
  4015.      jnz   .exit
  4016.      test  ecx,0x0000FFFF
  4017.      jz    .exit
  4018.      test  ecx,0xFFFF0000
  4019.      jnz   @f
  4020.   .exit:
  4021.      ret
  4022.  @@:
  4023.         mov     edi,[0x3000]
  4024.         shl     edi,8
  4025.         add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.top]
  4026.         rol     edx,16
  4027.         add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.left]
  4028.         rol     edx,16
  4029.   .forced:
  4030. ;        mov     eax, vga_putimage
  4031.         cmp     [0xfe0c], word 0x12
  4032.         jz      @f   ;.doit
  4033.         mov     eax, vesa12_putimage
  4034.         cmp     [0xfe0c], word 0100000000000000b
  4035.         jae     @f
  4036.         cmp     [0xfe0c], word 0x13
  4037.         jnz     .doit
  4038. @@:
  4039.         mov     eax, vesa20_putimage
  4040. .doit:
  4041.         inc     [mouse_pause]
  4042.         call    eax
  4043.         dec     [mouse_pause]
  4044.         jmp     [draw_pointer]
  4045.  
  4046. ; eax x beginning
  4047. ; ebx y beginning
  4048. ; ecx x end
  4049. ; edx y end
  4050. ; edi color
  4051.  
  4052. __sys_drawbar:
  4053.         mov     esi,[0x3000]
  4054.         shl     esi,8
  4055.         add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4056.         add     ecx,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4057.         add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4058.         add     edx,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4059.   .forced:
  4060.     inc   [mouse_pause]
  4061.     cmp   [0xfe0c],word 0x12
  4062.     je   dbv20
  4063.    sdbv20:
  4064.     cmp  [0xfe0c],word 0100000000000000b
  4065.     jge  dbv20
  4066.     cmp  [0xfe0c],word 0x13
  4067.     je   dbv20
  4068.     call vesa12_drawbar
  4069.     dec   [mouse_pause]
  4070.     call   [draw_pointer]
  4071.     ret
  4072.   dbv20:
  4073.     call vesa20_drawbar
  4074.     dec   [mouse_pause]
  4075.     call   [draw_pointer]
  4076.     ret
  4077.  
  4078.  
  4079.  
  4080. kb_read:
  4081.  
  4082.         push    ecx edx
  4083.  
  4084.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4085.       kr_loop:
  4086.         in      al,0x64
  4087.         test    al,1
  4088.         jnz     kr_ready
  4089.         loop    kr_loop
  4090.         mov     ah,1
  4091.         jmp     kr_exit
  4092.       kr_ready:
  4093.         push    ecx
  4094.         mov     ecx,32
  4095.       kr_delay:
  4096.         loop    kr_delay
  4097.         pop     ecx
  4098.         in      al,0x60
  4099.         xor     ah,ah
  4100.       kr_exit:
  4101.  
  4102.         pop     edx ecx
  4103.  
  4104.         ret
  4105.  
  4106.  
  4107. kb_write:
  4108.  
  4109.         push    ecx edx
  4110.  
  4111.         mov     dl,al
  4112.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4113.       kw_loop1:
  4114.         in      al,0x64
  4115.         test    al,0x20
  4116.         jz      kw_ok1
  4117.         loop    kw_loop1
  4118.         mov     ah,1
  4119.         jmp     kw_exit
  4120.       kw_ok1:
  4121.         in      al,0x60
  4122.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4123.       kw_loop:
  4124.         in      al,0x64
  4125.         test    al,2
  4126.         jz      kw_ok
  4127.         loop    kw_loop
  4128.         mov     ah,1
  4129.         jmp     kw_exit
  4130.       kw_ok:
  4131.         mov     al,dl
  4132.         out     0x60,al
  4133.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4134.       kw_loop3:
  4135.         in      al,0x64
  4136.         test    al,2
  4137.         jz      kw_ok3
  4138.         loop    kw_loop3
  4139.         mov     ah,1
  4140.         jmp     kw_exit
  4141.       kw_ok3:
  4142.         mov     ah,8
  4143.       kw_loop4:
  4144.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4145.       kw_loop5:
  4146.         in      al,0x64
  4147.         test    al,1
  4148.         jnz     kw_ok4
  4149.         loop    kw_loop5
  4150.         dec     ah
  4151.         jnz     kw_loop4
  4152.       kw_ok4:
  4153.         xor     ah,ah
  4154.       kw_exit:
  4155.  
  4156.         pop     edx ecx
  4157.  
  4158.         ret
  4159.  
  4160.  
  4161. kb_cmd:
  4162.  
  4163.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4164.       c_wait:
  4165.         in      al,0x64
  4166.         test    al,2
  4167.         jz      c_send
  4168.         loop    c_wait
  4169.         jmp     c_error
  4170.       c_send:
  4171.         mov     al,bl
  4172.         out     0x64,al
  4173.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4174.       c_accept:
  4175.         in      al,0x64
  4176.         test    al,2
  4177.         jz      c_ok
  4178.         loop    c_accept
  4179.       c_error:
  4180.         mov     ah,1
  4181.         jmp     c_exit
  4182.       c_ok:
  4183.         xor     ah,ah
  4184.       c_exit:
  4185.         ret
  4186.  
  4187.  
  4188. setmouse:  ; set mousepicture -pointer
  4189.            ; ps2 mouse enable
  4190.  
  4191.      mov     [0xf200],dword mousepointer
  4192.  
  4193.      cli
  4194. ;     mov     bl,0xa8                 ; enable mouse cmd
  4195. ;     call    kb_cmd
  4196. ;     call    kb_read                 ; read status
  4197. ;     mov     bl,0x20                 ; get command byte
  4198. ;     call    kb_cmd
  4199. ;     call    kb_read
  4200. ;     or      al,3                    ; enable interrupt
  4201. ;     mov     bl,0x60                 ; write command
  4202. ;     push    eax
  4203. ;     call    kb_cmd
  4204. ;     pop     eax
  4205. ;     call    kb_write
  4206. ;     mov     bl,0xd4                 ; for mouse
  4207. ;     call    kb_cmd
  4208. ;     mov     al,0xf4                 ; enable mouse device
  4209. ;     call    kb_write
  4210. ;     call    kb_read           ; read status return
  4211.  
  4212.      ; com1 mouse enable
  4213.  
  4214.      mov   bx,0x3f8 ; combase
  4215.  
  4216.      mov   dx,bx
  4217.      add   dx,3
  4218.      mov   al,0x80
  4219.      out   dx,al
  4220.  
  4221.      mov   dx,bx
  4222.      add   dx,1
  4223.      mov   al,0
  4224.      out   dx,al
  4225.  
  4226.      mov   dx,bx
  4227.      add   dx,0
  4228.      mov   al,0x30*2    ; 0x30 / 4
  4229.      out   dx,al
  4230.  
  4231.      mov   dx,bx
  4232.      add   dx,3
  4233.      mov   al,2         ; 3
  4234.      out   dx,al
  4235.  
  4236.      mov   dx,bx
  4237.      add   dx,4
  4238.      mov   al,0xb
  4239.      out   dx,al
  4240.  
  4241.      mov   dx,bx
  4242.      add   dx,1
  4243.      mov   al,1
  4244.      out   dx,al
  4245.  
  4246.  
  4247.      ; com2 mouse enable
  4248.  
  4249.      mov   bx,0x2f8 ; combase
  4250.  
  4251.      mov   dx,bx
  4252.      add   dx,3
  4253.      mov   al,0x80
  4254.      out   dx,al
  4255.  
  4256.      mov   dx,bx
  4257.      add   dx,1
  4258.      mov   al,0
  4259.      out   dx,al
  4260.  
  4261.      mov   dx,bx
  4262.      add   dx,0
  4263.      mov   al,0x30*2
  4264.      out   dx,al
  4265.  
  4266.      mov   dx,bx
  4267.      add   dx,3
  4268.      mov   al,2
  4269.      out   dx,al
  4270.  
  4271.      mov   dx,bx
  4272.      add   dx,4
  4273.      mov   al,0xb
  4274.      out   dx,al
  4275.  
  4276.      mov   dx,bx
  4277.      add   dx,1
  4278.      mov   al,1
  4279.      out   dx,al
  4280.  
  4281.      ret
  4282.  
  4283.  
  4284. _rdtsc:
  4285.      bt [cpu_caps], CAPS_TSC
  4286.      jnc ret_rdtsc
  4287.      rdtsc
  4288.      ret
  4289.    ret_rdtsc:
  4290.      mov   edx,0xffffffff
  4291.      mov   eax,0xffffffff
  4292.      ret
  4293.  
  4294. rerouteirqs:
  4295.  
  4296.         cli
  4297.  
  4298.         mov     al,0x11         ;  icw4, edge triggered
  4299.         out     0x20,al
  4300.         call    pic_delay
  4301.         out     0xA0,al
  4302.         call    pic_delay
  4303.  
  4304.         mov     al,0x20         ;  generate 0x20 +
  4305.         out     0x21,al
  4306.         call    pic_delay
  4307.         mov     al,0x28         ;  generate 0x28 +
  4308.         out     0xA1,al
  4309.         call    pic_delay
  4310.  
  4311.         mov     al,0x04         ;  slave at irq2
  4312.         out     0x21,al
  4313.         call    pic_delay
  4314.         mov     al,0x02         ;  at irq9
  4315.         out     0xA1,al
  4316.         call    pic_delay
  4317.  
  4318.         mov     al,0x01         ;  8086 mode
  4319.         out     0x21,al
  4320.         call    pic_delay
  4321.         out     0xA1,al
  4322.         call    pic_delay
  4323.  
  4324.         mov     al,255          ; mask all irq's
  4325.         out     0xA1,al
  4326.         call    pic_delay
  4327.         out     0x21,al
  4328.         call    pic_delay
  4329.  
  4330.         mov     ecx,0x1000
  4331.         cld
  4332. picl1:  call    pic_delay
  4333.         loop    picl1
  4334.  
  4335.         mov     al,255          ; mask all irq's
  4336.         out     0xA1,al
  4337.         call    pic_delay
  4338.         out     0x21,al
  4339.         call    pic_delay
  4340.  
  4341.         cli
  4342.  
  4343.         ret
  4344.  
  4345.  
  4346. pic_delay:
  4347.  
  4348.         jmp     pdl1
  4349. pdl1:   ret
  4350.  
  4351.  
  4352. sys_msg_board_str:
  4353.  
  4354.      pushad
  4355.    @@:
  4356.      cmp    [esi],byte 0
  4357.      je     @f
  4358.      mov    eax,1
  4359.      movzx  ebx,byte [esi]
  4360.      call   sys_msg_board
  4361.      inc    esi
  4362.      jmp    @b
  4363.    @@:
  4364.      popad
  4365.      ret
  4366.  
  4367. uglobal
  4368.   msg_board_data: times 512 db 0
  4369.   msg_board_count dd 0x0
  4370. endg
  4371.  
  4372. sys_msg_board:
  4373.  
  4374. ; eax=1 : write :  bl byte to write
  4375. ; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
  4376.  
  4377.      mov  ecx,[msg_board_count]
  4378.      cmp  eax, 1
  4379.      jne  smbl1
  4380.  
  4381.  
  4382.      mov  [msg_board_data+ecx],bl
  4383.      inc  ecx
  4384.      and  ecx, 511
  4385.      mov  [msg_board_count], ecx
  4386.      mov  [check_idle_semaphore], 5
  4387.      ret
  4388.    smbl1:
  4389.  
  4390.      cmp   eax, 2
  4391.      jne   smbl2
  4392.      test  ecx, ecx
  4393.      jz    smbl21
  4394. ;     mov   edi, msg_board_data
  4395. ;     mov   esi, msg_board_data+1
  4396. ;     movzx eax, byte [edi]
  4397.      mov   eax, msg_board_data+1
  4398.      mov   ebx, msg_board_data
  4399.      movzx edx, byte [ebx]
  4400.      call  memmove
  4401. ;     push  ecx
  4402. ;     shr   ecx, 2
  4403. ;     cld
  4404. ;     rep   movsd
  4405. ;     pop   ecx
  4406. ;     and   ecx, 3
  4407. ;     rep   movsb
  4408.      dec   [msg_board_count]
  4409.      mov   [esp+36], edx ;eax
  4410.      mov   [esp+24], dword 1
  4411.      ret
  4412.    smbl21:
  4413.      mov   [esp+36], ecx
  4414.      mov   [esp+24], ecx
  4415.  
  4416.    smbl2:
  4417.      ret
  4418.  
  4419.  
  4420.  
  4421. sys_trace:
  4422.  
  4423.      test eax, eax                  ; get event data
  4424.      jnz  no_get_sys_events
  4425.  
  4426.      mov  esi,save_syscall_data     ; data
  4427.      mov  edi,[0x3010]
  4428.      mov  edi,[edi+TASKDATA.mem_start]
  4429.      add  edi,ebx
  4430.      cld
  4431.      rep  movsb
  4432.  
  4433.      mov  [esp+24],dword 0
  4434.      mov  eax,[save_syscall_count]  ; count
  4435.      mov  [esp+36],eax
  4436.      ret
  4437.  
  4438.    no_get_sys_events:
  4439.  
  4440.      ret
  4441.  
  4442.  
  4443. sys_process_def:
  4444.         mov     edi, [0x3000]
  4445.  
  4446.         dec     eax             ; 1 = set keyboard mode
  4447.      jne   no_set_keyboard_setup
  4448.  
  4449.      shl   edi,8
  4450.      mov   [edi+0x80000 + APPDATA.keyboard_mode],bl
  4451.  
  4452.      ret
  4453.  
  4454.    no_set_keyboard_setup:
  4455.  
  4456.         dec     eax             ; 2 = get keyboard mode
  4457.      jne   no_get_keyboard_setup
  4458.  
  4459.      shl   edi,8
  4460.      movzx eax, byte [0x80000+edi + APPDATA.keyboard_mode]
  4461.  
  4462.      mov   [esp+36],eax
  4463.  
  4464.      ret
  4465.  
  4466.    no_get_keyboard_setup:
  4467.  
  4468.         dec     eax             ; 3 = get keyboard ctrl, alt, shift
  4469.      jne   no_get_keyboard_cas
  4470.  
  4471. ;     xor   eax,eax
  4472. ;     movzx eax,byte [shift]
  4473. ;     movzx ebx,byte [ctrl]
  4474. ;     shl   ebx,2
  4475. ;     add   eax,ebx
  4476. ;     movzx ebx,byte [alt]
  4477. ;     shl   ebx,3
  4478. ;     add   eax,ebx
  4479.  
  4480.  ;// mike.dld [
  4481.      mov   eax, [kb_state]
  4482.  ;// mike.dld ]
  4483.  
  4484.      mov   [esp+36],eax
  4485.  
  4486.      ret
  4487.  
  4488.    no_get_keyboard_cas:
  4489.  
  4490.         dec     eax
  4491.         jnz     no_add_keyboard_hotkey
  4492.  
  4493.         mov     eax, hotkey_list
  4494. @@:
  4495.         cmp     dword [eax+8], 0
  4496.         jz      .found_free
  4497.         add     eax, 16
  4498.         cmp     eax, hotkey_list+16*256
  4499.         jb      @b
  4500.         mov     dword [esp+36], 1
  4501.         ret
  4502. .found_free:
  4503.         mov     [eax+8], edi
  4504.         mov     [eax+4], ecx
  4505.         movzx   ebx, bl
  4506.         lea     ebx, [hotkey_scancodes+ebx*4]
  4507.         mov     ecx, [ebx]
  4508.         mov     [eax], ecx
  4509.         mov     [ebx], eax
  4510.         mov     [eax+12], ebx
  4511.         jecxz   @f
  4512.         mov     [ecx+12], eax
  4513. @@:
  4514.         and     dword [esp+36], 0
  4515.         ret
  4516.  
  4517. no_add_keyboard_hotkey:
  4518.  
  4519.         dec     eax
  4520.         jnz     no_del_keyboard_hotkey
  4521.  
  4522.         movzx   ebx, bl
  4523.         lea     ebx, [hotkey_scancodes+ebx*4]
  4524.         mov     eax, [ebx]
  4525. .scan:
  4526.         test    eax, eax
  4527.         jz      .notfound
  4528.         cmp     [eax+8], edi
  4529.         jnz     .next
  4530.         cmp     [eax+4], ecx
  4531.         jz      .found
  4532. .next:
  4533.         mov     eax, [eax]
  4534.         jmp     .scan
  4535. .notfound:
  4536.         mov     dword [esp+36], 1
  4537.         ret
  4538. .found:
  4539.         mov     ecx, [eax]
  4540.         jecxz   @f
  4541.         mov     edx, [eax+12]
  4542.         mov     [ecx+12], edx
  4543. @@:
  4544.         mov     ecx, [eax+12]
  4545.         mov     edx, [eax]
  4546.         mov     [ecx], edx
  4547.         xor     edx, edx
  4548.         mov     [eax+4], edx
  4549.         mov     [eax+8], edx
  4550.         mov     [eax+12], edx
  4551.         mov     [eax], edx
  4552.         mov     [esp+36], edx
  4553.         ret
  4554.  
  4555. no_del_keyboard_hotkey:
  4556.      ret
  4557.  
  4558.  
  4559. align 4
  4560.  
  4561. sys_gs:                         ; direct screen access
  4562.  
  4563.      cmp  eax,1                 ; resolution
  4564.      jne  no_gs1
  4565.      mov  eax,[0xfe00]
  4566.      shl  eax,16
  4567.      mov  ax,[0xfe04]
  4568.      add  eax,0x00010001
  4569.      mov  [esp+36],eax
  4570.      ret
  4571.    no_gs1:
  4572.  
  4573.      cmp   eax,2                ; bits per pixel
  4574.      jne   no_gs2
  4575.      movzx eax,byte [0xfbf1]
  4576.      mov   [esp+36],eax
  4577.      ret
  4578.    no_gs2:
  4579.  
  4580.      cmp   eax,3                ; bytes per scanline
  4581.      jne   no_gs3
  4582.      mov   eax,[0xfe08]
  4583.      mov   [esp+36],eax
  4584.      ret
  4585.    no_gs3:
  4586.  
  4587.      mov  [esp+36],dword -1
  4588.      ret
  4589.  
  4590.  
  4591. align 4 ; PCI functions
  4592.  
  4593. sys_pci:
  4594.  
  4595.      call  pci_api
  4596.      mov   [esp+36],eax
  4597.      ret
  4598.  
  4599.  
  4600. align 4  ;  system functions
  4601.  
  4602. syscall_setpixel:                       ; SetPixel
  4603.  
  4604.  
  4605.      mov   edx,[0x3010]
  4606.      add   eax,[edx-twdw+WDATA.box.left]
  4607.      add   ebx,[edx-twdw+WDATA.box.top]
  4608.         mov     edi,[0x3000]
  4609.         shl     edi,8
  4610.         add     eax,[edi+0x80000+APPDATA.wnd_clientbox.left]
  4611.         add     ebx,[edi+0x80000+APPDATA.wnd_clientbox.top]
  4612.      xor   edi,edi ; no force
  4613. ;     mov   edi,1
  4614.      call  [disable_mouse]
  4615.      jmp   [putpixel]
  4616.  
  4617. align 4
  4618.  
  4619. syscall_writetext:                      ; WriteText
  4620.  
  4621.      mov   edi,[0x3010]
  4622.      mov   ebp,[edi-twdw+WDATA.box.left]
  4623.         push    esi
  4624.         mov     esi,[0x3000]
  4625.         shl     esi,8
  4626.         add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4627.      shl   ebp,16
  4628.      add   ebp,[edi-twdw+WDATA.box.top]
  4629.         add     bp,word[esi+0x80000+APPDATA.wnd_clientbox.top]
  4630.         pop     esi
  4631.      add   ecx,[edi+TASKDATA.mem_start]
  4632.      add   eax,ebp
  4633.      xor   edi,edi
  4634.      jmp   dtext
  4635.  
  4636. align 4
  4637.  
  4638. syscall_openramdiskfile:                ; OpenRamdiskFile
  4639.  
  4640.  
  4641.      mov   edi,[0x3010]
  4642.      add   edi,TASKDATA.mem_start
  4643.      add   eax,[edi]
  4644.      add   edx,[edi]
  4645.      mov   esi,12
  4646.      call  fileread
  4647.      mov   [esp+36],ebx
  4648.      ret
  4649.  
  4650. align 4
  4651.  
  4652. syscall_drawrect:                       ; DrawRect
  4653.  
  4654.      mov   edi,ecx
  4655.      and   edi,0x80FFFFFF
  4656.      test  ax,ax
  4657.      je    drectr
  4658.      test  bx,bx
  4659.      je    drectr
  4660.      movzx ecx,ax
  4661.      shr   eax,16
  4662.      movzx edx,bx
  4663.      shr   ebx,16
  4664.         mov     esi,[0x3000]
  4665.         shl     esi,8
  4666.         add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4667.         add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4668.      add   ecx,eax
  4669.      add   edx,ebx
  4670.      jmp   [drawbar]
  4671.     drectr:
  4672.      ret
  4673.  
  4674. align 4
  4675.  
  4676. syscall_getscreensize:                  ; GetScreenSize
  4677.  
  4678.      movzx eax,word[0xfe00]
  4679.      shl   eax,16
  4680.      mov   ax,[0xfe04]
  4681.      mov   [esp+36],eax
  4682.      ret
  4683.  
  4684. align 4
  4685.  
  4686. syscall_cdaudio:                        ; CD
  4687.  
  4688.      call  sys_cd_audio
  4689.      mov   [esp+36],eax
  4690.      ret
  4691.  
  4692. align 4
  4693.  
  4694. syscall_delramdiskfile:                 ; DelRamdiskFile
  4695.  
  4696.      mov   edi,[0x3010]
  4697.      add   edi,TASKDATA.mem_start
  4698.      add   eax,[edi]
  4699.      call  filedelete
  4700.      mov   [esp+36],eax
  4701.      ret
  4702.  
  4703. align 4
  4704.  
  4705. syscall_writeramdiskfile:               ; WriteRamdiskFile
  4706.  
  4707.      mov   edi,[0x3010]
  4708.      add   edi,TASKDATA.mem_start
  4709.      add   eax,[edi]
  4710.      add   ebx,[edi]
  4711.      call  filesave
  4712.      mov   [esp+36],eax
  4713.      ret
  4714.  
  4715. align 4
  4716.  
  4717. syscall_getpixel:                       ; GetPixel
  4718.      mov   ecx,[0xfe00]
  4719.      inc   ecx
  4720.      xor   edx,edx
  4721.      div   ecx
  4722.      mov   ebx,edx
  4723.      xchg  eax,ebx
  4724.      call  dword [0xe024]
  4725.      mov   [esp+36],ecx
  4726.      ret
  4727.  
  4728. align 4
  4729.  
  4730. syscall_readstring:                     ; ReadString
  4731.  
  4732.      mov   edi,[0x3010]
  4733.      add   edi,TASKDATA.mem_start
  4734.      add   eax,[edi]
  4735.      call  read_string
  4736.      mov   [esp+36],eax
  4737.      ret
  4738.  
  4739. align 4
  4740.  
  4741. syscall_drawline:                       ; DrawLine
  4742.  
  4743.      mov   edi,[0x3010]
  4744.      movzx edx,word[edi-twdw+WDATA.box.left]
  4745.      mov   ebp,edx
  4746.         mov     esi,[0x3000]
  4747.         shl     esi,8
  4748.         add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4749.         add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.left]
  4750.      shl   edx,16
  4751.      add   ebp,edx
  4752.      movzx edx,word[edi-twdw+WDATA.box.top]
  4753.      add   eax,ebp
  4754.      mov   ebp,edx
  4755.         add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4756.         add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.top]
  4757.      shl   edx,16
  4758.      xor   edi,edi
  4759.      add   edx,ebp
  4760.      add   ebx,edx
  4761.      jmp   [draw_line]
  4762.  
  4763. align 4
  4764.  
  4765. syscall_getirqowner:                    ; GetIrqOwner
  4766.      cmp   eax,16
  4767.      jae   .err
  4768.      shl   eax,2
  4769.      add   eax,irq_owner
  4770.      mov   eax,[eax]
  4771.      mov   [esp+36],eax
  4772.      ret
  4773. .err:
  4774.      or    dword [esp+36], -1
  4775.      ret
  4776.  
  4777. align 4
  4778.  
  4779. syscall_reserveportarea:                ; ReservePortArea and FreePortArea
  4780.  
  4781.      call  r_f_port_area
  4782.      mov   [esp+36],eax
  4783.      ret
  4784.  
  4785. align 4
  4786.  
  4787. syscall_threads:                        ; CreateThreads
  4788.  
  4789.      call  sys_threads
  4790.      mov   [esp+36],eax
  4791.      ret
  4792.  
  4793. align 4
  4794.  
  4795. stack_driver_stat:
  4796.  
  4797.      call  app_stack_handler            ; Stack status
  4798.  
  4799. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  4800. ;     call  change_task                 ; between sent packet
  4801.  
  4802.      mov   [esp+36],eax
  4803.      ret
  4804.  
  4805. align 4
  4806.  
  4807. socket:                                 ; Socket interface
  4808.      call  app_socket_handler
  4809.  
  4810. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  4811. ;     call  change_task                 ; between sent packet
  4812.  
  4813.      mov   [esp+36],eax
  4814.      mov   [esp+24],ebx
  4815.      ret
  4816.  
  4817. align 4
  4818.  
  4819. user_events:                            ; User event times
  4820.  
  4821.      mov   eax,0x12345678
  4822.      mov   [esp+36],eax
  4823.  
  4824.      ret
  4825.  
  4826. align 4
  4827.  
  4828. read_from_hd:                           ; Read from hd - fn not in use
  4829.  
  4830.      mov   edi,[0x3010]
  4831.      add   edi,TASKDATA.mem_start
  4832.      add   eax,[edi]
  4833.      add   ecx,[edi]
  4834.      add   edx,[edi]
  4835.      call  file_read
  4836.  
  4837.      mov   [esp+36],eax
  4838.      mov   [esp+24],ebx
  4839.  
  4840.      ret
  4841.  
  4842.  
  4843. ; --------------- APM ---------------------
  4844. apm_entry    dp    0
  4845. apm_vf        dd    0
  4846. align 4
  4847. sys_apm:
  4848.     cmp    word [apm_vf], 0    ; Check APM BIOS enable
  4849.     jne    @f
  4850.     or    [esp + 56], byte 1    ; error
  4851.     mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
  4852.     ret
  4853.  
  4854. @@:    xchg    eax, ecx
  4855.     xchg    ebx, ecx
  4856.  
  4857.     cmp    al, 3
  4858.     ja    @f
  4859.     and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
  4860.     mov    eax, [apm_vf]
  4861.     mov    [esp + 36], eax
  4862.     shr    eax, 16
  4863.     mov    [esp + 32], eax
  4864.     ret
  4865.  
  4866. @@:    call    pword [apm_entry]    ; call APM BIOS
  4867.     mov    [esp + 8 ], edi
  4868.     mov    [esp + 12], esi
  4869.     mov    [esp + 24], ebx
  4870.     mov    [esp + 28], edx
  4871.     mov    [esp + 32], ecx
  4872.     mov    [esp + 36], eax
  4873.     setc    al
  4874.     and    [esp + 56], byte 0xfe
  4875.     or    [esp + 56], al
  4876.     ret
  4877. ; -----------------------------------------
  4878.  
  4879. align 4
  4880.  
  4881. undefined_syscall:                      ; Undefined system call
  4882.  
  4883.      mov   [esp+36],dword -1
  4884.      ret
  4885.  
  4886.  
  4887. ;clear_busy_flag_at_caller:
  4888.  
  4889. ;      push  edi
  4890.  
  4891. ;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
  4892. ;      imul  edi,8
  4893. ;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  4894.  
  4895. ;      pop   edi
  4896.  
  4897. ;      ret
  4898.  
  4899.  
  4900. keymap:
  4901.  
  4902.      db   '6',27
  4903.      db   '1234567890-=',8,9
  4904.      db   'qwertyuiop[]',13
  4905.      db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
  4906.      db   '@234567890123',180,178,184,'6',176,'7'
  4907.      db   179,'8',181,177,183,185,182
  4908.      db   'AB<D',255,'FGHIJKLMNOPQRSTUVWXYZ'
  4909.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4910.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4911.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4912.  
  4913.  
  4914. keymap_shift:
  4915.  
  4916.      db   '6',27
  4917.      db   '!@#$%^&*()_+',8,9
  4918.      db   'QWERTYUIOP{}',13
  4919.      db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
  4920.      db   '@234567890123',180,178,184,'6',176,'7'
  4921.      db   179,'8',181,177,183,185,182
  4922.      db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
  4923.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4924.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4925.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4926.  
  4927.  
  4928. keymap_alt:
  4929.  
  4930.      db   ' ',27
  4931.      db   ' @ $  {[]}\ ',8,9
  4932.      db   '            ',13
  4933.      db   '             ',0,'           ',0,'4',0,' '
  4934.      db   '             ',180,178,184,'6',176,'7'
  4935.      db   179,'8',181,177,183,185,182
  4936.      db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
  4937.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4938.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4939.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  4940.  
  4941.  
  4942. ; device irq owners
  4943. uglobal
  4944. irq_owner:       ; process id
  4945.  
  4946.      dd   0x0
  4947.      dd   0x0
  4948.      dd   0x0
  4949.      dd   0x0
  4950.      dd   0x0
  4951.      dd   0x0
  4952.      dd   0x0
  4953.      dd   0x0
  4954.      dd   0x0
  4955.      dd   0x0
  4956.      dd   0x0
  4957.      dd   0x0
  4958.      dd   0x0
  4959.      dd   0x0
  4960.      dd   0x0
  4961.      dd   0x0
  4962. endg
  4963.  
  4964.  
  4965. ; on irq read ports
  4966. uglobal
  4967.   irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4968.   irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4969.   irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4970.   irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4971.   irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4972.   irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4973.   irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4974.   irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4975.   irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4976.   irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4977.   irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4978.   irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4979.   irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4980.   irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4981.   irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4982.   irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4983. endg
  4984.  
  4985. ; status
  4986. uglobal
  4987.   hd1_status                  dd 0x0  ; 0 - free : other - pid
  4988.   application_table_status    dd 0x0  ; 0 - free : other - pid
  4989. endg
  4990.  
  4991. ; device addresses
  4992. uglobal
  4993.   mididp     dd 0x0
  4994.   midisp     dd 0x0
  4995.  
  4996.   cdbase     dd 0x0
  4997.   cdid       dd 0x0
  4998.  
  4999.   hdbase              dd   0x0  ; for boot 0x1f0
  5000.   hdid                dd   0x0
  5001.   hdpos               dd   0x0  ; for boot 0x1
  5002.   fat32part           dd   0x0  ; for boot 0x1
  5003.  
  5004.   ;part2_ld            dd   0x0
  5005.  
  5006. ;* start code - Mario79
  5007. mouse_pause         dd   0
  5008. MouseTickCounter    dd   0
  5009. ps2_mouse_detected  db   0
  5010. com1_mouse_detected db   0
  5011. com2_mouse_detected db   0
  5012. ;* end code - Mario79
  5013.  
  5014. wraw_bacground_select db 0
  5015.   lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
  5016.   pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
  5017.  
  5018.   sb16       dd 0x0
  5019.   wss        dd 0x0
  5020.  
  5021.   buttontype         dd 0x0
  5022.   windowtypechanged  dd 0x0
  5023.  
  5024. align 4
  5025.   cpu_caps    dd 4 dup(0)
  5026.   pg_data  PG_DATA
  5027.   heap_test   dd ?
  5028. endg
  5029.  
  5030. iglobal
  5031.   keyboard   dd 0x1
  5032.   sound_dma  dd 0x1
  5033.   syslang    dd 0x1
  5034. endg
  5035.  
  5036. IncludeIGlobals
  5037. endofcode:
  5038. IncludeUGlobals
  5039. uglobals_size = $ - endofcode
  5040. diff16 "end of kernel code",0,$
  5041.  
  5042.