/*
   CALL.ASM to zbior makr realizujacych przekazywanie parametrow do struktur .PROC
*/


* --------------- *
*  adresowanie @  *
* --------------- *
@call_@ .macro

 sta @stack_address+?@stack_offset,x
 ?@stack_offset = ?@stack_offset+1

.endm


* ---------------------------- *
*  adresowanie natychmiastowe  *
* ---------------------------- *
@call_nat .macro

     .if :1='B'
       lda #:2
       sta @stack_address+?@stack_offset,x
       ?@stack_offset = ?@stack_offset+1
     .else
       .if :1='W'
         lda <:2
         sta @stack_address+?@stack_offset,x
         lda >:2
         sta @stack_address+?@stack_offset+1,x
         ?@stack_offset = ?@stack_offset+2
       .else
         lda <:2
         sta @stack_address+?@stack_offset,x
         lda >:2
         sta @stack_address+?@stack_offset+1,x
         lda ^:2
         sta @stack_address+?@stack_offset+2,x
         ?@stack_offset = ?@stack_offset+3
       .endif
     .endif

.endm


* ----------------------- *
*  adresowanie absolutne  *
* ----------------------- *
@call_abs .macro

     .if :1='B'
       lda :2
       sta @stack_address+?@stack_offset,x
       ?@stack_offset = ?@stack_offset+1
     .else
       .if :1='W'
         lda :2
         sta @stack_address+?@stack_offset,x
         lda :2+1
         sta @stack_address+?@stack_offset+1,x
         ?@stack_offset = ?@stack_offset+2
       .else
         lda :2
         sta @stack_address+?@stack_offset,x
         lda :2+1
         sta @stack_address+?@stack_offset+1,x
         lda :2+2
         sta @stack_address+?@stack_offset+2,x
         ?@stack_offset = ?@stack_offset+3
       .endif
     .endif

.endm


* -------------------------------- *
*  przekazanie parametrow na stos  *
* -------------------------------- *
* tylko pierwszy parametr moze byc przekazany przez akumulator @
@call .macro
 ?@stack_offset = 0

 .if :2>>24<>$FF .and :3>>24<>$FF .and :4>>24<>$FF

 ldx @stack_pointer

   .if :2='@'
    @call_@
   .else

    .if :2='#'
     @call_nat :3,:4
    .else
     @call_abs :3,:4
    .endif

   .endif

 .endif

 .if :5>>24<>$FF .and :6>>24<>$FF .and :7>>24<>$FF

   .if :5='#'
    @call_nat :6,:7
   .else
    @call_abs :6,:7
   .endif

 .endif

 .if :8>>24<>$FF .and :9>>24<>$FF .and :10>>24<>$FF

   .if :8='#'
    @call_nat :9,:10
   .else
    @call_abs :9,:10
   .endif

 .endif

  .if ?@stack_offset<>0
   txa
   clc
   adc #?@stack_offset
   sta @stack_pointer
  .endif

 jsr :1

.endm
