Author Topic: java grinder  (Read 4122 times)

0 Members and 1 Guest are viewing this topic.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2274
  • Likes Given: 3478
java grinder
« on: 21:35, 04 March 16 »
Michael Kohn - java grinder

Anyone add support for CPC?  :)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Apollo

  • Supporter
  • CPC664
  • *
  • Posts: 66
  • Country: de
  • Liked: 22
  • Likes Given: 337
Re: java grinder
« Reply #1 on: 17:38, 05 March 16 »
I am actually impressed with what little java code that C64 demo runs...  8)
Would be nice to have a CPC API as well there as it an interesting project.
It is more or less a bit similar to CPCtelera project as far as I understand, isn't it?
« Last Edit: 17:40, 05 March 16 by Apollo »
CPC - My beloved first computer!

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #2 on: 14:57, 11 March 16 »
After taking a closer look at the C64 demo (which is impressive) it seems like this depends on very machine specific libraries.

The "JAVA" part "just" seems to be pure normal control flow (if, then,  a++, b++) - so I guess it is not worth
the effort while we have C and powerful libraries available for crossdevelopment.

I'm not very deep in CPCtelera, maybe it can be "recycled" as CPC Implementation for this use case. Maybe give the java grinder author a "hint" :) ...
« Last Edit: 20:09, 12 March 16 by SRS »

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 3.135
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1298
  • Likes Given: 2593
Re: java grinder
« Reply #3 on: 08:58, 12 March 16 »
For CPC development, CPCtelera is awesome for me.

What would have been nice with Java was for it to convert JavaME, which was almost the idea I had with sMIDP2lib.
I.e. you code for JavaME (using a certain approach of course), thus targeting older cellphones (and Android too if you had the sMIDP2lib for Android).
And then sMIDP2lib for the CPC would create a CPC version.

The thought was that it would make more people look into CPC game-development, because they wouldn't only be targeting the CPC.

I did actually start the sMIDP2lib project on the CPC. Demoniak helped out a lot creating functions for SDCC.
The idea was to create a J2ME game - then simply copy 99% of the source directly into a CPC project.
I managed to do this for J2ME -> Android and for J2ME -> Flash and even for J2ME -> HTML5 (had to run through a converter first though).

But the project died. And then came CPCtelera which I'm finding much more interesting.
« Last Edit: 09:06, 12 March 16 by mr_lou »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: java grinder
« Reply #4 on: 04:11, 13 March 16 »
I'd might check it out, if it was like this site, but that site only produces the results on the Canvas and Output provided, guess writing it for an Amstrad falls into the too hard basket. Just seems to be an interesting idea of making a language on a Website and having example programs, as well as documentation to get you through the language, to me has appeal.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Sykobee (Briggsy)

  • 6128 Plus
  • ******
  • Posts: 786
  • Country: gb
  • Liked: 288
  • Likes Given: 418
Re: java grinder
« Reply #5 on: 00:08, 14 March 16 »
Yep, this is merely a way to code for old computers using a different language - Java (but probably Clojure, Scala, Jython, JRuby, etc too) - but without the standard Java frameworks or compatibility.


As such, porting CPCTelera or similar to the framework would be a great idea, as I find a lot of the Java development ecosystem to be quite powerful (it's what I work with all the time).


The interesting aspect is that it really uses the Java bytecode as an intermediary object code for the final compilation step to native assembly.


The fact that you can write in Java for the Atari 2600 and get worthwhile results on a system with 128 bytes of RAM is pretty amazing. But then again, no JVM, no frameworks, and a static hardware-specific API...

Offline mikeakohn

  • Speccy
  • *
  • Posts: 2
  • Country: us
  • Liked: 1
  • Likes Given: 0
Re: java grinder
« Reply #6 on: 14:37, 21 March 16 »
There is already Z80 support in Java Grinder itself...  it wouldn't be so hard to create an API for hardware and fill in the assembly language code that goes along with the function calls.


Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder - WIP
« Reply #7 on: 19:26, 03 April 16 »
Hi there, I tried it a little bit with @mikeakohn helpo but now I am stuck.

So if you are C/Java experienced, maybe you can help me get it fly ...

**********************************************************

First, you need a gcc development environment. I have cygwin64 installed as described in this manual: CPCtelera Reference Manual - . .

after that (which takes a loong time if you are new to it :) ) you need to install a JAVA SDK (like this: Java SDK (64 Bit) - Download - CHIP)

Now you have to tell your Cygwin where to find JAVA ->

 I did edit the file ".bashrc" which is in the your users home directory of the cygwin installation (..\home\username\)
and entered the path to my JDK (which is located at Windows Drive "D" in Path "JavaSDK").

!! Use an editor that saves this in UNIX format ! (Like Notepad++ Notepad++ Portable - Download - heise online) !!

Code: [Select]
# -- Tell it where to find java, for example
# "/cygdrive/c/Program Files/Java/jdk1.8.0_05/bin"

export JAVA_HOME=/cygdrive/d/JavaSDK/bin
export PATH=$PATH:"/cygdrive/d/JavaSDK/bin"

In terminal, change where you want to have java-grinder (I chose my user home), and type in "git clone https://github.com/mikeakohn/java_grinder.git
". This will downlaod the latest release.

After that, type "make". Look if everything builds ...


Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #8 on: 19:52, 03 April 16 »
Now - install latest CPC try from attached ZIP into followin locations:
Code: [Select]
\api\cpc_.cxx
\api\cpc_.h
\generator\CPC.cxx
\generator\API_CPC.h
\generator\CPC.h
\java\net\mikekohn\java_grinder\CPC.java
\include\cpc.inc


\samples\cpc\CPCHello.java
\samples\cpc\CPCHello2.java
\samples\cpc\CPCGraph.java

Go to javagrinder home directory, "make clean", "make", "make java"

Now if you go to samples\cpc\

you can javac an example:

Code: [Select]
javac -classpath ../../build/JavaGrinder.jar CPCGraph.java
and javagrind it:
Code: [Select]
../../java_grinder CPCGraph.class cpc_graph.asm cpc
Now - I am stucked. I get
Quote
--> Function not implemented 'screen_I' ../api/invoke_static.cxx:171
** Error compiling class.








Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #9 on: 19:54, 03 April 16 »
@mikeakohn looked at it

"it should be:

int CPC:cpc_screen_I(

classes are all uppercase... functions are all lowercase except for the signature... it was done that way because the signature in JNI is always uppercase..."

Now it IS ... I must have some very noob mistake in there (brackets ? ; , ?) which does not disturb make, javac ... but javagrinder does not know my functions WITH parameter. CPC.cls()  i.e. works ...


Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
First JAVA Program on a CPC ! ( me thinks ...)
« Reply #10 on: 21:02, 07 April 16 »
Tada !

Ok, it is just a small demo, but with text and coloured graphics  ;D
Code: [Select]
import net.mikekohn.java_grinder.CPC;

public class GrafCPC
{
  public static void main(String args[])
  {
   int i;
   char c; 
     
   CPC.screen(1);
   CPC.plot(1,1,2);
   CPC.draw(640,200,1);
   CPC.draw(0,200,2);
   CPC.draw(640,0,3);
     
   
   String txt = "Very simple Grafix for CPC in JAVA";
   
   
   for (i = 0; i < txt.length(); i++)
   {
    c = txt.charAt(i);
    CPC.putChar(c);
   }
   
   c=CPC.readChar();
   
  }
}

Thx for your software and patience , @mikeakohn  !

Waiting for your first JAVA-games, ppl  :)
« Last Edit: 21:04, 07 April 16 by SRS »

Offline FloppySoftware

  • CPC6128
  • ****
  • Posts: 243
  • Country: es
  • The best team: Amstrad PCW, CP/M, and the Z80 cpu.
    • Floppy Software
  • Liked: 234
  • Likes Given: 171
Re: java grinder
« Reply #11 on: 08:57, 08 April 16 »
Congrats!

Support for 'new' is still missing?
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 3.135
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1298
  • Likes Given: 2593
Re: java grinder
« Reply #12 on: 09:05, 08 April 16 »
Now all we need to do is to port the CPC class to other Java-supporting platforms, and then we can create games for multiple platforms in (almost) one go.  :D

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #13 on: 13:25, 08 April 16 »
This would be very easy now - not a lot implemented yet :D


TBH, I wanted to get it work. "Finishing" the firmware class - I dunno.
[size=78%]Maybe I'll try to implement on sprite routine or something like that from CPCTelera as PoC.[/size]




The generated code is very push/pop heavy and looks not very speedy. So for real projects / games I'd still recommend C or ASM.




Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 3.135
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1298
  • Likes Given: 2593
Re: java grinder
« Reply #14 on: 16:41, 08 April 16 »
Yea... would probably be a better project to port CPCtelera to other platforms.  :)

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1981
  • Likes Given: 4650
Re: java grinder
« Reply #15 on: 23:06, 08 April 16 »
Java Grinder seems to be good idea. However I would prefer something CPC specific. The .dox format invented by @Prodatron seems to do this for SymbOS and HTML. So what's about a Java-like language for the CPC, but using specifically the powers of the CPC? I didn't look too close at Java Grinder, so it's hard to tell how close it could be to the CPC design. The problem of all the all-computer, all-OS solutions is a loss of speed. Windows is the perfect example for that. With a CPC I still can beat Windows in some tasks. Just my thoughts...  :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: java grinder
« Reply #16 on: 02:42, 09 April 16 »

The generated code is very push/pop heavy and looks not very speedy. So for real projects / games I'd still recommend C or ASM.


Guess it would depend on what Games one would want to write.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mikeakohn

  • Speccy
  • *
  • Posts: 2
  • Country: us
  • Liked: 1
  • Likes Given: 0
Re: java grinder
« Reply #17 on: 14:33, 09 April 16 »
The generated code is very push/pop heavy and looks not very speedy. So for real projects / games I'd still recommend C or ASM.


The push/pop can be changed to ld (I+D) instructions similar to what I did with 6809.  I did it this way because it was the easiest way to do it at the time.  Actually, I'm not sure if that would help or hurt it.

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1981
  • Likes Given: 4650
Re: java grinder
« Reply #18 on: 21:28, 09 April 16 »

The push/pop can be changed to ld (I+D) instructions similar to what I did with 6809.  I did it this way because it was the easiest way to do it at the time.  Actually, I'm not sure if that would help or hurt it.


Ah, do you have a link? (Found Z80 on the page, but can't click it).  :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #19 on: 23:54, 09 April 16 »
@TFM: have a look at my latest addition - after it was checked and gets released.

Just a short "snip" ->

You have to implement

Code: [Select]
virtual int cpc_setTxtPen_I() { return -1; }
 virtual int cpc_setTxtPen_I(int c) { return -1; }

The one with (int c) is the new one (for calling with CONST)

Code: [Select]
int CPC::cpc_setTxtPen_I(int c)
{

 if (c < 0 || c > 15)
  {
    printf("Error: Color index out of range\n");
    return -1;
  }
  fprintf(out, "  ld a, 0x%02x\n", c);
  fprintf(out, "  call TXT_SET_PEN\n");

  return 0;
}

int CPC::cpc_setTxtPen_I()
{
  fprintf(out, "  pop hl\n");
  fprintf(out, "  ld a,l\n");
  fprintf(out, "  call TXT_SET_PEN\n");

  return 0;
}

and add-on to CHECK_FUNC(setTxtPen,_I)  also CHECK_FUNC_CONST(setTxtPen,_I)
and  virtual int cpc_setTxtPen_I(); and  virtual int cpc_setTxtPen_I(int c);



*********************************************************

The new one compiles to i.e.

Code: [Select]
CPC.setTxtPen(3);
Code: [Select]
ld a, 0x03
call TXT_SET_PEN

the part with variable like

Code: [Select]
CPC.putChar(char c);
gets

Code: [Select]
ld e, (iy+8)
  ld d, (iy+9)
  push de
  ; putChar_C()
  pop hl
  ld a,l
  call TXT_OUTPUT

« Last Edit: 23:57, 09 April 16 by SRS »

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1981
  • Likes Given: 4650
Re: java grinder
« Reply #20 on: 01:55, 10 April 16 »
Cool! You're the man!  :) :) :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #21 on: 23:05, 27 April 16 »
Now with 16bit (unsigned) arithmetics and Memory-API support for Z80 Platform.

My test programs came to a point where the missing "new" (which is clearly stated at homepage) is a reason they can't be made (by me).

So, I'll for sure add some this and that for now and then but I won't be able to push it much further  - but all of you feel free to evolve it beyond (maybe some crack can implement the "new" capacity?).

Looking out for first games / demos written in Java now :)

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 598
  • Likes Given: 325
Re: java grinder
« Reply #22 on: 18:07, 28 April 16 »

The push/pop can be changed to ld (I+D) instructions similar to what I did with 6809.  I did it this way because it was the easiest way to do it at the time.  Actually, I'm not sure if that would help or hurt it.

It would be more a peephole optimization for the generated ASM that could help a bit for more serious projects.

Example : "screencpc" there are at least 3 "pairs" of push and direct pop the same register. removing them manually from ASM saves 6 Bytes of code / 63 cycles.

SDCC has a real nice peephole optimizer, but it's not like an extra *.exe that could be included  in the Makefile for samples/cpc, sadly.


This, of course, is "complaining on a high comfort level" :)

Offline Alcoholics Anonymous

  • CPC664
  • ***
  • Posts: 51
  • Country: ca
  • Liked: 44
  • Likes Given: 0
Re: java grinder
« Reply #23 on: 08:51, 21 May 16 »
 
The push/pop can be changed to ld (I+D) instructions similar to what I did with 6809.  I did it this way because it was the easiest way to do it at the time.  Actually, I'm not sure if that would help or hurt it.

Do you mean storing the stack parameters in a static block of memory instead?  Then you could only have one level of function calls.

It would be more a peephole optimization for the generated ASM that could help a bit for more serious projects.
SDCC has a real nice peephole optimizer, but it's not like an extra *.exe that could be included  in the Makefile for samples/cpc, sadly.

It is pretty good (but several bugs reduce its usefulness, most of which are fixed in z88dk's version btw) but even if it were separated into a separate exe it would not be portable to anything else. 

The least problematic issue is that it can only operate on asz80 syntax asm with correct whitespace.  Indexed register instructions have to use the weird ix syntax, constants must use the # operator and so on.

The real problem is that it is using information delivered to it by the compiler so it can't really be separated from the compiler.

However, having said that, there is another peephole optimizer that does operate separately from any compiler called copt.  This one is a regular expression engine that can look for patterns and make text substitutions.  For things like removing redundant pushes and pops, copt can do this very well.  If Java Grinder is a simple compiler that generates code locally rather than trying to do register assignment, as it seems to be, copt can be effectively used to optimizing common code patterns in its output.
Quote
My test programs came to a point where the missing "new" (which is clearly stated at homepage) is a reason they can't be made (by me).

So, I'll for sure add some this and that for now and then but I won't be able to push it much further  - but all of you feel free to evolve it beyond (maybe some crack can implement the "new" capacity?).

There are several characteristics that make Java unsuitable for embedded systems and new is one of them.  Objects are created and thrown away with impunity which is a problem for execution speed in small memory systems because of the frequent garbage collection and large amount of memory that must be set aside for a heap.  But it would still be interesting to see if someone does it.