Jump to content
IGNORED

Timers


GadgetUK

Recommended Posts

Are there any built in timers on the Lynx, something I can use to work out how my us / ms have passed? Something thats tied into an interrupt or something?

 

I am having real problems trying to control the speed of the game logic, so its all over the place, with soliders running normally for very small bursts and then jumping large distances because I just cannot run routines when x amount of time / cycles have passed?

Edited by GadgetUK
Link to comment
Share on other sites

There are timers you can use or you can use the VBL interrupt for it. The easiest way is to use the VBL interrupt.

 

In cc65 the interrupts are handled by the linker. You can define any asm-routine with a keyword "interruptor" and the linker will put its address on a table that is automatically run at every interrupt. The only problem is that it will be called also if anything else interrupts (like ComLynx). So you need to check for the right interrupt.

 

In Solitaire I created a file called gametime.s:

.export _interruptOccurred
.interruptor _gametime
.export _playtime
.export _paused
.export _getscore

.segment "DATA"

_interruptOccurred:
.byte $00
_playtime:
.byte $00
.byte $00
.byte $00
_paused:
.byte $00

; ---------------------------------------------------------------
; void __near__ getscore (void)
; ---------------------------------------------------------------

.segment "CODE"

.proc _getscore: near
lda _playtime+1
ldx _playtime+2
stz _playtime
stz _playtime+1
stz _playtime+2
rts

.endproc


.proc _gametime: near

.segment "CODE"

lda _paused
bne @goon
inc _interruptOccurred
lda _playtime
ina
sta _playtime
cmp #75
bne @goon
stz _playtime
inc _playtime+1
bne @goon
inc _playtime+2
@goon:
clc
rts
.endproc

 

You need to pass "clc" if you did not handle the interrupt. If you handled the interrupt and nobody else should do anything then you can call "sec" before returning. I always return "clc" so that someone else can hook into my interrupts for various reasons.

 

If you want to check for a VBL interrupt then you need to add this:

lda INTSET
and #VBL_INTERRUPT
beq @goon
... handle your time stuff here as it was a VBL interrupt

 

And before you ask. No, you cannot use C-code for interrupt handling, sorry.

Edited by karri
Link to comment
Share on other sites

Thank you!!! I also found this yesterday whilst searching:- http://www.atariage.com/forums/topic/172479-lynx-audio/

 

I was looking for example of .asm usage within CC65 as its not something I had done yet - it didnt help much beyond what you've provided as you said pretty much the same thing on that thread. I remembered that I had seen .asm files in LX.NETs Adventure code so I checked that and found what i needed - the missing line from one of the .mak files to handle .asm extension.

 

Incidentally, do you know how to include the lynx.inc file in a .asm file? I wanted to use the constants for the VBLANK interrupt (timer 2) and the value INTSET ($FD81).

 

Many Thanks for your help again!!

Link to comment
Share on other sites

Excellent, thanks!!!

 

I ended up with this:-

 

EDIT: Just thinking, maybe I don't need the LDA _vbllower as its already in the acc. No, I do need it!

 

.include "lynx.inc"

.interruptor RealTimeHandler

.export _vbllower

.export _vblupper

 

_vbllower: .word $00

_vblupper: .word $00

 

.proc RealTimeHandler: near

.segment "CODE"

lda INTSET

and #VBL_INTERRUPT

beq @1

inc _vbllower

bne @1

inc _vbllower+1

lda _vbllower

and #$FF

bne @1

inc _vblupper

bne @1

inc _vblupper+1

@1:

clc

rts

.endproc

Edited by GadgetUK
Link to comment
Share on other sites

Hmm. I am a bit sceptic about 2 lines of your code.

 

lda _vbllower

and #$FF

 

The _vbllower is always zero when you enter this part of the code and the branch following this will never be taken. So in reality the content of _vbllower+1 and _vblupper wil be identical.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...