Hi Ben,
I do not see anything wrong with your code. I am not in a position to test it at the moment.
What I do when I'm stumped is to modify the code, skip over sections, and see of I can identify where the problem is occurring. I would start by commenting out the copy of that last, odd sized section. If that doesn't reveal anything, put it back and remove the copy of another cevtion. This may not help you, but it shouldn't hurt. (we hope)
Long ago, when I used to fool with high-res graphics, I used to put he CPU into "big real mode", sometimes called "voodoo mode". Best name. IMO, would be "relimited real mode". You put the CPU into protected mode, point one ot more segment registers at a descriptor with a 4G limitt, and then swap back int real mode. This lets you use BIOS interrupts again. but you can address the entire graphics memory, even though it's more than 64k. This mode does not play nicely with other modes (Windows) so you may not be able to use it (easily). Nice to be able to address the whole block of graphics at once, though...
Good luck finding the problem with your code!
Best,
Frank