Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .macpack generic ; add and sub
- .macpack longbranch ; jeq, jne, jcc, jcs
- ; Meant to be an easy replacement for .repeat and .endrepeat
- ; when you're trying to save space. Uses a zeropage memory location
- ; instead of a register as a loop counter so as not to disturb any
- ; registers.
- ; Times - Number of times to loop ( may be a memory location )
- ; Free - Free zeropage memory location to use
- .macro .dj_loop Times, Free
- .scope
- DJ_Counter = Free
- lda Times
- sta Free
- DJ_Label:
- .endmacro
- .macro .end_djl
- NextIndex:
- dec DJ_Counter
- jne DJ_Label
- .endscope
- .endmacro
- ; Working with X,Y is much more fun than working with PPU addresses
- ; give it an X and Y position, as well as a nametable number (0-3),
- ; and if you want to save the address to a 16-bit zeropage address
- ; ( big endian ) you can give an additional argument.
- ; NT - Nametable number (0-3)
- ; PX - X position in tiles
- ; PY - Y position in tiles
- ; Var - Variable to store address in (optional)
- .macro PositionXY NT, PX, PY, Var
- .scope
- t0 = $2000 + (NT * 1024) ; Nametable data starts at $2000
- t1 = PX ; and each nametable is 1024 bytes in size
- t2 = PY * 32 ; Nametable rows are 32 bytes large
- t3 = t0 + t1 + t2
- .ifblank Var ; Are we going to be writing this directly to PPUADDR?
- lda #>t3
- sta $2006
- lda #<t3
- sta $2006
- .else ; Are we going to be storing this to a pointer in zeropage instead?
- lda #>t3
- sta Var+0
- lda #<t3
- sta Var+1
- .endif
- .endscope
- .endmacro
- .macro .nyb InpA, InpB ; Makes a .byt storing two 4 bit values
- .byt ( InpA<<4 ) | InpB
- .endmacro
- .macro .raddr This ; like .addr but for making "RTS trick" tables with
- .addr This-1
- .endmacro
- ; swap using X
- .macro swapx mema, memb
- ldx mema
- lda memb
- stx memb
- sta mema
- .endmacro
- ; swap using Y
- .macro swapy mema, memb
- ldy mema
- lda memb
- sty memb
- sta mema
- .endmacro
- ; swap using just A + stack
- .macro swapa mema, memb
- lda mema
- pha
- lda memb
- sta mema
- pla
- sta memb
- .endmacro
- .macro neg
- eor #255
- add #1
- .endmacro
- .macro abs ; absolute value
- .local Skip
- bpl Skip
- neg
- Skip:
- .endmacro
- .macro sex ; sign extend
- .local Skip
- ora #$7F
- bmi Skip
- lda #0
- Skip:
- .endmacro
- .macro neg16 lo, hi
- sec ;Ensure carry is set
- lda #0 ;Load constant zero
- sbc lo ;... subtract the least significant byte
- sta lo ;... and store the result
- lda #0 ;Load constant zero again
- sbc hi ;... subtract the most significant byte
- sta hi ;... and store the result
- .endmacro
- .macro pushaxy
- pha
- txa
- pha
- tya
- pha
- .endmacro
- .macro pullaxy
- pla
- tay
- pla
- tax
- pla
- .endmacro
- .macro pushax
- pha
- txa
- pha
- .endmacro
- .macro pullax
- pla
- tax
- pla
- .endmacro
- .macro pushay
- pha
- tya
- pha
- .endmacro
- .macro pullay
- pla
- tay
- pla
- .endmacro
- .macro addcarry to
- .local Skip
- bcc Skip
- inc to
- Skip:
- .endmacro
- .macro subcarry to
- .local Skip
- bcs Skip
- dec to
- Skip:
- .endmacro
- .macro addcarryx to
- .local Skip
- bcc Skip
- inc to,x
- Skip:
- .endmacro
- .macro subcarryx to
- .local Skip
- bcs Skip
- dec to,x
- Skip:
- .endmacro
- .macro RealPosToScreenPos RealLo, RealHi, Scroll, Store
- lda RealLo
- sub Scroll+0
- sta Store
- lda RealHi
- sbc Scroll+1
- .repeat 4
- lsr
- ror Store
- .endrep
- .endmacro
- .macro RealPosToScreenPosByX RealLo, RealHi, Scroll, Store
- lda RealLo,x
- sub Scroll+0
- sta Store
- lda RealHi,x
- sbc Scroll+1
- .repeat 4
- lsr
- ror Store
- .endrep
- .endmacro
- .macro ChrFile File, Size, Address
- .word Address
- .byt (Size/128)
- .incbin File
- .endmacro
- .macro LSpr Type, Direction, XPos, YPos, Extra
- .byt XPos
- .ifnblank Extra
- .byt (Extra<<4)|YPos
- .else
- .byt YPos
- .endif
- .byt (Type<<1)|Direction
- .endmacro
- .macro LObj Type, XPos, YPos, Extra1, Extra2
- .byt Type
- .byt (XPos<<4)|YPos
- .ifnblank Extra1
- .byt Extra1
- .ifnblank Extra2
- .byt Extra2
- .endif
- .endif
- .endmacro
- .macro LObjN Type, XPos, YPos, Width, Height, Extra
- LObj Type, XPos, YPos, (Width<<4)|Height
- .ifnblank Extra
- .byt Extra
- .endif
- .endmacro
- .macro LFinished
- .byt $f0
- .endmacro
- .macro LSetX NewX
- .byt $f1, NewX
- .endmacro
- .macro LWriteCol Col1, Col2, Col3
- .ifnblank Col3
- .byt $f4
- .byt Col1, Col2, Col3
- .else
- .ifnblank Col2
- .byt $f3
- .byt Col1, Col2
- .else
- .byt $f2
- .byt Col1
- .endif
- .endif
- .endmacro
- .macro LXMinus16
- .byt $f5
- .endmacro
- .macro LXPlus16
- .byt $f6
- .endmacro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement