3 ms·
I spent a few days during the last Christmas holidays to create a fast line renderer for an old 8-bit home computer with a 1.75MHz Z80 CPU and a video memory la
by flohofwoe 11y ago
I spent a few days during the last Christmas holidays to create a fast line renderer for an old 8-bit home computer with a 1.75MHz Z80 CPU and a video memory layout that groups 8 horizontal pixels into one byte. I also started with a generic 'put_pixel' subroutine, but that was way too slow no matter what the outer code looked like, because the video memory address had to be computed every time anew, and a pixel could only be set through a read-modify-write (read byte from video memory, set a bit, and write the byte back).
I ended up with an unrolled loop for 8 horizontal pixels and self-modifying code which jumped into this loop similar to a Duff's Device, and at each increment in y a pixel-mask byte was xor'ed into video memory, and a new jump-position into the pixel-loop was computed for the next 8-pixel-mask.
This was even fast enough for rendering a (distorted) 3D wireframe cube: https://www.youtube.com/watch?v=W8kxJLUParo https://www.youtube.com/watch?v=W8kxJLUParo
The line rendering code is here (I'm sure there's even more optimized 8-bit code out there): https://github.com/floooh/kc85sdk/blob/master/test/line.s https://github.com/floooh/kc85sdk/blob/master/test/line.s