Jump to content
IGNORED

Timer Recommendations


dhe

Recommended Posts

 
 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...
Link to comment
Share on other sites

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.

 

Sprite.thumb.png.3dfb30c00f733031a7e0744c997417bc.png

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

 

 

 

  • Thanks 1
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...