AHCC

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Eero Tamminen
Atari God
Atari God
Posts: 1559
Joined: Sun Jul 31, 2011 1:11 pm

Re: AHCC

Postby Eero Tamminen » Sat Jun 13, 2015 3:06 pm

The confusion probably comes from using C++ compiler on PC for compiling "C code".

Function declaration without any arguments is in C++ a shorthand for "name(void)" declaration.

In C, it's just an old (80's) K&R C function name declaration, not an ANSI-C function prototype. In C, function prototypes have always arguments.

As to AHCC complaining about prototype mismatch, I guess it defaults K&R prototypes to (int) argument. GCC disables all argument checking for K&R code, even when one uses -Wall and -Wextra. You need coupled of specific warning options to get GCC output any warnings about K&R function declarations / mismatches.

peterlane
Atari maniac
Atari maniac
Posts: 94
Joined: Tue Mar 05, 2013 2:44 pm
Contact:

Re: AHCC

Postby peterlane » Sun Jun 14, 2015 8:48 pm

m0n0 wrote:IMO you must also declare the parameters to functions (In your case: void), I think this should do the job:

Code: Select all

#include <stdio.h>

void say_hello (void);

void main () {
  say_hello ();
}

void say_hello (void) {
   printf ("hi\n");
}


Thanks, I have tried this through hatari, and adding the voids resolves the problem in version 5 of ahcc, so hopefully will work on the firebee.

Strange though, as I've written several programs without void args on my firebee and they were compiling fine until the update. Perhaps the new version is just stricter???
Peter Lane
Firebee | STE (4Mb, TOS 2.06)
http://peterlane.info/firebee.html

Henk Robbers
AHCC Developer
AHCC Developer
Posts: 39
Joined: Mon Nov 14, 2011 2:37 pm

AHCC v5.2

Postby Henk Robbers » Sat Aug 22, 2015 10:17 pm

august 23 2015
v5.2
Shell:
Compare folders:
Mismatch display order of filenames reversed.
Double clicking 'Mismatch': first file is left on top.
Compare files: (^2)
flipflop between red and green according to equality
of selected lines. (red: unequal, green : equal).

Compiler:
Small code improvements (no effects).
Small improvements in the optimizer.
Nicer display of options with -v.
fixed spurious denying of duplicate typ definitions
in some cases.

Library ahccgem:
Added function vq_vgdos in vdi_wstn.c

Calc:
(type Esc in journal)
Prompt '>'.

Assembler:
Deny operands of the form symbol.w .
shift Dn interpreted as shift #1,Dn (like Pure Asm).
Implement Local statement for labels in macros.
accept .w on swap instruction.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Thu Aug 27, 2015 10:50 pm

All,

Pretty sure this is a stupid misunderstanding on my part, but I cannot seem to get this environment configured so that it can create an executable version of the HELLO.C program. Every time I complete the creation of the HELLO.TOS executable it crashes. I am running AHCC under STEEM. I have tried both the original 3.2 release and the more recent SSE release with the same result.

I have tried both the original supplied HELLO.C file and one where I have added:

char ch;

at the beginning of main and:

ch=getchar();

after the printf call.

Neither of these can produce an executable that will run successfully under STEEM.

Please let me know if there is any further information required to better trouble shoot my environment. Thanks.
Russ Ruark Jr.

m0n0
Captain Atari
Captain Atari
Posts: 419
Joined: Mon Oct 05, 2009 3:13 am

Re: AHCC

Postby m0n0 » Thu Aug 27, 2015 10:57 pm

Hello jruark56,

3 options you should check in the configuration dialog:

- int 32 bit
- cdecl calling
- code for what architecture?

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Fri Aug 28, 2015 12:03 am

m0n0,

Thanks for the quick reply. I have int 32 bit unchecked, cdecl checked and coding for the 68000 processor.
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Wed Sep 09, 2015 12:18 am

All,

I think I found my problem. Seems my original PC folder that I was using as an ST C drive is slightly corrupted. When I installed AHCC in a clean folder, it works like a charm. The only odd thing is that in order to get a clean display, I must boot with an empty disk in drive A.

Maybe still a configuration issue?
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Wed Sep 16, 2015 2:38 am

Henk/All,

I am trying to walk my way through Clayton Walnum's Cmanship Complete book, working the exercises in each chapter using AHCC as my development environment. My earlier posted questions turned out to be resolved by making a clean install in a new folder on my PC. My problem now is that the definition for an OBJECT structure is different between Clayton's book and the header files included with AHCC. The ob_spec member is defined as a long in the book, but defined as an pointer to an OBSPEC structure in AHCC.

Part of Chapter 14's program (a dialog box construction example) calls for modifying a boxed text control. The code defines a TEDINFO pointer:

TEDINFO *ob_tedinfo

A bit further down in the code ob_tedinfo needs to be set equal to tree_addr[NUMBERS] ob_spec pointer like this:

ob_tedinfo=(TEDINFO *)tree_addr[NUMBERS].ob_spec

This fails using the definition for an OBJECT structure in AHCC. The error is that the union is not allowed. OBSPEC is defined as a union structure with possible data types including a TEDINFO pointer.

If I change the AES.H header file so that the OBJECT structure now refers to ob_spec as a long member, then the program compiles and links good, but crashes with two bombs on execution.

I can't seem to figure out how to properly use the OBJECT structure under AHCC. Any ideas about where I am going wrong?
Russ Ruark Jr.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 685
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: AHCC

Postby mfro » Wed Sep 16, 2015 6:18 am

jruark56 wrote:If I change the AES.H header file so that the OBJECT structure now refers to ob_spec as a long member, then the program compiles and links good, but crashes with two bombs on execution.


You should never change a header file that describes data structures defined in a library you can't change.

If you mean a tedinfo pointer, then use the tedinfo union member to access it:

Code: Select all

    TEDINFO *ob_tedinfo;
   
    ob_tedinfo = tree_addr[NUMBERS].ob_spec.tedinfo;


AHCC uses the Pure C "trick" that introduced unions in its AES bindings that allow one to access the different OBJECT members without casting them to the data types they point to.

Original DR code (which your book's code seems to describe) just (ab)used LONGs as pointers to different types (and needed lots of unsafe casts), the unions can be used to access members through union members.

It doesn't really increase type safety, but readability. Use it.

peterlane
Atari maniac
Atari maniac
Posts: 94
Joined: Tue Mar 05, 2013 2:44 pm
Contact:

Re: AHCC

Postby peterlane » Wed Sep 16, 2015 8:31 am

jruark56 wrote:Henk/All,

I am trying to walk my way through Clayton Walnum's Cmanship Complete book, working the exercises in each chapter using AHCC as my development environment. My earlier posted questions turned out to be resolved by making a clean install in a new folder on my PC. My problem now is that the definition for an OBJECT structure is different between Clayton's book and the header files included with AHCC. The ob_spec member is defined as a long in the book, but defined as an pointer to an OBSPEC structure in AHCC.

Part of Chapter 14's program (a dialog box construction example) calls for modifying a boxed text control. The code defines a TEDINFO pointer:

TEDINFO *ob_tedinfo

A bit further down in the code ob_tedinfo needs to be set equal to tree_addr[NUMBERS] ob_spec pointer like this:

ob_tedinfo=(TEDINFO *)tree_addr[NUMBERS].ob_spec

This fails using the definition for an OBJECT structure in AHCC. The error is that the union is not allowed. OBSPEC is defined as a union structure with possible data types including a TEDINFO pointer.

If I change the AES.H header file so that the OBJECT structure now refers to ob_spec as a long member, then the program compiles and links good, but crashes with two bombs on execution.

I can't seem to figure out how to properly use the OBJECT structure under AHCC. Any ideas about where I am going wrong?


I haven't done chapter 14 yet, but I have 'converted' some of CManship to compile under AHCC, which may help you. You can see the files on github: https://github.com/petercrlane/cmanship

Chapter 22 uses TEDINFO. To get the string in a dialog box, I have (as mfro says):

Code: Select all

char * get_tedinfo_str (OBJECT * tree, int object) {
   return tree[object].ob_spec.tedinfo->te_ptext;
}
Peter Lane
Firebee | STE (4Mb, TOS 2.06)
http://peterlane.info/firebee.html

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Fri Sep 18, 2015 1:57 am

Thanks to both mfro and Peter Lane. I had a feeling I was missing something along the way when it came to the way the AES header was declared.

I never really got a solid handle on the use of UNION data structures other than to understand that a UNION was a way to define a variable that could be of more than one type, but only one of those types at a time.

I truly appreciate the example of the calling method for using the OBSPEC union for OBJECT structures in AHCC. I will report back with my progress once I have applied this to the program from the book.
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Sat Sep 19, 2015 2:37 am

All,

Well, after applying the change to the code based on mfro's example I don't get the error about "union not allowed". However, I get a 2 bomb error on running the prg.

Here is the code (as modified):

Code: Select all

/***************************************/
/*                                     */
/*  CMANSHIP LISTING 1                 */
/*  CHAPTER 14                         */
/*  DEVELOPED WITH AHCC 5.2            */
/*                                     */
/***************************************/

#include <osbind.h>
#include <aes.h>
#include <vdi.h>
#include <string.h>
#include <stdio.h>
#include "SAMPLE.H"

#define R_TREE     0
#define FINGER     3


/* Required GEM global arrays */
int work_in[11],work_out[57],pxyarray[10];
int contrl[12],intin[128],intout[128];
int ptsin[128],ptsout[128];

/* Some globalvariables */
int handle,dum;
int dial_x,dial_y,dial_w,dial_h,num,n_x,n_y;
char number_str[13]="    0000    ";
OBJECT *tree_addr;
OBJECT tree;
MFORM sysmouse;

char* find_str(int object,char* string);
void open_vwork(void);
void do_dialog(void);
void do_up(void);
void do_down(void);
void edit_object(void);
void print_results(OBJECT *tree);
void button_wait(void);

int main()
{
   appl_init();
   open_vwork();
   do_dialog();
   button_wait();
   rsrc_free();
   v_clsvwk(handle);
   appl_exit();
   return(0);
}

void open_vwork()
{
   int i;

   handle=graf_handle(&dum,&dum,&dum,&dum);
   for(i=0;i<10;work_in[i++]=1);
   work_in[10]=2;
   v_opnvwk(work_in,&handle,work_out);
}

void do_dialog()
{
   int choice;

   if(!rsrc_load("SAMPLE.RSC"))
      form_alert(1,"[1][SAMPLE.RSC missing!][I'll do better]");
   else
   {
      rsrc_gaddr(R_TREE,SAMPLE,&tree_addr);
      form_center(tree_addr,&dial_x,&dial_y,&dial_w,&dial_h);
      objc_offset(tree_addr,NUMBERS,&n_x,&n_y);
      form_dial(FMD_START,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
      form_dial(FMD_GROW,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
      objc_draw(tree_addr,0,2,dial_x,dial_y,dial_w,dial_h);
      graf_mouse(FINGER,&sysmouse);

      num=0;
      do
      {
         choice=form_do(tree_addr,NAME);
         if(choice==RADIO1) v_gtext(handle,160,20,"Radio 1 ");
         if(choice==RADIO2) v_gtext(handle,160,20,"Radio 2 ");
         if(choice==RADIO3) v_gtext(handle,160,20,"Radio 3 ");
         if(choice==RADIO4) v_gtext(handle,160,20,"Radio 4 ");
         if(choice==RADIO5) v_gtext(handle,160,20,"Radio 5 ");
         if(choice==RADIO6) v_gtext(handle,160,20,"Radio 6 ");
         if(choice==OPTION1) v_gtext(handle,160,20,"Option 1 ");
         if(choice==OPTION2) v_gtext(handle,160,20,"Option 2 ");
         if(choice==UPARROW) do_up();
         if(choice==DWNARROW) do_down();
      }
      while(choice!=CANCEL && choice!=OK);

      form_dial(FMD_SHRINK,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
      form_dial(FMD_FINISH,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
      print_results(tree_addr);
   }
}

void do_up()
{
   num+=1;
   if(num>9999)
   {
      num=0;
      strcpy(number_str,"    0000    ");
   }
   edit_object();
}
void do_down()
{
   num-=1;
   if(num<0) num=9999;
   edit_object();
}

void edit_object()
{
   TEDINFO *ob_tedinfo;
   char temp_str[10];

   sprintf(temp_str,"%d",num);
   strcpy(&number_str[8 - strlen(temp_str)],temp_str);
   strcpy(&number_str[8],"                 ");

   ob_tedinfo=tree_addr[NUMBERS].ob_spec.tedinfo;
   ob_tedinfo->te_ptext=number_str;
   objc_draw(tree_addr,NUMBERS,1,n_x,n_y,96,16);
}

void print_results(OBJECT *tree)
{
   char* string;

   string=find_str(NAME,string);
   v_gtext(handle,160,20,"Your name is: ");
   v_gtext(handle,264,20,string);
   string=find_str(AGE,string);
   v_gtext(handle,160,36,"Your age is: ");
   v_gtext(handle,264,36,string);
   string=find_str(NUMBERS,string);
   v_gtext(handle,160,52,"Final number value: ");
   v_gtext(handle,320,52,&string[4]);
}

char* find_str(int object,char* string)
{
   TEDINFO *ob_tedinfo;

   ob_tedinfo=tree_addr[object].ob_spec.tedinfo;
   string=ob_tedinfo->te_ptext;
   return(string);
}

void button_wait()
{
   evnt_button(1,1,1,&dum,&dum,&dum,&dum);
   evnt_button(1,1,0,&dum,&dum,&dum,&dum);
}


I believe the problem to be that pointer to OBJECT *tree_addr is not being assigned a proper address. The program crashes on the call to form_do in the do_dialog procedure. I am, again, certain that my novice understanding of C is getting in my way here. It has to be something stupidly simple, but I can't reason it out.

Any help is greatly appreciated. Please feel free to offer pointers that help me debug this further. I am not looking for a completed solution here. I won't learn much that way. Just some better understanding of how the code is working. Thanks.
Russ Ruark Jr.

User avatar
jfl
Atari Super Hero
Atari Super Hero
Posts: 827
Joined: Tue Jul 18, 2006 10:55 pm
Location: Liège, Belgium
Contact:

Re: AHCC

Postby jfl » Sat Sep 19, 2015 7:32 am

jruark56 wrote:I believe the problem to be that pointer to OBJECT *tree_addr is not being assigned a proper address.

Then this looks to me like a good reason to check the return value of your rsrc_gaddr() call and exit gracefully if the call fails. It would give you the same information without the crash :wink:

Always check the return values of system calls. rsrc_gaddr() returns 0 in case of error.

Also, why do you declare a "tree" variable?
Jean-François
GEMDict – GEMClip

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 685
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: AHCC

Postby mfro » Sat Sep 19, 2015 8:05 am

I just had a quick glance at the code, but to me it looks as if you write over the bounds of number_str[] within edit_object().

number_str[] has been defined as 13 chars, but you copy 18 + 8 = 26 into it during the first few lines of edit_object() it which probably damages important variables (most likely tree_adr as well since its defined afterwards).

Something is wrong there...

P.S.: just found the book with the original example. Seems to be wrong right there already.

User avatar
jfl
Atari Super Hero
Atari Super Hero
Posts: 827
Joined: Tue Jul 18, 2006 10:55 pm
Location: Liège, Belgium
Contact:

Re: AHCC

Postby jfl » Sat Sep 19, 2015 10:33 am

mfro wrote:P.S.: just found the book with the original example. Seems to be wrong right there already.

I don't think it is. The original code writes 5 chars at index 8 in a 13 chars string.
Jean-François
GEMDict – GEMClip

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 685
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: AHCC

Postby mfro » Sat Sep 19, 2015 10:47 am

jfl wrote:
mfro wrote:P.S.: just found the book with the original example. Seems to be wrong right there already.

I don't think it is. The original code writes 5 chars at index 8 in a 13 chars string.


This:

Code: Select all

strcpy(&number_str[8],"                 ");


writes 17 chars (up to position 26) into a 13 chars string.

But you are right nevertheless.

Just milled the code posted above through latest AHCC and it doesn't crash for me until I first touch the up/down buttons of the lower right edit field which triggers the mentioned overwrite (makes the edit field go crazy).

So IMO, this is definitely wrong, but doesn't cause the crash.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Sat Sep 19, 2015 5:41 pm

jfl,

Thanks. I will try adjusting the code to add a check for the rsrc_gaddr call and see what turns up there. This is code from the book Cmanship Complete by Clayton Walnum. Fairly old book based on using the old Megamax C environment. The original code self-declared both the TEDINFO and OBJECT structures. The definition of *tree_addr comes from that code.

mfro,

It is entirely possible that I am adding too many blank spaces in the strcopy call found in edit_object. I will take a look at that as well. When working from an STGuide hypertext file it can be difficult to tell the exact number of spaces being asked for. I really should be thinking logically about things and not just verbatim copying what is presented.

Thanks to both of you for your suggestions. I appreciate the help.
Russ Ruark Jr.

User avatar
rudis
Captain Atari
Captain Atari
Posts: 153
Joined: Mon Feb 14, 2011 9:41 am
Contact:

Re: AHCC

Postby rudis » Sat Sep 19, 2015 6:32 pm

there is a pdf of the complete series http://info-coach.fr/atari/software/_de ... p-v1.0.pdf

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Mon Sep 21, 2015 5:40 pm

Rudis,

Thanks. I have a copy of that pdf in my library. I am working from the STGuide version because it is more convenient to have it loaded in the emulator for quick reference.
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Sun Oct 04, 2015 9:28 pm

All,

After a bit of experimentation, I discovered the apparent cause for the failure to execute the form_do call. It seems that the RCS that is included in the Megamax C distribution I have downloaded created a faulty resource. I built the dialog from the book in a step-by-step fashion using RCS V.3 from Atari and everything works fine (except for the numbers spinner). No more bombs. I am now testing just that control in a separate dialog. I hope to find the proper mix of code to get this thing working correctly.

Thanks to all of you who have posted helpful ideas and steps to take. It is truly appreciated.
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Sun Oct 11, 2015 6:52 pm

All,
A final update. I must learn to be more careful when working through old type-in stuff without the proper documentation for my tools. I used RCS V. 3 to finally build a working version of the dialog from the book. Unfortunately, what Megamax C called a BoxText control was re-named to a Formatted BoxText control in RCS v. 3. The older RCS's control used a full version of a TEDINFO structure while the newer BoxText still uses the same structure, but only provides access to the te_ptext member. Once I changed the resource to use a simple BoxText control, the entire program worked as described in the book.

Thanks again for all the help. Till next time...
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Fri Oct 23, 2015 11:41 pm

Hi all,

I have run up against another issue. Seems that AHCC (at least the binaries for the 68000) does not contain an intrinsic for the float type. Chapter 20 of Cmanship Complete uses this data type in calculating the size and position for a vertical slider. Is this a know issue with AHCC, or am I again missing something?
Russ Ruark Jr.

peterlane
Atari maniac
Atari maniac
Posts: 94
Joined: Tue Mar 05, 2013 2:44 pm
Contact:

Re: AHCC

Postby peterlane » Sat Oct 24, 2015 12:09 pm

jruark56 wrote:Hi all,

I have run up against another issue. Seems that AHCC (at least the binaries for the 68000) does not contain an intrinsic for the float type. Chapter 20 of Cmanship Complete uses this data type in calculating the size and position for a vertical slider. Is this a know issue with AHCC, or am I again missing something?


I believe this is a deliberate design decision: AHCC on the ST does not support float.

To run the CManship examples on an Hatari emulated STE, I modified the calculation so it's done in ints. The file for chapter 20 is at:
https://github.com/petercrlane/cmanship/blob/master/CHAP20ST.C see lines 270-272. I tested this using AHCC version 5.2.

This seems to work, for the scrolling. However, exiting the program freezes the emulator. I don't know why just yet.
Peter Lane
Firebee | STE (4Mb, TOS 2.06)
http://peterlane.info/firebee.html

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Sat Oct 24, 2015 9:08 pm

peterlane,

Thanks. I thought I had heard that about this compiler. I was considering doing the same using int for the data type. I will take a look at your code and try applying that to mine. I am using STEEM as my development environment. I will let you know if it freezes on exit.
Russ Ruark Jr.

jruark56
Atari freak
Atari freak
Posts: 56
Joined: Sun Nov 09, 2008 2:58 am

Re: AHCC

Postby jruark56 » Wed Oct 28, 2015 12:17 am

peterlane,

I tried your code for setting the vertical slider, but it doesn't work for me. The directory of files does move according to the other parts of the code, but the slider position never changes.

I think I don't understand your solution. You set the first tmp variable to the integer division of top and the total number of lines minus the lines currently shown in the window multiplying the result by 1000. When I apply the math using real numbers outside of the program, this always results in 0. Is it supposed to be something else?

Good news is STEEM does not crash or freeze when the program is run.
Russ Ruark Jr.


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest