Subversion Repositories Kolibri OS

Rev

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

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