Commit 202a456a2b2f6f331ee97618a485d8a74599a047
1 parent
3294b949
safer sb16 code
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@728 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
22 additions
and
12 deletions
hw/sb16.c
... | ... | @@ -26,7 +26,6 @@ |
26 | 26 | #define MIN(a, b) ((a)>(b)?(b):(a)) |
27 | 27 | #define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0]))) |
28 | 28 | |
29 | -#define DEREF(x) (void)x | |
30 | 29 | #define log(...) fprintf (stderr, "sb16: " __VA_ARGS__) |
31 | 30 | |
32 | 31 | /* #define DEBUG_SB16 */ |
... | ... | @@ -83,7 +82,7 @@ typedef struct SB16State { |
83 | 82 | |
84 | 83 | /* mixer state */ |
85 | 84 | int mixer_nreg; |
86 | - uint8_t mixer_regs[0x83]; | |
85 | + uint8_t mixer_regs[256]; | |
87 | 86 | } SB16State; |
88 | 87 | |
89 | 88 | /* XXX: suppress that and use a context */ |
... | ... | @@ -192,6 +191,12 @@ static void dma_cmd (uint8_t cmd, uint8_t d0, int dma_len) |
192 | 191 | dsp.speaker = 1; |
193 | 192 | } |
194 | 193 | |
194 | +static inline void dsp_out_data(SB16State *dsp, int val) | |
195 | +{ | |
196 | + if (dsp->out_data_len < sizeof(dsp->out_data)) | |
197 | + dsp->out_data[dsp->out_data_len++] = val; | |
198 | +} | |
199 | + | |
195 | 200 | static void command (SB16State *dsp, uint8_t cmd) |
196 | 201 | { |
197 | 202 | linfo ("%#x\n", cmd); |
... | ... | @@ -228,7 +233,7 @@ static void command (SB16State *dsp, uint8_t cmd) |
228 | 233 | break; |
229 | 234 | |
230 | 235 | case 0x20: |
231 | - dsp->out_data[dsp->out_data_len++] = 0xff; | |
236 | + dsp_out_data(dsp, 0xff); | |
232 | 237 | break; |
233 | 238 | |
234 | 239 | case 0x35: |
... | ... | @@ -315,12 +320,12 @@ static void command (SB16State *dsp, uint8_t cmd) |
315 | 320 | break; |
316 | 321 | |
317 | 322 | case 0xe1: |
318 | - dsp->out_data[dsp->out_data_len++] = sb.ver_lo; | |
319 | - dsp->out_data[dsp->out_data_len++] = sb.ver_hi; | |
323 | + dsp_out_data(dsp, sb.ver_lo); | |
324 | + dsp_out_data(dsp, sb.ver_hi); | |
320 | 325 | return; |
321 | 326 | |
322 | 327 | case 0xf2: |
323 | - dsp->out_data[dsp->out_data_len++] = 0xaa; | |
328 | + dsp_out_data(dsp, 0xaa); | |
324 | 329 | dsp->mixer_regs[0x82] |= dsp->mixer_regs[0x80]; |
325 | 330 | pic_set_irq (sb.irq, 1); |
326 | 331 | return; |
... | ... | @@ -398,9 +403,9 @@ static void complete (SB16State *dsp) |
398 | 403 | break; |
399 | 404 | |
400 | 405 | case 0xe0: |
401 | - dsp->out_data_len = 1; | |
406 | + dsp->out_data_len = 0; | |
402 | 407 | linfo ("data = %#x\n", dsp->in_data[0]); |
403 | - dsp->out_data[0] = dsp->in_data[0] ^ 0xff; | |
408 | + dsp_out_data(dsp, dsp->in_data[0] ^ 0xff); | |
404 | 409 | break; |
405 | 410 | |
406 | 411 | default: |
... | ... | @@ -426,7 +431,7 @@ static IO_WRITE_PROTO (dsp_write) |
426 | 431 | dsp->v2x6 = 0; |
427 | 432 | else if ((1 == val) && (0 == dsp->v2x6)) { |
428 | 433 | dsp->v2x6 = 1; |
429 | - dsp->out_data[dsp->out_data_len++] = 0xaa; | |
434 | + dsp_out_data(dsp, 0xaa); | |
430 | 435 | } |
431 | 436 | else |
432 | 437 | dsp->v2x6 = ~0; |
... | ... | @@ -519,12 +524,15 @@ static IO_READ_PROTO (dsp_read) |
519 | 524 | static IO_WRITE_PROTO(mixer_write_indexb) |
520 | 525 | { |
521 | 526 | SB16State *dsp = opaque; |
522 | - dsp->mixer_nreg = val & 0xff; | |
527 | + dsp->mixer_nreg = val; | |
523 | 528 | } |
524 | 529 | |
525 | 530 | static IO_WRITE_PROTO(mixer_write_datab) |
526 | 531 | { |
527 | 532 | SB16State *dsp = opaque; |
533 | + | |
534 | + if (dsp->mixer_nreg > 0x83) | |
535 | + return; | |
528 | 536 | dsp->mixer_regs[dsp->mixer_nreg] = val; |
529 | 537 | } |
530 | 538 | |
... | ... | @@ -666,6 +674,7 @@ static int magic_of_irq (int irq) |
666 | 674 | } |
667 | 675 | } |
668 | 676 | |
677 | +#if 0 | |
669 | 678 | static int irq_of_magic (int magic) |
670 | 679 | { |
671 | 680 | switch (magic) { |
... | ... | @@ -682,6 +691,7 @@ static int irq_of_magic (int magic) |
682 | 691 | return 2; |
683 | 692 | } |
684 | 693 | } |
694 | +#endif | |
685 | 695 | |
686 | 696 | void SB16_init (void) |
687 | 697 | { |
... | ... | @@ -690,12 +700,12 @@ void SB16_init (void) |
690 | 700 | static const uint8_t dsp_write_ports[] = {0x6, 0xc}; |
691 | 701 | static const uint8_t dsp_read_ports[] = {0x6, 0xa, 0xc, 0xd, 0xe, 0xf}; |
692 | 702 | |
703 | + memset(s->mixer_regs, 0xff, sizeof(s->mixer_regs)); | |
704 | + | |
693 | 705 | s->mixer_regs[0x0e] = ~0; |
694 | 706 | s->mixer_regs[0x80] = magic_of_irq (sb.irq); |
695 | 707 | s->mixer_regs[0x81] = 0x20 | (sb.dma << 1); |
696 | 708 | |
697 | - DEREF (irq_of_magic); | |
698 | - | |
699 | 709 | for (i = 0x30; i < 0x48; i++) { |
700 | 710 | s->mixer_regs[i] = 0x20; |
701 | 711 | } | ... | ... |