Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:15 29 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MK2: Graphics with flashing text cursor

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8584
Posted: 09:39am 27 Nov 2014
Copy link to clipboard 
Print this post

The rubbish weather is good for something - I can get lots of coding done!

This new version puts the screen refresh into an interrupt routine so the refresh command never needs to be called - screen updates should happen within 200msec. The clearscreen routine now just zeroes the local array and lets the interrupt routine update the screen. I've timed wiping the display completely at about 63msec.
Two routines "enablecursor" and "disablecursor" do what they say. The cursors work in all screen rotations and all text orientations. The cursor flashes with a cycle time of 800msec to the right of the last character output. It is only repositoned by "pstring" so you need to organise the text output to leave it where you want it.
The cursors will only be maintained properly if text is output using the "pstring" subroutine and not the "dchar" primitive so pstring should be used even for single characters. "pstring" also updates the x and y coordinates so an additional string can be output without repositioning the currsor as long as "pstring" is called with the x and y coordinates specified as variables. This should be useful for example displaying user input. There is no "wordwrap" capability

The example main program demonstrates all the features of the library and acts as a regression test for me.

For live use of course, depending on use, many of the basic graphics routines can be deleted to save space. I haven't drawn up a dependency list but is is pretty obvious from the code.

The cFunctions haven't changed.

Best Regards

Peter


' Monochrome Port of Adafruit graphics library with drivers for i2c SSD1306 display
'
' drawing primitives assume a graphics display where top left is point 0,0
'
'sub setrot(x) 'sets screen rot: 0=normal,1=invert,2=rotate right,3-rotate left
'sub dcirc(x0,y0,r) 'x,y coordinates of centre,radius
'sub fcirc(x0,y0,r) 'x,y coordinates of centre,radius
'sub dtri(x0,y0,x1,y1, x2,y2) 'three coordinate pairs
'sub ftri (x0,y0,x1,y1, x2,y2) 'three coordinate pairs
'sub dChar(xx,yy,ch,sz,orientation) 'x,y coordinates of top left of first character,ascii character,size,orientation
'sub pstring(xx0,yy0,text$,sz,orientation) 'x,y coordinates of top left of first character,text string,size,orientation
'sub dLine(xx0,yy0,xx1,yy1)' x,y of start line,x,y of end line
'sub dRect(x,y,w,h) 'x,y coordinate of top left,width,height
'sub frect(x,y,w,h)'x,y coordinate of top left,width,height
'sub drndRect(x,y,w,h,r) 'x,y coordinates of top left,width,height,radius of corner
'sub frndRect(x,y,w,h,r) 'x,y coordinates of top left,width,height,radius of corner
'
' These routines just update the memory image of the display
' Use the refresh command to write to the display as required
'
'CFunctions
'unsigned long long ffr(unsigned int *sense,unsigned int *x,unsigned int *y,unsigned int *width,unsigned int *height,unsigned int *rotation,unsigned int *screenwidth,unsigned int *screenheight,unsigned long long sc[]){
'unsigned long long S_getnextupdate(unsigned char outchar[],unsigned int *startcol,unsigned int *startrow,unsigned int *col,unsigned int *row,unsigned int *maxcols,unsigned int *maxrows,unsigned long long sc[],unsigned long long dd[]){
'unsigned long long pix(unsigned int *onoff,unsigned int *x,unsigned int *y,unsigned int *rot,unsigned int *wi,unsigned int *ht,unsigned long long p_array[])
'data cFunction FONT contains the pixel maps for the character set
cpu 48
OPTION EXPLICIT
OPTION DEFAULT NONE
'option autorun on
const normal=0
const inverse=1
const rt_right=2
const rt_left=3
const ON=&B1
const OFF=&B0
const ch=8
const cw=6
'
' SSD1306 Display specific constants
const S_wi=128
const S_ht=64
const S_nr=S_ht\8 'memory is arranged as rows 8 bits high
const S_i2caddr=&H3C
const S_SETCONTRAST=&H81
const S_DISPLAYALLON_RESUME=&HA4
const S_NORMALDISPLAY=&HA6
const S_DISPLAYOFF=&HAE
const S_DISPLAYON=&HAF
const S_SETDISPLAYOFFSET=&HD3
const S_SETCOMPINS=&HDA
const S_SETVCOMDETECT=&HDB
const S_SETDISPLAYCLOCKDIV=&HD5
const S_SETPRECHARGE=&HD9
const S_SETMULTIPLEX=&HA8
const S_SETSTARTLINE=&H40
const S_MEMORYMODE=&H20
const S_COMSCANDEC=&HC8
const S_SEGREMAP=&HA0
const S_CHARGEPUMP=&H8D
dim as integer debug=1
'
dim as integer wi,ht,nr,i2caddr,rot_ht,rot_wi,sz,nc,rot,i,j,k,char,AddrOfFo nt
dim as integer cursorx=255,cursory=255,cursorsizex,cursorsizey,allowupdate= ON,cursoronoff=on,cursorenable,cursorupdate=0 ' Global variables to enable flashing cursor
dim as integer sc(128),dd(128) 'set up arrays for screen map to mimic display

init:
print "Starting initialisation"
print "Using SSD1306"
initSdisplay 'initialise the display
AddrOfFont=PEEK(CFunAddr FONT) '
setrot(normal)
print "starting main"
'
dim as integer xforstring,yforstring

Main:
disablecursor
' test drawing rectangles
S_clearsc
for i=0 to 3
setrot(i)
frect(5,5,10,15)
drect(2,2,16,21)
next i
pause 2000
' test drawing rounded rectangles
S_clearsc
for i=0 to 3
setrot(i)
frndrect(5,5,10,15,4)
drndrect(2,2,16,21,6)
next i
pause 2000
' test drawing circles
S_clearsc
for i=0 to 3
setrot(i)
fcirc(10,10,7)
dcirc(10,10,9)
next i
pause 2000
' test drawing triangles and line drawing
S_clearsc
for i=0 to 3
setrot(i)
ftri(4,4,20,6,12,14)
dtri(1,2,24,4,12,17)
next i
pause 2000
' test character output and string output at all orientations
for sz=1 to 3
enablecursor
nc=2 'number of characters in the string I'm using
S_clearsc
setrot(normal)
xforstring=0
yforstring=0
pstring(xforstring,yforstring,"0g",sz,normal)
pstring(xforstring,yforstring,"A",sz,normal)
pause 2000
pstring(rot_wi-1,rot_ht-1,"0g",sz,inverse)
pause 2000
pstring(rot_wi-1,0,"0g",sz,rt_right)
pause 2000
pstring(0,rot_ht-1,"0g",sz,rt_left)
pause 2000
S_clearsc
setrot(inverse)
pstring(0,0,"0g",sz,normal)
pause 2000
pstring(rot_wi-1,rot_ht-1,"0g",sz,inverse)
pause 2000
pstring(rot_wi-1,0,"0g",sz,rt_right)
pause 2000
pstring(0,rot_ht-1,"0g",sz,rt_left)
pause 2000
S_clearsc
setrot(rt_right)
pstring(0,0,"0g",sz,normal)
pause 2000
pstring(rot_wi-1,rot_ht-1,"0g",sz,inverse)
pause 2000
pstring(rot_wi-1,0,"0g",sz,rt_right)
pause 2000
pstring(0,rot_ht-1,"0g",sz,rt_left)
pause 2000
S_clearsc
setrot(rt_left)
pstring(0,0,"0g",sz,normal)
pstring(0,0,"0g",sz,normal)
pause 2000
pstring(rot_wi-1,rot_ht-1,"0g",sz,inverse)
pause 2000
pstring(rot_wi-1,0,"0g",sz,rt_right)
pause 2000
pstring(0,rot_ht-1,"0g",sz,rt_left)
pause 2000
disablecursor
pause 4000
next sz
goto main
end
end

'
' SSD1306 Display specific routines
'
'
S_update:
cursorupdate=cursorupdate+1
if cursorenable and allowupdate and (cursorupdate mod 2) then
if cursoronoff then
crect(cursorx,cursory,cursorsizex,cursorsizey)
cursoronoff=off
else
cursoronoff=on
frect(cursorx,cursory,cursorsizex,cursorsizey)
endif
endif
S_refresh
ireturn
'
sub initSdisplay 'i2c oled
local i as integer
wi=S_wi
ht=S_ht
nr=S_nr
i2caddr=S_i2caddr
I2C OPEN 400,1000
S_command(S_DISPLAYOFF)' &HAE
S_command(S_SETDISPLAYCLOCKDIV)'&HD5
S_command(&H80)'the suggested ratio &H80
S_command(S_SETMULTIPLEX)'&HA8
S_command(&H3F)'
S_command(S_SETDISPLAYOFFSET)'&HD3
S_command(&H0)'no offset
S_command(S_SETSTARTLINE )'line #0
S_command(S_CHARGEPUMP)'&H8D
S_command(&H14)
S_command(S_MEMORYMODE)' &H20
S_command(&H00)'&H0 act like ks0108
S_command(S_SEGREMAP OR 1);
S_command(S_COMSCANDEC);
S_command(S_SETCOMPINS)' &HDA
S_command(&H12)
S_command(S_SETCONTRAST)'&H81
S_command(&HCF)
S_command(S_SETPRECHARGE)'&Hd9
S_command(&HF1)
S_command(S_SETVCOMDETECT)'&HDB
S_command(&H40)
S_command(S_DISPLAYALLON_RESUME)'&HA4
S_command(S_NORMALDISPLAY)'&HA6
S_command(S_DISPLAYON)
for i=0 to 127 'force the whole screen to be re-written at the next refresh
dd(i)= &HFFFFFFFFFFFFFFFF
sc(i)=0
next i
s_refresh
settick 200,s_update,1 'start the update interupt
end sub
'
Sub S_Command(command as integer)
I2C WRITE i2caddr,0,2,&H00,command
end sub
'
'
sub S_SendData(Dchar as integer)
I2C WRITE i2caddr,0,2,&H40,Dchar
end sub
'
sub S_refresh
local as integer rows=0,cols=0,startrow,startcol,retstatus
local outchar$ length 130
S_cursor(0,0)
do
retstatus=Sgetnextupdate(outchar$,startcol,startrow,cols,row s,wi,nr,sc(),dd())
if retstatus<>0 then
S_cursor(startcol,startrow)
i2c write i2caddr,0,len(outchar$),outchar$
endif
loop while retstatus<>0
end sub
'
Sub S_Clearsc
local i as integer
for i=0 to 127
sc(i)=0
next i
end sub
'
sub S_Cursor(x as integer,y as integer)
S_command(&HB0+y) 'set page address
S_command(&H10+(x>>4 and &H0F)) 'set high col address
S_command(&H00+(x AND &H0f)) 'set low col address
end sub
'
' Generic drawing routines
'
sub dcirc(x0 as integer,y0 as integer,r as integer) 'x,y coordinates of centre,radius
local as integer f=1-r,ddF_x=1,ddF_y=-2 * r,x=0,y=r,dp
dp=pix(ON,x0,y0+r,rot,wi,ht,sc())
dp=pix(ON,x0,y0-r,rot,wi,ht,sc())
dp=pix(ON,x0+r,y0,rot,wi,ht,sc())
dp=pix(ON,x0-r,y0,rot,wi,ht,sc())
do while (x<y)
if f>=0 then
y=y-1
ddF_y=ddF_y+2
f=f+ddF_y
endif
x=x+1
ddF_x=ddF_x+2
f=f+ddF_x
dp=pix(ON,x0+x,y0+y,rot,wi,ht,sc())
dp=pix(ON,x0-x,y0+y,rot,wi,ht,sc())
dp=pix(ON,x0+x,y0-y,rot,wi,ht,sc())
dp=pix(ON,x0-x,y0-y,rot,wi,ht,sc())
dp=pix(ON,x0+y,y0+x,rot,wi,ht,sc())
dp=pix(ON,x0-y,y0+x,rot,wi,ht,sc())
dp=pix(ON,x0+y,y0-x,rot,wi,ht,sc())
dp=pix(ON,x0-y,y0-x,rot,wi,ht,sc())
loop
end sub
'
sub dtri(x0 as integer,y0 as integer,x1 as integer,y1 as integer, x2 as integer,y2 as integer) 'three coordinate pairs
dLine(x0,y0,x1,y1)
dLine(x1,y1,x2,y2)
dLine(x2,y2,x0,y0)
end sub
'
sub ftri (x0 as integer,y0 as integer,x1 as integer,y1 as integer, x2 as integer,y2 as integer) 'three coordinate pairs
local as integer a,b,y,dp,last
if (y0>y1) then
swap(y0,y1)
swap(x0,x1)
endif
if (y1>y2) then
swap(y2,y1)
swap(x2,x1)
endif
if (y0>y1) then
swap(y0,y1)
swap(x0,x1)
endif
if(y0=y2) then ' Handle awkward all-on-same-line case as its own thing
a=x0
b=x0
if(x1<a) then
a=x1
else
if(x1>b) then b=x1
endif
if(x2<a) then
a=x2
else
if(x2>b) then b=x2
endif
dFastHLine(a,y0,b-a+1)
exit sub
endif
local as integer dx01=x1-x0, dy01=y1-y0, dx02=x2-x0, dy02=y2-y0,dx12=x2-x1, dy12=y2-y1, sa=0,sb=0
if(y1=y2) then
last=y1 'Include y1 scanline
else
last=y1-1 ' Skip it
endif
for y=y0 to last
a=x0+sa \ dy01
b=x0+sb \ dy02
sa=sa+dx01
sb=sb+dx02
a=x0+(x1-x0) * (y-y0) \ (y1-y0)
b=x0+(x2-x0) * (y-y0) \ (y2-y0)
if(a>b) then swap(a,b)
dp=ffr(ON,a,y,b-a+1,1,rot,wi,ht,sc())
next y
sa=dx12 * (y-y1)
sb=dx02 * (y-y0)
do while y<=y2
a=x1+sa \ dy12
b=x0+sb \ dy02
sa=sa+dx12
sb=sb+dx02
a=x1+(x2-x1) * (y-y1) \ (y2-y1)
b=x0+(x2-x0) * (y-y0) \ (y2-y0)
if(a>b) then swap(a,b)
dp=ffr(ON,a,y,b-a+1,1,rot,wi,ht,sc())
y=y+1
loop
end sub
'
sub enablecursor
cursorenable=on
end sub
'
sub disablecursor
cursorenable=off
cursoroff
end sub
'
sub cursoroff
if cursorx<>255 then 'get rid of any cursor from a previous pstring
crect(cursorx,cursory,cursorsizex,cursorsizey)
cursoronoff=OFF
endif
end sub
'
sub pstring(xx0 as integer,yy0 as integer,text$ as string,sz as integer,orientation as integer) 'x,y coordinates of top left of first character,text string,size,orientation
local as integer i,c,x=xx0,y=yy0
allowupdate=off 'stop the update routine processing the cursor
cursoroff
if orientation<2 then
cursorsizey=(ch-1)*sz
cursorsizex=sz
else
cursorsizey=sz
cursorsizex=(ch-1)*sz
endif
for i=1 to len(text$)
c=asc(mid$(text$,i,1))
dchar(x,y,c,sz,orientation)
on orientation+1 goto pnormal,pinvert,prtright,prtleft
pnormal:
x=x+(6*sz)
cursorx=x-sz
cursory=yy0
goto pcontinue
pinvert:
x=x-(6*sz)
cursorx=x+1
cursory=yy0-(ch-1)*sz+1
goto pcontinue
prtright:
y=y+(6*sz)
cursorx=x-(ch-1)*sz +1
cursory=y-sz
goto pcontinue
prtleft:
y=y-(6*sz)
cursorx=x
cursory=y+1
pcontinue:
next i
allowupdate=on
xx0=x
yy0=y
end sub
'
sub dLine(xx0 as integer,yy0 as integer,xx1 as integer,yy1 as integer) ' x,y of start line,x,y of end line
local as integer dx,dy,x0=xx0,y0=yy0,x1=xx1,y1=yy1,err,ystep,dp,steep=(abs(y1 -y0))>(abs(x1-x0))
if (steep) then
swap(x0,y0)
swap(x1,y1)
endif
if (x0>x1) then
swap(x0,x1)
swap(y0,y1)
endif
dx=x1-x0
dy=abs(y1-y0)
err=dx \ 2
if y0<y1 then
ystep=1
else
ystep=-1
endif
do while x0<=x1
if (steep) then
dp=pix(ON,y0,x0,rot,wi,ht,sc())
else
dp=pix(ON,x0,y0,rot,wi,ht,sc())
endif
err=err-dy
if err<0) then
y0=y0+ystep
err=err+dx
endif
x0=x0+1
loop
end sub
'
sub swap (a as integer,b as integer)
local as integer t
t=b
b=a
a=t
end sub
'
sub dRect(x as integer,y as integer,w as integer,h as integer) 'x,y coordinate of top left,wi,ht
local as integer a,dp
dp=ffr(ON,x,y,w,1,rot,wi,ht,sc())
a=y+h-1
dp=ffr(ON,x,a,w,1,rot,wi,ht,sc())
dp=ffr(ON,x,y,1,h,rot,wi,ht,sc())
a=x+w-1
dp=ffr(ON,a,y,1,h,rot,wi,ht,sc())
end sub
'
sub frect(x as integer,y as integer,w as integer,h as integer) 'x,y coordinate of top left,width,height
local as integer dp
dp=ffr(ON,x,y,w,h,rot,wi,ht,sc())
end sub
'
sub crect(x as integer,y as integer,w as integer,h as integer) 'x,y coordinate of top left,width,height
local as integer dp
dp=ffr(OFF,x,y,w,h,rot,wi,ht,sc())
end sub
'
FUNCTION Getchar(char as integer) as integer
local as integer i=char<<3
Getchar=PEEK(WORD AddrOfFont+i)+(PEEK(WORD AddrOfFont+i+4)<<32)
END FUNCTION
'
sub dChar(xx as integer,yy as integer,ch as integer,sz as integer,orientation as integer) 'x,y coordinates of top left of first character,ascii character,size,orientation
local as integer i,j,x=xx,y=yy,dp,addr,character
character=getchar(ch) 'loads the character
on orientation+1 goto dnormal,dinvert,drtright,drtleft
dnormal:
for i=0 to 5
for j=0 to 7
if (character>>(i*8+j)) and 1 then
if (sz=1) then
dp=pix(ON,x+5-i,y+j,rot,wi,ht,sc())
else
dp=ffr(ON,x+(5-i)*sz,y+(j*sz),sz,sz,rot,wi,ht,sc())
endif
else
if (sz=1) then
dp=pix(OFF,x+5-i,y+j,rot,wi,ht,sc())
else
dp=ffr(OFF,x+(5-i)*sz,y+(j*sz),sz,sz,rot,wi,ht,sc())
endif
endif
next j
next i
exit sub
'
dinvert:
for i=0 to 5 'step down the lines
for j=0 to 7
if (character>>(8*(5-i)+7-j)) and 1 then
if (sz=1) then
dp=pix(ON,x-i,y+j-7,rot,wi,ht,sc())
else
dp=ffr(ON,x-sz+1-(i*sz),y-sz+1+((j-7)*sz),sz,sz,rot,wi,ht,sc ())
endif
else
if (sz=1) then
dp=pix(OFF,x-i,y+j-7,rot,wi,ht,sc())
else
dp=ffr(OFF,x-sz+1-(i*sz),y-sz+1+((j-7)*sz),sz,sz,rot,wi,ht,s c())
endif
endif
next j
next i
exit sub
'
drtright:
for i=0 to 7 'step across the rows
for j=0 to 5
if (character>>((5-j)*8+i)) and 1 then
if (sz=1) then
dp=pix(ON,x-i,y+j,rot,wi,ht,sc())
else
dp=ffr(ON,x-sz+1-i*sz,y+(j)*sz,sz,sz,rot,wi,ht,sc())
endif
else
if (sz=1) then
dp=pix(OFF,x-i,y+j,rot,wi,ht,sc())
else
dp=ffr(OFF,x-sz+1-i*sz,y+(j)*sz,sz,sz,rot,wi,ht,sc())
endif
endif
next j
next i
exit sub
drtleft:
for i=0 to 7 'step across the rows
for j=0 to 5
' if bits(5-j,i) then
if (character>>(8*j+7-i)) and 1 then
if (sz=1) then
dp=pix(ON,x-i+7,y+j-5,rot,wi,ht,sc())
else
dp=ffr(ON,x-i*sz+7*sz,y+j*sz-6*sz+1,sz,sz,rot,wi,ht,sc())
endif
else
if (sz=1) then
dp=pix(OFF,x-i+7,y+j-5,rot,wi,ht,sc())
else
dp=ffr(OFF,x-i*sz+7*sz,y+j*sz-6*sz+1,sz,sz,rot,wi,ht,sc())
endif
endif
next j
next i
end sub
'

sub fcirc(x0 as integer,y0 as integer,r as integer) 'x,y coordinates of centre,radius
local as integer dp
dp=ffr(ON,x0,y0-r,1,2*r+1,rot,wi,ht,sc())
fcircH(x0,y0,r,3,0);
end sub
'
sub drndRect(x as integer,y as integer,w as integer,h as integer,r as integer) 'x,y coordinates of top left,width,height,radius of corner
local as integer dp
dp=ffr(ON,x+r,y,w-2*r,1,rot,wi,ht,sc())
dp=ffr(ON,x+r,y+h-1,w-2*r,1,rot,wi,ht,sc())
dp=ffr(ON,x,y+r,1,h-2*r,rot,wi,ht,sc())
dp=ffr(ON,x+w-1,y+r,1,h-2*r,rot,wi,ht,sc())
dcircH(x+r,y+r,r,1)
dcircH(x+w-r-1,y+r,r,2)
dcircH(x+w-r-1,y+h-r-1,r,4)
dcircH(x+r,y+h-r-1,r,8)
end sub
'
sub dcircH( x0 as integer,y0 as integer,r as integer,cn as integer)
local as integer f=1-r,ddF_x=1,ddF_y=-2 * r,x=0,y=r,dp
do while (x<y)
if (f>=0) then
y=y-1
ddF_y=ddF_y+2
f=f+ddF_y
endif
x=x+1
ddF_x=ddF_x+2
f=f+ddF_x
if (cn and 4) then
dp=pix(ON,x0+x,y0+y,rot,wi,ht,sc())
dp=pix(ON,x0+y,y0+x,rot,wi,ht,sc())
endif
if (cn and 2) then
dp=pix(ON,x0+x,y0-y,rot,wi,ht,sc())
dp=pix(ON,x0+y,y0-x,rot,wi,ht,sc())
endif
if (cn and 8) then
dp=pix(ON,x0-y,y0+x,rot,wi,ht,sc())
dp=pix(ON,x0-x,y0+y,rot,wi,ht,sc())
endif
if (cn and 1) then
dp=pix(ON,x0-y,y0-x,rot,wi,ht,sc())
dp=pix(ON,x0-x,y0-y,rot,wi,ht,sc())
endif
loop
end sub
'
sub fcircH(x0 as integer,y0 as integer,r as integer,cn as integer,delta as integer)
local as integer dp,f=1-r,ddF_x=1,ddF_y=-2 * r,x=0,y=r
do while x<y
if f>=0 then
y=y-1
ddF_y=ddF_y+2
f=f+ddF_y
endif
x=x+1
ddF_x=ddF_x+2
f=f+ddF_x

if (cn and 1) then
dp=ffr(ON,x0+x,y0-y,1,2*y+1+delta,rot,wi,ht,sc())
dp=ffr(ON,x0+y,y0-x,1,2*x+1+delta,rot,wi,ht,sc())
endif
if (cn and 2) then
dp=ffr(ON,x0-x,y0-y,1,2*y+1+delta,rot,wi,ht,sc())
dp=ffr(ON,x0-y,y0-x,1,2*x+1+delta,rot,wi,ht,sc())
endif
loop
end sub
'
sub frndRect(x as integer,y as integer,w as integer,h as integer,r as integer) 'x,y coordinates of top left,width,height,radius of corner
local as integer dp
dp=ffr(ON,x+r,y,w-2*r,h,rot,wi,ht,sc())
fcircH(x+w-r-1,y+r,r,1,h-2*r-1)
fcircH(x+r,y+r,r,2,h-2*r-1)
end sub
'
sub setrot(x as integer) 'sets screen rotation: 0=normal,1=invert,2=rotate right,3-rotate left
rot=(x and 3)
rot_wi=wi
rot_ht=ht
if x>=2 then
rot_wi=ht
rot_ht=wi
endif
end sub
'
' CFunctions
'
CFunction font
00000000
00000000 00000000 4f5b3e00 00003e5b 4f6b3e00 00003e6b 7c3e1c00 00001c3e
7e3c1800 0000183c 7d571c00 00001c57 7f5e1c00 00001c5e 3c180000 00000018
c3e7ff00 0000ffe7 24180000 00000018 dbe7ff00 0000ffe7 3a060e00 00003048
79292600 00002629 05050700 0000407f 05253f00 0000407f e73c5a00 00005a3c
1c1c0800 00007f3e 1c3e7f00 0000081c 7f221400 00001422 005f5f00 00005f5f
7f017f00 00000609 89956a00 00000066 60606000 00006060 ffa29400 000094a2
7e040800 00000804 7e201000 00001020 2a1c0800 00000808 2a080800 0000081c
10101000 00001e10 0c1e0c00 00000c1e 3e383000 00003038 3e0e0600 0000060e
00000000 00000000 5f000000 00000000 00070000 00000007 147f1400 0000147f
7f2a1200 0000242a 08646200 00002313 56205000 00003649 07030000 00000008
22410000 0000001c 221c0000 00000041 7f1c2a00 00002a1c 3e080800 00000808
70300000 00000080 08080800 00000808 60600000 00000000 08040200 00002010
49453e00 00003e51 7f400000 00000042 49494600 00007249 494d3300 00002141
127f1000 00001814 45453900 00002745 49493100 00003c4a 11090700 00004121
49493600 00003649 49291e00 00004649 14000000 00000000 34000000 00000040
14224100 00000008 14141400 00001414 22140800 00000041 59090600 00000201
5d594e00 00003e41 11127c00 00007c12 49493600 00007f49 41412200 00003e41
41413e00 00007f41 49494100 00007f49 09090100 00007f09 41517300 00003e41
08087f00 00007f08 7f410000 00000041 413f0100 00002040 14224100 00007f08
40404000 00007f40 1c027f00 00007f02 08107f00 00007f04 41413e00 00003e41
09090600 00007f09 51215e00 00003e41 19294600 00007f09 49493200 00002649
7f010300 00000301 40403f00 00003f40 40201f00 00001f20 38403f00 00003f40
08146300 00006314 78040300 00000304 494d4300 00006159 41414100 0000007f
08102000 00000204 41417f00 00000041 01020400 00000402 40404000 00004040
07080000 00000003 54784000 00002054 44443800 00007f28 44442800 00003844
44287f00 00003844 54541800 00003854 7e090200 00000008 a49c7800 000018a4
04047800 00007f08 7d400000 00000044 403d0000 00002040 28440000 00007f10
7f400000 00000041 78047800 00007c04 04047800 00007c08 44443800 00003844
24241800 0000fc18 2418fc00 00001824 04040800 00007c08 54542400 00004854
3f442400 00000404 40207c00 00003c40 40201c00 00001c20 30403c00 00003c40
10284400 00004428 90907c00 00004c90 544c4400 00004464 36410000 00000008
77000000 00000000 36080000 00000041 02040200 00000201 23263c00 00003c26
a1611200 00001ea1 40207a00 00003a40 54555900 00003854 55794100 00002155
54784200 00002254 54784000 00002155 55794000 00002054 52721200 00000c1e
55555900 00003955 54545900 00003954 54545800 00003955 457c4100 00000000
457d4200 00000002 457c4000 00000001 11127d00 00007d12 2528f000 0000f028
55450000 00007c54 547c5400 00002054 097f4900 00007c0a 49493200 00003249
44443a00 00003a44 48483000 0000324a 41217a00 00003a41 40207800 00003a42
a0a07d00 0000009d 42423d00 00003d42 40403d00 00003d40 ff242400 00003c24
49436600 0000487e fc2f2b00 00002b2f 29f62000 0000ff09 7e090300 0000c088
54794100 00002054 447d4100 00000000 484a3200 00003048 40227a00 00003840
0a0a7200 0000007a 19317d00 00007d0d 292f2800 00002629 29292600 00002629
4d402000 00003048 08080800 00003808 08083800 00000808 c8acba00 00002f10
2834fa00 00002f10 7b000000 00000000 2a142200 00000814 2a140800 00002214
5500aa00 0000aa00 aa55aa00 0000aa55 00ff0000 00000000 10ff0000 00001010
14ff0000 00001414 ff00ff00 00001010 f010f000 00001010 14fc0000 00001414
f700ff00 00001414 ff00ff00 00000000 f404fc00 00001414 17101f00 00001414
1f101f00 00001010 141f0000 00001414 10f00000 00001010 001f1000 00000000
101f1000 00001010 10f01000 00001010 00ff1000 00000000 10101000 00001010
10ff1000 00001010 00ff1400 00000000 ff00ff00 00000000 1f101700 00000000
fc04f400 00000000 17101700 00001414 f404f400 00001414 ff00f700 00000000
14141400 00001414 f700f700 00001414 14171400 00001414 1f101f00 00001010
14f41400 00001414 f010f000 00001010 1f101f00 00000000 001f1400 00000000
00fc1400 00000000 f010f000 00000000 ff10ff00 00001010 14ff1400 00001414
101f0000 00001010 00f01000 00000000 ffffff00 0000ffff f0f0f000 0000f0f0
ff000000 0000ffff 00ffff00 00000000 0f0f0f00 00000f0f 44384400 00003844
4a4a3400 0000fc4a 02060600 00007e02 027e0200 0000027e 49416300 00006355
443c0400 00003844 201e2000 0000407e 7e020200 00000602 e7a59900 000099a5
492a1c00 00001c2a 01724c00 00004c72 4d4d3000 0000304a 78483000 00003048
5a463d00 0000bc62 49490000 00003e49 01017e00 00007e01 2a2a2a00 00002a2a
5f444400 00004444 4a444000 00004051 4a514000 00004044 ff010300 00000000
ff000000 0000e080 6b6b0800 00000808 36243600 00003612 090f0600 0000060f
18180000 00000000 10100000 00000000 ff010100 00003040 01011e00 0000001f
1d171200 00000019 3c3c3c00 0000003c 00000000 00000000
End CFunction

'
CFunction pix
00000000
8faa0010 8fab0014 8ce70000 240d0001 10ed000e 8fac0018 50e00008 8ca80000
240d0002 10ed0014 240d0003 54ed0021 8d460000 10000018 8ca20000 00001821
8cc20000 1000001a 00004821 8ca80000 00084027 8d420000 01024021 00001821
8cc20000 00021027 8d650000 00451021 1000000f 00004821 8ca20000 00004821
8cc80000 00084027 8d430000 01034021 10000007 00001821 00021027 8d630000
00431021 00004821 8cc80000 00001821 8d460000 14600004 24050001 0106302b
14c00003 30a500ff 00002821 30a500ff 10a00039 00082d82 8d660000 15200004
24050001 0046302b 14c00003 30a500ff 00002821 30a500ff 50a0002f 00082d82
8c840000 10800016 2404ffff 00002021 15200008 00002821 15200004 24060001
2c460020 10c00004 24060001 10000003 00462004 24060001 00462804 000830c0
01866021 8d860000 00c43025 ad860000 8d860004 00c52025 10000016 ad840004
15200009 2405ffff 15200004 24060001 2c460020 10c00005 24060001 00463004
10000004 00062027 24060001 00463004 00062827 000830c0 01866021 8d860000
00c43024 ad860000 8d860004 00c52024 ad840004 00082d82 00032280 00a42025
00084280 01021021 0048402b 00894821 03e00008 01091821
End CFunction
'
CFunction Sgetnextupdate
00000000
27bdffd8 afbe0024 03a0f021 afc40028 afc5002c afc60030 afc70034 24040001
afc40008 8fc40028 24840001 24050040 a0850000 8fc40038 8c840000 afc40004
1000008f 00000000 8fc40034 8c840000 afc40000 10000081 00000000 8fc40000
000420c0 8fc50044 00a42021 8c850004 8c840000 afc40010 afc50014 8fc40000
000420c0 8fc50048 00a42021 8c850004 8c840000 afc40018 afc5001c 8fc40004
03c42021 90850010 8fc40004 03c42021 90840018 10a40064 00000000 8fc50000
8fc4002c ac850000 8fc50004 8fc40030 ac850000 8fc50004 8fc40038 ac850000
8fc50000 8fc40034 ac850000 10000031 00000000 8fc40004 03c42021 90850010
8fc40004 03c42021 a0850018 8fc40000 000420c0 8fc50048 00a43021 8fc40018
8fc5001c acc40000 acc50004 8fc40008 24840001 afc40008 8fc40008 8fc50028
00a42021 8fc50004 03c52821 90a50018 a0850000 8fc40000 24840001 afc40000
8fc40000 000420c0 8fc50044 00a42021 8c850004 8c840000 afc40010 afc50014
8fc40000 000420c0 8fc50048 00a42021 8c850004 8c840000 afc40018 afc5001c
8fc40034 8c840000 24850001 8fc40034 ac850000 8fc40004 03c42021 90850010
8fc40004 03c42021 90840018 10a40007 00000000 8fc50000 8fc4003c 8c840000
00a4202b 1480ffc3 00000000 8fc40034 8c850000 8fc4003c 8c840000 14a40008
00000000 8fc40038 8c840000 24850001 8fc40038 ac850000 8fc40034 ac800000
8fc40008 308500ff 8fc40028 a0850000 8fc20008 8fc40008 000427c3 00801821
10000017 00000000 8fc40034 ac800000 8fc40000 24840001 afc40000 8fc50000
8fc4003c 8c840000 00a4202b 1480ff7b 00000000 8fc40004 24840001 afc40004
8fc50004 8fc40040 8c840000 00a4202b 1480ff6d 00000000 00001021 00001821
03c0e821 8fbe0024 27bd0028 03e00008 00000000
End CFunction


CFunction ffr
00000000
27bdffc8 afb50034 afb40030 afb3002c afb20028 afb10024 afb00020 8fb10048
8fa80050 8fb00054 8fb90058 2402ffff a3a20008 2403fffe a3a30009 2403fffc
a3a3000a 2403fff8 a3a3000b 2403fff0 a3a3000c 2403ffe0 a3a3000d 2403ffc0
a3a3000e 2403ff80 a3a3000f 24030001 a3a30010 24030003 a3a30011 24030007
a3a30012 2403000f a3a30013 2403001f a3a30014 2403003f a3a30015 2403007f
a3a30016 a3a20017 8fa2004c 8c420000 24030001 50430023 8ca30000 50400008
8ca20000 24030002 10430037 24030003 5443006b 25a20007 10000050 8cc20000
00406021 8d030000 0043282b 00004021 10a000f4 00004821 2442ffff 8ce50000
00451021 0043c02b 2463ffff 0078100a 0040c021 8ccf0000 8e020000 01e2182b
106000e8 01e06821 25efffff 8e230000 01e37821 01e2182b 2442ffff 1000004f
0043c00a 00031827 8d020000 00621021 0040c021 00004021 044000da 00004821
8ce30000 00431023 24420001 284c0000 000c100b 00406021 8cc30000 00031827
8e020000 00621021 044000ce 00407821 8e2d0000 004d1023 244d0001 29a20000
10000036 0002680b 8d020000 8cc30000 00031827 00621821 0062c02b 2442ffff
0058180a 0060c021 8e220000 00621023 24420001 284c0000 000c100b 00406021
8ca20000 00406821 8e030000 0043282b 00004021 10a000b3 00004821 2442ffff
8ce50000 00451021 0043782b 2463ffff 006f100a 10000019 00407821 00406021
8d030000 0043302b 00004021 10c000a5 00004821 2442ffff 8e260000 00461021
0043c02b 2463ffff 0078100a 0040c021 8ca30000 00031827 8e020000 00621021
04400098 00407821 8ced0000 004d1023 244d0001 29a20000 0002680b 25a20007
29a90000 01a9100a 000248c3 25e20007 29f00000 01f0100a 000280c3 000990c0
01b29023 001040c0 15300028 01e84023 01803021 030c102b 14400024 03009821
000c28c0 03252821 03a8a821 03b2a021 03a93821 8ca20000 8ca30004 afa20000
afa30004 8c820000 10400008 00a08821 92820008 92ae0010 01c27024 90e20000
01c21025 10000009 a0e20000 92ae0010 92820008 01c27024 000e7027 31ce00ff
90e20000 01c21024 a0e20000 8fa20000 8fa30004 ae220000 ae230004 24c60001
0266102b 1040ffe3 24a50008 25330001 0213102b 14400030 0270102b 01803021
030c102b 1440002b 03008821 000c28c0 03252821 03b29021 03a94821 03a8a021
03b03821 8ca20000 8ca30004 afa20000 afa30004 8c820000 1040000a 00a04021
924b0008 91220000 01621025 a1220000 928a0010 90e20000 01421025 1000000d
a0e20000 924b0008 000b5827 316b00ff 91220000 01621024 a1220000 928a0010
000a5027 314a00ff 90e20000 01421024 a0e20000 8fa20000 8fa30004 ad020000
ad030004 24c60001 0226102b 1040ffdd 24a50008 0270102b 10400020 00001021
03b34021 03b08021 03004821 030c882b 000c90c0 03329021 2419ffff 16200014
01803021 02402821 8ca20000 8ca30004 afa20000 afa30004 8c820000 10400003
00a03821 10000002 a1190000 a1000000 8fa20000 8fa30004 ace20000 ace30004
24c60001 0126102b 1040ffef 24a50008 25080001 1510ffe9 00001021 7d823804
7f027a04 7da2bc04 7de2fe04 00001821 7d633804 7d437a04 7dc3bc04 00404021
00604821 01001021 01201821 8fb50034 8fb40030 8fb3002c 8fb20028 8fb10024
8fb00020 03e00008 27bd0038
End CFunction

Edited by matherp 2014-11-28
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:49am 27 Nov 2014
Copy link to clipboard 
Print this post

@matherp

Just got home to see this Thanks for more code

Can't wait to try this one to see if any speed increase for what I am trying to achieve.

Is there any chance you can provide the "C" code & explanation like you did for the NEC code? I really need to 'delve' into the way I drive the OLED and want to look at adding scrolling using the inbuilt SD1306 commands.

Massive thanks once again . . . .

WW


For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 02:26pm 27 Nov 2014
Copy link to clipboard 
Print this post

Sorry, but I don't like the way pstring now performs. It is very slow (and random speed) to display a string. I am not using the cursor - am I missing something or is this how it now 'updates' the screen?

Sorry to sound negative - hopefully I have made a mistake in using it

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8584
Posted: 10:24pm 27 Nov 2014
Copy link to clipboard 
Print this post

WW

Basically I need to recode the dchar routine into a cFunction, but in the meantime try replacing the s_update routine with the attached. This suppresses screen update while the pstring is taking place.


S_update:
cursorupdate=cursorupdate+1
if cursorenable and allowupdate and (cursorupdate mod 2) then
if cursoronoff then
crect(cursorx,cursory,cursorsizex,cursorsizey)
cursoronoff=off
else
cursoronoff=on
frect(cursorx,cursory,cursorsizex,cursorsizey)
endif
endif
if allowupdate then S_refresh
ireturn
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:56pm 27 Nov 2014
Copy link to clipboard 
Print this post

Thanks - I just tried it and although it's better, it now 'misses' some data I expect to display. Let me explain:

I have a countdown counter on the OLED screen and this refreshes nicely with the pre-flashing cursor code. Then when it reaches zero I want a top line of text to flash and two bottom lines of text to remain on screen (with a bi-colour screen, the flashing text is in yellow, and the static message is in blue - this setup draws attention to the user). With the 'new' S_update code, my countdown timer misses numbers so may count down like:10,9,8,6,3,2,0 (as opposed to 10,9,8,7,6,5,4,3,2,1,0),

Your original code worked fine, but the flashing text (top line) was showing signs of being 'drawn' rather than flashing. I was using pstring to display the text, then a delay, then pstring to write an empty line of text (all spaces) followed by a delay. The 'slowness' of the s_refresh caused the 'drawing' effect (rather than a rapid on/off).

I will try your 'blank rectangle' method and hope this is quicker & 'neater' to the eye.

My current fall-back plan is to flash the whole screen on and off (with DISPLAYON/OFF command.

Thanks for your continued support - much appreciated

WW Edited by WhiteWizzard 2014-11-29
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8584
Posted: 04:18am 28 Nov 2014
Copy link to clipboard 
Print this post

All

Please find below a new new version with all main text writing now converted to a cFunction, just use pstring(x , y, mystring$, size , orientation) to output text.
Size is 1 for a standard 7x5, 2 for 14x10, etc. Orientation is 1:normal, 2:inverted, 3:rotate right, 4:rotate left. In all cases the x,y coordinates are the top left of the first character viewed from its own perspective.
This character drawing code now runs 20x faster than before. The code protects against exceeding the screen display in any dimension.

I've attached the basic and C as a zip because the board seems to keep corrupting things, adding spaces in basic and losing square brackets in C

2014-11-28_152850_cfunctionSPI.zip Edited by matherp 2014-11-29
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024