[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 7.286::atarist

Title:Atari ST, TT, & Falcon
Notice:Please read note 1.0 and its replies before posting!
Moderator:FUNYET::ANDERSON
Created:Mon Apr 04 1988
Last Modified:Tue May 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1433
Total number of notes:10312

998.0. "C help again" by PIKES::BITTROLFF () Fri Nov 02 1990 14:23

Greetings,

I am fairly new to the world of C, and am having a problem with data storage.
I am using MWC (V3.09 I believe), and want to write an entire structure to disk
at once. My structure is moderately complex, containing another structure, and 
looks something like this:

STRUCT 1: contains 6 integers

STRUCT 2:
	6 pointers to char
	an array 0 to 16 of STRUCT 1
	STRUCT 1

I open the file for write using fopen (I have tried both "w" and "wb")
This seems to work OK as the correct filename shows up on my disk.

I then attempt to use fwrite to write the entire structure, using sizeof to pass
the number of bytes. It gets to this point and the program aborts with 2 or 3
bombs. I believe that the format of call to fwrite is correct, but the
documentation seems to contain an error in that the entry in the manual has one
way but the example reverses two of the parameters. I have tried it both ways,
same results. Unfortunately I don't have the code with me (I forgot my listing
this morning) but will post it if it would be helpful. Mainly I am wondering if
I am even on the right track using fwrite, or should I use Fopen and Fwrite?

On a side note, has anyone out there hooked up a scholar type modem to an Atari?
Did it take any special cableing?

Thanks in advance for any help,

Steve
T.RTitleUserPersonal
Name
DateLines
998.1Hope this example helpsYNOTME::WALLACEFri Nov 02 1990 16:0936
#include <stdio.h>

typedef struct item {
  char  name[10];
  int   type;
  char	*dir;		/* NOTE that the address of the allocated memory is
			 * what will get written to the file, not the string
			 * (directory name) which gets stored in that memory.
			 */
} ITEM;

main( )
{
  ITEM	item;
  FILE	*dest;

  strcpy( item.name, "Atari" );
  if( (item.dir = malloc(20)) == NULL ) {
    printf( "Out of memory\n" );
    exit(0);
  }
  strcpy( item.dir, "c:\\tools" );
  item.type = 16;

  if( (dest = fopen("items.dat", "wb")) != NULL ) {
    if( fwrite(&item, sizeof(item), 1, dest) != 1 ) {
	printf( "Item not written\n" );
    }
		/* -- or -- */
    if( fwrite(&item, 1, sizeof(item), dest) != sizeof(item) ) {
	printf( "Not all bytes were written\n" );
    }
  }
  else	printf( "Could not open file.\n" );
}
998.2Thanks!PIKES::BITTROLFFSat Nov 03 1990 00:3318
    re: .1
    
    Thanks! That got me going and I got it to work. Basically I had
    forgotton that @)(#(*#@$&# ampersand(&) in front of the structure name.
    Your example also pointed out to me how the middle two parameters are
    interchangeable, ie. it doesn't matter if you send 1 record of 50 bytes
    or 50 records of 1 byte to a stream file. I somehow missed this when I
    was looking at it.
    
    Regarding the Scholar, I just hooked it up, put the terminal in VT52
    mode, set the baud rate to 1200 (is the Atari just not capable of 2400
    as it isn't an option on the set up menu) and away it went. Now I will
    look through the other notes looking for some sort of terminal
    emulation above a VT52 and a download capability (Whack and Kermit?)
    
    Again, thanks for your help!
    
    Steve
998.3The ST supports up to 19,200BAGELS::FELDMANJerry Feldman DTN 227-3279Mon Nov 05 1990 09:287
    The Atari is certainly capable of baud rates up to 19,200. Many of us
    routinely use 2400BPS modems, and our BCS BBS runs 2 lines, 9600 HST on
    1, and 2400 on the other.
    
    I suggest using a more sophisticated terminal emulator such as Flash,
    Uniterm, Aladdin, etc. Most of these provide VT100 emulation, and
    support all the baud rates supported by the ST hardware.
998.4MWC and GEMPIKES::BITTROLFFWed Dec 12 1990 10:4630
I now have a couple of questions about form handling.

I am displaying a form with editable and non editable text fields that I created
using the MWC resource constructor. For the most part it works fine, but there
are a few minor problems that I can't seem to fix.

First, when I activate the form (form_do, or do_form, or whatever :^)) it comes
up just fine, and the cursor is at the field I specified, but it is at the end
of the field rather than the front. ESCAPE takes it to the front of the field as
it is supposed to, but I would prefer to have it there at the start. There is
no default value specified for that field.

Second, there are several fields that I fill in using data the user entered in
the other fields. The problem here is that the text merges with whatever is
there, rather than overwriting it. I have played with the opaque and transparent
flags in the resource editor, but to no avail. As a side note, if I do an 
objc_draw and redraw the whole tree it is OK, but the form flashes annoyingly.
If I just redraw the one object I get the problem I just described, and if I use
objc_change with the redraw option set nothing happens.

Finally, I seem to have problems with editable right justified fields. My non
editable right justified fields work just fine, but I get all sorts of strange
behaviors when I attempt to enter data into a field defined as right justified.
For instance, only two of the four characters will be displayed (on the right
edge) but the whole string will be there when I retrieve it.

Any help here would be greatly appreciated. I have workarounds for them all, but
I would much prefer to have them work as they are supposed to!

Steve
998.5Might not be Gem's problemPRNSYS::LOMICKAJJeffrey A. LomickaWed Dec 12 1990 12:591
Are you using an early version of Quick ST?
998.6QUICK ST?PIKES::BITTROLFFWed Dec 12 1990 14:395
I don't think so, although I don't know what QUICK ST is :^)

It's a pretty vanilla system, I don't have any desk accessories running at all.

Steve
998.7Some hopefully useful answersPRNSYS::LOMICKAJJeffrey A. LomickaWed Dec 12 1990 15:3844
>First, when I activate the form (form_do, or do_form, or whatever :^)) it comes
>up just fine, and the cursor is at the field I specified, but it is at the end
>of the field rather than the front. ESCAPE takes it to the front of the field as
>it is supposed to, but I would prefer to have it there at the start. There is
>no default value specified for that field.

You have to initialize the initial value of the te_ptext element of
each editable text string - usually to the null string (Such as :
foo->te_ptext[ 0] = 0;, or strcpy( foo->te_ptext, "42");)

>Second, there are several fields that I fill in using data the user entered in
>the other fields. The problem here is that the text merges with whatever is
>there, rather than overwriting it. I have played with the opaque and transparent
>flags in the resource editor, but to no avail. As a side note, if I do an 
>objc_draw and redraw the whole tree it is OK, but the form flashes annoyingly.
>If I just redraw the one object I get the problem I just described, and if I use
>objc_change with the redraw option set nothing happens.

This doesn't happen to me.  I update single objects by:

	1. Set ob_x and ob_y of the root object to 0.
	2. Call objc_find on the object index, to obtain the object's
		relative location.
	3. Add in the window origin to produce clipping origin x, y
	4. Get ob_width and ob_height for clipping width and height.
	5. Reset ob_x and ob_y
	6. objc_draw( object, clipping)

Of course, 1, 3, and 5 are not needed, but I do them because of the way
my code is structured.  I suspect you are using the ob_x and ob_y values
directly in the clipping parameter to objc_draw, rather than calling
objc_find to get the real ones.  These values are relative to the parent
rectangle, not to the tree origin.

>Finally, I seem to have problems with editable right justified fields. My non
>editable right justified fields work just fine, but I get all sorts of strange
>behaviors when I attempt to enter data into a field defined as right justified.
>For instance, only two of the four characters will be displayed (on the right
>edge) but the whole string will be there when I retrieve it.

This works for me too.  It may be related to the same problem as the
previous objc_draw problem.  Perhaps if youget passed the first two
problems, I can take a closer look at this one.

998.8Or perhaps...PRNSYS::LOMICKAJJeffrey A. LomickaWed Dec 12 1990 15:5018
>Second, there are several fields that I fill in using data the user entered in
>the other fields. The problem here is that the text merges with whatever is
>there, rather than overwriting it. I have played with the opaque and transparent

I just realised what you are trying to say here.  I think you may be
drawing with VDI using the wrong VDI identifier.  When you do the
graf_handle(), teh ID you get back is NOT the ID you should use to do
VDI calls.  I start my programs with:

	gid = graf_handle( &w, &h, &j, &k);
	wkid = gid;
	v_opnvwk( worki, &wkid, worko);

and I do ALL of my VDI calls with "wkid", NOT "gid".  If you, for
example, change vswr_mode() on "gid" instead of "wkid", it will mess up
any drawing that the AES does.


998.9I'll check it outPIKES::BITTROLFFThu Dec 13 1990 13:2929
Jeffrey, (or do you prefer Jeff?)

I didn't have a chance to work with it last night, hopefully I can tonight.

Are you using the resource editor provided by MWC when you create these forms?

I have tried the fields both initialized and not, but I don't remember it what
combinations. I'll go back and start again in a more systematic manner. I
believe that they are initialized for me when I get the resource.

I'm not using the objc_find call, I will give it a shot. When I do the redraw
the clipping I send is the same that I used when I created the form via 
form_dial. My thought was that this encompasses the whole form, and as long as
the output is within that form I should be OK. Is this valid? In any case, it
does update the field, it just does it in overwrite so that I get one number 
'superimposed' on another rather than just the second number.

For your second note, I think we missed something. I am not using any of the VDI 
calls directly, just the AES calls. I do use the VDI for setup, but only the 
minimum. I will check my code on that also and see if I am doing something along
the lines of what you described that may be messing me up.

Thanks for the response, I'll see if I can use it to get going. If not I will 
probably post a short code segment for your perusal to see if I am obviously
missing anything.

Steve

(It may be frustrating at times but it sure is fun to play with!)
998.10Two steps forward, one step back...PIKES::BITTROLFFFri Dec 14 1990 16:0523
Well,

I fixed one of my problems, kluged another and uncovered a third.

First, on the overwrite of the line of data rather than the replace. When I
checked the resource file again I found that the line was still set to
transparent rather than opaque. Flipping the bit did the trick. It also allowed
me to go back to using objc_draw for the one object rather than for the whole
form.

The right justified field problems I fixed by going back to left justified. I 
may play more with this one later.

As I looked over your note, I checked the call for objc_find. According to the
MWC documentation, this call is used for determining if the mouse is over the 
object rather than the raster location of the object. Am I missing something?

And finally, now what happens is that when I press either of the two buttons 
that allow me to exit the form everything hangs and I have to reset the machine
to continue. (Sigh). I love C error handling. The primary error message seems to
be a number of bombs followed by a crashing of the machine.

Steve
998.11Are we having fun yet?PIKES::BITTROLFFThu Jan 03 1991 16:0218
I've tracked down the hang, sort of. For some reason, after leaving the dialog
box, the wait for event call seems to be disabled. I enter that call, but
nothing I do ever triggers it and I loop forever...

On a different tack, I got a 40MB hard disk for Christmas and have been having a
ball. A couple of questions...

- When developing software is there some way to read from the current directory,
  rather than hard coding the entire path including the disk?

- I can't seem to move MOST of my games to play off of the hard disk. Many of 
  these are because they use an auto folder, some require access to their files
  in drive a: (hard coded apparently :^)) and some just don't function. I even
  found one that will not start up if the hard drive is even plugged in! Any tips
  on moving this type of software to the hard disk?


Steve
998.12One part is easyPRNSYS::LOMICKAJJeffrey A. LomickaFri Jan 04 1991 14:259
>- When developing software is there some way to read from the current directory,
>  rather than hard coding the entire path including the disk?

Think of it as unix:  If the default path is C:\stuff [Dsetdrv(3);Dsetpath( "stuff")]

	foo.bar will be c:\stuff\foo.bar
	bax\foo.bar will be c:\stuff\bax\foo.bar
and	\grp\bltq.tnk will be c:\grp\bltq.tnk

998.13Objects...PIKES::BITTROLFFTue Feb 05 1991 17:1315
This should be easy to find, but as yet I haven't found it. 

What is the easiest (or the proper) way to put bitmapped type objects onto the
screen? The symbols (army, airplane, ships, cities, etc.) used in the EMPIRE game
are a good example. 

In the 8 bit world these would be player-missles. I have heard them referred to
as 'sprites' for the 16 bit machines, but I am not sure how to go about 
implementing them. All I really need is a pointer to a starting place, either
an article or a call to some sort of system service, and I can take it from
there.

Thanks in advance for the help,

Steve
998.14a starting pointMIDIOT::POWERSI Dream of Wires - G. NumanWed Feb 06 1991 07:298
  RE: .13

      I think the way to do it is with the line-a function bitblt.  I don't
  know the parameters.  Perhaps if you looked in a book that covers the
  VDI, they might also cover the line-a functions.

  Bill Powers
998.15Sounds rightPIKES::BITTROLFFWed Feb 06 1991 10:116
Yeah, bitblt seems to ring a bell. I'll check it out when I get back from my
trip (about 2 weeks) and let you know.

Thanks!

Steve
998.16PRNSYS::LOMICKAJJeffrey A. LomickaFri Feb 08 1991 10:532
The easiest way is to put them into an object tree as icons, but that
assumes you know womething aobut GEM object trees.
998.17Object treesSALIDA::BITTROLFFMon Feb 18 1991 15:4510
Yep, I know about 'em.

Actually, that is what I tried first but I haven't yet succeeded in pulling an
object onto the screen, where I want it. 

I'll keep plugging away, I was just wondering if I'd missed something...

Thanks,

	Steve
998.18Integer->ASCII string-> Pointer ?SALIDA::BITTROLFFWed Mar 13 1991 15:3237
    Hey, this is turning into my own personal help note!
    
    This seems like it should be easy, but I can't make it work.
    
    I have a procedure that accepts a pointer to a string, ie:
    
    void proca(string)
    char *string;
    
    The calling line is simply:
    
    proca(str_ptr);
    
    where
    
    char *str_ptr;
    
    So far, so good. My problem is that I would like to take an integer
    value and pass it to this routine, after converting to a string. For
    example:
    
    int a;
    char a_str[4];
    
    a = 4;
    sprintf(a_str,"%d",a);
    proca(&a_str);
    
    When I run this code I get a 'requires lvalue' error from the compiler.
    I have tried type casting, defining a pointer and copying the string
    address into it, and can't get it to work. I always get either an
    lvalue error or end up sending the actual address instead of the
    string. What am I missing here?
    
    Thanks in advance, 
    
    Steve
998.19There must be something more to this.PRNSYS::LOMICKAJJeffrey A. LomickaWed Mar 13 1991 16:0019
For the information you've given, the following should workfine:
    
    void proca(string)
    char *string;
        {
	}

main()
    {    
    int a;
    char a_str[4];
    
    a = 4;
    sprintf(a_str,"%d",a);
    proca( a_str);
    }

Note there is no "&" on the call to proca, since array names in C, when
used without the []'s, are already pointers.
998.20I tried that once, I'll check it again...SALIDA::BITTROLFFWed Mar 13 1991 17:0814
    That was my first cut at it. What I believe happened is that the the
    value passed was the actual first byte of string data. I know the
    routine blew up when I ran it. (Actually it blew up further down in the
    routine when I used the value resulting from proca). At the time I
    assumed that it was because what proca received the address of the
    first byte of the string (isn't that what a_str really is?), used it as
    a pointer and bombed. Since then, however, I did find that another
    piece of code in the same area was also bad. I haven't tried to run it
    the way you described since eliminating that error, so I'll try again.
    
    Thanks for the quick response, I hope I'm not being to much of pain.
    :^)
    
    Steve
998.21strange pr�BRUMMY::LOXTONFri Nov 01 1991 05:1426
    
    I need an array off two pointers in a p�ogram I am writing.so I defined
    a pointer array like this.
    
    	short *name[2];
    
    	and
    	short array1[1000];
    	short array2[1000];	
    
    	Then within the program I set 
    
    	name[0]=array1;
    	name[1]=array2;
    When I insert this into my program in global space,the program doesn't
    work properly anymore,even if I don't use this data.
                 
    for instance printf stops working.(ie program runs but nothing prints
    on the screen.)
    
    	Can anyone see whats wrong.
    
    (I'm using Lattice C V5)
    
    		Thanks 
    			Brian
998.22It works fine on VAX/VMSYNOTME::WALLACEFri Nov 01 1991 10:225
The code looks fine to me. If you were defining the arrays local to some
function then you might be seeing a problem with running out of stack space.
But since you say they are global I don't see any problem.

	Ray
998.23Perhaps this is the problem?PRNSYS::LOMICKAJJeffrey A. LomickaSat Nov 02 1991 15:0829
I wonder if his C compiler is letting him get away with this outside the
context of any routine, I.E, if he meant the assignment statements to be
an initializer.  The following two forms should work:

	char a1[ 1000];
	char a2[ 1000];
	char *table[2] = {a1, a2};

Or

	char a1[ 1000];
	char a2[ 1000];
	char *table[2];
	main()
	    {
	    table[0] = a1;
	    table[1] = a2;
	    }

The form

	char a1[ 1000];
	char a2[ 1000];
	char *table[2];
	table[0] = a1;
	table[1] = a2;

outside a routine, this is a syntax error.

998.24m�BRUMMY::LOXTONMon Nov 04 1991 05:1118
    Thanks for the help,but I found the problem.
    
    In global space I had defined short sprite[64] directly before the
    definition for the pointer table,and was using this array to hold a
    sprite then during the program i was using the blitter to copy a sprite
    to this buffer,but I had the blitter parameters set wrong so the striog
    array(+other things) was being overwritten by the blitter.
    
    	As an aside,I found this problem with the aid of a device called 
    	The Ultimate Ripper.(uk 40 pounds).This allows you to interupt
    any!! program and scan memory for graphics,music samples etc.
    
    	It can display memory on the screen as bit mapped graphics in any
    form (ie screen width,no of planes) So you can scan through commercial
    programs,and save the graphics to disk with the origional pallette.
                        
    	This is useful if you want to write games for your own use but like
    me,can't draw.