Z80 Assembly 74: Displaying a Full Screen Image (Loading Graphics Data)

The Full Screen Data Load To display a custom image on the Spectrum (e.g., a title screen or game level background), you must copy two large blocks of data from your program’s memory into the Spectrum’s Display File RAM. The Two Blocks: Pixel Data: 6144 bytes of raw $256 \times 192$ pixel information (starts at `4000H′). Attribute Data: 768 bytes of color and flash information (starts at `5800H′). Routine 1: Loading the Pixel Data The Pixel Data is 6144 bytes long. Since the data layout is non-linear (Part 73), you generally copy the data block-by-block. However, if your source data is already arranged in the Spectrum’s non-linear format, you can use the fastest method: `LDIR′. ...

September 28, 2025

Z80 Assembly 73: The Non-Linear Screen Memory Calculation

The Challenge of the Spectrum Screen The ZX Spectrum screen memory is not linear. To save on hardware costs, the memory map was designed to simplify the display hardware’s access but complicate the CPU’s access. The Layout: The screen is divided into three major vertical bands, and within each band, the lines are interleaved. This means to find the address of the pixel at (X, Y), you must perform a complex, multi-step calculation. ...

September 28, 2025

Z80 Assembly 45: Software Sprite Scaling and Rotation

The Challenge of Geometric Transformations The Z80 has no native support for the complex trigonometric math needed for rotation, nor does it have floating-point math for precise scaling. All geometric transformations must be calculated using fixed-point math and look-up tables (LUTs). Sprite Scaling (Zooming) Scaling a sprite involves sampling the source image at mathematically calculated intervals and writing the result to the screen. The Principle: To double the size of a sprite (Scale Factor = 2), you read every $1^{st}$ pixel from the source and draw it twice on the screen, both horizontally and vertically. ...

September 27, 2025

Z80 Assembly 44: Sprite Multiplexing and Display Lists

The Limitation: Hardware Sprite Count Many systems with dedicated sprite hardware (like the MSX or certain arcade boards) have a severe limit on the number of sprites that can be displayed on a single horizontal scanline (e.g., 8 or 16 sprites). Exceeding this limit causes sprites to disappear or flicker. The Solution: Sprite Multiplexing Sprite Multiplexing is a software technique that dynamically reuses the hardware’s limited number of sprite slots multiple times per frame. The goal is to quickly change the sprite’s position and pattern as the display beam moves down the screen. ...

September 27, 2025

Z80 Assembly 36: Rendering Large Worlds with Tilemaps

The Tilemap Concept A tilemap is a technique that breaks a large game world (the map) into small, reusable graphic squares (tiles), typically $8\times 8$ or $16\times 16$ pixels. Why Tilemaps are Essential: Memory Saving: Instead of storing the pixel data for the entire map, you only store the data for a small set of unique tiles (the tileset) and then store the map itself as a small array of tile IDs (indices). Fast Rendering: The CPU can draw the screen by reading the tile ID from the map and using that ID as an index to quickly look up and draw the corresponding tile graphic. The Map Data Structure The map data is a simple, linear array stored in memory. ...

September 27, 2025

Z80 Assembly 27: Horizontal and Vertical Scrolling (Fast Block Moves)

The Challenge of Scrolling Creating the illusion of movement across a large background map (scrolling) is a major performance challenge for 8-bit CPUs. You must shift thousands of bytes of screen memory every single frame. Slow code will cause a noticeable flicker or lag. The Solution: LDIR The Z80’s LDIR (Load, Increment, Repeat) instruction is the fastest tool for this job. It executes much faster than any software loop built with LD, INC, DEC, and JP. ...

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 24: Color and Attributes (Manipulating Screen Appearance)

The Need for Attribute Memory On many Z80 retro systems (such as the ZX Spectrum), the screen display is split into two distinct areas of memory: Pixel Data: Where the bits defining the shape of the image (the ‘black’ or ‘white’ dots) are stored. Attribute Data: Where the bits defining the appearance (color, brightness, flash) of the image are stored. This separation is necessary to save memory, as one attribute byte typically controls the appearance of an entire $8\times 8$ block of pixels. ...

September 27, 2025

Z80 Assembly 23: Graphics and Pixel Plotting (Bitwise Drawing)

The Screen Memory Layout On a bitmap Z80 system (like the ZX Spectrum), the screen is a large array of memory where each byte controls a group of 8 horizontal pixels. To plot a single pixel at coordinate (X, Y), you need two things: Memory Address: The 16-bit address of the byte that contains the pixel. Bit Mask: A byte with a single bit set (10000000B, 01000000B, etc.) to isolate the target pixel within that byte. Step 1: Calculating the Byte Address The calculation for the byte address is highly complex and specific to each system’s memory layout. It typically involves combining the Y-coordinate (row) and the X-coordinate (column). ...

September 27, 2025