Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Vertical scrolling question

Reply to topic
Author Message
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Vertical scrolling question
Post Posted: Sun Apr 03, 2016 4:46 pm
I'm trying to get the screen to scroll vertically and wrap properly. I've printed hex values $00 through $1B on rows 0-27 of the name table as a visual aid, and I am writing an incrementing value (the frame counter) into register #9.

Now normally when you do this the screen 'hiccups' as scroll values $E0-$FF are the same as $00-$1F, so you don't get a smooth scroll. I assumed the solution would be to write the frame counter modulo 224 into register #9, but this doesn't work either. (using the 8-bit divide routine from http://www.smspower.org/Development/DivMod). The result looks the same.

What's the right approach for doing this? With the SMS2 VDP it was really easy with the larger display modes where the screen was 256 lines tall, but for some reason I can't quite figure it out here.
  View user's profile Send private message Visit poster's website
  • Joined: 20 Feb 2008
  • Posts: 118
  • Location: Saintes, France
Reply with quote
Post Posted: Sun Apr 03, 2016 6:11 pm
I guess you used an 8-bit frame counter, which wraps back to 0 beyond 255 (0 MOD 224 = 0 while 256 MOD 224 = 32).
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Sun Apr 03, 2016 6:42 pm
Yeah, just subtract 224 when the value is >= 224. Modulo only works if the underlying variable won't overflow, plus it's hugely slower.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Post Posted: Sun Apr 03, 2016 10:29 pm
Thanks guys, I see what went wrong. I switched to this and it works great:
         ld   hl, (yscroll)
         ld   de, 224
         ccf
next:    sbc   hl, de
         jr   z, next ; jge
         jr   nc, next
         out    (c), l


I can see as I scroll through this 16-bit virtual space the subtraction loop will become quite large as the scroll value increases. Is there a better way? I'd like to be able to jump to arbitrary Y positions ideally and derive the register #9 value from that position.
  View user's profile Send private message Visit poster's website
  • Joined: 17 Sep 2013
  • Posts: 128
  • Location: Gravataí, RS, Brazil
Reply with quote
Post Posted: Mon Apr 04, 2016 2:10 am
I believe a better way would be keeping two variables for scolling, one for yout 16 bit scroll, an the other that will actually be in the VDP scroll
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Mon Apr 04, 2016 6:46 am
Always better to add -224 than clear carry and sbc :) ccf may not be what you need here anyway.

If you want to jump to an arbitrary y in a large range, then maybe decouple the scroll value from it? Either you're scrolling there visually, and you apply a delta to the current scroll value, or you're jumping there and you may as well start again at 0 (for the tile-scale scroll, the fine scroll will be a bitmask away anyway).
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!