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:
- Line
2: InitializeC$="Y"as a sentinel to skip theINPUTat line40on the very first pass, using the value already inA$(or whatever the runtime provides). - Lines
10–50: Clear screen, print header, and accept a channel identifier. IfC$is not a letter (i.e., it came from INKEY$ being a digit or “Y”), the program skips theINPUT LINEat line40and usesC$directly asA$. - Lines
60–200: Determine channel type. If the first character’s CODE is above 64 (ASCII ‘A’), it’s a letter-coded cable channel; otherwiseVAL A$gives a numeric channel, and a chain of range checks dispatches to the correct base-channel/base-frequency pair. - Lines
300–360: Handle letter-coded cable channels (A–Z maps to channels 14–39 usingCODE - 51), classifying them as Mid Band or Super Band. - Lines
400–540: Shared frequency computation and display block. - Lines
550–580: “More?” prompt using INKEY$ polling; loops back to line10unless “N” is pressed. - Line
600: Error handler for invalid channels. - Lines
700–730: REM-commented alternative formulas for converter-based IF setups. - Line
9999:GO TO VAL "80"— targets non-existent line 80, a known memory-optimization idiom usingVALfor the literal.
Channel Band Dispatch Table
| Channel Range | Band | Base Channel (BC) | Base Freq (BF, MHz) |
|---|---|---|---|
| 2–4 | VHF Low | 2 | 54 |
| 5–6 | VHF Low (high) | 5 | 76 |
| 7–13 | VHF High | 7 | 174 |
| 14–83 | UHF | 14 | 470 |
| A–M (cable Mid Band) | Cable Mid | 14 | 120 |
| N–Z (cable Super Band) | Cable Super | 23 | 216 |
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 MHzUB = LB + 6— upper band edgeFV = LB + 1.25— picture (video) carrierFC = 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 IFIL = UB + 41*2andIU = 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
150checksIF B$(1)="C"for “Cable,” but numeric channels 5–13 also reach line140‘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
360setsBC=14andBF=120but does not include aGO TO 400; it falls through naturally since line400is the next line. This works correctly but could be confused for a missing branch. - Line
440:IL = UB + 41*2andIU = LB + 47*2. The image frequency for a superheterodyne receiver isLO + 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‘sGO 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.
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.
