Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > wonder for delay routine
2010-05-03 10:26
Dr.j

Registered: Feb 2003
Posts: 276
wonder for delay routine

i use this delay routine.

when i replace BPL command to BNE command it don't
work properly. i trying to figure why and i really don't know. i guess it may brake the Stack order and then
don't get back from the place i called this JSR.

bigdelay:
txa
pha
tya
pha
ldx #$ff
r1:ldy #$ff
!: dey
bpl !-
dex
bpl r1
pla
tay
pla
tax
rts



2010-05-03 10:34
Oswald

Registered: Apr 2002
Posts: 5023
you should have an idea maybe whats the difference between bpl & bne. look them up, dont make us do the work instead of you.
2010-05-03 11:13
Frantic

Registered: Mar 2003
Posts: 1628
I don't see any obvious problem with this code. As long as the jumps do not jump past the restoring of the X and Y registers, there should be no messed up stack. However, you don't save the A register, if that is the problem? I.e. the A register will not have the same value after leaving this routine as it had before (if you're not simply lucky: 1/256 chance).
2010-05-03 11:44
Dr.j

Registered: Feb 2003
Posts: 276
to Oswald: i know the differance, it was not the point
i don't understand why the routine goes wrong when
i use BNE instead of BPL . i guess it mess the stack
pointers . anybody know this problem?

to Frantic: i don't care for the A register. i want
to know why when i use the BNE instead of BPL in this
routine , it's going wrong .
2010-05-03 11:55
Oswald

Registered: Apr 2002
Posts: 5023
yes, sorry, you didnt made it clear (not even until now) how does it go wrong, I thought you have problem with the change in the amount of delay :) just like frantic I see no bugs in there, and the stack pointer shouldnt be affected.

try this without any code running before:

u
jsr delay
jmp u

does this work fex. ? if yes you have a bug, but not in the delay routine..
2010-05-03 12:00
j0x

Registered: Mar 2004
Posts: 215
Well, with the bpl's, you'll never branch.

With the bne's you'll have a delay of a few tenths of a second, with the bpl's you'll have a delay of a few tens of cycles.

Or have I been sniffing too much glue?
2010-05-03 12:10
Frantic

Registered: Mar 2003
Posts: 1628
@J0x: No.. just the right amount of glue, it seems. I seem to have had too much though. Of course those BPL's should be replaced for BMI's (for example).

@Dr.J: ...because BPL branches when the value is between $00-$7f, which means, as J0x says, that it will never branch. The code will just fall through.
2010-05-03 13:02
Martin Piper

Registered: Nov 2007
Posts: 644
Changed lines begin with a *
bigdelay:
*pha
txa
pha
tya
pha
ldx #$ff
r1:ldy #$ff
!: dey
*bne !-
dex
*bne r1
pla
tay
pla
tax
*pla
rts

Assuming you want the branches to loop and cause a "big delay" and also you want A saved.

bpl won't work as you intended since:
ldx #$ff
l1: dex ; X now = $fe
bpl l1 ; X $fe is negative (MSB is set), so "branch on plus" will never trigger since there is no loop.

Compare this with:
ldx #$f
woo: dex
bpl woo ; Will trigger because $f-1 ($e) is "plus" (positive) for a few interations.

Or with:
ldx #$ff
woo2: dex
bne woo2 ; Will trigger because $ff-1 ($fe) is "not equal" to 0 for a lot of interations.
2010-05-03 13:17
Skate

Registered: Jul 2003
Posts: 491
I think The Dr.j knows how bpl works but he missed the fact how signed numbers work.

Edit: Btw, this should be the best solution I guess

    stx storeX
    sty storeY
    ldx #$00
    ldy #$00
-   dex
    bne -
    dey
    bne -
    ldx #$00 : storeX = *-1
    ldy #$00 : storeY = *-1
2010-05-03 14:08
Dr.j

Registered: Feb 2003
Posts: 276
thanks for your replies. ofcourse i know what means
BPL and BNE -it wasn't the question , i guess i didn't asked as i should do :-(
my english isn't so well. i later post the all block of
code and i hope to figure out my specific problem.
2010-05-03 14:41
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
youre all wrong. read his code again :D

there is an easier way to make a pause of any length you want.. and that is to make a trigger that tells you exactly when to execute parts of your routines:


exe .byt 0
p1 .byt ff
p2 .byt ff
p3 .byt ff
(add as many as you want)

init:
lda #0 ;call this first, outside irq
sta exe
rts


count1:
dec p1 ;call this in irq 1 time pr frame
beq count2
rts

count2:
dec p2
beq count3
rts

count3:
dec p3
beq doit
rts

doit:
lda #1 ;set the signal to the irq, that you shall execute your wanted parts.
sta exe
rts


in your irq, do this:

lda exe
bne doit ;will GO when exe=1

sec
bcs exit ;else, skip the triggered part

doit:
jsr theroutine-you-want-to-trigger

exit:
... ;the rest of your current irq
...
...
rti



the idea is, you call this in irq.
it does absolutely nothing, it just counts, to exactly the moment you want, then set the execute flag, which you read, and do your stuff ONLY when the execute flag is set.
so instead of using a busy loop, you can use a trigger, which this is.

just edit the p1,p2,p3 bytes or how many you have, to fit so it makes the pause you need.


if you need a pause of x cycles, then its much better to make a bunch of NOP NOP NOP and maybe a BIT $02 or some other opcodes, to wait exactly the nr of cycles you need. :D
 
... 8 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
zscs
tlr
Knut Clausen/SHAPE/F..
Marvin
JEZ
hedning/G★P
Sentinel/Excess/TREX
Didi/Laxity
Guests online: 136
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 S!R  (9.7)
5 Faayd  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.054 sec.