[A83] Re: Tilemap


[Prev][Next][Index][Thread]

[A83] Re: Tilemap




> I know how to read the code, I should have just said: There are a few
lines
> where I don't know how or why something is happening.

Good.  You are learning to ask specific questions, which are much easier to
answer than general questions.  Specific questions shows you are thinking on
your own.

> this comes from the 8*8 tilemap routine
> hl->tilemap
> de->tiles
> bc,8*256+12 ;it does this telling where to place the first tile
> push bc  ;puts bc on the stack (tile coords)
> but...
> ld b,c what does this do(I know it loads the contents of c into b, but
what
> is in c?
> ld de,-(8*12)+1  also what does -(8*12)+, is it just saying - 8*12 then
add
> 1
> and putting it in de

What a mess.  How about capitalizing some things and spacing it out so I can
actually read it?  :)  Yes, this is me complaining, but you are much more
likely to get people to help you when you make it easier on them.

BC is a 16 bit register.  The high byte is B, and the low byte is C.  Thus
taking the value of (or the value being loaded into) BC and dividing by 256
(truncating the remainder) will give you B, and taking the modulus of 256
(the remainder after dividing) will give you C.

Therefore, 8 is being loaded into B, and 12 is being loaded into C.  I might
have written it as follows:

 ld bc,(8*256)+12

Or, another way it could be written is using the shift operator.  In this
case, 5 will be going into B, to make it clear what is what:

 ld bc,(5<<8)+12

The shift operator means to shift the binary value that many times.  Each
byte has 8 bits.  256 is 2 to the 8th power.  Each shift is the same as
multiplying by 2.  This concept is very important to understanding assembly
language.

In TASM, there is no order of operations (except for parenthesis).
Everything is evaluated left to right.  This is a stupid and confusing thing
to do, but it was likely done this way because writing a parser is easier
when you don't have to worry about order of operation.  Though if you use a
lex and yacc for your scanner and parser, then it's much easier.

My 8th grade math teacher taught me a very important concept.  There is no
such thing as subtraction.  The first thing to do when evaluating anything
is to replace subtraction with addition.  The negative sign is really
subtraction, so put a zero on the left side.  Then rewrite it as addition.
Then evaluate it left to right, and you will have your answer.

Of course, if you had bothered to read the manual to TASM or the Expressions
section in the Assembly Studio 8x help file, then you probably would have
known this.  Get Assembly Studio 8x and read the help file.  It is
incredibly useful.





References: