I have been using the glcd SSD1306 commands and am impressed. Very fast. I wrote a picaxe game that I want to convert to gcb and need to read a pixel from the screen buffer to see if it's set but don't know where it starts. I have code to find pixel position if it's 8 rows of 128 bytes.
I'm using atmega 328p and pic 18f25k22. I did not have success converting Bresenham's line draw from picaxe to gcb. Please see video https://www.youtube.com/watch?v=gGenryUZBa4
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Pretty cool, looks like an etch-a-sketch to me. My take is you need some sort of known starting point, and from that GLCDX and GLCDY is also known. Look at PSet_SSD1306 sub and you will find the register GLCDDataTemp as the requested screen buffer?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, my error. These notes will expose the methods.
1. There is a memory array that is the map for the pixels. Each array byte maps to eight pixels. The fastest method would be to study PSet_SDD1306 and then create RSet_SDD1306 to read the array for the calculated position of X and Y. Cursor_Position_SSD1306 is also a good reference.
SSD1306_BufferAlias is the array.
I have the latest glcd_SSD1306.h here for the next build. I would recommend you add your changes to your user programs so you do not lose your good work.
2. Bresenham's line draw. What is the issue? What is the need to port?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Anobium. Picaxe has no plot and line code for glcd because picaxe is too slow but it was interesting to code. Your GLCD routine is very good. It would be nice if xor plot and line was added.
xorplot2screenram:
pixel = py%8 ; pixel position
pixel=power(1,pixel)
ptr=((py/8)*128)+px ;screen byte
buffer (ptr)=buffer (ptr) xor pixel ;plot pixel in buffer
I posted elsewhere I get these errors
gcb_plot-not-working.gcb (150): Error: Invalid variable name: POWER1,PIXEL
gcb_plot-not-working.gcb (150): Error: Variable POWER1,PIXEL was not explicitly declared
gcb_plot-not-working.gcb (187): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (187): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (187): Error: Variable POWER(1,PIXEL) was not explicitly declared
gcb_plot-not-working.gcb (191): Error: Variable ROW was not explicitly declared
gcb_plot-not-working.gcb (202): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (202): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (217): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (217): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (231): Error: Cannot store -1 in the byte variable SY
gcb_plot-not-working.gcb (245): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (245): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (268): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (268): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (298): Error: Cannot store -1 in the byte variable SY
gcb_plot-not-working.gcb (310): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (310): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (332): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (332): Error: Invalid variable name: POWER(1,PIXEL)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please. Would this work to find if a pixel is lit? I'm not at home right now.
'is pixel lit
pixel=ty%8 ; pixel position tx,ty
ptr=((ty And $F8)16) Or tx
pixelon=(power (1,pixel)) and point: 'is pixel lit
pixel=ty%8 ; pixel position tx,ty
ptr=((ty And $F8)16) Or tx
pixelon=(power (1,pixel)) and SSD1306_BufferAlias (ptr) ; pixelon 0=not lit
Assuming SSD1306_BufferAlias is the start of the buffer.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Because I'm a new programmer I don't know how to view gcb source code. Is that for linux? I use windows. I read gcb is compiled with gcb????? Can I write my own routines into gcb? I write useful subs and share them but thought library functins were done by clever programers. Is that what open source is about. Is it something to do with github?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ps I forget that the final code is assembler and runs fast so I don't need power(1,val)
I could rotate left val times. It comes from using picaxe, not compiled code. I'm using gcb with arduino as well as pic because I don't do c++. I'm happy as a pig in sh..ugar.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry if I seem dim but please tell me how can I use SSD1306_BufferAlias in my code and why If ChipRAM > 1024 when the display ram 1024 bytes
If ChipRAM > 1024 Then
Dim SSD1306_BufferAlias(1024)
End if
,
This should test if a pixel is lit-copied from GLCD include
; GLCDX,GLCDY-pixel to test-pixelon=1 if pixel on
SSD1306_BufferLocationCalc = ( GLCDY / 8 )* GLCD_WIDTH
SSD1306_BufferLocationCalc = GLCDX + SSD1306_BufferLocationCalc+1
GLCDDataTemp = SSD1306_BufferAlias(SSD1306_BufferLocationCalc)
GLCDBitNo = GLCDY And 7
Repeat GLCDBitNo
Rotate GLCDChange Left
End Repeat
pixelon=SSD1306_BufferAlias(SSD1306_BufferLocationCalc) and GLCDChange
;
GLCDPrint ( 0, 0, pixelon)
How should I define SSD1306_BufferAlias?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Now this does bring back some memories.
It was early 1980. My brother came to stay in Cambridge.
We spent Maundy Thursday unpacking a new BBC Micro and Good Friday writing a game - Tron.
Cambridge was pretty hot in computing then. A few conversations later and I had the game published. 750GBP!
Then, more games, then the BBC Micro B ... developed networking for the BBC Micro and I had a lot of fun. oh.... And, then, the Jupiter Ace! Who remembers that?
Back to your game port. I am travelling so this is theory and this could be incorrect but this are my thoughts from the train!
This is relatively simple. The buffer is a pixel buffer.
Let us use these test cases.
X=0 and Y=0
Buffer( (Y/8) * X ).X mod 8 where () is the buffer byte and .X is the bit.
So, Buffer( (0/8)* 0 ).0 mod 8 equals Buffer( 0 ).0 This contains the state.
X=1 and Y=0
Buffer( (Y/8) * X ).X mod 8 where () is the buffer byte and .X is the bit.
So, Buffer( (0/8) * 1 ).1 mod 8 equals Buffer( 0 ).1 This contains the state.
X=63 and Y=15
Buffer( (Y/8) * X ).X mod 8 where () is the buffer byte and .X is the bit.
So, Buffer( (15/8) * 63 ).63 mod 8 equals Buffer( 63 ).7 This contains the state.
So, it should be simple.
bitstate = Buffer( (Y/8) * X ).X mod 8 ;you may need to expand this and rotate to extract the bit.
My thoughts from the train.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Memories Anobium...I wrote tron for zx spectrum,
"A few conversations later and I had the game published. 750GBP!"
I got 7500GBP!
using atmega 328p, ram data starts at 0x0100 so I pasted this into the GLCD demo
dim ptr as Word
dim pixel as Byte
dim pixelon as Byte
dim tx as Byte
dim ty as Byte
main:
GLCDCLS
pset (20,20,1)
;
tx=20:ty=20
ptr=0x0100
pixel=ty and 8 ; pixel position in screen buffer Byte
ptr=ptr+(ty*128)+tx ; byte in buffer
ty=pixel
repeat ty
rotate pixel
end repeat
pixelon=pixel and peek (ptr) ; pixelon 0=not lit
;
GLCDPrint ( 0, 0, pixelon)
It prints zero but should print 1. I must convert to acsii ??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What does the dot/full stop do?
bitstate = Buffer( (Y/8) * X ).X mod 8 ;you may need to expand this and rotate to extract the bit. ____^
In fact, I didn't understand your code really.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is an untested function. Should work but I do not have a device in my hotel room. If this does not work, and, you cannot fix. Can we please wait until the weekend?
HSerPrint GLCDReadPixel_SSD1306(0,1)
End
'Specific function to SSD1306 - other GLCD would need something similar but NOT the same....
function GLCDReadPixel_SSD1306( In GLCDX, In GLCDY ) as bit
SSD1306_BufferLocationCalc = ( GLCDY / 8 )* GLCD_WIDTH
SSD1306_BufferLocationCalc = GLCDX + SSD1306_BufferLocationCalc+1
GLCDDataTemp = SSD1306_BufferAlias(SSD1306_BufferLocationCalc)
GLCDPixelPtr = GLCDY mod 7
Set C Off
Repeat GLCDPixelPtr
Rotate GLCDDataTemp Left
End Repeat
GLCDReadPixel_SSD1306 =GLCDDataTemp.0
end function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobium. A chat would be nice.I'll try to contact you {how?}. I have got my code to compile with errors about lcd that is not in my code.
I'm writing this library because there is no xor plot or xor line so a meter needle is out as are sprites.
I include code and errors
Doubleclick on errormessage below to go to sourcecode-line:
lcd.h (387): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
lcd.h (388): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (398): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (472): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (473): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (474): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (475): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (849): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (899): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (900): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (901): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (902): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
My brains tired. function GLCDReadPixel_SSD1306( In GLCDX, In GLCDY ) as bit
I assume it is pasted into glcd lib.
so I need to make my xor line code into a function and paste it into glcd lib and save it...yes?
or am I on the wrong track again? Thanks for the function Anobium, I appreciate the help. and kent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No email.
Send me your email address via a personal message.
Meanwhile, as a general rule I would not advise changing the stock libraries.. We can change during releases and you, therefore, easily overwrite your good works. You can replace any library method using #define. Like #define GLCDCLD myGLCDCLS - then create a method in your user code which will not be lost during a release upgrade.
So, do not add to the .h . Simply add to your user code in this case.
Last edit: Anobium 2017-02-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I feel like an idiot! I didn't see the option to erase a line only erase a pixel.The glcd functions are top!
A video of a meter and so little code. https://youtu.be/gKxxL3Y-lzk
glcdcls
GLCDPrint (0,0,"0 10 20 30 40 50")
start:
x1=63:y1=63:y2=8
x2=0:px=x2
do until x2>119
line x1,y1,px,y2,0
px=x2:x2=x2+8
line x1,y1,x2,y2,1
loop
do until x2<8
line x1,y1,px,y2,0
px=x2:x2=x2-8
line x1,y1,x2,y2,1
loop
goto Start
My email is stanleycartwrightatgmail.com
Nice one Anobium.
Last edit: Anobium 2017-02-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been using the glcd SSD1306 commands and am impressed. Very fast. I wrote a picaxe game that I want to convert to gcb and need to read a pixel from the screen buffer to see if it's set but don't know where it starts. I have code to find pixel position if it's 8 rows of 128 bytes.
I'm using atmega 328p and pic 18f25k22. I did not have success converting Bresenham's line draw from picaxe to gcb. Please see video https://www.youtube.com/watch?v=gGenryUZBa4
We have line draw capabilities. Have a look at the Help and there a lot of GLCD demos to give you a great start.
Pretty cool, looks like an etch-a-sketch to me. My take is you need some sort of known starting point, and from that GLCDX and GLCDY is also known. Look at PSet_SSD1306 sub and you will find the register GLCDDataTemp as the requested screen buffer?
Yes, my error. These notes will expose the methods.
1. There is a memory array that is the map for the pixels. Each array byte maps to eight pixels. The fastest method would be to study PSet_SDD1306 and then create RSet_SDD1306 to read the array for the calculated position of X and Y. Cursor_Position_SSD1306 is also a good reference.
SSD1306_BufferAlias is the array.
I have the latest glcd_SSD1306.h here for the next build. I would recommend you add your changes to your user programs so you do not lose your good work.
2. Bresenham's line draw. What is the issue? What is the need to port?
I just posted the latest .h here: http://gcbasic.sourceforge.net/newfiles/glcd_SSD1306.h
Thank you Anobium. Picaxe has no plot and line code for glcd because picaxe is too slow but it was interesting to code. Your GLCD routine is very good. It would be nice if xor plot and line was added.
xorplot2screenram:
pixel = py%8 ; pixel position
pixel=power(1,pixel)
ptr=((py/8)*128)+px ;screen byte
buffer (ptr)=buffer (ptr) xor pixel ;plot pixel in buffer
I posted elsewhere I get these errors
gcb_plot-not-working.gcb (150): Error: Invalid variable name: POWER1,PIXEL
gcb_plot-not-working.gcb (150): Error: Variable POWER1,PIXEL was not explicitly declared
gcb_plot-not-working.gcb (187): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (187): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (187): Error: Variable POWER(1,PIXEL) was not explicitly declared
gcb_plot-not-working.gcb (191): Error: Variable ROW was not explicitly declared
gcb_plot-not-working.gcb (202): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (202): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (217): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (217): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (231): Error: Cannot store -1 in the byte variable SY
gcb_plot-not-working.gcb (245): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (245): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (268): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (268): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (298): Error: Cannot store -1 in the byte variable SY
gcb_plot-not-working.gcb (310): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (310): Error: Invalid variable name: POWER(1,PIXEL)
gcb_plot-not-working.gcb (332): Error: Array/Function PIXEL=POWER has not been declared
gcb_plot-not-working.gcb (332): Error: Invalid variable name: POWER(1,PIXEL)
Pleasure. Are you asking about Picaxe code? If yes, go to the Picaxe forum.
I am not sure what you are trying to achieve. Please post your code.
Please. Would this work to find if a pixel is lit? I'm not at home right now.
'is pixel lit
pixel=ty%8 ; pixel position tx,ty
ptr=((ty And $F8)16) Or tx
pixelon=(power (1,pixel)) and point: 'is pixel lit
pixel=ty%8 ; pixel position tx,ty
ptr=((ty And $F8)16) Or tx
pixelon=(power (1,pixel)) and SSD1306_BufferAlias (ptr) ; pixelon 0=not lit
Assuming SSD1306_BufferAlias is the start of the buffer.
Because I'm a new programmer I don't know how to view gcb source code. Is that for linux? I use windows. I read gcb is compiled with gcb????? Can I write my own routines into gcb? I write useful subs and share them but thought library functins were done by clever programers. Is that what open source is about. Is it something to do with github?
ps I forget that the final code is assembler and runs fast so I don't need power(1,val)
I could rotate left val times. It comes from using picaxe, not compiled code. I'm using gcb with arduino as well as pic because I don't do c++. I'm happy as a pig in sh..ugar.
Sorry if I seem dim but please tell me how can I use SSD1306_BufferAlias in my code and why If ChipRAM > 1024 when the display ram 1024 bytes
If ChipRAM > 1024 Then
Dim SSD1306_BufferAlias(1024)
End if
,
This should test if a pixel is lit-copied from GLCD include
; GLCDX,GLCDY-pixel to test-pixelon=1 if pixel on
SSD1306_BufferLocationCalc = ( GLCDY / 8 )* GLCD_WIDTH
SSD1306_BufferLocationCalc = GLCDX + SSD1306_BufferLocationCalc+1
GLCDDataTemp = SSD1306_BufferAlias(SSD1306_BufferLocationCalc)
GLCDBitNo = GLCDY And 7
Repeat GLCDBitNo
Rotate GLCDChange Left
End Repeat
pixelon=SSD1306_BufferAlias(SSD1306_BufferLocationCalc) and GLCDChange
;
GLCDPrint ( 0, 0, pixelon)
How should I define SSD1306_BufferAlias?
Now this does bring back some memories.
It was early 1980. My brother came to stay in Cambridge.
We spent Maundy Thursday unpacking a new BBC Micro and Good Friday writing a game - Tron.
Cambridge was pretty hot in computing then. A few conversations later and I had the game published. 750GBP!
Then, more games, then the BBC Micro B ... developed networking for the BBC Micro and I had a lot of fun. oh.... And, then, the Jupiter Ace! Who remembers that?
Back to your game port. I am travelling so this is theory and this could be incorrect but this are my thoughts from the train!
This is relatively simple. The buffer is a pixel buffer.
Let us use these test cases.
X=0 and Y=0
Buffer( (Y/8) * X ).X mod 8 where () is the buffer byte and .X is the bit.
So, Buffer( (0/8)* 0 ).0 mod 8 equals Buffer( 0 ).0 This contains the state.
X=1 and Y=0
Buffer( (Y/8) * X ).X mod 8 where () is the buffer byte and .X is the bit.
So, Buffer( (0/8) * 1 ).1 mod 8 equals Buffer( 0 ).1 This contains the state.
X=63 and Y=15
Buffer( (Y/8) * X ).X mod 8 where () is the buffer byte and .X is the bit.
So, Buffer( (15/8) * 63 ).63 mod 8 equals Buffer( 63 ).7 This contains the state.
So, it should be simple.
My thoughts from the train.
Memories Anobium...I wrote tron for zx spectrum,
"A few conversations later and I had the game published. 750GBP!"
I got 7500GBP!
using atmega 328p, ram data starts at 0x0100 so I pasted this into the GLCD demo
dim ptr as Word
dim pixel as Byte
dim pixelon as Byte
dim tx as Byte
dim ty as Byte
main:
GLCDCLS
pset (20,20,1)
;
tx=20:ty=20
ptr=0x0100
pixel=ty and 8 ; pixel position in screen buffer Byte
ptr=ptr+(ty*128)+tx ; byte in buffer
ty=pixel
repeat ty
rotate pixel
end repeat
pixelon=pixel and peek (ptr) ; pixelon 0=not lit
;
GLCDPrint ( 0, 0, pixelon)
It prints zero but should print 1. I must convert to acsii ??
What does the dot/full stop do?
bitstate = Buffer( (Y/8) * X ).X mod 8 ;you may need to expand this and rotate to extract the bit.
____^
In fact, I didn't understand your code really.
If you wish, I can look at this this evening. Send me a personal message with aSkype or Google chat id.
Here is an untested function. Should work but I do not have a device in my hotel room. If this does not work, and, you cannot fix. Can we please wait until the weekend?
Hi Anobium. A chat would be nice.I'll try to contact you {how?}. I have got my code to compile with errors about lcd that is not in my code.
I'm writing this library because there is no xor plot or xor line so a meter needle is out as are sprites.
I include code and errors
Doubleclick on errormessage below to go to sourcecode-line:
lcd.h (387): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
lcd.h (388): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (398): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (472): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (473): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (474): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (475): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (849): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (899): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (900): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (901): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (902): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
I sent you a gmail. I just thought... I could alter the glcd include you posted to do what I want...is it that simple???
My brains tired. function GLCDReadPixel_SSD1306( In GLCDX, In GLCDY ) as bit
I assume it is pasted into glcd lib.
so I need to make my xor line code into a function and paste it into glcd lib and save it...yes?
or am I on the wrong track again? Thanks for the function Anobium, I appreciate the help. and kent
No email.
Send me your email address via a personal message.
Meanwhile, as a general rule I would not advise changing the stock libraries.. We can change during releases and you, therefore, easily overwrite your good works. You can replace any library method using #define. Like #define GLCDCLD myGLCDCLS - then create a method in your user code which will not be lost during a release upgrade.
So, do not add to the .h . Simply add to your user code in this case.
Last edit: Anobium 2017-02-22
I feel like an idiot! I didn't see the option to erase a line only erase a pixel.The glcd functions are top!
A video of a meter and so little code.
https://youtu.be/gKxxL3Y-lzk
glcdcls
GLCDPrint (0,0,"0 10 20 30 40 50")
start:
x1=63:y1=63:y2=8
x2=0:px=x2
do until x2>119
line x1,y1,px,y2,0
px=x2:x2=x2+8
line x1,y1,x2,y2,1
loop
do until x2<8
line x1,y1,px,y2,0
px=x2:x2=x2-8
line x1,y1,x2,y2,1
loop
goto Start
My email is stanleycartwrightatgmail.com
Nice one Anobium.
Last edit: Anobium 2017-02-23
Very good - works on my simulator also!