; Edit version 1.08 ;************************************************************************** ;************************************************************************** ;*** *** ;*** Main MusicBox Note Generator. *** ;*** *** ;************************************************************************** ;************************************************************************** ; ; File Name : MUSIC.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 20-Mar-1988 Modified for SLR assember and 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) - however it works well ; with any 8080 or Z80 (and probably 64180) computer. Any further input on ; the history of this program would be welcome. ; This version does not require the Echelon libraries (VLIB, Z3LIB and ; SYSLIB) and can be assembled and linked with the SLR Z80ASM/SLRNKP tools ; to produce a program that will run on any CP/M based computer. ; ;************************************************************************** TITLE 'Dr Dobbs Music Box' NAME MUSIC ; =============== ; Global symbols. ; =============== ; n o n e ; =================== ; External Referances ; =================== EXTRN BDOS,RESTART ; ============== ; External Files ; ============== MACLIB MACROS.LIB ; Macro library ; ============ ; Local Macros ; ============ ; n o n e ; ============= ; Local Equates ; ============= BYTE EQU 1 WORD EQU BYTE*2 ;************************************************************************** ;*** Start of Music Program *** ;************************************************************************** COMMON /AREA/ SPEED: DEFS BYTE ; Song tempo value. DANAME: DEFS WORD ; Title string pointer. NOTES: DEFS WORD ; Start of song pointer. CSEG MUSIC: LD HL,(DANAME) ; Get address of string. EX DE,HL ; Print the songs title on the Console LD C,9 ; BDOS print string function. CALL BDOS ; PRINT MESSAGE ; Send the message to the console ; ; Read a "note" from the "score" ; LD HL,(NOTES) ; Get address of first note ; NEXT: LD A,(HL) ; Read a note. CP 0FFH ; Test for end of tune JP NZ,START ; Play the tune... ; ; End of the tune ... repeat unless we get a ^C from console ; Look for a ^C from the keyboard to abort. ; LD C,6 ; Direct BIOS i/o LD E,0FFH ; input CALL BDOS ; Get the character CP 3 ; Is it ^C ? JP Z,RESTART ; Exit only if Control C is hit. ; ; Play it again Sam... ; LD HL,(NOTES) ; Address of the "tune". START: LD A,(SPEED) ; Musical tempo for song... LD B,A ; ...will be saved in Reg B LD C,0 ; Clear counter. LD A,(HL) ; Retrive note to be played ; LOOP: EX (SP),HL ; ...delay... EX (SP),HL ; DEC A ; JP NZ,SKIP ; LD A,(HL) ; SKIP: DEC C ; JP NZ,LOOP ; DEC B ; JP NZ,LOOP ; INC HL ; JP NEXT ; Get next note DSEG MESSAGE: STRING 'Hit ^C to exit at the end of the song' END MUSIC