This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

screen split with shiru's neslib

screen split with shiru's neslib
by on (#121978)
Hey there!
I'm a noob in need of help.

Has anyone implemented a screen split with shiru's neslib?
I've tried to do one my self but without luck (either nothing happens, or the screen flickers between the two scrolls).
Any help would be appreciated!

So basically what I need is shiru's ppu_waitnmi() routine but with a sprite 0 hit check and scroll.

Here's shirus routines for ppu_waitnmi() and scroll(x, y):
Code:
_ppu_waitnmi:
   lda #1
   sta <VRAMUPDATE
   lda <FRAMECNT1
@1:
   cmp <FRAMECNT1
   beq @1
   lda <NTSCMODE
   beq @3
@2:
   lda <FRAMECNT2
   cmp #5
   beq @2
@3:
   lda #0
   sta <VRAMUPDATE
   rts


_scroll:
   sta <TEMP

   txa
   bne @1
   lda <TEMP
   cmp #240
   bcs @1
   sta <SCROLL_Y
   lda #0
   sta <TEMP
   beq @2   ;bra

@1:
   sec
   lda <TEMP
   sbc #240
   sta <SCROLL_Y
   lda #2
   sta <TEMP
@2:

   jsr popax
   sta <SCROLL_X
   txa
   and #$01
   ora <TEMP
   sta <TEMP
   lda <PPU_CTRL_VAR
   and #$fc
   ora <TEMP
   sta <PPU_CTRL_VAR
   rts


and here are my messy attempts to combine whatever ppu_waitnmi() does with the sprite 0 check:
note that I was just trying random things at the end before I gave up = /
Code:
;void __fastcall__ waitSprite0rel(void);

_waitSprite0rel:
   lda #1 ;no idéa what these two lines do, took it from ppu_waitnmi()
   sta <VRAMUPDATE ;but I think the sprites didn't even show up if I didn't include them = /
   lda $2002
   and #$40
   beq _waitSprite0rel
   rts
   
;void __fastcall__ waitSprite0set(void);
   
_waitSprite0set:
   lda $2002
   and #$40
   bne _waitSprite0set
;   lda $2000
;   and #$FE
;   sta $2000
   lda #0 ;same as above, these two are from ppu_waitnmi()
   sta <VRAMUPDATE
   rts
 
;void __fastcall__ waitVBLANKrel(void);
   
_waitVBLANKrel:   
   lda <FRAMECNT1
_waitVBLANKloop:
   cmp <FRAMECNT1
   beq _waitVBLANKloop
   lda #0 ;same as above, these two are from ppu_waitnmi()
   sta <VRAMUPDATE
   rts


This is how I'd like my game loop to look like
Code:
updateEverything();

scroll(0, scrollY);
waitSprite0rel(); // waits until rendering starts?
waitSprite0set(); // waits for sprite 0 hit?
scroll(scrollX, scrollY); // scrolls screen directly after hit
waitVBLANKrel(); // waits for rendering to end!?


Here's a screenshot, the orange square in the hud is my sprite 0
Image

Note that my assembly knowledge is extremely low (first time working with it last night).

Thanks in beforehand,
Mattias.
Re: screen split with shiru's neslib
by on (#121987)
Try to check the current version of the neslib. I added 'split' function today, and it has a number of other improvements added recently. Take a note that the split functionality is very limited: you have to handle PAL/NTSC difference by yourself, code execution time can't exceed frame time (split will be missed otherwise), you have to setup sprite to get sprite0 hit by yourself, you can't scroll bottom part vertically. Hopefully some of these limitations will be removed in the future.
Re: screen split with shiru's neslib
by on (#121989)
Shiru wrote:
I added 'split' function today, and it has a number of other improvements added recently.


Wow, thanks!
Great work with the neslib btw, I've been using it for a year now!
I'm currently running everything in NTSC speed and allowing the slowdown on PAL, any problems with this?
Re: screen split with shiru's neslib
by on (#121991)
Yes. The problem is that the speed compensation inserts dummy frames in NTSC mode, i.e. once in six frames ppu_waitnmi waits two frames rather than one. In this extra frame split won't take effect, which will make the bottom part scroll into a wrong position for a frame.

In current version automatic speed correction is disabled by default (could enabled in the crt0.s).
Re: screen split with shiru's neslib
by on (#121992)
Shiru wrote:
code execution time can't exceed frame time (split will be missed otherwise)


A couple of frames here and there flickers, so I guess my game is slow.
Anyways, might skip the split thing then =) thanks anyways!

Is there a change log somewhere? I would like to know what else is new.
Thanks,
Re: screen split with shiru's neslib
by on (#121993)
If you get a flicker every once in a while, your NMI handler needs to do all screen updates and sprite 0 waiting. I don't know whether neslib supports this.
Re: screen split with shiru's neslib
by on (#121998)
Sorry, there is no change log for now, not even a version number. The code gets occasional small updates time to time, with every project is is used in, and I'm too lazy to put extra effort on documenting the changes. It may change eventually, once it get into more stable form.

You can go without the split for now, and when your game will be done more or less, contact with me, so I'd add more functionality to the split scroll code, to make it work with your project.