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

  1. #226
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have made several submissions, but I'm not sure if I've completely broken stuff or not.

    It seems like it's thinking that .hpp files are binary for some reason - I don't understand why at this point in time (there is no NUL characters in the file, which is what one web-page says is the sign of a binary file in mercurial).

    Edit: I also added a makefile for the experimental section. As a consequence of the rather strict warning levels, I had to fix a few things to make it compile (and changing the local include files to use "" instead of <>).

    I will make some comments on the coding style in a second post.

    --
    Mats
    Last edited by matsp; 04-18-2009 at 07:59 AM.
    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. #227
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    As far as coding style goes, I had actually planned to modify the experimental code to conform to the style used in our original code, but just hadn't gotten around to it. I'll wait till you post before moving forward with any changes, though.

    Edit:

    >> It seems like it's thinking that .hpp files are binary for some reason - I don't understand why at this point in time

    I didn't have any trouble compiling the code that you added, so I think everything's kosher.
    Last edited by Sebastiani; 04-18-2009 at 08:42 AM. Reason: comment
    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. #228
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    How should embedded carriage returns ('\r') work when encountered in a multiple line update--a statement with embedded newlines? Does that account for newlines after a cursor reposition?

    Traditionally, a carriage return would only reset the cursor x position to the start of the line. I don't think this is how the original behaves, and I'm not to sure about the current state of IO or which branch to work from.

    I'll show some examples of what I've written. (I didn't really consider how the original might handle embedded carriage returns and newlines in my rewrite.)

    I'm working on adding a separate buffer abstraction. (It is based on my image abstraction which is loosely based on the way "Cairo" handles abstractions.) My color abstraction seems to work fine, but it is painfully slow if used to implement additional buffers at the abstraction level.

    I'm shooting for something like:

    Code:
       terminal_canvas * b = tc.craft_canvas();
       b->reposition(0, 0);
       b->print("Hello, World!");
       tc.transfer(*b, 10, 10); // print "Hello, World!" at 10, 10 in the terminal window
    Soma

    Assume--for each example--that this is the current state of our buffer:

    Code:
    0123456789
    0123456789
    0123456789
    0123456789
    0123456789
    This code:

    Code:
       tc.reposition(0, 0);
       tc.print("Hello!\nTesting!");
    updates the buffer to this state:

    Code:
    Hello!6789
    Testing!89
    0123456789
    0123456789
    0123456789
    This code:

    Code:
       tc.reposition(1, 1);
       tc.print("Hello!\nTesting!");
    updates the buffer to this state:

    Code:
    0123456789
    0Hello!789
    0Testing!9
    0123456789
    0123456789
    This code:

    Code:
       tc.reposition(2, 2);
       tc.print("Hello!\nTesting!\rWorking!\nGone!");
    updates the buffer to this state:

    Code:
    0123456789
    0123456789
    01Hello!89
    01Working!
    01Gone!789

  4. #229
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sebastiani View Post
    As far as coding style goes, I had actually planned to modify the experimental code to conform to the style used in our original code, but just hadn't gotten around to it. I'll wait till you post before moving forward with any changes, though.

    Edit:

    >> It seems like it's thinking that .hpp files are binary for some reason - I don't understand why at this point in time

    I didn't have any trouble compiling the code that you added, so I think everything's kosher.
    No, it was more the fact that the entire file was "new" when I hadn't actually modified it more than a line or two.

    But it seems fine.

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

  5. #230
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Coding style issues:
    1. Formatting - Sebasiani, you have already covered that, so please feel free to modify the style to match what I originally wrote, or something similar to it.

    2. Far too much code in header files. There is absolutely no need to put so much of the code in header files, and it makes a better design, in my opinion to split functions. Any member function more than about 3-4 lines (that isn't proven to need to be inlined for performance reasons).

    3. Use of the register keyword. I don't know if you've seen my comments on that elsewhere, but gcc actually tells us specifically that it's useless in one case - where it is used as a reference parameter.

    --
    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. #231
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    My first minibasic game.

    Code:
    ' Reign! - A Game For Cprogramming.com's Minibasic by Sebastian Garth
    1	@( 0 ) = 79 : @( 1 ) = 23 : @( 2 ) = 0 : @( 3 ) = @( 2 ) + @( 1 ) : @( 4 ) = 0 
    2	@( 5 ) = @( 4 ) + @( 0 ) : @( 6 ) = @( 0 ) / 2 : @( 7 ) = 0 : @( 8 ) = 0
    3	@( 10 ) = 0 : @( 11 ) = 0 : @( 12 ) = 100 : @( 13 ) = 13 : @( 14 ) = @( 13 )/2	
    4	@( 15 ) = 125 : @( 16 ) = @( 15 ) * 2 : @( 17 ) = @( 15 ) * 4 : @( 18 ) = 293 
    5	@( 19 ) = 466 : @( 20 ) = 440 : @( 21 ) = 391 : @( 22 ) = 349 : @( 23 ) = 277
    6	@( 24 ) = 587 : @( 25 ) = 659 : @( 26 ) = 739 : @( 34 ) = @( 15 ) / 2
    7	WINDOW @( 0 ) + 1, @( 1 ) + 2
    8	COLOR 15, 7
    100	@( 12 ) = 100 
    101	@( 27 ) = 3 : @( 28 ) = 0
    102	CLS
    103	FOR @( 29 ) = @( 4 ) TO @( 5 )
    104	FOR @( 30 ) = @( 2 ) TO @( 3 )
    105	IF ( @( 29 ) = @( 4 ) ) + ( @( 29 ) = @( 5 ) ) + ( @( 30 ) = @( 2 ) ) + ( @( 30 ) = @( 3 ) ) LOCATE @( 29 ), @( 30 ), 0 : PRINT "*";
    108	NEXT
    109	NEXT
    110	BEEP @( 20 ), @( 15 ) : BEEP @( 24 ), @( 16 ) : BEEP @( 25 ), @( 15 ) : BEEP @( 26 ), @( 15 ) 
    111	BEEP @( 25 ), @( 16 ) : BEEP @( 24 ), @( 16 ) : BEEP @( 25 ), @( 16 ) : BEEP @( 20 ), @( 17 )
    200	GOSUB 500
    201	GOSUB 300
    202	@( 33 ) = TIMER( ) + @( 12 )
    203	@( 11 ) = @( 2 )
    204	@( 10 ) = @( 4 ) + RND( @( 0 ) - 2 ) + 1
    205	@( 9 ) = 1
    206	@( 31 ) = RND( 1 )
    207	IF @( 31 ) @( 8 ) = 1
    208	IF @( 31 ) = 0 @( 8 ) = -1
    209	GOSUB 400		
    210	GET @( 32 ), 0		
    211	IF @( 32 ) = 27 STOP
    212	IF ( @( 32 ) <> 241 ) * ( @( 32 ) <> 243 ) GOTO 217
    213	GOSUB 300
    214	IF @( 32 ) = 241 IF @( 6 ) > @( 4 ) + @( 14 ) + 1 @( 6 ) = @( 6 ) - 1
    215	IF @( 32 ) = 243 IF @( 6 ) < ( @( 0 ) - @( 14 ) ) - 1 @( 6 ) = @( 6 ) + 1
    216	GOSUB 400
    217	IF TIMER( ) < @( 33 ) GOTO 210
    218	@( 33 ) = TIMER( ) + @( 12 )	
    219	IF @( 11 ) <> @( 2 ) LOCATE @( 10 ), @( 11 ), 0 : PRINT " ";
    220	@( 10 ) = @( 10 ) + @( 8 )
    221	@( 11 ) = @( 11 ) + @( 9 )
    222	IF @( 10 ) <= @( 4 ) @( 8 ) = 1 : @( 10 ) = @( 10 ) + @( 8 ) : @( 11 ) = @( 11 ) - @( 9 ) : BEEP 523, @( 34 )
    223	IF @( 10 ) >= @( 5 ) @( 8 ) = -1 : @( 10 ) = @( 10 ) + @( 8 ) : @( 11 ) = @( 11 ) - @( 9 ) : BEEP 523, @( 34 )
    224	IF @( 11 ) < @( 3 ) - 1 GOTO 231
    225	@( 35 ) = ABS( @( 10 ) - @( 6 ) ) <= @( 14 )
    226	IF @( 35 ) <> 0 @( 9 ) = -1 : @( 11 ) = @( 11 ) + @( 9 ) : @( 10 ) = @( 10 ) - @( 8 ) : BEEP 440, @( 34 ) : BEEP 587, @( 15 ) : @( 28 ) = @( 28 ) + 1 : @( 27 ) = @( 27 ) + 1 : GOSUB 500 : GOTO 231
    227	BEEP 587, @( 34 ) : BEEP 466, @( 15 )
    228	@( 27 ) = @( 27 ) - 1
    229	IF @( 27 ) = 0 GOTO 235
    230	GOTO 200
    231	IF @( 11 ) <= @( 2 ) @( 9 ) = 1 : @( 11 ) = @( 11 ) + @( 9 ) : @( 10 ) = @( 10 ) - @( 8 ) : @( 12 ) = @( 12 ) - 1 : @( 33 ) = @( 33 ) - 1 : BEEP 523, @( 34 )
    232	LOCATE @( 10 ), @( 11 ), 0
    233	PRINT "0";
    234	GOTO 210
    235	GOSUB 500
    236	BEEP @( 18 ), @( 15 ) : BEEP @( 19 ), @( 15 ) : BEEP @( 20 ), @( 15 ) : BEEP @( 19 ), @( 15 )
    237	BEEP @( 20 ), @( 15 ) : BEEP @( 21 ), @( 15 ) : BEEP @( 22 ), @( 15 ) : BEEP @( 21 ), @( 15 )
    238	BEEP @( 23 ), @( 15 ) : BEEP @( 18 ), @( 15 ) : BEEP 220, @( 16 ) : BEEP @( 18 ), @( 16 ) 
    239	PRINT "Play Again? (Y/N) > ";
    240	GET @( 32 )
    241	IF ( @( 32 ) = 89 ) + ( @( 32 ) = 121 ) GOTO 100
    242	CLS
    243	STOP
    300	LOCATE @( 6 ) - @( 14 ), @( 1 ) - 1, 0
    301	FOR @( 29 ) = 0 TO @( 13 ) - 1
    302	PRINT " ";
    303	NEXT
    304	RETURN
    400	LOCATE @( 6 ) - @( 14 ), @( 1 ) - 1, 0
    401	FOR @( 29 ) = 0 TO @( 13 ) - 1
    402	PRINT "=";
    403	NEXT
    404	RETURN
    500	LOCATE 0, @( 1 ) + 1, 0
    501	PRINT "      Points: ", @( 28 ), "      Lives: ", @( 27 ), "      ";
    502	RETURN
    Also, just wanted to let you guys know that I've been so busy writing my new game, that I haven't had time to address your latest comments. I'll be back on track shortly.

    I went ahead and attached the latest experimental code in case anyone wants to try the game out.

    In case you don't already know minibasic, you just type:
    LOAD REIGN
    RUN

    If for some reason you can't compile minibasic, I've attached an executable.
    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;
    }

  7. #232
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Traditionally, a carriage return would only reset the cursor x position to the start of the line. I don't think this is how the original behaves, and I'm not to sure about the current state of IO or which branch to work from.

    I think the expected behavior is to set X to 0 and increment Y (scrolling the buffer, if necessary).
    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. #233
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Why should a carriage return scroll the buffer? Ignoring the view is one thing, but acting exactly the same as newline is madness. Madness!

    Anyway, I've pushed a "single file" implementation of `any' that I'm using as part of the system abstraction. (Specifically, I'm using it as part of the canvas implementation preferring it over the traditional "pimpl" idiom or `shared_ptr' approach.) Before I "cleanup" my other source will someone give it "cleaning" to match the appropriate style? (It would be a huge help.)

    Edit: Just before I pushed the set I noticed that I was only demangling the target. I duplicated the lines for the result because I was in a hurry. It needs to be separated, but that is something for later.

    Edit: I don't know what "far too much code in header files" means exactly, but I have a long standing habit of splitting various bits up so that much of the code and interface can be separated into distinct files easily enough. I wouldn't recommend it, but it shouldn't be difficult to pull out some of the source into ".cpp" files.

    Edit: Before the push I also fixed a couple of errors related to MSVC and Comeau. It is a little odd at the moment.

    Soma
    Last edited by phantomotap; 04-19-2009 at 02:26 PM.

  9. #234
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Why should a carriage return scroll the buffer? Ignoring the view is one thing, but acting exactly the same as newline is madness. Madness!

    Right, right - I was thinking LF. I'd say your interpretation looks correct.

    I'm not so sure we need this functionality, though. Filesystems tend to treat those characters differently; I would just as soon discard them altogether (from user input, that is; they would still be used internally).

    >> Before I "cleanup" my other source will someone give it "cleaning" to match the appropriate style?

    I was going to find a good open-source code-formatter, but got sidetracked. I guess it could be done by hand, but I probably won't get around to it until sometime tomorrow.

    >> Edit: Before the push I also fixed a couple of errors related to MSVC and Comeau. It is a little odd at the moment.

    Wierd. What errors were they?
    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. #235
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    "Wierd. What errors were they?"

    Relevant to my code... I haven't tried the other code in a while.

    Soma

  11. #236
    Registered User
    Join Date
    Jun 2004
    Posts
    76
    Looks good so far, but it needs to force a carriage return when the user pressing the ENTER key. I tried out Dark Forest 1 & 2, written in MINI-BASIC, and it had an annoying problem of never forcing a carriage RETURN when ENTER was pressed.

    You can download Dark Forest 1 & 2 from my page below:

    http://www.geocities.com/dunric/dforest.zip

    Play it a bit and see what I mean.

    Paul

  12. #237
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Looks good so far, but it needs to force a carriage return when the user pressing the ENTER key.

    Ah, right. There are still some other console I/O issues to deal as well (try running PITMAN and you'll see what I mean). Besides that, the code I posted is still experimental, but hopefully we'll have everything in order by the end of the week. I'll keep you posted.
    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;
    }

  13. #238
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sebastiani,

    How much changes do you have that isn't submitted? I'd like to refactor your .hpp files to be .cpp, but that will pretty much mean you have to hand-merge, as the new file will be a different name than the current file.

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

  14. #239
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by matsp
    I'd like to refactor your .hpp files to be .cpp, but that will pretty much mean you have to hand-merge, as the new file will be a different name than the current file.
    Maybe not. If Mercurial tracks renames correctly, the merge should work as per normal. You may need to use hg rename.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #240
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    Maybe not. If Mercurial tracks renames correctly, the merge should work as per normal. You may need to use hg rename.
    Yes, I suppose. I will give that a go - rename the .hpp file to .cpp, then edit out the bits back to a .h file (without the 'pp' part), and then any new changes will fold into the .cpp file after rename. Good thinking.

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