---
created_at: '2015-01-13T20:43:50.000Z'
title: Microsoft BASIC for 6502 – Original Source Code (1978)
url: http://www.pagetable.com/?p=774
author: dezgeg
points: 250
story_text: ''
comment_text: 
num_comments: 70
story_id: 
story_title: 
story_url: 
parent_id: 
created_at_i: 1421181830
_tags:
- story
- author_dezgeg
- story_8882469
objectID: '8882469'

---
[Source](http://www.pagetable.com/?p=774 "Permalink to Microsoft BASIC for 6502 Original Source Code [1978] | pagetable.com")

# Microsoft BASIC for 6502 Original Source Code [1978] | pagetable.com

# [pagetable.com][1]

## Some Assembly Required

### Menu

[Skip to content][2]

* [Home][3]
* [About][4]

# Microsoft BASIC for 6502 Original Source Code [1978]

[28 Replies][5]

This is the original 1978 source code of Microsoft BASIC for 6502 with all original comments, documentation and easter eggs:

bah

[M6502.MAC][6] (1978-07-27, 6955 lines, 161,685 bytes)

This is currently the oldest publicly available piece of source written by Bill Gates.

## Language

Like the 8080 version, the 6502 version was developed on a PDP-10, using the MACRO-10 assembler. A set of macros developed by Paul Allen allowed MACRO-10 to understand and translate 6502 assembly, albeit in a modified format to fit the syntax of macros, for example:

| ----- |
|  MOS 6502 |  MACRO-10 |  
|  `LDA #0` |  `LDAI 0` |  
|  `LDA (ADDR),Y` |  `LDADY ADDR` | 

MACRO-10 did not support hex numbers, which is why most numbers are in decimal format. In the floating point code, all numbers are octal. The `RADIX` statement switches between the two. Octal can also be forced with a `^O` prefix.

Conditional translation is done using the `IFE` and `IFN` statements, which test whether the argument is zero. The following only adds the string to the binary if `REALIO` is equal to 4:
    
    
    
    IFE     REALIO-4,<DT"APPLE BASIC V1.1">
    

## Macros

The source defines many macros that make development easier. There are some examples:

| ----- |
|  Macro |  Definition |  Comment |  
|  `SYNCHK (Q)` |  `LDAI <Q>  
JSR SYNCHR` |  Get the next character and make sure it’s `Q`, otherwise `SYNTAX ERROR`. This pattern is used a lot. |  
|  `LDWD (WD)` |  `LDA WD  
LDY <WD>+1` |  Most 16 bit constants are loaded into A/Y with this macro, but macros for A/X and X/Y also exist. |  
|  `LDWDI (WD)` |  `LDAI <<WD>&^O377>  
LDYI <<WD>/^O400>` |  This loads an immediate constant into A/Y. |  
|  `PSHWD (WD)` |  `LDA <WD>+1  
PHA  
LDA WD  
PHA` |  This pushes a 16 bit value from memory (absolute or zero page) onto the stack. |  
|  `JEQ (WD)` |  `BNE .+5  
JMP WD` |  A compact way to express out-of-bounds branches. Macros exist for all branches. |  
|  `SKIP2` |  `XWD ^O1000,^O054` |  This emits a byte value of 0x2C (`BIT` absolute), which skips the next instruction. (The `^O1000` part wraps the byte in a PDP-10 instruction – see below.) | 

## Configurations

The BASIC source supports several compile-time configuration options:

| ----- |
|  Name |  Comment |  Description |  
|  `INTPRC` |  `INTEGER ARRAYS` |   |  
|  `ADDPRC` |  `FOR ADDITIONAL PRECISION` |  40 bit (9 digit) vs 32 bit (7 digit) float |  
|  `LNGERR` |  `LONG ERROR MESSAGES` |  Error message strings instead of two-character codes |  
|  `TIME` |  `CAPABILITY TO SET AND READ A CLK` |  TI and TI$ support |  
|  `EXTIO` |  `EXTERNAL I/O` |  `PRINT#`, `INPUT#`, `CMD`, `SYS` (!), `OPEN` and `CLOSE` support |  
|  `DISKO` |  `SAVE AND LOAD COMMANDS` |  `LOAD`, `SAVE` (and on Commodore: `VERIFY`) support |  
|  `NULCMD` |  `FOR THE "NULL" COMMAND` |  `NULL` support, a command to configure the number of NUL characters to print to the terminal after each line break |  
|  `GETCMD` |  `` |  `GET` support |  
|  `RORSW` |  `` |  If 1, the [`ROR` instruction][7] is [not used][8] |  
|  `ROMSW` |  `TELLS IF THIS IS ON ROM` |  The RAM version can optionally jetison the `SIN`, `COS`, `TAN` and `ATN` commands at startup |  
|  `CLMWID` |  `` |  Column width for `TAB()`“ |  
|  `LONGI` |  `LONG INITIALIZATION SWITCH` |   |  
|  `STKEND` |  `` |  The top of stack at startup |  
|  `BUFPAG` |  `` |  Page of the input buffer; if 0, the buffer uses _parts_ of the zero page |  
|  `BUFLEN` |  `INPUT BUFFER SIZE` |   |  
|  `LINLEN` |  `TERMINAL LINE LENGTH` |   |  
|  `ROMLOC` |  `ADDRESS OF START OF PURE SEGMENT` |   |  
|  `KIMROM` |  `` |  KIM-specific smaller config | 

## Targets

The constant `REALIO` is used to configure what computer system to generate the binary for. It has one of the following values:

| ----- |
|  Value |  Comment |  Banner |  Machine |  
|  0 |  `PDP-10 SIMULATING 6502` |  `SIMULATED BASIC FOR THE 6502 V1.1` |  Paul Allen’s Simulator on PDP-10 |  
|  1 |  `MOS TECH,KIM` |  `KIM BASIC V1.1` |  MOS KIM-1 |  
|  2 |  `OSI` |  `OSI 6502 BASIC VERSION 1.1` |  OSI Model 500 |  
|  3 |  `COMMODORE` |  `### COMMODORE BASIC ###` |  Commodore PET 2001 |  
|  4 |  `APPLE` |  `APPLE BASIC V1.1` |  Apple II |  
|  5 |  `STM` |  `STM BASIC V1.1` |  (unreleased) | 

All versions except Commodore also print “`COPYRIGHT 1978 MICROSOFT`” in a new line.

The target defines the setting of the configuration constants, but some code is also conditionally compiled depending on a specific target.

What is interesting is that initially it was Microsoft adapting their source for the different computers, instead of giving source to the different vendors and having them adapt it. Features like file I/O and time support seem to have been specifically developed for Commodore, for example. Later, the computer companies would get the source from Microsoft and develop themselves – source code of the [Apple][9] and [Commodore][10] derivatives is available; they both contain Microsoft comments.

By the way, the numbering of these targets probably indicated in which order Microsoft signed contracts with computer manufacturers. MOS was first (for the KIM), then OSI, then Commodore/MOS again (this time for the PET), then Apple.

### The PDP-10 Target

Paul Allen’s additional macros for 6502 development made the MACRO-10 assembler output one 36 bit PDP-10 instruction word for every 6502 byte. When targeting a real 6502 machine, the 6502 binary could be created by simply extracting one byte from every PDP-10 word.

In the case of targeting the simulator, the code created by the assembler could just be run without modification, since every emitted PDP-10 instruction was constructed so that it would trap – the linked-in simulator would then extract the 6502 opcode from the instruction and emulate the 6502 behavior.

While this trick was mostly abstracted by the (unreleased) macro package, its workings can be seen in a few cases in the BASIC source. Here, it defines `SKIP1` and `SKIP2`. Instead of just emitting 0×24 or 0x2C, respectively, it combines it with the octal value of 01000 to make it a PDP-10 instruction that traps:
    
    
    
    DEFINE  SKIP1,  <XWD ^O1000,^O044>      ;BIT ZERO PAGE TRICK.
    DEFINE  SKIP2,  <XWD ^O1000,^O054>      ;BIT ABS TRICK.
    

In the initialization code, it writes a `JMP` instruction into RAM. On the simulator, it has to patch up the opcode of JMP (0x4C, decimal 76) to be the correct PDP-10 instruction:
    
    
    
            LDAI    76              ;JMP INSTRUCTION.
    IFE     REALIO,<HRLI 1,^O1000>  ;MAKE AN INST.
    

With this information, we can reconstruct what the set of 6502 macros, which is not part of this source, probably looked like. Here is `LDAI` (`LDA` immediate):
    
    
    
    DEFINE  LDAI    (Q),<
            XWD ^O1000,^O251        ;EMIT OPCODE
            XWD ^O1000,<Q>          ;EMIT OPERAND
    >
    

You can also see native `TJSR` PDP-10 assembly instructions for character I/O:
    
    
    
    IFE     REALIO,<
            TJSR    INSIM##>        ;GET A CHARACTER FROM SIMULATOR
    
    
    
    
    IFE     REALIO,<
            TJSR    OUTSIM##>       ;CALL SIMULATOR OUTPUT ROUTINE
    

The `DDT` command, which breaks into the PDP-10′s DDT debugger, only exists in this config:
    
    
    
    IFE     REALIO,<
    DDT:    PLA                     ;GET RID OF NEWSTT RETURN.
            PLA
            HRRZ    14,.JBDDT##
            JRST    0(14)>
    

### The KIM and OSI Targets

The KIM target is meant for the [MOS KIM-1][11] and Ohio Scientific OSI Model 500 single-board computers. These are the first ports to specific computers, and also the cleanest, i.e. except for the character I/O interface and the very simple LOAD/SAVE implementation for the KIM, there is nothing specific about these targets.

### The Commodore Target

The Commodore target is meant for the Commodore PET 2001. It includes `LOAD`/`SAVE`/`VERIFY` (the commands jump directly to outside “KERNAL” ROM code), the I/O commands (`SYS`, `PRINT#`, `OPEN` etc.), the `GET` command and the `π`, `ST`, `TI` and `TI$` symbols. `CLEAR` is renamed to `CLR`, `"OK"` is renamed to `"READY."`, the BEL character is not printed, and character I/O code behaves differently to account for the more featureful screen editor of the PET.

Oh, and the Commodore version of course includes the [Bill Gates WAIT 6502,1 easter egg][12]! This is the `WAIT` instruction:
    
    
    
    ; THE WAIT LOCATION,MASK1,MASK2 STATEMENT WAITS UNTIL THE CONTENTS
    ; OF LOCATION IS NONZERO WHEN XORED WITH MASK2
    ; AND THEN ANDED WITH MASK1. IF MASK2 IS NOT PRESENT, IT
    ; IS ASSUMED TO BE ZERO.
    
    FNWAIT: JSR     GETNUM
            STX     ANDMSK
            LDXI    0
            JSR     CHRGOT
            BEQ     **ZSTORDO**
            JSR     COMBYT          ;GET MASK2.
    **STORDO**: STX     EORMSK
            LDYI    0
    WAITER: LDADY   POKER
            EOR     EORMSK
            AND     ANDMSK
            BEQ     WAITER
    ZERRTS: RTS                     ;GOT A NONZERO.
    

Note how the `BEQ` instruction references `ZSTORDO`, not `STORDO` – execution sneaks out of this function here.

Well, on non-Commodore machines, `ZSTORDO` is assigned to be the same as `STORDO`, so everything is fine:
    
    
    
    IFN     REALIO-3,<ZSTORDO=STORDO>
    

But on Commodore, we have this code hidden near the top of the floating point math package – close enough so the `BEQ` can reach it, but inside code that is least likely to get touched:
    
    
    
    IFE     REALIO-3,<
    ZSTORD:!        LDA     POKER
            CMPI    146
            BNE     STORDO
            LDA     POKER+1
            SBCI    31
            BNE     STORDO
            STA     POKER
            TAY
            LDAI    200
            STA     POKER+1
    MRCHKR: LDXI    12
    IF1,<
    MRCHR:  LDA     60000,X,>
    IF2,<
    MRCHR:  LDA     **SINCON**+36,X,>
            ANDI    77
            STADY   POKER
            INY
            BNE     PKINC
            INC     POKER+1
    PKINC:  DEX
            BNE     MRCHR
            DEC     ANDMSK
            BNE     MRCHKR
            RTS
    IF2,<PURGE ZSTORD>>
    

(`IF1` and `IF2` are true on the first and the second assembler pass, respectively, so the conditional there is to hint to the assembler in the first pass that `SINCON+36` is not a zero page address. Also note that all numbers here are octal, since this code is in the floating point package.)

First of all, the final line here removes `ZSTORD` from the list of symbols after the second pass, so that Commodore would not notice it in a printout of all symbols – very smart!

[As has been discussed before][12], this code writes the string “MICROSOFT!” into the PET’s screen RAM if the argument to WAIT is “6502″. The encoded string is hidden as two extra 40 bit floating point numbers appended to the coefficients used by the SIN function:
    
    
    
    IFN     ADDPRC,<
    SINCON: 5               ;DEGREE-1.
            204     ; -14.381383816
            346
            032
            055
            033
            206     ; 42.07777095
            050
            007
            373
            370
            207     ; -76.704133676
            231
            150
            211
            001
            207     ; 81.605223690
            043
            065
            337
            341
            206     ; -41.34170209
            245
            135
            347
            050
            203     ; 6.2831853070
            111
            017
            332
            242
            241     ; 7.2362932E7
            124
            106
            217
            23
            217     ; 73276.2515
            122
            103
            211
            315>
    

These last ten bytes, nicely disguised as octal values of floating point constants, spell out “MICROSOFT!” backwards after clearing the upper two bits. What’s interesting is that the floating point values next to them are actually incorrect: They should be 7.12278788E9 and 26913.7691 instead.

Also note that these constants are not conditionally assembled! All versions built since the Commodore easter egg was introduced also contained these 10 bytes – [including BASIC for the Motorola 6800][12]!

### The Apple Target

The Apple target is meant for the Apple II, and contains no customizations other than some changes around I/O handling (which calls into the monitor ROM). Note that this is not yet the “AppleSoft” version of BASIC, which was a more customized version modified by Apple later.

### The STM Target

“STM” most likely stands for “Semi-Tech Microelectronics” – a company that never shipped a 6502-based computer. Their first machine was the “Pied Piper”, a Z80-based system, and they later made a PC clone. It seems they had a 6502-based computer in development that never shipped – or at least they were considering making one, and Microsoft added the target; this target doesn’t actually change any of the defaults.

## Organization of the Source

The source uses the `PAGE` and `SUBTTL` keywords for organization. Here are the headings:
    
    
    
    SUBTTL  SWITCHES,MACROS.
    SUBTTL  INTRODUCTION AND COMPILATION PARAMETERS.
    SUBTTL  SOME EXPLANATION.
    SUBTTL  PAGE ZERO.
    SUBTTL  RAM CODE.
    SUBTTL  DISPATCH TABLES, RESERVED WORDS, AND ERROR TEXTS.
    SUBTTL  GENERAL STORAGE MANAGEMENT ROUTINES.
    SUBTTL  ERROR HANDLER, READY, TERMINAL INPUT, COMPACTIFY, NEW, REINIT.
    SUBTTL  THE "LIST" COMMAND.
    SUBTTL  THE "FOR" STATEMENT.
    SUBTTL  NEW STATEMENT FETCHER.
    SUBTTL  RESTORE,STOP,END,CONTINUE,NULL,CLEAR.
    SUBTTL  LOAD AND SAVE SUBROUTINES.
    SUBTTL  RUN,GOTO,GOSUB,RETURN.
    SUBTTL  "IF ... THEN" CODE.
    SUBTTL  "ON ... GO TO ..." CODE.
    SUBTTL  LINGET -- READ A LINE NUMBER INTO LINNUM
    SUBTTL  "LET" CODE.
    SUBTTL  PRINT CODE.
    SUBTTL  INPUT AND READ CODE.
    SUBTTL  THE NEXT CODE IS THE "NEXT CODE"
    SUBTTL  DIMENSION AND VARIABLE SEARCHING.
    SUBTTL  MULTIPLE DIMENSION CODE.
    SUBTTL  INTEGER ARITHMETIC ROUTINES.
    SUBTTL  FRE FUNCTION AND INTEGER TO FLOATING ROUTINES.
    SUBTTL  SIMPLE-USER-DEFINED-FUNCTION CODE.
    SUBTTL  STRING FUNCTIONS.
    SUBTTL  PEEK, POKE, AND FNWAIT.
    SUBTTL  FLOATING POINT ADDITION AND SUBTRACTION.
    SUBTTL  NATURAL LOG FUNCTION.
    SUBTTL  FLOATING MULTIPLICATION AND DIVISION.
    SUBTTL  FLOATING POINT MOVEMENT ROUTINES.
    SUBTTL  SIGN, SGN, FLOAT, NEG, ABS.
    SUBTTL  COMPARE TWO NUMBERS.
    SUBTTL  GREATEST INTEGER FUNCTION.
    SUBTTL  FLOATING POINT INPUT ROUTINE.
    SUBTTL  FLOATING POINT OUTPUT ROUTINE.
    SUBTTL  EXPONENTIATION AND SQUARE ROOT FUNCTION.
    SUBTTL  EXPONENTIATION FUNCTION.
    SUBTTL  POLYNOMIAL EVALUATOR AND THE RANDOM NUMBER GENERATOR.
    SUBTTL  SINE, COSINE AND TANGENT FUNCTIONS.
    SUBTTL  ARCTANGENT FUNCTION.
    SUBTTL  SYSTEM INITIALIZATION CODE.
    

## Paul Allen vs. Bill Gates

The source of the 8080 version states:
    
    
    
    PAUL ALLEN WROTE THE NON-RUNTIME STUFF.
    BILL GATES WROTE THE RUNTIME STUFF.
    MONTE DAVIDOFF WROTE THE MATH PACKAGE.
    

People have since [wondered][13] what runtime vs. non-runtime meant, especially since Paul Allen’s [recent debate][14] on whether the company’s ownership was faily split.

The BASIC for 6502 source sheds some light on this:
    
    
    
    NON-RUNTIME STUFF
            THE CODE TO INPUT A LINE, CRUNCH IT, GIVE ERRORS,
            FIND A SPECIFIC LINE IN THE PROGRAM,
            PERFORM A "NEW", "CLEAR", AND "LIST" ARE
            ALL IN THIS AREA. [...]
    

So by “runtime” they just literally mean “at run time”: all code that is active when the program runs, as opposed to non-runtime, which is all code that assists editing the program.

By this understanding, we can assume this:

* Paul Allen wrote the macro package for the MACRO-10 assembler, the 6502 simulator, the tokenizer, the detokenizer, as well as finding, inserting and deleting BASIC lines. 
* Bill Gates implemented all BASIC statements, functions, operators, expression evaluation, stack management for FOR and GOSUB, the memory manager, as well as the array and string library.
* Monte Davidoff wrote the floating point math package.

## Version and Date

The last entry in the change log has a date of 1978-07-27. Both the comment in the first line of the file and the message printed at startup call it version 1.1.

What does this say about the version of the source? Is it the last version? Let’s look at the last bug fix and compare which BASIC binaries contain this fix, and let’s see whether there are fixes in BASIC binaries that are not in the source.

I have previously compared binaries of derivatives of BASIC for 6502 and compiled the information at [github.com/mist64/msbasic][15]. The last entry in the log of this source is about a bug that failed to correctly invalidate a pointer in the `RETURN` statement. According to [my analysis of BASIC 6502 versions][16], this is fixed in the BASIC binaries for AIM-65, SYM-1, Commodore v2, KBD BASIC and MicroTAN, i.e. on everything my previous analysis calls `CONFIG_2A` and higher.

The same analysis also came to the conclusion that there were two successors, `CONFIG_2B` and `CONFIG_2C`. At least the two `CONFIG_2B` fixes exist in two BASIC binaries: KBD BASIC and MicroTAN, but they don’t exist in this source. It’s very unlikely that both these bugs (and only these!) got fixed by the two computer manufacturers independently, so it’s safe to assume that this source is not the final version – but pretty close to it!

## Interesting Finds

* This code is comparing a keyboard input character to the BEL code. [Bob Albrecht][17] is a computer educator that “was instrumental in helping bring about a public-domain version of Basic (called [Tiny Basic][18]) for early microcomputers.”. 
    
        
    CMPI    7               ;IS IT BOB ALBRECHT RINGING THE BELL
                            ;FOR SCHOOL KIDS?
    

* External documentation usually calls the conversion of ASCII BASIC text into the compressed format “tokenizing”. The source calls this “crunching”.
* Microsoft is still spelled “Micro-Soft”.
* Apparently the multiplication function could use some performance improvements: 
    
        		
    BNE     MLTPL2          ;SLOW AS A TURTLE !
    

* The `NEW` command is actually called `SCRATCH` in labels and comments – maybe other BASIC dialects called it that, and they decided to rename it to `NEW` later?
* The math package documentation says: 
    
        
    MATH PACKAGE
            THE MATH PACKAGE CONTAINS FLOATING INPUT (FIN),
            FLOATING OUTPUT (FOUT), FLOATING COMPARE (FCOMP)
            ... AND ALL THE NUMERIC OPERATORS AND FUNCTIONS.
            THE FORMATS, CONVENTIONS AND ENTRY POINTS ARE ALL
            DESCRIBED IN THE MATH PACKAGE ITSELF.
    

[Commodore’s derived source][10] changes this to:
    
        
    ; MATH PACKAGE
    ;       THE MATH PACKAGE CONTAINS FLOATING INPUT FIN, OUTPUT
    ;       FOUT, COMPARE FCOMP...AND ALL THE NUMERIC OPERATORS
    ;       AND FUNCTIONS.  THE FORMATS, CONVENTIONS AND ENTRY
    ;       POINTS ARE ALL DESCRIBED IN THE MATH PACKAGE ITSELF.
    ;       **_(HA,HA...)_**
    

* CHRGET is a central piece of BASIC for 6502. Here it is in its entirety: 
    
        
    ; THIS CODE GETS CHANGED THROUGHOUT EXECUTION.
    ; IT IS MADE TO BE FAST THIS WAY.
    ; ALSO, [X] AND [Y] ARE NOT DISTURBED
    ;
    ; "CHRGET" USING [TXTPTR] AS THE CURRENT TEXT PNTR
    ; FETCHES A NEW CHARACTER INTO ACCA AFTER INCREMENTING [TXTPTR]
    ; AND SETS CONDITION CODES ACCORDING TO WHAT'S IN ACCA.
    ;       NOT C=  NUMERIC   ("0" THRU "9")
    ;       Z=      ":" OR END-OF-LINE (A NULL)
    ;
    ; [ACCA] = NEW CHAR.
    ; [TXTPTR]=[TXTPTR]+1
    ;
    ; THE FOLLOWING EXISTS IN ROM IF ROM EXISTS AND IS LOADED
    ; DOWN HERE BY INIT. OTHERWISE IT IS JUST LOADED INTO THIS
    ; RAM LIKE ALL THE REST OF RAM IS LOADED.
    ;
    CHRGET: INC     CHRGET+7        ;INCREMENT THE WHOLE TXTPTR.
            BNE     CHRGOT
            INC     CHRGET+8
    CHRGOT: LDA     60000           ;A LOAD WITH AN EXT ADDR.
    TXTPTR= CHRGOT+1
            CMPI    " "             ;SKIP SPACES.
            BEQ     CHRGET
    QNUM:   CMPI    ":"             ;IS IT A ":"?
            BCS     CHRRTS          ;IT IS .GE. ":"
            SEC
            SBCI    "0"             ;ALL CHARS .GT. "9" HAVE RET'D SO
            SEC
            SBCI    256-"0"         ;SEE IF NUMERIC.
                                    ;TURN CARRY ON IF NUMERIC.
                                    ;ALSO, SETZ IF NULL.
    CHRRTS: RTS                     ;RETURN TO CALLER.
    

Did you ever wonder why [all][19] [versions][20] have $EA60 encoded into the `LDA` instruction that later gets overwritten? Because it’s 60000 decimal. That’s why! The source actually uses 60000 as a placeholder for 16 bit values in several places.
* The handling of `π`, `ST`, `TI` and `TI$` (all Commodore-specific) looks wonky: Instead of making them tokens, they are special cased in several places. I always assumed it was Commodore adding this without understanding (or wanting to disrupt) the existing code, but it was Microsoft adding these features. Maybe they were added by someone other than the original developers?

## Origin of the File

The source was posted on the Korean-language blog [6502.tistory.com][21] without further comment, in a marked-up format:
    
    
    
    ================================================================================================
    FILE: "david mac g5 b:m6502.asm"
    ================================================================================================
    
    000001  TITLE   BASIC M6502 8K VER 1.1 BY MICRO-SOFT
    [...]
    006955          END     $Z+START
    
    End of File -- Lines: 6955 Characters: 154740
    
    SUMMARY:
    
      Total number of files : 1
      Total file lines      : 6955
      Total file characters : 154740
    

This formatting was created by an unpublished tool by David T. Craig, who published a lot of Apple-related soure code (Apple II, Apple III, Lisa) [in this format][22] in as early as 1993, first [anonymously][23], later [with his name][24]).

The filename “`david mac g5 b:m6502.asm`” (disk name “david mac g5 b”, file name “m6502.asm”, since it was a classic Mac OS tool) confirms David Craig’s involvement, and it means the line numbers were added no earlier than 2003.

Given all this, it is safe to assume the file with the Microsoft BASIC for 6502 source originated at Apple, and was given to David Craig together with the other source he published.

The version I posted is a reconstruction of the original file, with the header, the footer and the line numbers removed, and the spaces converted back into tabs. I chose the name “M6502.MAC” to be consistent with the MACRO-10 file extension used by the [Microsoft BASIC for 8080 sources][25].

This entry was posted in [6502][26], [archeology][27] on [January 13, 2015][28] by [Michael Steil][29]. 

### Post navigation

←[ Using the OS X 10.10 Hypervisor Framework: A Simple DOS Emulator][30] [Fully Commented Commodore 64 BASIC ROM Disassembly – based on Microsoft’s Source →][31]

##  28 thoughts on “Microsoft BASIC for 6502 Original Source Code [1978]”

1. Pingback: [Microsoft BASIC for 6502 Original Source Code [1978] | The WordPress C(h)ronicle][32]

2. Pingback: [Código fuente original de Microsoft BASIC del año 1978 [ENG]][33]

3. **atomz** [January 14, 2015 at 01:14][34]

La verdad es que el código está de lujo. Excelentemente comentado y bastante claro y entendible (teniendo en cuenta la complejidad del lenguaje ensamblador). Hacer esto en los años 70 tiene muchísimo mérito principalmente debido a la falta de información y por ser un pionero en una tarea tan compleja. Los que hemos programado en ese lenguaje sabemos la dificultad de realizar todo el código sin errores, ya que cualquier mínimo fallo desbarata todo el programa sin saber muy bien por qué. No tiene nada que ver con los lenguajes de alto nivel, como Java o C++.

[Reply][35] ↓

4. **MagerValp** [January 14, 2015 at 02:43][36]

Commodore famously licensed Microsoft BASIC on a “pay once, no royalties” basis, and independently kept developing it for its 8-bit line of computers. If you’re interested in its history David Viner has posted the source for version 4.75 from 1982 with several enhancements:

<http://www.davidviner.com/cbm9.html>

[Reply][37] ↓

    1. **peterpies** [October 20, 2017 at 11:02][38]

Jack Tramiel the CEO of Commodore done the deal.

[Reply][39] ↓

5. Pingback: [Microsoft BASIC for 6502源代码泄露 | IT新闻 | html5tricks][40]

6. [**Thomas][41]** [January 14, 2015 at 23:49][42]

My RSS reader stops rendering in the second macro definition. Maybe the WD in angle brackets is not being escaped correctly?

[Reply][43] ↓

7. Pingback: [Au Courant || WNBTv][44]

8. [**Julian Skidmore][45]** [January 17, 2015 at 10:40][46]

You wrote: “The NEW command is actually called SCRATCH in labels and comments – maybe other BASIC dialects called it that, and they decided to rename it to NEW later?”

Indeed, NorthStar Horizon Multiuser Basic called it scratch (or rather scr). I didn’t know that was an early Microsoftism, I just thought it was a quirk of NorthStar Horizon Multiuser Basic.

[Reply][47] ↓

    1. **Gennaro Capuozzo** [February 17, 2015 at 08:05][48]

Several years later, the SCRATCH command was present again in CBM BASIC.  
It had nothing in common with the NEW command: it was a file-oriented DELete (rm) operation.

[Reply][49] ↓

        1. **Lasse Karkkainen** [August 11, 2015 at 05:31][50]

Actually, The Scratch in later CBM Basics was directly taken from CBM-DOS. At least The 1541 (and later) disk drives used Scratch command for removing files. I am not sure if the PET drives used same Disk Operating System? (and so Microsoft decided to change the name due possible confusion with Disk command?)

[Reply][51] ↓

9. Pingback: [Visto nel Web – 166 | Ok, panico][52]

10. Pingback: [Snippets: Io.js, FreeBSD in the Cloud and 6502 Basic | codescaling][53]

11. Pingback: [Les liens de la semaine – Édition #115 | French Coding][54]

12. **Ron** [January 20, 2015 at 01:27][55]

Certain characters in the headline of this entry causes most RSS readers on Mac to fail. (NSXMLParserErrorDomain 9)

[Reply][56] ↓

13. Pingback: [MSDN Blogs][57]

14. Pingback: [Compare in rete il codice sorgente del Basic Microsoft per 6502 (scritto da Bill Gates) | Archeologia Informatica][58]

15. Pingback: [Odd Lots – Jeff Duntemann's Contrapositive Diary][59]

16. Pingback: [Algunos programas que han hecho su código fuente público][60]

17. Pingback: [Algunos programas que han hecho su código fuente público | Entuespacio.com][61]

18. **Thiago** [March 13, 2015 at 23:36][62]

Perhaps STM means STMicroelectronics? Did they make some kind of 6502 clone?

[Reply][63] ↓

19. Pingback: [Intervista a Chuck Peddle, il papà del 6502! | Archeologia Informatica][64]

20. **falken** [March 22, 2015 at 06:07][65]

thanks, just cool ![;-\)][66]

[Reply][67] ↓

21. Pingback: [۱۸ نرم‌افزار قدیمی که امروزه آزاد هستند | سلام دنیا | رسانه تخصصی نرم‌افزارهای آزاد / متن‌باز][68]

22. Pingback: [Computer History: Links And Resources (19) | Angel "Java" Lopez on Blog][69]

23. Pingback: [Примеры классического кода, ставшего Open Source - itfm.pro][70]

24. Pingback: [Make Munich 2016 – das wars schon wieder | Steckschwein][71]

25. **Gordon** [March 5, 2017 at 01:28][72]

Hi Michael,  
I stumbled across your blog trying to find out the difference between the NTSC/PAL Futurama DVDs.

I’ve since taken a look at some of your other posts. It’s all really interesting stuff. I watched the talk on 6502 which was fascinating and hilarious. I’ll definitely be following this blog.

Also, you might wanna check out some of the comments. You seem to be getting fucked hard by spam.

Check out the most recent comment by “organic living”. What the hell? I don’t even get why someone would make a program that makes such bizarre comments. The use of non-ASCII characters is the icing on the WTF-cake for me — e.g. “diԀ” instead of “did”.

[Reply][73] ↓

### Leave a Reply [Cancel reply][74]

Your email address will not be published. Required fields are marked *

Name *

Email *

Website

Comment

You may use these HTML tags and attributes: `<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> `

Notify me of follow-up comments by email.

Notify me of new posts by email.

Search for:

### Recent Posts

* [Murdlok: A new old adventure game for the C64][75]
* [Commodore KERNAL History][76]
* [The Ultimate Apollo Guidance Computer Talk [video]][77]
* [The Ultimate Apollo Guidance Computer Talk @ 34C3][78]
* [62 Reverse-Engineered C64 Assembly Listings][79]

### github

### Blogroll

* [debugmode][80]
* [Alex Ionescu's Blog][81]
* [Fun with virtualization][82]
* [OS/2 Museum][83]

### Categories

* [6502][84]
* [archeology][85]
* [default][86]
* [digital video][87]
* [hacks][88]
* [literature][89]
* [puzzle][90]
* [SCUMM][91]
* [security][92]
* [tricks][93]
* [trivia][94]
* [Uncategorized][95]
* [whines][96]

### Meta

* [Log in][97]
* [Entries RSS][98]
* [Comments RSS][99]
* [WordPress.org][100]

[Proudly powered by WordPress][101]

[1]: http://www.pagetable.com/ "pagetable.com"
[2]: http://www.pagetable.com#content "Skip to content"
[3]: http://www.pagetable.com/
[4]: http://www.pagetable.com/?page_id=5
[5]: http://www.pagetable.com/?p=774#comments "Comment on Microsoft BASIC for 6502 Original Source Code [1978]"
[6]: http://www.pagetable.com/docs/M6502.MAC.txt
[7]: http://www.pagetable.com/?p=406
[8]: http://www.pagetable.com/?p=45
[9]: http://apple3.org/Documents/SourceCode/Apple3_Business_BASIC_1.3.pdf
[10]: http://www.davidviner.com/cbm9.html
[11]: http://www.pagetable.com/?p=359
[12]: http://www.pagetable.com/?p=43
[13]: http://harry-lewis.blogspot.com/2011/03/who-wrote-how-much-of-original.html
[14]: http://www.wsj.com/articles/SB10001424052748703806304576232051635476200
[15]: https://github.com/mist64/msbasic
[16]: https://github.com/mist64/msbasic/blob/master/README.md
[17]: http://www.amazon.com/Bob-Albrecht/e/B000APLRMU
[18]: http://en.wikipedia.org/wiki/Tiny_BASIC
[19]: http://www.pagetable.com/c64rom/c64rom_en.html#E3A2
[20]: http://www.txbobsc.com/scsc/scdocumentor/EFEA.html
[21]: http://6502.tistory.com/468
[22]: https://duckduckgo.com/?q=%22Total+number+of+files%22+%22Total+file+lines%22+%22Total+file+characters%22
[23]: http://apple3.applearchives.com/other_apple_resources/system_source_code/apple3sos13list.pdf
[24]: ftp://ftp.apple.asimov.net/pub/apple_II/documentation/apple3/dtca3doc/DTCA3DOC-180B%20apple%203%20sos%2013%20source%20listing.pdf
[25]: http://altairbasic.org/other%20versions/ian.htm
[26]: http://www.pagetable.com/?cat=2 "View all posts in 6502"
[27]: http://www.pagetable.com/?cat=3 "View all posts in archeology"
[28]: http://www.pagetable.com/?p=774 "12:00"
[29]: http://www.pagetable.com/?author=1 "View all posts by Michael Steil"
[30]: http://www.pagetable.com/?p=764
[31]: http://www.pagetable.com/?p=793
[32]: http://wp-cron.com/2015/01/13/microsoft-basic-for-6502-original-source-code-1978/
[33]: https://www.meneame.net/m/tecnología/codigo-fuente-original-microsoft-basic-ano-1978-eng
[34]: http://www.pagetable.com/?p=774#comment-26419
[35]: /?p=774&replytocom=26419#respond
[36]: http://www.pagetable.com/?p=774#comment-26439
[37]: /?p=774&replytocom=26439#respond
[38]: http://www.pagetable.com/?p=774#comment-543574
[39]: /?p=774&replytocom=543574#respond
[40]: http://news.html5tricks.com/microsoft-basic-for-6502-source-code.html
[41]: http://Upcoder.com
[42]: http://www.pagetable.com/?p=774#comment-26699
[43]: /?p=774&replytocom=26699#respond
[44]: http://willnotbetelevised.com/2015/01/17/au-courant-65/
[45]: https://sites.google.com/site/libby8dev/fignition
[46]: http://www.pagetable.com/?p=774#comment-27471
[47]: /?p=774&replytocom=27471#respond
[48]: http://www.pagetable.com/?p=774#comment-40773
[49]: /?p=774&replytocom=40773#respond
[50]: http://www.pagetable.com/?p=774#comment-99529
[51]: /?p=774&replytocom=99529#respond
[52]: https://okpanico.wordpress.com/2015/01/18/visto-nel-web-166/
[53]: http://codescaling.com/2015/01/18/snippets-io-js-freebsd-in-the-cloud-and-6502-basic/
[54]: http://frenchcoding.com/2015/01/19/les-liens-de-la-semaine-edition-115/
[55]: http://www.pagetable.com/?p=774#comment-28267
[56]: /?p=774&replytocom=28267#respond
[57]: http://blogs.msdn.com/b/eva/archive/2015/01/21/1-4.aspx
[58]: http://www.archeologiainformatica.it/2015/01/21/compare-in-rete-il-codice-sorgente-del-basic-microsoft-per-6502-scritto-da-bill-gates/
[59]: http://www.contrapositivediary.com/?p=3341
[60]: http://www.entuespacio.com/algunos-programas-que-han-hecho-su-codigo-fuente-publico/
[61]: https://entuespaciotv.wordpress.com/2015/02/10/algunos-programas-que-han-hecho-su-codigo-fuente-publico/
[62]: http://www.pagetable.com/?p=774#comment-49691
[63]: /?p=774&replytocom=49691#respond
[64]: http://www.archeologiainformatica.it/2015/03/21/intervista-a-chuck-peddle-il-papa-del-6502/
[65]: http://www.pagetable.com/?p=774#comment-53333
[66]: http://www.pagetable.com/wp-includes/images/smilies/icon_wink.gif
[67]: /?p=774&replytocom=53333#respond
[68]: http://salam-donya.com/18-pieces-of-classic-software-whose-code-is-now-accessible/
[69]: https://ajlopez.wordpress.com/2015/09/06/computer-history-links-and-resources-19/
[70]: http://itfm.pro/%d0%bf%d1%80%d0%b8%d0%bc%d0%b5%d1%80%d1%8b-%d0%ba%d0%bb%d0%b0%d1%81%d1%81%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d0%be%d0%b3%d0%be-%d0%ba%d0%be%d0%b4%d0%b0-%d1%81%d1%82%d0%b0%d0%b2%d1%88%d0%b5%
[71]: https://www.steckschwein.de/index.php/2016/01/18/make-munich-2016-das-wars-schon-wieder/
[72]: http://www.pagetable.com/?p=774#comment-492925
[73]: /?p=774&replytocom=492925#respond
[74]: /?p=774#respond
[75]: http://www.pagetable.com/?p=940
[76]: http://www.pagetable.com/?p=926
[77]: http://www.pagetable.com/?p=922
[78]: http://www.pagetable.com/?p=919
[79]: http://www.pagetable.com/?p=904
[80]: http://debugmo.de
[81]: http://www.alex-ionescu.com
[82]: http://virtuallyfun.superglobalmegacorp.com
[83]: http://www.os2museum.com/wp/
[84]: http://www.pagetable.com/?cat=2 "View all posts filed under 6502"
[85]: http://www.pagetable.com/?cat=3 "View all posts filed under archeology"
[86]: http://www.pagetable.com/?cat=4 "View all posts filed under default"
[87]: http://www.pagetable.com/?cat=5 "View all posts filed under digital video"
[88]: http://www.pagetable.com/?cat=6 "View all posts filed under hacks"
[89]: http://www.pagetable.com/?cat=7 "View all posts filed under literature"
[90]: http://www.pagetable.com/?cat=8 "View all posts filed under puzzle"
[91]: http://www.pagetable.com/?cat=9 "View all posts filed under SCUMM"
[92]: http://www.pagetable.com/?cat=10 "View all posts filed under security"
[93]: http://www.pagetable.com/?cat=11 "View all posts filed under tricks"
[94]: http://www.pagetable.com/?cat=12 "View all posts filed under trivia"
[95]: http://www.pagetable.com/?cat=1 "View all posts filed under Uncategorized"
[96]: http://www.pagetable.com/?cat=13 "View all posts filed under whines"
[97]: http://www.pagetable.com/wp-login.php
[98]: http://www.pagetable.com/?feed=rss2 "Syndicate this site using RSS 2.0"
[99]: http://www.pagetable.com/?feed=comments-rss2 "The latest comments to all posts in RSS"
[100]: http://wordpress.org/ "Powered by WordPress, state-of-the-art semantic personal publishing platform."
[101]: http://wordpress.org/ "Semantic Personal Publishing Platform"

  [*HTML]: HyperText Markup Language
  [*RSS]: Really Simple Syndication

