MZ-800 course Chapter 3
|3. Machine language on the SHARP MZ-800|
Of course you can also use machine language from within BASIC-800. A fine example on this is chapter 4, which covers all of the Video-RAM. Chapter 4 consists mainly of BASIC programs who make sure machine language instructions are executed. In this part of chapter 3 we will do exactly that, the main difference is that these programs have ( almost ) nothing to do with Video-RAM. So all programs can be used by everyone, you do not need the extra ICs.
Program 1: BORDER-change when seeing a flashing cursor.
While the cursor is flashing, the colour of the BORDER changes. So the BORDER will also change on INPUT, because of the flashing cursor.
10 DATA $21,$2C,$09,$36,$20,$23,$36,$F0,$21,$3C,$09,$36, $20,$23,$36,$F0,$C9 20 FOR A=0 TO 16:READ B:POKE $F000+A,B:NEXT 30 DATA $C5,$F5,$DB,$D5,$01,$CF,$06,$ED,$79,$F1,$C1,$CD,
To stop the flashing, type:
POKE $F025,$0 - flashing off.
Program 2: 20 functions keys.
It is possible to use the CTRL-key to define and use 20 function keys.
F1 - F5 = press directly
10 DATA 87,87,87,87,21,5F,57,C3,58,1,!0F 11 DATA FE,14,D2,6A,63,37,3F,DE,A,E5,!03 12 DATA CD,90,55,C3,5C,6C,!40 13 DATA E,0,DF,8,79,C6,31,57,1E,31,!0B 14 DATA FE,3A,20,3,11,32,30,ED,53,20,!39 15 DATA 6C,11,18,6C,DF,B,79,CD,90,55,!4F 16 DATA 46,23,C5,CD,BB,6B,C1,C,79,FE,!B4 17 DATA A,20,D7,DF,8,E1,C9,!46 18 DATA CB,77,C2,7F,C,3A,30,D,FE,FF,!03 19 DATA CA,3B,C,3A,31,D,CB,47,21,AF,!6E 20 DATA 57,28,3,21,5F,57,1,10,0,3A,!12 21 DATA 30,D,CB,7F,28,3,9,CB,77,28,!37 22 DATA 3,9,CB,6F,28,3,9,CB,67,28,!0B 23 DATA 6,9,CB,5F,3A,31,D,C2,3B,C,!C5 24 DATA C3,99,C,C,49,4E,49,54,22,43,!D2 25 DATA 52,54,3A,4D,32,D,0,0,0,8,!46 26 DATA 43,4F,4E,53,4F,4C,45,D,0,0,!66 27 DATA 0,0,0,0,0,6,53,59,4D,42,!A7 28 DATA 4F,4C,0,0,0,0,0,0,0,0,!42 29 DATA 0,6,4C,41,42,45,4C,22,0,0,!CA 30 DATA 0,0,0,0,0,0,0,9,4B,45,!63 31 DATA 59,20,4C,49,53,54,D,0,0,0,!25 32 DATA 0,0,0,6,50,4F,49,4E,54,28,!DD 33 DATA 0,0,0,0,0,0,0,0,0,7,!E4 34 DATA 52,45,53,54,4F,52,45,28,0,0,!30 35 DATA 0,0,0,0,0,B,4F,4E,45,52,!6F 36 DATA 52,4F,52,47,4F,54,4F,0,0,0,!9B 37 DATA 0,9,4C,49,4D,49,54,4D,41,58,!09 38 DATA D,0,0,0,0,0,0,6,53,54,!C3 39 DATA 49,43,4B,28,0,0,0,0,0,0,!C2 40 DATA 0,0,0,0,!C2 100 AD=$5590:RG=10 110 READ A$:IF LEFT$(A$,1)="!" THEN 140 120 POKE AD,VAL("$"+A$):AD=AD+1:CK=CK+VAL("$"+A$):
Of course you can put other instructions in the function keys. An instruction like INIT "CRT:M2" is useless when you do not have the extra ICs in your computer.
You can now use the DEF KEY instruction to define all 20 function keys as you please, you do not have to change any DATA lines.
With the CTRL-key you can define even more, this will be shown in an other program.
Program 3: Sprite movement with the joystick.
This program will make a sprite move with the joystick ( in port 1 ) on the screen. It is not for the full 100% a sprite as it is ( almost? ) impossible to make a complete sprite. In mode M2 there is also the possibility to move a sprite in front of or behind another object. Unfortunately in mode M1 this possibility does not exist. To show everyone how to work with sprites, this program is written for mode M1. After this program some additions will follow in order to move in front of and behind other objects in mode M2. This means that you do not need the extra ICs for this program, but you do for the additions.
10 LIMIT $FC00 20 INIT "CRT:M1":PAL 2,0:PAL 0,14 30 A$=CHR$(239,11,95,96,31,120,74,120,95,223,39,190,167,167,51,25,95,
This program can only be stopped by pressing CTRL/reset.
Moving the sprite in front of an object in mode M2 can be realized by changing and / or adding the following lines:
20 INIT "CRT:M2":PAL 0,14:PAL 3,1:PAL 2,5 80 LINE 0,0,319,0 90 LINE 0,199,319,199 95 CIRCLE 160,100,50:PAINT 160,10,0,2 195 POKE $FC7D,$08:POKE $FCB8,$08:POKE $FD05,$08:POKE $FD24,$08
To make the sprite move behind an object, you only have to change PAL 3,1 in line 20 to PAL 3,5.
In fact this program is also about Video-RAM, but because there is more than enough in chapter 4 and because this program also fits in this chapter, it was discussed here.
Program 4: Changing characters.
BASIC also has the possibility of changing characters. The disadvantage is that it uses 4K of extra memory. The character data is stored from $E000 to $EFFF. You can change the data of a character by multiplying the ASCII-value of the character by 8 and by adding this number to $E000. From this address the 8 bytes of data of the character are stored and by changing the data, you change the character.
Let us start by showing you the program, then we will show you an example on how to change a character.
10 LIMIT $E000 20 INIT "CRT:M1" 30 POKE $FC00,$DB,$E0,$21,$0,$10,$11,$0,$E0,$1,$0,$10,$ED,$B0,$DB, $E1,$C9 40 USR($FC00) 50 POKE $FD00,$29,$CB,$EC,$CB,$F4,$CB,$FC,$C3,$E2,$5 60 POKE $5DF,$C3,$0,$FD
For convenience we will change the letter B to a square. This goes as follows:
If you now type the letter B, you will see a square. This procedure is analogous for other characters.
You can also change the second character set by using $E800 instead of $E000.
You can retrieve the original character set at all times by typing:
Program 5: 2nd character set under CTRL-K.
As said before, the possibility exists to define a lot of keys with the CTRL key. With this program you can use CTRL-K or PRINT CHR$(11) to call the second character set or if you already use the second set, return to the first one. This way even more keys can be used in combination with the CTRL key for special purposes. The problem is that you need to know the address for each key. In order to make things not more difficult, we will not go into this further. After all, we are only interested in programs, not in the BASIC internals.
10 POKE $55ED,$DF,$20,$3A,$D4,$5,$FE,$0,$28,$2,$3E,$FF,$3C,$32,$D4,$5, $C9 20 POKE $71,$ED,$55 30 INIT "CRT:M1" 40 PRINT "NEPTUNES PRODUCTIONS" 50 PRINT CHR$(11)"NEPTUNES PRODUCTIONS" 60 PRINT CHR$(11)
We can come up with lots of these programs to put in this part of chapter 3, but that is not what we had in mind. This part of chapter 3 is just for programs that can not be categorized in other chapters.
Programs that alter BASIC drastically will not be present in this chapter either. This is to make sure BASIC does not crash. If you alter BASIC too much, you run the chance BASIC crashes. This can for example be caused by usage of one memory address for two purposes, for example an extra BASIC-instruction and changing the border while the cursor is flickering. The computer can crash at this stage and BASIC must be reloaded.