Z80 Assembly 42: Interfacing with a Real-Time Clock (RTC) Chip

The Need for a Real-Time Clock The Z80’s internal clock is only useful for instruction timing. It cannot track actual time (hours, minutes, days). A Real-Time Clock (RTC) is a separate, dedicated chip (like the DS1307 or MC146818) that contains its own crystal oscillator and often a small battery to maintain time even when the main computer is powered off. Communication: Indexed I/O The Z80 communicates with an RTC chip using a method called indexed I/O (similar to how the AY sound chip works). The RTC has a set of internal registers (e.g., 0-12) that store the seconds, minutes, hours, day, date, and control flags. ...

September 27, 2025

Z80 Assembly 25: Timing the Frame Rate (VSync) for Smooth Animation

The Problem: Screen Tearing If your Z80 code draws objects to the screen while the video hardware is actively reading and displaying that part of memory, you get a visual artifact called screen tearing (a horizontal break in the image). The Solution: VSync (Vertical Synchronization) Vertical Synchronization, or VSync, is the process of waiting until the video beam has finished drawing the current frame and is resetting to the top of the screen (the Vertical Blanking Interval, or VBI). By drawing only during the VBI, you ensure the user never sees partially rendered frames. ...

September 27, 2025

Z80 Assembly 18: Optimizing for T-States (Clock Cycles)

The T-State: Your Ultimate Performance Metric In Z80 programming, the speed of your code isn’t measured in lines, but in T-states (or clock cycles). Every instruction takes a precise, fixed number of T-states to execute. To write fast code, you must choose instructions that minimize this count. Why T-States Matter: If your Z80 runs at 3.5 MHz (as in the ZX Spectrum), 3,500,000 T-states happen every second. A faster instruction in a critical loop can save dozens of T-states every frame, leading to smoother graphics or faster game logic. ...

September 27, 2025

Z80 Assembly 15: Timers, Delays, and the Refresh Register (R)

Creating Software Delay Loops Since the Z80 runs at a fixed clock speed, you can create a precise time delay by executing a loop a fixed number of times, knowing the exact number of clock cycles each instruction takes. The Delay Routine: A delay routine typically uses nested loops and relies on the DJNZ instruction, as it’s efficient for looping. Example: Basic 16-bit Delay Loop This example uses the BC register pair for a longer delay (B for the outer loop, C for the inner loop). ...

September 27, 2025