rem: stk500v2_loadaddr(pgm, 0);
add: last_addr=-1;
context: static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,                               int page_size, int n_bytes){  int addr, block_size;  unsigned char commandbuf[10];  unsigned char buf[266];  unsigned char cmds[4];  int result;  DEBUG("STK500V2: stk500v2_paged_write(..,%s,%d,%d)\n",m->desc,page_size,n_bytes);  if (page_size == 0) page_size = 256;  // determine which command is to be used  if (strcmp(m->desc, "flash") == 0) {    commandbuf[0] = CMD_PROGRAM_FLASH_ISP;  } else if (strcmp(m->desc, "eeprom") == 0) {    commandbuf[0] = CMD_PROGRAM_EEPROM_ISP;  }  commandbuf[4] = m->delay;  // if the memory is paged, load the appropriate commands into the buffer  if (m->mode & 0x01) {    commandbuf[3] = m->mode | 0x80;		// yes, write the stupid page to flash    if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {      fprintf(stderr, "%s: stk500v2_paged_write: loadpage instruction not defined for part \"%s\"\n",              progname, p->desc);      return -1;    }    avr_set_bits(m->op[AVR_OP_LOADPAGE_LO], cmds);    commandbuf[5] = cmds[0];    if (m->op[AVR_OP_WRITEPAGE] == NULL) {      fprintf(stderr, "%s: stk500v2_paged_write: write page instruction not defined for part \"%s\"\n",              progname, p->desc);      return -1;    }    avr_set_bits(m->op[AVR_OP_WRITEPAGE], cmds);    commandbuf[6] = cmds[0];  // otherwise, we need to load different commands in  } else {    commandbuf[3] = m->mode | 0x80;		// yes, write the stupid words to flash    if (m->op[AVR_OP_WRITE_LO] == NULL) {      fprintf(stderr, "%s: stk500v2_paged_write: write instruction not defined for part \"%s\"\n",              progname, p->desc);      return -1;    }    avr_set_bits(m->op[AVR_OP_WRITE_LO], cmds);    commandbuf[6] = cmds[0];  }  // the read command is common to both methods  if (m->op[AVR_OP_READ_LO] == NULL) {    fprintf(stderr, "%s: stk500v2_paged_write: read instruction not defined for part \"%s\"\n",            progname, p->desc);    return -1;  }  avr_set_bits(m->op[AVR_OP_READ_LO], cmds);  commandbuf[7] = cmds[0];  commandbuf[8] = m->readback[0];  commandbuf[9] = m->readback[1];  stk500v2_loadaddr(pgm, 0);  for (addr=0; addr < n_bytes; addr += page_size) {    report_progress(addr,n_bytes,NULL);    if ((n_bytes-addr) < page_size)      block_size = n_bytes - addr;    else      block_size = page_size;    DEBUG("block_size at addr %d is %d\n",addr,block_size);    memcpy(buf,commandbuf,sizeof(commandbuf));    buf[1] = block_size >> 8;    buf[2] = block_size & 0xff;    memcpy(buf+10,m->buf+addr, block_size);    result = stk500v2_command(pgm,buf,block_size+10, sizeof(buf));    if (buf[1] != STATUS_CMD_OK) {      fprintf(stderr,"%s: stk500v2_paged_write: write command failed with %d\n",              progname,buf[1]);      return -1;    }  }  return n_bytes;}