Image writing
Moderators: David Barker, Jerry Messina
Thanks Tim.
I've persisted. This will print the 1024 byte 1bit bitmap data.
There's probably a way to neaten it.
Note: The "-1" is to invert the bit so that the image on a Yellow/green GLCD looks the same as the on your PC. You can leave it out for Blue/White.
Anyway, here's my small contribution if you want to tidy it.
Speed?
Well, quicker than you can say 'plop'.
Thanks everyone.
I've persisted. This will print the 1024 byte 1bit bitmap data.
There's probably a way to neaten it.
Note: The "-1" is to invert the bit so that the image on a Yellow/green GLCD looks the same as the on your PC. You can leave it out for Blue/White.
Anyway, here's my small contribution if you want to tidy it.
Code: Select all
Sub PlotPicture2()
XPos = 0
YPos = 7
GWord = 0
GCommand = DByte(1)
For I = 7 To 0 Step -1
For X2 = 0 To 15 ' Loop to get 8x8 cell . 16 = 1 line.
For X1 = 0 To 7 ' Generate cell byte (a vertical byte)
CellByte.7 = 1- (DByte(GWord) <<X1 >>7) ' Pick out bits
CellByte.6 = 1- (DByte(GWord+16) <<X1 >>7)
CellByte.5 = 1- (DByte(GWord+32) <<X1 >>7)
CellByte.4 = 1- (DByte(GWord+48) <<X1 >>7)
CellByte.3 = 1- (DByte(GWord+64) <<X1 >>7)
CellByte.2 = 1- (DByte(GWord+80) <<X1 >>7)
CellByte.1 = 1- (DByte(GWord+96) <<X1 >>7)
CellByte.0 = 1- (DByte(GWord+112) <<X1 >>7)
Pos.x = XPos // GLCD x pos
Pos.y = YPos // GLCD y pos
WriteByte(CellByte) // write a byte to KS0108
Inc(XPos)
Next 'Vertical byte
Inc(GWord) ' Next group of image bytes
Next 'X2
Dec(YPos)
XPos = 0 ' Set X back to start of line
Inc(GWord,112) ' Next block up
Next
End Sub
Well, quicker than you can say 'plop'.
Thanks everyone.
Last edited by Francis on Tue Jul 17, 2007 7:50 pm, edited 1 time in total.
Ok I could not resist it
Knocked of ~ 300 bytes with this, unable to test it unfortunately, I could reduce it more
Knocked of ~ 300 bytes with this, unable to test it unfortunately, I could reduce it more
Code: Select all
Include "ks0108.bas"
Dim XPos As Pos.x
Dim YPos As Pos.y
Dim gword As Byte
Dim x1, x2, I, CellByte As Byte
Dim GCommand As Byte
Dim DByte(1024) As Byte
Function DByteRead(POffset As Byte) As Byte
result = DByte(POffset+POffset)
result = (result <<x1 >>7)
End Function
Sub PlotPicture2()
XPos = 0
YPos = 7
gword = 0
GCommand = DByte(1)
For I = 7 To 0 Step -1
For x2 = 0 To 15 ' Loop to get 8x8 cell . 15 is a linesworth.
For x1 = 0 To 7 ' Generate cell byte (a vertical byte)
CellByte.7 = DByteRead(0) ' Pick out bits
CellByte.6 = DByteRead(16)
CellByte.5 = DByteRead(32)
CellByte.4 = DByteRead(48)
CellByte.3 = DByteRead(64)
CellByte.2 = DByteRead(80)
CellByte.1 = DByteRead(96)
CellByte.0 = DByteRead(112)
Pos.x = XPos // GLCD x pos
Pos.y = YPos // GLCD y pos
WriteByte(Not(CellByte)) // write a byte to KS0108
Inc(XPos)
Next 'Vertical byte
Inc(gword) ' Next group of image bytes
Next 'X2
Dec(YPos)
XPos = 0 ' Set X back to start of line
Inc(gword,112) ' Next block up
Next
End Sub
PlotPicture2
End
Err that looks wrong....
Code: Select all
Dim XPos As Pos.x
Dim YPos As Pos.y
Dim gword As Word
Dim x1, x2, I, CellByte As Byte
Dim GCommand As Byte
Dim DByte(1024) As Byte
Function DByteRead(POffset As Byte) As Byte
result = DByte(gword+POffset)
result = (result <<x1 >>7)
End Function
Aha, too tempting huh? Thanks, good stuff.
One little change needed:
Function DByteRead(POffset As Byte) As Byte
result = DByte(GWord+POffset)
result = (result <<X1 >>7)
End Function
I'm sure that was just a typo due to excitement
Another lesson for me.
Post crossed.... cheers!
Virtual pint on it's way.
One little change needed:
Function DByteRead(POffset As Byte) As Byte
result = DByte(GWord+POffset)
result = (result <<X1 >>7)
End Function
I'm sure that was just a typo due to excitement
Another lesson for me.
Post crossed.... cheers!
Virtual pint on it's way.
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
One little tip that is worth taking on board is to use local subroutine variables wherever possible. With Tims modification, it's probably OK to keep GWord and X1 as module level variables - this will ensure DReadByte executes a little quicker.
However, I would certainly look at placing some of your variables into the sub itself. For example,
XPos and YPos are actually aliases, but if they are only used inside ONE sub, it's worth making them private to that routine.
Personally, I would look at passing Gword and X1 to the DReadByte routine. It will increase your code space and execution time (very marginally!) but if you do this and don't notice a decrease in rendering speed then definitely look at doing it.
The main advantages of using parameter passing and making variables local are
(a) Swordfish can recycle all RAM used when the subroutine returns
(b) The subroutine is 'encapsulated'. That is, it doesn't have any external variable dependencies. This can make subroutines much more reusable and robust.
If you really wanted to go all the way, also look at passing the array 'byref'...
However, I would certainly look at placing some of your variables into the sub itself. For example,
Code: Select all
sub PlotPicture2()
dim XPos as Pos.x
dim YPos as Pos.y
dim x2, I, CellByte as byte
Personally, I would look at passing Gword and X1 to the DReadByte routine. It will increase your code space and execution time (very marginally!) but if you do this and don't notice a decrease in rendering speed then definitely look at doing it.
The main advantages of using parameter passing and making variables local are
(a) Swordfish can recycle all RAM used when the subroutine returns
(b) The subroutine is 'encapsulated'. That is, it doesn't have any external variable dependencies. This can make subroutines much more reusable and robust.
If you really wanted to go all the way, also look at passing the array 'byref'...
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
he he heDavid Barker wrote:I didn't mean it to come across as 'this is how it must be done'
At the end of the day, if you code a program and it works correctly and meets your design criteria - then that's all that matters...
Hopefully, the designs and codes you suggest, David, meets always the criteria of everyone on the forum