TV Channel

Date: 198x
Type: Program
Platform(s): TS 2068

This program calculates the frequency parameters for US television channels, covering VHF (channels 2–13), UHF (channels 14–83), and cable TV bands. Given a channel number or letter-coded cable designator, it computes the lower and upper band-edge frequencies, picture carrier, color subcarrier (3.58 MHz offset), sound carrier (4.5 MHz offset), local oscillator frequency, and image frequencies assuming a 41–47 MHz IF strip. The program branches on whether the input is numeric or alphabetic to handle over-the-air versus cable channels, and prompts the user whether a given channel is UHF or cable when ambiguity exists. REM statements at lines 700–730 document an alternate formulation for converter-based setups with a different IF output channel.

Program Structure

The program is organized as a top-level input/dispatch loop with frequency calculation in a shared computation block. Execution flows as follows:

  1. Line 2: Initialize C$="Y" as a sentinel to skip the INPUT at line 40 on the very first pass, using the value already in A$ (or whatever the runtime provides).
  2. Lines 10–50: Clear screen, print header, and accept a channel identifier. If C$ is not a letter (i.e., it came from INKEY$ being a digit or “Y”), the program skips the INPUT LINE at line 40 and uses C$ directly as A$.
  3. Lines 60–200: Determine channel type. If the first character’s CODE is above 64 (ASCII ‘A’), it’s a letter-coded cable channel; otherwise VAL A$ gives a numeric channel, and a chain of range checks dispatches to the correct base-channel/base-frequency pair.
  4. Lines 300–360: Handle letter-coded cable channels (A–Z maps to channels 14–39 using CODE - 51), classifying them as Mid Band or Super Band.
  5. Lines 400–540: Shared frequency computation and display block.
  6. Lines 550–580: “More?” prompt using INKEY$ polling; loops back to line 10 unless “N” is pressed.
  7. Line 600: Error handler for invalid channels.
  8. Lines 700–730: REM-commented alternative formulas for converter-based IF setups.
  9. Line 9999: GO TO VAL "80" — targets non-existent line 80, a known memory-optimization idiom using VAL for the literal.

Channel Band Dispatch Table

Channel RangeBandBase Channel (BC)Base Freq (BF, MHz)
2–4VHF Low254
5–6VHF Low (high)576
7–13VHF High7174
14–83UHF14470
A–M (cable Mid Band)Cable Mid14120
N–Z (cable Super Band)Cable Super23216

Frequency Calculation Block

Lines 400–540 contain the core math. All US analog TV channels are 6 MHz wide, so:

  • LB = BF + (C - BC) * 6 — lower band edge in MHz
  • UB = LB + 6 — upper band edge
  • FV = LB + 1.25 — picture (video) carrier
  • FC = FV + 3.58 — color subcarrier (NTSC 3.579545 MHz offset from picture carrier)
  • FA = FV + 4.5 — sound carrier (standard 4.5 MHz FM intercarrier offset)
  • FL = LB + 47 — local oscillator frequency, placing the picture carrier at 45.75 MHz IF
  • IL = UB + 41*2 and IU = LB + 47*2 — image frequency range for a 41–47 MHz IF strip

Input Handling Idioms

Line 2 pre-loads C$="Y" so that the conditional at line 31 (IF C$<"A") is false on the first run, causing the program to fall through to INPUT LINE A$. On subsequent iterations, C$ holds the INKEY$ result from the “More?” prompt; if the user pressed a digit key, the condition routes directly to line 50, reusing that keypress as the channel. This is a compact but somewhat fragile reuse of the loop variable.

Line 31 uses IF C$<"A" to distinguish digit characters (codes 48–57) from letters (codes 65+). Since “Y” has a code of 89, the first-run sentinel correctly falls through to INPUT LINE.

INKEY$ polling loops appear at lines 145 and 560, the standard busy-wait keypress idiom.

Cable Channel Letter Mapping

At line 310, the formula C = A - 51 converts a letter’s character code to a cable channel number. For ‘A’ (code 65), this gives channel 14; for ‘Z’ (code 90), channel 39. The boundary check at line 300 (IF A>90) limits valid letters to A–Z. The Mid/Super Band boundary is set at cable channel 23 (letter ‘N’, code 78), matching the standard US cable TV band plan.

Bugs and Anomalies

  • Line 150 checks IF B$(1)="C" for “Cable,” but numeric channels 5–13 also reach line 140‘s UHF/Cable prompt. Pressing anything other than “C” routes to UHF handling regardless of what letter was typed, with no validation.
  • The Mid Band cable path at line 360 sets BC=14 and BF=120 but does not include a GO TO 400; it falls through naturally since line 400 is the next line. This works correctly but could be confused for a missing branch.
  • Line 440: IL = UB + 41*2 and IU = LB + 47*2. The image frequency for a superheterodyne receiver is LO + IF, so image = signal + 2×IF. Using upper-band-edge plus 2×41 for the lower image limit and lower-band-edge plus 2×47 for the upper image limit is intentionally conservative (worst-case image window), not an error.
  • Line 9999‘s GO TO VAL "80" targets line 80, which does not exist; the program never normally reaches this line.

REM Documentation

Lines 700–730 contain detailed REM comments explaining how to adapt lines 430–510 for a cable converter box scenario where the receiver’s IF is tuned to a specific output channel rather than the standard 41–47 MHz strip. This is unusually thorough inline documentation for a BASIC program of this length.

Image Gallery

Source Code

    2 LET C$="Y"
   10 CLS :PRINT "TV CHANNEL FREQUENCY DIRECTORY"
   20 PRINT "******************************"
   30 PRINT "ENTER TV CHANNEL: ";
   31 IF C$<"A" THEN LET A$=C$:GO TO 50
   40 INPUT  LINE A$
   50 PRINT A$
   60 LET A= CODE A$:IF A>64 THEN GO TO 300
   70 LET C= VAL A$
  100 IF C<2 THEN GO TO 600
  110 IF C<5 THEN GO TO 200
  120 IF C<7 THEN GO TO 190
  130 IF C<14 THEN GO TO 180
  140 PRINT #0;"UHF OR CABLE? ";
  145 LET B$= INKEY$:IF B$="" THEN GO TO 145
  147 PRINT #0;B$
  150 IF B$(1)="C" THEN GO TO 320
  160 IF C>83 THEN GO TO 600
  170 LET BC=14:LET BF=470:GO TO 400
  180 LET BC=7:LET BF=174:GO TO 400
  190 LET BC=5:LET BF=76:GO TO 400
  200 LET BC=2:LET BF=54:GO TO 400
  300 IF A>90 THEN GO TO 600
  310 LET C=A-51:PRINT A$;" =CABLE CH# ";C
  320 IF C>40 THEN GO TO 600
  330 IF C<23 THEN PRINT "MID BAND CHANNEL":GO TO 360
  340 PRINT "SUPER BAND CHANNEL"
  350 LET BC=23:LET BF=216:GO TO 400
  360 LET BC=14:LET BF=120
  400 LET LB=BF+(C-BC)*6
  410 LET UB=LB+6
  420 LET FV=LB+1.25:LET FC=FV+3.58:LET FA=FV+4.5
  430 LET FL=LB+47
  440 LET IL=UB+41*2:LET IU=LB+47*2
  450 PRINT "FREQUENCY RANGE= ";LB;" TO ";UB;" MHz"
  460 PRINT "PIX CARRIER= ";FV;" MHz"
  470 PRINT "COLOR CARRIER= ";FC;" MHz"
  480 PRINT "SOUND CARRIER= ";FA;" MHz"
  490 PRINT "NOTE: THE FOLLOWING"
  500 PRINT "ASSUMES A RECEIVER"
  510 PRINT "WITH A 41-47 MHz I.F."
  515 PRINT "(41.25 MHz SOUND, 45.75 MHz PIX)"
  520 PRINT "LOCAL OSCILLATOR= ";FL;" MHz"
  540 PRINT "IMAGE RANGE= ";IL;" TO ";IU;" MHz"
  550 PRINT #0;"MORE?";
  560 LET C$= INKEY$:IF C$="" THEN GO TO 560
  570 IF C$ <>"N" THEN GO TO 10
  580 STOP 
  600 PRINT "NON-EXISTENT CHANNEL":GO TO 550
  700 REM 430LET FL=ABS (LB-(OUTPUT CHANNEL LOWER RANGE LIMIT)
  710 REM 440LET IL=ABS (LB-(OUTPUT CHANNEL LOWER RANGE LIMIT)*2):LET IU=ABS (UB-(OUTPUT CHANNEL UPPER RANGE LIMIT)*2)
  720 REM 500PRINT "IS FOR A CONVERTER"
  730 REM 510PRINT "WITH AN OUTPUT ON CHANNEL (NUMBER OF OUTPUT CHANNEL)" DELETE LINE 515
 9989 STOP 
 9992 REM PRINT USR 100:SAVE "TVCHNL.B1" LINE 1
 9998 REM PRINT USR 100:LOAD "L.B1"
 9999 GO TO VAL "80"

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.