Thread: Converting MINI-BASIC in MASM over to C++?

  1. #241
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, so I've just reorganized most fo the code that Sebastiani has written into separate .cpp files, renaming the header-files into .h instead of .hpp.

    It compiles and I think it works just as well as before (pitman works reasonably well, but some console stuff gets a bit messy).

    I think we should do more refactoring and split up "minibasic.cpp" into a couple of files, but I haven't looked into it very much.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #242
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    OK, I'll be posting some updates as well, soon, including some major changes to the FOR loop functionality (whereas before you could only use named variables, you can now use @ variables as well), the addition of the TIMER function and other minor extensions, and formatted the code to the original stype. By the way - where is console.h and token_scanner.h? I don't see them anywhere. Oh, and although I really don't mind changing the '.hpp' files to '.h', it is a pretty standard extension for C++ header files. No big deal, though, just thought I'd point that out. And I think the experimental code is stable enough to put it in the main directory.

    Thoughts?

    >> I think we should do more refactoring and split up "minibasic.cpp" into a couple of files, but I haven't looked into it very much.

    Ugh. My only objection there is that it is extremely time consuming. =/
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #243
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Drat! I forgot to add those files. They aren't hard to recreate, but I guess it's better to wait until tonight (my time) when I can submit them. Expect around 7PM BST.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #244
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Oh, don't worry about it - done.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #245
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't know if I've broken something - it seems to not work at all right now, exits either immediately or after the first letter. Did you test your code before pushing?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #246
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Found it. It was a case of "assign instead of equality test"
    Code:
    diff -r 75584b6b32c9 -r d7a2a568bcb3 minibasic/experimental/console.cpp
    --- a/minibasic/experimental/console.cpp        Tue Apr 21 21:50:42 2009 +0100
    +++ b/minibasic/experimental/console.cpp        Wed Apr 22 00:18:29 2009 +0100
    @@ -217,7 +217,7 @@
                            }
                    }
            }
    -       if( ch = '\r' )
    +       if( ch == '\r' )
                    put(ch);
            return ch;
     }
    I'll submit that and a few minor cosmetic changes.


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #247
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And I've changed a few long if-else chains to switch statements. Makes the code easier to read, I think, and also possibly more efficient as we don't have to walk down a long chain of if-else statements (not that it's a big performance hit at the moment)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #248
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Sounds good.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #249
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I finally decided to crack open the source to see what you two have been doing... fitting my work will require a sledge hammer... or a scalpel.

    I'll try to work on that some more later, but for now... please... pull down the latest update before doing any more work. I somehow got a bad set when I tried to merge my few updates to Mats updates. It was a pain... and I think I lost a bug fix in the progress. (I worked my changes into commit 37 manually, and I'll be happy to remove the macro bits later.)

    Anyway, the way the `get' helper routine(s) are implemented a simple approach to handling ESCAPE simply will not work. I needed this feature to test my theories, but I didn't want to break anything by trying to patch it; I've hacked a silly callback mechanism until it can be done right. (It can be pulled out later in a few seconds.)

    Nearest I can tell, the approach we've all taken to the padding feature is totally, utterly, miserably wrong. I've done the mathematics, and I believe fixing this feature will fix the "PITMAN.MBI" display problems. (I recorded the offsets we generate and compared those results with what the original and source seem to expect.) I've left minimal notes under the "issues" section of the "BitBucket" project page. I can't find anything else at fault... even the "EDIT" mode of "PITMAN.MBI" seems to display properly. (I imagine that this is because it uses a different layout engine for the "EDIT" mode display.)

    For whatever reason, interrupting "MBI" execution with ESCAPE followed by loading the same "MBI" back into memory will result in garbage. I'm thinking the compiler or virtual machine needs to be reset after an escape, but I didn't know if that would trash the loaded source as well, and I didn't have time to experiment any further.

    Soma

  10. #250
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I did lose a fix: after you compile the latest source type in something and hit backspace. (The cursor appears to be in the wrong position until a character is typed.)

    Oh... yea... and... my editor strips trailing whitespace so my set pushed a lot of unnecessary changes; to add insult, anything I've touched will use spaces instead of tabs because I forgot to change the settings. Sorry.

    Soma

  11. #251
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Rather than make you type in code, I've added the "MBI" to the repository.

    I grabbed another hour to experiment.

    I've uploaded some more source. I don't know the source well enough to put the hacks where they best belong; I've only just punned a hack that may correct the padding issues. (This will have to be cleanly fixed by someone who knows the source better if it proves correct.) The "PITMAN.MBI" program is still not correct, but it looks much better. (That said, the one issue may not be an issue of `void minibasic::show_pad()' but an artifact of one of the below problems.)

    I've also commented out the scrolling code because it behaves weirdly.

    Before either of you get upset about the punning and the tracing stuff... I've found two pretty crazy bugs. I'm listing them here for now, but if I can't find a fix in the next 15-20 minutes I'll probably try and grab a minute to pin a note to the "issues" section.

    1): The expression "64+1*3" is a silly way of saying "67" so how come the following code prints "Stage" and my little men starting at the same horizontal offset?

    2): How come running the code twice without a reset puts "Stage" in a two different places?

    Soma

    Code:
    10 CLS
    15 LET L=4
    20 LOCATE 70,1
    25 PRINT "Stage ";#2;1
    30 FOR A=1 TO 4
    35 LET X=3:LET Y=64+A*3
    37 LOCATE 0,0:PRINT X:LOCATE 2,0:PRINT Y
    40 COLOR 2,0
    45 LOCATE Y+1,X
    50 PRINT " 0 "
    55 LOCATE Y+1,X+1
    60 PRINT "/X\"
    65 LOCATE Y+1,X+2
    70 PRINT "/ \"
    75 NEXT A
    80 FOR Z=1 TO 25
    85 NEXT Z

  12. #252
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by phantomotap View Post
    I did lose a fix: after you compile the latest source type in something and hit backspace. (The cursor appears to be in the wrong position until a character is typed.)

    Oh... yea... and... my editor strips trailing whitespace so my set pushed a lot of unnecessary changes; to add insult, anything I've touched will use spaces instead of tabs because I forgot to change the settings. Sorry.

    Soma
    Speaking of which: The current code, I believe is a mix of tabs and spaces. We probably should use one or t'other.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #253
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    GET THE LATEST SOURCE!

    Paul:

    Unless Mats removes it, the link below my name will take you to a page where you can download our latest push. Please download it and try it with a few programs. You've used the original, a lot apparently, and should know when something is misbehaving. Please report back any issues you discover.

    Mats:

    The "experimental" branch is now the default, and the old default branch is now "depreciated".

    Sebastian:

    Your `std::string operator & <???> (const std::string &, const <???> &)', while cute, breaks MSVC. (The compiler literally crashes.) I've not explored this, but I imagine I can fix it. If you would though, do you mind trying to separate it from the class proper(non-membe, non-friend operator)?

    Everyone:

    I think I've found and fixed a few more bugs.

    As far as I can tell, I've fixed all of the bugs I've referenced. This naturally doesn't mean I've found them all; I'm sure to find more if I keep looking, but I've got other stuff to do for the rest of the week. (Which should explain my trying to get a lot done today.) I hope you guys, who should know more about the source, can look around at my changes and see where it will best fit into the design.

    The "PITMAN.MBI" program displays perfectly as do several other programs. That said, the one Sabastini made doesn't work at all. (I accidentally "removed" "REIGN.MBI" because I thought it was something I created by accident.) I'm not entirely sure what is happening. My only thoughts here: Sabastini wrote his program under the false pretense of the documentation. (Naturally, I could have broke something in fixing the others, but I hope not.)

    Soma

    matsp / minibasic / downloads &mdash; bitbucket.org

  14. #254
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    "We probably should use one or t'other."

    Check the latest set... especially the tip.

    Soma

  15. #255
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by phantomotap View Post
    "We probably should use one or t'other."

    Check the latest set... especially the tip.

    Soma
    Yes, I saw that now.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting textBox1->Text into a basic string.
    By azjherben in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2009, 08:27 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. VC++ 6 & MASM (eek)
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 07-16-2005, 10:00 AM