home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / header / macros.h65 < prev    next >
Text File  |  1993-01-19  |  6KB  |  343 lines

  1.    .if .not .def _MACROS_
  2. _MACROS_ = 1
  3.  
  4.    .if .not .def _STDDEF_
  5.       .include #stddef
  6.    .endif
  7.    
  8. ; version 2.12.90 (C) Natuerlich! (This comes from 4 years ago)
  9. ; -------------------------------------------------------------
  10. ; Purists might object to the use of 'BASIC'-like macros
  11. ; and it is true, that with every macro U use you might be losing
  12. ; some control (if you aren't careful) or that at least the
  13. ; temptation is very big to code sloppily to use a macro. But
  14. ; since I am currently editing on on a 24 line display, too many
  15. ; lda sta, sequences would just fill up too much screen space
  16. ; and I am not that brilliant to keep all this stuff in my brain,
  17. ; in 100% KODAK quality. Also I don't like printer output
  18. ; ----------------------------------------------------------------
  19. ;
  20. ; defines for macro use
  21. ;
  22.  
  23. ; Note that in order to not bother the internal label table with
  24. ; too many "temporary helper" variables, we are going to use the
  25. ; following shortcut:
  26. ; @0 means low level temporary variable (e.g. @STT)
  27. ; @1 means first level ..               (e.g. POKE)
  28. ; @2 means second level..
  29. ; from the fourth level, we just use @<name>
  30.  
  31.  
  32.    .macro @stt
  33. @0 .= @a
  34.       .if %0 = 2
  35. @0 .= %2
  36.       .endif
  37.       .if  @0 = @a
  38.          sta   %1
  39.       .else
  40.          .if @0 = @x
  41.             stx   %1
  42.          .else
  43.             sty   %1
  44.          .endif
  45.       .endif
  46.    .endm
  47.  
  48.  
  49.    .macro @ldi
  50. @0 .= @a
  51.       .if %0 = 2
  52. @0 .= %2
  53.       .endif
  54.       .if %2 = @a
  55.          lda   #%1
  56.       .else
  57.          .if %2 = @x
  58.             ldx   #%1
  59.          .else
  60.             ldy   #%1
  61.          .endif
  62.       .endif
  63.    .endm
  64.  
  65.    .macro @ldf
  66. @0 .= @a
  67.       .if %0 = 2
  68. @0 .= %2
  69.       .endif
  70.       .if   %2 = @a
  71.          lda   %1
  72.       .else
  73.          .if   %2 = @x
  74.             ldx   %1
  75.          .else
  76.             ldy   %1
  77.          .endif
  78.       .endif
  79.    .endm
  80.  
  81.  
  82.    .macro poke
  83. @1 .= @a
  84.       .if   %0 = 3
  85. @1 .= %3
  86.       .endif
  87.       @LDI  %2,@1
  88.       @STT  %1,@1
  89.    .endm
  90.  
  91.  
  92.    .macro dpoke
  93. @1 .= @a
  94.       .if %0 = 3
  95. @1 .= %3
  96.       .endif
  97.       @LDI  <%2,@1
  98.       @STT  %1,@1
  99.       @LDI  >%2,@1
  100.       @STT  %1+1,@1
  101.    .endm
  102.  
  103.    .macro move
  104. @1 .= @a
  105.       .if %0 = 3
  106. @1 .= %3
  107.       .endif
  108.       @LDF  %1,@1
  109.       @STT  %2,@1
  110.    .endm
  111.  
  112.    .macro dmove
  113. @1 .= @a
  114.       .if %0 = 3
  115. @1 .= %3
  116.       .endif         
  117.       @LDF  %1,@1
  118.       @STT  %2,@1
  119.       @LDF  %1+1,@1
  120.       @STT  %2+1,@1
  121.    .endm
  122.  
  123. ; the following macros are for indirect pokes
  124.  
  125.    .macro poke_x
  126.       lda   #<%2
  127.       sta   %1,x
  128.    .endm
  129.  
  130.    .macro poke_y
  131.       lda   #<%2
  132.       sta   %1,y
  133.    .endm
  134.  
  135.    .macro _move_x
  136.       lda   %1
  137.       sta   %2,x
  138.    .endm
  139.  
  140.    .macro _move_y
  141.       lda   %1
  142.       sta   %2,y
  143.    .endm
  144.  
  145.    .macro dpoke_x
  146.       lda   #<%2
  147.       sta   %1,x
  148.       lda   #>%2
  149.       sta   %1+1,x
  150.    .endm
  151.  
  152.    .macro dpoke_y
  153.       lda   #<%2
  154.       sta   %1,y
  155.       lda   #>%2
  156.       sta   %1+1,y
  157.    .endm
  158.  
  159.    .macro _dmove_x
  160.       lda   %1
  161.       sta   %2,x
  162.       lda   %1+1
  163.       sta   %2+1,x
  164.    .endm
  165.  
  166.    .macro _dmove_y
  167.       lda   %1
  168.       sta   %2,y
  169.       lda   %1+1
  170.       sta   %2+1,y
  171.    .endm
  172.  
  173. ; usage: ddec <address> decrements 8 bit byte by 2
  174.    .macro ddec
  175.       dec   %1
  176.       dec   %1
  177.    .endm
  178.  
  179. ; usage: dinc <address> increments 8 bit byte by 2
  180.    .macro dinc
  181.       inc   %1
  182.       inc   %1
  183.    .endm
  184.  
  185. ; usage: ddey          decrements Y by 2
  186.    .macro ddey
  187.       dey
  188.       dey
  189.    .endm
  190.  
  191. ; usage: diny          increments Y by 2
  192.    .macro diny
  193.       iny
  194.       iny
  195.    .endm
  196.  
  197. ; usage: dinx          decrements X by 2
  198.    .macro ddex
  199.       dex
  200.       dex
  201.    .endm
  202.  
  203. ; usage: dinx          increments X by 2
  204.    .macro dinx
  205.       inx
  206.       inx
  207.    .endm
  208.  
  209. ; usage: lxy <value>,[flags] loads value in x/y LSB/MSB
  210.    .macro lxy
  211. @0 .= @p1
  212.    .if %0 = 2
  213. @0 .= %2
  214.    .endif
  215.    .if @0 & @p1      
  216.       ldx   #<%1
  217.       ldy   #>%1
  218.    .else
  219.       ldx   %1
  220.       ldy   %1+1
  221.    .endif
  222.    .endm
  223.  
  224. ; usage: sxy <address> stores x/y in LSB/MSB of a 16 bit word
  225.    .macro sxy
  226.       stx   %1
  227.       sty   %1+1
  228.    .endm
  229.  
  230. ; -------------------------------------------------------------
  231. ; This is the macro for other macros. Assembles either a move
  232. ; or a poke (or a DPOKE or a DMOVE)
  233. ; Usage:
  234. ;        @MOKE  src,dst,select
  235. ; src as in    POKE dst,src    MOVE src,dst
  236. ; select -> see stddef.h65 ONLY %1 can be selected!
  237. ; --------------------------------------------------------------
  238.    .macro @moke
  239.       .if %3 & @p1
  240.          poke  %2,%1
  241.       .else
  242.          move  %1,%2
  243.       .endif
  244.    .endm
  245.  
  246.    .macro @moke_x
  247.       .if %3 & @p1    
  248.          poke_x   %2,%1
  249.       .else
  250.          _move_x   %1,%2
  251.       .endif
  252.    .endm
  253.  
  254.    .macro @moke_y
  255.       .if %3 & @p1
  256.          poke_y   %2,%1
  257.       .else
  258.          _move_y   %1,%2
  259.       .endif
  260.    .endm
  261.  
  262.  
  263. ; -------------------------------------------------------------
  264. ; This is the macro for other macros. Assembles either a DPOKE
  265. ; or DMOVE)
  266. ; Usage:
  267. ;        @DMOKE  src,dst,select
  268. ;
  269. ; select -> stddef.h65
  270. ; --------------------------------------------------------------
  271.    .macro @dmoke
  272.       .if %3 & @p1
  273.          dpoke %2,%1
  274.       .else
  275.          dmove %1,%2
  276.       .endif
  277.    .endm
  278.  
  279.    .macro @dmoke_x
  280.       .if %3 & @p1
  281.          dpoke_x  %2,%1
  282.       .else
  283.          _dmove_x  %1,%2
  284.       .endif
  285.    .endm
  286.  
  287.    .macro @dmoke_y
  288.       .if %3 & @p1
  289.          dpoke_y  %2,%1
  290.       .else
  291.          _dmove_y  %1,%2
  292.       .endif
  293.    .endm
  294.  
  295. ; -------------------------------------------------------------
  296. ; This is the macro for other macros. Assembles either a direct
  297. ; or an immediate load.
  298. ; Usage:
  299. ;        @MOAD  src,select[,reglsb]
  300. ;
  301. ; select -> stddef.h65
  302. ; reglsb -> @a @x @y
  303. ; --------------------------------------------------------------
  304.    .macro @moad
  305. @2lsb .= @a
  306.       .if %0 > 2
  307. @2lsb .= %3
  308.       .endif
  309.       .if %2 & @p1
  310.          @ldi   <%1,@2lsb
  311.       .else
  312.          @ldf   %1,@2lsb
  313.       .endif
  314.    .endm
  315.  
  316. ; -------------------------------------------------------------
  317. ; This is the macro for other macros. Assembles either a direct
  318. ; or an immediate load. (as you can see these comments were
  319. ; copied again and again) 
  320. ; Usage:
  321. ;        @DMOAD  src,select[,reglsb,regmsb]
  322. ;
  323. ; select -> stddef.h65
  324. ; reglsb -> @a @x @y
  325. ; --------------------------------------------------------------
  326.    .macro @dmoad
  327. @2lsb .= @a
  328. @2msb .= @y
  329.       .if %0 > 2
  330. @2lsb .= %3
  331. @2msb .= %4
  332.       .endif
  333.       .if %2 & @p1
  334.          @ldi  <%1,@2lsb
  335.          @ldi  >%1,@2msb
  336.       .else
  337.          @ldf  %1,@2lsb
  338.          @ldf  %1+1,@2msb
  339.       .endif
  340.    .endm
  341.  
  342.    .endif
  343.