![]() |
![]() |
#1 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,205
|
Cycle accurate delay loop
Say you have some classic 7MHz code that does a standard, stupid busy loop:
Code:
Loop: DBF D0,Loop Came up when I wanted to quickly extract A1000 startup sound as a more normal executable. This seems to work OK (empirically) on my machine: Code:
lsr.w #1,\1 .\@ tst.b $bfe001 dbf \1,.\@ |
![]() |
![]() |
#2 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
CIA Timer?
|
![]() |
![]() |
#3 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,205
|
|
![]() |
![]() |
#4 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,307
|
timer.device TR_ADDREQUEST and DoIO()?
|
![]() |
![]() |
#5 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
Quote:
Then I pass the multiplier as a parameter and do a dbf of that value (with a loop checking the underflow bit). |
|
![]() |
![]() |
#6 | |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,205
|
33 iterations of the loop is <5usec, I'll test (later) but I'm guessing it will be way off for small numbers. Quote:
Seems very reasonable. Bonus points to solutions that don't require setup though. Even if you do require setup, but use CIA for small numbers setup/check factors in... Difference of e.g. 10 CIA ticks doesn't matter too much, but if anyone can do better... ![]() |
|
![]() |
![]() |
#7 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,570
|
Manual audio mode and audio interrupts?
![]() |
![]() |
![]() |
#8 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,205
|
|
![]() |
![]() |
#9 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,369
|
here's what I use (Harry provided that code ages ago)
Code:
; < D0: value of D0 in line ; .x: DBF D0,x emulate_dbf swap D0 clr.w D0 swap D0 divu.w #$28,D0 swap D0 clr.w D0 swap D0 bsr beamdelay move.w #$FFFF,d0 rts ; < D0: numbers of vertical positions to wait beamdelay .bd_loop1 move.w d0,-(a7) move.b $dff006,d0 ; VPOS .bd_loop2 cmp.b $dff006,d0 beq.s .bd_loop2 move.w (a7)+,d0 dbf d0,.bd_loop1 rts Those busy waits end up having an impact on performance, so code rewrite would be better (with cia timers) but it's not trivial on an existing game code without source! |
![]() |
![]() |
#10 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,205
|
Yes, I've seen your beam delay function quite a bit
![]() Guess it should be possible to also use the HPOS part to improve the precision a bit (though in the the end it probably won't matter much). Mostly idle curiosity. |
![]() |
![]() |
#11 |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,719
|
|
![]() |
![]() |
#12 | |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,657
|
Quote:
![]() ROM, custom register, chip ram access speed is not enough. Raster is not enough, it will fail in productivity mode. CIA clock timing is the only accurate option for waits longer than 2-3us, if you don't use audio interrupts/requests. Busy-wait is still lazy and wasting resources, but you can use a one-shot CIA timer. Value set according to HRM. Between NTSC/PAL, the difference is small enough that you can use the largest value of the two. ![]() |
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Correct Game Loop and Event Loop? | mateusz_s | Coders. System | 0 | 28 March 2021 21:36 |
cycle exact cpu emulation speed, accurate ? | turrican3 | support.WinUAE | 1 | 23 December 2013 18:20 |
Loop optimization + cycle counts | losso | Coders. Asm / Hardware | 8 | 05 November 2013 11:50 |
ASM - Rolling Thunder sources - accurate delay | Asman | Coders. General | 5 | 21 September 2010 23:15 |
How accurate is the emulation? | manicx | support.WinUAE | 26 | 07 July 2003 08:35 |
|
|