<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Sprite-to-hex automater</title>
		<link>https://tibasicdev.wikidot.com/forum/t-13216405/sprite-to-hex-automater</link>
		<description>Posts in the discussion thread &quot;Sprite-to-hex automater&quot; - I need help optimizing a program that you can draw an 8x8 sprite in, and then output the 16-character hex code for it.</description>
				<copyright></copyright>
		<lastBuildDate>Mon, 16 Nov 2026 22:37:29 +0000</lastBuildDate>
		
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-13216405#post-4588932</guid>
				<title>Re: Sprite-to-hex automater</title>
				<link>https://tibasicdev.wikidot.com/forum/t-13216405/sprite-to-hex-automater#post-4588932</link>
				<description></description>
				<pubDate>Thu, 09 Apr 2020 13:16:47 +0000</pubDate>
				<wikidot:authorName>Z_dude</wikidot:authorName>				<wikidot:authorUserId>5690022</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>What I meant was, the Goto was originally inside the main loop. To prevent a memory leak, I made it come out in the middle of the while loop, so that it reads the &quot;End&quot; Command. That didn't work, though, so I moved the Goto out of the main loop, and got rid of the While loop.</p> <p>The only reason I can think of that the While loop wasn't working would be that it read the &quot;End&quot; command, and then went straight back to the Repeat command at the beginning of the main loop.</p> <p>This is what the code with the While loop looked like, and it didn't work.</p> <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">+&nbsp;show&nbsp;block</a></div> <div class="collapsible-block-unfolded" style="display:none"> <div class="collapsible-block-unfolded-link"><a class="collapsible-block-link" href="javascript:;">–&nbsp;hide&nbsp;block</a></div> <div class="collapsible-block-content"> <div class="code"> <pre><code>Start of Program... :While 0 :Lbl 0 :End Some time later... :Repeat K=22 //The Main loop All the stuff in the loop... :If K=23 :Goto 0 :End</code></pre></div> </div> </div> </div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-13216405#post-4588099</guid>
				<title>Re: Sprite-to-hex automater</title>
				<link>https://tibasicdev.wikidot.com/forum/t-13216405/sprite-to-hex-automater#post-4588099</link>
				<description></description>
				<pubDate>Thu, 09 Apr 2020 02:55:52 +0000</pubDate>
								<wikidot:authorUserId>3338172</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Memory leaks. Your Goto label instruction is fine, but the label is inside the while loop. This would be a memory leak if the <tt>If K=23:Goto 0</tt> is outside the While loop. If it is, just move the label too in front of the While loop.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-13216405#post-4587381</guid>
				<title>Re: Sprite-to-hex automater</title>
				<link>https://tibasicdev.wikidot.com/forum/t-13216405/sprite-to-hex-automater#post-4587381</link>
				<description></description>
				<pubDate>Wed, 08 Apr 2020 13:44:46 +0000</pubDate>
				<wikidot:authorName>Z_dude</wikidot:authorName>				<wikidot:authorUserId>5690022</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Update: I shortened this from 422 bytes down to 388 bytes, but it could definitely still be shorter.</p> <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">+&nbsp;show&nbsp;block</a></div> <div class="collapsible-block-unfolded" style="display:none"> <div class="collapsible-block-unfolded-link"><a class="collapsible-block-link" href="javascript:;">–&nbsp;hide&nbsp;block</a></div> <div class="collapsible-block-content"> <div class="code"> <pre><code>Recall GDB0 DispGraph Lbl 0 } //3 more bytes, but I need it for the improved Clear-box function ClrDraw } 18→X 29→Y Line(X,-X,X,-Y Line(X,-X,Y,-X Line(Y,-Y,X,-Y Line(Y,-Y,Y,-X 38→I 49→J Line(I,-X,J,-X Line(I,-X,I,-Y Line(J,-Y,I,-Y Line(J,-Y,J,-X DelVar K20→X //Replaced 0→K with DelVar K, this saves 2 bytes (because I also get rid of the newline) -Ans→Y //Replaced -20 with -Ans, 1 byte saved Pt-On(X,Y,3 Repeat max(K={22,23 //5 byte increase, but needed for the Clear-screen function Repeat Ans getKey→K //Moved the →K into the loop, 2 bytes and speed increase End Pt-Off(X,Y,3 max(20,min(27,X=sum(ΔList(K={24,26→X max(-27,min(-20,Y+sum(ΔList(K={34,25→Y Pt-On(X,Y,3 If K=105 Pxl-Change(-Y,20+X //Removed the old ClearScreen function, saved 32 bytes! If K=45 Return End If K=23 //9 more bytes, but needed for the new ClearScreen Function Goto 0 &quot;?→Str1 For(I,0,15 remainder(I,2→J //Although I'm losing a byte here by not doing fPart(I/2, I am improving speed 20+.5(I-J→K //Juggled some numbers, 1 byte 0 For(X,0,3, //Realized that the order of addition doesn't matter, so I got rid of the &quot;,-1&quot;. 3 bytes and speed saved. Ans+2^Xpxl-Test(K,43+4J-X //Removed the * symbol, 1 byte, combined 40+3 and saved 2 bytes End Str1+sub(&quot;0123456789ABCDEF&quot;,Ans+1,1→Str1 //Replaced an &quot;Ans&quot; with the actual code: Saved 2 bytes and some speed End sub(Str1,2,length(Str1)-1→Str1 Ans</code></pre></div> </div> </div> </div> <br /> The old ClearScreen function, when someone pressed Del, would just set up some For( loops to turn off all of the pixels in the Image Box. The new function uses Goto in order to basically restart the program. Interestingly enough, it takes the same amount of time to clear the screen and give back control to the user.<br /> I shied away from putting the Goto inside of the main loop, for fear of memory leaks, since at some point I apparently forgot how to use a While 0 command to enclose the Lbl. Every time I try, it goes to the While 0 with the Lbl inside, and then somehow skips back to the main loop. I tested this by putting Pause commands throughout the system, including in the While loop. When I started the program, it says &quot;Point 2,&quot; just like it should. Later, when I press Del and run the Goto, it says &quot;Point 1&quot;, but then goes back to the main loop without ever saying &quot;Point 2&quot;. So I'm very confused. <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">+&nbsp;show&nbsp;block</a></div> <div class="collapsible-block-unfolded" style="display:none"> <div class="collapsible-block-unfolded-link"><a class="collapsible-block-link" href="javascript:;">–&nbsp;hide&nbsp;block</a></div> <div class="collapsible-block-content"> <div class="code"> <pre><code>Recall GDB0 DispGraph While 0 Lbl 0 Pause &quot;Point 1 End Pause &quot;Point 2 ClrDraw 18→X 29→Y ... and everything else Way later... (But still in the main loop) If K=23 //23 is the Del Key Goto 0</code></pre></div> </div> </div> </div> <br /> Any ideas on more ways I can save bytes or speed?
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-13216405#post-4584228</guid>
				<title>Sprite-to-hex automater</title>
				<link>https://tibasicdev.wikidot.com/forum/t-13216405/sprite-to-hex-automater#post-4584228</link>
				<description></description>
				<pubDate>Mon, 06 Apr 2020 13:16:48 +0000</pubDate>
				<wikidot:authorName>Z_dude</wikidot:authorName>				<wikidot:authorUserId>5690022</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I made a program to design 8x8 monochrome sprites and then output the 16-character hex code for it. I've been doing some optimizations, but I feel like it could lose quite a lot of bytes, and at the end when it calculates the hex code it could be much faster. Any ideas? (Sorry that this is such a mess.) My focus is mainly on size, except for the last part, which I'm trying to optimize for speed.</p> <p>This code essentially draws 2 boxes: One, with opposite vertices of (18,-18) and (29,-29), is for the user. A small cross (I used Pt-On for this) is moved around by the arrow keys, and is prevented from leaving the square. The square is 10x10, but the movement area is 8x8, so that the cross cannot erase any of the square.<br /> The second box has opposite vertices of (38,-18) and (49,-29), and is for the image. When the user presses &quot;Enter,&quot; the pixel in the Image box corresponding to the position of the user in the User box changes color. So you move the user in the user box, then press Enter to change around how the Image box looks. This is solely so that the image isn't screwed up by having the user pointer in it. The Image Box also is 10x10, so that even if the entire 8x8 sprite is filled, there is a layer of white pixels between the box outlines and the sprite.</p> <div class="code"> <pre><code>Recall GDB0 //See note below on GDB0 DispGraph 18→X 29→Y Line(X,-X,X,-Y //This entire mess of code is to draw the 2 box outlines. Line(X,-X,Y,-X Line(Y,-Y,X,-Y Line(Y,-Y,Y,-X 38→I 49→J Line(I,-X,J,-X Line(I,-X,I,-Y Line(J,-Y,I,-Y Line(J,-Y,J,-X 0→K //Keypress Tester 20→X -20→Y Pt-On(X,Y,3 Repeat K=22 //This main loop gets exited out when the user presses &quot;Mode&quot; Repeat Ans getKey //Waits for a keypress End Ans→K Pt-Off(X,Y,3 //Erases the user pointer max(20,min(27,X=sum(ΔList(K={24,26→X //Change X and Y coords max(-27,min(-20,Y+sum(ΔList(K={34,25→Y Pt-On(X,Y,3 //Redraw User Pointer If K=105 //If you press Enter, change the Image Square pixel Pxl-Change(-Y,20+X If K=23:Then //If you press Del, clear the Image box For(I,40,47 For(J,20,27 Pxl-Off(J,I End:End:End If K=45 //If Clear is pressed, end the Program Return End //When Mode is pressed, the main loop terminates, and the to-hex part begins &quot;?→Str1 For(I,0,15 //Repeat for all 16 4-by-1 &quot;segments&quot; of the image, each of which is 1 character. remainder(I,2→J //Calculate if this segment is on the right or left side of the image 20+(I-J)/2→K //Figure out which row of the image this segment is on 0 //Reset Ans For(X,3,0,-1 Ans+2^X*pxl-Test(K,40+4J+3-X //Each time it loops through, it reads a new pixel in the segment, and adds it on to Ans. So 1110 translates to 8=8, 8+4=12, 12+2=14, so the value output at the end of this loop is 14. End sub(&quot;0123456789ABCDEF&quot;,Ans+1,1 //Translates the decimal value into a hex value Str1+Ans→Str1 //Adds the letter (which is the hex value of that segment) onto Str1 End sub(Str1,2,length(Str1)-1→Str1 //Gets rid of the &quot;?&quot; at the beginning of Str1 Ans</code></pre></div> <p>Note on GDB0:<br /> This is here so that all of the graph settings get set so that Xmin=0, Xmax=94, Ymin=-62, Ymax=0 (so that every pixel has its own coordinates, making the Pxl-On( and Pt-On( interchangeable, and to improve usage with the Line(Command</p> <p>Note on what I mean by &quot;Segments:&quot;<br /> An 8x8 sprite outputs a 16-character hex string. Each set of 4 pixels in a row translates to half a byte, or one of those characters. So the string of pixels 1101 would translate to the hex character D. I call each of these segments &quot;segments&quot; (I think the proper term is actually nibbles, but I'm not sure.) There are 2 segments per row of the sprite, and 8 rows of the image, which makes the 16 segments.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>