| |
Hurrican
Registered: Oct 2003 Posts: 10 |
Setting up a timer interrupt
Hello *.*,
I'm trying to set up a timer interrupt to make something happen at a regular basis (let's say: every 5 seconds). I already managed to do a raster interrupt, but setting up a timer interrupt beats me. After browsing the web I came up with this code:
----------------------8<----------------------8<---------
inittint lda #$7f
sta $dc0d ; disable cia1 int
lda $dc0e
and #$be
sta $dc0e ; stop timer a
lda $dc0f
and #$be
sta $dc0f ; stop timer b
lda #$00
sta $dc05 ; hibyte timer
lda #$ff
sta $dc04 ; lobyte timer
lda #<inthand
sta $0318
lda #>inthand
sta $0319 ; set t-int handler
lda $dc0e
and #$80
ora #$11
ldx #$81
stx $dc0d ; enable timer int
sta $dc0e ; start timer a
loop jmp loop
inthand lda $dc0d ; interrupt-source?
and #%00000001
beq timerint
rti
timerint jsr *fancy_stuff*
rti
----------------------8<----------------------8<---------
After running the program, the interrupt never seems to occur. Now, what's my mistake?
I assume I'm making a fool out of me for asking that question, but that's no problem for me... ;-) |
|
... 8 posts hidden. Click here to view all posts.... |
| |
Style Account closed
Registered: Jan 2002 Posts: 17 |
$0314/$0315 is for gheys
Use the hardware vectors.
|
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
@style: When you have graphics at $fffe/$ffff then the kernal vectors prove VERY potent. =) (such as in the case of an AGSP etc.)
So, it's not ONLY for ghays. |
| |
HCL
Registered: Feb 2003 Posts: 728 |
I'm not sure $0314-15 works at all, never used them a.f.a.i.can.remember. And.. why try now, after 15 years !? ;). |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
hahaha
I've started with 0314/15, but now Im also unsure wether it would work at all, fffe/ffff is my cosy territory, after all those years 314/15 is scarry :D |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
i second jackasser... there are times when the kernal vectors just come in super-handy. :D and yes, of course they work. |
| |
Compyx
Registered: Jan 2005 Posts: 631 |
When writing programs like editors, you'll more or less have to use $0314/$0315 to be able to use kernal-routines like GETIN (scanning the keyboard queue).
When you look at $fffe/$ffff you'll see it points to $ff48 which in turn JMP's to ($0314) or ($0316) when bit 4 of P is set (BRK).
So you're basically rerouting the kernal interrupt handler when setting $0314/$0315. There's no need to use $ea31 unless you're using GETIN, $ea81 is sufficient as it pulls A,X and Y from the stack which were pushed on it by $ff48.
Just my 2 cents ;)
|
| |
Ninja
Registered: Jan 2002 Posts: 411 |
Dunno if your 5-second-interval is the true value, but if it is then one timer won't be enough, as it can just count 65536 cycles. So, either you combine two timers (Timer B counts underruns of Timer A) or you use the Time-of-day-Clock. |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
WHAAAAH no TOD clock please :D inaccurate as hell |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
compyx: you can call yourself SCNKEY, so u can use GETIN. no need for kernal interrupt. |
| |
Ninja
Registered: Jan 2002 Posts: 411 |
Well, okay, I assumed that a 5-second-interval could also live with some tolerance, hence mentioning the TOD. If it needs to be more exact, combinig timers is inevitable. |
Previous - 1 | 2 - Next |