home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / cncd_editor.zip / example2.asm < prev    next >
Assembly Source File  |  2001-01-09  |  4KB  |  136 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. Player_SampleUpdate     equ     $4000
  7.  
  8. MusicBank               equ     2
  9. SampleBank              equ     3
  10.  
  11. SongNumber              equ     0       ; 0 - 7
  12.  
  13.  
  14.  
  15.         SECTION "Example",HOME[$150]
  16.  
  17. FirstTime:
  18.         ld      a,MusicBank             ; Switch to MusicBank
  19.         ld      [rROMB0],a
  20.  
  21.         call    Player_Initialize       ; Initialize sound registers and
  22.                                         ; player variables on startup
  23.  
  24. NewSong:
  25.         ld      a,MusicBank             ; Switch to MusicBank
  26.         ld      [rROMB0],a
  27.  
  28.         call    Player_MusicStart       ; Start music playing
  29.  
  30.         ld      a,SongNumber            ; Call SongSelect AFTER MusicStart!
  31.         call    Player_SongSelect       ; (Not needed if SongNumber = 0)
  32.  
  33.  
  34. FrameLoop:
  35.         ld      c,$08                   ; Waiting
  36.         call    WaitLCDLine
  37.  
  38.         ld      a,MusicBank             ; Switch to MusicBank
  39.         ld      [rROMB0],a
  40.         call    Player_MusicUpdate      ; Call this once a frame
  41.  
  42.  
  43. ; ---- Example of sample player timing (needed only if samples used) ---->
  44.         ld      c,$10                   ; Waiting
  45.         call    WaitLCDLine
  46.  
  47.         ld      a,SampleBank            ; Switch to SampleBank
  48.         ld      [rROMB0],a
  49.         call    Player_SampleUpdate     ; 1st call right after music update
  50.  
  51.         ; at least $24 LCD lines available for any routines here
  52.  
  53.         ld      c,$10 + $26
  54.         call    WaitLCDLine
  55.         ld      a,SampleBank            ; Switch to SampleBank
  56.         ld      [rROMB0],a
  57.         call    Player_SampleUpdate     ; 2nd call after $26 LCD lines
  58.  
  59.         ; at least $24 LCD lines available for any routines here
  60.  
  61.         ld      c,$10 + $4d
  62.         call    WaitLCDLine
  63.         ld      a,SampleBank            ; Switch to SampleBank
  64.         ld      [rROMB0],a
  65.         call    Player_SampleUpdate     ; 3rd call after $4d LCD lines
  66.  
  67.         ; at least $24 LCD lines available for any routines here
  68.  
  69.         ld      c,$10 + $73             ; < $90, don't waste VBlank time
  70.         call    WaitLCDLine
  71.         ld      a,SampleBank            ; Switch to SampleBank
  72.         ld      [rROMB0],a
  73.         call    Player_SampleUpdate     ; 4th call after $73 LCD lines
  74.  
  75.         ; a few more lines available for any routines here before VBlank
  76.  
  77. ; <---- Example of sample player timing (needed only if samples used) ----
  78.  
  79.  
  80.         ld      c,$90                   ; Wait for VBlank
  81.         call    WaitLCDLine
  82.  
  83.         ; VBlank routines here
  84.  
  85.         jr      FrameLoop
  86.  
  87.  
  88.  
  89. ; If you don't want to worry about the player calls, set up a series of
  90. ; rLY=rLYC interrupts, so that every interrupt sets the rLYC register to
  91. ; wait for the next player call, and the last interrupt sets rLYC back to
  92. ; the first line for looping.
  93. ;
  94. ; # rLY  CALL                   CPU usage (LCD lines)
  95. ; 1 $08  Player_MusicUpdate     1-3
  96. ; 2 $10  Player_SampleUpdate    0-1
  97. ; 3 $36  Player_SampleUpdate    0-1
  98. ; 4 $5d  Player_SampleUpdate    0-1
  99. ; 5 $83  Player_SampleUpdate    0-1
  100.  
  101. ;(6 $90  Normal VBlank interrupt routines here if needed)
  102.  
  103.  
  104. StopExample:
  105.         ld      a,MusicBank             ; Switch to MusicBank
  106.         ld      [rROMB0],a
  107.         call    Player_MusicStop        ; Stops reading note data and cuts
  108.                                         ; all music notes currently playing
  109.         ret
  110.  
  111.  
  112.  
  113. WaitLCDLine:
  114.         ld      a,[rLY]
  115.         cp      c
  116.         jr      nz,WaitLCDLine
  117.         ret
  118.  
  119.  
  120.  
  121.         SECTION "Music",DATA[$4000],BANK[MusicBank]
  122.  
  123.         INCBIN "music.bin"              ; player code and music data
  124.  
  125.  
  126.  
  127.         SECTION "Samples",DATA[$4000],BANK[SampleBank]
  128.  
  129.         INCBIN "music.sam"              ; needed only if samples used
  130.  
  131.  
  132.  
  133.         SECTION "Reserved",BSS[$c7c0]
  134.  
  135.         ds      $30                     ; $c7c0 - $c7ef for player variables
  136.