Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;void __fastcall__ oam_meta_spr(unsigned char x,unsigned char y,const unsigned char *data);
- ;sprid removed
- _oam_meta_spr:
- sta <PTR
- stx <PTR+1
- ldy #1 ;2 popa calls replacement, performed in reversed order
- lda (sp),y
- dey
- sta <SCRX
- lda (sp),y
- sta <SCRY
- ldx SPRID
- @1:
- lda (PTR),y ;x offset
- cmp #$80
- beq @2
- ; Did the caller request that the meta sprite be flipped?
- lda SPR_FLIP_META
- beq @skip_flip
- ; When flipped, the sprites should be draw at 8 - x_pos.
- sec
- lda #$8
- sbc (PTR),y ;x offset
- jmp @cont
- @skip_flip:
- lda (PTR),y ;x offset
- @cont:
- iny
- ; Store the sprite position in a temp while
- ; a gets used top manipulate the screen position.
- sta <SPR_POS ; store here for a moment.
- ; Is this an onscreen sprite or an offscreen sprite?
- lda SPR_OFFSCREEN_META
- beq @draw_onscreen
- ;draw_offscreen
- ; The next little chunk of code is to all us to detect
- ; wrap-around of unsigned + signed values, so that we can
- ; avoid drawing sprites that are off the screen.
- lda <SCRX ; Load up the screen position.
- eor #$80 ; Flip the high bit.
- clc ; Clear the carry flag, as needed by adc.
- adc <SPR_POS ; Add the sprite offset (signed).
- ; setting overflow if appropriate.
- eor #$80 ; Flip the high bit again.
- bvs @drawsprite ; Branch if there WAS overflow.
- jmp @skip_drawsprite
- @draw_onscreen:
- ; The next little chunk of code is to all us to detect
- ; wrap-around of unsigned + signed values, so that we can
- ; avoid drawing sprites that go off the screen.
- lda <SCRX ; Load up the screen position.
- eor #$80 ; Flip the high bit.
- clc ; Clear the carry flag, as needed by adc.
- adc <SPR_POS ; Add the sprite offset (signed).
- ; setting overflow if appropriate.
- eor #$80 ; Flip the high bit again.
- bvc @drawsprite ; Branch if there was NO overflow.
- ;jmp @skip_drawsprite
- @skip_drawsprite:
- ; a wrap happened so clean up and move to the next sprite.
- ; iny y to get to the next sprite in the meta sprite.
- iny
- iny
- iny
- jmp @skip
- @drawsprite:
- sta OAM_BUF+3,x
- lda (PTR),y ;y offset
- iny
- clc
- adc <SCRY
- sta OAM_BUF+0,x
- lda (PTR),y ;tile
- iny
- sta OAM_BUF+1,x
- ; Did the caller request that the meta sprite be flipped?
- lda SPR_FLIP_META
- beq @skip_attr_flip
- ; If the meta sprite is flipped, we need every sprite to have
- ; its horizontal flip bit... flipped.
- lda (PTR),y ;attribute
- ora #$40 ; flip
- jmp @cont_attr
- @skip_attr_flip:
- lda (PTR),y ;attribute
- @cont_attr:
- iny
- sta OAM_BUF+2,x
- @skip:
- inx
- inx
- inx
- inx
- jmp @1
- @2:
- lda <sp
- adc #1 ;2 ;carry is always set here, so it adds 3
- sta <sp
- bcc @3
- inc <sp+1
- @3:
- stx SPRID
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement