function ... efunc


SYNTAX

"function" ["loc:"] NAME:sym "[" [RL1:regslist] "]" ["," RL2:regslist] ":" OUT:var
...
"efunc" ["," RESULT:val]


MEANING

  1. A label is defined as the entry point of the function NAME.
  2. If RL2 is declared, the specified registers are stored in the stack.
  3. The code "..." is processed.
  4. If RESULT is declared, it is copied to OUT (with OUT's size).
  5. If RL2 is declared, the registers are restored from the stack.
  6. An rts is added as last operation.


NOTES

  1. RL1 tells how to assign the arguments when the function is called.
  2. OUT indicates where the result is returned.
  3. RL2 must not contain OUT (if OUT is a register).
  4. The exit point of the function gets labeled to allow forced exiting.
  5. Normally function labels are global (regardless of the prefix character chosen); if loc: is declared, the function definition will be local, i.e. its labels will start with '.'.
  6. NAME can be up to 30 characters long.
  7. Do not put a label on the same line of function....
  8. Repetition of function names is not checked.
  9. Size of OUT is used only inside boolean expressions.
  10. Brackets are used in places of parentheses to avoid ambiguities. F.ex., "move.l MyLabel(a0),d0" could mean both a) load in d0 the value at the address calculated as a0+MyLabel; b) load in d0 the value returned by the function MyLabel() with the parameter a0.


EXAMPLE 1

ESA
           function SetDMA[d0.w],d1:d0
           move.w     $dff002,d1
           ori.w      #$8000,d0
           move.w     d0,$dff096
           move.w     d1,d0
           efunc
assembly
f0000000   movem.l    d1,-(sp)         ;store RL2 registers
           move.w     $dff002,d1
           ori.w      #$8000,d0
           move.w     d0,$dff096
           move.w     d1,d0
f0000001   movem.l    (sp)+,d1         ;restore registers
           rts


EXAMPLE 2

ESA
           function GetMess[],d0-d7/a0-a6:MessAmount.b
           lea.l      TileTable,a0
           bsr        MessWithRegs
           move.b     (a5),MessAmount
           efunc
assembly
f0000000   movem.l     d0-d7/a0-a6,-(sp)
           lea.l       TileTable,a0
           bsr         MessWithRegs
           move.b      (a5),MessAmount
f0000001   movem.l     (sp)+,d0-d7/a0-a6
           rts


EXAMPLE 3

ESA
           function MessWithDMA[],d0:d1
           move.l      $dff004,d1
           move.l      d1,d0
           andi.l      #$3ff00,d1
           when.s eq
           move.l      $dff004,d1
           ewhen
           efunc,SetDMA[d1]
assembly
f0000002   movem.l     d0,-(sp)
           move.l      $dff004,d1
           move.l      d1,d0
           andi.l      #$3ff00,d1
           bne.s       .0000002
           move.l      $dff004,d1
.0000002
           move.w      d1,d0
           bsr         f0000000
           move.l      d0,d1
f0000003   movem.l     (sp)+,d0
           rts



home