diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -112,6 +112,8 @@ screen_talk(Device *d, u8 b0, u8 w) { | |||
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | static u8 buf[KB(1)]; | ||
116 | |||
115 | static void | 117 | static void |
116 | audio_talk(Device *d, u8 b0, u8 w) { | 118 | audio_talk(Device *d, u8 b0, u8 w) { |
117 | AudioChannel *c = &apu.chan_0; | 119 | AudioChannel *c = &apu.chan_0; |
@@ -126,14 +128,15 @@ audio_talk(Device *d, u8 b0, u8 w) { | |||
126 | c->n_samples = mempeek16(d->dat, 0xa); | 128 | c->n_samples = mempeek16(d->dat, 0xa); |
127 | c->samples = &d->mem[mempeek16(d->dat, 0xc)]; | 129 | c->samples = &d->mem[mempeek16(d->dat, 0xc)]; |
128 | // Transform the samples from u8 to s8. | 130 | // Transform the samples from u8 to s8. |
129 | // for (size_t i = 0; i < c->n_samples; ++i) { | 131 | for (size_t i = 0; i < c->n_samples; ++i) { |
130 | // c->samples[i] = c->samples[i] + 0x80; | 132 | buf[i] = (u8)c->samples[i] + 0x80; |
131 | // } | 133 | } |
134 | c->samples = &buf; | ||
132 | // c->volume[0] = d->dat[0xe] >> 4; | 135 | // c->volume[0] = d->dat[0xe] >> 4; |
133 | // c->volume[1] = d->dat[0xe] & 0xf; | 136 | // c->volume[1] = d->dat[0xe] & 0xf; |
134 | c->loop = !(d->dat[0xf] & 0x80); | 137 | c->loop = !(d->dat[0xf] & 0x80); |
135 | c->pitch = d->dat[0xf] & 0x7f; | 138 | c->pitch = d->dat[0xf] & 0x7f; |
136 | init_sound(c); | 139 | // init_sound(c); |
137 | reset_sound(c); | 140 | reset_sound(c); |
138 | txt_printf("note: %d \n", c->pitch); | 141 | txt_printf("note: %d \n", c->pitch); |
139 | // apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f); | 142 | // apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f); |
@@ -180,6 +183,9 @@ init_uxn(Uxn *u) { | |||
180 | // Initialize PPU. | 183 | // Initialize PPU. |
181 | initppu(&ppu, 30, 20, 0); | 184 | initppu(&ppu, 30, 20, 0); |
182 | 185 | ||
186 | // Enable sound. | ||
187 | SOUND_STATUS = SOUND_ENABLE; | ||
188 | |||
183 | // Copy rom to VM. | 189 | // Copy rom to VM. |
184 | memcpy(u->ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); | 190 | memcpy(u->ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); |
185 | 191 | ||
@@ -188,9 +194,9 @@ init_uxn(Uxn *u) { | |||
188 | portuxn(u, 0x1, "console", console_talk); | 194 | portuxn(u, 0x1, "console", console_talk); |
189 | devscreen = portuxn(u, 0x2, "screen", screen_talk); | 195 | devscreen = portuxn(u, 0x2, "screen", screen_talk); |
190 | devaudio = portuxn(u, 0x3, "audio0", audio_talk); | 196 | devaudio = portuxn(u, 0x3, "audio0", audio_talk); |
191 | portuxn(u, 0x4, "---", nil_talk); | 197 | portuxn(u, 0x4, "audio1", audio_talk); |
192 | portuxn(u, 0x5, "---", nil_talk); | 198 | portuxn(u, 0x5, "audio2", audio_talk); |
193 | portuxn(u, 0x6, "---", nil_talk); | 199 | portuxn(u, 0x6, "audio3", audio_talk); |
194 | portuxn(u, 0x7, "---", nil_talk); | 200 | portuxn(u, 0x7, "---", nil_talk); |
195 | devctrl = portuxn(u, 0x8, "controller", nil_talk); | 201 | devctrl = portuxn(u, 0x8, "controller", nil_talk); |
196 | devmouse = portuxn(u, 0x9, "mouse", nil_talk); | 202 | devmouse = portuxn(u, 0x9, "mouse", nil_talk); |