Advertisement
slydogstudios

Burn Time

Mar 26th, 2012
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Simple loop to burn time in a program
  2. ; Syntax used is for ca65
  3.  
  4. ; The three bytes needed in RAM
  5. nmi_wait:   .res 1
  6. one_second: .res 1
  7. big_seconds:    .res 1
  8.  
  9. ; The routine nmi_wait
  10. nmi_wait:
  11.     lda nmi_num
  12. :   cmp nmi_num
  13.     beq :-
  14.     rts
  15.  
  16. ; Must have one_second and big_seconds already setup.
  17. ; Use #$3c in one_second to wait 60 frames
  18. ; Use the number of seconds you want to use in big_seconds
  19. loop:
  20.     lda one_second          ; Subtract one_second by one
  21.     sec                             ;  and if it's not zero, branch
  22.     sbc #$01            ;  over
  23.     sta one_second          ;
  24.     bne @end            ;
  25.         lda #$3c        ; When one_second reaches zero,
  26.         sta one_second      ;  reset it to #$3c and subtract
  27.         lda big_seconds     ;  big_seconds by one. Test if
  28.         sec         ;  big_seconds is zero. If not,
  29.         sbc #$01        ;  we wait for another NMI and
  30.         sta big_seconds     ;  start the loop over. If zero,
  31.         bne @end        ;  jmp over the nmi_wait...
  32.             jmp @finally    ;
  33. @end:                   ;
  34.     jsr nmi_wait            ;
  35.     jmp loop            ;
  36. @finally:               ; Here we begin setup for the next
  37.                     ;  loop in the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement