Login
Back to forumReply to this topicGo to last reply

Posted By

Harry Potter
on 2025-03-22
19:18:07
 Help needed w/ TmpCreatP4

Hi! I have a program for several systems called Template Creator. It is a utility to create, handle, organize and use template files. I have DOS, Windows and C64 and 128 versions at https://sourceforge.net/projects/tmpcreat/files/. I'm trying to port it to the Plus4 but am getting garbage on the main menu when I go up from the top choice. Following is the code that handles displaying the menu:

-------------------------
/* Display pull-down menu with options in menuitems[] at (xloc, yloc) in
* specified len. and get # selection from user.
* xlen and ylen are assumed to be correct.
* This routine doesn't clear the screen.
*/
unsigned char __fastcall__ pulldown (char** menuitems,
unsigned char xloc,
unsigned char yloc,
unsigned char xlen,
unsigned char ylen)
{
//unsigned char i;
//fldzp.ptrchr[0]=yloc; /* Top of menu. */
//fldzp.ptrchr[1]=ylen;//yloc-1; /* # options in menu. */
//leftwindow=xloc; //X-offset to menu text location.
//widwindow=xlen; //Width of menu entries.
fldzp.sx=0;
/* Draw the border around the menu. */
//drawborder (xloc,yloc,xlen,ylen);
/* Write menu options. xlen and ylen are assumed to be correct. */
while (1)
{
//Set to unselected color.
//WBck();
reversoff();
textcol=menucolor;
for (fldzp.i=0; fldzp.i {
/* Write menu option. */
//Function clears the text on screen then fills it with
//with the text given in Parameter #4.
//DrawField (leftwindow, fldzp.i+fldzp.ptrchr[0], widwindow, menuitems[fldzp.i]);
gotoxy(leftwindow, fldzp.i+fldzp.ptrchr[0]); prints (menuitems[fldzp.i]);
//getkey();
}
//Hilight and print current entry.
//WHi();
textcol=menuhicolor;
reverson();
//revers(1);
//DispMenuOp (s+top, menuitems[s]);
//DrawField (leftwindow, fldzp.sx+fldzp.ptrchr[0], widwindow, menuitems[fldzp.sx]);
gotoxy(xloc, fldzp.sx+yloc); prints (menuitems[fldzp.sx]);
//}
//Get key press.
switch (getkey())
{
case CH_CURS_UP:
//If up, decrease current item # w/ wrap-around.
--fldzp.sx;
if ((signed char)fldzp.sx<0) fldzp.sx+=ylen;
break;
case CH_CURS_DOWN:
//If down, increase.
// fldzp.sx=(++fldzp.sx)%fldzp.ptrchr[1];
++fldzp.sx; if (fldzp.sx>=ylen) fldzp.sx=0;
break;
case CH_ENTER:
//If Enter, return item #.
return fldzp.sx;
case CH_ESC:
#ifdef CH_STOP
case CH_STOP:
#endif
//If cancel, return -1 for cancel.
reversoff();
return -1;
}
//This function will *not* clean up the screen upon exit.
}
}
------------------

Any help would be appreciated.
Posted By

gerliczer
on 2025-03-23
04:31:38
 Re: Help needed w/ TmpCreatP4

Two remarks. Publish clean code without trash if you want people to read it. Skipping not working leftover code is a bother. Publish code that reproduces your issue. Without that it could be anyone's guess what goes wrong.
Posted By

SukkoPera
on 2025-03-23
10:57:01
 Re: Help needed w/ TmpCreatP4

case CH_CURS_UP:
//If up, decrease current item # w/ wrap-around.
--fldzp.sx;
if ((signed char)fldzp.sx<0) fldzp.sx+=ylen;
break;


I don't know if it is the cause of the issue, but this code is suspicious. Casting signedness is always tricky, so if you want a variable to be able to go below zero, make it signed to begin with. If you want to keep it unsigned, then use different code, for example:


case CH_CURS_UP:
//If up, decrease current item # w/ wrap-around.
if (fldzp.sx == 0) {
fldzp.sx = ylen - 1;
} else {
--fldzp.sx;
}
break;
Posted By

Harry Potter
on 2025-03-23
12:46:59
 Re: Help needed w/ TmpCreatP4

Sukkopera: That seems to be one of the issues. What I was trying to do was, if the variable is negative, perform a wrap-around to the bottom, as a negative value is not valid. I will try your suggestion now. Thank you.
Posted By

Harry Potter
on 2025-03-23
12:54:04
 Re: Help needed w/ TmpCreatP4

I tried your suggestion, but it didn't work. sad I'll try patching the function code from another version, as other versions work.
Posted By

Harry Potter
on 2025-03-23
13:25:19
 Re: Help needed w/ TmpCreatP4

I did, and now it works. happy


Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2025. Support Plus/4 World on Patreon