Subject: Re: [stella] Does this look right? (clock) From: emooney@xxxxxxxxxxxxxxxx (Erik Mooney) Date: Wed, 01 Oct 1997 22:38:09 GMT |
>Well, I'll need a clock for my virtual pet game, and unfortunately the >2600 does not have a time clock like the C-64. But I'm hoping this code >(stuck first thing into the overscan) will accomplish my time keeping >needs. Is there an easier way to do this? Good, except that it's easier to do the incrementing first, so you only hit each value once, and the branching becomes much simpler. lda #0 ;keep 0 in A so we don't have to do separate LDA #0 to ldx FRAMES ; clear frames, seconds, minutes, etc. inx cpx #60 ;50 for PAL stx FRAMES ;STx does not affect the flags, so we can store here and bne DoneClock ;then the BNE will use the flags set by the CPX. sta FRAMES ldx SECONDS ;I'm using X instead of A for all this because INX is inx ; shorter than ADC #1, and doesn't involve a CLC. cpx #60 stx SECONDS bne DoneClock sta SECONDS ldx MINUTES inx cpx #60 stx MINUTES bne DoneClock sta MINUTES ldx HOURS inx cpx #24 stx HOURS bne DoneClock sta HOURS inc DAYS ;assuming you aren't keeping track of weeks separately ; from days. DoneClock ;continue from here. It's a little faster (because I do INX instead of INC zeropage) and smaller (because I don't need to do repeated LDA #00 instructions) and the branching is definitely much simpler. If you can modify it so it counts DOWN to 0 for each value, it becomes much more simpler again. dec FRAMES bne DoneClock lda #60 sta FRAMES dec SECONDS bne DoneClock sta SECONDS ;A was already 60 so no need to reload it dec MINUTES bne DoneClock sta MINUTES ;A still 60 dec HOURS bne DoneClock lda #24 sta HOURS inc DAYS ;of course, you could extend this to weeks, months, etc. DoneClock -- Archives updated once/day at http://www.biglist.com/lists/stella/archives/ Unsubscribing and other info at http://www.biglist.com/lists/stella/stella.html
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[stella] Does this look right? (clo, crackers | Thread | Re: [stella] Does this look right? , Piero Cavina |
[stella] Does this look right? (clo, Chris Wilkson - MCD | Date | Re: [stella] Does this look right? , Chris Wilkson - MCD |
Month |