Re: A86: (sqrt) KEY questions


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

Re: A86: (sqrt) KEY questions




Matt2000 wrote:
> 
> I am trying to understand the (sqrt) KEY program line by line.. I am
> referring to the
> KeyTemp template file on Dux Gregis's site.

There was an error in how I used .org, but I just fixed it, so take
another look.

> 
>  I am having difficulty
> understanding it after the call _CREATEPROG. So I understand about a 1/3 of
> it so far..
> :(
> 
> What does $4C3F do? After the call _CREATEPROG, what roles to a and b
> registers play in this program. Why do you xor a? twice?

_CREATEPROG outputs the abs address of the new program in bde.  Each of
the abs set addr calls input ahl.  The abs source is on page 0 (doesn't
need an abs addr), so we just put 0 into a.  Also, the number of bytes
(prog length) is less than 64K (you've got problems if it's not ... and
not just on your calc!  :-), so we can xor a there, too.
$4c3f increments ahl twice.  We need to do this because when we get bde
and switch it to ahl, we are pointing to the token ($8e28) and we want
to point instead to the start of the code.  It beats me why we have to
define the token at the beginning of our code and also skip over it (it
seems like you would have the token twice), but it crashes if you don't.

> 
> It appears that you are copying the source code of code: into the program
> using absolute addresses. Does that explain what the .db $8e, $28 is for
> before the .org _asm_exec_ram is that part of the file format? What exactly
> is  the PROGRAM format when creating a program.

.org _asm_exec_ram organizes our labels relative to $d748.  If this is
put at the start of the code, then the labels will point to the right
place when the code is copied to $d748.  Remember, [sqrt]KEY is just an
asm program, so we want it to run from _asm_exec_ram.  I had to fix
this; see if you can figure out why it had to be changed  :-)

> 
> Now when you in the code: itself, why do you pop OP1 and is that all that
> $479f does?

Yeah, when [sqrt]KEY is called from page $0d with _exec_assembly.  It
pushes op1 and never pops it again.  So, if we don't pop it, the prog
will crash.

> Plus, what was it that put the a in $d625 which you seem to get the keypress
> from.

_exec_assembly.  It saves the registers in RAM around there so that they
can be read from the module (see Ram86.inc).  We can just return the key
press in a though, without having to put it back: the calling routine
will automaticly inherit our registers/flags.

> Weirdness

You should see where it's called from.  It looks like TI used that pop
hl idea and put three pop hl instructions in a row ... it's impossible
for me to trace the program counter like that.   Zut.

> 
> Cool program it seems though, once I understand this I think I will
> understand a lot more
> about how variables, absolute addresses, the VAT, etc which will be great
> for the hangman game I am working on. You will hear more about this game on
> my site which I am working very very hard on (4+ hours a day for the past
> few days).. and my site should be updated fairly soon.

Coolness.  Alot of your z80 links don't work :-)


Follow-Ups: References: