Adding music to the title screen

This commit is contained in:
Christophe Meneboeuf 2017-01-17 01:19:33 +01:00
parent 4863e9a9e2
commit 17fa567473
6 changed files with 192 additions and 3 deletions

View File

@ -5,7 +5,7 @@ LINUX_OUT := bin/gol.out
APPLE2_CL := $(CC65_HOME)/bin/cl65
APPLE2_CC := $(CC65_HOME)/bin/cc65
APPLE2_SRC := src/gol_apple2.c src/gol_apple2_optimized.asm src/gfx.asm src/rnd_colors.asm src/file_io.c src/mli.asm
APPLE2_SRC := src/gol_apple2.c src/gol_apple2_optimized.asm src/gfx.asm src/rnd_colors.asm src/file_io.c src/mli.asm src/music.asm
APPLE2_MAP := gol_apple2.map
APPLE2_CFLAGS := -Oirs -v -t apple2
APPLE2_OUT := bin/gol.a2

BIN
disk.dsk

Binary file not shown.

BIN
scripts/Sound_Precalculus.ods Executable file

Binary file not shown.

View File

@ -27,6 +27,7 @@
#include "gfx.h"
#include "rnd_colors.h"
#include "file_io.h"
#include "music.h"
/******************* FUNCTION DEFINITIONS **************/
@ -85,7 +86,6 @@ enum {
static uint8_t Cells[ NB_COLUMNS ][ NB_LINES ];
static uint8_t Cells_Future[ NB_COLUMNS ][ NB_LINES ];
static uint8_t Cells_Initial[ NB_COLUMNS ][ NB_LINES ];
//static uint8_t Title_Screen[ 0x2000 ];
/******************** CODE ************************/
@ -388,6 +388,9 @@ void run( void )
#define SWITCH_FULLSCREEN *((uint8_t*)0xC052)=1
#define SWITCH_PAGE2 *((uint8_t*)0xC055)=1
#define SWITCH_HIRES *((uint8_t*)0xC057)=1
/******* KEYBOARD ***********/
#define CLEAR_KEYBOARD_STROBE *((uint8_t*)0xC010)=1;
#define KEY_PRESSED (*((uint8_t*)0xC000)&0x7F) != 0
//The Title Screen asset is located in the "assets" folder
void title_screen( void )
@ -406,5 +409,37 @@ void title_screen( void )
SWITCH_PAGE2;
SWITCH_HIRES;
cgetc();
CLEAR_KEYBOARD_STROBE
//Playing the music
pause(WHOLE);
if( KEY_PRESSED ) { return; }
note(WHOLE, D4);
note(QUARTER, F4);
note(HALF, G4);
note(QUARTER, As4);
if( KEY_PRESSED ) { return; }
pause(QUARTER);
note(QUARTER, F5);
note(QUARTER, D5);
note(WHOLE, C5);
if( KEY_PRESSED ) { return; }
pause(QUARTER);
note(EIGHTH, As4);
note(EIGHTH, A4);
note(EIGHTH, As4);
note(EIGHTH, A4);
note(EIGHTH, As4);
note(EIGHTH, A4);
note(WHOLE, G4);
if( KEY_PRESSED ) { return; }
pause(EIGHTH);
note(QUARTER, F4);
note(QUARTER, G5);
}

135
src/music.asm Executable file
View File

@ -0,0 +1,135 @@
.include "apple2.inc"
.include "zeropage.inc"
.import popa
.export _note
.export _pause
.DATA
Loops: .byte 149, 141, 133, 125, 118, 111, 105, 99, 94, 88, 83, 78 ;Note loops
Test: .word 31100
;NB nop loops of each note, lasting hal a period
Half_Periods: .byte 251, 237, 224, 211, 199, 188, 177, 167, 158
.byte 149, 140, 132, 125, 118, 111, 105, 99, 93, 88, 83, 78
.byte 74, 69, 65, 62, 58, 55, 52, 49, 46, 43, 41, 38
;NB duration loop for each note to last for 1 second
Durations: .word 311, 330, 349, 370, 392, 415, 440, 466, 494
.word 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988
.word 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976
;Inner and Outer loop of silence to last for 1 second
Silence_Inner: .byte 125
Silence_Outer: .word 622
.ALIGN 256
.CODE
; ******************
; \param idx_note : index of the note to play, used to fetch values in Half_Periods and Durations tables
;void __fastcall__ note( uint8_t nb_shift_duration, uint8_t idx_note )
_note:
;aliases
half_period := tmp1
duration_lo := tmp2
duration_hi := tmp3
;processing parameters
TAX ; idx_note in X
LDA Half_Periods, X
STA half_period
TXA
ASL ;Durations are on 16 bits
TAX
LDA Durations, X
STA duration_lo
LDA Durations+1, X
STA duration_hi
JSR popa ; nb_shift_duration in A
TAY
BEQ end_shift
loop_shift: ;shifting the duration
LSR duration_hi
ROR duration_lo
DEY
BNE loop_shift
end_shift:
;Init loop duration
CLC
LDY duration_lo
INC duration_hi
;Starting to vibe ;)
;These loop should fit in one page to respect the timings
loop_half_period:
LDA $C030 ;4 cycles //SPEAKER
LDX half_period ;3 cycles
loop_nops:
NOP ;2 cycles
NOP ;2 cycles
NOP ;2 cycles
NOP ;2 cycles
DEX ;2 cycles
BNE loop_nops ;3 cycles
;Testing duration loop
DEY ;2 cycles
BNE loop_half_period ;3 cycles
DEC duration_hi ;5 cycles
BNE loop_half_period ;3 cycles
end:
RTS
.ALIGN 256
; ******************
;void __fastcall__ pause( uint8_t nb_shift_duration )
_pause:
;DEBUG:
; CLC
; BCC DEBUG
; ; ++++++ DEBUG
;aliases
pause_lo := tmp2
pause_hi := tmp3
TAY ; duration shift in Y
INY
LDA Silence_Outer
STA pause_lo
LDA Silence_Outer+1
STA pause_hi
DEY
BEQ end_shift_silence
loop_shift_silence: ;shifting the duration
LSR pause_hi
ROR pause_lo
DEY
BNE loop_shift_silence
end_shift_silence:
;Init loop duration
CLC
LDY pause_lo
INC pause_hi
;Starting to be mute
;These loop should fit in one page to respect the timings
loop_silence:
LDX Silence_Inner ;4 cycles
loop_nops_silence:
NOP ;2 cycles
NOP ;2 cycles
NOP ;2 cycles
NOP ;2 cycles
DEX ;2 cycles
BNE loop_nops_silence ;3 cycles
;Testing duration loop
DEY ;2 cycles
BNE loop_silence ;3 cycles
DEC pause_hi ;5 cycles
BNE loop_silence ;3 cycles
RTS

19
src/music.h Executable file
View File

@ -0,0 +1,19 @@
#ifndef _MUSIC_H
#define _MUSIC_H
#include <stdint.h>
void __fastcall__ note(const uint8_t nb_shift_duration, const uint8_t idx_not);
void __fastcall__ pause(const uint8_t nb_shift_duration);
enum eNotes {
Ds3 = 0, E3, F3, Fs3, G3, Gs3, A3, As3, B3,
C4, Cs4, D4, Ds4, E4, F4, Fs4, G4, Gs4, A4, As4, B4,
C5, Cs5, D5, Ds5, E5, F5, Fs5, G5, Gs5, A5, As5, B5
};
enum eDuration {
WHOLE = 0, HALF, QUARTER, EIGHTH, SIXTEENTH, THIRTY_SECOND, SIXTY_FOURTH, HUNDRED_TWENTY_EIGHTH
};
#endif