Define CHR data in asm code (NESASM) + nametable problem...

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
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Define CHR data in asm code (NESASM) + nametable problem...

Post by sdm »

I want define all CHR DATA in ASM code, how to make it correctly?? (NESASM)
I make simple sprite move program, which work corectly (i see first tile set at .defchr and i can move it) But i cannot set second tile on screen :? How to make it?

ps. Where go Tiles define in code? To VRAM or VROM??


Code: Select all

	.bank 2
	.org $0000

	.defchr $23333331,\
		$32000013,\
		$30200103,\
		$30021003,\
		$30012003,\
		$30100203,\
		$31000023,\
		$13333332

	.defchr $30000003,\
		$00000000,\
		$00223300,\
		$00211300,\
		$00211300,\
		$00223300,\
		$00000000,\
		$30000003


Last edited by sdm on Mon Jul 30, 2007 12:09 pm, edited 1 time in total.
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

I'm not familiar with NESASM syntax, but shouldn't everything be somewhere along the lines of something like ".defchr %01111110 | %10000001 (etc until 16 bytes for 1 tile)"?

Code: Select all

          *=$0000
loop      JMP loop
          .eof
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Define CHR data in asm code (NESASM)

Post by tokumaru »

sdm wrote:ps. Where go Tiles define in code? To VRAM or VROM??
I don't know NESASM either, but I know that tiles never go to VRAM by themselves, it is always the responsability of the programmer to copy tile data from PRG-ROM to CHR-RAM (in CHR-RAM carts).

I really don't know NESASM at all, but the code you showed probably just defines tiles in ROM, be it PRG-ROM or CHR-ROM. If you want to use CHR-RAM, you'll have to draw the tiles in PRG-ROM and write code to copy that to CHR-RAM. If you are just testing things out, using CHR-ROM is probably easier.
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Post by sdm »

ok. i made it:) - works

Code: Select all

	.ineschr 0

Code: Select all

Start:
	jsr tiles

Code: Select all

tiles:                  ;copy defchr tiles to VRAM

        lda #0          ;set VRAM row for first row of tiles ($0000)
        sta $2006
        lda #$10        ;blank firs tile
        sta $2006
        ldy #0
tiles1:
        lda tileset,y
        sta $2007
        iny
        cpy #$20        ;number of tiles x 16 bytes ($10) per tile
        bne tiles1
        rts

Code: Select all

tileset:

	.defchr $23333331,\
		$32000013,\
		$30200103,\
		$30021003,\
		$30012003,\
		$30100203,\
		$31000023,\
		$13333332

	.defchr $30000003,\
		$00000000,\
		$00223300,\
		$00211300,\
		$00211300,\
		$00223300,\
		$00000000,\
		$30000003
Now i want animate moving tile, somebody know how to easy make it??
User avatar
kyuusaku
Posts: 1665
Joined: Mon Sep 27, 2004 2:13 pm

Post by kyuusaku »

You can:

-Change the nametable/sprite reference (to the next frame of animation)
-Replace the tile in VRAM (with the next frame)
-Use bankswitching (depending on which mapper you're using)
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Post by sdm »

Ok... How to load full nametable into VRAM ($2000)???
I can only load first 256 (255 FF) tiles. (must be 16bit value)

Next... Why BG tiles be irregular vertically??? How to fix it? :P

Image

http://siudymus.w.interia.pl/vram_demo2.asm
http://siudymus.w.interia.pl/vram_demo2.nes

Code: Select all

	.inesprg 1
	.inesmap 0
	.inesmir 0
	.ineschr 0

	.bank 1     
	.org $FFFA
	.dw 0
	.dw Start
	.dw 0

	.bank 0
	.org $0000

YPos	.db 00
XPos	.db 00

	.org $8000
Start:

	jsr screen_off	;ekran wylaczony
	jsr cleartiles	;(?)
	jsr tiles	;kopiujemy tilesy z defchr do VRAM (w karcie)
	jsr sound
	jsr screen_on	;wlaczamy ekran

palette:

	lda #$3F	;set ppu to start of palette
	sta $2006
	lda #$00
	sta $2006
	ldx #$00

loadpal:

	lda Paldata,x
	sta $2007
	inx
	cpx #$20
	bne loadpal

	jsr loadNames

infinite:

	jsr vwait

	ldx #$00	;set start SPRRAM
	stx $2003
	ldx #$00
	stx $2003

	lda YPos	;Y
	sta $2004
	lda #$01	;tile number w pamieci VRAM na karcie
	sta $2004
	lda #%00000000	;attr
	sta $2004
	lda XPos	;X
	sta $2004


	lda #$01	;reset pada (od)
	sta $4016
	lda #$00
	sta $4016

	lda $4016
	lda $4016
	lda $4016
	lda $4016	;reset pada (do)

	lda $4016
	and #1
	bne PressU
	lda $4016
	and #1
	bne PressD
	lda $4016
	and #1
	bne PressL
	lda $4016
	and #1
	bne PressR

	jmp PressN

PressU:			;tutaj jest to, co ma byc odpalone gdy wciskamy up

	lda YPos
	sbc #1
	sta YPos
	jmp PressN

PressD:			;tutaj jest to, co ma byc odpalone gdy wciskamy down

	lda YPos
	adc #1
	sta YPos
	jmp PressN

PressL:			;tutaj jest to, co ma byc odpalone gdy wciskamy left

	lda XPos
	sbc #1
	sta XPos
	jmp PressN

PressR:			;tutaj jest to, co ma byc odpalone gdy wciskamy prawo
			; jak dodam jsr vwait, to chodzi wolniej
	lda XPos	; bo czeka za kazdym ruchem na vb
	adc #1
	sta XPos
	jmp PressN

PressN:			;tutaj jest to, co ma byc wykonane gdy nic nie wciskamy
	jmp infinite

screen_on:

	jsr vwait
	lda #%00000000
	sta $2000
	lda #%00011110	;spr on, bg off, spr no clipp
	sta $2001
	rts


screen_off:
	
	jsr vwait
	lda #$00
	sta $2000
	sta $2001
	rts

vwait:

	lda $2002	;bit $2002 ?
	bpl vwait
	rts

Paldata:

	.db $3F,$20,$10,$00,$3F,$10,$10,$10,$3F,$10,$10,$10,$3F,$00,$00,$00
	.db $3F,$16,$19,$01,$3F,$00,$00,$00,$3F,$00,$00,$00,$3F,$00,$00,$00

loadNames:

	jsr vwait
	lda #$20	;set ppu to start vram
	sta $2006
	lda #$00
	sta $2006
loadNames1:
	lda nametable,x
	sta $2007
	inx
	cpx #$FF		;zmieniamy w zaleznosci od wielkosci nametable
	bne loadNames1
	rts

nametable:

	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $02,$02,$02,$02,$01,$01,$01,$01,$02,$02,$02,$02,$01,$01,$01,$01
	.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00	;attr
	.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
	
tiles:                  ;copy defchr tiles to VRAM

        lda #0          ;set VRAM row for first row of tiles ($0000)
        sta $2006
        lda #$10        ;skip the first tile (blank space)
        sta $2006
        ldy #0          ;reset indexer
tiles1:
        lda tileset,y
        sta $2007
        iny
        cpy #$20        ;number of tiles x 16 bytes ($10) per tile
        bne tiles1
        rts

cleartiles:                     ;clears out $0000-$0FFF in VRAM

        jsr vwait
        lda #0
        sta $2006
        sta $2006
        ldy #$10
cleartiles1:
        ldx #0
cleartiles2:
        sta $2007
        dex
        bne cleartiles2
        dey
        bne cleartiles1
        rts

sound:

	lda %00011111
	sta $4015	

	lda #%10101011
	sta $4000
	lda #%11111111
	sta $4001
	lda #%11111111
	sta $4002
	lda #%11111111
	sta $4003
	rts

tileset:

	.defchr $23333331,\
		$32000013,\
		$30200103,\
		$30021003,\
		$30012003,\
		$30100203,\
		$31000023,\
		$13333332

	.defchr $30000003,\
		$00000000,\
		$00223300,\
		$00211300,\
		$00211300,\
		$00223300,\
		$00000000,\
		$30000003

;	.defchr $00001111,\
;		$00110000,\
;		$11000000,\
;		$00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000
;
;	.defchr $00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000,\
;		$00000000
;dummy tile
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

sdm wrote:Next... Why BG tiles be irregular vertically??? How to fix it? :P
The emu is probably clipping the top (and bottom) 8 scanlines. This is normal behavior since those lines are usually not visible on a TV. To "fix" this, scroll the screen up 8 pixels.
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Post by sdm »

Yes, but there is 3 pixel not 8 irregular (3pixel over the screen).
ps. i use full PAL res.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Try setting the PPUSCROLL register ($2005) every time before you turn on rendering with PPUMASK ($2001).
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Post by sdm »

ok. i fix it.
Post Reply