Saturday, February 28, 2009

Here is some old code for you...

The Apple ][ computer didn't have super fancy graphics.  They had a portion of memory mapped to the graphic screen.  Since I don't really feel like trying to explain it here because others have done it far better than I could read this: http://en.wikipedia.org/wiki/Apple_II_graphics   Specifically the Hires Graphics section.

Now, I had a need to be able to scroll the Hires Screen left or right.  Thanks to a series of articles by David Lubar in Creative Computing called The Graph Paper (October 1982 -> March 1983) and an article called Lookup Tables (March 1982) I had a very good understanding of how each byte in memory made up the picture that was displayed so I wrote the following code using the SC Macro Assembler.  This version of the code did the scroll left.

The 'Lookup Table' allowed me to access each line of the hires screen directly and in order (since the screen was 'interlaced').

BTW, comments are for losers. :)

1000        .OR $6000
1010        .TF SCROLLLEFT
1020        .LIST OFF
1030        JMP HERE
1040 TABLHI .HS 2024282C3034383C
1050        .HS 2024282C3034383C
1060        .HS 2125292D3135393D 
1070        .HS 2125292D3135393D
1080        .HS 22262A2E32363A3E
1090        .HS 22262A2E32363A3E
1100        .HS 23272B2F33373B3F
1110        .HS 23272B2F33373B3F
1120        .HS 2024282C3034383C 
1130        .HS 2024282C3034383C
1140        .HS 2125292D3135393D 
1150        .HS 2125292D3135393D
1160        .HS 22262A2E32363A3E
1170        .HS 22262A2E32363A3E 
1180        .HS 23272B2F33373B3F
1190        .HS 23272B2F33373B3F
1200        .HS 2024282C3034383C 
1210        .HS 2024282C3034383C
1220        .HS 2125292D3135393D
1230        .HS 2125292D3135393D
1240        .HS 22262A2E32363A3E 
1250        .HS 22262A2E32363A3E
1260        .HS 23272B2F33373B3F
1270        .HS 23272B2F33373B3F
1280 TABLLO .HS 0000000000000000
1290        .HS 8080808080808080
1300        .HS 0000000000000000
1310        .HS 8080808080808080
1320        .HS 0000000000000000 
1330        .HS 8080808080808080 
1340        .HS 0000000000000000
1350        .HS 8080808080808080
1360        .HS 2828282828282828
1370        .HS A8A8A8A8A8A8A8A8
1380        .HS 2828282828282828
1390        .HS A8A8A8A8A8A8A8A8 
1400        .HS 2828282828282828 
1410        .HS A8A8A8A8A8A8A8A8 
1420        .HS 2828282828282828 
1430        .HS A8A8A8A8A8A8A8A8 
1440        .HS 5050505050505050
1450        .HS D0D0D0D0D0D0D0D0
1460        .HS 5050505050505050 
1470        .HS D0D0D0D0D0D0D0D0 
1480        .HS 5050505050505050 
1490        .HS D0D0D0D0D0D0D0D0
1500        .HS 5050505050505050 
1510        .HS D0D0D0D0D0D0D0D0 
1520 HERE   STA $C050 
1530        STA $C057
1540        STA $C054
1550        STA $C052
1560        LDX #$00
1570 A7     LDA TABLLO,X  
1580        STA $F0
1590        LDA TABLHI,X
1600        STA $F1
1610        CLC
1620        LDY #$27
1630 A6     LDA ($F0),Y
1640        ROL
1650        BCC A1
1660        ROR
1670        BCC A2
1680        SEC
1690        ROR
1710        JMP A3
1720 A2     ROL
1730        CLC
1740        ROR
1750        SEC
1760        ROR
1770        JMPA3
1780 A1     ROR
1790        BCC A4
1800        ROL
1810        SEC
1820        ROR
1830 A4     ROR
1840 A3     STA ($F0),Y
1850        ROR
1860        DEY
1870        BMI A5
1880        ROL
1890        JMP A6
1900 A5     INX
1910        CPX #$C0
1920        BNE A7
1930        RTS

And the code to scroll right looks like this:

1000        .OR $6000
1010        .TF SCROLLRGHT
1020        .LIST OFF
1030        JMP HERE
1040 TABLHI .HS 2024282C3034383C
1050        .HS 2024282C3034383C
1060        .HS 2125292D3135393D 
1070        .HS 2125292D3135393D
1080        .HS 22262A2E32363A3E
1090        .HS 22262A2E32363A3E
1100        .HS 23272B2F33373B3F
1110        .HS 23272B2F33373B3F
1120        .HS 2024282C3034383C 
1130        .HS 2024282C3034383C
1140        .HS 2125292D3135393D 
1150        .HS 2125292D3135393D
1160        .HS 22262A2E32363A3E
1170        .HS 22262A2E32363A3E 
1180        .HS 23272B2F33373B3F
1190        .HS 23272B2F33373B3F
1200        .HS 2024282C3034383C 
1210        .HS 2024282C3034383C
1220        .HS 2125292D3135393D
1230        .HS 2125292D3135393D
1240        .HS 22262A2E32363A3E 
1250        .HS 22262A2E32363A3E
1260        .HS 23272B2F33373B3F
1270        .HS 23272B2F33373B3F
1280 TABLLO .HS 0000000000000000
1290        .HS 8080808080808080
1300        .HS 0000000000000000
1310        .HS 8080808080808080
1320        .HS 0000000000000000 
1330        .HS 8080808080808080 
1340        .HS 0000000000000000
1350        .HS 8080808080808080
1360        .HS 2828282828282828
1370        .HS A8A8A8A8A8A8A8A8
1380        .HS 2828282828282828
1390        .HS A8A8A8A8A8A8A8A8 
1400        .HS 2828282828282828 
1410        .HS A8A8A8A8A8A8A8A8 
1420        .HS 2828282828282828 
1430        .HS A8A8A8A8A8A8A8A8 
1440        .HS 5050505050505050
1450        .HS D0D0D0D0D0D0D0D0
1460        .HS 5050505050505050 
1470        .HS D0D0D0D0D0D0D0D0 
1480        .HS 5050505050505050 
1490        .HS D0D0D0D0D0D0D0D0
1500        .HS 5050505050505050 
1510        .HS D0D0D0D0D0D0D0D0 
1520 HERE   STA $C050 
1530        STA $C057
1540        STA $C054
1550        STA $C052
1560        LDX #$00
1570 A7     LDA TABLLO,X  
1580        STA $F0
1590        LDA TABLHI,X
1600        STA $F1
1610        CLC
1620        LDY #$00
1630 A6     LDA ($F0),Y
1640        ROL
1650        BCC A1
1660        ROL
1670        BCC A2
1680        SEC
1690        ROR
1700        SEC
1710        BCS A3
1720 A2     SEC
1730        ROR
1740        CLC
1750        BCC A3
1760 A1     ROL
1770        BCC A4
1780        CLC
1790        ROR
1800        SEC
1810        BCS A3
1820 A4     CLC
1830        ROR
1840        CLC
1850 A3     STA ($F0),Y
1860        ROR
1870        INY
1880        CPY #$28
1890        BEQ A5
1900        ROL
1910        JMP A6
1920 A5     INX
1930        CPX #$C0
1940        BNE A7
1950        RTS

The code is very close but there are some important differences (like line 1620, 00 starts on the left of the line and #27 starts on the right of the line).

Now, you may ask, Why did I bother posting this?  Because I could and I felt like sharing.  I do have some old notebook pages I found with some hand written code on them that I'm going to scan in and post here at some point in the near future.

No comments:

Post a Comment

Comments are moderated. We're only going to allow stuff that we find funny, interesting, or just plain for the heck of it. If you don't like that, feel free to leave.

Copyright Realm Laboratories, LLC