A good tip for speeding these sort of things up is to try and avoid referencing arrays when you can use locals and to simplify any repeated calculations if you can. As an example, I had a similar routine for displaying a normal x-oriented bitmap on an LCD screen which works in strips where each byte you write represents a vertical row of 8 pixels. The routine I originally wrote was:
Code: Select all
Public Sub WriteXBitmap(ByRefConst bmap() As Byte, xPos As Byte = 0, yPos As Byte = 0)
Dim i, j, k, l As Byte
Dim w As Word
Dim bm(8) As Byte
Dim ts As Byte
Dim ImgWidth, ImgHeight As Byte
Clear(bm)
ImgWidth = bmap(0)/8 // Width in bytes
ImgHeight = bmap(1)/8 // Height in pages
For i = 0 To ImgHeight-1
Set_Start_Page(i+(yPos / 8))
Set_Start_Column(D_OFFSET + xPos)
Start_Data
For j = 0 To ImgWidth-1 // Bitmap is 16 bytes wide
w = (i * bmap(0)) + j + 2 // Calculate the offset in the bitmap data table
For k = 0 To 7
ts = bmap(w+(k*ImgWidth))
For l = 0 To 7
bm(l) = bm(l) >> 1
bm(l).7 = ts.7
ts = ts << 1
Next
Next
For k = 0 To 7
Display_Data(bm(k))
Next
Next
Stop_Data
Next
End Sub
In the context of a program which uses this routine it compiled to 11405 words. I spent a while editing it down and removing array references and calculations where possible. I ended up with:
Code: Select all
Public Sub WriteXBitmap(ByRefConst bmap() As Byte, xPos As Byte = 0, yPos As Byte = 0)
Dim i, j, k, l As Byte
Dim w As Word
Dim bm(8) As Byte
Dim ts As Byte
Dim ImgWidth, ImgHeight As Byte
Dim tb As Byte
Dim PWidth As Byte
Clear(bm)
PWidth = bmap(0)
ImgWidth = PWidth/8 // Width in bytes
ImgHeight = bmap(1)/8 // Height in pages
yPos = yPos / 8
For i = 0 To ImgHeight-1
Set_Start_Page(yPos)
Inc(yPos)
Set_Start_Column(D_OFFSET + xPos)
Start_Data
w = (i * PWidth) + 2
j = ImgWidth
Repeat
k = 8
Repeat
ts = bmap(w)
w = w + ImgWidth
For l = 0 To 7
tb = bm(l)
tb = tb >> 1
tb.7 = ts.7
bm(l) = tb
ts = ts << 1
Next
Dec(k)
Until k = 0
For k = 0 To 7
Display_Data(bm(k))
Next
Inc(w)
Dec(j)
Until j = 0
Stop_Data
Next
End Sub
This compiles to 11275 words so I've removed 130 words of code, many of which are run multiple times. The biggest single improvement came from replacing
Code: Select all
bm(l) = bm(l) >> 1
bm(l).7 = ts.7
with
Code: Select all
tb = bm(l)
tb = tb >> 1
tb.7 = ts.7
bm(l) = tb
This saved 60 words which, for a 128x64 image are in a loop which is run 16 * 8 * 8 * 8 = 8192 times. This saves nearly half a million instruction executions....
I'd suggest trying something similar at first and using temporary variables rather than referencing arrays directly.
Simplifying the calculations you do inside the loop will also help and it might be worth trying replacing the const array reference with a calculation if that is possible.
There are other techniques such as using the FSR registers for linear memory access and the Table register for const access but try the above for a starter.