Skip to content

Instantly share code, notes, and snippets.

@spacekitcat
Created August 24, 2019 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spacekitcat/735f02430096393ed68e5ec8c2007af3 to your computer and use it in GitHub Desktop.
Save spacekitcat/735f02430096393ed68e5ec8c2007af3 to your computer and use it in GitHub Desktop.
Creates a time delay on the 6502. Easy to adapt the intervals or even parameterise the subroutine
; Written for the CA65 assembler and tested on a NES emulator
.zeropage
counter_lsb: .res 1
counter_msb: .res 1
.proc RateLimit
lda #$EE ; Most Significant Byte 'interval'
sta counter_msb
LOOP_MSB:
lda #$00 ; Least Significant Byte 'interval'
sta counter_lsb
LOOP_LSB:
inc counter_lsb
lda counter_lsb
bne LOOP_LSB
inc counter_msb
lda counter_msb
bne LOOP_MSB
rts
.endproc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment