David Scheltema's

Asm z80 Made Simple v0.1

(first release)


email: scheltem@aaps.k12.mi.us

ICQ#: 168175900



... Notes on How to Use This Document

Part I

Ia ... Definitions of Basic Commands

Ib ... Information on Sprites

Ic ... Making a background image

Id ... What are Some Different Routines??

Ie ... Mystery of Hex

If ... KeyLoops

Part II

IIa ... Where to go from here!



Best viewed by edit pad! The point of this is to break down simple commands that can be used in z80 so that you can quickly understand some of the basics of the language. I try to stay away from using technical detail in this document because I want you to get it without re-reading. Really if you break asm down into pieces it should not be that hard to understand. What this document is not: your key to knowing all about asm, yeah right it took me a while to just make this and it is just a piece of what you need to know. There is not a real order in this only what came into my head so you have to hunt for stuff until I make it organized. Sorry for that aspect of it, o yeah I all of the information I have interpreted through my own eyes if you know asm and an incorrect statement is in here Please let me know. Good Luck with what ever you hope to get from this!


Section Ia ... Definitions of Basic Commands

ld a,1

This stores 1 into a so if you want a to = 4


This calls a ROM functions, label, or string


call _clrLCD clears the screen (ROM)

call Loop calls a label

call String calls a string


This can be the name of a label


lbl Loop would be in basic


.db "String example",0

This is what it says a string example

It is just like a label but .db "",0 is after it

Define Bytes

i.e.. right now you can make strings but .db is used for sprites and just defining bytes too


Ends String

i.e.. This tell the compiler that it is the end of the string.

include "filename"

Includes command file

i.e.. It is like any other programming language that has include files.

.org _asm_exec_ram


i.e.. This is the start of all asm codes never forget it!


Returns to a portion of code or exits program

ie1. There are two ways this can be used if it is in a loop that has been called it will return to the statement after the call



call Loop2





What would happen here is that code1 would happen then jump to Loop2 after code2 was done it would return to the next code line after the call or code3

ie2. Return that exits the program and quits to the TI OS




This is where a nice programmer can put comments in his/her code.


i.e.. This ends the sprite


.db %01110000

.db %01110000

.db %00100000

.db %00110000

.db %00110000

.db %01110000

.db %00101000

.db %01101100



i.e.. (note no .) This ends the program

push & pop

i.e.. push bc & pop bc What is this you ask well lets say that you have a number stored in b... Wate we know how to show this in asm no more lead you by the hand on this one here is the code:


ld b,2 ;look at ld command if you don't know what this does

push bc ;push saves b until you pop it

ld b,1

pop b


Code Breakdown:

;okay at this point in the code what does b=... well if push saves b and ;then pop recalls the previous b then b of course is equal to 2

;don't get it here I will walk you through it.

;if b is stored as 2 and then it is pushed it is saved as the push value b

;the only way you get the push value b back is by performing the pop b

;this is very useful in routines that use registries that you want to use ;but can't because they are saving important numerical values

ROM calls:

These are really cool because it saves you time and does things that would be hard to do with out ROM calls.

i.e.. call _vputs This call is used when you want to display the small font on the 86 (graph screen text)

call _clrLCD ;Clears screen

Do you see a pattern I do call _Command

If ...then...Statements


cp K_Exit

jr z,End ;If exit is true then goto label exit


Section ... Ib Information on Sprites

The basic idea of a sprite is to limit the work that you have to do to display an 8*8 figure sprites can be longer, but they require you to have a different sprite routine. Most sprite routines are good it is just learning how to use them. I suggest getting the sprite routine on my site. This routine is commented on every line not by me, all the stuff you basics you need to learn about sprites are present in that code. It also shows how to display background.


Section ... Ic Making a Background Image

In order to make a really good background image or a title screen you need a basic paint program. I use "Paint" it comes with windows it is all that you will need. Then you can insert it in this code:

... code ...

call _clrLCD ;clears screen

ld hl,Title ;loads title in hl

ld de,$fc00 ;calls video mem

ld bc,1024 ;blocks out 1024 bytes


... code ...

That is all you have to do to make a title screen. Note that if you want to make a program with a sprite that moves on top of the background you have to have a routine that updates the background. This is a more advanced routine so I am leaving it out of the document. Also once you get the hang of this check out the program that David Phillips made that will compress a title screen to save memory (RLE2PIC).


Section ... Id What Routines??

So you have gone through a lot of source and you have found a lot of really cool stuff out, but it is just not clicking because there are these routines that people reefer to like you should know what they are talking about. Well after you read this you should know what they are talking about. Lets look at some of my opponents in learning asm. Most of the trouble that I have or am having with asm is the graphics. It is not just about strings. There are the great 8*8 sprites or 8*16 sprites. You have to love then though they give you the cool looking graphics that asm is known for. Well there is more than just making a cool sprite that goes into displaying a sprite. You need a FindPixel Routine (your favorite word) and a PutSprite Routine. Okay lets start with the PutSprite even though in a way we are working backwards. PutSprite Routines do what they say (all routines do it is just what does what they are saying mean) they put a sprite at a certain x,y cords. This is really useful because you have a great amount of control over the sprite. As I have said before I will not break down any routines for you. Why you ask... simple there are a couple reasons. One is that there are a ton of putsprite routines out there, you find the one that works best for you or try and make your own (this is hard to do). So when you find a putsprite routine you also need to get a findpixel routine. What the find pixel does is mark the pixels that you want to turn on (darken) or turn off (lighten). There is really a whole lot more to this that is out there check it out. After you figure out the findpixel routine (the best way is to see it in action) you know really have a basic understanding of sprites and how to move them around by changing the x and y cords. Later I will talk about moving with key commands!


Section If ... KeyLoops

Okay well I am just going to give a example of a simple key loop so that you can have a reference. This is a simple loop it does not deal with ports or interrupts (they are used in a faster keyroutine). So with out any further delay here it is:



call _getkey ;gets the key pressed

cp K_EXIT ;Is it exit?

jr z,Quit ;If it is then goto Quit

;you will notice that there is a z

;that sets a zero flag don't worry about

;that right now

cp K_F1 ;Is it F1?

jr z,Load

cp K_F2

jr z,New

jr Start ;notice no z if none of the statements are

;true before it then it will go back to



call _clrLCD

ld hl,%0000 ;what is this number? Read what is hex to ;find out.

ld (_curRow),hl

ld hl,end ;loads a string named end

call _puts



call _clrLCD


call _clrLCD


;String Data


.db "Made By:"

.db "David Scheltema",0


Okay that was easy it is as close to basic on the TI as you will come. If you want to use this as a framework go ahead cut out or make new labels and have then do what you want.




Section I.e. ... The Mystery of Hex

The only mystery here is why it seems so hard. I could show you how to do the conversion of hexadecimal to our regular notation, but I would be wasting my time. No, this is not an insult it is the truth lets see what the TI-86 can do other than play games and program them. Type in 45154 and then hit 2nd 1, F3, and finally F3 again. What does it give you? It should be B062h. Okay well leave off the h that just tells you that it is in hexadecimal so the answer is B062. You can also convert back of course, but hey that is something to do some other time not now. In programs source code the hex will be shown with a $ prefix sign so if you were to out the answer into your program it would be done like so: $B062. Just so you do know a little about hex it goes from 1-9 and then A-F so F=15. Now you know could you even think of what it would be like trying to find what 45154 is in hex without your calculator. Let me tell you from personal experience it is not fun at all. Mystery no more!


Section IIa ...Where to go from here!

Now that you have gotten through the basics of asm you can do a few things. First make lots of pointless programs! This is the best thing to do... why? That is simple there is no way with the information that I supplied that you are going to make a game or even a good math program. Start out simple learn about how to make a sprite and move it around with a key loop add background etc. It is not that I want this to be incomplete it is just that I don't want to say everything. It would take to long and of course I don't know all there is to know about asm (to be honest i started about a month or two ago). Also I would check out programs that use routines that you want to learn about such as inverted text. Where can you find out about this? Well that is simple look in a game that has invert text and see how it is done. If this does not work there are plenty of people to ask on the 86asm list or you could just ask me (remember though I have two month under my belt some on the 86 list have two years).