
TITLE ELEPIANO -- Electric piano
;This procedure makes the computer keyboard function
;Like a two_octave piano keyboad
;To play a lower_octave natural note,
;  press a number kry (1--7)
;To play an upper_octave natural note,
;  hold shift down and press a number key (1_7)
;To play a sharp or flat,press the a or b key
;  and then the number key(1-7)
;To exit,press return
;--------------------------------------------------
      extrn gensound:far
stack segment para stack 'stack'
	db 64 dup('stack...')
stack ends
;--------------------------------------------------
dseg segment para 'data'
l_nat   dw   131,147,165,175,196,220,247
u_nat   dw   262,294,330,349,392,440,494
l_sha   dw   139,156,175,185,208,233,262
u_sha   dw   277,311,349,370,415,466,523
l_fla   dw   123,139,156,165,185,208,233
u_fla   dw   247,277,311,330,370,415,466
dseg ends
;--------------------------------------------------
cseg segment para 'code'
play proc far
     assume cs:cseg, ds:dseg, ss:stack
	push	ds	      ;eor return to DOS
	sub	ax,ax
	push	ax
	mov	ax,dseg	      ;initialize the data
	mov	ds,ax	      ;  segment addr.
new_note:
	mov	ah,0	      ;read the next key
	int	16h
	cmp	al,0dh	      ;is it return?
	jne	lwr_flt
	ret		      ;exit
lwr_flt:sub	si,si
	cmp	al,'b'
	jne	upr_flt
	lea	bx,l_fla  ;possible lower octave flat 
get_lc: mov	ah,0
	int	16h
	jmp	short chk_lo
upr_flt:cmp	al,'B'
	jne	lwr_shp
	lea	bx,u_fla  ;possible upper octave flat
get_uc:	mov	al,0
	int	16h
	jmp	short chk_uo
lwr_shp:cmp	al,'a'
        jne 	upr_shp
	lea	bx,l_sha  ;possible lower octave sharp
	jmp	short get_lc
upr_shp:cmp	al,'A'
	jne	lwr_nat
	lea	bx,u_sha  ;possible upper octave sharp
	jmp	short get_uc
lwr_nat:cmp	al,'1'
	jb	upr_nat
	cmp	al,'7'
	ja	upr_nat
	lea	bx,l_nat
	jmp	short new_frq
upr_nat:lea	bx,u_nat
	jmp	short chk_uo
;check whether the key selects lower octave(1-7)
chk_lo:	cmp	al,'1'
	jb	new_note
	cmp	al,'7'
	ja	new_note
	jna	new_frq
;check whether the key selects upper
;  octave (shift_'1'-'7')
chk_uo:	cmp	al,'!'
	jb	new_note
	cmp	al,'%'
	jna	new_frq
	cmp	al,'&'
	jne	again
	add	al,1	     ;convert "&" to index 7
	jmp	new_frq
again:	cmp	al,'@'
	jne	next
	add	al,2	     ;convert "@" to index 2
	jmp	new_frq
next:	cmp	al,'^'
	jne	new_note
;look_up a freq and call gensound to 
;  play the note for 0.01 second
new_frq:and	ax,07h
	shl	ax,1
	sub	ax,2
	mov	si,ax	       ;an index in SI
	mov	di,[bx][si]    ;get a freq to DI
	mov	bx,10	       ;for 0.01 second
	call	gensound       ;play the note
	jmp	new_note       ;next key code
play	endp
cseg	ends
;--------------------------------------------------
	end	play
