Hacker News new | past | comments | ask | show | jobs | submit login

A few months ago I also built a GameBoy emulator with the intent of educating myself. It's in Java and uses Swing for the GUI. It also supports sound but its implementation is definitely not ideal.

While most of the games I tested are playable, I couldn't get SBC and ADC instructions to work correctly for all cases. I especially have no idea whatsoever how they're supposed to affect the carry flags. Test ROMs aren't very helpful either because the ones I used just ran the instruction with all possible combinations of input parameters, checksummed the results, compared the checksum to the expected value, and said "duh, your thing is wrong". And Googling around wasn't any more helpful. Since most of my childhood games ran fine anyway, I gave up. I'd still like to fix it eventually though.

That said, writing a video game system emulator is a tedious but rewarding experience. You just move bytes around and do an unhealthy amount of bit operations, and a game comes out. IMO every software developer should try writing an emulator at some point.




Hey,

  SBC:
    result = byte1 - byte2 - carry
    carry = result < 0
    return result & 0xff

  ADC:
    result = byte1 + byte2 + carry
    carry = result > 0xff
    return result & 0xff
Source - my implementation, passes tests. Look for SBC & ADC in https://github.com/trekawek/coffee-gb/blob/master/src/main/j...


Huh, I'm pretty sure I did exactly this initially, but it didn't work. Maybe it didn't work because some other instruction that the test itself relies on didn't. I'll check again, thanks.


I wanted to write an 8080 emulator for the hell of it. What target? I started in Javascript, but I ended up writing it in 8088 (MS-DOS) assembly, because it has all the same flag behavior built in. Way more fun!

ZEXALL and derivatives are pretty good test suites. I think it checksums results but it does have lots of tiny tests to exercise particular instructions and operands. You'll still need to single-step through all the code that runs the generated test suite and prints the results. I know there's a port to a Sega Master System rom (ZEXSMS), dunno about the Gameboy.



That’s for the 6502, the Game Boy uses a Z80 variant


Imagine a 6502 game boy? 3 hours of battery but those spirits would fly. Also imagine a PPU similar to NES. Would have been tons of ports. I’m actually not sure why they didn’t go this route. They didn’t use stock 6502 so repackaging would have been fine.


Isn’t the 6502 slower?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: