Welcome, Guest. Please login or register.
Did you miss your activation email?
June 26, 2019, 09:49:58 AM
Home Famicom World Search Calendar Login Register

+  Famicom World
|-+  Family Computer
| |-+  Famicom / Disk System (Moderators: manuel, L___E___T)
| | |-+  Family BASIC scrolling backgrounds
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: Family BASIC scrolling backgrounds  (Read 7140 times)
zmaster18
Twin Famicom
*****
Gender: Male
Canada Canada
Posts: 984



WWW
« on: August 20, 2015, 07:47:15 PM »

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.
Logged
UglyJoe
Administrator
Disk-kun
*****
Gender: Male
United States United States
Posts: 5434



WWW
« Reply #1 on: August 20, 2015, 07:58:22 PM »

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).
Logged
zmaster18
Twin Famicom
*****
Gender: Male
Canada Canada
Posts: 984



WWW
« Reply #2 on: August 20, 2015, 08:22:51 PM »

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.
Logged
P
FamicomBox
*****
Gender: Male
Sweden Sweden
Posts: 3430


« Reply #3 on: August 20, 2015, 10:05:51 PM »

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.
« Last Edit: August 21, 2015, 05:17:18 AM by P » Logged

zmaster18
Twin Famicom
*****
Gender: Male
Canada Canada
Posts: 984



WWW
« Reply #4 on: August 20, 2015, 10:58:41 PM »

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.
Logged
P
FamicomBox
*****
Gender: Male
Sweden Sweden
Posts: 3430


« Reply #5 on: August 21, 2015, 05:50:39 AM »

Ah parallax scrolling even. Smiley 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?
« Last Edit: August 21, 2015, 09:59:11 PM by P » Logged

UglyJoe
Administrator
Disk-kun
*****
Gender: Male
United States United States
Posts: 5434



WWW
« Reply #6 on: August 22, 2015, 11:46:42 AM »

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.
Logged
P
FamicomBox
*****
Gender: Male
Sweden Sweden
Posts: 3430


« Reply #7 on: August 22, 2015, 12:31:58 PM »

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.

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.

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.
Code:
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.
Code:
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.
« Last Edit: August 22, 2015, 04:25:36 PM by P » Logged

zmaster18
Twin Famicom
*****
Gender: Male
Canada Canada
Posts: 984



WWW
« Reply #8 on: August 22, 2015, 09:48:30 PM »

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.  Grin  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.
Logged
P
FamicomBox
*****
Gender: Male
Sweden Sweden
Posts: 3430


« Reply #9 on: August 23, 2015, 06:50:14 AM »

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 Embarrassed).

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):
Code:
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.
Logged

zmaster18
Twin Famicom
*****
Gender: Male
Canada Canada
Posts: 984



WWW
« Reply #10 on: August 23, 2015, 12:36:04 PM »

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:
Code:
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.
« Last Edit: August 23, 2015, 03:19:56 PM by zmaster18 » Logged
UglyJoe
Administrator
Disk-kun
*****
Gender: Male
United States United States
Posts: 5434



WWW
« Reply #11 on: August 23, 2015, 03:08:51 PM »

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:

Code:
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).
Logged
zmaster18
Twin Famicom
*****
Gender: Male
Canada Canada
Posts: 984



WWW
« Reply #12 on: August 23, 2015, 03:27:11 PM »

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.
Logged
UglyJoe
Administrator
Disk-kun
*****
Gender: Male
United States United States
Posts: 5434



WWW
« Reply #13 on: August 23, 2015, 04:00:58 PM »

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).
Logged
P
FamicomBox
*****
Gender: Male
Sweden Sweden
Posts: 3430


« Reply #14 on: August 23, 2015, 04:50:51 PM »

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!
Logged

Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!