Jump to content
IGNORED

Using the Real Time Clock to Pause


Recommended Posts

All,

 

I'm trying to write some simple (I would have thought) code to pause for a little while using the real time clock.

 

Here it is:

 

.proc pause
LDA #0
STA 20 ;CLOCK_C
LDA #200
WAIT_A_BIT:
CMP 20 ;CLOCK_C
BCC WAIT_A_BIT

RTS
.endp

 

So I am setting the jiffy count to 0 and then waiting until 200 jiffies have passed. What I don't understand is that the code runs through immediately, but I would have thought that it would have required about 4 seconds on a PAL system.

 

What am I doing wrong? Probably something simple.

 

Is it my use of BCC?

 

Link to comment
Share on other sites

A carry check is more common after a math operation.

In this case you knew what the target was and so a BNE would have made more sense to someone reading this.

.proc pause
    LDA #0
    STA 20         ;CLOCK_C
    LDA #200
WAIT_A_BIT:
    CMP 20         ;CLOCK_C
    BNE WAIT_A_BIT
    RTS
.endp

So the alternative would have been:

.proc pause
    LDA #0
    STA 20         ;CLOCK_C
WAIT_A_BIT:
    LDA 20         ;CLOCK_C
    SEC
    SBC #200
    BCC WAIT_A_BIT
    RTS
.endp

Which is a lot more long-winded :)

 

Link to comment
Share on other sites

Often a game or program will use a general "wait one frame" type subroutine.

You could do a recursive call, an with a little extra programming cater for Pal/Ntsc differences.

 

 

waitvb
  lda $14
waitvb1  cmp $14
  beq waitvb1
  rts

 

The PAL register in GTIA is 1 for PAL, 15 for NTSC. So, you could simply do and AND #10 (decimal). Which gives 0 for PAL, 10 dec for NTSC.

Then add to 50, giving you the proper delay for 1 second.

 

 

  lda pal
  and #$0A
  clc
  adc #50 ; get proper FPS
  tax
wait1sec
  jsr waitvb
  dex
  bne wait1sec
Link to comment
Share on other sites

Thank you chaps. I've gone with FJC's option as it is good in that it doesn't write to the RTC (which may be useful later on) and because it is neat and simple.

 

RB's code looks good (as always!) but maybe a little overkill for what I am trying to do. It's very good to know though.

 

As for Wrathchild, your option looks good and the use of BNE was considered but decided against as I wasn't sure whether it could accidentally jump the number of jiffies that is looking for, forcing you to wait another 4.something seconds. Knowing a little more now, I don't think that it could.

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...