@@ -1800,7 +1800,7 @@ int inlinealphadata (char **statement)
18001800 int quotelen = 0 ;
18011801
18021802 if (currentcharset [0 ] == '\0' )
1803- prerror ("the characterset statement needs to precede plotchars with an inline string" );
1803+ prerror ("the characterset statement needs to precede a command with an inline string" );
18041804
18051805
18061806 for (t = 0 ; statement [2 ][t ] != '\0' ; t ++ )
@@ -7960,11 +7960,16 @@ void next (char **statement)
79607960
79617961void autodim (char * * statement )
79627962{
7963+ #define AD_BYTE 0
7964+ #define AD_44 1
7965+ #define AD_88 2
7966+
79637967 static int inititialized = 0 ;
79647968 static char start_addr [80 ];
79657969 static char end_addr [80 ];
79667970 static int current_index ;
79677971
7972+ int variable_type ;
79687973 int memsize ,t ;
79697974 int objsize , objcount ;
79707975
@@ -7976,11 +7981,13 @@ void autodim (char **statement)
79767981 // 1 2 3 4
79777982 // autodim type name count
79787983
7979- assertminimumargs (statement , "autodim" , 3 );
7984+ assertminimumargs (statement , "autodim" , 2 );
7985+ removeCR (statement [3 ]);
79807986 removeCR (statement [4 ]);
79817987
79827988 if (strncmp (statement [2 ],"init" ,5 )== 0 )
79837989 {
7990+ assertminimumargs (statement , "autodim (init)" , 3 );
79847991 inititialized = 1 ;
79857992 current_index = 0 ;
79867993 strncpy (start_addr ,statement [3 ],79 );
@@ -7991,23 +7998,68 @@ void autodim (char **statement)
79917998 if (!inititialized )
79927999 prerror ("autodim used without initializing." );
79938000
8001+ variable_type = -1 ;
79948002 if (strncmp (statement [2 ],"byte" ,5 )== 0 )
79958003 {
7996- objsize = 1 ;
7997- snprintf (redefined_variables [numredefvars ], 100 , "%s = (%s + %d)" ,statement [3 ],start_addr ,current_index );
7998- numredefvars ++ ;
8004+ variable_type = AD_BYTE ;
8005+ objsize = 1 ;
8006+ }
8007+ else if (strncmp (statement [2 ],"4.4" ,5 )== 0 )
8008+ {
8009+ variable_type = AD_44 ;
8010+ objsize = 1 ;
8011+ }
8012+ else if (strncmp (statement [2 ],"8.8" ,5 )== 0 )
8013+ {
8014+ variable_type = AD_88 ;
8015+ objsize = 2 ;
8016+ }
8017+
8018+ if (variable_type == -1 )
8019+ prerror ("autodim type not recognized." );
79998020
8000- // advance the autodim index past this recent allocation...
8021+ if ((statement [4 ][0 ] == 0 ) || (statement [4 ][0 ] == ':' ))
8022+ objcount = 1 ;
8023+ else
8024+ {
8025+ // retrieve and validate how many bytes/objects are needed
80018026 objcount = strictatoi (statement [4 ]);
80028027 if (objcount < 1 )
80038028 prerror ("autodim invalid object count used." );
8004- current_index = current_index + objcount ;
8029+ }
80058030
8006- // check that the allocation didn't go past the end value
8007- printf (" if ((%s + %d) > %s)\n echo \"\"\n echo \"######## ERROR: autodim of variable '%s' exceeded allocated memory\"\n ERR\n endif\n" ,start_addr ,current_index - 1 , end_addr , statement [3 ]);
8031+ // register the base variable name
8032+ snprintf (redefined_variables [numredefvars ], 100 , "%s = (%s + %d)" ,statement [3 ],start_addr ,current_index );
8033+ numredefvars ++ ;
8034+
8035+ if ( variable_type == AD_44 )
8036+ {
8037+ snprintf (redefined_variables [numredefvars ], 100 , "%sb44 = (%s + %d)" ,statement [3 ],start_addr ,current_index );
8038+ numredefvars ++ ;
8039+ snprintf (fixpoint44 [0 ][numfixpoint44 ], 46 , "%s" ,statement [3 ]);
8040+ snprintf (fixpoint44 [1 ][numfixpoint44 ], 46 , "%sb44" ,statement [3 ]);
8041+ numfixpoint44 ++ ;
80088042 }
8009- else
8010- prerror ("unknown autodim type:%s" ,statement [2 ]);
8043+
8044+ if ( variable_type == AD_88 )
8045+ {
8046+ snprintf (redefined_variables [numredefvars ], 100 , "%s_hi = (%s + %d)" ,statement [3 ],start_addr ,current_index );
8047+ numredefvars ++ ;
8048+ snprintf (redefined_variables [numredefvars ], 100 , "%s_lo = (%s + %d)" ,statement [3 ],start_addr ,current_index + objcount );
8049+ numredefvars ++ ;
8050+ snprintf (fixpoint88 [0 ][numfixpoint88 ], 46 , "%s" ,statement [3 ]);
8051+ snprintf (fixpoint88 [1 ][numfixpoint88 ], 46 , "%s_lo" ,statement [3 ]);
8052+ numfixpoint88 ++ ;
8053+
8054+ }
8055+
8056+ // advance the autodim index past this recent allocation...
8057+ current_index = current_index + (objcount * objsize );
8058+
8059+ // Add an assembly check that the allocation didn't go past the end value
8060+ // This needs to be at the asm level, because we allow the program to
8061+ // use symbols for the start and end address.
8062+ printf (" if ((%s + %d) > %s)\n echo \"\"\n echo \"######## ERROR: autodim of variable '%s' exceeded range end. (%s)\"\n ERR\n endif\n" ,start_addr ,current_index - 1 , end_addr , statement [3 ],end_addr );
80118063}
80128064
80138065void dim (char * * statement )
0 commit comments