Sharp logo

MZ-800 course Chapter 4 
4. Video-RAM


4.2 More funny things in Video-RAM

In this part of chapter 4 we will show some more programs that demonstrate what is possible in Video-RAM. We will also give the BASIC program, so you can compare the speed of machine code with the speed of BASIC.

Program 1: Inverse.

The following program will inverse the colours on the screen. Black will become white and vice versa.

10 POKE $F800,$DB,$E0,$21,$0,$80,$E,$C8,$6,$28,$16,$4,$3E,$1,
$D3,$CC,$D3,$CD,$87,$32,$C,$F8,$7E,$2F,$77,$15,$20,$F0,$23,$3E,
$1,$32,$C,$F8,$10,$E6,$D,$20,$E1,$DB,$E1,$C9
20 USR($F800)

Inverse in BASIC:

10 FOR Y=0 TO 199
20 FOR X=0 TO 319
30 SET [3-POINT(X,Y)]X,Y
40 NEXT X,Y

If you have got the expansion ICs and if you run the program in mode M2, you can change line 30 to:

30 SET [15-POINT(X,Y)]X,Y

Program 2: Rain.

This program makes everything on the screen disappear by deleting a small part of the screen at a random position. This looks somewhat like rain, hence the title.

10 COLOR 0:CURSOR 0,0:PRINT CHR$(200);
20 DATA $DB,$E0,$11,$00,$00,$21,$00,$80,$3E,$3C,$32,$30,$D0,$E5,$DB,
$D5,$5F,$19,$36,$FF,$E1,$11,$80,$00,$19,$3A,$30,$D0,$3D,$20,$EB,$DB,
$E1,$C9
30 FOR T=0 TO 33:READ A:POKE $D000+T,A:NEXT T
40 FOR A=1 TO 2000:USR($D000):NEXT A
50 INIT "CRT:M1"

Rain in BASIC:

10 INIT "CRT:M1":LIST:LIST:LIST
20 FOR T=1 TO 100000
30 X=INT(RND*40):Y=INT(RND*200):LINE [0]X*8,Y,X*8+7,Y:NEXT T

Program 3: Mirror in the central Y-axis.

This program turns the whole screen around. In fact it is mirrored in the vertical axis that runs through the middle of the screen. Everything will therefore be mirrored.

10 DATA $DB,$E0,$21,$00,$80,$11,$27,$80,$0E,$C7,$06,$14,$C5,$3E,$01,
$D3,$CC,$D3,$CD,$7E,$CD,$46,$FC,$08,$1A,$CD,$46,$FC,$77,$08,$12,$3A,
$0E,$FC,$87,$32,$0E,$FC,$FE,$10,$20,$E3,$3E,$01,$32,$0E,$FC
20 DATA $23,$1B,$C1,$10,$D8,$06,$14,$23,$13,$13,$13,$10,$FA,$00,$00,
$00,$00,$0D,$20,$C7,$DB,$E1,$C9,$CB,$47,$28,$2E,$CB,$F8,$CB,$4F,$28,
$2D,$CB,$F0,$CB,$57,$28,$2C,$CB,$E8,$CB,$5F,$28,$2B,$CB,$E0,$CB,$67,
$28,$2A,$CB,$D8,$CB,$6F,$28,$29,$CB,$D0,$CB,$77,$28
30 DATA $28,$CB,$C8,$CB,$7F,$28,$27,$CB,$C0,$78,$C9,$CB,$B8,$C3,$4C,
$FC,$CB,$B0,$C3,$52,$FC,$CB,$A8,$C3,$58,$FC,$CB,$A0,$C3,$5E,$FC,$CB,
$98,$C3,$64,$FC,$CB,$90,$C3,$6A,$FC,$CB,$88,$C3,$70,$FC,$CB,$80,$C3,
$76,$FC
40 FOR T=0 TO 159:READ A:POKE $FC00+T,A:NEXT T
50 USR($FC00)

Vertical mirror in BASIC:

10 INIT "CRT:M1"
20 COLOR 2:LIST
30 COLOR 3:LIST
40 FOR Y=0 TO 199
50 FOR X=0 TO 159
60 A=POINT(X,Y):B=POINT(319-X,Y)
70 SET [B]X,Y:SET [A]319-X,Y
80 NEXT X,Y

Program 4: Mirror in the central X-axis.

This program mirrors the screen in the horizontal axis that runs through the middle of the screen. An even better result can be obtained when this program is combined with program 3.

10 DATA $DB,$E0,$11,$18,$9F,$21,$00,$80,$0E,$64,$06,$28,$C5,$3E,$01,
$D3,$CC,$D3,$CD,$7E,$08,$1A,$08,$12,$08,$77,$3A,$0E,$FC,$87,$32,$0E,
$FC,$FE,$10,$20,$E8,$3E,$01,$32,$0E,$FC,$23,$13,$C1,$10,$DD,$06,$50,
$1B,$10,$FD,$0D,$20,$D3,$DB,$E1,$C9
40 FOR T=0 TO 57:READ A:POKE $FC00+T,A:NEXT
50 USR($FC00)
60 CURSOR 0,23

Horizontal mirror in BASIC:

10 INIT "CRT:M1"
20 COLOR 2:LIST
30 COLOR 3:LIST
40 FOR Y=0 TO 99
50 FOR X=0 TO 319
60 A=POINT(X,Y):B=POINT(X,199-Y)
70 SET [B]X,Y:SET [A]X,199-Y
80 NEXT X,Y

Program 5: ( Random ) colours.

This program gives each byte a more or less random colour. The colour is not entirely random, because a computer is a logical device and can not pick a random number. By adding something extra to the program we got something that approximates randomness a bit more. Just add the following line and see the difference:

35 POKE $D010,0,0,0

You will see clearly that the randomness is gone for the most part.

This program only works with the extra ICs.

10 INIT "CRT:M1"
20 DATA $DB,$E0,$21,$00,$80,$0E,$C8,$06,$28,$DB,$D5,$D3,$CC,$36,$FF,
$23,$3D,$20,$FD,$10,$F4,$0D,$20,$EF,$DB,$E1,$C9
30 FOR T=0 TO 26:READ A:POKE $D00+T,A:NEXT T
40 USR($D000)

Random colours in BASIC:

10 INIT "CRT:M2"
20 FOR Y=0 TO 199
30 FOR X=0 TO 319 STEP 8
40 LINE [RND*16]X,Y,X+7,Y
50 NEXT X,Y

In anticipation of program 7, we want to show you the following:

It is possible to use 13 colours in mode M1, in this program it can be done by adding the following lines to the machine language program:

15 INIT "CRT:M1":OUT@$CE,2:CLS

To jump back to four colours, type:

OUT@$CE,0

We will go into this in the following programs.

People that have the extra Video-RAM ICs can use 16K of extra memory in modes M1 and M3. This is because of the fact that in those modes there are two frames for the colours ( In modern terminology, we use the term page instead of frame and the method described here is related to page-flipping ). In mode M1 there are 2 primary colours and in mode M3 there is one. Because there is only one frame in use in both of these modes, we can use the other frame to store something else. We can use the entire second frame like this, without seeing something on the screen. The following program uses this method.

Program 6: Rain with restoration of the screen.

This program does the same as program 2, except for the fact that the screen is restored when the program ends. We start by copying the screen to the other frame. Then we let the screen decay and afterwards, we copy the second frame back to the first one, thereby restoring the original screen.

Of course it does not matter what is displayed on the screen, we use “NEPTUNES PRODUCTIONS” as an example. It does not matter what is displayed, everything will return to its original position and NO extra normal memory is used, just a piece of unused Video-RAM.

10 INIT "CRT:M1"
20 DATA $DB,$E0,$3E,$80,$D3,$CC,$11,$00,$00,$21,$00,$80,$3E,$3C,$32,
$30,$D0,$E5,$DB,$D5,$5F,$19,$36,$FF,$E1,$11,$80,$00,$19,$3A,$30,$D0,
$3D,$20,$EB,$DB,$E1,$C9
30 FOR T=0 TO 37:READ A:POKE $D000+T,A:NEXT T
40 CURSOR 0,9
50 COLOR 1:PRINT" ****** NEPTUNES PRODUCTIONS ****** "
60 COLOR 2:PRINT" ****** NEPTUNES PRODUCTIONS ****** "
70 COLOR 3:PRINT" ****** NEPTUNES PRODUCTIONS ****** "
80 DATA $DB,$E0,$3E,$04,$D3,$CC,$3E,$01,$D3,$CD,$21,$00,$80,$11,$00,
$80,$01,$40,$1F,$ED,$B0,$DB,$E1,$C9
90 DATA $DB,$E0,$3E,$08,$D3,$CC,$3E,$02,$D3,$CD,$21,$00,$80,$11,$00,
$80,$01,$40,$1F,$ED,$B0,$DB,$E1,$C9
100 FOR A=0 TO 23:READ B:POKE $FD00+A,B:NEXT A
110 FOR A=0 TO 23:READ B:POKE $FD20+A,B:NEXT A
120 USR($FD00):USR($FD20)
130 FOR A=1 TO 2000:USR($FD00):NEXT
140 POKE $FD03,1:POKE $FD07,4:POKE $FD23,2:POKE $FD27,8:USR($FD00):
USR($FD20)

There is also the possibility of using 13 colours in mode M1. This is done by displaying both the first and the second frame. How this is done is shown in the next program.

Program 7: 13 colours in mode M1.

As mentioned twice before, there is the possibility of using 13 colours in mode M1, this is done by displaying frame A and B at the same time. In fact you are playing a trick on the computer. Everything works like it should in mode M1, except for the Video-RAM, it is in mode M2.

Why are there only 13 colours and not 16? This has to do with the fact that in mode M1 the colours red and blue yield the colour white ( this also applies after the change ) and in mode M2 this combination will yield purple. In mode M1 all four colours together will also yield white, as in mode M2. All in all this gets very complicated. Hopefully it makes some sense. To keep the program relatively short, the field is built up in mode M2 and then shown in mode M1. Neither are all 13 colours shown. With a small piece of machine code we can make all 13 colours visible. We will not do that here, because the objective is to show that it is possible to use more than four colours in mode M1.

Of course this program only works with the extra ICs.

10 INIT "CRT:M2"
20 FOR A=0 TO 15
30 BOX [A]A*20,A*12,A*20+15,A*12+8,A
40 NEXT A
50 INIT "CRT:M1"
60 FOR A=0 TO 15 STEP 2
70 BOX [1]A*20,A*12,A*20+15,A*12+8,1
80 NEXT A
90 FOR A=0 TO 15 STEP 4
100 BOX [2]A*20,A*12,A*20+15,A*12+8,2
110 OUT@$CE,$2
120 NEXT A

In line 110 you see the instruction OUT@$CE,$2. You can accomplish more nice effects with this instruction, for this is the instruction that determines how the memory and also the Video-RAM is partitioned, which determines the screen resolution. For example, a nice effect can be seen when the computer is in mode M3 or M4 and with the OUT@$CE,n the Video-RAM is
partitioned to mode M1 or M2. Just try the following:

INIT "CRT:M3":OUT@$CE,0 - This also works when you do not have the extra ICs.

Or:

INIT "CRT:M4":OUT@$CE,2 - This only works with the extra ICs.

You see that the computer switches to the 40-column mode and that the characters get twice as high. The problem however, is that a line still contains 80 characters. ( Just try it ). Another problem is that the memory is partitioned different and because of this you could loose part of your listing. It would be very nice if the screen could be used this way, but unfortunately, this is ( almost ) impossible.

Previous page
Next page
Contents


Go to the top of this page Home

last updated July 8, 2004
Arjan Habing, Mark de Rover, Jeroen F. J. Laros, sharpmz@sharpmz.org