#include #include #include // for sine //I like these definitions #define begin { #define end } #define countMS 62 //ticks/mSec //my definitions #define nosound_state 0b00000000 #define menumusic_state 0b00010000 #define flapping_state 0b00100000 #define winmusic_state 0b00110000 #define losemusic_state 0b01000000 #define doglaugh_state 0b01010000 #define nosound 0 #define music 1 #define soundeffect 2 #define flap 0 #define gun 1 unsigned long accumulator @0x2f0; unsigned char highbyte @0x2f3; //the HIGH byte of the accumulator variable unsigned long increment; unsigned char sineTable[256] @0x300; //need loc to avoid glitch unsigned int i, time; char count; //sound variables unsigned char soundtype; unsigned char currentstate; unsigned char menumusic_count; unsigned int flap_count; unsigned char gunshotsound; unsigned char winmusic_count; unsigned char losemusic_count; unsigned char newstate; unsigned char init; unsigned char gunshot; unsigned int gun_count; unsigned char clip; unsigned char y; unsigned char falling_count; unsigned char falling; unsigned char laugh_count; unsigned char fallingsound; unsigned char opt; unsigned char yflap; //Array for gunshot sound loaded into flash, sampling 7813Hz flash unsigned char gunshotA[141] = {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 127, 126, 128, 128, 126, 126, 126, 126, 126, 126, 127, 127, 127, 126, 127, 126, 126, 127, 127, 127, 127, 127, 128, 127, 126, 129, 127, 127, 128, 127, 127, 125, 127, 128, 127, 127, 127, 127, 128, 128, 127, 124, 129, 114, 78, 79, 169, 216, 203, 203, 194, 180, 174, 130, 87, 141, 43, 25, 28, 36, 43, 106, 70, 117, 220, 202, 206, 116, 40, 54, 66, 91, 198, 223, 200, 98, 46, 74, 80, 158, 235, 224, 219, 208, 160, 45, 79, 110, 169, 120, 155, 180, 43, 42, 46, 63, 82, 181, 233, 208, 216, 102, 96, 216, 126, 31, 143, 217, 194, 185, 177, 159, 141, 23, 56, 59, 2, 41, 21, 110, 181, 100, 225, 202, 205, 116, 85, 207}; flash unsigned char gunshotB[141] = {184, 180, 163, 157, 140, 119, 17, 89, 78, 4, 141, 185, 170, 123, 136, 154, 48, 129, 129, 18, 22, 25, 153, 102, 37, 110, 188, 127, 96, 27, 164, 163, 203, 218, 74, 104, 214, 210, 124, 57, 198, 207, 189, 182, 167, 164, 137, 116, 67, 45, 141, 150, 130, 53, 14, 26, 30, 38, 87, 216, 214, 143, 187, 215, 190, 186, 166, 157, 87, 14, 81, 203, 171, 165, 68, 101, 51, 19, 86, 207, 209, 194, 183, 127, 18, 87, 70, 96, 226, 203, 200, 145, 80, 108, 67, 76, 218, 179, 125, 155, 152, 51, 128, 206, 176, 169, 144, 65, 9, 48, 69, 104, 215, 191, 156, 177, 61, 137, 207, 172, 166, 149, 135, 88, 0, 97, 79, 47, 95, 22, 144, 93, 41, 131, 97, 171, 244, 223, 229, 215, 211}; flash unsigned char gunshotC[141] = {189, 169, 69, 127, 43, 161, 109, 0, 72, 62, 36, 141, 222, 209, 208, 168, 36, 121, 216, 198, 161, 150, 175, 124, 76, 111, 18, 13, 55, 48, 168, 133, 179, 216, 189, 190, 153, 127, 161, 92, 13, 83, 76, 146, 104, 178, 116, 35, 128, 96, 163, 211, 159, 131, 82, 30, 167, 204, 178, 168, 147, 130, 55, 19, 78, 50, 36, 68, 105, 211, 225, 224, 206, 204, 141, 157, 145, 35, 32, 40, 56, 149, 243, 165, 161, 227, 184, 193, 119, 84, 47, 140, 192, 169, 116, 59, 174, 150, 59, 28, 43, 151, 219, 192, 174, 164, 159, 63, 43, 45, 138, 220, 176, 191, 105, 106, 141, 90, 192, 160, 157, 136, 130, 120, 92, 54, 121, 125, 113, 113, 95, 81, 81, 106, 147, 124, 120, 58, 39, 56, 78}; flash unsigned char gunshotD[141] = {168, 125, 103, 210, 121, 220, 251, 225, 226, 103, 43, 65, 143, 234, 231, 158, 119, 222, 191, 157, 38, 33, 164, 172, 154, 155, 192, 171, 155, 146, 100, 38, 109, 38, 149, 75, 7, 29, 54, 214, 134, 165, 166, 114, 71, 41, 37, 63, 112, 117, 225, 226, 222, 215, 203, 190, 175, 159, 146, 129, 97, 11, 10, 16, 26, 49, 155, 218, 203, 195, 184, 135, 34, 80, 60, 37, 44, 79, 192, 210, 194, 208, 180, 174, 64, 12, 31, 105, 130, 195, 208, 104, 135, 212, 116, 64, 133, 176, 132, 110, 52, 32, 145, 103, 124, 207, 159, 164, 72, 34, 183, 108, 57, 181, 132, 84, 57, 46, 55, 32, 58, 160, 236, 212, 211, 196, 197, 139, 105, 176, 108, 26, 25, 47, 158, 202, 87, 34, 113, 131, 229}; flash unsigned char gunshotE[141] = {202, 213, 198, 182, 161, 58, 17, 72, 83, 80, 59, 162, 229, 203, 184, 192, 185, 164, 153, 119, 111, 59, 10, 25, 49, 190, 200, 182, 180, 150, 92, 139, 149, 65, 60, 153, 67, 161, 147, 131, 89, 23, 28, 35, 68, 194, 226, 212, 204, 185, 174, 130, 88, 144, 108, 27, 35, 27, 117, 156, 121, 233, 208, 203, 184, 160, 146, 64, 24, 62, 78, 102, 187, 216, 127, 106, 221, 185, 139, 131, 60, 23, 39, 50, 66, 69, 146, 245, 220, 231, 126, 154, 223, 78, 44, 61, 180, 94, 81, 224, 218, 213, 103, 55, 195, 225, 205, 196, 182, 155, 62, 110, 31, 19, 30, 45, 92, 189, 223, 206, 167, 164, 89, 76, 73, 211, 143, 122, 195, 127, 187, 90, 175, 100, 102, 112, 11, 31, 24, 64, 143}; flash unsigned char gunshotF[141] = {98, 201, 221, 207, 197, 174, 147, 163, 157, 134, 112, 28, 26, 20, 115, 146, 70, 64, 33, 118, 175, 151, 108, 176, 245, 195, 203, 207, 186, 170, 150, 63, 18, 73, 195, 151, 115, 151, 156, 73, 81, 160, 154, 134, 105, 112, 92, 28, 38, 88, 81, 38, 105, 83, 50, 100, 73, 114, 120, 220, 211, 209, 253, 151, 63, 84, 101, 207, 255, 234, 223, 184, 215, 195, 185, 93, 26, 120, 201, 169, 78, 122, 50, 42, 76, 81, 149, 75, 66, 62, 100, 219, 221, 222, 145, 105, 219, 163, 169, 131, 31, 111, 199, 173, 152, 70, 31, 42, 65, 104, 187, 154, 160, 134, 102, 204, 191, 173, 160, 112, 32, 29, 68, 166, 152, 65, 106, 175, 153, 167, 49, 71, 177, 90, 38, 43, 96, 187, 197, 163, 163}; flash unsigned char gunshotG[141] = {215, 119, 50, 64, 54, 68, 140, 211, 220, 184, 182, 176, 180, 122, 69, 72, 29, 40, 68, 71, 155, 111, 141, 73, 124, 224, 213, 88, 119, 230, 207, 192, 185, 174, 156, 91, 16, 30, 26, 43, 57, 125, 221, 192, 146, 85, 115, 214, 134, 107, 153, 173, 115, 132, 127, 42, 67, 37, 149, 185, 111, 132, 169, 183, 157, 75, 57, 120, 167, 139, 182, 98, 34, 79, 79, 72, 61, 47, 182, 135, 135, 133, 43, 136, 193, 145, 152, 229, 205, 197, 196, 116, 115, 119, 193, 125, 92, 96, 69, 130, 102, 98, 61, 89, 142, 64, 135, 117, 124, 168, 212, 155, 105, 156, 189, 205, 123, 156, 156, 99, 55, 46, 60, 174, 172, 66, 72, 90, 185, 136, 84, 166, 164, 169, 152, 58, 79, 85, 169, 179, 107}; flash unsigned char gunshotH[141] = {84, 104, 89, 90, 194, 110, 129, 195, 165, 167, 167, 144, 119, 191, 183, 165, 89, 55, 60, 76, 79, 139, 206, 201, 202, 211, 204, 181, 111, 43, 34, 52, 76, 66, 76, 186, 140, 109, 176, 89, 97, 190, 197, 101, 55, 70, 157, 137, 139, 216, 178, 181, 102, 49, 62, 82, 186, 142, 59, 173, 217, 117, 127, 195, 91, 58, 121, 150, 126, 157, 170, 98, 121, 207, 198, 156, 141, 118, 122, 180, 113, 45, 34, 122, 86, 34, 52, 43, 69, 96, 95, 109, 105, 167, 236, 209, 236, 228, 216, 204, 151, 53, 46, 92, 75, 54, 60, 116, 197, 77, 93, 129, 181, 200, 125, 104, 219, 221, 206, 194, 187, 167, 82, 29, 44, 35, 40, 42, 50, 59, 75, 95, 192, 236, 221, 221, 199, 137, 76, 54, 77}; flash unsigned char gunshotI[141] = {147, 159, 208, 168, 174, 210, 173, 164, 147, 110, 130, 61, 29, 40, 49, 89, 95, 134, 205, 124, 94, 97, 89, 107, 51, 65, 89, 192, 214, 143, 174, 199, 186, 109, 40, 84, 108, 143, 125, 173, 164, 84, 122, 69, 75, 116, 96, 169, 212, 128, 119, 203, 179, 191, 169, 175, 175, 87, 42, 55, 64, 98, 168, 226, 195, 153, 132, 134, 99, 60, 117, 169, 172, 152, 95, 169, 155, 147, 141, 69, 59, 88, 45, 49, 74, 56, 51, 68, 74, 81, 154, 206, 192, 150, 144, 180, 216, 231, 204, 189, 193, 157, 143, 135, 118, 129, 94, 33, 47, 71, 160, 146, 191, 169, 109, 155, 69, 43, 47, 135, 169, 115, 62, 55, 54, 78, 101, 103, 139, 151, 206, 188, 168, 212, 192, 178, 109, 71, 70, 114, 102}; flash unsigned char gunshotJ[141] = {76, 96, 192, 191, 108, 165, 147, 63, 132, 157, 129, 146, 145, 136, 145, 148, 150, 135, 90, 49, 103, 182, 79, 82, 105, 158, 132, 49, 96, 130, 182, 147, 132, 135, 149, 146, 133, 197, 189, 155, 82, 49, 78, 145, 145, 62, 74, 159, 91, 150, 170, 77, 130, 128, 140, 189, 160, 128, 137, 179, 131, 71, 67, 78, 94, 145, 200, 192, 183, 187, 173, 124, 48, 117, 110, 45, 80, 60, 79, 120, 95, 147, 159, 162, 202, 189, 145, 176, 200, 105, 60, 132, 138, 102, 115, 185, 128, 79, 84, 49, 85, 165, 183, 142, 125, 179, 190, 166, 122, 161, 121, 95, 127, 149, 105, 55, 55, 51, 62, 144, 215, 193, 167, 151, 120, 112, 107, 73, 72, 57, 117, 171, 80, 150, 186, 127, 109, 71, 85, 98, 120}; flash unsigned char gunshotK[141] = {209, 194, 146, 90, 85, 149, 169, 177, 168, 159, 158, 106, 134, 134, 132, 183, 180, 169, 107, 145, 91, 58, 158, 93, 98, 117, 178, 155, 125, 154, 126, 138, 133, 67, 71, 65, 94, 64, 119, 138, 139, 155, 91, 108, 140, 87, 89, 109, 113, 177, 221, 206, 190, 131, 96, 116, 94, 110, 138, 121, 116, 166, 131, 162, 187, 205, 173, 81, 84, 132, 87, 108, 171, 140, 113, 108, 97, 142, 80, 116, 179, 78, 109, 154, 143, 122, 142, 180, 162, 133, 125, 156, 114, 67, 69, 113, 113, 77, 89, 123, 137, 125, 65, 113, 127, 110, 121, 129, 118, 174, 160, 119, 195, 171, 71, 100, 108, 127, 195, 223, 204, 184, 159, 147, 163, 67, 52, 107, 62, 97, 107, 126, 136, 143, 124, 59, 80, 112, 80, 150, 190}; flash unsigned char gunshotL[141] = {117, 143, 142, 104, 121, 135, 150, 81, 69, 99, 145, 111, 131, 192, 155, 176, 181, 137, 135, 110, 87, 63, 66, 113, 159, 124, 118, 140, 158, 169, 191, 204, 152, 139, 152, 118, 99, 51, 44, 65, 74, 70, 87, 71, 112, 175, 170, 162, 185, 155, 136, 186, 180, 168, 138, 119, 102, 83, 70, 73, 81, 88, 84, 117, 103, 117, 152, 118, 187, 210, 201, 200, 187, 167, 155, 99, 51, 62, 65, 101, 146, 152, 102, 172, 184, 135, 142, 110, 118, 143, 149, 163, 91, 68, 80, 69, 80, 108, 143, 115, 143, 190, 126, 130, 138, 134, 155, 118, 158, 143, 179, 199, 117, 79, 99, 136, 134, 107, 105, 84, 109, 77, 85, 107, 112, 149, 151, 119, 173, 198, 192, 184, 159, 116, 92, 125, 196, 161, 125, 96, 117}; flash unsigned char gunshotM[141] = {154, 145, 136, 61, 73, 110, 141, 133, 119, 122, 113, 124, 104, 104, 132, 174, 170, 130, 90, 85, 65, 98, 107, 126, 159, 159, 121, 105, 100, 119, 138, 124, 153, 176, 179, 128, 115, 121, 98, 129, 121, 118, 178, 160, 146, 167, 138, 95, 83, 87, 122, 98, 64, 97, 102, 88, 122, 151, 178, 139, 159, 202, 188, 168, 164, 148, 99, 85, 133, 122, 82, 88, 124, 137, 125, 98, 102, 68, 73, 105, 104, 138, 187, 160, 173, 138, 115, 129, 143, 165, 177, 131, 114, 109, 131, 99, 83, 107, 122, 179, 169, 157, 153, 112, 90, 83, 91, 146, 159, 172, 133, 119, 133, 113, 119, 124, 119, 147, 157, 123, 117, 106, 111, 123, 120, 112, 120, 130, 149, 120, 138, 158, 138, 97, 124, 148, 129, 108, 102, 107, 160}; flash unsigned char gunshotN[141] = {167, 120, 109, 123, 130, 146, 146, 129, 141, 114, 97, 110, 124, 142, 115, 75, 92, 136, 181, 186, 147, 147, 117, 113, 116, 93, 110, 127, 100, 114, 145, 146, 151, 142, 150, 147, 115, 108, 84, 80, 92, 101, 128, 128, 130, 146, 136, 91, 147, 163, 121, 133, 161, 160, 158, 134, 115, 136, 146, 123, 82, 106, 107, 115, 147, 168, 170, 134, 120, 115, 111, 115, 95, 117, 105, 108, 115, 97, 111, 114, 158, 152, 126, 116, 93, 113, 134, 168, 166, 148, 172, 175, 164, 152, 156, 160, 146, 109, 111, 113, 82, 82, 92, 83, 89, 92, 82, 98, 121, 113, 150, 168, 160, 184, 176, 160, 127, 107, 101, 92, 98, 110, 111, 99, 105, 104, 122, 155, 155, 172, 159, 147, 152, 153, 177, 165, 140, 105, 87, 103, 105}; flash unsigned char gunshotO[141] = {121, 135, 137, 148, 151, 131, 116, 101, 97, 101, 129, 138, 133, 158, 156, 122, 121, 103, 97, 101, 68, 79, 110, 125, 129, 142, 171, 174, 142, 128, 129, 129, 123, 132, 118, 111, 126, 136, 144, 147, 153, 130, 86, 82, 108, 143, 155, 139, 149, 149, 148, 126, 94, 120, 136, 124, 120, 108, 116, 131, 134, 134, 130, 121, 131, 147, 134, 107, 98, 111, 116, 103, 121, 125, 115, 117, 131, 136, 146, 142, 140, 142, 144, 152, 152, 152, 163, 130, 121, 130, 118, 120, 125, 127, 129, 99, 85, 113, 111, 113, 121, 121, 132, 118, 131, 147, 142, 169, 156, 151, 148, 125, 123, 106, 103, 102, 120, 130, 108, 113, 137, 136, 109, 120, 145, 134, 141, 152, 160, 134, 120, 113, 98, 106, 124, 118, 133, 129, 96, 88, 108}; flash unsigned char gunshotP[141] = {118, 121, 131, 135, 144, 145, 139, 145, 152, 144, 137, 133, 132, 124, 111, 106, 98, 94, 112, 98, 114, 145, 143, 150, 148, 136, 150, 136, 127, 148, 143, 143, 141, 129, 125, 109, 124, 128, 114, 105, 132, 142, 125, 117, 113, 123, 121, 122, 130, 117, 136, 138, 133, 115, 120, 127, 112, 97, 116, 126, 119, 138, 158, 149, 140, 132, 119, 114, 113, 122, 129, 138, 145, 139, 117, 118, 119, 116, 124, 119, 131, 159, 152, 153, 152, 145, 148, 124, 98, 93, 103, 115, 129, 133, 120, 135, 139, 122, 126, 124, 126, 125, 115, 109, 114, 134, 123, 120, 128, 134, 139, 134, 130, 129, 121, 130, 143, 131, 119, 120, 128, 131, 134, 135, 126, 131, 134, 131, 127, 125, 132, 134, 120, 137, 140, 136, 132, 117, 97, 100, 112}; flash unsigned char gunshotQ[141] = {118, 125, 116, 117, 128, 118, 122, 129, 136, 134, 137, 138, 128, 131, 132, 144, 145, 137, 133, 124, 115, 123, 127, 118, 126, 131, 129, 124, 120, 128, 135, 118, 121, 128, 116, 117, 115, 125, 139, 125, 130, 136, 122, 119, 111, 105, 115, 137, 132, 130, 146, 142, 136, 135, 134, 136, 127, 121, 127, 128, 115, 112, 119, 134, 128, 122, 132, 133, 147, 148, 148, 147, 130, 122, 122, 132, 134, 133, 121, 117, 123, 116, 113, 110, 116, 123, 114, 115, 120, 117, 125, 134, 128, 136, 147, 137, 121, 122, 117, 118, 127, 131, 138, 139, 138, 138, 136, 125, 133, 142, 146, 137, 127, 134, 128, 114, 99, 93, 109, 116, 121, 127, 129, 129, 136, 144, 142, 138, 141, 140, 131, 120, 124, 125, 122, 127, 129, 132, 128, 122, 119}; flash unsigned char gunshotR[141] = {119, 121, 115, 125, 129, 123, 119, 115, 119, 121, 121, 127, 132, 141, 141, 130, 128, 122, 116, 124, 124, 122, 132, 137, 142, 147, 140, 137, 123, 108, 112, 117, 118, 121, 123, 124, 129, 132, 135, 135, 136, 128, 125, 128, 128, 130, 131, 127, 126, 132, 130, 124, 122, 124, 123, 123, 122, 117, 121, 132, 133, 133, 136, 139, 135, 132, 135, 139, 142, 127, 106, 109, 119, 116, 114, 121, 118, 122, 132, 135, 130, 125, 125, 126, 126, 127, 123, 127, 131, 128, 124, 130, 135, 133, 124, 126, 132, 129, 129, 130, 127, 129, 127, 134, 142, 135, 126, 130, 127, 126, 124, 123, 125, 122, 119, 119, 117, 121, 131, 128, 126, 126, 127, 130, 131, 128, 121, 122, 131, 125, 123, 125, 120, 119, 122, 125, 133, 141, 141, 138, 126}; flash unsigned char gunshotS[141] = {113, 117, 122, 119, 123, 126, 125, 123, 130, 145, 146, 138, 137, 132, 130, 128, 123, 120, 119, 120, 122, 131, 136, 136, 135, 126, 120, 124, 126, 126, 125, 128, 137, 131, 125, 123, 122, 122, 115, 118, 122, 125, 129, 128, 137, 139, 136, 136, 135, 131, 121, 117, 117, 112, 114, 123, 126, 127, 131, 134, 137, 142, 145, 141, 132, 129, 129, 125, 124, 126, 125, 126, 128, 131, 129, 125, 118, 115, 122, 131, 130, 125, 127, 130, 131, 134, 134, 131, 124, 115, 122, 125, 121, 124, 130, 126, 121, 126, 128, 127, 126, 125, 128, 133, 134, 134, 132, 129, 126, 122, 120, 126, 127, 129, 130, 127, 130, 128, 123, 121, 120, 121, 130, 134, 132, 131, 129, 126, 126, 123, 121, 124, 129, 131, 126, 130, 129, 125, 121, 126, 130}; flash unsigned char gunshotT[141] = {130, 130, 128, 127, 125, 122, 120, 124, 125, 126, 133, 135, 133, 135, 135, 133, 132, 129, 126, 120, 115, 115, 115, 114, 116, 124, 131, 135, 134, 134, 136, 136, 135, 136, 132, 125, 126, 124, 123, 123, 126, 129, 129, 130, 130, 130, 127, 122, 123, 124, 122, 124, 124, 125, 121, 125, 128, 128, 131, 138, 135, 132, 131, 129, 128, 128, 130, 127, 127, 127, 125, 125, 123, 120, 120, 120, 120, 125, 132, 133, 135, 136, 133, 133, 131, 129, 127, 126, 125, 122, 121, 120, 124, 126, 129, 131, 131, 133, 133, 133, 128, 123, 124, 125, 123, 124, 128, 130, 131, 131, 130, 130, 125, 121, 125, 125, 126, 129, 128, 126, 130, 129, 123, 120, 121, 121, 123, 125, 125, 126, 129, 134, 134, 133, 133, 133, 128, 127, 126, 127, 128}; flash unsigned char gunshotU[141] = {126, 124, 122, 121, 123, 122, 118, 120, 127, 134, 135, 136, 134, 131, 131, 131, 130, 131, 129, 130, 129, 128, 126, 125, 125, 126, 125, 125, 128, 128, 124, 124, 122, 121, 124, 126, 130, 131, 126, 130, 134, 132, 130, 130, 129, 128, 128, 126, 123, 123, 124, 127, 127, 124, 124, 126, 128, 130, 131, 131, 130, 130, 130, 130, 127, 125, 127, 128, 126, 126, 124, 120, 125, 124, 124, 126, 126, 125, 126, 126, 128, 128, 128, 129, 130, 129, 128, 128, 126, 128, 130, 130, 130, 130, 127, 126, 126, 128, 127, 125, 126, 125, 126, 129, 130, 130, 129, 127, 127, 129, 126, 123, 123, 125, 126, 125, 129, 128, 128, 129, 128, 128, 130, 130, 130, 126, 123, 123, 125, 129, 130, 128, 125, 126, 126, 123, 125, 125, 125, 126, 125}; flash unsigned char gunshotV[141] = {127, 128, 131, 131, 130, 130, 130, 130, 130, 130, 130, 131, 127, 125, 125, 125, 125, 125, 124, 125, 127, 128, 129, 130, 126, 125, 126, 128, 128, 128, 129, 132, 133, 135, 132, 131, 130, 124, 121, 121, 121, 121, 123, 123, 125, 126, 128, 129, 131, 131, 130, 129, 130, 128, 125, 125, 125, 126, 125, 125, 128, 127, 126, 126, 126, 126, 125, 126, 128, 128, 128, 129, 133, 133, 133, 130, 127, 125, 124, 121, 120, 120, 123, 124, 124, 127, 129, 132, 133, 134, 133, 130, 128, 127, 126, 125, 126, 126, 125, 125, 125, 125, 126, 126, 126, 128, 126, 125, 127, 128, 130, 130, 129, 130, 129, 128, 128, 128, 128, 126, 125, 125, 125, 126, 129, 130, 129, 129, 130, 130, 130, 128, 125, 123, 123, 125, 125, 127, 130, 130, 130}; //Array for flapping sound loaded into flash, sampling 7813Hz flash unsigned char flapA[169] = {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 127, 128, 128, 128, 128, 128, 128, 128, 128, 127, 128, 128, 127, 128, 129, 128, 128, 128, 129, 129, 127, 129, 129, 128, 128, 124, 119, 123, 126, 127, 123, 122, 121, 119, 121, 119, 124, 128, 127, 121, 125, 130, 125, 126, 124, 125, 127, 127, 128, 124, 126, 132, 126, 132, 130, 133, 133, 139, 134, 132, 132, 134, 131, 142, 140, 131, 122, 131, 133, 129, 131, 125, 131, 128, 129, 126, 124, 127, 129, 129, 129, 124, 119, 122, 123, 126, 128, 126, 124, 129, 139, 119, 117, 125, 122, 118, 138, 127, 145, 150, 126, 126, 139, 133, 143, 135, 132, 124, 136, 133, 127, 140, 134, 127, 110, 127, 119, 117, 149, 139, 132, 114, 129, 116, 132, 132, 137, 146, 115, 126, 125, 128, 134, 96, 128, 130, 119, 127, 113, 107, 143, 160, 154, 136, 116, 94, 107, 116}; flash unsigned char flapB[169] = {116, 120, 152, 106, 91, 97, 94, 119, 124, 142, 108, 120, 137, 130, 139, 150, 148, 153, 156, 137, 120, 123, 133, 114, 139, 115, 84, 99, 108, 129, 126, 96, 99, 131, 144, 121, 167, 136, 115, 142, 114, 140, 101, 110, 130, 129, 129, 111, 134, 113, 107, 127, 122, 112, 145, 133, 135, 111, 116, 113, 107, 136, 128, 137, 157, 128, 111, 134, 142, 90, 89, 76, 71, 88, 121, 104, 91, 137, 145, 151, 159, 167, 144, 152, 145, 182, 183, 137, 154, 131, 99, 124, 133, 135, 136, 141, 101, 125, 113, 147, 123, 135, 131, 109, 121, 104, 183, 159, 133, 170, 106, 119, 123, 101, 106, 127, 138, 126, 96, 76, 129, 110, 174, 157, 153, 140, 157, 175, 155, 145, 139, 113, 96, 123, 124, 145, 120, 152, 191, 131, 160, 119, 136, 139, 146, 144, 154, 98, 103, 122, 126, 140, 151, 120, 118, 131, 152, 118, 86, 118, 93, 95, 138, 146, 138, 158, 168, 144, 118}; flash unsigned char flapC[169] = {119, 125, 132, 149, 140, 148, 134, 146, 123, 176, 170, 153, 127, 152, 155, 163, 160, 114, 145, 129, 121, 162, 161, 141, 127, 129, 132, 152, 128, 130, 162, 144, 144, 138, 155, 126, 149, 119, 97, 152, 158, 117, 86, 98, 129, 158, 120, 138, 139, 105, 94, 123, 122, 114, 141, 142, 110, 114, 95, 82, 110, 130, 122, 125, 95, 103, 103, 101, 147, 127, 123, 119, 133, 129, 94, 107, 130, 123, 138, 134, 105, 126, 131, 119, 133, 124, 140, 146, 116, 115, 113, 154, 140, 104, 132, 109, 112, 152, 119, 94, 95, 114, 129, 113, 123, 142, 129, 114, 127, 137, 140, 119, 127, 147, 109, 124, 141, 147, 132, 88, 104, 127, 131, 121, 105, 134, 160, 151, 119, 95, 143, 170, 133, 114, 124, 128, 145, 151, 111, 120, 94, 90, 95, 111, 141, 129, 106, 108, 122, 123, 131, 118, 137, 144, 126, 134, 136, 127, 104, 131, 153, 115, 151, 104, 90, 132, 139, 152, 193}; flash unsigned char flapD[169] = {135, 138, 136, 127, 107, 111, 126, 115, 110, 120, 94, 101, 135, 116, 129, 127, 136, 121, 120, 130, 120, 165, 149, 129, 120, 124, 110, 146, 147, 169, 171, 127, 99, 133, 140, 157, 143, 139, 114, 131, 172, 126, 118, 84, 119, 122, 141, 183, 160, 146, 129, 65, 113, 155, 153, 121, 107, 153, 141, 177, 164, 121, 131, 140, 153, 123, 139, 121, 132, 134, 138, 126, 111, 122, 118, 133, 149, 129, 139, 108, 106, 124, 136, 162, 138, 131, 142, 130, 129, 128, 123, 109, 104, 106, 133, 131, 123, 105, 126, 122, 94, 85, 111, 124, 144, 149, 131, 97, 127, 107, 98, 125, 122, 121, 125, 111, 104, 102, 96, 105, 136, 144, 126, 106, 100, 132, 115, 141, 158, 135, 116, 118, 105, 118, 137, 130, 96, 115, 108, 108, 96, 107, 127, 103, 135, 118, 109, 124, 133, 129, 106, 122, 123, 124, 104, 107, 133, 118, 107, 121, 139, 146, 124, 117, 120, 107, 127, 132, 127}; flash unsigned char flapE[169] = {138, 134, 141, 110, 119, 158, 130, 116, 115, 116, 130, 118, 109, 131, 119, 112, 102, 123, 128, 136, 148, 150, 148, 122, 130, 165, 137, 113, 118, 133, 142, 137, 137, 156, 126, 131, 122, 121, 122, 134, 126, 133, 143, 142, 144, 109, 98, 141, 141, 152, 102, 109, 128, 156, 145, 127, 136, 142, 145, 110, 129, 137, 136, 125, 155, 132, 123, 135, 165, 131, 130, 141, 150, 121, 123, 128, 121, 123, 143, 99, 100, 102, 116, 90, 124, 131, 124, 141, 138, 152, 89, 104, 126, 114, 125, 150, 134, 120, 118, 131, 135, 119, 146, 172, 133, 104, 109, 135, 169, 173, 159, 156, 147, 159, 152, 129, 168, 181, 163, 154, 151, 141, 143, 147, 152, 134, 127, 145, 132, 141, 136, 135, 119, 132, 137, 110, 98, 113, 114, 94, 110, 108, 98, 120, 117, 114, 136, 126, 152, 146, 121, 130, 108, 125, 126, 105, 129, 127, 133, 152, 126, 144, 111, 144, 151, 112, 135, 138, 141}; flash unsigned char flapF[169] = {148, 119, 153, 129, 120, 126, 140, 147, 135, 126, 113, 97, 120, 146, 119, 115, 150, 151, 133, 147, 111, 98, 99, 138, 152, 122, 114, 128, 101, 97, 135, 123, 125, 120, 132, 116, 114, 133, 109, 114, 109, 123, 132, 129, 115, 110, 118, 125, 134, 135, 115, 143, 103, 139, 150, 136, 140, 131, 93, 119, 123, 124, 101, 122, 163, 146, 128, 119, 130, 138, 140, 142, 145, 149, 138, 117, 97, 133, 147, 130, 133, 132, 113, 128, 125, 112, 127, 143, 150, 147, 157, 152, 86, 122, 118, 118, 120, 128, 138, 125, 115, 127, 118, 116, 120, 110, 109, 114, 117, 134, 138, 135, 115, 126, 107, 96, 114, 134, 126, 119, 115, 120, 128, 94, 100, 124, 122, 128, 140, 113, 86, 122, 133, 142, 129, 136, 121, 143, 137, 128, 107, 105, 113, 125, 141, 139, 133, 121, 120, 117, 149, 130, 104, 120, 137, 132, 107, 129, 134, 155, 132, 127, 99, 139, 143, 129, 142, 128, 118}; flash unsigned char flapG[169] = {142, 162, 146, 139, 153, 127, 114, 142, 149, 131, 124, 125, 126, 146, 133, 128, 144, 141, 128, 133, 129, 126, 150, 127, 141, 126, 113, 138, 159, 139, 136, 135, 114, 112, 114, 126, 134, 124, 119, 108, 127, 143, 129, 126, 125, 143, 124, 133, 118, 119, 118, 126, 124, 138, 132, 84, 116, 135, 118, 140, 126, 135, 117, 116, 126, 134, 132, 105, 122, 118, 141, 144, 123, 115, 129, 113, 120, 137, 115, 111, 111, 133, 148, 136, 134, 110, 119, 146, 157, 137, 146, 116, 129, 124, 121, 153, 151, 137, 125, 107, 96, 115, 116, 135, 117, 114, 103, 122, 123, 115, 142, 113, 131, 147, 140, 131, 133, 135, 122, 115, 148, 162, 134, 121, 124, 121, 136, 138, 139, 136, 135, 129, 127, 142, 132, 139, 128, 116, 106, 150, 131, 138, 161, 124, 135, 81, 114, 118, 130, 124, 131, 123, 123, 124, 120, 118, 130, 145, 138, 130, 127, 124, 125, 128, 130, 131, 130, 128, 127}; flash unsigned char flapH[169] = {126, 127, 128, 129, 129, 129, 128, 127, 127, 127, 128, 128, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}; //flash unsigned int menumusic[] = {196, 196, 0, 196, 196, 0, 233, 233, 0, 196, 196, 0, 262, 262, 0, 196, 196, 0, 294, 294, 262, 262, 233, 233, 262, 262, 0, 233, 233, 0}; flash unsigned int winmusic[] = {349, 440, 392, 494, 524, 659, 523}; flash unsigned int losemusic[] = {262, 247, 233, 220, 207}; flash unsigned int laugh[] = {1480, 1568, 1661, 1760, 1864, 1976, 2094, 1661, 1661, 1661, 1661, 0, 0, 0, 1568, 1568, 1568, 1568, 0, 0, 0, 1480, 1480, 1480, 1480, 0, 0, 0, 1397, 1397, 1397, 1397}; flash unsigned int duckfalling[] = {2349, 2349, 2284, 2218, 2156, 2093, 2035, 1976}; flash unsigned int menumusic[] = {330, 330, 392, 392, 330, 330, 392, 392, 262, 294, 330, 349, 294, 330, 349, 392}; interrupt [TIM0_OVF] void sgen(void) begin if(soundtype == music) //the sound to be played needs the sine table begin //the DDR code and scaling accumulator = accumulator + increment; OCR0 = sineTable[highbyte]; //Put sine table value on the output compare register // 62 counts is about 1 mSec count--; if (0 == count) begin count=countMS; time++; //in mSec end end else if(soundtype == soundeffect) //The sound to be played needs to be loaded from flash begin if(clip == flap) //The sound is flapping begin //goes through all the flapping arrays if(yflap==0) OCR0 = flapA[flap_count++]; else if(yflap==1) OCR0 = flapB[flap_count++]; else if(yflap==2) OCR0 = flapC[flap_count++]; else if(yflap==3) OCR0 = flapD[flap_count++]; else if(yflap==4) OCR0 = flapE[flap_count++]; else if(yflap==5) OCR0 = flapF[flap_count++]; else if(yflap==6) OCR0 = flapG[flap_count++]; else if(yflap==7) OCR0 = flapH[flap_count++]; else begin flap_count++; OCR0 = 0; end end else if(clip == gun) begin if(opt == 1) //optimization to make the interrupt have less instructions begin if(y==0) OCR0 = gunshotA[gun_count++]; else if(y==1) OCR0 = gunshotB[gun_count++]; else if(y==2) OCR0 = gunshotC[gun_count++]; else if(y==3) OCR0 = gunshotD[gun_count++]; else if(y==4) OCR0 = gunshotE[gun_count++]; else if(y==5) OCR0 = gunshotF[gun_count++]; else if(y==6) OCR0 = gunshotG[gun_count++]; else if(y==7) OCR0 = gunshotH[gun_count++]; else if(y==8) OCR0 = gunshotI[gun_count++]; else if(y==9) OCR0 = gunshotJ[gun_count++]; else if(y==10) OCR0 = gunshotK[gun_count++]; end else if(opt == 2) begin if(y==11) OCR0 = gunshotL[gun_count++]; else if(y==12) OCR0 = gunshotM[gun_count++]; else if(y==13) OCR0 = gunshotN[gun_count++]; else if(y==14) OCR0 = gunshotO[gun_count++]; else if(y==15) OCR0 = gunshotP[gun_count++]; else if(y==16) OCR0 = gunshotQ[gun_count++]; else if(y==17) OCR0 = gunshotR[gun_count++]; else if(y==18) OCR0 = gunshotS[gun_count++]; else if(y==19) OCR0 = gunshotT[gun_count++]; else if(y==20) OCR0 = gunshotU[gun_count++]; else if(y==21) OCR0 = gunshotV[gun_count++]; end end end else if(soundtype == nosound) //Turnoff PWM TCCR0 = 0b00000001; end void main(void) begin DDRB=0xff; //PORT B is output (OC0 = PORT B3) DDRD=0x00; //PORT D is input (PIN D2 - D6) MCUCR=MCUCR|0b00000101; //Toggling INT1 generates gunshot sound MCUCR=MCUCR|0b11110101; //Toggling INT0 generates falling sound //turn on timer 0 overflow ISR TIMSK = 0b00000001; //init the sine table for(i=0; i<256; i++) begin sineTable[i] = 128 + (char)(127.0 * sin(6.283*((float)i)/256.0)); end //init the DDS phase increment increment = 0; time=0; TCCR0 = 0b00000001; //variable initializations currentstate = menumusic_state; menumusic_count = 0; flap_count = 0; gunshotsound = 0; winmusic_count = 0; losemusic_count = 0; gun_count = 0; y = 0; falling_count = 0; init = 1; yflap = 0; #asm sei #endasm while(1) begin //get the newstate newstate = PIND&0b01110000; //if the current state is not equal to the new state on the Pins if(currentstate != newstate) begin currentstate = newstate; //update the current state init = 1; //first time initializations need to be performed because of new state gunshotsound = 0; //turn off gunshot sound if it is playing end gunshot=GIFR&0b10000000; //Check for level change on gunshot input pin falling=GIFR&0b01000000; //Check for level change on falling input pin if(falling == 0b01000000) //if falling toggle has been detected begin GIFR=GIFR|0b01000000; //clear the flag gunshotsound = 0; //turn off gunshot sound fallingsound = 1; //turn on flapping sound soundtype = music; //sound type uses sinetable falling_count = 0; TCCR0 = 0b1101001; //turn on fast PWM with no prescaler time = 125; //note is 1/8 second end if(gunshot == 0b10000000) //if gunshot toggle has been detected begin GIFR=GIFR|0b10000000; //clear the flag gunshotsound = 1; //turn on gunshot sound fallingsound = 0; //turn off falling sound soundtype = soundeffect; //sound type requires flash memory gun_count = 0; y = 0; opt = 1; clip = gun; //play gunshot TCCR0 = 0b01101010; //turn on fast PWM with prescaler of 8 end if(fallingsound == 1) //plays the falling sound begin if(time == 125) begin time = 0; if(falling_count > 7) //falling sound has ended begin fallingsound = 0; //Turn off PWM because the song has ended init = 1; end increment = duckfalling[falling_count++]*68719; //update the frequency of falling sound end end if(gunshotsound == 1) //plays the gunshot sound begin if(gun_count > 140) //140 elements of array have been stepped through begin gun_count = 0; //start from beginning of new array y++; if(y>10) opt = 2; if(y>21) //gunshot sound has ended begin gunshotsound = 0; //turn off gunshot sound TCCR0 = 0b00000001; //turn off pwm mode init = 1; end end end if((gunshotsound != 1) && (fallingsound != 1)) //if gunshot and flapping are not playing, go back to playing state sounds begin if(currentstate == nosound_state) //no sound on speaker begin soundtype = nosound; end else if(currentstate == menumusic_state) //menu music begin if(init == 1) //initialization for first time entering into menu music state begin init = 0; soundtype = music; //music requires sinetable TCCR0 = 0b01101001; //fast PWM no prescaler time = 250; //1/4 s per note menumusic_count = 0; //initialize menu music count end if(time == 250) //note is done begin time = 0; increment = menumusic[menumusic_count++]*68719; //get new note if(menumusic_count > 15) menumusic_count = 0; //menu music has ended so start from beginning and loop end end else if(currentstate == flapping_state) //flapping sound begin if(init == 1) begin init = 0; //initialization for first time entering into flapping state soundtype = soundeffect; //sound is from flash memory clip = flap; //play the flap sound TCCR0 = 0b01101010; //turn on fast PWM and set prescaler to 8 flap_count = 0; //initialize flap count yflap = 0; end if(flap_count > 168) //if one array has been stepped through begin flap_count = 0; yflap++; //step through next array if(yflap > 15) //if flap sound is done begin yflap = 0; //loop around and play flap sound again flap_count = 0; end end end else if(currentstate == winmusic_state) //win music begin if(init == 1) //initialization for first time entering into win music state begin init = 0; soundtype = music; //sound requires sine table TCCR0 = 0b01101001; //turn on fast PWM and no prescaler time = 250; //note gets quarter of a second winmusic_count = 0; end if(time == 250) //on note done playing begin time = 0; if(winmusic_count > 6) TCCR0 = 0b00000001; //Turn off PWM because the song has ended increment = winmusic[winmusic_count++]*68719; //get new note end end else if(currentstate == losemusic_state) //lose music begin if(init == 1) //initialization for first time entering into lose music state begin init = 0; soundtype = music; //sound requires sine table TCCR0 = 0b01101001; //turn on fast PWM and no prescaler time = 250; //note gets quarter of a second losemusic_count = 0; end if(time == 250) //on note done playing begin time = 0; if(losemusic_count > 4) TCCR0 = 0b00000001; //Turn off PWM because the song has ended increment = losemusic[losemusic_count++]*68719; //get new note end end else if(currentstate == doglaugh_state) //dog laugh begin if(init == 1) //initialization for first time entering into dog laugh state begin init = 0; soundtype = music; //sound requires sine table TCCR0 = 0b01101001; //fast PWM mode no prescaler time = 36; //note gets 36/1000 seconds laugh_count = 0; end if(time == 36) //on note done playing begin time = 0; if(laugh_count > 31) TCCR0 = 0b00000001; //Turn off PWM because the song has ended increment = laugh[laugh_count++]*68719; //get new note end end end end // end while end //end main