English Amiga Board


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

 
 
Thread Tools
Old 21 August 2020, 08:48   #1
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
blitter waits and hardware bugs

Something I'm not sure of even today


Is that a correct way to wait for blitter on all machines?


Code:
.wait
    BTST    #6,$DFF002
    BNE.B    .wait

or should we add something like


Code:
   tst.b $BFE001

or something first to wait a while before waiting?


Isn't there a bug in some machine chipset (like A4000) that makes the blitwait inefficient in some circumstances ?
jotd is offline  
Old 21 August 2020, 08:57   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by jotd View Post
Is that a correct way to wait for blitter on all machines?
The correct way is to call WaitBlit() of the graphics library. The problem with the blitter is that it has a couple of issues, depending on the machine, where it does not yet indicate that the blit has started because the CPU is ahead of the blitter, and the latter only updates its state based on the 7Mhz clock of the custom chips. Another issue the blitter has that it may erase the blitter-busy flag too soon while, in fact, the last word is still being blitted.

The graphics.library contains workarounds for such issues, it is thus the recommended way.
Thomas Richter is online now  
Old 21 August 2020, 09:37   #3
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Quote:
Originally Posted by Thomas Richter View Post
The correct way is to call WaitBlit() of the graphics library. The problem with the blitter is that it has a couple of issues, depending on the machine, where it does not yet indicate that the blit has started because the CPU is ahead of the blitter, and the latter only updates its state based on the 7Mhz clock of the custom chips. Another issue the blitter has that it may erase the blitter-busy flag too soon while, in fact, the last word is still being blitted.

The graphics.library contains workarounds for such issues, it is thus the recommended way.
It would be nice if you could unlock the details of these workarounds for the many scenarios where the programmer is unable/unwilling to keep the operating system running.
alpine9000 is offline  
Old 21 August 2020, 09:55   #4
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 839
Quote:
Originally Posted by jotd View Post
Is that a correct way to wait for blitter on all machines?
I'm sure Toni has a better explanation, but there is a bug that makes BUSY not flag until the blitter has actually started working. The workaround is thus that after an access to the chip bus you will be guaranteed that it actually has. (Correct?)

I don't know what revision fixed this to flag it as soon as the size register is written.
NorthWay is offline  
Old 21 August 2020, 10:02   #5
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
Quote:
Originally Posted by jotd View Post
Something I'm not sure of even today

Is that a correct way to wait for blitter on all machines?
Code:
.wait
    BTST    #6,$DFF002
    BNE.B    .wait
No, this code can fail on some machines. There are early Agnus chips that have a bug starts their blits one cycle later than normal. On such machines the above will fail. Not that many of these machines exist, so it's not that likely you'll have personally run into this issue. However, they do exist and the Blitwait above will fail on them.
Quote:
or should we add something like
Code:
   tst.b $BFE001
or something first to wait a while before waiting?
Adding any custom chip access is enough to bypass the issue above. Most programs just do a tst.w $DFF002 or similar. Accessing the CIA will also work, but does waste a few cycles
Quote:
Isn't there a bug in some machine chipset (like A4000) that makes the blitwait inefficient in some circumstances ?
I'm unaware of this, but I'm kind of doubtful. If BlitWaits were more inefficient on A4000's, lot's of games (including AGA ones) would not run well on them and I don't recall any such issues being mentioned. However, I have no evidence either way so it could be true.
Quote:
Originally Posted by alpine9000 View Post
It would be nice if you could unlock the details of these workarounds for the many scenarios where the programmer is unable/unwilling to keep the operating system running.
The OS BlitWait routine for several Kickstart versions has been disassembled ages ago and the core of it works like the idea pointed out here (the loop above + one additional wait). Some versions add a few NOP's to keep the CPU in ROM and out of chipmemory a bigger percentage of time to optimise the waiting, though.

Note that the HRM provides Blitter Waiting code which also works like how it's been described in this thread (below is a copy from the HRM Blitter examples):
Code:
waitblit:
        btst.b  #DMAB_BLTDONE-8,DMACONR(a1)
waitblit2:
        btst.b  #DMAB_BLTDONE-8,DMACONR(a1)
        bne     waitblit2
        rts
Edit: the original source for the HRM code segment I copied can be found here http://amigadev.elowar.com/read/ADCD.../node02DE.html

Last edited by roondar; 21 August 2020 at 10:12.
roondar is offline  
Old 21 August 2020, 10:13   #6
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
I'm guessing that turning on BLITHOG before the "broken" wait loop and turning it off after the wait loop would avoid any issues as that would give you the required custom chip access ?
alpine9000 is offline  
Old 21 August 2020, 10:17   #7
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
Quote:
Originally Posted by alpine9000 View Post
I'm guessing that turning on BLITHOG before the "broken" wait loop and turning it off after the wait loop would avoid any issues as that would give you the required custom chip access ?
Yes, this is another common solution. It also has the extra benefit of making the waiting impact the Blitter a lot less, so the Blit will be done faster.
roondar is offline  
Old 21 August 2020, 10:29   #8
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
A1000 blitter sets BUSY when it gets first memory cycle. All (?) blitters clear BUSY when it has internally processed last word, not when last word gets written to memory. (which means at least 2 cycle delay). EDIT: this is almost always harmless (unless you access exact same word with CPU in next cycle) because any blitter register can be written safely during this period, including BLTSIZE. (which needed extra logic in emulation because there was demo that did it..)

Quote:
Originally Posted by Thomas Richter View Post
The correct way is to call WaitBlit()
I think you should already know that even when this is correct answer, it is also useless answer in this forum.
Toni Wilen is offline  
Old 21 August 2020, 10:31   #9
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
Quote:
There are early Agnus chips that have a bug starts their blits one cycle later than normal. On such machines the above will fail. Not that many of these machines exist, so it's not that likely you'll have personally run into this issue. However, they do exist and the Blitwait above will fail on them.
So possibly it could happen with A500+ACA accelerator right? A500 alone could leave that bug unnoticed, but accelerating it with a buggy Agnus could trigger issues I guess.

Quote:
I think you should already know that even when this is correct answer, it is also useless answer in this forum.
Yeah, I wanted to answer exactly that. Slightly condescending and all like RTFM... but in my case (I'm fixing an OS-compliant game) that could actually be an option. But I'd prefer a routine that I can paste in any context, even with OS down.

Maybe Toni you could add a special "agnus bug" option to be able to reproduce those bugs. I already love your "chipset hack" to find broken audio replays, it helped a lot. Maybe adding another bit in chipset hack could be enough.
jotd is offline  
Old 21 August 2020, 10:34   #10
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
Quote:
Originally Posted by Toni Wilen View Post
All (?) blitters clear BUSY when it has internally processed last word, not when last word gets written to memory. (which means at least 2 cycle delay)
Interesting. That makes me wonder: are there situations in which this causes issues? For instance, suppose I start setting Blitter registers immediately after BUSY is cleared, can this go wrong? Or is the fact that the Blitter has internally processed the last word already enough to prevent issues in this case.

I suppose it's possible an issue could arise if the CPU tries to read the very last word blit directly after BUSY is cleared. On fast machines this should then give the CPU the old pre-blit answer rather than the new. Not sure this is really going to cause many issues, but it's certainly interesting!
Quote:
Originally Posted by jotd View Post
So possibly it could happen with A500+ACA accelerator right? A500 alone could leave that bug unnoticed, but accelerating it with a buggy Agnus could trigger issues I guess.
This should really only affect the A1000. But, it's always wise to have the extra access just in case
roondar is offline  
Old 21 August 2020, 10:35   #11
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
So maybe waiting BEFORE writing to blitter registers is more dangerous than waiting just after having written to BLTSIZE (even if the first solution is less wasteful because the CPU can work in the meantime, specially when the blit is interleaved)

I rarely could insert blitwaits before blitter operations in games I fixed. It almost never worked... But it's also more difficult because if another routine changes a bitter register (not BLTSIZE) before you wait, you're toast.
jotd is offline  
Old 21 August 2020, 10:51   #12
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
Quote:
Originally Posted by jotd View Post
So maybe waiting BEFORE writing to blitter registers is more dangerous than waiting just after having written to BLTSIZE (even if the first solution is less wasteful because the CPU can work in the meantime, specially when the blit is interleaved)
It would seem to me that it's still safe considering what Toni wrote. Edit: it's also what I've always done without any known issues.

However, I'll defer judgement of this to Toni - he knows a heck of a lot more than me, that's for sure.
roondar is offline  
Old 21 August 2020, 22:15   #13
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
I fixed the incorrect blitter errors and it seems to have done it for a A4000/040 user...

http://mantis.whdload.de/view.php?id=4440

so thanks. And it seems that some A4000 machines have an issue like this too...
jotd is offline  
Old 21 August 2020, 22:31   #14
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
There is this interesting old thread: http://eab.abime.net/showthread.php?t=31758
I would like to understand why the addition of waits with CIA access improves the situation on fast machines..
The maximum I had at the time was a 030/50 so the fewer wasted waits I did the better it was
ross is offline  
Old 21 August 2020, 22:41   #15
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
it's probably not wasted if you have to wait most of the time anyway.
jotd is offline  
Old 21 August 2020, 23:11   #16
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by jotd View Post
it's probably not wasted if you have to wait most of the time anyway.
Well, I'm against code waste
ross is offline  
Old 22 August 2020, 11:58   #17
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
My guess is that using the CIA to wait is simply a good way to wait a specified number of cycles. Why this affects faster machines more is an interesting question though, it doesn't feel like it should - most of these machines access chip memory slower than the A1200 does.
roondar is offline  
Old 22 August 2020, 12:12   #18
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
I guess one unknown when the question was asked (which is now known) feature was blitter idle cycles being usable by the CPU but if blitter nasty is off and CPU steals cycle from blitter (by reading DMACONR) and it was going to be blitter idle cycle: blitter loses the cycle. Without cycle steal both blitter and CPU would have "used" it.
Toni Wilen is offline  
Old 22 August 2020, 12:28   #19
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by Toni Wilen View Post
I guess one unknown when the question was asked (which is now known) feature was blitter idle cycles being usable by the CPU but if blitter nasty is off and CPU steals cycle from blitter (by reading DMACONR) and it was going to be blitter idle cycle: blitter loses the cycle. Without cycle steal both blitter and CPU would have "used" it.
So that's one more reason to use blitter nasty before the wait. But when I have blitter operations that don't use all available cycles? What is the best technique for the wait?
ross is offline  
Old 22 August 2020, 14:56   #20
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
well if the code is running in chipmem and if you enable blitter nasty I guess you don't even have to loopwait. Enable it, wait just enough so the blitter understands that it can steal all cpu and disable it again.
jotd 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
Amiga 1200 hardware fixes for Gayle bugs Mick support.Hardware 0 10 November 2019 12:59
Triple buffering, blitter queues and bugs deimos Coders. General 0 03 October 2019 11:25
Blitter settings + amiga hardware ref. Legionary Amiga scene 1 25 September 2016 16:57
Chip's Challenge slowdown due to blitter waits Gaula92 project.WHDLoad 33 10 March 2013 16:43
Lack of blitter waits on A500 Codetapper Coders. Asm / Hardware 3 09 September 2012 13:45

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 16:26.

Top

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