comparison ym2612.c @ 1102:c15896605bf2

Clean up symbol visiblity and delete a ltitle bit of dead code
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Nov 2016 22:45:46 -0800
parents 8d032a368dd5
children 4b893b02444e
comparison
equal deleted inserted replaced
1101:e2d345e351b5 1102:c15896605bf2
37 #define BIT_TIMERB_LOAD 0x80 37 #define BIT_TIMERB_LOAD 0x80
38 38
39 #define BIT_STATUS_TIMERA 0x1 39 #define BIT_STATUS_TIMERA 0x1
40 #define BIT_STATUS_TIMERB 0x2 40 #define BIT_STATUS_TIMERB 0x2
41 41
42 uint32_t ym_calc_phase_inc(ym2612_context * context, ym_operator * operator, uint32_t op); 42 static uint32_t ym_calc_phase_inc(ym2612_context * context, ym_operator * operator, uint32_t op);
43 43
44 enum { 44 enum {
45 PHASE_ATTACK, 45 PHASE_ATTACK,
46 PHASE_DECAY, 46 PHASE_DECAY,
47 PHASE_SUSTAIN, 47 PHASE_SUSTAIN,
51 uint8_t did_tbl_init = 0; 51 uint8_t did_tbl_init = 0;
52 //According to Nemesis, real hardware only uses a 256 entry quarter sine table; however, 52 //According to Nemesis, real hardware only uses a 256 entry quarter sine table; however,
53 //memory is cheap so using a half sine table will probably save some cycles 53 //memory is cheap so using a half sine table will probably save some cycles
54 //a full sine table would be nice, but negative numbers don't get along with log2 54 //a full sine table would be nice, but negative numbers don't get along with log2
55 #define SINE_TABLE_SIZE 512 55 #define SINE_TABLE_SIZE 512
56 uint16_t sine_table[SINE_TABLE_SIZE]; 56 static uint16_t sine_table[SINE_TABLE_SIZE];
57 //Similar deal here with the power table for log -> linear conversion 57 //Similar deal here with the power table for log -> linear conversion
58 //According to Nemesis, real hardware only uses a 256 entry table for the fractional part 58 //According to Nemesis, real hardware only uses a 256 entry table for the fractional part
59 //and uses the whole part as a shift amount. 59 //and uses the whole part as a shift amount.
60 #define POW_TABLE_SIZE (1 << 13) 60 #define POW_TABLE_SIZE (1 << 13)
61 uint16_t pow_table[POW_TABLE_SIZE]; 61 static uint16_t pow_table[POW_TABLE_SIZE];
62 62
63 uint16_t rate_table_base[] = { 63 static uint16_t rate_table_base[] = {
64 //main portion 64 //main portion
65 0,1,0,1,0,1,0,1, 65 0,1,0,1,0,1,0,1,
66 0,1,0,1,1,1,0,1, 66 0,1,0,1,1,1,0,1,
67 0,1,1,1,0,1,1,1, 67 0,1,1,1,0,1,1,1,
68 0,1,1,1,1,1,1,1, 68 0,1,1,1,1,1,1,1,
71 1,1,1,2,1,1,1,2, 71 1,1,1,2,1,1,1,2,
72 1,2,1,2,1,2,1,2, 72 1,2,1,2,1,2,1,2,
73 1,2,2,2,1,2,2,2, 73 1,2,2,2,1,2,2,2,
74 }; 74 };
75 75
76 uint16_t rate_table[64*8]; 76 static uint16_t rate_table[64*8];
77 77
78 uint8_t lfo_timer_values[] = {108, 77, 71, 67, 62, 44, 8, 5}; 78 static uint8_t lfo_timer_values[] = {108, 77, 71, 67, 62, 44, 8, 5};
79 uint8_t lfo_pm_base[][8] = { 79 static uint8_t lfo_pm_base[][8] = {
80 {0, 0, 0, 0, 0, 0, 0, 0}, 80 {0, 0, 0, 0, 0, 0, 0, 0},
81 {0, 0, 0, 0, 4, 4, 4, 4}, 81 {0, 0, 0, 0, 4, 4, 4, 4},
82 {0, 0, 0, 4, 4, 4, 8, 8}, 82 {0, 0, 0, 4, 4, 4, 8, 8},
83 {0, 0, 4, 4, 8, 8, 0xc, 0xc}, 83 {0, 0, 4, 4, 8, 8, 0xc, 0xc},
84 {0, 0, 4, 8, 8, 8, 0xc,0x10}, 84 {0, 0, 4, 8, 8, 8, 0xc,0x10},
85 {0, 0, 8, 0xc,0x10,0x10,0x14,0x18}, 85 {0, 0, 8, 0xc,0x10,0x10,0x14,0x18},
86 {0, 0,0x10,0x18,0x20,0x20,0x28,0x30}, 86 {0, 0,0x10,0x18,0x20,0x20,0x28,0x30},
87 {0, 0,0x20,0x30,0x40,0x40,0x50,0x60} 87 {0, 0,0x20,0x30,0x40,0x40,0x50,0x60}
88 }; 88 };
89 int16_t lfo_pm_table[128 * 32 * 8]; 89 static int16_t lfo_pm_table[128 * 32 * 8];
90 90
91 int16_t ams_shift[] = {8, 1, -1, -2}; 91 int16_t ams_shift[] = {8, 1, -1, -2};
92 92
93 #define MAX_ENVELOPE 0xFFC 93 #define MAX_ENVELOPE 0xFFC
94 #define YM_DIVIDER 2 94 #define YM_DIVIDER 2
95 #define CYCLE_NEVER 0xFFFFFFFF 95 #define CYCLE_NEVER 0xFFFFFFFF
96 96
97 uint16_t round_fixed_point(double value, int dec_bits) 97 static uint16_t round_fixed_point(double value, int dec_bits)
98 { 98 {
99 return value * (1 << dec_bits) + 0.5; 99 return value * (1 << dec_bits) + 0.5;
100 } 100 }
101 101
102 FILE * debug_file = NULL; 102 static FILE * debug_file = NULL;
103 uint32_t first_key_on=0; 103 static uint32_t first_key_on=0;
104 104
105 ym2612_context * log_context = NULL; 105 static ym2612_context * log_context = NULL;
106 106
107 void ym_finalize_log() 107 static void ym_finalize_log()
108 { 108 {
109 if (!log_context) { 109 if (!log_context) {
110 return; 110 return;
111 } 111 }
112 for (int i = 0; i < NUM_CHANNELS; i++) { 112 for (int i = 0; i < NUM_CHANNELS; i++) {
562 context->write_cycle = context->current_cycle; 562 context->write_cycle = context->current_cycle;
563 context->busy_cycles = BUSY_CYCLES_ADDRESS; 563 context->busy_cycles = BUSY_CYCLES_ADDRESS;
564 context->status |= 0x80; 564 context->status |= 0x80;
565 } 565 }
566 566
567 uint8_t fnum_to_keycode[] = { 567 static uint8_t fnum_to_keycode[] = {
568 //F11 = 0 568 //F11 = 0
569 0,0,0,0,0,0,0,1, 569 0,0,0,0,0,0,0,1,
570 //F11 = 1 570 //F11 = 1
571 2,3,3,3,3,3,3,3 571 2,3,3,3,3,3,3,3
572 }; 572 };
573 573
574 //table courtesy of Nemesis 574 //table courtesy of Nemesis
575 uint32_t detune_table[][4] = { 575 static uint32_t detune_table[][4] = {
576 {0, 0, 1, 2}, //0 (0x00) 576 {0, 0, 1, 2}, //0 (0x00)
577 {0, 0, 1, 2}, //1 (0x01) 577 {0, 0, 1, 2}, //1 (0x01)
578 {0, 0, 1, 2}, //2 (0x02) 578 {0, 0, 1, 2}, //2 (0x02)
579 {0, 0, 1, 2}, //3 (0x03) 579 {0, 0, 1, 2}, //3 (0x03)
580 {0, 1, 2, 2}, //4 (0x04) 580 {0, 1, 2, 2}, //4 (0x04)
605 {0, 8,16,22}, //29 (0x1D) 605 {0, 8,16,22}, //29 (0x1D)
606 {0, 8,16,22}, //30 (0x1E) 606 {0, 8,16,22}, //30 (0x1E)
607 {0, 8,16,22} 607 {0, 8,16,22}
608 }; //31 (0x1F) 608 }; //31 (0x1F)
609 609
610 uint32_t ym_calc_phase_inc(ym2612_context * context, ym_operator * operator, uint32_t op) 610 static uint32_t ym_calc_phase_inc(ym2612_context * context, ym_operator * operator, uint32_t op)
611 { 611 {
612 uint32_t chan_num = op / 4; 612 uint32_t chan_num = op / 4;
613 //printf("ym_update_phase_inc | channel: %d, op: %d\n", chan_num, op); 613 //printf("ym_update_phase_inc | channel: %d, op: %d\n", chan_num, op);
614 //base frequency 614 //base frequency
615 ym_channel * channel = context->channels + chan_num; 615 ym_channel * channel = context->channels + chan_num;