snicklin Posted October 15, 2014 Share Posted October 15, 2014 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 #200WAIT_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? Quote Link to comment Share on other sites More sharing options...
NRV Posted October 15, 2014 Share Posted October 15, 2014 bcc --> jmp if (A < M) A = 200 M = 0 ..don't jump.. bcs --> jump if (A >= M) Quote Link to comment Share on other sites More sharing options...
snicklin Posted October 15, 2014 Author Share Posted October 15, 2014 Yes, you are correct! I did try using bcs before but it didn't work, but I think that I must have had something else in the code wrong at the time. Thank you!! Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted October 15, 2014 Share Posted October 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted October 15, 2014 Share Posted October 15, 2014 And if you'd rather not write to the system clock at all: .proc pause lda 20 clc adc #200 Wait_a_bit: cmp 20 bne wait_a_bit rts .endp Quote Link to comment Share on other sites More sharing options...
Rybags Posted October 15, 2014 Share Posted October 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
snicklin Posted October 15, 2014 Author Share Posted October 15, 2014 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. 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.