{"id":195,"date":"2022-01-01T03:48:00","date_gmt":"2022-01-01T03:48:00","guid":{"rendered":"https:\/\/matterforge.website\/MatterForge\/?p=195"},"modified":"2023-04-10T02:55:47","modified_gmt":"2023-04-10T02:55:47","slug":"attint10a-microcontroller-pal-rca-snake-game","status":"publish","type":"post","link":"https:\/\/matterforge.website\/MatterForge\/attint10a-microcontroller-pal-rca-snake-game\/","title":{"rendered":"\u00b5C Snake &#8216;PAL&#8217; Game"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/Snake-img.png?resize=580%2C580&#038;ssl=1\" alt=\"\" class=\"wp-image-380\" width=\"580\" height=\"580\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/Snake-img.png?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/Snake-img.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/Snake-img.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/Snake-img.png?resize=600%2C600&amp;ssl=1 600w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>THE VINTAGE GAMES OF YESTER-YEAR<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Ever Since the early 50&#8217;s &#8211; 60&#8217;s video game entertainment units have always been the domain of nerds and the socially reclused. As technology has &#8216;speed-raced&#8217; through from transistors &#8211; to TTL Logic chips &#8211; to micro controllers\/processors &#8211; to FPGAs and Graphic cards &#8211; and beyond into the SoC technologies &#8211; proves one thing; The fundamental principles of Game logic forming: <\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>Objective &#8211; and &#8211; Reward <\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">have been more effective in lowering the teen birth rate than Communist China,<br>and more pacifying to the mass-populace than the gladiatorial combat of Pax Romana.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">RE-INVENTING THE WHEEL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The earliest of games of Pong, Snake and Asteroids used only negligible memory, clock speed and hardware peripherals (in comparison to today&#8217;s standards). It was the time where Male gamers where real men, and Female Gamers where real women<br>and little green space aliens were only virtual little green space aliens.<br>It was a simpler time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The task of trying to synthesize similar gaming experiences using modern hardware is not<br>a new one. There are already Arduino libraries such as TVOut that can be implemented<br>on the Arduino Uno\/Mega.<br>But When investigating how low can we go in the technology food chain<br>There isn&#8217;t much lower (and price and time affordabability)<br>that the ATTiny10. A 6 pin (3 pin + Reset + Vcc and GND) micro controller with<br>1k of program memory and get this only 32 bytes of RAM!.<br>This 3rd world equiv. CPU is so resource lacking it presents a significant challenge<br>when programming just the video handling yet alone the game logic.<br>This is of coarse ignoring the 1x int. timer and max 16MHz Clock (8MHz max internal clock).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It was decided that out of the many games to try to reproduce; snake was one that<br>there was enough popularity to know but not much attempts to create on the ATTiny.<br>It should be stated clearly that this project is not novel but a following of<br>Ben Heck&#8217;s Hacks video where he used the same chip to produce a<br>mini space invaders games. I just decided to follow suit and try to re-create snake.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">I WONT BORE YOU WITH THE DETAILS<\/h2>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-8f761849 wp-block-group-is-layout-flex\">\n<p class=\"wp-block-paragraph\">First step in getting this done was to see the timing and voltage requirements<br>of using an old style PAL RCA connector.<br>An analogue PAL format can be accessed at http:\/\/martin.hinner.info\/vga\/pal.html a pulse minium of 2us was needed<br>Given the int. clock can give a 8MHz signal (by adjusting CLKMSR.CLKMS,OSCCAL)<br>and the the CPU prescaler can do 1:1 this meant I could use the internal clock to fufill timing requirements instead of using an external clock. The advantage of this was to reduce pin usage because of the precious pin count.<\/p>\n<\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/pal_tv_diagram_non_interlace_inv.jpg?resize=580%2C401&#038;ssl=1\" alt=\"\" class=\"wp-image-387\" width=\"580\" height=\"401\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/pal_tv_diagram_non_interlace_inv.jpg?w=419&amp;ssl=1 419w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/pal_tv_diagram_non_interlace_inv.jpg?resize=300%2C208&amp;ssl=1 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The Voltage requirements need a 1V p-p voltage BUT! a -0.3V sync voltage.<br>The negative voltage complicates matters The sync pulse along with the video signal<br>used different polarities and whilst a H bridge could resolve this so could a virtual ground.<br>I decided to use a virtual ground.<br>The other issue I ran into was the output voltage of the Video screen I used need about +3V in order to<br>register a white pixel. A transistor was chosen to amplifier the video signal as the collector side<br>also isolated the virtual ground from the base. Also by adding a transistor The load current in the 75ohm<br>input impedance wouldn&#8217;t cause over current issues.<br>However the common emitter-transistor was inverting the signal and so a 7404 inverter was added to correct it.<br>A voltage divider allowed the video signal to meet the require voltage constraints. <\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-8f761849 wp-block-group-is-layout-flex\">\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-pic.png?resize=580%2C324&#038;ssl=1\" alt=\"\" class=\"wp-image-388\" width=\"580\" height=\"324\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-pic.png?w=1009&amp;ssl=1 1009w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-pic.png?resize=300%2C168&amp;ssl=1 300w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-pic.png?resize=768%2C429&amp;ssl=1 768w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-pic.png?resize=600%2C335&amp;ssl=1 600w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><figcaption class=\"wp-element-caption\">KiCAD Schematic of Buffer amplifier<\/figcaption><\/figure>\n<\/div>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?resize=580%2C370&#038;ssl=1\" alt=\"\" class=\"wp-image-389\" width=\"580\" height=\"370\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?resize=1024%2C654&amp;ssl=1 1024w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?resize=300%2C192&amp;ssl=1 300w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?resize=768%2C490&amp;ssl=1 768w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?resize=600%2C383&amp;ssl=1 600w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?w=1436&amp;ssl=1 1436w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/tvamp-i.png?w=1160&amp;ssl=1 1160w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><figcaption class=\"wp-element-caption\">PCB Render<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now that Timing and voltage are sorted, Pixel Resolution was the next on the list.<br>What was the minimum pixel width the chip could provide? you ask.<br>Although the CPU clock could give out (1\/8MHz)sec cycles; each instruction took from 1 &#8211; 3 clock cycles to complete<br>It was decided to use 2 pins for a SYNC PIN and a VID PIN (as used in the TVOut Library)<br>as the sync pulse was a crucial timing constraint and could be tied to the compare interrupt<br>and changing 2 pins at once was low instruction timing usage (4 instr).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the inital test the pixel count got down to 74 across by 40 down but this was using<br>just PORT = &#8216;toggle&#8217;<br>So if a custom pixel layour was to be worked out pointers had to be used.<br>The resolution was acceptable for the task of &#8216;snake&#8217; and after tweaking the timing and<br>potentiameters a smoother image of black, whites and greys could be made.<\/p>\n\n\n\n<div class=\"wp-block-group has-small-font-size is-horizontal is-nowrap is-layout-flex wp-container-core-group-is-layout-68a6192b wp-block-group-is-layout-flex\">\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=327%2C245&#038;ssl=1\" alt=\"\" class=\"wp-image-391\" width=\"327\" height=\"245\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=1024%2C768&amp;ssl=1 1024w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=1536%2C1152&amp;ssl=1 1536w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=2048%2C1536&amp;ssl=1 2048w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?resize=600%2C450&amp;ssl=1 600w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?w=1160&amp;ssl=1 1160w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220403_084503-1.jpg?w=1740&amp;ssl=1 1740w\" sizes=\"(max-width: 327px) 100vw, 327px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"580\" height=\"435\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=580%2C435&#038;ssl=1\" alt=\"\" class=\"wp-image-392\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=1024%2C768&amp;ssl=1 1024w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=1536%2C1152&amp;ssl=1 1536w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=2048%2C1536&amp;ssl=1 2048w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?resize=600%2C450&amp;ssl=1 600w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?w=1160&amp;ssl=1 1160w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2022\/06\/IMG_20220326_203547.jpg?w=1740&amp;ssl=1 1740w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/figure>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">GAME LOGIC<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before considering the logic of snake I&#8217;d like to pay my respect to the game logic elders both past and present. and mention the beauty in sequential timing circuits and the age old process of drawing &#8216;the game&#8217; &#8216;the state\/staus&#8217; and &#8216;the users\/sprites&#8217; and non so clearly shows this that the PAL Game of Atari&#8217;s PONG:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=580%2C375&#038;ssl=1\" alt=\"\" class=\"wp-image-608\" width=\"580\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=1024%2C663&amp;ssl=1 1024w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=300%2C194&amp;ssl=1 300w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=768%2C497&amp;ssl=1 768w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=1536%2C995&amp;ssl=1 1536w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=1200%2C777&amp;ssl=1 1200w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=1980%2C1282&amp;ssl=1 1980w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?resize=600%2C388&amp;ssl=1 600w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?w=2048&amp;ssl=1 2048w, https:\/\/i0.wp.com\/matterforge.website\/MatterForge\/wp-content\/uploads\/2023\/04\/pong_circuit.jpg?w=1740&amp;ssl=1 1740w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It is a sight to behold and a revelation for how a game goes together in hardware form.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Regarding the logic required for the snake project It&#8217;s currently underway and is being adapted from a javascript <a rel=\"noreferrer noopener\" href=\"https:\/\/codesandbox.io\/s\/github\/patorjk\/JavaScript-Snake?file=\/index.html\" data-type=\"URL\" data-id=\"https:\/\/codesandbox.io\/s\/github\/patorjk\/JavaScript-Snake?file=\/index.html\" target=\"_blank\">game<\/a>, <a href=\"https:\/\/www.educative.io\/blog\/javascript-snake-game-tutorial\" data-type=\"URL\" data-id=\"https:\/\/www.educative.io\/blog\/javascript-snake-game-tutorial\" target=\"_blank\" rel=\"noreferrer noopener\">games2<\/a><br>that was developed previously. STAY TURNED TRUE BELIEVERS<\/p>\n","protected":false},"excerpt":{"rendered":"<p>THE VINTAGE GAMES OF YESTER-YEAR Ever Since the early 50&#8217;s &#8211; 60&#8217;s video game entertainment units have always been the domain of nerds and the socially reclused. As technology has &#8216;speed-raced&#8217; through from transistors &#8211; to TTL Logic chips &#8211; to micro controllers\/processors &#8211; to FPGAs and Graphic cards &#8211; and beyond into the SoC [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23,20],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-code","category-electronic"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":63,"url":"https:\/\/matterforge.website\/MatterForge\/2013-w-s-c-solar-car\/","url_meta":{"origin":195,"position":0},"title":"2013 W.S.C. Solar Car","author":"mrsmithwebsite","date":"January 23, 2021","format":false,"excerpt":"","rel":"","context":"In &quot;CAD - Modelling Projects&quot;","block_context":{"text":"CAD - Modelling Projects","link":"https:\/\/matterforge.website\/MatterForge\/category\/cgi\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":4,"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":609,"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/posts\/195\/revisions\/609"}],"wp:attachment":[{"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matterforge.website\/MatterForge\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}