When KermM started making progress with Graph3DP and issues kept popping up about the math engine (it was made for 16KB of RAM and ROM Razz), I decided I should go looking for something more powerful. I settled on giac, however when looking at the requirements, STL containers and other C++ features made me want to port libstdc++.

Thanks to the progress on libc functions and loads of gcc poking, I now have libsupc++ and libgcc compiled (using sjlj exception handler code, DWARF2 is broken on the prizm for whatever reason), which let me compile uClibc++ as a drop-in replacement for gcc's libstdc++.

Let me just give you an example of what you can do now:
Code:
#include <iostream>
#include <fxcg/display.h>
#include <fxcg/keyboard.h>
using namespace std;

void test(int x)
{
  if(x == 0)
    throw string("Zero found!");
}
int main()
{
  int i = 3;

  try
  {
    while(1)
    {
      test(i);
      i--;
    }
  }
  catch(string e)
  {
    PrintXY(1,1,"  Caught exception:", 0, 0);
    PrintXY(1,2,string("  ").append(e).c_str(), 0, 0);  // Fun fun fun!
    int key;
    while(1) GetKey(&key);
  }
  catch(...)
  {
    PrintXY(1,1,"  Bad exception!", 0, 0); // Doesn't execute, as expected!
   
    int key;
    while(1) GetKey(&key);
  }
}

The Prizm happily prints out the intended exception message. It seems most things in libuClibc++ work. STL containers work, as you can already see. cout (and probably other file access) doesn't work as it having buffering issues. I will run tests on the rest of the container types, fix file IO, give cout more control, and move on.

Very Happy
Sorry if I just missed something but how is file i/o going?


This is great. This will allow porting of even more programs and increased power for this great calc Thanks for doing this
File I/O is improving nicely, and if you take a look on the Wiki, you'll see a bit of information on using it. Much of the I/O stuff is still in flux as libc and libfxcg continue to grow and evolve, though:
http://prizm.cemetech.net/index.php?title=Prizm_Programming_Portal
I am redoing the file I/O code in libc, so I am starting where libc left off at and rewriting portions and adding on.

@ruler501: Thanks!
AHelper wrote:
I am redoing the file I/O code in libc, so I am starting where libc left off at and rewriting portions and adding on.

@ruler501: Thanks!
Excellent. What I really need are some special versions of the f* functions for the Lua I/O library that will redirect calls with file handle 0/1/2 to PrizmIO's functions, but that's something I'll have to code myself, and shouldn't be too bad. Good luck with stringstream. Razz
Stringstreams will work when _v_printf can handle more formats. Right now, can anyone help out with this:

I have a global class variable, but the constructor is never called. I have
Code:
namespace std { basic_ostream cout(&_cout_filebuf); };
but basic_ostream::basic_ostream(...) is never called. Can this be caused by something left out in the crt0? This seems to be the root of all of my troubles, as loads of globals are defined, but they are never constructed. Any pointers?
KermMartian wrote:
File I/O is improving nicely, and if you take a look on the Wiki, you'll see a bit of information on using it. Much of the I/O stuff is still in flux as libc and libfxcg continue to grow and evolve, though:
http://prizm.cemetech.net/index.php?title=Prizm_Programming_Portal


I've seen the one on the programming portal I was asking for more on the stdlib implementations
Well, I suck at SH4 asm. Is there anything wrong with the following:
Code:
    mov.l ctors_s, r7
    mov.l .ctors_until_end, r6
    mov.l .call_constructor, r14
    mov.l dtors_e, r1
    mov.l @r1, r1
    jmp @r6
    nop
.call_constructor:
    jsr @r7
    add #4,r7
.ctors_until_end:
    cmp/eq r1, r7
    bf .call_constructor
ctors_s:
    .long start_ctors
ctors_e:
    .long end_ctors
dtors_s:
    .long start_dtors
dtors_e:
    .long end_dtors

I basically need to execute all of the constructors. The function table is from start_ctors and ends at end_ctors. I get a read exception here, not sure which line. If you need more info, poke me as I am very tired while writing this post Razz
AHelper wrote:
Well, I suck at SH4 asm. Is there anything wrong with the following:
Code:
    mov.l ctors_s, r7
    mov.l .ctors_until_end, r6
    mov.l .call_constructor, r14
    mov.l dtors_e, r1
    mov.l @r1, r1
    jmp @r6
    nop
.call_constructor:
    jsr @r7
    add #4,r7
.ctors_until_end:
    cmp/eq r1, r7
    bf .call_constructor
ctors_s:
    .long start_ctors
ctors_e:
    .long end_ctors
dtors_s:
    .long start_dtors
dtors_e:
    .long end_dtors

I basically need to execute all of the constructors. The function table is from start_ctors and ends at end_ctors. I get a read exception here, not sure which line. If you need more info, poke me as I am very tired while writing this post Razz

I don't know sh4, so I'm stabbing in the dark here, but don't you need to dereference r7 on the second line like you do for r1?

Code:
    mov.l ctors_s, r7
    mov.l @r7, r7

Otherwise r7 probably points at ctor_s at first, and then at ctor_e, and so on, as you increment r7.
No, that doesn't work because of jmp @r7. Also, I get crashing if I have r6 set to jump over my code, so one of the mov.l's is failing... no idea why.

Still not getting it:
Code:
.align 4
    mov.l ctors_s, r7
    mov.l dtors_e, r1
    bra .ctors_until_end
    mov.l @r1, r1
.call_constructor:
!    jsr @r7
    add #4,r7
.ctors_until_end:
    mov.l @r7,r14
    cmp/eq r14, r7
    bf .call_constructor
.align 2


I keep getting an illegal instruction error.

I really need help as I can't write it. I don't know how to jump (what is jump vs branch?) to a subroutine with the address in Rn.
That would be jsr. It'll illegal to modify the target of a branch in the corresponding delay slot. You'll need to add to r7, then branch and insert a nop in the delay slot.

If this code is being called by something, you also need to save pr before doing any jsr.
I have this now:
Code:
    mov.l ctors_s, r0
    mov.l ctors_e, r1
    mov.l @r0,r0
    bra .const_until_end
    mov.l @r1,r1
.call_constructor:
    jsr @r0
    add #4,r0
.const_until_end:
    cmp/eq r1, r0
    bf .call_constructor
    nop
This executes code, but it crashes. I don't know if I am calling it wrong and it can't return properly, or if the constructors are dieing somewhere, but the Prizm reboots before executing main.

Oh, there is only one function that is called and I can see stuff being initialized, but I can't find a way to have gcc tell me what is being initialized.

I see what you were saying. Note that the pipeline reads r0 before the add instruction get executed. My constructor is called, but it fails to return. I will change the order to see what happens. Do you know what registers are caller-saves and callee-saves? I saw it before but forgot where.
I'm glad I wrote this up, I guess.
https://www.taricorp.net/muse/casio-prizm-binaries

Looks like your problem now is that you assume r0 and r1 won't be touched, when r0 will certainly be clobbered, and r1 may be.
Ah, thank you, that's where I saw those at. Where do you recommend going to learn sh assembly? I have just been looking at what op codes do, but have no idea on anything else.

Also, I changed it to this:
Code:
    mov.l ctors_s, r8
    mov.l ctors_e, r9
    mov.l @r8,r8
    bra .const_until_end
    mov.l @r9,r9
.call_constructor:
    jsr @r8
    nop
    add #4,r8
.const_until_end:
    cmp/eq r9, r8
    bf .call_constructor
    nop
and have this as my cpp source
Code:
class test
{
public:
  test()
  {
    PrintXY(1,1,"  init",0,0);
  };
  ~test()
  {
    PrintXY(1,3,"  decon",0,0);
  };
  void go()
  {
    PrintXY(1,2,"  did",0,0);
  };
};
test t;
int main()
{
  PrintXY(1,4,"  main",0,0);
  t.go();
  int key;
  while(1) GetKey(&key);
}

It gets to printing init, but then gets a read address exception (0x1 / 0x8004DC66). :-\

I think I am nuking registers. I currently have this code right before main is called. Where should it go that wouldn't harm anything?

I am going to guess that somehow r8 and r9 are not saved since it crashes if I try to access them. Do I push like mov.l r0,@-r15 and pop with mov.l @r15+, r0 ?

<edit>

Well, I replaced the printf in libfxcg with the one in uClibc. It works just fine. Here is an example of it working on the prizm:

Code:
#include <iostream>
#include <fxcg/keyboard.h>
using namespace std;

int main()
{
  cout << "Hello!" << endl;
  cout << 1 << ".." << 2 << ".." << 3 << ".. YAY!" << endl;
  cout << "EOF is " << EOF << endl;
  cout << "\"" << s << "\" is at " << (void*)s << endl;

  int key;
  while(1) GetKey(&key);
}

output:
Hello!
1..2..3.. YAY!
EOF is -1
"this is a string" is at 0x30aaf8


ostream uses snprintf to print out all text and numbers. It supports %[npxXoudifFeEgGaACScs] and fun modifiers. I will get scanf tomorrow and look into manipulating std streams to change position, color, font, etc.
I have libm (full), libstdc++ (full), libc (with full printf, not complete), libgmp (full, should work, untested) compiled for the prizm! Here is a demo source file:
Code:
#include <math.h>
#include <iostream>
#include <fxcg/keyboard.h>
using namespace std;

int main()
{
  const char *s = "this is a string";
  cout << "asin(1)=" << asin(1) << "  pow(3,9)=" << pow(3,9) << "  nan=" << NAN << "  -inf=" << -INFINITY << endl;
  cout << "Hello!\n";
  cout << 1 << ".." << 2 << ".." << 3 << ".. YAY!" << endl;
  cout << "EOF is " << EOF << endl;
  cout << "\"" << s << "\" is at " << (void*)s << endl;
  cout << hex << 300 << dec << endl << endl;
  printf ("Characters: %c %c \n", 'a', 65);
  printf ("Decimals: %d %ld\n", 1977, 650000L);
  printf ("Preceding with blanks: %10d \n", 1977);
  printf ("Preceding with zeros : %010d \n", 1977);
  printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
  printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
  printf ("Width trick: %*d \n", 5, 10);
  printf ("%s \n", "A string");
  try
  {
    int *test = new int[1000000];
    cout << "This is bad...\n";
    delete test;
  }
  catch(bad_alloc e)
  {
    cout << "Caught exception: " << e.what() << endl;
  }
  int key;
  while(1) GetKey(&key);
}
and here is the add-in running:

Everything is working properly Very Happy.
That's PrintMiniMini, right? You do realize that doesn't seem to support special characters, making your printf implementation less appropriate for localized applications?
I know (it does print special characters, not all I guess). I am not making a terminal emulator, just something to print text. You will be able to change the font. That isn't a priority for me at all now.

<edit>

libc will be able to create files seemlessly using dynamically expanding files. Also, ifstream was tested and can read files Very Happy It doesn't have full functionality since scanf is missing, but readline works perfectly. libc is also getting a lot of love in terms of fixes.

Work on giac has stopped as it is a HUGE PITA.
  
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 GMT - 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