help? program won't compile
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
help? program won't compile
don't have a clue why either. It appears to get past zcpp fine but barfs on something when it gets to dealing with the resulting assembler file.
got the thing uploaded here (didn't want to paste 15.1k in a code block)
i'm compiling it like so:
zcc +ti86ansi -startup=10 -o tgen -create-app tgen.c
what is the difference between ti86 and ti86ansi anyway?
tried doing that > aa.txt but all I got was up to the zcpp part
anyone have any idea why it's failing? i'm getting many many error messages, it scrolls off the screen quite fast so I can't catch all of the messages. (tried setting the command line buffer up to 500 lines and it still isn't enough)
using the win32 binary version of 1.7 if that matters at all.
the really odd part is that if I block comment out 11-20 of the switch statement it compiles fine. If I block comment out 1-10 it also works fine. With all of the cases in there it fails quite specularly.
anyone have a clue why it's failing to compile like that?
got the thing uploaded here (didn't want to paste 15.1k in a code block)
i'm compiling it like so:
zcc +ti86ansi -startup=10 -o tgen -create-app tgen.c
what is the difference between ti86 and ti86ansi anyway?
tried doing that > aa.txt but all I got was up to the zcpp part
anyone have any idea why it's failing? i'm getting many many error messages, it scrolls off the screen quite fast so I can't catch all of the messages. (tried setting the command line buffer up to 500 lines and it still isn't enough)
using the win32 binary version of 1.7 if that matters at all.
the really odd part is that if I block comment out 11-20 of the switch statement it compiles fine. If I block comment out 1-10 it also works fine. With all of the cases in there it fails quite specularly.
anyone have a clue why it's failing to compile like that?
The ansi version has the stdout character stream emulate a vt100 terminal (or close to it), which means some character sequences are used to mean "move cursor to x,y position", "change text colour", "apply underline", etc. So you can printf() strings that contain these codes to do more than just print on the same line.Freakazoid wrote:what is the difference between ti86 and ti86ansi anyway?
The regular version does not emulate a vt100 terminal but may contain special codes as well but this is platform dependent. The advantage of the ansi library is that all platforms' ansi libraries understand the same cursor commands (the vt100 standard).
I can't for the life of me remember where the vt100 sequences z88dk understands are listed. Maybe someone else will pop in with a link.
You can redirect all those error messages to a file by redirecting the stderr stream (stream #2):tried doing that > aa.txt but all I got was up to the zcpp part
anyone have any idea why it's failing? i'm getting many many error messages, it scrolls off the screen quite fast so I can't catch all of the messages. (tried setting the command line buffer up to 500 lines and it still isn't enough)
zcc +ti86ansi -startup=10 -o tgen -create-app tgen.c 2> temp.txt
The good news is there's nothing wrong with your program. I compiled it fine and ran it on the ZX Spectrum target. The bad news is you have a ti calculator and not a ZX Spectrumthe really odd part is that if I block comment out 11-20 of the switch statement it compiles fine. If I block comment out 1-10 it also works fine. With all of the cases in there it fails quite specularly.
There is something wrong with the -startup tag because if you eliminate it the program compiles fine to a ".86p" file. With the -startup, close to 700 complaints about out-of-range library routines is made; here is an excerpt:
Code: Select all
691 errors occurred during assembly
Key to filenames:
C:\DOCUME~1\ALVINA~1\LOCALS~1\Temp\s1i8_.o = ftest.c
File 'c:\z88dk\lib\clibs\ti86ansi_clib.lib', Module 'ANSI_CHAR', Out of range
Error in expression POST+1
File 'c:\z88dk\lib\clibs\ti86ansi_clib.lib', Module 'ANSI_SCROLLUP', Out of range
Error in expression ANSI_DEL_LINE
File 'c:\z88dk\lib\clibs\ti86ansi_clib.lib', Module 'ANSI_LF', Out of range
Error in expression ANSI_SCROLLUP
File 'c:\z88dk\lib\clibs\ti86ansi_clib.lib', Module 'ANSI_PUTC', Out of range
Error in expression ANSI_LF
File 'c:\z88dk\lib\clibs\ti86ansi_clib.lib', Module 'F_ANSI', Out of range
Error in expression ANSI_CLS
File 'c:\z88dk\lib\clibs\ti86ansi_clib.lib', Module 'F_ANSI', Out of range
Error in expression ANSI_LF
...
I think what this means is that the program is too big to fit into memory.
On the ti86 it looks like programs start at 0xD748 which doesn't leave that much memory especially when the ANSI library is used.
Which probably means that it's a good idea to restructure the program, there's a lot of very similar code, so it might be a good idea to use an array of structures to contain the limits which means the duplication vanishes. Alternatively, you could factor out the bulk of the switch statements into a separate function and pass in parameters that contain the limits.
On the ti86 it looks like programs start at 0xD748 which doesn't leave that much memory especially when the ANSI library is used.
Which probably means that it's a good idea to restructure the program, there's a lot of very similar code, so it might be a good idea to use an array of structures to contain the limits which means the duplication vanishes. Alternatively, you could factor out the bulk of the switch statements into a separate function and pass in parameters that contain the limits.
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
Aarg... I thought about trying to do something like that at the start but the problem is that everything changes so much it was going to be almost unfeasible...dom wrote:I think what this means is that the program is too big to fit into memory.
On the ti86 it looks like programs start at 0xD748 which doesn't leave that much memory especially when the ANSI library is used.
Which probably means that it's a good idea to restructure the program, there's a lot of very similar code, so it might be a good idea to use an array of structures to contain the limits which means the duplication vanishes. Alternatively, you could factor out the bulk of the switch statements into a separate function and pass in parameters that contain the limits.
this is going to be a major pain to rewrite.
going to have to write the ugly function from hell with a pointer to a struct array to pass all of the parameters it's going to need...
mmkay, that's interesting. Tried compiling a slightly trimmed down version (still had all of do_treasure, just lacked most of main) with just +ti86 instead of +ti86ansi, compiled fine but did all kinds of weird stuff when it ran then shut off the calculator. Ended up bricking it as every time it was turned on again the screen went wonky. Good thing this was only a virtual calculator and restoring it is as easy as "exit without saving state" then re-running it
edit: yup, it's been confirmed... the TI-86 is limited to a maximum of a 8k asm file...
the annoying bit is that it can still run the 28k monstrosity of a TI-BASIC file just fine.
I think this program idea of mine is officially close to dead right now. The only way I can think of getting it to work now involves maybe loading it's data from a file rather than embedding it in the program, something i'm not even sure is possible... The routines are there but I don't know if they'll work for my purposes. C string manipulation! whee!!! (spot the sarcasm) haven't dealt with that in a long long while.
Last edited by Freakazoid on Sun Oct 14, 2007 7:36 am, edited 1 time in total.
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
Quick question before I get to testing things. Is there a way to call program b from within program a? If the program finds it's data file missing it'll be nice if it could call the program to create it for me.Freakazoid wrote:The only way I can think of getting it to work now involves maybe loading it's data from a file rather than embedding it in the program, something i'm not even sure is possible... The routines are there but I don't know if they'll work for my purposes. C string manipulation! whee!!! (spot the sarcasm) haven't dealt with that in a long long while.
Likely going to have it programatically created as i'm not sure if I can upload a file of the right formatting to the calculator.
Ugh. That's really tight for a compiled program. It doesn't seem right that only 8k is available for asm programs... there must be a way to use the full (or larger portion) 24k. The TI target is on my to-do list (and maybe Stef/Dom too I can't speak for them) and maybe we can clear these things up down the line.Freakazoid wrote:edit: yup, it's been confirmed... the TI-86 is limited to a maximum of a 8k asm file...
the annoying bit is that it can still run the 28k monstrosity of a TI-BASIC file just fine.
I did a compile and found that your code is in the 8k area and the rest is library routines. The fact that you are using printf means a large block of code needs to be attached to handle all the scan conversions even if you don't use them. If you can do without them and can just print raw characters using "fputs()", you will cut down on binary size quite a bit (a couple K I would guess). Rather than using the %d stuff that printf offers you can use the strcpy(), strcat(), itoa(), etc functions in stdlib to build up a string of raw characters to be output with fputs; all these functions are small and are written in asm. This approach, coupled with a table substituted for the switch, will probably make it possible to fit it all in 8k. I'll see if I can cook up an example in the next few days if only for reference if you choose not to go this way (I'm dealing with a broken tooth at the moment which I find very distracting).
About loading data or launching another program... this I can't help without more knowledge of the TI. Stef might be able to help?
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
Well, it is possible to get around 16k with LASM but last time I tried that one on the virtual calculator it bricked the thing. Even if I could get it working it involves wiping the calculator clean to install LASM (the loader that'll load large asm files) something i'm also not too keen on.alvin wrote:Ugh. That's really tight for a compiled program. It doesn't seem right that only 8k is available for asm programs... there must be a way to use the full (or larger portion) 24k. The TI target is on my to-do list (and maybe Stef/Dom too I can't speak for them) and maybe we can clear these things up down the line.
I did a compile and found that your code is in the 8k area and the rest is library routines. The fact that you are using printf means a large block of code needs to be attached to handle all the scan conversions even if you don't use them. If you can do without them and can just print raw characters using "fputs()", you will cut down on binary size quite a bit (a couple K I would guess). Rather than using the %d stuff that printf offers you can use the strcpy(), strcat(), itoa(), etc functions in stdlib to build up a string of raw characters to be output with fputs; all these functions are small and are written in asm. This approach, coupled with a table substituted for the switch, will probably make it possible to fit it all in 8k. I'll see if I can cook up an example in the next few days if only for reference if you choose not to go this way (I'm dealing with a broken tooth at the moment which I find very distracting).
About loading data or launching another program... this I can't help without more knowledge of the TI. Stef might be able to help?
That's why i'm (eventually) going to get around to loading it's data from a file. Will likely take up more runtime memory than the other method but it should (hopefully) fit then.
Sorry but the workaround provided by LASM is the only trick I found.
The TI86 was a bad surprise, such a powerful toy with that strange memory handling.. but it seems to me someone was developing a new shell trying to solve that problem: am I dreaming ?
You can also try by using printk() or directly fputc(), with the non-ansi library, obviously.
The TI86 was a bad surprise, such a powerful toy with that strange memory handling.. but it seems to me someone was developing a new shell trying to solve that problem: am I dreaming ?
You can also try by using printk() or directly fputc(), with the non-ansi library, obviously.
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
AARG! if it isn't one problem it's another. Apparently file operations don't work on the TI-86. Guess i'm back to trying to fit the code + data into 8k...Freakazoid wrote:That's why i'm (eventually) going to get around to loading it's data from a file. Will likely take up more runtime memory than the other method but it should (hopefully) fit then.
This runs, but nothing new shows up on the calculator
Code: Select all
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE * outfile;
fopen("tgendata",outfile);
fputs("This is text1",outfile);
fputs("This is text2",outfile);
fclose(outfile);
}
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
whee!! yet another dead-end.
had an idea to make a struct then pre-load the entire thing in one fell swoop upon initialization. (would have been a big mess but it would have worked well)
threw together a test:
the compiler threw back this:
sccz80:"testing.c" L:42 Error:#57:Cannot assign to compound auto variable 't'
had an idea to make a struct then pre-load the entire thing in one fell swoop upon initialization. (would have been a big mess but it would have worked well)
threw together a test:
Code: Select all
struct
{
int data[2];
}test;
main()
{
struct test t[2] = {0,1,10,11};
}
sccz80:"testing.c" L:42 Error:#57:Cannot assign to compound auto variable 't'
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
apologies in advance for the copious number of repliesalvin wrote:Ugh. That's really tight for a compiled program. It doesn't seem right that only 8k is available for asm programs... there must be a way to use the full (or larger portion) 24k. The TI target is on my to-do list (and maybe Stef/Dom too I can't speak for them) and maybe we can clear these things up down the line.
I did a compile and found that your code is in the 8k area and the rest is library routines. The fact that you are using printf means a large block of code needs to be attached to handle all the scan conversions even if you don't use them. If you can do without them and can just print raw characters using "fputs()", you will cut down on binary size quite a bit (a couple K I would guess). Rather than using the %d stuff that printf offers you can use the strcpy(), strcat(), itoa(), etc functions in stdlib to build up a string of raw characters to be output with fputs; all these functions are small and are written in asm. This approach, coupled with a table substituted for the switch, will probably make it possible to fit it all in 8k. I'll see if I can cook up an example in the next few days if only for reference if you choose not to go this way (I'm dealing with a broken tooth at the moment which I find very distracting).
About loading data or launching another program... this I can't help without more knowledge of the TI. Stef might be able to help?
Tried what you suggested in the exiting program. Got really close by just using +ti86 and replacing all the printf's with puts. Now I only have to comment out 19 & 20 to get it to compile. Wondering how I can shave a bit of space off from here.
for the sake of my lazyness, i'll just paste the current code in a code block.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern int rand_timer(49161);
uint dice(int numdice, int dsize, int plus);
uint u_rnd(uint range);
void do_treasure(int level);
void printf2(char * text, uint num);
void main()
{
int x;
int level = 0;
int number = 0;
int slurp = 0;
srand((rand_timer & 0xff) * 0x0101);
puts("Encounter level?");
scanf("%d", &level);
puts("Number to roll?");
scanf("%d", &number);
for(x=1;x<=number;x++)
{
do_treasure(level);
//printf("paused: press a key to continue");
//slurp = getk();
}
//wait until something's pressed to present the output
//y=fgetc_cons();
}
void do_treasure(int level)
{
unsigned int roll = 0;
//let the evilness begin
switch(level)
{
case 1:
roll = dice(1,100,0);
if (roll >= 15 && roll <= 29)
{
printf2(" cp",(dice(1,6,0)*1000));
}
else if (roll <= 52)
{
printf2(" sp",(dice(1,8,0)*100));
}
else if (roll <= 95)
{
printf2(" gp",(dice(2,8,0)*10));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,4,0)*10));
}
roll = dice(1,100,0);
if (roll >= 91 && roll <= 95)
{
puts("1 gem");
}
else if (roll <= 100)
{
puts("1 art");
}
roll = dice(1,100,0);
if (roll >= 72 && roll <= 95)
{
puts("1 mundane");
}
else if (roll <=100)
{
puts("1 minor");
}
break;
case 2:
roll = dice(1,100,0);
if (roll >= 14 && roll <= 23)
{
printf2(" cp",(dice(1,10,0)*1000));
}
else if (roll <= 43)
{
printf2(" sp",(dice(2,10,0)*100));
}
else if (roll <= 95)
{
printf2(" gp",(dice(4,10,0)*10));
}
else if (roll <= 100)
{
printf2(" pp",(dice(2,8,0)*10));
}
roll = dice(1,100,0);
if (roll >= 82 && roll <= 95)
{
printf2(" gems",dice(1,3,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,3,0));
}
roll = dice(1,100,0);
if (roll >= 50 && roll <= 85)
{
puts("1 mundane");
}
else if (roll <= 100)
{
puts("1 minor");
}
break;
case 3:
roll = dice(1,100,0);
if (roll >= 12 && roll <= 21)
{
printf2(" cp",(dice(2,10,0)*1000));
}
else if (roll <= 41)
{
printf2(" sp",(dice(4,8,0)*100));
}
else if (roll <= 95)
{
printf2(" gp",(dice(1,4,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,10,0)*10));
}
roll = dice(1,100,0);
if (roll >= 78 && roll <= 95)
{
printf2(" gems",dice(1,3,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,3,0));
}
roll = dice(1,100,0);
if (roll >= 50 && roll <= 79)
{
printf2(" mundane",dice(1,3,0));
}
else if (roll <= 100)
{
puts("1 minor");
}
break;
case 4:
roll = dice(1,100,0);
if (roll >= 12 && roll <= 21)
{
printf2(" cp",(dice(3,10,0)*1000));
}
else if (roll <= 41)
{
printf2(" sp",(dice(4,12,0)*100));
}
else if (roll <= 95)
{
printf2(" gp",(dice(1,6,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,8,0)*10));
}
roll = dice(1,100,0);
if (roll >= 71 && roll <= 95)
{
printf2(" gems",dice(1,4,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,3,0));
}
roll = dice(1,100,0);
if (roll >= 43 && roll <= 62)
{
printf2(" mundane",dice(1,4,0));
}
else if (roll <= 100)
{
puts("1 minor");
}
break;
case 5:
roll = dice(1,100,0);
if (roll >= 11 && roll <= 19)
{
printf2(" cp",(dice(1,4,0)*10000));
}
else if (roll <= 41)
{
printf2(" sp",(dice(1,6,0)*1000));
}
else if (roll <= 95)
{
printf2(" gp",(dice(1,8,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,10,0)*10));
}
roll = dice(1,100,0);
if (roll >= 61 && roll <= 95)
{
printf2(" gems",dice(1,4,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,3,0));
}
roll = dice(1,100,0);
if (roll >= 56 && roll <= 67)
{
printf2(" mundane",dice(1,4,0));
}
else if (roll <= 100)
{
printf2(" minor",dice(1,3,0));
}
break;
case 6:
roll = dice(1,100,0);
if (roll >= 11 && roll <= 18)
{
printf2(" cp",(dice(1,6,0)*10000));
}
else if (roll <= 37)
{
printf2(" sp",(dice(1,8,0)*1000));
}
else if (roll <= 95)
{
printf2(" gp",(dice(1,10,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,12,0)*10));
}
roll = dice(1,100,0);
if (roll >= 57 && roll <= 92)
{
printf2(" gems",dice(1,4,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,4,0));
}
roll = dice(1,100,0);
if (roll >= 55 && roll <= 59)
{
printf2(" mundane",dice(1,4,0));
}
else if (roll <= 99)
{
printf2(" minor",dice(1,3,0));
}
else if (roll <=100)
{
puts("1 medium");
}
break;
case 7:
roll = dice(1,100,0);
if (roll >= 12 && roll <= 18)
{
printf2(" cp",(dice(1,10,0)*10000));
}
else if (roll <= 35)
{
printf2(" sp",(dice(1,12,0)*1000));
}
else if (roll <= 93)
{
printf2(" gp",(dice(2,6,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(3,4,0)*10));
}
roll = dice(1,100,0);
if (roll >= 49 && roll <= 88)
{
printf2(" gems",dice(1,4,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,4,0));
}
roll = dice(1,100,0);
if (roll >= 52 && roll <= 97)
{
printf2(" minor",dice(1,3,0));
}
else if (roll <= 100)
{
puts("1 medium");
}
break;
case 8:
roll = dice(1,100,0);
if (roll >= 11 && roll <= 15)
{
printf2(" cp",(dice(1,12,0)*10000));
}
else if (roll <= 29)
{
printf2(" sp",(dice(2,6,0)*1000));
}
else if (roll <= 87)
{
printf2(" gp",(dice(2,8,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(3,6,0)*10));
}
roll = dice(1,100,0);
if (roll >= 46 && roll <= 85)
{
printf2(" gems",dice(1,6,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,4,0));
}
roll = dice(1,100,0);
if (roll >= 49 && roll <= 96)
{
printf2(" minor",dice(1,4,0));
}
else if (roll <= 100)
{
puts("1 medium");
}
break;
case 9:
roll = dice(1,100,0);
if (roll >= 11 && roll <= 15)
{
printf2(" cp",(dice(2,6,0)*10000));
}
else if (roll <= 29)
{
printf2(" sp",(dice(2,8,0)*1000));
}
else if (roll <= 85)
{
printf2(" gp",(dice(5,4,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(2,12,0)*10));
}
roll = dice(1,100,0);
if (roll >= 41 && roll <= 80)
{
printf2(" gems",dice(1,8,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,4,0));
}
roll = dice(1,100,0);
if (roll >= 44 && roll <= 91)
{
printf2(" minor",dice(1,4,0));
}
else if (roll <= 100)
{
puts("1 medium");
}
break;
case 10:
roll = dice(1,100,0);
if (roll >= 11 && roll <= 24)
{
printf2(" sp",(dice(2,10,0)*1000));
}
else if (roll <= 79)
{
printf2(" gp",(dice(6,4,0)*100));
}
else if (roll <= 100)
{
printf2(" pp",(dice(5,6,0)*10));
}
roll = dice(1,100,0);
if (roll >= 36 && roll <= 79)
{
printf2(" gems",dice(1,8,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,6,0));
}
roll = dice(1,100,0);
if (roll >= 41 && roll <= 88)
{
printf2(" minor",dice(1,4,0));
}
else if (roll <= 99)
{
puts("1 medium");
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 11:
roll = dice(1,100,0);
if (roll >= 9 && roll <= 14)
{
printf2(" sp",(dice(3,10,0)*1000));
}
else if (roll <= 75)
{
printf2(" gp",(dice(4,8,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(4,10,0)*100));
}
roll = dice(1,100,0);
if (roll >= 25 && roll <= 74)
{
printf2(" gems",dice(1,10,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,6,0));
}
roll = dice(1,100,0);
if (roll >= 32 && roll <= 84)
{
printf2(" minor",dice(1,4,0));
}
else if (roll <= 98)
{
puts("1 medium");
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 12:
roll = dice(1,100,0);
if (roll >= 9 && roll <= 14)
{
printf2(" sp",(dice(3,12,0)*1000));
}
else if (roll <= 75)
{
printf2(" gp",(dice(1,4,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,4,0)*100));
}
roll = dice(1,100,0);
if (roll >= 18 && roll <= 70)
{
printf2(" gems",dice(1,10,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,8,0));
}
roll = dice(1,100,0);
if (roll >= 28 && roll <= 82)
{
printf2(" minor",dice(1,6,0));
}
else if (roll <= 97)
{
puts("1 medium");
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 13:
roll = dice(1,100,0);
if (roll >= 9 && roll <= 75)
{
printf2(" gp",(dice(1,4,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,10,0)*100));
}
roll = dice(1,100,0);
if (roll >= 12 && roll <= 66)
{
printf2(" gems",dice(1,12,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(1,10,0));
}
roll = dice(1,100,0);
if (roll >= 20 && roll <= 73)
{
printf2(" minor",dice(1,6,0));
}
else if (roll <= 95)
{
puts("1 medium");
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 14:
roll = dice(1,100,0);
if (roll >= 9 && roll <= 75)
{
printf2(" gp",(dice(1,6,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(1,12,0)*100));
}
roll = dice(1,100,0);
if (roll >= 12 && roll <= 66)
{
printf2(" gems",dice(2,8,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(2,6,0));
}
roll = dice(1,100,0);
if (roll >= 20 && roll <= 58)
{
printf2(" minor",dice(1,6,0));
}
else if (roll <= 92)
{
puts("1 medium");
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 15:
roll = dice(1,100,0);
if (roll >= 4 && roll <= 74)
{
printf2(" gp",(dice(1,8,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(3,4,0)*100));
}
roll = dice(1,100,0);
if (roll >= 10 && roll <= 65)
{
printf2(" gems",dice(2,10,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(2,8,0));
}
roll = dice(1,100,0);
if (roll >= 12 && roll <= 46)
{
printf2(" minor",dice(1,10,0));
}
else if (roll <= 90)
{
puts("1 medium");
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 16:
roll = dice(1,100,0);
if (roll >= 4 && roll <= 74)
{
printf2(" gp",(dice(1,12,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(3,4,0)*100));
}
roll = dice(1,100,0);
if (roll >= 8 && roll <= 64)
{
printf2(" gems",dice(4,6,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(2,10,0));
}
roll = dice(1,100,0);
if (roll >= 41 && roll <= 46)
{
printf2(" minor",dice(1,10,0));
}
else if (roll <= 90)
{
printf2(" medium",dice(1,3,0));
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 17:
roll = dice(1,100,0);
if (roll >= 4 && roll <= 68)
{
printf2(" gp",(dice(3,4,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(2,10,0)*100));
}
roll = dice(1,100,0);
if (roll >= 5 && roll <= 63)
{
printf2(" gems",dice(4,8,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(3,8,0));
}
roll = dice(1,100,0);
if (roll >= 34 && roll <= 83)
{
printf2(" medium",dice(1,3,0));
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 18:
roll = dice(1,100,0);
if (roll >= 3 && roll <= 65)
{
printf2(" gp",(dice(3,6,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(5,4,0)*100));
}
roll = dice(1,100,0);
if (roll >= 5 && roll <= 54)
{
printf2(" gems",dice(3,12,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(3,10,0));
}
roll = dice(1,100,0);
if (roll >= 25 && roll <= 80)
{
printf2(" medium",dice(1,4,0));
}
else if (roll <= 100)
{
puts("1 major");
}
break;
/*
case 19:
roll = dice(1,100,0);
if (roll >= 3 && roll <= 65)
{
printf2(" gp",(dice(3,8,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(3,10,0)*100));
}
roll = dice(1,100,0);
if (roll >= 4 && roll <= 50)
{
printf2(" gems",dice(6,6,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(6,6,0));
}
roll = dice(1,100,0);
if (roll >= 5 && roll <= 70)
{
printf2(" medium",dice(1,4,0));
}
else if (roll <= 100)
{
puts("1 major");
}
break;
case 20:
roll = dice(1,100,0);
if (roll >= 3 && roll <= 65)
{
printf2(" gp",(dice(4,8,0)*1000));
}
else if (roll <= 100)
{
printf2(" pp",(dice(4,10,0)*100));
}
roll = dice(1,100,0);
if (roll >= 3 && roll <= 38)
{
printf2(" gems",dice(4,10,0));
}
else if (roll <= 100)
{
printf2(" art objects",dice(7,6,0));
}
roll = dice(1,100,0);
if (roll >= 25 && roll <= 65)
{
printf2(" medium",dice(1,4,0));
}
else if (roll <= 100)
{
printf2(" major",dice(1,3,0));
}
break;*/
}
}
void printf2(char * text, uint num)
{
char temp[30];
itoa(temp,num);
strcat(temp,text);
puts(temp);
}
//uint == unsigned int
uint dice(int numdice, int dsize, int plus)
{
int x = 0;
uint total = 0;
//better rand routine: (uses more bits of randomness)
// RAND_MAX == constant
// (uint)(((long)(range) * rand()) / (long)(RAND_MAX));
for(x=1; x <= numdice; x++)
{
//total += ((rand() % dsize) + 1);
total += (u_rnd(dsize) + 1);
}
total += plus;
return(total);
}
uint u_rnd(uint range)
{
return (uint)(((long)(range) * rand()) / (long)(RAND_MAX));
}
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
new problem: (semi-related to this so i'll stick it under here)
threw together a quick program to test my latest idea (initializing a whopping huge array with all of my data)
the only problem is that it didn't work.
here's the code:
z88dk spits out this error message:
sccz80:"fnord.c" L:5 Error:#57:Cannot assign to compound auto variable 'test'
threw together a quick program to test my latest idea (initializing a whopping huge array with all of my data)
the only problem is that it didn't work.
here's the code:
Code: Select all
#include <stdio.h>
void main()
{
int test[10] = {1,2,3,4,5,6,7,8,9,10};
for (x=1; x<=10; x++)
{
printf("%d ", x);
}
}
sccz80:"fnord.c" L:5 Error:#57:Cannot assign to compound auto variable 'test'
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
wow.. in a color me confused moment.dom wrote:If you make test[] static then it will work.
This is a limitation of the compiler that is actually quite useful - initialising an array on the stack is quite inefficient compared to static initialisation which just causes the values to be dropped inline.
altered my code thusly:
Code: Select all
#include <stdio.h>
void main()
{
static int test[10] = {1,2,3,4,5,6,7,8,9,10};
int x = 0;
int slurp = 0;
for (x=0; x < 4; x++)
{
printf("%d:%d\n",x, test[x]);
}
//pause: wait before quitting
slurp=fgetc_cons();
}
got frustrated, closed everything down. Pulled out C/C++ book to verify I had the for loop right. Opened everything up again (the folder, my editor of choice, command prompt, Virtual TI) compiled it again. Ran fine...
now it's time to destruction test things: see if it can handle a 880 element int array...
wondering one thing:
from a size perspective, which is smaller, getk or fgetc_cons? not going to be using it for anything other than a "pause" function so functionality doesn't matter
Another easy thing you can do to save on memory is make all variables global (or static) rather than local. Looking at your program this might save a hundred bytes or so.
Local variables are stored on the stack and have to be popped off when used while global variables are stored at fixed memory addresses which are easy for the compiler to pick off with single "LD HL,(nn)" and "LD (nn),HL" instructions.
Also with the array you're playing with, is it possible to make it into a char array? Ints are 2-bytes and chars are 1-byte so this would cut the size in half...
Let us know how close you are after the above change. If you are really close there is a way to reduce the program size by 2 bytes for each printf2() and dice() call by changing these functions to CALLEE linkage but that will involve dipping a bit into assembler which is only worthwhile if the codesize is close. I would say a couple hundred bytes would be saved with a switch to CALLEE linkage for these two functions.
Local variables are stored on the stack and have to be popped off when used while global variables are stored at fixed memory addresses which are easy for the compiler to pick off with single "LD HL,(nn)" and "LD (nn),HL" instructions.
Also with the array you're playing with, is it possible to make it into a char array? Ints are 2-bytes and chars are 1-byte so this would cut the size in half...
Let us know how close you are after the above change. If you are really close there is a way to reduce the program size by 2 bytes for each printf2() and dice() call by changing these functions to CALLEE linkage but that will involve dipping a bit into assembler which is only worthwhile if the codesize is close. I would say a couple hundred bytes would be saved with a switch to CALLEE linkage for these two functions.
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
ok, thanks. i'll just use getk anyway, less to typedom wrote:Looking at libsrc/stdio/ticalc it looks like getk is marginally smaller, though there's probably not that much in it since there's a keymap table used for both functions.
not really. Right now it all fits into memory fine (6.6k of storage spaced used and it does run), i'm just having some issues with some if statements and code not running right...alvin wrote:Another easy thing you can do to save on memory is make all variables global (or static) rather than local. Looking at your program this might save a hundred bytes or so.
Local variables are stored on the stack and have to be popped off when used while global variables are stored at fixed memory addresses which are easy for the compiler to pick off with single "LD HL,(nn)" and "LD (nn),HL" instructions.
Also with the array you're playing with, is it possible to make it into a char array? Ints are 2-bytes and chars are 1-byte so this would cut the size in half...
Let us know how close you are after the above change. If you are really close there is a way to reduce the program size by 2 bytes for each printf2() and dice() call by changing these functions to CALLEE linkage but that will involve dipping a bit into assembler which is only worthwhile if the codesize is close.
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
ok. Code works but i've got one last (cosmetic) concern. How do I clear the screen?
for the curious, here's the code (messy as parts of it are)
for the curious, here's the code (messy as parts of it are)
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//44 per level: 880 total for all 20 levels
/*
format:
a = lower percent
b = upper percent
c = number of dice
d = size of dice
e = multiplier
a b c d e
15, 29, 1, 6, 1000, cp
30, 52, 1, 8, 100, sp
53, 95, 2, 8, 10, gp
96,100, 1, 4, 10, gp
91, 95, 1, 1, gems
96,100, 1, 1, art
72, 95, 1, 1, mundane
96,100, 1, 1, minor
0 , 0 , 0, 0, medium
0 , 0 , 0, 0, major
*/
static int treasure_array[880] = {
15, 29, 1, 6, 1000,
30, 52, 1, 8, 100,
53, 95, 2, 8, 10,
96,100, 1, 4, 10,
91, 95, 1, 1,
96,100, 1, 1,
72, 95, 1, 1,
96,100, 1, 1,
0 , 0 , 0, 0,
0 , 0 , 0, 0,
14, 23, 1,10, 1000,
24, 43, 2,10, 100,
44, 95, 4,10, 10,
96,100, 2, 8, 10,
82, 95, 1, 3,
96,100, 1, 3,
50, 85, 1, 1,
86,100, 1, 1,
0 , 0 , 0, 0,
0 , 0 , 0, 0,
12, 21, 2,10, 1000,
22, 41, 4, 8, 100,
42, 95, 1, 4, 100,
96,100, 1, 4, 10,
78, 95, 1, 3,
96,100, 1, 3,
50, 79, 1, 3,
80,100, 1, 1,
0 , 0 , 0, 0,
0 , 0 , 0, 0,
12, 21, 3,10, 1000,
22, 41, 4,12, 1000,
42, 95, 1, 6, 100,
96,100, 1, 8, 10,
71, 95, 1, 4,
96,100, 1, 3,
43, 62, 1, 4,
68,100, 1, 1,
0 , 0 , 0, 0,
0 , 0 , 0, 0,
11, 19, 1, 4, 10000,
20, 38, 1, 6, 1000,
39, 95, 1, 8, 100,
96,100, 1,10, 10,
61, 95, 1, 4,
96,100, 1, 4,
58, 67, 1, 4,
68,100, 1, 3,
0 , 0 , 0, 0,
0 , 0 , 0, 0,
11, 18, 1, 6, 10000,
19, 37, 1, 8, 1000,
38, 95, 1,10, 100,
96,100, 1,12, 10,
57, 92, 1, 4,
93,100, 1, 4,
50, 55, 1, 4,
60, 99, 1, 3,
100,100,1, 1,
0 , 0 , 0, 0,
12, 18, 1,10, 10000,
19, 35, 1,12, 1000,
36, 93, 2, 6, 100,
94,100, 3, 4, 10,
49, 88, 1, 4,
89,100, 1, 4,
0, 0 , 0, 0,
52, 97, 1, 3,
98,100, 1, 1,
0 , 0 , 0, 0,
11, 15, 1,12, 10000,
16, 29, 2, 6, 1000,
30, 87, 2, 8, 100,
88,100, 3, 6, 10,
46, 85, 1, 6,
86,100, 1, 4,
0, 0 , 0, 0,
49, 96, 1, 4,
97,100, 1, 1,
0 , 0 , 0, 0,
11, 15, 2, 6, 10000,
16, 29, 2, 8, 1000,
30, 85, 5, 4, 100,
86,100, 2,12, 10,
41, 80, 1, 8,
81,100, 1, 4,
0, 0 , 0, 0,
44, 91, 1, 4,
92,100, 1, 1,
0 , 0 , 0, 0,
0, 0 , 0, 0, 0,
11, 24, 2,10, 1000,
25, 79, 6, 4, 100,
80,100, 5, 6, 10,
36, 79, 1, 8,
80,100, 1, 6,
0, 0 , 0, 0,
41, 88, 1, 4,
89, 99, 1, 1,
100,100,1, 1,
0, 0 , 0, 0, 0,
9, 14, 3,10, 1000,
15, 75, 4, 8, 1000,
76,100, 4,10, 10,
25, 74, 1,10,
75,100, 1, 6,
0, 0 , 0, 0,
32, 84, 1, 4,
85, 98, 1, 1,
99,100, 1, 1,
0, 0 , 0, 0, 0,
9, 14, 3,12, 1000,
15, 75, 1, 4, 1000,
76,100, 1, 4, 100,
18, 70, 1,10,
71,100, 1, 8,
0, 0 , 0, 0,
28, 82, 1, 6,
83, 97, 1, 1,
98,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
9, 75, 1, 4, 1000,
76,100, 1,10, 100,
12, 66, 1,12,
67,100, 1,10,
0, 0 , 0, 0,
20, 73, 1, 6,
74, 95, 1, 1,
96,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
9, 75, 1, 6, 1000,
76,100, 1,12, 100,
12, 66, 2, 8,
67,100, 2, 6,
0, 0 , 0, 0,
20, 58, 1, 6,
59, 92, 1, 1,
93,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
4, 74, 1, 8, 1000,
75,100, 3, 4, 100,
10, 65, 2,10,
66,100, 2, 8,
0, 0 , 0, 0,
12, 46, 1,10,
47, 90, 1, 1,
91,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
4, 74, 1,12, 1000,
75,100, 3, 4, 100,
8, 64, 4, 6,
65,100, 2,10,
0, 0 , 0, 0,
41, 46, 1,10,
47, 90, 1, 3,
91,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
4, 68, 3, 4, 1000,
69,100, 2,10, 100,
5, 63, 4, 8,
64,100, 3, 8,
0, 0 , 0, 0,
0, 0 , 0, 0,
34, 83, 1, 3,
84,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
3, 65, 3, 6, 1000,
66,100, 5, 4, 100,
5, 54, 3,12,
55,100, 3,10,
0, 0 , 0, 0,
0, 0 , 0, 0,
25, 80, 1, 4,
81,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
3, 65, 3, 8, 1000,
66,100, 3,10, 100,
4, 50, 6, 6,
51,100, 6, 6,
0, 0 , 0, 0,
0, 0 , 0, 0,
5, 70, 1, 4,
71,100, 1, 1,
0, 0 , 0, 0, 0,
0, 0 , 0, 0, 0,
3, 65, 4, 8, 1000,
66,100, 4,10, 100,
3, 38, 4,10,
39,100, 7, 6,
0, 0 , 0, 0,
0, 0 , 0, 0,
26, 65, 1, 4,
66,100, 1, 3};
typedef struct
{
int lower;
int upper;
int numdice;
int dsize;
int mult;
}coins_type;
typedef struct
{
int lower;
int upper;
int numdice;
int dsize;
int mult;
}bitem;
typedef struct
{
coins_type cp;
coins_type sp;
coins_type gp;
coins_type pp;
bitem gems;
bitem art;
bitem mundane;
bitem minor;
bitem medium;
bitem major;
}t_type;
//yeah yeah, global variables are evil and all that rot
extern int rand_timer(49161);
t_type treasure;
char temp[30];
uint dice(int numdice, int dsize);
uint u_rnd(uint range);
void do_treasure(int level);
void printf2(char * text, uint num);
void get_data(int level);
int get_element(int level, int element);
void main()
{
int x;
int level = 0;
int number = 0;
int slurp = 0;
srand((rand_timer & 0xff) * 0x0101);
puts("Encounter level?");
scanf("%d", &level);
puts("Number to roll?");
scanf("%d", &number);
//alter it because 0 == level 1 and 19 == level 20
level--;
for(x=1;x<=number;x++)
{
itoa(temp,x);
puts(temp);
temp[0]='\0'; //"empty" the string
do_treasure(level);
puts("press a button to continue");
slurp = getk();
}
//wait until something's pressed to present the output
//puts("press a button to quit");
//slurp=getk();
}
void do_treasure(int level)
{
unsigned int roll = 0;
get_data(level);
roll = dice(1,100);
if (roll >= treasure.cp.lower && roll <= treasure.cp.upper)
{
printf2(" cp", (dice(treasure.cp.numdice,treasure.cp.dsize) * treasure.cp.mult));
}
if (roll >= treasure.sp.lower && roll <= treasure.sp.upper)
{
printf2(" sp", (dice(treasure.sp.numdice,treasure.sp.dsize) * treasure.sp.mult));
}
if (roll >= treasure.gp.lower && roll <= treasure.gp.upper)
{
printf2(" gp", (dice(treasure.gp.numdice,treasure.gp.dsize) * treasure.gp.mult));
}
if (roll >= treasure.pp.lower && roll <= treasure.pp.upper)
{
printf2(" pp", (dice(treasure.pp.numdice,treasure.pp.dsize) * treasure.pp.mult));
}
roll = dice(1,100);
if ( (roll >= treasure.gems.lower) && (roll <= treasure.gems.upper) )
{
if ( treasure.gems.dsize == 1)
{
puts("1 gem");
}
else if (treasure.gems.dsize > 1)
{
printf2(" gems",dice(treasure.gems.numdice,treasure.gems.dsize));
}
}
if ( (roll >= treasure.art.lower) && (roll <= treasure.art.upper) )
{
if ( treasure.art.dsize == 1)
{
puts("1 art object");
}
else if (treasure.art.dsize > 1)
{
printf2(" art objects",dice(treasure.art.numdice,treasure.art.dsize));
}
}
roll = dice(1,100);
if ( (roll >= treasure.mundane.lower) && (roll <= treasure.mundane.upper) )
{
if ( treasure.mundane.dsize == 1)
{
puts("1 mundane");
}
else if (treasure.mundane.dsize > 1)
{
printf2(" mundane",dice(treasure.mundane.numdice,treasure.mundane.dsize));
}
}
if ( (roll >= treasure.minor.lower) && (roll <= treasure.minor.upper) )
{
if ( treasure.minor.dsize == 1)
{
puts("1 minor");
}
else if (treasure.minor.dsize > 1)
{
printf2(" minor",dice(treasure.minor.numdice,treasure.minor.dsize));
}
}
if ( (roll >= treasure.medium.lower) && (roll <= treasure.medium.upper) )
{
if ( treasure.medium.dsize == 1)
{
puts("1 medium");
}
else if (treasure.medium.dsize > 1)
{
printf2(" medium",dice(treasure.medium.numdice,treasure.medium.dsize));
}
}
if ( (roll >= treasure.major.lower) && (roll <= treasure.major.upper) )
{
if ( treasure.major.dsize == 1)
{
puts("1 major");
}
else if (treasure.major.dsize > 1)
{
printf2(" major",dice(treasure.major.numdice,treasure.major.dsize));
}
}
}
void get_data(int level)
{
//put code to fetch data with get_element here
treasure.cp.lower = get_element(level,0);
treasure.cp.upper = get_element(level,1);
treasure.cp.numdice = get_element(level,2);
treasure.cp.dsize = get_element(level,3);
treasure.cp.mult = get_element(level,4);
treasure.sp.lower = get_element(level,5);
treasure.sp.upper = get_element(level,6);
treasure.sp.numdice = get_element(level,7);
treasure.sp.dsize = get_element(level,8);
treasure.sp.mult = get_element(level,9);
treasure.gp.lower = get_element(level,10);
treasure.gp.upper = get_element(level,11);
treasure.gp.numdice = get_element(level,12);
treasure.gp.dsize = get_element(level,13);
treasure.gp.mult = get_element(level,14);
treasure.pp.lower = get_element(level,15);
treasure.pp.upper = get_element(level,16);
treasure.pp.numdice = get_element(level,17);
treasure.pp.dsize = get_element(level,18);
treasure.pp.mult = get_element(level,19);
treasure.gems.lower = get_element(level,20);
treasure.gems.upper = get_element(level,21);
treasure.gems.numdice = get_element(level,22);
treasure.gems.dsize = get_element(level,23);
treasure.art.lower = get_element(level,24);
treasure.art.upper = get_element(level,25);
treasure.art.numdice = get_element(level,26);
treasure.art.dsize = get_element(level,27);
treasure.mundane.lower = get_element(level,28);
treasure.mundane.upper = get_element(level,29);
treasure.mundane.numdice = get_element(level,30);
treasure.mundane.dsize = get_element(level,31);
treasure.minor.lower = get_element(level,32);
treasure.minor.upper = get_element(level,33);
treasure.minor.numdice = get_element(level,34);
treasure.minor.dsize = get_element(level,35);
treasure.medium.lower = get_element(level,36);
treasure.medium.upper = get_element(level,37);
treasure.medium.numdice = get_element(level,38);
treasure.medium.dsize = get_element(level,39);
treasure.major.lower = get_element(level,40);
treasure.major.upper = get_element(level,41);
treasure.major.numdice = get_element(level,42);
treasure.major.dsize = get_element(level,43);
}
int get_element(int level, int element)
{
//0 == level 1 2 == level 3, etc... (20 levels, 0-19)
//elements go from 0-43. (44 per level)
int num;
num = 44 * level + element;
return treasure_array[num];
}
void printf2(char * text, uint num)
{
itoa(temp,num);
strcat(temp,text);
puts(temp);
}
//uint == unsigned int
uint dice(int numdice, int dsize)
{
int x = 0;
uint total = 0;
//better rand routine: (uses more bits of randomness)
// RAND_MAX == constant
// (uint)(((long)(range) * rand()) / (long)(RAND_MAX));
for(x=1; x <= numdice; x++)
{
//total += ((rand() % dsize) + 1);
total += (u_rnd(dsize) + 1);
}
return(total);
}
uint u_rnd(uint range)
{
return (uint)(((long)(range) * rand()) / (long)(RAND_MAX));
}
Outputting code 12 should clear the screen and reset the coordinates to the top left:Freakazoid wrote:ok. Code works but i've got one last (cosmetic) concern. How do I clear the screen?
Code: Select all
putchar(12);
-
- Member
- Posts: 23
- Joined: Tue Oct 02, 2007 5:24 pm
woot! thanks for the help everyonedom wrote:Outputting code 12 should clear the screen and reset the coordinates to the top left:Freakazoid wrote:ok. Code works but i've got one last (cosmetic) concern. How do I clear the screen?
Code: Select all
putchar(12);
have a couple more ideas on how to shrink it a bit to make room for a possible addition but I should be able to handle it from here. Should be able to eliminate more if statements there at the cost of a bit more runtime space. (aka: adding more elements to the array )