Re: LZ: Basics
[Prev][Next][Index][Thread]
Re: LZ: Basics
Nathan Adams wrote:
>
> At 12:34 12/21/96 -0400, you wrote:
> >OK, I am kind of new at this programming zshell stuff. I have a basic
> >question. Lets say that I was trying to write a program that would ask
> >the user for two numbers and then it would add them. My question is how
> >do I input the numbers to be added?
> >
> >Thanks,
> >Dennis
> >
> This is the way I would do it:
>
> Loop:
> call GET_KEY ;Key code of last key pressed
> cp $21 ;compare is with keycode of zerokey
> JUMP_Z(ZeroKey) ;jump to ZeroKey if equal
> cp $22
> JUMP_Z(OneKey)
> cp $1A
> JUMP_Z(TwoKey)
> cp $12
> JUMP_Z(ThreeKey)
> cp $23
> JUMP_Z(FourKey)
> cp $1B
> JUMP_Z(FiveKey)
> cp $13
> JUMP_Z(SixKey)
> cp $24
> JUMP_Z(SevenKey)
> cp $1C
> JUMP_Z(EightKey)
> cp $14
> JUMP_Z(NineKey)
> cp $09
> JUMP_Z(Add)
> JUMP_(Loop)
>
> ZeroKey:
> ld a,0 ;load zero into a
> push af ;push a onto stack
> JUMP_(Loop)
> OneKey:
> ld a,1
> push af
> JUMP_(Loop)
> TwoKey:
> ld a,2
> push af
> JUMP_(Loop)
> ThreeKey:
> ld a,3
> push af
> JUMP_(Loop)
> FourKey:
> ld a,4
> push af
> JUMP_(Loop)
> FiveKey:
> ld a,5
> push af
> JUMP_(Loop)
> SixKey:
> ld a,6
> push af
> JUMP_(Loop)
> SevenKey:
> ld a,7
> push af
> JUMP_(Loop)
> EightKey:
> ld a,8
> push af
> JUMP_(Loop)
> NineKey:
> ld a,9
> push af
> JUMP_(Loop)
> Add:
> pop af ;Get first number from stack
> pop bc ;Get second number from stack
> add a,b ;add them
>
> This isn't complete, but I think it shows the basic way to input. I'm not
> sure if this is the best way it can be done, but I hope it helps.
> Nathan Adams
> nathana@goodnet.com
> "It is better to remain silent and be thought a fool,
> than to speak out and remove all doubt."
The easiest way to do a input > number is with a table. Think of it as
old sine tables in math books. You take an angle, look it up in the
table, and it gives you the sine. Here's how you'd do it:
loop:
call GET_KEY
cp 0
jr z,loop
ld hl,(PROGRAM_ADDR)
ld de,table
add hl,de
ld e,a
ld d,0
add hl,de
ld a,(hl)
ROM_CALL(M_CHARPUT)
table:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,3,6,9,0,0,0,0,0,2,5,8,0,0,0
.db 0,0,1,4,7,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0
That table accounts for all the scancodes and returns a zero if anyhting
else was pressed. Adding is simple, just store them and add them. This
won't work with double digits either, but it'd be simple to put it.
--
Compliments of:
_-_-_-_-_-_-_-_
Alan Bailey
mailto:bailala@mw.sisna.com
IRC:Abalone
Web:http://www.mw.sisna.com/users/bailala/home.htm
References: