Sharp logo

MZ-800 course Chapter 3 
3. Machine language on the SHARP MZ-800

3.2 Machine language from within BASIC

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,
30 DATA $C5,$F5,$DB,$D5,$01,$CF,$06,$ED,$79,$F1,$C1,$CD,
$BA,$00,$C9 40 FOR A=0 TO 14:READ B:POKE $F020+A,B:NEXT 50 USR($F000)

To stop the flashing, type:

POKE $F025,$0 - flashing off.
POKE $F025,$CF - flashing on.

Program 2: 20 functions keys.

It is possible to use the CTRL-key to define and use 20 function keys.

F1 - F5 = press directly
F5 - F10 = press +SHIFT
F11 - F15 = press +CTRL
F16 - F20 = press +SHIFT+CTRL

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$):
IF CK>255 THEN CK=CK-256 130 GOTO 110 140 KC=VAL("$"+RIGHT$(A$,2)):
IF KC<>CK THEN PRINT "Error in DATA line: ";RG:END 150 RG=RG+1:IF RG<13 THEN 110 200 AD=$55C1:RG=13:CK=0 210 READ A$:IF LEFT$(A$,1)="!" THEN 240 220 POKE AD,VAL("$"+A$):AD=AD+1:CK=CK+VAL("$"+A$):
IF CK>255 THEN CK=CK-256 230 GOTO 210 240 KC=VAL("$"+RIGHT$(A$,2)):
IF KC<>CK THEN PRINT "Error in DATA line: ";RG:END 250 RG=RG+1:IF RG<18 THEN 210 300 AD=$5720:RG=18:CK=0 310 READ A$:IF LEFT$(A$,1)="!" THEN 340 320 POKE AD,VAL("$"+A$):AD=AD+1:CK=CK+VAL("$"+A$):
IF CK>255 THEN CK=CK-256 330 GOTO 319 340 KC=VAL("$"+RIGHT$(A$,2)):
IF KC<>CK THEN PRINT "Error in DATA line: ";RG:END 350 RG=RG+1:IF RG<41 THEN 310 400 POKE $6C56,$9A,$55:POKE $6BB7,$C3,$C1,$55:
POKE $C7B,$C3,$20,$57 410 CLS:KEY LIST

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,
86,182,103,111,95,111,239) 40 B$=CHR$(66,231,255,60,165,165,165,165,165,165,36,255,0,195,255,128,
127,170,148,127,128,255,247,65) 50 C$=CHR$(247,246,250,6,248,30,82,30,250,244,116,228,142,226,242,126,
174,174,102,246,250,254,237) 60 D$=A$+B$+C$ 70 POSITION 0,1:PATTERN [1]-24,D$ 80 LINE [2]0,0,319,0 90 LINE [2]0,199,319,199 100 DATA $3E,$00,$DB,$E0,$3E,$01,$D3,$CD,$D3,$CC,$21,$28,$80,$DB,$F0,
$CC,$AB,$FC,$C3,$04,$FC 110 DATA $3A,$01,$FC,$3C,$FE,$08,$CA,$00,$FD,$32,$01,$FC,$11,$24,$00,
$0D,$20,$F2,$AF,$C9 120 DATA $3A,$01,$FC,$3D,$FE,$FF,$CA,$22,$FD,$32,$01,$FC,$11,$03,$00,
$2B,$10,$FA,$19,$0D,$20,$F2,$AF,$C9 130 DATA $E5,$EB,$D5,$E1,$11,$D8,$FF,$19,$3E,$02,$D3,$CD,$7E,$FE,$00,
$EA,$AF,$C9,$D1,$AF,$C9 140 DATA $11,$9B,$03,$19,$E5,$EB,$E1,$D5,$11,$28,$00,$19,$3E,$02,$D3,
$FC,$E1,$3E,$01,$D3,$CD,$D1,$0E,$19,$06,$04,$1A,$77,$2B,$1B,$10,$FA 150 DATA $13,$13,$13,$13,$D5,$11,$B4,$FF,$19,$D1,$EB,$0D,$20,$EA,$AF,
$C9 160 FOR T=0 TO 235:READ A:POKE $FC00+T,A:NEXT 170 DATA $11,$9C,$03,$19,$3E,$02,$D3,$CD,$7E,$FE,$00,$C2,$49,$FC,$11,
$64,$FC,$19, $CD,$32,$FC,$2A,$0B,$FC,$23,$22,$0B,$FC,$32,$01,$FC,$C3,$49,$FC 180 DATA $2B,$3E,$02,$D3,$CD,$7E,$FE,$00,$C2,$72,$FC,$22,$0B,$FC,$3E, $07,$C3,$54,$FC 190 FOR T=0 TO 52 :READ A :POKE $FD00+T,A:NEXT 200 USR($FC00)

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 [8]0,0,319,0
90 LINE [8]0,199,319,199
95 CIRCLE [2]160,100,50:PAINT [2]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,
40 USR($FC00)
50 POKE $FD00,$29,$CB,$EC,$CB,$F4,$CB,$FC,$C3,$E2,$5
60 POKE $5DF,$C3,$0,$FD

An example:
Let us assume that you want to change the letter ’B’. First you have to find out which ASCII-value this letter has and the value is 02. You multiply this by 8 and this will yield 16. The hexadecimal value of 16 is $10. Add this number to $E000 and we get the address $E010.

For convenience we will change the letter ’B’ to a square. This goes as follows:

POKE $E010,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF

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:

POKE $5DF,$29,$C3,$E4

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,
20 POKE $71,$ED,$55
30 INIT "CRT:M1"
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.

Previous page
Next page

Go to the top of this page Home

last updated July 1, 2004
Arjan Habing, Mark de Rover, Jeroen F. J. Laros,