I’m fairly new to creating adins. I’ve managed to get the Prizm SDK setup on Windows and I’ve created a couple of adins in C, drawing text and pop ups to the screen.
I’m now wondering what the best way is to draw polygons or even sprites to the screen, and also what the best way to clear the screen is so that another frame can be drawn.

Thanks!

Edit: spelling
I'm not sure about drawing sprites, but I can tell you about shapes.

Drawing a rectangle is pretty simple, just use
Code:
void Bdisp_Rectangle(int x1, int y1, int x2, int y2, char color)
(where color is a TEXT_COLOR_*).

The calculator also has syscalls to create lines and circles, but these are not exposed in libfxcg.
However, you can use Bdisp_ShapeBase to draw these. The wiki explains this function, but has an incorrect version of display_shape, the same as used in libfxcg. SimLo explains this struct much better here (he calls it 'TShape').

However, as libfxcg currently includes an incorrect struct for this, you will have to create your own struct as described by SimLo, and then manually call the syscall, like this:

Code:
__asm__(".text; .align 2; .global _ShapeBase; "
        "_ShapeBase: mov.l sc_addr, r2; mov.l 1f, r0; "
        "jmp @r2; nop; 1: .long 0x1c7; "
        "sc_addr: .long 0x80020070");
ShapeBase(0, struct_ptr, COLOR_GREEN, 1, 0, 0);


You also asked what to do for clearing the screen.
Well, the most efficient thing to do is to not clear the screen, and only set areas to white if they are not being overridden with other colours.
If you need to, there is a syscall called Bdisp_AllClr_VRAM() which will do the trick.
However, it is somewhat slow as it writes white to every pixel individually, which is not very fast, as the processor can write many bits at once.
For a more efficent version, read this wiki article.

Another thing to note is that I explained drawing shapes and clearing the VRAM. This means that the display isn't actually updated. To do this, run Bdisp_PutDisp_DD(), or GetKey() (which runs Bdisp_PutDisp_DD()), or if you want to be able to execute code whilst this is happening, check out the wiki article on Non-blocking DMA. The benefit of this is that you can change multiple things and show them at once, reducing the amount of screen writing done, and not showing things bit-by-bit to the user. There are usually ways of drawing directly to the screen, let us know if you want to know about these.

Let us know if any of this didn't make sense, or you have further questions.

EDIT: before the __asm__ function call, you also need to declare the function prototype, i.e.

Code:
void ShapeBase( unsigned char*work, struct TShape *shape, int color, int line_width, int zero1, int zero2 );
This looks great thank you!

I’ll try it tomorrow when I’m free and get back to you if I have any questions.
Great. I haven't specifically tested the snippets I wrote, but they should work.
I have written some code to try and display a rectangle using the snippets you gave me, but when i run the make.bat file I get these two messages:

...\AppData\Local\Temp\ccZdHTcS.s: Assembler messages:
...\AppData\Local\Temp\ccZdHTcS.s: Error: .size expression for _main does not evaluate to a constant
make[1]: *** [.../Documents/PrizmSDK_(0.5.2)/toolchain/prizm_rules:64: main.o] Error 1
make: *** [Makefile:108: all] Error 2

I'm not completely sure what it's telling me I've done wrong, so any help would be appreciated

This is my code:

Code:

#include <fxcg/display.h>
#include <fxcg/keyboard.h>

struct TShape{
    unsigned int x1;
    unsigned int y1;
    unsigned int x2;
    unsigned int y2;
    unsigned char f[4];
    unsigned int on_bits;
    unsigned int off_bits;
};

void ShapeBase( unsigned char*work, struct TShape *shape, int color, int line_width, int zero1, int zero2 );

int main(void) {

    struct TShape info = {1, 1, 3, 3, {2, 5, 1, 1}, 0, 0};

    __asm__(".text; .align 2; .global _ShapeBase; "
        "_ShapeBase: mov.l sc_addr, r2; mov.l 1f, r0; "
        "jmp @r2; nop; 1: .long 0x1c7; "
        "sc_addr: .long 0x80020070");
    ShapeBase(0, &info, COLOR_GREEN, 1, 0, 0);

    int key;
    while (1)
    {
        GetKey(&key);
    }
    return 0;
}
Ah, my bad.

I have done some testing and fixed the problem.
First, you probably are, but make sure you are using C not C++ (this created an error for me).

Then, you can use variadic arguments (i.e. don't specify them) for the ShapeBase function.
I also changed the way the TShape struct was defined (idk if this helped).
Anyway, the following code compiles on my machine:


Code:

#include <fxcg/display.h>
#include <fxcg/keyboard.h>

void ShapeBase();

typedef struct {
  unsigned int x1;
  unsigned int y1;
  unsigned int x2;
  unsigned int y2;
  unsigned char f[4];
  unsigned int on_bits;
  unsigned int off_bits;
} TShape;

__asm__(".text; .align 2; .global _ShapeBase; "
        "_ShapeBase: mov.l sc_addr, r2; mov.l 1f, r0; "
        "jmp @r2; nop; 1: .long 0x1c7; "
        "sc_addr: .long 0x80020070");

int main(void) {

  TShape info = {1, 1, 3, 3, {2, 5, 1, 1}, 0, 0};
  unsigned char work[1];
  work[0] = 0;

  ShapeBase(work, &info, COLOR_GREEN, 1, 0, 0);

  int key;
  while (1) {
    GetKey(&key);
  }
  return 0;
}


Let me know if there are any problems.
If it doesn't work on the calculator, try changing the 'work[0] = 0' statement to 'work[0] = 1', I'm not sure which it is supposed to be...
Could you tell me what the __asm__ line does?
It's a rather dirty way to define the syscall. Essentially the real ShapeBase is an OS-provided function and the way to call it is a little unusual. This __asm__ statement defines a wrapper ShapeBase() function which can be called normally from C code and performs the unusual call sequence to get into the real ShapeBase.
  
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