home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / UTILITYS / SOUNDS.ARC / SPLAY.MAC < prev    next >
Text File  |  1987-10-31  |  4KB  |  228 lines

  1.      .radix    0ah
  2.     aseg
  3.     .z80
  4.     title    MultiLength Sound replayer
  5.     org    100h
  6.  
  7.     jp    start
  8.  
  9. our_fcb:    ds    36        ;room for fcb.
  10.  
  11.         include        EQUATES.MAC
  12.  
  13.     
  14. ;bdos:        equ    5
  15. cr        equ    13
  16. lf        equ    10
  17. esc        equ    27
  18.  
  19. stop_bit    equ    0
  20. start_bit    equ    1
  21. default_fcb    equ    05ch
  22.  
  23. ;---------------------------------
  24. ;    Text messages
  25.  
  26. start_msg:
  27.         db    'MultiLength sound replayer',cr,lf
  28.         db    '$'
  29. playing:    db    'Playing....',cr,lf
  30.         db    '$'
  31. length_record:    db    'Sound recorded occupies $'
  32. length_record2:    db    ' bytes in memory',cr,lf,'$'
  33. disk_err:    db    'Disk Error- file not loaded',cr,lf,'$'
  34.  
  35. ;----------------------------------
  36. ;    subroutines
  37.  
  38. bdos:    push    hl
  39.     push    de
  40.     push    bc
  41.     call    5
  42.     pop    bc
  43.     pop    de
  44.     pop    hl
  45.     ret
  46.  
  47. ;
  48. ; DECIMAL PRINT ROUTINE
  49. ; NUMBER TO PRINT IN HL REGISTER
  50. ;
  51. ODEC:    PUSH AF        ; SAVE
  52.     PUSH BC        ;
  53.     PUSH DE        ;
  54.     LD   IX,TENS    ; POINTER TO POWERS OF TEN
  55.     LD   B,5    ; FIVE DIGITS
  56.     LD   C,'0'    ; use C as leading zero flag
  57. ;
  58. LOOP:    LD   A,2FH    ; ASCII ZERO - 1
  59.     LD   E,(IX+0)    ; GET LOW BYTE
  60.     LD   D,(IX+1)    ; GET HIGH BYTE
  61. LOOP1:  AND  A        ; CHEAR CARRY
  62.     SBC  HL,DE    ; SUBTRACT DECADE
  63.     INC  A        ; INCREASE DIGIT
  64.     JR   NC,LOOP1    ; NOT NEGATIVE YET
  65.     ADD  HL,DE    ;  OK, RESTORE NO
  66.     CP   '0'    ; IS IT A ZERO ?
  67.     JR   Z,ZERO    ; YES DO LEADING ZERO TEST
  68.     LD   C,A    ; NO REMOVE SUPRESSION
  69. ODEC1:    PUSH BC        ; SAVE COUNT
  70.     LD   B,A    ; print needs it in B
  71.         CALL  VDU       ; PRINT
  72.     POP   BC    ; RESTORE COUNT
  73.     INC   IX    ; POINT TO NEXT
  74.     INC   IX    ; DECADE VALUE
  75.     DJNZ  LOOP    ; DO IT 5 TIMES
  76.     POP DE        ; RESTORE REGISTERS
  77.     POP BC        ;
  78.     POP AF        ;
  79.         RET        ; FINISHED
  80. ;
  81. ZERO:    CP   C        ; If A = '0' AND C = '0'
  82.     JR   NZ,ODEC1    ; IF NOT PRINT ZERO
  83.     LD   A,B    ; TEST COUNTER
  84.     CP   1        ; TO SEE IF LAST DIGIT
  85.     LD   A,'0'    ; RESTORE A
  86.     JR   Z,ODEC1    ; LAST DIGIT,PRINT '0'
  87.     LD   A,' '    ; IF TRUE PRINT SPACE
  88.     JR   ODEC1;
  89. ; Table for conversion to decimal
  90. ;
  91. TENS:   DEFW  10000
  92.     DEFW  1000
  93.     DEFW  100
  94.     DEFW  10
  95.     DEFW  1
  96. ;
  97. ; Carriage Return  Line Feed Routine
  98. ; called CRLF.
  99. ; no registers are changed.
  100. ;
  101. CRLF:    PUSH BC        ; Save BC.
  102.     LD   B,0DH    ; CR
  103.     CALL VDU    ; do it
  104.     LD   B,0AH    ; LF
  105.     CALL VDU    ; do it
  106.     POP  BC        ; Restore BC
  107.     RET        ; Thats All !!
  108.  
  109. vdu:    push    de
  110.     ld    e,b
  111.     ld    c,wr_con
  112.     call    bdos
  113.     pop    de
  114.     ret
  115. ;--------------------------------
  116. ;    program code
  117.  
  118. start:    ld    de,start_msg
  119.     ld    c,print_buf
  120.     call    bdos
  121. ;init_pio:
  122.     ld    a,11001111b    ;set up port for control
  123.     out    (1),a
  124.     ld    a,00000011b    ;bits 0,1 inputs, rest outputs 
  125.     out    (1),a
  126.  
  127.     ld    hl,default_fcb
  128.     ld    de,our_fcb
  129.     ld    bc,12
  130.     ldir            ;copy the fcb
  131.  
  132.     ld    hl,our_fcb+12
  133.     ld    de,our_fcb+13
  134.     ld    (hl),0
  135.     ld    bc,23
  136.     ldir
  137.  
  138.     ld    de,our_fcb    ;now try to open the relevant file
  139.     ld    c,open_fil
  140.     call    bdos
  141.     cp    255        ;disk stuff_up?
  142.     jr    z,no_file
  143.  
  144.     ld    de,play
  145. load_sound:
  146.     ld    c,set_dma
  147.     call    bdos        ;set write address
  148.     push    de
  149.     ld    de,our_fcb
  150.     ld    c,rd_seq
  151.     call    bdos
  152.     pop    de
  153.     ld    hl,80h
  154.     add    hl,de
  155.     ex    de,hl        ;inc dma address to next sector
  156.     or    a
  157.     jr    z,load_sound    
  158.  
  159.     ld    de,our_fcb
  160.     ld    c,close_fil
  161.     call    bdos
  162.  
  163.     ld    de,length_record    ;how long is it?
  164.     ld    c,print_buf
  165.     call    bdos
  166.     ld    hl,(play)
  167.     call    odec
  168.     ld    de,length_record2
  169.     ld    c,print_buf
  170.     call    bdos
  171.  
  172.     ld    de,playing
  173.     ld    c,print_buf
  174.     call    bdos
  175.  
  176.     ld    hl,(play)    ;length goes in record buffer start.
  177.     ld    b,h
  178.     ld    c,l        ;length to bc.
  179.     ld    hl,play+2
  180. main_play:
  181.     push    bc
  182.     ld    b,7        ;count bits thru cass.
  183.     ld    c,(hl)        ;start with clean accumulator
  184. play_loop:
  185.     rl    c        ;get bit out
  186.     rra
  187.     rra            ;into speaker bit
  188.     out    (2),a
  189.     ld    a,11
  190. here:    dec    a
  191.     jr    nz,here
  192.     ld    a,0    
  193.     djnz    play_loop
  194.     rl    c
  195.     rra
  196.     rra
  197.     out    (2),a
  198.     pop    bc        ;restore loop count before quitting    
  199.     ld    a,8
  200. here2:    dec    a
  201.     jr    nz,here2
  202.     inc    hl
  203.     inc    de
  204.     dec    bc        ;count down length
  205.     ld    a,b
  206.     or    c
  207.     jr    nz,main_play
  208.  
  209.     jr    done
  210.  
  211. no_file:
  212.     ld    de,our_fcb
  213.     ld    c,close_fil
  214.     call    bdos
  215.     ld    c,del_fil
  216.     call    bdos
  217.     ld    de,disk_err
  218.     ld    c,print_buf
  219.     call    bdos
  220.  
  221. done:    ld    a,00001111b        ;reset pio to output
  222.     out    (1),a
  223.     jp    sys_rst            ;program done
  224.  
  225. play    equ    $
  226.  
  227.     end
  228.