SHARE
TWEET

vrc7_patch_macro.s

HertzDevil Aug 30th, 2015 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .segment "HEADER"
  2.  
  3. .include "nsf_wrap.s"
  4.  
  5.  
  6.  
  7. .segment "CODE"
  8.  
  9. ; VRC7[Y] <- A
  10. .macro vrc7write
  11.         sty $9010
  12.         jsr vrc7_delay2
  13.         sta $9030
  14.         jsr vrc7_delay
  15. .endmacro
  16.  
  17. OCTAVE = 5
  18. VOLUME = 13
  19. DURATION = 120
  20.  
  21. FREQ_LO  = $00
  22. FREQ_HI  = $01
  23. TRIGGER  = $02 ; 00 -> nothing, 01 -> new note, 80 -> released
  24. LENGTH   = $03
  25. READING  = $04
  26. PATCHPOS = $05
  27. PATCHCOUNT = $06
  28. PATCHLOOP = $07
  29. PATCHREL = $08
  30. TIMER    = $09
  31. var_Temp = $0A
  32. TEMP_X   = $FF
  33.  
  34. LOAD:
  35. INIT:
  36.         tax
  37.         lda vrc7freq_l, x
  38.         sta FREQ_LO
  39.         lda vrc7freq_h, x
  40.         ora #(OCTAVE << 1)
  41.         sta FREQ_HI
  42.         lda #$00
  43.         ldy #$30
  44. :       vrc7write
  45.         dey
  46.         bpl :-
  47.  
  48.         ldy #$10
  49.         lda FREQ_LO
  50.         vrc7write
  51.         ldy #$30
  52.         lda #($0F - VOLUME)
  53.         vrc7write
  54.  
  55.         ldx #$02
  56. :       lda patchmacro, x
  57.         sta PATCHCOUNT, x
  58.         dex
  59.         bpl :-
  60.         jsr resetpatch
  61.         rts
  62.  
  63. PLAY:
  64.         lda READING
  65.         bne :+
  66.         jmp @DoneLoading
  67. :       lda LENGTH
  68.         beq :+
  69.         jmp @DoneLoading
  70. :       lda PATCHPOS
  71.         asl a
  72.         asl a
  73.         asl a
  74.         ora #$07
  75.         tax
  76.         ldy #$07
  77. :       lda patchdef, x
  78.         vrc7write
  79.         dex
  80.         dey
  81.         bpl :-
  82.  
  83.         lda PATCHPOS
  84.         asl a
  85.         tax
  86.         inx
  87.         inx
  88.         inx
  89.         lda patchmacro, x
  90.         sta LENGTH
  91.         lda TRIGGER
  92.         bmi :+
  93.         inx
  94.         lda patchmacro, x
  95.         bpl :+
  96.         lda #$00
  97.         jsr vrc7trigger
  98.         lda #$01
  99.         jsr vrc7trigger
  100. :
  101.         inc PATCHPOS
  102.         lda TRIGGER
  103.         bpl @Looping
  104. @Releasing:
  105.         lda PATCHPOS
  106.         cmp PATCHCOUNT
  107.         bcc @DoneLoading
  108.         lda #$FF
  109.         sta var_Temp
  110.         lda PATCHLOOP
  111.         cmp #$FF
  112.         beq :+
  113.         sta var_Temp
  114.         lda PATCHREL
  115.         cmp #$FF
  116.         beq :+
  117.         cmp var_Temp
  118.         bcc :+
  119.         sta var_Temp
  120. :       lda var_Temp
  121.         cmp #$FF
  122.         bne :+
  123.         lda #$00
  124.         sta READING
  125.         jmp @DoneLoading
  126. :       sta PATCHPOS
  127.         jmp @DoneLoading
  128. @Looping:
  129.         lda PATCHREL
  130.         sta var_Temp
  131.         inc var_Temp
  132.         bne :+
  133.         lda PATCHCOUNT
  134.         sta var_Temp
  135. :       lda PATCHPOS
  136.         cmp var_Temp
  137.         bcc @DoneLoading
  138.         lda PATCHLOOP
  139.         cmp PATCHREL
  140.         bcc :+
  141.         lda #$00
  142.         sta READING
  143.         jmp @DoneLoading
  144. :       lda PATCHLOOP
  145.         sta PATCHPOS
  146.  
  147. @DoneLoading:
  148.         lda TRIGGER
  149.         cmp #$01
  150.         bne :+
  151.         lda #$01
  152.         jsr vrc7trigger
  153.         lda #$00
  154.         sta TRIGGER
  155. :
  156.         dec LENGTH
  157.         inc TIMER
  158.         bne :+
  159.         jsr resetpatch
  160.         rts
  161. :       lda #DURATION
  162.         cmp TIMER
  163.         bne :++
  164.         lda PATCHREL
  165.         cmp #$FF
  166.         beq :+
  167.         sta PATCHPOS
  168.         asl a
  169.         tax
  170.         inx
  171.         inx
  172.         inx
  173.         lda patchmacro, x
  174.         sta LENGTH
  175.         dec LENGTH
  176. :       lda #$80
  177.         sta TRIGGER
  178.         lda #$01
  179.         sta READING
  180.         lda #$00
  181.         jsr vrc7trigger
  182. :       rts
  183.  
  184. vrc7_delay:
  185.         stx TEMP_X
  186.         ldx #$08
  187. :       dex
  188.         bne :-
  189.         ldx TEMP_X
  190. vrc7_delay2:
  191.         rts
  192.  
  193. resetpatch:
  194.         lda #$01
  195.         sta TRIGGER
  196.         sta READING
  197.         lda #$00
  198.         sta PATCHPOS
  199.         sta LENGTH
  200.         rts
  201.  
  202. vrc7trigger:
  203.         beq :+
  204.         lda #$10
  205.         bpl :++ ; always
  206. :       lda #$00
  207. :       ora FREQ_HI
  208.         ldy #$20
  209.         vrc7write
  210.         rts
  211.  
  212.  
  213.  
  214. .define ft_vrc7_table 172, 183, 194, 205, 217, 230, 244, 258, 274, 290, 307, 326
  215. vrc7freq_l:
  216.         .lobytes ft_vrc7_table
  217. vrc7freq_h:
  218.         .hibytes ft_vrc7_table
  219.  
  220. .macro VRC7PATCH tl,fb, ar0,dr0,sl0,rr0,kl0,mt0,am0,vb0,eg0,kr0,di0, ar1,dr1,sl1,rr1,kl1,mt1,am1,vb1,eg1,kr1,di1
  221.      ; bit count  6  3    4   4   4   4   2   4   1   1   1   1   1  ...
  222.         .byte ((am0 & $01) << 7) | ((vb0 & $01) << 6) | ((eg0 & $01) << 5) | ((kr0 & $01) << 4) | (mt0 & $0F)
  223.         .byte ((am1 & $01) << 7) | ((vb1 & $01) << 6) | ((eg1 & $01) << 5) | ((kr1 & $01) << 4) | (mt1 & $0F)
  224.         .byte ((kl0 & $03) << 6) |   (tl & $3F)
  225.         .byte ((kl1 & $03) << 6) | ((di0 & $01) << 4) | ((di1 & $01) << 3) |   (fb & $07)
  226.         .byte ((ar0 & $0F) << 4) |  (dr0 & $0F)
  227.         .byte ((ar1 & $0F) << 4) |  (dr1 & $0F)
  228.         .byte ((sl0 & $0F) << 4) |  (rr0 & $0F)
  229.         .byte ((sl1 & $0F) << 4) |  (rr1 & $0F)
  230. .endmacro
  231.  
  232. patchdef:
  233.                  ;TL,FB, AR,DR,SL,RR,KL,MT,AM,VB,EG,KR,DT, (same for carrier)
  234.         VRC7PATCH 29,6, 15,0,0,0,0,1,0,0,0,0,0, 6,5,2,5,0,1,0,0,1,0,1
  235.         VRC7PATCH 29,6, 15,0,0,0,0,0,0,0,0,0,0, 6,5,2,5,0,1,0,0,1,0,1
  236.         VRC7PATCH 26,6, 15,0,0,0,0,0,0,0,0,0,0, 6,5,2,5,0,1,0,0,1,0,1
  237.         VRC7PATCH 23,6, 15,0,0,0,0,0,0,0,0,0,0, 6,5,2,5,0,1,0,0,1,0,1
  238.         VRC7PATCH 20,6, 15,0,0,0,0,0,0,0,0,0,0, 6,5,2,5,0,1,0,0,1,0,1
  239.         VRC7PATCH 18,6, 15,0,0,0,0,0,0,0,0,0,0, 6,5,2,5,0,1,0,0,1,0,1
  240.         VRC7PATCH 17,6, 15,0,0,0,0,0,0,1,0,0,0, 6,5,2,5,0,1,0,1,1,0,1
  241.         VRC7PATCH 18,6, 15,0,0,0,0,0,0,1,0,0,0, 6,5,2,5,0,1,0,1,1,0,1
  242.         VRC7PATCH 20,6, 15,0,0,0,0,0,0,1,0,0,0, 6,5,2,5,0,1,0,1,1,0,1
  243.         VRC7PATCH 22,6, 15,0,0,0,0,0,0,1,0,0,0, 6,5,2,5,0,1,0,1,1,0,1
  244.         VRC7PATCH 23,6, 15,0,0,0,0,0,0,1,0,0,0, 6,5,2,5,0,1,0,1,1,0,1
  245. patchmacro:
  246.         .byte $0B               ; count
  247.         .byte $09               ; loop point (FF: hold)
  248.         .byte $06               ; release point (FF: ignore)
  249.         .byte $01, $80          ; length, flags
  250.         .byte $02, $80          ; length, flags
  251.         .byte $03, $00          ; length, flags
  252.         .byte $03, $00          ; length, flags
  253.         .byte $03, $00          ; length, flags
  254.         .byte $03, $00          ; length, flags
  255.         .byte $01, $00          ; length, flags
  256.         .byte $01, $00          ; length, flags
  257.         .byte $02, $00          ; length, flags
  258.         .byte $02, $00          ; length, flags
  259.         .byte $02, $00          ; length, flags
  260.  
  261. ; flags:
  262. ; .7: retrigger (#$10 -> $2x, #$30 -> $2x)
  263. ;     first tick always issues a trigger
  264. ;     flag at 00 makes sense if loop point is also 00
  265. ;     flag is ignored during note release (no ADSR resetting)
  266. ; .6 - .0: unused
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top