Family BASIC scrolling backgrounds

Started by zmaster18, August 20, 2015, 01:47:15 pm

Previous topic - Next topic

zmaster18

I've been watching many videos of BASIC programs and many of them actually have scrolling backgrounds. How is this achieved? Would it have to coded in assembly or is there a technique in BASIC? This is popular in space-shooter programs.

UglyJoe

Where are these videos?

I could conceive of a way to do "choppy" scrolling without ASM, but not smooth scrolling (without wasting all of your sprites).

zmaster18

Search Youtube for "family basic nnd". These are videos taken from Nico Nico Douga and there are over a hundred sample videos of BASIC programs. And yes, this is pixel-level scrolling. Using sprites and PRINT CHR$ would be impossible. This is smooth pixel-level scrolling using 2 BG screens. I would assume it has to be in V3 because in V3 you can have 2 BG screens in memory.

P

August 20, 2015, 04:05:51 pm #3 Last Edit: August 20, 2015, 11:17:18 pm by P
I've seen lots of those NND compilations but I don't remember any of them scrolling. Do you remember which one it is?

I'm not sure how to do it in assembly though. V3 seems to use SCREEN to switch between the two nametables. Syntax is:
SCREEN display,active
where "display" is screen number (0 or 1) used to choose which screen to display and "active" is which screen (0 or 1 again) the cursor is placed on (you can type stuff on the screen you can't see). If you get stuck you can press CTR+D to restore both to screen 0.

But the question is if V3 keeps it's scroll position buffered somewhere in memory so it can be controlled at will. Else it will keep resetting the scroll position to the beginning of either screen 0 or 1 every frame. Also scroll position must be set in a vertical blanking.

zmaster18

Here's a good example showing 2 layers of scrolling:  https://www.youtube.com/watch?v=iis_xxyw6xs  at 32:40
(as a bonus, check out the awesome little game at 21:08. It's the best and most original BASIC game I've ever seen!)

Most of the space-shooter games I've seen have scrolling backgrounds.

P

August 20, 2015, 11:50:39 pm #5 Last Edit: August 21, 2015, 03:59:11 pm by P
Ah parallax scrolling even. :) I think auto scrolling shmups like this (especially if it's just a starry background) can get away with "fake" scrolling by simply moving the BG tiles (the stars). But it does look really smooth!

"Real" scrolling basically means moving the scroll position into the second screen, then redraw the first screen before it wraps around into the first one again. Family BASIC is hardwired to a horizontal-scroll setting (AKA vertical mirroring), which means the two screens are aligned horizontally and if you try to scroll vertically instead you will just wrap around the current screen (a mirror).


Edit: But the stars moves very smoothly. BG tiles can't be moved pixel by pixel like that on a Famicom, and the stars can't be sprites either. Maybe he does use the scroll register somehow?

UglyJoe

It has to be the scroll register.  I don't know why you wouldn't be able to manipulate it.  I can't explain the paralax stars (the upper layer).  I don't know how you'd do that without using sprites.

You don't need two screens to do smooth vertical scrolling if you hide the topmost and bottom-most rows of tiles (which are often cut-off by TVs anyway).  You move the first screen down smoothly for a single row, then redefine your name tables so that the every row shifts up by one and the top row gets wrapped around to the bottom, and then you reset your scroll register so it's at the very top again.  RPGs do this for world maps often.

I'm having fun with these videos, though (when I have the time).  A bunch of them apparently are from a magazine called マイコンBASICマガジン.  I'm trying to find scans of the magazine, but have only found one so far: April 1988.  It has three FB listings in it (two sports and one action), although I haven't typed up any of them.  I did find a nice resource site that indexes the names of the programs found in each issue: link.  Has page numbers, too, which helped me find the program listings in that one scan.

The game we're talking about is called "Metal Arms" and was published in the January 1990 edition of the magazine.

P

August 22, 2015, 06:31:58 am #7 Last Edit: August 22, 2015, 10:25:36 am by P
Oh thanks for those links! We should post programs that we have typed up in the forum, so that they can just be copy-pasted in the future.

Quote from: UglyJoe on August 22, 2015, 05:46:42 am
It has to be the scroll register.  I don't know why you wouldn't be able to manipulate it.

You just have to figure out where Famibe keeps its scroll coordinates I guess. Writing to &H2005 directly wouldn't work.

Quote from: UglyJoe on August 22, 2015, 05:46:42 am
You don't need two screens to do smooth vertical scrolling if you hide the topmost and bottom-most rows of tiles (which are often cut-off by TVs anyway).  You move the first screen down smoothly for a single row, then redefine your name tables so that the every row shifts up by one and the top row gets wrapped around to the bottom, and then you reset your scroll register so it's at the very top again.  RPGs do this for world maps often.
Yeah I was just explaining the basics of scrolling.



Edit:
It seems zero page variable &H00E4 holds the Y-scroll position in V3. Poking it changes the vertical scroll position but I couldn't do any loops that scrolls, kept getting IL-errors.

POKE &HE4,50


But for vertical scrolling... It seems to just write zero to it (since it never needs to scroll vertically), it doesn't seem to use a place in RAM for the X-position.




Edit: Family BASIC V2.1 has both Y and X scroll positions in RAM! They are in $009D and $0069 respectively.

10 A=0
20 FOR I=0 TO 100
30 A=A+1
40 POKE &H9D,A
50 POKE &H69,A
60 PAUSE
70 NEXT

Scrolls diagonally as you hold down a key.

zmaster18

Wow you're a genius, P! Thanks for digging this up. Although the code doesn't work in V3, I'm eagerly awaiting to see the V3 version.  ;D  I feel like these techniques, as well as other assembly techniques, should have been mentioned in Family BASIC documentation. I'm sure NES Dev people would already know stuff like this, but the beginners like myself would never know about stuff like this.

P

I knew that they must write the current desired scroll position to $2005 (the scroll register) every frame or else the screen would jump around randomly (because other things affect the scroll register). So I just looked in the ROM what they wrote to it and it turned out to be the contents of the RAM addresses $009D and $0069 (later I realized that Enri had it all documented :-[).

V3 seems to write to $2005 on several occasions though so it might need to be looked at. But try the same code but use only one poke (for Y-scroll) and see if you can scroll vertically (also change Y-scroll variable to $E4 in V3):

10 A=0
20 A=A+1
40 POKE &HE4,A
50 PAUSE
60 GOTO 20

This code isn't tested but see if it works for you. Hold a key to scroll down.

zmaster18

August 23, 2015, 06:36:04 am #10 Last Edit: August 23, 2015, 09:19:56 am by zmaster18
Woah! It worked P! This is awesome! What a cool effect! Where did you learn stuff like this? That link you provided won't open for me.

I modified the code to show the status of A:

10 A=0
20 A=A+1
30 POKE &HE4
40 PAUSE:LOCATE 10,10:PRINT A
50 GOTO 20

After A is 255, the screen has wrapped around in a full cycle. Also what's interesting is that the print of A only stays on the same line 8 counts, then takes another line even though the location specified is 10,10.

EDIT: I understand why the number takes a new line every 8 counts - it's because it moves the entire screen 1 pixel at a time and once 8 pixels have been moved, a new line has been made. 8 pixels is the height of a line. So the location 10,10 is correct.

UglyJoe

I tried the examples but found that they didn't work when I removed the PAUSE statement.  I got around this by poking the scroll registers directly.  Here's my v2.1a code listing for generating a star field and then scrolling it vertically indefinitely:


10 CLS
20 FOR I=1 TO 30
30 RX=RND(27):RY=RND(24)
40 IF SCR$(RX,RY)<>" " GOTO 30
50 LOCATE RX,RY:PRINT CHR$(205)
60 NEXT
150 A=0
200 REM PAUSE 1
250 POKE &H2005,0
300 POKE &H2005,A
500 A=A+1
600 IF A>239 THEN A=0
650 GOTO 200


You can unREM line 200 to make the stars scroll a bit more slowly.  I stole the starfield code from a book, but will have to rewrite it at some point since you can't use LOCATE to draw onto all portions of the background (hence the big black gap you see between the bottom and top of the starfield when scrolling).

zmaster18

I just tried this in V3 and it works well. Very impressive. So is horizontal scrolling possible? I noticed that when I REM line 250, it scrolls diagonally.

UglyJoe

Quote from: zmaster18 on August 23, 2015, 09:27:11 am
I just tried this in V3 and it works well. Very impressive. So is horizontal scrolling possible? I noticed that when I REM line 250, it scrolls diagonally.


Horizontal scrolling is possible (I've seen it done in a video).  The two POKEs to 2005 set the horizontal and vertical scroll positions (respectively).  Because FB uses vertical mirroring, you can scroll vertically and the nametable will appear to wrap around.  When scrolling horizontally (basically, swap 250 and 300), you'll see the stars move off the left of the screen into a blank screen.  The screen is blank because it's not a mirror of the first page.  If I can figure out a better starfield routine (one that fills the whole screen), then I'll probably also have a way of writing to that blank page.  (I suspect this is easier to do in V3, since it supports two backgrounds, but I haven't looked up those details, nor do I own a V3 cart).

P

Quote from: UglyJoe on August 23, 2015, 09:08:51 am
I got around this by poking the scroll registers directly.

I didn't think that was possible since I couldn't get it to work. I must had done something wrong.
This is much better than messing with those RAM registers anyway. Good job!