Sharp logo

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


In this chapter we will show you how to use machine language on the SHARP with some small machine language examples. Not only shall we show pure machine language programs, but also hybrid BASIC-programs.

Some programs will be explained in more detail later on in this book. If you want to know what all the DATA instructions represent, in other words, what the assembler instruction is, you can find them in APPENDIX A, all hexadecimal codes are there with their translated assembly instructions.


3.1 Useful and funny machine language (sub)routines

First of all the pure machine language will be discussed. Let us start by showing you how to make such a program.

  • Turn on your computer.
  • Press M ( Monitor ).
  • Enter M2000 if your listing starts at address 2000, M1200 if the listing starts at address 1200.
  • If it says 1200 0D on paper, you only have to enter 0D ( followed by a <cr> of course ), because, if all is well, the 1200 will already be present on the screen. After you have typed <cr> 1201 will appear on the screen and this way you can enter the entire program until you are finished.
  • When you are finished, press SHIFT / BREAK.
  • You can now SAVE your program to tape or QD.
  • Enter S for the tape.
  • Enter QS for QD.
  • Now the words Filename, Top adrs, End adrs and Exc adrs will appear in this order, all followed by a ? The data you must enter will be mentioned with each program.
  • You can now start the program by typing Gxxxx. We will also mention which string to type instead of xxxx with each program.
  • The program will either stop by itself, or has to be stopped with the reset button or another button, this will also be mentioned.
  • You can load a machine language program by simply turning on the computer and by pressing C.
  • How you can load a machine language program from QD has already been discussed in chapter 1.

Unfortunately not all programs are accompanied by their assembly listing. The listing of some programs can be found later on in this book. A reasonable explanation of the programs can be found there as well. It will not be so extensive that a rookie will be able to learn assembly language completely from scratch, but someone who is in the beginning stages, will be able to advance and people who are moderate assembly programmers might get some new ideas.

For those who would like to learn machine language; in 1990 a book will probably come out on this subject from SCCE or us.

Scroll the screen to the left.

1200 21 1205 D0 120A 06 120F 13 1214 23 1219 0E 121E 20
1201 00 1206 0E 120B 27 1210 10 1215 13 121A 20 121F FB
1202 D0 1207 19 120C 1A 1211 FA 1216 0D 121B 10 1220 C3
1203 11 1208 7E 120D 77 1212 08 1217 20 121C FE 1221 00
1204 01 1209 D8 120E 23 1213 77 1218 EF 121D 0D 1222 12

Filename? SCROLL-LEFT
Top adrs? 1200
End adrs? 1222
Exc adrs? 1200
Start this program with G1200.
This program can only be stopped by pressing the reset button.

The program will shift the entire screen to the left. What falls of the screen on the left is inserted on the right.

Scroll the screen to the right.

1200 21 1205 D3 120A 06 120F 1B 1214 2B 1219 0E 121E 20
1201 E7 1206 0E 120B 27 1210 10 1215 1B 121A 20 121F FB
1202 D3 1207 19 120C 1A 1211 FA 1216 0D 121B 10 1220 C3
1203 11 1208 7E 120D 77 1212 08 1217 20 121C FE 1221 00
1204 E6 1209 08 120E 2B 1213 77 1218 EF 121D 0D 1222 12

Filename? SCROLL-RIGHT
Top adrs? 1200
End adrs? 1222
Exc adrs? 1200
Start this program with G1200.
This program can only be stopped by pressing the reset button.

The program will shift the entire screen to the right. What falls of the screen on the right is inserted on the left.

Scroll the screen up.

1200 21 1207 1A 120E 10 1215 CF 121C 77 1223 10 122A 00
1201 D8 1208 06 120F FA 1216 21 121D 23 1224 FE 122B C0
1202 CF 1209 27 1210 0D 1217 C0 121E 13 1225 0D 122C C3
1203 11 120A 1A 1211 20 1218 D3 121F 10 1226 20 122D 00
1204 00 120B 77 1212 F5 1219 06 1220 FA 1227 FB 122E 12
1205 D0 120C 23 1213 11 121A 28 1221 0E 1228 CD
1206 0E 120D 13 1214 D8 121B 1A 1222 20 1229 1B

Filename? SCROLL-UP
Top adrs? 1200
End adrs? 122E
Exc adrs? 1200
Start this program with G1200.
This program can be stopped by pressing the reset button or any other button.

Scroll the screen down.

1200 21 1207 1A 120E 10 1215 D3 121C 77 1223 10 122A 00
1201 0F 1208 06 120F FA 1216 21 121D 23 1224 FE 122B C0
1202 D4 1209 27 1210 0D 1217 00 121E 13 1225 0D 122C C3
1203 11 120A 1A 1211 20 1218 D0 121F 10 1226 20 122D 00
1204 E7 120B 77 1212 F5 1219 06 1220 FA 1227 FB 122E 12
1205 D3 120C 2B 1213 11 121A 28 1221 0E 1228 CD
1206 0E 120D 1B 1214 E8 121B 1A 1222 20 1229 1B

Filename? SCROLL-DOWN
Top adrs? 1200
End adrs? 122E
Exc adrs? 1200
Start this program with G1200.
This program can be stopped by pressing the reset button or any other button.

The previous program scrolled the screen up and inserted all that fell off at the bottom. This program does the inverse.

Show 2 character sets.

1200 3E 1206 00 120C FF 1212 52 1218 D1 121E F0 1224 C9
1201 C6 1207 08 120D 70 1213 23 1219 06 121F ED
1202 CD 1208 21 120E 19 1214 10 121A FF 1220 52
1203 DC 1209 00 120F 36 1215 F7 121B 70 1221 23
1204 0D 120A D0 1210 70 1216 21 121C 19 1222 10
1205 11 120B 06 1211 ED 1217 18 121D 36 1223 F7

Filename? 2 CHARACTERSETS
Top adrs? 1200
End adrs? 1224
Exc adrs? 1200
Start this program with G1200.
This program stops by itself.

This program shows the two character sets present in the SHARP. Totally there are 512 characters at your disposal and those characters may be redefined to any other character, but that will be shown at the hand of another program in this chapter.

Change the border colour with the joystick.

2000 3E 2008 32 2010 FD 2018 CC 2020 FE 2028 0C 2030 0C
2001 5F 2009 01 2011 25 2019 27 2021 EF 2029 20 2031 20
2002 01 200A 20 2012 20 201A 20 2022 C8 202A 2D 2032 2C
2003 CF 200B 21 2013 FA 201B FE 2023 00 202B 22 2033 C3
2004 06 200C 20 2014 DB 201C FD 2024 C3 202C 0C 2034 2B
2005 ED 200D 03 2015 F0 201D CC 2025 00 202D 20 2035 20
2006 79 200E 2D 2016 FE 201E 2F 2026 20 202E C9
2007 3D 200F 20 2017 FE 201F 20 2027 2A 202F 2A

Filename? BORDER-JOY
Top adrs? 2000
End adrs? 2035
Exc adrs? 2000
Start this program with G2000.
This program can be stopped by pressing the reset button or the fire button on joystick 1.

With the joystick ( in port 1 ) you can change the speed with which the border colour changes. When the program starts, you will see a couple of colours moving up very slowly.

Normally you can only set the border to 1 colour and yet you see more of them. That is because the human eye is only capable of recording 21 frames a second and the border colour is updated at a far higher speed. This also explains why you will see the border flickering.

We will not explain exactly how this is all possible, because there is physics and a little biology involved.

Put something randomly on the screen.

1200 21 1208 16 1210 12 1218 23 1220 23 1228 0E 1230 00
1201 BF 1209 09 1211 3D 1219 0D 1221 36 1229 20 1231 12
1202 D3 120A 06 1212 10 121A 20 1222 6B 122A 10 1232 4F
1203 3A 120B 26 1213 F8 121B FC 1223 3E 122B FE 1233 C3
1204 05 120C FE 1214 15 121C 36 1224 C0 122C 0D 1234 0A
1205 E0 120D 00 1215 C2 121D 6B 1225 CD 122D 20 1235 12
1206 07 120E CA 1216 32 121E 23 1226 DC 122E FB
1207 3F 120F 18 1217 12 121F 23 1227 0D 122F C3

Filename? RANDOM
Top adrs? 1200
End adrs? 1235
Exc adrs? 1200
Start this program with G1200.
This program can only be stopped by pressing the reset button.

This program puts two stars on a ’random’ spot at the bottom of the screen and moves them up. This cycle repeats itself. Why is random between quotes?

A computer is only capable of logical processing. Choosing a random number is illogical, that it why it is very difficult. In this particular case the number is extracted from the clock, which runs very accurate even though this is a very special clock. It is very hard to get a good random number.

Change fore- and background colours.

2000 21 2006 28 200C 20 2012 20 2018 00
2001 00 2007 73 200D F7 2013 FD 2019 C0
2002 D8 2008 23 200E 1D 2014 10 201A C3
2003 0E 2009 10 200F 06 2015 FB 201B 00
2004 19 200A FC 2010 50 2016 CD 201C 20
2005 06 200B 0D 2011 0D 2017 1B

Filename? COLOURS
Top adrs? 2000
End adrs? 201C
Exc adrs? 2000
Start this program with G2000.
This program can be stopped by pressing the reset button or any other button.

This program will change the fore- and background colours. Once in a while you will also see the character set change. So you can use a different character set by choosing a different colour. This has also been demonstrated by another program in this chapter. If the code for the colour is smaller than 80H, the first character set will be shown.

SCORE routine.

2000 3E 200C 23 2018 D1 2024 36 2030 20 203C 20 2048 C3
2001 C6 200D 10 2019 7E 2025 20 2031 36 203D 20 2049 20
2002 CD 200E FB 201A 3C 2026 2B 2032 20 203E 36 204A 20
2003 DC 200F 06 201B FE 2027 7E 2033 2B 203F 20 204B 36
2004 0D 2010 01 201C 2A 2028 3C 2034 7E 2040 2B 204C 20
2005 21 2011 0D 201D CA 2029 FE 2035 3C 2041 7E 204D 2B
2006 F2 2012 20 201E 24 202A 2A 2036 FE 2042 3C 204E 36
2007 D1 2013 FD 201F 20 202B CA 2037 2A 2043 FE 204F 21
2008 06 2014 10 2020 77 202C 31 2038 CA 2044 2A 2050 C9
2009 04 2015 FB 2021 C3 202D 20 2039 3E 2045 CA
200A 36 2016 21 2022 0F 202E C3 203A 20 2046 4B
200B 20 2017 F5 2023 20 202F 20 203B C3 2047 20

Filename? SCORE-ROUTINE
Top adrs? 2000
End adrs? 2050
Exc adrs? 2000
Start this program with G2000.
This program stops by itself.

In the middle of the screen the score will appear, counting from 0 to 10000. This has a small delay built-in, otherwise the score will be at 10000 before you even notice it. Of course you can also use this program for something completely different.

Change character.

A000 D3 A00A 11 A014 36 A01E FF A028 23 A032 01 A03C C9
A001 E4 A00B 00 A015 FF A01F 23 A029 36 A033 00
A002 dB A00C A8 A016 23 A020 36 A02A 00 A034 10
A003 E0 A00D ED A017 36 A021 FF A02B D3 A035 11
A004 21 A00E B0 A018 FF A022 23 A02C E4 A036 00
A005 00 A00F dB A019 23 A023 36 A02D dB A037 C0
A006 C0 A010 E1 A01A 36 A024 FF A02E E0 A038 ED
A007 01 A011 21 A01B FF A025 23 A02F 21 A039 B0
A008 00 A012 00 A01C 23 A026 36 A030 00 A03A dB
A009 10 A013 A8 A01D 36 A027 FF A031 AB A03B E1

Filename? CHAR-CHANGE
Top adrs? A000
End adrs? A050
Exc adrs? A000
Start this program with GA000.
This program stops by itself.

A nice result, but what has happened? The space sign has changed into a square and all occurrences of the space sign have been replaced with those squares. This way you can redefine all 256 signs in the first character set and all 256 signs in the second character set.

Let us look into this:
The data of all characters is stored in shadow memory. Bankswitching makes you able to access this data and move all data to the normal memory. In this case all data from A800 will be moved to memory. Each character has its own code, space has code 00. Because the data is stored by code in ascending order, the space will come first.

Each character consists of 8 bytes. The data for the space is therefore stored from A000 to A007. When this data is altered and if the data is written back to the shadow memory afterwards, the space sign will be changed and you have just seen the result.

So if you want to change a certain character, you have to look up the code, multiply it by 8 and add it to A000. ( These codes are not present in the manual, you will have to look them up yourself ). From this address up to 7 bytes after this address the data of the character is stored. The rest of this program is explained further on.

High-resolution scroll.

6000 dB 600C D3 6018 78 6024 F0 6030 dB 603C 0B 6048 06
6001 E0 600D CC 6019 B1 6025 21 6031 7F 603D 78 6049 28
6002 3E 600E 21 601A C2 6026 F0 6032 11 603E B1 604A 1A
6003 00 600F 00 601B 14 6027 8F 6033 00 603F C2 604B 77
6004 D3 6010 80 601C 60 6028 06 6034 80 6040 38 604C 23
6005 CE 6011 01 601D 3E 6029 28 6035 01 6041 60 604D 13
6006 3E 6012 00 601E 32 602A 36 6036 40 6042 21 604E 10
6007 00 6013 20 601F D3 602B FF 6037 1F 6043 18 604F FA
6008 D3 6014 AF 6020 F0 602C 23 6038 1A 6044 9F 6050 C3
6009 F0 6015 77 6021 3E 602D 10 6039 77 6045 11 6051 F2
600A 3E 6016 23 6022 C3 602E FB 603A 23 6046 D8 6052 60
600B 03 2017 0B 6023 D3 602F 21 603B 13 6047 7F

Filename? HR-SCROLL
Top adrs? 6000
End adrs? 6052
Exc adrs? 6000
Start this program with G6000.
This program can only be stopped by pressing the reset button.

This program will scroll a red line upward slowly. When the line disappears at the top of the screen, it will reappear at the bottom. The difference with the previously shown scrolling program is that this goes smoothly. This has to do with the fact that this program uses the Video-RAM, which is only present in the MZ-800, while the other scrolling programs will also run on the MZ-700.

How programming in the Video-RAM works will be discussed in another chapter in more detail, which is all about Video-RAM. From BASIC you can do more with the Video-RAM and it is easier, so that is why we will discuss it later on.

Border scroll.

A000 BF A018 00 A030 23 A048 D0 A060 11 A078 07 A090 4E
A001 A1 A019 A8 A031 A0 A049 11 A061 00 A079 77 A091 11
A002 AD A01A ED A032 21 A04A 27 A062 C6 A07A 23 A092 EE
A003 A5 A01B B0 A033 00 A04B 00 A063 ED A07B 10 A093 AE
A004 A5 A01C dB A034 D0 A04C 06 A064 B0 A07C FA A094 06
A005 BD A01D E1 A035 06 A04D 17 A065 dB A07D 21 A095 07
A006 81 A01E 21 A036 28 A04E 36 A066 E1 A07E E0 A096 1A
A007 FF A01F E0 A037 36 A04F DD A067 21 A07F AE A097 77
A008 3E A020 AE A038 DF A050 19 A068 F8 A080 11 A098 2B
A009 C6 A021 0E A039 23 A051 36 A069 AE A081 E1 A099 1B
A00A CD A022 04 A03A 10 A052 DC A06A 06 A082 AE A09A 10
A00B DC A023 11 A03B FB A053 23 A06B 08 A083 4E A09B FA
A00C 0D A024 00 A03C 21 A054 10 A06C 7E A084 06 A09C 71
A00D D3 A025 A0 A03D C0 A055 F8 A06D 0F A085 07 A09D 0E
A00E E4 A026 06 A03E D3 A056 D3 A06E 77 A086 1A A09E 10
A00F dB A027 08 A03F 06 A057 E4 A06F 23 A087 77 A09F 06
A010 E0 A028 1A A040 28 A058 dB A070 10 A088 13 A0A0 FF
A011 21 A029 77 A041 36 A059 E0 A071 FA A089 23 A0A1 10
A012 00 A02A 23 A042 DE A05A 21 A072 21 A08A 10 A0A2 FE
A013 C0 A02B 13 A043 23 A05B 00 A073 F0 A08B FA A0A3 0D
A014 01 A02C 10 A044 10 A05C AE A074 AE A08C 71 A0A4 20
A015 00 A02D FA A045 FB A05D 01 A075 06 A08D 21 A0A5 F9
A016 10 A02E 0D A046 21 A05E 00 A076 08 A08E EF A0A6 C3
A017 11 A02F C2 A047 28 A05F 01 A077 7E A08F AE A0A7 56
A0A8 A0

Filename? BORDER-SCROLL
Top adrs? A000
End adrs? A0A8
Exc adrs? A008
Start this program with GA008.
This program can only be stopped by pressing the reset button.

A nice effect. You can use it as an introduction screen, for example. In the middle you could put a copyright message and the name of the author of the program.

Here the characters in the character set are also changed. By putting these characters on the screen, you will see the special figures.

It seems that everything moves left, right, up or down, but this is not the case. The character is just rotated and that causes the effect.

Border text.

This program consists of two parts. The first part is the main program and the second part is the data. You can use this program as the introduction screen of your own machine language program. In the middle you could put the name of your program. People who know the game BREAK-OUT from SFF-SOFT ( club tape three of SCCE ) probably know what we are talking about, because this is also used in that game.

Part 1.

2000 CD 2015 11 202A 21 203F 00 2054 00 2069 7E 207E C9
2001 87 2016 59 202B 01 2040 21 2055 ED 206A FE 207F AF
2002 20 2017 FD 202C 28 2041 21 2056 B0 206B 7F 2080 32
2003 0E 2018 19 202D 00 2042 00 2057 CD 206C CC 2081 29
2004 08 2019 10 202E ED 2043 D0 2058 1B 206D 7F 2082 20
2005 06 201A EC 202F B0 2044 06 2059 00 206E 20 2083 32
2006 28 201B 0D 2030 1B 2045 18 205A FE 206F 0E 2084 3F
2007 36 201C 20 2031 06 2046 1A 205B 00 2070 A0 2085 20
2008 02 201D E7 2032 18 2047 77 205C C2 2071 10 2086 C9
2009 11 201E 06 2033 0E 2048 13 205D 79 2072 FE 2087 CD
200A 68 201F 28 2034 28 2049 C5 205E 20 2073 0D 2088 79
200B 01 2020 36 2035 13 204A 01 205F 3A 2074 20 2089 20
200C 19 2021 07 2036 0D 204B 28 2060 29 2075 FB 208A CD
200D 36 2022 23 2037 20 204C 00 2061 20 2076 C3 208B 7F
200E 07 2023 10 2038 FC 204D 09 2062 3C 2077 25 208C 20
200F 11 2024 FB 2039 7E 204E C1 2063 32 2078 20 208D 21
2010 40 2025 11 203A 12 204F 10 2064 29 2079 3E 208E 00
2011 01 2026 00 203B 23 2050 F5 2065 20 207A C6 208F D8
2012 19 2027 D0 203C 10 2051 EB 2066 32 207B CD 2090 C9
2013 36 2028 21 203D F5 2052 01 2067 3F 207C DC
2014 09 2029 00 203E 11 2053 28 2068 20 207D 0D

Part 2.

2100 6B 2128 6B 2150 0B 2178 17 21A0 05 21C8 6B 21F0 6B
2101 6B 2129 6B 2151 00 2179 00 21A1 00 21C9 6B 21F1 6B
2102 6B 212A 6B 2152 16 217A 05 21A2 04 21CA 6B 21F2 6B
2103 6B 212B 6B 2153 0F 217B 09 21A3 12 21CB 6B 21F3 6B
2104 6B 212C 6B 2154 0F 217C 07 21A4 15 21CC 6B 21F4 6B
2105 6B 212D 6B 2155 12 217D 05 21A5 0B 21CD 6B 21F5 6B
2106 6B 212E 6B 2156 02 217E 0E 21A6 0B 21CE 6B 21F6 6B
2107 6B 212F 6B 2157 05 217F 00 21A7 05 21CF 6B 21F7 6B
2108 6B 2130 6B 2158 05 2180 10 21A8 0E 21D0 6B 21F8 6B
2109 6B 2131 6B 2159 0C 2181 12 21A9 00 21D1 6B 21F9 6B
210A 6B 2132 6B 215A 04 2182 0F 21AA 13 21D2 6B 21FA 6B
210B 6B 2133 6B 215B 00 2183 07 21AB 14 21D3 6B 21FB 6B
210C 6B 2134 6B 215C 0F 2184 12 21AC 0F 21D4 6B 21FC 6B
210D 6B 2135 6B 215D 0D 2185 01 21AD 10 21D5 6B 21FD 6B
210E 6B 2136 6B 215E 00 2186 0D 21AE 14 21D6 6B 21FE 6B
210F 6B 2137 6B 215F 14 2187 0D 21AF 00 21D7 6B 21FF 7F
2110 6B 2138 6B 2160 0F 2188 01 21B0 04 21D8 6B
2111 6B 2139 6B 2161 05 2189 69 21B1 09 21D9 6B
2112 6B 213A 6B 2162 00 218A 13 21B2 14 21DA 6B
2113 6B 213B 6B 2163 14 218B 2E 21B3 00 21DB 6B
2114 6B 213C 6B 2164 05 218C 00 21B4 10 21DC 6B
2115 6B 213D 6B 2165 00 218D 04 21B5 12 21DD 6B
2116 6B 213E 6B 2166 0B 218E 0F 21B6 0F 21DE 6B
2117 6B 213F 6B 2167 15 218F 0F 21B7 07 21DF 6B
2118 6B 2140 00 2168 0E 2190 12 21B8 12 21E0 6B
2119 6B 2141 00 2169 0E 2191 00 21B9 01 21E1 6B
211A 6B 2142 04 216A 05 2192 0F 21BA 0D 21E2 6B
211B 6B 2143 09 216B 0E 2193 10 21BB 0D 21E3 6B
211C 6B 2144 14 216C 00 2194 00 21BC 01 21E4 6B
211D 6B 2145 00 216D 10 2195 05 21BD 2E 21E5 6B
211E 6B 2146 09 216E 01 2196 05 21BE 00 21E6 6B
211F 6B 2147 13 216F 13 2197 0E 21BF 00 21E7 6B
2120 6B 2148 00 2170 13 2198 00 21C0 6B 21E8 6B
2121 6B 2149 05 2171 05 2199 14 21C1 6B 21E9 6B
2122 6B 214A 05 2172 0E 219A 0F 21C2 6B 21EA 6B
2123 6B 214B 0E 2173 00 219B 05 21C3 6B 21EB 6B
2124 6B 214C 00 2174 09 219C 14 21C4 6B 21EC 6B
2125 6B 214D 0C 2175 0E 219D 13 21C5 6B 21ED 6B
2126 6B 214E 05 2176 00 219E 00 21C6 6B 21EE 6B
2127 6B 214F 15 2177 15 219F 14 21C7 6B 21EF 6B

Filename? BORDERTEXT
Top adrs? 2000
End adrs? 2200
Exc adrs? 2000
Start this program with G2000.
This program stops when you press any key.

Random colours.

As mentioned before, the word random is not quite correct. On this computer it is impossible to choose a random number because a computer is a logical device and choosing a random number is illogical.

In this program the A-register is rotated and a short delay is built-in to get a better random approximation.

The ( random ) number is extracted from the clock. This is not a normal clock, but a clock that keeps track of how many clock-cycles certain instructions use.

2000 3E 2005 21 200A 06 200F 77 2014 15 2019 F8 201E EB
2001 C6 2006 00 200B 28 2010 23 2015 20 201A 10 201F C9
2002 CD 2007 D8 200C 3A 2011 0F 2016 FD 201B F0
2003 DC 2008 0E 200D 05 2012 16 2017 3D 201C 0D
2004 0D 2009 19 200E E0 2013 20 2018 20 201D 20

Filename? RAND. COLOURS
Top adrs? 2000
End adrs? 201F
Exc adrs? 2000
Start this program with G1200.
This program stops by itself.

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