Classic Computer Magazine Archive PROGRAM LISTING: 86-12/STEPPER.C


/* 
 *  ST Stepper Motor
 *  (c) 1986 Antic Publishing
 *  Version 073086  Wednesday
 *  Written by Patrick Bass
 *
 *  The purpose of this program is to explore creating
 *   and manipulating a form while performing a job.
 *
 *---- Alcyon Include File -----------------*/

#include       "stepper.h"
#include       "osbind.h"

#define   TRUE           (1)
#define   FALSE          (0)
#define   begin          {
#define   end            }
#define   wend           }
#define   repeat         }
#define   next           }
#define   endif          }
#define   not            !
#define   equals         ==
#define   does_not_equal !=
#define   then
#define   CONSOL         2
#define   PRINTER        0
#define   DELAY          for( i=0; i<1000; i++ );
#define   LWGET(x)       ( (int) *((int *)(x)) )
#define   OB_W(x)        ( box_address+(x)*sizeof(OBJECT)+20 )
#define   OB_H(x)        ( box_address+(x)*sizeof(OBJECT)+22 )

typedef  struct  object
     begin
          int            ob_next;
          int            ob_head;
          int            ob_tail;
          unsigned int   ob_type;
          unsigned int   ob_flags;
          unsigned int   ob_state;
          long           ob_spec;
          int            ob_x;
          int            ob_y;
          int            ob_width;
          int            ob_heigth;
     end  OBJECT;

typedef  struct  text_edinfo
     begin
          long           te_ptext;
          long           te_ptmplt;
          long           te_pvalid;
          int            te_font;
          int            te_junk1;
          int            te_just;
          int            te_color;
          int            te_junk2;
          int            te_thickness;
          int            te_txtlen;
          int            te_tmplen;
     end  TEDINFO;

/*---------------- Alcyon Declarations/Equates --------*/
int  contrl[ 12 ],
     intin[ 256 ],  ptsin[ 256 ],
     intout[ 256 ], ptsout[ 256 ],
     workin[]={ 1,1,1,1,1,1,1,1,1,1,2 }, workout[ 57 ],
     i, j, k, l, x, y, w, h,
     mtopx, mtopy, mbotx, mboty,
     t_x, t_y, t_w, t_h, 
     b_x, b_y, b_w, b_h,
     c_x, c_y, c_w, c_h,
     s_x, s_y, s_w, s_h,
     top, bottom, current, speed,
     delay, drive, dum, gem_handle,
     button, pressed, finished, xdial, ydial, wdial, hdial;

char topstring[ 20 ],  botstring[ 20 ],
     currstring[ 20 ], speedstring[ 20 ],
     a, b, c, d;

long box_address;

/*-------------------------------------------------------------------*/
main()
begin
     initialize();

     do begin

          move_the_stepper_motor();

     repeat while( not finished );

     terminate();     
end

/*--------------------------------*/
initialize()
begin
     appl_init();
     gem_handle=graf_handle( &i, &i, &i, &i );
     v_opnvwk( workin, &gem_handle, workout );

     rsrc_load( "\STEPPER.RSC" );
     rsrc_gaddr( 0, TREE1, &box_address );

     a=5; b=6; c=10; d=9;

     graf_mouse( 0, 0L );
     finished=FALSE;
end

/*--------------------------------*/
move_the_stepper_motor()
begin
     x=0; y=0, w=10, h=10;
     form_center( box_address, &xdial, &ydial, &wdial, &hdial );

     find_box_sizes();

     form_dial ( 0, x, y, w, h, xdial, ydial, wdial, hdial );
     form_dial ( 1, x, y, w, h, xdial, ydial, wdial, hdial );
 
     objc_draw( box_address, TREE1, 2, xdial, ydial, wdial, hdial );

     do begin
          button=form_do( box_address, 0 );

          if( button equals MOVETOP )then move_top();
          if( button equals MOVEBOT )then move_bottom();

          if( button equals TOPUP )then d_topup();
          if( button equals TOPDN )then d_topdn();

          if( button equals BOTUP )then d_botup();
          if( button equals BOTDN )then d_botdn();

          if( button equals CURRUP )then d_curup();
          if( button equals CURRDN )then d_curdn();

          if( button equals SPEEDUP )then d_speup();
          if( button equals SPEEDDN )then d_spedn();

     repeat while( button does_not_equal QUIT );

     form_dial( 2, x, y, w, h, xdial, ydial, wdial, hdial ); 
     form_dial( 3, x, y, w, h, xdial, ydial, wdial, hdial );

     finished=TRUE;
end

/*----------------------------------*/
find_box_sizes()
begin
     objc_offset( box_address, TOPNUM, &t_x, &t_y );
     t_w=( LWGET( OB_W( TOPNUM )))-1;
     t_h=( LWGET( OB_H( TOPNUM )))-1;

     objc_offset( box_address, BOTNUM, &b_x, &b_y );
     b_w=( LWGET( OB_W( BOTNUM )))-1;
     b_h=( LWGET( OB_H( BOTNUM )))-1;

     objc_offset( box_address, CURRNUM, &c_x, &c_y );
     c_w=( LWGET( OB_W( CURRNUM )))-1;
     c_h=( LWGET( OB_H( CURRNUM )))-1;

     objc_offset( box_address, SPEEDNUM, &s_x, &s_y );
     s_w=( LWGET( OB_W( SPEEDNUM )))-1;
     s_h=( LWGET( OB_H( SPEEDNUM )))-1;
end

/*----------------------------------*/
d_topup()
begin
     top=top+1;
     adjust( TOPNUM, top, &topstring, t_x, t_y, t_w, t_h ); 
end

/*----------------------------------*/
d_topdn()
begin
     if( top>bottom )then begin
          top=top-1;
          adjust( TOPNUM, top, &topstring, t_x, t_y, t_w, t_h ); 
          if( top<=current )then begin
               current=top;
               d_curdn();
          endif
     endif
end

/*----------------------------------*/
d_botup()
begin
     if( bottom<top )then begin
          bottom=bottom+1;
          adjust( BOTNUM, bottom, &botstring, b_x, b_y, b_w, b_h ); 
          if( bottom>=current )then begin
               current=bottom;
               d_curup();
          endif
     endif
end

/*----------------------------------*/
d_botdn()
begin
     bottom=bottom-1;
     adjust( BOTNUM, bottom, &botstring, b_x, b_y, b_w, b_h ); 
end

/*----------------------------------*/
d_curup()
begin
     int  i;

     current=current+1;
     adjust( CURRNUM, current, &currstring, c_x, c_y, c_w, c_h );
     Bconout( PRINTER, d ); DELAY
     Bconout( PRINTER, c ); DELAY
     Bconout( PRINTER, b ); DELAY
     Bconout( PRINTER, a ); DELAY
end

/*----------------------------------*/
d_curdn()
begin
     int  i;

     current=current-1;
     adjust( CURRNUM, current, &currstring, c_x, c_y, c_w, c_h ); 
     Bconout( PRINTER, a ); DELAY
     Bconout( PRINTER, b ); DELAY
     Bconout( PRINTER, c ); DELAY
     Bconout( PRINTER, d ); DELAY
end

/*----------------------------------*/
d_speup()
begin
     speed=speed+1;
     adjust( SPEEDNUM, speed, &speedstring, s_x, s_y, s_w, s_h ); 
end

/*----------------------------------*/
d_spedn()
begin
     if( speed>0 )then begin
          speed=speed-1;
          adjust( SPEEDNUM, speed, &speedstring, s_x, s_y, s_w, s_h ); 
     endif
end

/*--------------------------------*/
adjust( object, variable, string, x, y, w, h )
int  object, variable, x, y, w, h;
char *string;
begin
     ftoa( (float)variable, string, 0 );
     set_text( box_address, object, string );
     objc_draw( box_address, object, 1, x, y, w, h );
     beep( 0, 1, 50 );
end

/*--------------------------------*/
set_text( tree_address, obj_number, string_address )
OBJECT    *tree_address;
int       obj_number;
char      *string_address;

begin
     TEDINFO   *obj_specification;

     obj_specification=(TEDINFO *)(tree_address+obj_number)->ob_spec;
     obj_specification->te_ptext=( string_address );
     obj_specification->te_txtlen=( 4 );
end

/*--------------------------------*/
move_top()
begin
     int  i, j, k, mx, my, pressed, key;

     for( i=current; i<top; i++ )begin
          graf_mkstate( &mx, &my, &pressed, &key );
          if( pressed )then i=top;
          if( not pressed )then begin
               d_curup();
               for( j=0; j<speed; j++ )begin
                    for( k=0; k<500; k++ );
               next
          endif
     next
     beep( 0, 2, 15000 );
     beep( 0, 1, 15000 );
     beep( 0, 2, 15000 );
end

/*--------------------------------*/
move_bottom()
begin
     int  i, j, k, mx, my, pressed, key;

     for( i=current; i>bottom; i-- )begin
          graf_mkstate( &mx, &my, &pressed, &key );
          if( pressed )then i=bottom;
          if( not pressed )then begin
               d_curdn();
               for( j=0; j<speed; j++ )begin
                    for( k=0; k<500; k++ );
               next
          endif
     next
     beep( 0, 2, 15000 );
     beep( 0, 1, 15000 );
     beep( 0, 2, 15000 );
end

/*--------------------------------*/
beep( notelo, notehi, delay )
char  notehi;
int  notelo, delay;

begin
     int  portstate;

     Giaccess( 15, 8+128 );
     Giaccess( 0, 128 );
     portstate=Giaccess( portstate, 7 );
     Giaccess( 60, 7+128 );

     Giaccess( notelo, 0+128 );
     Giaccess( notehi, 1+128 );

     for( i=0; i<delay; i++ );

     Giaccess( 0, 0+128 );
     Giaccess( 0, 1+128 );

     Giaccess( portstate, 7+128 );
     Giaccess( 0, 8+128 );      
end

/*--------------------------------*/
terminate()
begin
     rsrc_free();
     v_clsvwk( gem_handle );
     appl_exit();
end



Back to previous page