Path: news1.icaen!news.uiowa.edu!chi-news.cic.net!199.60.229.3!newsfeed.direct.ca!news.uoregon.edu!cie-2.uoregon.edu!nparker From: nparker@cie-2.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2.programmer Subject: Re: Assembly language Scroll the HGR screen horizontally Date: 4 Jul 1997 06:54:22 GMT Organization: University of Oregon Campus Information Exchange Lines: 83 Message-ID: <5pi6mu$n1t@pith.uoregon.edu> References: <5ph2g1$e83$2@mentor.telis.org> NNTP-Posting-Host: cie-2.uoregon.edu NNTP-Posting-User: nparker In article <5ph2g1$e83$2@mentor.telis.org> itsme writes: >How do you do this? I know that It probably requires alot of bit >rotating. > >I can get it to scroll vertically, but that Is a whole different can o >worms. > >Could someone post the program to do this? Im sure that someone has >messed around with this and figured it out. Scrolling the screen one pixel horizontally is kind of a pain, because only seven bits out of each byte get shifted. Here's some source code that I was playing with tonight, which scrolls the screen one pixel to the right. It's far from perfect--it only shifts the visible pixels, leaving the high bits untouched, which means that if you shift more than a couple of times, you may notice colors starting to separate from themselves. And of course every shift will cause green and purple to trade places, and likewise with orange and blue, due to the way hires colors work. HBASL EQU $26 HBASH EQU $27 LDA #0 ;Start at $2000 STA HBASL LDA #$20 STA HBASH L1 CLC ;Beginning of row: prepare to shift in 0 bit PHP ;Save bit to be shifted in on the stack LDY #0 ;Start at beginning of row L2 PLP ;Get bit to be shifted in to next byte LDA (HBASL),Y ;Get screen byte PHA ;Save it for later (we'll only need its hi bit) ROL ;Shift it (note L shift looks like R shift on screen) PHA ;Save shifted byte for later AND #$7F ;Temporarily eliminate hi bit STA (HBASL),Y ;Back to the screen PLA ;Get new hi bit (old next-to-hi bit) back ASL ;Catch it in carry PLA ;Get original hi bit AND #$80 ;Mask off everything else ORA (HBASL),Y ;Get it into screen memory STA (HBASL),Y PHP ;Save carry flag (old next-to-hi bit) INY ;Advance to next byte CPY #40 ;Done entire row? BCC L2 ;If not, go do more... PLP ;...else discard last bit from row TYA ;Advance to a new row (note Y=40 here) CLC ADC HBASL STA HBASL LDA #0 ADC HBASH STA HBASH LDA HBASL ;Have we reached a screen hole yet? AND #$7F CMP #$78 BCC L1 ;If not, go back for another row... LDA HBASL ;...else skip 8-byte screen hole (note carry set here) ADC #7 STA HBASL LDA HBASH ADC #0 STA HBASH CMP #$40 ;End of screen yet? BCC L1 ;If not, go do another row... RTS ;...else return to caller I do not, of course, claim that this is the quickest or most compact way to do it. I did, however, make an effort to save some execution time by operating on the rows in memory order rather than in display order. Shifting the screen the other way is left as an exercise for the reader (translation: I was too lazy to work out the magic bit-shifting code myself). - Neil Parker -- Neil Parker, nparker@{cie-2,cie}.uoregon.edu, http://cie-2.uoregon.edu/~nparker "I was going to be a neo-deconstructivist but Mom wouldn't let me." -- Calvin and Hobbes, 7/13/1995 Unsolicited commercial e-mail to my address will be discarded unread. Path: news1.icaen!news.uiowa.edu!chi-news.cic.net!howland.erols.net!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!News1.Ottawa.iSTAR.net!news.istar.net!cal.istar!news From: jerryp@nospam.ziprobes.com (Jerry Penner) Newsgroups: comp.sys.apple2.programmer Subject: Re: Assembly language Scroll the HGR screen horizontally Date: 4 Jul 1997 14:25:43 GMT Organization: Z.I. Probes Inc. Lines: 60 Message-ID: <5pj157$kek@nr1.calgary.istar.net> References: <5ph2g1$e83$2@mentor.telis.org> <5pi6mu$n1t@pith.uoregon.edu> NNTP-Posting-Host: gateway.ziprobes.com X-Newsreader: News Xpress 2.0 Beta #0 In article <5pi6mu$n1t@pith.uoregon.edu>, nparker@cie-2.uoregon.edu (Neil Parker) wrote: >In article <5ph2g1$e83$2@mentor.telis.org> itsme writes: >>How do you do this? I know that It probably requires alot of bit >>rotating. >> >>I can get it to scroll vertically, but that Is a whole different can o >>worms. >> >>Could someone post the program to do this? Im sure that someone has >>messed around with this and figured it out. > >Scrolling the screen one pixel horizontally is kind of a pain, because only >seven bits out of each byte get shifted. > >Here's some source code that I was playing with tonight, which scrolls the >screen one pixel to the right. It's far from perfect--it only shifts the >visible pixels, leaving the high bits untouched, which means that if you >shift more than a couple of times, you may notice colors starting to >separate from themselves. And of course every shift will cause green and >purple to trade places, and likewise with orange and blue, due to the way >hires colors work. I once read about a faster way to do this in a 1983/1984 Softalk magazine. They used lookup tables for all the byte values. They call them Pre-shift tables. Basically, the idea is that you have two tables for left-direction shifts, and two tables for right-direction shifts. They called them ShiftStay and ShiftOut. So for left and right you would have LshiftStay ds 256 LshiftOut ds 256 RshiftStay ds 256 RshiftOut ds 256 Now you have to calculate these values, but only once, before you start scrolling your screen. To scroll the screen left, you start at the right side. Read a screen byte and use it as an index into the LshiftStay/Out tables. Read the LshiftStay table (lda LshiftStay,X), bitwise-OR it with the LshiftOut value from the previous (next rightmost byte), and then store it back onto the screen. Repeat until you get to the left side. Another thing you could do when you build the lookup tables is to make them so they scroll 2 pixels at a time. This way the colors would stay mostly the same. You will still run into trouble if you have the high-bits on in part of the line, but not the whole thing. That's a tricky problem. I'd also use a lookup table for the screen base line addresses, but you could also do Neil Parker's technique and scroll the screen in memory order (especially if you want an interesting visual effect, or if you are using page flipping). ,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~. | Jerry Penner, P.Eng. Z.I. Probes Inc. | | jerryp at ziprobes dot com Ph 403 462 3400 Fax 403 463 1567 | `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'