Need help with text scrolling
-
mjassocies
- Posts: 2
- Joined: Sun Feb 01, 2026 2:31 pm
Need help with text scrolling
Hey, I'm really excited about the quality that UGBASIC offers! However, I've got a question. How do you do fine scrolling on a text-only screen? I already know how to scroll vertically, but it's not necessarily smooth like in games. Thanks for getting back to me!
-
spotlessmind1975
- Site Admin
- Posts: 218
- Joined: Fri Oct 06, 2023 8:25 pm
Re: Need help with text scrolling
Hi mjassocies, and welcome!
To achieve this, you can try this code.
The randomStars procedure feeds the drawing, simulating a continuous stream of stars. The PEN WHITE instruction, followed by the CLS instruction, is essential because the VIC-II chipset has a single video memory buffer for the color component. This means that when we perform software scrolling, the background will also scroll—however, since we're using double buffering, we'll always see the old background color on the screen. For this reason, I decided to assign a uniform white color to the entire screen. Note that if we hadn't used double buffering, we wouldn't have suffered from this limitation. The SCREEN COLUMNS statement allows you to "narrow" the screen, going from 40 columns to 38 columns. The two columns that aren't visible (located at the sides of the screen) will be populated as the screen scrolls. Since populating can take longer than a screen refresh, we do it on the unseen portion.
The ADD statement with this syntax allows you to summarize a limited increment between two extremes. It's like writing:
The HSCROLL SCREEN RIGHT statement allows you to scroll the screen to the right by an entire column, leaving the first column on the left blank and we draw the first column of stars by callng randomStars. Remember that this column is hidden, so you won't see it while redrawing! The WAIT VBL statement allows you to wait for the vertical blank to arrive, to avoid flickering, and the SCREEN HORIZONTAL SCROLL instruction allows you to set the VIC-II's hardware register to one of eight screen offsets: from 0 (the screen is completely aligned to the left) to 7 (the screen is shifted to the right by 7 pixels). It doesn't need to be higher than this, because once we reach 8 pixels, we'll be scrolling a full character. Finally, the SCREEN SWAP command allows you to switch the screen you're drawing on to the visible one, which is how we avoid flickering.
Please download the latest version of the compiler, which has been tested with this example program. I hope this was helpful!
Thank you very much for the compliments, and have a nice retrocoding!
On the Commodore 64 (with or without REU) and the Commodore 128, you can use the shift register on the VIC-II, as well as perform coarser software scrolling, and use double buffering to avoid flickering.
To achieve this, you can try this code.
Code: Select all
PEN WHITE
CLS
PROCEDURE randomStars
n = 0: REPEAT
LOCATE 0, RND(ROWS)
PRINT "*";
INC n
UNTIL n > 5
END PROC
SCREEN COLUMNS 38
DOUBLE BUFFER ON
randomStars[]
i = 0
DO
ADD i, 1, 0 TO 7
IF i = 0 THEN
HSCROLL SCREEN RIGHT
randomStars[]
ENDIF
WAIT VBL
SCREEN HORIZONTAL SCROLL i
SCREEN SWAP
LOOP
The ADD statement with this syntax allows you to summarize a limited increment between two extremes. It's like writing:
Code: Select all
i = i + 1
IF i > 7 THEN i = 0
IF i < 0 THEN i = 7Please download the latest version of the compiler, which has been tested with this example program. I hope this was helpful!
Thank you very much for the compliments, and have a nice retrocoding!
-
mjassocies
- Posts: 2
- Joined: Sun Feb 01, 2026 2:31 pm
Re: Need help with text scrolling
Thank you so mutch!