My comment was with regards to tepples' "template" ca65 example.
The one piece of WLA DX code I cannot figure out is this:
Code: Select all
;============================================================================
; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM
;----------------------------------------------------------------------------
; In: SRC_ADDR -- 24 bit address of source data
; DEST -- VRAM address to write to (WORD address!!)
; SIZE -- number of BYTEs to copy
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: A, X, Y
;----------------------------------------------------------------------------
;LoadBlockToVRAM SRC_ADDRESS, DEST, SIZE
; requires: mem/A = 8 bit, X/Y = 16 bit
.MACRO LoadBlockToVRAM
lda #$80
sta $2115
ldx #\2 ; DEST
stx $2116 ; $2116: Word address for accessing VRAM.
lda #:\1 ; SRCBANK
ldx #\1+\4 ; SRCOFFSET
ldy #\3 ; SIZE
jsr LoadVRAM
.ENDM
What is \4 here? It refers to the 4th argument to the macro, but the comment preceding the macro doesn't mention it. The code clearly uses it (note 2nd SpriteTiles load; it's the only call where it's non-zero)
Code: Select all
LoadBlockToVRAM SpriteTiles, $0000, $0040, $0000
LoadBlockToVRAM SpriteTiles, $100, $0040, $0040
LoadBlockToVRAM BackgroundPics, $2000, $3620, $0000 ; 384 tiles * (8bit color)= 0x6000 bytes
LoadBlockToVRAM BackgroundMap, $7000, $1000, $0000 ; 64x64 tiles = 4096 words = 8192 bytes
I fully understand what LoadVRAM does -- the contents of X make it into $4302, which is the 16-bit portion of the 24-bit address that DMA channel #0 is going to read from when populating VRAM, but I do not understand why the logic in the macro is to add argument 1 and argument 4 together to make up the 16-bit base address of where the source data is. Argument 1 = SRC_ADDR, which should be a full 24-bit address (according to the comments).
The WLA DX docs, as I expected, don't shed any light on this either.
Code: Select all
Also, if you want to use macro arguments in e.g., calculation, you can
type '\X' where X is the number of the argument. Another way to refer
to the arguments is to use their names given in the definition of the
macro (see the examples for this).
To me,
ldx #\1+\4 when doing
SpriteTiles, $100, $0040, $0040 (assume SpriteTiles full 24-bit address is $02f3f0 would result in
ldx #($20f3f0 + $0040) (the bank byte is effectively stripped), thus
ldx #$f430. What I don't understand is what the purpose of the 4th argument actually is. If I had seen
ldx #\1 I might think "the lower 16-bits of the 1st argument", but again the WLA DX docs don't shed any light on this, going back to the need for a listing generation.
I
think it's used as an "additional offset" within whatever you provide in argument 1, i.e. SpriteTiles+$0040, but the fact the macro doesn't properly document the use of the 4th argument worries me.
Edit: and your code isn't very well organised either. :-) But it's at least something I can follow a lot easier than the ca65 lorom example.