| |
Dr.j
Registered: Feb 2003 Posts: 277 |
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
|
|
... 8 posts hidden. Click here to view all posts.... |
| |
Dr.j
Registered: Feb 2003 Posts: 277 |
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.
|
| |
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
|
| |
Skate
Registered: Jul 2003 Posts: 494 |
even if we didn't get the actual problem, I think The Dr.j already diagnosed the problem himself. it's stack related and self modifying code should be the solution without changing his method. replace these "txa pha tya pha ... pla tay pla tax" with "sta sta ... lda lda" and it's solved. |
| |
SIDWAVE Account closed
Registered: Apr 2002 Posts: 2238 |
i fucked up my code. that code wont work as intended, and now i look like a fool :D |
| |
SIDWAVE Account closed
Registered: Apr 2002 Posts: 2238 |
Quote: even if we didn't get the actual problem, I think The Dr.j already diagnosed the problem himself. it's stack related and self modifying code should be the solution without changing his method. replace these "txa pha tya pha ... pla tay pla tax" with "sta sta ... lda lda" and it's solved.
he just forgot to do a pha FIRST and a PLA last, thats the only bug.. :D |
| |
Skate
Registered: Jul 2003 Posts: 494 |
@Jan Harries: Martin Piper already mentioned that and I'm not sure if it is the only problem.
Thing is, if you are not trying to optimize by code length, always use self modifying code. Only exception can be branched irq structures (which is usually a rare case for my coding style). Correct me if I'm wrong. |
| |
Devia
Registered: Oct 2004 Posts: 401 |
Quoting SkateThing is, if you are not trying to optimize by code length, always use self modifying code. Only exception can be branched irq structures (which is usually a rare case for my coding style). Correct me if I'm wrong.
Do you mean nested IRQs? - If so, then storing the regs along with the opcodes that loads them at their correct places will make nesting IRQs work like a charm.
If you indeed mean "branched" IRQ structures, I have no idea what you are referring to ;-)
|
| |
Skate
Registered: Jul 2003 Posts: 494 |
I mean when an irq starts at some point but ends conditionally in different points without sharing the same irq exit routine. I always prefer using the same irq exit routine but this can be needed when you don't have enough cycles for even a single JMP opcode. That's a rare but possible case. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
more usual case: effect is running at a fixed frame rate, and what's left for the 'main program' can be used for loading:
irq:
pha
txa
pha
tya
pha
...
lda running
bne itsrunning
inc running
cli <-- if effect runs for many frames more of this irq still may occur
jsr effect
dec running
itsrunning
...
pla
tay
pla
tax
pla
rti |
| |
Skate
Registered: Jul 2003 Posts: 494 |
of course there is still a chance to store a,x,y at zeropage (or any other available memory location) but stack is fine too :) |
Previous - 1 | 2 - Next |