Subversion Repositories Kolibri OS

Rev

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

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