home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / cncd_editor.zip / fxhammer.zip / full-ex2.asm < prev    next >
Assembly Source File  |  2000-12-17  |  5KB  |  155 lines

  1. Player_Initialize       equ     $4000
  2. Player_MusicStart       equ     $4003
  3. Player_MusicStop        equ     $4006
  4. Player_SongSelect       equ     $400c
  5. Player_MusicUpdate      equ     $4100
  6.  
  7. Player_SampleUpdate     equ     $4000
  8.  
  9. SoundFX_Trig            equ     $4000
  10. SoundFX_Stop            equ     $4003
  11. SoundFX_Update          equ     $4006
  12.  
  13. MusicBank               equ     1
  14. SampleBank              equ     2
  15. FXBank                  equ     3
  16.  
  17. SongNumber              equ     0       ; 0 - 7
  18.  
  19.  
  20.  
  21.         SECTION "Example",HOME[$150]
  22.  
  23. FirstTime:
  24.         ld      a,MusicBank             ; Switch to MusicBank
  25.         ld      [rROMB0],a
  26.  
  27.         call    Player_Initialize       ; Initialize sound registers and
  28.                                         ; player variables on startup
  29.  
  30. NewSong:
  31.         ld      a,MusicBank             ; Switch to MusicBank
  32.         ld      [rROMB0],a
  33.  
  34.         call    Player_MusicStart       ; Start music playing
  35.  
  36.         ld      a,SongNumber            ; Call SongSelect AFTER MusicStart!
  37.         call    Player_SongSelect       ; (Not needed if SongNumber = 0)
  38.  
  39.  
  40. FrameLoop:
  41.         ld      c,$04                   ; Waiting (see notes below)
  42.         call    WaitLCDLine
  43.  
  44.         ld      a,MusicBank             ; Switch to MusicBank
  45.         ld      [rROMB0],a
  46.         call    Player_MusicUpdate      ; Call this once a frame
  47.  
  48.         ld      a,FXBank                ; Switch to FXBank
  49.         ld      [rROMB0],a
  50.         call    SoundFX_Update          ; Call this once a frame too
  51.  
  52.  
  53. ; ---- Example of sample player timing (needed only if samples used) ---->
  54.         ld      c,$10                   ; Waiting
  55.         call    WaitLCDLine
  56.  
  57.         ld      a,SampleBank            ; Switch to SampleBank
  58.         ld      [rROMB0],a
  59.         call    Player_SampleUpdate     ; 1st call right after music update
  60.  
  61.         ; at least $24 LCD lines available for any routines here
  62.  
  63.         ld      c,$10 + $26
  64.         call    WaitLCDLine
  65.         ld      a,SampleBank            ; Switch to SampleBank
  66.         ld      [rROMB0],a
  67.         call    Player_SampleUpdate     ; 2nd call after $26 LCD lines
  68.  
  69.         ; at least $24 LCD lines available for any routines here
  70.  
  71.         ld      c,$10 + $4d
  72.         call    WaitLCDLine
  73.         ld      a,SampleBank            ; Switch to SampleBank
  74.         ld      [rROMB0],a
  75.         call    Player_SampleUpdate     ; 3rd call after $4d LCD lines
  76.  
  77.         ; at least $24 LCD lines available for any routines here
  78.  
  79.         ld      c,$10 + $73             ; < $90, don't waste VBlank time
  80.         call    WaitLCDLine
  81.         ld      a,SampleBank            ; Switch to SampleBank
  82.         ld      [rROMB0],a
  83.         call    Player_SampleUpdate     ; 4th call after $73 LCD lines
  84.  
  85.         ; a few more lines available for any routines here before VBlank
  86.  
  87. ; <---- Example of sample player timing (needed only if samples used) ----
  88.  
  89.  
  90.         jr      FrameLoop
  91.  
  92.  
  93.  
  94. ; If you don't want to worry about the player calls, set up a series of
  95. ; rLY=rLYC interrupts, so that every interrupt sets the rLYC register to
  96. ; wait for the next player call, and the last interrupt sets rLYC back to
  97. ; the first line for looping.
  98. ;
  99. ; #  rLY  CALL                                   LCD lines used
  100. ; 1  $04  Player_MusicUpdate & SoundFX_Update    0-3
  101. ; 2  $10  Player_SampleUpdate                    0-1
  102. ; 3  $36  Player_SampleUpdate                    0-1
  103. ; 4  $5d  Player_SampleUpdate                    0-1
  104. ; 5  $83  Player_SampleUpdate                    0-1
  105.  
  106. ;(6  $90  Normal VBlank interrupt routines here if needed)
  107.  
  108. ; Player_MusicUpdate can in fact use any LCD line, but when using samples
  109. ; it should be called at the same line every frame.
  110.  
  111.  
  112. StopExample:
  113.         ld      a,MusicBank             ; Switch to MusicBank
  114.         ld      [rROMB0],a
  115.         call    Player_MusicStop        ; Stops reading note data and cuts
  116.                                         ; all music notes currently playing
  117.         ret
  118.  
  119.  
  120. TrigSoundFXExample:
  121.         ld      a,FxBank                ; Switch to FXBank
  122.         ld      [rROMB0],a
  123.         ld      a,2
  124.         call    SoundFX_Trig            ; Trig sound FX number 2
  125.  
  126.         ret
  127.  
  128.  
  129. WaitLCDLine:
  130.         ld      a,[rLY]
  131.         cp      c
  132.         jr      nz,WaitLCDLine
  133.         ret
  134.  
  135.  
  136.  
  137.         SECTION "Music",DATA[$4000],BANK[MusicBank]
  138.  
  139.         INCBIN "music.bin"              ; player code and music data
  140.  
  141.  
  142.         SECTION "Samples",DATA[$4000],BANK[SampleBank]
  143.  
  144.         INCBIN "music.sam"              ; needed only if samples used
  145.  
  146.  
  147.         SECTION "FX",DATA[$4000],BANK[FXBank]
  148.  
  149.         INCBIN "fxbank.bin"
  150.  
  151.  
  152.         SECTION "Reserved",BSS[$c7c0]
  153.  
  154.         ds      $30                     ; $c7c0 - $c7ef for player variables
  155.