home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 1794.dms / in.adf / Extensions_Sources / Extension_Sources.Lzh / _music.s < prev    next >
Encoding:
Text File  |  1992-02-01  |  86.7 KB  |  4,360 lines

  1. ;---------------------------------------------------------------------
  2. ;    **   **   **  ***   ***   ****     **    ***  **  ****
  3. ;   ****  *** *** ** ** **     ** **   ****  **    ** **  **
  4. ;  **  ** ** * ** ** **  ***   *****  **  **  ***  ** **
  5. ;  ****** **   ** ** **    **  **  ** ******    ** ** **
  6. ;  **  ** **   ** ** ** *  **  **  ** **  ** *  ** ** **  **
  7. ;  **  ** **   **  ***   ***   *****  **  **  ***  **  ****
  8. ;---------------------------------------------------------------------
  9. ; Music extension source code, V1.5  Last change 21/10/1991
  10. ; By Francois Lionet
  11. ; StarTrecker adaptation by Gary Simon & F.L.
  12. ; AMOS and AMOS Compiler (c) Europress Software 1991
  13. ; To be used with AMOS1.3 and over
  14. ;--------------------------------------------------------------------- 
  15. ; This file is public domain
  16. ;---------------------------------------------------------------------
  17. ;
  18. ; This listing explains how to create an extension for both AMOS and the
  19. ; AMOS compiler. Two possibilities for you:
  20. ;   - You have already made an extension for AMOS 1.2 versions, you'll 
  21. ;     have to re-write your code to have them work with AMOS 1.3 and the
  22. ;     compiler. Do not panic, as it is not a big deal.
  23. ;   - This is the first extension you write. Please ignore the text 
  24. ;     referencing to the old extension system.
  25. ;
  26. ; >>> What's an extension?
  27. ;
  28. ; An extension to AMOS is a machine language program that adds new 
  29. ; instructions to the already huge AMOS instruction set. This system is
  30. ; designed to be as powerfull as AMOS itself: the extension includes its 
  31. ; own token list, its own routines. It can even access some main AMOS
  32. ; routines via special macros. It has a total access to the internal AMOS 
  33. ; data zone, and to the graphic library functions.
  34. ;
  35. ; To produce your own extension, I suggest you copy and rename this
  36. ; file, and remove the used code. This way you will not forgive one line.
  37. ; Also keep in mind that you can perfectly call AMOS from within MONAM2,
  38. ; and set some ILLEGAL instructions where you want to debug. To flip back to
  39. ; MONAM2 display, just press AMIGA-A.
  40. ;
  41. ; I have designed the extension system so that one only file works with 
  42. ; both AMOS interpretor and compiler. 
  43. ;     - The extension is more a compiler library than a one chunk program:
  44. ;    it is done so that the compiler can pick one routine here and there
  45. ;    to cope with the program it is compiling.
  46. ;    - AMOS 1.3 extension loader works a little like the compiler, exept
  47. ;    that all instructions are loaded and relocated.
  48. ;
  49. ; This code was assembled with GENIM2 on a A3000 25 Mhz machine, but a
  50. ; A500 can do it very well!
  51. ; The assembled program must be ONE CHUNK only, you must not link the 
  52. ; the symbol table with it. Also be sure that you program is totally 
  53. ; relocatable (see later) : if not it will add a relocation chunk to 
  54. ; the output code, and your extension will simply crash AMOS on loading
  55. ; (and the compiler too!).
  56.  
  57. **********************************************************************
  58. ;
  59. ; Here we go now!
  60. ;
  61. ; Here comes the number of the extension in the list of extensions in
  62. ; Config1_3.AMOS program (minus one).
  63. ; This number is used later to reference the extension in internal AMOS 
  64. ; tables...
  65. ;
  66. ExtNb        equ    1-1
  67.  
  68. ; You must include all this files, they can be found in the folder where
  69. ; you found this program. Do not remove the RsSet instruction!
  70.          Include    "_Equ.s"
  71.         RsSet    DataLong
  72.         Include "_Pointe.s"
  73.         Include "_CEqu.s"
  74.         Include    "_WEqu.s"
  75.         Include    "_LEqu.s"
  76.  
  77. ; A usefull macro to find the address of data in the extension's own 
  78. ; datazone (see later)...
  79. DLea        MACRO
  80.         move.l    ExtAdr+ExtNb*16(a5),\2
  81.         add.w    #\1-MB,\2
  82.         ENDM
  83.  
  84. ; Another macro to load the base address of the datazone...
  85. DLoad        MACRO
  86.         move.l    ExtAdr+ExtNb*16(a5),\1
  87.         ENDM
  88.  
  89. ; Now some equates used by the music extension itself. Ignore this in your
  90. ; code!
  91.  
  92. Translate    equ -30
  93.  
  94. *************** Enveloppes definitions
  95.         RsReset
  96. EnvNb:        rs.w    1
  97. EnvDVol:    rs.w    1
  98. EnvVol:        rs.l    1
  99. EnvDelta:    rs.l     1
  100. EnvAd:        rs.l    1
  101. EnvDeb:        rs.l    1
  102. EnvLong:    equ     __Rs
  103.  
  104. *************** Wave definition
  105. LWave:        equ     256+128+64+32+16+8+4+2
  106.     LNoise:        equ     LWave
  107.         RsReset
  108. WaveNext:    rs.l    1
  109. WaveNb:        rs.w    1
  110. WaveEnv:    rs.w    16*2
  111. WaveDeb:    rs.b    LWave
  112. WaveLong:    equ     __Rs
  113.  
  114. *************** Music voice data
  115.         RsReset
  116. VoiAdr        rs.l    1
  117. VoiDeb        rs.l    1
  118. VoiInst        rs.l    1
  119. VoiDPat        rs.l    1
  120. VoiPat        rs.l    1
  121. VoiCpt        rs.w    1
  122. VoiRep        rs.w    1
  123. VoiNote        rs.w    1
  124. VoiDVol        rs.w    1
  125. VoiVol        rs.w    1
  126. VoiEffect    rs.l    1
  127. VoiValue    rs.w    1
  128. VoiPToTo    rs.w    1
  129. VoiPTone    rs.b    1
  130. VoiVib        rs.b    1
  131. VoiLong        equ     __Rs
  132.  
  133. *************** MUBASE table
  134.         RsReset
  135. * Voix 0
  136. MuVoix0        equ    __Rs
  137. VoiAdr0        rs.l    1
  138. VoiDeb0        rs.l    1
  139. VoiInst0    rs.l    1
  140. VoiDPat0    rs.l    1
  141. VoiPat0        rs.l    1
  142. VoiCpt0        rs.w    1
  143. VoiRep0        rs.w    1
  144. VoiNote0    rs.w    1
  145. VoiDVol0    rs.w    1
  146. VoiVol0        rs.w    1
  147. VoiEffect0    rs.l    1
  148. VoiValue0    rs.w    1
  149. VoiPToTo0    rs.w    1
  150. VoiPTone0    rs.b    1
  151. VoiVib0        rs.b    1
  152. * Voix 1
  153. MuVoix1        equ    __Rs
  154. VoiAdr1        rs.l    1
  155. VoiDeb1        rs.l    1
  156. VoiInst1    rs.l    1
  157. VoiDPat1    rs.l    1
  158. VoiPat1        rs.l    1
  159. VoiCpt1        rs.w    1
  160. VoiRep1        rs.w    1
  161. VoiNote1    rs.w    1
  162. VoiDVol1    rs.w    1
  163. VoiVol1        rs.w    1
  164. VoiEffect1    rs.l    1
  165. VoiValue1    rs.w    1
  166. VoiPToTo1    rs.w    1
  167. VoiPTone1    rs.b    1
  168. VoiVib1        rs.b    1
  169. * Voix 2
  170. MuVoix2        equ    __Rs
  171. VoiAdr2        rs.l    1
  172. VoiDeb2        rs.l    1
  173. VoiInst2    rs.l    1
  174. VoiDPat2    rs.l    1
  175. VoiPat2        rs.l    1
  176. VoiCpt2        rs.w    1
  177. VoiRep2        rs.w    1
  178. VoiNote2    rs.w    1
  179. VoiDVol2    rs.w    1
  180. VoiVol2        rs.w    1
  181. VoiEffect2    rs.l    1
  182. VoiValue2    rs.w    1
  183. VoiPToTo2    rs.w    1
  184. VoiPTone2    rs.b    1
  185. VoiVib2        rs.b    1
  186. * Voix 3
  187. MuVoix3        equ    __Rs
  188. VoiAdr3        rs.l    1
  189. VoiDeb3        rs.l    1
  190. VoiInst3    rs.l    1
  191. VoiDPat3    rs.l    1
  192. VoiPat3        rs.l    1
  193. VoiCpt3        rs.w    1
  194. VoiRep3        rs.w    1
  195. VoiNote3    rs.w    1
  196. VoiDVol3    rs.w    1
  197. VoiVol3        rs.w    1
  198. VoiEffect3    rs.l    1
  199. VoiValue3    rs.w    1
  200. VoiPToTo3    rs.w    1
  201. VoiPTone3    rs.b    1
  202. VoiVib3        rs.b    1
  203.  
  204. * Other data
  205. MuCpt        rs.w    1
  206. MuTempo        rs.w    1
  207. MuStart        rs.w    1
  208. MuStop        rs.w    1
  209. * Total length
  210. MuLong        equ     __Rs
  211.  
  212. IntEnaR        equ    $1c
  213. IntReqR        equ    $1e
  214. is_data        equ    $0e
  215. is_code        equ    $12
  216. ln_pri        equ    $09
  217. ln_type        equ    $08
  218.  
  219. ; All the above did not produce any byte of code. Here is the real beginning
  220. ; of the program. It MUST begin by a small table of pointers so that both
  221. ; AMOS and the compiler know where to get their data...
  222. ; Please remark that everything is relocatable...
  223.  
  224. ******************************************************************
  225. *    AMOS MUSIC EXTENSION
  226. ;
  227. ; First, a pointer to the token list
  228. Start    dc.l    C_Tk-C_Off
  229. ;
  230. ; Then, a pointer to the first library function
  231.     dc.l    C_Lib-C_Tk
  232. ;
  233. ; Then to the title
  234.     dc.l    C_Title-C_Lib
  235. ;
  236. ; From title to the end of the program
  237.     dc.l    C_End-C_Title
  238. ;
  239. ; An important flag. Imagine a program does not call your extension, the 
  240. ; compiler will NOT copy any routine from it in the object program. For 
  241. ; certain extensions, like MUSIC, COMPACT, it is perfect.
  242. ; But for the REQUEST extension, even if it is not called, the first routine 
  243. ; MUST be called, otherwise AMOS requester will not work!
  244. ; So, a value of 0 indicates to copy if needed only,
  245. ; A value of -1 forces the copy of the first library routine...
  246.     dc.w    0    
  247.  
  248. ******************************************************************
  249. *    Offset to library
  250. ;
  251. ; This list contains all informations for the compiler 
  252. ; and AMOS to locate your routines, in a relocatable way.
  253. ; You can produce such tables using the MAKE_LABEL.AMOS utility, found 
  254. ; on this very disc.
  255. ; All labels MUST be in order. The size of each routine MUST BE EVEN,
  256. ; as the size is divided by two. So be carefull to put an EVEN instruction
  257. ; after some text...
  258. ; You easily understand that the size of each routine can reach 128K, 
  259. ; which is largely enough. You can have up to 2000 routines in the list.
  260. ; The main AMOS.Lib library has 1100 labels...
  261.  
  262. C_Off   dc.w (L1-L0)/2,(L2-L1)/2,(L3-L2)/2,(L4-L3)/2
  263.         dc.w (L5-L4)/2,(L6-L5)/2,(L7-L6)/2,(L8-L7)/2
  264.         dc.w (L9-L8)/2,(L10-L9)/2,(L11-L10)/2,(L12-L11)/2
  265.         dc.w (L13-L12)/2,(L14-L13)/2,(L15-L14)/2,(L16-L15)/2
  266.         dc.w (L17-L16)/2,(L18-L17)/2,(L19-L18)/2,(L20-L19)/2
  267.         dc.w (L21-L20)/2,(L22-L21)/2,(L23-L22)/2,(L24-L23)/2
  268.         dc.w (L25-L24)/2,(L26-L25)/2,(L27-L26)/2,(L28-L27)/2
  269.         dc.w (L29-L28)/2,(L30-L29)/2,(L31-L30)/2,(L32-L31)/2
  270.         dc.w (L33-L32)/2,(L34-L33)/2,(L35-L34)/2,(L36-L35)/2
  271.         dc.w (L37-L36)/2,(L38-L37)/2,(L39-L38)/2,(L40-L39)/2
  272.         dc.w (L41-L40)/2,(L42-L41)/2,(L43-L42)/2,(L44-L43)/2
  273.         dc.w (L45-L44)/2,(L46-L45)/2,(L47-L46)/2,(L48-L47)/2
  274.         dc.w (L49-L48)/2,(L50-L49)/2,(L51-L50)/2,(L52-L51)/2
  275.         dc.w (L53-L52)/2,(L54-L53)/2,(L55-L54)/2,(L56-L55)/2
  276.         dc.w (L57-L56)/2,(L58-L57)/2,(L59-L58)/2,(L60-L59)/2
  277.         dc.w (L61-L60)/2,(L62-L61)/2,(L63-L62)/2,(L64-L63)/2
  278.         dc.w (L65-L64)/2,(L66-L65)/2,(L67-L66)/2,(L68-L67)/2
  279.         dc.w (L69-L68)/2,(L70-L69)/2,(L71-L70)/2,(L72-L71)/2
  280.         dc.w (L73-L72)/2,(L74-L73)/2,(L75-L74)/2,(L76-L75)/2
  281.         dc.w (L77-L76)/2,(L78-L77)/2,(L79-L78)/2,(L80-L79)/2
  282.         dc.w (L81-L80)/2,(L82-L81)/2,(L83-L82)/2,(L84-L83)/2
  283.         dc.w (L85-L84)/2,(L86-L85)/2,(L87-L86)/2,(L88-L87)/2
  284.     dc.w (L89-L88)/2,(L90-L89)/2,(L91-L90)/2,(L92-L91)/2
  285.         dc.w (L93-L92)/2,(L94-L93)/2,(L95-L94)/2,(L96-L95)/2
  286.         dc.w (L97-L96)/2,(L98-L97)/2,(L99-L98)/2,(L100-L99)/2
  287.         dc.w (L101-L100)/2,(L102-L101)/2
  288. ; Do not forget the LAST label!!!
  289.  
  290. ******************************************************************
  291. *    TOKEN TABLE
  292. ;
  293. ;
  294. ;    
  295. ; This table is the crucial point of the extension! It tells
  296. ; everything the tokenisation process needs to know. You have to 
  297. ; be carefull when writing it!
  298. ;
  299. ; The format is simple:
  300. ;    dc.w    Number of instruction,Number of function
  301. ;    dc.b    "instruction nam","e"+$80,"Param list",-1[or -2]
  302. ;
  303. ;    (1) Number of instruction / function
  304. ;        You must state the one that is needed for this token.
  305. ;               I suggest you keep the same method of referencing the
  306. ;        routines than mine: L_name, this label being defined
  307. ;        in the main program. (If you come from a 1.23 extension,
  308. ;        changing your program is easy: just add L_ before the 
  309. ;        name of each routine.
  310. ;        A -1 means take no routine is called (example a 
  311. ;        instruction only will have a -1 in the function space...)
  312. ;
  313. ;    (2) Instruction name
  314. ;        It must be finished by the letter plus $80. Be carefull
  315. ;        ARGASM assembler produces bad code if you do "a"+$80, 
  316. ;        he wants $80+"a"!!!
  317. ;        - You can SET A MARK in the token table with a "!" before
  318. ;        the name. See later
  319. ;        -Using a $80 ALONE as a name definition, will force AMOS
  320. ;        to point to the previous "!" mark...
  321. ;    
  322. ;    (3) Param list
  323. ;        This list tells AMOS everything about the instruction.
  324. ;
  325. ;    - First character:
  326. ;        The first character defines the TYPE on instruction:
  327. ;            I--> instruction
  328. ;            0--> function that returns a integer
  329. ;            1--> function that returns a float
  330. ;            2--> function that returns a string
  331. ;            V--> reserved variable. In that case, you must
  332. ;                state the type int-float-string
  333. ;    - If your instruction does not need parameters, then you stop
  334. ;    - Your instruction needs parameters, now comes the param list
  335. ;            Type,TypetType,Type...
  336. ;        Type of the parameter (0 1 2)
  337. ;        Comma or "t" for TO
  338. ;
  339. ;    (4) End of instruction
  340. ;            "-1" states the end of the instruction
  341. ;            "-2" tells AMOS that another parameter list
  342. ;                 can be accepted. if so, MUST follow the
  343. ;                 complete instruction definition as explained
  344. ;                 but with another param list.
  345. ;    If so, you can use the "!" and $80 facility not to rewrite the
  346. ;    full name of the instruction...See SAM LOOP ON instruction for an
  347. ;    example...
  348. ;
  349. ;    Remember that AMOS token list comes first, so names like:
  350. ;    PRINTHELLO will never work: AMOS will tokenise PRINT first!
  351. ;    Extension token list are explored in order of number...
  352.  
  353. ; The next two lines needs to be unchanged...
  354. C_Tk:    dc.w     1,0
  355.     dc.b     $80,-1
  356.  
  357. ; Now the real tokens...
  358.     dc.w    -1,L_FMB
  359.     dc.b    "mubas","e"+$80,"0",-1
  360.     dc.w    -1,L_FVu
  361.     dc.b    "vumete","r"+$80,"00",-1
  362.     dc.w    L_IVoice,-1
  363.     dc.b    "voic","e"+$80,"I0",-1
  364.     dc.w    L_IMusOff,-1
  365.     dc.b    "music of","f"+$80,"I",-1
  366.     dc.w    L_IMuStop,-1
  367.     dc.b    "music sto","p"+$80,"I",-1
  368.     dc.w    L_ITempo,-1
  369.     dc.b    "temp","o"+$80,"I0",-1
  370.     dc.w    L_IMusic,-1
  371.     dc.b    "musi","c"+$80,"I0",-1
  372.  
  373.     dc.w    L_INoTo,-1
  374.     dc.b    "noise t","o"+$80,"I0",-1
  375.     dc.w    L_Boom,-1
  376.     dc.b     "boo","m"+$80,"I",-1
  377.     dc.w    L_Shoot,-1
  378.     dc.b    "shoo","t"+$80,"I",-1
  379.     dc.w    L_ISBank,-1
  380.     dc.b    "sam ban","k"+$80,"I0",-1
  381.     dc.w    L_ISLOn0,-1
  382.     dc.b    "!sam loop o","n"+$80,"I",-2
  383.     dc.w    L_ISLOn1,-1
  384.     dc.b    $80,"I",-1
  385.     dc.w    L_ISLOf0,-1
  386.     dc.b    "sam loop of","f"+$80,"I",-2
  387.     dc.w    L_ISLOf1,-1
  388.     dc.b    $80,"I0",-1
  389.     dc.w    L_ISamTo,-1
  390.     dc.b    "sampl","e"+$80,"I0t0",-1
  391.     dc.w     L_ISam1,-1
  392.     dc.b     "!sam pla","y"+$80,"I0",-2
  393.     dc.w    L_ISam2,-1
  394.     dc.b    $80,"I0,0",-2
  395.     dc.w     L_ISam3,-1
  396.     dc.b    $80,"I0,0,0",-1 
  397.     dc.w     L_ISamR,-1
  398.     dc.b     "sam ra","w"+$80,"I0,0,0,0",-1    
  399.     dc.w    L_Bell0,-1
  400.     dc.b     "!bel","l"+$80,"I",-2
  401.     dc.w     L_Bell1,-1
  402.     dc.b    $80,"I0",-1
  403.     dc.w    L_IPlOf0,-1
  404.     dc.b    "!play of","f"+$80,"I",-2
  405.     dc.w    L_IPlOf1,-1
  406.     dc.b    $80,"I0",-1
  407.     dc.w     L_IPlay2,-1
  408.     dc.b    "!pla","y"+$80,"I0,0",-2
  409.     dc.w    L_IPlay3,-1
  410.     dc.b    $80,"I0,0,0",-1
  411.     dc.w     L_ISWave,-1
  412.     dc.b     "set wav","e"+$80,"I0,2",-1
  413.     dc.w    L_IDWave1,-1
  414.     dc.b    "del wav","e"+$80,"I0",-1
  415.     dc.w    L_ISEnv,-1
  416.     dc.b    "set enve","l"+$80,"I0,0t0,0",-1
  417.     dc.w    L_IMVol,-1
  418.     dc.b    "mvolum","e"+$80,"I0",-1
  419.     dc.w     L_IVol1,-1
  420.     dc.b    "!volum","e"+$80,"I0",-2
  421.     dc.w     L_IVol2,-1
  422.     dc.b    $80,"I0,0",-1
  423.     dc.w    L_IWave,-1
  424.     dc.b     "wav","e"+$80,"I0t0",-1
  425.     dc.w    L_LedOn,-1
  426.     dc.b    "led o","n"+$80,"I",-1
  427.     dc.w    L_LedOf,-1
  428.     dc.b    "led of","f"+$80,"I",-1
  429.     dc.w    L_ISay1,-1
  430.     dc.b    "!sa","y"+$80,"I2",-2
  431.     dc.w    L_ISay2,-1
  432.     dc.b    $80,"I2,0",-1
  433.     dc.w    L_ITalk,-1
  434.     dc.b    "set tal","k"+$80,"I0,0,0,0",-1
  435.     dc.w    L_SLoad,-1
  436.     dc.b    "sloa","d"+$80,"I0t0,0",-1
  437.     dc.w    -1,L_Samswapped
  438.     dc.b    "sam swappe","d"+$80,"00",-1
  439.     dc.w    L_SamSwap,-1
  440.     dc.b    "sam swa","p"+$80,"I0t0,0",-1
  441.     dc.w     L_SamStop0,-1
  442.     dc.b    "!sam sto","p"+$80,"I",-2
  443.     dc.w    L_SamStop1,-1
  444.     dc.b    $80,"I0",-1
  445.  
  446.     dc.w    L_TrackStop,-1
  447.     dc.b    "track sto","p"+$80,"I",-1
  448.     dc.w    L_TrackLoopon,-1
  449.     dc.b    "track loop o","n"+$80,"I",-1
  450.     dc.w    L_TrackLoopof,-1
  451.     dc.b    "track loop o","f"+$80,"I",-1
  452.     dc.w    L_TrackPlay0,-1
  453.     dc.b    "!track pla","y"+$80,"I",-2
  454.     dc.w    L_TrackPlay1,-1
  455.     dc.b    $80,"I0",-2
  456.     dc.w    L_TrackPlay2,-1
  457.     dc.b    $80,"I0,0",-1
  458.     dc.w    L_TrackLoad,-1
  459.     dc.b    "track loa","d"+$80,"I2,0",-1
  460.  
  461.     
  462.     dc.w     0
  463.  
  464. ;
  465. ; Now come the big part, the library. Every routine is delimited by the
  466. ; two labels: L(N) and L(N+1).
  467. ; AMOS loads the whole extension, but the compiler works differently:
  468. ; The compiler picks each routine in the library and copy it into the
  469. ; program, INDIVIDUALLY. It means that you MUST NEVER perform a JMP, a
  470. ; BSR or get an address from one library routine to another: the distance
  471. ; between them may change!!! Use the special macros instead...
  472. ;
  473. ; Importants points to follow: 
  474. ;
  475. ;    - Your code must be (pc), TOTALLY relocatable, check carefully your
  476. ;      code!
  477. ;    - You cannot directly call other library routines from one routine
  478. ;    by doing a BSR, but I have defined special macros (in S_CEQU file) 
  479. ;    to allow you to easily do so. Here is the list of available macros:
  480. ;
  481. ;    RBsr    L_Routine    does a simple BSR to the routine
  482. ;    RBra    L_Routine    as a normal BRA
  483. ;    RBeq    L_Routine    as a normal Beq
  484. ;    RBne    L_Routine    ...
  485. ;    RBcc    L_Routine
  486. ;    RBcs    L_Routine
  487. ;    RBlt    L_Routine
  488. ;    RBge    L_Routine
  489. ;    RBls    L_Routine
  490. ;    RBhi    L_Routine
  491. ;    RBle    L_Routine
  492. ;    RBpl    L_Routine
  493. ;    RBmi    L_Routine
  494. ;
  495. ; I remind you that you can only use this to call an library routine
  496. ; from ANOTHER routine. You cannot do a call WITHIN a routine, or call
  497. ; the number of the routine your caling from...
  498. ; The compiler (and AMOS1.3 extension loading part) will manage to find
  499. ; the good addresses in your program from the offset table.
  500. ;
  501. ; You can also call some main AMOS.Lib routines, to do so, use the 
  502. ; following macros:
  503. ;
  504. ;    RJsr    L_Routine    
  505. ;    RJmp    L_Routine    
  506. ; As you do not have access any more to the small table with jumps to the
  507. ; routines within AMOS, here is the concordance of the routines (the numbers
  508. ; are just refecrences to the old AMOS 1.23 calling table, and is not of
  509. ; any use in AMOS1.3):
  510. ;
  511. ;    04- Normal error    RJmp    L_Error
  512. ;    08- Specific error    RJmp     L_Error
  513. ;    0C- D3->A0 Bank address    RJsr    L_BankAd
  514. ;    10- Performs update    RJsr    L_Tests
  515. ;    14- Wait routine    RJsr    L_WaitRout
  516. ;    18- Get screen address    RJsr    L_GetEc
  517. ;    1C- Address or bank?    RJsr    L_AdOuBank
  518. ;    20- Erases bank #D3    RJsr    L_EffBank
  519. ;    24- Ask for string     RJsr    L_Demande
  520. ;
  521. ; Explanation:
  522. ;    04- Normal error, please look to the last routine in the library.
  523. ;    08- D3.l (number of bank-1) -> A0 Bank address
  524. ;    10- Performs update
  525. ;     14- Wait routine (see play)
  526. ;    18- Get screen address D0.l= screen number, return A0= adress
  527. ;    1C- Address or memory bank? (D3.l)
  528. ;    20- Erases bank #D3.l
  529. ;    24- D3.l is the length to ask for. Return A0/A1 point to free space.
  530. ;        Poke your string there, add the length of it to A0, EVEN the 
  531. ;        adress to the highest multiple of two, and move it into
  532. ;        HICHAINE(a5) location...
  533. ;
  534. ; Some extra routines:
  535. ;    RJsr    L_RamChip    Ask for CLEAR, CHIP ram, size D0, 
  536. ;                returns address in D0, nothing changed
  537. ;    RJsr    L_RamChip2    CHIP, not cleared
  538. ;    RJsr    L_RamFast    CLEAR, fast mem
  539. ;    RJsr    L_RamFast2    Fast mem, not cleared
  540. ;    RJsr    L_RamFree    Free memory A1/D0
  541. ;
  542. ; You will see in the S_LEQU all the labels in the AMOS.Lib file, you
  543. ; can if you want have fun calling some of them. But such code will
  544. ; only work with the compiler: the AMOS1.3 loader will NOT recognise
  545. ; such calls!
  546. ;
  547. ;    HOW DOES IT WORK?
  548. ;
  549. ; Having a look at the S_CEQU file, you see that I use special codes
  550. ; to show the compiler that it has to copy the asked routine and relocate
  551. ; the branch. Some remarks:
  552. ;    - The size of a Rbsr is 4 bytes, like the normal branch, it does
  553. ; not change the program (you can make some jumps over it)
  554. ;    - Although I have coded the signal, and put a lot a security, 
  555. ; a mischance may lead to the compiler thinking there is a RBsr where
  556. ; there is nothing than normal data. The result may be disastrous! So if
  557. ; you have BIG parts of datas in which you do not make any special calls,
  558. ; you can put before it the macro: RDATA. It tells the compiler that 
  559. ; the following code, up to the end of the library routine (up to the next
  560. ; L(N) label) is normal data: the compiler will not check for RBranches...
  561. ; Up to now, I have not been forced to do so, but if something goes wrong,
  562. ; try that!
  563. ;
  564. ;
  565. ;    THE NEW GRAPHIC VECTORS (if you come from AMOS1.23)
  566. ;
  567. ; AMOS1.23 graphic functions used 3 vectors in locations $100,$104 and $108
  568. ; to point to the routines. All the graphic macros
  569. ; (like Eccall, Wicall, Sycall) loaded these adresses...
  570. ; This was VERY bad, it was really a  shame to do so on the Amiga. So the
  571. ; compiler had to produce good code, repectfull to the system. That's why
  572. ; I had to put the vector in the AMOS internal datazone, pointed to by 
  573. ; A5.
  574. ; Coming from AMOS1.23, nothing have change for you, as long you assemble 
  575. ; you program with the new S_EQU file, which takes care of that. 
  576. ; The only difference is that register A5 MUST BE LOADED WITH THE 
  577. ; DATAZONE ADDRESS before using one of the macro! So check your code!
  578.  
  579. iii        equ    0
  580.  
  581. C_Lib
  582. ******************************************************************
  583. *        COLD START
  584. *
  585. ; The first routine of the library will perform all initialisations in the
  586. ; booting of AMOS.
  587. ;
  588. ; I have put here all the music datazone, and all the interrupt routines.
  589. ; I suggest you put all you C-Code here too if you have some...
  590.  
  591. ; ALL the following code, from L0 to L1 will be copied into the compiled 
  592. ; program (if any music is used in the program) at once. All RBSR, RBRA etc
  593. ; will be detected and relocated. AMOS1.3 extension loader does the same.
  594.  
  595. L0    movem.l    a3-a6,-(sp)
  596.  
  597. ;
  598. ; Here I store the address of the extension data zone in the special area
  599.     lea    MB(pc),a3
  600.     move.l    a3,ExtAdr+ExtNb*16(a5)
  601. ;
  602. ; Here, I store the address of the routine called by DEFAULT, or RUN
  603.     lea    MusDef(pc),a0
  604.     move.l    a0,ExtAdr+ExtNb*16+4(a5)
  605. ;
  606. ; Here, the address of the END routine,
  607.     lea    MusEnd(pc),a0
  608.     move.l    a0,ExtAdr+ExtNb*16+8(a5)
  609. ;
  610. ; And now the Bank check routine..
  611.     lea    BkCheck(pc),a0
  612.     move.l    a0,ExtAdr+ExtNb*16+12(a5)
  613.  
  614. ; mt: allocate memory for am wave forms
  615.     move.l    #488,d0
  616.     Sycall    SyChip
  617.     move.l    d0,mt_amwave-MB(a3)
  618.     move.l    d0,a0
  619.     lea    96(a0),a2
  620.     move.l    a2,mt_noise-MB(a3)
  621.     lea    32(a2),a2
  622.     move.l    a2,mt_ams-MB(a3)
  623.     moveq    #121,d0
  624.     lea    mt_amwaveforms-MB(a3),a1
  625. .lp    move.l    (a1)+,(a0)+
  626.     dbf    d0,.lp
  627.  
  628. ; You are not obliged to store something in the above areas, you can leave
  629. ; them to zero if no routine is to be called...
  630. ;
  631. ; In AMOS data zone, stands 8 long words allowing you to simply
  632. ; put a patch in the VBL interrupt. The first on is at VBLRout.
  633. ; At each VBL, AMOS explores this list, and call all address <> 0
  634. ; It stops at the FIRST zero. The music patch is the first routine
  635. ; called.
  636.     lea    MusInt(pc),a0        * Interrupt routine
  637.     move.l    a0,VBLRout(a5)
  638. ; 50/60 herz?
  639.     move.l    #3546895,MusClock-MB(a3)
  640.     move.w    #100,TempoBase-MB(a3)
  641.     EcCall    NTSC            * Is system NTSC?
  642.     tst.w    d1
  643.     beq.s    ItsPAL
  644.     move.w    #120,TempoBase-MB(a3)
  645.     move.l    #3579545,MusClock-MB(a3)
  646. ItsPAL    
  647. ; Install sample interrupts
  648.     lea    Sami_handler(pc),a0
  649.     move.l    a0,Sami_handad-MB(a3)
  650.  
  651. ; As you can see, you MUST preserve A3-A6, and return in D0 the 
  652. ; Number of the extension if everything went allright. If an error has
  653. ; occured (no more memory, no file found etc...), return -1 in D0 and
  654. ; AMOS will refuse to start.
  655.     movem.l    (sp)+,a3-a6
  656.     moveq    #ExtNb,d0        * NO ERRORS
  657.     rts
  658.  
  659. ******* SCREEN RESET
  660. ; This routine is called each time a DEFAULT occurs...
  661. ;
  662. ; The next instruction loads the internal datazone address. I could have
  663. ; of course done a load MB(pc),a3 as the datazone is in the same
  664. ; library chunk. 
  665.  
  666. MusDef    DLoad    a3    
  667. * Reset TRACKER music
  668.     RBsr    L_TrackStop
  669.     clr.b    sorploop-MB(a3)
  670. * Reset Sam_interrupts
  671.     move.w    #$000F,Circuits+DmaCon
  672.     Rbsr    L_Sami_install
  673. * Init narrator
  674.     Rbsr    L_NarInit
  675. * Init musique
  676.     Rbsr    L_RazWave        * Reset waves
  677.     move.l    Buffer(a5),a0        * Draw square wave
  678.     move.l    a0,a1
  679.     moveq    #127,d0
  680. MuDf1    move.b    #-127,128(a0)
  681.     move.b    #127,(a0)+
  682.     dbra    d0,MuDf1
  683.     moveq    #0,d1            * 0-> Noise
  684.     Rbsr    L_NeWave
  685.     moveq    #1,d1            * 1-> Square wave
  686.     Rbsr    L_NeWave
  687.     move.w    #LNoise/2-1,d2        * Draw first noise
  688.     move.w    BSeed-MB(a3),d1
  689.     move.l    WaveBase-MB(a3),a0
  690.     lea    WaveDeb(a0),a0
  691. MuDf2    add.w    Circuits+6,d1
  692.     mulu    #$3171,d1
  693.     lsr.l    #8,d1
  694.     move.w    d1,(a0)+
  695.     dbra    d2,MuDf2
  696.     move.w    d1,BSeed-MB(a3)
  697.     moveq    #56,d0            * Default settings
  698.     moveq    #%1111,d1
  699.     Rbsr    L_Vol
  700.     Rbsr    L_MVol
  701.     move.w    #5,SamBank-MB(a3)    * Sample bank=5    
  702.     moveq    #-1,d0            * Sam loop off
  703.     moveq    #-1,d1
  704.     Rbsr    L_SL0
  705.     Rbra    L_MuInit
  706.  
  707. ******* QUIT
  708. ; This routine is called when you quit AMOS or when the compiled program
  709. ; ends. If you have opend devices, reserved memory you MUST close and
  710. ; restore everything to normal.
  711.  
  712. MusEnd:    DLoad    a3
  713. * No more VBL
  714.     clr.l    VBLRout(a5)
  715. * No more Sami
  716.     RBsr    L_Sami_remove
  717. * End narrator (if there)
  718.     move.l    $4.w,a6
  719.     tst.l    TranBase-MB(a3)
  720.     beq.s    NarEnd
  721.     lea    WriteRep-MB(a3),a1
  722.     jsr    RemPort(a6)
  723.     lea    TalkIO-MB(a3),a1
  724.     jsr    CloseDev(a6)
  725.     move.l    TranBase-MB(a3),a1
  726.     jsr    CloseLib(a6)
  727. * End music
  728. NarEnd    Rbsr    L_MOff
  729.     moveq    #%1111,d0
  730.     Rbsr    L_EnvOff
  731.     Rbsr    L_RazWave
  732.     lea    Circuits,a0
  733.     move.w    #$000F,DmaCon(a0)
  734.     clr.w    $a8(a0)
  735.     clr.w    $b8(a0)
  736.     clr.w    $c8(a0)
  737.     clr.w    $d8(a0)
  738. * mt: remove data zone
  739.     move.l    #488,d0
  740.     move.l    mt_amwave-MB(a3),a1
  741.     Sycall    SyFree
  742. * Finished!
  743.     rts
  744.  
  745. ******* LOOK FOR MUSIC BANK
  746. ; This routine is called after any bank has been loaded, reserved or erased.
  747. ; Here, if a music is being played and if the music bank is erased, I MUST
  748. ; stop the music, otherwise it might crash the computer. That's why I
  749. ; do a checksum on the first bytes of the bank to see if they have changed...
  750. BkCheck    RBsr    L_TrackCheck        * Check Tracker.
  751. * Check normal music.
  752.     DLoad    a3
  753.     move.l    MusBank-MB(a3),d0    * Address of OLD music bank
  754.     move.l    2*8(a0),d1        * Address of ACTUAL music bank
  755.     beq.s    BkNo            * 8 bytes per bank (here bank 3)
  756.     move.l    d1,a1            * Looks for "Musi"
  757.     move.l    (a1),d2        
  758.     cmp.l    BkMus-MB(a3),d2
  759.     bne.s    BkNo
  760.     lea    8(a1),a1
  761.     moveq    #0,d1            * Performs a check sum
  762.     add.l    (a1),d1
  763.     add.l    4(a1),d1
  764.     add.l    8(a1),d1
  765.     add.l    12(a1),d1
  766.     cmp.l    d0,a1
  767.     bne.s    BkNew
  768.     cmp.l    MusCheck-MB(a3),d1
  769.     bne.s    BkNew
  770. * Same bank! Do nothing!
  771.     rts
  772. * No more bank!
  773. BkNo    tst.l    d0
  774.     beq.s    BkNo1
  775.     Rbsr    L_MuInit
  776.     clr.l    MusBank-MB(a3)
  777. BkNo1    rts
  778. * A NEW bank
  779. BkNew    move.l    a1,MusBank-MB(a3)
  780.     move.l    d1,MusCheck-MB(a3)
  781.     Rbsr    L_MuInit
  782.     move.l    MusBank-MB(a3),a0
  783.     move.l    a0,a1
  784.     add.l    (a0),a1
  785.     move.l    a1,BankInst-MB(a3)
  786.     move.l    a0,a1
  787.     add.l    4(a0),a1
  788.     move.l    a1,BankSong-MB(a3)
  789.     add.l    8(a0),a0
  790.     move.l    a0,BankPat-MB(a3)
  791.     rts
  792.  
  793. ***********************************************************
  794. *
  795. *    INTERRUPT ROUTINES
  796. *
  797. ***********************************************************    
  798.  
  799. ******* Sami interrupt handlers
  800. Sami_handler
  801.     add.w    Sami_reg(a1),a0
  802.     move.l    Sami_pos(a1),d0
  803.     cmp.l    Sami_long(a1),d0
  804.     bcc.s    .whatnow
  805. * Poursuit la lecture du sample
  806. .samloop
  807.     move.l    d0,d1
  808.     add.l    #Sami_lplay,d1
  809.     cmp.l    Sami_long(a1),d1
  810.     bls.s    .skip
  811.     move.l    Sami_long(a1),d1
  812. .skip    move.l    d1,Sami_pos(a1)
  813.     sub.l    d0,d1
  814.     lsr.l    #1,d1
  815.     add.l    Sami_adr(a1),d0
  816.     move.l    d0,(a0)                * AUDxLOC
  817.     move.w    d1,4(a0)            * AUDxLEN
  818.     move.w    Sami_dvol(a1),d0
  819.     bmi.s    .skip1
  820.     move.w    d0,8(a0)            * AUDxVOL
  821. .skip1    move.w    Sami_bit(a1),Circuits+IntReq
  822.     rts
  823. * Sample termine. Que faire?
  824. .whatnow
  825.     move.l    d0,d1
  826.     move.l    Sami_radr(a1),d0        * Double buffer?
  827.     bne.s    .swap
  828.     move.l    Sami_rpos(a1),d0        * Boucler?
  829.     bpl.s    .samloop
  830.     bset    #7,Sami_pos(a1)            * Attend?
  831.     tst.l    d1
  832.     bpl.s    .skip1
  833. * Fin du sample-> met du blanc!
  834.     move.w    #0,$a(a0)
  835.     move.w    Sami_dma(a1),d0
  836.     moveq    #0,d1
  837.     bset    d0,d1
  838.     move.w    d1,Circuits+DmaCon
  839.     tst.w    Sami_dvol(a1)
  840.     bmi.s    .skip2
  841.     lea    MB(pc),a0            * Restart music
  842.     bset    d0,MuReStart+1-MB(a0)
  843. .skip2    move.w    Sami_bit(a1),Circuits+IntEna    * No more interrupts
  844.     move.w    Sami_bit(a1),Circuits+IntReq
  845.     rts
  846. * Change de buffer
  847. .swap    clr.l    Sami_radr(a1)
  848.     move.l    d0,Sami_adr(a1)
  849.     move.l    Sami_rlong(a1),Sami_long(a1)
  850.     moveq    #0,d0
  851.     bra    .samloop
  852.  
  853. ******* VBL Entry
  854. MusInt    lea    MB(pc),a3    
  855.     move.w    EnvOn-MB(a3),d0
  856.     beq    Music
  857.     lea    EnvBase-MB(a3),a0
  858.     lea    $a0(a6),a2
  859.     moveq    #0,d1
  860.     moveq    #3,d2
  861.     moveq    #0,d5
  862. MuInt1    btst    d1,d0
  863.     beq.s    MuIntN
  864.     move.l    EnvDelta(a0),d3
  865.     add.l    EnvVol(a0),d3
  866.     move.l    d3,EnvVol(a0)
  867.     swap    d3
  868.     move.w    d3,8(a2)
  869. MuInt2    subq.w    #1,EnvNb(a0)
  870.     bne.s    MuIntN
  871.     Rbsr    L_MuIntE
  872. MuIntN    lea    EnvLong(a0),a0
  873.     lea    $10(a2),a2
  874.     addq.w    #1,d1
  875.     dbra    d2,MuInt1
  876.     move.w    d0,EnvOn-MB(a3)
  877.     move.w    d5,DmaCon(a6)
  878.     lsl.w    #7,d5
  879.     move.w    d5,IntEna(a6)
  880. ******* Make noise?
  881.     tst.w    Noise-MB(a3)
  882.     beq.s    Music
  883.     move.w    PNoise-MB(a3),d0
  884.     moveq    #7,d2
  885.     move.w    BSeed-MB(a3),d1
  886.     move.l    WaveBase-MB(a3),a0
  887. INoi1    add.w    6(a6),d1
  888.     mulu    #$3171,d1
  889.     lsr.l    #8,d1
  890.     move.w    d1,WaveDeb(a0,d0.w)
  891.     subq.w    #2,d0
  892.     bpl.s    INoi2
  893.     move.w    #LNoise-2,d0
  894. INoi2    dbra    d2,INoi1
  895.     move.w    d0,PNoise-MB(a3)
  896.     move.w    d1,BSeed-MB(a3)
  897.  
  898. *******    Music routine
  899. Music:    move.l    MuBase-MB(a3),d0
  900.     beq    Tracker
  901.     movem.l    a4-a6,-(sp)
  902.     move.l    d0,a5
  903.     bsr    MuEvery
  904. * Here is a smart counter, which gives progressive results
  905. * from zero to 100(PAL), 120(NTSC)...
  906.     move.w    MuCpt(a5),d0
  907.     add.w    MuTempo(a5),d0
  908.     move.w    d0,MuCpt(a5)
  909.     move.w    TempoBase-MB(a3),d1
  910.     cmp.w    d1,d0
  911.     bcs    MuEff
  912.     sub.w    d1,MuCpt(a5)
  913. * Lets go for one step of music!
  914.     moveq    #0,d5
  915.     moveq    #0,d7
  916.     move.l    a5,a4
  917.  
  918.     tst.b    VoiCpt+1(a4)
  919.     beq.s    Mus0
  920.     addq.w    #1,d5
  921.     subq.b    #1,VoiCpt+1(a4)
  922.     bne.s    Mus0
  923.     moveq    #0,d6
  924.     move.l    MuChip0-MB(a3),a6
  925.     bsr    MuStep
  926. Mus0    
  927.     lea    MuVoix1(a5),a4
  928.     tst.b    VoiCpt+1(a4)
  929.     beq.s    Mus1
  930.     addq.w    #1,d5
  931.     subq.b    #1,VoiCpt+1(a4)
  932.     bne.s    Mus1
  933.     moveq    #1,d6
  934.     move.l    MuChip1-MB(a3),a6
  935.     bsr    MuStep
  936. Mus1
  937.     lea    MuVoix2(a5),a4
  938.     tst.b    VoiCpt+1(a4)
  939.     beq.s    Mus2
  940.     addq.w    #1,d5
  941.     subq.b    #1,VoiCpt+1(a4)
  942.     bne.s    Mus2
  943.     moveq    #2,d6
  944.     move.l    MuChip2-MB(a3),a6
  945.     bsr    MuStep
  946. Mus2    
  947.     lea    MuVoix3(a5),a4
  948.     tst.b    VoiCpt+1(a4)
  949.     beq.s    Mus3
  950.     addq.w    #1,d5
  951.     subq.b    #1,VoiCpt+1(a4)
  952.     bne.s    Mus3
  953.     moveq    #3,d6
  954.     move.l    MuChip3-MB(a3),a6
  955.     bsr    MuStep
  956. Mus3    
  957.     and.w    MuDMAsk-MB(a3),d7
  958.     move.w    d7,$DFF096
  959.     tst.w    d5
  960.     beq.s    MuFin
  961.     bne.s    MuEnd
  962. MuEff    bsr    DoEffects
  963. MuEnd    movem.l    (sp)+,a4-a6
  964. MuEnd1    rts
  965. * Finished?
  966. MuFin    subq.w    #1,MuNumber-MB(a3)
  967.     beq    MuFini
  968. * Restarts previous music
  969.     move.w    MuNumber-MB(a3),d0
  970.     subq.w    #1,d0
  971.     mulu    #MuLong,d0
  972.     lea    MuBuffer-MB(a3),a0
  973.     add.w    d0,a0
  974.     move.l    a0,MuBase-MB(a3)
  975.     move.w    MuDMAsk-MB(a3),MuReStart-MB(a3)
  976.     clr.w    MuStart(a0)
  977.     clr.w    MuStop(a0)
  978.     bra.s    MuEnd
  979. * Really finished!
  980. MuFini    clr.l    MuBase-MB(a3)
  981.     Rbsr    L_MOff
  982.     bra.s    MuEnd
  983.  
  984. ******* One step of music for one voice
  985. MuStep    lea    MuJumps(pc),a1
  986.     move.l    VoiAdr(a4),a2
  987. MuSt0    move.w    (a2)+,d0
  988.     bpl.s    DoNote
  989.     move.w    d0,d1
  990.     and.w    #$7F00,d0
  991.     lsr.w    #6,d0
  992.     jmp    0(a1,d0.w)
  993.  
  994. ******* Play a note
  995. DoNote    btst    #14,d0
  996.     bne.s    OldNote
  997. * Play normal note
  998.     and.w    #$0FFF,d0
  999.     move.l    BankInst-MB(a3),d1
  1000.     move.l    VoiInst(a4),a0
  1001.     add.l    (a0),d1
  1002.     move.l    d1,(a6)
  1003.     move.w    8(a0),$04(a6)
  1004.     bset    d6,d7
  1005.     bclr    d6,MuStop+1(a5)
  1006.     bset    d6,MuStart+1(a5)
  1007.     move.b    VoiVol+1(a4),0(a3,d6.w)
  1008.     tst.b    VoiPTone(a4)
  1009.     bne.s    MuSt1
  1010. * No portamento
  1011.     move.w    d0,VoiNote(a4)
  1012.     move.w    d0,$06(a6)
  1013.     bra.s    MuSt0
  1014. * Start portamento
  1015. MuSt1    clr.b    VoiPTone(a4)
  1016.     move.w    d0,VoiPToTo(a4)
  1017.     lea    MuPTone(pc),a0
  1018.     move.l    a0,VoiEffect(a4)
  1019.     bra.s    MuSt0
  1020. * Play note compatible with first version
  1021. OldNote    move.w    d0,VoiCpt(a4)
  1022.     move.w    (a2)+,d0
  1023.     beq.s    ONoteE
  1024.     and.w    #$0FFF,d0
  1025.     move.w    d0,VoiNote(a4)
  1026.     move.w    d0,$06(a6)
  1027.     move.l    BankInst-MB(a3),d0
  1028.     move.l    VoiInst(a4),a0
  1029.     add.l    (a0),d0
  1030.     move.l    d0,(a6)
  1031.     move.w    8(a0),$04(a6)
  1032.     bset    d6,d7
  1033.     bclr    d6,MuStop+1(a5)
  1034.     bset    d6,MuStart+1(a5)
  1035.     move.b    VoiVol+1(a4),0(a3,d6.w)
  1036. ONoteE    move.l    a2,VoiAdr(a4)
  1037.     rts
  1038.  
  1039. ******* Jump table to labels
  1040. MuJumps    bra    EtEnd            * 00-> Fin pattern
  1041.     bra    MuSt0            * 01-> Old Slide up
  1042.     bra    MuSt0            * 02-> Old Slide down
  1043.     bra    EtSVol            * 03-> Set volume
  1044.     bra    EtStop            * 04-> Stop effet
  1045.     bra    EtRep            * 05-> Repeat
  1046.     bra    EtLOn            * 06-> Led On
  1047.     bra    EtLOff            * 07-> Led Off
  1048.     bra    EtTemp            * 08-> Set Tempo
  1049.     bra    EtInst            * 09-> Set Instrument
  1050.     bra    EtArp            * 10-> Arpeggiato
  1051.     bra    EtPort            * 11-> Portamento
  1052.     bra    EtVib            * 12-> Vibrato
  1053.     bra    EtVSl            * 13-> Volume slide
  1054.     bra    EtSlU            * 14-> Slide up
  1055.     bra    EtSlD            * 15-> Slide down
  1056.      bra    EtDel            * 16-> Delay
  1057.     bra    EtJmp            * 17-> Position jump
  1058.     bra    MuSt0            * 18-> Free space
  1059.     bra    MuSt0            * 19-> Free space
  1060.     bra    MuSt0            * 20-> Free space
  1061.     bra    MuSt0            * 21-> Free space
  1062.     bra    MuSt0            * 22-> Free space
  1063.     bra    MuSt0            * 23-> Free space
  1064.     bra    MuSt0            * 24-> Free space
  1065.     bra    MuSt0            * 25-> Free space
  1066.     bra    MuSt0            * 26-> Free space
  1067.     bra    MuSt0            * 27-> Free space
  1068.     bra    MuSt0            * 28-> Free space
  1069.     bra    MuSt0            * 29-> Free space
  1070.     bra    MuSt0            * 30-> Free space
  1071.     bra    MuSt0            * 31-> Free space
  1072.  
  1073. ******* End of a pattern
  1074. EtEnd    clr.w    VoiCpt(a4)
  1075.     clr.w    VoiRep(a4)
  1076.     clr.l    VoiDeb(a4)
  1077.     lea    NoEffect(pc),a0
  1078.     move.l    a0,VoiEffect(a4)
  1079.     move.l    VoiPat(a4),a0
  1080. RePat    moveq    #0,d0
  1081.     move.w    (a0)+,d0
  1082.     bmi.s    EtEnd1
  1083.     move.l    a0,VoiPat(a4)
  1084.     move.l    BankPat-MB(a3),a0
  1085.     cmp.w    (a0),d0
  1086.     bhi.s    EtEndX
  1087.     lsl.w    #2,d0
  1088.     add.w    d6,d0
  1089.     lsl.w    #1,d0
  1090.     move.w    2(a0,d0.w),d0
  1091.     beq.s    EtEndX
  1092.     lea    0(a0,d0.l),a2
  1093.     bra    MuSt0
  1094. EtEndX    rts
  1095. EtEnd1    cmp.w    #-1,d0
  1096.     beq.s    EtEndX
  1097.      move.l    VoiDPat(a4),a0
  1098.     bra.s    RePat
  1099. ******* Change instrument
  1100. EtInst    and.w    #$00FF,d1
  1101.     move.l    BankInst-MB(a3),a0
  1102.     lsl.w    #5,d1
  1103.     lea    2(a0,d1.w),a0
  1104.     move.l    a0,VoiInst(a4)
  1105.     move.w    12(a0),d0
  1106.     cmp.w    #64,d0
  1107.     bcs.s    EtInst1
  1108.     moveq    #63,d0
  1109. EtInst1    move.w    d0,VoiDVol(a4)
  1110.     mulu    MuVolume-MB(a3),d0
  1111.     lsr.w    #6,d0
  1112.     move.w    d0,VoiVol(a4)
  1113.     bra    MuSt0
  1114. ******* Set Volume
  1115. EtSVol    and.w    #$00FF,d1
  1116.     cmp.w    #64,d1
  1117.     bcs.s    EtSVol1
  1118.     moveq    #63,d1
  1119. EtSVol1    move.w    d1,VoiDVol(a4)
  1120.     mulu    MuVolume-MB(a3),d1
  1121.     lsr.w    #6,d1
  1122.     move.w    d1,VoiVol(a4)
  1123.     bra    MuSt0
  1124. ******* Set Tempo
  1125. EtTemp    and.w    #$00FF,d1
  1126.     move.w    d1,MuTempo(a5)
  1127.     bra    MuSt0
  1128. ******* Led On
  1129. EtLOn    bclr    #1,$bfe001
  1130.     bra    MuSt0
  1131. ******* Led Off
  1132. EtLOff    bset    #1,$bfe001
  1133.     bra    MuSt0
  1134. ******* Repeat
  1135. EtRep    and.w    #$00FF,d1
  1136.     bne.s    EtRep1
  1137.     move.l    a2,VoiDeb(a4)
  1138.     bra    MuSt0
  1139. EtRep1    tst.w    VoiRep(a4)
  1140.     bne.s    EtRep2
  1141.     move.w    d1,VoiRep(a4)
  1142.     bra    MuSt0
  1143. EtRep2    subq.w    #1,VoiRep(a4)
  1144.     beq    MuSt0
  1145.     move.l    VoiDeb(a4),d0
  1146.     beq    MuSt0
  1147.     move.l    d0,a2
  1148.     bra    MuSt0
  1149. ******* Arpeggio
  1150. EtArp    move.b    d1,VoiValue+1(a4)
  1151.     lea    MuArp(pc),a0
  1152.     move.l    a0,VoiEffect(a4)
  1153.     bra    MuSt0
  1154. ******* Portamento
  1155. EtPort    move.b    #1,VoiPTone(a4)
  1156.     lea    MuPTone(pc),a0
  1157.     bra.s    EtSetE
  1158. ******* Vibrato
  1159. EtVib    lea    MuVib(pc),a0
  1160.     bra.s    EtSetE
  1161. ******* Volume slide
  1162. EtVSl    and.w    #$00FF,d1
  1163.     move.w    d1,d0
  1164.     lsr.w    #4,d0
  1165.     tst.w    d0
  1166.     bne.s    VsEnd
  1167.     and.w    #$000F,d1
  1168.     neg.w    d1
  1169.     move.w    d1,d0
  1170. VsEnd    move.w    d0,VoiValue(a4)
  1171.     lea    MuVSl(pc),a0
  1172.     move.l    a0,VoiEffect(a4)
  1173.     bra    MuSt0
  1174. ******* Slide up
  1175. EtSlU    and.w    #$00FF,d1
  1176.     neg.w    d1
  1177.     lea    MuSlide(pc),a0
  1178.     bra.s    EtSte
  1179. ******* Slide Down
  1180. EtSlD    lea    MuSlide(pc),a0
  1181. EtSetE    and.w    #$00FF,d1
  1182. EtSte    move.w    d1,VoiValue(a4)
  1183.     move.l    a0,VoiEffect(a4)
  1184.     bra    MuSt0
  1185. ******* Stop effect
  1186. EtStop    lea    NoEffect(pc),a0
  1187.     move.l    a0,VoiEffect(a4)
  1188.     bra    MuSt0
  1189. ******* Jump to pattern
  1190. EtJmp    and.w    #$00FF,d1
  1191.     lsl.w    #1,d1
  1192.     move.l    VoiDPat(a4),a0
  1193.     add.w    d1,a0
  1194.     move.l    a0,VoiPat(a4)
  1195.     bra    EtEnd
  1196. ******* Delay
  1197. EtDel    move.w    d1,VoiCpt(a4)
  1198.     move.l    a2,VoiAdr(a4)
  1199.     rts
  1200.  
  1201. ******* Effect routines
  1202.  
  1203. * Performs all effects
  1204. DoEffects
  1205.     move.l    a5,a4
  1206.     move.l    MuChip0-MB(a3),a6
  1207.     move.l    VoiEffect(a4),a0
  1208.     jsr    (a0)
  1209.     move.w    VoiVol(a4),$08(a6)
  1210.     lea    MuVoix1(a5),a4
  1211.     move.l    MuChip1-MB(a3),a6
  1212.     move.l    VoiEffect(a4),a0
  1213.     jsr    (a0)
  1214.     move.w    VoiVol(a4),$08(a6)
  1215.     lea    MuVoix2(a5),a4
  1216.     move.l    MuChip2-MB(a3),a6
  1217.     move.l    VoiEffect(a4),a0
  1218.     jsr    (a0)
  1219.     move.w    VoiVol(a4),$08(a6)
  1220.     lea    MuVoix3(a5),a4
  1221.     move.l    MuChip3-MB(a3),a6
  1222.     move.l    VoiEffect(a4),a0
  1223.     jsr    (a0)
  1224.     move.w    VoiVol(a4),$08(a6)
  1225.     rts
  1226.  
  1227. * TONE SLIDE
  1228. MuSlide    move.w    VoiValue(a4),d0
  1229.     beq.s    NoMoreE
  1230.     add.w    VoiNote(a4),d0
  1231.     cmp.w    #$71,d0
  1232.     bcc.s    MuSl1
  1233.     moveq    #$71,d0
  1234.     bsr    NoMoreE
  1235. MuSl1    cmp.w    #$358,d0
  1236.     bls.s    MuSl2
  1237.     move.w    #$358,d0
  1238.     bsr    NoMoreE
  1239. MuSl2    move.w    d0,VoiNote(a4)
  1240.     move.w    d0,$06(a6)
  1241.     rts
  1242. NoMoreE    lea    NoEffect(pc),a0
  1243.     move.l    a0,VoiEffect(a4)
  1244.     rts
  1245. NoEffect
  1246.     move.w    VoiNote(a4),$06(a6)
  1247.     rts
  1248.  
  1249. * ARPEGGIO
  1250. MuArp    moveq    #0,d0
  1251.     move.b    VoiValue+1(a4),d0
  1252.     move.b    VoiValue(a4),d1
  1253.     cmp.b    #3,d1
  1254.     bcs.s    MuArp0
  1255.     moveq    #2,d1
  1256. MuArp0    subq.b    #1,d1
  1257.     move.b    d1,VoiValue(a4)
  1258.     beq.s    MuArp2
  1259.     bpl.s    MuArp1
  1260.     lsr.b    #4,d0
  1261.     bra.s    MuArp3
  1262. MuArp1    and.b    #$0f,d0
  1263.     bra.s    MuArp3
  1264. MuArp2    move.w    VoiNote(a4),d2
  1265.     bra.s    MuArp4
  1266. MuArp3    add.w    d0,d0
  1267.     moveq    #0,d1
  1268.     move.w    VoiNote(a4),d1
  1269.     lea    Periods(pc),a0
  1270.     moveq    #$24,d3
  1271. MuArpL    move.w    (a0,d0.w),d2
  1272.     cmp.w    (a0),d1
  1273.     bge.s    MuArp4
  1274.     addq.l    #2,a0
  1275.     dbra    d3,MuArpL
  1276.     rts
  1277. MuArp4    move.w    d2,$06(a6)
  1278.     rts
  1279.  
  1280. * PORTAMENTO
  1281. MuPTone    move.w    VoiValue(a4),d0
  1282.     move.w    VoiNote(a4),d1
  1283.     cmp.w    VoiPToTo(a4),d1
  1284.     beq.s    MuPTo3
  1285.     bcs.s    MuPTo1
  1286.     sub.w    d0,d1
  1287.     cmp.w    VoiPToTo(a4),d1
  1288.     bhi.s    MuPto4
  1289.     bra.s    MuPTo2
  1290. MuPTo1    add.w    d0,d1
  1291.     cmp.w    VoiPToTo(a4),d1
  1292.     bcs.s    MuPTo4
  1293. MuPTo2    move.w    VoiPToTo(a4),d1
  1294. MuPTo3    bsr    NoMoreE
  1295. MuPTo4    move.w    d1,VoiNote(a4)
  1296.     move.w    d1,$06(a6)
  1297.     rts
  1298.  
  1299. * VIBRATO
  1300. MuVib    move.b    VoiVib(a4),d0
  1301.     lea    Sinus(pc),a0
  1302.     lsr.w    #2,d0
  1303.     and.w    #$1f,d0
  1304.     moveq    #0,d2
  1305.     move.b    0(a0,d0.w),d2
  1306.     move.b    VoiValue+1(a4),d0
  1307.     and.w    #$0F,d0
  1308.     mulu    d0,d2
  1309.     lsr.w    #$06,d2
  1310.     move.w    VoiNote(a4),d0
  1311.     tst.b    VoiVib(a4)
  1312.     bmi.s    MuVib1
  1313.     add.w    d2,d0
  1314.     bra.s    MuVib2
  1315. MuVib1    sub.w    d2,d0
  1316. MuVib2    move.w    d0,$06(a6)
  1317.     move.b    VoiValue+1(a4),d0
  1318.     lsr.w    #2,d0
  1319.     and.w    #$3C,d0
  1320.     add.b    d0,VoiVib(a4)
  1321.     rts
  1322.  
  1323. * VOLUME SLIDE
  1324. MuVSl    move.w    VoiDVol(a4),d0
  1325.     add.w    VoiValue(a4),d0
  1326.     bpl.s    MuVSl1
  1327.     clr.w    d0
  1328. MuVSl1    cmp.w    #$40,d0
  1329.     bcs.s    MuVSl2
  1330.     moveq    #$3F,d0
  1331. MuVSl2    move.w    d0,VoiDVol(a4)
  1332.     mulu    MuVolume-MB(a3),d0
  1333.     lsr.w    #6,d0
  1334.     move.w    d0,VoiVol(a4)
  1335.     rts
  1336.  
  1337. *******    Routine called every VBL
  1338. MuEvery    
  1339.  
  1340. * Second step of sample?
  1341.     move.w    MuStop(a5),d0
  1342.     beq    MuEvX
  1343.     move.l    BankInst-MB(a3),d1
  1344.     btst    #0,d0                * Voix 0
  1345.     beq.s    MuEv0
  1346.     move.l    MuChip0-MB(a3),a6
  1347.     move.l    VoiInst0(a5),a0
  1348.     move.l    d1,d2
  1349.     add.l    4(a0),d2
  1350.     move.l    d2,(a6)
  1351.     move.w    10(a0),$04(a6)
  1352. MuEv0    btst    #1,d0                * Voix 1
  1353.     beq.s    MuEv1
  1354.     move.l    MuChip1-MB(a3),a6
  1355.     move.l    VoiInst1(a5),a0
  1356.     move.l    d1,d2
  1357.     add.l    4(a0),d2
  1358.     move.l    d2,(a6)
  1359.     move.w    10(a0),$04(a6)
  1360. MuEv1    btst    #2,d0                * Voix 2
  1361.     beq.s    MuEv2
  1362.     move.l    MuChip2-MB(a3),a6
  1363.     move.l    VoiInst2(a5),a0
  1364.     move.l    d1,d2
  1365.     add.l    4(a0),d2
  1366.     move.l    d2,(a6)
  1367.     move.w    10(a0),$04(a6)
  1368. MuEv2    btst    #3,d0                * Voix 3
  1369.     beq.s    MuEv3
  1370.     move.l    MuChip3-MB(a3),a6
  1371.     move.l    VoiInst3(a5),a0
  1372.     move.l    d1,d2
  1373.     add.l    4(a0),d2
  1374.     move.l    d2,(a6)
  1375.     move.w    10(a0),$04(a6)
  1376. MuEv3    
  1377.  
  1378. * Start a voice
  1379. MuEvX    move.w    MuStart(a5),d1
  1380.     move.w    d1,MuStop(a5)
  1381.     clr.w    MuStart(a5)
  1382.     or.w    d1,d0
  1383.     and.w    MuDMAsk-MB(a3),d0
  1384.     bset    #15,d0
  1385.     move.w    d0,$DFF096
  1386.  
  1387. * Restart voices?
  1388.     move.w    MuReStart-MB(a3),d0
  1389.     beq    MuRsX
  1390.     moveq    #0,d3
  1391.     btst    #0,d0                * Voix 0
  1392.     beq.s    MuRs0
  1393.     lea    $DFF0A0,a6
  1394.     move.l    a6,MuChip0-MB(a3)
  1395.     move.w    #2,$04(a6)
  1396.     tst.l    VoiInst0(a5)
  1397.     beq.s    MuRs0
  1398.     bset    #0,d3
  1399. MuRs0    btst    #1,d0                * Voix 1
  1400.     beq.s    MuRs1
  1401.     lea    $DFF0B0,a6
  1402.     move.l    a6,MuChip1-MB(a3)
  1403.     move.w    #2,$04(a6)
  1404.     tst.l    VoiInst1(a5)
  1405.     beq.s    MuRs1
  1406.     bset    #1,d3
  1407. MuRs1    btst    #2,d0                * Voix 2
  1408.     beq.s    MuRs2
  1409.     lea    $DFF0C0,a6
  1410.     move.l    a6,MuChip2-MB(a3)
  1411.     move.w    #2,$04(a6)
  1412.     tst.l    VoiInst2(a5)
  1413.     beq.s    MuRs2
  1414.     bset    #2,d3
  1415. MuRs2    btst    #3,d0                * Voix 3
  1416.     beq.s    MuRs3
  1417.     lea    $DFF0D0,a6
  1418.     move.l    a6,MuChip3-MB(a3)
  1419.     move.w    #2,$04(a6)
  1420.     tst.l    VoiInst3(a5)
  1421.     beq.s    MuRs3
  1422.     bset    #3,d3
  1423. MuRs3    clr.w    MuReStart-MB(a3)
  1424.     or.w    d0,MuDMAsk-MB(a3)
  1425.     or.w    d3,MuStop(a5)
  1426. MuRsX    
  1427.     rts
  1428.  
  1429.  
  1430. ***********************************************************
  1431. *
  1432. *    TRACKER INTERRUPT ROUTINES
  1433. *
  1434. ***********************************************************    
  1435. Tracker
  1436.     lea    MB(pc),a3
  1437.     tst.b    mt_on-MB(a3)
  1438.     beq.s    mt_i
  1439.     movem.l    a4-a6,-(sp)
  1440.     bsr.s    mt_music
  1441.     lea    MB(pc),a3
  1442.     tst.b    sorpend-MB(a3)
  1443.     beq.s    .nof
  1444.     clr.w    $dff0a8
  1445.     clr.w    $dff0b8
  1446.     clr.w    $dff0c8
  1447.     clr.w    $dff0d8
  1448.     move.w    #$f,$dff096
  1449.     clr.b    mt_on-MB(a3)
  1450. .nof    movem.l    (sp)+,a4-a6
  1451. mt_i    rts
  1452.  
  1453. mt_music:
  1454.     lea    (a3),a6
  1455.  
  1456.     move.l    mt_data-MB(a6),a0
  1457.     addq.b    #1,mt_counter-MB(a6)
  1458.     move.b    mt_counter-MB(a6),d0
  1459.     cmp.b    mt_speed-MB(a6),d0
  1460.     blt    mt_nonew
  1461.     clr.b    mt_counter-MB(a6)
  1462.  
  1463.     move.l    mt_data-MB(a6),a0
  1464.     lea    $c(a0),a3
  1465.     lea    $3b8(a0),a2
  1466.     lea    $43c(a0),a0
  1467.  
  1468.     moveq    #0,d0
  1469.     moveq    #0,d1
  1470.     move.b    mt_songpos-MB(a6),d0
  1471.     move.b    (a2,d0.w),d1
  1472.     lsl.w    #8,d1
  1473.     lsl.w    #2,d1
  1474.     add.w    mt_pattpos-MB(a6),d1
  1475.     clr.w    mt_dmacon-MB(a6)
  1476.  
  1477.     lea    $dff0a0,a5
  1478.     lea    mt_voice1-MB(a6),a4
  1479.     moveq    #0,d6
  1480.     bsr    mt_playvoice
  1481.     addq.l    #4,d1
  1482.     lea    $dff0b0,a5
  1483.     lea    mt_voice2-MB(a6),a4
  1484.     moveq    #1,d6
  1485.     bsr    mt_playvoice
  1486.     addq.l    #4,d1
  1487.     lea    $dff0c0,a5
  1488.     lea    mt_voice3-MB(a6),a4
  1489.     moveq    #2,d6
  1490.     bsr    mt_playvoice
  1491.     addq.l    #4,d1
  1492.     lea    $dff0d0,a5
  1493.     lea    mt_voice4-MB(a6),a4
  1494.     moveq    #3,d6
  1495.     bsr    mt_playvoice
  1496.  
  1497.     bsr    mt_wait
  1498.     move.w    mt_dmacon-MB(a6),d0
  1499.     or.w    #$8000,d0
  1500.     move.w    d0,$dff096
  1501.     bsr    mt_wait
  1502. mt_nodma:
  1503.     lea    mt_voice1-MB(a6),a4
  1504.     move.l    $a(a4),$a0+$dff000
  1505.     move.w    $e(a4),$a4+$dff000
  1506.     tst.w    30(a4)
  1507.     bne.s    mt_nov1
  1508.     move.w    $12(a4),$a8+$dff000
  1509. mt_nov1:lea    mt_voice2-MB(a6),a4
  1510.     move.l    $a(a4),$b0+$dff000
  1511.     move.w    $e(a4),$b4+$dff000
  1512.     tst.w    30(a4)
  1513.     bne.s    mt_nov2
  1514.     move.w    $12(a4),$b8+$dff000
  1515. mt_nov2:lea    mt_voice3-MB(a6),a4
  1516.     move.l    $a(a4),$c0+$dff000
  1517.     move.w    $e(a4),$c4+$dff000
  1518.     tst.w    30(a4)
  1519.     bne.s    mt_nov3
  1520.     move.w    $12(a4),$c8+$dff000
  1521. mt_nov3:lea    mt_voice4-MB(a6),a4
  1522.     move.l    $a(a4),$d0+$dff000
  1523.     tst.w    30(a4)
  1524.     bne.s    mt_nov4
  1525.     move.w    $e(a4),$d4+$dff000
  1526.     move.w    $12(a4),$d8+$dff000
  1527.  
  1528. mt_nov4:add.w    #$10,mt_pattpos-MB(a6)
  1529.     cmp.w    #$400,mt_pattpos-MB(a6)
  1530.     bne.s    mt_exit
  1531. mt_next:clr.w    mt_pattpos-MB(a6)
  1532.     clr.b    mt_break-MB(a6)
  1533.     move.l    mt_data-MB(a6),a0
  1534.     tst.b    sorp-MB(a6)
  1535.     beq    song
  1536.     cmp.b    #1,sorploop-MB(a6)
  1537.     beq    rep
  1538.     move.b    #1,sorpend-MB(a6)
  1539. rep    rts
  1540.  
  1541. song    clr.w    mt_pattpos-MB(a6)
  1542.     addq.b    #1,mt_songpos-MB(a6)
  1543.     and.b    #$7f,mt_songpos-MB(a6)
  1544.     move.b    $3b6(a0),d0
  1545.     cmp.b    mt_songpos-MB(a6),d0
  1546.     bne.s    mt_exit
  1547.     tst.b    sorploop-MB(a6)
  1548.     bne    srep
  1549.     move.b    #1,sorpend-MB(a6)
  1550.     rts
  1551.  
  1552. srep    move.b    omt_songpos-MB(a6),mt_songpos-MB(a6)
  1553. mt_exit:tst.b    mt_break-MB(a6)
  1554.     bne.s    mt_next
  1555.     bra    mt_amhandler
  1556.  
  1557. mt_wait:moveq    #4,d3        
  1558. mt_wai2:move.b    $dff006,d2    
  1559. mt_wai3:cmp.b    $dff006,d2    
  1560.     beq.s    mt_wai3
  1561.     dbf    d3,mt_wai2    
  1562.     moveq    #8,d2
  1563. mt_wai4:dbf    d2,mt_wai4
  1564.  
  1565. mt_nonew:
  1566.     lea    mt_voice1-MB(a6),a4
  1567.     lea    $dff0a0,a5
  1568.     bsr    mt_com
  1569.     lea    mt_voice2-MB(a6),a4
  1570.     lea    $dff0b0,a5
  1571.     bsr    mt_com
  1572.     lea    mt_voice3-MB(a6),a4
  1573.     lea    $dff0c0,a5
  1574.     bsr    mt_com
  1575.     lea    mt_voice4-MB(a6),a4
  1576.     lea    $dff0d0,a5
  1577.     bsr    mt_com
  1578.     bra.s    mt_exit
  1579.  
  1580.  
  1581. mt_playvoice:
  1582.     move.l    (a0,d1.l),(a4)
  1583.     moveq    #0,d2
  1584.     move.b    2(a4),d2
  1585.     lsr.b    #4,d2
  1586.     move.b    (a4),d0
  1587.     and.b    #$f0,d0
  1588.     or.b    d0,d2
  1589.     beq    mt_oldinstr
  1590.  
  1591.     lea    mt_samplestarts-4-MB(a6),a1
  1592.     move.w    d2,34(a4)
  1593.     move.w    d2,d0
  1594.     mulu    #120,d0
  1595.     add.l    mt_data2-MB(a6),d0
  1596.     move.l    a0,-(sp)
  1597.     move.l    d0,a0
  1598.     clr.w    30(a4)
  1599.     cmp.w    #"AM",(a0)
  1600.     bne.s    mt_noa9
  1601.     move.w    6(a0),d0
  1602.     lsr.w    #2,d0
  1603.     st    30(a4)
  1604. mt_noa9:move.l    (sp)+,a0
  1605.  
  1606.     asl.w    #2,d2
  1607.     move.l    (a1,d2.l),4(a4)
  1608.     lsr.w    #2,d2
  1609.     mulu    #30,d2
  1610.     move.w    (a3,d2.w),8(a4)
  1611.     tst.w    30(a4)
  1612.     beq.s    mt_noa8
  1613.     move.w    d0,$12(a4)
  1614.     bra.s    mt_noa7
  1615. mt_noa8:move.w    2(a3,d2.w),$12(a4)
  1616. mt_noa7:moveq    #0,d3
  1617.     move.w    4(a3,d2.w),d3
  1618.     tst.w    d3
  1619.     beq.s    mt_noloop
  1620.     move.l    4(a4),d0
  1621.     asl.w    #1,d3
  1622.     add.l    d3,d0
  1623.     move.l    d0,$a(a4)
  1624.     move.w    4(a3,d2.w),d0
  1625.     add.w    6(a3,d2.w),d0
  1626.     move.w    d0,8(a4)
  1627.     bra.s    mt_hejaSverige
  1628. mt_noloop:
  1629.     move.l    4(a4),d0
  1630.     add.l    d3,d0
  1631.     move.l    d0,$a(a4)
  1632. mt_hejaSverige:
  1633.     move.w    6(a3,d2.w),$e(a4)
  1634.  
  1635. mt_oldinstr:
  1636.     move.w    (a4),d0
  1637.     and.w    #$fff,d0
  1638.     beq    mt_com2
  1639.     tst.w    30(a4)
  1640.     bne.s    mt_rambo
  1641.     tst.w    8(a4)
  1642.     beq    mt_stopsound
  1643.     tst.b    $12(a4)
  1644.     bne    mt_stopsound
  1645.     move.b    2(a4),d0
  1646.     and.b    #$f,d0
  1647.     cmp.b    #5,d0
  1648.     beq    mt_setport
  1649.     cmp.b    #3,d0
  1650.     beq    mt_setport
  1651.  
  1652. mt_rambo:
  1653.     move.w    (a4),$10(a4)
  1654.     and.w    #$fff,$10(a4)
  1655.     move.w    $1a(a4),$dff096
  1656.     clr.b    $19(a4)
  1657.  
  1658.     tst.w    30(a4)
  1659.     beq.s    mt_noaminst
  1660.     move.l    a0,-(sp)
  1661.     move.w    34(a4),d0
  1662.     mulu    #120,d0
  1663.     add.l    mt_data2-MB(a6),d0
  1664.     move.l    d0,a0
  1665.     moveq    #0,d0
  1666.     move.w    26(a0),d0
  1667.     lsl.w    #5,d0
  1668.     
  1669.     move.l    a0,-(sp)
  1670.     move.l    mt_amwave-MB(a6),a0
  1671.     add.l    a0,d0    
  1672.     move.l    (sp)+,a0
  1673.  
  1674.     move.l    d0,(a5)
  1675.     move.w    #16,4(a5)
  1676.     move.l    d0,$a(a4)
  1677.     move.w    #16,$e(a4)
  1678.     move.w    6(a0),32(a4)
  1679.     move.l    #1,36(a4)
  1680.     move.w    34(a0),d0
  1681.     move.w    d1,-(sp)
  1682.     move.w    $10(a4),d1
  1683.     lsl.w    d0,d1
  1684.     move.w    d1,$10(a4)
  1685.     move.w    d1,6(a5)
  1686.     move.w    (sp)+,d1
  1687.     move.l    (sp)+,a0
  1688.     bra.s    mt_juck
  1689.  
  1690. mt_noaminst:
  1691.     move.l    4(a4),(a5)
  1692.     move.w    8(a4),4(a5)
  1693.     move.w    $10(a4),6(a5)
  1694.  
  1695. mt_juck:
  1696.     move.b    $13(a4),MuVu-MB(a6,d6.w)    * Vu-metres...
  1697.     move.w    $1a(a4),d0
  1698.     or.w    d0,mt_dmacon-MB(a6)
  1699.     bra    mt_com2
  1700.  
  1701. mt_stopsound:
  1702.     move.w    $1a(a4),$dff096
  1703.     bra    mt_com2
  1704.  
  1705. mt_setport:
  1706.     move.w    (a4),d2
  1707.     and.w    #$fff,d2
  1708.     move.w    d2,$16(a4)
  1709.     move.w    $10(a4),d0
  1710.     clr.b    $14(a4)
  1711.     cmp.w    d0,d2
  1712.     beq.s    mt_clrport
  1713.     bge    mt_com2
  1714.     move.b    #1,$14(a4)
  1715.     bra    mt_com2
  1716. mt_clrport:
  1717.     clr.w    $16(a4)
  1718.     rts
  1719.  
  1720. mt_port:move.b    3(a4),d0
  1721.     beq.s    mt_port2
  1722.     move.b    d0,$15(a4)
  1723.     clr.b    3(a4)
  1724. mt_port2:
  1725.     tst.w    $16(a4)
  1726.     beq.s    mt_rts
  1727.     moveq    #0,d0
  1728.     move.b    $15(a4),d0
  1729.     tst.b    $14(a4)
  1730.     bne.s    mt_sub
  1731.     add.w    d0,$10(a4)
  1732.     move.w    $16(a4),d0
  1733.     cmp.w    $10(a4),d0
  1734.     bgt.s    mt_portok
  1735.     move.w    $16(a4),$10(a4)
  1736.     clr.w    $16(a4)
  1737. mt_portok:
  1738.     move.w    $10(a4),6(a5)
  1739. mt_rts:    rts
  1740.  
  1741. mt_sub:    sub.w    d0,$10(a4)
  1742.     move.w    $16(a4),d0
  1743.     cmp.w    $10(a4),d0
  1744.     blt.s    mt_portok
  1745.     move.w    $16(a4),$10(a4)
  1746.     clr.w    $16(a4)
  1747.     move.w    $10(a4),6(a5)
  1748.     rts
  1749.  
  1750.  
  1751. mt_vib:    move.b    $3(a4),d0
  1752.     beq.s    mt_vib2
  1753.     move.b    d0,$18(a4)
  1754.  
  1755. mt_vib2:move.b    $19(a4),d0
  1756.     lsr.w    #2,d0
  1757.     and.w    #$1f,d0
  1758.     moveq    #0,d2
  1759.  
  1760.     move.l    a0,-(sp)
  1761.     lea    mt_sin-MB(a6),a0
  1762.     move.b    (a0,d0.w),d2
  1763.     move.l    (sp)+,a0
  1764.  
  1765.     move.b    $18(a4),d0
  1766.     and.w    #$f,d0
  1767.     mulu    d0,d2
  1768.     lsr.w    #7,d2
  1769.     move.w    $10(a4),d0
  1770.     tst.b    $19(a4)
  1771.     bmi.s    mt_vibsub
  1772.     add.w    d2,d0
  1773.     bra.s    mt_vib3
  1774. mt_vibsub:
  1775.     sub.w    d2,d0
  1776. mt_vib3:move.w    d0,6(a5)
  1777.     move.b    $18(a4),d0
  1778.     lsr.w    #2,d0
  1779.     and.w    #$3c,d0
  1780.     add.b    d0,$19(a4)
  1781.     rts
  1782.  
  1783.  
  1784. mt_arp:    moveq    #0,d0
  1785.     move.b    mt_counter-MB(a6),d0
  1786.  
  1787.     move.l    a0,-(sp)
  1788.     lea    mt_arplist-MB(a6),a0
  1789.     move.b    (a0,d0.w),d0
  1790.     move.l    (sp)+,a0
  1791.     tst.b    d0
  1792.  
  1793.     beq.s    mt_arp0
  1794.     cmp.b    #2,d0
  1795.     beq.s    mt_arp2
  1796. mt_arp1:moveq    #0,d0
  1797.     move.b    3(a4),d0
  1798.     lsr.b    #4,d0
  1799.     bra.s    mt_arpdo
  1800. mt_arp2:moveq    #0,d0
  1801.     move.b    3(a4),d0
  1802.     and.b    #$f,d0
  1803. mt_arpdo:
  1804.     asl.w    #1,d0
  1805.     move.w    $10(a4),d1
  1806.     and.w    #$fff,d1
  1807.     lea    mt_periods-MB(a6),a0
  1808.     moveq    #$24,d2
  1809. mt_arp3:cmp.w    (a0)+,d1
  1810.     bge.s    mt_arpfound
  1811.     dbf    d2,mt_arp3
  1812. mt_arp0:move.w    $10(a4),6(a5)
  1813.     rts
  1814. mt_arpfound:
  1815.     move.w    -2(a0,d0.w),6(a5)
  1816.     rts
  1817.  
  1818. mt_normper:
  1819.     move.w    $10(a4),6(a5)
  1820.     rts
  1821.  
  1822. mt_com:    move.w    2(a4),d0
  1823.     and.w    #$fff,d0
  1824.     beq.s    mt_normper
  1825.     move.b    2(a4),d0
  1826.     and.b    #$f,d0
  1827.     tst.b    d0
  1828.     beq.s    mt_arp
  1829.     cmp.b    #1,d0
  1830.     beq.s    mt_portup
  1831.     cmp.b    #2,d0
  1832.     beq.s    mt_portdown
  1833.     cmp.b    #3,d0
  1834.     beq    mt_port
  1835.     cmp.b    #4,d0
  1836.     beq    mt_vib
  1837.     cmp.b    #5,d0
  1838.     beq.s    mt_volport
  1839.     cmp.b    #6,d0
  1840.     beq.s    mt_volvib
  1841.     move.w    $10(a4),6(a5)
  1842.     cmp.b    #$a,d0
  1843.     beq.s    mt_volslide
  1844.     rts
  1845.  
  1846. mt_portup:
  1847.     moveq    #0,d0
  1848.     move.b    3(a4),d0
  1849.     sub.w    d0,$10(a4)
  1850.     move.w    $10(a4),d0
  1851.     cmp.w    #$71,d0
  1852.     bpl.s    mt_portup2
  1853.     move.w    #$71,$10(a4)
  1854. mt_portup2:
  1855.     move.w    $10(a4),6(a5)
  1856.     rts
  1857.  
  1858. mt_portdown:
  1859.     moveq    #0,d0
  1860.     move.b    3(a4),d0
  1861.     add.w    d0,$10(a4)
  1862.     move.w    $10(a4),d0
  1863.     cmp.w    #$358,d0
  1864.     bmi.s    mt_portdown2
  1865.     move.w    #$358,$10(a4)
  1866. mt_portdown2:
  1867.     move.w    $10(a4),6(a5)
  1868.     rts
  1869.  
  1870. mt_volvib:
  1871.      bsr    mt_vib2
  1872.      bra.s    mt_volslide
  1873. mt_volport:
  1874.      bsr    mt_port2
  1875.  
  1876. mt_volslide:
  1877.     moveq    #0,d0
  1878.     move.b    3(a4),d0
  1879.     lsr.b    #4,d0
  1880.     beq.s    mt_vol3
  1881.     add.b    d0,$13(a4)
  1882.     cmp.b    #$40,$13(a4)
  1883.     bmi.s    mt_vol2
  1884.     move.b    #$40,$13(a4)
  1885. mt_vol2:moveq    #0,d0
  1886.     move.b    $13(a4),d0
  1887.     move.w    d0,8(a5)
  1888.     rts
  1889.  
  1890. mt_vol3:move.b    3(a4),d0
  1891.     and.b    #$f,d0
  1892.     sub.b    d0,$13(a4)
  1893.     bpl.s    mt_vol4
  1894.     clr.b    $13(a4)
  1895. mt_vol4:moveq    #0,d0
  1896.     move.b    $13(a4),d0
  1897.     move.w    d0,8(a5)
  1898.     rts
  1899.  
  1900. mt_com2:move.b    $2(a4),d0
  1901.     and.b    #$f,d0
  1902.     cmp.b    #$e,d0
  1903.     beq.s    mt_filter
  1904.     cmp.b    #$d,d0
  1905.     beq.s    mt_pattbreak
  1906.     cmp.b    #$b,d0
  1907.     beq.s    mt_songjmp
  1908.     cmp.b    #$c,d0
  1909.     beq.s    mt_setvol
  1910.     cmp.b    #$f,d0
  1911.     beq.s    mt_setspeed
  1912.     rts
  1913.  
  1914. mt_filter:
  1915.     move.b    3(a4),d0
  1916.     and.b    #1,d0
  1917.     asl.b    #1,d0
  1918.     and.b    #$fd,$bfe001
  1919.     or.b    d0,$bfe001
  1920.     rts
  1921.  
  1922. mt_pattbreak:
  1923.     move.b    #1,mt_break-Mb(a6)
  1924.     rts
  1925.  
  1926. mt_songjmp:
  1927.     move.b    #1,mt_break-MB(a6)
  1928.     move.b    3(a4),d0
  1929.     subq.b    #1,d0
  1930.     move.b    d0,mt_songpos-MB(a6)
  1931.     rts
  1932.  
  1933. mt_setvol:
  1934.     cmp.b    #$40,3(a4)
  1935.     bls.s    mt_sv2
  1936.     move.b    #$40,3(a4)
  1937. mt_sv2:    moveq    #0,d0
  1938.     move.b    3(a4),d0
  1939.     move.b    d0,$13(a4)
  1940.  
  1941.     sub.b    #$20,d0
  1942.     bpl    mt_sv22
  1943.     moveq    #0,d0
  1944. mt_sv22
  1945.     move.w    d0,8(a5)
  1946.     rts
  1947.  
  1948. mt_setspeed:
  1949.     moveq    #0,d0
  1950.     move.b    3(a4),d0
  1951.     cmp.b    #$1f,d0
  1952.     bls.s    mt_sp2
  1953.     moveq    #$1f,d0
  1954. mt_sp2:    tst.w    d0
  1955.     bne.s    mt_sp3
  1956.     moveq    #1,d0
  1957. mt_sp3:    move.b    d0,mt_speed-MB(a6)
  1958.     rts
  1959.  
  1960. mt_amhandler:
  1961.     moveq    #3,d7
  1962.  
  1963.     move.l    a4,-(sp)
  1964.     lea    mt_voice1-MB(a6),a4
  1965.     lea    $dff0a0,a5        aud0lch
  1966. mt_amloop:
  1967.     tst.w    30(a4)
  1968.     beq    mt_anrp
  1969.     move.w    34(a4),d0
  1970.     mulu    #120,d0
  1971.     add.l    mt_data2-MB(a6),d0
  1972.     move.l    d0,a0
  1973.     tst.w    38(a4)
  1974.     beq    mt_anrp
  1975.     cmp.w    #1,38(a4)
  1976.     bne.s    mt_anat
  1977.     move.w    32(a4),d0
  1978.     cmp.w    8(a0),d0
  1979.     beq.s    mt_aaeq
  1980.     cmp.w    8(a0),d0
  1981.     blt.s    mt_aaad
  1982.     move.w    10(a0),d0
  1983.     sub.w    d0,32(a4)
  1984.     move.w    32(a4),d0
  1985.     cmp.w    8(a0),d0
  1986.     bgt    mt_anxt
  1987.     move.w    8(a0),32(a4)
  1988. mt_aaeq:move.w    #2,38(a4)
  1989.     bra    mt_anxt
  1990. mt_aaad:move.w    10(a0),d0
  1991.     add.w    d0,32(a4)
  1992.     move.w    32(a4),d0
  1993.     cmp.w    8(a0),d0
  1994.     blt    mt_anxt
  1995.     move.w    8(a0),32(a4)
  1996.     bra.s    mt_aaeq
  1997. mt_anat:cmp.w    #2,38(a4)
  1998.     bne.s    mt_ana2
  1999.     move.w    32(a4),d0
  2000.     cmp.w    12(a0),d0
  2001.     beq.s    mt_a2eq
  2002.     cmp.w    12(a0),d0
  2003.     blt.s    mt_a2ad
  2004.     move.w    14(a0),d0
  2005.     sub.w    d0,32(a4)
  2006.     move.w    32(a4),d0
  2007.     cmp.w    12(a0),d0
  2008.     bgt    mt_anxt
  2009.     move.w    12(a0),32(a4)
  2010. mt_a2eq:move.w    #3,38(a4)
  2011.     bra    mt_anxt
  2012. mt_a2ad:move.w    14(a0),d0
  2013.     add.w    d0,32(a4)
  2014.     move.w    32(a4),d0
  2015.     cmp.w    12(a0),d0
  2016.     blt    mt_anxt
  2017.     move.w    12(a0),32(a4)
  2018.     bra.s    mt_a2eq
  2019. mt_ana2:cmp.w    #3,38(a4)
  2020.     bne.s    mt_andc
  2021.     move.w    32(a4),d0
  2022.     cmp.w    16(a0),d0
  2023.     beq.s    mt_adeq
  2024.     cmp.w    16(a0),d0
  2025.     blt.s    mt_adad
  2026.     move.w    18(a0),d0
  2027.     sub.w    d0,32(a4)
  2028.     move.w    32(a4),d0
  2029.     cmp.w    16(a0),d0
  2030.     bgt.s    mt_anxt
  2031.     move.w    16(a0),32(a4)
  2032. mt_adeq:move.w    #4,38(a4)
  2033.     move.w    20(a0),40(a4)
  2034.     bra.s    mt_anxt
  2035. mt_adad:move.w    18(a0),d0
  2036.     add.w    d0,32(a4)
  2037.     move.w    32(a4),d0
  2038.     cmp.w    16(a0),d0
  2039.     blt.s    mt_anxt
  2040.     move.w    16(a0),32(a4)
  2041.     bra.s    mt_adeq
  2042. mt_andc:cmp.w    #4,38(a4)
  2043.     bne.s    mt_anst
  2044.     subq.w    #1,40(a4)
  2045.     bpl.s    mt_anxt
  2046.     move.w    #5,38(a4)
  2047.     bra.s    mt_anxt
  2048. mt_anst:move.w    24(a0),d0
  2049.     sub.w    d0,32(a4)
  2050.     bpl.s    mt_anxt
  2051.     clr.l    30(a4)
  2052.     clr.w    38(a4)
  2053.     move.w    26(a4),$dff096        dmaconw
  2054. mt_anxt:move.w    32(a4),d0
  2055.     lsr.w    #2,d0
  2056.     move.w    d0,8(a5)
  2057.     move.w    28(a0),d0
  2058.     add.w    d0,16(a4)
  2059.     move.w    30(a0),d1
  2060.     beq.s    mt_nvib
  2061.     move.w    36(a4),d2
  2062.     moveq    #0,d3
  2063.     cmp.w    #360,d2
  2064.     blt.s    mt_vibq
  2065.     sub.w    #360,d2
  2066.     moveq    #1,d3
  2067. mt_vibq:move.l    mt_ams-MB(a6),a2
  2068.     muls    (a2,d2.w),d1
  2069.     asr.w    #7,d1
  2070.     tst.w    d3
  2071.     beq.s    mt_nvib
  2072.     neg.w    d1
  2073. mt_nvib:add.w    16(a4),d1
  2074.     move.w    d1,6(a5)
  2075.     move.w    32(a0),d0
  2076.     add.w    d0,d0
  2077.     add.w    d0,36(a4)
  2078.     cmp.w    #720,36(a4)
  2079.     blt.s    mt_anrp
  2080.     sub.w    #720,36(a4)
  2081. mt_anrp:lea    $10(a5),a5
  2082.     lea    42(a4),a4
  2083.     dbra    d7,mt_amloop
  2084.     move.l    mt_noise-MB(a6),a0
  2085.     move.w    #$7327,d0
  2086.     moveq    #31,d1
  2087. mt_nlop:move.b    d0,(a0)+
  2088.     add.b    $dff007,d0
  2089.     eor.w    #124,d0
  2090.     rol.w    #3,d0
  2091.     dbra    d1,mt_nlop
  2092.     move.l    (sp)+,a4
  2093.     rts
  2094.  
  2095. ; Now follows a big chunk of data. Better disable the RBsr system...
  2096.  
  2097.     RDATA
  2098.  
  2099. *********************************************************************
  2100. *        MUSIC extension data zone
  2101. MB:    
  2102. MuVu        dc.l    0        * Vu Meters
  2103. MuBase        dc.l    0        * Curretn music address
  2104. MusAdr        dc.l    0        * Branch table address
  2105. MusClock    dc.l     3546895        * Clock speed
  2106. WaveBase    dc.l    0        * Wave tree
  2107. Waves        dc.w     0,0,0,0
  2108. EnvOn:        dc.w     0        * ADSR running?
  2109. EnvBase:    ds.b    EnvLong*4    * ADSR table
  2110. SamBank:    dc.w     0        * Sample bank
  2111. BSeed:        dc.w     0        * Random seed
  2112. Noise:        dc.w    0        * Noise on?
  2113. PNoise:        dc.w    0        * Pointer to noise buffer
  2114. TempoBase:    dc.w    0        * 100 (PAL) - 120 (NTSC)
  2115. *         Musique
  2116. MusBank        dc.l     0        * Music bank
  2117. MusCheck    dc.l    0        * Check sum
  2118. BankInst    dc.l    0        * Instruments
  2119. BankSong    dc.l    0        * Songs
  2120. BankPat        dc.l     0        * Patterns
  2121. MuNumber    dc.w    0        * Music priority
  2122. MuVolume    dc.w    0        * Music volume
  2123. MuDMAsk        dc.w    0        * Voice mask
  2124. MuReStart    dc.w    0        * Restart the voice
  2125. MuChip0        dc.l    0        * Circuits 0
  2126. MuChip1        dc.l     0        *       1
  2127. MuChip2        dc.l     0        *          2
  2128. MuChip3        dc.l     0        *          3
  2129. FoEnd        dc.w    $8000        * Fake empty pattern
  2130. MuBuffer    ds.b    MuLong*3    * Music tables
  2131.  
  2132. *************** Tables for effects
  2133. Sinus    
  2134.  dc.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
  2135.  dc.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18
  2136.  
  2137. Periods    
  2138.  dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
  2139.  dc.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
  2140.  dc.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
  2141.  dc.w $007f,$0078,$0071,$0000,$0000
  2142.  
  2143. *************** Default enveloppes
  2144. EnvDef:        dc.w 1,64,4,55,5,50,25,0,0,0
  2145. EnvShoot    dc.w 1,64,10,0,0,0
  2146. EnvBoom        dc.w 1,64,10,50,50,0,0,0
  2147. EnvBell        dc.w 1,64,4,40,25,0,0,0
  2148.  
  2149. *************** Bank headers
  2150. BkMus:        dc.b "Music   "
  2151.  
  2152. *************** Frequency / notes
  2153. TFreq:    dc.w 000,256/2
  2154.     dc.w 000,256/2
  2155.     dc.w 256,128/2
  2156.     dc.w 384,64/2
  2157.     dc.w 448,32/2
  2158.     dc.w 480,16/2
  2159.     dc.w 496,8/2
  2160.     dc.w 504,4/2
  2161.     dc.w 504,4/2
  2162. TNotes:    dc.w 00,00,00,33,35,37,39,41,44,46,49,52
  2163.     dc.w 55,58,62,65,69,73,78,82,87,92,98,104
  2164.     dc.w 110,117,123,131,139,147,156,165,175,185,196,208
  2165.     dc.w 220,233,247,262,277,294,311,330,349,370,392,415
  2166.     dc.w 440,466,494,523,554,587,622,659,698,740,784,830
  2167.     dc.w 880,932,988,1046,1109,1175,1245,1319,1397,1480,1568,1661
  2168.     dc.w 1760,1865,1986,2093,2217,2349,2489,2637,2794,2960,3136,3322
  2169.     dc.w 3520,3729,3952,4186,4435,4699,4978,5274,5588,5920,6272,6645
  2170.     dc.w 7040,7459,7902,8372
  2171.  
  2172. *************** SAMPLE PLAYER INTERRUPT STRUCTURES
  2173. Sami_lplay    equ    1024*4
  2174. Sami_bit    equ    22
  2175. Sami_dma    equ    24
  2176. Sami_reg    equ    26
  2177. Sami_adr    equ    28
  2178. Sami_long    equ    32
  2179. Sami_pos    equ    36
  2180. Sami_rpos    equ    40
  2181. Sami_radr    equ    44
  2182. Sami_rlong    equ    48
  2183. Sami_dvol    equ    52
  2184. Sami_old    equ    54
  2185. Sami_intl    equ    58
  2186.  
  2187. Sami_int    ds.b    22                * Channel 0
  2188.         dc.w    %0000000010000000    bit
  2189.         dc.w    0            dma
  2190.         dc.w    $a0            reg
  2191.         dc.l    0            adr
  2192.         dc.l    0            long
  2193.         dc.l    0            pos
  2194.         dc.l    0            rpos
  2195.         dc.l    0            radr
  2196.         dc.l    0            rlong
  2197.         dc.w    0            dvol
  2198.         dc.l    0            old            
  2199.  
  2200.         ds.b    22                * Channel 1
  2201.         dc.w    %0000000100000000    bit
  2202.         dc.w    1            dma
  2203.         dc.w    $b0            reg
  2204.         dc.l    0            adr
  2205.         dc.l    0            long
  2206.         dc.l    0            pos
  2207.         dc.l    0            rpos
  2208.         dc.l    0            radr
  2209.         dc.l    0            rlong
  2210.         dc.w    0            dvol
  2211.         dc.l    0            old            
  2212.  
  2213.         ds.b    22                * Channel 2
  2214.         dc.w    %0000001000000000    bit
  2215.         dc.w    2            dma
  2216.         dc.w    $c0            reg
  2217.         dc.l    0            adr
  2218.         dc.l    0            long
  2219.         dc.l    0            pos
  2220.         dc.l    0            rpos
  2221.         dc.l    0            radr
  2222.         dc.l    0            rlong
  2223.         dc.w    0            dvol
  2224.         dc.l    0            old            
  2225.  
  2226.         ds.b    22                * Channel 3
  2227.         dc.w    %0000010000000000    bit
  2228.         dc.w    3            dma
  2229.         dc.w    $d0            reg
  2230.         dc.l    0            adr
  2231.         dc.l    0            long
  2232.         dc.l    0            pos
  2233.         dc.l    0            rpos
  2234.         dc.l    0            radr
  2235.         dc.l    0            rlong
  2236.         dc.w    0            dvol
  2237.         dc.l    0            old            
  2238.  
  2239. Sami_OldEna    dc.w    0
  2240. Sami_empty    dc.l    0
  2241. Sami_bits    dc.w    0
  2242. Sami_handad    dc.l    0
  2243. Sami_flag    dc.w    0
  2244. SamLoops    dc.w    0
  2245. *************** NARRATOR
  2246. Amaps:        dc.b    3,5,10,12
  2247. TranBase    dc.l    0
  2248. TalkIO:        ds.l    20
  2249. WriteRep:    ds.l    8
  2250. TranName    dc.b    "translator.library",0
  2251. NarDevice    dc.b    "narrator.device",0
  2252.  
  2253. *************** Welcome message
  2254. MusWel:        dc.b     27,"Y8Music player V 1.3",0
  2255.         even
  2256.  
  2257. *********************************************************************
  2258. *    mt TRACKER data zone
  2259.  
  2260. Track_Bank    dc.w    6        Bank number 6= tracker
  2261. sorpend        dc.b    0        turn music off if 1        
  2262. sorploop    dc.b    0        0=once:1=loop 
  2263. sorp        dc.b    0        0=song:1=patt
  2264. omt_songpos    dc.b    0
  2265.  
  2266. mt_amwave    dc.l    0        address of wave forms
  2267. mt_noise    dc.l    0        address of wave forms
  2268. mt_ams        dc.l    0        address of wave forms
  2269.     even
  2270. mt_mulu:
  2271.     dc.w    0,$1e,$3c,$5a,$78,$96,$b4,$d2,$f0,$10e,$12c,$14a
  2272.     dc.w    $168,$186,$1a4,$1c2,$1e0,$1fe,$21c,$23a,$258,$276
  2273.     dc.w    $294,$2b2,$2d0,$2ee,$30c,$32a,$348,$366,$384,$3a2
  2274.  
  2275. mt_sin:    dc.b    0,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4
  2276.     dc.b    $fa,$fd
  2277.     dc.b    $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61
  2278.     dc.b    $4a,$31,$18
  2279.  
  2280. mt_arplist:
  2281.     dc.b    0,1,2,0,1,2,0,1,2,0,1,2,0
  2282.     dc.b    1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1
  2283.  
  2284. mt_amwaveforms:
  2285.     dc.b    0,25,49,71,90,106,117,125
  2286.     dc.b    127,125,117,106,90,71,49,25
  2287.     dc.b    0,-25,-49,-71,-90,-106,-117
  2288.     dc.b    -125,-127,-125,-117,-106
  2289.     dc.b    -90,-71,-49,-25
  2290.     dc.b    -128,-120,-112,-104,-96,-88,-80,-72,-64,-56,-48
  2291.     dc.b    -40,-32,-24,-16,-8,0,8,16,24,32,40,48,56,64,72,80
  2292.     dc.b    88,96,104,112,120
  2293.     dc.b    -128
  2294.     dc.b    -128
  2295.     dc.b    -128
  2296.     dc.b    -128
  2297.     dc.b    -128
  2298.     dc.b    -128
  2299.     dc.b    -128
  2300.     dc.b    -128
  2301.     dc.b    -128
  2302.     dc.b    -128
  2303.     dc.b    -128
  2304.     dc.b    -128
  2305.     dc.b    -128
  2306.     dc.b    -128
  2307.     dc.b    -128
  2308.     dc.b    -128
  2309.     
  2310.     
  2311.     dc.b    127
  2312.     dc.b    127
  2313.     dc.b    127
  2314.     dc.b    127
  2315.     dc.b    127
  2316.     dc.b    127
  2317.     dc.b    127
  2318.     dc.b    127
  2319.     dc.b    127
  2320.     dc.b    127
  2321.     dc.b    127
  2322.     dc.b    127
  2323.     dc.b    127
  2324.     dc.b    127
  2325.     dc.b    127
  2326.     dc.b    127
  2327.     
  2328. mt_noisewave:
  2329.     dc.b    0
  2330.     dc.b    0
  2331.     dc.b    0
  2332.     dc.b    0
  2333.     dc.b    0
  2334.     dc.b    0
  2335.     dc.b    0
  2336.     dc.b    0
  2337.     dc.b    0
  2338.     dc.b    0
  2339.     dc.b    0
  2340.     dc.b    0
  2341.     dc.b    0
  2342.     dc.b    0
  2343.     dc.b    0
  2344.     dc.b    0
  2345.     dc.b    0
  2346.     dc.b    0
  2347.     dc.b    0
  2348.     dc.b    0
  2349.     dc.b    0
  2350.     dc.b    0
  2351.     dc.b    0
  2352.     dc.b    0
  2353.     dc.b    0
  2354.     dc.b    0
  2355.     dc.b    0
  2356.     dc.b    0
  2357.     dc.b    0
  2358.     dc.b    0
  2359.     dc.b    0
  2360.     dc.b    0
  2361.  
  2362. mt_amsinus:
  2363.     dc.w    0,2,4,6,8,$b,$d,$f,$11,$14,$16,$18,$1a,$1c,$1e,$21
  2364.     dc.w    $23,$25,$27,$29,$2b,$2d,$2f,$32,$34,$36,$38,$3a,$3c,$3e
  2365.     dc.w    $3f,$41,$43,$45,$47,$49,$4b,$4d,$4e,$50,$52,$53,$55,$57
  2366.     dc.w    $58,$5a,$5c,$5d,$5f,$60,$62,$63,$64,$66,$67,$68,$6a,$6b
  2367.     dc.w    $6c,$6d,$6e,$6f,$71,$72,$73,$74,$74,$75,$76,$77,$78,$79
  2368.     dc.w    $79,$7a,$7b,$7b,$7c,$7c,$7d,$7d,$7e,$7e,$7e,$7f,$7f,$7f
  2369.     dc.w    $7f,$7f,$7f,$7f,$80,$7f,$7f,$7f,$7f,$7f,$7f,$7f,$7e,$7e
  2370.     dc.w    $7e,$7d,$7d,$7c,$7c,$7b,$7b,$7a,$79,$79,$78,$77,$76,$75
  2371.     dc.w    $74,$73,$72,$71,$6f,$6e,$6d,$6c,$6b,$6a,$68,$67,$66,$64
  2372.     dc.w    $63,$62,$60,$5f,$5d,$5c,$5a,$58,$57,$55,$53,$52,$50,$4e
  2373.     dc.w    $4d,$4b,$49,$47,$45,$43,$41,$40,$3e,$3c,$3a,$38,$36,$34
  2374.     dc.w    $32,$2f,$2d,$2b,$29,$27,$25,$23,$21,$1e,$1c,$1a,$18,$16
  2375.     dc.w    $14,$11,$f,$d,$b,$8,$6,$4,$2,0
  2376.     
  2377. mt_periods:
  2378.     dc.w    $358,$328,$2fa,$2d0,$2a6,$280,$25c,$23a,$21a,$1fc,$1e0
  2379.     dc.w    $1c5,$1ac,$194,$17d,$168,$153,$140,$12e,$11d,$10d,$fe
  2380.     dc.w    $f0,$e2,$d6,$ca,$be,$b4,$aa,$a0,$97,$8f,$87
  2381.     dc.w    $7f,$78,$71,0
  2382.     
  2383.  
  2384.  
  2385. mt_speed:    dc.b    6
  2386. mt_counter:    dc.b    0
  2387. mt_pattpos:    dc.w    0
  2388. mt_songpos:    dc.b    0
  2389. mt_break:    dc.b    0
  2390. mt_dmacon:    dc.w    0
  2391. mt_samplestarts:
  2392.         dc.l    0
  2393.         dc.l    0
  2394.         dc.l    0
  2395.         dc.l    0
  2396.         dc.l    0
  2397.         dc.l    0
  2398.         dc.l    0
  2399.         dc.l    0
  2400.         dc.l    0
  2401.         dc.l    0
  2402.         dc.l    0
  2403.         dc.l    0
  2404.         dc.l    0
  2405.         dc.l    0
  2406.         dc.l    0
  2407.         dc.l    0
  2408.         dc.l    0
  2409.         dc.l    0
  2410.         dc.l    0
  2411.         dc.l    0
  2412.         dc.l    0
  2413.         dc.l    0
  2414.         dc.l    0
  2415.         dc.l    0
  2416.         dc.l    0
  2417.         dc.l    0
  2418.         dc.l    0
  2419.         dc.l    0
  2420.         dc.l    0
  2421.         dc.l    0
  2422.         dc.l    0
  2423.  
  2424.  
  2425.  
  2426. mt_voice1:
  2427.         dc.w    0
  2428.         dc.w    0
  2429.         dc.w    0
  2430.         dc.w    0
  2431.         dc.w    0
  2432.         dc.w    0
  2433.         dc.w    0
  2434.         dc.w    0
  2435.         dc.w    0
  2436.         dc.w    0
  2437.         dc.w    0
  2438.         dc.w    0
  2439.         dc.w    0
  2440.         dc.w    1
  2441.         dc.w    0
  2442.         dc.w    0
  2443.         dc.w    0
  2444.         dc.w    0
  2445.         dc.w    0
  2446.         dc.w    0
  2447.         dc.w    0
  2448. mt_voice2:
  2449.         dc.w    0
  2450.         dc.w    0
  2451.         dc.w    0
  2452.         dc.w    0
  2453.         dc.w    0
  2454.         dc.w    0
  2455.         dc.w    0
  2456.         dc.w    0
  2457.         dc.w    0
  2458.         dc.w    0
  2459.         dc.w    0
  2460.         dc.w    0
  2461.         dc.w    0
  2462.         dc.w    2
  2463.         dc.w    0
  2464.         dc.w    0
  2465.         dc.w    0
  2466.         dc.w    0
  2467.         dc.w    0
  2468.         dc.w    0
  2469.         dc.w    0
  2470. mt_voice3:
  2471.         dc.w    0
  2472.         dc.w    0
  2473.         dc.w    0
  2474.         dc.w    0
  2475.         dc.w    0
  2476.         dc.w    0
  2477.         dc.w    0
  2478.         dc.w    0
  2479.         dc.w    0
  2480.         dc.w    0
  2481.         dc.w    0
  2482.         dc.w    0
  2483.         dc.w    0
  2484.         dc.w    4
  2485.         dc.w    0
  2486.         dc.w    0
  2487.         dc.w    0
  2488.         dc.w    0
  2489.         dc.w    0
  2490.         dc.w    0
  2491.         dc.w    0
  2492. mt_voice4:    
  2493.         dc.w    0
  2494.         dc.w    0
  2495.         dc.w    0
  2496.         dc.w    0
  2497.         dc.w    0
  2498.         dc.w    0
  2499.         dc.w    0
  2500.         dc.w    0
  2501.         dc.w    0
  2502.         dc.w    0
  2503.         dc.w    0
  2504.         dc.w    0
  2505.         dc.w    0
  2506.         dc.w    8
  2507.         dc.w    0
  2508.         dc.w    0
  2509.         dc.w    0
  2510.         dc.w    0
  2511.         dc.w    0
  2512.         dc.w    0
  2513.         dc.w    0
  2514.  
  2515.  
  2516. mt_on        dc.b    0
  2517.         even
  2518.  
  2519. colour        dc.w    0
  2520.  
  2521. mt_data dc.l    0
  2522. mt_data2 dc.l    0
  2523.  
  2524.  
  2525. **********************************************************************
  2526. ; Please leave 1 or two labels free for future extension. You never
  2527. ; know!
  2528. L1
  2529.  
  2530. ; Now follow all the music routines. Some are just routines called by others,
  2531. ; some are instructions. 
  2532. ; See how a adress the internal music datazone, by using a base register
  2533. ; (usually A3) and adding the offset of the data in the datazone...
  2534.  
  2535. ; >>> How to get the parameters for the instruction?
  2536. ;
  2537. ; When an instruction or function is called, you get the parameters
  2538. ; pushed in A3. Remember that you unpile them in REVERSE order than
  2539. ; the instruction syntax.
  2540. ; As you have a entry point for each set of parameters, you know
  2541. ; how many are pushed...
  2542. ;    - INTEGER:    move.l    (a3)+,d0
  2543. ;    - STRING:    move.l    (a3)+,a0
  2544. ;            move.w    (a0)+,d0
  2545. ;        A0---> start of the string.
  2546. ;        D0---> length of the string
  2547. ;    - FLOAT:    move.l    (a3)+,d0
  2548. ;        fast floatting point format.
  2549. ;
  2550. ; IMPORTANT POINT: you MUST unpile the EXACT number of parameters,
  2551. ; to restore A3 to its original level. If you do not, you will not
  2552. ; have a immediate error, and AMOS will certainely crash on next
  2553. ; UNTIL / WEND / ENDIF / NEXT etc... 
  2554. ;
  2555. ; So, your instruction must:
  2556. ;    - Unpile the EXACT number of parameters from A3, and exit with
  2557. ;    A3 at the original level it was before collecting your parameters)
  2558. ;    - Preserve A4, A5 and A6
  2559. ; You can use D0-D7/A0-A2 freely...
  2560. ;
  2561. ; You can jump to the error routine without thinking about A3 if an error
  2562. ; occurs in your routine (via a RBra of course). BUT A4, A5 and A6 registers
  2563. ; MUST be preserved!
  2564. ;
  2565. ; You end must end by a RTS.
  2566. ;
  2567. ; >>> Functions, how to return the parameter?
  2568. ;
  2569. ; To send a function`s parameter back to AMOS, you load it in D3,
  2570. ; and put its type in D2:
  2571. ;    moveq    #0,d2    for an integer
  2572. ;    moveq    #1,d2    for a float
  2573. ;    moveq    #2,d2    for a string
  2574. ;
  2575.  
  2576. ******* Stop sound routine
  2577. L_MOff        equ    2
  2578. L2    lea    Circuits,a0
  2579.     move.w    #%0000011110000000,IntEna(a0)     * No more interrupts
  2580.     move.w    MuDMAsk-MB(a3),d0
  2581.     beq.s    MOf3
  2582.     move.w    d0,DmaCon(a0)
  2583.     moveq    #3,d1
  2584. MOf1    btst    d1,d0
  2585.     beq.s    MOf2
  2586.     move.w    #2,$a4(a0)
  2587.     clr.w    $a8(a0)
  2588. MOf2    lea    $10(a0),a0
  2589.     dbra    d1,MOf1
  2590. MOf3    rts
  2591.  
  2592. ***********************************************************
  2593. *    NARRATOR!
  2594.  
  2595. ******* Open narrator
  2596. L_OpNar        equ    3
  2597. L3    DLoad    a0
  2598.     move.l    TranBase-MB(a0),d0
  2599.     bne.s    OpNarOk
  2600.     movem.l    a3-a6,-(sp)
  2601.  
  2602.     move.l    a0,a3
  2603.     sub.l    a1,a1            * Narrator.device
  2604.     move.l    $4,a6
  2605.     jsr    FindTask(a6)
  2606.     lea    WriteRep-MB(a3),a1
  2607.     move.l    d0,$10(a1)
  2608.     jsr    AddPort(a6)
  2609.     lea    TalkIo-MB(a3),a1
  2610.     moveq    #0,d0
  2611.     moveq    #0,d1
  2612.     lea    NarDevice-MB(a3),a0
  2613.     jsr    OpenDev(a6)
  2614.     tst.l    d0
  2615.     bne    OpNarE
  2616.     Rbsr    L_NarInit
  2617.     lea    TranName-MB(a3),a1    * Translator.library
  2618.     moveq    #0,d0
  2619.     jsr    OpenLib(a6)
  2620.     move.l    d0,TranBase-MB(a3)
  2621.     beq    OpNarE
  2622. * Restore Sami interrupts
  2623.     move.l    DosBase(a5),a6
  2624.     moveq    #50,d1
  2625.     jsr    -198(a6)
  2626.     clr.w    Sami_Flag-MB(a3)
  2627.     RBsr    L_Sami_Install
  2628. * Ok!
  2629.     movem.l    (sp)+,a3-a6
  2630. OpNarOk    rts
  2631. OpNarE    movem.l    (sp)+,a3-a6
  2632. NoNar    moveq    #7,d0
  2633.     Rbra    L_Custom
  2634.  
  2635. ******* Init narrator (if here)!
  2636. L_NarInit    equ    4
  2637. L4    lea    TalkIO-MB(a3),a1
  2638.     lea    WriteRep-MB(a3),a0
  2639.     move.l    a0,14(a1)
  2640.     move.w    #150,48(a1)
  2641.     move.w    #110,50(a1)
  2642.     clr.w    52(a1)
  2643.     clr.w    54(a1)
  2644.     lea    Amaps-MB(a3),a0
  2645.     move.l    a0,56(a1)
  2646.     move.w    #4,60(a1)
  2647.     move.w    #63,62(a1)
  2648.     move.w    #22200,64(a1)
  2649.     rts
  2650.  
  2651. ******* SAY a$[,multi]
  2652. L_ISay2:    equ    5
  2653. L5    Rbsr    L_OpNar
  2654.     move.l    (a3)+,d7
  2655.     RBra    L_ISay
  2656. L_ISay1:    equ    6
  2657. L6    Rbsr    L_OpNar
  2658.     moveq    #0,d7    
  2659.     Rbra    L_ISay
  2660. L_ISay:        equ    7
  2661. L7    moveq    #%0000,d0
  2662.     Rbsr    L_StopDma
  2663.     Rbsr    L_VOnOf
  2664.     DLoad    a0
  2665.     clr.w    EnvOn-MB(a0)
  2666.     clr.w    Noise-MB(a0)
  2667.     move.l    (a3)+,a0
  2668.     moveq    #0,d0
  2669.     move.w    (a0)+,d0
  2670. * Phoneme?
  2671.     cmp.b    #"~",(a0)
  2672.     bne.s    ISayN
  2673.     addq.l    #1,a0
  2674.     move.l    Buffer(a5),a1
  2675.     move.w    d0,d1
  2676.     cmp.w    #1024,d1
  2677.     bcc    ISayN
  2678.     subq.w    #2,d1
  2679.     bmi.s    ISayN
  2680. ISayP    move.b    (a0)+,(a1)+
  2681.     dbra    d1,ISayP
  2682.     move.b    #"Q",(a1)+
  2683.     move.b    #"#",(a1)+
  2684.     move.b    #"U",(a1)+
  2685.     clr.b    (a1)+
  2686.     clr.b    (a1)+
  2687.     addq.w    #4,d0
  2688.     movem.l    a3/a6,-(sp)
  2689.     DLoad    a3
  2690.     bra.s    ISayNn
  2691. * Call TRANSLATOR
  2692. ISayN    move.l    Buffer(a5),a1
  2693.     move.l    a1,a2
  2694.     move.l    #1024,d1
  2695.     move.l    d1,d2
  2696.     lsr.w    #2,d2
  2697.     subq.w    #2,d2
  2698. ISayN1    clr.l    (a2)+
  2699.     dbra    d2,ISayN1
  2700.     movem.l    a3/a6,-(sp)
  2701.     DLoad    a3
  2702.     move.l    TranBase-MB(a3),a6
  2703.     jsr    Translate(a6)
  2704.     tst.w    d0
  2705.     bne.s    SayX
  2706.     move.l    #1024,d0
  2707. ISayNn
  2708.     Rbsr    L_Sami_remove
  2709.     lea    TalkIO-MB(a3),a1
  2710.     move.w    #3,28(a1)
  2711.     move.l    d0,36(a1)
  2712.     move.l    Buffer(a5),40(a1)
  2713.     move.l    ExecBase,a6
  2714. ;    tst.w    d7
  2715. ;    bne.s    ISayA
  2716.     jsr    DoIO(a6)
  2717. ;    bra.s    SayX
  2718. ;ISayA    jsr    SendIO(a6)
  2719. SayX    RBsr    L_Sami_install
  2720.     movem.l    (sp)+,a3/a6
  2721.     moveq    #%1111,d0
  2722.     Rbsr    L_VOnOf
  2723.     rts
  2724. ******* SET TALK sex,mode,pitch,rate
  2725. L_ITalk        equ    8
  2726. L8    Rbsr    L_OpNar
  2727.     move.l    #EntNul,d0
  2728.     Dlea    TalkIO,a1
  2729.     move.l    (a3)+,d1
  2730.     cmp.l    d0,d1
  2731.     beq.s    IRd1
  2732.     cmp.w    #40,d1
  2733.     Rbcs    L_IFonc
  2734.     cmp.w    #400,d1
  2735.     Rbhi    L_IFonc
  2736.     move.w    d1,48(a1)
  2737. IRd1    move.l    (a3)+,d1
  2738.     cmp.l    d0,d1
  2739.     beq.s    IRd2
  2740.     cmp.w    #65,d1
  2741.     Rbcs    L_IFonc
  2742.     cmp.w    #320,d1
  2743.     Rbhi    L_IFonc
  2744.     move.w    d1,50(a1)
  2745. IRd2    move.l    (a3)+,d1
  2746.     cmp.l    d0,d1
  2747.     beq.s    IRd3
  2748.     and.w    #$0001,d1
  2749.     move.w    d1,52(a1)
  2750. IRd3    move.l    (a3)+,d1
  2751.     cmp.l    d0,d1
  2752.     beq.s    IRd4
  2753.     and.w    #$0001,d1
  2754.     move.w    d1,54(a1)
  2755. IRd4    rts
  2756.  
  2757. L9
  2758. L10
  2759.  
  2760. ***********************************************************
  2761. *    MUSIC INSTRUCTION
  2762.  
  2763. *******    BELL
  2764. L_Bell0        equ    11
  2765. L11    moveq    #0,d3
  2766.     moveq    #70,d2
  2767.     moveq    #%1111,d1
  2768.     moveq    #1,d5
  2769.     Dlea    EnvBell,a0
  2770.     move.l    a0,d6
  2771.     Rbra    L_GoBel
  2772. L_Bell1        equ    12
  2773. L12    moveq    #0,d3
  2774.     move.l    (a3)+,d2
  2775.     moveq    #%1111,d1
  2776.     moveq    #1,d5
  2777.     Dlea    EnvBell,a0
  2778.     move.l    a0,d6
  2779.     Rbra    L_GoBel
  2780. ******* BOOM
  2781. L_Boom        equ    13
  2782. L13    moveq    #0,d3
  2783.     moveq    #36,d2
  2784.     moveq    #0,d5
  2785.     Dlea    EnvBoom,a0
  2786.     move.l    a0,d6
  2787.     Rbra    L_Shout
  2788. ******* SHOOT
  2789. L_Shoot        equ    14
  2790. L14    moveq    #0,d3
  2791.     moveq    #60,d2
  2792.     moveq    #0,d5
  2793.     Dlea    EnvShoot,a0
  2794.     move.l    a0,d6
  2795.     Rbra    L_Shout
  2796. * Gives a stereo effect
  2797. L_Shout:    equ    15
  2798. L15    moveq    #%0000,d0
  2799.     Rbsr    L_StopDma
  2800.     Rbsr    L_VOnOf
  2801.     moveq    #%1000,d1
  2802. Shot    movem.l    d0-d7,-(sp)
  2803.     Rbsr    L_GoShot
  2804.     movem.l    (sp)+,d0-d7
  2805.     addq.w    #1,d2
  2806.     lsr.w    #1,d1
  2807.     bcc.s    Shot
  2808.     rts
  2809.  
  2810. *******    VOLUME n
  2811. L_IVol1        equ    16
  2812. L16    move.l    (a3)+,d0
  2813.     moveq    #%1111,d1
  2814.     Rbsr    L_Vol
  2815.     Rbsr    L_MVol
  2816.     rts
  2817. ******* VOLUME voice,n
  2818. L_IVol2        equ    17
  2819. L17    move.l    (a3)+,d0
  2820.     move.l    (a3)+,d1
  2821.     Rbra    L_Vol
  2822. * Set voices volume level
  2823. L_Vol        equ    18
  2824. L18    cmp.l    #64,d0
  2825.     Rbcc    L_IFonc
  2826.     moveq    #0,d2
  2827.     Dlea    EnvBase,a0
  2828.     Dlea    Sami_int,a1
  2829. Vol1    btst    d2,d1
  2830.     beq.s    Vol2
  2831.     move.w    d0,EnvDVol(a0)
  2832.     tst.w    Sami_dvol(a1)
  2833.     bmi.s    Vol2
  2834.     move.w    d0,Sami_dvol(a1)
  2835. Vol2    lea    EnvLong(a0),a0
  2836.     lea    Sami_intl(a1),a1
  2837.     addq.w    #1,d2
  2838.     cmp.w    #4,d2
  2839.     bcs.s    Vol1
  2840.     rts
  2841.  
  2842. L19
  2843.  
  2844. *******    PLAY note,length
  2845. L_IPlay2    equ    20
  2846. L20    move.l    (a3)+,d3
  2847.     Rbmi    L_IFonc
  2848.     move.l    (a3)+,d2
  2849.     moveq    #%1111,d1
  2850.     moveq    #-1,d5
  2851.     moveq    #0,d6
  2852.     Rbra    L_GoBel
  2853. ******* Play voice,note,length
  2854. L_IPlay3    equ    21
  2855. L21    move.l    (a3)+,d3
  2856.     Rbmi    L_IFonc
  2857.     move.l    (a3)+,d2
  2858.     move.l    (a3)+,d1
  2859.     moveq    #-1,d5
  2860.     moveq    #0,d6
  2861.     Rbra    L_GoBel
  2862. L_GoBel        equ    22
  2863. L22    cmp.l    #96,d2            * <96?
  2864.     Rbhi    L_IFonc
  2865.     move.w    d1,d0            * Stop voices
  2866.     eor.w    #$000F,d0
  2867.     Rbsr    L_StopDma
  2868.     Rbsr    L_VOnOf
  2869.     Rbra    L_GoShot
  2870. L_GoShot    equ    23
  2871. L23    move.l    a3,-(sp)
  2872.     lea    Circuits,a2
  2873.     Dload    a3
  2874.     move.w    EnvOn-MB(a3),d7
  2875.     clr.w    EnvOn-MB(a3)
  2876.     move.w    #$8000,Sami_Bits-MB(a3)
  2877. * Explores all 4 voices
  2878.     moveq    #0,d0
  2879.     move.w    d1,d4
  2880.     moveq    #3,d1
  2881. IPl1    btst    d1,d4
  2882.     beq.s    IPl2
  2883.     Rbsr    L_VPlay
  2884. IPl2    dbra    d1,IPl1
  2885. ******* Start!
  2886. IPlX    Rbsr    L_DmaWait
  2887.     bset    #15,d0
  2888.     move.w    d0,DmaCon(a2)
  2889.     move.w    Sami_bits-MB(a3),IntEna(a2)
  2890.     move.w    d7,EnvOn-MB(a3)
  2891.     move.l    (sp)+,a3
  2892. * Wait?
  2893.     tst.l    d3
  2894.     beq.s    IPlX1
  2895.     Rjsr    L_WaitRout
  2896. IPlX1    rts
  2897.  
  2898. ******* Play voice D1: WAVE orSAMPLE
  2899. L_VPlay        equ    24
  2900. L24    movem.l    d0-d6/a0-a2,-(sp)
  2901.  
  2902.     moveq    #0,d3
  2903.     bset    d1,d3
  2904.     move.w    d3,DmaCon(a2)        * Stop voice
  2905.     lsl.w    #7,d3
  2906.     move.w    d3,IntEna(a2)        * Stop interrupts
  2907.     bclr    d1,Noise-MB(a3)        * No more random
  2908.     
  2909.     tst.w    d2
  2910.     beq    VSil
  2911.     addq.w    #3,d2
  2912.     move.w    d5,d0            * Forced wave? (bell)
  2913.     bpl.s    VPl0
  2914.     move.w    d1,d0            * Wave or Sample?
  2915.     lsl.w    #1,d0
  2916.     lea    Waves-MB(a3),a0
  2917.     move.w    0(a0,d0.w),d0
  2918.     bmi    VPl2
  2919.  
  2920. * Play WAVE!
  2921. VPl0    beq    VPl4
  2922.     lea    $a0(a2),a2
  2923.     move.w    d1,d3
  2924.     lsl.w    #4,d3
  2925.     add.w    d3,a2            * a2-> I/O
  2926.     movem.l    d1-d3/a2,-(sp)
  2927.     move.w    d0,d1
  2928.     Rbsr    L_WaveAd
  2929.     Rbeq    L_WNDef
  2930.     move.l    a2,a1
  2931.     movem.l    (sp)+,d1-d3/a2
  2932.     pea    WaveEnv(a1)
  2933.     lea    WaveDeb(a1),a1
  2934.     subq.w    #1,d2
  2935.     move.w    d2,d3
  2936.     ext.l    d3
  2937.     divu    #12,d3
  2938.     lsl.w    #2,d3
  2939.     lea    TFreq-MB(a3),a0
  2940.     add.w    d3,a0
  2941.     add.w    (a0)+,a1
  2942.     move.l    a1,(a2)            * AudAd
  2943.     move.w    (a0)+,d3
  2944.     move.w    d3,4(a2)        * AudLen
  2945.     lsl.w    #1,d3
  2946.     lea    TNotes-MB(a3),a1
  2947.     lsl.w    #1,d2
  2948.     mulu    0(a1,d2.w),d3
  2949.     move.l    MusClock-MB(a3),d2
  2950.     divu    d3,d2
  2951.     cmp.w    #124,d2
  2952.     bcc.s    VPl1
  2953.     moveq    #124,d2
  2954. VPl1:    move.w    d2,6(a2)        * AudPer
  2955. * Start enveloppe 
  2956.     move.l    (sp)+,d5
  2957.     tst.l    d6            * Fixed enveloppe? (bell / shoot)
  2958.     bne.s    VPl1a
  2959.     move.l    d5,d6
  2960. VPl1a    lea    EnvBase-MB(a3),a0    
  2961.     move.w    d1,d0
  2962.     mulu    #EnvLong,d0
  2963.     add.w    d0,a0
  2964.     move.l    d6,EnvAd(a0)
  2965.     move.l    d6,EnvDeb(a0)
  2966.     clr.w    EnvVol(a0)
  2967.     Rbsr    L_MuIntE
  2968.     movem.l    (sp)+,a0-a2/d0-d6
  2969.     bset    d1,d0
  2970.     bset    d1,d7
  2971.     rts
  2972. ******* Silence!
  2973. VSil    moveq    #0,d0
  2974.     bset    d1,d0
  2975.     move.w    d0,DmaCon(a2)
  2976.     movem.l    (sp)+,a0-a2/d0-d6
  2977.     bclr    d1,d7
  2978.     rts
  2979. ******* Play SAMPLE
  2980. VPl2    move.l    a2,-(sp)
  2981.     move.w    d2,-(sp)
  2982.     neg.w    d0
  2983.     Rbsr    L_GetSam
  2984.     move.w    (sp)+,d0
  2985.     move.l    (sp)+,a2
  2986.     moveq    #0,d6
  2987. VPl3    lea    TNotes-MB(a3),a0
  2988.     lsl.w    #1,d0
  2989.     mulu    -2(a0,d0.w),d3
  2990.     divu    #440,d3
  2991.     and.l    #$0000FFFF,d3
  2992.     Rbra    L_SPl0
  2993. ******* Play NOISE
  2994. VPl4    bset    d1,Noise-MB(a3)
  2995.     move.w    d2,d0
  2996.     move.l    WaveBase-MB(a3),a1
  2997.     lea    WaveEnv(a1),a0
  2998.     lea    WaveDeb(a1),a1
  2999.     move.l    #LNoise,d2
  3000.     move.l    #2000,d3
  3001.     tst.l    d6
  3002.     bne.s    VPl3
  3003.     move.l    a0,d6
  3004.     bset    #0,d6
  3005.     bra.s    VPl3
  3006.  
  3007. ******* PLAY OFF (voice)
  3008. L_IPlOf0    equ    25
  3009. L25    moveq    #%1111,d0
  3010.     Rbra    L_PlOf
  3011. L_IPlOf1    equ    26
  3012. L26    move.l    (a3)+,d0
  3013.     Rbra    L_Plof
  3014. L_PlOf        equ    27
  3015. L27    move.l    a3,-(sp)
  3016.     Dload    a3
  3017.     Rbsr    L_EnvOff
  3018.     move.l    (sp)+,a3
  3019.     rts
  3020.  
  3021. ******* Attente DMA
  3022. L_DmaWait    equ    28
  3023. L28    movem.l    d2-d3,-(sp)
  3024.  
  3025. ; A modifier!!! Demander les caracteristiques du DMA!!!
  3026. ;    move.w    #$200,d0
  3027. ;.loop    nop
  3028. ;    dbra    d0,.loop
  3029.  
  3030. .wait    moveq    #4,d3        
  3031. .wai2    move.b    $dff006,d2    
  3032. .wai3    cmp.b    $dff006,d2    
  3033.     beq.s    .wai3
  3034.     dbf    d3,.wai2    
  3035.     moveq    #8,d2
  3036. .wai4    dbf    d2,.wai4
  3037.  
  3038.     movem.l    (sp)+,d2-d3
  3039.     rts
  3040.  
  3041. ***********************************************************
  3042. *    SAMPLE INSTRUCTIONS
  3043.  
  3044. *******    SAM BANK n
  3045. L_ISBank    equ    29
  3046. L29    move.l    (a3)+,d0
  3047.     Rbls    L_IFonc
  3048.     cmp.l    #16,d0
  3049.     Rbhi    L_IFonc
  3050.     Dlea    SamBank,a0
  3051.     move.w    d0,(a0)
  3052.     rts
  3053. ******* SAMLOOP ON
  3054. L_ISLOn1    equ    30
  3055. L30    moveq    #0,d0
  3056.     move.l    (a3)+,d1
  3057.     Rbra    L_Sl0
  3058.  
  3059. ******* STOP DMA / INTERUPTS
  3060. *    D0= value
  3061. L_StopDma    equ    31
  3062. L31    move.w    d0,-(sp)
  3063.     eor.w    #%1111,d0
  3064.     move.w    d0,Circuits+DmaCon
  3065.     lsl.w    #7,d0
  3066.     move.w    d0,Circuits+IntEna
  3067.     move.w    (sp)+,d0
  3068.     RBra    L_DmaWait
  3069.  
  3070. L_ISLOn0    equ    32
  3071. L32    moveq    #0,d0
  3072.     moveq    #%1111,d1
  3073.     Rbra    L_Sl0
  3074.  
  3075. ******* SAMLOOP OFF
  3076. L_ISLOf1    equ    33
  3077. L33    moveq    #-1,d0
  3078.     move.l    (a3)+,d1
  3079.     Rbra    L_Sl0
  3080. L_ISLOf0    equ    34
  3081. L34    moveq    #-1,d0
  3082.     moveq    #%1111,d1
  3083.     Rbra    L_SL0
  3084. L_SL0        equ    35
  3085. L35    moveq    #0,d2
  3086.     Dlea    Sami_int,a0
  3087. Sl1    btst    d2,d1
  3088.     beq.s    Sl2
  3089.     bclr    d2,SamLoops+1-MB(a3)
  3090.     move.l    d0,Sami_rpos(a0)
  3091.     bmi.s    Sl2
  3092.     bset    d2,SamLoops+1-MB(a3)
  3093. Sl2    lea    Sami_intl(a0),a0
  3094.     addq.w    #1,d2
  3095.     cmp.w    #4,d2
  3096.     bcs.s    Sl1
  3097.     rts
  3098.  
  3099. ******* NOISE TO voice
  3100. L_INoTo        equ    36
  3101. L36    move.l    (a3)+,d1
  3102.     moveq    #0,d0
  3103.     Rbra    L_ISmt
  3104. ******* SAMPLE n TO voice
  3105. L_ISamTo    equ    37
  3106. L37    move.l    4(a3),d0
  3107.     Rbsr    L_GetSam
  3108.     move.l    (a3)+,d1
  3109.     move.l    (a3)+,d0
  3110.     neg.w    d0
  3111.     Rbra    L_Ismt
  3112. * Poke D1-> waves
  3113. L_ISmt        equ    38
  3114. L38    Dlea    Waves,a0
  3115.     moveq    #0,d2
  3116. ISmt1    btst    d2,d1
  3117.     beq.s    ISmt2
  3118.     move.w    d0,(a0)
  3119. ISmt2    addq.l    #2,a0
  3120.     addq.w    #1,d2
  3121.     cmp.w    #4,d2
  3122.     bcs.s    ISmt1
  3123.     rts
  3124.  
  3125. ******* SAM PLAY number
  3126. L_ISam1        equ    39
  3127. L39    move.l    (a3)+,d0
  3128.     Rbsr    L_GetSam
  3129.     moveq    #%1111,d1
  3130.     Rbra    L_GoSam
  3131. ******* SAM PLAY voix,number
  3132. L_ISam2        equ    40
  3133. L40    move.l    (a3)+,d0
  3134.     Rbsr    L_GetSam
  3135.     move.l    (a3)+,d1
  3136.     Rbra    L_GoSam
  3137. ******* SAM PLAY voix,number,frequence
  3138. L_ISam3        equ    41
  3139. L41    move.l    4(a3),d0
  3140.     Rbsr    L_GetSam
  3141.     move.l    (a3)+,d3
  3142.     cmp.l    #500,d3
  3143.     Rble    L_IFonc
  3144.     addq.l    #4,a3
  3145.     move.l    (a3)+,d1    
  3146.     Rbra    L_GoSam
  3147. ******* SAM RAW voice,ad,length,freq
  3148. L_ISamR        equ    42
  3149. L42    move.l    (a3)+,d3
  3150.     cmp.l    #500,d3
  3151.     Rble    L_IFonc
  3152.     move.l    (a3)+,d2
  3153.     cmp.l    #256,d2
  3154.     Rble    L_IFonc
  3155.     move.l    (a3)+,a1
  3156.     move.l    (a3)+,d1
  3157.     Rbra    L_GoSam
  3158. L_GoSam:    equ    43
  3159. L43    move.l    a3,-(sp)
  3160.     Dload    a3
  3161.  
  3162.     move.w    d1,d0
  3163.     eor.w    #$000F,d0
  3164.     Rbsr    L_StopDma
  3165.     Rbsr    L_VOnOf    
  3166.  
  3167.     lea    Circuits,a2
  3168.     move.w    EnvOn-MB(a3),d7
  3169.     clr.w    EnvOn-MB(a3)
  3170.     move.w    #$8000,Sami_bits-MB(a3)
  3171. * Do all voices
  3172.     moveq    #0,d0
  3173.     move.w    d1,d4
  3174.     moveq    #3,d1
  3175. ISp2b    btst    d1,d4
  3176.     beq.s    ISp2c
  3177.     Rbsr    L_SPlay
  3178. ISp2c    dbra    d1,ISp2b
  3179. * Start!
  3180. ISpX    
  3181.     Rbsr    L_DmaWait
  3182.     bset    #15,d0
  3183.     move.w    d0,DmaCon(a2)
  3184.     move.w    Sami_bits-MB(a3),IntEna(a2)
  3185.     move.w    d7,EnvOn-MB(a3)
  3186.     move.l    (sp)+,a3
  3187.     rts
  3188.     
  3189. ******* Find a sample -> A0
  3190. L_GetSam    equ    44
  3191. L44    move.l    d0,-(sp)
  3192.     Dload    a0
  3193.     move.w    SamBank-MB(a0),d3
  3194.     ext.l    d3
  3195.     Rbeq    L_IFonc
  3196.     Rjsr    L_BkAd
  3197.     move.l    -8(a0),d0
  3198.     cmp.l    #"Samp",d0
  3199.     Rbne    L_BNSam
  3200. * Get sample characteristics1
  3201.     move.l    (sp)+,d0
  3202.     Rbls    L_IFonc
  3203.     cmp.w    (a0),d0
  3204.     Rbhi    L_SNDef
  3205.     lsl.w    #2,d0
  3206.     move.l    2-4(a0,d0.w),d0
  3207.     Rbeq    L_SNDef
  3208.     add.l    d0,a0
  3209.     moveq    #0,d3
  3210.     move.w    8(a0),d3
  3211.     move.l    10(a0),d2
  3212.     lea    14(a0),a1
  3213.     rts
  3214.  
  3215. *********************************************************************
  3216. *    SLOAD fichier,adresse,longueur
  3217. L_Sload        equ    45
  3218. L45    move.l    (a3)+,d4
  3219.     RBmi    L_IFonc
  3220.     RJsr    L_AdOuBank
  3221.     move.l    (a3)+,d0
  3222.     cmp.l    #10,d0
  3223.     Rbcc    L_IFonc
  3224.     subq.l    #1,d0
  3225.     Rbmi    L_IFonc
  3226.     mulu    #TFiche,d0
  3227.     lea    Fichiers(a5),a2
  3228.     add.w    d0,a2
  3229.     move.l    Fha(a2),d1
  3230.     btst    #2,FhT(a2)
  3231.     Rbne    L_IFonc
  3232. * Load the data
  3233.     move.l    d3,d2
  3234.     move.l    d4,d3
  3235.     move.l    a6,-(sp)
  3236.     move.l    DosBase(a5),a6
  3237.     jsr    -42(a6)            DosRead
  3238.     move.l    (sp)+,a6
  3239.     tst.l    d0
  3240.     RBmi    L_IDError
  3241.     rts
  3242.  
  3243. ******* SAMPLAY routine
  3244. *    A1= Sample
  3245. *    D3= Freq
  3246. *    D2= Long
  3247. *    D1= Voice
  3248. L_SPlay:    equ    46
  3249. L46    movem.l    d0-d6/a0-a2,-(sp)
  3250.     bclr    d1,Noise-MB(a3)
  3251.     moveq    #0,d6
  3252.     Rbra    L_SPl0
  3253.  
  3254. L_SPl0        equ    47
  3255. L47
  3256.     movem.l    a4,-(sp)
  3257.  
  3258.     moveq    #0,d0
  3259.     bset    d1,d0            * Stop voice
  3260.     move.w    d0,DmaCon(a2)
  3261.  
  3262.     lea    Sami_int-MB(a3),a4
  3263.     move.w    #Sami_intl,d0
  3264.     mulu    d1,d0
  3265.     add.w    d0,a4            * a4-> Sami interrupts
  3266.     move.w    Sami_bit(a4),IntEna(a2)    * No more interrupts
  3267.  
  3268.     lea    EnvBase-MB(a3),a0    * Enveloppe
  3269.     move.w    d1,d0
  3270.     mulu    #EnvLong,d0
  3271.     add.w    d0,a0
  3272.  
  3273.     lea    $a0(a2),a2
  3274.     move.w    d1,d4
  3275.     lsl.w    #4,d4
  3276.     add.w    d4,a2            * a2-> I/O
  3277.  
  3278.     move.w    #1,$4(a2)
  3279.     move.l    a1,Sami_adr(a4)            * Adresse
  3280.     move.l    d2,Sami_long(a4)        * Longueur
  3281.     clr.l    Sami_pos(a4)            * Position
  3282.     clr.l    Sami_rpos(a4)            * Sam loop on?
  3283.     btst    d1,SamLoops+1-MB(a3)
  3284.     bne.s    .skipa
  3285.     subq.l    #1,Sami_rpos(a4)
  3286. .skipa    clr.l    Sami_radr(a4)            * Pas de double buffer
  3287.     
  3288.     move.l    d6,d5
  3289.     move.l    MusClock-MB(a3),d6
  3290.     bsr    Div32
  3291.     cmp.l    #124,d0
  3292.     bcc.s    .skip0
  3293.     moveq    #124,d0
  3294. .skip0    move.w    d0,6(a2)            * AudPer
  3295.  
  3296.     bclr    d1,d7
  3297.     move.w    EnvDVol(a0),Sami_dvol(a4)    * Volume, sauf si 
  3298.     tst.l    d5                  une enveloppe est
  3299.     beq.s    .skip1                  definie
  3300.     clr.l    Sami_rpos(a4)
  3301.     bclr    #0,d5
  3302.     bne.s    .skipb
  3303.     subq.l    #1,Sami_rpos(a4)
  3304. .skipb    bset    d1,d7
  3305.     move.w    #-1,Sami_dvol(a4)
  3306.     move.l    d5,EnvAd(a0)
  3307.     move.l    d5,EnvDeb(a0)
  3308.     clr.w    EnvVol(a0)
  3309.     Rbsr    L_MuIntE
  3310.  
  3311. .skip1    move.w    Sami_bit(a4),d0
  3312.     or.w    d0,Sami_bits-MB(a3)
  3313.  
  3314. * Va demarrer le son...
  3315.     lea    Circuits,a0
  3316.     move.l    a4,a1
  3317.     move.l    Sami_Handad-MB(a3),a2
  3318.     jsr    (a2)
  3319. * Fini!
  3320.     move.l    (sp)+,a4
  3321.     movem.l    (sp)+,d0-d6/a0-a2
  3322.     bset    d1,d0
  3323.     rts
  3324.  
  3325. * Division 32 bits
  3326. * D6/D3 -> D0
  3327. Div32    movem.l    d1/d3/d4/d5/d6,-(sp)
  3328.     moveq     #31,d5
  3329.         moveq     #-1,d4
  3330.         clr.l     d1
  3331. dv2:    lsl.l     #1,d6
  3332.         roxl.l     #1,d1
  3333.         cmp.l     d3,d1
  3334.         bcs.s     dv1
  3335.         sub.l     d3,d1
  3336.         lsr     #1,d4
  3337. dv1:    roxl.l     #1,d0
  3338.         dbra     d5,dv2
  3339.     movem.l    (sp)+,d1/d3/d4/d5/d6
  3340.     rts
  3341.  
  3342. ***********************************************************
  3343. *    WAVE INSTRUCTION SET
  3344.  
  3345. *******    WAVE n TO n
  3346. L_IWave:    equ    48
  3347. L48    move.l    4(a3),d1
  3348.     Rbmi    L_IFonc
  3349.     Rbsr    L_WaveAd
  3350.     Rbeq    L_WNDef
  3351.     move.l    (a3)+,d1
  3352.     move.l    (a3)+,d0
  3353.     Rbra    L_ISmt
  3354. *******    SET WAVE n,a$
  3355. L_ISWave:    equ    49
  3356. L49    move.l    (a3)+,a1
  3357.     move.w    (a1)+,d1
  3358.     cmp.w    #256,d1
  3359.     Rbcs    L_STSho
  3360.     move.l    (a3)+,d1
  3361.     Rbls    L_IFonc
  3362.     move.l    a3,-(sp)
  3363.     Dload    a3
  3364.     Rbsr    L_NeWave
  3365.     Rbne    L_IOOMem
  3366.     move.l    (sp)+,a3
  3367.     rts
  3368. *******    DEL WAVE 
  3369. L_IDWave1    equ    50
  3370. L50    move.l    (a3)+,d1
  3371.     Rbmi    L_IFonc
  3372.     Rbeq    L_W0Res
  3373.     cmp.l    #1,d1
  3374.     Rbeq    L_W0Res
  3375.     move.l    a3,-(sp)
  3376.     DLoad    a3
  3377.     moveq    #%1111,d0
  3378.     Rbsr    L_EnvOff
  3379.     Rbsr    L_WaveAd
  3380.     Rbeq    L_WNDef
  3381.     Rbsr    L_WaveDel
  3382.     Rbsr    L_NoWave
  3383.     move.l    (sp)+,a3
  3384.     rts
  3385. *******    SET ENVEL n,n TO n,v
  3386. L_ISEnv        equ    51
  3387. L51    move.l    (a3)+,d4
  3388.     cmp.l    #64,d4
  3389.     Rbcc    L_IFonc
  3390.     move.l    (a3)+,d3
  3391.     move.l    (a3)+,d5
  3392.     Rbmi    L_IFonc
  3393.     cmp.l    #7,d5
  3394.     Rbcc    L_IFonc
  3395.     move.l    (a3)+,d1
  3396.     Rbmi    L_IFonc
  3397.     tst.w    d5
  3398.     bne.s    ISe1
  3399.     tst.w    d3
  3400.     Rbls    L_IFonc
  3401. ISe1    move.l    a3,-(sp)
  3402.     Dload    a3
  3403.     Rbsr    L_WaveAd
  3404.     Rbeq    L_WNDef
  3405.     lsl.w    #2,d5
  3406.     lea    WaveEnv(a2,d5.w),a2
  3407.     move.w    d3,(a2)+
  3408.     move.w    d4,(a2)+
  3409.     clr.w    (a2)
  3410.     move.l    (sp)+,a3
  3411.     rts
  3412. ******* RAZ WAVES
  3413. L_RazWave    equ    52
  3414. L52    movem.l    a2/d0-d2,-(sp)
  3415.     moveq    #%1111,d0
  3416.     Rbsr    L_EnvOff        * Stop all voices
  3417.     lea    WaveBase-MB(a3),a2    * Erase all instruments
  3418.     move.l    a2,d2
  3419. RzW1    move.l    d2,a2
  3420.     move.l    (a2),d0
  3421.     beq.s    RzW2
  3422.     move.l    d0,a2
  3423.     Rbsr    L_WaveDel
  3424.     bra.s    RzW1
  3425. RzW2    Rbsr    L_NoWave
  3426.     movem.l    (sp)+,a2/d0-d2
  3427.     rts
  3428. * Plus de Waves speciales
  3429. L_NoWave    equ    53
  3430. L53    Dlea    Waves,a0        * Default waves
  3431.     move.w    #1,(a0)+
  3432.     move.w    #1,(a0)+
  3433.     move.w    #1,(a0)+
  3434.     move.w    #1,(a0)+
  3435.     rts
  3436.  
  3437. ******* NEW WAVES
  3438. *    A1= Array address
  3439. *    D1= # to create
  3440. L_NeWave:    equ    54
  3441. L54    movem.l    d1-d7/a1-a2,-(sp)
  3442. NeW0    Rbsr    L_WaveAd
  3443.     beq.s    NeW1
  3444.     moveq    #%1111,d0
  3445.     Rbsr    L_EnvOff
  3446.     Rbsr    L_WaveDel
  3447.     bra.s    NeW0
  3448. NeW1    move.l    #WaveLong,d0
  3449.     RJsr    L_RamChip
  3450.     beq.s    NeWE
  3451.     move.l    d0,(a2)
  3452.     move.l    d0,a2
  3453.     move.w    d1,WaveNb(a2)
  3454. * Copy default ADSR
  3455.     move.l    a1,-(sp)
  3456.     lea    EnvDef-MB(a3),a0
  3457.     lea    WaveEnv(a2),a1
  3458. NeW3    move.l    (a0)+,(a1)+
  3459.     bne.s    NeW3
  3460.     move.l    (sp)+,a1
  3461. * Full wave: 256 bytes
  3462.     lea    WaveDeb(a2),a2
  3463.     move.l    a2,a0
  3464.     moveq    #256/4-1,d0
  3465. NeW2    move.l    (a1)+,(a0)+
  3466.     dbra    d0,NeW2
  3467. * 1/2
  3468.     move.l    a2,a1
  3469.     move.l    a0,a2
  3470.     moveq    #127,d0
  3471.     bsr    NewRout
  3472. * 1/4
  3473.     move.l    a2,a1
  3474.     move.l    a0,a2
  3475.     moveq    #63,d0
  3476.     bsr    NewRout
  3477. * 1/8
  3478.     move.l    a2,a1    
  3479.     move.l    a0,a2
  3480.     moveq    #31,d0
  3481.     bsr    NewRout
  3482. * 1/16
  3483.     move.l    a2,a1
  3484.     move.l    a0,a2
  3485.     moveq    #15,d0
  3486.     bsr    NewRout
  3487. * 1/32
  3488.     move.l    a2,a1
  3489.     move.l    a0,a2
  3490.     moveq    #7,d0
  3491.     bsr    NewRout
  3492. * 1/64
  3493.     move.l    a2,a1
  3494.     move.l    a0,a2
  3495.     moveq    #3,d0
  3496.     bsr    NewRout
  3497. ******* No error
  3498.     moveq    #0,d0
  3499. NeWx    movem.l    (sp)+,d1-d7/a1-a2
  3500.     rts
  3501. ******* Out of mem
  3502. NeWE    moveq    #-1,d0
  3503.     bra.s    NeWx
  3504. ******* Divide a sample by 2
  3505. NewRout    move.b    (a1)+,d1
  3506.     ext.w    d1
  3507.     move.b    (a1)+,d2
  3508.     ext.w    d2
  3509.     add.w    d2,d1
  3510.     asr.w    #1,d1
  3511.     move.b    d1,(a0)+
  3512.     dbra    d0,NewRout
  3513.     rts
  3514.  
  3515. ******* Get a wave address
  3516. L_WaveAd:    equ    55
  3517. L55    moveq    #0,d2
  3518.     Dlea    WaveBase,a2
  3519.     move.l    (a2),d0
  3520.     beq.s    WAd2
  3521. WAd1    move.l    a2,d2
  3522.     move.l    d0,a2
  3523.     cmp.w    WaveNb(a2),d1
  3524.     beq.s    WAd3
  3525.     move.l    (a2),d0
  3526.     bne.s    WAd1
  3527. WAd2    moveq    #0,d0
  3528.     rts
  3529. WAd3    moveq    #-1,d0
  3530.     rts
  3531.  
  3532. ******* Deletion of a WAVE (A2)-D2
  3533. L_WaveDel    equ    56
  3534. L56    movem.l    a0-a2/d0-d2,-(sp)
  3535.     move.w    WaveNb(a2),d1
  3536.     move.l    d2,a0
  3537.     move.l    (a2),(a0)
  3538.     move.l    #WaveLong,d0
  3539.     move.l    a2,a1
  3540.     Rjsr    L_RamFree
  3541.     movem.l    (sp)+,a0-a2/d0-d2
  3542.     rts
  3543.  
  3544. ***********************************************************
  3545. *    STOP SAMPLES INTERRUPTS
  3546. L_Sami_stop    equ    57
  3547. L57    move.w    #%0000011110000000,d0
  3548.     move.w    d0,Circuits+IntEna
  3549.     move.w    d0,Circuits+IntReq
  3550.     rts
  3551.  
  3552. ***********************************************************
  3553. *    ENVELOPPES 
  3554.  
  3555. ***********************************************************
  3556. *    STOP ENVELOPPE D0
  3557. L_EnvOff    equ    58
  3558. L58    movem.l    d0-d3/a0,-(sp)
  3559.     move.w    EnvOn-MB(a3),d1
  3560.     clr.w    EnvOn-MB(a3)
  3561.     moveq    #0,d3
  3562.     lea    Circuits,a0
  3563.     moveq    #0,d2
  3564. EOf1    btst    d2,d0
  3565.     beq.s    EOf2
  3566.     bclr    d2,d1
  3567.     beq.s    EOf2
  3568.     bset    d2,d3
  3569.     move.w    #2,$a4(a0)
  3570.     clr.w    $a8(a0)
  3571. EOf2    lea    $10(a0),a0
  3572.     addq.w    #1,d2
  3573.     cmp.w    #4,d2
  3574.     bcs.s    EOf1
  3575.     move.w    d1,EnvOn-MB(a3)
  3576.     move.w    d3,MuReStart-MB(a3)
  3577.     movem.l    (sp)+,d0-d3/a0
  3578.     rts
  3579.     
  3580. ******* Next enveloppe
  3581. L_MuIntE    equ    59
  3582. L59    move.l    EnvAd(a0),a1
  3583. MuIe0    move.w    (a1)+,d3
  3584.     beq.s    MuIntS
  3585.     bmi.s    MuIe1
  3586.     move.w    d3,EnvNb(a0)
  3587.     move.w    EnvDVol(a0),d4
  3588.     mulu    (a1)+,d4
  3589.     lsr.w    #6,d4
  3590.     sub.w    EnvVol(a0),d4
  3591.     ext.l    d4
  3592.     lsl.w    #8,d4
  3593.     divs    d3,d4
  3594.     ext.l    d4
  3595.     lsl.l    #8,d4
  3596.     move.l    d4,EnvDelta(a0)
  3597.     clr.w    EnvVol+2(a0)
  3598.     move.l    a1,EnvAd(a0)
  3599.     rts
  3600. * Loop
  3601. MuIe1    move.l    EnvDeb(a0),a1
  3602.     bra.s    MuIe0
  3603. * End of a voice
  3604. MuIntS    bset    d1,d5
  3605.     bclr    d1,d0
  3606.     bclr    d1,Noise-MB(a3)
  3607. * Restarts the music
  3608.     bset    d1,MuReStart+1-MB(a3)
  3609.     rts
  3610.  
  3611. ******************************************************************
  3612. *    MUSIC
  3613.  
  3614. ******* Music initialisation
  3615. L_MuInit:    equ    60
  3616. L60    clr.l    MuBase-MB(a3)
  3617.     clr.w    MuNumber-MB(a3)
  3618.     move.l    #$DFF0A0,MuChip0-MB(a3)
  3619.     move.l    #$DFF0B0,MuChip1-MB(a3)
  3620.     move.l    #$DFF0C0,MuChip2-MB(a3)
  3621.     move.l    #$DFF0D0,MuChip3-MB(a3)
  3622.     move.w    #$000F,MuDMAsk-MB(a3)
  3623.     clr.w    MuReStart-MB(a3)
  3624.     Rbra    L_MOff
  3625.  
  3626. ******* MUSIC OFF-> Stops all musics
  3627. L_IMuSOff    equ    61
  3628. L61    movem.l    a0-a3/d0-d1,-(sp)
  3629.     Dload    a3
  3630.     clr.l    MuBase-MB(a3)
  3631.     clr.w    MuNumber-MB(a3)
  3632.     Rbsr    L_MOff
  3633.     movem.l    (sp)+,a0-a3/d0-d1
  3634.     rts
  3635.  
  3636. ******* MUSIC STOP-> Stops current music
  3637. L_IMuStop    equ    62
  3638. L62    movem.l    a0-a3/d0-d1,-(sp)
  3639.     Dload    a3
  3640.     move.l    MuBase-MB(a3),d0
  3641.     beq.s    IStp
  3642.     clr.w    MuBase-MB(a3)
  3643.     move.l    d0,a0
  3644.     clr.w    VoiCpt0(a0)
  3645.     clr.w    VoiCpt1(a0)
  3646.     clr.w    VoiCpt2(a0)
  3647.     clr.w    VoiCpt3(a0)
  3648.     move.l    d0,MuBase-MB(a3)
  3649. IStp    movem.l    (sp)+,a0-a3/d0-d1
  3650.     rts
  3651.  
  3652. ******* MUSIC VOLUME
  3653. L_IMVol        equ    63
  3654. L63    move.l    (a3)+,d0
  3655.     cmp.l    #64,d0
  3656.     Rbcs    L_MVol
  3657.     Rbcc    L_IFonc
  3658. * Set volume
  3659. L_MVol        equ    64
  3660. L64    and.w    #63,d0
  3661.     Dload    a0
  3662.     move.w    d0,MuVolume-MB(a0)
  3663.     move.l    MuBase-MB(a0),d4
  3664.     beq.s    MVol3
  3665.     clr.l    MuBase-MB(a0)
  3666.     lea    MuBuffer-MB(a0),a1
  3667.     move.w    MuNumber-MB(a0),d1
  3668. MVol0    move.l    a1,a2
  3669.     moveq    #3,d2
  3670. MVol1    move.w    VoiDVol(a2),d3
  3671.     mulu    d0,d3
  3672.     lsr.w    #6,d3
  3673.     move.w    d3,VoiVol(a2)
  3674.     lea    VoiLong(a2),a2
  3675.     dbra    d2,MVol1
  3676. MVol2    lea    MuLong(a1),a1
  3677.     subq.w    #1,d1
  3678.     bne.s    MVol0
  3679.     move.l    d4,MuBase-MB(a0)
  3680. MVol3    rts
  3681.  
  3682. ******* VOICE ON/OFF Voices
  3683. L_IVoice    equ    65
  3684. L65    move.l    (a3)+,d0
  3685.     and.w    #$000F,d0
  3686.     move.l    a3,-(sp)
  3687.     Dload    a3
  3688.     Rbsr    L_VOnOf
  3689.     movem.l    (sp)+,a3
  3690.     rts
  3691.  
  3692. ******* Start / Stop voices D0
  3693. L_VOnOf        equ    66
  3694. L66    movem.l    d0-d5/a0-a3,-(sp)
  3695.     move.w    d0,d4
  3696.     Dload    a3
  3697.     move.l    MuBase-MB(a3),d1
  3698.     beq.s    VooX
  3699.     clr.l    MuBase-MB(a3)
  3700.     move.l    d1,a1
  3701.     move.l    d1,a2
  3702.     move.w    MuDMAsk-MB(a3),d1
  3703.     move.w    d0,MuDMAsk-MB(a3)
  3704.     move.l    WaveBase-MB(a3),a0
  3705.     lea    WaveDeb(a0),a0
  3706.     move.l    a0,d3
  3707.     lea    MuChip0-MB(a3),a0
  3708.     moveq    #0,d2
  3709.     moveq    #0,d4
  3710. * Exploration loop
  3711. Voo1    btst    d2,d0
  3712.     bne.s    Voo2
  3713. * Stop a voice!
  3714.     btst    d2,d1            * Already stopped?
  3715.     beq.s    VooN
  3716.     bset    d2,d4
  3717.     move.l    d3,(a0)
  3718.     bclr    d2,MuStart+1(a2)
  3719.     bclr    d2,MuStop+1(a2)
  3720.     bra.s    VooN
  3721. * Re start a voice
  3722. Voo2    btst    d2,d1            * Already on?
  3723.     bne.s    VooN
  3724.     bset    d2,MuReStart+1-MB(a3)
  3725. * Next
  3726. VooN    addq.l    #4,a0
  3727.     lea    VoiLong(a1),a1
  3728.     addq.w    #1,d2
  3729.     cmp.w    #4,d2
  3730.     bcs.s    Voo1
  3731. * Stop them!
  3732.     move.l    a2,MuBase-MB(a3)
  3733.     move.w    d4,Circuits+DmaCon
  3734. VooX    movem.l    (sp)+,d0-d5/a0-a3
  3735.     rts
  3736.  
  3737. ******* MUSIC n
  3738. L_IMusic    equ    67
  3739. L67    move.l    (a3)+,d3
  3740.     Rbls    L_IFonc
  3741. * Points to the SONG
  3742.     move.l    a3,-(sp)
  3743.     Dload    a3
  3744.     tst.l    MusBank-MB(a3)
  3745.     Rbeq    L_MnRes
  3746.     move.l    BankSong-MB(a3),a1
  3747.     cmp.w    (a1),d3
  3748.     Rbhi    L_MNDef
  3749.     lsl.w    #2,d3
  3750.     add.l    2-4(a1,d3.w),a1
  3751. * Still room?
  3752.     cmp.w    #3,MuNumber-MB(a3)
  3753.     bcc    IMusX
  3754.     clr.l    MuBase-MB(a3)
  3755. * Buffer address
  3756.     move.w    MuNumber-MB(a3),d0
  3757.     move.w    d0,d1
  3758.     addq.w    #1,MuNumber-MB(a3)
  3759.     mulu    #MuLong,d0
  3760.     lea    MuBuffer-MB(a3),a2
  3761.     add.w    d0,a2
  3762. * Init datas
  3763.     moveq    #(VoiLong*4)/2-1,d0
  3764.     move.l    a2,a0
  3765. IMus1    clr.w    (a0)+
  3766.     dbra    d0,IMus1
  3767.     clr.w    MuStop(a2)
  3768.     clr.w    MuStart(a2)
  3769. * Init parameters
  3770.     move.l    a2,d2
  3771.     move.w    TempoBase-MB(a3),MuCpt(a2)
  3772.     move.w    #17,MuTempo(a2)            *XXX
  3773.     moveq    #0,d0
  3774. IMus2    move.w    #1,VoiCpt(a2)
  3775.     lea    FoEnd-MB(a3),a0
  3776.     move.l    a0,VoiAdr(a2)
  3777.     move.l    a1,a0
  3778.     add.w    0(a0,d0.w),a0
  3779.     move.l    a0,VoiPat(a2)
  3780.     move.l    a0,VoiDPat(a2)
  3781.     lea    NoEffect2(pc),a0
  3782.     move.l    a0,VoiEffect(a2)
  3783.     lea    VoiLong(a2),a2
  3784.     addq.w    #2,d0
  3785.     cmp.w    #8,d0
  3786.     bne.s    IMus2
  3787. * No more samples
  3788.     move.w    #%0000011110000000,Circuits+IntEna
  3789. * Starts music
  3790.     move.l    d2,MuBase-MB(a3)
  3791. IMusX    move.l    (sp)+,a3
  3792.     rts
  3793. NoEffect2
  3794.     move.w    VoiNote(a4),$06(a6)
  3795.     rts
  3796.  
  3797. ******* Tempo T
  3798. L_ITempo    equ    68
  3799. L68    move.l    (a3)+,d0
  3800.     cmp.l    #100,d0
  3801.     Rbhi    L_IFonc
  3802.     Dload    a0
  3803.     move.l    MuBase-MB(a0),d1
  3804.     beq.s    ITemp
  3805.     move.l    d1,a0
  3806.     move.w    d0,MuTempo(a0)
  3807. ITemp    rts
  3808.  
  3809. ***********************************************************
  3810. *    =VU METRE(v)
  3811. L_FVu        equ    69
  3812. L69    move.l    (a3)+,d0
  3813.     cmp.l    #4,d0
  3814.     Rbcc    L_IFonc
  3815.     Dload    a0
  3816.     moveq    #0,d3
  3817.     move.b    0(a0,d0.w),d3
  3818.     clr.b    0(a0,d0.w)
  3819.     moveq    #0,d2
  3820.     rts
  3821.  
  3822. ***********************************************************
  3823. *    =MU BASE
  3824. L_FMB        equ    70
  3825. L70    Dload    a0
  3826.     move.l    a0,d3
  3827.     moveq    #0,d2
  3828.     rts
  3829.  
  3830. ***********************************************************
  3831. *    LED INSTRUCTION
  3832. L_LedOn        equ    71
  3833. L71    bclr    #1,$BFE001
  3834.     rts
  3835. L_LedOf        equ    72
  3836. L72    bset    #1,$BFE001
  3837.     rts
  3838.  
  3839. ***********************************************************
  3840. *    INSTALL THE SAMPLE HANDLER
  3841. L_Sami_install    equ    73
  3842. L73    tst.w    Sami_flag-MB(a3)
  3843.     bne.s    .skip
  3844.     movem.l    d0-d2/a0-a2/a6,-(sp)
  3845.     move.l    $4.w,a6
  3846. ; Save state of interrupts
  3847.     move.w    Circuits+IntEnaR,d0
  3848.     and.w    #%0000011110000000,d0
  3849.     move.w    d0,Sami_OldEna-MB(a3)
  3850.     Rbsr    L_Sami_stop
  3851. ; Install 4 voices
  3852.     lea    Sami_int-MB(a3),a1
  3853.     moveq    #7,d0
  3854. .loop    bsr.s    Sami_start
  3855.     lea    Sami_intl(a1),a1
  3856.     addq.w    #1,d0
  3857.     cmp.w    #11,d0
  3858.     bne.s    .loop
  3859.     subq.w    #1,Sami_flag-MB(a3)
  3860.     movem.l    (sp)+,d0-d2/a0-a2/a6
  3861. .skip    rts
  3862. Sami_start
  3863.     move.l    a1,is_data(a1)
  3864.     move.l    Sami_handad-MB(a3),is_code(a1)
  3865.     move.b    #2,ln_type(a1)
  3866.     move.b    #0,ln_pri(a1)
  3867.     move.l    $4.w,a6    
  3868.     movem.l    d0/a1,-(sp)
  3869.     jsr    -162(a6)        SetIntVector
  3870.     move.l    d0,d1
  3871.     movem.l    (sp)+,d0/a1
  3872.     move.l    d1,Sami_old(a1)
  3873.     rts
  3874.  
  3875. ***********************************************************
  3876. *    REMOVE THE SAMPLE HANDLER
  3877. L_Sami_remove    equ    74
  3878. L74    tst.w    Sami_flag-MB(a3)
  3879.     beq.s    .skip
  3880.     movem.l    a0-a2/a6/d0-d2,-(sp)
  3881.     Rbsr    L_Sami_Stop
  3882.     move.l    $4.w,a6
  3883.     moveq    #7,d2
  3884.     lea    Sami_Int-MB(a3),a2
  3885. .loop    move.l    Sami_old(a2),a1
  3886.     move.l    d2,d0
  3887.     jsr    -162(a6)        SetIntVector
  3888.     lea    Sami_intl(a2),a2
  3889.     addq.w    #1,d2    
  3890.     cmp.w    #11,d2
  3891.     bne.s    .loop
  3892.     lea    Circuits,a0
  3893.     move.w    #$000F,DmaCon(a0)
  3894.     move.w    Sami_oldena-MB(a3),IntEna(a0)
  3895.     clr.w    Sami_flag-MB(a3)
  3896.     movem.l    (sp)+,a0-a2/a6/d0-d2
  3897. .skip    rts
  3898.  
  3899. ***********************************************************
  3900. *    Normal error messages
  3901. ; This routines performs jump to the normal AMOS error messages:
  3902. ; Load in D0 the number of the error, and do a RJmp to L_Error.
  3903. L_IOOMem    equ    75
  3904. L75    
  3905.     moveq    #24,d0
  3906.     Rjmp    L_Error
  3907. L_IFonc        equ    76
  3908. L76    moveq    #23,d0
  3909.     Rjmp    L_Error
  3910.  
  3911. ***********************************************************
  3912. *     Customized error messages
  3913. ; This list of routines just load in D0 the number of the error message in
  3914. ; the extension error-list, and call the error handling routine.
  3915.  
  3916. L_WNDef        equ    77
  3917. L77    moveq    #0,d0    
  3918.     Rbra    L_Custom
  3919. L_SNDef        equ    78
  3920. L78    moveq    #1,d0
  3921.     Rbra    L_Custom
  3922. L_BNSam        equ    79
  3923. L79    moveq    #2,d0
  3924.     Rbra    L_Custom
  3925. L_STSho        equ    80
  3926. L80    moveq    #3,d0
  3927.     Rbra    L_Custom
  3928. L_W0Res        equ    81
  3929. L81    moveq    #4,d0
  3930.     Rbra    L_Custom
  3931. L_MnRes        equ    82
  3932. L82    moveq    #5,d0
  3933.     Rbra    L_Custom
  3934. L_MNDef        equ    83
  3935. L83    moveq    #6,d0
  3936.     Rbra    L_Custom
  3937.  
  3938.  
  3939. ********************************************************************
  3940. *    =SAM SWAPPED(V)
  3941. L_Samswapped    equ    84
  3942. L84    move.l    (a3)+,d0
  3943.     moveq    #0,d2
  3944.     moveq    #0,d3
  3945.     cmp.l    #3,d0
  3946.     Rbhi    L_IFonc
  3947.     move.w    Circuits+IntEnaR,d1
  3948.     lsr.w    #7,d1
  3949.     btst    d0,d1
  3950.     beq.s    .stop
  3951.     Dlea    Sami_int,a0
  3952.     mulu    #Sami_intl,d0
  3953.     tst.l    Sami_radr(a0,d0.l)
  3954.     bne.s    .skip
  3955.     move.l    Sami_pos(a0,d0.l),d1
  3956.     cmp.l    #Sami_lplay,d1
  3957.     beq.s    .skip
  3958.     moveq    #-1,d3
  3959. .skip    rts
  3960. .stop    moveq    #1,d3
  3961.     rts
  3962. *********************************************************************
  3963. *    SAM SWAP
  3964. L_SamSwap    equ    85
  3965. L85    move.l    (a3)+,d4
  3966.     Rbmi    L_IFonc
  3967.     Rjsr    L_AdOuBank
  3968.     move.l    (a3)+,d2
  3969.     moveq    #0,d1
  3970.     Dlea    Sami_int,a0
  3971. .loop    btst    d1,d2
  3972.     beq.s    .skip
  3973.     move.l    d3,Sami_radr(a0)
  3974.     move.l    d4,Sami_rlong(a0)
  3975. .skip    lea    Sami_intl(a0),a0
  3976.     addq.w    #1,d1
  3977.     cmp.w    #4,d1
  3978.     bne.s    .loop
  3979.     rts
  3980. *********************************************************************
  3981. *    SAM STOP
  3982. L_SamStop0    equ    86
  3983. L86    move.l    #$f,-(a3)
  3984.     RBra    L_SamStop1
  3985. L_SamStop1    equ    87
  3986. L87    move.l    (a3)+,d1
  3987.     and.l    #$F,d1
  3988.     move.w    d1,Circuits+DmaCon
  3989.     lsl.w    #7,d1    
  3990.     move.w    d1,Circuits+IntEna
  3991.     rts
  3992.  
  3993. *********************************************************************
  3994. *    TRACKER instructions
  3995.  
  3996. *******    TRACK LOAD "nom",banque
  3997. L_Trackload    equ    88
  3998. L88
  3999.     move.l    (a3)+,d3
  4000.     subq.l    #1,d3
  4001.     cmp.l    #16,d3
  4002.     Rbcc    L_IFonc
  4003.     Dload    a0
  4004.     cmp.w    Track_Bank-MB(a0),d3
  4005.     bne.s    .kkk
  4006.     tst.b    mt_on-MB(a0)
  4007.     beq.s    .kkk
  4008.     RBsr    L_TrackStop
  4009. .kkk    move.w    d3,Track_Bank-MB(a0)    * Numero de la banque
  4010.     RJsr    L_EffBank
  4011.     lsl.w    #3,d3
  4012.     move.l    ABanks(a5),a0
  4013.     add.w    d3,a0
  4014.     move.l    a0,-(sp)
  4015. * Get name to load
  4016.     move.l    (a3)+,a0
  4017.     move.w    (a0)+,d0
  4018.     subq.w    #1,d0    
  4019.     cmp.w    #128,d0
  4020.     Rbcc    L_IFonc
  4021.     move.l    Buffer(a5),a1
  4022.     lea    128(a1),a2
  4023.     move.l    a1,d1
  4024. .loop    move.b    (a0),(a1)+
  4025.     move.b    (a0)+,(a2)+
  4026.     dbra    d0,.loop
  4027.     clr.b    (a1)
  4028.     move.b    #".",(a2)+
  4029.     move.b    #"N",(a2)+
  4030.     move.b    #"T",(a2)+
  4031.     clr.b    (a2)
  4032.     move.l    #1005,d2
  4033.     move.l    a6,-(sp)
  4034.     move.l    DosBase(a5),a6
  4035.     jsr    -30(a6)            DosOpen, fichier sons
  4036.     move.l    (sp)+,a6
  4037.     move.l    d0,d7
  4038.     Rbeq    L_IDError
  4039.     move.l    d7,d1            Trouve la taille
  4040.     bsr    .taille
  4041.     move.l    d0,d6
  4042. * Fichier des instruments
  4043.     moveq    #0,d5
  4044.     moveq    #0,d4
  4045.     move.l    Buffer(a5),d1
  4046.     add.l    #128,d1
  4047.     move.l    #1005,d2
  4048.     move.l    a6,-(sp)
  4049.     move.l    DosBase(a5),a6
  4050.     jsr    -30(a6)            DosOpen,
  4051.     move.l    (sp)+,a6
  4052.     move.l    d0,d5
  4053.     beq.s    .noins
  4054.     move.l    d5,d1            Trouve la taille
  4055.     bsr    .taille
  4056.     move.l    d0,d4
  4057. .noins
  4058. * Reserve la banque
  4059.     move.l    (sp)+,a1
  4060.     move.l    d6,d0
  4061.     add.l    d4,d0
  4062.     add.l    #16,d0
  4063.     move.l    d0,d1
  4064.     Rjsr    L_RamChip
  4065.     beq    .mem
  4066.     move.l    d0,(a1)+
  4067.     bset    #31,d1
  4068.     bset    #30,d1
  4069.     move.l    d1,(a1)+
  4070.     move.l    d0,a1
  4071.     move.l    #"Trac",(a1)+
  4072.     move.l    #"ker ",(a1)+
  4073. * Charge les instruments
  4074.     move.l    d5,d1
  4075.     beq.s    .noins2
  4076.     move.l    a1,d2
  4077.     move.l    d4,d3
  4078.     movem.l    a6/a1,-(sp)
  4079.     move.l    DosBase(a5),a6
  4080.     jsr    -42(a6)            Read
  4081.     movem.l    (sp)+,a6/a1
  4082.     move.l    d0,d2
  4083.     move.l    d5,d1
  4084.     bsr    .clo
  4085.     cmp.l    d2,d3
  4086.     Rbne    L_IFonc
  4087.     move.l    #$03011992,(a1)
  4088.     addq.l    #1,d4
  4089.     and.w    #$FFFE,d4
  4090.     move.l    d4,4(a1)
  4091.     add.l    d4,a1
  4092. .noins2
  4093. * Charge la musique
  4094.     move.l    d7,d1
  4095.     move.l    a1,d2
  4096.     move.l    d6,d3
  4097.     move.l    a6,-(sp)
  4098.     move.l    DosBase(a5),a6
  4099.     jsr    -42(a6)            Read
  4100.     move.l    (sp)+,a6
  4101.     move.l    d0,d2
  4102.     move.l    d7,d1
  4103.     bsr    .clo
  4104.     cmp.l    d2,d3
  4105.     Rbne    L_IFonc
  4106.     rts
  4107. * Ferme le fichier
  4108. .clo    movem.l    a6/a0/a1,-(sp)
  4109.     move.l    DosBase(a5),a6
  4110.     jsr    -36(a6)            Close
  4111.     movem.l    (sp)+,a6/a0/a1
  4112.     rts
  4113. * Out of memory
  4114. .mem    move.l    d5,d1
  4115.     beq.s    .xx
  4116.     bsr.s    .clo
  4117. .xx    move.l    d7,d1
  4118.     bsr.s    .clo
  4119.     RBra    L_IOOMem
  4120. * Routine, trouve la taille d'un fichier
  4121. .taille    move.l    a6,-(sp)
  4122.     move.l    d1,-(sp)
  4123.     moveq    #0,d2
  4124.     moveq    #1,d3
  4125.     move.l    DosBase(a5),a6
  4126.     jsr    -66(a6)            DosSeek
  4127.     move.l    (sp)+,d1
  4128.     move.l    d0,d2
  4129.     moveq    #-1,d3
  4130.     move.l    DosBase(a5),a6
  4131.     jsr    -66(a6)            DosSeek
  4132.     move.l    (sp)+,a6
  4133.     rts
  4134.  
  4135. ******* TRACK CHECK, arrete la musique si pas banque...
  4136. L_TrackCheck    equ    89
  4137. L89    movem.l    a0-a1,-(sp)
  4138.     DLoad    a1
  4139.     tst.b    mt_on-MB(a1)
  4140.     beq.s    .skip
  4141.     move.l    mt_data-MB(a1),a0
  4142.     cmp.l    #"ker ",-(a0)
  4143.     bne.s    .stop
  4144.     cmp.l    #"Trac",-(a0)
  4145.     beq.s    .skip
  4146. .stop    RBsr    L_TrackStop
  4147. .skip    movem.l    (sp)+,a0-a1
  4148.     rts
  4149.  
  4150. ******* TRACK STOP
  4151. L_TrackStop    equ    90
  4152. L90
  4153.     move.l    a3,-(sp)
  4154.     Dload    a3
  4155.     clr.b    mt_on-MB(a3)
  4156.     clr.w    $dff0a8
  4157.     clr.w    $dff0b8
  4158.     clr.w    $dff0c8
  4159.     clr.w    $dff0d8
  4160.     move.w    #$f,$dff096
  4161.     move.l    (sp)+,a3
  4162.     rts
  4163.  
  4164. ******* TRACK LOOP ON/OFF
  4165. L_TrackLoopon    equ    91
  4166. L91    DLea    sorploop,a0
  4167.     move.b    #1,(a0)
  4168.     rts
  4169. L_TrackLoopof    equ    92
  4170. L92    DLea    sorploop,a0
  4171.     clr.b    (a0)
  4172.     rts
  4173.  
  4174. ******* TRACK PLAY [Bank],[Pattern]
  4175.  
  4176. L_TrackPlay0    equ    93
  4177. L93
  4178.     move.l    #Entnul,-(a3)
  4179.     Rbra    94
  4180.  
  4181. L_TrackPlay1    equ    94
  4182. L94    
  4183.     clr.l    -(a3)
  4184.     Rbra    95
  4185.  
  4186. L_TrackPlay2    equ    95
  4187. L95    
  4188.     move.l    (a3)+,d7
  4189.     cmp.l    #Entnul,(a3)
  4190.     bne.s    .skip
  4191.     Dload    a0
  4192.     moveq    #0,d0
  4193.     move.w    Track_Bank-MB(a0),d0
  4194.     addq.w    #1,d0
  4195.     move.l    d0,(a3)
  4196. .skip    
  4197.     Rjsr    L_Adoubank
  4198.     move.l    d3,a2
  4199.     cmp.l    #"Trac",-8(a2)    
  4200.     bne    .nobank
  4201.     cmp.l    #"ker ",-4(a2)
  4202.     bne    .nobank
  4203.     
  4204.     Rbsr    L_SamStop0
  4205.     Rbsr    L_TrackStop
  4206.     
  4207.     move.l    a3,-(sp)
  4208.     Dload    a3
  4209.  
  4210.     moveq    #0,d1
  4211.     and.b    #$7f,d7
  4212.     move.b    d7,mt_songpos-MB(a3)
  4213.     move.b    d7,omt_songpos-MB(a3)
  4214.     beq.s    .skp
  4215.     moveq    #1,d1
  4216. .skp    move.b    d1,sorp-MB(a3)
  4217.     clr.b    sorpend-MB(a3)
  4218.     clr.w    mt_pattpos-MB(a3)        * Position dans pattern
  4219.  
  4220.     move.l    a2,a1
  4221.     clr.l    mt_data2-MB(a3)
  4222.     cmp.l    #$03011992,(a2)        Des instruments?
  4223.     bne.s    .skd
  4224.     move.l    4(a2),d0        Prend l'adresse
  4225.     lea    0(a2,d0.l),a1
  4226.     lea    24(a2),a2
  4227.     move.l    a2,mt_data2-MB(a3)
  4228. .skd
  4229.     move.l    a1,mt_data-MB(a3)
  4230.     lea    (a1),a0
  4231.     lea    $3b8(a0),a1
  4232.     moveq    #$7f,d0
  4233.     moveq    #0,d2
  4234.     moveq    #0,d1
  4235. .mt_lop2:
  4236.     move.b    (a1)+,d1
  4237.     cmp.b    d2,d1
  4238.     ble.s    .mt_lop
  4239.     move.l    d1,d2
  4240. .mt_lop:    
  4241.     dbf    d0,.mt_lop2
  4242.     addq.b    #1,d2
  4243.     asl.l    #8,d2
  4244.     asl.l    #2,d2
  4245.     lea    4(a1,d2.l),a2
  4246.     lea    mt_samplestarts-MB(a3),a1
  4247.     add.w    #42,a0
  4248.     moveq    #$1e,d0
  4249. .mt_lop3:
  4250.     clr.l    (a2)
  4251.     move.l    a2,(a1)+
  4252.     moveq    #0,d1
  4253.     move.w    (a0),d1
  4254.     clr.b    2(a0)
  4255.     asl.l    #1,d1
  4256.     add.l    d1,a2
  4257.     add.l    #30,a0
  4258.     dbf    d0,.mt_lop3
  4259.     or.b    #2,$bfe001
  4260.     moveq    #0,d0
  4261.     lea    $dff000,a0
  4262.     move.w    d0,$a8(a0)
  4263.     move.w    d0,$b8(a0)
  4264.     move.w    d0,$c8(a0)
  4265.     move.w    d0,$d8(a0)
  4266.  
  4267.     move.w    TempoBase-MB(a3),d0
  4268.     divu    #16,d0
  4269.     move.b    d0,mt_speed-MB(a3)
  4270.     clr.b    mt_counter-MB(a3)
  4271.     move.b    #1,mt_on-MB(a3)
  4272.     move.l    (sp)+,a3    
  4273.     rts
  4274. * Pas un module tracker
  4275. .nobank    moveq    #8,d0
  4276.     Rbra    L_Custom
  4277.  
  4278. ******* Erreur disque
  4279. L_IDError    equ    96
  4280. L96    move.w    #DEBase+15,d0
  4281.     Rjmp    L_Error
  4282.  
  4283. L97
  4284. L98
  4285. L99
  4286.  
  4287.  
  4288. *********************************************************************
  4289. *    ERROR MESSAGES...
  4290. ;
  4291. ; You know that the compiler have a -E1 option (with errors) and a 
  4292. ; a -E0 (without errors). To achieve that, the compiler copies one of
  4293. ; the two next routines, depending on the -E flag. If errors are to be
  4294. ; copied along with the program, then the next next routine is used. If not,
  4295. ; then the next one is copied.
  4296. ; The compiler assumes that the two last routines in the library handles
  4297. ; the errors: the previous last is WITH errors, the last is WITHOUT. So,
  4298. ; remember:
  4299. ;
  4300. ; THESE ROUTINES MUST BE THE LAST ONES IN THE LIBRARY
  4301. ;
  4302. ; The AMOS interpretor always needs errors. So make all your custom errors
  4303. ; calls point to the L_Custom routine, and everything will work fine...
  4304. ;
  4305. ******* "With messages" routine.
  4306. ; The following routine is the one your program must call to output
  4307. ; a extension error message. It will be used under interpretor and under
  4308. ; compiled program with -E1
  4309.  
  4310. L_Custom    equ    100
  4311. L100    lea    ErrMess(pc),a0
  4312.     moveq    #0,d1            * Can be trapped
  4313.     moveq    #ExtNb,d2        * Number of extension
  4314.     moveq    #0,d3            * IMPORTANT!!!
  4315.     RJmp    L_ErrorExt        * Jump to routine...
  4316. * Messages...
  4317. ErrMess    dc.b    "Wave not defined",0            *0
  4318.     dc.b     "Sample not defined",0            *1
  4319.     dc.b     "Sample bank not found",0        *2
  4320.     dc.b    "256 characters for a wave",0        *3
  4321.     dc.b    "Wave 0 and 1 are reserved",0        *4
  4322.     dc.b    "Music bank not found",0        *5
  4323.     dc.b     "Music not defined",0            *6
  4324.     dc.b    "Can't open narrator",0            *7
  4325.     dc.b    "Not a tracker module",0        *8
  4326. * IMPORTANT! Always EVEN!
  4327.     even
  4328.  
  4329. ******* "No errors" routine
  4330. ; If you compile with -E0, the compiler will replace the previous
  4331. ; routine by this one. This one just sets D3 to -1, and does not
  4332. ; load messages in A0. Anyway, values in D1 and D2 must be valid.
  4333. ;    
  4334. ; THIS ROUTINE MUST BE THE LAST ONE IN THE LIBRARY!
  4335. ;
  4336.  
  4337. L101    moveq    #0,d1
  4338.     moveq    #ExtNb,d2
  4339.     moveq    #-1,d3
  4340.     RJmp    L_ErrorExt
  4341.  
  4342. ; Do not forget the last label to delimit the last library routine!
  4343. L102
  4344.  
  4345. *********************************************************************
  4346. ; Now the title of the extension. If you come from V1.23 note that
  4347. ; the cursor is no more located on the screen, instead a CDOWN (31)
  4348. ; control code is used...
  4349.  
  4350. ******* TITLE MESSAGE
  4351. C_Title    dc.b    31,"Music extension V1.53",0
  4352.     Even
  4353.  
  4354. ******* END OF THE EXTENSION
  4355. C_End    dc.w    0
  4356.     even
  4357.  
  4358.  
  4359.