Skip to content

B side: Controlling the hardware

A cassette tape with a handwritten label: "B Side. Fortran, the language that speaks maths."

B B side · Fortran · The language that speaks maths

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

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

What Fortran says well here

  • Fortran does not depend on one machine. The same text works on many processors.
  • Fortran makes the numbers that the hardware needs, before the game runs. For sound, the divisor of each note is nint(1193182.0_real64 / f). The B side also reports the error of each note in cents.

What is hard to say

  • Fortran cannot talk to the hardware directly. It needs help from C or from assembly (through ISO_C_BINDING).

One sentence in Fortran

! Standard Fortran has no word for this.
use iso_c_binding

It says: Fortran asks a C or assembly routine to do the hardware work.

The words, by part of speech

Adjectives (1) · An attribute, for example ALLOCATABLE or PARAMETER.

WordMeaningExample
BIND(C)Make this procedure or type match the layout of the C language.subroutine vsync() bind(c)

Idioms (3) · A built-in function or subroutine, for example SQRT or MATMUL.

WordMeaningExample
SYSTEM_CLOCKRead the count of clock ticks.call system_clock(t0)
CPU_TIMERead the processor time that the program used.call cpu_time(t)
EXECUTE_COMMAND_LINEAsk the operating system to run a command.call execute_command_line('ls')

Note to the translators (2) · A structure word, for example PROGRAM, MODULE or CONTAINS.

WordMeaningExample
ISO_C_BINDINGA built-in module with the words to talk to C code, and through C, to the hardware.use iso_c_binding
ISO_FORTRAN_ENVA built-in module with exact sizes, for example INT32 and REAL64.use iso_fortran_env

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.