Subversion Repositories Kolibri OS

Rev

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

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