![]() |
Forum Index : Microcontroller and PC projects : Picomite and Picomite VGA flash slots
![]() ![]() |
|||||
Author | Message | ||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1115 |
Paul, A little bit of trickery here and not sure if it will throw up errors in other areas but the following is an example of how to get back to the main program from a chained flash program. Tested (limited) on the latest software. Doug. ' First, create the following using EDIT ' flash memory 1 Print "Flash memory 1 - hello world" Exit Sub ' trickery to return to calling program ' save it in flash slot 1 ' now create the following program in main memory using EDIT 'main memory Print "Main memory - hello world" Pause 1000 Print ' ... now chain to flash 1" godoflash Print "made it back from subroutine?????" End Sub godoflash Print " now chaining to flash 1 from main" Flash chain 1 Print " .. ?????" ' should never get here End Sub ' If you now type RUN and execute the main program, it will chain to the ' flash via the subroutine and in the chained file, the END SUB will bounce ' you back to the main program. Further to the above, it looks like you can not use subs in the flash program chained to in this way - the alternative is to use goto's (incredibly clunky, I know) as follows:- ' flash memory 1 Print "Flash memory 1 - hello world" ' some dummy subroutines GoTo dummy1 d1Ret: GoTo dummy2 d2Ret: Pause 1000 Print " now back to main from flash 1" Exit Sub dummy1: Print "dummy 1 psuedo sub" GoTo d1Ret Pause 1000 dummy2: Print "dummy 2 psuedo sub" GoTo d2Ret Edited 2022-12-14 12:43 by panky ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
Remember that using CHAIN the variables are preserved. I think you might be able to do the following (untested as I haven't got a {PicoMite set up). It depends on the (assumed) ability of GOTO to accept a string descriptor for a label: 'main program in flash slot 5 if gt$>"" then GOTO gt$ :label1 'something happens here gt$="label3" FLASH CHAIN 1 :label2 'something happens here gt$="label1" FLASH CHAIN 2 :label3 'something happens here gt$="label2" FLASH CHAIN 3 END '--------------------- 'in flash slot 3 ?"Hello from flash slot 3" FLASH CHAIN 5 END '-------------------- 'in flash slot 2 ?"Hello from flash slot 2" FLASH CHAIN 5 END '-------------------- 'in flash slot 1 ?"Hello from flash slot 1" FLASH CHAIN 5 END Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Hey Mick, What's with the colon before the label, yet another trick that I'm unaware of? Every time I look at the manual, I seem to discover something new ![]() Craig |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
You can chain to the main program with FLASH CHAIN 0 in latest releases |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
No, Craig, that's an ooopsie on my part! A label should terminate with a colon, not start with one. I said it was untested. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Bowden_P Senior Member ![]() Joined: 20/03/2019 Location: United KingdomPosts: 162 |
Hi matherp, That's excellent news - saves the above crafty workarounds !! At the moment I am getting "educated" in using the Picomite - I don't have any hardware yet - but come Christmas day I hope that will change ! Thanks to Panky and Mixtel90 for your code - worth a try when I can - even if just to expand my program knowledge of what is possible with MMBasic. With best regards, Paul. Nothing so constant as change. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
I stand corrected then! ![]() ![]() Good to know. Is that in the manual anywhere? Smoke makes things work. When the smoke gets out, it stops! |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
As an add-on to my code, we can implement the opposite of GOTO - the COMETO command. :) sub COMETO(destination_label$) gt$=destination_label$ end sub 'then we can use this construct: COMETO mylabel$ FLASH CHAIN n :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Reminds me of the COMEFROM statement etc :) John |
||||
TheMonkeys![]() Regular Member ![]() Joined: 15/12/2022 Location: AustraliaPosts: 59 |
G'day I'm using the following... setup: '~~~ledstrip' (Jaycar XC4385 led ring) setup ledpin = 14 SetPin ledpin, DOut striplen% = 24' led strip length ledoffset = 9' led ring rotational offset Dim ledbar%(striplen% + 1) For a = 0 To striplen% ' clear ledring ledbar%(a) = 0 Next '~~~kscan' setup/reset keypin = 31 ami% = 0 '~~~pre-calc'd ladder voltages Dim rvol!(12) rvol!(0) = 0: rvol!(1) = 0.12: rvol!(2) = 0.24: rvol!(3) = 0.3 rvol!(4) = 0.4: rvol!(5) = 0.5: rvol!(6) = 0.55: rvol!(7) = 0.64 rvol!(8) = 0.72: rvol!(9) = 0.76: rvol!(10) = 0.84: rvol!(11) = 0.91 '~~~init exec string array Dim xec$(4, 9) For ky = 0 To 8 '4 sets with two Ami keyshifts (including both) For sk = 0 To 3 'shifts xec$(sk, ky) = "" Next sk Next ky exec$=""'JIC '~~~set 3 RESERVED for CHAIN start xec$(3,0) = "FLASH RUN 1": xec$(3,1) = "FLASH CHAIN 2": xec$(3,2) = "FLASH CHAIN 3" xec$(3,3) = "FLASH CHAIN 4": xec$(3,4) = "FLASH CHAIN 5": xec$(3,5) = "FLASH CHAIN 6" 'rotational offset 7=left/8=reset/9=right xec$(3,6) = "ofst(-1)": xec$(3,7) = "ofst(0)": xec$(3,8) = "ofst(1)" '~~~set 3 RESERVED for CHAIN end kscan 'init keyboard ADC pin main: 'offset display ledbar%((ledoffset) Mod striplen%) = RGB(32,32,32)'top ledbar%((18 + ledoffset) Mod striplen%) = RGB(32,0,0)'left ledbar%((6 + ledoffset) Mod striplen%) = RGB(0,32,0)'right ledbar%((12 + ledoffset) Mod striplen%) = RGB(ami% And 2,ami% And 1,ami% And 4)'bottom status Bitbang ws2812 O, ledpin, striplen%, ledbar%(0) For i = 1 To striplen% ledbar%(i) = 0 Next If exec$ <> "" Then Execute exec$: exec$ = "" GoTo main Sub kscan SetPin keypin, ain 'read keypad voltage Bitbang ws2812 O, ledpin, 1, 240'feedback B Pause 20 For rladd = 0 To 11 If Abs(rvol!(rladd) - Pin(keypin)) < .03 Then If rladd = 9 Then ami% = Choice(ami% And 1,ami% And 2,ami% Or 1)'toggle' lAmi ElseIf rladd = 10 Then ami% = 0'clear shifts ElseIf rladd = 11 Then ami% = Choice(ami% And 2,ami% And 1,ami% Or 2)'toggle' rAmi Else exec$ = xec$(ami%, rladd) Exit For EndIf EndIf Next rladd Bitbang ws2812 O, ledpin, 1, 15728640'feedback R Do While Pin(keypin) < 1 Pause 20 Loop SetPin keypin, IntL, kscan 'ready for next keypress Bitbang ws2812 O, ledpin, 1, 61440'feedback G End Sub Sub ofst(ofs) If ofs = 0 Then ledoffset = 0 Else Inc ledoffset, ofs If ledoffset < 0 Then ledoffset = striplen% - 1 If ledoffset > striplen% Then ledoffset = 1 End Sub which sort of works. If I execute the call within 'kscan' it works, but the keypad stops working. In this example, it loads, runs, and promptly crashes (resets serial port). Thoughts? Edited 2022-12-17 18:11 by TheMonkeys |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
Not sure. Remember though that CHAIN is exactly like starting a new program, it's just that the variables aren't destroyed like the RUN does. Consequently any open ports will be closed and the system is, to all intents and purposes, completely reset. Your CHAINed program sees a new, clean system except that the variable are still available and runs from the first line. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
TheMonkeys![]() Regular Member ![]() Joined: 15/12/2022 Location: AustraliaPosts: 59 |
Understood. I think it might be the timeout associated with the Execute command. I tried your 'goto label' code which works fine. My slot 2 programme is a clock (using the LEDring mentioned in the code), which runs for about a second before implementing high-velocity dummy ejection. The console (ttyACM0) & the RTC are reset and putty leaves the building. |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
It does that just by being run, with no input? I'm suspicious of kscan which appears to leave itself permanently hooked to an interrupt. John |
||||
TheMonkeys![]() Regular Member ![]() Joined: 15/12/2022 Location: AustraliaPosts: 59 |
That was my initial concern. Running standalone it's fine. In the chained programme, kscan (yes, a second copy in slot 2) is called after some local variables are set and returns cleanly. |
||||
TheMonkeys![]() Regular Member ![]() Joined: 15/12/2022 Location: AustraliaPosts: 59 |
Yep, it was the execute watchdog. The following changes to the above listing fix the problem. ' in setup xec$(3,0) = "-1": xec$(3,1) = "2": xec$(3,2) = "3" xec$(3,3) = "4": xec$(3,4) = "5": xec$(3,5) = "6" ' add this kp$ = "123456789-0+"' for keyboard/pad support ' in main If exec$ <> "" Then Execute exec$: exec$ = "" ' is replaced with inchr$ = Inkey$' keyboard/pad support If inchr$ <> "" Then kbscan' see kbscan below If exec$ <> "" Then If ami% = 3 Then tv = Val(x$) If tv < 0 Then Flash Run -tv If tv > 0 Then Flash Chain tv Else Execute exec$: EndIf exec$ = "" EndIf ' new keyboard/pad support Sub kbscan kbv=instr(kp$, inchr$) select case kbv case 10 ami% = Choice(ami% And 1,ami% And 2,ami% Or 1)'toggle' lAmi case 11 ami% = 0'clear shifts case 12 ami% = Choice(ami% And 2,ami% And 1,ami% Or 2)'toggle' rAmi case 1 To 9 x$ = xec$(ami%, kbv-1) End select End Sub Note that console keypad/board support has been added. The keypad and console seem to play nicely. If it makes things easier, I can post the full updated code, rather than just the changes. |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |