English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 18 July 2020, 00:40   #1
Quagliarulo
Registered User
 
Quagliarulo's Avatar
 
Join Date: Mar 2010
Location: Napoli, Italia
Posts: 76
Busy wait for screen lines

Hello, consider this code (adapted from an exercise I'm doing - I can provide the real source if needed):

Code:
; Wait for line 100
loop1:
	move.l	$dff004,D0
	lsr.l	#8,D0
	and.w	#%111111111,D0
	cmp.w	#100,D0
	bne.s	loop1

; Wait for line 310
loop2:
	move.l	$dff004,D0
	lsr.l	#8,D0
	and.w	#%111111111,D0
	cmp.w	#310,D0
	bne.s	loop2

; Do something and repeat forever
	bsr do_something
	bra loop1
Assume we are in lores 320x256. We wait for line 100, then we wait for line 310, which is much further down the screen. Removing the first loop, I would expect "do_something" to be executed at the same pace as before; instead, it's called twice as fast.
Why is this?
Quagliarulo is offline  
Old 18 July 2020, 00:58   #2
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by Quagliarulo View Post
Hello, consider this code (adapted from an exercise I'm doing - I can provide the real source if needed):

Code:
; Wait for line 100
loop1:
	move.l	$dff004,D0
	lsr.l	#8,D0
	and.w	#%111111111,D0
	cmp.w	#100,D0
	bne.s	loop1

; Wait for line 310
loop2:
	move.l	$dff004,D0
	lsr.l	#8,D0
	and.w	#%111111111,D0
	cmp.w	#310,D0
	bne.s	loop2

; Do something and repeat forever
	bsr do_something
	bra loop1
Assume we are in lores 320x256. We wait for line 100, then we wait for line 310, which is much further down the screen. Removing the first loop, I would expect "do_something" to be executed at the same pace as before; instead, it's called twice as fast.
Why is this?
It depends on what 'do_something' does

If it is a very fast routine it can also be performed twice in the same video line.
ross is offline  
Old 18 July 2020, 09:21   #3
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Quagliarulo View Post
Hello, consider this code (adapted from an exercise I'm doing - I can provide the real source if needed):

Code:
; Wait for line 100
loop1:
	move.l	$dff004,D0
	lsr.l	#8,D0
	and.w	#%111111111,D0
	cmp.w	#100,D0
	bne.s	loop1

; Wait for line 310
loop2:
	move.l	$dff004,D0
	lsr.l	#8,D0
	and.w	#%111111111,D0
	cmp.w	#310,D0
	bne.s	loop2

; Do something and repeat forever
	bsr do_something
	bra loop1
Assume we are in lores 320x256. We wait for line 100, then we wait for line 310, which is much further down the screen. Removing the first loop, I would expect "do_something" to be executed at the same pace as before; instead, it's called twice as fast.
Why is this?

This is something that can trip you up if you don't understand the video beam properly.

I would suggest you watch the first 4 minutes of the video below:
[ Show youtube player ]

The Amiga can track the 312 vertical PAL lines but you also have the horizontal time it takes to get from one line to the next. As Ross says your routine is probably executing twice on the same line because your loop is checking if it present on the same line.

If you want to fix it, then check you have reached a line (which you have), then you can either wait for the beam to reach a horizontal position on the line or wait until you reach a VPOS that is different to the one you are currently on.

This tripped me up on one Bomb Jack Beer Edition where the round start sequence moved faster on AGA machines.

Geezer
mcgeezer is offline  
Old 18 July 2020, 11:21   #4
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
There is also another reason why I ALWAYS advise against doing such a single check.

Nobody assures you that your code can be executed on that line!
Okay, no problem in a test program, but when does the program get complex?
When do you have IRQs arriving at unpredictable moments (like a CIA timed IRQ) and it use all the line time?
You risk failing because, for your check code, this line is never existed and, for the frame, code is skipped...

So always do a cross check and not for Z but for different conditions.
ross is offline  
Old 18 July 2020, 11:28   #5
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
I would personnally never do an equality check for a scan line, but a check for greater than. This alone can eliminate a lot of troubles.
meynaf is offline  
Old 18 July 2020, 12:17   #6
Quagliarulo
Registered User
 
Quagliarulo's Avatar
 
Join Date: Mar 2010
Location: Napoli, Italia
Posts: 76
Thanks for all your advice. I know that the code I posted is blasphemy, but I had to understand.
The BNE was the problem!
Quagliarulo is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Upgraded WHD load, now black screen with white lines?! dabbler project.WHDLoad 12 14 February 2020 22:33
Repeating vertical lines on screen on A2000 with ScanPlus ECS scandoubler 5kb support.Hardware 3 03 January 2020 03:55
Busy Waiting or avoiding it Nightshft Coders. Blitz Basic 7 03 November 2019 19:21
Drawing lines off the screen h0ffman Coders. Asm / Hardware 7 23 August 2014 01:22
stingray being busy extralife request.Demos 30 08 January 2013 16:44

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:30.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.33042 seconds with 15 queries