In and Out of SYNC

See all articles from SYNC v3 n5

Making Borders and a Bouncing Ball

David Grosjean

We will begin our series on comparative programming with the Panasonic JR-200, the Vic-20, and the TS1000. Our first exercise is to develop step by step the routine for creating a border around the screen and then vary its dimensions. Our second exercise is develop a routine for a bouncing ball. Both exercises are useful in certain types of games.

Making Borders

Our first exercise is easy on the JR-200 and TS1000 because they have the PLOT command, while the Vic-20 does not. First, let’s look at the PLOT command.

On the JR-200, the X axis is along the top (from 0 to 63), and the Y axis is down the left (from 0 to 47). On the TS1000, the X axis is along the bottom of the screen (from 0 to 63), and the Y axis is up the left side (from 0 to 43).

Let’s PLOT a single point at the center of the screen. Notice that a rather complicated method of cursor movement is the simplest method for the Vic, while the JR-200 and TS1000 use the easier PLOT command.

JR-200:           TS1000:
PLOT 31,23 PLOT 30,21

VIC-20;

 5 PRINT "#"
10 FOR I=1 TO 11
20 PRINT "####";
30 NEXT I
40 PRINT "###"

Line notes for the Vic:

5: The control character is a clear screen character.

10: The control characters in the quotation marks are: reverse on, cursor right, cursor down, reverse off.

40: The control characters are: reverse on, one space, reverse off.

To light up this point without any other printing on the screen, use these short programs:

JR-200:           TS1000:
10 CLS 10 CLS
20 PLOT 31,23 20 PLOT 30,21
30 GOTO 20 30 GOTO 20

To the Vic version above, add 50 GOTO 50. This does not keep printing the point over and over again, but it does avoid printing on the screen.

Now, how can we expand this one point to a whole line? One way would be to use a series of PLOT statements. For example:

JR-200:           TS1000:
10 CLS 10 CLS
20 PLOT 1,23 20 PLOT 1,21
30 PLOT 2,23 30 PLOT 2,21
40 PLOT 3,23 40 PLOT 3,21
• •
• •
640 PLOT 63,23 640 PLOT 63,21

Obviously, this is very inefficient and cumbersome. We could use a FOR-NEXT statement instead:

JR-200:             TS1000:
10 CLS 10 CLS
20 FOR X=0 TO 63 20 FOR X=0 TO 63
30 PLOT X,23 30 PLOT X,21
40 NEXT X 40 NEXT X
50 GOTO 20 50 GOTO 20

Vic-20:

 5 PRINT "#"
10 FOR I=1 TO 11
20 PRINT "###";
30 NEXT I
40 FOR I=1 TO 22
50 PRINT "###";
60 NEXT I
70 GOTO 70

Line notes for the Vic:

5: Control character is to clear screen.

20: Control characters are: reverse on, cursor down, reverse off.

50: Control characters are: reverse on, one space, reverse off.

These programs simply draw a horizontal line and, when finished, draw it over and over again.

As long as we are varying X from the left to right of the screen, why not draw two horizontal lines at once, one at the top and one at the bottom? Here are the programs to do this:

JR-200:             TS1000:
10 CLS 10 CLS
20 FOR X=0 TO 63 20 FOR X=0 TO 63
30 PLOT X,0 30 PLOT X,0
40 PLOT X,47 40 PLOT X,43
50 NEXT X 50 NEXT X
60 GOTO 20 60 GOTO 20

Vic-20:

On the Vic, drawing one line using cursor movement is fairly easy, but when you get into more than that, it is easier to POKE into the screen memory. From now on, we will only use POKE. In the following program, SM is the start of screen memory, and the control character in line 10 is the clear screen control character.

In lines 40 and 50, the second POKE command POKEs into the color memory. This is to insure that what you POKE into the screen memory is not the same color as the background. Now that we are POKEing, there are no X,Y coordinates; each space on the screen is numbered consecutively, so our equations for the correct display must change.

10 PRINT "#"
20 SM=7680
30 FOR I=0 TO 21
40 POKE SM+I,160:POKE 38400+I,2
50 POKE SM+484+I,160:POKE 38884,2
60 NEXT I

But we want to have vertical borders, too. We can use the same loop by adding two more PLOT statements.

JR-200:

10 CLS
20 FOR X=0 TO 63
30 PLOT X,0
40 PLOT X,47
50 PLOT 0,X
60 PLOT 63,X
70 NEXT X
80 GOTO 20

TS1000:

10 CLS
20 FOR X=0 TO 63
30 PLOT X,0
40 PLOT X,43
50 PLOT 0,X
60 PLOT 63,X
70 NEXT X
80 GOTO 20

But a value error occurs in line 50 because X exceeds the maximum Y value that can be plotted. This can be fixed easily be adding a line before 50 to test for a value of X over the maximum.

JR-200: 45 IF X>43 THEN 70
TS1000: 45 IF X>47 THEN GOTO 70

This final program is one of the shortest ways to draw a border. Of course, if you are using this routine in another program, you would not need line 80.

Vic-20:

On the Vic letting the overflow mistake occur as on the other machines would be too risky to the program in memory because we are POKEing. Therefore we must add the overflow checking line (line 45) before we make a possibly disastrous mistake. Several times while we were developing this routine, we completely lost control of the computer and simply had to turn it off and on again. Needless to say, this required much retyping. (If you are writing your own program, you cannot write the test line first; you must do it through testing.)

 10 PRINT "#"
20 SM=7680
30 A=4
40 FOR I=0 TO 22
45 IF I>=22 THEN 70
50 POKE SM+I,160:POKE 38400+I,A
60 POKE SM+I+484,160:POKE 38884+I,A
70 POKE SM+I*22,160:POKE 38400+I*22,A
80 POKE SM+I*22+21,160:POKE 38421+I*22,A
90 NEXT I
100 GOTO 100

On the JR-200, color can be added easily by adding a line 5. Try these:

5 COLOR 1
5 COLOR 3,5
5 COLOR 2,6,3

To add a variety of color to the Vic, change line 30 to:

30 A=INT(7*RND(0))

In the previous program, instead of having the border print at the edges of the screen, it is possible to let the non X value vary. We will let the distance or increment from the edge of the screen be I. The value of I can be used as the coordinate for the top and left side; however, the right side must be defined as 63-I (JR-200 and TS1000) and the bottom as 47-I (JR-200) or 43-I (TS1000).

This program uses these relationships to draw a series of concentric borders which start at random points in the upper left quarter of the screen. Note that the test to see if the maximum Y value has been exceeded is changed somewhat. Can you explain why?

JR-200:

 10 CLS
20 RANDOMIZE
30 I=INT(23*RND(0))
40 COLOR (INT(8*RND(0))
50 X2=63-I
60 Y2=47-I
70 FOR X=I TO X2
80 PLOT X,I
90 PLOT X,Y2
100 IF X2-X<=16 THEN 130
110 PLOT I,X
120 PLOT X2,X
130 NEXT X
140 GOTO 30

TS1000:

 10 CLS
20 RAND
30 LET I=INT (RND*22)
50 LET X2=63-I
60 LET Y2=43-I
70 FOR X=I TO X2
80 PLOT X,I
90 PLOT X,Y2
100 IF X2-X<=20 THEN GOTO 130
110 PLOT I,X
120 PLOT X2,X
130 NEXT X
140 GOTO 30

Again, since we are not using a coordinate system on the Vic, the equations to figure out the parameters of each border are different from the equations of the TS1000 and JR-200. Can you figure out how the equations work? Tip: lines 100 and 110 draw the horizontal lines. CM is the start of color memory; SM is the start of screen memory; B is a random color; I is a random starting point for the borders. Remember also that the Vic screen is 22 by 23 (0 to 21 and 0 to 22).

 10 PRINT "#"
20 SM=7680
30 CM=38400
40 I=INT(11*RND(0))
50 B=INT (8*RND(0))
60 X2=21-I
70 Y2=22-I
80 FOR X=I TO Y2
90 IF Y2-X<=1 THEN 120
100 POKE SM+I*22+X,160:POKE CM+I*22+X,B
110 POKE SM+Y2*22+X,160:POKE CM+Y2*22+X,B
120 POKE SM+X*22+I,160:POKE CM+X*22+I,B
130 POKE SM+X*22+X2,160:POKE CM+X*22+X2,B
140 NEXT X
150 GOTO 40

Making a Bouncing Ball

Our second exercise is a simple one for the JR-200 and TS1000: to produce a ball that bounces off the borders of the screen. At this point, we will deal only with the JR-200 and TS1000 since the method for doing this on the Vic is vastly different.

Let’s start with just four main statements: one to give us a starting point for our plot of a bouncing ball, one to clear the screen, one to plot the ball, and one to repeat the plot.

JR-200              TS1000:
10 X=2:Y=2 10 LET X=2
50 CLS 15 LET Y=2
160 PLOT X,Y 50 CLS
190 GOTO 160 160 PLOT X,Y
190 GOTO 160

This is definitely a long way from bouncing, so let’s get the ball moving by adding the following lines. Remember, use SLOW mode on the TS1000 if you want to see the ball.

JR-200              TS1000
20 I=1:J=1 20 LET I=1
90 X=X+I 25 LET J=1
100 Y=Y+J 90 LET X=X+I
190 GOTO 90 100 LET Y=Y+J
190 GOTO 90

As you can see, the same thing happened as with the border program, namely, the values exceeded the dimensions of the screen. To avoid this, we must add four IF statements to test for the screen edges. On the TS1000 version, we combined them into two statements to increase the speed a little. (As you know, SLOW mode really is SLOW!)

JR-200:

110 IF X>=62 THEN I=-I
120 IF X<=1 THEN I=-I
130 IF Y>=46 THEN J=-J
140 IF Y<=1 THEN J=-J

TS1000:

110 IF X>=62 OR X<=1 THEN LET I=-I
130 IF Y>=42 OR Y<=1 THEN LET J=-J

What happens when you RUN the program now? Try it and see. Just for kicks, on the JR-200 version add line 150 to change the color of the ball:

150 COLOR (INT(1+6*RND(0)))

While these programs produce interesting patterns, it is hardly a bouncing ball because the computer does not erase the previous ball position when it draws a new one. Add these lines to do that:

JR-200:

 70 COLOR 5
80 PLOT X,Y
190 GOTO 70

TS1000

 80 UNPLOT X,Y
190 GOTO 70

Now the program works at it ought to, but you may wish to add a few more lines that give you the opportunity to choose whether the trail of the ball be erased or not. We also added a beep when the ball hits the edge of the screen on the JR-200. Here is the final program:

JR-200:

 10 X=2:Y=2
20 I=1:J=1
30 PRINT "Leave trail (y,n)"
40 INPUT A$
50 COLOR 0,0
60 CLS
70 COLOR 0,0
80 PLOT X,Y
90 X=X+I
100 Y=Y+J
110 IF X>=62 THEN I=-I:BEEP 1
120 IF X<=1 THEN I=-I:BEEP 1
130 IF Y>=46 THEN J=-J:BEEP 1
140 IF Y<=1 THEN J=-J: BEEP 1
150 COLOR (INT(1+6*RND(0)))
160 PLOT X,Y
170 BEEP 0
180 IF A$="Y" OR A$="y" THEN 90
190 GOTO 70

TS1000:

 10 LET X=2
15 LET Y=2
20 LET I=1
25 LET J=1
30 PRINT "LEAVE TRAIL? (Y,N)"
40 INPUT A$
50 CLS
70 UNPLOT X,Y
90 LET X=X+I
100 LET Y=Y+J
110 IF X>=62 OR X<=1 THEN I=-I
130 IF Y>=42 OR Y<=1 THEN J=-J
160 PLOT X,Y
180 IF A$="Y" THEN GOTO 90
190 GOTO 70

When a trail is left, the plot eventually fills in only every other screen location. How could we modify it to fill in every location? There are two or three ways to accomplish this, some of which produce more interesting effects than others. Hint: try doing it with a random variable or tricky rebounds.

Vic-20:

The Vic program for making a bouncing ball is altogether different from the TS1000 and JR-200 versions because we had to use POKE to produce the same effect. Let’s start with a few statements to get a ball onto the screen and to make sure that it can be seen against the background. The control character in line 30 is the clear screen control character.

 30 PRINT "#"
40 X=7680
60 CM=38400
80 B=2
110 POKE X,81:POKE CM,B

That is, of course, a very long way from bouncing, so we can get the ball moving with the following lines. As in the border program, we must add the checking lines before you test the program, unless you enjoy subjecting your program to a possible crash. Also, be very certain that you type in the checking lines accurately; they are extremely important. When you are writing your own programs using POKE, you will find that the computer can and will crash. Then you will have to retype your program, if you did not SAVE it first. For experience, try changing the addresses of some of the POKE commands and see what happens. It is not a pretty sight.

 50 I=23
90 CM=CM+I
100 X=X+I
120 IF X>8163 THEN I=I-44
130 IF X<7702 THEN I=I+44
140 IF (X-7680)/22=INT((X-7680)/22) THEN I=I+2
150 IF (X-7679)/22=INT((X-7679)/22) THEN I=I-2
190 GOTO 80

Now you can modify line 80 to what is below. This new line 80 gives the ball a random color. If the color chosen is white (the starting background of the Vic), a new color will be chosen. This is accomplished by the IF statement at the end:

80 B=INT (7*RND(0)):IF B=1 THEN 80

Although this program produces pretty patterns, it is still not a true bouncing ball because the trail is not erased. Line 180 erases the trail by POKEing a space into the last position of the ball.

180 POKE X,32

Now the program is complete, but you may want more frills. The following program, in addition to bouncing a ball, gives you the option of erasing the trail or leaving it, and it adds a beep when the ball hits a side. Make sure you type this in exactly as shown.

  5 POKE 36874,249
10 PRINT "LEAVE TRAIL (Y,N)"
20 INPUT A$
30 PRINT "#"
40 X=7680
50 I=23
60 CM=38400
70 A=36878
80 B=INT(7*RND(0)):IF B=1 THEN 80
90 CM=CM+I
100 X=X+I
110 POKE X,81:POKE CM,B
120 IF X>8163 THEN I=I-44:POKE A,15
130 IF X<7702 THEN I=I+44:POKE A,15
140 IF (X-7680)/22=INT((X-7680)/22) THEN I=I+2: POKE A,15
150 IF (X-7679)/22=INT((X-7679)/22) THEN I=I-2:POKE A,15
160 POKE A,0
170 IF A$="Y" THEN 80
180 POKE X,32
190 GOTO 80

The Panasonic JR-200 Personal Computer

David H. Ahl

The Panasonic JR-200 personal computer from Matsushita has been several years in the making, and it was worth the wait.

Handsome Styling

Outwardly, the JR-200 has modern, pleasing styling. The plastic case measures 13.5″ X 8.0″ and slants from a height of 1″ in the front to 2″ in the rear. Finished in silver and matte black in the keyboard area, the case is rugged and durable.

Connectors and Switches

An 8-pin D.I.N. connector provides for an NTSC composite video or RGB monitor, while an RCA jack gives an RF signal on channel 3 or 4 at a 75-ohm impendence. On most current TV sets with a 75-ohm F-type input the JR-200 produces a crisp, clear image, almost of monitor quality.

Another RCA jack provides 8-ohm audio output to an external speaker. Audio power is more than adequate; people in the rear of a 100-seat conference room had no trouble hearing the internal speaker during a demonstration.

A second 8-pin D.I.N. connector is for the tape recorder. A DIP switch selects either 600 or 2400 bps. We were pleased to find that the JR-200 performed reliably at 2400 BPS on modest quality ($19-$29) recorders over a reasonable range of volume settings on standard tape.

Two other connectors are for a printer and an external bus. Via this bus, the JR-200 has a serial RS-232C port which may be set up for half or full duplex, 7- or 8-bit words, and odd, even, or no parity. JR-Basic does not use the standard format for RS-232C communications. Although data may be transmitted by using the OPEN-INPUT#/PRINT#-CLOSE statements a routine is needed to send or receive data on the end of the line.

User-Friendly Keyboard

The keyboard has 63 “Chiclet” style rubberized keys in standard typewriter layout, a 5″ spacebar, two double-width shift keys, and a double-height return key. The keys are 1/2″ square with standard keyboard spacing.

As on the TS1000, each key can make multiple inputs. The JR-200 has 253 built-in characters: 96 English letters, numbers, and symbols; 5 Greek letters; 63 graphics characters; 79 Katakana (Japanese) symbols; and 10 music and other symbols. All told, this is an exceptionally rich character set, right down to the inclusion of a happy face and stick figure man. All the symbols are formed within an 8 X 8 matrix as on the TS1000.

Although the keys do not provide any tactile feedback, each keystroke is accompanied by a beep. All keys can repeat except CONTROL, SHIFT, RETURN, and BREAK.

Screen Display

Like the TS1000, the screen display is 32 X 24, and PLOT gives medium resolution of 64 X 48. However, very high resolution images, up to 256 X 192, are possible with LOCATE (x,y) which can address each of the 768 locations.

PLOT is also used with COLOR to select character color, background color, and display mode. Four display modes are available: normal, user-defined characters, inverse color of previous characters, and alter background color for positions following the cursor. When we got the hang of it, we found the COLOR command very powerful for producing interesting, and occasionally bizarre, effects.

Eight colors are available for foreground and background use: blue, red, magenta, green, cyan, yellow, white, and black.

Sound

While the JR-200 is theoretically capable of producing tones from 0 to 65535 Hz, realistically, the usable sound range is about five octaves, an impressive achievement in a computer of this size. The simplest way of producing sound is with BEEP 1 which turns on the beeper (880 Hz or A above the middle octave).

The next step up is SOUND (P,L) in which P is the pitch in Hertz (0 to 65535) and L is the length of the tone in milliseconds (0 to 255). This is very easy to use in a program.

More complicated are the PLAY and TEMPO commands which permit playing tunes with up to three parts over a 5-octave range at any imaginable tempo. Notes are stored in memory and may be played either in foreground (pauses program) or background (program continues) mode.

JR-200 Basic

JR-Basic is not Microsoft Basic, but it is not far away either. Most of the commands, statements, and functions are identical or very similar. Let’s look at some of the more interesting and novel features.

JR-Basic has immediate mode and will execute most Basic commands directly from the keyboard singly or in groups (separated with a colon) as long as the maximum line length of 80 characters is not exceeded.

When the JR-200 is fired up, a copyright notice appears along with the number of free bytes. In all configurations, 2052 bytes are reserved for the Basic work area and the remaining RAM is available to the user. User memory can be expanded to 40K. Basic occupies 16K of ROM while video RAM, I/O, and the built-in character set use another 6K plus.

JR-Basic requires that Basic keywords be separated by at least one space or a colon or semi-colon from other characters. This enhances the readability of finished programs.

Numeric values can range from 2.9^-39 to 1.06^38 and are stored and displayed with nine digits of accuracy. Both numeric and string variable arrays can have one or two dimensions. Unfortunately, variable names are restricted to two letters or a letter and a number.

All the standard operators are available: arithmetic, relational, logical and string concatenation. LET is optional.

RUN performs its usual function but can also be imbedded within a program to run another program or to run the existing program from any specified line number, e.g., RUN 480. When used with a filename (RUN “Border”), it will load the program from tape and then run it.

The functions HOPS and VPOS return the current horizontal and vertical position of the cursor respectively. PEEK and POKE function as on the TS1000. An unusual function is VARPTR which returns the memory location where a particular variable is stored.

On-Screen Editing

A delightful feature of the JR-200 is full on-screen editing. To correct a mistake or make a change you simply list the line or group of lines to be changed, and move the cursor with the four directional keys to the character to be changed. Then type in the change or use the insert, delete, or rub out keys. You then move the cursor to the end of the line and type RETURN. Whoosh; the change is made.

FIND searches for a string of characters and then lists the line(s) with that combination of characters. LFIND performs the same function but lists the lines on the printer.

Tape Handling and Files

LOADing and SAVEing are done as on the TS1000, but there are some additional commands.

MSAVE and MLOAD permit files or other material to be saved and loaded directly from and to memory.

MERGE enables loading one program at the end of another.

VERIFY checks to see if a program in memory and on tape match.

PRINT # stores files of data (not programs) sequentially on tape, and INPUT # reads back the data. While sequential tape files are not nearly as handy as random access disk files, the 2400 bps I/O speed is quite tolerable.

Printed Output

The JR-200 has five printer commands: LPRINT and LLIST as on the TS1000; HCOPY which is the same as COPY on the TS1000; TAB which tabs over from the left margin; and SPC which spaces over from the last cursor position.

Joysticks

Two DB-9 sockets accept standard Atari-tyupe joysticks. Values form them can be read into programs by means of the STICK function.

Monitor Commands

The JR-200 allows machine language aficionados to get into the monitor and the assembly language.

The monitor has only three commands: D, M, and G. D displays 128 bytes of memory from the location from the address specified and allows you to alter them. G begins execution of an assembly language program from a specified address. Memory locations are all in hexadecimal.

Software and Support

Panasonic is sincere in trying to provide support for the JR-200. All the early machines have been put in the hands of software developers such as Datamost—a smart move for getting third party software on the market. Also Datamost has produced a version of their book, Kids and the Apple, for the JR-200. Likewise, we are in the process of producing a volume in our ideabook series for the JR-200, The Panasonic JR-200 Ideabook.

On the other hand, the preliminary JR-Basic manual is tough going, has very few programming examples, and could in no way be considered user-friendly. We are told that the Datamost book will be supplied with the JR-200 as the Basic programming primer.

In Summary

The Panasonic JR-200 is one of the nicest new computers to make the scene in some time. Attractively styled and easy to use, it boasts an excellent, if not standard, Basic language. The graphics are very approachable and, although resolution is not exceptionally high, the character set is excellent and allows the creation of detailed images. The keyboard is among the best of its type and the separate cursor movement keys make on-screen editing a joy. The JR-200 is cassette tape oriented and uses it well for program and data storage.

Peripherals, documentation, software and support are, at this time, question marks although Panasonic appears to be moving in the right direction on all fronts.

At the suggested list price of $350, the JR-200 is an excellent choice.