Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:41 24 Nov 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 : LOAD command question

     Page 1 of 2    
Author Message
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 06:54pm 22 Aug 2024
Copy link to clipboard 
Print this post

I wrote small file browser.

Saved it to flash 1

Added OPTION function key F5 so when I press F5, may small file browser satrts and I can walk through files (similar like we have in CMM2) and select file I need to load for editing or run

Then i would like to load this file like normal command LOAD would do from command prompt, but I want it to run from program itself

Good to be, but sure i receive Error: Invalid in a program :D

I must be trying to do something anti-systemic :) ?
Or I just do it wrong way ?
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3800
Posted: 07:08pm 22 Aug 2024
Copy link to clipboard 
Print this post

Please post the short part of the code which makes the error.

(You may need to use EXECUTE if you're not.)

John
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 07:16pm 22 Aug 2024
Copy link to clipboard 
Print this post

I believe this is a limitation of MMBasic, and you can't work around it by using EXECUTE. Something to do with how tokenisation works ... I don't think it needs to be this way, but likewise I don't expect Peter or Geoff to "fix" it.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 08:27pm 22 Aug 2024
Copy link to clipboard 
Print this post

I tried EXECUTE, while it is said in manual "Use should be limited to basic commands that execute sequentially ... " so no, it did not worked.

I tried also make trick using eval(), while I feel I try to go against system :D
I feel it must be against logic somehow, I might not be able load program on top what is running already.

Why I was in hope for some sucess, was, while browser program is loaded from flash, main editing window is empty. No program loaded so I had a hope, while it is not in execution for a while it might be alowed to load. That would be interesting and I believe usefull.

I understand, we have no file browser like in CMM2 becouse of lack of resources
still it seems to me like fun idea to have custom one :D
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 08:35pm 22 Aug 2024
Copy link to clipboard 
Print this post

  thwill said  I don't expect Peter or Geoff to "fix" it.


Peter makes me wonder. You might never know... :)  

I was sure he will play with new PICO2 but did not expected this happen so fast.
And I did not ordered new chip thinking it will wait.
How wrong I was :D
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 09:03pm 22 Aug 2024
Copy link to clipboard 
Print this post

  JohnS said  Please post the short part of the code which makes the error.
John


It just takes file name from array and try to load that

file_to_load$=all_files(f_active) ' result is string containing full name, I can print it as debug info
Load file_to_load$


if I would change to

load "test.bas"

it would throw same error: Invalid in a program
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6780
Posted: 09:41pm 22 Aug 2024
Copy link to clipboard 
Print this post

Isn't it "LOAD file$, R" to load and run a program automatically?

Just LOAD file$ does just that - it won't run.

It was more fun using "FLASH CHAIN n" when we had a lot of flash slots. :)
.
Edited 2024-08-23 07:43 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 09:52pm 22 Aug 2024
Copy link to clipboard 
Print this post

To the best of my knowledge Load can only replace what is in program memory, not add to it.

Flash Chain runs the next program but retains all the variables of the first.
If the first program has a copy in another flash slot you can then Flash Chain back to that. However the program will restart back at the beginning, not at the point where you left it.

It might be possible to get around that by setting a flag (in the first program) just before the Flash Chain command. When you Flash Chain back to the first program that flag can be used to GOTO a Label: at the desired re-entry point.

Edit
You may be able to chain back to program memory with Flash Chain 0.
The "Flag and Label:" trick would still be needed.

eg. near the start of the program:-

On Error Skip 3
If Flag = 1 then Goto Label1
If Flag = 2 then Goto Label2
Dim Integer Flag
'etc...
...
Label1:
'...
Label2:
'...

Also although LOAD "Program2.BAS" may not work within a program but RUN "Program2.BAS" does.
I have used it in this thread. Scroll up to the footnote in the post on 04-03-2024 and the program "IR Remote Control key recorder and translator"
Sub Finished ends with RUN Fname$

The program modifies itself by first saving itself to A: then creating and appending 2 Subs to the end then RUNing the altered program from A:, replacing the original.

For some the use of Goto and On Error Skip offends their aesthetic but from a pragmatic point of view any thing that works is a thing of beauty.
.
Edited 2024-08-23 10:25 by phil99
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 04:41am 23 Aug 2024
Copy link to clipboard 
Print this post

  phil99 said  
RUN Fname$

Yes! It solves problem!

It runs file after laods it instead of just loading and stopping.
But on other side it is even closer to what I wanted to see :)
Thank you all for good time!
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6780
Posted: 06:41am 23 Aug 2024
Copy link to clipboard 
Print this post

FLASH CHAIN can be clever. Each CHAINed program has to run from the first instruction, but you can pass a variable by using VAR SAVE. If a CHAINed program reads that first it can be used to choose one of several sub-programs from that flash slot. So you can have a lot of small programs in the space of one slot. The only problem is that you are subjecting the flash to a bit of wear, but hey ho, that's what backups are for, isn't it? You probably won't notice for the first ten years of continuous running anyway. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 08:59am 23 Aug 2024
Copy link to clipboard 
Print this post

  Mixtel90 said  FLASH CHAIN can be clever


Yes, agree. But my idea was something close to Maximite`s F1.
Something close, as I just wanted to load program without starting it to execute but for editing.

For larger projects I mostly use Notepad++ and do not see any discomfort, but for smaller editing I just like console editing so much!

And sometimes jumping through multiple files it starts to be bored many times type in LOAD " {and some long name}

So I wrote small browser similar to that we see in Maximite after we press F1
Saved it to flash slot and call by dedicated to that task OPTION function key F5 :)
It alows me be even more lazy   or seriously - it`s just faster  


FLASH CHAIN sure is nice thing but not this case.

What rised me new question while reading your answer
  Mixtel90 said    it can be used to choose one of several sub-programs from that flash slot. So you can have a lot of small programs in the space of one slot.  
How lot of small programs can be saved in one flash slot ? I know we can save LIBRARRY, but multiple small programs in one slot? In picomiteVGA manual ver2 MMBasic Ver 5.07.07 I cant find such option. I was sure only one program could be saved into one of three slots if librarry not occupied said, by slot 3 ?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 09:00am 23 Aug 2024
Copy link to clipboard 
Print this post

Have you tried

EDIT fname$

at the command line? Edits from and back to disk
Edited 2024-08-23 19:00 by matherp
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 09:06am 23 Aug 2024
Copy link to clipboard 
Print this post

  matherp said  Have you tried EDIT fname$


Yes, Peter
This is what I got

  Quote  
[104]  Edit file_to_load$
Error: Invalid in a program


? MM.Info(version) = 5.08
Edited 2024-08-23 19:09 by electricat
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 09:18am 23 Aug 2024
Copy link to clipboard 
Print this post

You need to use it at the command line
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 09:20am 23 Aug 2024
Copy link to clipboard 
Print this post

Peter and all might be interested, this is code itself (currently without dir listing as in beginning it was wrote for another project just idea came later to use for fast browsing, loading/editing)

this part


 If keydown$=Chr$(13) Then
 svars(all_files(f_active))
 file_to_load$=all_files(f_active)
 Run file_to_load$ ' <<<<<<<<<<<




'fm ver 0.2
Drive "b:"
Font 4
CLS
debug=0

Dim ff=0
Dim arr_s=0
Dim f_page_size=15

max_fnl=0 'fnl read as File Name Lenght

ft$ = Dir$("*", FILE)
Do While ft$ <> ""
ft$= Dir$()
this_fnl=Len(ft$)
 If this_fnl > max_fnl Then max_fnl=this_fnl 'we are looking for longest file name
Inc arr_s
Loop

empty_records=f_page_size-(arr_s-(Fix(arr_s/f_page_size)*f_page_size))
Dim all_files(arr_s+empty_records) As string

tmp_arr_s=0
file$ = Dir$("*",FILE)
If file$ <> "" Then all_files(tmp_arr_s) = file$
Inc tmp_arr_s

Do While file$ <> ""
 file$= Dir$()
 If file$ <> "" Then all_files(tmp_arr_s) = file$
 Inc tmp_arr_s
Loop

For a= 0 To empty_records
all_files(arr_s+a) = "..."
Next a

f_active=0 : draw_files()
ch_y=0 : f_active=0 : f_list=0

Do

   draw_active_file()

Do While keydown$=""
keydown$=Inkey$
Loop

draw_active_file()

 If keydown$=Chr$(129) Then 'print "down"
  f_list=f_list+1

  If f_list > f_page_size-1 And (f_active =arr_s+empty_records-1) Then
  ch_y=17*(f_page_size-1)  : f_list=f_page_size-1
  f_active=arr_s+empty_records-1
GoTo fin
  EndIf

  If f_list > f_page_size-1 Then
  f_list=0 : f_active=f_active+1
  draw_files()
  f_active=f_active-f_page_size: ch_y=0
GoTo fin
EndIf
  draw_inactive_file()
  ch_y=ch_y+17
  f_active=f_active+1
  fin:
  draw_active_file()
  svars("down")

 EndIf

 If keydown$=Chr$(128) Then 'print "up"
  f_list=f_list-1
  If f_list < 0 And f_active =0 Then
  ch_y=0  : f_list=0: f_active=0
GoTo fin2
  EndIf

  If f_list < 0 Then
  f_list=f_page_size-1 :  f_active=f_active-f_page_size
draw_files()
ch_y=17*(f_page_size-1) : f_active=f_active-1
GoTo fin2
EndIf
       draw_inactive_file()
       ch_y=ch_y-17
       f_active=f_active-1
 draw_active_file()
fin2:

       draw_active_file()
       svars("up")
'        Pause 150
 EndIf

 If keydown$=Chr$(13) Then
 svars(all_files(f_active))
 file_to_load$=all_files(f_active)
 Run file_to_load$

 EndIf

keydown$=""
Loop

Sub draw_files
ch_x=0 : ch_y=0
Colour RGB(black),RGB(white)
 If f_active < 0 Then f_active = 0 : ch_y=0 : f_list=1 : GoTo donothing
 If f_active > arr_s+empty_records-f_page_size Then f_active = arr_s+empty_records : f_list=f_page_size-1 : ch_y=17*f_page_size : GoTo donothing

 For l=0 To f_page_size-1
'  console f_active
 Print @(ch_x,ch_y)"  " ; all_files(f_active) ; Space$(40-Len(all_files(f_active)))
 ch_y=ch_y+17
 f_active=f_active+1
 Next l
donothing:
 svars("draw_files")
End Sub

Sub draw_active_file
 Colour RGB(red),RGB(cyan)
 Print @(ch_x,ch_y) "> " ; all_files(f_active) ; Space$(40-Len(all_files(f_active)))
End Sub

Sub draw_inactive_file
 Colour RGB(black),RGB(white)
 Print @(ch_x,ch_y) "  " ; all_files(f_active) ; Space$(40-Len(all_files(f_active)))
End Sub

Sub svars(come$)
 If debug=1 Then
 Print @(450,0) "f_active>" ;"         "
 Print @(450,17) "f_list>" ;"         "
 Print @(450,34) "from>" ;"         "
 Print @(450,0) "f_active>"f_active;"    "
 Print @(450,17) "f_list>"f_list;"    "
 Print @(450,34) "from>"come$;"    "
 EndIf
End Sub


 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 09:22am 23 Aug 2024
Copy link to clipboard 
Print this post

  matherp said  You need to use it at the command line


I know, I know.

RUN file_to_load$  >>> almost makes  mekes what I want to do ;)
My language barrier (not the best english) might be problem in describing what I want to achieve.

Program sits in >>> flash 1
I call it with F5

loads me something = fast and easy run/editg program from list
Edited 2024-08-23 19:26 by electricat
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 09:30am 23 Aug 2024
Copy link to clipboard 
Print this post

EDIT cannot and will never be able to be run from a program. Edit uses all available RAM as a buffer and therefore would destroy the context of any other program making return impossible.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6780
Posted: 09:35am 23 Aug 2024
Copy link to clipboard 
Print this post

  electricat said  
  Mixtel90 said  FLASH CHAIN can be clever

What rised me new question while reading your answer
  Mixtel90 said    it can be used to choose one of several sub-programs from that flash slot. So you can have a lot of small programs in the space of one slot.  
How lot of small programs can be saved in one flash slot ? I know we can save LIBRARRY, but multiple small programs in one slot? In picomiteVGA manual ver2 MMBasic Ver 5.07.07 I cant find such option. I was sure only one program could be saved into one of three slots if librarry not occupied said, by slot 3 ?


Not actually separate programs, although it can look like it. More like the library.

You set a variable to the number of the program you want to run
Use FLASH CHAIN to load the new slot.
In the new program use VAR READ to get the variable.
Use SELECT CASE to run the program that you want
Use FLASH CHAIN to get back to the calling program.

You need something at the beginning of that one to jump to another point unless the program is being run for the first time. Something like using VAR READ and jump if the value is zero. The called slot can set it to non-zero.

It's a bit fiddly to do, but it's perfectly possible.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 10:11am 23 Aug 2024
Copy link to clipboard 
Print this post

  matherp said  Edit uses all available RAM as a buffer and therefore would destroy the context of any other program making return impossible.


Yes. I listen and undesrstand that.

But my aim isn`t return to current executed program ;) (I tried to explain what I wanted to do few posts up.)  

RUN file_to_load$   =-->  in fact makes happen what I wanted.  except I should take care save it after some editing.

It would be good if EDIT would do instead of RUN, or it would be perfect if we would have small file browser like in cmm2 "out of box".

I just love so much that feature in cmm2. So wanted somehow reimplement from user side perspective
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 10:26am 23 Aug 2024
Copy link to clipboard 
Print this post

  Mixtel90 said  
Use FLASH CHAIN to load the new slot.
In the new program use VAR READ to get the variable.
Use SELECT CASE to run the program that you want
Use FLASH CHAIN to get back to the calling program.


Ahhh, I got it. Yes. I clearly understand idea. For overcoming 100 kb limit it is doable, yes. But this was not what I needed this case  
 
     Page 1 of 2    
Print this page
© JAQ Software 2024