apu.h (2072B)
1 #ifndef APU_H 2 #define APU_H 3 4 #include <stdint.h> 5 6 struct pulse { 7 /* $4000/$4004 */ 8 uint8_t duty : 2; 9 uint8_t envelope : 1; 10 uint8_t const_vol : 1; 11 uint8_t envelope_vol : 4; 12 /* $4001/$4005 */ 13 uint8_t sweep_enable : 1; 14 uint8_t sweep_period : 3; 15 uint8_t sweep_negative : 1; 16 uint8_t sweep_shift_count : 3; 17 /* $4002/$4006 */ 18 uint8_t timer_low; 19 /* $4003/$4007 */ 20 uint8_t length_counter_load : 5; 21 uint8_t timer_high : 3; 22 }; 23 24 struct triangle { 25 /* $4008 */ 26 uint8_t counter_disable : 1; 27 uint8_t counter_reload : 7; 28 /* $400A */ 29 uint8_t timer_low; 30 /* $400B */ 31 uint8_t counter_load : 5; 32 uint8_t timer_high : 3; 33 }; 34 35 struct noise { 36 /* $400C */ 37 uint8_t padding1 : 2; 38 uint8_t loop_envelope : 1; 39 uint8_t constant_volume : 1; 40 uint8_t envelope_volume : 4; 41 /* $400E */ 42 uint8_t loop_noise : 1; 43 uint8_t padding2 : 3; 44 uint8_t noise_period : 4; 45 /* $400F */ 46 uint8_t length_counter_load : 5; 47 uint8_t padding3 : 3; 48 }; 49 50 struct dmc { 51 /* $4010 */ 52 uint8_t irq_enable : 1; 53 uint8_t loop : 1; 54 uint8_t padding1 : 2; 55 uint8_t frequency : 4; 56 /* $4011 */ 57 uint8_t padding2 : 1; 58 uint8_t load_counter : 7; 59 /* $4012 */ 60 uint8_t sample_addr; 61 /* $4013 */ 62 uint8_t sample_length; 63 }; 64 65 struct apu { 66 /* $4000-$4013 (write) */ 67 struct pulse pulse1; 68 struct pulse pulse2; 69 struct triangle triangle; 70 struct noise noise; 71 struct dmc dmc; 72 /* $4015 (write) */ 73 struct control { 74 uint8_t padding : 3; 75 uint8_t dmc_enable : 1; 76 uint8_t noise_enable : 1; 77 uint8_t triangle_enable : 1; 78 uint8_t pulse2_enable : 1; 79 uint8_t pulse1_enable : 1; 80 } control; 81 /* $4015 (read) */ 82 struct status { 83 uint8_t dmc_int : 1; 84 uint8_t frame_int : 1; 85 uint8_t padding : 1; 86 uint8_t dmc_active : 1; 87 uint8_t lc_noise : 1; 88 uint8_t lc_triangle : 1; 89 uint8_t lc_pulse2 : 1; 90 uint8_t lc_pulse1 : 1; 91 } status; 92 /* $4017 (write) */ 93 struct frame_counter { 94 uint8_t mode : 1; 95 uint8_t irq_inhibit : 1; 96 uint8_t padding : 6; 97 } frame_counter; 98 }; 99 extern struct apu apu; 100 101 void apu_tick(void); 102 uint8_t apu_read(uint16_t addr); 103 void apu_write(uint16_t addr, uint8_t byte); 104 105 #endif /* APU_H */