<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GuShH&#039;s DevBlog &#187; purebasic</title>
	<atom:link href="http://gushh.net/blog/?tag=purebasic&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics engineering and game development.</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>(PB) Loading Assets, the simple way.</title>
		<link>http://gushh.net/blog/loading-assets-simple-way/</link>
		<comments>http://gushh.net/blog/loading-assets-simple-way/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 00:29:27 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[asset]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[loading files]]></category>
		<category><![CDATA[purebasic]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=1284</guid>
		<description><![CDATA[Intro Assets are an essential part of most games, how you manage them determines whether you spend more time working on them than dealing with them. For small to medium games, loading an entire directory and having it referenced to a Map is the ideal solution. It&#8217;s both flexible and simple. The following code allows [...]]]></description>
			<content:encoded><![CDATA[<h2>Intro</h2>
<p>Assets are an essential part of most games, how you manage them determines whether you spend more time working on them than dealing with them.</p>
<p>For small to medium games, loading an entire directory and having it referenced to a Map is the ideal solution. It&#8217;s both flexible and simple.</p>
<h4>The following code allows you to do just this:</h4>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Prototype</span>.i LOAD_DIRECTORY_CALLBACK<span style="color: #000066;">&#40;</span> Map Assets.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory.s, extension.s, name.s, userDefined.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i LoadDirectory<span style="color: #000066;">&#40;</span> Map assets.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory.s, extension.s, <span style="color: #000066;">*</span>callback.LOAD_DIRECTORY_CALLBACK, userDefined.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i dir <span style="color: #000066;">=</span> <span style="color: #0000ff;">ExamineDirectory</span><span style="color: #000066;">&#40;</span> #PB_Any, directory, <span style="color: #009900;">&quot;*&quot;</span> <span style="color: #000066;">+</span> extension <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsDirectory</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">Define</span>.i count <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.s name <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;&quot;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">While</span> <span style="color: #0000ff;">NextDirectoryEntry</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">DirectoryEntryType</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> #PB_DirectoryEntry_File
				name <span style="color: #000066;">=</span> <span style="color: #0000ff;">DirectoryEntryName</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span><span style="color: #ff0000; font-style: italic;">;</span>
				assets<span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">ReplaceString</span><span style="color: #000066;">&#40;</span> name, extension, <span style="color: #009900;">&quot;&quot;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>callback<span style="color: #000066;">&#40;</span> assets<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory, extension, name, userDefined <span style="color: #000066;">&#41;</span><span style="color: #ff0000; font-style: italic;">;LoadSound( #PB_Any, directory + &quot;\&quot; + name )</span>
				count <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Wend</span>
&nbsp;
		<span style="color: #0000ff;">FinishDirectory</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> count
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>To use this code you must define a procedure of your own, this procedure is going to be called on each file to be loaded; you&#8217;ll have to load and process the file in this function.</p>
<h4>Example use:</h4>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Global</span> NewMap sprite.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Procedure</span>.i callback_loadsprites<span style="color: #000066;">&#40;</span> Map Assets.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory.s, extension.s, name.s, userDefined.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">LoadSprite</span><span style="color: #000066;">&#40;</span> #PB_Any, directory <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;\&quot;</span> <span style="color: #000066;">+</span> name, userDefined <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
LoadDirectory<span style="color: #000066;">&#40;</span> sprite<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, <span style="color: #009900;">&quot;sprites&quot;</span>, <span style="color: #009900;">&quot;.png&quot;</span>, @callback_loadsprites<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span></pre></div></div>

<p>The example will attempt to scan through the directory &#8220;sprites&#8221;, it will execute your callback on each png file it finds inside the aforementioned directory, furthermore it&#8217;ll reference the filename (without extension) to the sprite() Map, so when you need a handle for the sprite called &#8220;fire.png&#8221; you&#8217;d just use sprite(&#8220;fire&#8221;) to obtain it.</p>
<p>Since the files are referenced to a Map by their actual name, you could easily implement a scripting system or any other dynamic management solution for your assets without much hassle.</p>
<blockquote><p>An interesting part of the code is the return value, it&#8217;s actually the number of assets found (not the ones loaded, since your callback could choose not to load a certain file, for instance).</p></blockquote>
<p>There are several limitations to this simple implementation, which is why I mentioned &#8220;small games&#8221; &#8211; There is no directory recursion, no advanced filtering options, no way to parallel the process on a separate thread and there&#8217;s no error handling at the moment.</p>
<p>However, it&#8217;s still very useful and I highly recommend you try it out, while it&#8217;s not a novel aproach, it&#8217;s always been the method I used to load my assets and it just works.</p>
<p>Have fun!</p>
<g:plusone href='http://gushh.net/blog/loading-assets-simple-way/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/loading-assets-simple-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(PB) String Between Characters</title>
		<link>http://gushh.net/blog/pb-string-characters/</link>
		<comments>http://gushh.net/blog/pb-string-characters/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 12:30:07 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[find string]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[string between chars]]></category>
		<category><![CDATA[str_between_char]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=849</guid>
		<description><![CDATA[This is a small purebasic function used to retrieve a string between two known characters, it also allows you to provide a starting position. Procedure.s str_between_char&#40; *Source.CHARACTER, First.C, Last.C, StartAt.i = 0 &#41; Define.i dwLength &#160; *Source + &#40;StartAt * SizeOf&#40;CHARACTER&#41;&#41; Repeat If *Source\c = First ; If this character matches the First character *Source [...]]]></description>
			<content:encoded><![CDATA[<p>This is a small purebasic function used to retrieve a string between two known characters, it also allows you to provide a starting position.</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.s str_between_char<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>Source.CHARACTER, First.C, Last.C, StartAt.i <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.i dwLength
&nbsp;
	<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span>StartAt <span style="color: #000066;">*</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Repeat</span>
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>Source<span style="color: #000066;">\</span>c <span style="color: #000066;">=</span> First <span style="color: #ff0000; font-style: italic;">; If this character matches the First character</span>
			<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span>
			dwLength <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>Source
			<span style="color: #000066; font-weight: bold;">Repeat</span> <span style="color: #ff0000; font-style: italic;">; Repeat until we find an occurrance with the Last character</span>
				<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #000066;">*</span>Source<span style="color: #000066;">\</span>c <span style="color: #000066;">=</span> Last
			dwLength <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>Source <span style="color: #000066;">-</span> dwLength<span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">PeekS</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>Source <span style="color: #000066;">-</span> dwLength, dwLength <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; Peek the output string</span>
			<span style="color: #000066; font-weight: bold;">Break</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #000066;">*</span>Source<span style="color: #000066;">\</span>c <span style="color: #000066;">=</span> #Null
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Example use:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Define</span>.s <span style="color: #0000ff;">str</span> 		<span style="color: #000066;">=</span> <span style="color: #009900;">&quot;dd(hallo)xyz(a)&quot;</span>
<span style="color: #000066; font-weight: bold;">Define</span>.s result 	<span style="color: #000066;">=</span> str_between_char<span style="color: #000066;">&#40;</span>@<span style="color: #0000ff;">str</span>, '<span style="color: #000066;">&#40;</span>', '<span style="color: #000066;">&#41;</span>', <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Debug</span> result</pre></div></div>

<p>If you&#8217;re working on a parser or similar project this will sure come in handy.<br />
<strong>Enjoy!</strong></p>
<g:plusone href='http://gushh.net/blog/pb-string-characters/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/pb-string-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PB Parallel Port Library</title>
		<link>http://gushh.net/blog/parallel-port-library/</link>
		<comments>http://gushh.net/blog/parallel-port-library/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 04:17:42 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[LPT]]></category>
		<category><![CDATA[Parallel Port]]></category>
		<category><![CDATA[Paraport]]></category>
		<category><![CDATA[PB Parallel Library]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[Stepper Motor]]></category>
		<category><![CDATA[Unipolar Stepper]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=743</guid>
		<description><![CDATA[What is it: This is a minimalist  library based on the inpout32 DLL Basically I wrapped the original library and added a whole bunch of useful constants to easily access the Control and Status registers while keeping things clean and simple. This library is currently being used on a side project I&#8217;ve been working on with a friend, [...]]]></description>
			<content:encoded><![CDATA[<h2>What is it:</h2>
<p>This is a minimalist  library based on the <a title="http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html" href="http://" target="_blank">inpout32 DLL</a></p>
<p>Basically I wrapped the original library and added a whole bunch of useful constants to easily access the Control and Status registers while keeping things clean and simple.</p>
<p>This library is currently being used on a side project I&#8217;ve been working on with a friend, since he doesn&#8217;t have any μController experience we decided to use LPT for the time being.</p>
<h3></h3>
<h2>The code:</h2>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;">&nbsp;
<span style="color: #ff0000; font-style: italic;">; 	Minimalist Library for Parallel port access based on inpout32.dll </span>
<span style="color: #ff0000; font-style: italic;">;		by Gustavo J. Fiorenza AKA GuShH (info@gushh.net - info@gushh.com.ar)</span>
<span style="color: #ff0000; font-style: italic;">;		Version 1.0 - 11/01/2011</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EnableExplicit</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">; Default LPT Addresses.</span>
#PARALLEL_PORT_LPT1						<span style="color: #000066;">=</span> $3BC
#PARALLEL_PORT_LPT2						<span style="color: #000066;">=</span> $378
#PARALLEL_PORT_LPT3						<span style="color: #000066;">=</span> $278
&nbsp;
<span style="color: #ff0000; font-style: italic;">; Register offsets.</span>
#PARALLEL_PORT_STATUS						<span style="color: #000066;">=</span> $01
#PARALLEL_PORT_CONTROL						<span style="color: #000066;">=</span> $02
&nbsp;
<span style="color: #ff0000; font-style: italic;">; Shared with Data Register.</span>
#PARALLEL_PORT_OFF						<span style="color: #000066;">=</span> $00
#PARALLEL_PORT_BIT0						<span style="color: #000066;">=</span> $01
#PARALLEL_PORT_BIT1						<span style="color: #000066;">=</span> $02
#PARALLEL_PORT_BIT2						<span style="color: #000066;">=</span> $04
#PARALLEL_PORT_BIT3						<span style="color: #000066;">=</span> $08
#PARALLEL_PORT_BIT4						<span style="color: #000066;">=</span> $10
#PARALLEL_PORT_BIT5						<span style="color: #000066;">=</span> $20
#PARALLEL_PORT_BIT6						<span style="color: #000066;">=</span> $40
#PARALLEL_PORT_BIT7						<span style="color: #000066;">=</span> $80
&nbsp;
<span style="color: #000066; font-weight: bold;">XIncludeFile</span> <span style="color: #009900;">&quot;ParallelPort_Constants.pbi&quot;</span> 	<span style="color: #ff0000; font-style: italic;">; All of the helper, non-essential constants are defined here.</span>
&nbsp;
&nbsp;
<span style="color: #000066; font-weight: bold;">Structure</span> PARALLEL_PORT
	Handle.i
	Port.i
	LastData.i
<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
&nbsp;
<span style="color: #ff0000; font-style: italic;">;- Instance construction and destruction</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_Create<span style="color: #000066;">&#40;</span> Port.i <span style="color: #000066;">=</span> #PARALLEL_PORT_LPT2 <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.PARALLEL_PORT <span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> <span style="color: #0000ff;">AllocateMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>PARALLEL_PORT<span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Port 	<span style="color: #000066;">=</span> port
		<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Handle 	<span style="color: #000066;">=</span> <span style="color: #0000ff;">OpenLibrary</span><span style="color: #000066;">&#40;</span> #PB_Any, <span style="color: #009900;">&quot;inpout32.dll&quot;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsLibrary</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Handle <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">Else</span>
			<span style="color: #000066; font-weight: bold;">Debug</span> <span style="color: #009900;">&quot;Couldn't load inpout32.dll&quot;</span>
			<span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #Null
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_Destroy<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsLibrary</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Handle <span style="color: #000066;">&#41;</span>
			<span style="color: #0000ff;">CloseLibrary</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Handle <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span>
		<span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> #Null
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">;- Communication Functions</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_Out<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT, Bits.w <span style="color: #000066;">=</span> $00 <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>LastData <span style="color: #000066;">=</span> Bits <span style="color: #000066;">&amp;</span> $FF
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">CallFunction</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>handle, <span style="color: #009900;">&quot;Out32&quot;</span>, <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Port, Bits <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_In<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT, Type.i <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">CallFunction</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>handle, <span style="color: #009900;">&quot;Inp32&quot;</span>, <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Port <span style="color: #000066;">+</span> Type <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">;- Getter Functions</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_GetHandle<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Handle
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_GetPort<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>Port
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_GetLastData<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>LastData
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">;- Helper Functions</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i ParallelPort_Clear<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.PARALLEL_PORT <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		ParallelPort_Out<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; The default data parameter is $00</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>And the constants include:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;">&nbsp;
<span style="color: #ff0000; font-style: italic;">; Read Only Status Register.</span>
#PARALLEL_PORT_STATUS_IRQ		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT2
&nbsp;
#PARALLEL_PORT_STATUS_ERROR		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT3
#PARALLEL_PORT_STATUS_SELECT		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT4
#PARALLEL_PORT_STATUS_PAPEROUT		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT5
#PARALLEL_PORT_STATUS_ACK		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT6
#PARALLEL_PORT_STATUS_BUSY		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT7
&nbsp;
<span style="color: #ff0000; font-style: italic;">; Read / Write Control Register.</span>
#PARALLEL_PORT_CONTROL_STROBE		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT0
#PARALLEL_PORT_CONTROL_LINEFEED		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT1
#PARALLEL_PORT_CONTROL_RESET		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT2 <span style="color: #ff0000; font-style: italic;">; AKA Initialize Printer OR Init.</span>
#PARALLEL_PORT_CONTROL_SELECT		<span style="color: #000066;">=</span> #PARALLEL_PORT_BIT3
&nbsp;
<span style="color: #ff0000; font-style: italic;">; These constants are icluded for completeness. All pin numbers are relative to D-Type 25, Centronics pins are between parentheses.</span>
&nbsp;
#PARALLEL_PORT_D0	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT0			<span style="color: #ff0000; font-style: italic;">; PIN2</span>
#PARALLEL_PORT_D1	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT1			<span style="color: #ff0000; font-style: italic;">; PIN3</span>
#PARALLEL_PORT_D2	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT2			<span style="color: #ff0000; font-style: italic;">; PIN4</span>
#PARALLEL_PORT_D3	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT3			<span style="color: #ff0000; font-style: italic;">; PIN5</span>
#PARALLEL_PORT_D4	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT4			<span style="color: #ff0000; font-style: italic;">; PIN6</span>
#PARALLEL_PORT_D5	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT5			<span style="color: #ff0000; font-style: italic;">; PIN7</span>
#PARALLEL_PORT_D6	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT6			<span style="color: #ff0000; font-style: italic;">; PIN8</span>
#PARALLEL_PORT_D7	<span style="color: #000066;">=</span>	#PARALLEL_PORT_BIT7			<span style="color: #ff0000; font-style: italic;">; PIN9</span>
&nbsp;
#PARALLEL_PORT_C0	<span style="color: #000066;">=</span>	#PARALLEL_PORT_CONTROL_STROBE		<span style="color: #ff0000; font-style: italic;">; PIN 1</span>
#PARALLEL_PORT_C1	<span style="color: #000066;">=</span>	#PARALLEL_PORT_CONTROL_LINEFEED		<span style="color: #ff0000; font-style: italic;">; PIN 14</span>
#PARALLEL_PORT_C2	<span style="color: #000066;">=</span>	#PARALLEL_PORT_CONTROL_RESET		<span style="color: #ff0000; font-style: italic;">; PIN 16	(31)</span>
#PARALLEL_PORT_C3	<span style="color: #000066;">=</span>	#PARALLEL_PORT_CONTROL_SELECT		<span style="color: #ff0000; font-style: italic;">; PIN 17	(36)</span>
&nbsp;
#PARALLEL_PORT_S3	<span style="color: #000066;">=</span>	#PARALLEL_PORT_STATUS_ERROR		<span style="color: #ff0000; font-style: italic;">; PIN 15	(32)</span>
#PARALLEL_PORT_S4	<span style="color: #000066;">=</span>	#PARALLEL_PORT_STATUS_SELECT		<span style="color: #ff0000; font-style: italic;">; PIN 13</span>
#PARALLEL_PORT_S5	<span style="color: #000066;">=</span>	#PARALLEL_PORT_STATUS_PAPEROUT		<span style="color: #ff0000; font-style: italic;">; PIN 12</span>
#PARALLEL_PORT_S6	<span style="color: #000066;">=</span>	#PARALLEL_PORT_STATUS_ACK		<span style="color: #ff0000; font-style: italic;">; PIN 10</span>
#PARALLEL_PORT_S7	<span style="color: #000066;">=</span>	#PARALLEL_PORT_STATUS_BUSY		<span style="color: #ff0000; font-style: italic;">; PIN 11</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">; PINS 18-25 (19-30) Are all tied to GND.</span></pre></div></div>

<h3>The hardware:</h3>
<p>You don&#8217;t need any special hardware other than a Centronics or similar cable and a PC with a Parallel port (I&#8217;m sure some of you keep older PCs around for a good reason!) &#8212; Aside from this if you&#8217;re planning on running the examples you might want to get some LEDs and Switches.</p>
<h3>Something to download:</h3>
<p>The entire sources and support files including the examples can be found <a href='http://gushh.net/blog/wp-content/uploads/2011/01/ParallelPort.zip'>Here</a>. Remember to exit the demo programs with the ESC key so the program gets a chance to reset the output bits.</p>
<h3>Useful companion:</h3>
<p>During development you may want to keep an eye on the status of each pin, however not everyone has a breakout board for this particular interface so you may want to use a software version of this concept instead, one of my favourite ones is <a href="http://neil.fraser.name/software/lpt/" target="_blank">LPT.exe</a> &#8212; It works fairly well and there are several ports to different languages in case you&#8217;re interested in modifying it to suit your own needs.</p>
<h3>Closing up:</h3>
<p>That&#8217;s all for now, hopefully I&#8217;ll be able to finish the project and post some of the code here. Hint: it involves controlling unipolar steppers, computer vision and webcams!</p>
<p>Can you guess what it is?</p>
<p>Cheers.</p>
<g:plusone href='http://gushh.net/blog/parallel-port-library/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/parallel-port-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ICMP Ping Routine (Windows only)</title>
		<link>http://gushh.net/blog/icmp-ping-routine/</link>
		<comments>http://gushh.net/blog/icmp-ping-routine/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 22:14:50 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[icmp]]></category>
		<category><![CDATA[is online]]></category>
		<category><![CDATA[netping]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[roundtrip]]></category>
		<category><![CDATA[winapi]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=303</guid>
		<description><![CDATA[Heres my ping routine, It&#8217;s the weapon of choice for checking online status, update servers, or just plain pinging an IP for whatever reason happens to float your boat! EnableExplicit Procedure.i NetPing&#40; IP_Address.s = &#34;209.85.225.105&#34;, Timeout.i = 5000 &#41; ; Timeout in Milliseconds, Defaults to 5 seconds. &#160; ;Returns =&#62; 0 Upon pinging. Otherwise returns [...]]]></description>
			<content:encoded><![CDATA[<p>Heres my ping routine, It&#8217;s the weapon of choice for checking online status, update servers, or just plain pinging an IP for whatever reason happens to float your boat!</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">EnableExplicit</span>
<span style="color: #000066; font-weight: bold;">Procedure</span>.i NetPing<span style="color: #000066;">&#40;</span> IP_Address.s <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;209.85.225.105&quot;</span>, Timeout.i <span style="color: #000066;">=</span> <span style="color: #CC0000;">5000</span> <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; Timeout in Milliseconds, Defaults to 5 seconds.</span>
&nbsp;
  <span style="color: #ff0000; font-style: italic;">;Returns =&gt; 0 Upon pinging. Otherwise returns &lt; 0 -- The actual return value is the roundtrip time in milliseconds.</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">Define</span>.i hIcmpFile, dwRetVal			<span style="color: #000066;">=</span> <span style="color: #000066;">-</span><span style="color: #CC0000;">1</span>
  <span style="color: #000066; font-weight: bold;">Define</span>.s DataBuffer 				<span style="color: #000066;">=</span> <span style="color: #009900;">&quot;PING&quot;</span>
  <span style="color: #000066; font-weight: bold;">Define</span>.i ReplyBufferSize 			<span style="color: #000066;">=</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>ICMP_ECHO_REPLY<span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">Len</span><span style="color: #000066;">&#40;</span>DataBuffer<span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>character<span style="color: #000066;">&#41;</span>
  <span style="color: #000066; font-weight: bold;">Define</span>.ICMP_ECHO_REPLY <span style="color: #000066;">*</span>ReplyBuffer 		<span style="color: #000066;">=</span> <span style="color: #0000ff;">AllocateMemory</span><span style="color: #000066;">&#40;</span>ReplyBufferSize<span style="color: #000066;">&#41;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>ReplyBuffer <span style="color: #000066;">&#41;</span>
&nbsp;
	  hIcmpFile <span style="color: #000066;">=</span> IcmpCreateFile_<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">If</span> hIcmpFile
&nbsp;
		 <span style="color: #000066; font-weight: bold;">If</span> IcmpSendEcho_<span style="color: #000066;">&#40;</span> hIcmpFile, inet_addr_<span style="color: #000066;">&#40;</span>IP_Address<span style="color: #000066;">&#41;</span>, @DataBuffer, <span style="color: #0000ff;">Len</span><span style="color: #000066;">&#40;</span>DataBuffer<span style="color: #000066;">&#41;</span>, #Null, <span style="color: #000066;">*</span>ReplyBuffer, ReplyBufferSize <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>ICMP_ECHO_REPLY<span style="color: #000066;">&#41;</span>, Timeout <span style="color: #000066;">&#41;</span>
			dwRetVal <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>ReplyBuffer<span style="color: #000066;">\</span>RoundTripTime
		 <span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		 IcmpCloseHandle_<span style="color: #000066;">&#40;</span> hIcmpFile <span style="color: #000066;">&#41;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">Else</span>
	  	<span style="color: #000066; font-weight: bold;">Debug</span> <span style="color: #009900;">&quot;NetPing -- IcmpCreateFile returned false.&quot;</span>
	  <span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	  <span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>ReplyBuffer <span style="color: #000066;">&#41;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">Else</span>
  	<span style="color: #000066; font-weight: bold;">Debug</span> <span style="color: #009900;">&quot;NetPing -- Couldn't allocate memory.&quot;</span>
  <span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">ProcedureReturn</span> dwRetVal
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Enjoy!</pre>
<g:plusone href='http://gushh.net/blog/icmp-ping-routine/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/icmp-ping-routine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FileToMemory &#8211; MemoryToFile</title>
		<link>http://gushh.net/blog/filetomemory-memorytofile/</link>
		<comments>http://gushh.net/blog/filetomemory-memorytofile/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 16:49:49 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[file to memory]]></category>
		<category><![CDATA[memory to file]]></category>
		<category><![CDATA[purebasic]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=259</guid>
		<description><![CDATA[I haven&#8217;t had much time to write, so I figured I could at least share some old -yet useful- PB code in the meantime, as promised. Quite often you&#8217;ll need to load a file right into memory or dump memory into a file, these are relatively trivial tasks but I&#8217;m sure someone will eventually benefit [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t had much time to write, so I figured I could at least share some old -yet useful- PB code in the meantime, as promised.</p>
<p>Quite often you&#8217;ll need to load a file right into memory or dump memory into a file, these are relatively trivial tasks but I&#8217;m sure someone will eventually benefit from the functions, so here we go:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">; Be careful trying to read big files into memory, always check the available RAM is enough before doing anything crazy.</span>
<span style="color: #000066; font-weight: bold;">Procedure</span>.i FileToMemory<span style="color: #000066;">&#40;</span> File.s <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; Returns memory handle if the file was properly loaded, otherwise 0.</span>
 <span style="color: #ff0000; font-style: italic;">; Sanitize filename using your own routine.</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.i fileHandle	<span style="color: #000066;">=</span>	<span style="color: #0000ff;">ReadFile</span><span style="color: #000066;">&#40;</span> #PB_Any, File <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsFile</span><span style="color: #000066;">&#40;</span>fileHandle<span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i <span style="color: #0000ff;">fileSize</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">Lof</span><span style="color: #000066;">&#40;</span>fileHandle<span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">fileSize</span>
			<span style="color: #000066; font-weight: bold;">Define</span>.i fileBuffer <span style="color: #000066;">=</span> <span style="color: #0000ff;">AllocateMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">fileSize</span> <span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> fileBuffer
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">ReadData</span><span style="color: #000066;">&#40;</span> fileHandle,  fileBuffer, <span style="color: #0000ff;">fileSize</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">fileSize</span>
&nbsp;
					<span style="color: #0000ff;">CloseFile</span><span style="color: #000066;">&#40;</span> fileHandle <span style="color: #000066;">&#41;</span>
					<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> fileBuffer
&nbsp;
				<span style="color: #000066; font-weight: bold;">Else</span>
					<span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span>fileBuffer<span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #0000ff;">CloseFile</span><span style="color: #000066;">&#40;</span>fileHandle<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #Null
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.i MemoryToFile<span style="color: #000066;">&#40;</span> Memory.i, File.s <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; Returns the amount of written data in bytes, otherwise 0.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> Memory
		<span style="color: #000066; font-weight: bold;">If</span> File <span style="color: #ff0000; font-style: italic;">; Sanitize filename using your own routine.</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">Define</span>.i <span style="color: #0000ff;">MemorySize</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">MemorySize</span><span style="color: #000066;">&#40;</span>Memory<span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">MemorySize</span> <span style="color: #000066;">&gt;</span> <span style="color: #CC0000;">0</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">Define</span>.i fileHandle <span style="color: #000066;">=</span> <span style="color: #0000ff;">CreateFile</span><span style="color: #000066;">&#40;</span> #PB_Any, File <span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsFile</span><span style="color: #000066;">&#40;</span> fileHandle <span style="color: #000066;">&#41;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">Define</span>.i DataWritten <span style="color: #000066;">=</span> <span style="color: #0000ff;">WriteData</span><span style="color: #000066;">&#40;</span> fileHandle, Memory, <span style="color: #0000ff;">MemorySize</span> <span style="color: #000066;">&#41;</span>
					<span style="color: #0000ff;">CloseFile</span><span style="color: #000066;">&#40;</span> fileHandle <span style="color: #000066;">&#41;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> DataWritten
&nbsp;
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #Null
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Filename sanitation was not included since this is often part of a separate lib.</p>
<p>Quite frankly functions like these should be part of the official libraries, seeing as how often they&#8217;re used&#8230; I really do think they should focus on adding new functionality to the language &#8212; I hear a rant coming!</p>
<p>Well, not today. Let&#8217;s keep it simple.</p>
<p>Cheers!</p>
<g:plusone href='http://gushh.net/blog/filetomemory-memorytofile/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/filetomemory-memorytofile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: gushh.net @ 2012-02-09 07:42:20 by W3 Total Cache -->
