![]() |
|
|||||||
| Register | >> Amiga FAQ/Wiki << | Rules & Help | Members List / Moderators List | Search | Today's Posts | Mark Forums Read |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Zone Friend
|
ASM: Wait for Vertical Blank
I'm looking for best/accurate wait vb routine. Any examples are welcome
![]()
__________________
Asman |
|
|
|
|
|
#2 |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
I do it like this:
Code:
.loop move.l $dff004,d0 and.l #$1ff00,d0 cmp.l #303<<8,d0 bne.b .loop |
|
|
|
|
|
#3 |
|
In deep Trouble
Join Date: Sep 2004
Location: Manchester, Made in Norway
Age: 40
Posts: 802
|
what does the << in the cmp.l line do?
|
|
|
|
|
|
#4 |
|
Registered User
Join Date: Feb 2010
Location: Germany
Posts: 30
|
#303<<8 should be a shift 8 bits to the left
303 == $12f, so #$12f<<8 becomes #$12f00 given the initial and.l #$1ff00,d0 basically the comparison is only for bits 33-16 of the value initially read in d0 why this works is a mystery to me, but I assume StingRay knows what he's doing ![]() By the way, just this morning I was playing around with the exec routines to add my handler to the vertical blank interrupt, is there a lot of difference in performance? I took and modified the code from the HRM, something on the lines of Code:
move.l _GfxBase,a6
jsr _LVOOwnBlitter(a6)
move.l $4.w,a6
jsr _LVOForbid(a6)
moveq.l #INTB_VERTB,d0
lea VBlankServer(pc),a1
jsr _LVOAddIntServer(a6)
|
|
|
|
|
|
#5 |
|
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 38
Posts: 11,937
|
|
|
|
|
|
|
#6 | ||
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
Quote:
![]() Quote:
|
||
|
|
|
|
|
#7 |
|
Zone Friend
|
I find
Code:
wait_vb .1 btst #0,(_custom+vposr+1) beq .1 .2 btst #0,(_custom+vposr+1) bne .2\@ rts ![]()
__________________
Asman |
|
|
|
|
|
#8 |
|
Leffmann with two n's
Join Date: Jul 2008
Location: Sweden
Posts: 1,187
|
Looks perfectly fine to me, and it's both safe for all displays up to 512 scanlines and guaranteed to only run once per frame, as opposed to a single wait that might run several times if the other code in the loop finishes in less than 1 scanline.
I use this, works with any operand like WaitLine D3, #$FF, (A0)+ etc. Code:
WaitLine macro
.\@ move.l vposr(a6), d0
lsr.l #1, d0
lsr.w #7, d0
cmp.w \1, d0
bne .\@
endm
|
|
|
|
|
|
#9 | |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
Quote:
Code:
.loop move.l $dff004,d0 and.l #$1ff00,d0 cmp.l #303<<8,d0 bne.b .loop .loop2 move.l $dff004,d0 and.l #$1ff00,d0 cmp.l #303<<8,d0 beq.b .loop2 |
|
|
|
|
|
|
#10 |
|
Leffmann with two n's
Join Date: Jul 2008
Location: Sweden
Posts: 1,187
|
No there's not a whole lot of code that will run in less than 1 scanline, BUT there are a few very good examples that will, and many more things run under WinUAE with JIT and immediate blitter or on a faster system might as well.
Try something like a simple fade to black of a 16 color screen in 12-bit RGB on an 060 and you'll be looking at 1 scanline or less. I'm just saying the check for the MSB switch from 1 to 0 is safe, short, and works for all programmed displays. If people wrote solid code to begin with they wouldn't have to sit in sorry hindsight when their code freaks out on faster systems, and people like you wouldn't have to sit and WHD-fix poor games that won't run on A1200 ![]() |
|
|
|
|
|
#11 |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
I know that they exist, I wrote that the likelihood is "not very high" after all (WinUAE and JIT do not count for me!). In 99% of all cases a standard "wait for line xxx" routine does the job without wasting cycles.
|
|
|
|
|
|
#12 |
|
Zone Friend
|
@Leffmann, StingRay - thanks a lot.
Is there any difference between Code:
wait_vb_1 .1 btst #0,(_custom+vposr+1) beq .1 .2 btst #0,(_custom+vposr+1) bne .2 rts Code:
wait_vb_2 .1 btst #0,(_custom+vposr+1) bne .1 .2 btst #0,(_custom+vposr+1) beq .2 rts And second ( stupid ) question. Is legal to do btst on odd address _custom+vposr+1 ?
__________________
Asman |
|
|
|
|
|
#13 |
|
is long gone
Join Date: Apr 2007
Location: London
Posts: 1,590
|
@ Asman - btst when used with mem locations is btst.b so yes, testing bytes at odd mem locations is legal.
I used a btst to an odd mem address (intreqr+1) in my trackloader. |
|
|
|
|
|
#14 | ||
|
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 38
Posts: 11,937
|
Quote:
)Quote:
![]() Byte writes to custom registers may not work properly with all accelerator models (Blizzard 1260 for example, only to odd or even bytes, if I remember correctly) |
||
|
|
|
|
|
#15 |
|
Moderator
|
I would avoid waiting for a fixed raster line number. Because if there are interrupts like sound via cia interrupt or also a keyboard handler which uses direct wait for ack, it may tigger not in the following frame or several frames later.
|
|
|
|
|
|
#16 | |
|
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 38
Posts: 11,937
|
Quote:
![]() There is no 100% safe way to wait for vblank if "random" interrupts are enabled. |
|
|
|
|
|
|
#17 | ||
|
Moderator
|
Quote:
Quote:
![]() |
||
|
|
|
|
|
#18 |
|
Moderator
|
|
|
|
|
|
|
#19 |
|
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 38
Posts: 11,937
|
|
|
|
|
|
|
#20 | ||
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
Quote:
Quote:
![]() Maybe a better way would be to set a flag in the VBI and poll that flag in the mainloop? Disadvantage is that you need a vertical blank interrupt though. Last edited by StingRay; 10 April 2010 at 20:25. Reason: additions |
||
|
|
|
|
|
#21 | |
|
Zone Friend
|
Quote:
__________________
Asman |
|
|
|
|
|
|
#22 |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
Actually it is not that rare, a lot of demos from "the good old days" (i.e. 50FPS effects or die! ;D) do everything in the VBI and the only thing they do outside the VBI is checking left mouse button.
|
|
|
|
|
|
#23 |
|
Oldskool Demo Coder
|
I execute "stuff to happen at Vblank" with a Vblank interrupt
Or use a lib function. If you have a copper running you can write to INTREQ and poll a bit. If you have random ints running you can have a bhs-wait for a rasterline and a bhi-wait to make sure you leave it in case you do nothing that frame.The Amiga is versatile ![]()
__________________
Henrik. Programs Amiga demos, iPhone apps, websites, etc. A1000/512k - A500 2.0/040@28/4M/.5M slowmem/8M/SCSI/CF - A600 portable II 3.1/ACA630/WiFi/CF - 'A1700' 3.1/68060@80/64M/IDE-Fix Express/CF - etc."The difference between PC and Amiga is that 10yo PCs are worth $0. 20yo Amigas are worth a lot, and Amigas that are only 15yo cost a fortune!" If you like Portal 2, try my >> single player and cooperation maps << |
|
|
|
|
|
#24 | |
|
is long gone
Join Date: Apr 2007
Location: London
Posts: 1,590
|
Quote:
My good old days are today! \o/ ![]() |
|
|
|
|
|
|
#25 | |
|
Registered User
Join Date: Dec 2007
Location: Dark Kingdom
Posts: 114
|
Quote:
I do remember that HRM says its legal to read/write a pair of registers with a long access, and that since many (or all?) registers are either read-only or write-only, it is illegal to access a register with a CPU instruction that perform both a read and a write on its operand like CLR on 68000, or BSET/BCLR. But BTST should only read its operand, I think. |
|
|
|
|
|
|
#26 | |
|
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 38
Posts: 11,937
|
Quote:
A500: 0x12 byte write is written as 0x1212 but in some accelerators it can be 0x0012 or even 0x<garbage byte>12 or something similar. (afaik whdload AUDxVOL byte write fixes on 68060 are needed because of above "feature") (getting a bit offtopic, sorry) |
|
|
|
|
|
|
#27 |
|
Zone Friend
|
Just for clarification. About byte read from custom register ($dff005). If I understand correctly below code
Code:
wait_vb_2 .1 btst #0,(_custom+vposr+1) bne .1 .2 btst #0,(_custom+vposr+1) beq .2 rts Code:
wait_vb_2 moveq #1,d0 lea (_custom+vposr),a0 .1 move.w (a0),d1 and.w d0,d1 bne .1 .2 move.w (a0),d1 and.w d0,d1 beq .2 rts
__________________
Asman |
|
|
|
|
|
#28 |
|
Registered User
Join Date: Jan 2012
Location: USA
Posts: 84
|
A bit off-topic, but I'd give yourself some more processing time by waiting for the last displayable scanline instead of VB. The best place to begin running code for the next frame if single-buffering is often just after the last displayable line, especially if some memory needs to be cleared. You get almost double the normal memory bandwidth when there's no other DMA going on. Pairing MOVEM with a blitter memory clear is especially fast. A blit using channels BCD (a rectangular bitmap move, for example) runs nicely in parallel with the CPU during the overscan areas, even with blitter-nasty turned on.
If you're double buffering, beginning your processing at the first line is often best, especially if you're calling anything in ROM. |
|
|
|
|
|
#29 | |
|
Moderator
|
Quote:
|
|
|
|
|
|
|
#30 |
|
tulou
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 35
|
I usually set a flag in the vblank isr, like this:
Code:
bset.b #0,flags(pc) Code:
.wait bclr.b #0,flags(pc) beq.b .wait |
|
|
|
|
|
#31 |
|
Registered User
Join Date: Nov 2009
Location: Herford / Germany
Posts: 264
|
Your approach is recommendable, although the PC-relative addressing mode is not allowed here.
![]() In Sqrxz I am incrementing a frame counter during a copper interrupt, caused at the bottom of the display. The rendering routine can then compare its frame counter with the hardware frame counter and decide to either drop the frame, when the hw-counter is higher, or wait until both are equal again. |
|
|
|
|
|
#32 |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
The disadvantage is that you need a level 3 interrupt which is not always what you want.
![]()
__________________
Makes me sick when I hear all the shit that you say So much crap coming out, it must take you all day There's a space kept in hell with your name on the seat With a spike in the chair just to make it complete |
|
|
|
|
|
#33 |
|
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 36
Posts: 1,587
|
Why not do it properly and use the VBL interrupt instead of doing it like they do it on the peecee? On the peecee polling is necessary, on the Amiga it's not
![]()
__________________
Random number generation is the art of producing pure gibberish as quickly as possible. - Bob Jenkins |
|
|
|
|
|
#34 |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
It can be done "properly" without a VBL interrupt too! And there are situations where you just don't want any interrupts at all.
__________________
Makes me sick when I hear all the shit that you say So much crap coming out, it must take you all day There's a space kept in hell with your name on the seat With a spike in the chair just to make it complete |
|
|
|
|
|
#35 | |
|
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 36
Posts: 1,587
|
Of course, but it's peecee like and therefore uncool
![]() Quote:
)?
__________________
Random number generation is the art of producing pure gibberish as quickly as possible. - Bob Jenkins |
|
|
|
|
|
|
#36 |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
So you call more than 50% of the old and classic demos "uncool"?
Interrupt processing needs CPU time, need I say more?
__________________
Makes me sick when I hear all the shit that you say So much crap coming out, it must take you all day There's a space kept in hell with your name on the seat With a spike in the chair just to make it complete |
|
|
|
|
|
#37 | |
|
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 36
Posts: 1,587
|
Quote:
Does it take up so much time you'd use polling? That sucks ![]() Maybe I'm missing the point ![]()
__________________
Random number generation is the art of producing pure gibberish as quickly as possible. - Bob Jenkins |
|
|
|
|
|
|
#38 | |
|
Registered User
Join Date: Jan 2012
Location: USA
Posts: 84
|
Quote:
And then you have to worry about the time it takes for the current instruction to complete before interrupt handling can even begin. A DIVU can delay interrupt handling by 100+cycles. This can be helped by executing a STOP and waiting for an interrupt, but the E-clock still complicates things. There are even situations where an interrupt handler must be padded with a variable number of instructions based on the predicted phase of the E-clock so as to perfectly time 68000 writes to chip registers. This might happen when reprogramming the sprite registers with a MOVEM in the middle of a scanline. Polling is quick and simple. |
|
|
|
|
|
|
#39 |
|
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 38
Posts: 11,937
|
|
|
|
|
|
|
#40 | |
|
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 4,541
|
Quote:
![]()
__________________
Makes me sick when I hear all the shit that you say So much crap coming out, it must take you all day There's a space kept in hell with your name on the seat With a spike in the chair just to make it complete |
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 'Wait' program that checks for a joy button press instead of 'Return' key... | Heavy Stylus | request.Apps | 7 | 10 May 2009 19:01 |
| timed wait using CIAs | jotd | support.Other | 3 | 23 March 2008 14:55 |
| HD won't boot now..wait failed returncode? | Amigan25 | project.ClassicWB | 2 | 08 June 2007 18:21 |
| vertical sync flickers | PiCiJi | support.WinUAE | 2 | 25 September 2004 14:34 |
| Wait a sec - what about Macs? | Computolio | Amiga scene | 10 | 02 June 2004 07:23 |