GadgetUK Posted December 7, 2012 Share Posted December 7, 2012 (edited) 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 December 7, 2012 by GadgetUK Quote Link to comment Share on other sites More sharing options...
+karri Posted December 8, 2012 Share Posted December 8, 2012 (edited) 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 December 8, 2012 by karri Quote Link to comment Share on other sites More sharing options...
GadgetUK Posted December 9, 2012 Author Share Posted December 9, 2012 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!! Quote Link to comment Share on other sites More sharing options...
+karri Posted December 9, 2012 Share Posted December 9, 2012 .include "lynx.inc" should do the trick. Quote Link to comment Share on other sites More sharing options...
GadgetUK Posted December 9, 2012 Author Share Posted December 9, 2012 (edited) 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 December 9, 2012 by GadgetUK Quote Link to comment Share on other sites More sharing options...
+karri Posted December 12, 2012 Share Posted December 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
GadgetUK Posted December 12, 2012 Author Share Posted December 12, 2012 Hmmm, it doesnt seem to reflect that though?? When lower gets to FF upper is incremented? And this is working atm? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.