{"id":909,"date":"2018-03-29T23:15:09","date_gmt":"2018-03-29T23:15:09","guid":{"rendered":"http:\/\/cppdepend.com\/blog\/?p=909"},"modified":"2023-05-31T15:38:03","modified_gmt":"2023-05-31T15:38:03","slug":"bill-gates-legend","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/bill-gates-legend\/","title":{"rendered":"Bill Gates Legend: 40 Years Since Basic for 6502"},"content":{"rendered":"<p>Let&#8217;s first comeback in the past and discover what Bill Gates was doing in his beginning, here&#8217;s from Wikipedia a brief story:<\/p>\n<p><em>After Gates read the January 1975 issue of\u00a0Popular Electronics, which demonstrated the\u00a0Altair 8800, he contacted\u00a0Micro Instrumentation and Telemetry Systems\u00a0(MITS), the creators of the new microcomputer, to inform them that he and others were working on a\u00a0BASIC\u00a0interpreter for the platform.\u00a0In reality, Gates and Allen did not have an Altair and had not written code for it; they merely wanted to gauge MITS&#8217;s interest. MITS president\u00a0Ed Roberts\u00a0agreed to meet them for a demo, and over the course of a few <\/em>weeks<em> they developed an Altair\u00a0emulator\u00a0that ran on a minicomputer, and then the BASIC interpreter. The demonstration, held at MITS&#8217;s offices in\u00a0Albuquerque, was a success and resulted in a deal with MITS to distribute the interpreter as\u00a0Altair BASIC. Paul Allen was hired into MITS,\u00a0and Gates took a leave of absence from Harvard to work with Allen at MITS in Albuquerque in November 1975. They named their partnership &#8220;Micro-Soft&#8221; and had their first office located in Albuquerque. Within a year, the hyphen was dropped, and on November 26, 1976, the trade name &#8220;Microsoft&#8221; was registered with the Office of the Secretary of the\u00a0State of New Mexico. Gates never returned to Harvard to complete his studies.<\/em><\/p>\n<p><!--more--><\/p>\n<p>Microsoft BASIC for 6502 was based on\u00a0Altair BASIC, which Bill Gates and Paul Allen famously created for the MITS Altair 8800 (which used Intel\u2019s 8080 CPU) in 1975, writing it in a\u00a0motel in Albuquerque, New Mexico. That same year, MOS Technology created the 6502 microprocessor as a cheaper alternative to other microprocessors of the day. The 6502 would eventually be used in a number of popular computers, such as the Apple I, the Apple II, Commodore VIC-20 and 64 systems, as well as gaming consoles such as the Atari 2600.<\/p>\n<p>For the hobbyist,\u00a0here&#8217;s one of the\u00a0machines using the 6502 microprocessor and where the Microsoft Basic worked on.<br \/>\n<img decoding=\"async\" src=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/c\/c5\/Commodore_2001_Series-IMG_0448b.jpg\/800px-Commodore_2001_Series-IMG_0448b.jpg\" \/><\/p>\n<p>Here are some characteristics:<\/p>\n<p>OS: Commodore Basic 1.0. CPU: 6502 @ 1 mHz. RAM: 4 KB (early version) then 8 KB VRAM: 1 KB ROM: 14 KB TEXT MODES: 40 x 25. GRAPHIC MODES: None<\/p>\n<p>What you can do with a RAM of 4KB, today we need a minimum of 4Go. Was it possible to write software with the only 4KB of RAM?<\/p>\n<p>Yes, it was and here&#8217;s the <a href=\"https:\/\/github.com\/brajeshwar\/Microsoft-BASIC-for-6502-Original-Source-Code-1978\/blob\/master\/M6502.MAC.txt\">proof<\/a>. The oldest publicly available piece of source written by Bill Gates in 1978.<\/p>\n<p>Let&#8217;s discover some facts about this piece of code.\u00a0 And first, let&#8217;s generate a word cloud from the comments from the source code that describe it to discover what was the main preoccupation of the developers:<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.cppdepend.com\/img\/words.png\" \/><\/p>\n<p>String, Pointer, Variable, Value, Space are the most recurrent ones, which proves that the memory management was a big issue for this kind of machines. The code is optimized to make the most of the RAM available. Another interesting remark is the Garbage word which is cited many times.\u00a0 The garbage was very important to optimize the memory usage.<\/p>\n<p>Here&#8217;s from the source code comments how the strings are managed:<\/p>\n<pre>STRINGS\r\n\t\tIN THE VARIABLE TABLES STRINGS ARE STORED JUST LIKE\r\n\t\tNUMERIC VARIABLES. SIMPLE STRINGS HAVE THREE VALUE\r\n\t\tBYTES WHICH ARE INITIALIZED TO ALL ZEROS (WHICH\r\n\t\tREPRESENTS THE NULL STRING). THE ONLY DIFFERENCE\r\n\t\tIN HANDLING IS THAT WHEN \"PTRGET\" SEES A \"$\" AFTER THE\r\n\t\tNAME OF A VARIABLE, \"PTRGET\" SETS [VALTYP]\r\n\t\tTO NEGATIVE ONE AND TURNS\r\n\t\tON THE MSB (MOST-SIGNIFIGANT-BIT) OF THE VALUE OF\r\n\t\tTHE FIRST CHARACTER OF THE VARIABLE NAME.\r\n\t\tHAVING THIS BIT ON IN THE NAME OF THE VARIABLE ENSURES\r\n\t\tTHAT THE SEARCH ROUTINE WILL NOT MATCH\r\n\t\t'A' WITH 'A$' OR 'A$' WITH 'A'. THE MEANING OF\r\n\t\tTHE THREE VALUE BYTES ARE:\r\n\t\t\tLOW\r\n\t\t\t\tLENGTH OF THE STRING\r\n\t\t\t\tLOW 8 BITS\r\n\t\t\t\tHIGH 8 BITS  OF THE ADDRESS\r\n\t\t\t\t\tOF THE CHARACTERS IN THE\r\n\t\t\t\t\tSTRING IF LENGTH.NE.0.\r\n\t\t\t\t\tMEANINGLESS OTHERWISE.\r\n\t\t\tHIGH\r\n\t\tTHE VALUE OF A STRING VARIABLE (THESE 3 BYTES)\r\n\t\tIS CALLED THE STRING DESCRIPTOR TO DISTINGUISH\r\n\t\tIT FROM THE ACTUAL STRING DATA. WHENEVER A\r\n\t\tSTRING CONSTANT IS ENCOUNTERED IN A FORMULA OR AS\r\n\t\tPART OF AN INPUT STRING, OR AS PART OF DATA, \"STRLIT\"\r\n\t\tIS CALLED, CAUSING A DESCRIPTOR TO BE BUILT FOR\r\n\t\tTHE STRING. WHEN ASSIGNMENT IS MADE TO A STRING POINTING INTO\r\n\t\t\"BUF\" THE VALUE IS COPIED INTO STRING SPACE SINCE [BUF]\r\n\t\tIS ALWAYS CHANGING.\r\n<\/pre>\n<p>And how the errors are managed:<\/p>\n<pre>\tERROR MESSAGES\r\n\t\tWHEN AN ERROR CONDITION IS DETECTED,\r\n\t\t[ACCX] MUST BE SET UP TO INDICATE WHICH ERROR\r\n\t\tMESSAGE IS APPROPRIATE AND A BRANCH MUST BE MADE\r\n\t\tTO \"ERROR\". THE STACK WILL BE RESET AND ALL\r\n\t\tPROGRAM CONTEXT WILL BE LOST. VARIABLES\r\n\t\tVALUES AND THE ACTUAL PROGRAM REMAIN INTACT.\r\n\t\tONLY THE VALUE OF [ACCX] IS IMPORTANT WHEN\r\n\t\tTHE BRANCH IS MADE TO ERROR. [ACCX] IS USED AS AN\r\n\t\tINDEX INTO \"ERRTAB\" WHICH GIVES THE TWO\r\n\t\tCHARACTER ERROR MESSAGE THAT WILL BE PRINTED ON THE\r\n\t\tUSER'S TERMINAL.\r\n\r\n<\/pre>\n<p>What&#8217;s interesting in this source code is the clear explanation of many aspects of the program. no need to search elsewhere to understand what the code does.<\/p>\n<p><strong>Some facts about the code quality:<\/strong><\/p>\n<ul>\n<li>The naming is\u00a0easy to understand<\/li>\n<\/ul>\n<p>When exploring the source code, you don\u2019t find variable names such as\u00a0a, b or x, like some recently developed projects. The names are well chosen and well commented.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.cppdepend.com\/img\/vars.png\" \/><\/p>\n<ul>\n<li>\u00a0The code is split into many small subroutines<\/li>\n<\/ul>\n<p>The\u00a06502 assembly language is very low level, and to make the code easier to understand and maintain, the \u201cDivide and Conquer\u201d principle is applied. Indeed the code is split into many small subroutines, what makes them easy to read and maintain. Here\u2019s an\u00a0example of a small subroutine defined in its source code:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.cppdepend.com\/img\/code.png\" \/><\/p>\n<p>After exploring the code, In my opinion, Bill Gate was a genius developer and also a good businessman. It&#8217;s not a surprise that he become\u00a0one of the most influencers in the computer world as steve jobs and a few other legends.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s first comeback in the past and discover what Bill Gates was doing in his beginning, here&#8217;s from Wikipedia a brief story: After Gates read the January 1975 issue of\u00a0Popular Electronics, which demonstrated the\u00a0Altair 8800, he contacted\u00a0Micro Instrumentation and Telemetry Systems\u00a0(MITS), the creators of the new microcomputer, to inform them that he and others were &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/bill-gates-legend\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bill Gates Legend: 40 Years Since Basic for 6502&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[63,62],"class_list":["post-909","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-basic","tag-bill-gates"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/comments?post=909"}],"version-history":[{"count":13,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/909\/revisions"}],"predecessor-version":[{"id":1472,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/909\/revisions\/1472"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}