home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 556b.lha / DiamondQuest_v1.1 / Voice / voice.asm < prev    next >
Assembly Source File  |  1991-09-17  |  6KB  |  336 lines

  1.  
  2.  nol
  3.  
  4.  INCLUDE "exec/types.i"
  5.  INCLUDE "exec/ports.i"
  6.  INCLUDE "exec/io.i"
  7.  INCLUDE "libraries/dosextens.i"
  8.  INCLUDE "exec/memory.i"
  9.  INCLUDE "devices/audio.i"
  10.  
  11.  xref _AbsExecBase
  12.  xref _BeginIO
  13.  xref _LVOAddPort
  14.  xref _LVOAllocMem
  15.  xref _LVOAllocSignal
  16.  xref _LVOCheckIO
  17.  xref _LVOClose
  18.  xref _LVOCloseDevice
  19.  xref _LVOCloseLibrary
  20.  xref _LVODoIO
  21.  xref _LVOFindPort
  22.  xref _LVOFindTask
  23.  xref _LVOFreeMem
  24.  xref _LVOFreeSignal
  25.  xref _LVOGetMsg
  26.  xref _LVOOpen
  27.  xref _LVOOpenDevice
  28.  xref _LVOOpenLibrary
  29.  xref _LVOOutput
  30.  xref _LVOPutMsg
  31.  xref _LVORead
  32.  xref _LVORemPort
  33.  xref _LVOReplyMsg
  34.  xref _LVOSendIO
  35.  xref _LVOWait
  36.  xref _LVOWaitIO
  37.  xref _LVOWaitPort
  38.  xref _LVOWrite
  39.  
  40.  list
  41.  
  42.  movea.l #intname,a1
  43.  moveq #31,d0
  44.  movea.l 4,a6
  45.  jsr _LVOOpenLibrary(a6)
  46.  move.l d0,intbase
  47.  beq abort
  48.  movea.l #dosname,a1
  49.  moveq #0,d0
  50.  movea.l 4,a6
  51.  jsr _LVOOpenLibrary(a6)
  52.  move.l d0,dosbase
  53.  beq abort
  54.  movea.l #grname,a1
  55.  moveq #0,d0
  56.  movea.l 4,a6
  57.  jsr _LVOOpenLibrary(a6)
  58.  move.l d0,grbase
  59.  beq abort
  60.  
  61.   movea.l dosbase,a6  ; get output handle
  62.   jsr _LVOOutput(a6)
  63.   move.l d0,writehandle
  64.  
  65.   lea msg0,a0
  66.   move.l #msglen0,d3
  67.   bsr CKirjoita
  68.  
  69.  
  70.  bsr init_audio
  71.  tst.l d0
  72.  beq abort
  73.   lea msg3,a0
  74.   move.l #msglen3,d3
  75.   bsr CKirjoita
  76.  bsr do_voice
  77.   lea msg4,a0
  78.   move.l #msglen4,d3
  79.   bsr CKirjoita
  80.  bsr free_audio
  81.   lea msg5,a0
  82.   move.l #msglen5,d3
  83.   bsr CKirjoita
  84.  
  85. abort
  86.  rts
  87.  
  88. init_audio
  89.  
  90.  move.l #ioa_SIZEOF,d0
  91.  move.l #(MEMF_CLEAR!MEMF_CHIP),d1
  92.  move.l 4,a6
  93.  jsr _LVOAllocMem(a6)
  94.  move.l d0,aumsg
  95.  beq ei_chip_muistia
  96.  
  97.  move.l #10000,d0
  98.  move.l #MEMF_CHIP,d1
  99.  move.l 4,a6
  100.  jsr _LVOAllocMem(a6)
  101.  move.l d0,audiodata
  102.  beq ei_chip_muistia
  103.  bsr Lataa
  104.  
  105.  move.l aumsg,a1
  106.  lea allocbits,a0
  107.  move.l a0,ioa_Data(a1)
  108.  move.l #4,ioa_Length(a1)
  109.  move.l #0,MN_REPLYPORT(a1)
  110.  move.b #127,LN_PRI(a1)
  111.  move.b #ADIOF_NOWAIT,IO_FLAGS(a1)
  112.  
  113.  lea audioname,a0
  114.  moveq #0,d0
  115.  moveq #0,d1
  116.  move.l 4,a6
  117.  jsr _LVOOpenDevice(a6)
  118.  tst.l d0
  119.  bne ei_audiota
  120.  
  121.  move.l aumsg,a0
  122.  move.l IO_UNIT(a0),unit
  123. ; move.l #0,MN_REPLYPORT(a0)
  124.  move.l IO_DEVICE(a0),audev
  125.  move.l ioa_AllocKey(a0),allockey
  126.  moveq #-1,d0
  127. init_audio_pois
  128.  rts
  129.  
  130. ei_audiota
  131.   lea msg1,a0
  132.   move.l #msglen1,d3
  133.   bsr CKirjoita
  134.   moveq #0,d0
  135.   bra.s init_audio_pois
  136.  
  137. ei_chip_muistia
  138.   lea msg2,a0
  139.   move.l #msglen2,d3
  140.   bsr CKirjoita
  141.   moveq #0,d0
  142.   bra.s init_audio_pois
  143.  
  144. voice_out
  145.  ; annetaan a0:ssa osoite messagedataan
  146.  moveq #13,d1
  147.  move.l aumsg,a1
  148. voice_out_loop
  149.  move.b 0(a0,d1.w),ioa_Data(a1,d1.w)
  150.  dbra d1,voice_out_loop
  151.  
  152. ; move.l audiodata,ioa_Data(a1)
  153. ; move.w allockey,ioa_AllocKey(a1)
  154.  move.w #CMD_WRITE,IO_COMMAND(a1)
  155. ; move.l unit,IO_UNIT(a1)
  156.  move.b #(ADIOF_NOWAIT!ADIOF_PERVOL),IO_FLAGS(a1)
  157.  
  158.   lea msg6,a0
  159.   move.l #msglen6,d3
  160.   bsr CKirjoita
  161.  move.l 4,a6
  162.  move.l aumsg,a1
  163.  move.l a1,-(sp)
  164.  jsr _BeginIO
  165.  move.l (sp)+,a1
  166.   lea msg7,a0
  167.   move.l #msglen7,d3
  168.   bsr CKirjoita
  169.  
  170.  rts
  171.  
  172. do_voice
  173.  lea voice1,a0
  174.  bsr voice_out
  175.  move.l #100,d7
  176.  move.l #100,d0
  177. do_loop
  178. ; move.l aumsg,a1
  179. ; move.l 4,a6
  180. ; jsr _LVOCheckIO(a6)
  181.  move.l aumsg,a1
  182.  move.w allockey,ioa_AllocKey(a1)
  183.  move.w #CMD_READ,IO_COMMAND(a1)
  184.  move.b #IOF_QUICK,IO_FLAGS(a1)
  185.  move.l unit,IO_UNIT(a1)
  186.  move.l 4,a6
  187.  jsr _LVODoIO(a6)
  188.   move.l d0,d2
  189.   bsr modify
  190.   move.l a5,addr
  191.   move.l #10,lenght
  192.   bsr type
  193.  dbra d7,do_loop
  194. do_voice_loop
  195.  move.l aumsg,a1
  196.  move.l 4,a6
  197.  jsr _LVOCheckIO(a6)
  198.  tst.l d0
  199.  ;bne do_voice_loop
  200.  rts
  201.  
  202. free_audio
  203.  move.l aumsg,a1
  204. ; move.w allockey,ioa_AllocKey(a1)
  205.  move.w #ADCMD_FREE,IO_COMMAND(a1)
  206.  move.b #IOF_QUICK,IO_FLAGS(a1)
  207. ; move.l unit,IO_UNIT(a1)
  208.  move.l 4,a6
  209.  jsr _LVODoIO(a6)
  210.  
  211.  move.l aumsg,a1
  212.  move.l 4,a6
  213.  jsr _LVOCloseDevice(a6)
  214.  
  215.  move.l aumsg,a1
  216.  move.l #ioa_SIZEOF,d0
  217.  move.l 4,a6
  218.  jsr _LVOFreeMem(a6)
  219.  move.l audiodata,a1
  220.  move.l #10000,d0
  221.  move.l 4,a6
  222.  jsr _LVOFreeMem(a6)
  223.  rts
  224.  
  225. CKirjoita
  226.   ; viestin osoite a0:ssa
  227.   ; pituus d3:ssa
  228.   move.l a0,d2
  229.   move.l writehandle,d1
  230.   movea.l dosbase,a6
  231.   jsr _LVOWrite(a6)
  232.   rts
  233.  
  234. Lataa
  235.    move.l a6,-(sp)
  236.  
  237.  ; avataan tiedosto
  238.    lea sound,a0
  239.    move.l a0,d1   ; Nimen osoite : name
  240.    move.l #MODE_OLDFILE,d2 ; accessMode
  241.    movea.l dosbase,a6
  242.    jsr _LVOOpen(a6)
  243.    tst.l d0   ; jos tulos on nolla, tiedostoa ei ole
  244.    beq.s lataa_loppu
  245.  
  246.  ; tiedosto saatiin avattua
  247.    move.l d0,filehandle ;tiedoston tunnus muistiin
  248.    move.l d0,d1
  249.    move.l audiodata,d2 ; osoite muistiin, jonne kirjoitetaan : buffer
  250.    move.l #10000,d3 ; muistiblokin koko : length
  251.    movea.l dosbase,a6
  252.    jsr _LVORead(a6)
  253.  
  254.  ; suljetaan tiedosto
  255.    move.l filehandle,d1
  256.    movea.l dosbase,a6
  257.    jsr _LVOClose(a6)
  258.    move.l audiodata,voice1
  259. lataa_loppu
  260.    move.l (sp)+,a6
  261.    rts
  262.  
  263. modify                 ;muutettava luku d2:ssa
  264.  move.l #string,a5     ;merkkijonon osoite, joho luku tulee
  265.  moveq #8,d1
  266. loop
  267.  move.l d2,d0
  268.  lsr.l #4,d2
  269.  bsr.s muuta
  270.  move.b d0,-1(a5,d1.l)
  271.  subi.b #1,d1
  272.  bne loop
  273.  rts
  274. muuta                  ;muutettava luku d0:ssa
  275.  and.b #$f,d0
  276.  or.b #$30,d0
  277.  cmp.b #$3a,d0
  278.  blt pois
  279.  add.b #7,d0
  280. pois
  281.  rts
  282. type
  283.  move.l dosbase,a6
  284.  move.l writehandle,d1
  285.  move.l addr,d2
  286.  move.l lenght,d3
  287.  jsr -48(a6)
  288.  rts
  289.  
  290. intbase     ds.l 1
  291. dosbase     ds.l 1
  292. grbase      ds.l 1
  293. filehandle   dc.l 0
  294. writehandle  dc.l 0
  295.  
  296. audiodata   dc.l 0
  297. audev       dc.l 0
  298. unit        dc.l 0
  299. aumsg       dc.l 0
  300. allockey    dc.w 0
  301. allocbits   dc.b 1,2,4,8
  302.  
  303. voice1
  304.  dc.l 0     ; ioa_Data
  305.  dc.l 8660  ; ioa_Length
  306.  dc.w 300   ; ioa_Period
  307.  dc.w 63    ; ioa_Volume
  308.  dc.w 2     ; ioa_Cycles
  309.  
  310. intname     dc.b 'intuition.library',0
  311. dosname     dc.b 'dos.library',0
  312. grname      dc.b 'graphics.library',0
  313. audioname   dc.b 'audio.device',0
  314. sound       dc.b 'sound',0
  315. string dc.b '********',32,10
  316. addr dc.l 0
  317. lenght dc.l 0
  318.  
  319. msg0       dc.b 'Voice V1.0 © Leo Puolamaa May 1991',$0a
  320. msglen0    equ *-msg0
  321. msg1       dc.b 'audio.device ei avaudu !',$0a
  322. msglen1    equ *-msg1
  323. msg2       dc.b 'MEMF_CHIP loppu !',$0a
  324. msglen2    equ *-msg2
  325. msg3       dc.b 'Audio.device alustettu.',$0a
  326. msglen3    equ *-msg3
  327. msg4       dc.b 'Ääni soitettu.',$0a
  328. msglen4    equ *-msg4
  329. msg5       dc.b 'Audio.device suljettu.',$0a
  330. msglen5    equ *-msg5
  331. msg6       dc.b 'Seuraavaksi kutsutaan _BeginIO...',$0a
  332. msglen6    equ *-msg6
  333. msg7       dc.b '..._BeginIO suoritettu !',$0a
  334. msglen7    equ *-msg7
  335.  end
  336.