Issue with maps

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
sneed_generator
Posts: 15
Joined: Wed Feb 21, 2024 7:47 pm

Issue with maps

Post by sneed_generator »

Basically, I'm trying to build a room in a map in quarters--there's a certain number of possible patterns stored in bank 1, all under the label "quarters." There's another section directly beneath it called "quarterAddresses."

My problem I'm having is that it works for the first twelve quarters, but thirteen draws nonsense on the screen, and fourteen, which I created so I could figure out what's going on, just shows a blank screen.

Does anybody know what I'm doing wrong? Here's my code:

Code: Select all

  .inesprg 1   ; 2x 16KB PRG code banks (banks 0, 1, 2, 3)
  .ineschr 1   ; 1x  8KB CHR data banks (bank 4)
  .inesmap 0   ; mapper (0 = NROM), no bank swapping
  .inesmir 1   ; 0 = horizontal background mirroring (for vertical scrolling)

  .bank 0
  .org $C000
  .rsset      $0000
bgLow      .rs 1
bgHigh     .rs 1
smLow      .rs 1
smHigh     .rs 1
compPtr    .rs 1
rowFlag    .rs 1
randSeed   .rs 1
randNum    .rs 1
quarter    .rs 1
roomIndex  .rs 1
qOffset    .rs 1
urQOffset  .rs 1

RESET:
    sei        ; ignore IRQs
    cld        ; disable decimal mode
    ldx #$40
    stx $4017  ; disable APU frame IRQ
    ldx #$ff
    txs        ; Set up stack
    inx        ; now X = 0
    stx $2000  ; disable NMI
    stx $2001  ; disable rendering
    stx $4010  ; disable DMC IRQs

    ; Optional (omitted):
    ; Set up mapper and jmp to further init code here.

    ; The vblank flag is in an unknown state after reset,
    ; so it is cleared here to make sure that @vblankwait1
    ; does not exit immediately.
    bit $2002

    ; First of two waits for vertical blank to make sure that the
    ; PPU has stabilized
vblankwait1:  
    bit $2002
    bpl vblankwait1

    ; We now have about 30,000 cycles to burn before the PPU stabilizes.
    ; One thing we can do with this time is put RAM in a known state.
    ; Here we fill it with $00, which matches what (say) a C compiler
    ; expects for BSS.  Conveniently, X is still 0.
    txa
clrmem:
    sta $000,x
    sta $000,x
    sta $200,x
    sta $300,x
    sta $400,x
    sta $500,x
    sta $600,x
    sta $700,x
    inx
    bne clrmem

    ; Other things you can do between vblank waits are set up audio
    ; or set up other mapper registers.
   
vblankwait2:
  bit $2002
  bpl vblankwait2

setZeroes:
  lda #$00
  sta bgHigh
  sta bgLow
  sta rowFlag
  sta compPtr
  sta qOffset

disableNMI:	
  lda #%00000000 
  sta $2000
  lda #%00000000
  sta $2001


  
loadPalettes:
  
  lda #HIGH(bgPalettes)
  sta bgHigh
  lda #LOW(bgPalettes)
  sta bgLow
  
  
  ldy #$00
  
  lda $2002
  lda #$3F
  sta $2006
  lda #$00
  sta $2006
  
  lda #$0F
  sta $2007
  
  loadPalettesLoop:
  lda bgPalettes, y
  sta $2007
  iny
  cpy #8
  bne loadPalettesLoop
 
lockScroll:
  lda #$00
  sta $2005
  sta $2005	

  lda #14
  sta quarter

  jsr loadBasicMap
  jsr loadQuarter
  ;inc quarter
  inc qOffset
  jsr loadQuarter
  ;inc quarter
  inc qOffset
  jsr loadQuarter
  ;inc quarter 
  inc qOffset
  jsr loadQuarter
  jsr loadTestMap
  
  lda #$00
  sta randSeed
  

	
  lda $2002
  lda #%10010000
  sta $2000
  lda #%00111110
  sta $2001  
  

infinite:

  jmp infinite

	
NMI:
  lda #$00
  sta $2003
  lda #$02
  sta $4014
  
  lda #$00
  sta $2005
  sta $2005	

  rti
  
loadQuarter:
  lda qOffset
  sta urQOffset
  
  ldx #$00
  
  lda #HIGH($0500)
  sta smHigh
  lda #LOW($0500)
  sta smLow  

  pha
  txa
  pha
  
  ldy qOffset

  clc
  adc quarterStart, y
  sta smLow
  
  pla
  tax
  pla

  ldy quarter
  lda qHigh, y
  sta bgHigh
  lda qLow, y
  sta bgLow

  ldy #$00
  ldx #$00

  loadQuarterLoop:
  lda [bgLow], y
  sta [smLow], y
  
  iny
  cpy #7
  bne loadQuarterLoop
  
  lda smLow
  clc
  adc #16
  sta smLow
  
  lda bgLow
  clc
  adc #$07
  sta bgLow
  
  ldy #$00
  
  inx
  cpx #$06
  bne loadQuarterLoop
 	
	
	
  rts
  
loadTestMap:
  ldy #$00
  ldx #$00
  
  lda $2002
  lda #$20
  sta $2006
  lda #$00
  sta $2006
  
  ldy #$00
  
  loadTestMapLoop:
  lda $0500, y
  tax
  lda TL, x
  sta $2007
  lda TR, x
  sta $2007
  
  tya
  pha
  ldy compPtr
  lda BL, x
  sta $0400, y
  iny
  lda BR, x
  sta $0400, y
  iny
  tya
  sta compPtr
  
  
  
  pla
  tay
  
  lda compPtr
  cmp #32
  beq dropSecondRow
    
  returnFromSecondRow:
  
  iny
  cpy #240
  bne loadTestMapLoop
  
  rts
  
dropSecondRow:
  tya
  pha
  
  ldy #$00
  
  loadSecondRowLoop:
  lda $0400, y
  sta $2007
  
  lda #$00
  sta $0400, y
  
  iny
  cpy #32  
  bne loadSecondRowLoop
  
  lda #$00
  sta compPtr
  
  pla
  tay
  
  jmp returnFromSecondRow
  rts

loadBasicMap:
  tya
  pha
  
  lda #$01
  ldy #$00
  
  loadBasicMapLoop:
  lda baseMap, y
  sta $0500, y
  iny  
  cpy #240
  bne loadBasicMapLoop
  
  pla
  tay
  rts

  
  
  .bank 1
  .org $E000
  
  quarters:
  quarter1:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $01, $01, $01, $01, $04
  .byte $04, $01, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $04, $01, $01, $04
  .byte $04, $01, $04, $04, $01, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter2:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $01, $01, $01, $01, $04
  .byte $04, $04, $04, $04, $04, $01, $04
  .byte $04, $01, $01, $04, $04, $01, $04
  .byte $04, $01, $01, $04, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
   quarter3:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $04, $01, $01, $04
  .byte $04, $01, $04, $04, $01, $01, $04
  .byte $04, $01, $04, $04, $04, $04, $04
  .byte $04, $01, $01, $01, $01, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04

  quarter4:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $01, $04, $04, $01, $04
  .byte $04, $01, $01, $04, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $01, $04
  .byte $04, $01, $01, $01, $01, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04

  quarter5:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter6:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $01, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $01, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $01, $04, $01, $04
  
  quarter7:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $01, $04, $01, $04, $01
  .byte $01, $04, $01, $04, $01, $04, $01
  .byte $01, $04, $01, $04, $01, $04, $01
  .byte $04, $04, $01, $04, $01, $04, $01
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter8:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $01, $04, $01, $04, $01, $04, $04
  .byte $01, $04, $01, $04, $01, $04, $01
  .byte $01, $04, $01, $04, $01, $04, $01
  .byte $01, $04, $01, $04, $01, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter9:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $01, $04, $01, $04, $04
  .byte $04, $01, $04, $04, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $01, $04, $01, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter10:
  .byte $04, $01, $04, $01, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $01, $04, $01, $04, $01, $04, $01
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $01, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter11:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $01, $01, $01, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $01, $01, $01, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter12:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $01, $04, $04, $04, $01, $04
  .byte $04, $01, $04, $01, $04, $01, $04
  .byte $04, $01, $04, $01, $04, $01, $04
  .byte $04, $01, $04, $04, $04, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter13:
  .byte $04, $04, $04, $04, $04, $04, $04
  .byte $04, $04, $04, $01, $04, $04, $04
  .byte $04, $01, $04, $04, $04, $01, $04
  .byte $04, $01, $04, $04, $04, $01, $04
  .byte $04, $04, $04, $01, $04, $04, $04
  .byte $04, $04, $04, $04, $04, $04, $04
  
  quarter14:
  .byte $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01  
  .byte $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01
  
  quarterAddresses:
  qHigh:
  .byte $E0, $E0, $E0, $E0, $E0, $E0, $E0, $E1, $E1, $E1, $E1, $E1, $E1, $E2
  qLow: 
  .byte $00, $2A, $54, $7E, $A8, $D2, $FC, $26, $50, $7A, $A4, $CE, $F8, $22
  
  quarterStart:
  .byte $21, $28, $81, $88
  
  tileDefinitions:
  TL: .byte $00, $01, $05, $00, $21, $22, $26, $27, $28, $29
  TR: .byte $00, $02, $06, $00, $21, $23, $26, $27, $28, $29
  BL: .byte $00, $03, $07, $00, $21, $24, $26, $27, $28, $29
  BR: .byte $00, $04, $08, $00, $21, $25, $26, $27, $28, $29

  bgPalettes:
  .byte $0F, $09, $16, $27, $04, $0B, $1A, $29
  
  baseMap:
  .byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
  .byte $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01


  
  
  .org $FFFA     ; first of the three vectors starts here
    .dw NMI        ; when an NMI happens (once per frame if enabled) the processor will jump to the label NMI:
    .dw RESET      ; when the processor first turns on or is reset, it will jump to the label RESET:
    .dw 0          ; external interrupt IRQ unused

  .bank 2
  .org $0000
  .incbin "bwzrd.chr"  
  
Attachments
dng.nes
(32.02 KiB) Downloaded 12 times
dng.asm
(10.45 KiB) Downloaded 11 times
bwzrd.chr
(16 KiB) Downloaded 10 times
User avatar
tokumaru
Posts: 12459
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Issue with maps

Post by tokumaru »

It could be that you're not doing a proper 16-bit addition when incrementing your pointers (bgLow and smLow), so when a quarter crosses a page boundary you're getting the wrong data.
User avatar
donato-zits-
Posts: 65
Joined: Fri Jun 03, 2022 11:14 am
Contact:

Re: Issue with maps

Post by donato-zits- »

where are you studying?Metatiles right? do you like to follow/have templates to build your algorithms?
viewtopic.php?t=24252 <<<<my game
viewtopic.php?t=25285 <<<my second game
sneed_generator
Posts: 15
Joined: Wed Feb 21, 2024 7:47 pm

Re: Issue with maps

Post by sneed_generator »

tokumaru wrote: Thu Sep 26, 2024 3:20 am It could be that you're not doing a proper 16-bit addition when incrementing your pointers (bgLow and smLow), so when a quarter crosses a page boundary you're getting the wrong data.
I'll have to look into that. Thanks.
sneed_generator
Posts: 15
Joined: Wed Feb 21, 2024 7:47 pm

Re: Issue with maps

Post by sneed_generator »

donato-zits- wrote: Thu Sep 26, 2024 5:13 am where are you studying?Metatiles right? do you like to follow/have templates to build your algorithms?
Mainly Famicom.party, but most of this was me figuring stuff out. Apparently not the best way of doing it ig
Post Reply