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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sebastiani View Post
    >> I did have another idea, to keep the existing structure, but also get the code a bit less messy [no setjmp/longjmp!], which is to simply make a main loop that has a statemachine in it, and it does either "run the program" or "enter a line" functionality. That would be a lot less different from the current code.

    That sounds good. How does it work?
    If that's your subtle way of saying "Have you proven that it works yet", then the answer is no, I haven't implemented that. I've been busy preparing my sons 5th birthday by spending a lot of money at Toys'R'Us and Game - he's getting a bunch of Star Wars Lego models, and the second Lego Star Wars PS-2 game.
    Oh, and matsp - what shall I put yours down as?
    Mats is my first name, Petersson my last name.

    I think it's fair to also mention the original author of MiniBasic: Sylvain BIZOIRRE - at least as far as "this implementation is based on an assembler variant by ..." or some such.

    As to the Win32, editing etc, perhaps we should abstract that out into a separate class, so that it can be implemented using Win32, Curses or something else. It would make it a bit more portable! Certainly, if we want this to be at least reasonably successful, we should ensure that it can be built for non-windows platforms, even if it's not "complete" in those systems.

    --
    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. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    "As to the Win32, editing etc, perhaps [...] not "complete" in those systems."

    I had been working against a comparatively simple abstraction under the assumption we could glue them together easily enough. I'll post the terminal/console part of the abstraction. Unfortunately, my changes to the interpreter made it unusable in the context of the original and may have been too slow from the considerable use of polymorphic composition.

    I should probably explain that... just in case Sebastiani is headed down that same road. My changes were able to load existing "mini-basic" files easily enough, but the expression simplification and name aliasing stuff left the source far different than what was loaded. It performed the same mechanic, but did not result in the same source. So, if you loaded a file and promptly saved it the result wold be drastically different from the original. Any constant mathematic expressions with important magic numbers, which is obviously all that is available to the original, were compressed to the constant result before being passed to the interpreter or saved. It, basically, mangled the source.

    Anyway, I like the idea of having a dedicated trace/debug area, but I don't want to add to many dependencies either. It's pretty basic to split the terminal area up into multiple windows with `curses' so for now how about we just do that (only with the WIN32API)? For example, if the debug flag is set keep the height 2 lines longer with some arbitrary byte, maybe just `-', separating the status line from the actual buffer area. Will that work for everyone else? Possibly adding a dedicated `???::trace(const std::string)' function/method this purpose?

    I figure you guys can guess what exactly these methods return so I'm not going to label anything for now.

    Soma

    Code:
    typedef uint32_t colour_type;
    typedef std::pair<uint32_t, uint32_t> dimension_type;
    typedef std::pair<colour_type, colour_type> font_type;
    
    class terminal_server // singleton
    {
       public:
          std::pair<bool, font_type> colour
          (
             colour_type new_foreground_colour,
             colour_type new_background_colour
          );
          std::pair<bool, font_type> colour_at
          (
             uint32_t x_offset,
             uint32_t y_offset
          );
          std::pair<bool, bool> echo_mode
          (
             bool with_echo
          );
          std::pair<bool, dimension_type> move
          (
             uint32_t new_x_offset,
             uint32_t new_y_offset
          );
          // modified virtual character code (F5, "Up Arrow", Escape)
          std::pair<bool, uint32_t> read();
          std::pair<bool, dimension_type> resize
          (
             uint32_t new_width,
             uint32_t new_height
          );
          std::pair<bool, std::string> text
          (
             const std::string & new_text
          );
          std::pair<bool, std::string> text_at
          (
             uint32_t x_offset,
             uint32_t y_offset
          );
          std::pair<bool, std::string> title
          (
             const std::string & new_title
          );
       public:
       private:
          ???::any_like
       private:
    };
    
    class line_editor // implied singleton
    {
       public:
          // ??? (glue)
          std::pair<bool, std::string> read_some();
       public:
       private:
          terminal_server terminal;
          ubasic_interpreter interpreter;
       private:
    };

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    OK, so before everyonce gets started writing more code, let me just post a final revision so that there won't be any duplication of effort. We can break everything down into modules and work on them individually.

    >> As to the Win32, editing etc, perhaps we should abstract that out into a separate class, so that it can be implemented using Win32, Curses or something else.

    That's an excellent idea. I'm all for that.

    >> I was thinking of trying my hand at a simple editor window, cloning the look of the console as much as I could, so we could drop the implicit singleton of the actual console window.

    Sounds fine to me. The only thing that worries me is that having to work with things on the pixel level might get complicated. For example, since there is no standard guaranteed way to get a monospaced font in a GUI, you might have to just store the glyphs as bitmap images. I don't know. If you feel up to it, go for it. But just for posterity, I'll post the (possibly) IO code I have, as a short term alternative.

    >> If that's your subtle way of saying "Have you proven that it works yet", then the answer is no, I haven't implemented that. I've been busy preparing my sons 5th birthday by spending a lot of money at Toys'R'Us and Game - he's getting a bunch of Star Wars Lego models, and the second Lego Star Wars PS-2 game.

    And so the legacy of Star Wars is passed down to the next generation. Very good. Anyway, no rush, and Happy Birthday to your son.

    >> Well, you asked for it...

    Indeed. Well, don't feel bad. I have my share of "foolish parasite" family members; a notorious example being my (not-so-)great uncle, Billie Sol Estes. His actions and behavior caused a so much grief and shame for our family (mostly the older generation, anyway) that it got to the point where many complained that there was almost a stigma attached to the name itself!

    >> I think it's fair to also mention the original author of MiniBasic: Sylvain BIZOIRRE

    OK, I've updated the credits. One last question, though: should I include the original MiniBasic creator (I think he has a Japanese name - I'll look it up)?

    [edit]
    Soma, I posted without seeing if there were any previous - I'm reading through your last post now, though...
    [/edit]
    Last edited by Sebastiani; 04-11-2009 at 09:04 PM.
    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;
    }

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    "OK, I've updated the credits. One last question, though: should I include the original MiniBasic creator (I think he has a Japanese name - I'll look it up)?"

    Well, as far as I am concerned, you may give credit to all you wish. That said, the original assembler we are working from was an just an assembler project based on a "how to" document project implementing this dialect which is based on an old BASIC distribution for small machines which is itself based on a distribution for the old Apple computers. My point is, where exactly would you stop?

    (This is what I found out when I tried to find a better existing implementation to work from than the horribly confusing assembler you guys translated.)

    Edit: And of course, this is the age of the "wiki-people"; there is no telling how wrong the information I found may be...

    Soma

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Soma, the design looks good. Let me know if you want me to post the IO code I have (for reference, if nothing else).
    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. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Yes. Please. The less we duplicate each others work the better. (Like you I had been using C++ streams for testing purposes.)

    Soma

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