Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » Re: Looking moremore optimizations!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Looking moremore optimizations! [message #375019] Thu, 25 October 2018 23:39 Go to next message
Anonymous
Karma:
Originally posted by: nospam.Niklas.Lindholm

HP> Please ignore the commented-out code. It's left-overs from
HP> debugging. :(

The human brain is not a compiler that easily skips commented out lines. It
will still see everything and having that much noise in the code makes it
extremely hard to read. If you want to improve code you need to be able to read
what's already there. And in this case you can't really.
Re: Looking moremore optimizations! [message #375037 is a reply to message #375019] Sat, 27 October 2018 08:21 Go to previous messageGo to next message
Harry Potter is currently offline  Harry Potter
Messages: 1304
Registered: March 2012
Karma: 0
Senior Member
Let me try again:
-------------------------
void vLook (void)//char Itm1)
{
static void (*func)();
if (Itm1!=0xFF) {
if (SearchInvPlayer () || SearchInvRoom ())
{
if ((s=hidereadw((void*)&Item[Itm1].Info))==0) {
printscr ("No help available for that item.");
return;
}
printh (s);
//printh ((void*)&Item[Itm1].Info);
//else
// ;
//return;
//}
}
else {
//puts (Message[msgItemNotAvail]);
printmsg(msgItemNotAvail);
}
return;
}
CurRoomInv=Player.RoomInv[CRoom];
CRm=(void*)&Room[CRoom];
printh ((char*)hidereadw((void*)&CRm->Desc));
func=hidereadw((void*)&CRm->RoomHandler);
(*func) ();
printcr();

for (i=0; i<8 && (c=CurRoomInv[i])!=0xFF;++i) {
prints ("There is a ");
printh (hidereadw((void*)&Item[/*CurRoomInv[i]*/c].Name));
printscr (" here.");
}
if (i)
printcr();
}

void vLook2 (void)
{
Itm1=-1;
vLook ();

}

void vGo ()//char Itm1)
{
if (Itm1>=160 && Itm1<164) {
j = Itm1&0x0F; //goto godir;
if ((i=CRm->NextRoom[j])==0xFF) {
printmsg(msgCantGoThere); return;
}
CRoom = i; goto exitgood;
}
switch (Itm1)
{
case iTeleporter:
if (!SearchInvRoom()) {
printscr ("There's no teleporter here.");
return;
}
Player.ExitRoom = CRoom;
CRoom = rTeleporter;
goto exitgood;
}
printmsg(msgCantGoThere); return;
godir:
exitgood:
Player.ExitRoom =-1; vLook2();
}
------------------------------------
void main (void)
{
//static unsigned char c;
//static char Input [38];
//static unsigned char Vrb;//, Itm, ItmNum, CurPos;
//static unsigned char CurPos;//IncPos;
//static unsigned char i;
static void (* vfunc) ();
//printf ("%X\n", &Item[0].Name);
//cgetc();
//bordercolor(8); bgcolor (1);
//textcolor (4);
brdrcol=8;
backcol=1;
//textcol=4;
/*123456789012345678901234567890123456789*/
//clrscr ();
printscr("\f\n\x9cWelcome to \"Adventures on Planet Smir\n"
"III, Episode 1, v .10\" for the Commo-\n"
"dore 64 and emulators, created with cc65"
"by Joseph Rose.\n\n"

"Type INTRO during the game for\n"
"instructions.\n\n"
"Do you want to load a saved game?");
switch (getkey ())
{
case 'd': ++c;
case 'y': ++c;
}
InitPlayer ();
if (c==2) {
printscr ("Debug mode: Enter room #"); GetInput (Input, 4);
for (CurPos=0;Input[CurPos]; ++CurPos)
{
CRoom=(((CRoom<<2)+CRoom)<<1)+(Input[CurPos]&0xF);
}
}
vLook2 ();
while (1)
{
DispScoreBoard();
if (!GetInput (Input,38)) continue;
Vrb = FindVerb (/*Input*/);
if (Vrb == 0xFF) {
prints ("I don't know how to ");
prints (Input);
printperiod ();
continue;
}
while (Input[CurPos]==32) ++CurPos;
if (Input[CurPos]) //Itm1=-1; goto runverb;}
{
if ((Itm1 = FindItem (&Input[CurPos]))==0xFF ) {
prints ("I don't know what a ");
prints (&Input[CurPos]);
printscr (" is.");
continue;
}
} else Itm1=0xFF;
vfunc=hidereadw((void*)&Verb[Vrb].vdo);
(*vfunc) ();
}
}
-----------------------
Does this help? :)

BTW, if necesssary, I can supply some of the variables' purposes.
Re: Looking moremore optimizations! [message #375628 is a reply to message #375037] Thu, 08 November 2018 13:04 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Herr Doktor

I realize I'm jumping into the middle of a conversation and it isn't
my intention to derail it. What jumps out at me from your code is the
lack of comments. It's been years since I did any programming but
when I did I always commented extensively. I also use many small
modules rather than one huge source file. Then the main program
becomes just the flow of logic and decision with calls to the
appropriate modules as required.

I find that writing in this way makes things much easier all the way
around, all aspects.

You say your program is going to be a big one. They can become
unwieldy pretty fast when good organizing techniques are not used.
On Sat, 27 Oct 2018 05:21:07 -0700 (PDT), Harry Potter
<rose.joseph12@yahoo.com> wrote:

> Let me try again:
> -------------------------
> void vLook (void)//char Itm1)
> {
> static void (*func)();
> if (Itm1!=0xFF) {
> if (SearchInvPlayer () || SearchInvRoom ())
> {
> if ((s=hidereadw((void*)&Item[Itm1].Info))==0) {
> printscr ("No help available for that item.");
> return;
> }
> printh (s);
> //printh ((void*)&Item[Itm1].Info);
> //else
> // ;
> //return;
> //}
> }
> else {
> //puts (Message[msgItemNotAvail]);
> printmsg(msgItemNotAvail);
> }
> return;
> }
> CurRoomInv=Player.RoomInv[CRoom];
> CRm=(void*)&Room[CRoom];
> printh ((char*)hidereadw((void*)&CRm->Desc));
> func=hidereadw((void*)&CRm->RoomHandler);
> (*func) ();
> printcr();
>
> for (i=0; i<8 && (c=CurRoomInv[i])!=0xFF;++i) {
> prints ("There is a ");
> printh (hidereadw((void*)&Item[/*CurRoomInv[i]*/c].Name));
> printscr (" here.");
> }
> if (i)
> printcr();
> }
>
> void vLook2 (void)
> {
> Itm1=-1;
> vLook ();
>
> }
>
> void vGo ()//char Itm1)
> {
> if (Itm1>=160 && Itm1<164) {
> j = Itm1&0x0F; //goto godir;
> if ((i=CRm->NextRoom[j])==0xFF) {
> printmsg(msgCantGoThere); return;
> }
> CRoom = i; goto exitgood;
> }
> switch (Itm1)
> {
> case iTeleporter:
> if (!SearchInvRoom()) {
> printscr ("There's no teleporter here.");
> return;
> }
> Player.ExitRoom = CRoom;
> CRoom = rTeleporter;
> goto exitgood;
> }
> printmsg(msgCantGoThere); return;
> godir:
> exitgood:
> Player.ExitRoom =-1; vLook2();
> }
> ------------------------------------
> void main (void)
> {
> //static unsigned char c;
> //static char Input [38];
> //static unsigned char Vrb;//, Itm, ItmNum, CurPos;
> //static unsigned char CurPos;//IncPos;
> //static unsigned char i;
> static void (* vfunc) ();
> //printf ("%X\n", &Item[0].Name);
> //cgetc();
> //bordercolor(8); bgcolor (1);
> //textcolor (4);
> brdrcol=8;
> backcol=1;
> //textcol=4;
> /*123456789012345678901234567890123456789*/
> //clrscr ();
> printscr("\f\n\x9cWelcome to \"Adventures on Planet Smir\n"
> "III, Episode 1, v .10\" for the Commo-\n"
> "dore 64 and emulators, created with cc65"
> "by Joseph Rose.\n\n"
>
> "Type INTRO during the game for\n"
> "instructions.\n\n"
> "Do you want to load a saved game?");
> switch (getkey ())
> {
> case 'd': ++c;
> case 'y': ++c;
> }
> InitPlayer ();
> if (c==2) {
> printscr ("Debug mode: Enter room #"); GetInput (Input, 4);
> for (CurPos=0;Input[CurPos]; ++CurPos)
> {
> CRoom=(((CRoom<<2)+CRoom)<<1)+(Input[CurPos]&0xF);
> }
> }
> vLook2 ();
> while (1)
> {
> DispScoreBoard();
> if (!GetInput (Input,38)) continue;
> Vrb = FindVerb (/*Input*/);
> if (Vrb == 0xFF) {
> prints ("I don't know how to ");
> prints (Input);
> printperiod ();
> continue;
> }
> while (Input[CurPos]==32) ++CurPos;
> if (Input[CurPos]) //Itm1=-1; goto runverb;}
> {
> if ((Itm1 = FindItem (&Input[CurPos]))==0xFF ) {
> prints ("I don't know what a ");
> prints (&Input[CurPos]);
> printscr (" is.");
> continue;
> }
> } else Itm1=0xFF;
> vfunc=hidereadw((void*)&Verb[Vrb].vdo);
> (*vfunc) ();
> }
> }
> -----------------------
> Does this help? :)
>
> BTW, if necesssary, I can supply some of the variables' purposes.
Re: Looking moremore optimizations! [message #375785 is a reply to message #375628] Sat, 10 November 2018 12:10 Go to previous messageGo to next message
Pekka Takala is currently offline  Pekka Takala
Messages: 73
Registered: March 2012
Karma: 0
Member
On 08.11.2018 20:04, Herr Doktor wrote:
> I realize I'm jumping into the middle of a conversation and it isn't
> my intention to derail it. What jumps out at me from your code is the
> lack of comments. It's been years since I did any programming but
> when I did I always commented extensively. I also use many small
> modules rather than one huge source file. Then the main program
> becomes just the flow of logic and decision with calls to the
> appropriate modules as required.
>
> I find that writing in this way makes things much easier all the way
> around, all aspects.

Also, creating the game as modules helps you if you exceed the usable
memory. You can then split things if they do not depend on each other
and load them from disk/tape/cartridge when needed. If the code is in
one big snippet, the splitting is WAY more difficult to do if needed.

Commenting is important- what does what. The comments DO NOT take any
space after compiling, the compiler just skips them completely. It helps
you to read the code afterwards and makes guessing less needed. And
also, if you make the code as modules, you can support various hardware
easier since you can load various pieces to memory depending on hardware.

And, when you have tasks those are common, in their own files, you
lessen the trouble of getting hard-to-repair bugs. You can parametrise
the functions so that you can use same code to little various tasks,
still being similar. For example, you can read keyboard with its own
function. If parametrised, you can restrict the keys needed to read, so
you do not need to check them in later code since the keyboard code does
that for you already. This method makes the code less prone to exploits,
although on commodore platform the exploit avoiding is not so important
than on platforms those are connectable to Internet. Still practicing
this makes you better coder on other platforms also.
Re: Looking moremore optimizations! [message #375789 is a reply to message #375785] Sat, 10 November 2018 14:29 Go to previous message
Harry Potter is currently offline  Harry Potter
Messages: 1304
Registered: March 2012
Karma: 0
Senior Member
On Saturday, November 10, 2018 at 12:10:24 PM UTC-5, Pekka Takala wrote:
> Also, creating the game as modules helps you if you exceed the usable
> memory. You can then split things if they do not depend on each other
> and load them from disk/tape/cartridge when needed. If the code is in
> one big snippet, the splitting is WAY more difficult to do if needed.
>
Well, the game currently *is* modularized. In fact, the executable is currently split into multiple parts, but, currently, all parts are loaded in at once. The main executable loads first, then two stubs loaded into the first k, then some strings and misc. data behind the I/O and kernal ROM to be accessed using my cc65 Hidden64 library.

> Commenting is important- what does what. The comments DO NOT take any
> space after compiling, the compiler just skips them completely. It helps
> you to read the code afterwards and makes guessing less needed. And
> also, if you make the code as modules, you can support various hardware
> easier since you can load various pieces to memory depending on hardware.
>
I used to comment extravagantly but recently stopped. I don't know why. :(

> And, when you have tasks those are common, in their own files, you
> lessen the trouble of getting hard-to-repair bugs. You can parametrise
> the functions so that you can use same code to little various tasks,
> still being similar. For example, you can read keyboard with its own
> function. If parametrised, you can restrict the keys needed to read, so
> you do not need to check them in later code since the keyboard code does
> that for you already. This method makes the code less prone to exploits,
> although on commodore platform the exploit avoiding is not so important
> than on platforms those are connectable to Internet. Still practicing
> this makes you better coder on other platforms also.

Well, I have my own input routine called AltInput for cc65. It is a front-end to my CBMSimpleIO library. Both are at https://sourceforge.net/projects/cc65extra/files/ui/.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Kanet updates GEOS Megapatch, geoDOS 64, GeoConvert
Next Topic: 1571 SPEED ADJUSTMENT FOR SUPERCARD-RAMBOARD NEEDED
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Mar 28 14:54:45 EDT 2024

Total time taken to generate the page: 0.10203 seconds