home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 42 / af042b.adf / Extensions.lha / _music.s < prev    next >
Text File  |  1992-02-21  |  89KB  |  4,370 lines

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