Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. ; Spin until power off
  2. game_loop:
  3. jsr play_music_engine
  4. jmp game_loop
  5.  
  6. ; Play song data
  7. play_music_engine:
  8. ; If duration lower than 0 load next note and play it
  9. lda note_duration
  10. beq load_next_note
  11. ; If not then lower duration
  12. lda current_tempo
  13. beq reset_tempo
  14. dec current_tempo
  15. rts
  16.  
  17. load_next_note:
  18. inc note_pointer ; Increment note pointer
  19. ldx note_pointer ; load note pointer into X
  20. lda songdata1, X ; load note
  21. sta note
  22. inc note_pointer ; Increment note pointer again
  23. ldx note_pointer ; load note pointer into X
  24. lda songdata1, X ; load note duration
  25. sta note_duration
  26. ; check for special opcodes
  27. lda note
  28. cmp #$FD
  29. beq handle_rest
  30. cmp #$FE
  31. beq handle_jump
  32. cmp #$FF
  33. beq handle_end
  34. ; if not special opcode, now sound the note
  35. jsr lookup_note ; jump to note lookup subroutine
  36. rts
  37.  
  38. handle_rest:
  39. ldx note ; load note pointer into X
  40. lda #$00 ; load rest data
  41. sta $4002; play note
  42. lda #$00 ; load rest data
  43. sta $4003; play note
  44. rts ; go back to playing the note
  45.  
  46. handle_jump:
  47. lda #$00
  48. sta note_pointer
  49. lda #$00
  50. sta current_tempo
  51. lda #$00
  52. sta note_duration
  53. ldx note_pointer ; load note pointer into X
  54. lda songdata1, X ; load tempo
  55. rts
  56.  
  57. handle_end:
  58. lda #$01
  59. sta done_playing
  60. rts
  61.  
  62. handle_done_playing:
  63. ldx note ; load note pointer into X
  64. lda #$00 ; load rest data
  65. sta $4002; play note
  66. lda #$00 ; load rest data
  67. sta $4003; play note
  68. lda #$FF
  69. sta note_duration
  70. rts
  71.  
  72. lookup_note:
  73. ldx note ; load note pointer into X
  74. lda periodTableLo, X ; load actual note
  75. sta $4002; play note
  76. lda periodTableHi, X ; load actual note
  77. sta $4003; play note
  78. lda done_playing
  79. cmp #$01
  80. beq handle_done_playing
  81. rts ; go back to playing the note
  82.  
  83. reset_tempo:
  84. lda tempo_duration
  85. sta current_tempo
  86. dec note_duration
  87. rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement