Advertisement
NovaYoshi

Ca65 macros

Mar 25th, 2011
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. .feature leading_dot_in_identifiers
  2. .macpack generic
  3. .macpack longbranch
  4.  
  5. ; Meant to be an easy replacement for .repeat and .endrepeat
  6. ; when you're trying to save space. Uses a zeropage memory location
  7. ; instead of a register as a loop counter so as not to disturb any
  8. ; registers.
  9. ; Times - Number of times to loop ( may be a memory location )
  10. ; Free - Free zeropage memory location to use
  11. .macro .dj_loop Times, Free
  12. .scope
  13. DJ_Counter = Free
  14. lda Times
  15. sta Free
  16. DJ_Label:
  17. .endmacro
  18. .macro .end_djl
  19. NextIndex:
  20. dec DJ_Counter
  21. jne DJ_Label
  22. .endscope
  23. .endmacro
  24.  
  25.  
  26. ; Imitation of z80's djnz opcode.
  27. ; Can be on A, X, Y, or a zeropage memory location
  28. ; Label - Label to jump to
  29. ; Reg - Counter register to use: A,X,Y or memory location
  30. .macro djnz Label, Reg
  31. .if (.match({Reg}, a))
  32. sub #1
  33. .elseif (.match({Reg}, x))
  34. dex
  35. .elseif (.match({Reg}, y))
  36. dey
  37. .else
  38. dec var
  39. .endif
  40. bne Label
  41. .endmacro
  42.  
  43.  
  44. ; Working with X,Y is much more fun than working with PPU addresses
  45. ; give it an X and Y position, as well as a nametable number (0-3),
  46. ; and if you want to save the address to a 16-bit zeropage address
  47. ; ( big endian ) you can give an additional argument.
  48. ; NT - Nametable number (0-3)
  49. ; PX - X position in tiles
  50. ; PY - Y position in tiles
  51. ; Var - Variable to store address in (optional)
  52. .macro PositionXY NT, PX, PY, Var
  53. .scope
  54. t0 = $2000 + (NT * 1024) ; Nametable data starts at $2000
  55. t1 = PX ; and each nametable is 1024 bytes in size
  56. t2 = PY * 32 ; Nametable rows are 32 bytes large
  57. t3 = t0 + t1 + t2
  58. .ifblank Var
  59. lda #>t3
  60. sta $2006
  61. lda #<t3
  62. sta $2006
  63. .else
  64. lda #>t3
  65. sta Var+0
  66. lda #<t3
  67. sta Var+1
  68. .endif
  69. .endscope
  70. .endmacro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement