S-C DocuMentor — Applesoft

               SAVE S.F49C
               1010 *--------------------------------
               1020 *      "XDRAW" ONE BIT
               1030 *--------------------------------
F49C- 18       1040 LRUDX1 CLC          C=0 MEANS NO 90 DEGREE ROTATION
F49D- A5 D1    1050 LRUDX2 LDA HGR.DX+1      C=1 MEANS ROTATE 90 DEGREES
F49F- 29 04    1060        AND #4       IF BIT2=0 THEN DON'T PLOT
F4A1- F0 25    1070        BEQ LRUD4    YES, DO NOT PLOT
F4A3- A9 7F    1080        LDA #$7F     NO, LOOK AT WHAT IS ALREADY THERE
F4A5- 25 30    1090        AND MON.HMASK
F4A7- 31 26    1100        AND (MON.GBASL),Y  SCREEN BIT = 1?
F4A9- D0 19    1110        BNE LRUD3          YES, GO CLEAR IT
F4AB- E6 EA    1120        INC HGR.COLLISIONS       NO, COUNT THE COLLISION
F4AD- A9 7F    1130        LDA #$7F           AND TURN THE BIT ON
F4AF- 25 30    1140        AND MON.HMASK
F4B1- 10 11    1150        BPL LRUD3    ...ALWAYS
               1160 *--------------------------------
               1170 *      "DRAW" ONE BIT
               1180 *--------------------------------
F4B3- 18       1190 LRUD1  CLC          C=0 MEANS NO 90 DEGREE ROTATION
F4B4- A5 D1    1200 LRUD2  LDA HGR.DX+1      C=1 MEANS ROTATE
F4B6- 29 04    1210        AND #4       IF BIT2=0 THEN DO NOT PLOT
F4B8- F0 0E    1220        BEQ LRUD4    DO NOT PLOT
F4BA- B1 26    1230        LDA (MON.GBASL),Y
F4BC- 45 1C    1240        EOR HGR.BITS      1'S WHERE ANY BITS NOT IN COLOR
F4BE- 25 30    1250        AND MON.HMASK    LOOK AT JUST THIS BIT POSITION
F4C0- D0 02    1260        BNE LRUD3        THE BIT WAS ZERO, SO PLOT IT
F4C2- E6 EA    1270        INC HGR.COLLISIONS  BIT IS ALREADY 1; COUNT COLLSN
               1280 *--------------------------------
               1290 *      TOGGLE BIT ON SCREEN WITH (A)
               1300 *--------------------------------
F4C4- 51 26    1310 LRUD3  EOR (MON.GBASL),Y
F4C6- 91 26    1320        STA (MON.GBASL),Y
               1330 *--------------------------------
               1340 *      DETERMINE WHERE NEXT POINT WILL BE, AND MOVE THERE
               1350 *      C=0 IF NO 90 DEGREE ROTATION
               1360 *      C=1 ROTATES 90 DEGREES
               1370 *--------------------------------
F4C8- A5 D1    1380 LRUD4  LDA HGR.DX+1      CALCULATE THE DIRECTION TO MOVE
F4CA- 65 D3    1390        ADC HGR.QUADRANT
F4CC- 29 03    1400        AND #3       WRAP AROUND THE CIRCLE
F4CD-          1410 CON.03 .EQ *-1  (( A CONSTANT ))
               1420 *
               1430 *                   00 -- UP
               1440 *                   01 -- DOWN
               1450 *                   10 -- RIGHT
               1460 *                   11 -- LEFT
               1470 *
F4CE- C9 02    1480        CMP #2       C=0 IF 0 OR 1, C=1 IF 2 OR 3
F4D0- 6A       1490        ROR          PUT C INTO SIGN, ODD/EVEN INTO C
F4D1- B0 92    1500        BCS MOVE.LEFT.OR.RIGHT
               1510 *--------------------------------
               1520 MOVE.UP.OR.DOWN
F4D3- 30 30    1530        BMI MOVE.DOWN     SIGN FOR UP/DOWN SELECT.
               1540 *--------------------------------
               1550 *      MOVE UP ONE PIXEL
               1560 *      IF ALREADY AT TOP, GO TO BOTTOM
               1570 *
               1580 *      REMEMBER:  Y-COORD   GBASH     GBASL
               1590 *                ABCDEFGH  PPPFGHCD  EABAB000
               1600 *--------------------------------
F4D5- 18       1610        CLC          MOVE UP
F4D6- A5 27    1620        LDA MON.GBASH    CALC. BASE ADDRESS OF PREV. LINE
F4D8- 2C B9 F5 1630        BIT CON.1C       LOOK AT BITS 000FGH00 IN GBASH
F4DB- D0 22    1640        BNE .5           SIMPLE, JUST FGH=FGH-1
               1650 *                   GBASH=PPP000CD, GBASL=EABAB000
F4DD- 06 26    1660        ASL MON.GBASL   WHAT IS "E"?
F4DF- B0 1A    1670        BCS .3          E=1, THEN EFGH=EFGH-1
F4E1- 2C CD F4 1680        BIT CON.03   LOOK AT 000000CD IN GBASH
F4E4- F0 05    1690        BEQ .1       Y-POS IS AB000000 FORM
F4E6- 69 1F    1700        ADC #$1F     CD <> 0, SO CDEFGH=CDEFGH-1
F4E8- 38       1710        SEC
F4E9- B0 12    1720        BCS .4       ...ALWAYS
F4EB- 69 23    1730 .1     ADC #$23     ENOUGH TO MAKE GBASH=PPP11111 LATER
F4ED- 48       1740        PHA          SAVE FOR LATER
F4EE- A5 26    1750        LDA MON.GBASL  GBASL IS NOW ABAB0000 (AB=00,01,10)
F4F0- 69 B0    1760        ADC #$B0         0000+1011=1011 AND CARRY CLEAR
               1770 *                    OR 0101+1011=0000 AND CARRY SET
               1780 *                    OR 1010+1011=0101 AND CARRY SET
F4F2- B0 02    1790        BCS .2       NO WRAP-AROUND NEEDED
F4F4- 69 F0    1800        ADC #$F0     CHANGE 1011 TO 1010 (WRAP-AROUND)
F4F6- 85 26    1810 .2     STA MON.GBASL   FORM IS NOW STILL ABAB0000
F4F8- 68       1820        PLA          PARTIALLY MODIFIED GBASH
F4F9- B0 02    1830        BCS .4       ...ALWAYS
F4FB- 69 1F    1840 .3     ADC #$1F
F4FD- 66 26    1850 .4     ROR MON.GBASL    SHIFT IN E, TO GET EABAB000 FORM
F4FF- 69 FC    1860 .5     ADC #$FC     FINISH GBASH MODS
F501- 85 27    1870 UD.1   STA MON.GBASH
F503- 60       1880        RTS
               1890 *--------------------------------
F504- 18       1900        CLC          <<<NEVER USED>>>
               1910 *--------------------------------
               1920 *      MOVE DOWN ONE PIXEL
               1930 *      IF ALREADY AT BOTTOM, GO TO TOP
               1940 *
               1950 *      REMEMBER:  Y-COORD   GBASH     GBASL
               1960 *                ABCDEFGH  PPPFGHCD  EABAB000
               1970 *--------------------------------
               1980 MOVE.DOWN
F505- A5 27    1990        LDA MON.GBASH     TRY IT FIRST, BY FGH=FGH+1
F507- 69 04    2000        ADC #4            GBASH = PPPFGHCD
F508-          2010 CON.04 .EQ *-1   (( CONSTANT ))
F509- 2C B9 F5 2020        BIT CON.1C        IS FGH FIELD NOW ZERO?
F50C- D0 F3    2030        BNE UD.1          NO, SO WE ARE FINISHED
               2040 *                        YES, RIPPLE THE CARRY AS HIGH
               2050 *                        AS NECESSARY
F50E- 06 26    2060        ASL MON.GBASL     LOOK AT "E" BIT
F510- 90 18    2070        BCC .2            NOW ZERO; MAKE IT 1 AND LEAVE
F512- 69 E0    2080        ADC #$E0     CARRY = 1, SO ADDS $E1
F514- 18       2090        CLC          IS "CD" NOT ZERO?
F515- 2C 08 F5 2100        BIT CON.04   TESTS BIT 2 FOR CARRY OUT OF "CD"
F518- F0 12    2110        BEQ .3       NO CARRY, FINISHED
               2120 *                   INCREMENT "AB" THEN
               2130 *                   0000 --> 0101
               2140 *                   0101 --> 1010
               2150 *                   1010 --> WRAP AROUND TO LINE 0
F51A- A5 26    2160        LDA MON.GBASL     0000  0101  1010
F51C- 69 50    2170        ADC #$50          0101  1010  1111
F51E- 49 F0    2180        EOR #$F0          1010  0101  0000
F520- F0 02    2190        BEQ .1
F522- 49 F0    2200        EOR #$F0          0101  1010
F524- 85 26    2210 .1     STA MON.GBASL     NEW ABAB0000
F526- A5 E6    2220        LDA HGR.PAGE     WRAP AROUND TO LINE ZERO OF GROUP
F528- 90 02    2230        BCC .3            ...ALWAYS
F52A- 69 E0    2240 .2     ADC #$E0
F52C- 66 26    2250 .3     ROR MON.GBASL
F52E- 90 D1    2260        BCC UD.1     ...ALWAYS
               2270 *--------------------------------
               2280 *      HLINRL IS NEVER CALLED BY APPLESOFT
               2290 *
               2300 *      ENTER WITH:  (A,X) = DX FROM CURRENT POINT
               2310 *                   (Y)   = DY FROM CURRENT POINT
               2320 *--------------------------------
F530- 48       2330 HLINRL PHA          SAVE (A)
F531- A9 00    2340        LDA #0       CLEAR CURRENT POINT SO HGLIN WILL
F533- 85 E0    2350        STA HGR.X      ACT RELATIVELY
F535- 85 E1    2360        STA HGR.X+1
F537- 85 E2    2370        STA HGR.Y
F539- 68       2380        PLA          RESTORE (A)
               2390 *--------------------------------
               2400 *      DRAW LINE FROM LAST PLOTTED POINT TO (A,X),(Y)
               2410 *
               2420 *      ENTER WITH:  (A,X) = X OF TARGET POINT
               2430 *                   (Y)   = Y OF TARGET POINT
               2440 *--------------------------------
F53A- 48       2450 HGLIN  PHA          COMPUTE DX = X- X0
F53B- 38       2460        SEC
F53C- E5 E0    2470        SBC HGR.X
F53E- 48       2480        PHA
F53F- 8A       2490        TXA
F540- E5 E1    2500        SBC HGR.X+1
F542- 85 D3    2510        STA HGR.QUADRANT SAVE DX SIGN (+ = RIGHT, - = LEFT)
F544- B0 0A    2520        BCS .1       NOW FIND ABS (DX)
F546- 68       2530        PLA          FORMS 2'S COMPLEMENT
F547- 49 FF    2540        EOR #$FF
F549- 69 01    2550        ADC #1
F54B- 48       2560        PHA
F54C- A9 00    2570        LDA #0
F54E- E5 D3    2580        SBC HGR.QUADRANT
F550- 85 D1    2590 .1     STA HGR.DX+1
F552- 85 D5    2600        STA HGR.E+1       INIT HGR.E TO ABS(X-X0)
F554- 68       2610        PLA
F555- 85 D0    2620        STA HGR.DX
F557- 85 D4    2630        STA HGR.E
F559- 68       2640        PLA
F55A- 85 E0    2650        STA HGR.X      TARGET X POINT
F55C- 86 E1    2660        STX HGR.X+1
F55E- 98       2670        TYA          TARGET Y POINT
F55F- 18       2680        CLC          COMPUTE DY = Y-HGR.Y
F560- E5 E2    2690        SBC HGR.Y       AND SAVE -ABS(Y-HGR.Y)-1 IN HGR.DY
F562- 90 04    2700        BCC .2       (SO + MEANS UP, - MEANS DOWN)
F564- 49 FF    2710        EOR #$FF     2'S COMPLEMENT OF DY
F566- 69 FE    2720        ADC #$FE
F568- 85 D2    2730 .2     STA HGR.DY
F56A- 84 E2    2740        STY HGR.Y       TARGET Y POINT
F56C- 66 D3    2750        ROR HGR.QUADRANT    SHIFT Y-DIRECTION INTO QUADRANT
F56E- 38       2760        SEC          COUNT = DX -(-DY) = # OF DOTS NEEDED
F56F- E5 D0    2770        SBC HGR.DX
F571- AA       2780        TAX          COUNTL IS IN X-REG
F572- A9 FF    2790        LDA #$FF
F574- E5 D1    2800        SBC HGR.DX+1
F576- 85 1D    2810        STA HGR.COUNT
F578- A4 E5    2820        LDY HGR.HORIZ     HORIZONTAL INDEX
F57A- B0 05    2830        BCS MOVEX2   ...ALWAYS
               2840 *--------------------------------
               2850 *      MOVE LEFT OR RIGHT ONE PIXEL
               2860 *      (A) BIT 6 HAS DIRECTION
               2870 *--------------------------------
F57C- 0A       2880 MOVEX  ASL          PUT BIT 6 INTO SIGN POSITION
F57D- 20 65 F4 2890        JSR MOVE.LEFT.OR.RIGHT
F580- 38       2900        SEC
               2910 *--------------------------------
               2920 *      DRAW LINE NOW
               2930 *--------------------------------
F581- A5 D4    2940 MOVEX2 LDA HGR.E       CARRY IS SET
F583- 65 D2    2950        ADC HGR.DY       E = E-DELTY
F585- 85 D4    2960        STA HGR.E       NOTE: DY IS (-DELTA Y)-1
F587- A5 D5    2970        LDA HGR.E+1       CARRY CLR IF HGR.E GOES NEGATIVE
F589- E9 00    2980        SBC #0
F58B- 85 D5    2990 .1     STA HGR.E+1
F58D- B1 26    3000        LDA (MON.GBASL),Y
F58F- 45 1C    3010        EOR HGR.BITS  PLOT A DOT
F591- 25 30    3020        AND MON.HMASK
F593- 51 26    3030        EOR (MON.GBASL),Y
F595- 91 26    3040        STA (MON.GBASL),Y
F597- E8       3050        INX          FINISHED ALL THE DOTS?
F598- D0 04    3060        BNE .2       NO
F59A- E6 1D    3070        INC HGR.COUNT   TEST REST OF COUNT
F59C- F0 62    3080        BEQ RTS.22   YES, FINISHED.
F59E- A5 D3    3090 .2     LDA HGR.QUADRANT    TEST DIRECTION
F5A0- B0 DA    3100        BCS MOVEX    NEXT MOVE IS IN THE X DIRECTION
F5A2- 20 D3 F4 3110        JSR MOVE.UP.OR.DOWN    IF CLR, NEG, MOVE
F5A5- 18       3120        CLC          E = E+DX
F5A6- A5 D4    3130        LDA HGR.E
F5A8- 65 D0    3140        ADC HGR.DX
F5AA- 85 D4    3150        STA HGR.E
F5AC- A5 D5    3160        LDA HGR.E+1
F5AE- 65 D1    3170        ADC HGR.DX+1
F5B0- 50 D9    3180        BVC .1       ...ALWAYS
               3190 *--------------------------------
F5B2- 81 82 84
F5B5- 88 90 A0
F5B8- C0       3200 MSKTBL .HS 8182848890A0C0
               3210 *--------------------------------
F5B9- 1C       3220 CON.1C .HS 1C       MASK FOR "FGH" BITS
               3230 *--------------------------------