Advertisement
mhughson

oam_meta_spr

Dec 20th, 2022
2,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;void __fastcall__ oam_meta_spr(unsigned char x,unsigned char y,const unsigned char *data);
  2. ;sprid removed
  3.  
  4. _oam_meta_spr:
  5.  
  6.     sta <PTR
  7.     stx <PTR+1
  8.  
  9.     ldy #1      ;2 popa calls replacement, performed in reversed order
  10.     lda (sp),y
  11.     dey
  12.     sta <SCRX
  13.     lda (sp),y
  14.     sta <SCRY
  15.    
  16.     ldx SPRID
  17.  
  18. @1:
  19.  
  20.     lda (PTR),y     ;x offset
  21.     cmp #$80
  22.     beq @2
  23.    
  24.     ; Did the caller request that the meta sprite be flipped?
  25.     lda SPR_FLIP_META
  26.     beq @skip_flip
  27.  
  28.     ; When flipped, the sprites should be draw at 8 - x_pos.
  29.     sec
  30.     lda #$8
  31.     sbc (PTR),y     ;x offset
  32.     jmp @cont
  33.  
  34. @skip_flip:
  35.  
  36.     lda (PTR),y     ;x offset
  37.  
  38. @cont:
  39.  
  40.     iny
  41.     ; Store the sprite position in a temp while
  42.     ; a gets used top manipulate the screen position.
  43.     sta <SPR_POS ; store here for a moment.
  44.  
  45.     ; Is this an onscreen sprite or an offscreen sprite?
  46.     lda SPR_OFFSCREEN_META
  47.     beq @draw_onscreen
  48.  
  49. ;draw_offscreen
  50.  
  51.     ; The next little chunk of code is to all us to detect
  52.     ; wrap-around of unsigned + signed values, so that we can
  53.     ; avoid drawing sprites that are off the screen.
  54.     lda <SCRX       ; Load up the screen position.
  55.     eor #$80        ; Flip the high bit.
  56.     clc             ; Clear the carry flag, as needed by adc.
  57.     adc <SPR_POS    ; Add the sprite offset (signed).
  58.                     ; setting overflow if appropriate.
  59.     eor #$80        ; Flip the high bit again.
  60.     bvs @drawsprite ; Branch if there WAS overflow.
  61.     jmp @skip_drawsprite
  62.  
  63. @draw_onscreen:
  64.  
  65.     ; The next little chunk of code is to all us to detect
  66.     ; wrap-around of unsigned + signed values, so that we can
  67.     ; avoid drawing sprites that go off the screen.
  68.     lda <SCRX       ; Load up the screen position.
  69.     eor #$80        ; Flip the high bit.
  70.     clc             ; Clear the carry flag, as needed by adc.
  71.     adc <SPR_POS    ; Add the sprite offset (signed).
  72.                     ; setting overflow if appropriate.
  73.     eor #$80        ; Flip the high bit again.
  74.     bvc @drawsprite ; Branch if there was NO overflow.
  75. ;jmp @skip_drawsprite
  76.  
  77. @skip_drawsprite:
  78.     ; a wrap happened so clean up and move to the next sprite.
  79.     ; iny y to get to the next sprite in the meta sprite.
  80.     iny
  81.     iny
  82.     iny
  83.     jmp @skip
  84. @drawsprite:
  85.     sta OAM_BUF+3,x
  86.     lda (PTR),y     ;y offset
  87.     iny
  88.     clc
  89.     adc <SCRY
  90.     sta OAM_BUF+0,x
  91.     lda (PTR),y     ;tile
  92.     iny
  93.     sta OAM_BUF+1,x
  94.  
  95.     ; Did the caller request that the meta sprite be flipped?
  96.     lda SPR_FLIP_META
  97.     beq @skip_attr_flip
  98.  
  99.     ; If the meta sprite is flipped, we need every sprite to have
  100.     ; its horizontal flip bit... flipped.
  101.     lda (PTR),y     ;attribute
  102.     ora #$40 ; flip
  103.     jmp @cont_attr
  104. @skip_attr_flip:
  105.     lda (PTR),y     ;attribute
  106. @cont_attr:
  107.     iny
  108.     sta OAM_BUF+2,x
  109. @skip:
  110.     inx
  111.     inx
  112.     inx
  113.     inx
  114.     jmp @1
  115.  
  116. @2:
  117.  
  118.     lda <sp
  119.     adc #1 ;2           ;carry is always set here, so it adds 3
  120.     sta <sp
  121.     bcc @3
  122.     inc <sp+1
  123.  
  124. @3:
  125.  
  126.     stx SPRID
  127.     rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement