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 : Please welcome the newest MMBasic sibling to the family!
Page 1 of 2 | |||||
Author | Message | ||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
Please welcome the newest MMBasic sibling to the family! MMDebug is now available to people using MMBasic to help debug their PicoMite programs. MMDebug is a powerful but easy to use debugger. MMDebug is fully compatible with MMEdit and MMCC (MM Control Centre). It also works with TeraTerm if you have a need to use that terminal emulator. You need to use the latest version of MMCC. MMDebug makes extensive use of the cursor escape sequences and several errata needed to be squashed to make the MMDebug and MMCC siblings get along together. You can get the latest version of MMEdit/MMCC at: https://www.c-com.com.au/MMedit5.htm Once you have the latest MMCC installed, you need to go edit your MMCC.inf file to adjust the cursor reporting to make it accurate. On Windows, my MMCC.inf file is located at: C:\Users\EDN\AppData\Local\MMedit5\MMCC.inf You want to adjust the “Click Y shift = 5” line to something more like “Click Y shift = 15”. It will be close to 105 lines into the file. The actual number you use for the “Click Y shift” factor will vary depending on your system and the type of mouse cursor you are using. The reason you need to adjust this line in your MMCC.inf file is because a mouse click on the upper half of a character will get reported as being the previous line if you don’t make the correction. It will get very confusing if your mouse clicks are not reported accurately. Later, when you are actually using MMDebug, you can see exactly what is being reported for any given mouse click by looking at the bottom line of the MMDebug window. You can use that to verify that clicking on the upper part of a character reports the same line number as clicking on the lower part of the same character. If you get the same value being reported, you have the “Click Y shift” factor set correctly. (In the picture below MMDebug is reporting a mouse click at (90,18). Included in this post is a .zip file with MMDebug in it. The actual file name is MMDebug.uf2. You load this onto your Pico just as you would load a PicoMite.uf2 file. It should be fully compatible with PicoMite V5.07.08b15. MMDebug.zip MMDebug is activated by pressing Ctrl-D. Much as you can stop your program by typing Ctrl-C, you can halt your program and transfer control to MMDebug by pressing Ctrl-D. There are several ways to use this capability. If the program is running you can press Ctrl-D and MMDebug will get control just before the next MMBasic statement is executed. Alternatively, you can take control at the very start of your program’s execution by typing > Run Ctrl-D Enter. Typing Run obviously starts execution of your program, and by typing the Ctrl-D just before typing Enter will wake MMDebug up before the first line of your program is executed. Below is a screen shot of the modified Amazing.bas program running with MMDebug in control. You can see one of the modifications where this version of Amazing.bas is displaying the solution to the maze after the actual maze is printed. During the print out of the solution I pressed Ctrl-D and MMDebug woke up and took control. The purpose of this section of the post is to identify the different areas of the MMDebug screen and how they can be used. At the bottom various command buttons are available. A simple mouse click on the button performs the function specified. In the far bottom right of the screen is a status area telling you how deeply the program is currently nested into subroutines or user defined functions. In the upper right of the screen are the most recently seen variables. This is the ‘Watch Area’ of the screen. A variable with a Red value has just changed value. On the left side of the screen you can see a line highlighted in Yellow and Red. This is the current MMBasic statement that is about to be executed. And on the far left are white numbers. These are the actual MMEdit line numbers of the program. Two different capabilities are present that are not handled by the command buttons. If you click on a White line number, a Break Point will be set at that location and control will be relinquished to MMBasic until that statement is next to be executed. If the variables in the upper right side of the screen do not include a variable (and value) you need to see, you can click on a line of logic that has the variable you are interested in. You might have to Page-Up or Page-Down to find a line of logic with the variable you are interested in. But when you click on that line of logic any variable that is currently defined will be placed at the top of the ‘Watch Area’. A few words about the Step commands will be helpful to you. Step does just what you would expect it to. It will execute one statement. Even if there are multiple statements on the same line, Step will do one at a time. Step also loads any currently defined variables for the current statement into the top of the variable ‘Watch Area’ of the screen. Step-Over steps much faster than single stepping. Step-Over sets a break point at the start of the next line of code independently of how many statements are on the current line of code. But Step-Over also steps over For-Next loops and Do-Loops. If you Step-Over a For or Next statement, the entire loop will be completed and control will be given back to MMBasic at the logic line immediately following the Next statement. The same applies to Do-Loops. If Step-Over is done when the Break Point is on a Do or a Loop, the entire loop will be executed and control will be given back to MMDebug at the statement immediately following the Do-Loop. Lastly, Step-Over can be used to quickly execute entire Gosub’s , Subroutines, user defined functions and Select Case statements. Please note that if you have a spaghetti program that arbitrarily jumps out of For-Next or Do-Loop’s, you will lose control and have to press Ctrl-D to get control back. Step-Out is conceptually much like Step-Over except its purpose is to help you get out of functions and subroutines. You do not need to step repetitively to get out of a subroutine or user defined function. You just Step-Out and MMDebug will take back control at the statement following where the function or subroutine was invoked. Lastly, Edit-Value needs to be discussed. With a character orientated display it is very difficult to display elements of a large matrix. This fact combined with the need to easily display variable values that are not in the ‘Watch Area’ necessitates the Edit-Value command. The Edit-Value command actually uses MMBasic’s ExecuteProgram() function to do its work. At the command prompt you can enter either a Print statement or a Let statement depending upon whether you want to see a variable’s value or change a variable’s value. For example, at the prompt in the Edit-Value command you could say > Print xyz . If xyz has been defined it will print the current value. If you wish to change the value of a matrix element you might type something like > Let MM(R+1,C-1) = 10.2 You can use normal MMBasic syntax and index into arrays using current variable values. If what you type has a syntax error in it, MMBasic will complain about the syntax problem and report the current line you have MMDebug break pointed at as the line that caused the problem. Of course, this isn’t strictly true. The line you are break pointed at is probably fine, but MMBasic doesn’t know that. If MMBasic complains about a syntax error, MMDebug will yank control back from MMBasic Pressing an empty Return when in the Edit-Value window will terminate and close out the window. If you ask the Edit-Value window to display the value of a variable, you can just type Print (or ?) to reset the window and look at another value. The important point to understand is an empty Return gets you out of the Edit-Value window. MMDebug was written to be as easy to use and intuitive as possible. The best thing to do is pull a program you have written into it and try different things. And of course… If you find a bug please post a small MMBasic program that manifests the problem with instructions on how to duplicate the bug. Enjoy! |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4040 |
Hi @EDNEDN, Actually the zip file only contains a "PicoMite.uf2" ??? Do I understand correctly that MMDebug is fundamentally a custom MMBasic/PicoMite firmware with inbuilt debugger capabilities ? Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
And if so, what version number/release of PicoMite firmware? I'm very interested in trying this, but will be travelling and won't have an opportunity for a good month. 3 years ago I made a good start on a MMBasic debugger based on the DOS version. It required a single hook in the MMBasic code, and a MMBasic variable set to 1/0 to enable/disable the debugger. But DOS MMBasic seemed very dated, and the project lapsed. Congratulations on bringing this to publication. I'd be interested in hearing more about how you have planned out and made this journey. ~ Edited 2023-11-13 22:50 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
Ooooops.... I don't know how that happened. I double checked everything before I saved the post. But I did verify the PicoMite.uf2 file in the MMDebug.zip file is correct. That **IS** the debugger. And "Yes!", MMDebug is an extra module of code that gets added to the standard PicoMite.uf2 code. For some reason... I can't edit the post to correct it. And I can't even post a corrected .zip file in a Reply. Please go ahead and use that file. It should work for you. I downloaded the .zip file, extracted the .uf2 file and loaded it. It does contain the MMDebug module. It is currently added to PicoMite V5.07.08b15. That seemed to be the most stable of the recent Release Candidates. There are only about a dozen modified lines to the PicoMite code base. You probably cut in the same place I did. At the very top of the while() loop in ExecuteProgram() I added: if(MMDebug || (p==MMDebug_Brk_Pnt_Addr) || MMDebug_Level_Change==gosubindex ) { // EDN added hook to get to the Debugger if ( p < (unsigned char *) 0x20000000 ) { // For right now, we only break point in the main program code. // Not the library code. WDTimer = 0; // turn off the watchdog timer ShowCursor(true); p = Debugger( p ); if ( *p == 0) p++; } } I wrapped everything in CODE delimiters. But for some reason the website is messing with the formatting. The good news is it is only a few lines of code and a C programmer should be able to see what is there pretty easily. if MMDebug gets set by the keyboard interrupt handler, that will force entry into the MMDebug module. Alternatively, the MMDebug_Brk_Pnt_Addr variable can be set (by MMDebug) as a place to break point. That is used by the Step-Over command to communicate where the next halt is desired. And lastly, the MMDebug_Level_Change variable is used by the Step-Out command. There are also a few lines of support code in routinechecks() to notice the user pressed Ctrl-D. if (DebugKey && c == DebugKey /* defaults to Ctrl-D */) { // if the user wants to enter the debugger MMDebug = true; // set the flag that happened ConsoleRxBufHead = ConsoleRxBufTail; // empty the buffer } else { Other than that only a few declarations in the .h files This can be moved easily to the latest release. The code is written cleanly. If the MMBasic user base finds it valuable, it should be very easy to be absorbed by the PicoMite code base. One of the design constraints was to make sure the main PicoMite code base was impacted the absolute minimum so it is easier to verify the additional code is not affecting the correctness of the main code body. For example, everything is set up so a user could use the OPTION command to change the ASCII code that triggers MMDebug to wake up. But none of that code is added yet. Right now it defaults to Ctrl-D. Edited 2023-11-14 01:35 by EDNEDN |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Thanks for the explanation. Yes, that sounds very similar to what I had done--a few definitions and a hook in the MMBasic code. It was helpful that the MMBasic structure was such that it was easy to add variable watches. This will be far more useful on the PicoMite than it would have been on MMBasic for DOS. Notes: You can only edit a post if no reply to it has been posted. You also can't modify a ZIP file (unless you're a forum admin like matherp), so you have to repost if there are changes. The [ CODE] [ /CODE] tags (without spaces) have to be in upper case on this forum. With a long post, it's good to PREVIEW it before submitting. ~ Edited 2023-11-14 03:23 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9119 |
If you get it fully finished and integrated I would be happy to add it to the main code (and get rid of TRACE!!!!!). Things to check - library obviously, FLASH RUN runs direct from the flash slot and not the main code area, VGA version or OPTION LCDPANEL CONSOLE integration, + anything else I've forgotten. I wouldn't look to integrate it if not compatible across all three versions and all modes of operation (i.e. local editing and local console). It could work very well in MMB4W as you could use the second panel for the debug window Edited 2023-11-14 03:39 by matherp |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
Right now the only assumption is MMDebug has a 145x45 character display to display its information. And all of the development work was done using MM Control Centre. TeraTerm was used occasionally just to verify it was MMCC that was not producing the correct results from some of the extensive cursor controls. And TeraTerm works with it also. As long as the Pico allows a USB Serial connection, it should be minor tweaking to get the terminal emulator working with the particular PicoMite firmware version. The MMDebug screen was deliberately placed in the upper right hand corner of the console screen to allow the MMBasic program to still output things and to be observed by the user. (It isn't implemented yet, but everything was done to make the size of the debug window adjustable (both vertical and horizontal) by the user.) All expected features of MMBasic are intact. (You can see from the two hooks above that things like Local Editing and local console work normally. In fact, a few small functions were duplicated (like MMgetline() ) because different behavior was required and keeping the MMBasic code unaltered was the best approach.) Edited 2023-11-14 04:01 by EDNEDN |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 172 |
@EDNEDN: This is really cool!! The debuger worked out-of-the-box. I only used it in TeraTerm so far, but it works The only glitch that I saw so far was when using the mouse to click on the buttons, a brief "?? Invalid debugger command" message flashes, but the action is carried out anyways. Best, Thomas |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
The only glitch that I saw so far was when using the mouse to click on the buttons, a brief "?? Invalid debugger command" message flashes, but the action is carried out anyways. Best, Thomas I'll check into that. TeraTerm does a Mouse Cursor Report for the down click on the mouse. And then it does a Mouse Cursor Report for the release of the mouse button. In order to make it work for both MMCC and TeraTerm I ended up using the mouse button release as the 'click' for TeraTerm. Probably some of the characters being sent for the mouse click aren't getting disposed of properly. I'll get that fixed ASAP. Incidentally... With TeraTerm you don't have to do any calibration to get the mouse clicks to report the location accurately. You probably can confirm what you point at is indeed getting clicked.... Edited 2023-11-16 01:17 by EDNEDN |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
@karlelch I got it fixed for you... It was a little more logic than what I expected. Because TeraTerm reports both Mouse Click Down and Mouse Click Up it kind of messed with things if the user is doing an Input statement. What was happening with the simple fix was the Mouse Click Down on Step would send control off to MMBasic and the Input statement would be active grabbing characters to assign to the variable. But when the user released the mouse button for the click on the Step command in MMDebug, another Mouse Cursor Report Escape Sequence was being sent and causing noise characters to show up at the Input prompt. That required some extra logic to notice TeraTerm was being used as the terminal emulator and then switch to use the Mouse Button Release instead of the Mouse Button Clicked. (Or stated differently... MMDebug needed to be active in order to eat and discard the extra Mouse Cursor Reports. So if the user's program was at an Input statement that necessitates making the Step happen on the release of the mouse button and not on down click.) Anyway... Here is an updated version of MMDebug.uf2 for you to give a try. MMDebug.zip Edited 2023-11-16 06:54 by EDNEDN |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 172 |
I got it fixed for you... [...] Here is an updated version of MMDebug.uf2 for you to give a try. Thank you! I tried it and it works. Sorry that it was more complicated than expected. You said your mod works with all PicoMite versions? I could imagine that it would be particularly nice for the VGA firmware. Because then you could run the debugger in the terminal and while your program is generating graphics undisturbed on the VGA monitor. May be of help for the PICO PETSCII team when the game code becomes increasingly complex. Best Thomas |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
I just updated the MMDebug.zip file in the previous post. You might want to pull it down and reload it. TeraTerm does Clear to End of Line differently than MMCC. If you have a statement like: if some < condition then x = x + 1 They were getting highlighted slightly differently between the two terminal emulators. When you first start executing the If statement the whole line is highlighted. But if when you Step and the condition is found to be true, only the Then clause was intended to be highlighted. In TeraTerm the whole line was still highlighted. That is corrected now for the TeraTerm users. (And actually... I suspect TeraTerm is doing things correctly. But it doesn't matter. The highlighting is now the same for both. MMCC was clearing the background color to Black which is what was intended even if the background color was something else. Now both are being told the background color should be Black.) You said your mod works with all PicoMite versions? I could imagine that it would be particularly nice for the VGA firmware. Because then you could run the debugger in the terminal and while your program is generating graphics undisturbed on the VGA monitor. May be of help for the PICO PETSCII team when the game code becomes increasingly complex. I don't have any working boards other than a normal Raspberry Pi Pico. But if anybody wants a VGA version of the firmware with MMDebug in it I can generate it for them and post it here. Edited 2023-11-16 07:16 by EDNEDN |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 172 |
Ok - I can check it out tomorrow after work I’d be happy to test drive a VGA version. |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
I’d be happy to test drive a VGA version. I'll work on figuring out how to generate a VGA verson... |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 172 |
I recently got 5 of matherp’s VGA boards made. Depending on where you are located and if your interested, I could mail you one. |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
Thank You for the offer... But I've been looking at how to build the VGA version. I think I'll be able to build it and test that it works without an actual Pico-VGA board. I think I have the VGA version built. I don't have any way to attach a console and see what it is displaying using the 2nd core, but MMBasic and MMDebug are alive and working. Please give this a try: MMDebugVGA.zip Edited 2023-11-17 08:52 by EDNEDN |
||||
tom_g Newbie Joined: 21/02/2023 Location: SwitzerlandPosts: 16 |
Good evening EDNEDN, I consider your work a huge added value to PicoMite ! A software debugger complements hardware debugging (set/reset/toggle) outputs and watch them with a scope, and print/log variables from the console (I use VSPE as com splitter from Etherlogic to hook in RealView logger software from abacom-online to graph the debug variables yet to be able to use MCC) Thank you so much for offering this to us ! I have two questions (although I am aware that the debugger is and must remain lean): 1. the watch list can become long and cluttered with non relevant variables during the debugging. Would it be possible to delete watch variables for instance by clicking it away ? 2. one of my programs contains more than 1000 code lines, instead of having to access debug code area by multiple page up/dn button presses (which is very weary) would it rather be possible to center the debug code window content for instance around a line number, which could be pointed/entered directly to ? Best regards from Thomas |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
1. the watch list can become long and cluttered with non relevant variables during the debugging. Would it be possible to delete watch variables for instance by clicking it away ? Yes. This is almost trivial to do. I was thinking about allowing the user to click on a variable and that would tell the debugger to run until that variable was referenced. And then alternately allow the user to click on the variable's value and that would tell the debugger to run until that variable's value changed. But the problem with these ideas is the amount of code (and where that code would cut into MMBasic) required to do this. What you are suggesting for removing the clutter of the watch list is almost trivial and can be done with just a couple lines of code. 2. one of my programs contains more than 1000 code lines, instead of having to access debug code area by multiple page up/dn button presses (which is very weary) would it rather be possible to center the debug code window content for instance around a line number, which could be pointed/entered directly to ? Yes. Moving the display window to a given line of code is also almost trivial. The hardest part of doing this is deciding on the way for the user to specify where they want to move the window. And perhaps it should allow multiple ways to enter that information. It could be a hard number of lines from the start of the program. It could be a given label or line number (for programs that use line numbers). It might be that the first couple of clicks move the window 20 lines but subsequent clicks start moving more and more lines at a time. Doing what you suggest is actually very easy to do. Would typing in a line number be a good way to position the window? Alternatively, a new button at the bottom could be added to query a position from the user. Edited 2023-12-03 11:11 by EDNEDN |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6795 |
How about a pseudo-command in a comment? Something like 'TRACE starts the list. It could even be temporarily commented out with ''Trace :) It could be extended 'Trace 30 to list the next 30 lines. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
tom_g Newbie Joined: 21/02/2023 Location: SwitzerlandPosts: 16 |
Good morning EDNEDN, tnx for your answer. Personally I would be happy with a way to erase a selected variable or even the whole watch list, both ways would do, the simpler to implement. And I would prefer entering an absolute line number as the pointer to the debug code zone, I would not like to have to edit my code with debug commands. Have a good sunday, best regards Thomas |
||||
Page 1 of 2 |
Print this page |