
 1000  *--------------------------------
 1010  *      HI-RES SCRN FUNCTION WITH COLOR
 1020  *
 1030  *      BY DAVID DOUDNA, FERGUSON, MISSOURI
 1040  *      NOVEMBER 30, 1981
 1050  *--------------------------------
 1060  HBASL  .EQ $26      BASE ADDRESS
 1070  HBASH  .EQ $27
 1080  HMASK  .EQ $30      BIT MASK
 1090  *--------------------------------
 1100  X0L    .EQ $320     X-COORDINATE
 1110  X0H    .EQ $321
 1120  Y0     .EQ $322     Y-COORDINATE
 1130  HCOLOR.BYTE .EQ $324
 1140  HPAGE  .EQ $326     HI-RES PAGE ($20 OR $40)
 1150  *--------------------------------
 1160  HSCRN  LDA Y0       GET (A)=Y-COORDINATE
 1170         LDX X0L      GET (Y,X)=X-COORD.
 1180         LDY X0H
 1190         PHA          Y-COORD BITS LABELED ABCDEFGH
 1200         AND #$C0     CALCULATE BASE ADDRESS FOR Y-COORD
 1210         STA HBASL         IN HBASL,HBASH FOR
 1220         LSR               ACCESSING SCREEN MEMORY
 1230         LSR               VIA (HBASL),Y
 1240         ORA HBASL    HBASH = PPPFGHCD
 1250         STA HBASL    HBASL = EABAB000
 1260         PLA          WHERE PPP=001 FOR $2000-3FFF
 1270         STA HBASH      AND PPP=010 FOR $4000-5FFF
 1280         ASL
 1290         ASL
 1300         ASL
 1310         ROL HBASH
 1320         ASL
 1330         ROL HBASH
 1340         ASL
 1350         ROR HBASL
 1360         LDA HBASH
 1370         AND #$1F
 1380         ORA HPAGE
 1390         STA HBASH
 1400  *--------------------------------
 1410         TXA          DIVIDE X-COORD BY 7 (7 DOTS PER BYTE)
 1420         CPY #0       IS X-COORD > 255?
 1430         BEQ .2       NO, ENTER SUBTRACTION LOOP
 1440         LDY #35      YES: 256 = 7*36 + 4
 1450         ADC #4       CARRY WAS SET, SO ADDS 5
 1460  *                   ALSO CLEARS CARRY, SO SBC #7 BELOW
 1470  *                   ACTUALLY SUBTRACTS 8
 1480  .1     INY          INCREASE QUOTIENT
 1490  .2     SBC #7       SUBTRACT 7 (OR 8 IF CARRY CLEAR)
 1500         BCS .1       STILL MORE 7'S
 1510         TAX          REMAINDER IS BIT POSITION
 1520         LDA MSKTBL-249,X
 1530         STA HMASK
 1540  *--------------------------------
 1550         LDA (HBASL),Y     GET BYTE WHICH HAS OUR SPOT
 1560         AND #$80     ISOLATE HALF-DOT SHIFT BIT
 1570         STA HIBIT
 1580         LDA (HBASL),Y     GET BYTE AGAIN
 1590         AND HMASK    ISOLATE OUR SPOT
 1600         BEQ .9       COLOR IS BLACK (0 OR 4)
 1610         LDA X0L      NOT BLACK
 1620         LDX #1
 1630         LSR          ODD OR EVEN X-COORD.?
 1640         BCS .3       ODD, COLOR=1 OR 5
 1650         INX          EVEN, COLOR=2 OR 6
 1660  *--------------------------------
 1670  .3     LDA HMASK    LOOK AT NEIGHBOR BIT ON LEFT
 1680         LSR          BITS ARE IN BYTE BACKWARDS
 1690         BCC .4       NEIGHBOR IN SAME BYTE
 1700         TYA          NEIGHBOR IN DIFFERENT BYTE
 1710         BEQ .5       NO BYTE LEFT OF THIS ONE
 1720         DEY
 1730         LDA (HBASL),Y
 1740         AND #$40
 1750         BNE .7       WHITE
 1760         INY          RESTORE Y
 1770         BNE .5       ...ALWAYS
 1780  .4     AND (HBASL),Y
 1790         BNE .7       WHITE
 1800  *--------------------------------
 1810  .5     LDA HMASK    LOOK AT NEIGHBOR BIT ON RIGHT
 1820         ASL
 1830         BPL .6       NEIGHBOR IS IN SAME BYTE
 1840         CPY #39      ALREADY AT RIGHT END?
 1850         BCS .8       YES, NOT WHITE THEN
 1860         INY
 1870         LDA (HBASL),Y
 1880         AND #1
 1890         BNE .7       WHITE
 1900         BEQ .8       ...ALWAYS (NOT WHITE)
 1910  .6     AND (HBASL),Y
 1920         BEQ .8       NOT WHITE
 1930  *--------------------------------
 1940  .7     LDX #3       COLOR IS WHITE (3 OR 7)
 1950  *--------------------------------
 1960  .8     TXA          COLOR TO A-REG
 1970  *--------------------------------
 1980  .9     BIT HIBIT    SEE IF HALF DOT SHIFT
 1990         BPL .10      NO
 2000         CLC
 2010         ADC #4       YES
 2020  .10    STA HCOLOR
 2030         TAX          USE COLOR # (0-7) TO GET COLOR BYTE
 2040         LDA COLOR.TABLE,X
 2050         STA HCOLOR.BYTE
 2060         RTS
 2070  *--------------------------------
 2080  MSKTBL .HS 01020408102040
 2090  *--------------------------------
 2100  COLOR.TABLE .HS 002A557F80AAD5FF
 2110  *--------------------------------
 2120  HIBIT  .BS 1        MSB
 2130  HCOLOR .BS 1        COLOR INDEX 0-7

