Subversion Repositories Kolibri OS

Rev

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

  1. @^ fix macro comment {
  2. ^@ fix }
  3.  
  4.  
  5. macro m2m dest,src {
  6.  push src
  7.  pop  dest
  8. }
  9.  
  10.  
  11. macro iglobal {
  12.   IGlobals equ IGlobals,
  13.   macro __IGlobalBlock { }
  14.  
  15. macro uglobal {
  16.   UGlobals equ UGlobals,
  17.   macro __UGlobalBlock { }
  18.  
  19. endg fix }      ; Use endg for ending iglobal and uglobal blocks.
  20.  
  21.  
  22. macro IncludeIGlobals{
  23.   macro IGlobals dummy,[n] \{ __IGlobalBlock
  24.      purge __IGlobalBlock  \}
  25.   match I, IGlobals \{ I \} }
  26.  
  27. macro IncludeUGlobals{
  28.   macro UGlobals dummy,[n] \{
  29.     \common
  30.       \local begin, size
  31.       begin = $
  32.       virtual at $
  33.     \forward
  34.       __UGlobalBlock
  35.       purge __UGlobalBlock
  36.     \common
  37.       size = $ - begin
  38.     end virtual
  39.     rb size
  40.   \}
  41.   match U, UGlobals \{ U \} }
  42.  
  43. uglobal
  44. endg
  45.  
  46. iglobal
  47. endg
  48.  
  49.  
  50. ; new application structure
  51. macro meos_app_start
  52.  {
  53.   use32
  54.   org 0x0
  55.  
  56.   db 'MENUET01'
  57.   dd 0x01
  58.   dd __start
  59.   dd __end
  60.   dd __memory
  61.   dd __stack
  62.  
  63.   if used __params & ~defined __params
  64.     dd __params
  65.   else
  66.     dd 0x0
  67.   end if
  68.  
  69.   dd 0x0
  70.  }
  71. MEOS_APP_START fix meos_app_start
  72.  
  73. macro code
  74.  {
  75.   __start:
  76.  }
  77. CODE fix code
  78.  
  79. macro data
  80.  {
  81.   __data:
  82.   IncludeIGlobals
  83.  }
  84. DATA fix data
  85.  
  86. macro udata
  87.  {
  88.   if used __params & ~defined __params
  89.     __params:
  90.       db 0
  91.     __end:
  92.       rb 255
  93.   else
  94.     __end:
  95.   end if
  96.   __udata:
  97.   IncludeUGlobals
  98.  }
  99. UDATA fix udata
  100.  
  101. macro meos_app_end
  102.  {
  103.   align 32
  104.   rb 2048
  105.   __stack:
  106.   __memory:
  107.  }
  108. MEOS_APP_END fix meos_app_end
  109.  
  110.  
  111. ; macro for defining multiline text data
  112. struc mstr [sstring]
  113.  {
  114.   forward
  115.     local ssize
  116.     virtual at 0
  117.       db sstring
  118.       ssize = $
  119.     end virtual
  120.     dd ssize
  121.     db sstring
  122.   common
  123.     dd -1
  124.  }
  125.  
  126. ; macro for defining multiline text data
  127. struc mls [sstring]
  128.  {
  129.   forward
  130.     local ssize
  131.     virtual at 0
  132.       db sstring  ; mod
  133.       ssize = $
  134.     end virtual
  135.     db ssize
  136.     db sstring
  137.   common
  138.     db -1         ; mod
  139.  }
  140.  
  141.  
  142.  
  143. ; strings
  144. macro sz name,[data] {       ; from MFAR [mike.dld]
  145.  common
  146.   if used name
  147.    name db data
  148.    .size = $-name
  149.   end if
  150. }
  151.  
  152. macro lsz name,[lng,data] {  ; from MFAR [mike.dld]
  153.  common
  154.   if used name
  155.    label name
  156.  forward
  157.   if lang eq lng
  158.    db data
  159.   end if
  160.  common
  161.    .size = $-name
  162.   end if
  163. }
  164.  
  165. macro szc name,elsz,[data] {         ; from MFAR [mike.dld]
  166.  common
  167.   local s,m
  168.   m = 0
  169.   if used name
  170.    label name
  171.  forward
  172.    virtual at 0
  173.     db data
  174.     s = $
  175.    end virtual
  176.    d#elsz s
  177.    if m < s
  178.     m = s
  179.    end if
  180.    db data
  181.  common
  182.    .size = $-name
  183.    .maxl = m
  184.   end if
  185. }
  186.  
  187. macro lszc name,elsz,[lng,data] {  ; from MFAR [mike.dld]
  188.  common
  189.   local s,m,c
  190.   m = 0
  191.   c = 0
  192.   if used name
  193.    label name
  194.  forward
  195.   if lang eq lng
  196.    virtual at 0
  197.     db data
  198.     s = $
  199.    end virtual
  200.    d#elsz s
  201.    if m < s
  202.     m = s
  203.    end if
  204.    db data
  205.    c = c+1
  206.   end if
  207.  common
  208.    .size  = $-name
  209.    .maxl  = m
  210.    .count = c
  211.   end if
  212. }
  213.  
  214.  
  215. ; easy system call macro
  216. macro mpack dest, hsrc, lsrc
  217. {
  218.   if (hsrc eqtype 0) & (lsrc eqtype 0)
  219.     mov dest, (hsrc) shl 16 + lsrc
  220.   else
  221.     if (hsrc eqtype 0) & (~lsrc eqtype 0)
  222.       mov dest, (hsrc) shl 16
  223.       add dest, lsrc
  224.     else
  225.       mov dest, hsrc
  226.       shl dest, 16
  227.       add dest, lsrc
  228.     end if
  229.   end if
  230. }
  231.  
  232. macro __mov reg,a,b {       ; mike.dld
  233.  if (~a eq)&(~b eq)
  234.    mpack reg,a,b
  235.  else if (~a eq)&(b eq)
  236.    mov reg,a
  237.  end if
  238. }
  239.  
  240.  
  241. include 'config.inc'
  242. ;__CPU_type     equ     p5
  243. SYSENTER_VAR    equ     0
  244.  
  245. macro mcall a,b,c,d,e,f {   ; mike.dld, updated by Ghost for Fast System Calls
  246.  local  ..ret_point
  247.  __mov eax,a
  248.  __mov ebx,b
  249.  __mov ecx,c
  250.  __mov edx,d
  251.  __mov esi,e
  252.  __mov edi,f
  253.  
  254.  if __CPU_type eq p5
  255.         int     0x40
  256.  else
  257.   if __CPU_type eq p6
  258.         push    ebp
  259.         mov     ebp, esp
  260.         push    ..ret_point     ; it may be 2 or 5 byte
  261.         sysenter
  262.  ..ret_point:
  263.         pop     edx
  264.         pop     ecx
  265.  
  266.   else
  267.    if __CPU_type eq k6
  268.         push    ecx
  269.         syscall
  270.         pop     ecx
  271.    else
  272.         display 'ERROR : unknown CPU type'
  273.         int     0x40
  274.    end if
  275.   end if
  276.  end if
  277. }
  278.  
  279.  
  280. ; -------------------------
  281. macro header a,[b] {
  282.  common
  283.   use32
  284.   org 0
  285.   db 'MENUET',a
  286.  forward
  287.   if b eq
  288.    dd 0
  289.   else
  290.    dd b
  291.   end if }
  292. macro section name { align 16
  293.  label name }
  294. macro func name {
  295.  if ~used name
  296.   display 'FUNC NOT USED: ',`name,13,10
  297.  else
  298.   align 4
  299.   name:
  300.   ;diff16 `name,0,name
  301. ;pushad
  302. ;pushfd
  303. ;dps `name
  304. ;newline
  305. ;mcall 5,1
  306. ;popfd
  307. ;popad
  308. }
  309. macro endf { end if }
  310.  
  311. macro diff16 title,l1,l2
  312.  {
  313.   local s,d
  314.   s = l2-l1
  315.   display title,': 0x'
  316.   repeat 8
  317.    d = '0' + s shr ((8-%) shl 2) and $0F
  318.    if d > '9'
  319.     d = d + 'A'-'9'-1
  320.    end if
  321.    display d
  322.   end repeat
  323.   display 13,10
  324.  }
  325.  
  326. macro diff10 title,l1,l2
  327.  {
  328.   local s,d,z,m
  329.   s = l2-l1
  330.   z = 0
  331.   m = 1000000000
  332.   display title,': '
  333.   repeat 10
  334.    d = '0' + s / m
  335.    s = s - (s/m)*m
  336.    m = m / 10
  337.    if d <> '0'
  338.     z = 1
  339.    end if
  340.    if z <> 0
  341.     display d
  342.    end if
  343.   end repeat
  344.   display 13,10
  345.  }
  346.  
  347. ; optimize the code for size
  348. __regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
  349.  
  350. macro add arg1,arg2
  351.  {
  352.    if (arg2 eqtype 0)
  353.       if (arg2) = 1
  354.          inc arg1
  355.       else
  356.          add arg1,arg2
  357.       end if
  358.    else
  359.       add arg1,arg2
  360.    end if
  361.  }
  362.  
  363. macro sub arg1,arg2
  364.  {
  365.    if (arg2 eqtype 0)
  366.       if (arg2) = 1
  367.          dec arg1
  368.       else
  369.          sub arg1,arg2
  370.       end if
  371.    else
  372.       sub arg1,arg2
  373.    end if
  374.  }
  375.  
  376. macro mov arg1,arg2
  377.  {
  378.    if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0'))
  379.       if (arg2) = 0
  380.          xor arg1,arg1
  381.       else if (arg2) = 1
  382.          xor arg1,arg1
  383.          inc arg1
  384.       else if (arg2) = -1
  385.          or  arg1,-1
  386.       else if (arg2) > -128 & (arg2) < 128
  387.          push arg2
  388.          pop  arg1
  389.       else
  390.          mov  arg1,arg2
  391.       end if
  392.    else
  393.       mov arg1,arg2
  394.    end if
  395.  }
  396.  
  397.  
  398. macro RGB [a] {
  399.  common
  400.   match (r=,g=,b),a \{
  401.    \dd ((r) shl 16) or ((g) shl 8) or (b)
  402.   \}
  403. }
  404.  
  405.  
  406. struc POINT _t,_dx,_dy {
  407.  .x _t _dx
  408.  .y _t _dy
  409. }
  410.  
  411. ; structure definition helper
  412. include 'struct.inc'
  413.  
  414. struct RECT
  415.   left   dd ?
  416.   top    dd ?
  417.   right  dd ?
  418.   bottom dd ?
  419. ends
  420.  
  421. struct BOX
  422.   left   dd ?
  423.   top    dd ?
  424.   width  dd ?
  425.   height dd ?
  426. ends
  427.  
  428. ; structures used in MeOS
  429. struct process_information
  430.   cpu_usage               dd; +0
  431.   window_stack_position   dw; +4
  432.   window_stack_value      dw; +6
  433.                           dw; +8
  434.   process_name            rb 12 ; +10
  435.   memory_start            dd; +22
  436.   used_memory             dd; +26
  437.   PID                     dd; +30
  438.   box                     BOX   ; +34
  439.   slot_state              dw; +50
  440.                           dw; +52
  441.   client_box              BOX   ; +54
  442.   wnd_state               db ?  ; +70
  443.   rb (1024-71)
  444. ends
  445.  
  446. struct system_colors
  447.   frame            dd ?
  448.   grab             dd ?
  449.   grab_button      dd ?
  450.   grab_button_text dd ?
  451.   grab_text        dd ?
  452.   work             dd ?
  453.   work_button      dd ?
  454.   work_button_text dd ?
  455.   work_text        dd ?
  456.   work_graph       dd ?
  457. ends
  458.  
  459. struct FILEDATE
  460.   Second db ?
  461.   Minute db ?
  462.   Hour   db ?
  463.          db ?
  464.   Day    db ?
  465.   Month  db ?
  466.   Year   dw ?
  467. ends
  468.  
  469. struct FILEINFO
  470.   Attributes dd ?
  471.   IsUnicode  db ?
  472.              db 3 dup(?)
  473.   DateCreate FILEDATE
  474.   DateAccess FILEDATE
  475.   DateModify FILEDATE
  476.   Size       dq ?
  477. ends
  478.  
  479. ; constants
  480.  
  481. ; events
  482. EV_IDLE        = 0
  483. EV_TIMER       = 0
  484. EV_REDRAW      = 1
  485. EV_KEY         = 2
  486. EV_BUTTON      = 3
  487. EV_EXIT        = 4
  488. EV_BACKGROUND  = 5
  489. EV_MOUSE       = 6
  490. EV_IPC         = 7
  491. EV_STACK       = 8
  492.  
  493. ; event mask bits for function 40
  494. EVM_REDRAW     =        1b
  495. EVM_KEY        =       10b
  496. EVM_BUTTON     =      100b
  497. EVM_EXIT       =     1000b
  498. EVM_BACKGROUND =    10000b
  499. EVM_MOUSE      =   100000b
  500. EVM_IPC        =  1000000b
  501. EVM_STACK      = 10000000b