A86: Re:


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

A86: Re:




OK, when I run into an error, I always comment the crap out of the
source.  So let's try that, and it should work:

---

#include "asm86.h"        ;ALWAYS put asm86.h before ti86asm.inc
#include "ti86asm.inc"    ;(you had ti86asm.inc first before)

p_health   = _textShadow     ;I prefer to use _textShadow for temp
p_attack   = _textShadow+1   ; variable storage - much easier to
p_defence  = _textShadow+2   ; manage.  _textShadow is 168 bytes long,
e_health   = _textShadow+3   ; starting at $C0F9
e_attack   = _textShadow+4
e_defence  = _textShadow+5

.org _asm_exec_ram  ;you didn't have a .org in your source!
                    ; bad!  bad!  bad!  :)

 ld a,20                        ; a = 20
 ld (p_health),a                ; p_health = 20
 ld a,10                        ; a = 10
 ld (p_attack),a                ; p_attack = 20
 ld a,3                         ; a = 3
 ld (p_defence),a               ; p_attack = 3

 ld hl,10                       ; hl = 10
 ld (e_health),hl               ; e_health = 10
 ld hl,5                        ; hl = 5
 ld (e_attack),hl               ; e_attack = 5
 ld hl,2                        ; hl = 2
 ld (e_defence),hl              ; e_defence = 2

keyloop:          ;I'm not gonna comment this...too easy...you
 call GET_KEY     ; obviously know what it does
 cp K_F1
 jr z,fight
 cp K_F5
 jr z,exit
 jr keyloop

fight:           ;                                1st loop    2nd loop
 ld a,(e_defence); load enemy defence              a = 3        " "
 ld c,a          ; put into C                      c = 3        " "
 ld a,(p_attack) ; load player attack              a = 10       " "
 sub c           ; sub defence from attack         a = 7        " "
 ld c,a          ;                                 c = 7        " "
 ld a,(e_health) ; load enemy health               a = 10       a = 3
 sub c           ; subtract resultant attack force a = 3        a = -4
 ld (e_health),a ; save new health                 e_health = 3 " = -4
 cp 0            ; if greater than zero...  |the 2nd time around, it is
 jp p, keyloop   ; ...return to loop        |less than 0
                 ; NOTE - I prefer to use "jp" for conditional jumps
                 ;        since it is easier to use (in this case, "p"
                 ;        means "positive")
 jr exit

exit:
 ret             ; quit

.end             ;DON'T forget your .end!  It wasn't there before

---

OK, that's the optimized code.  I just tested it, and you press [F1]
twice, and it goes away.

		-Rick

		http://www.angelfire.com/ga/ti86

Dave VanEe wrote:
> 
> I can't get this to work! Sorry, I tried for quite a long time trying to
> make this work. I just need someone else (for a different perspective) to
> see what is wrong. It's supposed to just wait for you to press F1 2 times
> then quit. That's the main concept, but there is a greater program
> (obviously). I know there are easier ways to just wait for two keypresses.
> 
> Thanx,
> Dave
> 
> PS: Sorry for posting the whole thing, I tried to cut it down a lot...
> 
> #include "ti86asm.inc"
> #include "asm86.h"
> 
> p_health                = $8001
> p_attack                = $8002
> p_defence               = $8003
> e_health                = $8005
> e_attack                = $8006
> e_defence               = $8007
> 
>  ld a,20                        ; load stats...
>  ld (p_health),a                ; this will be done another way later
>  ld a,10
>  ld (p_attack),a
>  ld a,3
>  ld (p_defence),a
> 
>  ld hl,10                       ; I used HL for a mem-addressing
>  ld (e_health),hl               ; reason which isn't shown here
>  ld hl,5
>  ld (e_attack),hl
>  ld hl,2
>  ld (e_defence),hl
> 
> keyloop:
>  call GET_KEY
>  cp K_F1
>  jr z,fight
>  cp K_F5
>  jr z,exit
>  jr keyloop
> 
> fight:
>  ld a,(e_defence)               ; load enemy defence
>  ld c,a                 ; put into C
>  ld a,(p_attack)                ; load player attack
>  sub c                  ; sub defence from attack
>  ld c,a
>  ld a,(e_health)                ; load enemy health
>  sub c                  ; subtract resultant attack force
>  ld (e_health),a                ; save new health
>  cp 0                           ; if greater than zero...
>  jr nc, keyloop         ; ...return to loop
>  jr exit
> 
> exit:
>  ret                            ; quit


References: