Subversion Repositories Kolibri OS

Rev

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

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