Branch tables
Programming Features - Command Branch Tables
Branch Tables
Command Branches
The table below cross-references the main prompt command keys, their internal command numbers, and where they branch.
When a user presses a key at the main prompt, Color 64 does not immediately jump to a routine based on the key itself. Instead, it performs a lookup:
- The pressed key is first converted to its ASCII value.
- The program searches the array CM%(I,1), which stores the ASCII value for each defined command key.
- When a match is found, the corresponding array position becomes the command number in I.
- The caller's access level is then checked against CM%(I,2), which stores the required level for that command.
- If the key is valid and the caller has access, the value in I is then used by the branch tables beginning at line 13160.
In the table below, the value shown under No. is the command number ultimately stored in I.
How the ON GOTO branch tables work
The series of ON GOTO statements beginning at line 13160 is easier to understand if you think of it as a two-step dispatcher.
First, line 13160 chooses which group of commands is being handled. The commands are grouped into blocks of ten:
- 0 to 9
- 10 to 19
- 20 to 28
- 30 to 39
- 40 to 42
Line 13160 does not jump directly to the final command routine. Instead, it jumps to the correct branch table for that group.
For example:
- ON I/10+1 GOTO 13170,13180,13190,13195,13197
If I=7, then I/10+1 evaluates to 1, so BASIC branches to line 13170, which handles commands 0 to 9.
If I=24, then I/10+1 evaluates to 3, so BASIC branches to line 13190, which handles commands 20 to 28.
Once inside the proper group, a second ON GOTO chooses the exact destination within that group. Example:
- 13170 ON I+1 GOTO 13202,13205,13210,13220,92,92,92,92,96,13260
This line handles command numbers 0 through 9. BASIC uses I+1 because ON GOTO counts from 1, while the command numbers begin at 0.
So, if I=0, BASIC takes item 1 in the list and branches to 13202. If I=1, it takes item 2 and branches to 13205. If I=4, it takes item 5 and branches to 92.
The same idea is used for the later ranges, except the program subtracts an offset so the numbering again starts at 1 for that range:
- ON I-9 GOTO ... handles 10 to 19
- ON I-19 GOTO ... handles 20 to 28
- ON I-29 GOTO ... handles 30 to 39
- ON I-39 GOTO ... handles 40 to 42
This is why the branch tables can look confusing at first glance. They are not testing the key directly. They are using the command number in I, first to select the correct table, then to select the correct destination within that table.
Example
Using the code below:
13140 FOR I=. TO 42:IF ASC(A$)<>CM%(I,1) NEXT:GOSUB995:@ 13145 @I=29 OR LV<CM%(I,2) OR I>39 AND M3=. 13150 #:GOSUB8004 13160 ON I/10+1 GOTO13170,13180,13190,13195,13197 13170 ON I+1 GOTO13202,13205,13210,13220,92,92,92,92,96,13260 13180 ON I-9 GOTO96,96,13290,96,96,96,13330,96,13360,13370 13190 ON I-19 GOTO92,13375,96,92,96,96,96,92,92 13195 ON I-29 GOTO35651,35652,96,98,100,96,96,96,96,96 13197 ON I-39 GOTO102,88,88
If the user presses P:
- the search finds P in the command array
- I becomes 2
- line 13160 branches to 13170 because command 2 is in the 0 to 9 range
- line 13170 evaluates ON I+1, which becomes ON 3
- BASIC takes the 3rd item in that list, which is 13210
That is the mini-routine for the [P]ost a Public Message command.
If the user presses 3:
- I=32
- line 13160 branches to 13195
- line 13195 evaluates ON I-29, which becomes ON 3
- BASIC takes the 3rd item in the list, which is 96
Line 96 is an overlay loader, so command 32 is not handled locally in that overlay and must be relayed elsewhere.
| Key | No. | Key | No. | |
|---|---|---|---|---|
| @ | 1 | N | 22 | |
| P | 2 | X | 23 | |
| S | 3 | T | 24 | |
| $ | 4 | L | 25 | |
| D | 5 | + | 26 | |
| # | 6 | Z | 27 | |
| U | 7 | <blank> | 29 | |
| ! | 8 | 1 | 30 | |
| F | 9 | 2 | 31 | |
| C | 10 | 3 | 32 | |
| A | 11 | * | 33 | |
| O | 12 | 5 | 34 | |
| G | 13 | 6 | 35 | |
| H | 14 | 7 | 36 | |
| W | 15 | 8 | 37 | |
| M | 16 | 9 | 38 | |
| I | 17 | % | 39 | |
| E | 18 | = | 40 | |
| ↑ | 19 | & | 41 | |
| > | 20 | - | 42 | |
| < | 21 |
For commands that are in the currently loaded overlay, the ON GOTO usually branches to a short intermediary routine, or "mini-routine", in the line range 13200 to 13480. That mini-routine normally performs a GOSUB to the actual command routine, then does a GOTO 13100 to return to the main prompt.
This extra step exists because some command routines are also called from other places, such as the SYSOP menu. In those cases, the routine must perform its work without always forcing a return to the main prompt. The mini-routine provides a standard entry path for main-prompt commands while still allowing the underlying routine to be reused elsewhere.
The line numbers for these mini-routines are listed in the table below under the heading Mini.
Overlay Cross-Reference
The actual command routines are usually located in various places throughout the overlays. Sometimes an entire command is not fully contained in one overlay. For example, the [A]lter Password command must eventually branch to √bbs.init to change the password. In the table below, the overlay listed is the first overlay branched to. For the Alter Password command, that first destination is √bbs.ovl. The line numbers for the true underlying routines are listed under Actual.
Commands not present in the current overlay are sent to one of the overlay loader lines, which exist at lines 88 to 103. These lines load the overlay in which the command actually resides. The loader line is shown under Load, and the overlay abbreviation is shown under Overlay.
Before loading the new overlay, the variable OV is set so that the newly loaded overlay knows where to branch once loaded. Usually this is set to 1 automatically when the standard loader lines are used, because most overlays reserve OV=1 for a command relayed from another overlay.
Once the new overlay is loaded, the value in I is used again by the branch tables beginning at line 13160. In this way, the command number is preserved even though the command has been handed off to another overlay.
Sometimes the OV setting is not 1. This usually occurs in overlays that do not have a normal main prompt of their own, such as √bbs.init. In those cases, the loader must set a different OV value so the receiving overlay enters the correct routine.
| Key | No. | Mini | Actual | Overlay | Load | OV | Function |
|---|---|---|---|---|---|---|---|
| R | 0 | 13202 | 3005 | MSGS | 90 | 1 | Read Public Messages |
| @ | 1 | 13205 | 3710 | MSGS | 90 | 1 | Post Office |
| P | 2 | 13210 | 1260 | MSGS | 90 | 1 | Post a Public Message |
| S | 3 | 13220 | 4005 | MSGS | 90 | 1 | Scratch a Public Message |
| $ | 4 | 13230 | 405 | XFER | 92 | 1 | View Download Directory |
| D | 5 | 13240 | 16505 | XFER | 92 | 1 | Download File(s) |
| # | 6 | 13245 | 16110 | XFER | 92 | 1 | Choose a Download Directory |
| U | 7 | 13250 | 16300 | XFER | 92 | 1 | Upload a File |
| ! | 8 | 13255 | 27005 | OVL | 96 | 1 | Edit User Stats |
| F | 9 | 13260 | 7010 | MSGS | 90 | 1 | Feedback to Sysop |
| C | 10 | 13270 | 15002 | OVL | 96 | 1 | Chat with the Sysop |
| A | 11 | 13280 | 13735 | OVL | 96 | 1 | Alter Password |
| O | 12 | 13290 | 19010 | OVL | 96 | 1 | Log off System |
| G | 13 | 13295 | 13910 | OVL | 96 | 1 | Select Graphics/ASCII/ANSI |
| H | 14 | 13300 | 17015 | OVL | 96 | 1 | View Help Files |
| W | 15 | 13310 | 13310 | OVL | 96 | 1 | View Welcome Files |
| M | 16 | 13330 | 19510 | MSGS | 90 | 1 | View Membership List |
| I | 17 | 13350 | 13350 | OVL | 96 | 1 | View Information File |
| E | 18 | 13360 | 5010 | MSGS | 90 | 1 | Edit a Public Message |
| . | 19 | 13370 | 24005 | INIT | 95 | 2 | Set Date & Time |
| > | 20 | 13372 | 22010 | XFER | 92 | 1 | DOS Wedge |
| < | 21 | 13375 | 20010 | INIT | 95 | 7 | Password Maintenance |
| N | 22 | 13377 | 15505 | OVL | 96 | 1 | New Downloads |
| X | 23 | 13380 | 13810 | XFER | 92 | 1 | Scratch a Download |
| T | 24 | 13385 | 17010 | XFER | 96 | 1 | Text Files Area |
| L | 25 | 13380 | 8110 | OVL | 96 | 1 | View Caller Log |
| + | 26 | 13400 | 35020 | OVL | 96 | 1 | Multi-Upload |
| Z | 27 | 13410 | 13710 | XFER | 92 | 1 | Edit Download Description |
| Y | 28 | 13420 | 14010 | XFER | 92 | 1 | Release a Download |
| 1 | 30 | 13430 | 14310 | MSGS | 90 | 1 | Spare Command 1 (8.1a Games) |
| 2 | 31 | 13440 | 13440 | XFER | 92 | 1 | Spare Command 2 (8.1a User Profile) |
| 3 | 32 | 13450 | 13450 | OVL | 96 | 1 | Spare Command 3 |
| * | 33 | 13455 | 2000 | OV2 | 98 | 1 | Spare Command 4 (Mod Menu) |
| 5 | 34 | 13460 | OV3 | 100 | 1 | Spare Command 5 | |
| 6 | 35 | 13465 | 13465 | OVL | 96 | 1 | Spare Command 6 |
| 7 | 36 | 13470 | 13470 | OVL | 96 | 1 | Spare Command 7 |
| 8 | 37 | 13475 | 13475 | OVL | 96 | 1 | Spare Command 8 |
| 9 | 38 | 13480 | 13480 | OVL | 96 | 1 | Spare Command 9 |
| % | 39 | 13425 | 16050 | OVL | 96 | 1 | Select Transfer Protocol |
| = | 40 | 14005 | NW1 | 102 | 1 | Network Post | |
| & | 41 | 34010 | NW2 | 88 | 1 | Network Maintenance Menu | |
| - | 42 | 9010 | NW2 | 88 | 1 | Release Network Messages | |
| ? | -- | 13010 | All | Main BBS Menu |
The Overlay Loader Lines
The table below defines the standard main overlay loader lines. Some of these lines are not present in every overlay because they may not be needed.
| Line | Overlay | Line | Overlay | |
|---|---|---|---|---|
| 89 | √bbs.nw2 | 97 | √bbs.ovl | |
| 91 | √bbs.msgs | 99 | √bbs.ov2 | |
| 93 | √bbs.xfer | 101 | √bbs.ov3 | |
| 95 | √bbs.init | 103 | √bbs.nw1 | |
| 35651 | √bbs.games | 35652 | √bbs.profile |
In overlays that have a main prompt, there is usually a line immediately before each loader line that sets OV=1. For example, to set OV=1 and load the √bbs.msgs overlay, use GOTO 90, which is one line before 91.
Individual Overlay Branching
The following sections describe how each overlay behaves depending on the setting of OV when the overlay is loaded. The path of GOTOs, GOSUBs, and overlay jumps is listed in a shorthand format.
Example path from √bbs.nw1:
OV=3 : 50, (12010), (12220), [6/INIT]
- This regenerates the Net index from the Net Menu
In this notation:
- Plain line numbers, such as 50, indicate a GOTO.
- Line numbers in parentheses indicate a GOSUB.
- A jump to another overlay is shown as [N/XXXX], where N is the new value of OV and XXXX is the destination overlay.
Using the example above, the actual flow would be:
5 GOTO 50
- Line 5 is always the first branch point, where the overlay performs its ON OV GOTO dispatch.
50 GOSUB 12010:GOSUB 12220:OV=6:GOTO 95
- Line 95 is the standard INIT loader.
In some cases this shorthand is slightly simplified from the exact code, but it provides a reliable map of the actual control flow.
The "OV" Settings for Overlays
The table below shows the paths for all defined settings of OV in the various overlays.
| Line Command | Setting |
|---|---|
| √bbs.init | |
| OV=1 : 40, (19044), 30 | Post-logoff procedures |
| OV=2 : 50, (12865), [3/MSGS] | Set Date & Time (from main BBS prompt) |
| OV=3 : 60, (12760), 30 | Back to Answer Feedback prompt (from √bbs.msgs) |
| OV=4 : 30, (12010), [2/MSGS] | Wait-For-Call screen |
| OV=5 : 9999 | Save msg index, variables, end program |
| OV=6 : 70, (12800), 30 | Network Menu |
| OV=7 : 75, (20010), [3/MSGS] | Password Maint (from main BBS prompt) |
| OV=8 : 80, (2710), [4/MSGS] | Validate by E-mail |
| OV=9 : 78, (13735), [3/MSGS] | Set new password (relayed from √bbs.ovl) |
| OV=10 : 65, (12092), [2/MSGS] | End of midnight routine (back to WFC) |
| OV=11 : 35, (11905), 30 | Reset √level x files |
| OV=12 : 85, (18240), [2/MSGS] | Return to application routine (from NW1) |
| OV=13 : 33, (29010), 30 | Return to WFC after new node applied |
| OV=14 : 79, (13735) | Save User Profile from √bbs.profile |
| √bbs.msgs | |
| OV=1 : 60, (13160), 57 | Command relayed from other overlay |
| OV=2 : 50, <read √welcome2>, (13523), (8510), (9005), 55 | Welcome msgs |
| OV=3 : 55, (13100), 57 | Main BBS prompt |
| OV=4 : 70, (1410), <ON VX GOTO 71,72,55,74> | General msg editor prompt |
| OV=5 : 65, (12822), [3/INIT] | Answer SYSOP feedback |
| OV=6 : 80, (7020), 55 | Feedback to SYSOP |
| OV=7 : 71, (9048), 55 | Continue reading mail (after replying Net mail) |
| OV=8 : 72, (3675), (3320), 55 | Continue reading msgs (after Net reply) |
| ---- : 57, [3/OVL] | Logoff |
| ---- : 74, [3/INIT] | Back to Answer SYSOP Feedback prompt |
| √bbs.xfer | |
| OV=1 : 60, (13160), [3/OVL] | Command relayed from other overlay |
| OV=2 : 65, (22010), [4/INIT] | DOS command (from SYSOP Menu) |
| √bbs.ovl | |
| OV=1 : 60, (13160), 80 | Command relayed from other overlay |
OV=2 : 70, (28005), (25005), (25100)
|
Purge old mail Validate disks Update download accesses Continue midnight routine in INIT or Continue with Network midnight routines |
| OV=3 : 80, (19010), [1/INIT] | Logoff |
| √bbs.nw1 | |
| OV=1 : 60, (14005), [3/MSGS] | Post Network Msg (from main BBS prompt) |
| OV=2 : 40, (14005), [6/INIT] | Post Net Msg (from Net Menu) |
| OV=3 : 50, (12010), (12220), [6/INIT] | Regen Net index (from Net Menu) |
| OV=4 : 35 | Illegal OV number (not used in v8.0+) |
OV=5 : 67, (1110), (8010), (40000)
|
Outgoing Net Send Update LOCK status Post-outgoing routines |
| OV=6 : 13110 | Node login |
| OV=7 : 85, (12010), (12220), [8/NW2] | Regen Net index (midnight routine) |
| OV=8 : 35 | See OV=4 |
| OV=9 : 35 | See OV=4 |
| OV=10 : 35 | See OV=4 |
| OV=11 : 30, (14490), [12/INIT] | New billing entry (during application) |
| OV=12 : 35 | See OV=4 |
| OV=13 : 15, (7010), [7/MSGS] | Private net reply (during e-mail reading) |
| OV=14 : 20, (7010), [8/MSGS] | Private net reply (during public msgs) |
| OV=15 : 66, (12010), (12220), [11/INIT] | Regen Net index (startup) |
| OV=16 : 74, (8010), [13/INIT] | Continue outgoing after CARRIER LOCK |
| OV=17 : 35 | See OV=4 |
| OV=18 : 77, (40000), 72 | Continue outgoing after Verify Net Mail |
| √bbs.nw2 | |
| OV=1 : 70, <ON I-40 GOSUB 3010,4010>, [3/MSGS] | Relay from other overlay |
| OV=2 : 25, (3010), [6/INIT] | Net Maintenance Menu |
| OV=3 : 30 | Illegal OV number |
| OV=4 : 35, (7010), (7500), [6/INIT] | Set window/speaker (from Net Menu) |
| OV=5 : 40, (11750), (18520), (18600), [15/NW1] | System start-up routine |
| OV=6 : 50, (5001), [6/INIT] | Send default net message (from Net Menu) |
| OV=7 : 55, (6050), (6220), [16/NW1] | Update after CARRIER LOCK |
| OV=8 : 22, (21120), [10/INIT] | Midnight routine; create √node x users |
| OV=9 : 27, (6290), (6600), [13/INIT] | New node application |
| OV=10 : 23, (4010), [6/INIT] | Release public net msgs (from Net Menu) |
| OV=11 : 30 | See OV=3 |
| OV=12 : 37, (6300), (6800), [18/NW1] | Post-application to remote node |
| OV=13 : 47, (1110), [18/NW1] | For use by Verify Net Mail mod |
| OV=14 : 65, (35440), (8100), [13/INIT] | Distribute incoming Net data |
Sysop Menu Branching
The table below shows where each menu command branches, by overlay.
| Key | Line (+function, if applicable) | Destination |
|---|---|---|
| SYSOP MENU - √bbs.init overlay Routines begin at line 12510 | ||
| F1 | 12100 | Logon (Local Mode) |
| F2 | 12615 | Load BBS term; if not found, return to 12010 |
| F3 | 12635, (8100), 12010 | View Caller Log |
| F4 | 12610
|
Set Date & Time, or go to Net Menu |
| F5 | 12630, (12710), 12010 | Read Feedback to Sysop |
| F6 | 12620, (20010), 12010 | Password Maintenance |
| F7 | 12625, [3/XFER] | DOS Wedge |
| F8 | 12640, 9999 | Shut BBS down |
| NETWORK MENU - √bbs.init overlay Routines begin at line 12800 | ||
| F1 | 12865, (24005), 11920 | Set Date & Time |
| F2 | 12850, [4/NW2] | Set Net window/speaker |
| F3 | 12835, [2/NW2] | Net Maintenance Menu |
| F4 | 12855, [6/NW2] | Default Net message multi-send |
| F5 | 12840, [10/NW2] | Release public Net messages holding |
| F6 | 12860, [3/NW1] | Regenerate Network index |
| F7 | 12845, [2/NW1] | Post Network Message |
| F8 | Return to WFC | |
| NETWORK MAINT MENU - √bbs.nw2 overlay Routines begin at line 3010 | ||
| 1 | 3080 | Billing List/Print |
| 2 | 3160 | Billing Edit |
| 3 | 3300 | Billing Report Generator |
| 4 | 3450 | Billing Total Accounts |
| 5 | 6010 | Node Status Report |
| 6 | 7110 | Node Account File Edit |
| 7 | 7600 | Attach File |
| 8 | 3072 | Read Send Log |
| 9 | 3073 | Read Receive Log |
Midnight Routines
The midnight maintenance routines begin in the √bbs.init overlay and continue through several other overlays. The table below maps this process.
| Line Command | Branch and Functional Area |
|---|---|
| INIT : (26210), [2/OVL] | Call to 26210 resets time limits |
2/OVL : 70, (28005), (25005), (25100),
|
Calls to:
|
| 7/NW1 : 85, (12010), (12220), [8/NW2] | Calls to:
|
| 8/NW2 : 22, (21120), [10/INIT] | Call to 21120 creates √node x users |
| 10/INIT : 65, (12092) | Call to 12092 ends the midnight routine and returns to WFC |
Next section: Absolute Day Numbers (ADN)