+dhe Posted April 1, 2022 Share Posted April 1, 2022 I'm writing some code, and I need to time the amount of time allocated to a user to do a thing. Functional description: Start timer - user has 30 seconds. Let User do their thing. check if time is up, goto next part of program. Bruce Harrison in his assembler article used the VDP to time executions and I know the 9901 has timer capability. Just thought I'd check with you folks on your idea for solving this programatically... Quote Link to comment Share on other sites More sharing options...
Tursi Posted April 1, 2022 Share Posted April 1, 2022 VDP interrupt is easiest, unless you're in an environment they don't run reliably. 1 Quote Link to comment Share on other sites More sharing options...
+FarmerPotato Posted April 1, 2022 Share Posted April 1, 2022 I used a user-defined interrupt routine under XB to tick off time in units of 1/60th second. For a simple counter, you choose a location in low RAM (say >2500 or 9472) for a 16-bit number. The ISR decrements it until 0. From XB you do CALL LOAD(9472, 7, 8 ) to set the value "1800" (30*60). CALL PEEK tells you if there's any time left. You could also use two locations, for seconds and 60ths seconds. The super easy way to check time in XB is the sprite trick. Set a sprite below the bottom of the screen and check how far it's moved. 10 CALL SPRITE(#1,42,2,192,1,0,1) 20 CALL POSITION(#1,R,C) 30 DISPLAY AT(24,1):C 40 GOTO 20 Nicer demonstration: 10 S=10 20 CALL HCHAR(23,1,46,32) 30 K=16/60 40 CE=S/K 50 CALL SPRITE(#1,124,2,177,256,0,1) 60 CALL SPRITE(#2,124,16,177,CE,0,0) 70 CALL POSITION(#1,R,C) 80 T=INT(C*K) 90 DISPLAY AT (24,1):T,C 100 IF C<CE THEN 70 110 IF C=256 THEN 70 120 CALL MOTION(#1,0,0) 130 CALL COLOR(#1,5) 140 GOTO 140 An interrupt tick (in the NTSC countries) is 1/60th second. A sprite moves V/16 on each tick. At V=1 it moves 60/16 pixels per second, or about 3.8. CE is the column the sprite should reach when S seconds have passed. I start the sprite at column 0 or 256 to make the math simpler (just C not C-1) In PAL countries, I have heard that sprites go slower? Change 60 to 50. So your program needs to know where you are, or Italy will get an advantage in the game. 1 1 Quote Link to comment Share on other sites More sharing options...
Ed in SoDak Posted April 2, 2022 Share Posted April 2, 2022 Bruce sent this to me to use in my darkroom timer program. CALL LINK("STARTT") CALL CLOCK CALL CLKOFF CLOCKO 2 1 Quote Link to comment Share on other sites More sharing options...
senior_falcon Posted April 2, 2022 Share Posted April 2, 2022 15 hours ago, dhe said: I'm writing some code, and I need to time the amount of time allocated to a user to do a thing. Functional description: Start timer - user has 30 seconds. Let User do their thing. check if time is up, goto next part of program. Bruce Harrison in his assembler article used the VDP to time executions and I know the 9901 has timer capability. Just thought I'd check with you folks on your idea for solving this programatically... Are you writing in XB or in assembly? Quote Link to comment Share on other sites More sharing options...
+dhe Posted April 2, 2022 Author Share Posted April 2, 2022 1 minute ago, senior_falcon said: Are you writing in XB or in assembly? Worse, c99! ? Quote Link to comment Share on other sites More sharing options...
+TheBF Posted April 2, 2022 Share Posted April 2, 2022 2 hours ago, dhe said: Worse, c99! ? It might be possible for your needs to simply hook the user interrupt and update a global variable. If you write a sub-routine like this Forth Assembler example in C ASM VARIABLE t CODE COUNTER ( -- ) t @@ INC, RT, ENDCODE or something like this in C ?? /* Please pardon my C errors. Have never done anything serious with it */ void timer() { t=t++; } Where t is a global variable, you can plug the address of timer() into address 0x83C4. This will will just keep incrementing t every VDP interrupt, which you can read at your leisure. That's all I got. 1 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.