Subversion Repositories Kolibri OS

Rev

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