Re: [hatari-devel] DSP addressing bug |
[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]
I had a look at the patch and i'm still not sure, if everything is correct about it. I read the data sheet over and over and i made two new variants. A few things that i don't understand about the original code: r_reg beeing Sint16: if dsp_core.registers[DSP_REG_R0+numreg] is greater than 0x7FFF, r_reg will be negative, while the unsigned lobound and hibound will be positive. Won't that cause problems comparing them? The calculation that is done, if orig_modifier > modulo, but Nn = P * 2^k is not true: Where did you get this from? Why only doing the modulo operation, if orig_modifier!=modulo. Shouldn't r_reg be always updated to modulo bounds? first variant: static void dsp_update_rn_modulo(Uint32 numreg, Sint16 modifier) { Uint16 bufsize, modulo, lobound, hibound, bufmask, abs_modifier; Sint16 r_reg; modulo = dsp_core.registers[DSP_REG_M0+numreg]+1; bufsize = 1; while (bufsize < modulo) { bufsize <<= 1; } bufmask = bufsize - 1; lobound = dsp_core.registers[DSP_REG_R0+numreg] & (~bufmask); hibound = lobound + modulo - 1; r_reg = (Sint16) dsp_core.registers[DSP_REG_R0+numreg]; if (modifier<0) { abs_modifier = -modifier; } else { abs_modifier = modifier; } if (abs_modifier>modulo) { if (abs_modifier&bufmask) { fprintf(stderr,"Dsp: Modulo addressing result unpredictable\n"); } else { r_reg += modifier; } } else { r_reg += modifier; if (r_reg>hibound) { r_reg -= modulo; } else if (r_reg<lobound) { r_reg += modulo; } } dsp_core.registers[DSP_REG_R0+numreg] = ((Uint32) r_reg) & BITMASK(16); } second variant: static void dsp_update_rn_modulo(Uint32 numreg, Sint16 modifier) { Uint16 bufsize, modulo, bufmask, abs_modifier; Uint32 r_reg, lobound, hibound; modulo = dsp_core.registers[DSP_REG_M0+numreg]+1; r_reg = dsp_core.registers[DSP_REG_R0+numreg]; bufsize = 1; while (bufsize < modulo) { bufsize <<= 1; } bufmask = bufsize - 1; lobound = r_reg & (~bufmask); hibound = lobound + modulo - 1; if (modifier<0) { abs_modifier = -modifier; } else { abs_modifier = modifier; } if (abs_modifier>modulo) { if (abs_modifier&bufmask) { fprintf(stderr,"Dsp: Modulo addressing result unpredictable\n"); return; } else { lobound += modifier; hibound += modifier; } } r_reg += modifier; if (r_reg>hibound) { r_reg -= modulo; } else if (r_reg<lobound) { r_reg += modulo; } dsp_core.registers[DSP_REG_R0+numreg] = r_reg & BITMASK(16); } Am 28.10.2015 um 19:13 schrieb Laurent Sallafranque <laurent.sallafranque@xxxxxxx>:
|
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |