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

  1. #76
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Got it.
    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;
    }

  2. #77
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Ok, so this update contains the implementation for 'EvalExpr', and the 'LET' command, plus some other minor changes. Let me know if I broke anything.

    Paul, just thought I'd let you know that it still has a way to go before you'll be able to test it out, but it is coming along...
    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. #78
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    Ok, thanks Sebastiani.

    Paul

  4. #79
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I took a look at the code... the original is a bad dog.

    Before I jump into this, which I may if time allows, may I at least suggest updating the API test to do something useful?

    Soma

    Code:
    void mbox_error_handler
    (
       const std::string & from_f,
       const std::size_t where_f,
       const bool show_f
    )
    {
       if(show_f)
       {
          const DWORD buffer_length(256);
          char message_buffer[buffer_length];
          const DWORD characters_written = FormatMessageA
          (
             FORMAT_MESSAGE_FROM_SYSTEM,
             0, // lpSource (ignored here)
             GetLastError(),
             0, // dwLanguageId (use system defaults)
             message_buffer,
             buffer_length,
             0 // Arguments (pointless VA_LIST nonsense)
          );
          std::ostringstream message;
          if(0 == characters_written)
          {
             message
                << "File: " << from_f << '\n'
                << "Line Number: " << where_f << '\n'
                << "Error Message:\n"
                << "unknown exception"
             ;
          }
          else
          {
             message_buffer[characters_written - 2] = 0;
             message
                << "File: " << from_f << '\n'
                << "Line Number: " << where_f << '\n'
                << "Error Message:\n"
                << message_buffer
             ;
          }
          MessageBoxA
          (
             0, // hWnd (no owner)
             message.str().c_str(),
             "WIN32API Exception",
             MB_ICONERROR | MB_OK | MB_TASKMODAL
          );
       }
    }
    
    #define WINAPITEST(BADVALUE, RESULT) mbox_error_handler(__FILE__, __LINE__, BADVALUE == RESULT)

  5. #80
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> I took a look at the code... the original is a bad dog.

    I couldn't agree more.

    >> may I at least suggest updating the API test to do something useful?

    That's a good idea. And since API errors are basically fatal, you might as well just have the program die at that point.
    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;
    }

  6. #81
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Agreed - I was going to do something like that, but I hadn't got round to it.

    Can we just do a small change:
    Code:
    #define WINAPITEST(RESULT, EXPECTED) mbox_error_handler(__FILE__, __LINE__, RESULT == EXPECTED)
    By putting names there, it's easier to see what is what.
    --
    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. #82
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by phantomotap View Post
    I took a look at the code... the original is a bad dog.
    I'm pretty sure I said something like that when I started the work - it's definitely not easy-to-follow, straight-forward assembly code. Lots of jumps. One of my favourites was a bit that did
    Code:
    pop ebx    // get return address
    add ebx, 2
    jmp ebx
    to skip over a jmp instruction in the calling code. That is hard to achieve in C or C++.

    I'm going to have a quick look at Sebastianis change's, but do not expect me to do much with it until Monday.

    In the mean-time, keep up the good work.

    --
    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. #83
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    Ok, thanks.

    Paul

  9. #84
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A couple of comments on the updated code:
    1. what is #include <std> for?
    2. In VS 2008, the loss of const in RedimWindow() doesn't work.

    I also think we should keep the functionality of RedimWindow - there is a "WINDOW" command in the language itself that uses it. I believe existing code would break if you remove that command.

    It may well be that some situations do not allow completely free re-sizing of windows, but it should still be there for those apps that can/want to do it.

    --
    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.

  10. #85
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Oh, the header include was just for debugging purposes. Ignore it.

    As far as RedimWindow goes, it just needs to be restructured so that it takes on a default value when the program starts up, and then if the user tries to resize the window and it fails, it just reverts back to the default without causing a fatal error.
    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;
    }

  11. #86
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    For some reason the documentation in MBI.zip doen't list all of the functions (such as WINDOW, LOCATE, etc). Anyone have a complete listing?
    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;
    }

  12. #87
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sebastiani View Post
    For some reason the documentation in MBI.zip doen't list all of the functions (such as WINDOW, LOCATE, etc). Anyone have a complete listing?
    There is a complete listing in the original source...

    --
    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. #88
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Ha! Yeah, I admit it, I was trying to avoid looking at the assembly...
    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;
    }

  14. #89
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sebastiani View Post
    Ha! Yeah, I admit it, I was trying to avoid looking at the assembly...
    That may or may not be a good idea. To make it "binary compatible" with the existing assembly code, I think reading documentation may not be sufficient.

    --
    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.

  15. #90
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    BTW, Are PEEK and POKE supposed to refer to the @ variable?
    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;
    }

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