I've already put in a lot of optimization work, and at this rate I don't see enough opportunities left. I'm wondering what corners I can cut that would allow for the serious improvements I need to see while having the smallest impact on overall compatibility. While I would love to have a perfectly compatible emulator, I've pretty much resigned myself to the fact that I'll need to break some things to reach playable speeds on the current gen hardware.
I'm interested. If you don't mind typing it up, I'd love to hear how you're doing this.Dwedit wrote:I could explain the algorithm I use in PocketNES if you're interested.
Dwedit: The CPU and PPU are standard J2SE with different frontends for different targets, like Swing and Android. I'd love to hear about your speedhacks.
Same here.James wrote:I'm interested. If you don't mind typing it up, I'd love to hear how you're doing this.Dwedit wrote:I could explain the algorithm I use in PocketNES if you're interested.
The "jump" hack is for games that use the "superloop" structure such as Super Mario Bros. In these games, the entire game runs as NMI and IRQ handlers. The NMI handler updates VRAM and then runs the next frame of game logic.
Code: Select all
; initialize the registers and the game loop variables ; for the first time, and once that's done, just ; jump in place forever forever: jmp forever nmihandler: pha txa pha ; ... pla tax pla rti
The other is for games that repeatedly read a variable that the NMI handler updates and branch based on it. For example, LJ65, Concentration Room, Lawn Mower, and Thwaite and all use this structure:
Code: Select all
; ... lda retraces nmiwaitloop: cmp retraces beq nmiwaitloop ; ... nmihandler: inc retraces rti
PocketNES gets a lot of mileage out of its speed hacks because it delegates most of the work of drawing tiles to the GBA's PPU and most of the work of playing audio to the GBC's APU. This leaves the CPU as by far the biggest item on the profile. On a platform with a dumb frame buffer, such as your PCs and Android devices, your mileage may vary.
PocketNES sets up three of the GBA's four DMA channels for HDMA, pointing at the GBA's equivalents of PPUSCROLL, PPUCTRL, and PPUMASK (BG0XOFS/BG0YOFS, BG0CNT, and DISPCNT respectively). The fourth is used to stream decoded DPCM (but not $4011 PCM, unfortunately for Big Bird fans).foobaz wrote:How can you delegate tile drawing to the hardware? Isn't there too much state that can change per scanline to make that possible?