Author Topic: TI-Nspire GB Emulator  (Read 154714 times)

0 Members and 1 Guest are viewing this topic.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI-Nspire GB Emulator
« Reply #75 on: December 07, 2009, 05:25:45 pm »
Animated shot here (linked because it's about 5MB)
Firefox recommended for fullspeed, since I actually got it over 10fps this time using camstudio
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #76 on: December 07, 2009, 07:29:53 pm »

I warned you Calc84, but you didn't listen, now see what you did to my brain?!

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #77 on: December 07, 2009, 09:18:29 pm »
Looks nice! How is the color pallet being handled?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI-Nspire GB Emulator
« Reply #78 on: December 07, 2009, 09:34:30 pm »
Well, the current method (which is certainly subject to change) is this: Each of the red, green, and blue components have a value from 0-31. So I take int( 1/8*R + 3/16*G + 3/16*B ) and use that as the grayscale value.

Edit:
Super Mario Bros Deluxe
« Last Edit: December 07, 2009, 09:59:06 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #79 on: December 07, 2009, 10:00:11 pm »
Any reason you are using 16ths and 8ths instead of just 1/6th for all?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI-Nspire GB Emulator
« Reply #80 on: December 07, 2009, 10:02:20 pm »
Any reason you are using 16ths and 8ths instead of just 1/6th for all?
Because that would require division. Eww.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #81 on: December 07, 2009, 10:08:12 pm »
:P Or you could just multiply by .1666 and call it good XD.  I assume you are doing somthing similar to that with 3/16 = .1875?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI-Nspire GB Emulator
« Reply #82 on: December 07, 2009, 10:21:29 pm »
:P Or you could just multiply by .1666 and call it good XD.  I assume you are doing somthing similar to that with 3/16 = .1875?
Nah, I can divide by 8 or 16 by shifting right 3 or 4 bits.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #83 on: December 07, 2009, 10:23:08 pm »
Ohhhhh i see now.  Well, it seems to work pretty good!!  I think i may have to stop reading this thread for a while for the better of my health :P

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-Nspire GB Emulator
« Reply #84 on: December 08, 2009, 12:00:49 am »
darn that's fucking awesome. Some still screenshots (and links to your own but hosted on Omni) will make front page soon in their own news

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #85 on: December 08, 2009, 07:49:44 am »
Nice work!

Edit:
Actually, I was able to get the Nspire emulator running in translated mode now since I changed a certain part of my code, and it runs... really fast. I don't think there should be any worries :)
The translator should work with anything, unless you either repeatedly store to memory that was previously used as code (which will slow it way down, since it wipes all translations on this kind of store - this could be improved), or store to memory that is ahead in the current basic block of code (very perverse thing to do in my opinion, I've seen it fail on real CPUs before :)). If anything else broke it, I would like to hear about it...

Any reason you are using 16ths and 8ths instead of just 1/6th for all?
Because that would require division. Eww.

The truly correct way to do grayscaling is more complicated even than that:
  • Perform gamma expansion on all three channels. Gamma expansion is the non-linear relationship from video input signals (R', G', B') to the amount of energy emitted by the display (R, G, B). On a typical CRT monitor, this can be approximated with the power law x = x' ^ 2.2. (The Game Boy Color uses an LCD instead, so I don't know what the equation for it is.)
  • Calculate the luminance. This is a weighted average of all three channels, which takes into account that the human eye is more sensitive to green light than red, and more sensitive to red than blue. The traditional formula is Y = 0.299R + 0.587G + 0.114B, but it really depends on the color space used on that particular display. (Not everyone agrees on just what "red", "green", and "blue" are.)
  • Perform gamma compression, the inverse of gamma expansion.

Some people forget the gamma operations, which results in saturated colors ending up too dark.
« Last Edit: December 08, 2009, 07:51:14 am by Goplat »
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

Offline JoeyBelgier

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 545
  • Rating: +25/-21
  • Joey
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #86 on: December 08, 2009, 07:51:30 am »
* NecroF-_-ckk Loves Calc84Maniac for that SMB:D screenie
* NecroF-_-ckk Hugs Calc84Maniac
Dx

I always cheat in level 1-2 and go to 4-1 :P
« Last Edit: December 08, 2009, 07:54:36 am by NecroF-_-ckk »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI-Nspire GB Emulator
« Reply #87 on: December 08, 2009, 09:22:08 am »
Nice work!

Edit:
Actually, I was able to get the Nspire emulator running in translated mode now since I changed a certain part of my code, and it runs... really fast. I don't think there should be any worries :)
The translator should work with anything, unless you either repeatedly store to memory that was previously used as code (which will slow it way down, since it wipes all translations on this kind of store - this could be improved), or store to memory that is ahead in the current basic block of code (very perverse thing to do in my opinion, I've seen it fail on real CPUs before :)). If anything else broke it, I would like to hear about it...

Any reason you are using 16ths and 8ths instead of just 1/6th for all?
Because that would require division. Eww.

The truly correct way to do grayscaling is more complicated even than that:
  • Perform gamma expansion on all three channels. Gamma expansion is the non-linear relationship from video input signals (R', G', B') to the amount of energy emitted by the display (R, G, B). On a typical CRT monitor, this can be approximated with the power law x = x' ^ 2.2. (The Game Boy Color uses an LCD instead, so I don't know what the equation for it is.)
  • Calculate the luminance. This is a weighted average of all three channels, which takes into account that the human eye is more sensitive to green light than red, and more sensitive to red than blue. The traditional formula is Y = 0.299R + 0.587G + 0.114B, but it really depends on the color space used on that particular display. (Not everyone agrees on just what "red", "green", and "blue" are.)
  • Perform gamma compression, the inverse of gamma expansion.

Some people forget the gamma operations, which results in saturated colors ending up too dark.
Yeah, my color conversion is pretty much just a placeholder for now. By the way, is the emulator's speed accurate? I mean, I added a delay loop of "loop subs r8,r8,#1 \ bne loop" when r8 contained 400,000, and that was for each of 60 frames. That loop should be 4 cycles per iteration, right? That adds up to delays of more than 90MHz, which doesn't add up.

Edit:
Oh, and I did use self-modifying code for a bit, but it was pretty unnecessary (hence why I didn't get it in translated mode sooner)
« Last Edit: December 08, 2009, 09:29:10 am by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-Nspire GB Emulator
« Reply #88 on: December 08, 2009, 11:17:18 am »
Hi Goplat and welcome here. Very nice job on that TI-Nspire emu. :)

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
Re: TI-Nspire GB Emulator
« Reply #89 on: December 08, 2009, 12:12:59 pm »
By the way, is the emulator's speed accurate? I mean, I added a delay loop of "loop subs r8,r8,#1 \ bne loop" when r8 contained 400,000, and that was for each of 60 frames. That loop should be 4 cycles per iteration, right? That adds up to delays of more than 90MHz, which doesn't add up.
It's not accurate. Right now, it just assumes all instructions are one cycle, or 1/90 microseconds. If your computer is not fast, it can lag, however. A tight loop like that is very likely to lag; I would recommend adding a few dozen repetitions of a simple instruction like "mov r0,r0" which nspire_emu can execute very fast.

This kind of "busy-wait" loop is a bad way to do timing in general (wastes energy, doesn't take into account time taken up by other code) but I can certainly understand if you're not willing to write code to deal with timer interrupts yet, considering that future updates to nspire_emu would almost surely break it.

Quote
Edit:
Oh, and I did use self-modifying code for a bit, but it was pretty unnecessary (hence why I didn't get it in translated mode sooner)
I checked the ARM manual; it says self-modifying code "cannot be relied on without the use instructions to ensure synchronization".

EDIT: I've released a new version that puts graphics and keys in the same window, so it should be possible for you to record gameplay with CalcCapture now.
« Last Edit: December 08, 2009, 02:58:18 pm by Goplat »
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo