Page 1 of 2
java_grinder for 65816
Posted: Fri Sep 11, 2015 3:54 pm
by joe7
Made a 65816 target for the java_grinder byte code compiler. Mike posted a demo we used for testing stuff:
http://www.mikekohn.net/micro/apple_iigs_java.php
Right now there is a little bit of graphics API for the IIgs but not much else. However one may use inline asm like this:
Code: Select all
// import the CPU API
import net.mikekohn.java_grinder.CPU;
// put asm anywhere in the java code
CPU.asm("lda #1\n");
CPU.asm("sta $1234\n");
CPU.asm("brk\n");
Please visit the main project page for more information:
http://www.mikekohn.net/micro/java_grinder.php
Edit: forgot to share the Mandelbrot test I did on my shiny new W65C265SXB dev board:

Re: java_grinder for 65816
Posted: Sat Sep 12, 2015 10:32 am
by Martin_H
That's pretty neat. I love the character Mandelbrot set drawing too.
Re: java_grinder for 65816
Posted: Thu Jan 07, 2016 9:07 pm
by joe7
I've been thinking about making a 32-bit code generator (with floating-point) for the 65816. The current generator also has a flaw in that long addresses won't fit on the 16-bit Java variable stack, so programs are limited to the first 64k.
The integer routines will be easy, as I already did 6502 in 16-bit and most of that will translate over to doing 32-bit on the 65816. But having never implemented floating-point math before, I'm looking for wisdom. All that is required is add/subtract/multiply, and division with remainder. Can anyone recommend books/links?
If it helps, here are the generators for 6502/65816. Basically each function implements a bytecode instruction:
https://github.com/mikeakohn/java_grind ... /M6502.cxx
https://github.com/mikeakohn/java_grind ... W65816.cxx
Re: java_grinder for 65816
Posted: Thu Jan 07, 2016 9:36 pm
by BigEd
You could try Woz' routines from 1976 - Jeff Tranter put them on github at
https://github.com/jefftranter/6502/tre ... /asm/wozfp
There's also a BCD-based floating point package by C R Bond, see
viewtopic.php?f=2&t=2202
Either of these might need some testing and attention - in the case of Woz' routines, there might be published errata.
Edit: Hmm, these could surely be improved for the 816 - maybe even change the formats to help. A byte-orientated layout won't work as well as a 16-bit word-oriented layout.
Re: java_grinder for 65816
Posted: Thu Jan 07, 2016 9:47 pm
by GARTHWILSON
Re: java_grinder for 65816
Posted: Fri Jan 08, 2016 7:59 am
by BigDumbDinosaur
I seem to recall seeing Woz's code published somewhere around here as well.
Edit: Hmm, these could surely be improved for the 816 - maybe even change the formats to help. A byte-orientated layout won't work as well as a 16-bit word-oriented layout.
At one time, I looked at implementing Woz's FP stuff on the 65C816 but set the idea aside for two reason. Fully adapting the code to the 65C816 would almost require a rewrite, as merely running the code as is on the '816 would gain little to nothing. Also, the code would become somewhat cumbersome, as constant switching of the accumulator size in order to take advantage of 16 bit operations would be necessary.
The other reason is Woz's FP format is limited to no more than seven significant digits, due to the use of a three byte mantissa. Also, ASCII to binary conversion errors of fractional content will be a problem.
My humble opinion is that it would be more profitable to implement IEEE double-precision on the '816, not a simple feat, but not as onerous as it would be on a 65C02.
I've tried out that one but it's not very speedy. I don't think trying to run a graphics program using FP BCD would work out well. However, being BCD, it does eliminate ASCII-FP conversion errors. 1.2345 ends up being 1.2345.

Re: java_grinder for 65816
Posted: Fri Jan 08, 2016 9:22 am
by BigEd
Quite so, Woz' routines and others can be found at:
http://6502.org/source/#floatingpoint
For the 816, instead of 3 (or 4) bytes of mantissa and one byte of exponent, I'd suggest two (or three) words of mantissa and one word of exponent, with judicious placement of the two sign bits. Try to avoid switching widths. The existing code would be a guide to the algorithms needed. For fractal purposes, you might want a much wider format, or even an extensible format - something like a counted string. I wouldn't use IEEE format though.
I wouldn't recommend BCD at all - it
doesn't have the attractive characteristics that proponents think it has. And it's always going to be slow.
Back to an earlier question:
I'm not sure "remainder" means anything when you're in floating point - have I misunderstood?
Re: java_grinder for 65816
Posted: Fri Jan 08, 2016 11:28 am
by BitWise
If you want to go with a more modern definition for floating point then look at SoftFloat
http://www.jhauser.us/arithmetic/SoftFloat.html
Someone did a (partial) conversion for the pic years ago
http://picfloat.sourceforge.net/
Re: java_grinder for 65816
Posted: Fri Jan 08, 2016 11:33 am
by BigEd
Thanks for the pointer.
All required rounding modes, exception flags, and special values are supported.
Full IEEE is quite a handful...
Re: java_grinder for 65816
Posted: Fri Jan 08, 2016 11:47 am
by BitWise
Full IEEE is quite a handful...
It is. Its not unusual for 8-bit implementations to leave out the signed zero, infinities, NaNs and rounding -- just using the basic float layouts and precisions, although QNaNs can be quite useful.
Re: java_grinder for 65816
Posted: Sat Jan 09, 2016 2:34 am
by joe7
I'm not sure "remainder" means anything when you're in floating point - have I misunderstood?
I misspoke. Integer divide algorithms were on my mind which typically provide the remainder. Java supports floating-point remainders, but nothing special is required for that.
After catching up on all the reading (thank you), I'm bewildered by the number of options. I think I'll start off easier and try to add 16-bit float support to the existing code generator, which is probably enough for game or microcontroller projects anyway.
Re: java_grinder for 65816
Posted: Sat Jan 09, 2016 5:05 am
by theGSman
After catching up on all the reading (thank you), I'm bewildered by the number of options. I think I'll start off easier and try to add 16-bit float support to the existing code generator, which is probably enough for game or microcontroller projects anyway.
Why not just adapt the relevant code from EhBasic?
Re: java_grinder for 65816
Posted: Sat Jan 09, 2016 5:42 am
by barrym95838
Quite so, Woz' routines and others can be found at:
http://6502.org/source/#floatingpoint
For the 816, instead of 3 (or 4) bytes of mantissa and one byte of exponent, I'd suggest two (or three) words of mantissa and one word of exponent, with judicious placement of the two sign bits. Try to avoid switching widths. The existing code would be a guide to the algorithms needed ...
That sounds like a very interesting little project. Too bad I already have too many pans in the fire, or I would have a go at a version with a 16-bit exponent and a 32-bit mantissa (48-bit float). I have my own unfinished implementation for 32-bit and 64-bit floats that has provisions for a single 0.0, a single NaN, +/- infinity, and +/- infinitesimal. It is completely symmetric, and allows integer negation and integer signed comparison to work correctly on my floats without modification. Obviously non-standard ... but so am I.
Mike B.
Re: java_grinder for 65816
Posted: Sat Jan 09, 2016 2:10 pm
by handyandy
my 2 cents and maybe a little off topic...
Every once in a while I come across some proof that 1 = 0.99999... It goes something like this: 1/3 * 3 = 0.9999...
I usually respond that it depends on what number BASE you are using i.e. if the above example was using BASE 3, 1/10 * 10 = 1. I never get back a response to my response. BTW number theory give me headaches and I like math but dislike arithmetic.
Andy W.
Re: java_grinder for 65816
Posted: Sat Jan 09, 2016 2:16 pm
by BigEd
The "..." notation for numbers does sometimes get people confused. As you say, 1/3 * 3 is obviously exactly one.
To write a good arithmetic package you'd really have to understand arithmetic very well. It's esoteric, but for amusement see John Gustafson's "Unum" idea, which adds one bit to floating point numbers to signify "..." which he finds to be an enormous improvement:
https://www.youtube.com/watch?v=jN9L7TpMxeA [
slides and transcript here] (He's also written
a book on the subject.)