A86: PlayTone routine


[Prev][Next][Index][Thread]

A86: PlayTone routine




I don't have Sound Demo v1.0 working as of yet. However, here is the
PlayTone routine.
 You can also disable interrupts before calling the routine, that should
speed it up (improve the sound).

BTW, Please do not upload this to TICALC.ORG.

Example of it's use:

 ld c, $10
 ld hl, 5500
 call PlayTone

#define   MONO          %11000000        ;Turns on both red and white wires
#define   OFF       %11111100        ;Turns off both red and white wires
#define   LINK_PORT     7          ;address of com port

;---------------------------------------------------------------------------
--------------------
;
; PLAYTONE - Plays a tone
;
; Input:
;   C = Frequency (Pitch of Sound, up to 255 where 255 is the lowest pitch)
;   HL = Duration (Length of Tone, up to 65,535)
;
; Output:
;
;---------------------------------------------------------------------------
--------------------

PlayTone:

  dec HL

  xor a     ; Clear a
  cp h     ; Check if H is 0
  jr nz, Speaker_OFF

  xor a     ; Clear A
  cp l     ; Check if L is 0

  ret z           ; Both H and L were zero, so HL = 0 and now we return

Speaker_OFF:
     ld    A, OFF
     out   (LINK_PORT), A   ; Turn off both red and white wires

  ld b, c
Delay1: djnz  Delay1           ; The larger B is, the higher the delay thus
the lower the frequency

Speaker_ON:
     ld  A, MONO    ; Turn on both red and white wires
     out (LINK_PORT), A


  ld b, c
Delay2: djnz  Delay2           ; The larger B is, the higher the delay thus
the lower the frequency

  jp PlayTone

;---------------------------------------------------------------------------
----------------------------



-Matt
http://www.dogtech.com/cybop/ti86/



Follow-Ups: