Good 6502 sources for reading

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
jblang
Posts: 35
Joined: 18 Jan 2017

Good 6502 sources for reading

Post by jblang »

Having just finished my annotation of the Supermon64 sources (see viewtopic.php?f=2&t=4385), I'm looking for suggestions about what code I should read next. A few interesting alternatives I'm aware of:

- DurexForth https://github.com/jkotlinski/durexforth
- SpeedScript https://archive.org/details/Computes_Speedscript
- Spindle (Trackmo Loader by LFT) http://www.linusakesson.net/software/spindle/v2.php
- AppleDOS code http://www.computerhistory.org/atchm/ap ... urce-code/
- Microsoft 6502 Basic http://www.pagetable.com/?p=774
- The C64 rom http://www.pagetable.com/c64rom/c64rom_en.html
- Apple I Integer Basic https://github.com/jefftranter/6502/tre ... sm/a1basic
- Price of Persia: https://github.com/jmechner/Prince-of-Persia-Apple-II
- Tiny Basic: https://github.com/jefftranter/6502/tre ... /tinybasic
- Acorn's BBC Basic: http://8bs.com/basic/basic4.htm

I'd prefer to read the code for real applications, not snippets or trivial examples. However, I've found a few things that look interesting enough that I'll make an exception:

- Stuff on Codebase64: http://codebase64.org/doku.php
- 6502 Assembly Language Subroutines by Leventhal and Seville: https://archive.org/details/6502_Assemb ... ubroutines

I've already read through the 256 byte Woz monitor. I'm not necessarily opposed to another annotation project, but after Supermon64 I could stand some "light reading", so things that already have comments are fine too.

I'd really like to look at the source for some C64 demos but I'm not aware of many that have been released. I know I could dissassemble them but I'd rather start with something that at least has labels, and preferably comments to help guide me along.

I'm primarily focused on original 6502 sources for classic computers, but I wouldn't mind looking at newer 65C02 or 65C816 sources if they are noteworthy.
Last edited by jblang on Wed Jan 25, 2017 11:35 pm, edited 1 time in total.
User avatar
cbmeeks
Posts: 1254
Joined: 17 Aug 2005
Location: Soddy-Daisy, TN USA
Contact:

Re: Good 6502 sources for reading

Post by cbmeeks »

One of my favorites is the source code to Prince of Persia for the Apple IIe.

https://github.com/jmechner/Prince-of-Persia-Apple-II
Cat; the other white meat.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Good 6502 sources for reading

Post by BigEd »

Maybe Tom Pitman's implementation of Tiny Basic which I think uses an inner interpreter:
https://github.com/jefftranter/6502/tre ... /tinybasic
Jeff Tranter has assembled(!) some other sources nearby.

Perhaps Acorn's BBC Basic:
http://8bs.com/basic/basic4.htm
jblang
Posts: 35
Joined: 18 Jan 2017

Re: Good 6502 sources for reading

Post by jblang »

Thanks for the suggestions... added them to the list.
User avatar
jac_goudsmit
Posts: 229
Joined: 23 Jun 2011
Location: Rancho Cucamonga, California
Contact:

Re: Good 6502 sources for reading

Post by jac_goudsmit »

There are two versions of Space Invaders for the PET: one that has graphics that look like little aliens, and starts up with a screen that shows you how to add sound to your PET.

The other one which I've always known as "space intruders" uses blocks to represent the aliens but has REALLY smooth movements because it uses the various graphics characters with different size blocks to move the aliens around. It also has a screen (written in Assembly if I remember correctly) that lets you adjust parameters (and cheat). See e.g. https://youtu.be/bNAS-fJpKaE?t=4m12s.

It only works on a PET with a v1 or v2 ROM; if you run it on a later CBM, the program stops with an error message because the BASIC part does a PEEK to check which ROM the machine has, uses the value in a calculation and then tries to poke it back, but ROMs other than the PET cause an overflow.

The machine language part of the program was hidden in some smart way: It loads from tape, but you can't see it when you do a LIST and if you try to save the program and load it back from tape, it won't work because a SAVE won't save the machine language part of the program.

I've always wondered how that program was written but right now I can't even find it online for downloading (the other Space Invaders is all over the place).

===Jac
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Good 6502 sources for reading

Post by BigEd »

Might be interesting to read this recent disassembly of Thrust (for the Beeb)
https://github.com/kieranhj/thrust-disa ... hrust.6502
White Flame
Posts: 704
Joined: 24 Jul 2012

Re: Good 6502 sources for reading

Post by White Flame »

jac_goudsmit wrote:
The machine language part of the program was hidden in some smart way: It loads from tape, but you can't see it when you do a LIST and if you try to save the program and load it back from tape, it won't work because a SAVE won't save the machine language part of the program.

I've always wondered how that program was written but right now I can't even find it online for downloading (the other Space Invaders is all over the place).
That's not any sort of special manipulation to hide it. BASIC can't list machine language, so it would just show up as garble anyway if it tried. For single-file programs, the machine code is generally just concatenated to the end of the BASIC program, and the SYS instruction should be hardcoded to wherever that happens to land.

To build it, either the assembled binary file is appended onto the end of the BASIC program file as a file operation; or the BASIC and asm portions are both loaded into memory and saved together as 1 file (after POKEing the end of BASIC listing to an exaggerated address to include the ML, or saved from a resident ML monitor); or the assembly source code included the bytes for the BASIC launcher as effectively .byte directives inline. For that era, I would suspect option #2 was the most common.
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Good 6502 sources for reading

Post by BigDumbDinosaur »

jac_goudsmit wrote:
The machine language part of the program was hidden in some smart way: It loads from tape, but you can't see it when you do a LIST and if you try to save the program and load it back from tape, it won't work because a SAVE won't save the machine language part of the program.
That is a common technique, in which a short piece of BASIC code says something like SYS 2063 (on the Commodore 64).

At the time when the program was created, the save was from the machine language monitor so that memory beyond the end-of-BASIC-text address was saved along with the BASIC text. When a program of any kind is LOADed with LOAD "<prog name>" (tape) or LOAD "<prog name>",8 (disk), a relocating load will occur. Once the load from tape or disk has finished, the BASIC interpreter will set its end-of-text pointer to a null that immediately follows the tokenized form of SYS 2063. This action is part of the normal linking process performed once the program has been read into memory (starting at $0800 in the Commodore 64). Due to these actions on the part of BASIC, the only thing that will be seen when the program is LISTed will be SYS 2063, even though all of the following machine code was LOADed as well. Also, as the end-of-program-text pointer points to the end of the BASIC text, not the entire program, an attempt to SAVE the program will "fail," since only the BASIC text will be saved.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
jac_goudsmit
Posts: 229
Joined: 23 Jun 2011
Location: Rancho Cucamonga, California
Contact:

Re: Good 6502 sources for reading

Post by jac_goudsmit »

I know how assembler programs were piggybacked to basic programs on the PET, I imagine many assembler programs were written completely in assembler and just had "org $400" (start of basic RAM on PET/CBM) followed by the bytes that represent the SYS instruction to jump into the machine language.

Space intruders (or whatever the official name is) had quite a few lines of basic preceding the ML part of the program, it wasn't just a single SYS instruction. Anyway in the days when I was interested in saving a version of the program that started with different parameters, I didn't know that "SAVE" in basic wouldn't save the machine language part, so I know I ruined someone's recording of the program at least once (sorry Mr Verschuren). Fortunately he had a backup.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: Good 6502 sources for reading

Post by barrym95838 »

Bob Bishop's "AppleVision" mixed a substantial amount of Integer BASIC and ML as well ... it was very clever and a bit tricky ... so tricky that I never completely understood how he did it, although I was able to track down his hi-res character generator code and use it as an inspiration for my own versions.

https://www.youtube.com/watch?v=RiWE-aO-cyU

Mike B.
Post Reply