Seyed Masoud Hosseini · Overview · Study log · Ideas · Transcript · RSS feed

Embedded Systems, 6502 breadboard computer · Lecture 7 of 29 · 17:42

Part 7: Subroutine calls, now with RAM

Subroutine calls, now with RAM — 6502 part 7 on YouTube

Study guide

What this lecture covers

This video completes the RAM wiring started in part 6 by adding the timing logic needed so the RAM chip's chip-select signal only goes active once the address lines have stabilized, and goes inactive again before they change on the next cycle. With that logic connected, the "Hello world" program that relies on subroutine calls finally works.

The lecture then reconnects the Arduino bus monitor to single-step through a JSR/RTS sequence and confirm, cycle by cycle, that the return address is correctly pushed to and pulled from the stack in RAM. It closes by adding a clear-display instruction to the LCD program so the screen resets cleanly, and previews replacing the manual clock module with a real crystal oscillator in the next video.

Key ideas

  • Chip-select timing logic: extra NAND-gate logic ensures the RAM's chip-select signal activates only after the address bus is stable and deactivates before the address changes, avoiding corrupted reads or writes.
  • Reusing existing gates: the same inverted A15 signal already used for the EEPROM's chip select is fed into another NAND gate along with the clock signal to generate the RAM's properly timed chip select.
  • Unused gate inputs: leaving logic-chip inputs unconnected risks them floating and causing noise, so the lecture ties the unused fourth NAND gate's inputs high as good practice.
  • Stack push/pull verified on the bus: single-stepping shows the processor writing the return address to $01FF/$01FE during JSR and correctly reading it back during RTS, something that failed entirely before RAM was installed.
  • Internal-only clock cycles: some clock cycles during JSR/RTS don't actually transfer meaningful bus data; the address and data lines just happen to show whatever was last driven, which can be misleading when reading a bus trace.
  • Clear display instruction: sending an all-zero-except-last-bit instruction byte to the LCD clears its screen, useful for resetting cleanly instead of relying on the display's power-on blank state.

Walkthrough

Completing the RAM chip-select logic (0:00)

Building on part 6's partial RAM wiring, address line 14 is connected to the RAM's output enable pin, and the already-inverted A15 signal is combined with the clock signal through another NAND gate to drive the RAM's properly timed chip select.

Powering up and confirming the fix (4:02)

With the wiring complete, the unmodified subroutine-based program from part 5 is run again. This time it works, printing text to the LCD instead of failing, confirming that the missing RAM was indeed the root cause.

Single-stepping the working stack (6:04)

The Arduino bus monitor is reconnected to trace a full JSR call to the LCD-instruction subroutine and its matching RTS, showing the return address correctly written to and read back from $01FF/$01FE, in contrast to the broken behavior seen without RAM in part 5.

Adding a clear-display instruction (13:12)

Noting that resetting no longer clears a previously used LCD, the lecture looks up the LCD's clear-display instruction in the datasheet and adds it as another subroutine call at the start of the program, then reassembles and reprograms the EEPROM to confirm the screen clears properly on reset.

Before you watch

  • Watch part 5 (the stack failure) and part 6 (the initial RAM wiring) first, since this video directly resolves the problem they set up.
  • Familiarity with reading a single-stepped address/data bus trace, introduced in earlier videos, is assumed.

Check your understanding

  1. Why does the RAM's chip-select signal need extra timing logic instead of being driven directly by the address lines?
  2. What evidence in the bus trace confirms that the return address is now being correctly saved to and restored from the stack?
  3. Why can some values seen on the bus during certain clock cycles be misleading when tracing JSR and RTS?
  4. What instruction byte clears the LCD display, and why did the lecture add it to the initialization sequence?
  5. What change does the lecture plan for the next video regarding the computer's clock source?

Chapters

From the YouTube description

Schematics, kits, and more: https://eater.net/6502

Part 1: https://www.youtube.com/watch?v=LnzuMJLZRdU
Part 2: https://www.youtube.com/watch?v=yl8vPW5hydQ
Part 3: https://www.youtube.com/watch?v=oO8_2JJV0B4
Part 4: https://www.youtube.com/watch?v=FY3zTUaykVo
Part 5: https://www.youtube.com/watch?v=xBjQVxVxOxc
Part 6: https://www.youtube.com/watch?v=i_wrxBdXTgM
Part 7: This video!

Support these videos on Patreon: https://www.patreon.com/beneater or https://eater.net/support for other ways to support.

------------------

Social media:
Website: https://www.eater.net
Twitter: https://x.com/beneater
Patreon: https://patreon.com/beneater
Reddit: https://www.reddit.com/r/beneater

Special thanks to these supporters for making this video possible:
Adam Lininger, Adrien Friggeri, Alex Catchpole, Alexander Wendland, Andrew Miller, Andrew R. Whalley, Anthony Cuccia, Armin Brauns, Austin Grant, BakerStaunch, Beau-James Erion, Ben Dyson, Ben Kamens, Ben Williams, Bill Cooksey, Bradley Pirtle, Bryan Brickman, Carlos Ambrozak, Charles Haseltine, Christopher Blackmon, Clayton Parker Coleman, Daniel Jeppsson, Daniel Struthers, Daniel Tang, Dave Walter, David Boardman, David Brown, David Clark, David H. Friedman, David House, David Turner, Dean Winger, Debilu Krastas, Dirk Lentzen, Dmitry Guyvoronsky, Dušan Dželebdžić, Dzevad Trumic, Eric Brummer, Eric Busalacchi, Eric Dynowski, Eric Twilegar, Erik Broeders, Eugene Bulkin, Foaly, fxshlein, George Miroshnykov, Harry McDow, HaykH, Hidde de Jong, Ian Tait, Ingo Eble, Ivan Sorokin, Jason DeStefano, JavaXP, Jay Binks, Jayne Gabriele, Jeremy A., Jeremy Wise, Jimmy Campbell, Joel Jakobsson, Joel Messerli, Joel Miller, Joern Heidenreich, John Fenwick, John Meade, Jon Dugan, Jordan Scales, Joshua King, Kefen, Kent Collins, Lambda GPU Workstations, Lucas Nestor, Lukasz Pacholik, Maksym Zavershynskyi, Manne Moquist, Marcus Classon, Mats Fredriksson, Matt Alexander, Matteo Mohr, Matthäus Pawelczyk, Michael, Michael Burke, Michael Garland, Michael Tedder, Miguel Ríos, Nathan Wachholz, Nicholas Counts, Nicholas Moresco, Örn Arnarson, Örper Forilan, Paul Pluzhnikov, Paul Randal, Pete Dietl, Philip Hofstetter, Randy True, Ric King, Richard Wells, Rob Bruno, Robert Butler, Robert Diaz, Ross, Sachin Chitale, Sam Rose, Sam Soffes, Samuel E Joseph, Scott, Sergey Ten, SonOfSofaman, Stefan Nesinger, Stefanus Du Toit, Stephen Riley, Stephen Smithstone, Steve Jones, Steve Gorman, Steven Pequeno, Thomas Ballinger, Tom Burns, Vladimir Kanazir, Warren Miller, xisente, Ziggy L

← Part 6: RAM and bus timing · Why build an entire computer on breadboards? →