Mercurial > hg > dmlib
changeset 274:31e62b1f1b6e
Add boundary checks for the scope drawing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 10 Oct 2012 21:23:09 +0300 |
parents | 3b5493fac928 |
children | 26d714c72c0f |
files | ppl.c |
diffstat | 1 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ppl.c Wed Oct 10 20:45:10 2012 +0300 +++ b/ppl.c Wed Oct 10 21:23:09 2012 +0300 @@ -262,6 +262,7 @@ int xc, ym = y0 + (y1 - y0) / 2, vol = FP_GETH(chn->chVolume); int pitch = screen->pitch / sizeof(Uint32); + int len = chn->chSize; DMFixedPoint offs = chn->chPos; Uint32 coln = dmCol(0.0, 0.8, 0.0), colx = dmCol(1.0, 0, 0); Uint32 *pix = screen->pixels; @@ -276,14 +277,27 @@ if (chn->chData == NULL || !chn->chPlaying) return; - for (xc = x0 + 1; xc < x1 - 1; xc++) + if (chn->chDirection) { - Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255); - pix[xc + val * pitch] = coln; - if (chn->chDirection) + for (xc = x0 + 1; xc < x1 - 1; xc++) + { + if (FP_GETH(offs) >= len) + break; + Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255); + pix[xc + val * pitch] = coln; FP_ADD(offs, chn->chDeltaO); - else + } + } + else + { + for (xc = x0 + 1; xc < x1 - 1; xc++) + { + if (FP_GETH(offs) < 0) + break; + Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255); + pix[xc + val * pitch] = coln; FP_SUB(offs, chn->chDeltaO); + } } }