diff --git a/ChangeLog b/ChangeLog
index 7da9ebe4..e41359de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-07-24 Thomas Fischl <tfischl@gmx.de>
+
+	* usbasp.c: Added long addresses to support devices with more
+        than 64kB flash. Closes bug #20558: Long address problem with
+        USBasp.
+
 2007-06-27 Joerg Wunsch <j@uriah.heep.sax.de>
 
 	* Makefile.am (EXTRA_DIST): Add ChangeLog-2004-2006.
diff --git a/usbasp.c b/usbasp.c
index 434d8229..6bfe14e0 100644
--- a/usbasp.c
+++ b/usbasp.c
@@ -316,8 +316,22 @@ static int usbasp_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
       wbytes = 0;
     }
 
+    /* set address (new mode) - if firmware on usbasp support newmode, then they use address from this command */
+    unsigned char temp[4];
+    memset(temp, 0, sizeof(temp));
     cmd[0] = address & 0xFF;
     cmd[1] = address >> 8;
+    cmd[2] = address >> 16;
+    cmd[3] = address >> 24;
+    usbasp_transmit(1, USBASP_FUNC_SETLONGADDRESS, cmd, temp, sizeof(temp));	
+    
+    /* send command with address (compatibility mode) - if firmware on
+	  usbasp doesn't support newmode, then they use address from this */
+    cmd[0] = address & 0xFF;
+    cmd[1] = address >> 8;
+    // for compatibility - previous version of usbasp.c doesn't initialize this fields (firmware ignore it)
+    cmd[2] = 0;
+    cmd[3] = 0;
 
     n = usbasp_transmit(1, function, cmd, buffer, blocksize);
 
@@ -366,6 +380,19 @@ static int usbasp_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
       blockflags |= USBASP_BLOCKFLAG_LAST;
     }
 
+    /* set address (new mode) - if firmware on usbasp support newmode, then
+      they use address from this command */
+    unsigned char temp[4];
+    memset(temp, 0, sizeof(temp));
+    cmd[0] = address & 0xFF;
+    cmd[1] = address >> 8;
+    cmd[2] = address >> 16;
+    cmd[3] = address >> 24;
+    usbasp_transmit(1, USBASP_FUNC_SETLONGADDRESS, cmd, temp, sizeof(temp));
+    
+    /* normal command - firmware what support newmode - use address from previous command,
+      firmware what doesn't support newmode - ignore previous command and use address from this command */
+      
     cmd[0] = address & 0xFF;
     cmd[1] = address >> 8;
     cmd[2] = page_size & 0xFF;
diff --git a/usbasp.h b/usbasp.h
index 003a6088..2da429bc 100644
--- a/usbasp.h
+++ b/usbasp.h
@@ -39,6 +39,7 @@
 #define USBASP_FUNC_WRITEFLASH 6
 #define USBASP_FUNC_READEEPROM 7
 #define USBASP_FUNC_WRITEEEPROM 8
+#define USBASP_FUNC_SETLONGADDRESS 9
 
 #define USBASP_BLOCKFLAG_FIRST    1
 #define USBASP_BLOCKFLAG_LAST     2