Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:09 17 Nov 2025 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 : Armmite F4: BLIT WRITE seem to interfere with string array

Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3477
Posted: 07:15pm 08 Feb 2021
Copy link to clipboard 
Print this post

Using the bmp file in the attached zip, this code shows the problem I'm seeing:

Dim integer i,j,k,x=10,y=0,lblue=RGB(172,209,255)
box 0,0,320,240,,rgb(white),lblue
dim string labels(10)
for i=0 to 10: labels(i)="Label "+str$(i):next i

font 7: cls lblue
x=0:y=0:for i=0 to 10:
 text x,y,labels$(i),,7,,rgb(black),lblue:
 print str$(i)+": "+labels$(i): y=y+12:
next i
do while inkey$="": loop
geticons
do while inkey$="": loop
cls lblue:x=0:y=00:for i=1 to 6:blit write i,x,y,50,50:x=x+52:next i
do while inkey$="": loop
cls lblue
x=0:y=0:for i=0 to 10:
 text x,y,labels$(i),,7,,rgb(black),lblue:
 print str$(i)+": "+labels$(i): y=y+12:
next i
do while inkey$="": loop

x=100: y=0: for i=0 to 10: text x,y,labels$(i),,7,,rgb(black),lblue: y=y+12: next i
blit write 1,80,180,50,50
x=200: y=0: for i=0 to 10: text x,y,labels$(i),,7,,rgb(black),lblue: y=y+12: next i
end

sub geticons
'local integer i,j,k,x,y
Load image "icons.bmp"
for i=1 to 9: on error skip: blit close i: next i
k=1:x=0
for i=1 to 3
 y=0
 for j=1 to 3
   blit read k,x,y,50,50: y=y+50:k=k+1
 next j
 x=x+50: y=0
next i
end sub

First I PRINT and TEXT 11 string array elements to the LCD and await a keystroke; then I load the bmp file, extract 9 BLIT buffers and await a keystroke; then I BLIT WRITE 6 of the BLIT buffers and await a keystroke; then I again TEXT and PRINT the same 11 string array elements to the LCE and await a keystroke, but they are garbled.

Is there anything evident that I am doing wrong? ARMmite MMBasic Version 5.05.10.

icons.zip
Edited 2021-02-09 05:17 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3477
Posted: 07:35pm 08 Feb 2021
Copy link to clipboard 
Print this post

Further info: after rebooting, the program works the first time, but not subsequently.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1047
Posted: 04:47am 09 Feb 2021
Copy link to clipboard 
Print this post

It looks like the line

for i=1 to 9: on error skip: blit close i: next i

causes a few problems. The next read of blit seems to overwrites the variables in the program.
See code below where I have put the closing of the BLIT buffers at the end of the main program and removed ON ERROR SKIP. Once the CPU is restarted runs OK from then on.

I think relying on ON ERROR SKIP to manage the opening/closing of the BLIT buffers
is probably not a good practise.

Gerry




Dim integer i,j,k,x=10,y=0,lblue=RGB(172,209,255)
box 0,0,320,240,,rgb(white),lblue
dim string labels(10)
for i=0 to 10: labels(i)="Label "+str$(i):next i

font 7: cls lblue
x=0:y=0:for i=0 to 10:
text x,y,labels$(i),,7,,rgb(black),lblue:
print str$(i)+": "+labels$(i): y=y+12:
next i
do while inkey$="": loop
geticons
do while inkey$="": loop
cls lblue:x=0:y=00:for i=1 to 6:blit write i,x,y,50,50:x=x+52:next i
do while inkey$="": loop
cls lblue
x=0:y=0:for i=0 to 10:
text x,y,labels$(i),,7,,rgb(black),lblue:
print str$(i)+": "+labels$(i): y=y+12:
next i
do while inkey$="": loop

x=100: y=0: for i=0 to 10: text x,y,labels$(i),,7,,rgb(black),lblue: y=y+12: next i
blit write 1,80,180,50,50
x=200: y=0: for i=0 to 10: text x,y,labels$(i),,7,,rgb(black),lblue: y=y+12: next i
' Close the buffers here
for i=1 to 9 : blit close i: next i

end

sub geticons
'local integer i,j,k,x,y
Load image "icons.bmp"
' Dont use on error to hide the errors
'for i=1 to 9: on error skip: blit close i: next i
k=1:x=0
for i=1 to 3
y=0
for j=1 to 3
  blit read k,x,y,50,50: y=y+50:k=k+1
next j
x=x+50: y=0
next i



F4 H7FotSF4xGT
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 09:15am 09 Feb 2021
Copy link to clipboard 
Print this post

  Quote  It looks like the line

for i=1 to 9: on error skip: blit close i: next i

causes a few problems. The next read of blit seems to overwrites the variables in the program.
See code below where I have put the closing of the BLIT buffers at the end of the main program and removed ON ERROR SKIP. Once the CPU is restarted runs OK from then on.


Perfect diagnosis which has allowed me to find the problem instantly. I'll post an ArmmiteF4 firmware update later today
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3477
Posted: 01:40pm 09 Feb 2021
Copy link to clipboard 
Print this post

Excellent. Thank you.

I put the BLIT CLOSE i at the beginning because if the program fails, and the BLIT buffers have not been closed, BLIT READ will fail at the next run of the program because unlike on the CMM2, the BLIT buffers appear to persist in some way between program runs.

(If that is fixed, it would be great--they'd never have to be closed in my usage thus far.)
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3477
Posted: 01:10pm 10 Feb 2021
Copy link to clipboard 
Print this post

With the new F4 MMBasic, I no longer need to do BLIT CLOSE for each BLIT buffer before a program is rerun. That's good.

But there's a new oddity: after running the program and quitting with Ctrl-C, I get  "Error : Not enough memory" when I run FILES. MEMORY reports "26K (24%) Free".

Dim integer lblue=RGB(172,209,255),grey=rgb(192,192,192),i,j,k,l,m,n
Dim integer EspFlag=0,iconFlag=1,txtFont=1
Dim integer ls%(2000),nNames=9,degrees, x_endpoint, y_endpoint
'Dim cx% = 225, cy% = 100, wid% = 50
Dim cx% = mm.hres*.75-20, cy% = (mm.vres-40)/2+20, wid% = mm.hres/6
Dim ang! = 0.087266463, rad90! = 1.570796327  '90 degrees in radians
Dim string a$,b$,c$,d$,item$,Values(10) length 20
Dim string names$(10) length 15
names(0)="description":names(1)="temp":names(2)="pressure":names(3)="humidity"
names(4)="speed":names(5)="deg":names(6)="gust":names(7)="country":names(8)="name"
Dim string labels$(10) length 25
labels$(0)="Sky": labels$(1)="Temperature": labels$(2)="Atmospheric Pressure"
labels$(3)="Humidity": labels$(4)="Wind Speed": labels$(5)="From the"
labels$(6)="Gusting to": labels$(7)="City": labels$(8)=","
Dim string points$(16) length 3  =("N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","","")
points(15)="NNW": points(16)="N"

if iconFlag then: geticons: endif

box 0,0,mm.hres,40,,rgb(white),grey
box 0,40,mm.hres/2,mm.vres-40,2,rgb(white),lblue
box mm.hres/2+1,40,mm.hres/2,mm.vres-40,2,rgb(white),lblue
text mm.hres/2,5,"Weather: Milton, Nova Scotia",C,1,,rgb(white),grey
text mm.hres/2,20,date$+" "+time$,C,1,,rgb(white),grey
compass_rose cx%,cy%,wid%

if mm.hres=320 then: txtFont=7: endif
getWeather
x=10:y=45:
for i=0 to 6
 if i=2 then
   text x,y,labels$(i)+": ",,txtFont,,rgb(black),lblue:y=y+15:
   text x,y,"  "+Values$(i),,txtFont,,rgb(black),lblue:y=y+15:
 else
   text x,y,labels$(i)+": "+Values$(i),,txtFont,,rgb(black),lblue):y=y+15:
 endif
next i
circle cx%+15,cy%+15,wid%-6,,,lblue,lblue
circle cx%+15,cy%+15,wid%/8,,,rgb(red),rgb(red) ' center
n=(degrees+270) mod 360
for i=12 to 18 ' lines offset from center (cx%+15) to make arrow
 x_endpoint=(cx%+15)+(Cos(n*ang!)*(wid%-8))
 y_endpoint=(cy%+15)-(Sin(n*ang!)*(wid%-8))
 Line (cx%+i),(cy%+i),x_endpoint,y_endpoint,,RGB(RED)
'  Line (cx%+i),(cy%+i),(cx%+15)+(Cos(n*ang!)*(wid%-8)),(cy%+15)-(Sin(n*ang!)*(wid%-8)),,RGB(RED)
next i
text x,200,"Condition:",,txtFont,,rgb(black),lblue
if iconFlag then
 blit write 2,mm.hres/4,180,50,50
else
 text x+10,212,Values$(0),,txtFont,,rgb(black),lblue
endif
do:loop

sub compass_rose cx%,cy%,wid%
Local a%
Text cx%+9,cy%+15-(wid%+17),"N",L,1,,RGB(1,1,1),lblue
Text cx%+9,cy%+15+(wid%+5),"S",L,1,,RGB(1,1,1),lblue
Text cx%+wid%+20,cy%+4,"E",L,1,,RGB(1,1,1),lblue
Text cx%-(wid%)+5,cy%+4,"W",L,1,,RGB(1,1,1),lblue
if a%<>a% then
Text 10,10,"NE",L,7,,RGB(1,1,1),RGB(134,174,230)
Image rotate 6,4,30,30,cx%+(wid%-16)*Cos(.785),cy%-(wid%-16)*Cos(.785),45,1
Text 10,10,"SE",L,7,,RGB(1,1,1),RGB(134,174,230)
Image rotate 6,4,30,30,cx%+(wid%-16)*Cos(.785),cy%+(wid%-16)*Cos(.785),135,1
Text 10,10,"SW",L,7,,RGB(1,1,1),RGB(134,174,230)
Image rotate 6,4,30,30,cx%-(wid%-16)*Cos(.785),cy%+(wid%-16)*Cos(.785),225,1
Text 10,10,"NW",L,7,,RGB(1,1,1),RGB(134,174,230)
Image rotate 6,4,29,29,cx%-(wid%-16)*Cos(.785),cy%-(wid%-16)*Cos(.785),315,1
Text 10,10,"  ",L,7,,RGB(134,174,230),RGB(134,174,230) ' clear text
' tick marks, every 5 degrees (360/5 = 72)
endif
For a% = 0 To 71 ' note: for angles, East is zero
 Line (cx%+15)+(Cos(a%*ang!)*(wid%-4)),(cy%+15)-(Sin(a%*ang!)*(wid%-4)),(cx%+15)+(Cos(a%*ang!)*(wid%+1)),(cy%+15)-(Sin(a%*ang!)*(wid%+1)),,RGB(WHITE)
Next
' COMPASS perimiter
Circle cx%+15,cy%+15,wid%
Circle cx%+15,cy%+15,wid%-4
circle cx%+15,cy%+15,wid%/8,,,rgb(red),rgb(red) ' center
End Sub

Sub getWeather
if EspFlag then:
else
Open "livr.jsn" For input As #1
Do While Not Eof(1)
 Line Input #1, a$: ' Print a$
 LongString append ls%(),a$
Loop
Close #1
' LongString print ls%(): Print

For n=0 To nNames-1
 item$=names$(n)
 Values$(n)=pseudo_json$(ls%(),item$)
'  Print item$,Values$(n)
 If item$="temp" Then: Values$(n)=Str$(Val(Values$(n))-273.15)+"C": EndIf
 If item$="deg" Then
   degrees=Val(Values$(n))
   i=(degrees+11.25)/22.5
   Values$(n)=points$(i)
'    print item$,degrees,i,Values$(n)
 EndIf
 If item$="humidity" Then: Values$(n)=Values$(n)+"%": EndIf
 If item$="speed" Then: Values$(n)=Values$(n)+"kph": EndIf
 If item$="pressure" Then: Values$(n)=Values$(n)+" millibars": EndIf
 If item$="gust" Then: Values$(n)=Values$(n)+"kph": EndIf
Next n
endif
End Sub

Function pseudo_json$(ls%(),key$)
 local integer i,j,k,l,m
 local string a,b
 m=1
 pseudo_json$=""
 Do
   i=LInStr(ls%(),key$,m)
'    Print key$,i
   If i Then
     a=LGetStr$(ls%(),i-1,1)
     b=LGetStr$(ls%(),i+Len(key$),1)
'      Print "|";a;"|","|";b;"|";
     If a=Chr$(34) And b=Chr$(34) Then ' found the key
       j=LInStr(ls%(),",",i+Len(key$)+2)
       If j>0 Then
         k=i+Len(key$)+2
         a=LGetStr$(ls%(),k,j-k)
'          Print a
         If Mid$(a,1,1)=Chr$(34) Then ' remove "s
           a=Mid$(a,2,Len(a)-2)
         EndIf
         If Instr(a,"}") Then: a=Mid$(a,1,Len(a)-1): EndIf
         pseudo_json$=a
         Exit Do
       EndIf
     EndIf
     m=i+Len(key$)
   Else
     Exit Do ' key not found
   EndIf
 Loop
End Function

sub geticons
local integer i,j,k,x,y
Load image "icons.bmp"
for i=1 to 9: on error skip: blit close i: next i
k=1:x=0
for i=1 to 3
 y=0
 for j=1 to 3
   blit read k,x,y,50,50: y=y+50:k=k+1
 next j
 x=x+50: y=0
next i
end sub

This uses the same "icons.bmp" as before.

> run
> files
Error : Not enough memory
> memory
Flash:
  5K ( 3%) Program (157 lines)
139K (97%) Free

RAM:
 20K (17%) 32 Variables
 68K (59%) General
 26K (24%) Free
>

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 01:13pm 10 Feb 2021
Copy link to clipboard 
Print this post

The BLIT buffers are left in place after Ctrl-C and they use memory so you need to close them before using FILES - this uses memory to sort the filenames
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025