Posted: Fri Mar 25, 2011 5:28 pm
cool! totally understand!unregistered wrote:^ yesyesyall, sorry, I'm uncomfortable to meet with you.
NES Development Forums
https://forums.nesdev.org/
cool! totally understand!unregistered wrote:^ yesyesyall, sorry, I'm uncomfortable to meet with you.
How do you make the coordinates relative to the position of the object/character being drawn?unregistered wrote:tokumaru wrote:It may seem strange if you are doing it in a hardcoded way (manually setting up all the sprites of a particular object), but usually programmers implement a sprite system. For each possible frame of a character there is a list of the necessary sprites to draw it. It's just a series of .db or .dw statements that represent things like "this frame needs 4 sprites; the first one is at coordinates (4, 5) and uses tile $78; the second is at coordinates (12, 8) and uses tile $79 (...)". The coordinates are usually relative to the position of the object/character being drawn.
Code: Select all
aY .byte 10
aX .byte 20
.db aY, $80, $00, aX, aY, $81, $00, aX +1
Code: Select all
aY .equ 10
aX .equ 20
.db aY,$80,$00, aX, aY, $81, $00, aX +1
Really happy to have found this, thank you.unregistered wrote:tokumaru wrote:This means that the sprite system can draw any frame of any character if you point it to the correct list.
How do you point it to the correct list? So far I have thisunregistered wrote:unregistered wrote:tokumaru wrote:This means that the sprite system can draw any frame of any character if you point it to the correct list.
Code: Select all
;80 81
;90 91
;a0 a1
;b0 b1
.db aY, $80, $00, aX, aY, $81, $00, aX+8,
aY+8, $90, $00, aX, aY+8, $91, $00, aX+8,
aY+16, $a0, $00, aX, aY+16, $a1, $00, aX+8,
aY+24, $b0, $00, aX, aY+24, $b1, $00, aX+8
Code: Select all
hero_frame1:
.db aY, $80, $00, aX, aY, $81, $00, aX+8
.db aY+8, $90, $00, aX, aY+8, $91, $00, aX+8
.db aY+16, $a0, $00, aX, aY+16, $a1, $00, aX+8
.db aY+24, $b0, $00, aX, aY+24, $b1, $00, aX+8
hero_frame2:
.db aY, $82, $00, aX, aY, $83, $00, aX+8
.db aY+8, $92, $00, aX, aY+8, $93, $00, aX+8
.db aY+16, $a2, $00, aX, aY+16, $a3, $00, aX+8
.db aY+24, $b2, $00, aX, aY+24, $b3, $00, aX+8
hero_frame3:
.db aY, $84, $00, aX, aY, $85, $00, aX+8
.db aY+8, $94, $00, aX, aY+8, $95, $00, aX+8
.db aY+16, $a4, $00, aX, aY+16, $a5, $00, aX+8
.db aY+24, $b4, $00, aX, aY+24, $b5, $00, aX+8
hero_frame4:
.db aY, $86, $00, aX, aY, $87, $00, aX+8
.db aY+8, $96, $00, aX, aY+8, $97, $00, aX+8
.db aY+16, $a6, $00, aX, aY+16, $a7, $00, aX+8
.db aY+24, $b6, $00, aX, aY+24, $b7, $00, aX+8
; Operator < produces the low byte of an address
sprite_layouts_lo:
.db <hero_frame1, <hero_frame2, <hero_frame3, <hero_frame4
; Operator > produces the high byte of an address
sprite_layouts_hi:
.db >hero_frame1, >hero_frame2, >hero_frame3, >hero_frame4
; Number of hardware sprites in each layout
sprite_layouts_count:
.db 8, 8, 8, 8
draw_sprite:
; t0-t2 are temporary zero page locations holding
; the address of a particular sprite layout and the
; number of sprites left to draw
lda sprite_layouts_lo,x
sta t0
lda sprite_layouts_hi,x
sta t0+1
lda sprite_layouts_count,x
sta t2
ldy #0
; oamIndex is a variable tracking how far you've written
; into shadow OAM (customarily at $0200-$02FF)
ldx oamIndex
@loop:
; If you have the address of an array in a zero page pointer,
; you use the (d),y addressing mode and increase Y to go
; to the next byte.
lda (t0),y
iny
; etc.
dec t2
bne @loop
stx oamIndex
rts
some_other_method:
ldx #2
jsr draw_sprite
Thank you tepples! And thank you qbradq for your work... haven't really thought about it yet, sorry, tired. And thank you tokumaru! This is the second time, i think, you have explained step by step the first guy's help and that helps me so much too! Tomorrow is going to be so much fun! Good night.tepples wrote:It'd go a little something like this (untested):Code: Select all
hero_frame1: .db aY, $80, $00, aX, aY, $81, $00, aX+8 .db aY+8, $90, $00, aX, aY+8, $91, $00, aX+8 .db aY+16, $a0, $00, aX, aY+16, $a1, $00, aX+8 .db aY+24, $b0, $00, aX, aY+24, $b1, $00, aX+8 hero_frame2: .db aY, $82, $00, aX, aY, $83, $00, aX+8 .db aY+8, $92, $00, aX, aY+8, $93, $00, aX+8 .db aY+16, $a2, $00, aX, aY+16, $a3, $00, aX+8 .db aY+24, $b2, $00, aX, aY+24, $b3, $00, aX+8 hero_frame3: .db aY, $84, $00, aX, aY, $85, $00, aX+8 .db aY+8, $94, $00, aX, aY+8, $95, $00, aX+8 .db aY+16, $a4, $00, aX, aY+16, $a5, $00, aX+8 .db aY+24, $b4, $00, aX, aY+24, $b5, $00, aX+8 hero_frame4: .db aY, $86, $00, aX, aY, $87, $00, aX+8 .db aY+8, $96, $00, aX, aY+8, $97, $00, aX+8 .db aY+16, $a6, $00, aX, aY+16, $a7, $00, aX+8 .db aY+24, $b6, $00, aX, aY+24, $b7, $00, aX+8 ; Operator < produces the low byte of an address sprite_layouts_lo: .db <hero_frame1, <hero_frame2, <hero_frame3, <hero_frame4 ; Operator > produces the high byte of an address sprite_layouts_hi: .db >hero_frame1, >hero_frame2, >hero_frame3, >hero_frame4 ; Number of hardware sprites in each layout sprite_layouts_count: .db 8, 8, 8, 8 draw_sprite: ; t0-t2 are temporary zero page locations holding ; the address of a particular sprite layout and the ; number of sprites left to draw lda sprite_layouts_lo,x sta t0 lda sprite_layouts_hi,x sta t0+1 lda sprite_layouts_count,x sta t2 ldy #0 ; oamIndex is a variable tracking how far you've written ; into shadow OAM (customarily at $0200-$02FF) ldx oamIndex @loop: ; If you have the address of an array in a zero page pointer, ; you use the (d),y addressing mode and increase Y to go ; to the next byte. lda (t0),y iny ; etc. dec t2 bne loop stx oamIndex rts some_other_method: ldx #2 jsr draw_sprite
Code: Select all
draw_sprite:
; t0-t2 are temporary zero page locations holding
; the address of a particular sprite layout and the
; number of sprites left to draw
lda sprite_layouts_lo, x
sta t0
lda sprite_layouts_hi, x
sta t0+1
lda sprite_layouts_count, x
sta t2
ldy #0
; oamIndex is a variable tracking how far you've written
; into shadow OAM (customarily at $0200-$02FF)
ldx oamIndex
@loop:
; If you have the address of an array in a zero page pointer,
; you use the (d),y addressing mode and increase Y to go
; to the next byte.
lda (t0), y
iny
;ect.
dec t2
bne loop ;########(LINE NUMBER 250)
stx oamIndex
rts
; Set initial value of dx
lda #$01
sta dx
rts
; Load palette into $3F00
load_palette:
I don't understand though.koitsu wrote:Branch instructions range from +127 to -128. It's just a signed 8-bit number.
Code: Select all
bne @loop