Skip to content

A side: Controlling the hardware

A cassette tape with a handwritten label: "A Side. Assembly - the first language of the machine."

A A side · Assembly · The first language of the machine

How do you talk to the screen, the keyboard chip and the clock directly?

12 Assembly words in this segment
6 Fortran words for the same job

What Assembly says well here

  • This is the native tongue of the processor. Ports, interrupts and screen memory are all in reach.
  • It is the best tool to make a retro game fast and responsive.
  • The helper chips of the PC speak through ports, and the order of the writes is the protocol. To play a note: the command byte B6h to port 43h, then the two bytes of the divisor to port 42h, then bits 0 and 1 of port 61h. A wrong order gives a wrong note or silence.

What is hard to say

  • Each processor family speaks a different dialect. 8086 words do not work on an ARM processor.
  • One frame at 70 Hz gives a 4.77 MHz 8086 about 68,000 clock cycles. A fill of the full screen with REP STOSB costs about 640,000. Plan the picture before you draw it.
  • The VGA has no HDMA, no sprites and no color math. Mode 13h has one page. Mode X has more than one page (four at 200 lines, three at 240 lines), a start address for page flips, and a line compare for a fixed status bar. A per-line effect is work for the 8086 itself, or it does not happen.

One sentence in Assembly

mov dx, 3DAh
vsync: in al, dx
test al, 8
jz vsync

It says: Wait until the screen beam starts its return to the top (vertical retrace).

The words, by part of speech

Verbs (6) · An instruction: one step that the processor does, for example MOV or ADD.

WordMeaningExample
INRead a value from a hardware port.in al, dx
OUTWrite a value to a hardware port.out dx, al
CLIStop hardware interrupts for a short time.cli
STILet hardware interrupts start again.sti
IRETReturn from an interrupt handler.iret
HLTStop the processor until the next interrupt.hlt

Nouns (6) · A register, a flag, a port or a place in memory, for example AX.

WordMeaningExample
portA numbered door to a hardware device. The processor talks to devices through ports.in al, 60h
interruptA signal that stops the program for a moment, runs a handler, then lets the program continue.
A000hThe segment of the VGA screen memory in Mode 13h. Each byte is one pixel.mov ax, 0A000h
3DAhThe VGA status port. Bit 3 is 1 while the screen beam returns to the top (vertical retrace).mov dx, 3DAh
3C8h / 3C9hThe VGA palette ports. Select a color number, then write its red, green and blue parts.mov dx, 3C8h
INT 09hThe keyboard interrupt. A game replaces its handler to read keys fast.

Watch out: what the review found

These notes come from the review of the AI-written guides. They show traps that are easy to miss.

  • D02-C4 critical (a) Mode 13h runs at 70 Hz. Thus a game locked to vsync gets 70 or 35 fps, not a locked 60. (b) Mode 13h has one page, thus page flipping is not possible. A copy of 64,000 bytes in the ~1 to 1.5 ms vertical blank is not possible over ISA. As a result, tearing becomes less, but it does not stop. Flipping without tears needs Mode X (L11 mentions it, but the roadmap does not use it). (c) The figure in the document (L70), 3.84 MB/s, is more than many 8/16-bit ISA VGA cards can supply.
  • D02-M8 major 86Box tries to be cycle-accurate. DOSBox-X does not (it uses approximate "cycles"). This is important because performance tuning in DOSBox-X will not match real hardware.
  • D02-M1 major This is true for 8-bit systems in the 1980s. It is false for the PC in the early 1990s. At that time, C with assembly inner loops was the norm (for example, id Software titles). The source is a Reddit thread [1].
  • D15-C3 critical The video shows the parallax on the title screen, not in the game [34:08]. The HDMA writes the "background two horizontal scroll register" [35:31], which is $210F (BG2HOFS), not $2111. The table has three bytes per entry: a line count and a two-byte value [35:51]. All band limits, speeds and pixel values on the page are invented. The video names no line numbers. The CPU must build the table and re-enable the channel every frame [36:11], and HDMA itself takes bus cycles from the CPU. The BG3 layer in the game is black tiles [37:13], not mountains. The slider models a screen that does not exist.
  • D14-M5 major The four addresses $2140 to $2143 are correct. But the video stresses that these are "eight separate registers" (12:28 to 12:48): four per direction, so a write on one side does not erase the value of the other side. The handshake of the boot ROM ($AA and $BB on ports 0 and 1, address on ports 2 and 3, then $CC, 12:48 to 13:48) is the main content of the audio part, and the document omits it. The "16-bit DSP" label at L92 is not in the video.