This is my code:

Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
#include <HEAP_syscalls.h>
 
int main(void) {
   int key;
     
        Bdisp_AllClr_VRAM();
      Bdisp_PutDisp_DD();
   while (1) {
        GetKey(&key);
      int i = 0;
      int* mal;
      switch (key) {
         locate_OS(2, 2);
         Print_OS((unsigned char*)"  Test",TEXT_MODE_NORMAL,0);
         mal = malloc(1);
         if(mal != 0) {
            i++;
         }
      }
      Bdisp_PutDisp_DD();
   }
 
   return 0;
}


It currently won't display anything, and I'm confused as to why. Eventually, I want it to print i out on the screen.
If you think of z80 ASM, we have the equivalents:

:: Bdisp_AllClr_VRAM() is like _clrlcdfull
:: Bdisp_PutDisp_DD() is like iFastCopy
:: Print_OS is like _puts

Therefore, I suggest trying a Bdisp_PutDisp_DD() right after your Print_OS. I'm not sure why you're displaying right after you clear the screen.
Thanks for the equivalents. I'm still getting nothing displayed with this code:

Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
#include <HEAP_syscalls.h>
 
int main(void) {
   int key;
     
        Bdisp_AllClr_VRAM();
   while (1) {
        GetKey(&key);
      int i = 0;
      int* mal;
      switch (key) {
         locate_OS(2, 2);
         Print_OS((unsigned char*)"  Test",TEXT_MODE_NORMAL,0);
         Bdisp_PutDisp_DD();
         mal = malloc(1);
         if(mal != 0) {
            i++;
         }
      }
   }
 
   return 0;
}
Any reason why you're using locate/Print instead of PrintXY, which I know works very nicely? It's PrintXY(x,y,string,mode,color). Also, isn't color 0 white? (edit: nope, it's black).
Code changed to this:

Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
#include <HEAP_syscalls.h>
 
int main(void) {
   int key;
     
        Bdisp_AllClr_VRAM();
   while (1) {
        GetKey(&key);
      int i = 0;
      int* mal;
      switch (key) {
         PrintXY(2,2,(char*)"  Test",TEXT_MODE_NORMAL,TEXT_COLOR_BLACK);
         Bdisp_PutDisp_DD();
         mal = malloc(1);
         if(mal != 0) {
            i++;
         }
      }
   }
 
   return 0;
}

Still nothing.
You have your code inside a switch statement without any case statements, so it doesn't run at all.

edit: that could be a clever (ab)use of the switch keyword if it were done intentionally, which I don't think it was in this case. Smile
... If you felt the world shake, that was me hitting my head like an idiot. Thanks Christop for pointing out an obvious mistake.
This is my current code, which still doesn't work:

Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
#include <HEAP_syscalls.h>
 
int main(void) {
   int key;
     
        Bdisp_AllClr_VRAM();
   while (1) {
        GetKey(&key);
      int i = 0;
      int* mal;
      char* text;
      itoa(i,text);
      Bdisp_AllClr_VRAM();
      PrintXY(2,2,text,TEXT_MODE_NORMAL,TEXT_COLOR_BLACK);
      Bdisp_PutDisp_DD();
      mal = malloc(1);
      if(mal != 0) {
         i++;
      }
      switch(key) {
      
      }
   }
 
   return 0;
}
I'm guessing that itoa takes a char buffer as its second argument. If so, you need to allocate space for it. The "text" variable is a pointer that can point to anything since it wasn't initialized, so you are in fact trashing some unknown piece of memory.

The easiest fix is to change char* text to char text[12] (12 characters is enough space for the decimal representation of a signed 32-bit integer plus the terminating nul byte).

Edit: also, "i" will always be 0 because it's defined and initialized at the beginning of the loop. Move "int i = 0;" outside the loop.
I'm really feeling dumb with all of these programming mistakes. All of these should have been instantly obvious to me. This is my current working code:

Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
#include <HEAP_syscalls.h>
 
int main(void) {
   int key;
    int count = 0;
   int i;
   int* mal;
   char text[14];
   Bdisp_AllClr_VRAM();
   int inc = 1;
   while (1) {
      Bdisp_AllClr_VRAM();
      PrintXY(1,1,(char*)"  Test",TEXT_MODE_NORMAL,TEXT_COLOR_BLACK);
      itoa(count,text);
      for(i=14; i>1; i--) {
         text[i] = text[i-2];
      }
      text[0] = " ";
      text[1] = " ";
      PrintXY(2,2,text,TEXT_MODE_NORMAL,TEXT_COLOR_BLACK);
      Bdisp_PutDisp_DD();
      mal = malloc(inc);
      if(mal != 0) {
         count += inc;
      }
      /**
      GetKey(&key);
      switch(key) {
      
      }
      */
   }
 
   return 0;
}


Thanks for your help guys!
That is not entirely true. Let me first point out that upon every malloc, the OS has to include a header for it. That header takes up quite a bit of space compared to 1 byte Smile Therefore, you need to malloc a large amount of data and decrease that amount until you get a valid pointer (around 120KB).

<edit>

You removed the line saying you can only get ~61KB malloc'd D-:
AHelper wrote:
That is not entirely true. Let me first point out that upon every malloc, the OS has to include a header for it. That header takes up quite a bit of space compared to 1 byte Smile Therefore, you need to malloc a large amount of data and decrease that amount until you get a valid pointer (around 120KB).

<edit>

You removed the line saying you can only get ~61KB malloc'd D-:

Indeed, because I found something interesting with it that I'm posting in a new topic.
Personally, I don't know why we want to get as much space out of a supposed 128KB add-in stack when there is a 512 add-in heap available Wink My game is using it and has no issues at all
We're using malloc, so wouldn't it be from the heap? or did you switch those by accident?
oh, oops... I got those swapped >.<
AHelper wrote:
oh, oops... I got those swapped >.<

So there's a 512KB stack? That's interesting.
Quote:
EDIT: Yeah, we can only malloc 61 Kib or 65536 bytes.
65536 bytes is 64KiB, actually, since 1KiB = 1024 bytes and 65536/1024 = 64. Smile Either way, I'm positive that figure is wrong.

Edit: Heh, you already retconned that.
About printing a number, you can simply make a function like this :

Code:
void PrintInt(unsigned int n)
{
   char str[11]="0";
   int i, l=0;
   for(i=n ; i ; i/=10)
      l++;
   for(i=n ; i ; i/=10)
      str[--l] = i%10+'0';
   Print_OS(str, 0, 0);
}


About malloc, like I said in another topic, you can allocate 131060 bytes max.
There's an itoa syscall, no need to do it yourself.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement