Author Topic: BxbAsm  (Read 178880 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BxbAsm
« Reply #210 on: May 02, 2012, 11:58:26 PM »
Here is the ScriptBasic filesys.c that supports Windows, Linux and Mac OS.

I would think this is as extensive as it gets with conditional compiling directives in SB.


jcfuller

  • Guest
Re: BxbAsm
« Reply #211 on: May 03, 2012, 02:56:31 AM »

Some of those (snuck back in and) were not intended for the Linux port and should be deleted and removed from bxblib.lib.
Some of those would be: clearscreen, locate, color, StdOut, StrLen, gdi_oldbrush, wherexy, etc.
In other words, any win32 related .obj's, just delete from bxblib.lib.
Sorry about that.
In their stead, the original or Linux specific code can be used.


Steve,
  That is exactly the opposite of what I suggested I think.
I believe my suggestion was to put all Win32 related code in a library wrapped with generic procs called from the main asm source... I would try to duplicate functionality in a library for linux. Where it was impossible (or not known how to implement) there could be dummy procs during the development cycle. So you would have for example Win32 cls,locate,color in the library and I would have the linux versions I demonstrated.

Also your bxb.inc would be OS specific.
James
 

« Last Edit: May 03, 2012, 03:09:58 AM by jcfuller »

jcfuller

  • Guest
Re: BxbAsm
« Reply #212 on: May 03, 2012, 03:46:29 AM »
Steve,
  On reflection I did advocate a library instead of source ( bad memory -> mine) so I guess you would need two.
One for the generic functions (the one you just created) and one for os specific functions.

James

jcfuller

  • Guest
Re: BxbAsm
« Reply #213 on: May 03, 2012, 05:39:20 AM »
Steve,
 I was able to compile most of the BxbLib modules and add them to a library. A number were win only.
ltoa is win only but I found "c" code for it,compiled to object file and added it to the library so that is covered.
I also did timestr and datestr even though all the time date code is windows only I believe I have code somewhere that can be placed in an OS specific library.
 Not sure any of these work yet :) but it is one step closer.

James
 
modules compiled on linux
Code: [Select]
atodw.o
catstrng.o
chrstr.o
clear_allvars.o
clearfltvar.o
clearintvar.o
clearLngstrng_bffr.o
clearstrng_bffr.o
clearstrvar.o
closeafile.o
closeallfiles.o
copystrng_bffr.o
copystrng.o
datestr.o
dblArryElement.o
dimstrarray.o
Do_initialize.o
dwtoa.o
freeArray.o
getArryOffst.o
getfilehandle.o
getfilelength.o
leftstr.o
lsetstr.o
ltoa.o
mid_str.o
mkdstr.o
mkistr.o
mkqstr.o
movstrng_bffr.o
quadArryElement.o
readfltstr.o
readintstr.o
readQintstr.o
redimarray.o
rightstr.o
rsetstr.o
setupiobuffer.o
spacestr.o
stringstr.o
strsFval.o
strsIval.o
szLeft.o
szMid.o
szRight.o
timestr.o

« Last Edit: May 03, 2012, 05:41:09 AM by jcfuller »

jcfuller

  • Guest
Re: BxbAsm
« Reply #214 on: May 03, 2012, 06:12:16 AM »
Steve,
  How about using crt time date functions instead of Windows?
Here is a bcx -> c demo.
James

Code: [Select]
// *********************************************************************
// Created with BCX32 - BASIC To C/C++ Translator (V) 9.0.0.7 (2012/03/23)
//                 BCX (c) 1999 - 2012 by Kevin Diggins
// *********************************************************************
//          Translated for compiling with an ANSI/ISO C Compiler
// *********************************************************************

// ***************************************************
// types from winapi that may be needed
// ***************************************************
typedef char *PCHAR,*LPCH,*PCH,*NPSTR,*LPSTR,*PSTR;
typedef unsigned int UINT;
typedef char byte;
typedef unsigned long DWORD,ULONG;
typedef unsigned char UCHAR;
//----------------------------------------------------

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************


// *************************************************
//               Standard Prototypes
// *************************************************

// char*   BCX_TmpStr(size_t,size_t= 128,int= 1);
char*    BCX_TmpStr(size_t,size_t,int);
// char*   timef(int=0, int=0);
char*    timef(int,int);
// *************************************************
//          User Defined Types And Unions
// *************************************************


// *************************************************
//                System Variables
// *************************************************


// *************************************************
//            User Global Variables
// *************************************************

static PCHAR   *g_argv;
static int     g_argc;


// *************************************************
//            User Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************

#ifndef BCXTmpStrSize
#define BCXTmpStrSize  2048
#endif
char *BCX_TmpStr (size_t Bites,size_t  iPad,int iAlloc)
{
  static int   StrCnt;
  static char *StrFunc[BCXTmpStrSize];
  StrCnt=(StrCnt + 1) & (BCXTmpStrSize-1);
  if(StrFunc[StrCnt]) {free (StrFunc[StrCnt]); StrFunc[StrCnt] = NULL;}
#if defined BCX_MAX_VAR_SIZE
  if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)
  {
  printf("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);
  abort();
  }
#endif
  if(iAlloc) StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
  return StrFunc[StrCnt];
}


char *timef (int t, int u)
{
  time_t elapse_time;
  struct tm *tp;
  char *strtmp = BCX_TmpStr(256,128,1);
  time (&elapse_time);
  if(u==0)
    tp = localtime(&elapse_time);
  else
    tp = gmtime(&elapse_time);
  switch (t)
  {
   case 0:
   strftime(strtmp,256,"%H:%M:%S",tp); break;
   case 1:
   strftime(strtmp,256,"%H",tp); break;
   case 2:
   strftime(strtmp,256,"%M",tp); break;
   case 3:
   strftime(strtmp,256,"%S",tp); break;
   case 4:
   strftime(strtmp,256,"%p",tp); break;
   case 5:
   strftime(strtmp,256,"%Y",tp); break;
   case 6:
   strftime(strtmp,256,"%m",tp); break;
   case 7:
   strftime(strtmp,256,"%d",tp); break;
   case 8:
   strftime(strtmp,256,"%A",tp); break;
   case 9:
   strftime(strtmp,256,"%w",tp); break;
   case 10:
   strftime(strtmp,256,"%j",tp); break;
   case 11:
   strftime(strtmp,256,"%U",tp); break;
  }
  return strtmp;
}



// ************************************
//       User Subs and Functions
// ************************************

// *************************************************
//                  Main Program
// *************************************************

int main(int argc, char *argv[])
{
  g_argc = argc;
  g_argv = argv;
printf("%s%s\n","Printing TIME$   ",timef( 0 , 0));
printf("%s\n","-----------------");
printf("%s%s\n","Printing HOUR    ",timef( 1 , 0));
printf("%s%s\n","Printing MINUTE  ",timef( 2 , 0));
printf("%s%s\n","Printing SECOND  ",timef( 3 , 0));
printf("%s%s\n","Printing AMPM    ",timef( 4 , 0));
printf("%s\n","-----------------");
printf("%s%s\n","Printing YEAR    ",timef( 5 , 0));
printf("%s%s\n","Printing MONTH   ",timef( 6 , 0));
printf("%s%s\n","Printing DAY     ",timef( 7 , 0));
printf("%s\n","-----------------");
printf("%s%s\n","Printing DAYNAME ",timef( 8 , 0));
printf("%s%s\n","Printing WEEKDAY ",timef( 9 , 0));
printf("%s%s\n","Printing YEARDAY ",timef( 10 , 0));
printf("%s%s\n","Printing WEEK    ",timef( 11 , 0));
  return 0;   /* End of main program */
}


jcfuller

  • Guest
Re: BxbAsm
« Reply #215 on: May 03, 2012, 06:34:14 AM »
Steve,
  I am probably jumping the gun here but is file i/o operational?
I get a fault on both Windows and linux with:
Code: [Select]
'  test.bas version 37
'  CLS
'
  PRINT "Opening Test File"
  OPEN "I", #1, "test.txt"
  CLOSE 1
' ------------------------------------------
TheEnd:
  END


James

SteveA

  • Guest
Re: BxbAsm
« Reply #216 on: May 03, 2012, 09:29:33 AM »
 I am probably jumping the gun here but is file i/o operational?
I get a fault on both Windows and linux with:

Yes,
did you create test.txt ahead of time ?
As it needs to exist to open it for INPUT.

Quote
Before we can run this next program, you will need to create a file named
Test.txt. Using Notepad, create an empty file,  just hit the return key
about three or four times, then save the file to your working directory,
naming it "Test.txt", and close it.

edit:
I just tested that exact code and it works just fine.
Create test.txt.
« Last Edit: May 03, 2012, 09:33:58 AM by SteveA »

SteveA

  • Guest
Re: BxbAsm
« Reply #217 on: May 03, 2012, 09:53:43 AM »
 How about using crt time date functions instead of Windows?

Sure.
Give me a bit to switch that over.
I'll upload the .asm files when done.


edit:
crt modified data/time .asm files attached.

I hope this works right.
Looking at the difference between the CRT -vs- Win32 struct's.

I wasn't sure it would work without making several other changes.
But, it appears to be working...or not.


edit:
oops...false positive.
« Last Edit: May 03, 2012, 06:53:53 PM by SteveA »

jcfuller

  • Guest
Re: BxbAsm
« Reply #218 on: May 03, 2012, 11:24:33 AM »
Steve,
  Not working as you are still using the Windows call.
There is no SYSTEMTIME structure in time.h.
comment out the windows include. Should not be needed

James
 

SteveA

  • Guest
Re: BxbAsm
« Reply #219 on: May 03, 2012, 12:20:29 PM »
Not working as you are still using the Windows call.
There is no SYSTEMTIME structure in time.h.

As I feared, I will need to make several other changes.
This may take a while, it's not going to be as easy as commenting something out.
I need to change the structure setup.

jcfuller

  • Guest
Re: BxbAsm
« Reply #220 on: May 03, 2012, 12:26:53 PM »
Steve,
  I don't know if this works but it compiled ok. I just followed what bcx did.

James


get_sys_date
Code: [Select]
; *************BxbAsm Compiler*************
; Copyright: sarbayo (c) 2004-2012
; =========================================================================
  .486                       ; use 486 instructions
  .model flat, stdcall       ; Win32 memory model
  option casemap:none        ; case sensitive

    ;include C:\JWasm\JWasm206\Include\windows.inc
    ;include C:\JWasm\JWasm206\Include\time.inc
    include BxbLib.inc
  
    EXTERNDEF system_time:tm
    EXTERNDEF iYear:DWORD
    EXTERNDEF iMonth:DWORD
    EXTERNDEF iDay:DWORD

  .code

get_sys_date  proc
  ; --------------------------------------------------
;  invoke  GetLocalTime, addr system_time    ;Win32: Get Local Time
;  invoke  localtime, addr system_time    ; Get Local Time
local elapsed_time:DWORD
invoke time,addr elapsed_time
invoke localtime,addr elapsed_time
mov system_time,eax
xor  eax, eax
mov  eax, system_time.tm_year
mov  iYear, eax
mov  eax, system_time.tm_mon
mov  iMonth, eax
mov  eax, system_time.tm_wday
mov  iDay, eax
ret
; --------------------------------------------------
get_sys_date  endp

end


get_sys_time
Code: [Select]
; *************BxbAsm Compiler*************
; Copyright: sarbayo (c) 2004-2012
; =========================================================================
  .486                       ; use 486 instructions
  .model flat, stdcall       ; Win32 memory model
  option casemap:none        ; case sensitive

    ;include C:\JWasm\JWasm206\Include\windows.inc
    ;include C:\JWasm\JWasm206\Include\time.inc
  include BxbLib.inc
    ;EXTERNDEF system_time:SYSTEMTIME
    EXTERNDEF system_time:tm
    EXTERNDEF iHour:DWORD
    EXTERNDEF iMinute:DWORD
    EXTERNDEF iSecond:DWORD
    EXTERNDEF iMilli:DWORD

  .code

get_sys_time  proc
; --------------------------------------------------
;  invoke  GetLocalTime, addr system_time       ; Win32: Get Local Time
  ;invoke  localtime, addr system_time       ; Get Local Time
local elapsed_time:DWORD
invoke time,addr elapsed_time
invoke localtime,addr elapsed_time
mov system_time,eax
  
xor  eax, eax
mov  eax, system_time.tm_hour
mov  iHour, eax
mov  eax, system_time.tm_min
mov  iMinute, eax
mov  eax, system_time.tm_sec
mov  iSecond, eax
;  mov  eax, system_time.wMilliseconds
;  mov  iMilli, eax
ret
; --------------------------------------------------
get_sys_time  endp

end

« Last Edit: May 03, 2012, 12:28:33 PM by jcfuller »

SteveA

  • Guest
Re: BxbAsm
« Reply #221 on: May 03, 2012, 06:50:13 PM »
Okay,...
I have to say, using the crt time functions is a real pain.
Not at all easy, like the API.

Now, program files that need to be un-commented:
  prototyp.h
  input.c
  ainput.c
  astring.c
  globals.h

so that the date and time functions work properly and compile without error.

jcfuller

  • Guest
Re: BxbAsm
« Reply #222 on: May 04, 2012, 07:23:51 AM »
Steve,
  Will you be putting together a new package soon?
 I thought I might be able to make the changes but really have no idea what's needed especially in AInput.c

James


SteveA

  • Guest
Re: BxbAsm
« Reply #223 on: May 04, 2012, 08:46:08 AM »
Well, I thought about it just yesterday, but, decided not to, because I don't know what you have and what changes/corrections you have made.
That's why I simply uploaded the specific files in question.

I don't want to be counter-productive to the work you are doing.
When I upload a complete package, I cringe at the thought that what I have may conflict with what you have.
I don't want changes I've made to wipe-out changes you've made.

On my system, I have two (2) distinct versions of Bxbasm in production.
One for Win32 and one that I share with you for Linux development.

The one I share with you, I consider to be the "stripped down version", is free of win32 references.
To create that version, in most cases, I simply commented-out certain functions and variables that specifically used win32 API.
As in the case of the TIME$ and DATE$ functions, that list of files that I mentioned was where there were references to the date and time functions and variables.

The only way to prevent collisions would be if I know what modifications you have made.
I can send you what I have, but, then you would need to compare code and figure out what changes exist, so as to prevent those collisions.

jcfuller

  • Guest
Re: BxbAsm
« Reply #224 on: May 04, 2012, 09:18:30 AM »
Steve,
  As bad as my memory is I prefer the complete stripped down version that is working on windows (without any Win32 api calls).
There really isn't all that much to change; mainly include directories. I plan to automate the library creation.
I use diff-merge on windows and linux.

James