Smooth scrolling

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
kan
Posts: 15
Joined: Mon Sep 21, 2015 6:44 pm
Location: Seville, Spain

Smooth scrolling

Post by kan »

Hi,
After learning how to put pixels in the screen, I want to write an small example of double buffering and how to do an smooth scrolling.
I'm using the MODE 4, 256x192, and two pages for the screen data. The first one from $0200 to $19FF, the second one from $1A00 to $31FF.
My idea is to put some basic tiles in the same row and then move down and up. It writes to the page which isn't been displayed and then switch to it, so I can get an smooth scrolling.
However, I think that sometimes it flickers because I'm not doing anything related to vertical sync. I haven't found info about that, so any help will be appreciated. I think I have to check the register at $FF03, but I'm not sure.

I attach the source code (and the .cas file) so you can take a look at it.

Regards
Attachments
simplescroll.zip
(2 KiB) Downloaded 308 times
User avatar
Bosco
Posts: 330
Joined: Tue Mar 04, 2014 11:49 pm
Location: Nottingham, UK

Re: Smooth scrolling

Post by Bosco »

Hi kan.

Try adding the SYNC instruction just before switching your display's base address.

This should cause processing to wait until an interrupt is encountered, keeping you in sync with the vertical refresh.
sorchard
Posts: 530
Joined: Sat Jun 07, 2014 9:43 pm
Location: Norwich UK

Re: Smooth scrolling

Post by sorchard »

Hi kan, great to see you've figured out the double buffering!

As Bosco said, the sync instruction will wait for the vertical retrace.

I think there may also be a small bug. You have in a couple of places the instruction cmpa $00, where I think you may have intended cmpa #$00. If you change these then it fixes the flickering.
Stew
kan
Posts: 15
Joined: Mon Sep 21, 2015 6:44 pm
Location: Seville, Spain

Re: Smooth scrolling

Post by kan »

Hi,
Try adding the SYNC instruction just before switching your display's base address.

This should cause processing to wait until an interrupt is encountered, keeping you in sync with the vertical refresh.
I think the SYNC instruction waits until any interrupt is encountered, but I think I need something more to know if it was the vertical refresh.
I think there may also be a small bug. You have in a couple of places the instruction cmpa $00, where I think you may have intended cmpa #$00. If you change these then it fixes the flickering.
Yes, you're right. I fix it, altough it's still flickering.

Regards!
sorchard
Posts: 530
Joined: Sat Jun 07, 2014 9:43 pm
Location: Norwich UK

Re: Smooth scrolling

Post by sorchard »

kan wrote:I think the SYNC instruction waits until any interrupt is encountered, but I think I need something more to know if it was the vertical refresh.
There's a lot of truth in that statement but generally you use SYNC when you know which interrupt is coming next and in the specific case of the Dragon, the frame sync irq is usually the only active interrupt.

The other interrupt sources are: horizontal retrace (usually disabled); printer ack (usually disabled); cartridge (enabled but nothing happens without a cartridge); NMI (also comes from external hardware)

I added a sync instruction and corrected the cmpa instructions in the attached file. It doesn't flicker when I try it.
Attachments
simplescroll.zip
(1.11 KiB) Downloaded 310 times
Stew
simon
Posts: 163
Joined: Wed Nov 27, 2013 8:56 pm

Re: Smooth scrolling

Post by simon »

Hey there,

looks pretty good....

you can do away with your cmpa #0's you know ?

/Simon :-)
kan
Posts: 15
Joined: Mon Sep 21, 2015 6:44 pm
Location: Seville, Spain

Re: Smooth scrolling

Post by kan »

Hi,
There's a lot of truth in that statement but generally you use SYNC when you know which interrupt is coming next and in the specific case of the Dragon, the frame sync irq is usually the only active interrupt.

The other interrupt sources are: horizontal retrace (usually disabled); printer ack (usually disabled); cartridge (enabled but nothing happens without a cartridge); NMI (also comes from external hardware)
Ok, thanks for the info. So SYNC should work in a controlled but the most common case.
I added a sync instruction and corrected the cmpa instructions in the attached file. It doesn't flicker when I try it.
I tried your version, using XRoar, and I'm still getting the flicker when the tiles are in the beginning of the screen. Have you used the emu or running directly in a Dragon computer? Maybe I have anything pre-configured in my XRoar which makes other interrupts active.

However, I write a new version of the simple scroll program. I remove all the "cmpa #0" as Simon suggested... The 6809 is a great CPU when you learn well their instructions :)
Also, I tried something that I read elsewhere. I reduce the loops of cleaning the screen and putting the tiles, repeating the same instructions, such as:

Code: Select all

; *********************************************
; PCLS: Clear screen
; *********************************************	

PCLS   	PSHS	X
		LDY   	#TEMPTY
		LDA		#192
		LDU   	,Y
PCLSLOP STU     ,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		STU   	,X++
		DECA
		BNE		PCLSLOP
		PULS	X,PC
It has less opcodes so it's faster, altough the code looks worse :D

Regards
Attachments
simplescroll_v2.zip
(2.03 KiB) Downloaded 300 times
simon
Posts: 163
Joined: Wed Nov 27, 2013 8:56 pm

Re: Smooth scrolling

Post by simon »

check if xroar is configured for PAL or NTSC !

SPEED IS NOT ABOUT NICE LOOKING CODE !

/Simon :-)
kan
Posts: 15
Joined: Mon Sep 21, 2015 6:44 pm
Location: Seville, Spain

Re: Smooth scrolling

Post by kan »

Hi Simon,
Yes! I chose "PAL 60 Hz" and then there isn't any flickering. Thanks guys for your help.

Next post will be an (again) enhanced version for the simple scroll example.

Regards
Post Reply