From 36bce8aade0c354aeec3fb9611de655a5f4658c2 Mon Sep 17 00:00:00 2001
From: Georg Lukas <georg@op-co.de>
Date: Fri, 6 Feb 2009 01:00:26 +0100
Subject: [PATCH] flash progress bar; requires division support from crt.a

Warning: libgcc.a path is hardcoded!

---
 Makefile  |    4 ++--
 ramtool.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index f51dd25..f01e63c 100644
--- a/Makefile
+++ b/Makefile
@@ -53,13 +53,13 @@ ramtool.bin: ramtool.elf
 	$(OC) -O binary ramtool.elf ramtool.bin
 
 ramtool.elf: crt.o serial.o lcd.o fonty.o flash.o ramtool.o  lpc2220.ld
-	$(LD) $(LDFLAGS) -o ramtool.elf crt.o serial.o lcd.o fonty.o flash.o ramtool.o
+	$(LD) $(LDFLAGS) -o ramtool.elf crt.o serial.o lcd.o fonty.o flash.o ramtool.o /opt/armtool/4.1.1/lib/gcc/arm-elf/4.1.1/interwork/libgcc.a
 
 romtool.bin: romtool.elf
 	$(OC) -O binary romtool.elf romtool.bin
 
 romtool.elf: crt.o serial.o lcd.o fonty.o flash.o romtool.o  lpc2220_rom.ld
-	$(LD) $(ROMLDFLAGS) -o romtool.elf crt.o serial.o lcd.o fonty.o flash.o romtool.o
+	$(LD) $(ROMLDFLAGS) -o romtool.elf crt.o serial.o lcd.o fonty.o flash.o romtool.o /opt/armtool/4.1.1/lib/gcc/arm-elf/4.1.1/interwork/libgcc.a
 
 crt.o: crt.s
 	$(AS) $(ASFLAGS) -o crt.o crt.s
diff --git a/ramtool.c b/ramtool.c
index d4a44f5..49a73b2 100644
--- a/ramtool.c
+++ b/ramtool.c
@@ -26,6 +26,7 @@ unsigned long checksum;
 unsigned short count;
 unsigned long adr;
 unsigned long numBytes;
+unsigned long gotBytes;
 
 void putHN(unsigned char pos, unsigned long hn)
 {
@@ -41,6 +42,31 @@ void putInfoVal(unsigned char pos, char *name, unsigned long val)
 	putHN(pos, val);
 }
 
+extern char hval[16];
+
+void putProgress(unsigned char pos, int value, int max) {
+	int width = 124*value / max;
+	int pct = 100*value / max;
+	static char str[5] = "100%";
+	str[0] = (pct < 100) ? ' ' : hval[pct / 100];
+	str[1] = (pct < 10) ? ' ' : hval[(pct / 10) % 10];
+	str[2] = hval[pct % 10];
+
+
+	/* draw rectangle frame */
+	draw_hline(0, pos, 128, 3, DRAW_PUT);
+	draw_hline(0, pos+14, 128, 3, DRAW_PUT);
+	draw_vline(0, pos+1, 13, 3, DRAW_PUT);
+	draw_vline(127, pos+1, 13, 3, DRAW_PUT);
+
+	/* draw progress bar */
+	draw_block(2, pos+2, width, 11, 3, DRAW_PUT);
+	draw_block(2+width, pos+2, 124 - width, 11, 3, DRAW_ERASE);
+
+	/* display percentage */
+	draw_string(50, pos+4, str, 3, DRAW_XOR);
+}
+
 void ACK(void)
 {
 	serial_puts(ACKTOKEN);
@@ -240,6 +266,8 @@ fail_f:
 				{
 					adr += (count<<2);
 					ACK();
+					gotBytes += (count<<2);
+					putProgress(130, gotBytes, numBytes);
 				}
 				else
 				{
@@ -308,6 +336,7 @@ fail_f:
 			numBytes += serial_getc() << 16;
 			numBytes += serial_getc() << 8;
 			numBytes += serial_getc();
+			gotBytes = 0;
 			putInfoVal(104, "NumB:", numBytes); 
 			if(numBytes <= 0x00100000)
 			{
-- 
1.5.6.5

