; Title - Happy Birthday Music
; For Bally Arcade/Astrocade
; Birthday Fix-Up by "hxlnt"
; Posted to AtariAge forums on Mon Jan 22, 2018 9:11 PM
;
; "hxlnt" wrote:
; "Speaking of sound, I noticed a request on the Bally Alley website to
; clean up some of the notes in the Happy Birthday music [1.0] demo [by
; Adam Trionfo], so I took a shot at it. Here's my version."
; 
; Here is a link to the original message:
; http://atariage.com/forums/topic/ [... URL broken into two lines] 
; 251416-programming-the-bally-arcadeastrocade/page-2#entry3942403

MUSSTK  EQU     $4F12            ; Music Stack Pointer

        INCLUDE "HVGLIB.H"

        ORG     $2000            ; First byte of Cartridge

        DB      "U"              ; User System Sentinel

        DW      MENUST           ; Next menu link
        DW      PRGNAM           ; Address of title for program
        DW      PRGST            ; Jump here if prog is selected

; Main Program
PRGST:  DI
        SYSTEM  (INTPC)
        ;
        DO      (SETOUT)         ; UPI - Set Display Ports 
        DB      90*2             ; ... Vertical Blanking Line (Line 90)
        DB      44               ; ... Left/Right Color Boundary
        DB      $08              ; ... Interrupt Mode
        ;
        DO      (COLSET)         ; UPI - Set Color Registers
        DW      COLTAB           ; ... Color Table
        ;
        DO      (FILL)           ; UPI - Screen Fill
        DW      NORMEM           ; ... Destination
        DW      4000D            ; ... Bytes to move
        DB      $00              ; ... Background color
        ;
        DO      (STRDIS)         ; UPI - Display String
        DB      10               ; ... X coordinate
        DB      30               ; ... Y coordinate
        DB      01101000B        ; ... Options (2x X-OR Write in Color 2)
        DW      STRING           ; ... Address of string to display
        ;
        DO     (ACTINT)          ; UPI - ACTivate sub timer INTerrupts
        ;
        DO      (BMUSIC)         ; UPI - Begin Playing "Happy Birthday" Music
        DW      MUSSTK           ; ... Music Stack
        DB      11000000B        ; ... Setup Voices, Use Tone A
        DW      BDAY             ; ... Music Score for "Happy Birthday"
        ;
        EXIT

LOOP:   NOP
        JP      LOOP             ; Infinite loop

; Color Table #1
COLTAB: DB      $00              ; Color 3 Left  - Black
        DB      $5A              ; Color 2 Left  - Red
        DB      $77              ; Color 1 Left  - Yellow
        DB      $07              ; Color 0 Left  - White
        DB      $00              ; Color 3 Right - Black
        DB      $5A              ; Color 2 Right - Red
        DB      $77              ; Color 1 Right - Yellow
        DB      $07              ; Color 0 Right - White

PRGNAM: DB      "HAPPY BIRTHDAY      (120 BPM)",0

STRING: DB      "  HAPPY    BIRTHDAY!",0

; "Happy Birthday" Music Score 
; 1/8 Note = 15          1/2 Note  = 60
; 1/4 Note = 30          Full Note = 120
BDAY:   
        ; Happy birthday to you      
        MASTER  OA1              ; Master Oscillator (User HVGLIB.H Note Value)
        VOLUME  $0A, $00         ; Set Volumes TONE A = 10, Tone B = 0, and Tone C = 0
        NOTE1   15,G5            ; 1/8 Note
        LEGSTA                   ; Turn on LEGATO
        NOTE1   15,G5            ; 1/8 Note 
        NOTE1   30,A5            ; 1/4 Note
        NOTE1   30,G5            ; 1/4 Note 
        MASTER  OA3              
        NOTE1   30,C4            ; 1/4 Note
        NOTE1   30,B3            ; 1/2 Note
        LEGSTA                   ; Turn off LEGATO
        MASTER  OA2
        VOICEM  11110000B        ; Set Voices, Use Tones A and B
        VOLUME  $AA,$00          ; Set Volumes, Tone A = 10, Tone B = 10, and Tone C = 0
        NOTE2   30,F4,G4         ; 1/4 Note

        ; Happy birthday to you
        VOICEM  11000000B        ; Set Voices, Use Tone A
        VOLUME  $0A, $00         ; Set Volumes
        MASTER  OA1              
        NOTE1   15,G5            ; 1/8 Note
        LEGSTA                   ; Turn on LEGATO
        NOTE1   15,G5            ; 1/8 Note
        NOTE1   30,A5            ; 1/4 Note          
        NOTE1   30,G5            ; 1/4 Note
        MASTER  OA3
        NOTE1   30,D4            ; 1/4 Note
        MASTER  OA2
        NOTE1   30,C5            ; 1/4 Note
        LEGSTA                   ; Turn off LEGATO
        VOICEM  11110000B        ; Set Voices, Use Tones A and B
        VOLUME  $AA,$00          ; Set Volumes, Tone A = 10, Tone B = 10, and Tone C = 0
        NOTE2   30,E4,G4         ; 1/4 Note

        ; Happy birthday, dear _____
        VOICEM  11000000B        ; Set Voices, Use Tone A
        VOLUME  $0A, $00         ; Set Volumes, TONE A = 10, Tone B = 0, and Tone C = 0
        MASTER  OA1
        NOTE1   15,G5            ; 1/8 Note
        LEGSTA                   ; Turn on LEGATO
        NOTE1   15,G5            ; 1/8 Note
        MASTER  OA3
        NOTE1   30,G4            ; 1/4 Note               
        NOTE1   30,E4            ; 1/4 Note
        MASTER  OA2
        NOTE1   30,C5            ; 1/4 Note
        MASTER  OA3             
        NOTE1   30,B3            ; 1/4 Note
        NOTE1   30,A3            ; 1/4 Note
        LEGSTA                   ; Turn off LEGATO

        ; Happy birthday to you
        VOICEM  11110000B        ; Set Voices, Use Tones A and B
        VOLUME  $AA,$00          ; Set Volumes, Tone A = 10, Tone B = 10, and Tone C = 0
        NOTE2   15,F4,A4         ; 1/8 Notes
        VOICEM  11000000B        ; Set Voices, Use Tone A
        VOLUME  $0A,$00          ; Set Volumes, TONE A = 10, Tone B = 0, and Tone C = 0
        NOTE1   15,F4            ; 1/8 Note
        LEGSTA                   ; Turn on LEGATO
        VOICEM  11110000B        
        VOLUME  $AA,$00          
        NOTE2   30,E4,G4         
        NOTE2   30,C4,G4        
        NOTE2   30,B3,D2         
        MASTER  OA2              
        VOICEM  11000000B        
        VOLUME  $0A,$00          
        NOTE1   30,C5            
        VOLUME  $AA,$00          
        VOICEM  11110000B        
        NOTE2   15,E4,G4         

        QUIET