A83: Re: A Few ASM Questions to all the Gurus out there


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

A83: Re: A Few ASM Questions to all the Gurus out there



> 1st Question:
>  How do I go about acknowledging 2 key presses at once like up-right or
> down-left...
> I think Bill Nagel did this is penguins... but there is no code..

Sorry, no idea.  Perhaps checking for one, then another using direct input?

> 3rd Question:
> Could someone explain to me the differences between the commands: call, jr
> and jp

Here's the "Key Input and Conditionals Tutorial..." I'd advise getting my tutorials :)
------------------------------------------------------------------------------------
Introduction.
If you want to do any real program, at one stage or another, you are going to want to get input from the user.  This is where the key input comes in.  Now, you will want to do something with that keycode, that is where conditionals come in.

New Commands.

_getkey - Gets a key, and puts it in the accumulator.
cp - Compares with accumulator.
jr - The ASM equivalent to If xx then jump to xxxxxx
jp - Same as above, except very different…
_ipoint - Turns a point on/off/switch or tests.
_runIndicOff - Simply turns off run indicator.

_ipoint uses the b and c registers to store the coordinates (in pixels) of the point in question, and d is set to either 0, 1, 2, 3, or 4.  0 turns the pixel off, 1 turns the pixel on, 2 switches the pixel (If on, off.  If off, on), 3 tests whether the pixel is on or off (returns value to z), finally 4 copies from PLOTSSCREEN to the screen.

Note:  Most subsequent programs are written by me, and me alone.  Why do I say this?  Well, you should feel like you could have written them by the end of the tutorials...

The Code.

Ok, here we go!  Try to follow along...

...the standard start...

; Defines are merely for demonstration.

#DEFINE kLeft       02h

#DEFINE kRight      01h

#DEFINE kUp         03h

#DEFINE kDown       04h     ;All these guys are hex code

#DEFINE kEnter      05h     ;for keys on the Ti-keyboard.

#DEFINE kClear      09h

.org 9327h
call _clrLCDFull ;Clear the screen.
ld b,47
ld c,47
ld d,1 ;Set D to 1.
call _IPoint
call _runIndicOff ;Turn off run indicator.
GetKey:
call _getKey ;Asked for a key.
cp kLeft ;Compare key with code for left.
jp z,Left ;If equals 0, go to left.
cp kRight
jp z,Right
cp kUp
jp z,Up
cp kDown
jp z,Down
cp kClear
jp z,Quit
jp GetKey
Left:
ld d,0 ;Set D to 0.
call _IPoint

dec b ;Decrement B
jp Draw
Right:
ld d,0
call _IPoint
inc b
jp Draw
Up:
ld d,0
call _IPoint
inc c
jp Draw
Down:
ld d,0
call _IPoint
dec c8
jp Draw
Draw:
ld d,1
call _IPoint
jp GetKey ;Repeat
Quit:
ret ;Return to OS.
.end
END

CP, JP, JR.

OK, chances are that you didn't fully understand the code.  To fully understand it, you have to see how the commands work.  JP can only work with the following conditions:
• C     (Carry)
• NC   (No Carry)
• Z      (Zero)
• NZ   (Not Zero)
• M     (Minus)
• P      (Positive)
• PE    (Parity Even)
• PO    (Parity Odd)
Addition:  I think I can explain each conditional now.  Carry is whether the calculator had to carry a figure in addition, this returns 1 is it does, 0 if not.  No Carry, I assume, is the opposite.  Zero and Non-zero are obvious…is the result zero, or not.  Minus and positive are self-explanatory.  The parities are whether the number is even or odd.  Simple really.  If I have any of this wrong, please contact me.

Since jp can only think in terms of zeros, or non-zeros we have to do something with our keycode to help jp.  This is what cp does.  cp stands for compare.  It takes the value that it has after it and subtracts it from the accumulator.  Thus, if the accumulator equals 05h due to the _Getkey return, and we use cp kEnter, the value returned will be zero.  This is then what JP uses.

What is the difference between jr and jp? There is one massive difference.  JR is a relative jump — meaning, when TASM compiles it, the instruction for the Z80 simply tells it how many bytes forward or backward to jump.  Thus, jr has a limited range.  jp on the other hand is an absolute jump — tells the Z80 the address to jump to.  The advantage of JR over JP is the file size is smaller and faster once compiled.  (Thank you to Mindless Productions for this information.)  Harper told me that jr is a small jump (up to 128 bytes), and jp is a large jump (up to 32K…the whole RAM, basically!).

Conclusion.

Now, that lesson really covered a lot.  If you understood it first time, great!  But I would advise you read over the section again, and make sure you understand the program perfectly.
I now have a confession to make...I haven't had a monitor for over 3-4 weeks, so I couldn't type up any tutorials, but I managed to get TASM/Winlink etc., on to my mum's laptop.  So, I've stormed ahead!  Well, that's a little exaggeration, but I now know about the stack, how to set modes on the Ti, how to detect modes on the Ti, and a few more things.  So I am a little ahead.  So apologizes now if I say anything you don't understand...:).

A Look Ahead...

Next lesson, I will talk about how to set/reset/detect traits or modes of the Ti.  I made a program that will output what graphing mode you are in.  I will share the code with you all!  The lesson after that will talk about the stack, a very important 'structure' that holds numbers for you.  The next lesson or two will be some more fun stuff — how to turn the calculator off, and how to change the contrast!

Related Topics.

All tutorials Copyright (c) James Matthews 1998, unless specified.
------------------------------------------------------------------------------------


Follow-Ups: