Author Topic: [68k] Function not working as expected  (Read 3368 times)

0 Members and 1 Guest are viewing this topic.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
[68k] Function not working as expected
« on: December 25, 2012, 06:08:25 pm »
Whenever I call enableUndo for this program (from a menu), I get light gray vertical lines as on the image attached. I think I did everything right, so here is the excerpt I am having trouble with:
Code: [Select]
typedef struct {
void* prevl,*prevd;
char canUndo:1,isUndone:1;
} UndoInfo;
void* allocBUB(void)
{
void* buffer=NULL;
if (!(buffer=calloc(LCD_SIZE,1)))
{
dlgError(DMA_ERROR,MEMALLOC_FAIL);
return NULL;
}
return buffer;
}
int allocGBUB(void** lbuff,void** dbuff)
{
if (!(*lbuff=allocBUB()))
{
return 0;
}
if (!(*dbuff=allocBUB()))
{
free(*lbuff);
return 0;
}
return 1;
}
void enableUndo(UndoInfo* p) {
GrayOff();
SetIntVec(AUTO_INT_1,I1);
SetIntVec(AUTO_INT_5,I5);
//*v: this may be the cause of the gray bars
p->canUndo=allocGBUB((void**)p,(void**)((char*)p+4));
SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
SetIntVec(AUTO_INT_5,DUMMY_HANDLER);
GrayOn();
}
I would appreciate any assistance given!
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [68k] Function not working as expected
« Reply #1 on: December 26, 2012, 02:26:10 am »
I haven't looked at the entire code base yet, but three stylistic notes on your excerpt:
* why are you killing gray mode before allocating data, and activating it back later ? :)
* you're using a bit field in struct UndoInfo, but bit fields are inefficient (and once in every while, when faced with bit fields, compilers generate incorrect code which corrupts memory). As your struct needs padding anyway, why not using two chars, instead of a char containing two bits ?
* "DMA" is seldom used for abbreviating Dynamic Memory Allocation, it usually stands for Direct Memory Access.

One of the causes of screen corruption with a repeatable pattern is a stack overflow... but here, you're precisely not allocating on the stack. Another cause is an invalid argument passed to a string drawing routine, but that seems less likely.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: [68k] Function not working as expected
« Reply #2 on: December 26, 2012, 12:26:13 pm »
1. The dialog boxes are supposed to be in black-and-white, not some shade of gray. Does it matter whether I kill gray mode before allocating data or after?
2. Sure.
3. ...
4. Maybe I've used a lot of stack space for, maybe, function calling?

Edit: I changed canUndo and isUndone to regular char types, and the repeatable pattern no longer occurs.
« Last Edit: December 26, 2012, 12:32:51 pm by blue_bear_94 »
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [68k] Function not working as expected
« Reply #3 on: December 26, 2012, 03:37:36 pm »
Indeed, AMS dialogs just don't work in grayscale mode. But what about pushing most of the code of enableUndo() - and possibly similar routines - to the error path (dlgError()) ?
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: [68k] Function not working as expected
« Reply #4 on: December 26, 2012, 03:56:23 pm »
But what about pushing most of the code of enableUndo() - and possibly similar routines - to the error path (dlgError()) ?

Excuse me? (I don't understand what you mean.)
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの