; Edit version 1.02 ;************************************************************************** ;************************************************************************** ;*** *** ;*** Main MusicBox Note Generator. *** ;*** *** ;************************************************************************** ;************************************************************************** ; ; File Name : ZMUSIC.Z80 ; Library Name : MUSICBOX.LBR ; Module Build File : MUSICBOX.ZEX ; Author : Edmund Cramp ; Creation Date : 28-Sep-1985 ; ; Assembler Name : Z80ASM (SLR Systems) ; Linker Name : SLRNKP (SLR Systems) ; ; Ammendment Record ; ***************** ; Name Date Details of Ammendment ; ---- ---- --------------------- ; Edmund Cramp 28-Sep-1985 Initial creation from Dr. Dobbs Vol 1-9. ; Edmund Cramp 17-Apr-1987 Modified for ZAS/ZLINK. ; Edmund Cramp 18-Apr-1987 Enhanced to demonstrate SYSLIB,Z3LIB,VLIB. ; Edmund Cramp 19-Mar-1988 Modified for SLR assember/linker. ; ; Module Function ; *************** ; Music Program from Dr. Dobbs. This originally appeared in the ; February issue of 1976 and was written for either an ALTAIR or IMSAI ; by Steven Dompier (if my memory serves me well). Any further input on ; the history of this program would be welcome. ; This version requires that the ZCPR library VLIB be available. It ; can be assembled and linked with the SLR assember and linker. ; ;************************************************************************** TITLE 'ZCPR3 Version of Dr Dobbs Music Box' NAME ZMUSIC ; =============== ; Global symbols. ; =============== PUBLIC CVERS,STACK,Z3ENV ; =================== ; External Referances ; =================== EXTRN QUIT,INITENV,CHECKBD ; ============== ; External Files ; ============== MACLIB MACROS.LIB ; Macro library ; ============ ; Local Macros ; ============ ; n o n e ; ============= ; Local Equates ; ============= VERSION: EQU 100 ; Internal version number. BYTE: EQU 1 WORD EQU BYTE*2 ;************************************************************************** ;*** Start of Music Program *** ;************************************************************************** CSEG DEFB 'Z3ENV',01 ; ZCPR3 ext env id string. Z3ENV: DEFW 0000 ; Environment pointer. ; CVERS: MVERSN ; Embed program version number ; MUSIC: LD (STACK),SP ; Save BDOS stack LD SP,STACK ; Setup a local stack. ; CALL INITENV ; Initialise our local environment. ; START: CALL CHECKBD ; Check keyboard for abort. ; ; Initialise song pointer LD HL,(SONG) ; Address of the first note. ; AGAIN: LD A,(HL) ; Retrieve note to be played. CP 0FFH ; Test for End-of-Tune. JR Z,START ; Branch if done. ; ; Note loop ... ; Reg HL points to note. ; Reg B is the tempo counter (outer loop). ; Reg C is used as a loop counter. ; LD A,(TEMPO) ; Retrive music tempo constant LD B,A ; Preset tempo counter. LD C,0 ; Preset 256 counter. LD A,(HL) ; Retrieve note to be played. ; LOOP: EX (SP),HL ; A delay... EX (SP),HL ; ... DEC A ; Decrement note... JP NZ,SKIP ; ...branch if NZ. LD A,(HL) ; Reload note value. ; SKIP: DEC C ; Decrement 256 count... JP NZ,LOOP ; ...branch until done. ; DEC B ; Decrement tempo counter... JP NZ,LOOP ; ...until done. ; Done. INC HL ; Bump pointer to next note. JR AGAIN ; Branch to get next note (if any). COMMON /AREA/ TEMPO: DEFS BYTE ; Tempo value. DEFS WORD ; Pointer to song title string. SONG: DEFS WORD ; Pointer to start of song notes. DSEG DEFS 100*2 ; Reserve 100 words for stack STACK DEFW 0000 ; O/S Stack storage. END MUSIC