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

  1. #61
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    First of all, you may want to modify it so that it doesn't try to change the window to a size not supported, instead of giving "bad parameter".

    Whether it is valuable to change the size or not is a different matter. I kept it the way the original code was - the principle being "Make it work first - then change it around".

    I have made changes - e.g. the way that lines are kept in memory as a linked list instead of as a big chunk of text (with binary line numbers in it) is a change from the original format. In a proper C++ solution, I think a std::map<int, string> would be the right solution, but linked list was easy to implement at the spur of a 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.

  2. #62
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I'm working on 'EvalExpr' right now, and I think it's almost done. I'll post an update soon...
    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. #63
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sebastiani View Post
    I'm working on 'EvalExpr' right now, and I think it's almost done. I'll post an update soon...
    Excellent.

    --
    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. #64
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    Cool. Thanks.

    Paul

  5. #65
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Hmm, I'm getting seg-faults with the PRINT routine. Any ideas, matsp?
    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. #66
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sebastiani View Post
    Hmm, I'm getting seg-faults with the PRINT routine. Any ideas, matsp?
    Not without you telling me more? What dev-environment are you using? In visual studio, I can just click on the call-stack to see how I got there.

    Or is it segfaulting in EvalExpr?

    [You could always use dispstr() to display where you get to]

    --
    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. #67
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Ah, it's because when 'NextLine' was called in 'direct' mode, BasicLine* 'current' was NULL. These changes seemed to fix the problem:

    Code:
    void DirectCommand(const char *LineBuffer)
    {
    	current = 0;
    	Execute(LineBuffer, tab1);
    }
    
    void NextLine(void)
    {	
    	if(current)
    		current = current->next;
    	if (!current)
    	{
    		Prompt();
    	}
    }
    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;
    }

  8. #68
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That looks like a good change - although changing current in DirectCommand may not be the right thing, as I think you should be able to stop the code, then continue after for example printing values of variables.

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

  9. #69
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I see what you mean. Well then how about:

    Code:
    void DirectCommand(const char *LineBuffer)
    {
    	const BasicLine* saved = current;
    	current = 0;
    	Execute(LineBuffer, tab1);
    	current = saved;
    }
    Last edited by Sebastiani; 03-19-2009 at 10:23 AM. Reason: Changed to const
    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;
    }

  10. #70
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    I agree. I think that's a good change. It looks good.

    Paul

  11. #71
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    So what is the difference between ':' and ';' when separating commands?
    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. #72
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    I think : is for how MINI-BASIC separates commands. I'm not sure how C++ does.

    Paul

  13. #73
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Minor fix: changed the 'while' loop in DispNumber to a 'do/while' loop so that zero is displayed:

    Code:
    	do
    	{
    		*ptr-- = (n % 10) + '0';
    		size--;
    		n /= 10;
    	}
    	while(n);
    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. #74
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> I think : is for how MINI-BASIC separates commands.

    But looking at the doc you posted, it has:

    LET A=234-5*6;A=A/2;X=A-100;@(X+9)=A-1
    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;
    }

  15. #75
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    I think that's an error in the document. Let me post some example code really quick:

    Windows Console Tiny Basic V.1
    Ready.
    >load castle
    Ready.
    >list
    Code:
        5 CLS
       10 PRINT "MINI-BASIC ASCII Art":PRINT
       15 PRINT"|---| |---| |---|                 |---| |---| |---|"
       20 PRINT"|   ---   ---   |                 |   ---   ---   |"
       25 PRINT"\              /                  \               /"
       30 PRINT" |            |                    |             |"
       35 PRINT" |            | |---| |---| |---|  |             |"
       40 PRINT" |            |--   ---   ---    --|             |"
       45 PRINT" |                                               |"
       50 PRINT" |                                               |"
       55 PRINT" |                                               |"
       60 PRINT" |             /------------------\              |"
       65 PRINT" |             |[][][][][][][][][]|              |"
       70 PRINT" |             |[][][][][][][][][]|              |"
       75 PRINT" |             |[][][][][][][][][]|              |"
       80 PRINT" |             |[][][][][][][][][]|              |"
       85 PRINT" |             |[][][][][][][][][]|              |"
       90 PRINT" -------------------------------------------------"
       95 PRINT"Castle by dunric"
    Ready.
    >

    Notice the ":" in line 10. So it has to be ":" and not ";". Otherwise it would be a syntax error.

    Paul

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