; FILENAME      J31CAL.ASM
; DESCRIPTION   SOUND SUBROUTINE FOR BASIC CALL
; HARDWARE      JAZZ31
; ASSEMBLER     SXA51
; START-DATE    14/10/91
; COMPANY       SILA RESEARCH CO.,LTD.

         ORG    9000H
CONB     EQU    0F801H

; ********** SOUND SUB ********** 
; SOUND GENERATOR
; IN  = 18H FREQUENCY
;     = 19H LENGTH
; REG = A,R2,R3,R4,R5,DPTR

SOUND:   SETB   RS0               ;SELECT REG BANK-3
         SETB   RS1
         MOV    R2,18H
         MOV    R3,19H
         MOV    R5,#0             ;END FLAG
         MOV    R4,#80H           ;DELAY CONSTANT
SOUND1:  LCALL  SOUNDS
         CJNE   R5,#1,SOUND1
         CLR    RS0               ;SELECT REG BANK-0
         CLR    RS1
         RET

SOUNDS:  MOV    DPTR,#CONB        ;OUT 1 (PORTB BIT3)
         MOVX   A,@DPTR
         ORL    A,#08H
         MOVX   @DPTR,A
         LCALL  SOUNDX
         MOV    DPTR,#CONB        ;OUT 0
         MOVX   A,@DPTR
         ANL    A,#0F7H
         MOVX   @DPTR,A
         LCALL  SOUNDX
         RET

SOUNDX:  MOV    A,R2              ;FREQUENCY DELAY
SOUNDX1: LCALL  SOUNDY
         DEC    A
         JNZ    SOUNDX1
         RET

SOUNDY:  DJNZ   R4,SOUNDY1        ;LENGTH COUNT DOWN
         MOV    R4,#80H
         DJNZ   R3,SOUNDY1
         MOV    R5,#1
SOUNDY1: RET

         END

