Subversion Repositories Kolibri OS

Rev

Rev 205 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. ;~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  3. macro iglobal {
  4.   IGlobals equ IGlobals,
  5.   macro __IGlobalBlock { }
  6.  
  7. macro uglobal {
  8.   UGlobals equ UGlobals,
  9.   macro __UGlobalBlock { }
  10.  
  11. endg fix }      ; Use endg for ending iglobal and uglobal blocks.
  12.  
  13.  
  14. macro IncludeIGlobals{
  15.   macro IGlobals dummy,[n] \{ __IGlobalBlock
  16.      purge __IGlobalBlock  \}
  17.   match I, IGlobals \{ I \} }
  18.  
  19. macro IncludeUGlobals{
  20.   macro UGlobals dummy,[n] \{
  21.     \common
  22.       \local begin, size
  23.       begin = $
  24.       virtual at $
  25.     \forward
  26.       __UGlobalBlock
  27.       purge __UGlobalBlock
  28.     \common
  29.       size = $ - begin
  30.     end virtual
  31.     rb size
  32.   \}
  33.   match U, UGlobals \{ U \} }
  34.  
  35. uglobal
  36. endg
  37.  
  38. iglobal
  39. endg
  40.  
  41. ;~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  42. ; new application structure
  43. macro meos_app_start
  44.  {
  45.   use32
  46.   org 0x0
  47.  
  48.   db 'MENUET01'
  49.   dd 0x01
  50.   dd __start
  51.   dd __end
  52.   dd __memory
  53.   dd __stack
  54.  
  55.   if used __params & ~defined __params
  56.     dd __params
  57.   else
  58.     dd 0x0
  59.   end if
  60.  
  61.   dd 0x0
  62.  }
  63. MEOS_APP_START fix meos_app_start
  64.  
  65. macro code
  66.  {
  67.   __start:
  68.  }
  69. CODE fix code
  70.  
  71. macro data
  72.  {
  73.   __data:
  74.   IncludeIGlobals
  75.  }
  76. DATA fix data
  77.  
  78. macro udata
  79.  {
  80.   if used __params & ~defined __params
  81.     __params:
  82.       db 0
  83.     __end:
  84.       rb 255
  85.   else
  86.     __end:
  87.   end if
  88.   __udata:
  89.   IncludeUGlobals
  90.  }
  91. UDATA fix udata
  92.  
  93. macro meos_app_end
  94.  {
  95.   align 32
  96.   rb 2048
  97.   __stack:
  98.   __memory:
  99.  }
  100. MEOS_APP_END fix meos_app_end
  101.  
  102.  
  103. ; macro for defining multiline text data
  104. struc mstr [sstring]
  105.  {
  106.   forward
  107.     local ssize
  108.     virtual at 0
  109.       db sstring
  110.       ssize = $
  111.     end virtual
  112.     dd ssize
  113.     db sstring
  114.   common
  115.     dd -1
  116.  }
  117.  
  118. ; macro for defining multiline text data
  119. struc mls [sstring] {
  120.         forward
  121.         local ssize
  122.         virtual at 0
  123.                 db sstring      ; mod
  124.                 ssize = $
  125.         end virtual
  126.         db ssize
  127.         db sstring
  128.         common
  129.  
  130.         db -1                   ; mod
  131. }
  132.  
  133.  
  134.  
  135. ; strings
  136. macro sz name,[data] {       ; from MFAR [mike.dld]
  137.   common
  138.    if used name
  139.     label name
  140.    end if
  141.   forward
  142.    if used name
  143.     db data
  144.    end if
  145.   common
  146.    if used name
  147.     .size = $-name
  148.    end if
  149. }
  150.  
  151. macro lsz name,[lng,data] {  ; from MFAR [mike.dld]
  152.   common
  153.    if used name
  154.     label name
  155.    end if
  156.   forward
  157.    if (used name)&(lang eq lng)
  158.     db data
  159.    end if
  160.   common
  161.    if used name
  162.     .size = $-name
  163.    end if
  164. }
  165.  
  166.  
  167.  
  168. ; easy system call macro
  169. macro mpack dest, hsrc, lsrc
  170. {
  171.   if (hsrc eqtype 0) & (lsrc eqtype 0)
  172.     mov dest, (hsrc) shl 16 + lsrc
  173.   else
  174.     if (hsrc eqtype 0) & (~lsrc eqtype 0)
  175.       mov dest, (hsrc) shl 16
  176.       add dest, lsrc
  177.     else
  178.       mov dest, hsrc
  179.       shl dest, 16
  180.       add dest, lsrc
  181.     end if
  182.   end if
  183. }
  184.  
  185. macro __mov reg,a,b {         ; mike.dld
  186.  if (~a eq)&(~b eq)
  187.    mpack reg,a,b
  188.  else if (~a eq)&(b eq)
  189.    mov reg,a
  190.  end if
  191. }
  192.  
  193. __CPU_type      equ     p5
  194. SYSENTER_VAR    equ     0
  195.  
  196. macro mcall a,b,c,d,e,f {   ; mike.dld, updated by Ghost for Fast System Calls
  197.  local  ..ret_point
  198.  __mov eax,a
  199.  __mov ebx,b
  200.  __mov ecx,c
  201.  __mov edx,d
  202.  __mov esi,e
  203.  __mov edi,f
  204.  
  205.  if __CPU_type eq p5
  206.         int     0x40
  207.  else
  208.   if __CPU_type eq p6
  209.         push    ebp
  210.         mov     ebp, esp
  211.         push    ..ret_point     ; it may be 2 or 5 byte
  212.         sysenter
  213.  ..ret_point:
  214.         pop     edx
  215.         pop     ecx
  216.  
  217.   else
  218.    if __CPU_type eq k6
  219.         push    ecx
  220.         syscall
  221.         pop     ecx
  222.    else
  223.         display 'ERROR : unknown CPU type'
  224.         int     0x40
  225.    end if
  226.   end if
  227.  end if
  228. }
  229.  
  230.  
  231.  
  232.  
  233. ; optimize the code for size
  234. __regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
  235.  
  236. macro add arg1,arg2
  237.  {
  238.    if (arg2 eqtype 0)
  239.       if (arg2) = 1
  240.          inc arg1
  241.       else
  242.          add arg1,arg2
  243.       end if
  244.    else
  245.       add arg1,arg2
  246.    end if
  247.  }
  248.  
  249. macro sub arg1,arg2
  250.  {
  251.    if (arg2 eqtype 0)
  252.       if (arg2) = 1
  253.          dec arg1
  254.       else
  255.          sub arg1,arg2
  256.       end if
  257.    else
  258.       sub arg1,arg2
  259.    end if
  260.  }
  261.  
  262. macro mov arg1,arg2
  263.  {
  264.    if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0'))
  265.       if (arg2) = 0
  266.          xor arg1,arg1
  267.       else if (arg2) = 1
  268.          xor arg1,arg1
  269.          inc arg1
  270.       else if (arg2) = -1
  271.          or  arg1,-1
  272.       else if (arg2) > -128 & (arg2) < 128
  273.          push arg2
  274.          pop  arg1
  275.       else
  276.          mov  arg1,arg2
  277.       end if
  278.    else
  279.       mov arg1,arg2
  280.    end if
  281.  }
  282.  
  283.  
  284. macro struct name
  285.  {
  286.   virtual at 0
  287.    name name
  288.    sizeof.#name = $ - name
  289.   end virtual
  290.  }
  291.  
  292. ; structures used in MeOS
  293. struc process_information
  294.  {
  295.   .cpu_usage               dd ?  ; +0
  296.   .window_stack_position   dw ?  ; +4
  297.   .window_stack_value      dw ?  ; +6
  298.   .not_used1               dw ?  ; +8
  299.   .process_name            rb 12 ; +10
  300.   .memory_start            dd ?  ; +22
  301.   .used_memory             dd ?  ; +26
  302.   .PID                     dd ?  ; +30
  303.   .x_start                 dd ?  ; +34
  304.   .y_start                 dd ?  ; +38
  305.   .x_size                  dd ?  ; +42
  306.   .y_size                  dd ?  ; +46
  307.   .slot_state              dw ?  ; +50
  308.                            dw ?  ; +52 - reserved
  309.   .client_left             dd ?  ; +54
  310.   .client_top              dd ?  ; +58
  311.   .client_width            dd ?  ; +62
  312.   .client_height           dd ?  ; +66
  313.   .wnd_state               db ?  ; +70
  314.   rb (1024-71)
  315.  }
  316. struct process_information
  317.  
  318. struc system_colors
  319.  {
  320.   .frame            dd ?
  321.   .grab             dd ?
  322.   .grab_button      dd ?
  323.   .grab_button_text dd ?
  324.   .grab_text        dd ?
  325.   .work             dd ?
  326.   .work_button      dd ?
  327.   .work_button_text dd ?
  328.   .work_text        dd ?
  329.   .work_graph       dd ?
  330.  }
  331. struct system_colors
  332.  
  333.  
  334. ; constants
  335.  
  336. ; events
  337. EV_IDLE        = 0
  338. EV_TIMER       = 0
  339. EV_REDRAW      = 1
  340. EV_KEY         = 2
  341. EV_BUTTON      = 3
  342. EV_EXIT        = 4
  343. EV_BACKGROUND  = 5
  344. EV_MOUSE       = 6
  345. EV_IPC         = 7
  346. EV_STACK       = 8
  347.  
  348. ; event mask bits for function 40
  349. EVM_REDRAW     =        1b
  350. EVM_KEY        =       10b
  351. EVM_BUTTON     =      100b
  352. EVM_EXIT       =     1000b
  353. EVM_BACKGROUND =    10000b
  354. EVM_MOUSE      =   100000b
  355. EVM_IPC        =  1000000b
  356. EVM_STACK      = 10000000b