- sndlength = left;
- do {
- err = tcp_write(pcb, fb->fbaddr + state->update_pos, sndlength, TCP_WRITE_FLAG_COPY /* The card can't DMA from there. */);
- if (err == ERR_MEM) /* Back down until lwip says we've got space. */
- sndlength /= 2;
- } while (err == ERR_MEM && sndlength > 1);
+ state->chunk_height = ceildiv(fb->curmode.yres, SCREEN_CHUNKS_Y);
+ state->chunk_ypos = state->chunk_height
+ * state->chunk_ynum;
+ totaldim = state->chunk_height * (state->chunk_ynum + 1);
+ if (totaldim > fb->curmode.yres) {
+ state->chunk_height -= (totaldim - fb->curmode.yres);
+ }
+
+ /* Do we _actually_ need to send this chunk? */
+ if (fb->checksum_rect) {
+ state->chunk_checksum = fb->checksum_rect(state->chunk_xpos, state->chunk_ypos,
+ state->chunk_width, state->chunk_height);
+
+ if (state->chunk_checksum == state->checksums[state->chunk_xnum][state->chunk_ynum]) {
+ if (advance_chunk(state))
+ return;
+ continue;
+ }
+ /* Checksum gets set in data block, AFTER the data has been sent. */
+ }
+
+ outputf("actually sent");
+ state->chunk_actually_sent = 1;
+
+ /* Send a header */
+ hdr.msgtype = 0;
+ state->chunk_bytes_sent = 0;
+ hdr.nrects = htons(1);
+ hdr.xpos = htons(state->chunk_xpos);
+ hdr.ypos = htons(state->chunk_ypos);
+ hdr.width = htons(state->chunk_width);
+ hdr.height= htons(state->chunk_height);
+ hdr.enctype = htonl(0);
+
+ err = tcp_write(pcb, &hdr, sizeof(hdr), TCP_WRITE_FLAG_COPY);