I'm trying to create a level for my game. However, the tiles are grouping up at the top.I am using FCEUX, and the tutorial I was following didn't have this problem (despite using FCEUX; I have a clean install).
Here is a minimal reproducible code for the bug:Code:
.inesprg 1 ; 1x 16KB PRG code .ineschr 1 ; 1x 8KB CHR data .inesmap 0 ; mapper 0 = NROM, no bank swapping .inesmir 1 ; background mirroring ;;;;;;;;;;;;;;;;; DECLARE SOME VARIABLES HERE .rsset $0000 ;;start variables at ram location 0currentlevel .rs 1 ; reference to the current level;;;;;;;;;;;;;;;;;; .bank 0 .org $C000 RESET: SEI ; disable 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 IRQsvblankwait1: ; First wait for vblank to make sure PPU is ready BIT $2002 BPL vblankwait1clrmem: LDA #$00 STA $0000, x STA $0100, x STA $0300, x STA $0400, x STA $0500, x STA $0600, x STA $0700, x LDA #$FE STA $0200, x INX BNE clrmem vblankwait2: ; Second wait for vblank, PPU is ready after this BIT $2002 BPL vblankwait2LoadPalettes: LDA $2002 ; read PPU status to reset the high/low latch LDA #$3F STA $2006 ; write the high byte of $3F00 address LDA #$00 STA $2006 ; write the low byte of $3F00 address LDX #$00 ; start out at 0LoadPalettesLoop: LDA palette, x ; load data from address (palette + the value in x) ; 1st time through loop it will load palette+0 ; 2nd time through loop it will load palette+1 ; 3rd time through loop it will load palette+2 ; etc STA $2007 ; write to PPU INX ; X = X + 1 CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero ; if compare was equal to 32, keep going downSetVars:;;;Set level LDA #$00 STA currentlevel LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1 STA $2000 LDA #%00011110 ; enable sprites, enable background, no clipping on left side STA $2001WaitForNMI: JMP WaitForNMI ;jump back to WaitForNMI, infinite loop, waiting for NMINMI: LDA #$00 STA $2003 ; set the low byte (00) of the RAM address LDA #$02 STA $4014 ; set the high byte (02) of the RAM address, start the transfer LDA $2002 LDA #$20 STA $2006 LDA #$00 STA $2006 ; start drawing at PPU $2000 JSR DrawBlackLine JSR DrawBlackLine JSR DrawLevel JSR DrawBlackLine ;;This is the PPU clean up section, so rendering the next frame starts properly. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1 STA $2000 LDA #%00011110 ; enable sprites, enable background, no clipping on left side STA $2001 LDA #$00 ;;tell the ppu there is no background scrolling STA $2005 STA $2005 ;;;all graphics updates done by here, run game engine GameEngineDone: JMP WaitForNMI;;;;;;;;;;;;;;; callable functionsDrawBlackLine: LDX #$00 LDA #$26DrawBlackLineLoop: STA $2007 INX CPX #$20 ; 32 is the width of the NES screen in background tiles BNE DrawBlackLineLoop RTSDrawLevel: LDX #$00 ; start out at 0DrawLevelLoop: LDA currentlevel CMP #$00 ; Level 0 BEQ DrawLevel0Loop RTSDrawLevel0Loop: LDA level0, x STA $2007 INX ; X+=1 CPX #$80 BNE DrawLevel0Loop ; Keep branching to DrawLevel0Loop until X = 32 RTS;; levelslevel0: .db $25 .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1 .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky ($24 = sky) .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2 .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky .db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3 .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$53,$54,$24,$24 ;;some brick tops .db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4 .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms;;;;;;;;;;;;;; .bank 1 .org $E000palette: .db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette .db $22,$15,$25,$1D, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette .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 is not used in this tutorial .bank 2 .org $0000 .incbin "mario.chr" ;includes 8KB graphics file
Statistics: Posted by Hipposgrumm — Mon Apr 29, 2024 1:35 pm — Replies 2 — Views 118