Microsoft BASIC for 6502 – Original Source Code (1978)
pagetable.com
pagetable.com
I became good friends with the salesmen (yes they were all men back then) and they liked me working in the window...it helped them sell the system if they could show a 12-year old kid writing programs on it. "How hard can it be if..."
The first real program I ever wrote was in MS ROM-BASIC (that's what I remember calling it, because it booted into it if you didn't put the DOS floppy into one of the two (yes two, we were lucky!) 360k floppy drives it had.
The program was a blackjack simulation and trainer for counting cards. My older brother became infatuated with the topic and I remember reading the books on it and wondering if the math and systems were real or just casino trickery.
So I learned this version of BASIC and went to town, building decks of cards and configurable card-counting systems, and proved to myself that, yes, under certain conditions, BJ counters do actually have a long-term advantage over the house.
It's fascinating to see the actual code that ran my simulations.
As I read this post I thought the same thing as you; how fascinating it was to see the actual code that ran many of my programs.
In my time, I got into BBS software and assembler and I find myself copying the BASIC Emulator out of ROM and studying it.
anyway, it's just so cool to read posts by so many people that thought the same way.
Just FYI, I felt the same way reading your post. Thanks for that.
Of course I remember the C-64, and it's "advanced" sprite handling routines...it sure beat PEEKing and POKEing memory in BASIC.
Tandy was the RadioShack brand in Europe.
From: http://jacquesmattheij.com/computers-I-have-known
I wonder how many kids got their start with computers because of friendly RS employees.
Thank you Gidon & Gert Jan, wherever you are.
To keep myself sane lately, I've been working on a fun hobby project. It's an HTML5 game. You pilot a spacecraft, but the only way to control the spacecraft is through a 6502 based computer. So all flight controls have to be coded yourself on the machine. There are hardware modules for radar, engines, weapons, etc, but you need to write software to control them all. I haven't fleshed out all the ideas yet, but I get a strange kick out of the idea of piloting a spacecraft with a Commodore 64.
So far I've got an asm.js, cycle accurate implementation of a 6502, a bus system which is roughly a combination of the C64 and Apple IIe, and 320x200 4 color display. Just started working on the radar hardware subsystem, and was going to try assembling C64 BASIC for it today. Which is why seeing this article on Hacker News was a neat surprise.
I wonder what became of 0x10C after Notch dropped it. Has anyone picked it up and kept working on it? Alternatively, I know Space Engineers is similar in kind, and was quite a bit of fun to play. It just doesn't (or didn't?) have any computing component.
There is some successor projects. Perhaps the most famous is Trillek at trillek.org .Forums are dead, but IRC is pretty active at freenode #project-trillek
Actually we have a full computer working with a more realistic behaviour, using TR3200 CPU (RISC like 32 bit cpu), with screen, keyboard, floppy drive, timer, RTC, beeper, hardware "random" number generator, etc. Tehre is two assemblers for it, WaveAsm and VASM. Also, SmallerC can output assembly code for it, and there is other C compiler that would have TR3200 backend (qcc , D language write C compiler).
A BASIC interpreter for it would very appreciate (or FORTH or any other easy learn language)
Links :
Computer specs : https://github.com/trillek-team/trillek-computer
Computer implementation library with a not very friendly emulator and a few tools (I'm working in an user friendly emulator using the lib): https://github.com/trillek-team/trillek-vcomputer-module
WaveAsm : https://github.com/Meisaka/WaveAsm
VASM : http://sun.hasenbraten.de/vasm/
SmallerC : https://github.com/alexfru/SmallerC
Toolkit recopilatory (wip) : https://github.com/trillek-team/computer-toolkit
PD: I forgot to mention that we have a simple firmware that detect devices, prints some information, try to bootup from floppy, and have a machine code monitor that is a clone of Woz's monitor ? https://github.com/Zardoz89/trillek-firmware
Also, you should check FUZIX (unix clone for 8 bit machines), there is some working to get it working on a 6502 cpu
Gates specifically says that "not a line of code went out that I didn't look over" for the BASIC 6502 product. At the time (1986) he said he considered BASIC for the 8080 his "greatest achievement ever in programming" and admitted that he no longer programs himself but does was still looking at code and discussing algorithms with his 160 Microsoft engineers.
[1] https://programmersatwork.wordpress.com/bill-gates-1986/
My dad had one of those OSI machines. Just a few years ago he found it again in the basement and booted it up, and we were greeted w/ the message saying something like 'OSI Basic, (c) Microsoft 1979'
There was also a pretty cool hack he did - where the OSI supported 40 columns of text, and connected to B&W TV screen. Somehow my dad hacked the motherboard to show 80 columns of text, which worked perfectly on the TV screen, fully readable with characters at half width. Not sure how he added the extra memory for the text, but it worked super well. He even mounted a small switch on the motherboard to flip between 40/80 mode. (EDIT - it may have really been a doubler from 24 columns to 48, as I'm reading up on old OSI specs right now)
I think that's the machine I learned to code on, when I was 6 years old. My dad showed me how to write a BASIC program to count, and I was hooked ever since. (Though I shortly migrated to a TRS-80 for my main childhood hacking).
Back on topic, the TRS-80 also had basic supplied by Microsoft (but Z80 code). I spent a lot of time reverse engineering some of it to add new functionality to the disk basic commands, which were unused if you only had cassette tape storage.
We used to "Protect" BASic programs by poking a dummy line number -1 at the start of the program. The program would still work, but refused to list.
Though I thought the way it handled graphics was pretty ingenious, where each character could be split into 2x3 blocks, and these 64 combinations were represented in the upper ASCII characters, for 128x48 resolution that is really just 'text'.
That's the machine I really learned how to code on, in Microsoft Level 2 Basic, armed with some David Ahl Creative Computing compilations.
How did you figure out the negative line number hack, just playing around to see what happened?
I cut my programming teeth on the old TRS-80 too. Learned Basic, then Z80 assembler. Still have mine with the interface and pair of disks.
I came across the line number hack when writing a line renumber program in assembler. While getting it working, I screwed up quite a lot and ended up with all kinds of values in there. Screw-ups can be a great way to learn, or especially trying to fix them!
The line number was held as two bytes at the start of each line, which could also be massaged by using the Poke command. When listing the program, Basic expects the lines numbers to increase in value and stops listing as soon as it comes to one that's smaller than the last one (presumably thinks it's reached the end of the program). Poking 65535 (255,255) into the first line does the trick.
Surprisingly, it doesn't affect the running of the program. When looking for targets of GOTO or GOSUB, it seems to scan the whole program and not stop at the hacked line number. Weird.
A friend of mine used to "protect" his basic programs against being line printed by poking 200 page feed characters into one of the early lines of the program. Really made the paper shoot out of the old Epson MX80 dot matrix printer :-)
Cheers! [Edit typo]
Sadly I never got into assembly on the Z80, I guess I didn't realize it would be accessible :-(
Cheers for reminding me of the Epson MX80 which I also had. I loved the programming manual for it, embedded with funny comments like how to forge the Mona Lisa.
Heck, Bill and Steve bought QDOS from Tim Paterson for that exact amount, and resold it to IBM for use as PC-DOS.
Maybe they needed your $50k to help finance the purchase.
I did some research in to hashing, simulated a couple of hashing functions in FORTRAN (I was still in school), and found a good way to optimize the function to avoid collisions on the core set of 6502 opcodes. This earned me an immediate raise from $7/hour to $9/hour.
The assembler ran blazingly fast and I still have the listings for it. As soon as it was able to self-assemble, I added macros for all of the opcodes that rightfully belonged in the 6502 ISA but were not there. Mostly a set of loads and transfers that made the ISA almost fully orthogonal.
DEFINE BCCA(Q),< BCC Q> ;BRANCHES THAT ALWAYS BRANCH
DEFINE BCSA(Q),< BCS Q> ;THESE ARE USED ON THE 6502 BECAUSE
DEFINE BEQA(Q),< BEQ Q> ;THERE IS NO UNCONDITIONAL BRANCH
Huh? The 6502 totally does have a regular unconditional branch instruction, as JMP. http://e-tradition.net/bytes/6502/6502_instruction_set.htmlThat was one hacking thing in these days: finding flags that are guaranteed to be set or cleared to use as condition for a branch instruction. I remember, that I always tried to avoid JMPs.
Branches are the only Jumps with condition. So, when you have a far destination that is more than 127 bytes away, you have to do that:
want to do:
BCS far_dest
Have to do:
BCC no_jump
JMP far_dest
no_jmp: ...
So, when you wasted to many "single bytes", you may end up up adding 3 Bytes and at least 3 cycles to your conditional jumps.-- veteran of several game cartridges for the 6502
"Paul Allen wrote the macro package for the MACRO-10 assembler"
In the part below it.
I learned a lot from that, on a high level how a language implementation works, on a lower level how things like arrays, tokenization, memory management, strings and statement dispatch worked. The hardest part to get my head wrapped around by far was the expression evaluator.
But once understood you could do all kinds of nifty things such as extend the language and call bits and pieces of the interpreter from assembly to perform some task, it instantly became like a library accessible from any machine language program (no such thing as upgrading your ROM).
BTW AmigaBASIC must have been a very interesting affair too. I think Commodore's agreement with Microsoft was somehow broken after release; it was never updated, it was never really integrated into the system - Intuition, the co-processors, the famous HAM mode, etc. So it left everyone unsatisfied. And it was slow and bloated. There was a compiler for it, the AC-Basic, which I successfully used for a short while, until AmigaBASIC was literally eclipsed by AMOS.
AmigaBASIC was indeed a bit of a lame duck. I used HiSoft BASIC myself, which was backwards compatible but added a lot of features, including a compiler.
The source was posted on the Korean-language blog
6502.tistory.com without further comment, in a marked-u
format:...
[ lots of interesting background here ]
...
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
be published.
So my guess is potentially safe to look at, but that's about it. If you have any doubts, I'd recommend not reading the original post.Then there is reading as in opening the link, examining the code, deeply understanding it, then going off and writing your own one 'from scratch'.
When I wrote a set of 80 bit IEEE Temporary Real floating point functions for the 6502, I used an early version of Maple running on a VAX that I, ahem, "acquired" an account for running at a local university to compute the coefficients for my functions.
I grew up with this code; it's so awesome to finally see the source!
LDWDI WORDS ;MORE BULLSHIT. TABER: PHP ;REMEMBER IF SPC OR TAB FUNCTION.
JSR GTBYTC ;GET VALUE INTO ACCX.
CMPI 41
BNE SNERR4
also it appears right in the middle FRETMP: STWD INDEX ;GET LENGTH FOR LATER.
JSR FRETMS ;FREE UP THE TEMPORARY DESC.
PHP ;SAVE CODES.
LDYI 0 ;PREP TO GET STUFF.
LDADY INDEX ;GET COUNT AND
http://www.obelisk.demon.co.uk/6502/reference.html#PHPHehe, that's been a while.