Ask HN: Books to learn 6502 ASM and the Apple II
Posted by abkt 2 days ago
I want to learn Assembly to make games on the Apple II. What are the old books to learn 6502 Assembly and the Apple II itself (memory, screen management) ? And is it absolutely necessary to learn BASIC before Assembly ?
Comments
Comment by neomantra 2 days ago
if you think this is impressive, I once opened a modal dialog on an Apple IIGS in 65C816 assembly
I don't think you need to learn BASIC, if you know concepts like conditionals and looping and indexing. It is interesting to compare the higher-level language of the time with its companion assembly. And you might find yourself writing BASIC programs to complement your assembly, if you stick to that platform.
<lore> A friend dropped me a BASIC program that ran and wrote text to the Apple IIGS border. He asked me to figure it out, because it wasn't obvious what was going on. OG hacker puzzle... it was a BASIC program that jumped to hidden assembly after the apparent end of the text file (hidden chars maybe, I forget) and the assembly was changing the border at appropriate rate to "draw" on it. Those were the days... trying to find some reference to this and am failing. </lore>
I certainly credit my stack-frame debugging capability to dealing with that stuff so long ago. Oddly enough, I didn't really find it helpful for computer architecture class. Just because you know registers exists and how to manipulate them, doesn't exactly map architecting modern hardware system. But being fluent in logic operations and bit-twiddling and indexing does help a lot.
Comment by aa-jv 2 days ago
Check the books section and find something that compels you.
Also, don't forget the HUGE number of resources for 6502 assembly programming that are available in the https://archive.org/ magazine and book sections:
https://archive.org/search?query=6502
Rodney Zaks' books are great - I like especially "6502 Games", which taught me a lot back in the day:
https://archive.org/download/6502g/6502Games.pdf
I'm also especially fond of the easy6502 emulator - its a very handy tool to have while studying 6502 techniques:
https://skilldrick.github.io/easy6502/
Its not absolutely necessary to learn BASIC before Assembly, but it will definitely help you understand the resources of the machine better if you can debug BASIC ROM code. My personal 6502 platform of choice, the Oric-1/Atmos machines, has a pretty great ROM disassembly available, from which a lot of great knowledge can be obtained - but it does of course first require an undersanding of BASIC.
In case you're curious, the Oric-1 ROM Disassembly:
https://library.defence-force.org/books/content/oric_advance...
(You can get an Oric emulator named Oricutron, or you can access a virtual Oric here: https://oric.games/ ..)
Good luck!
Comment by OhMeadhbh 2 days ago
And I have a vague memory of this book: https://archive.org/details/aiimp/mode/2up
Not sure what level you're at, but I can't remember if this is the text Jef Raskin wrote, but it's a decent backgrounder: https://archive.org/details/aiirm/mode/2up
Comment by abkt 2 days ago
Comment by le-mark 2 days ago
https://www.google.com/search?q=apple+2+game+programming+tut...
Formulating questions is a valuable skill as is finding existing resources.
As some one from that era, it is truly amazing how much information there is online about all aspects of 8 bit computers
Comment by abkt 2 days ago
Comment by nippoo 2 days ago
Comment by fuzzfactor 2 days ago
It's the language that was designed for you to learn about programming and a computer language at the same time.
Whether or not you actually "master" the language or just barely learn a few commands, before using a few commands to make a simple finished program. One approach would surely be a lot faster than the other ;)
After that then decide how much you learned about programming itself from the little project, then you can see how far that BASIC alone may be able to advance your programming abilities even after you may be very familiar with the language in detail, or not.
In that '80's generation of home computers with a 6502, most had built-in BASIC so a common progression for so many was to learn BASIC at the same time as learn programming, since nobody had ever had home computers before. This could be just fine for business applications. Assembly is not nearly as easy as BASIC to learn, but in some sense programming is programming.
Then for gaming BASIC was not nearly as fast as assembly but often BASIC performed just fine anyway for developing the logical game flow and making it a "fun" game at its core to begin with. The problem with BASIC was all the other little details like video, I/O, UI, HID, were all so dramatically slower because each BASIC command needed to be interpreted before it could be run on the hardware and that took a little extra time in between each command but it really added up when you have challenging hardware interfaces and not simply fundamental game logic (many times game logic can be so simple that it's never slow in any language).
For a plain BASIC game that is "complete" but is supposed to have quick action and low latency, the next step in the learning curve would then be to find out which part of the BASIC code is the main resource bottleneck when it comes to processing time, then replace that one function with an equivalent written in assembly. It was accepted that it was a lot more work then to introduce assembly to make the game do the same thing it was before, only quicker.
It may not be very clear looking back, but there were a number of good reference books and instructional approaches and so much of it was intertwined with "learn BASIC + programming at the same time" followed by "useful assembly language techniques" to speed up your programs.
As crowds moved along these lines together to a degree as they emerged, it might help to look at publication dates for the books of the time, and use what's found in the earlier texts to help you with later concepts.
Comment by ksherlock 2 days ago
The Assembly Lines book -- https://archive.org/details/AssemblyLinesCompleteWagner
Understanding the Apple IIe -- https://archive.org/details/understandingapp0000sath
Understanding the Apple II -- https://archive.org/details/understanding_the_apple_ii
Comment by not_clear 2 days ago
I just noticed that Understanding the Apple IIe also got a re-issue from Call-A.P.P.L.E. in 2024 (print edition from Lulu) - https://www.callapple.org/books-3/understanding-the-apple-ii... .
Comment by joezydeco 2 days ago
Comment by Gracana 2 days ago
Comment by billygoat 2 days ago
This book specifically targets beginners that are new to 6502 assembly. The examples cover all of the 1980s-era computers including the Apple II. It's free on archive.org and the introductory chapters are worth reading.
Comment by kenjackson 2 days ago
Comment by einr 2 days ago
Comment by kurlberg 2 days ago
Comment by i_don_t_know 2 days ago
https://archive.org/details/Advanced_6502_Programming/mode/2...
Comment by c64cryptoboy 2 days ago
Comment by Tor3 2 days ago
Comment by abkt 2 days ago
Comment by JKCalhoun 2 days ago
You could do a lot worse than picking up a new Commodore 64 Ultimate [1]. They're a more or less faithful remake of the Commodore 64 but have an HDMI port, SD card instead of disk drive, etc. You could learn BASIC, should be able move to assembly as well—a quick search pulled up a YouTube course on 6502 assembly for the Commodore [2].
(I realize I am not contributing "books"—but others have done well in this regard. I did want to share what I think is a pragmatic way to learn 6502.)
[2] https://youtube.com/playlist?list=PLU1o_YShTPgoA7_nZ0PutqaPD...
Comment by Tor3 2 days ago
For actual 6502 programming you'll need a dedicated 6502 assembly programming book, for example the aforementioned Rodney Zaks books.
Comment by mmphosis 2 days ago
Comment by RiverCrochet 1 day ago
If you don't have experience programming, learning BASIC before Assembly will be super helpful before you learn 6502.
If you only have experience programming in modern languages (Javascript, etc.), learning the Applesoft BASIC will also be super helpful before you learn 6502, as you'll learn how to get by without ...
A) the following language conveniences:
- function names (it's all line numbers),
- variables with more than 2 letters,
and
B) the following modern concepts:
- function calls (no stack other than for GOSUB, use subroutines with dedicated variables for passing parameters instead),
- scoped variables (everything is global),
- dynamic allocation (you have to DIM arrays with the max size upfront),
- anything object-like like structs or classes (hack it with multi-dimensional arrays)
- other fancy stuff like callbacks, promises, hashtables and any other data structure beyond arrays.
and that will nicely prepare you for 6502 assembly (or any kind of assembly really). The advantage in 6502 assembly is you can implement most of B) yourself if you do need it.
Comment by dehrmann 2 days ago
Comment by rahimnathwani 2 days ago
Comment by eej71 2 days ago
Randy Hyde the creator of the Lisa assembler.
https://archive.org/details/A2_Hyde_6502_Asm_Lang/mode/1up
Ken Williams of Sierra OnLine fame.
https://vintageapple.org/apple_ii/pdf/Apple_II_Computer_Grap...
Comment by runjake 2 days ago
This is how I learned. This book is great. I have the worn paper copy sitting 6 feet behind me as I type this. It's worth getting a paper copy if that is still possible.
https://archive.org/details/6502-assembly-language-programmi...
Comment by hybrid_study 2 days ago
Comment by jsrcout 1 day ago
Here's a link from archive.org. It's not the best scan, but you can easily find other copies.
https://archive.org/details/applerefjan78/page/n69/mode/2up
If you're feeling adventurous, you can find assembly listings for the AppleSoft BASIC language (though maybe only from third parties). It's pretty huge.
Comment by asdefghyk 1 day ago
Pinball Construction Set, by Bill Bludge
Chop Lifter, modeled on 1979–1981 Iran Hostage Crisis, Dan Gorlin, Brøderbund 1982
Castle Wolfenstein (1981) (Muse) by Silas Warner
Red Alert (1981) Olaf Lubeck, Broderbund
I still have some of these original games and the artwork in the shed.....
All classic Apple games of very early 80s
At the time, the programming was recognized as amazing, the sound and graphics. It was a marvel that it was achieved on such a low resource machine ....
Comment by WillAdams 2 days ago
https://www.goodreads.com/en/book/show/5011686-apple-machine...
Here is an interesting article on porting a BASIC game for the Apple II to GW BASIC:
https://nanochess.org/akalabeth.html
and it includes a link to the documented source code for Akalabeth (also known as Ultima 0)
Somewhere, there's an article discussing the assembly-language like bit-blitting used to draw the high-res graphics in a timely fashion and the variable/memory management techniques needed to drive that which I'm sure a bit of searching will turn up (or one can derive it from the source).
Comment by 8bitsrule 1 day ago
Comment by asdefghyk 1 day ago
Suggest to look at some of the archives of old Apple Magazines from around the Apple I era , cira late 70s and early 80s.
Some of them would have had assembly language programming columns. I recall one Named Softtalk , but there where many. There are other Sites than Archive.org. Some archive sites solely devoted to early apple computers like Apple 2
Comment by EvanAnderson 2 days ago
If you can do simple exercises on a machine like that and get comfortable with simple operations (loops, memory addressing modes) I think you'd have a better time grokking something more feature-filled.
[0] http://retro.hansotten.nl/6502-sbc/kim-1-manuals-and-softwar...
Comment by wang_li 2 days ago
As in other comments, if you are specifically interested in the Apple II line, the Assembly Lines books by Roger Wagner is fantastic.
Also, if you can find it Sandy Mossberg's Disassembly Lines articles in Nibble magazine were great too. Start with Assembly Lines, then read the Disassembly Lines and you'll be quite expert.
Comment by vparikh 2 days ago
https://archive.org/details/ataribooks-machine-language-for-...
and
https://archive.org/details/ataribooks-the-second-book-of-ma...
These two books will give you a good understanding of 6502 assembler - it is general but gives a good background and has a nice assembler with a full walk through of the code. I used these two books to learn 6502 on my Commodore 64 and they are highly recommended.
Comment by mwexler 2 days ago
Comment by andreybaskov 2 days ago
And then obviously Programming the 6502 by Rodnay Zaks.
Comment by alnwlsn 2 days ago
In my opinion BASIC, with its line numbers and GOTO / GOSUB feels assembly-ish anyway - you'll be doing a lot of JMP / JSR to control program flow which is different to how modern high levels are normally written.
Comment by justin66 2 days ago
Comment by waffletower 2 days ago
Comment by absynth 1 day ago
Personally I'd approach it using a raspi + python + pygame. Learn the fundamentals there then switch to apple.
Comment by sloaken 2 days ago
Only reason I can think to learn basic is if you do not know any programming language. And even then there are better choices.
Do they make an C compiler for the AppleII?
Comment by jlmcgraw 2 days ago
I have fond memories from the late 1980s of trying to get the assembler contained within this book working, typing line after line of the MLX listing in. Unfortunately I never did finish it back then.
A week or so ago I got the urge to complete this project and I literally just finished getting the source in it to a point where it can be compiled online and then within an emulator: https://github.com/jlmcgraw/LADS_DOS33
Comment by jacquesm 2 days ago
Comment by Smalltalker-80 2 days ago
Comment by lakkal 2 days ago
Comment by christkv 2 days ago
Comment by ajross 2 days ago
https://archive.org/details/mos_microcomputers_programming_m...
And it's really not so complicated! The chip is simple, so the docs are simple. There's more to read about the history to come later, but there's also something to be said for understanding it in the context its designers presented it.
Comment by ThinkingGuy 2 days ago
Comment by asdefghyk 2 days ago
Id look for a book that targets Assembly programming on a Apple 2, ie not a book on general 6502 programming.
Such a book Id expect to discuss things like Apple 2 memory map , Apple 2 hardware and how they are used in assembler language.
Hopefully the book would also provide guidance using a particular assembler ( hopefully still available)I googled phrase Apple 2 assembly language programming for beginners?
and lots of very good looking links popped up.
You aim is a challenging task. Much to learn. Good luck. However entirely do able these days.
My background is electronics engineer, embedded programing on in assembler (some Motorola processors and others) and C for a few years before moving on to other things ....
The book Assembly Lines: The Complete Book available as a FREE PDF download from .... site https://ct6502.org/product/assembly-lines-the-complete-book/
INCLUDES All 33 of Roger Wagner’s Assembly Lines articles from Softalk magazine, plus appendices, in one complete volume.
Comment by abkt 2 days ago
Comment by peterevans 2 days ago
Can you explain a bit more about how you became interested in assembly and programming the Apple II? And specifically, why you want to start the journey towards programming there?
Comment by zabzonk 2 days ago
Comment by Joel_Mckay 2 days ago
Getting a 6502 kit from Ben Eater, and walking though how the CPU works will implicitly show how languages abstracted away whats actually happening. And more importantly, the skills necessary to understand how to write efficient programs.
https://www.youtube.com/watch?v=LnzuMJLZRdU&list=PLowKtXNTBy...
Starting with a simple architecture is highly recommended. =3
Comment by 20wenty 2 days ago
Comment by Joel_Mckay 2 days ago
Cheers, =3
"Build a Superscalar CPU" (Fabian Schuiki)
https://www.youtube.com/watch?v=bwjMLyBU4RU&list=PLyR4neQXqQ...
https://github.com/fabianschuiki/superscalar-cpu
"Making an 8 Bit pipelined CPU" (James Sharman)
https://www.youtube.com/watch?v=3iHag4k4yEg&list=PLFhc0MFC8M...
Comment by whartung 2 days ago
Programming concepts are pretty much universal. Being distanced from computer architecture is not a limitation for novice programmers, Python et al succeeds for a reason.
If you're determined to start with assembly, then I hope you can find someone to help you get started with all the machinations necessary to get from LDA #0 to A9 00 with as little drama as possible. Someone to show you how to use the assembler, what the directives mean, the linker, a symbolic debugger (if you're lucky). Someone to provide you with a .DUMPREG "START OF SORT" and .DUMPMEM BUFF $80 "AFTER INPUT" macros that you can liberally scatter throughout your code so you actually progress and get some insight into what the heck you code is doing. Perhaps some way to stop your programs that doesn't include hitting the reset button on the machine.
I mention that because, again, the tooling is terrible. All of the is easier said than done. None of the assembly books address this, none of the assembly program reference guides do either. Assembly is VERY black box. It's a large step up to even get started.
It's much easier to "learn programming" first at a higher level, where you can quickly progress and succeed, before turning into the dark hole that is assembly, particularly on older machines.
At least on a KIM-1 you can hit the STOP button and cursor through memory (being conscious that the memory architecture of the KIM is quite funky), something that simple is quite difficult on an Apple ][.
Comment by Joel_Mckay 2 days ago
I would recommend looking at a few random samples of Ben's build series, as he covers most first year subjects in subtle efficient ways.
Soldering kit PCB or Emulators are insufficient to demonstrate a physical bus wire harness, clock timing, and memory layout. Best of luck =3
Comment by zabzonk 2 days ago
Comment by Tor3 2 days ago
Comment by Joel_Mckay 2 days ago
They say "one always ends up coding in whatever your first language was... regardless of what language you are using".
People could always bring up the BASIC software Rom at the end of the build if interest arises after learning how a simple computer works. =3
Comment by rustyhancock 2 days ago
I have a special place in my heart for the original pic16f84a the modern equivalent is the pic16F1827.
Which uses the same 35 core instructions.
AVR8 is a close second.
Comment by dmezzetti 2 days ago