Retro Lord #1 Posted March 5, 2015 I'm done with the first level of my little Adventure Island tribute, and I'm thinking of a way to make the level end. I'm thinking of having the levels last 5 minutes, and when you have survived for 5 minutes an exit sign appears that leads to the next stage. How many frames would there be in 5 minutes? I was thinking of calculating it something like this: r=r+1 if r=255 then q=q+1 : r=0 if q=60 then goto LEVEL_2 Quote Share this post Link to post Share on other sites
+SpiceWare #2 Posted March 5, 2015 Depends if you're making an NTSC or PAL game. NTSC = 5 minutes * 60 seconds per minute * 60 frames per second = 18,000 frames PAL = 50 minutes * 60 seconds per minute * 50 frames per second = 15,000 frames A byte value will automatically wrap from 255 to 0, so no need to manually reset r to 0. Quote Share this post Link to post Share on other sites
+Random Terrain #3 Posted March 5, 2015 Here is one way to do it for NTSC and PAL60 if I didn't screw up the math: dim _Counter1 = a dim _Counter2 = b ;*************************************************************** ; ; New level check. ; ;``````````````````````````````````````````````````````````````` ; Increments _Counter1. ; _Counter1 = _Counter1 + 1 ;``````````````````````````````````````````````````````````````` ; _Counter1 resets every 4 seconds (60 * 4 = 240). ; if _Counter1 < 240 then goto __Skip_5_Min_Check ;``````````````````````````````````````````````````````````````` ; Clears _Counter1 after 4 seconds have gone by. ; _Counter1 = 0 ;``````````````````````````````````````````````````````````````` ; _Counter2 increments every 4 seconds. ; _Counter2 = _Counter2 + 1 ;``````````````````````````````````````````````````````````````` ; If _Counter2 reaches 75 (4 seconds x 75 = 5 minutes), ; program jumps to __LEVEL_2. ; if _Counter2 > 74 then goto __LEVEL_2 __Skip_5_Min_Check Quote Share this post Link to post Share on other sites
+SpiceWare #4 Posted March 5, 2015 That works, though it'll take less ROM and CPU time if you utilize the automatic wrap to 0 to your advantage: counter1 = counter1 + 1 if counter1 then skip_check ; skip if counter1 is not 0 counter2 = counter2 + 1 ; 18000 frames / 256 = 70 if (counter2 >= 70) then goto level2 skip_check I'm not sure if bB does the implicit check for non-zero. If it doesn't, the counter1 test would need to be if counter1 > 0 then skip_check 1 Quote Share this post Link to post Share on other sites
+Random Terrain #5 Posted March 5, 2015 Does ">= 70" use more cycles than "> 69"? Quote Share this post Link to post Share on other sites
+SpiceWare #6 Posted March 5, 2015 using >= in assembly should be more efficient than > Compare sets flags as if a subtraction had been carried out. If the value in the accumulator is equal or greater than the compared value, the Carry will be set. The equal (Z) and sign (S) flags will be set based on equality or lack thereof and the sign (i.e. A>=$80) of the accumulator. a >= check only needs to worry about the state of C test: cmp #70 bcc Skip ;C is set if Greater Than or Equal To 70 ; >= 70 logic here Skip: while a > check needs to worry about C and Z. test: cmp #69 bcc Skip ; C is clear if Less Than 69 beq Skip ; Z is set if Equal To 69 ; > 69 logic here Skip: It's possible bB is written in a way that makes > more efficient than >= 1 Quote Share this post Link to post Share on other sites
+Random Terrain #7 Posted March 5, 2015 Thanks. Maybe someone who knows about the guts of bB will post so we can be sure. If ">=" is also better when using bB, I should add that info to the bB page. Quote Share this post Link to post Share on other sites
pacgreg #8 Posted March 6, 2015 Ooh I forgot about adventure island, excited to see what comes of this. Quote Share this post Link to post Share on other sites
bogax #9 Posted March 6, 2015 They produce basically similar code .L00 ; if a >= 70 then skip LDA a CMP #70 bcs .skip . ; .L01 ; if a > 69 then skip LDA #69 CMP a bcc .skip . another way to do the timer timer will rollover at 256 and .01 is actually .78125 ie .01 gets rounded to 2/256 dim timer = counter1.counter0 counter1 = 115 timer = timer + 0.01 if !counter1 then next_level Quote Share this post Link to post Share on other sites
Retro Lord #10 Posted March 6, 2015 Cheers for the help guys =D Quote Share this post Link to post Share on other sites
bogax #11 Posted March 7, 2015 (edited) I shouldn't post this stuff when I'm tired In the cold light of day.. It's more straight forward to make the timer count down .01 rounds to .0078125 I chose that because it gives you the closest to 5 minutes while only setting one variable (I think) dim timer = counter1.counter0 counter1 = 142 timer = timer - 0.01 if !counter1 then next_level Edited March 7, 2015 by bogax Quote Share this post Link to post Share on other sites