Page 1 of 1
Good 6502 sources for reading
Posted: Wed Jan 25, 2017 2:24 pm
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.
Re: Good 6502 sources for reading
Posted: Wed Jan 25, 2017 2:45 pm
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
Re: Good 6502 sources for reading
Posted: Wed Jan 25, 2017 4:59 pm
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
Re: Good 6502 sources for reading
Posted: Wed Jan 25, 2017 11:35 pm
by jblang
Thanks for the suggestions... added them to the list.
Re: Good 6502 sources for reading
Posted: Fri Jan 27, 2017 11:00 pm
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
Re: Good 6502 sources for reading
Posted: Sat Jan 28, 2017 7:44 pm
by BigEd
Might be interesting to read this recent disassembly of Thrust (for the Beeb)
https://github.com/kieranhj/thrust-disa ... hrust.6502
Re: Good 6502 sources for reading
Posted: Sun Jan 29, 2017 8:51 am
by White Flame
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.
Re: Good 6502 sources for reading
Posted: Sun Jan 29, 2017 4:09 pm
by BigDumbDinosaur
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.
Re: Good 6502 sources for reading
Posted: Sun Jan 29, 2017 4:52 pm
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.
Re: Good 6502 sources for reading
Posted: Sun Jan 29, 2017 6:26 pm
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.