GP2X Jabber's Log-fire

Discussion in 'General Discussions' started by Mr.Jabberwocky, Sep 21, 2006.

  1. frutbunn

    frutbunn Member

    Joined:
    Aug 30, 2006
    Messages:
    215
    Location:
    The East Wing

    Simple example:

    Code:
    // Pointers to Magic-Eyes hardware registers:
    volatile unsigned short *hardware_regs16;
    volatile unsigned int *hardware_regs32;
    
    // Map it:
    	int devmem_fd;
    
    		/* Allow access to MMSP2 hardware registers:
    		 */
    		if ( (devmem_fd=open("/dev/mem", O_RDWR)) == 0 ) {
    				fprintf(stderr, "Could not open /dev/mem,"
    				 " are you sure you're root?\n");
    
    				return 1;
    		}
    		if ( (hardware_regs32=mmap(0, 0x10000, 3, 1, devmem_fd, 0xC0000000))
    		  == MAP_FAILED ) {
    				fprintf(stderr, "Call to mmap failed, are you sure"
    				 " you're root?\n");
    
    				return 1;
    		}
    
    	hardware_regs16 = (unsigned short*) hardware_regs32;
    
    // Write to hardware registers (set to 8 bit color depth):
    	hardware_regs16[0x28DA>>1] = 0x02AB;	// 8bbp
    	hardware_regs16[0x290C>>1] = 320;	// width;
    
    Most of the Magic-Eyes hardware registers are 16 bit, so if we map a C pointer to the base of the hardware registers at 0xC0000000 (using mmap), we want to easily say which register we want to set. The easiest way is to index that pointer is to use the [n] notation.

    So, to set the hardware register 0xC0000002AB, I've mapped hardware_regs32 and hardware_regs16 to point to 0xC00000000 in memory. If I add a displacement to hardware_regs16, then I can assume that hardware_regs16 points to the real address of 0xC0000000, and my index (in the []) points to the offset from that base. So, it's indexed from 0, so adding an offset of 0x02AB will offset 0xC0000000 by 0x02AB bytes!

    But! No it won't, because an unsigned short is a 16 bit data type, so it will index from 0xC000000 by TWICE that amount! Remember in C an index is an offset multipled by the size of the variable data type. So char mystring[10] is &mystring+10, but unsigned short myint[10] is actually &myint+(10*2), as the unsigned short is two bytes long.

    So we need to divide our pointers offset by the number of bytes the data type uses. So for hardware_regs16 we divide by 2 (or use a logical shift of 1), for hardware_regs32 we divide by four (or use a logical shift of 2). So that's what the >>2 is for!

    Hope this helps, I'm not that good at explaining things!
     
    Last edited by a moderator: Feb 5, 2016
  2. Mr.Jabberwocky

    Mr.Jabberwocky Bloke with a brick on his head

    Joined:
    Sep 27, 2005
    Messages:
    402
    Welcome to the board.

    Thank you very much for the information. This has been my only attempt at a GP2X game and is a rather simple little game. The Knight Lore comment was a joke - although I would love to give it a go. I think it may be a little beyond my abilities.

    Perhaps I should hold a poll :

    Should Jabber make a complete dick of himself and try to recreate Knight Lore Y/N

    Now you have been so kind as to provide these links I feel obliged to at least give it some serious thought. It could be a couple of years in the making though.

    Although the original Spectrum tape image is not available officially I remember having no trouble finding it last time I looked. I lost my hard disc a while back so I don't have it now - in fact a quick google for knightlore.tap while writing this has found it.

    I guess I better go and install an emu and see if it works- any recommendations ? M.E.S.S. sounds cool.

    Thanks for the info on the hardware registers. I have yet to really understand it - I'm a bit dense.

    *** EDIT - having read it a second time your explanation is clear - thank you, I now understand ***

    Is there a simpler explanation of the device than their data sheet ? I have looked at that and it is way over my head.

    I need a nice little manual written in plain English explaining in simple terms and pictures how the thing is laid out.

    Are the registers always at 0xC0000000 or is that implemented by the manufacturer of the device it is used in ? Having learned that the registers are at that address how do we know what they are ?

    I have specifically looked for this information in the data sheet but it is like an alien language to me.

    I have also looked for other material but with no luck. Can you recommend anything ? Please.
     
  3. frutbunn

    frutbunn Member

    Joined:
    Aug 30, 2006
    Messages:
    215
    Location:
    The East Wing
    Don't worry, I had the details in a file so I just cut&pasted it!

    You could do an 'Atic Atac' clone, that would be much easier to implement:

    http://www.icefear.com/dataformats/aticatac/index.html
    http://www.icefear.com/downloads/files/sprites.zip

    One of the GP2x Spectrum emulators I tried is really good, but my GP2x has decided to fry the SD card (again) so can't tell you which one... :angry:

    I think the Magic-Eyes documentation is the only source for details of the hardware registers. It's the only one I've found so far...

    SDL is probably the best way to go. It's my personal choice anyway! :D
     
    Last edited by a moderator: Feb 5, 2016
  4. YakumoFuji

    YakumoFuji Member

    Joined:
    Sep 30, 2005
    Messages:
    189
    Id rather see a head over heels conversion isntead of knightlore ;) probably just as hard to implement tho...

    jabber, you could try a conversion of a dual screen game like green house, use triggers to flip between screen...
     
  5. Mr.Jabberwocky

    Mr.Jabberwocky Bloke with a brick on his head

    Joined:
    Sep 27, 2005
    Messages:
    402
    I would like to see Head over Heels too. :) It has some 300 rooms as opposed to around 128 so it would be a much bigger job. Has anyone come across the sprites for it ?

    I am going to see if I can knock together something that will generate an isometric, room by room play area. If I succeed it could be used for either I guess. How about remaking Atic Atac as an isometric game ?
     
    Last edited by a moderator: Feb 5, 2016
  6. TheMinder

    TheMinder Member

    Joined:
    Mar 21, 2006
    Messages:
    150
  7. Mr.Jabberwocky

    Mr.Jabberwocky Bloke with a brick on his head

    Joined:
    Sep 27, 2005
    Messages:
    402
    I have the Head over Heels Pc remake (and Atic Atac). Awsome. Double our screen res tho'.

    Thanks for the sprite ripping tip. Due to a natural flair for idleness I was hoping someone had already made them available, but it is good to know I can do it myself (if I have to). It might be fun just to play with.
     
  8. twojame

    twojame Member

    Joined:
    Dec 27, 2005
    Messages:
    120
    Hello there... 'Mr.Jabberwocky'...

    I've just tried this game and found it great. Very entertaining and I like the new colour mode.

    I'm a developer working in VB.Net and Coldfusion. I've just got my dev environment setup with Codeblocks (GP2X) and I’ve just started my own project which is a remake of "Monaco GP (1979) with a few twists" think the dates correct :) .

    Anyway I found this a very useful log of you're development and it will certainly help me with my project.


    All the best...
     
  9. Mr.Jabberwocky

    Mr.Jabberwocky Bloke with a brick on his head

    Joined:
    Sep 27, 2005
    Messages:
    402
    Hi twojame

    Thanks for the compliment. I feel particularly honoured since it has prompted only your second post in almost two years of membership :)

    Monaco GP looks good. A little more involved than Game & Watch :lol:

    Best of luck - let us know how it is coming along.
     
    Last edited by a moderator: Dec 18, 2015
  10. twojame

    twojame Member

    Joined:
    Dec 27, 2005
    Messages:
    120
     
    Last edited by a moderator: Dec 18, 2015
  11. cactusbin

    cactusbin Still Fresh

    Joined:
    Sep 2, 2007
    Messages:
    24
    Hello Mr.Jabberman, could you post your source code? I would like to study it ;)
     
  12. Mr.Jabberwocky

    Mr.Jabberwocky Bloke with a brick on his head

    Joined:
    Sep 27, 2005
    Messages:
    402
    You are obviously insane so I have uploaded it to the archives for you.

    If you can work out whats going on let me know, I can't make head nor tail of it.

    I suppose you want a link as well.
     
    Last edited by a moderator: Dec 18, 2015

Share This Page

Loading...