Difference between revisions of "Z80 Routines:Sound:Beep"

From WikiTI
Jump to: navigation, search
m (removed 'error' label)
(83+, final output, stuff)
Line 9: Line 9:
 
; c=frequency, b=duration
 
; c=frequency, b=duration
 
beep: di
 
beep: di
ld e,$D0
+
ld e,INIT
 
beepl1: ld a,c
 
beepl1: ld a,c
 
beepl2: dec a
 
beepl2: dec a
Line 18: Line 18:
 
out (0),a
 
out (0),a
 
djnz beepl1
 
djnz beepl1
 +
ld a,INIT ; you may be able to omit
 +
out (0),a ; these two lines
 
ei
 
ei
 
         ret</nowiki>
 
         ret</nowiki>
 +
 +
== Notes ==
 +
 +
* On the TI-83, INIT = 0D0h.  On the TI-83 Plus, INIT = 0.
 +
* You may omit the final output if you make sure to always pass an even value for B.  Otherwise you risk leaving the link port active.
 +
* Remember that using port 0 also affects the memory mapping on the TI-83.
 +
* On the TI-83 Plus SE and TI-84 Plus, you may need to [[83Plus:Ports:08|disable the hardware assist]] and [[83Plus:Ports:20|slow the CPU clock]] as well.
 +
 +
== See Also ==
 +
 +
* [[83:Ports:00]]
 +
* [[83Plus:Ports:00]]

Revision as of 17:07, 13 July 2005


By Joe Wingbermuehle (joewing@calc.org). This routine was written for the ZLib library for the SOS shell.

;---------= Make a sound =---------
; c=frequency, b=duration
beep:	di
	ld	e,INIT
beepl1:	ld	a,c
beepl2:	dec	a
	jr	nz,beepl2
	ld	a,e
	xor	%00000011
	ld	e,a
	out	(0),a
	djnz	beepl1
	ld	a,INIT	; you may be able to omit
	out	(0),a	; these two lines
	ei
        ret

Notes

  • On the TI-83, INIT = 0D0h. On the TI-83 Plus, INIT = 0.
  • You may omit the final output if you make sure to always pass an even value for B. Otherwise you risk leaving the link port active.
  • Remember that using port 0 also affects the memory mapping on the TI-83.
  • On the TI-83 Plus SE and TI-84 Plus, you may need to disable the hardware assist and slow the CPU clock as well.

See Also