Hacker News new | past | comments | ask | show | jobs | submit login
Easy 6502 (skilldrick.github.com)
304 points by anigbrowl on Feb 7, 2013 | hide | past | favorite | 59 comments



I ported Serpentine for Broderbund to the C64 and a few other games for other publishers. After I changed to being a Producer, I thought I would ever program in 6502 again.

Then years later, I was given the task to program toys, all in 6502. I did a Little People Farm, Little People Phone, a musical jumprope and a reading of Goldielocks and the three bears.

I think the 6502 will never die.


This is such a silly question, but are you the one that made the barn door on the farm moo when it opened?


lol probably! Does it not work right?


No way - just the opposite! In fact I think it worked the last time I ever saw it years later. That was an incredibly memorable piece of my childhood, and apparently that of many others' as well: http://dribbble.com/shots/680831-Fisher-Price-WIP-2 (wherein I also mention that feature).


I'm proud of the phone too. It taught kids their own home phone number in a really cool way. I didn't design the features, I just programmed them. I wonder how many kids called home because they learned their number from this toy.


I loved Serpentine on the C64. I keep playing it a few rounds every now and again still (with a USB version of the Competition Pro joystick hooked up to my laptop, these days...).

According to Western Design Centre's website they're still licensing hundreds of millions 65xx series designs a year, which puts them in the league of MIPS, PPC and x86 in volumes. Don't know if that message is current, though.

It's fun to think that the many years worth of sales of all the 80's home computers most of us associate with C64 adds up to less than a years current sales of an ISA that's closing in on 40 years.

(EDIT: also, for examples of other obscure uses of 65xx cores: Some Amiga models, like the A500, had a 65xx core on the keyboard, in a model with a tiny onchip PROM and a some RAM, that was used as a serial controller)


What a luxury an assembler was compared to writing programs directly in hex where LDA # was $A9 nn, JMP was $4C aa aa, and RTS was $60 for example. Your brain would just about as quickly speak hex, though calculating relative branches (limited to a 256 byte range) was a "two pass" mental operation. I still have the green Rodnay Zaks book.


Yah, you learn very quickly how incredibly convenient something as simple as a labeled address can be. Thank god for modern assemblers!


At first I didn't have an assembler on the Apple ][ so I wrote a horrible Applesoft tool that would calculate jumps and do a little bit of what a real assembler does. Later I used something called BigMac, I think. I didn't understand macros at all, though, until years later.


The funny thing is that an assembler that calculates relative branches for you is a pretty simple program. Why did people spend so much time without writing one?


I can't speak for everyone but having 1K of total RAM and no cross assembler from which to write that first native assembler were enough to stop me from attempting it :)


Yeah, the RAM limitation in particular requires a lot of creativity; this version would use the entire 1K for its label table: http://lists.canonical.org/pipermail/kragen-discuss/2012-May...

Did you have any external media available, or just the RAM?


Unfortunately just RAM, lots of time and the mind of a 12 y/o!


Probably about the best you could do then would be to interactively assemble code (probably without mnemonics!) and output the assembled version. You could probably do a reasonable interactive assembler without mnemonics in 256 bytes; not sure about base64 input and output (four letters/numbers per 3 bytes of code!), or error correction.

Did the machine not even have a memory of what was on the screen? Because that's usually at least 2K, and that would go a long way.


This bring back childhood memories. I remember creating an interrupt subroutine in assembly on my commodore 64 that listened to the push button on the joystick and quickly changed the background colors on the screen. If I pressed the button it looked like the monitor flickered. Played lot's of pranks with my friends with that hack.


I'm right there with you. I recall there was a Horizontal and Vertical refresh interrupt, and you could catch that horizontal refresh (when the scan line was returning from the right side to the left side) and switch video modes from graphics into text cleanly, then, on the vertical refresh, when the scan line returned to the upper left hand corner, switch back to graphics mode. Allowed you to (easily) display images and text on the screen at the same time (graphics on top part of screen, text below whatever horizontal line you decided to switch back to text)


It was a single interrupt, but you could trigger it on a specific scan line by storing the number of the scan line in $D012. So to do stuff during the vertical blank you'd just need to set $D012 to a large enough value.

It was/is the bread and butter of the C64 demo scene.


"I don’t think you’ll ever have to write assembly language in your day job"

Not completely true. My company for example develops embedded systems for trains.

These systems can have a lifespan of decades, where they see daily use, and there's no reason for the customers to upgrade, but they might ask a change or some new functionality over the existing system.

Not me personally but I know of a few engineers that every now and then have to roll up their sleeves and write assembly. I would be surprised if this is not somewhat common, for companies mantaining long term systems.

Nice article BTW.


My first job after graduating from Maryland in 1984 - writing 6502 assembly for a voice/data switch and feature phones for GTE's OMNI series. Yes, the Leventhal book was all there was back then (it still sits on my shelf). I was working with some incredibly talented hardware and software developers, and the learning experience working with assembly and hardware was unmatched.

Later moving on to the Motorola 68000 series chips which were great, but just not as fun as working with the 6502. The 6502 was so simple and well designed, writing in assembly was actually productive.

To this day, the best job I've ever had.


Assembly is still the best way to leverage small microcontrollers and they're big business (AVR, Microchip). And a lot of fun BTW.


Which reminds me of Notchs upcoming(?) game with the DCPU-16. http://dcpu.com/dcpu-16/ http://0x10co.de/ Assembler know-how might be in demand soon.



Good catch and well worth reading. I thought there was something familiar about the link but oddly HN didn't refer me back to the earlier thread.


HN will never refer you to an earlier thread unless the URL matches exactly. See the '/index.html' suffix on the original and the lack thereof on this one, that's the difference that allowed you to submit the URL for a second time.


It is awesome though, I enjoyed it the first time, and apparently no one saw it because it is now at the top of HN.


Yes, it is awesome. When I learned how to program 6502 asm the best you could do was to buy Lance Leventhal's book and cobble together your own assembler, now you can learn the same thing interactively in a browser. 30 years difference.


Machine code monitor on the Apple ][+...had to calculate jump offsets in my head.


On the C64 I had the monitor cartridge. Always great when you had to block move memory to add an instruction in the middle. Converting things to data statements was also fun.


Did some of that, had to throw in delay loops so the sprites wouldn't tear when moving in response to the joystick.


yeah I used KIM-1 http://en.wikipedia.org/wiki/KIM-1 , fun :-)


Oh that takes me back! I remember peeking & poking for hours to various memory locations on my old 64 just to see what would happen.

Later I wrote a good bit of assembly for demo programs (which frankly sucked). I particularly loved the SID chip (http://en.wikipedia.org/wiki/MOS_Technology_SID).

Anybody remember Impossible Misson? I'm still fond of uttering "Destroy Him, My Robots". I don't think anybody gets the reference anymore though. https://www.youtube.com/watch?v=ginShVeGpGY


I remember peeking and poking a PET (or was it a CBM?) we had in the copier room at school until it would make a horrible whining sound requiring turning off the machine. Learned much later that some of the video registers could be poked with values that might damage the hardware :-)


I'll second the childhood memories comment. I also remember pouring over Z80 machine code and does anyone remember typing in individual numbers on a 1K ZX81 to run a blocky space invaders program (circa 1979)??


I remember forking an open source game library around 1985. Well, typing the source code in from the magazine so I could make my own game with sprites. I don't think I made it because of those awful rubber keys and it was not my computer anyway. The owner claimed he knew a guy who could replace the weird rubber keys with some plastic Commodore keyboard (though that would make typing BASIC code challenging -- the Spectrum keyboard had some strange mode where you could type just a single key to insert DIM or LIST).


Worse, it required that mode. It was memory-saving by using single character codes for the commands rather than 3 bytes for DIM or 4 bytes to store LIST as ASCII.


ZX81..... clue in name, not 1979.

Still, love and upvoted you for also having a ZX81 and, like me, typing in insane machine code. Probably felt like travelling back 2 years in time!!!! :)


Back in the early 80's. I saw a commodore 64 ROM with a cool looking spaceship on the packaging. It read: 'Make your games run faster'. I got my father to buy it for me. It was a 6510 assembly language monitor. This is how I jumped from Basic to assembly. It was a brutal learning curve. There was no Internet, as far as I was concerned back then.

There was a magazine called 'The Transactor':

http://www.scribd.com/collections/2988621/The-Transactor-Com...

The experience, definitely gave me a leg up later on, as an EE student, where I got to learn x86 ASM as well. The symbolic assemblers were much nicer. Most people would start out with templates where all the various memory segments were already setup. What was crazy was that after a awhile, you got to a point where you could recognize the instructions from looking at the HEX.



Reading all the positive recollections of the 6502 (esp. from people who've programmed other controllers) makes me feel nostalgic. It brings back happy memories of programming (with a paper and pencil -- I had no concept of an editor, or even assembly language) my C=64 -- I had a book of opcodes, and would scan up and down the list to find what I thought I wanted, then write it all out in a notebook. Then I would collect this code, and POKE it into place in the C=64 memory, and voila! Magic! The C=64 was so malleable. I would "hack the kernel"("OS Wedge" is what I knew it as) by resetting an interrupt vector for some function (ie: keyboard interrupt) to the address of my new code, and at the end of my code, call to the ROM for the original code. This way, I could get the screen to change colours every time I pressed a key.

It was one of my first introductions to computing, and probably exactly what I needed.


I actually find both 6502/6510 and x86 assembly languages fun.


I remember moving from 6502 to mips. Had to build a calculator for compsci. I rewrote the multiply instruction, didnt even consider it would be there in mips. 6502 was my first assembly, and i hold it dear to my heart :)


Aw MIPS, the first ASM that I ever encountered at my technical institiute. A trip down memory lane on a Thursday, well thank you very much! :)


I never coded in assembly apart from the basic hello worlds and such, but this is awesome.

I actually wouldn't mind learning assembly as a pet language :D


We had to create a CPU and program it for my undergrad, assembly turned out to be really easy to learn. I also found it really easy to program in, and my first program had no errors on first run (how rare!), but I think that's because it forces you to break it down into really small chunks, plus it was just an RPN calculator, nothing fancy.

I did enjoy it, and even wrote a toy compiler for it.


I recently stepped through "Programming from the Ground Up", and found it very educational. It's aimed at the x86 processor on Linux, so it's still quite relevant.

Worth going through, if you have the time.

http://programminggroundup.blogspot.com/


Nice link, thanks :)


What was everyone's favorite 6502 book from back then? Please list yours. I see Rodnay Zaks and Leventhal mentioned by other commenters.

What was yours?


I uniformly found anything but the manufacturer's references to be verbose and slow. I learned Z-80 assembly from Zilog's instruction set reference, and 6502 assembly from the Synertek reference. Ditto the 68000.

I never really learned x86 assembly because I started with some awful Scelbi book.

BTW, I used assembly in a real-world project about two years ago, and one of my cow-orkers was using it yesterday. It's anything but dead.


Richard Haskell's book ( http://www.amazon.com/Apple-II-6502-assembly-language-tutor/... ) was the one that finally made it click for me. Zaks's book was an older one -- targeting the KIM-1, IIRC. It didn't have any Apple II-specific content, but it was still interesting to read once I'd worked my way through Haskell's book.

Richard Haskell is still writing accessible introductory books for Verilog and VHDL. His new books look pretty good, but they came along a bit too late to help me this time.


I read Zaks' book back when, but it was rather dry and these days I'd recommend Machine Language for the Commodore 64 by Jim Butterfield instead.


Is anyone still producing 6502 processors today? Is there any price advantage to using such an venerable and well-known design today?


Yes, Western Design Center is selling the 65C02 in the classic 40-pin DIP package for about $5 a pop.

The last time I checked, which admittedly was almost 10 years ago, microcontrollers with embedded 6502 cores were quite popular with chinese toy manufacturers.


You reminded me of the Playpower Foundation that is designing a $10 6502-based "TV-computer" for distributing educational games to developing countries. This is cool, but I can't help but think that Moore's Law will deliver a cheap Android device.

Is there an Android device cheaper than the Raspberry Pi?

http://playpower.org/


I used to have an "IDE" called "Develop 64" that had a 6502 assembler and disassembler (6510 actually). Anybody else remember that? It was pretty good for its time.

I have fond memories of capturing an interrupt and displaying the time in the upper left corner of the screen without blocking the command line. Good times!


There's no difference in the instruction set between 6502 and 6510 (at least not in the documented opcodes) - the 6510 is a 6502 with up to 8 GPIO pins and a tristate address bus. On the C64 the IO pins were used for bank switching the ROM and underlying RAM, and for controlling the tape port.

(fun and useless trivia about the tape port: you could use your C64 as a very primitive 1-bit sampler by recording the tape input, and play it back by toggling the input to max and down again on every "1"; with some basic run-length encoding you could get a reasonable length sample in memory and still be able to record at a tolerable sample rate to get recognizable output)


OT: That's a beautiful github project page. I wasn't even aware that GitHub Pages existed...


Well, there goes my weekend.


The page looks very bad (read: is almost unreadable) on non Macs :(


I'm not sure I understand what looks poorly. It looks fine with Firefox on Ubuntu. I like the way it looks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: