1040 Form

This file is part of and Timex Sinclair Public Domain Library Tape 1007. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Finance

This program implements an income tax return assistant that handles data entry, tax calculation, data review, and tape storage for US tax forms 1040 and Schedule A. It uses a 107-element numeric array L() to store line-item amounts and a parallel 107-element string array C$() of 18-character descriptions for each tax line. Navigation is driven by a two-level menu system: a main menu with five options and a sub-menu for selecting between Form 1040 and Schedule A, with GOSUB dispatch performed via VAL K$*1000 and VAL K$*100+2000 arithmetic on the keypress. Initialization at line 9000 prompts the user to enter all 107 line descriptions interactively in FAST mode before use, with the instruction at line 51 directing users to GO TO 9000 first. The SAVE at line 4050 preserves the entire program and its data arrays to tape under the name “TAX”.


Program Analysis

Program Structure

The program is organized into clearly delineated routines, each prefixed by an inverse-video REM label. The main loop runs from lines 100–200, presenting a five-option menu and dispatching to one of five subroutines. A second-level dispatcher at line 7000 handles form selection (1040 or Schedule A). The overall flow is:

  1. Lines 51–52: Bootstrap message and STOP — user must first run line 9000.
  2. Lines 100–200: Main menu loop.
  3. Lines 1000–1120: Option 1 — Enter Data.
  4. Lines 2000–2248: Option 2 — Calculate Tax (Form 1040 at 2100, Schedule A at 2200).
  5. Lines 3000–3080: Option 3 — Review Data.
  6. Lines 4000–4060: Option 4 — Record Data (SAVE to tape).
  7. Lines 5000–5030: Option 5 — Erase All Entries.
  8. Lines 6000–6030: Shared pause/continue subroutine.
  9. Lines 7000–7214: Form selection subroutine and form setup routines.
  10. Lines 9000–9090: Initialization — dimensions arrays and prompts for 107 line descriptions.

Menu Dispatch via Arithmetic on INKEY$

The program uses a compact but powerful idiom for computed GOSUB dispatch. At line 180, GOSUB VAL K$*1000 converts the character “1”–”5″ to the integer 1000–5000, jumping directly to the correct routine. Similarly, GOSUB VAL K$*100+2000 at line 2020 and GOSUB VAL K$*100+7000 at line 7090 select sub-forms. This eliminates a chain of IF/THEN statements and is a recognized memory and speed optimization in Sinclair BASIC.

Data Model

Two parallel arrays form the core data structure:

  • L(107) — numeric array holding the dollar amount for each of 107 tax line items.
  • C$(107,18) — string array holding an 18-character description for each line item, entered by the user at initialization time.

A offset variable Z is used to map logical line numbers (as entered by the user) to physical array indices. For Form 1040, Z=0; for Schedule A, Z=66, allowing Schedule A entries 1–41 to occupy L(67)L(107).

Form Setup Routines

Lines 7100–7130 (Form 1040) and 7200–7214 (Schedule A) configure four variables used by the Review Data and Enter Data routines:

VariablePurpose
ZArray offset (0 for 1040, 66 for Schedule A)
PNumber of sections to display in review
J(N)Start line number for section N
K(N)End line number for section N

This gives the Review Data routine (lines 3000–3080) a generic paginated display loop that works for both forms without hardcoded ranges.

Tax Calculation Logic

The Form 1040 calculation (lines 2100–2182) manually replicates the aggregation rules of the actual IRS Form 1040, using FOR loops to sum ranges of L()L(21), L(30), L(31)). A rounding idiom appears at line 2160: INT(100*X+.5)/10 — note this divides by 10 rather than 100, which appears to be an intentional scaling (perhaps converting cents to a percentage or applying a rate), though it could also be a bug depending on intended semantics. The refund/amount-owed logic at lines 2156–2172 correctly handles negative results by branching and zeroing out the opposing field.

Initialization and FAST Mode

Line 9000 begins the initialization sequence, which must be run manually via GO TO 9000. It dimensions all four arrays, then enters FAST mode (line 9012) before looping through all 107 entries to accept user-typed descriptions via INPUT C$(I). FAST mode suppresses the display interrupt, greatly accelerating the input loop. After completion, SLOW is restored at line 9055 and execution falls through to the main menu. Lines 9070–9090 (CLEAR, SAVE, LIST) appear to be a development artifact for saving the initialized program state; CLEAR before SAVE would erase variables, so these lines are presumably not reached in normal operation.

Notable Techniques and Idioms

  • The PAUSE 40000 / INKEY$ pattern is used throughout as a keypress wait at lines 155, 160, 4030, 7032, and 7034.
  • STR$ I at line 3025 converts the line number to a string for display, avoiding a separate PRINT of a numeric variable.
  • The SAVE "TAX" at line 4050 saves the entire program including current variable state, providing a simple data persistence mechanism without any file format overhead.
  • Inverse-video REM labels (e.g., %E%N%T%E%R% %D%A%T%A) serve as section markers that are visually distinct in the listing.

Anomalies and Potential Issues

  • Line 5030 prints “ALL ENTRIES ERASED” but does not return or GOTO anywhere — it falls through to line 5999 (a REM), then to line 6000. This accidentally calls the pause/continue routine after erasing, which may or may not be intentional.
  • The rounding expression at line 2160, INT(100*X+.5)/10, divides by 10 instead of 100. If the intent was to round to the nearest cent, the divisor should be 100. As written, it multiplies by 10 instead of rounding to two decimal places.
  • DIM I$(3) at line 9010 dimensions a string array of three 1-character elements, but the program uses I$ as a simple string variable (e.g., LET I$=STR$ I at line 3025). In Sinclair BASIC, once a variable is dimensioned as an array, the simple variable of the same name is inaccessible; this would cause an error at line 3025 unless I$ was intended to be I$(N).
  • Line 9080 saves the file as "1030%5" where %5 is inverse “5”. This appears to be a development save with a specific filename.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10294-10335.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

  51 PRINT "USE GOTO 9000,TO FILL IN LINES"
  52 STOP 
 100 PRINT AT 3,6;"INCOME TAX RETURN"
 110 PRINT AT 6,4;"PRESS DESIRED FUNCTION"
 120 PRINT AT 8,6;"1. ENTER DATA"
 130 PRINT AT 9,6;"2. CALCULATE TAX"
 140 PRINT AT 10,6;"3. REVIEW DATA"
 150 PRINT AT 11,6;"4. RECORD DATA"
 152 PRINT AT 12,6;"5. ERASE ALL ENTRIES"
 155 PAUSE 40000
 160 LET K$=INKEY$
 170 IF K$<"1" OR K$>"5" THEN GOTO 100
 180 GOSUB VAL K$*1000
 200 GOTO 100
 999 REM %E%N%T%E%R% %D%A%T%A
 1000 GOSUB 7000
 1010 PRINT AT 6,8;"LINE NUMBER"
 1020 INPUT Y
 1030 PRINT AT 6,20;Y
 1040 LET X=Y+Z
 1050 PRINT AT 8,8;"AMOUNT $"
 1060 INPUT A
 1070 PRINT AT 8,16;A
 1080 LET L(X)=L(X)+A
 1090 PRINT AT 10,8;"TOTAL $";L(X)
 1100 GOSUB 6000
 1120 RETURN 
 1999 REM %C%A%L%C%U%L%A%T%E% %T%A%X
 2000 GOSUB 7000
 2020 GOSUB VAL K$*100+2000
 2030 RETURN 
 2099 REM %F%O%R%M% %1%0%4%0
 2100 LET L(21)=0
 2102 FOR I=7 TO 20
 2104 LET L(21)=L(21)+L(I)
 2106 NEXT I
 2108 LET L(30)=0
 2110 FOR I=22 TO 29
 2112 LET L(30)=L(30)+L(I)
 2114 NEXT I
 2116 LET L(31)=L(21)-L(30)
 2117 LET L(32)=L(107)
 2118 LET L(34)=L(31)-L(32)-L(33)
 2120 PRINT AT 21,0;"ENTER TAX FOR $";L(34)
 2122 INPUT L(35)
 2124 PRINT AT 21,0;"ENTER ADDITIONAL TAXES"
 2126 INPUT L(36)
 2128 LET L(37)=L(35)+L(36)
 2130 LET L(46)=0
 2132 FOR I=38 TO 45
 2134 LET L(46)=L(46)+L(I)
 2136 NEXT I
 2138 LET L(47)=L(37)-L(46)
 2140 LET L(54)=0
 2142 FOR I=47 TO 53
 2144 LET L(54)=L(54)+L(I)
 2146 NEXT I
 2148 LET L(62)=0
 2150 FOR I=55 TO 61
 2152 LET L(62)=L(62)+L(I)
 2154 NEXT I
 2156 LET X=L(62)-L(54)
 2158 IF X<0 THEN GOTO 2166
 2160 LET L(63)=INT (100*X+.5)/10
 2162 LET L(64)=L(63)-L(65)
 2164 GOTO 2174
 2166 LET L(63)=0
 2168 LET L(64)=0
 2170 LET L(65)=0
 2172 LET L(66)=X*-1
 2174 FOR I=63 TO 66
 2176 PRINT AT I-53,0;I;" ";C$(I);" $";L(I)
 2178 NEXT I
 2180 GOSUB 6000
 2182 RETURN 
 2199 REM %S%C%H%E%D%U%L%E% %A
 2200 LET L(69)=INT (L(31)+.5)/100
 2201 LET L(70)=L(68)-L(69)
 2202 IF L(69)>L(68) THEN LET L(70)=0
 2204 LET L(73)=L(70)+L(71)+L(72)
 2206 LET L(74)=3*L(69)
 2208 LET L(75)=L(73)-L(74)
 2210 IF L(74)>L(73) THEN LET L(75)=0
 2212 LET L(76)=L(67)+L(75)
 2214 LET L(82)=L(77)+L(78)+L(79)+L(80)+L(81)
 2216 LET L(86)=L(83)+L(84)+L(85)
 2218 LET L(90)=L(87)+L(88)+L(89)
 2220 LET L(95)=L(91)+L(92)+L(93)+L(94)
 2222 LET L(98)=L(96)+L(97)
 2224 LET L(99)=L(76)
 2226 LET L(100)=L(82)
 2228 LET L(101)=L(86)
 2230 LET L(102)=L(90)
 2232 LET L(103)=L(95)
 2234 LET L(104)=L(98)
 2236 LET L(105)=L(99)+L(100)+L(101)+L(102)+L(103)+L(104)
 2238 LET L(107)=L(105)-L(106)
 2240 IF L(106)>L(105) THEN LET L(107)=0
 2242 PRINT AT 15,0;"41 ";C$(107);" $";L(107)
 2244 GOSUB 6000
 2248 RETURN 
 2999 REM %R%E%V%I%E%W% %D%A%T%A
 3000 GOSUB 7000
 3010 FOR N=1 TO P
 3020 FOR I=J(N) TO K(N)
 3025 LET I$=STR$ I
 3030 PRINT I$;" ";C$(I+Z);" $";L(I+Z)
 3040 NEXT I
 3050 GOSUB 6000
 3070 NEXT N
 3080 RETURN 
 3999 REM %R%E%C%O%R%D% %D%A%T%A
 4000 CLS 
 4010 PRINT AT 6,7;"PREPARE RECORDER"
 4020 PRINT AT 10,3;"PRESS ANY KEY WHEN READY"
 4030 PAUSE 40000
 4040 CLS 
 4050 SAVE "TAX"
 4060 RETURN 
 4999 REM %E%R%A%S%E% %A%L%L% %E%N%T%R%I%E%S
 5000 CLS 
 5005 FOR I=1 TO 107
 5010 LET L(I)=0
 5020 NEXT I
 5030 PRINT AT 10,7;"ALL ENTRIES ERASED"
 5999 REM %P%A%U%S%E
 6000 PRINT AT 21,0;"PRESS ANY KEY TO CONTINUE"
 6010 PAUSE 40000
 6020 CLS 
 6030 RETURN 
 6999 REM %F%O%R%M% %S%E%L%E%C%T%I%O%N
 7000 CLS 
 7010 PRINT AT 6,7;"PRESS DESIRED FORM"
 7020 PRINT AT 8,9;"1. FORM 1040"
 7030 PRINT AT 9,9;"2. SCHEDULE A"
 7032 PAUSE 40000
 7034 LET K$=INKEY$
 7036 IF K$<"1" OR K$>"2" THEN GOTO 7000
 7088 CLS 
 7090 GOSUB VAL K$*100+7000
 7092 RETURN 
 7099 REM %F%O%R%M% %1%0%4%0
 7100 PRINT AT 0,11;"FORM 1040"
 7102 LET Z=0
 7104 LET P=4
 7106 LET J(1)=7
 7108 LET J(2)=21
 7110 LET J(3)=37
 7112 LET J(4)=47
 7114 LET K(1)=21
 7116 LET K(2)=37
 7118 LET K(3)=54
 7120 LET K(4)=66
 7130 RETURN 
 7199 REM %S%C%H%E%D%U%L%E% %A
 7200 PRINT AT 0,11;"SCHEDULE A"
 7202 LET Z=66
 7204 LET P=2
 7206 LET J(1)=1
 7208 LET J(2)=21
 7210 LET K(1)=20
 7212 LET K(2)=41
 7214 RETURN 
 8999 REM %I%N%I%T%I%A%L%I%Z%A%T%I%O%N
 9000 LET J=1
 9002 DIM J(4)
 9004 DIM K(4)
 9006 DIM C$(107,18)
 9008 DIM L(107)
 9010 DIM I$(3)
 9012 FAST 
 9020 FOR I=J TO 107
 9025 LET I$=STR$ I
 9030 PRINT AT 21,0;I$;"****************"
 9040 INPUT C$(I)
 9050 NEXT I
 9055 SLOW 
 9060 GOTO 100
 9070 CLEAR 
 9080 SAVE "1030%5"
 9090 LIST 

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

People

No people associated with this content.

Scroll to Top