{"author_name":"GreaseMonkey","cat":"LD #22","comments":[],"epoch":1324090920,"likes":1,"metadata":{"p_key":"62139","p_author":"GreaseMonkey","p_authorkey":"2396","p_urlkey":"97905","p_title":"Sprite flipping","p_cat":"LD #22","p_event":"LD22","p_time":"1324090920","p_likes":"1","p_comments":"0","p_status":"UPD5","us_key":"2396","us_name":"GreaseMonkey","us_username":"greasemonkey","event_start":"1323993600","event_key":"8","event_name":"LD22"},"text":"<p>I&#8217;ve filled in the other 3 frames required, and set it up so that it only loads one frame of animation into VRAM. There are enough scanlines to do this completely in VBlank with a comfortable amount of headroom; unfortunately, the method used isn&#8217;t fast enough to require me to slow it down during not-VBlank, and so this provides no speed advantage.<\/p>\n <p>Anyhow, on the topic of sprite flipping. The TMS9918A provides a lovely feature which allows you to flip tile data horizontally and\/or vertically. Unfortunately, this was not provided with sprites, despite the fact that there&#8217;s a blatantly unused section which would have been <em>perfect<\/em> for sticking these flags in. So you have to flip the sprites manually.<\/p>\n <p>This is where we use a table to perform the flip. It looks like this:<\/p>\n <p><strong>(\u256f\u00b0\u25a1\u00b0\uff09\u256f\ufe35 \u253b\u2501\u253b<\/strong><\/p>\n <p>Erm, I mean THIS:<\/p>\n <blockquote><p>.macro m_build_fliptab_gen<br \/>\n .redefine mv_q 0<br \/>\n .rept 256<br \/>\n .redefine mv_x mv_q<br \/>\n .redefine mv_x (((mv_x&lt;&lt;1)&amp;$AA)|((mv_x&gt;&gt;1)&amp;$55))<br \/>\n .redefine mv_x (((mv_x&lt;&lt;2)&amp;$CC)|((mv_x&gt;&gt;2)&amp;$33))<br \/>\n .redefine mv_x (((mv_x&lt;&lt;4)&amp;$F0)|((mv_x&gt;&gt;4)&amp;$0F))<br \/>\n .db mv_x<br \/>\n .redefine mv_q 1+mv_q<br \/>\n .endr<br \/>\n .endm<\/p><\/blockquote>\n <p>I also have one which generates a &#8220;no flip table&#8221; which is just a bunch of bytes from 0 to 255.<\/p>\n <p>Here&#8217;s the code:<\/p>\n <blockquote><p>ld de,$0000<br \/>\n &#8211;:<br \/>\n .rept 4<br \/>\n rst $08<br \/>\n .endr<\/p>\n <p>; load sprite<br \/>\n ld hl,$4000 + ($7C * 32)<br \/>\n ld bc,$80BF<br \/>\n out (c),l<br \/>\n out (c),h<\/p>\n <p>ld hl,g_spriteset_plr<br \/>\n add hl,de<br \/>\n push de<br \/>\n ld d,fliptab&gt;&gt;8<br \/>\n -:<br \/>\n ld e,(hl) ; 19<br \/>\n inc l ; 23<br \/>\n ld a,(de) ; 30<br \/>\n out ($BE),a ; 41 &#8211; SAFE<br \/>\n djnz &#8211; ; START: 12<br \/>\n pop de<\/p>\n <p>ex de,hl<br \/>\n ld de,$0080<br \/>\n add hl,de<br \/>\n ex de,hl<br \/>\n ld a,d<br \/>\n and $02 -1<br \/>\n ld d,a<\/p>\n <p>; there&#8217;s still plenty of breathing room<br \/>\n ; mednafen reports $DA with the occasional flicker of $D5<\/p>\n <p>jp &#8212;<\/p><\/blockquote>\n <p>I hope you can work out whether the walk animation is any good or not. I&#8217;ve loaded it into an unused space of VRAM. If you look carefully, you&#8217;ll notice that one of the frames involves the player bobbing up. See, I put in effort!<\/p>\n <p><a href=\"http:\/\/www.ludumdare.com\/compo\/2011\/12\/16\/sprite-flipping\/screeny183\/\" rel=\"attachment wp-att-88021\"><img class=\"alignnone size-large wp-image-88021\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2011\/12\/screeny183-550x527.png\" alt=\"flip table\" width=\"550\" height=\"527\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2011\/12\/screeny183-300x287.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2011\/12\/screeny183-550x527.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2011\/12\/screeny183.png 772w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/p>\n <p>&nbsp;<\/p>","time":"December 16th, 2011 10:02 pm","title":"Sprite flipping"}