Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  signed/unsigned  (Read 1245 times)
0 Members and 1 Guest are viewing this topic.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Posted 2004-08-02 11:45:23 »

Hi there,

I've finally started with creating an M68000 emulator. This is a 32bit processor in many aspects and I want to use integeres for the registers (which are 32 bit).
Now here's the trouble; we don't have any unsigned datatypes in java (except for char) and Sun says it's not necessary to have them. (which sucks btw)
So, say the PC points to memory address 0xffffffff (memory is an array), how would I do that?

Obviously, doing something like
1  
byte fetched = memory[PC];

would get me an ArrayOutOfBoundsException since PC is 0xffffffff, which is -1.
I don't want to revert to long because I feel that should not be necessary. Any thoughts?

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2004-08-02 12:20:02 »

Just thinking out loud here...

1  
2  
3  
4  
5  
6  
7  
byte[] lowermem = new byte[0x7FFFFFFF];
byte[] highmem = new byte[0x7FFFFFFF];

...

if((memloc & 0x80000000) > 0) highmem[(memloc & 0x7FFFFFFF)] = databyte;
else lowermem[memloc] = memloc;


I *think* that'll do it. Obviously you wouldn't want to allocate 4 gigs of memory, so replace that with what mem sizes you're actually using. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2004-08-02 13:22:17 »

Quote
*think* that'll do it. Obviously you wouldn't want to allocate 4 gigs of memory, so replace that with what mem sizes you're actually using.


Thanks, although that was the kind of thing I wanted to avoid  Smiley
It's all hypothetical anyway for now since the 68K addressing space is 24bit, but maybe later I will have a problem.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Raghar

Junior Member




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #3 - Posted 2004-08-05 16:35:04 »

Actually it's unnecessary to have them. You just need a unsigned multiplication/division and some unsigned comparissons.
Java lacks them as well.
[source]
int[] someArray;

read(int c1){
     int temp = someArray[c1>>>2];
     return (byte) ((temp>>>((c1%4)*Cool)&0xff);
}
Would it work? Who knows. Would it be faster than:
switch(c1%4){
     someCode...
}
[/source]
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #4 - Posted 2004-08-05 22:58:03 »

You will never REALLY have a 4gig array will you?

And how about the more general problem of dealing with memory at discontinuous addresses.  E.g. one ROM for sound data at 0xF0000000, one for graphics data at 0xE0000000, and the code at 0x10000000 just for kicks?

Also imagine emulating a Windows machine, where all protected kernel addresses are >0x80000000, even though you may only have 256MB of RAM.

I don't think there is any getting around the fact that you need an address translation function, and that solves the original problem.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2004-08-10 11:53:17 »

You're right and this is just a bad example of my issues with java types.
The original problem is not addressing that much memory, the original problem is the lack of unsigned types and generally all inconveniences dealing with byte and bits in java.

When dealing with bits and bytes, you are forced to continuously cast back and forth between byte and int (with all performance implications), which makes java IMO a bad choice for this kind of thing.

With emulating 8bit machines, the example makes perfect sense though.
I have 3 options for the PC (Program Counter) or other 16 bit registers:
* Use an int. I have to keep masking them by doing an &0xffff to prevent them from going out of scope. Yuck.
* Use short. I can't use it anymore for addressing since it can become negative for high memory.
* Use char. Possible (= the only unsigned type in java), but if I do one logical operation it gets cast to an int and I have to cast it back again. Yuck.

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #6 - Posted 2004-08-10 19:45:32 »

You are correct that Java is not suited to bit twiddling.  But one would hope that after JIT compiling the casts cost nothing because the compiler can see that simply using an instruction that processes the data as unsigned gives the correct result.

No argument that it is a significant pain when you need to write the Java code though.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (24 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!