Mercurial > repos > blastem
comparison oscilloscope.c @ 2275:e27ab5f4bfe3
Fix off by one in oscilloscope rendering
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 02 Jan 2023 11:36:16 -0800 |
parents | d220305e81b9 |
children | d30ea441b92e |
comparison
equal
deleted
inserted
replaced
2274:bf1bb893f104 | 2275:e27ab5f4bfe3 |
---|---|
82 { | 82 { |
83 //TODO: bresenham | 83 //TODO: bresenham |
84 //TODO: at least linear filtering | 84 //TODO: at least linear filtering |
85 int16_t sample = scope->channels[i].samples[(int)(cur_sample + 0.5f)]; | 85 int16_t sample = scope->channels[i].samples[(int)(cur_sample + 0.5f)]; |
86 int y = (float)sample * value_scale + 0.5f; | 86 int y = (float)sample * value_scale + 0.5f; |
87 if (y > row_height / 2) { | 87 if (y > row_height / 2 - 1) { |
88 y = row_height / 2; | 88 y = row_height / 2 - 1; |
89 } else if (y < -(row_height / 2)) { | 89 } else if (y < -(row_height / 2)) { |
90 y = -(row_height / 2); | 90 y = -(row_height / 2); |
91 } | 91 } |
92 y += row_height / 2; | 92 y += row_height / 2; |
93 if (last_y >= 0) { | 93 if (last_y >= 0) { |
104 cur_sample += samples_per_pixel; | 104 cur_sample += samples_per_pixel; |
105 if (cur_sample + 0.5f >= scope->channels[i].period) { | 105 if (cur_sample + 0.5f >= scope->channels[i].period) { |
106 cur_sample -= scope->channels[i].period; | 106 cur_sample -= scope->channels[i].period; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 offset += column_width; | 110 offset += column_width; |
111 if (offset >= width) { | 111 if (offset >= width) { |
112 offset = 0; | 112 offset = 0; |
113 cur_line += pitch * row_height; | 113 cur_line += pitch * row_height; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 render_framebuffer_updated(scope->window, WIDTH); | 118 render_framebuffer_updated(scope->window, WIDTH); |
119 } | 119 } |
120 | 120 |
121 void scope_close(oscilloscope *scope) | 121 void scope_close(oscilloscope *scope) |
122 { | 122 { |