tag:blogger.com,1999:blog-29188139886613032242024-02-18T23:51:26.677-08:00Commodore and Retro ComputingMarek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-2918813988661303224.post-19665203765830262312019-06-20T18:45:00.000-07:002019-06-20T18:48:32.349-07:00CP/M - screen saver / screen lockOur precious vintage CP/M machines aren't getting any younger. The same goes for CRT displays. If you are a CP/M programmer, you may be in need of a utility program which will either blank the screen or display random content on the screen to prevent the burnout while you are away from the console taking a break from your project. You may also want a password protected screen lock function with it to protect your precious code from prying eyes.<br />
<br />
<a href="https://github.com/makarcz/scrsavcpm" target="_blank"><span style="color: yellow;">Here</span></a> I present something I created out of my own need.<br />
In the process I learned a bit of CP/M system programming in C.<br />
<br />
Some interesting problems that I needed to solve due to deficiencies in the standard library of Aztec C 1.05 compiler:<br />
<br />
- generating random numbers<br />
- non-blocking keyboard reading<br />
- reading time from the system<br />
- direct cursor addressing<br />
<br />
<table class="highlight tab-size js-file-line-container" data-tab-size="8" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; tab-size: 8;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td class="blob-code blob-code-inner js-file-line" id="LC28" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">long</span> next = <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">1</span>;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="29" id="L29" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC29" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="30" id="L30" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC30" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;">/*</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="31" id="L31" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC31" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Aztec C 1.05 doesn't have random generator in the library of functions.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="32" id="L32" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC32" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Here is something I found on the internet.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="33" id="L33" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC33" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Will return value 0 - 32767.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="34" id="L34" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC34" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> <span class="pl-c" style="box-sizing: border-box;">*/</span></span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="35" id="L35" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC35" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">unsigned</span> <span class="pl-en" style="box-sizing: border-box; color: #6f42c1;">rand</span>()</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="36" id="L36" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC36" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">{</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="37" id="L37" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC37" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">next = next * <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">1103515245</span> + <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">12345</span>;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="38" id="L38" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC38" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">return</span> (<span class="pl-k" style="box-sizing: border-box; color: #d73a49;">unsigned</span>)(next / <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">65536</span>) % <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">32768</span>;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="39" id="L39" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC39" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">}
</td></tr>
</tbody></table>
<table class="highlight tab-size js-file-line-container" data-tab-size="8" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; tab-size: 8;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td class="blob-code blob-code-inner js-file-line" id="LC62" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> /*</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="63" id="L63" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC63" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Clear the screen (ADM31).</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="64" id="L64" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC64" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> <span class="pl-c" style="box-sizing: border-box;">*/</span></span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="65" id="L65" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC65" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-en" style="box-sizing: border-box; color: #6f42c1;">BlankScr</span>()</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="66" id="L66" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC66" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">{</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="67" id="L67" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC67" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">putchar</span>(ESC);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="68" id="L68" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC68" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">putchar</span>(<span class="pl-s" style="box-sizing: border-box; color: #032f62;"><span class="pl-pds" style="box-sizing: border-box;">'</span>*<span class="pl-pds" style="box-sizing: border-box;">'</span></span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="69" id="L69" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC69" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">}</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="70" id="L70" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC70" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="71" id="L71" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC71" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;">/*</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="72" id="L72" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC72" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Cursor positioning (absolute cursor addressing) for ADM31.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="73" id="L73" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC73" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> <span class="pl-c" style="box-sizing: border-box;">*/</span></span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="74" id="L74" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC74" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-en" style="box-sizing: border-box; color: #6f42c1;">GotoXY</span>(col, row)</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="75" id="L75" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC75" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">char col, row;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="76" id="L76" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC76" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">{</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="77" id="L77" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC77" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">putchar</span>(ESC);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="78" id="L78" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC78" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">putchar</span>(<span class="pl-s" style="box-sizing: border-box; color: #032f62;"><span class="pl-pds" style="box-sizing: border-box;">'</span>=<span class="pl-pds" style="box-sizing: border-box;">'</span></span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="79" id="L79" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC79" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">putchar</span>(<span class="pl-s" style="box-sizing: border-box; color: #032f62;"><span class="pl-pds" style="box-sizing: border-box;">'</span> <span class="pl-pds" style="box-sizing: border-box;">'</span></span>+row);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="80" id="L80" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC80" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">putchar</span>(<span class="pl-s" style="box-sizing: border-box; color: #032f62;"><span class="pl-pds" style="box-sizing: border-box;">'</span> <span class="pl-pds" style="box-sizing: border-box;">'</span></span>+col); </td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="81" id="L81" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC81" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">}</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="82" id="L82" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC82" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="83" id="L83" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC83" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;">/*</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="84" id="L84" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC84" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Non-blocking character input.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="85" id="L85" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC85" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Return 0 if no character is waiting.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="86" id="L86" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC86" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * return a character without echoing if one is waiting.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="87" id="L87" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC87" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> <span class="pl-c" style="box-sizing: border-box;">*/</span></span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="88" id="L88" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC88" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">int</span> <span class="pl-en" style="box-sizing: border-box; color: #6f42c1;">KeyPress</span>()</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="89" id="L89" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC89" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">{</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="90" id="L90" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC90" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">return</span> (<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">bdos</span> (<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0x06</span>, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0xFF</span>)); </td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="91" id="L91" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC91" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">}
</td></tr>
</tbody></table>
<table class="highlight tab-size js-file-line-container" data-tab-size="8" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; tab-size: 8;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td class="blob-code blob-code-inner js-file-line" id="LC141" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;">/*</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="142" id="L142" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC142" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Get date / time (for rand seed initialization).</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="143" id="L143" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC143" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Returns # of seconds (packed BCD), tptr - address of time stamp.</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="144" id="L144" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC144" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * The format of time stamp:</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="145" id="L145" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC145" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * DW day ;Day 1 is Jan 1-st 1978</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="146" id="L146" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC146" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * DB hr ;Packed BCD</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="147" id="L147" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC147" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * DB min ;Packed BCD</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="148" id="L148" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC148" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> <span class="pl-c" style="box-sizing: border-box;">*/</span></span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="149" id="L149" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC149" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">int</span> <span class="pl-en" style="box-sizing: border-box; color: #6f42c1;">GetDtTm</span>(tptr)</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="150" id="L150" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC150" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">int *tptr;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="151" id="L151" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC151" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">{</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="152" id="L152" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC152" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">return</span> (<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">bdos</span> (<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0x69</span>, tptr)); </td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="153" id="L153" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC153" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">}</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="154" id="L154" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC154" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="155" id="L155" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC155" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;">/*</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="156" id="L156" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC156" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> * Get time string in format hh:mm:ss</span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="157" id="L157" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC157" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c" style="box-sizing: border-box; color: #6a737d;"> <span class="pl-c" style="box-sizing: border-box;">*/</span></span></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="158" id="L158" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC158" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">char</span> *<span class="pl-en" style="box-sizing: border-box; color: #6f42c1;">GetTimeStr</span>()</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="159" id="L159" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC159" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">{</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="160" id="L160" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC160" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">long</span> dtm;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="161" id="L161" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC161" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">char</span> buf[<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">10</span>], hr[<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">3</span>], min[<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">3</span>];</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="162" id="L162" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC162" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">int</span> sec;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="163" id="L163" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC163" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">static</span> <span class="pl-k" style="box-sizing: border-box; color: #d73a49;">char</span> ret[<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">10</span>];</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="164" id="L164" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC164" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="165" id="L165" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC165" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">clear</span>(buf, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">10</span>, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0</span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="166" id="L166" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC166" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">clear</span>(ret, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">10</span>, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0</span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="167" id="L167" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC167" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">hr[<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">2</span>] = <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0</span>;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="168" id="L168" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC168" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">min[<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">2</span>] = <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">0</span>;</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="169" id="L169" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC169" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">sec = <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">GetDtTm</span>(&dtm);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="170" id="L170" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC170" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">sprintf</span>(buf, <span class="pl-s" style="box-sizing: border-box; color: #032f62;"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">%08x</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span>, dtm >> <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">16</span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="171" id="L171" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC171" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">strncpy</span>(hr, buf+<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">6</span>, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">2</span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="172" id="L172" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC172" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">strncpy</span>(min, buf+<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">4</span>, <span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">2</span>);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="173" id="L173" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC173" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">sprintf</span>(ret, <span class="pl-s" style="box-sizing: border-box; color: #032f62;"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">%s</span>:<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">%s</span>:<span class="pl-c1" style="box-sizing: border-box; color: #005cc5;">%02x</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span>, hr, min, sec); </td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="174" id="L174" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC174" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"></td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="175" id="L175" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC175" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;"><span class="pl-k" style="box-sizing: border-box; color: #d73a49;">return</span> (ret);</td></tr>
<tr style="box-sizing: border-box;"><td class="blob-num js-line-number" data-line-number="176" id="L176" style="box-sizing: border-box; color: rgba(27, 31, 35, 0.3); cursor: pointer; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50px;"></td><td class="blob-code blob-code-inner js-file-line" id="LC176" style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;">}
</td></tr>
</tbody></table>
<br />
Program is short and well commented.<br />
<br />
Enjoy!<br />
<br />
MK'6/20/2019Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com1tag:blogger.com,1999:blog-2918813988661303224.post-91806463504082557242016-09-15T20:13:00.002-07:002016-09-15T20:28:47.047-07:00CP/M : Tetris Clone in Turbo Pascal 3.0.<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">CP/M
being an 8-bit era MS-DOS equivalent, a platform for
professional/business software had the advantage over most home
computer platforms of that time, which were usually equipped and
stuck with BASIC as their main programming language and operating
system. CP/M was a “grown-up” OS, which defined distinct
abstraction layers that separated user from hardware and was not
oriented toward any particular programming language or hardware
platform/architecture.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">The
abstraction layers consisted of Basic I/O System (BIOS), Basic Disk
O.S. (BDOS) and Console Command Processor (CCP). The complexity of
the system was mostly implemented in BDOS and in CCP layers,
therefore it was enough to rewrite some BIOS routines to adapt the
code to any particular hardware platform.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">There
were versions of CP/M later developed for different more advanced
16-bit processors (CP/M-86 for Intel 8086, CP/M-68k for Motorola
68000 or CP/M-8000 for Zilog Z8000), however CP/M originally targeted
and was written for an Intel 8080/85/Z-80 microprocessor family
(CP/M-80), therefore its native language was Intel 8080 assembly
language. Programs therefore could be ported fairly well between
different computer platforms in their original binary form under
assumption that they were compiled to base Intel 8080 machine
language and were not using any platform specific hardware features
and were confined to 64 kB of RAM and ASCII mode. Assembly language
is technically speaking not a programming language but merely a
notation system that makes writing programs in machine code a bit
easier. Also, the original version of CP/M wasn't even written in
assembly, but rather in a higher level language called PL/M invented
by Gary Kildall </span><span style="color: #252525;"><span style="font-family: sans-serif;">(May
19, 1942 – July 11, 1994)</span></span> <span style="font-family: "verdana" , sans-serif;">–
who was also the original author of CP/M. So lets stick with that. </span>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">There
were many professional development packages available for CP/M,
including various assemblers, macro assemblers, BASIC, C, Pascal,
FORTH, Modula-2, Fortran, Cobol, Lisp and variety of other obscure
and less known languages. The package that stands out among these
programming development tools is Borland's Turbo Pascal 3.0, which
was released for CP/M in 1986.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Pros:
Low price, small size and great speed of compilation (single pass
compiler).</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">TP
3.0 supported overlays, which allowed programmer to go beyond the 64
kB memory limit.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Very
good standard library was included and Turbo Pascal was very closely
compatible with standard Pascal language. Included with product
reference manual was very well written.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Pascal
language is well structured and there is strong type control –
that's its nature. </span><span style="font-family: "verdana" , sans-serif;">The
Pascal program starts with an optional heading section, which if
present gives the program a name and optionally lists the parameters
interfacing program to the environment.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Examples:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace;"><span style="font-size: large;">program
Complex;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace;"><span style="font-size: large;">program
Editor (Input, Output);</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">After
that comes the declaration part which consists of 5 sections:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<ul>
<li><div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">labels
declaration</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">constants
definition</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">types
definition</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">variables
declaration</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">procedures
and functions declaration</span></div>
</li>
</ul>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Pascal
defines that each of above sections is optional and may occur only
once in exact order specified above. Turbo Pascal however allows any
order and any number of occurrences of above sections.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">You
may find more information in <a href="http://techtinkering.com/2013/03/05/turbo-pascal-a-great-choice-for-programming-under-cpm/" target="_blank"><b><span style="color: #e69138;">this</span></b> </a>article on the net.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Commodore
128 is my favorite 8-bit era machine, CP/M my favorite OS of that
time and C-128 can run CP/M, so it comes natural that I wanted to
start a programming project on C-128 under CP/M in TP 3.0.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">I
have never created any arcade computer game. I was not active in game
development in general and except some simple games like Tic-Tac-Toe
or some Text Adventure my achievements in this are are quite poor if
not non-existent. Great place to start learning and from the best
that is – I decided to create my own Tetris clone for CP/M.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Those
who know CP/M environment know its limitations. One is that the
system doesn't provide any GUI. It is text based, 80 column standard.
For a CP/M program to be portable across different hardware
platforms, it should stick with that format.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">But
that's OK. It is possible to create a Tetris clone in text only.
After all classic Tetris is made out of puzzles that are made out of
square blocks. We can use alphanumeric characters or semi-graphics
characters (like reverse-mode space) to build any shapes we need.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Classic
Tetris block or a puzzle is made out of square blocks. The longest
one is made out of 4 blocks in one dimension, so I decided the base
for all my shapes will be a 4 x 4 matrix (like a table):</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPNcc-tBGab_5XqbP-D0uJSFL0eWSqGZ5_6M-9X4sHh5zqfvdNnjcKkb4V1Zd4gs-oFUN4vgkNhFxHNHe6ytHBIByCfqqXQthEqIlQAYKmJPbTNYCf24Ye0CRUUSJe62TPdpESBbkPtFk/s1600/MKTetris1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPNcc-tBGab_5XqbP-D0uJSFL0eWSqGZ5_6M-9X4sHh5zqfvdNnjcKkb4V1Zd4gs-oFUN4vgkNhFxHNHe6ytHBIByCfqqXQthEqIlQAYKmJPbTNYCf24Ye0CRUUSJe62TPdpESBbkPtFk/s1600/MKTetris1.png" /></a></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">In
above matrix I will place the squares to form different shapes.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Also,
each of these shapes can be rotated, so we need an array of 4 of such
matrices to create full sequence for shape animation.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">E.g.:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">1) </span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdKOX2gn18sAAmpThjl15K_iVmM1wB34JkwqHnEeUttLXCAh11GjKp17fJeWGoYEoncFJncnn5EA1VY-Irz3jY8nYbwpcpardijMYgriONkOZKflwPR9VNhYWsu61RVAoDGKHlD_DiI44/s1600/MKTetris2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdKOX2gn18sAAmpThjl15K_iVmM1wB34JkwqHnEeUttLXCAh11GjKp17fJeWGoYEoncFJncnn5EA1VY-Irz3jY8nYbwpcpardijMYgriONkOZKflwPR9VNhYWsu61RVAoDGKHlD_DiI44/s1600/MKTetris2.png" /></a></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif;"><br /></span></div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">2) </span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaou5PEtxXjwRbYpw0IuRDOHAcXV6eaDoLFkX2Mkj5s_B3f-fbSMlLycMyxgiL6RQMqC-jkvEixxtRR-GBFyNosQC0MarpUTgA412WL44uTzb4TPN41xF4-kE7gYSrK6RWOvaY_mwSjKQ/s1600/MKTetris3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaou5PEtxXjwRbYpw0IuRDOHAcXV6eaDoLFkX2Mkj5s_B3f-fbSMlLycMyxgiL6RQMqC-jkvEixxtRR-GBFyNosQC0MarpUTgA412WL44uTzb4TPN41xF4-kE7gYSrK6RWOvaY_mwSjKQ/s1600/MKTetris3.png" /></a></span></div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: xx-small;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">3) </span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxfnkmTobEJQJiWqnN9swY43Uqyq4DtaJIECmdn6XM2vFGKCmhd2706wlslVAsIYtObY0fweamc7TohqdtHlYAF_lGMBFXAEB9hcn149ylnOOfAZNzLWJv9Fl79yZX0VIyGRpQYi2ZEyY/s1600/MKTetris4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxfnkmTobEJQJiWqnN9swY43Uqyq4DtaJIECmdn6XM2vFGKCmhd2706wlslVAsIYtObY0fweamc7TohqdtHlYAF_lGMBFXAEB9hcn149ylnOOfAZNzLWJv9Fl79yZX0VIyGRpQYi2ZEyY/s1600/MKTetris4.png" /></a></span></div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: xx-small;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">4) </span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "verdana" , sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKMH0XvlnYf0MhmdwgFs0_ade9n7QkDEmDzekjaelRBNoax-TFd1QkzmZvL4gvbPzJtRcz91_Gfh5LgmPx9Tl4x-T3ybFqYYy3CaG8vYx2rYbMyEaWWVZHN_mWwAP-qshusZkG0pAmqKU/s1600/MKTetris5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKMH0XvlnYf0MhmdwgFs0_ade9n7QkDEmDzekjaelRBNoax-TFd1QkzmZvL4gvbPzJtRcz91_Gfh5LgmPx9Tl4x-T3ybFqYYy3CaG8vYx2rYbMyEaWWVZHN_mWwAP-qshusZkG0pAmqKU/s1600/MKTetris5.png" /></a></span></div>
<br />
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">The
type declaration of my program may start like this:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">type</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Shape = array[1..4,1..4] of Char;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Block = array[1..4] of Shape;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> All = array[1..6] of Block;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PtrBlkInfo = ^BlkInfo;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> BlkInfo = record { keep info about the block on the scene }</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevRow,PrevCol: Integer; {previous coord. (for repainting)}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Row,Col: Integer; {block coordinates}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint: Boolean; {flag if block needs repainting}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ShNum,SeqNum: Integer; {shape and sequence numbers}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Next: PtrBlkInfo; {pointer to next block}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><i>Shape</i>
holds a single animation frame, <i>Block</i> holds all 4 variants of
the <i>Shape</i> (rotated 0, 90, 180 and 270 degrees) and <i>All</i>
holds all 6 Tetris blocks/shapes with their rotated variants.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><i>PtrBlkInfo</i>
is a pointer to the <i>BlkInfo</i> record which in turn is a data
structure defining exact position of the block on the screen, its
previous coordinates (for re-painting purpose), flag <i>Repaint</i>
that indicates if the shape was rotated or moved, the shape and
sequence number and the pointer to the next block. Thus we defined
the means to manage the Tetris puzzles and all that may be added to
the game scene.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">At
the beginning of our program we may want to initialize all of these
data structures with a procedure similar to this:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">{</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> -----------------------------------------------------------</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Init Shape Array.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> v - character to fill with.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> -----------------------------------------------------------</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">procedure InitShape(v: Char);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">var</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> i,j: Integer;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> for i := 1 to 4 do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> for j:= 1 to 4 do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[i,j] := v;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">{</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> -----------------------------------------------------------</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Initialize All Shapes.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> -----------------------------------------------------------</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">procedure InitAllShapes;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">var</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> i,j: Integer;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> {BlockSymb := Chr(178);}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,4] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[1] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[4,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[2] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[3] := bl[1];</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[4] := bl[2];</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Pieces[1] := bl;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[1] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[2] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[3] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[4] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Pieces[2] := bl;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[1] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[2] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[3] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[4] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Pieces[3] := bl;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[1] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[2] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[3] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[4] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Pieces[4] := bl;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[1] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[3] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[2] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[4] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Pieces[5] := bl;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[3,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[1] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[3] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> InitShape(EmptySymb);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,1] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[2,2] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> sh[1,3] := BlockSymb;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[2] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> bl[4] := sh;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;"> Pieces[6] := bl;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: large;">end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace;"><span style="font-size: 10.6667px;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><i>BlockSymb</i>
and <i>EmptySymb</i> are defined in constants section of the program:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">const</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ScWidth = 16; {scene width}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ScHeight = 20; {scene height}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ScRow = 1; {scene left-upper corner coordinate (Y or Row)}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ScCol = 1; {scene left-upper corner coordinate (X or Col)}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> FallSpeed = 10;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> RefrRate = 100;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> BoxVert = 'I';</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> BoxHoriz = '-';</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> BlockSymb = '#';</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> EmptySymb = ' ';</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace;"><span style="font-size: 10.6667px;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Now
we are ready to write our first test code, not yet a game, but we
need to see if all our laboriously created blocks look good and if
their rotated sequences are in order.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">First
we need to create a main game loop. The main game loop task is to
take user input, perform game logic computations and update the scene
and refresh screen.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">The
procedure may look like this, but feel free to design more advanced
algorithm:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">{ --------------------- MAIN PROGRAM ---------------- }</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> InitGame;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> while not GameEnd do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> UpdScene;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> GetInput;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Delay(RefrRate);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ClrScr;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> writeln('Thank you for playing mktetris!');</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">end.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace;"><span style="font-size: 10.6667px;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><i>InitGame</i>
is where we can draw the static elements of the game screen/scene,
initialize the game variables, blocks positions, score etc.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">procedure InitGame;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">var xx,x1,x2,x3,x4,x5 : Integer;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> InitAllShapes;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Key := 'r';</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ValidKey := False;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ClrScr;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DrawBox(ScCol, ScRow, ScWidth, ScHeight);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> { Show all pieces - this will be removed in final version }</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> xx := ScWidth; x1 := 3; x2 := 8; x3 := 13; x4 := 18; x5 := 23;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x1, 1, 1, 1, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x1, 5, 1, 2, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x1, 9, 2, 1, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x1, 13, 3, 1, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x2, 13, 3, 2, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x3, 13, 3, 3, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x4, 13, 3, 4, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x2, 1, 4, 1, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x3, 1, 4, 2, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x4, 1, 4, 3, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x5, 1, 4, 4, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x2, 5, 5, 1, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x3, 5, 5, 2, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x4, 5, 5, 3, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x5, 5, 5, 4, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x2, 9, 6, 1, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x3, 9, 6, 2, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x4, 9, 6, 3, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(xx+x5, 9, 6, 4, False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> GotoXY(40, 18); write(':/; - move left/right');</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> GotoXY(40, 19); write(',/. - rotate left/right');</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> GotoXY(40, 20); write(' @ - start over');</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> { Add 1st piece to the scene. }</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> New(NewBlk);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> FrstBlk := NewBlk;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> CurrBlk := FrstBlk;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if FrstBlk <> nil then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> with FrstBlk^ do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Col := ScCol + 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Row := ScRow;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevCol := Col;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevRow := Row;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint := True;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> ShNum := 4;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> SeqNum := 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Next := nil;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace;"><span style="font-size: 10.6667px;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><i>UpdScene</i>
is a procedure where we move/paint the pieces of the game depending
on recent user input and game logic.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">procedure UpdScene;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">var</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Blk: PtrBlkInfo;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevSeqNum: Integer;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Blk := FrstBlk;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevSeqNum := -1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> while Blk <> nil do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> with Blk^ do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if Repaint = True then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(PrevCol,PrevRow,ShNum,SeqNum,True);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(Col,Row,ShNum,SeqNum,False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevCol := Col;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevRow := Row;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint := False;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Blk := Next;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> { perform block rotation }</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if CurrBlk <> nil then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> with CurrBlk^ do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if ValidKey and (Key = '.') then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevSeqNum := SeqNum;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> SeqNum := SeqNum + 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if SeqNum > 4 then SeqNum := 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if ValidKey and (Key = ',') then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> PrevSeqNum := SeqNum;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> SeqNum := SeqNum - 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if SeqNum < 1 then SeqNum := 4;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if PrevSeqNum > 0 then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(Col,Row,ShNum,PrevSeqNum,True);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> DispBlock(Col,Row,ShNum,SeqNum,False);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> { perform block falling down and movement }</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if CurrBlk <> nil then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> with CurrBlk^ do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if ValidKey and (Key = ';') then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if Col + 4 < ScCol + 1 + ScWidth then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Col := Col + 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint := True;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if ValidKey and (Key = ':') then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if Col > ScCol + 1 then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Col := Col - 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint := True;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if Row < ScHeight+ScRow-3 then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Row := Row + 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint := True;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if ValidKey and (Key = '@') then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Row := 1;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Repaint := True;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">end;</span></div>
<div style="margin-bottom: 0in;">
<i style="font-family: verdana, sans-serif;"><br /></i></div>
<div style="margin-bottom: 0in;">
<i style="font-family: Verdana, sans-serif;">DispBlock</i><span style="font-family: "verdana" , sans-serif;">
is a procedure responsible for displaying/erasing the individual
block on the screen.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">{</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> -----------------------------------------------------------</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> Display or erase block.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> x, y - screen coordinates (x: 1..40, y: 1..24)</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> sn - shape # (1..5)</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> rn - sequence/rotation # (1..4)</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> era - True: erase block/False: paint block.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> -----------------------------------------------------------</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">}</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">procedure DispBlock(x,y,sn,rn: Integer; era: Boolean);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">var</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> i,j: Integer;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> bl := Pieces[sn];</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> sh := bl[rn];</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> for i := 1 to 4 do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> for j := 1 to 4 do</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> GotoXY(x*2+i*2-4,y+j-1);</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if sh[i,j] = BlockSymb then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> if era = True then</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> write(' ')</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> else</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> begin</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> write(Chr(27));</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> write('G4 ');</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> write(Chr(27));</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> write('G0');</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;"> end;</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "courier new" , monospace; font-size: large;">end;</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">The
reverse color space character is used to paint a single square. Also,
please note that I paint 2 characters (2 columns) per single row to
bring the aspect ratio of the single square closer to 50/50, since
the 80-column display has the letters much narrower than their
height, thus appearing irregular and it creates undesirable effect,
especially when rotating the block.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">So,
that's the beginning of a fun retro-programming project and I hope I
will have time to continue and improve upon it and find some
following audience that may possibly learn from this experience of mine.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Source
code available on <a href="https://github.com/makarcz/mktetr_tp3" target="_blank"><b><span style="color: #f6b26b;">github</span></b></a>.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Thanks for reading.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">Marek K</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: "verdana" , sans-serif;">9/15/2016</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<br />
<div style="margin-bottom: 0in;">
<br /></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-64773373508809522872014-09-21T17:52:00.002-07:002014-09-21T19:05:22.506-07:00Commodore 128 BASIC 7.0 - graphics programming.<span style="font-family: Verdana, sans-serif;"> I have never owned Commodore 128 computer in my youth. I recently purchased two C-128-s from e-bay due to my fascination with CP/M operating system. However there is plenty more to do with this versatile machine than just CP/M or playing games. Compared to its famous predecessor, model 64, it is in many aspects a better microcomputer. Not only it is 100% compatible with C64, making it possible to use all that huge code base created for C-64. It incorporates also a Z-80 microprocessor, making it compatible with CP/M - a huge business oriented software library exists for that operating system. And of course C-128 offers its own improved C-128 native mode with bigger memory (128 KB, banked) and better memory management thanks to the MMU on chip and new graphic facilities, like 80-column text mode (also very useful in CP/M which by default runs in 80-column mode). Last weekend I explored its built in BASIC. Anyone who owned C-64 and made first steps in programming using built in BASIC on that machine knows full well how inadequate that dialect was. Based on Microsoft's version 2, there were no machine specific keywords to take advantage of the built in hardware. All that had to be done with peek'n'poke trickery. No structural constructs available as well. Shortly speaking - a mess and it wasn't easy to create a structured readable program. The program also had to take more space in memory and was slower due to all that extra peek and pokes programmer had to use to generate sounds or create graphics on the screen. There were few options available, all at the cost - switching to machine language (difficult and long development cycle), using extended BASIC dialects (at the cost of memory available for code and variables, sometimes speed) or using different than BASIC languages (also at the cost of memory and/or speed).</span><br />
<span style="font-family: Verdana, sans-serif;">Brilliant engineers at Commodore tried to address most of these issues in this next model (and as it turned out later, the last 8-bit computer by Commodore). BASIC 7.0 is much improved comparing to version 2.0 seen in C-64. It offers keywords that take advantage of the built in graphic and sound hardware as well as memory management (bank selection with BANK command) without the need of remembering the addresses of all the involved hardware registers. The new BASIC also adds some structural constructs like multiple line IF/THEN/BEGIN/BEND decision branches, open-ended (with optional condition) flow/loop control constructs like DO/WHILE/LOOP, DO/LOOP/WHILE, DO/UNTIL/LOOP, DO/LOOP/UNTIL in addition to standard BASIC's FOR/NEXT loop. C-128 offers so much more than C-64 that in fact I put it on my permanent retro-computer desk and replaced C-64 that was there before. Now I have 3-in-1 system (C-64, CP/M and C-128) taking up only slightly more space than C-64.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">To do a little BASIC 7.0 exercise, I decided to write a simple analog clock application that would use the basic graphic capabilities of the machine. I will add sound/alarm abilities to it later, it should be as easy as graphics part with all the extensions that BASIC 7.0 provides.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">To switch C-128 to high resolution mode (or a bitmap mode), BASIC command GRAPHIC is used.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<b><span style="font-family: Verdana, sans-serif;">Formats: GRAPHIC <i>mode, [clear], [split]</i></span></b><br />
<b><span style="font-family: Verdana, sans-serif;"> GRAPHICS CLR</span></b><br />
<br />
<span style="font-family: Verdana, sans-serif;">Where <i>mode</i> can be one of:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">0 - 40 columns (composite or monochrome monitor, tv set),</span><br />
<span style="font-family: Verdana, sans-serif;">1 - hi-res graphics (composite or monochrome monitor, tv set),</span><br />
<span style="font-family: Verdana, sans-serif;">2 - hi-res graphics (split screen, the same type of output like 0 or 1),</span><br />
<span style="font-family: Verdana, sans-serif;">3 - multicolor graphics (the same output as above),</span><br />
<span style="font-family: Verdana, sans-serif;">4 - multicolor graphics (split screen, the same output as above),</span><br />
<span style="font-family: Verdana, sans-serif;">5 - 80 columns (RGB or monochrome monitor).</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I did not mention before that C-128 features 2 separate video output ports, the composite/TV and RGB. Composite/TV output is of the same format as C-64 video output, that provides 40 column text and high-resolution (320x200) graphics mode as well as other graphics modes (multicolor). Technically it is possible for C-128 to work with two monitors at the same time, one RGB and one composite (or a TV set). This is the setup that I have. User can freely switch between these modes in immediate mode and in program mode where application can output text to 80-column (RGB) monitor while drawing graphics on the composite monitor or alternate text output to both monitors by switching the modes with GRAPHIC command. I think this is pretty cool for a 8-bit 30 years old computer to be able to do that.</span><br />
<span style="font-family: Verdana, sans-serif;">The "GRAPHICS CLR" command is NOT a screen clearing command. It clears and de-allocates memory used for graphics operations reclaiming it back for BASIC. To clear any given graphics mode, use flag <i>clear</i> in the GRAPHIC command or command SCNCLR.</span><br />
<span style="font-family: Verdana, sans-serif;">You may want to use "GRAPHIC CLR" if you run out of memory for BASIC and you're no longer using hi-res graphics.</span><br />
<span style="font-family: Verdana, sans-serif;">Flag <i>split</i> lets user have graphics and text on the same screen, thus allowing to present text output of the application in the more convenient text mode while having hi-res picture on top of it as well as allowing the standard text input from user (INPUT command). The number used in <i>split</i> tells BASIC interpreter at which line number the split screen starts. The text can also be mixed with graphics on the hi-res screen, but BASIC command PRINT can not be used for that - CHAR command is the graphics command designed for that purpose.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">To draw a circle in one of the bitmap modes, BASIC command CIRCLE can be used:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><b>Format: CIRCLE color_source, x_center, y_center, x_radius, y_radius, [start_angle], [end_angle], [rotation], [segment]</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Computer must be in proper graphics mode to be able to draw a circle.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The color source is a number from 0 to 3, as in the COLOR command:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">0 - 40-column (composite) background,</span><br />
<span style="font-family: Verdana, sans-serif;">1 - 40-column foreground,</span><br />
<span style="font-family: Verdana, sans-serif;">2 - multicolor 1,</span><br />
<span style="font-family: Verdana, sans-serif;">3 - multicolor 2.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The COLOR command stores a color into the color source register.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><b>Format: COLOR color_source, color_number</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Please refer to the C-128 system guide for the colors and their assigned numbers.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">BASIC command DRAW puts a line on the hi-res screen.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><b>Formats: DRAW color_source, x1, y1 [TO x2, y2]</b></span><br />
<span style="font-family: Verdana, sans-serif;"><b> DRAW TO x, y</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">DRAW is used to draw points and lines in the hi-res and multicolor modes. It can draw a line from one specified location (x1, y1) to another (x2, y2) or from the current graphic cursor position to the specified coordinates (DRAW TO). If the 1st format is used but the 2nd set of coordinates is ommited (TO x2, y2), a point is turned on. The <i>color_source</i> as in COLOR and CIRCLE commands tells BASIC which color to use for a point/line. This can also be used to remove existing points or lines, when we draw with background as a color source (<i>color_source=0</i>). You can also specify relative coordinates by supplying a distance and an angle. This method of locating a point requires to use semicolon in the command.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Example:<b> GRAPHIC 1:LOCATE 50,50:DRAW 1,25;90</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">will plot a point at coordinates 75,50.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Example: <b>DRAW 0,160,100 to 50;hr%*(360/12)+(mi%/15)*(360/48)</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">will plot a line from point at coordinates 160,100, length=50 at the angle calculated from hr% and mi% variables (this particular example shows how to draw a small hand of the analog clock).</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Without further ado, let me present the BASIC code that will display graphical (very simplified) analog clock image that is updated every minute (except seconds which are drawn more often) based on the system time <i>TI$</i>. I used <i>petcat</i> program (part of the WinVICE Commodore emulator software) to convert native BASIC code (<i>PRG</i>) to the text format.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>petcat -70 -o analogclock.txt -- analogclock.prg</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10 rem analog clock v1.0</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 20 rem (c) by marek karcz 2014</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 30 rem all rights reserved</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 40 rem</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 50 rem variables</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 60 hr%=0:mi%=0:se%=0:pr%=0:hm%=0</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 70 hr$="":mi$="":se$="":hm$=""</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 80 input "set time (hhmmss) ";tm$</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 90 ti$=tm$</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 900 goto 10000</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1000 rem initgr</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1005 scnclr</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1010 graphic 1,1:width 2</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1020 color 0,1:color 1,6:color 5,6</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1030 circle 1,160,100,110,90</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1040 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1050 rem draw short hand</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1060 draw 1,160,100 to 50;hr%*(360/12)+(mi%/15)*(360/48)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1070 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1080 rem draw long hand</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1090 draw 1,160,100 to 90;mi%*(360/60)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1110 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1130 rem eraseshorthand</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1140 locate 160,100</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1150 draw 0,160,100 to 50;hr%*(360/12)+(mi%/15)*(360/48)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1160 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1170 rem eraselonghand</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1180 draw 0,160,100 to 90;mi%*(360/60)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1190 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1200 rem gethr</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1210 hr$=mid$(ti$,1,2)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1220 hr%=val(hr$)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1225 if hr%>11 then hr%=hr%-12</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1230 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1240 rem getmi</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1250 mi$=mid$(ti$,3,2)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1260 mi%=val(mi$)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1270 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1280 rem getsec</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1290 se$=mid$(ti$,5,2)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1300 se%=val(se$)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1310 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1320 rem draw seconds</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1330 char 1,0,24,se$,1</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1340 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1350 rem gethrmi</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1360 hm$=mid$(ti$,1,4)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1370 hm%=val(hm$)</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 1380 return</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10000 rem main</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10010 gosub 1000</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10015 gosub 1200:gosub 1240:gosub 1280:rem get hr%,mi%,se%</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10017 rem gosub 1050:gosub 1090:rem draw hands</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10020 do</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10025 gosub 1350:get hrmi</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10030 if pr%<>hm% then begin:</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10040 gosub 1130:gosub 1170:rem erase hands</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10050 gosub 1200:gosub 1240:rem get hr%,mi%</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10060 gosub 1050:gosub 1090:rem draw hands</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10070 bend:</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10080 gosub 1280:rem get se%</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10090 gosub 1320:rem draw seconds</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10100 pr%=hm%</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 10110 loop:rem loop forever</span><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> 20000 end</span><br />
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Thanks to support for graphics modes in BASIC, code is short and clear.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Because image speaks 1,000 words, here are some pictures of this code in action:</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBkvhZI4leY0ygbUJZQRy0MB-hle-89qcUdPXEytVewb3PcZWWnQu_fqHv6CCJWBUeFOd3SNBYZaAWONeOGY1jZQaN62p7qM8G5H4Ab26bJ4pEkbKV6bITnoFCrGUph0_nQmy8NtGwknw/s1600/IMG_2033.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBkvhZI4leY0ygbUJZQRy0MB-hle-89qcUdPXEytVewb3PcZWWnQu_fqHv6CCJWBUeFOd3SNBYZaAWONeOGY1jZQaN62p7qM8G5H4Ab26bJ4pEkbKV6bITnoFCrGUph0_nQmy8NtGwknw/s1600/IMG_2033.JPG" height="640" width="480" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrwWRgcqlOaSIuHus2zHwi_2tDM8aemef_QF7qz1k2K2Qh3SQG6ZroXA95gXcO0McR_kHgx9G8xjH3NTJYYgdd_lPB3tj0aFpJ9ZCoJ9wWaeFZGEZghGQEI1g8IKt9XOCOOwK0r-7PP-s/s1600/IMG_2032.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrwWRgcqlOaSIuHus2zHwi_2tDM8aemef_QF7qz1k2K2Qh3SQG6ZroXA95gXcO0McR_kHgx9G8xjH3NTJYYgdd_lPB3tj0aFpJ9ZCoJ9wWaeFZGEZghGQEI1g8IKt9XOCOOwK0r-7PP-s/s1600/IMG_2032.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkfNeOnia4lhA8oewRqkz4JsofDxNjv9zJctodgWowssPojK0Q0KZ8SOvPOLSdxDwTobIn_SR1fgCEL1wtvOKL_9eKW49C6KvrUWsCcEe0c-S5EhNH3zTt4nwQkZfNEFQ6PvXm4EJ_PE8/s1600/IMG_2034.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkfNeOnia4lhA8oewRqkz4JsofDxNjv9zJctodgWowssPojK0Q0KZ8SOvPOLSdxDwTobIn_SR1fgCEL1wtvOKL_9eKW49C6KvrUWsCcEe0c-S5EhNH3zTt4nwQkZfNEFQ6PvXm4EJ_PE8/s1600/IMG_2034.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWiwQCShVc2CQsq5Bigj284RndBgr1hTeP_m8bktcjUptnQGsjuc0abRPXmjes4Ro-d1AjKxlvJIYvcI7XvtacdfoqCYCPZaYkCRVogN58cmpDKJdE78pg7hUNWndFkuX58mzWiMYkUb0/s1600/IMG_2034_z.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWiwQCShVc2CQsq5Bigj284RndBgr1hTeP_m8bktcjUptnQGsjuc0abRPXmjes4Ro-d1AjKxlvJIYvcI7XvtacdfoqCYCPZaYkCRVogN58cmpDKJdE78pg7hUNWndFkuX58mzWiMYkUb0/s1600/IMG_2034_z.JPG" height="436" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgve2PdmpHipM0nUO7oPw3yQJ-lpXn_IZA997MxtOkIEIrx45t5z-2uIYIRA0mE-bmOS6inWN1PtycVrvPqMB_ZNk3_qGE4BcT_QJTMi_UWrZkI1e7AQLkv8Moma7rMcjJTUMcr4CfOBFs/s1600/IMG_2036.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgve2PdmpHipM0nUO7oPw3yQJ-lpXn_IZA997MxtOkIEIrx45t5z-2uIYIRA0mE-bmOS6inWN1PtycVrvPqMB_ZNk3_qGE4BcT_QJTMi_UWrZkI1e7AQLkv8Moma7rMcjJTUMcr4CfOBFs/s1600/IMG_2036.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN4tqYiJEzMll2uxEYoQiySMjigEmiUxFaHTomKCG-oeJjvikO9fcQEAnU213szIQUO_Vc_e1QCJtMIiFLsKPLzNlGypjx6Ru7yB7V5EBhBt69E3Gha3-GhtL2ov5gxM4dpHWr5Cs8P50/s1600/IMG_2037.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN4tqYiJEzMll2uxEYoQiySMjigEmiUxFaHTomKCG-oeJjvikO9fcQEAnU213szIQUO_Vc_e1QCJtMIiFLsKPLzNlGypjx6Ru7yB7V5EBhBt69E3Gha3-GhtL2ov5gxM4dpHWr5Cs8P50/s1600/IMG_2037.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFruApRI7Ien_EuSac4krpqVlnon2YpibKHi8aCY1qUnvQ6wJQv9du97A3ut68iOK7IYifVkV0-B6PIoz5KLfmEFRtJLubQ0wFsU1fy15hLJiG1zEB6PDf9cp66saLjHqmU5v3egedvu4/s1600/IMG_2040.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFruApRI7Ien_EuSac4krpqVlnon2YpibKHi8aCY1qUnvQ6wJQv9du97A3ut68iOK7IYifVkV0-B6PIoz5KLfmEFRtJLubQ0wFsU1fy15hLJiG1zEB6PDf9cp66saLjHqmU5v3egedvu4/s1600/IMG_2040.JPG" height="480" width="640" /></a></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Thank you for your time.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Literature:</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">COMPUTE!'s 128 Programmer's Guide, ISBN 0-87455-031-9.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Marek Karcz</span></div>
<div>
<span style="font-family: Verdana, sans-serif;">9/21/2014</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com1tag:blogger.com,1999:blog-2918813988661303224.post-88690056894665135842014-03-22T08:45:00.000-07:002014-03-22T08:45:51.372-07:00Maintaining your ancient CBM hardware.<span style="font-family: Verdana, sans-serif;">You will not believe (or perhaps most of you seasoned Commodore equipment users will) how much time in troubleshooting costed me putting an old diskette from e-bay in my Commodore disk drives.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">It all started when my GEOS-128 set arrived from e-bay. Two manuals, 6 diskettes, all visually in a very good shape. The smell of these items suggested they possibly spent long time at the bottom of some closet. No indication of dampness. The pages in one of the books were only yellowed a little bit. The diskettes looked clean (perhaps except one, which only you could notice by looking at the surface at certain angle that there is some residue on it, which of course I noticed after all my troubles).</span><br />
<span style="font-family: Verdana, sans-serif;">So, I opened the GEOS manual on the page with instruction how to boot the system for the first time, I put the system diskette in my primary drive (I use three 1571 drives, first one with Jiffy DOS installed and a uIEC-SD device, this setup works very nice with CP/M) and booted it. The 1st disturbing thing to notice was a whining sound from the drive. The disk did not boot of course. I made a few extra attempts with the same result.</span><br />
<span style="font-family: Verdana, sans-serif;">"OK" - I thought. - "This is just an old disk, I will try to read its directory."</span><br />
<span style="font-family: Verdana, sans-serif;">This of course did not work, but perhaps because it is a GEOS diskette?</span><br />
<span style="font-family: Verdana, sans-serif;">Anyway, I tried in my other drives. Then I put some of the other diskettes that arrived with the set in all of my drives and tried to read them. None has worked.</span><br />
<span style="font-family: Verdana, sans-serif;">This is kind of expected and it happens with old diskettes. The most disturbing part however was that my normally working disks now has stopped reading too in any of my disk drives.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">"What is it?" - I thought. - "The day of broken Commodore drives?".</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I realized it is rather unlikely that all of the disk drives went down the same day. But, still clueless, I opened my first drive to see for obvious mechanical issues. Did not find any (even magnetic head looked clean). Next I opened my worst 1571 (the one I owned the longest time and looks like the one most worn down by time) and attempted to align it. Nothing worked. I gave up some time in the morning. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The next day I got my revelation moment - "A dirty head!".</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Yep! That was it. These old disks must have been stored in some not too good conditions, perhaps for some time exposed to moisture and/or high temperature. Their magnetic layer literally peeled off their surface and it deposited on magnetic heads choking them up! I swabbed them with alcohol and they are all like new again.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I know most of the Commodore or any retro computer equipment users know this stuff. But if you are a young inexperienced retro computer technology enthusiast, beware! Better to have a designated disk drive (instead of your best primary disk drive) for reading/examining the diskettes from unknown sources, especially if they are listed as untested or their condition is not mentioned by the selling party. And if your equipment stops working as expected, first look for the obvious reasons (like neglected maintenance in my case, head cleaning was long overdue, regardless of the dirty diskettes put in recently). I swabbed the heads but I think it is better (and more convenient) to use one of those head cleaning diskettes, which unfortunately are not being made these days. I saw them on e-bay though and I am going to order some for myself.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Cheers!</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com1tag:blogger.com,1999:blog-2918813988661303224.post-81442310689076822742013-11-17T11:49:00.000-08:002013-11-17T11:49:23.562-08:00Serial port communication on Apple IIc.<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Apple
II was a very good </span><span style="font-family: Verdana, sans-serif;">and quite popular 8-bit machine </span><span style="font-family: Verdana, sans-serif;">in its time. It
features a hardware UART for RS-232 port communication that can still
be used today. Even from the BASIC language level, it is quite simple
to make the use of that feature. I happen to own Apple IIc, which I did not own in the 80-s. I bought the set of the computer, monitor, printer and software on e-bay out of curiosity. I have to admit I also like the look of the little machine which was advertised as a portable Apple II. It would no pass the standards of portability today, however in the early to mid 1980-s it was enough if the computer had a carrying handle and/or some sort of a case. Apple IIc has an UART/RS-232 built in permanently as it does not feature the expansion bus as its bigger brother Apple II does.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
basics are as follows:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">On
the PC side setup port to 300 baud (default apple 2c speed), 8 bit,
no parity, 1 stop bit, no flow control. Your terminal may or may not
offer customization of the parameters listed below. I used the Hyper
Terminal Private Edition. Other emulators may offer the customization
of the listed below properties in the different form. Follow you
terminal emulator's documentation:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Terminal
setup: ANSI</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">ASCII
setup: append line feed to incoming line ends, force incoming data to
7-bit ASCII.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Apple IIc side - issue command PR#2.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Now
all the output goes via serial wire to a PC.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Alternative
baud setup:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Apple
2c:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">After
PR#2 command, press CTRL-A and then the baud code:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">CODE BAUD</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">1B 50</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">2B 75</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">3B 110</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">4B 135</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">5B 150</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">6B 300</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">7B 600</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">8B 1200</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">9B 1800</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">10B 2400</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">11B 3600</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">12B 4800</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">13B 7200</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">14B 9600</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">15B 19200</span></b></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Courier New, Courier, monospace;">16B 115k</span></b></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">To
setup the serial port speed from basic, use print chr$(1) followed by
the speed code, e.g:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>10
pr# 2</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>15
print chr$(1);"15b"</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>20
print "hello world!"</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>30
goto 20</b></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Above
program will redirect output to serial port and setup transmission
speed to 19200 baud.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">PC
side - follow manual of your terminal emulator software to match the
baud rate of the Apple 2c.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
automatic line trace in BASIC is automatically on (seems to be a
feature) when the output is redirected to a serial line. Perhaps
because such mode of working was intended for development/debugging
purpose. Anyway, it is good to include NOTRACE just after PR#2 in
your program to turn this feature off. There are several other (than
baud rate) parameters that can be setup for serial port after IN#2 or
PR#2. Just use PRINT CHR$(1);"{command_code}" to set them
up.</span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Here
are the command codes:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>Data
format</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>Code Data
Length Stop bits</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>0D 8 1</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>1D 7 1</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>2D 6 1</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>3D 5 1</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>4D 8 2</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>5D 7 2</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>6D 6 2</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>7D 5 2</b></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">ASCII
setup:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Code Effect</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I echo
output to the screen</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">K do
not send line feed after carriage return</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">L send
line feed after carriage return</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>Parity:</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>Code Parity
Check Mode</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>0P none</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>1P odd</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>2P none</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>3P even</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>4P none</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>5P MARK(1)</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>6P none</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, Courier, monospace;"><b>7P SPACE(0)</b></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Example
BASIC program setting up 9600 baud, 8-N-1, send LF after CR:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>20
PR#2</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>30
NOTRACE</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>40
PRINT CHR$(1);"14b"</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>50
PRINT CHR$(1);"0d"</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>60
PRINT CHR$(1);"0p"</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>70
PRINT CHR$(1);"l":rem it is small "L".</b></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">For
some reason, I have to setup 7 bit data length, 1 stop bit on the PC
side, even though Apple works in 8-1 mode. I will have to look into
this later, for now I don't understand why the discrepancy. </span>
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">On
Linux (R-Pi) I used 'putty' or just plain "cat /dev/ttyUSB0"
to receive data from apple.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">To
redirect input and output to serial port, so you can work on apple
from remote terminal, type on apple:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>IN#2</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>{CTRL-A)14b</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><b>PR#2</b></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">From
this moment, whatever you type in the terminal emulator on the PC
workstation is really happening on Apple. The PC workstation acts a a dumb terminal
for the Apple computer. Pretty cool. You can actually create a boot
diskette for the Apple to load up and execute all necessary serial
port initialization commands at the boot time and with a PC/laptop
connected to the Apple via serial port (or USB with USB to serial converter) you do not need a display monitor with the Apple computer.
This way of working with Apple II of course may have some
limitations, which I am sure user would discover very quickly.
However it is possible to work with BASIC and text based programs in
this manner.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Happy
retro-computing!</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Thank
you for reading.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Marek
Karcz, 11/17/2013</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-44941668561306971542013-11-16T17:11:00.001-08:002013-11-16T17:12:06.997-08:00Apple IIc as a dumb text terminal.<div style="margin-bottom: 0in;">
<b><span style="font-family: Verdana, sans-serif;">Using
you old computer hardware with modern equipment.</span></b></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">If you
happen to have Apple II (IIc) computer and you think it is just
taking space, do not put it in the trash, sell or donate just yet.
The thing is, you own it because perhaps you purchased it long time
ago, or got it as a gift and at some time liked it. It gave you hours
of fun and helped to introduce you into the computing world. Whatever
the reason, it may make your heart heavy to let it go. Well, you can
still use it! Consider this - Apple IIc has a good serial port
hardware driver and can be easily interfaced with modern equipment
that is also equipped with a serial or USB ports (with USB to serial
converter). All that is needed on the Apple side is a terminal
emulation software and a serial null-modem cable adaptor that
converts the Apple's mini-din to the DB-9 connector seen on modern PC
computers. All the information I needed in order to turn my Apple IIc
into the serial dumb terminal I found here: </span>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><a href="http://www.biscade.com/2012/03/apple-iic-compact-serial-console/">http://www.biscade.com/2012/03/apple-iic-compact-serial-console/</a>
</span>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">and
here:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><a href="http://pdw.weinstein.org/2007/06/apple-hacking-for-fun-and-profit.html">http://pdw.weinstein.org/2007/06/apple-hacking-for-fun-and-profit.html</a>
</span>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">First
I prepared 3 blank floppy disks for Modem MGR software. I used
AppleWorks software which I happen to have purchased with my Apple
IIc. To transfer the Modem MGR images to Apple, you need ADT Pro
client on the Apple side and a server on the PC side. Both are
available on the internet as well as detailed instructions how to
install and configure them, so I will not duplicate it here. Just
check out the web site:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><a href="http://adtpro.sourceforge.net/">http://adtpro.sourceforge.net/</a>
</span>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">After
the transfer of Modem MGR software, I had 3 disks: Installation,
Utilities and Work. First I inserted and booted the Installation disk
on my Apple and follow the instructions. I configured the software to
work in 80-column mode (menu option 2) video driver, non-smart modem
(menu option 10) and saved the configuration back to the work disk.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Next I
connected the Apple's serial port to my DSL (Damn Small Linux)
server. The server runs a script:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">#!/bin/bash</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">while
true</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">do</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">/sbin/getty
-L 9600 ttyS1 vt100</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">done</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
connection via standard serial cable and the mini-din to DB-9 adapter requires no null-modem connector, since the mini-din to DB-9 adapter cable is already a NULL modem. However I used the null modem serial
cable and wondered for some time why this did not work. Then I had to
add extra null-modem adapter.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Once
computers were connected, I booted Modem MGR work disk on the Apple.
It displays a bunch of options that can be accessed by pressing ESC
key followed by the letter. At any time, I can press ESC and Shift-?
to re-display the list of available options.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
first step is to setup the modem baud rate, which in my case is 9600.
Next, the data format - number of bits, the parity and the number of
stop bits: 8-N-1. The last step is to enter the Modem MGR into the
terminal emulation mode, which is achieved by pressing ESC and ':'
(colon) and then pressing V for loading the VT220 terminal emulation
mode. Then I pressed enter and voila! - the login prompt appeared.
Even though on the server side 'getty' runs in vt100 mode, I
experienced no issues. This of course is easily adjusted on the
server side.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Pictures:</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW5O9_ytwdNnQRZ9eLPXXt7n3-v0HG5NgRS8n_6ZV1M3r6jooaGYZnlnJZ9Vrld0z98ymd1xk2VsGySxcssTyuRkNIEBgmlCnttvYM6JV1SheXLQ6uPJYyTbn1uJGur1vHRvF3iKTO4q8/s1600/IMG_1886.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW5O9_ytwdNnQRZ9eLPXXt7n3-v0HG5NgRS8n_6ZV1M3r6jooaGYZnlnJZ9Vrld0z98ymd1xk2VsGySxcssTyuRkNIEBgmlCnttvYM6JV1SheXLQ6uPJYyTbn1uJGur1vHRvF3iKTO4q8/s640/IMG_1886.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Image
1: Transferring Modem MGR images to Apple 2c diskettes - client side.</b></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<br />
<span style="font-family: Verdana, sans-serif;"><b></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBgYvVBtesVr-2CrGU0yL5yODfrp_XbGzfbZGdynB23-rzoUwnVLZd0RAlHCe6TkV-U4O-sF0kz5kFLOlmXatKjNZWXPl6GcCJBp0mLEzwhvgEl4E9FYdJfMYhpvCELpcKLduA61QDzYU/s1600/IMG_1887.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBgYvVBtesVr-2CrGU0yL5yODfrp_XbGzfbZGdynB23-rzoUwnVLZd0RAlHCe6TkV-U4O-sF0kz5kFLOlmXatKjNZWXPl6GcCJBp0mLEzwhvgEl4E9FYdJfMYhpvCELpcKLduA61QDzYU/s640/IMG_1887.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Image
2: Transferring disk images - server side.</b></span></div>
<div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIlu4GIXdHq0pBCLpXvOG3hzvpUMapY9DS-46QcWxD7Id-0D7K1TxmVcNDko3V1OoJEdEeJKeJry-a6aSc1oIU6OkDaXfbMOm2CsBVAO0fVzBDGgpzW2ENHN2k8GKfYOWO5zXpT4Dceas/s1600/IMG_1890.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIlu4GIXdHq0pBCLpXvOG3hzvpUMapY9DS-46QcWxD7Id-0D7K1TxmVcNDko3V1OoJEdEeJKeJry-a6aSc1oIU6OkDaXfbMOm2CsBVAO0fVzBDGgpzW2ENHN2k8GKfYOWO5zXpT4Dceas/s640/IMG_1890.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Image
3: A working text terminal emulator on Apple IIc.</b></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd5ltABle9qj8HtJ7_jZkckUstjJdD-ck5ZKRKwif5x1BiGcJrKPai5vsQ74sufEW-ubQlGZut_nIb4kE998m1VJ21Q2Qp4dkwPwMVZLKTaVzSivLLND8D3uURpL8VMrLu98FGvkobHdI/s1600/IMG_1893.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd5ltABle9qj8HtJ7_jZkckUstjJdD-ck5ZKRKwif5x1BiGcJrKPai5vsQ74sufEW-ubQlGZut_nIb4kE998m1VJ21Q2Qp4dkwPwMVZLKTaVzSivLLND8D3uURpL8VMrLu98FGvkobHdI/s640/IMG_1893.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Image
4: The output from 'top' command - it ran well and there were no
emulation issues.</b></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">It was a fun little project. Now whenever I want to have retro computing experience I can connect to my DSL server with Apple IIc and run Z-machine emulator to play one of the Infocom's text adventures.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Thank you for reading.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Marek Karcz, 11/16/2013</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-47765638778665322652013-09-14T23:39:00.001-07:002013-09-15T11:18:12.836-07:00Conway's Game Of Life on a Commodore 64.<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I remember when I learned for the 1<sup>st</sup>
time about Conway's Game Of Life – a Cellular Automata model in a
Polish equivalent of Popular Mechanics for youth: “Mlody Technik”
(Young Technician) in 1984. I have been at the time a technical high school
freshman. I
immediately recognized how great a simulation platform a computer would
be for this model. Unfortunately I did not have a computer or even an
access to one. I spent long hours simulating colonies on a piece of a
graph paper.
</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">In the early 2000-s when I was learning
C#/.NET I did a C# implementation as an exercise. The GUI is a bit awkward, but simulation is fairly
fast and can emulate quite big arrays of the cells. My son loves to
play with this program even though I never had time to refine it or get rid of few bugs. It has edit/load/save abilities, user
can set, unset cells with a mouse click, zoom in and out and enable
grid lines. My 9-year old has no problem with that, so I guess everybody could get used to it.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir4OTgDeUFsxghpESp5N-se0ckRrIZZcuJEC-NMEm9kfreLkSuNQyBZftbEopNTjxjdWEVr0076J8vmPfk3KP2AQgY7-9EwEK4C-R9ehv8MRDZHScQ2pJl1oPh1rexdhz6F4Oy-fi7x8E/s1600/scr1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir4OTgDeUFsxghpESp5N-se0ckRrIZZcuJEC-NMEm9kfreLkSuNQyBZftbEopNTjxjdWEVr0076J8vmPfk3KP2AQgY7-9EwEK4C-R9ehv8MRDZHScQ2pJl1oPh1rexdhz6F4Oy-fi7x8E/s1600/scr1.jpg" height="456" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Modern GUI C#
implementation of Game of Life.</i></span></div>
</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqBh2BrS8AqIveZLPQ0dWru_IsevT3MfGC8fDabuyqGuGp3WWkJ4mnoQXKtMxpmIwV8AhbdTcD561DJpNWgP8bEkAgCyLEiqThyxa9fL0mdGdeIAaUBDMCItVNhm00QF7FCX7l7tZzLy8/s1600/scr2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqBh2BrS8AqIveZLPQ0dWru_IsevT3MfGC8fDabuyqGuGp3WWkJ4mnoQXKtMxpmIwV8AhbdTcD561DJpNWgP8bEkAgCyLEiqThyxa9fL0mdGdeIAaUBDMCItVNhm00QF7FCX7l7tZzLy8/s1600/scr2.jpg" height="474" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>C# Game of Life -
program setup.</i></span></div>
</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfyxkAN56yqHTPrNFpgYxF2fiswLPjr6ro1dBjNHJwJWQW51F3JKZ6PEvSU8wirNqyTCnf5_VflyLH1lxipjQKmwvZO9UKlQyqFMbosRvdWT-9P4O_fJ2Mj15Ooo99kL60WL9QLpYu9YU/s1600/scr3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfyxkAN56yqHTPrNFpgYxF2fiswLPjr6ro1dBjNHJwJWQW51F3JKZ6PEvSU8wirNqyTCnf5_VflyLH1lxipjQKmwvZO9UKlQyqFMbosRvdWT-9P4O_fJ2Mj15Ooo99kL60WL9QLpYu9YU/s1600/scr3.jpg" height="456" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>C# Game of Life - with
elevated zoom and grid lines enabled for easy editing.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">In the meantime I made numerous console
based ports in C language for DOS and Linux. It is always fun. Now, while this is quite easy with modern computers and programming languages, it is not the same on some old slow CPU and limited memory platform using low level machine language or slow interpreted language like BASIC for example.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Recently I realized that I have never
did a C-64 port. Being a Commodore aficionado, I found this a great
oversight, so I got to work.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">My first tries using BASIC and Power-C
for C-64 and C-128 were disappointing. My algorithm was very slow. I
realize that with some clever coding I could do a fast simulation in
higher level language. Perhaps one day I will try to
invent some clever GOL simulation algorithm in C which will be fast enough for practical application. Even though I like to work directly on a retro hardware, (emulator does not emulate look and feel), this time I wanted to try the cross-platform IDE called C64 Studio (I love the demo helicopter game that comes with it). I
installed it, made sure it points to my installation of Vice emulator
and got to work. I researched some GOL implementations for CBM
platform on the internet and have been impressed by this great piece
of 6502/C64 code by 'Ruk':</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><a href="http://csdb.dk/release/?id=104384&show=notes#notes" target="_blank">Ruk's Game of Life, under 256 bytes implementation with sound and double buffering.</a></span><br />
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Although Ruk's goal was minimum size
and maximum speed, so the program is not really packed with features, it is
still very impressive what you can do with this ancient by today's standard hardware. He
does some pretty clever encoding of the colony so the calculating of
the next generation is real fast and code is extremely compact. It
fits in less than 256 bytes with full screen emulation/presentation
and sound.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I did not match Ruk's implementation of
GOL speed and tiny size, however these were not my goals (well, maybe the speed was, but I lack the skill at the moment). Instead my program is
packed with practical features and makes up for slower speed and
(much) bigger code size with numerous functions like: built-in demo colonies,
random colony generator, colony full screen screen editor and disk I/O. Although
program takes 16 blocks on a disk, the colony files are only one
block in size (binary encoded, 40*25/8 = 125 bytes is all it takes to encode 1000-cell colony) and save and load pretty fast. The
simulation speed is also satisfactory with about 2 ¼ generations per
second.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Verdana, sans-serif;">Conway's Game Of Life – the rules.</span></b></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The world of Game of Life (GOL)
consists of a 2-dimensional array of cells, which can have a dot
(live cell) or be empty. The next generation of dots is calculated by
counting the live neighbors on adjacent cells. E.g: please refer to
illustration below, where the central cell is live (has a dot) and
has 8 adjacent cells, which contain a total of 3 live neighbors.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju9PX-Nx4G88e9rgXCWA1evtrFtNlkl83Hj95kuE9czKGOA-9eYrKhDqtHzqWf7pBxfDxT5T-a8BhvNCezgmfdJjPUT326YI-a-V8WBX1QeVJk0GOpGg0UfFA8YR0q2j5Pkzpiu_mBu9s/s1600/scr4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju9PX-Nx4G88e9rgXCWA1evtrFtNlkl83Hj95kuE9czKGOA-9eYrKhDqtHzqWf7pBxfDxT5T-a8BhvNCezgmfdJjPUT326YI-a-V8WBX1QeVJk0GOpGg0UfFA8YR0q2j5Pkzpiu_mBu9s/s1600/scr4.jpg" height="262" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>A cell with adjacent
cells.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The rules of death and life are as
follows:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">- Death -</span></div>
<ul>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Each dot that has 1 or no live
neighbors dies out of loneliness.</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Each dot that has 4 or more live
neighbors, dies out of the overcrowding.</span></div>
</li>
</ul>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">- Life -</span></div>
<ul>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">On each empty cell that has
exactly 3 live neighbors, a new dot is born.</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Each dot that has 2 or 3 live
neighbors, remains in its live status.</span></div>
</li>
</ul>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<b><span style="font-family: Verdana, sans-serif;">Computer algorithm.</span></b></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">On today's fast hardware, the directly
implemented algorithm causes no speed concerns. The cells can be
encoded in bit fields or directly in a BOOLEAN or character array.
The cells of the arrays are iterated sequentially and the neighbors
number is calculated for each cell separately and the next generation
of the colony can be generated to the separate memory buffer and then
presented in whatever form to the user.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">However working with the 1 MHz 8-bit
CPU with limited RAM is different. There are memory and performance
considerations. We want to avoid too much of the data copying
operations (internal colony representation vs. screen presentation,
copying data between buffers etc.) and really huge arrays. In my
implementation I decided to compute the next generation directly in
the text screen memory (the world is a 1000 cells array, 25 rows 40
columns each). To avoid artifacts on the screen while the next
generation is calculated, double buffering technique could be used.
However I chose a technique to encode the screen codes for dying and
born cells of the next generation to be as closely represented on the
screen to the live and empty cells of a current generation as
possible. For example the dot (live cell) is presented with screen
code $51, which is a big filled oval dot. The dying cell is
represented with code $57, which is a very similar semi-graphical
character to the one represented by code $51, except it just has a
small not filled with color hole inside (donut like) while remaining
the same size. Therefore when the next generation calculating
algorithm is marking the cells for dying, their screen presentation
do not change significantly. Just a little hole appears briefly in
the middle of each dying cell, which has a nice side effect for the
presentation function anyway. Even better screen code match was found
for a new-born cell. Note that it is not desired to have new born
dots appear on the screen before the whole array is calculated. The
screen code $60 is represented on the screen as empty space, just as
the empty cell is represented by code $20, also resulting with an
empty space on the screen. For the computer algorithm these are 2
different codes (desirable feature). However for the user, there is
no change on the screen when the algorithm marks cells where a new
dot is born in the next generation. Thanks to that I avoided
necessity of performing double buffering and switching screen memory
banks. After next generation is calculated, quick routine converts
the died and new born screen codes to the empty and dot codes (fully
filled) and the next generation is again calculated in the endless
loop. The end-user presentation in effect is quite pleasant and
appears as a seamless generation after generation display.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Apparently the assembly routine
calculating the next generation of the colony was the most
challenging for me. The performance of the simulation depends on it
the most. I used direct GOL rules implementation with few tricks and
optimization techniques. The resulting binary image is under 4 kB in
size. Considering the amount of features packed, I consider this a
moderate achievement. Thanks to the speed of the machine language, I
achieved satisfactory performance without affecting the readability
of the code or necessity to use advanced colony encoding techniques.
Although it is my desire in the future to do just that and make the
code blazing fast, for now I will settle for 2 generations per second
speed as I need some more 6502 assembly language practice to achieve
better results in code.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Zero page indexing addressing mode and
various counters are used by the algorithm to cycle through screen
memory cells from left upper corner to right-lower corner of the
screen (YIND – column counter is used to iterate through cells in a
row and then ZPG vector is increased by 40 and YIND zeroed at the
beginning of each next row).</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Here is the routine which is the heart of the GOL simulation algorithm:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">; calculate the next generation </span><br />
<span style="font-family: Courier New, Courier, monospace;">; Theory of operation:</span><br />
<span style="font-family: Courier New, Courier, monospace;">; The screen memory is scanned from start to end.</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Each row is iterated with pointer ZPGA1 and index Y.</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Addressing mode (ZPGA1),Y is used. Register Y is</span><br />
<span style="font-family: Courier New, Courier, monospace;">; reloaded with column counter yind, which is incremented</span><br />
<span style="font-family: Courier New, Courier, monospace;">; accordingly at the end of the loop,</span><br />
<span style="font-family: Courier New, Courier, monospace;">; then ZPGA1 is increased by 40 at the start of the next row.</span><br />
<span style="font-family: Courier New, Courier, monospace;">; The number of neighbors is calculated for each cell.</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Depending on the # of neighbors, the cell is encoded</span><br />
<span style="font-family: Courier New, Courier, monospace;">; to either die (DCELL), be born (BCELL) or remain unchanged.</span><br />
<span style="font-family: Courier New, Courier, monospace;">; After this procedure, the 'disp' routine should be called</span><br />
<span style="font-family: Courier New, Courier, monospace;">; to convert died cells to empty spaces and born cells (BCELL)</span><br />
<span style="font-family: Courier New, Courier, monospace;">; to live cells (LCELL).</span><br />
<span style="font-family: Courier New, Courier, monospace;">next</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldx #0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> stx xind ; initialize row index</span><br />
<span style="font-family: Courier New, Courier, monospace;"> stx yind ; initialize column index</span><br />
<span style="font-family: Courier New, Courier, monospace;"> stx nbct ; initialize neighbor cells counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #<MSCR ; initialize ZPG address buffer</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta ZPGA1 ; and current cell address counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta smct</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #>MSCR</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta ZPGA1+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta smct+1</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl0 ; left neighbor check </span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl1 ; skip left neighbor check if column=0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> dey ; decrement ZPGA1 pointer (left side neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl00 ; jump to nl00</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl000 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl00 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yind</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl1 ; right neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cpy #MAXCOL ; if cell at the far right side</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl2 ; then skip right neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iny ; increment ZPGA1 pointer (right side neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl111</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl2 ; jump to nl2</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl111 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl2 ; north neighbors check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda xind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl4 ; skip north neighbors check if row=0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr sb40zpga1 ; subtract 40 from ZPGA1 (north neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl222</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl22 ; jump to nl22</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl222 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl22 ; north-west (NW) neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl3 ; skip NW neighbor check if column=0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> dey ; decrement ZPGA1 pointer (NW side neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl2220</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl220 ; jump to nl220</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl2220 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl220</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iny ; return ZPGA1 pointer to north neighbor's cell</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cpy #MAXCOL ; if cell at the far right side</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl33 ; then skip the right neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iny ; increment ZPGA1 (right side neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl333</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl33 ; jump to nl33</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl333 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl33</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr rldsm2zpga1 ; reload smct to ZPGA1</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl4 ; south neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda xind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #MAXROW ; if row at maximum,</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl6 ; skip south neighbors check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr add40zpga1 ; add 40 to ZPGA1 (now ZPGA1+Y -> south neighbor's cell)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl444</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl44 ; jump to nl44</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl444 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl44 ; south-west (SW) neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl5 ; skip SW neighbor check if column=0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> dey ; decrement ZPGA1 (SW side neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl4440</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl440 ; jump to nl440</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl4440 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl440</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iny ; return ZPGA1 pointer to south neighbor's cell</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl5</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cpy #MAXCOL ; if cell at the far right side</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl6 ; then skip the right neighbor check</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iny ; increment ZPGA1 (SE side neighbor)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load cell's value</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; if not a live cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl55</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL ; or not a 'died' cell (in this iteration)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl6 ; jump to nl6</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl55 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc nbct ; increment neighbors count </span><br />
<span style="font-family: Courier New, Courier, monospace;">nl6</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr rldsm2zpga1 ; reload smct to ZPGA1 (restore address of the row)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda yind ; store old column# before incrementing</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta yold ; for further calculations</span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc yind ; increment column#</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #(MAXCOL+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl66</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta yind</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr add40smct ; increment smct (point to the next row of cells)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc xind ; increment row#</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl66 ; now mark the cells to live/die/be born</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yold</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load current cell</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #LCELL ; check if a live one</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nl666</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #DCELL</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nl7 ; not a live one, jump to nl7</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl666 ; live cell, determine its fate</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda nbct ; load neighbors counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #0 ; if nbct<2, cell dies</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nldie</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nldie</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nlnext</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #3 ; if nbct==3, cell does not change</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nlnext ; if nbct>3, cell dies</span><br />
<span style="font-family: Courier New, Courier, monospace;">nldie</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #DCELL</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yold</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta (ZPGA1),y ; update cell with 'died' code</span><br />
<span style="font-family: Courier New, Courier, monospace;"> clc</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bcc nlnext ; prepare for next cell</span><br />
<span style="font-family: Courier New, Courier, monospace;">nl7 ; not a live cell, determine its fate</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda nbct ; load neighbors counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #3 ; only if nbct==3, a new one is born</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne nlnext</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #BCELL</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy yold</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta (ZPGA1),y ; update cell with 'born' status.</span><br />
<span style="font-family: Courier New, Courier, monospace;">nlnext</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda xind ; check if the end</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #(MAXROW+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq nlend ; yes, jump to nlend</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr rldsm2zpga1 ; reload smct to ZPGA1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #0 ; initialize neighbors counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta nbct</span><br />
<span style="font-family: Courier New, Courier, monospace;"> jmp nl0 ; do the next cell</span><br />
<span style="font-family: Courier New, Courier, monospace;">nlend</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"> rts</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Before saving, colony's editor screen is encoded into binary form (so each byte holds information about 8 cells) into buffer with this routine:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">; convert screen (editor's format) into binary format</span><br />
<span style="font-family: Courier New, Courier, monospace;">; store in colb buffer</span><br />
<span style="font-family: Courier New, Courier, monospace;">encodeed2colb</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #<MSCR</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta ZPGA1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #>MSCR</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta ZPGA1+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta gpct ; gpct - encoded byte</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta gpct+1 ; index to colb buffer (encoded colony)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #8</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta gpbyt ; gpbyt - bit counter</span><br />
<span style="font-family: Courier New, Courier, monospace;">ee2cloop000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldy #0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda (ZPGA1),y ; load byte from screen memory</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #'*' ; is it live cell?</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne ee2cloop002 ; no, branch to ee2cloop002</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda gpct ; load encoded byte to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldx gpbyt ; load bit counter to X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ora encodearr,x ; set the bit in Acc masked by encodearr,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta gpct ; store updated encoded byte</span><br />
<span style="font-family: Courier New, Courier, monospace;">ee2cloop002 </span><br />
<span style="font-family: Courier New, Courier, monospace;"> dec gpbyt ; decrement bit counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda gpbyt</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq ee2cloop001 ; if byte counter is 0, branch to ee2cloop001</span><br />
<span style="font-family: Courier New, Courier, monospace;">ee2cloop000a </span><br />
<span style="font-family: Courier New, Courier, monospace;"> jsr SystemZone.inczpga1 ; increment ZPG1 (screen memory)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda ZPGA1 ; check if end of screen memory</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #<MESCR</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bne ee2cloop000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda ZPGA1+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> cmp #>MESCR</span><br />
<span style="font-family: Courier New, Courier, monospace;"> beq ee2cfinished</span><br />
<span style="font-family: Courier New, Courier, monospace;"> clc</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bcc ee2cloop000 ; do next bit</span><br />
<span style="font-family: Courier New, Courier, monospace;">ee2cloop001 ; single byte encoding finished</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ldx gpct+1 ; load encoded colony buffer index</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda gpct ; load encoded byte</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta colb,x ; store byte in the encoded colony buffer</span><br />
<span style="font-family: Courier New, Courier, monospace;"> inc gpct+1 ; increment index to encoded colony buffer</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #8 ; reload bit counter</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta gpbyt</span><br />
<span style="font-family: Courier New, Courier, monospace;"> lda #0 ; reset encoded byte</span><br />
<span style="font-family: Courier New, Courier, monospace;"> sta gpct</span><br />
<span style="font-family: Courier New, Courier, monospace;"> clc</span><br />
<span style="font-family: Courier New, Courier, monospace;"> bcc ee2cloop000a ; do the next bit</span><br />
<span style="font-family: Courier New, Courier, monospace;">ee2cfinished</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"> rts</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Here is how the encoded binary format colony look like, this example is a built in demo colony:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">; shooter colony, binary encoded </span><br />
<span style="font-family: Courier New, Courier, monospace;">dcshootenc </span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> !byte 100 ; first byte is the number of encoded bytes that follow</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ; encoded colony</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B11000000,B00011000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000001,B01000000,B00011000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B01100000,B00110000,B00000001,B10000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B01100000,B01010000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B01100000,B01100000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B01010000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B01000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00001100</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00001010</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00001000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00000000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B01110000,B00000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B01000000,B00000000</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"> !text B00000000,B00000000,B00000000,B00100000,B00000000</span><br />
<div>
<br /></div>
<b><span style="font-family: Verdana, sans-serif;"><br /></span></b>
<b><span style="font-family: Verdana, sans-serif;">Features and presentation.</span></b></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">After the welcome screen, user presses
a key and the help screen is displayed showing keyboard shortcuts to
the functions of the program. Due to the presentation environment
being text based, that information is not present on the screen
during colony editing or simulation, therefore it is a good idea to
read and memorize this screen or print it before proceeding.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7x44o7vWb2G43ePG4FtnEpzlngyrWYIUQHGYoYxHA0yCPVWh69EF54jBGkbfbKNzDd0zORa0Lf-fm_PSTdtf_trfvKUOoU1F_4uhelszzSYhPBv1WRM2Id3D1Mrhh5K5gEonBD0Zo_W4/s1600/scr5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7x44o7vWb2G43ePG4FtnEpzlngyrWYIUQHGYoYxHA0yCPVWh69EF54jBGkbfbKNzDd0zORa0Lf-fm_PSTdtf_trfvKUOoU1F_4uhelszzSYhPBv1WRM2Id3D1Mrhh5K5gEonBD0Zo_W4/s1600/scr5.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life simulator
- help screen.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">In the next step, user is presented
with the program's start menu. Possible choices consist of two
template/demo colonies, ability to start with an empty editor or
editor filled with random colony. There is also a load from file
option available and option to terminate the application
(confirmation is required).</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwJ_9LmcrptdZlDgQY2GyFiLc2PJckWqnGA9OOK-mhLIJBB_qgvcnmTVlC4-fevolWGGnZiexerRC5uCmWaaDVc9ZLTqIhC6e0g5Fd_oGPPQ2pqOleqmew4KF__t9s08lZQOmksHxWSw8/s1600/scr6.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwJ_9LmcrptdZlDgQY2GyFiLc2PJckWqnGA9OOK-mhLIJBB_qgvcnmTVlC4-fevolWGGnZiexerRC5uCmWaaDVc9ZLTqIhC6e0g5Fd_oGPPQ2pqOleqmew4KF__t9s08lZQOmksHxWSw8/s1600/scr6.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - start
menu.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Depending on the user's choice, the
editor starts filled with the colony or empty. Editor encodes the
empty and life cells differently than the simulator. The empty cells
are represented by minus '-' signs, while the life cells are
represented with asterisks '*'. This approach has 2 advantages:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<ol>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">User can recognize immediately in
what mode the application is currently working (remember – there
is no extra text information, the whole screen is taken by colony
data presentation).</span></div>
</li>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The empty cells done with minus
sign present a grid which makes it easier for user to design/modify
the colony.</span></div>
</li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBvR3LZcHl-UqfAX5WCmqk9_TcofiNUZBF87i9LxXeWCQC15l2uKjPUx8fK8xfKwEF235B1jxLBHiX0bpzQJvQ8iJLymTs6A0Lby2Qejj9lfCVTVx4yRNNrvp94L9dWCFRKzIbLAmAGHk/s1600/scr7.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBvR3LZcHl-UqfAX5WCmqk9_TcofiNUZBF87i9LxXeWCQC15l2uKjPUx8fK8xfKwEF235B1jxLBHiX0bpzQJvQ8iJLymTs6A0Lby2Qejj9lfCVTVx4yRNNrvp94L9dWCFRKzIbLAmAGHk/s1600/scr7.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - editor
screen filled with random colony.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">In editor, user can position the cursor
(visible as a reverse color rectangle) using cursor keys on the
keyboard and alter the cell status with space key. Other possible
functions are 'H' to display help screen, 'C' to clear all the cells
(requires confirmation), 'R' to fill cells with random values
(requires confirmation) and 'Q' to exit the editor and start
simulation. At the exit, user is prompted to save the colony to file,
which can be skipped.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBlTOPLIQ3UXmIOqx6x5ubYKcHiCdHBv2vbZd3toCHRX-5fDQ3W9oZvbsIra-gV5x618KhVpRqZass1dHlim03GgzQpmsKRJtocIF7ICxlW_ExYWqpW2xRJW9pVRBCXdMbA1t8LFpUi7Y/s1600/scr8.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBlTOPLIQ3UXmIOqx6x5ubYKcHiCdHBv2vbZd3toCHRX-5fDQ3W9oZvbsIra-gV5x618KhVpRqZass1dHlim03GgzQpmsKRJtocIF7ICxlW_ExYWqpW2xRJW9pVRBCXdMbA1t8LFpUi7Y/s1600/scr8.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - exit
editor, save to file prompt.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">If user chooses to save the colony to
file, a prompt appears to enter the colony file name.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiig_vlehKqG-rLgYnAiMgA7UhxaDUcSqrjndrFt6wswa3I_QISn2Yw6m8o6jPZ42Y_lAmHNo9_qo7MkPGRHbJcBYk_vvEUZ4gxc_511GFS8GUg8LrmVULB-Sut5b2kVvjq_hCLssDqqxg/s1600/scr9.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiig_vlehKqG-rLgYnAiMgA7UhxaDUcSqrjndrFt6wswa3I_QISn2Yw6m8o6jPZ42Y_lAmHNo9_qo7MkPGRHbJcBYk_vvEUZ4gxc_511GFS8GUg8LrmVULB-Sut5b2kVvjq_hCLssDqqxg/s1600/scr9.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - save
colony, file name prompt.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The simple file name editor allows to
enter alpha-numeric string of up to 12 characters in length. User can
press DEL key to remove incorrectly entered characters. If the
entered file name is empty (RETURN key pressed with the cursor
positioned at the 1<sup>st</sup> character of the file name), the
Save operation is considered as canceled and program proceeds to
simulation. Otherwise, the program attempts to save the colony to
file. In case of I/O error, there is no action. Extension “.COL”
is added to the file name automatically.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Simulator starts in paused mode. User
can immediately see that program entered simulation mode because the
cells are now presented differently on the screen (Illustration
below).</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8S4TBLe3dwXDiDFPaShaZQH4gY7nYFVAGuusTPCCdlcKK_PuLOot7ZzVSsr72lVi2uz51_mjvaOONl7mQsJzT9o-pMc9S_zhlhTQ88wihIbOXNMxh1g8tp48ESJ-fJIRDDHTNqiVVQgg/s1600/scr10.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8S4TBLe3dwXDiDFPaShaZQH4gY7nYFVAGuusTPCCdlcKK_PuLOot7ZzVSsr72lVi2uz51_mjvaOONl7mQsJzT9o-pMc9S_zhlhTQ88wihIbOXNMxh1g8tp48ESJ-fJIRDDHTNqiVVQgg/s1600/scr10.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life – paused
simulator.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Pressing any key starts the simulation.
Please note the donut style cells (see Illustration below), which are
the cells marked to die in the next generation by the algorithm.
Newborn dots are not visible until the next generation is fully
created and the screen codes converted to the full dots or spaces
accordingly.</span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">(NOTE: on the screen shot below, not
all the cells that are supposed to die in the next generation are yet
marked like donut, because the screen shot captured the screen in the
middle of the process)</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht1XGTUT9w7VaVex3Ie-DeIEH2w18V_e8p-MvZNmakRbmOxrccIxmkVBElihmV3goIPugwEgiJgO9MTP3aDo5IE5h_9o_qsjMMlwSkYQXESpG8rG37zPV-alghvsDijxUmRlF3d_Jj-Ao/s1600/scr11.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht1XGTUT9w7VaVex3Ie-DeIEH2w18V_e8p-MvZNmakRbmOxrccIxmkVBElihmV3goIPugwEgiJgO9MTP3aDo5IE5h_9o_qsjMMlwSkYQXESpG8rG37zPV-alghvsDijxUmRlF3d_Jj-Ao/s1600/scr11.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - running
simulation.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">At any moment during simulation user
can choose to quit application (requires confirmation), pause it, go
to editor and alter/save the colony, display the help screen or go
back to start menu (requires confirmation) using the keyboard
shortcuts presented on the help screen at the program start up.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-Zt938YTRllfcdG0adkBT_FdWUkjgVZGIbQFKJEYr1ZT5U10hv-LVzyOVnoSTcWCRLBNtACLu0yn72ikdatGDb5B2YIKwnsIR7_DtBvr3017mOgGbCTyLsArrdiPNMxXfMbIg6f9FCyQ/s1600/scr12.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-Zt938YTRllfcdG0adkBT_FdWUkjgVZGIbQFKJEYr1ZT5U10hv-LVzyOVnoSTcWCRLBNtACLu0yn72ikdatGDb5B2YIKwnsIR7_DtBvr3017mOgGbCTyLsArrdiPNMxXfMbIg6f9FCyQ/s1600/scr12.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - quitting
the application.</i></span></div>
</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAYHaGVaHo0xEV4wGhVZF_rGLrSwGFCRqKZYK6gviHep0RTMJkHTaZUFlaPo3FuNDN0yxkR_5Gw2SfpAxATLm6puGUlQiUMbp68zlCxe2hSTinGu_kOXFrKdLQ1LQTKrx1Nh5iMLe4yew/s1600/scr13.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAYHaGVaHo0xEV4wGhVZF_rGLrSwGFCRqKZYK6gviHep0RTMJkHTaZUFlaPo3FuNDN0yxkR_5Gw2SfpAxATLm6puGUlQiUMbp68zlCxe2hSTinGu_kOXFrKdLQ1LQTKrx1Nh5iMLe4yew/s1600/scr13.jpg" height="524" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="margin-top: 0.08in;">
<span style="font-size: small;"><i>Game of Life - the fun
is over.</i></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Here is the <a href="https://skydrive.live.com/redir?resid=1134B9F29C36FE0B!106" target="_blank">link to source code.</a> Look for a ZIP archive named <i>ConwaysLife</i>.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Thank you for visiting.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Marek Karcz</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">9/15/2013.</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-49729880334959377972013-02-03T18:10:00.004-08:002013-02-03T18:10:51.789-08:00IRQ sprite clock for Commodore-64.<span style="font-family: Verdana, sans-serif;">Today I'd like to share with Commodore community this little piece I made back in the 1990-s - an IRQ sprite clock for Commodore-64.</span><br />
<br />
<br />
<span style="font-family: Verdana, sans-serif;">Clock works in IRQ interrupt. Presentation is made </span><span style="font-family: Verdana, sans-serif;">with sprites (clock digits are mapped to sprite </span><span style="font-family: Verdana, sans-serif;">objects and displayed on screen). It is possible </span><span style="font-family: Verdana, sans-serif;">to use C-64 while this clock works. Oddly enough, </span><span style="font-family: Verdana, sans-serif;">this clock seems to be interfering with I/O while </span><span style="font-family: Verdana, sans-serif;">running on real hardware (unable to use disk drive or </span><span style="font-family: Verdana, sans-serif;">tape, will hung) but works fine in emulator. </span><span style="font-family: Verdana, sans-serif;">If you find the bug, please let me know!</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<span style="font-family: Courier New, Courier, monospace;">; SPRITE IRQ CLOCK (C) Marek Karcz</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Code below compiles with CC65 assembler:</span><br />
<span style="font-family: Courier New, Courier, monospace;">; cl65 --verbose --listing spriteclock.asm</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Use HEX editor to insert "00 C0" at the beginning</span><br />
<span style="font-family: Courier New, Courier, monospace;">; of the executable to be able to run it on C64 or</span><br />
<span style="font-family: Courier New, Courier, monospace;">; in emulator.</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Usage:</span><br />
<span style="font-family: Courier New, Courier, monospace;">; LOAD"SPRITECLOCK",8,1</span><br />
<span style="font-family: Courier New, Courier, monospace;">; CLR:NEW</span><br />
<span style="font-family: Courier New, Courier, monospace;">; SYS49152,"HHMMSS"</span><br />
<span style="font-family: Courier New, Courier, monospace;">; Where:</span><br />
<span style="font-family: Courier New, Courier, monospace;">; HH - hours, MM - minutes, SS - seconds</span><br />
<span style="font-family: Courier New, Courier, monospace;">; To turn the clock off:</span><br />
<span style="font-family: Courier New, Courier, monospace;">; SYS49152</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">VIC = 53248 ;VIC Base</span><br />
<span style="font-family: Courier New, Courier, monospace;">WSKSP0 = 2040 ;PTR. SPRITE 0</span><br />
<span style="font-family: Courier New, Courier, monospace;">WSKSP1 = 2041 ;PTR. SPRITE 1</span><br />
<span style="font-family: Courier New, Courier, monospace;">WSKSP2 = 2042 ;PTR. SPRITE 2</span><br />
<span style="font-family: Courier New, Courier, monospace;">BLOK13 = 832 ;PTR. BEG. OF BLOCK 13</span><br />
<span style="font-family: Courier New, Courier, monospace;">BLOK14 = 896 ;PTR. BEG. OF BLOCK 14</span><br />
<span style="font-family: Courier New, Courier, monospace;">BLOK15 = 960 ;SEE ABOVE - BLOCK 15</span><br />
<span style="font-family: Courier New, Courier, monospace;">IRQWKT = 788 ;IRQ VECT.</span><br />
<span style="font-family: Courier New, Courier, monospace;">POBZNA = 121 ;READ CURR. BYTE</span><br />
<span style="font-family: Courier New, Courier, monospace;">PRZECT = $AEFD ;CHECK COMMA</span><br />
<span style="font-family: Courier New, Courier, monospace;">ANAWYR = 44446 ;PARSE EXPR.</span><br />
<span style="font-family: Courier New, Courier, monospace;">POBTXT = 46978 ;GET STRING</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> .ORG $C000</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> JMP STEROW</span><br />
<span style="font-family: Courier New, Courier, monospace;">LICZNIK: .BYTE 60 ;COUNTER</span><br />
<span style="font-family: Courier New, Courier, monospace;">WZORCE: .BYTE 2,3,5,9,5,9 ;TEMPLATES</span><br />
<span style="font-family: Courier New, Courier, monospace;">CZAS: .BYTE 1,2,0,0,0,0 ;TIME</span><br />
<span style="font-family: Courier New, Courier, monospace;">LICZPOZ: .BYTE 1 ;POS. COUNTER</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF0: .BYTE 0,252,204,204 ;DIGIT 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 204,204,204,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF1: .BYTE 0,12,12,12 ;DIGIT 1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 12,12,12,12</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF2: .BYTE 0,252,12,12 ;DIGIT 2, etc...</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 252,192,192,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF3: .BYTE 0,252,12,12</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 60,12,12,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF4: .BYTE 0,204,204,204</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 252,12,12,12</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF5: .BYTE 0,252,192,252</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 12,12,12,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF6: .BYTE 0,252,192,192</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 252,204,204,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF7: .BYTE 0,252,12,24</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 48,96,192,192</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF8: .BYTE 0,252,204,204</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 252,204,204,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">CYF9: .BYTE 0,252,204,204</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 252,12,12,252</span><br />
<span style="font-family: Courier New, Courier, monospace;">DWUKR: .BYTE 0,0,48,48 ;COLON</span><br />
<span style="font-family: Courier New, Courier, monospace;"> .BYTE 0,48,48,0</span><br />
<span style="font-family: Courier New, Courier, monospace;">COPY: LDX #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;">LOOP1: LDA CYF0,X</span><br />
<span style="font-family: Courier New, Courier, monospace;">BLKNR: STA BLOK13,Y</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CPX #7</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BEQ POZ</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INX</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP LOOP1</span><br />
<span style="font-family: Courier New, Courier, monospace;">POZ: RTS</span><br />
<span style="font-family: Courier New, Courier, monospace;">IRQROM: JMP $EA31</span><br />
<span style="font-family: Courier New, Courier, monospace;">MAIN: DEC LICZNIK</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE IRQROM</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #60</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA LICZNIK</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA CZAS</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CMP #2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BEQ NOC</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #9</span><br />
<span style="font-family: Courier New, Courier, monospace;">NOC: STX WZORCE+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #5</span><br />
<span style="font-family: Courier New, Courier, monospace;">NXTCYF: LDA CZAS,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INC CZAS,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CMP WZORCE,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE KOP1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA CZAS,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> DEX</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BPL NXTCYF</span><br />
<span style="font-family: Courier New, Courier, monospace;">KOP1: LDA #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA LICZPOZ</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CZAS</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CZAS</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX KOPIUJ+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY KOPIUJ+3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<BLOK13</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>BLOK13</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX POS0B+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY POS0C+1</span><br />
<span style="font-family: Courier New, Courier, monospace;">KOPIUJ: LDX #<CZAS</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CZAS</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX POS0+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY POS0+2</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS0: LDA CZAS</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CMP #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF0</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS0A: STX LOOP1+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY LOOP1+2</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS0B: LDX #<BLOK13</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS0C: LDY #>BLOK13</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX BLKNR+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY BLKNR+2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JSR COPY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS1</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE00: CMP #$01</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE01</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE01: CMP #$02</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE02</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE02: CMP #$03</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE03</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE03: CMP #$04</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE04</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF4</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF4</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE04: CMP #$05</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE05</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF5</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF5</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE05: CMP #$06</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE06</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF6</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF6</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE06: CMP #$07</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE07</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF7</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF7</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE07: CMP #$08</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE NIE08</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<CYF8</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF8</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">NIE08: LDX #<CYF9</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>CYF9</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS0A</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1: INC KOPIUJ+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA KOPIUJ+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CMP #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE POS1A</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INC KOPIUJ+3</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1A: INC LICZPOZ</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA LICZPOZ</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CMP #1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE POS1B</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<(BLOK13+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>(BLOK13+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1A1: STX POS0B+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY POS0C+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP KOPIUJ</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1B: CMP #2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE POS1C</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<BLOK14</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>BLOK14</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS1A1</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1C: CMP #3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE POS1D</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<(BLOK14+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>(BLOK14+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS1A1</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1D: CMP #4</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE POS1E</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<BLOK15</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>BLOK15</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS1A1</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1E: CMP #5</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE POS1F</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<(BLOK15+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>(BLOK15+1)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP POS1A1</span><br />
<span style="font-family: Courier New, Courier, monospace;">POS1F: JMP $EA31</span><br />
<span style="font-family: Courier New, Courier, monospace;">START: LDX #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;">STLOOP: STA BLOK13,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA BLOK14,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA BLOK15,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INX</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CPX #63</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BEQ ST1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP STLOOP</span><br />
<span style="font-family: Courier New, Courier, monospace;">ST1: LDX #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;">ST1LOOP: LDA DWUKR,X</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA BLOK13+2,Y</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA BLOK14+2,Y</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INX</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CPX #8</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BEQ ST2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP ST1LOOP</span><br />
<span style="font-family: Courier New, Courier, monospace;">ST2: LDX #13</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX WSKSP0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INX</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX WSKSP1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> INX</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX WSKSP2</span><br />
<span style="font-family: Courier New, Courier, monospace;">KOLOR: LDA #13</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+39</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+40</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+41</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #000110</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+16</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #215</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #50</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX VIC+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #7</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX VIC+3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ADC #48</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+4</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX VIC+5</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #000111</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+23</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+29</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+27</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+21</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDX #<MAIN</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #>MAIN</span><br />
<span style="font-family: Courier New, Courier, monospace;"> SEI</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX IRQWKT</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY IRQWKT+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CLI</span><br />
<span style="font-family: Courier New, Courier, monospace;"> RTS</span><br />
<span style="font-family: Courier New, Courier, monospace;">STEROW: JSR POBZNA</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BEQ WYLACZ</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JSR PRZECT</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JSR ANAWYR</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ROL 13</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BCS NASTAW</span><br />
<span style="font-family: Courier New, Courier, monospace;">ILLQUA: JMP 47000</span><br />
<span style="font-family: Courier New, Courier, monospace;">NASTAW: JSR POBTXT</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CMP #6</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BNE ILLQUA</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #5</span><br />
<span style="font-family: Courier New, Courier, monospace;"> SEI</span><br />
<span style="font-family: Courier New, Courier, monospace;">NASTPE: LDA (34),Y</span><br />
<span style="font-family: Courier New, Courier, monospace;"> SEC</span><br />
<span style="font-family: Courier New, Courier, monospace;"> SBC #48</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA CZAS,Y</span><br />
<span style="font-family: Courier New, Courier, monospace;"> DEY</span><br />
<span style="font-family: Courier New, Courier, monospace;"> BPL NASTPE</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #60</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA LICZNIK</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CLI</span><br />
<span style="font-family: Courier New, Courier, monospace;"> JMP START</span><br />
<span style="font-family: Courier New, Courier, monospace;">WYLACZ: LDX #$31</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDY #$EA</span><br />
<span style="font-family: Courier New, Courier, monospace;"> SEI</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STX IRQWKT</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STY IRQWKT+1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> CLI</span><br />
<span style="font-family: Courier New, Courier, monospace;"> LDA #$00</span><br />
<span style="font-family: Courier New, Courier, monospace;"> STA VIC+21</span><br />
<span style="font-family: Courier New, Courier, monospace;"> RTS</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Verdana, sans-serif;">In the next episode I will present a BASIC program that uses above clock to sound an alarm (sound and visual effects) at predefined time.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Thanks for reading.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Marek Karcz</span><br />
<span style="font-family: Verdana, sans-serif;">2/3/2013</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com2tag:blogger.com,1999:blog-2918813988661303224.post-24132002424993589512012-11-05T00:37:00.000-08:002012-11-05T00:37:08.547-08:00Super Forth 64 – dynamic load and execution of machine language object.<br />
<div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;"><b>Super
Forth 64 – dynamic load and execution of machine language object.</b></span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">I
struggled with some project for the past week and finally I figured
it out. Forth system is great to have huge dictionary of commands at
user's disposal, which all reside in memory and are as a result able
to load and execute fast. However it would be also nice to have
ability to load the ML code from disk to memory buffer, execute it
and return control to Forth. After all, you can not stuff everything
in 20+ kB of RAM.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">Super
Forth 64 has ability to do just that with dictionary definitions SYS
and SYSCALL:</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">SYS
(.A .X .Y ADDR --- .A .X .Y STATUS)</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">Above
word interfaces with ML subroutines which are external to FORTH
system (e.g: C64 KERNAL routines).</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">.A,
.X and .Y are values which will be loaded to corresponding MOS6510
registers prior to performing JSR to the routine at ADDR.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">Upon
return, CPU registers and status word will be put on parameter stack.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">The
called routine must end with RTS and the hardware stack must be left
in the same condition as when the routine was first called.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">SYSCALL
(.A .X .Y ADDR --- )</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;"> Alternative
to SYS, which does not return CPU registers and status on the
parameter stack.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">I
wanted my machine language object to be fully relocatable so FORTH
could load it to any memory location that was available, preferably
to predefined buffer. To achieve that, jumps to absolute address
locations within program can not be performed and the access to data
must be performed via zero page vector.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">The
design assumes that ML program contains at the beginning 3 bytes long unconditional branch jump to the main routine and between that jump
instruction and the code, data section is located. Byte #4 (index=3,
assuming byte #1 is at offset 0) in ML object contains zero page
address that ML program will use to access its data section. Starting
at byte #5 (index=4 from the beginning of the object) data section is
located.</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">I
used Turbo Assembler to write my ML demo program and save its object to
disk. It does not matter what the starting address is during
compilation, since program does not use absolute addresses to access
its own data and code. I assembled program to $C000, however it will be
loadable to any address:</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
MODULE: HELLOSF64 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
PURPOSE: THE DEMO OF RELOCATEABLE ML </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
PROGRAM RUNNING IN SUPER </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
FORTH 64 ENVIRONMENT. </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
DATE: 11/05/2012 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
AUTHOR: MAREK KARCZ </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">ZPGl = $02 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">CHROUT
= $FFD2 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> *= $C000</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> CLC
</span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> BCC
MAIN </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
ZERO PAGE POINTER, TO BE READ BY SF64 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
CALLING ROUTINE TO DETERMINE WHERE TO </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
PUT DATA SECTION ADDRESS. </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
CALCULATED AT RUNTIME BY ADDING 3 TO </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
THE PROGRAM LOAD ADDRESS. </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">ZPGPTR</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> .BYTE
ZPG1</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
DATA SECTION, CALCULATED BY ADDING 4 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">;
TO THE PROGRAM LOAD ADDRESS.</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">DATA</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> .BYTE
$0D</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> .TEXT
"HELLO FORTH!" </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> .BYTE
$0D,$00 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> .TEXT
"GOODBYE FORTH!" </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> .BYTE
$0D,$FF </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">MAIN</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> LDY
#0</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">LOOP</span></span></div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> LDA
(ZPG1), Y </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> BEQ
TX2 </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> CMP
#$FF </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> BEQ
END </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> JSR
CHROUT </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">TX2
</span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> INY
</span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> BNE
LOOP </span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;">END
</span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<span style="font-family: Courier New;"><span style="font-size: medium;"> RTS
</span></span>
</div>
<div lang="en-US" style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">As
mentioned before, the first byte after branch jump contains zero page
address (ZPGPTR). This is information for Super Forth's run time where ML
program will read its data section vector from. It is important
because Super Forth's routine calling the ML object code will have to
save and then restore values at that memory location, otherwise SF64
will crash. </span></span>
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">Now
we need to define framework in SF64 supporting dynamic ML load and
execution and then return to SF64 interpreter. We will need buffer for code (MLBUF), a function that
loads the ML object from disk to the buffer (LOAD-ML) and function
that executes the code (EXEC-ML). The EXEC-ML function saves values
at zero page location that will be used by ML program as a data
vector, then loads to that location the calculated data section of
the ML program thus creating the actual data section vector for a ML
program. Then the function executes ML code and upon return restores
zero page address to its former values. Below is the FORTH code:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirS76tqcQOLjHHZnznpADC5jBs6EZ46Pm3YDXvdlIm5V8S3HgpJijmUYvrvpvMtoINRXE9t37znVXWIkwZdBnO5T7DwVm_GW-dXNTw3XmrqsI2Lf2bgLlCYJqFpXECMT_yUgb2EgK972I/s1600/sf64execml.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirS76tqcQOLjHHZnznpADC5jBs6EZ46Pm3YDXvdlIm5V8S3HgpJijmUYvrvpvMtoINRXE9t37znVXWIkwZdBnO5T7DwVm_GW-dXNTw3XmrqsI2Lf2bgLlCYJqFpXECMT_yUgb2EgK972I/s640/sf64execml.bmp" width="412" /></a></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;">Load above definitions with:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">1
LOAD</span></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: large;">Please see screenshots below from Turbo Assembler and
SF64 sessions testing the concept:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_bkPoZC0QVKQQFTI_iPgNx1it6OzSvek-bmNWGm4YFOYYZQiS6VDYAMoj8l3cIJwSPPpxNAQOPVCafjZuWsGkBnC3mDZoFSfA5O85Db1W0XBAaw6okZf3MRTp4MeNJuxkbUXWTwLkRWk/s1600/img_1076.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_bkPoZC0QVKQQFTI_iPgNx1it6OzSvek-bmNWGm4YFOYYZQiS6VDYAMoj8l3cIJwSPPpxNAQOPVCafjZuWsGkBnC3mDZoFSfA5O85Db1W0XBAaw6okZf3MRTp4MeNJuxkbUXWTwLkRWk/s640/img_1076.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Turbo Assembler - program code edit.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAw8bbvlPOJQhTXOAfgQgOyCJRiCZIqZ34lVECzbwMzrBFZ2zvzC6Y_mktcGCHFr0K4hUH0-umQwoMmNz11D2IdJQ6W5cW7DIbT6AFhmb6ez55mMnPw0-Kdzh0B9DL2a7GPVKZkdu1oMw/s1600/img_1075.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAw8bbvlPOJQhTXOAfgQgOyCJRiCZIqZ34lVECzbwMzrBFZ2zvzC6Y_mktcGCHFr0K4hUH0-umQwoMmNz11D2IdJQ6W5cW7DIbT6AFhmb6ez55mMnPw0-Kdzh0B9DL2a7GPVKZkdu1oMw/s640/img_1075.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Code assembled to disk file.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1C2HWsATMHhHkVEBPrffkVvRnqOAvvVeXd2ET0h8ddB0fZqLFabEBWBVYxeFDOJU6y9NKePK5ZDosN7EtG8oCDToBEhmZjqMwFVd53ld9q9QnsV3rxyY17dS8sFcJ0pGB4_-J7ZrrC1c/s1600/img_1077.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1C2HWsATMHhHkVEBPrffkVvRnqOAvvVeXd2ET0h8ddB0fZqLFabEBWBVYxeFDOJU6y9NKePK5ZDosN7EtG8oCDToBEhmZjqMwFVd53ld9q9QnsV3rxyY17dS8sFcJ0pGB4_-J7ZrrC1c/s640/img_1077.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">FORTH code loaded.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDchYMQMSeFocAzgdgqe2mhzQQfuKGI-Yojr_0Ptq9etni_kw1H9rVE3f1rxtKsVQEZMprcb5Fc77H6r9v4taqEPYGcLiAE0jsJ2QIFDWh55xd1OFvp7zSUbkzk7qnqSStlZvV0honf2I/s1600/img_1078.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDchYMQMSeFocAzgdgqe2mhzQQfuKGI-Yojr_0Ptq9etni_kw1H9rVE3f1rxtKsVQEZMprcb5Fc77H6r9v4taqEPYGcLiAE0jsJ2QIFDWh55xd1OFvp7zSUbkzk7qnqSStlZvV0honf2I/s640/img_1078.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">ML code buffer properly initialized.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixmo3y81Qt66dVSNxj7UmAkZotFVohyphenhyphenHJA9kcjfphNgw8FHXJwR9PZxAqBwTjF4VvBuMy7ov7de_0JFEbHIEycWdq-v2gThHSONWq6RcKa9IA3UlKImgGZOGr4eV9m2aBcgq-UWF4tc1U/s1600/img_1080.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixmo3y81Qt66dVSNxj7UmAkZotFVohyphenhyphenHJA9kcjfphNgw8FHXJwR9PZxAqBwTjF4VvBuMy7ov7de_0JFEbHIEycWdq-v2gThHSONWq6RcKa9IA3UlKImgGZOGr4eV9m2aBcgq-UWF4tc1U/s640/img_1080.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Switch to disk #9 where ML object resides.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifgI5mEpf32_d-lxfnToxluu5GpjymF_17RRcJBqiv5tEwzCpaVicMuQxcXmr0eyW876MNtyQ_1CXZNnTpIzxucAtcQ1FQST_VEE4R7NTsuJnVNSPduKSOLZ5hOqraa1Jjy_Y2fUcRFNQ/s1600/img_1081.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifgI5mEpf32_d-lxfnToxluu5GpjymF_17RRcJBqiv5tEwzCpaVicMuQxcXmr0eyW876MNtyQ_1CXZNnTpIzxucAtcQ1FQST_VEE4R7NTsuJnVNSPduKSOLZ5hOqraa1Jjy_Y2fUcRFNQ/s640/img_1081.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">ML object loaded and MLBUF dumped for verification.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdBx-kbXZtPU6JvIg7C95FDF8PdZO8SN8Q2BHJYCsiywxqPUd5qqEufB-0cxHJ9xcamRptEDJOi2fNb0mjMtWe2gSYFKyMecJgIoejbc3SAW-Hw2bEj-l20lK8fxrpb8zGUvBY8YnFJ7k/s1600/img_1082.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdBx-kbXZtPU6JvIg7C95FDF8PdZO8SN8Q2BHJYCsiywxqPUd5qqEufB-0cxHJ9xcamRptEDJOi2fNb0mjMtWe2gSYFKyMecJgIoejbc3SAW-Hw2bEj-l20lK8fxrpb8zGUvBY8YnFJ7k/s640/img_1082.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">...and execute - Success!</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;">Both functions (loading and executing) can be of course combined into one. Also, the ML object name prompt can be replaced with reading file name from standard stream used by FORTH. Anyway, concept is proven to work and after refinement can be a valuable tool while working in FORTH's environment.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;">Thanks for visiting my blog.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;">Marek Karcz</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: large;">11/5/2012</span></div>
<br />
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com2tag:blogger.com,1999:blog-2918813988661303224.post-47085319124996964892012-10-30T00:09:00.000-07:002012-10-30T00:09:08.578-07:00Super Forth 64 - RS 232 console.<br />
<span style="font-family: Verdana, sans-serif; font-size: large;">Today I managed to connect to my C64 running Super Forth 64 from a PC computer via RS-232 with Hyper Terminal program.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: large;">To do so, first we need to open logical file to user port's RS-232:</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: large;">10 2 10 " {CTRL-H}" OPEN</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><i>NOTE: CTRL-H represents code CHR$(8) which sets the speed of RS-232 interface to 1200 baud. To connect with 300 baud, use CTRL-F (CHR$(6)).</i></span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: large;">Assuming that PC computer is connected to C64's user port via RS-232's COM1 and that C64's user port is equipped with appropriate interface, </span><span style="font-family: Verdana, sans-serif; font-size: large;">on the PC side, open Hyper Terminal session to COM1 at 1200 baud 8N1.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: large;">After opening logical file, we need to redirect I/O to that file. On the C64 side type:</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: large;">10 OUTLFN !</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: large;">10 INPLFN !</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><i>NOTE: After output redirection (typing in 1st line above and pressing Return), C64 console will no longer show output. Instead it now should appear on the Hyper Terminal's screen. After entering 2nd line, enable CAPS-LOCK on the PC and perform all FORTH session interaction from Hyper Terminal (HT) from now on.</i></span><span style="font-family: Verdana, sans-serif; font-size: large;"> </span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: large;">Commodore 64 is now a Super Forth 64 host, and PC with HT is a client session. Not all operations are possible via such session. E.g: user will be unable to use screen editing facility. Also, character codes are not fully compatible between PC and C64, so all C64 responses will be in capital letters. If there is any text using mixed caps coming from C64, the letters that'd be visible as capital letters on C64 will not come right on the HT side. </span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinFbC5Y1KVPFVpUeNxYqYF566TYZEKctlca9wsjUtRifX9FGDFNqo8vYVQFGgwj_vFreq_IXa8hOprUtssqjxO4eJNZE4Wd3oEwQzhrLuwKRterZf_d0pDcKBydV-DqFGRVcbmycj-Qz0/s1600/IMG_1028.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinFbC5Y1KVPFVpUeNxYqYF566TYZEKctlca9wsjUtRifX9FGDFNqo8vYVQFGgwj_vFreq_IXa8hOprUtssqjxO4eJNZE4Wd3oEwQzhrLuwKRterZf_d0pDcKBydV-DqFGRVcbmycj-Qz0/s640/IMG_1028.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: large;">C64 screen after redirection to RS-232 just sits quietly while interaction is performed from HT on a PC.<br /></span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh__QpiqpFWWf8pNeCtGVWZ3C9fWq7Pu6AWbAt4uRReGb5Dta1Qg9zaBxlNUxXk_VnR4ku7nryu7cd1l9MKXzK1I4CqNvBE2iw5QKAzjQFuMeuFYKHMY9wFc_-vPXZ-6aoe75oPPV9Pt_I/s1600/IMG_1030.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh__QpiqpFWWf8pNeCtGVWZ3C9fWq7Pu6AWbAt4uRReGb5Dta1Qg9zaBxlNUxXk_VnR4ku7nryu7cd1l9MKXzK1I4CqNvBE2iw5QKAzjQFuMeuFYKHMY9wFc_-vPXZ-6aoe75oPPV9Pt_I/s640/IMG_1030.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: large;">HT/PC side.</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: large;">Thanks for visiting my blog.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: large;">Marek Karcz</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;">10/30/2012</span><br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-79851192830394780732012-10-21T22:07:00.001-07:002012-10-22T05:47:49.936-07:00Super Forth 64 - interrupt driven screen clock.<br />
<div align="CENTER" style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Programming
routines running in interrupts can be tricky under FORTH. In this
article I describe the design and code of 12-hour text mode screen
clock running in interrupt. The system of my choice was Super Forth
64 by Elliot B. Schneider. That was the first FORTH system I have had
experience with and I think it is a good choice to develop
applications and operating systems on C64 because of the powerful
extensions that SF-64 offers. In particular a very well defined
assembler vocabulary as well as C64 specific hardware support
(graphics, sprites and sound).</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<ol>
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Interrupt
driven code.</span></span></div>
</li>
</ol>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"> The
tight time constraints of interrupt handler make the assembler an
easy choice language for this kind of task. The single “frame” of
the clock routine must complete within 1/60 of a second. FORTH is
fast, however still an interpreted language. Therefore I decided to
code IRQ handler using Super Forth's assembler vocabulary. Before I coded the clock, I needed
some helper definitions and variables. To minimize code size and
maximize speed, I decided to use an array of clock digits, hard coded
in a 120 bytes long vector, that would hold an array of strings:
“00”, “01”, “02” … “58”, “59”.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">The
strings representing current hours, minutes and seconds would be then
selected from the table by indexing with clock counters.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">FORTH
DEFINITIONS</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">:
VECTOR ( n --- ADDR )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> CREATE
ALLOT</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> DOES>
+</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">59953
CONSTANT IRQROM ( ADDRESS OF STANDARD IRQ IN ROM )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">2
VECTOR IRQCLKPTR ( POINTER TO CLOCK ROUTINE – NEW ORQ ADDRESS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">2
VECTOR IRQROMPTR ( POINTER TO STANDARD IRQ IN ROM )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">IRQROM
0 IRQROMPTR ! ( SET POINTER TO ROM IRQ )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">120
VECTOR GMS ( VECTOR WITH CLOCK “DIGITS” )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">48
0 GMS ! ( SET “00” )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">48
1 GMS !</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">48
2 GMS ! ( SET “01” )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">49
3 GMS !</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">48
4 GMS ! ( SET “02” )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">50
5 GMS !</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">(NOTE:
continue initialization of GMS vector until “59”)</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">53
116 GMS ! ( SET “58” )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">56
117 GMS !</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">53
118 GMS ! ( SET “59” )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">57
119 GMS !</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">VARIABLE
LICNIK ( COUNTER, SORRY - I AM POLISH :-) )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">VARIABLE
GODZINA ( HOURS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">VARIABLE
MINUTA ( MINUTES )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">VARIABLE
SEKUNDA ( SECONDS )</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">(
INITIALIZE VARIABLES )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">0
LICNIK !</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">2
GODZINA !</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">0
SEKUNDA !</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">OK,
I am done with helper vectors and variables. Now there is time to
write some code.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">In
SF-64 system the assembler routine starts with the word CODE followed
by the name of the routine. The assembler dictionary in SF-64 is
quite sophisticated. Thanks to the general dictionary based
architecture, the labels used in traditional assembler code are not
needed here. We have branch structures (IF, THEN,) as well as loop
control words that allow to write structurally looking code without
the need for jumps and labels. In a way, the SF-64 assembler is like
a macro turbo-assembler that compiles the code as user types it or as
it is being read from the input stream.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">My
interrupt driven clock routine is presented below:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">CODE
IRQCLOCK</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> (
UPDATE COUNTERS, CALLED EVERY 1/60 OF SECOND )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> LICNIK
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> LICNIK
LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 60
# CMP,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0=</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> IF,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
# LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> LICNIK
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEKUNDA
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEKUNDA
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEKUNDA
LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 120
# CMP,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0=</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> IF,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
# LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEKUNDA
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> MINUTA
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> MINUTA
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> MINUTA
LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 120
# CMP,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0=</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> IF,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
# LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> MINUTA
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> GODZINA
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> GODZINA
INC,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> GODZINA
LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 26
# CMP,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0=</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> IF,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 2
# LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> GODZINA
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> THEN,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> THEN,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> THEN,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> THEN,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> (
UPDATING COUNTERS DONE, NOW PRESENTATION )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> GODZINA
LDX, ( USE GODZINA AS INDEX IN GMS VECTOR )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
GMS ,X LDA, ( LOAD DIGITS FOR CURRENT HOUR )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1056
STA, ( POKE DIRECTLY TO SCREEN MEMORY )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> INX,
( IN THE HOURS FIELD )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
GMS ,X LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1057
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 58
# LDA, ( TAKE COLON CHARACTER CODE ':' )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1058
STA, ( POKE TO THE SCREEN MEMORY, NOW – HH:_____ )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> MINUTA
LDX, ( REPEAT PROCEDURE FOR MINUTES )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
GMS ,X LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1059
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> INX,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
GMS ,X LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1060
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 58
# LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1061
STA, ( NOW ON SCREEN – HH:MM:__ )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEKUNDA
LDX, ( … AND FOR SECONDS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
GMS ,X LDA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1062
STA,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> INX,</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 0
GMS ,X LDA, ( PRESENTATION UPDATE COMPLETE )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1063
STA, ( NOW ON SCREEN (NORTH-EAST) – HH:MM:SS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> IRQROM
JMP ( CONTINUE TO ROM IRQ HANDLING ROUTINE )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">END-CODE</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">(
SETUP THE NEW IRQ POINTER TO OUR CLOCK ROUTINE )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">FIND
IRQCLOCK @ 0 IRQCLKPTR !</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Now
we need a word defined that would allow to set a new IRQ vector. </span></span><br />
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span>
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Remember the algorithm?</span></span><br />
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span>
<br />
<ul>
<li><span style="font-family: Verdana, sans-serif; font-size: medium;">Mask interrupts (disable). </span></li>
<li><span style="font-family: Verdana, sans-serif; font-size: medium;">Set new IRQ
vector.</span></li>
<li><span style="font-family: Verdana, sans-serif; font-size: medium;">Unmask interrupts (enable).</span></li>
</ul>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">CODE
SET-NEWIRQ ( LO HI --- )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEI,
( MASK INTERRUPTS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> BOT
LDA, ( READ BOTTOM OF STACK WHERE LO BYTE IS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 788
STA, ( PUT IN THE C64'S IRQ VECTOR - LO )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SEC
LDA, ( READ NEXT STACK BYTE WHERE HI BYTE IS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 789
STA, ( PUT IN THE C64'S IRQ VECTOR – HI )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> CLI,
( UNMASK INTERRUPTS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> NEXT
JMP, ( CONTINUE TO THE NEXT FORTH WORD IN QUEUE )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">END-CODE</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<ol start="2">
<li><div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Control
routines.</span></span></div>
</li>
</ol>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"> Now
that I am done with low level code, time to define words that would
allow the user to set the clock and turn it on and off. This is the
easy part:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">FORTH
DEFINITIONS</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">:
SET-IRQCLOCK</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SP!
CR</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> .”
HOURS (1-12)? “ INPUT 2 * GODZINA ! CR</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> .”
MINUTES (0-59)? “ INPUT 2 * MINUTA ! CR</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> .”
SECONDS (0-59)? “ INPUT 2 * SEKUNDA ! CR</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> .”
CLOCK IS SET “ CR SP</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">;</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">:
IRQCLOCK-ON</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SET-IRQCLOCK</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> (
LEAVE ON STACK HI/LO BYTES OF NEW IRQ ADDRESS )</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> 1
IRQCLKPTR C@ 0 IRQCLKPTR C@</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SET-NEWIRQ</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">;</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">:
IRQCLOCK-OFF</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> (
LEAVE ON STACK HI/LO BYTES OF ROM IRQ ADDRESS )<br /> 1 IRQROMPTR C@ 0
IRQROMPTR C@</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;"> SET-NEWIRQ</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: medium;">;</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">This
is pretty much it. It is amazing how efficient programming in
FORTH can be. I love it.</span></span><br />
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span>
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">And now some screens for non-believers :-)</span></span><br />
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAizHaZc3ZGs6UVesY5sCjQgIUaXobXcMuBbaCimbys4kzoOKYPWMJSwnn1Jl0-8F1MH-s99tCDQ1US80cnIs-GNr8Rswi-Mpr2qZTu-0FhHSCuT98tvjImy77kHjWcVwi3b9Zjg3tEaM/s1600/img_1024.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAizHaZc3ZGs6UVesY5sCjQgIUaXobXcMuBbaCimbys4kzoOKYPWMJSwnn1Jl0-8F1MH-s99tCDQ1US80cnIs-GNr8Rswi-Mpr2qZTu-0FhHSCuT98tvjImy77kHjWcVwi3b9Zjg3tEaM/s640/img_1024.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: large;">Code finished loading/compiling.</span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5HkOOAN2P4rBa53LtgxwSMMNRA9nHpEEfG6bT4hIDo-x0cRJ90c2E_nccYNzM4869U3tzfsZYkLfeIfk2sq5pyp8LTzWgHKmaZXLdcfPYYiRRbO5TpwTM8Z-Q6ecu9nMjpNS04TRlsqE/s1600/img_1025.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5HkOOAN2P4rBa53LtgxwSMMNRA9nHpEEfG6bT4hIDo-x0cRJ90c2E_nccYNzM4869U3tzfsZYkLfeIfk2sq5pyp8LTzWgHKmaZXLdcfPYYiRRbO5TpwTM8Z-Q6ecu9nMjpNS04TRlsqE/s640/img_1025.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: large;">Setting up the clock.</span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWSdAMqZqRegn7vKE1cefYxrm9hC7Jl5OHzYsx97iwVTXSKllaDFwYx7tICSp_DVGWpJnkLu8lBgHGVY_CFl-CYDUlJHNcQeLuAQTiDSO-DKtOV0nsW_5746eZPcJXW0FxPL5_86mUIho/s1600/img_1026.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWSdAMqZqRegn7vKE1cefYxrm9hC7Jl5OHzYsx97iwVTXSKllaDFwYx7tICSp_DVGWpJnkLu8lBgHGVY_CFl-CYDUlJHNcQeLuAQTiDSO-DKtOV0nsW_5746eZPcJXW0FxPL5_86mUIho/s640/img_1026.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: large;">Clock is running (upper right corner).</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Thank you for reading.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">Marek
Karcz</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: medium;">10/22/2012</span></span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-50772959703615259582012-10-16T17:01:00.000-07:002013-05-27T07:41:05.339-07:00CP/M on a C64 - fun and learning.<br />
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Hello
again.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">What
I learned so far about CP/M for C64 by practical application:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<ol>
<li value="1"><div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Commodore
64 will not support 2 disk drives (unless you patch it with simple
BASIC program, which updates CP/M disk for 2 drive support).</span></span></div>
</li>
</ol>
<div style="margin-bottom: 0in;">
<br /></div>
<ol>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Even
though bios configuration program seems to have the option to switch
between 1 and 2 disk drives mode, when I switched to 2 drives mode,
saved the configuration on disk and re-booted with 2 disk drives
connected to my C64, attempts to switch to drive B: ended in BDOS
error. My 2<sup>nd</sup> drive is 1571, however AFAIK, it works by
default in 1541 mode unless explicitly reprogrammed to use extra
features.</span></span></div>
</ol>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"> There
is a remedy though. With the help of a BASIC program found here: <a href="http://www.z80.eu/c64.html">URL</a>,
I patched CP/M disk so that C64 now is able to support 2 disk drives
under CP/M.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">You
need to type in the BASIC program, save it on the disk (but not a
CP/M disk, just your regular C64 storage for backup purposes) and
then switch the disk for a CP/M one into drive 8 and run the BASIC
program you just entered. Next time you need to patch up a CP/M disk,
load that program from your backup, switch disk for a CP/M one and
run the program again. After booting up CP/M, run your CONFIG.COM
program to change the number of drives to 2 and save the current I/O
setup to disk (option #6), then exit to CP/M (option #7), insert
valid CP/M disk to drive B: (9) and test the functionality:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">A>
dir B:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjefKOTuCJo1v0DQrFVYEzFt5FGQT_9dVLtyz5qugNPlVIP7GjbVNTNivZuUc35PYanX8T65Hgc-bYkM4Fi4ojNM17oD6Z3EV1N15tgpTett2xrfQInlgVAyGDStXNBb8JdQ97mYvxT5BY/s1600/img_1014.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjefKOTuCJo1v0DQrFVYEzFt5FGQT_9dVLtyz5qugNPlVIP7GjbVNTNivZuUc35PYanX8T65Hgc-bYkM4Fi4ojNM17oD6Z3EV1N15tgpTett2xrfQInlgVAyGDStXNBb8JdQ97mYvxT5BY/s640/img_1014.jpg" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Config program.</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFJG4E7yqCL2PwEI4nzbmLvt4nbl_BEOjspHAThoh4qddXivoOsF0qWoWcl4zXTlmDRniX_NOxW8_MHOT1nxvH6lmxiz2yj81MYFbP6IMAaf9xKc-nkmwMym3RsbYb0S3D7Bt5CNC-ScE/s1600/img_1013.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFJG4E7yqCL2PwEI4nzbmLvt4nbl_BEOjspHAThoh4qddXivoOsF0qWoWcl4zXTlmDRniX_NOxW8_MHOT1nxvH6lmxiz2yj81MYFbP6IMAaf9xKc-nkmwMym3RsbYb0S3D7Bt5CNC-ScE/s640/img_1013.jpg" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Checking disk B: stats</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<br /></div>
<ol start="2">
<li value="2"><div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Changing
the diskette in drive.</span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Changing
the diskette in drive without warm restart (CTRL-C or RUN-STOP) will
switch that disk to R/O mode. User will be unable to make
modifications to that drive until next warm restart. With that in
mind, the disk in drive must be always CP/M type with c64boot
procedure on track 1, sector 5.</span></span></div>
</li>
</ol>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">OK,
enough learning. Now there is time for some fun.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">What
would be a computer without a game? Just a piece of junk, I say!
Fortunately, many popular games were ported to CP/M platform. Most of
them are text mode based games, due to nature of CP/M (no built in
graphical support, generally incompatible across hardware platforms).
However it does not matter much, because in the CP/M era, many
popular games were text based. Good examples are Infocom's adventures
or a famous StarTrek game (originally written in BASIC AFAIK).</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">I
successfully created C64 CP/M ZORK1 and ZORK2 game disks (google up "ctools by Jochen Metzinger" for transferring programs to C64/C128 CP/M disk images, can also create Commodore format CP/M blank disks - an awesome tool). Even though
they were designed to work with 80 column mode, since there is no
fixed ASCII art or elaborate ASCII screens that depend on fixed size,
similar to famous Star Trek game, the ZORK adventures are perfectly
playable on C64 under CP/M. I know there is no point of playing them
under CP/M, since they were released for native C64, but it is not
the point of this exercise.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">I
have been unable to run Star Trek game though. All the files fit on
one disk (MBASIC.COM, STARTREK.BAS, TREKINST.BAS), however C64 leaves
insufficient memory for MBASIC.COM to load STARTREK.BAS. </span></span>
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsvGQdgQbXpGygKtN4mG-JpEvQ1r7R1xlbd_aIkhTxnaAfqSuITI4963TEgirk4tpYhZasE7Dh2iaAal8XEFXbxLgE42imWbiPje3TLd7I9YwxEteTac_wXBuE7q01cOT5vFieYYKgKGw/s1600/img_1012.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsvGQdgQbXpGygKtN4mG-JpEvQ1r7R1xlbd_aIkhTxnaAfqSuITI4963TEgirk4tpYhZasE7Dh2iaAal8XEFXbxLgE42imWbiPje3TLd7I9YwxEteTac_wXBuE7q01cOT5vFieYYKgKGw/s640/img_1012.jpg" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Zork1 game.</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj15a8_yxR70rTgeCKDhOmaf4yht7oZorxiKJT7rGbn_LP9WHTgX4hhVFJIyy99pg5zg_PJkweD7sIAN9zeRlnH7E8PpcuCjjUDFTnvvqdFZyEvZvavXK52pQqFCWm6K7eMSv4o45BmXKE/s1600/img_1011.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj15a8_yxR70rTgeCKDhOmaf4yht7oZorxiKJT7rGbn_LP9WHTgX4hhVFJIyy99pg5zg_PJkweD7sIAN9zeRlnH7E8PpcuCjjUDFTnvvqdFZyEvZvavXK52pQqFCWm6K7eMSv4o45BmXKE/s640/img_1011.jpg" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Zork2 game.</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">So
far I have a very positive experience with CP/M for C64.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">In
the next episode: 80 column display emulation and perhaps some more
programming examples.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Cheers!</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Marek</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">10/16/2012</span></span></div>
<br />Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com1tag:blogger.com,1999:blog-2918813988661303224.post-54882705906674953882012-10-14T11:59:00.000-07:002013-06-08T10:08:37.539-07:00CP/M on a C64 - Hello World<br />
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: 'Lucida Sans Unicode', sans-serif; font-size: medium;">I think a good old “Hello World!”
application is in order now in our quest of CP/M exploration.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Since
I don't know the Z80 assembler (yet) nor the structure of the
assembly program for CP/M I again turn to the internet for rescue.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">I
found one very good comprehensive explanation of how to use assembler
compiler 'ASM' under CP/M system and an example of “Hello World!”
application written in 8080 CPU assembly (which BTW is a subset of
Z80's assembly). Here is the </span></span><span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><a href="http://www.shaels.net/index.php/cpm80-22-documents/using-cpm/9-asm-utility" name="CP/M ASM and "Hello World!" example."><span style="color: red;">URL</span></a>.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">So,
in short – to compile assembler code, saved on the disk under name
HELLO2.ASM (I prepared that one with the CP/M's line editor: ED), you invoke CP/M command:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">A>
ASM HELO2</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi54dQbIVJXHExPTD3r5bbl1EJt-y1AM0jPORgIHmMM8bLcIURbRsfbk_XdPFYOrM9g2bzBJ2d8kdCpq260RtPAZvwMJI3fpAGbgdgAau4wunltszpJHnUARxOfqlhoSkDGMd0WXojWajU/s1600/sany0004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi54dQbIVJXHExPTD3r5bbl1EJt-y1AM0jPORgIHmMM8bLcIURbRsfbk_XdPFYOrM9g2bzBJ2d8kdCpq260RtPAZvwMJI3fpAGbgdgAau4wunltszpJHnUARxOfqlhoSkDGMd0WXojWajU/s640/sany0004.jpg" height="360" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8WHyp2eqimOtFS4oQzOrYO2XIrLFC1T27NvxCbj24hDcV0xH7NCTeviVy6qn7yYNqv0KWWtTKL2k-Q2dg3t0lqBb87VfTRKA7_ZZP0Qqdj5lkh-fDhsoQ5rivHORlM2-JJlgjqm0xfhw/s1600/sany0005.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8WHyp2eqimOtFS4oQzOrYO2XIrLFC1T27NvxCbj24hDcV0xH7NCTeviVy6qn7yYNqv0KWWtTKL2k-Q2dg3t0lqBb87VfTRKA7_ZZP0Qqdj5lkh-fDhsoQ5rivHORlM2-JJlgjqm0xfhw/s640/sany0005.jpg" height="360" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQnpw6N26pxUrp-576jOncfkK489qW4QIPPivbl83phHFpKWRUApPisb2kgxW3qgwIjJYwxQ3IRfNBf44jlc0ll_VZI8WkLn8SGdyMs7SL_lwzumOA1P5P-ZCDvr68PtN2HISkbPj4MUU/s1600/sany0006.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQnpw6N26pxUrp-576jOncfkK489qW4QIPPivbl83phHFpKWRUApPisb2kgxW3qgwIjJYwxQ3IRfNBf44jlc0ll_VZI8WkLn8SGdyMs7SL_lwzumOA1P5P-ZCDvr68PtN2HISkbPj4MUU/s640/sany0006.jpg" height="360" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjewf-Qy1f889fuHAd7yMqcyqqBc4K9R5QZWFVfVwh-CjVoZ-uBgCci00WnP9Rn1Sh6Bc655Fqkj9kCnhO0FgpNwaIYcUhh6aqGpviCcynIcc0VC5W8D0UM7BhQnMA8_dxaYaDiVTIhfy0/s1600/sany0007.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjewf-Qy1f889fuHAd7yMqcyqqBc4K9R5QZWFVfVwh-CjVoZ-uBgCci00WnP9Rn1Sh6Bc655Fqkj9kCnhO0FgpNwaIYcUhh6aqGpviCcynIcc0VC5W8D0UM7BhQnMA8_dxaYaDiVTIhfy0/s640/sany0007.jpg" height="360" width="640" /></a></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">As
a resut, the Intel HEX format file is generated along with PRN file:
HELLO2.HEX, HELLO2.PRN</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">The
PRN file is of no concern to us at the moment.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Now
we need to convert Intel HEX file into CP/M executable. This is done
with LOAD utility:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">A>
LOAD HELLO2</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Above
command will produce some information about resulting executable
(.COM) in the form of first address, last address, bytes read and
records written numbers. It will also create HELLO2.COM program on
the disk as well.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Now
type at the prompt the name of the program:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">A>
HELLO2</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">and
enjoy the resulting message:</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">HELLO
WORLD.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFeh-Vz5ZlTUYZs_Qf_87T-yibpvOntBAqr8kPJLcX9pa23XbRNax5GbpcXHYAZcViHModrjp66HaaQ-5DRy8h2bZMO_AbMf2zKS8yqQT0dkM9d7QzcgZvFc2G4Ty0CGrsukOoCqeHDC8/s1600/sany0011.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFeh-Vz5ZlTUYZs_Qf_87T-yibpvOntBAqr8kPJLcX9pa23XbRNax5GbpcXHYAZcViHModrjp66HaaQ-5DRy8h2bZMO_AbMf2zKS8yqQT0dkM9d7QzcgZvFc2G4Ty0CGrsukOoCqeHDC8/s640/sany0011.jpg" height="360" width="640" /></a></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">I
think it is enough excitement for a moment. Go ahead and experiment
with other CP/M BIOS functions, observe the results and learn if you want.</span></span><br />
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span>
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">In the next episode - what I learned about CP/M so far and how I created my own C64 CP/M disk with Infocom's ZORK1 adventure game.</span></span><br />
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span>
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Stay tuned!</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">Marek</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Lucida Sans Unicode, sans-serif;"><span style="font-size: medium;">10/14/2012</span></span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-2918813988661303224.post-79266309527231388152012-10-13T14:03:00.000-07:002013-06-08T10:06:50.513-07:00CP/M on a Commodore 64.<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;"> I've always been intrigued by CP/M operating system although I've never used it before. I possessed some knowledge about it, mostly that it was Intel CPU and Z80 oriented and how the user interface looked like and that it was a disk OS and that a lot of good professional software has been created for it. At some time in the 90-s, when I was still active (read - every day) C64 user, I made an attempt to create operating system of my own, only to learn later that the principles I chose for my OS, how it was bootstrapped, the architecture of kernel and control program and UI were very similar to these of CP/M. I liked CP/M because it provides structure and standardization that home computers needed so much, especially in the 70s and 80s era. The standardization we now possess and take for granted in the form of PC architecture did not exist at the time with the exception of mainframe computers and for home computers, CP/M filled the niche.</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;">I recently acquired CP/M cartridge for C64 on eBay. A great opportunity to give that OS a try when I finally had hardware that could run it in its very historical, almost original form. I knew that C64's cartridge was somewhat infamous for not delivering exactly on its promise and that it had been discontinued shortly after it was offered in retail. However I believe much of the bad rap this piece of hardware got can be attributed to the fact that it was not user friendly, or to better put it (since not a lot of software or computer hardware in the day you could call "user friendly" anyway) - not easy to use. First and foremost, the main obstacle to get the promised software base was incompatible to CP/M standard Commodore's disk format. The other - slowness. The cartridge has Z80 CPU on board with some glue logic that allows for it to use C64's resources (RAM, VIC, peripherals, CPU bus in general) together with C64's CPU - 6510 (well, not together, they switch between each other using some register, but pretty much C64 is turned into a dual CPU machine). The design of the cartridge and timing considerations forced the Commodore engineers to retard the Z80 clock, so the computer did not run too fast in CP/M mode. Another problem with the cartridge, which manifested itself later in history is that it did not work well with later versions of C64 main boards, especially with C64-C, which can be probably attributed to some peripheral chips (like VIC II) that were "fixed" in that model. Since Commodore did not produce the CP/M cartridge anymore at that time, they did not bother to produce a fix.</span><br />
<span style="font-family: Times, 'Times New Roman', serif; font-size: large;"><br /></span>
<span style="font-family: Times, 'Times New Roman', serif; font-size: large;">First, I wanted to test somewhat if the cartridge itself is not "dead". Original cartridge was sold with CP/M disk, instruction manual and some teat program in BASIC, I am not sure if it was on the disk or to be typed in from instruction manual. Since the program is pretty short, I believe it could be distributed in the form of printed copy that user could type in and run to test the cartridge without booting up the CP/M disk. Since we live in internet era, a lot of information is widely available on the net. I started the google search and quickly found the </span><a href="http://www.zimmers.net/anonftp/pub/cbm/schematics/cartridges/c64/cpm/README" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span style="color: #cc0000;">page</span></a><span style="font-family: Times, 'Times New Roman', serif; font-size: large;"> with test program listing. I inserted the cartridge into C64, typed in the test program, saved it on disk and ran it. It all seemed to work. The interesting note here - the test program seemed to work fine on C64-C model as well, it was the CP/M itself that I could not get to work on that one and had to turn to my older model - the bread bin C64 made in 1983.</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;">OK, so the test has passed, time to check how the actual CP/M works. However I had no original disk. No worries, in this day and era anything in electronic format is at your fingertips. I found the images <a href="http://www.zimmers.net/anonftp/pub/cbm/demodisks/c64/cpm/index.html"><span style="color: red;">here</span></a>. With the help of my <i>X1541 </i>cable and <i>opencbm </i>software I transferred my image. Loaded the disk to C64. Typed in:</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>LOAD"CPM",8</b></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>RUN</b></span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;">Moment of truth...(this is C64-C) the asterisks appeared on the screen, but stopped. The system hangs. I repeat, this time I get OS startup message and UI prompt, but attempt to type in anything hangs up computer again. The next try ends up in artifacts on the screen and hang-up as well. I switched to my older bread bin C64 and now we were in business. At the prompt:</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>A></b></span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;">I typed:</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>A> DIR</b></span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;">pressed ENTER and the directory of files has appeared. I have successfully booted up CP/M in year 2012 on my C64.</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;">The CP/M adventures will continue in following posts, please stay tuned...</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;"><br /></span>
<span style="font-family: Times, Times New Roman, serif; font-size: large;">Marek</span><br />
<span style="font-family: Times, Times New Roman, serif; font-size: large;">2012/10/13</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0