Code: Select all
backgroundPalette1: .res 3
backgroundPalette2: .res 3
backgroundPalette3: .res 3
backgroundPalette4: .res 3
lda #$00
tax
@fillPalette:
lda (paletteData), x
sta (backgroundPalette1, x
inx
cpx #12
bne @fillPalette
Moderator: Moderators
Code: Select all
backgroundPalette1: .res 3
backgroundPalette2: .res 3
backgroundPalette3: .res 3
backgroundPalette4: .res 3
lda #$00
tax
@fillPalette:
lda (paletteData), x
sta (backgroundPalette1, x
inx
cpx #12
bne @fillPalette
for those who search this question on the future, it is not possible, at least with my assembler ca65nyanberrycake wrote: ↑Sun Sep 13, 2020 5:11 pmI have palettes set up in ram one after another. For simplicity's sake I would like to fill them all with one loop while still keeping labels on them separately. Is there any harm to this (besides possibly being "bad style"
Code: Select all
backgroundPalette1: .res 3 backgroundPalette2: .res 3 backgroundPalette3: .res 3 backgroundPalette4: .res 3 lda #$00 tax @fillPalette: lda (paletteData), x sta (backgroundPalette1, x inx cpx #12 bne @fillPalette
It's totally ok to do so in asm, but don't forget about .align directive which can add padding bytes between arrays.nyanberrycake wrote: ↑Sun Sep 13, 2020 5:11 pmFor simplicity's sake I would like to fill them all with one loop while still keeping labels on them separately.
Code: Select all
backgroundPalette1: .res 4
backgroundPalette2: .res 4
backgroundPalette3: .res 4
backgroundPalette4: .res 4
ldy #15
@fillPalette:
lda (paletteData), y
sta backgroundPalette1, y
dey
bpl @fillPalette
Code: Select all
ldx #15
@fillPalette:
lda paletteData,x
sta backgroundPalette1, x
dex
bpl @fillPalette
This information is not correct. You can definitely use indices past the end of tables/labels in any assembler, as long as you know what you're doing and are 100% sure that the data is stored in memory sequentially.nyanberrycake wrote: ↑Sun Sep 13, 2020 6:34 pmfor those who search this question on the future, it is not possible, at least with my assembler ca65
Code: Select all
palette .res 32
backgroundPalette = palette
spritePalette = palette + 16
Code: Select all
.macro staBGpal pal, entry
sta backgroundPalette + (pal * 4) + entry
.endmacro
; example
lda #$29
staBGpal 1,1
Code: Select all
backgroundPalette:
backgroundPalette1: .res 4
backgroundPalette2: .res 4
backgroundPalette3: .res 4
backgroundPalette4: .res 4
This is the solution I use when I need to access multiple tables from one "master" label.Movax12 wrote: ↑Mon Sep 14, 2020 12:39 pmCode: Select all
backgroundPalette: backgroundPalette1: .res 4 backgroundPalette2: .res 4 backgroundPalette3: .res 4 backgroundPalette4: .res 4
Agreed. I just increment the PPU pointer with meaningless data in the first slot when loading palettes in a loop and store global BG after at $3F20.tokumaru wrote: ↑Mon Sep 14, 2020 4:33 pmFor palettes specifically I don't waste space with the unused colors though, so I have a variable for the global background color, and 8 sets of 3 colors (total of 25 colors, instead of 32). I don't see any point in pretending that NES palettes are 4 colors when they really aren't.
You can also increment the pointer by reading $2007 using the BIT instruction, which doesn't affect any registers, so you don't have to do the BG color last if you don't want to.Controllerhead wrote: ↑Mon Sep 14, 2020 5:14 pmI just increment the PPU pointer with meaningless data in the first slot when loading palettes in a loop and store global BG after at $3F20.
Oziphantom wrote: ↑Mon Sep 14, 2020 1:07 amyes I mistyped that example. I know that (address), y is for pointers, not arrays. Maybe that's why I got undefined behaviour when i tried itCode: Select all
backgroundPalette1: .res 4 backgroundPalette2: .res 4 backgroundPalette3: .res 4 backgroundPalette4: .res 4 ldy #15 @fillPalette: lda (paletteData), y sta backgroundPalette1, y dey bpl @fillPalette
but is paletteData a vector point to the data or just an address, because if its an address you can doCode: Select all
ldx #15 @fillPalette: lda paletteData,x sta backgroundPalette1, x dex bpl @fillPalette
tokumaru wrote: ↑Mon Sep 14, 2020 4:33 pmThis is the solution I use when I need to access multiple tables from one "master" label.Movax12 wrote: ↑Mon Sep 14, 2020 12:39 pmCode: Select all
backgroundPalette: backgroundPalette1: .res 4 backgroundPalette2: .res 4 backgroundPalette3: .res 4 backgroundPalette4: .res 4
For palettes specifically I don't waste space with the unused colors though, so I have a variable for the global background color, and 8 sets of 3 colors (total of 25 colors, instead of 32). I don't see any point in pretending that NES palettes are 4 colors when they really aren't.
Yeah I didn't mean to write the (), xtokumaru wrote: ↑Mon Sep 14, 2020 3:14 amThis information is not correct. You can definitely use indices past the end of tables/labels in any assembler, as long as you know what you're doing and are 100% sure that the data is stored in memory sequentially.nyanberrycake wrote: ↑Sun Sep 13, 2020 6:34 pmfor those who search this question on the future, it is not possible, at least with my assembler ca65
Your problem here is that you're trying to use an addressing mode that doesn't exist on the 6502: lda (zp), x doesn't exist. The only indirect addressing mode that uses the X register is (zp, x), where X is added to the address of the pointer itself, not the address that the pointer points to. You have to use the Y register for what your trying to do.
Assembler is different from high-level languages in that you can't just learn the syntax and use every addressing mode and operation with every register, each operation is physically implemented inside the CPU, and not all combinations of operations, addressing modes and registers are available. You have to consult the documentation in order to see if a particular combination you want to use exists. With time you get the hang of what exists and what doesn't.