Author Topic: BxbAsm  (Read 178877 times)

jcfuller

  • Guest
Re: BxbAsm
« Reply #150 on: April 19, 2012, 02:55:37 PM »
Steve,
  Got side tracked and had a bit of a problem following setcolor. cls works fine and I think I got locate almost working.
 Time for dinner and then the Yankee game. I'll let you know more tomorrow.

James
 

SteveA

  • Guest
Re: BxbAsm
« Reply #151 on: April 19, 2012, 03:53:56 PM »
Hey James,
no problem. Just wanted to know if there were any issues I need to fix.
Have a nice evening, enjoy the game.

jcfuller

  • Guest
Re: BxbAsm
« Reply #152 on: April 20, 2012, 03:47:00 AM »
Steve,
  I'm a bit confised with locate.
In the example from BXBASIC.TXT:
Code: [Select]
1  REM  test.bas version 6
   DIM Row = 0, Column = 0
2  CLS
3  PRINT "hello world!"
4  LET Row = 2
5  LET Column = 10
6  LOCATE Row, Column
7  PRINT "hello world!"
8  LET Row = 4
9  LET Column = 20
10 LOCATE Row, Column
11 PRINT "hello world!"
12 END

you are calling with Row, Column but in your commented function in BxbLib.c you have

Code: [Select]
//void  locate(int cx, int cy)
//{
//    COORD coordScreen;
//    HANDLE hConsole;
//
//
//    coordScreen.X = cx;
//    coordScreen.Y = cy;
//                             /* Get this console handle */
//    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
//
//                             /* Put the cursor at its coordinates */
//    SetConsoleCursorPosition(hConsole, coordScreen);
//
//}

I may be mistaken but I believe coordScreen.X is Column and coordScreen.Y is Row??

Also you require Row and Column names specifically in the basic source???

James

jcfuller

  • Guest
Re: BxbAsm
« Reply #153 on: April 20, 2012, 04:07:16 AM »
Ok I think I see now. BxbAsm is translating to:
Code: [Select]
invoke locate, Column, Row

but it is confusing.

James

jcfuller

  • Guest
Re: BxbAsm
« Reply #154 on: April 20, 2012, 05:50:59 AM »
Steve,
  I have cls,locate,color working. I think it would be best for now to change settextcolor to a "c" proc instead of asm code.
Using invoke color,fg,bg
I put them all in one object file as I didn't figure it needed to be anymore granular than that.
I added the protos to bxb.inc for now
I'm going to try to do the same on the windows side.

Using this basic source:
Code: [Select]
CLS
DIM Row = 0, Column = 0
LET Row = 10
LET Column = 5
COLOR 4,7
LOCATE Column,Row
PRINT "Hello World"
END

I modified the asm listing by hand before compiling with jwasm

Code: [Select]
  ;mov  eax, 4
  ;mov  ebx, 7
  ;call setcolortext
  invoke color,4,7

This is the console.c compiled to an object and added to libbxbasm.a with ar and linked to the demo executable

Code: [Select]
#include <stdio.h>
#include <curses.h>
#include <termios.h>
//void cls(void);
void cls(void)
{
printf("%c%s%c%s",27,"[2J",27,"[H");
}
//==============================================================================
//void locate(int,int);
void  locate(int col, int row)
{
printf("%c%s%u%s%u%s",27,"[",row,";",col,"H");
}
//==============================================================================
//void color (int, int)
void color (int fg,int bg)
{
  printf("%c%s%u%s%u%s",27,"[",30+(fg&7),";",40+(bg&7),"m");
}
//==============================================================================
//int _getch_(int);
int _getch_(int waitkey)
{

    struct termios initial_settings, new_settings;
    unsigned char ch;

    tcgetattr(0,&initial_settings);
    new_settings = initial_settings;
    new_settings.c_lflag &= ~ICANON;
    new_settings.c_lflag &= ~ECHO;
    new_settings.c_lflag &= ~ISIG;
    new_settings.c_cc[VMIN] = waitkey;
    new_settings.c_cc[VTIME] = 0;
    tcsetattr(0, TCSANOW, &new_settings);
    ch = getchar();
    tcsetattr(0, TCSANOW, &initial_settings);
    return ch;

}

//void bxbPause(void)
void _getch(void)
{
    int ch;
    printf("Press any key to continue . . .\n");
ch = _getch_(1);
}
//==============================================================================


James

SteveA

  • Guest
Re: BxbAsm
« Reply #155 on: April 20, 2012, 05:57:11 AM »
  LOCATE Row, Column

Yes, this is not a mistake.
It's that way because QuickBasic does it that way.

SteveA

  • Guest
Re: BxbAsm
« Reply #156 on: April 20, 2012, 05:59:15 AM »
LOCATE Column,Row

This statement would be in error.

Yes, I double checked the QuickBasic 4.5 Docs and it's: LOCATE Row, Column
« Last Edit: April 20, 2012, 06:09:14 AM by SteveA »

SteveA

  • Guest
Re: BxbAsm
« Reply #157 on: April 20, 2012, 06:18:29 AM »
Quote
This is the console.c compiled to an object and added to libbxbasm.a with ar and linked to the demo executable

I'm not familiar with "ar". I don't know what it does. Must be a Linux thing.

edit:
Oh, I see, MingW has it too, archiver of some sort.

« Last Edit: April 20, 2012, 06:27:08 AM by SteveA »

jcfuller

  • Guest
Re: BxbAsm
« Reply #158 on: April 20, 2012, 06:51:37 AM »
Steve,
  Works on windows.

I use this for the libbxbasm.a library on windows.

Code: [Select]
#include <windows.h>
void cls(void)
{
system("cls");
}
//==============================================================================
void  locate(int cx, int cy)
{
    COORD coordScreen;
    HANDLE hConsole;


    coordScreen.X = cx;
    coordScreen.Y = cy;
                             /* Get this console handle */
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

                             /* Put the cursor at its coordinates */
    SetConsoleCursorPosition(hConsole, coordScreen);

}
//==============================================================================

void color (int fg,int bg)
{

 HANDLE hConsole;
 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleTextAttribute (hConsole,fg+bg*16);

}
//==============================================================================


James

jcfuller

  • Guest
Re: BxbAsm
« Reply #159 on: April 20, 2012, 06:53:31 AM »
Steve,
  Doesn't LccWin32 have a library maker? It should work the same. I'm just more familiar with ar.

James

SteveA

  • Guest
Re: BxbAsm
« Reply #160 on: April 20, 2012, 07:44:31 AM »
 Doesn't LccWin32 have a library maker? It should work the same. I'm just more familiar with ar.

You can create ".Lib" files, (like bxblib.lib), but, I don't know of a "library maker".

LccWin32 is not a console mode application.
It is based on an IDE called "Wedit".
I've not seen a Wedit function for adding functions to .Lib files.
You just add new C source and recompile your .Lib.

When you mentioned "granularity", I kind of went  ???
I just don't know how I would do that.
« Last Edit: April 20, 2012, 07:47:32 AM by SteveA »

jcfuller

  • Guest
Re: BxbAsm
« Reply #161 on: April 20, 2012, 08:16:54 AM »
Steve,
  Check out the LccWin32 lcclib Utility.

James


jcfuller

  • Guest
Re: BxbAsm
« Reply #162 on: April 20, 2012, 08:24:41 AM »
Steve,
  What I mean by granualrity:
Several years ago I was active with FreeBASIC and wrote a library of routines and created a library with them which I linked to apps that I wrote. I was under the false knowledge that the linker was smart enough to only link the functions used. This is not the case.
I went back and put each function in it's own source file, compiled each one to an object file and then used ar to put all the object files in a library. Now when I linked the library only the functions I used were added to the exe.

LIB.exe is the MS equivalent to ar.

James

SteveA

  • Guest
Re: BxbAsm
« Reply #163 on: April 20, 2012, 09:45:05 AM »
  Check out the LccWin32 lcclib Utility.

Right.
That's what you use (thru Wedit) to create .Libs.

SteveA

  • Guest
Re: BxbAsm
« Reply #164 on: April 20, 2012, 09:52:16 AM »
What I mean by granualrity:
I was under the false knowledge that the linker was smart enough to only link the functions used.
This is not the case.

Right,
that's why I designed Bxbasm--Afunc.c the way I did:

Code: [Select]
void Do_functions()
{
    if(stringcopy == 1)
    {
        copystrng_bffr();
    }

    if(asnchrstr == 1)
    {
        func_chrstr();
    }

    if(asnleftstr == 1)
    {
        func_leftstr();
    }
(snip)


Code: [Select]
void func_rightstr()
{
    writeln("; --------------------------------------------------");
    writeln("rightstr proc ");
    writeln("; --------------------------------------------------");
    writeln("  mov  edi, offset BffrInput");
    writeln("  invoke szRight, esi, edi, eax");
    writeln("  mov  [edi+eax], byte ptr 0");
    writeln("  mov  esi, offset BffrInput");
    writeln("  ret");
    writeln("; --------------------------------------------------");
    writeln("rightstr endp");
    writeln("; =========================================================================");
}
/*---------- end func_rightstr ----------*/


void func_leftstr()
{
    writeln("; --------------------------------------------------");
    writeln("leftstr proc ");
    writeln("; --------------------------------------------------");
    writeln("  mov  edi, offset BffrInput");
    writeln("  invoke szLeft, esi, edi, eax");
    writeln("  mov  [edi+eax], byte ptr 0");
    writeln("  mov  esi, offset BffrInput");
    writeln("  ret");
    writeln("; --------------------------------------------------");
    writeln("leftstr endp");
    writeln("; =========================================================================");
}
/*---------- end func_leftstr ----------*/


void func_chrstr()
{
    writeln("; --------------------------------------------------");
    writeln("chrstr proc ");
    writeln("; --------------------------------------------------");
    writeln("  mov  esi, offset BffrInput");
    writeln("  mov  [esi], byte ptr al");
    writeln("  mov  [esi+1], byte ptr 0");
    writeln("  ret");
    writeln("; --------------------------------------------------");
    writeln("chrstr endp");
    writeln("; =========================================================================");
}
/*---------- end func_chrstr ----------*/


Sort of "conditional assembly", without all the clutter.
« Last Edit: April 20, 2012, 09:54:07 AM by SteveA »