DYSTOPIANPIXEL

Next steps and checklist

Connect the lesson to Next Asset Lab and prepare for Tutorial 3.

Next Asset Lab concept artwork showing sprite patterns, palette colours and animation frames
Next Asset Lab concept artwork · Begin with Odin Dev.2k and the foundations of Z80 assembly.
TUTORIAL 2 / PART 18

Connecting the lesson to the real Next Asset Lab

We now have four important building blocks: decision (CP plus a branch), repetition (DJNZ), delegation (CALL / RET) and preservation (PUSH / POP). These are the foundations for writing the resident core, the input dispatcher, file helpers, drawing tools, and later modules defined in the Product Requirements & Architecture v1.0.

This tutorial does not modify that frozen architecture. The current helper is an educational candidate, not a new design requirement. What will carry over immediately is the development discipline: give every routine a clear entry point, document its inputs and side effects, maintain stack balance on every path, test boundary conditions, and keep Odin-native source alongside a plain-text export.

When we begin integrating modules, we will document both the source path and the test that proved the routine worked. We will not assume any unverified Odin directive or silently invent a NextZXOS ABI. The architecture’s resident core, MMU windows and adaptive bank allocation remain for their assigned later tutorials.

Why we do not make a NEX yet

The frozen roadmap places the first NEX and packaging workflow in Tutorial 3. That order is deliberate. We need a grasp of programme entry points, subroutine calls and register preservation before writing a startup framework which must interact safely with the environment. Tutorial 3 will have to confirm an actual deterministic NEX packaging tool/workflow rather than pretending Odin’s A command already produces a distributable NEX.

Mini-glossary

UnsignedInterpreting an 8-bit pattern as a number from 0 to 255
Signed two’s-complementInterpreting an 8-bit pattern as a number from −128 to +127
Carry / borrowCondition recorded in C by appropriate arithmetic or comparison
OverflowArithmetic result lies outside the chosen signed range
Compare (CP)Test A against a value by updating flags without changing A
Conditional branchJump only if a specified flag condition is true
Fall-throughExecution continues into the next sequential instruction
LoopInstructions repeated until a condition is met
DJNZDecrement B, then jump if B is not zero
StackMemory used in last-in, first-out order
SPStack Pointer, locating the top of the stack
CALLEnter a subroutine while saving the return address
RETPop a saved return address into PC to return
PUSH / POPSave and recover a 16-bit register pair on the stack
Calling contractDocumented inputs, outputs, changed registers and return behaviour
ABIApplication Binary Interface: the detailed rules governing calls across interfaces

Completion checklist

  • ☐ I can distinguish signed and unsigned interpretations of the same byte.
  • ☐ I understand why Carry and signed Overflow are not interchangeable.
  • ☐ I can use CP and predict the Zero or Carry condition for simple unsigned values.
  • ☐ I can explain why a conditional branch takes one path and skips another.
  • ☐ I know that labels name positions; they do not end a block automatically.
  • ☐ I can trace a three-iteration DJNZ loop.
  • ☐ I understand that the stack is memory and SP changes as values are pushed and popped.
  • ☐ I can describe exactly what CALL saves and what RET restores.
  • ☐ I can save and restore BC without leaving the stack unbalanced.
  • ☐ I can read a basic routine’s input/output and register-preservation contract.
  • ☐ I can assemble, inspect, run and export the final Odin example.
  • ☐ I know that the final helper is not yet a validated production NEX module.

Publication and hardware-check record

Before marking the website version as hardware-verified, work through both Tutorial 1 and Tutorial 2 in order on the real Next. For this tutorial, ensure that the flags, signed comparisons, both JR decision paths, DJNZ, CALL/RET, PUSH/POP, BC preservation and all six clamp test inputs behave as predicted. Capture the Odin version and exact results, rather than copying expected values into the results column.

Summary and what comes next

This tutorial turned a tiny sequence of instructions into a structured Z80 programme. We learned to compare without destroying A, branch according to flags, repeat work with a counter, call a subroutine and return using the stack. We saw how a caller’s register values can be protected, and why a small routine needs an explicit contract. Finally, we wrote a boundary-tested nibble clamp helper and used Odin to connect source, symbols, machine code and observable register results.

The next chapter in the frozen 38-step roadmap is Tutorial 3 — Building the First NEX. We will then move from Odin-run teaching routines to a minimal application image with a documented entry point, a safe execution/exit strategy and a reproducible packaging stage. NEX packaging choices and tool syntax will be verified for the actual Next environment before we ask anyone to type build commands.