A85: I need help with this code!


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

A85: I need help with this code!



    I have been working on some code for Usgard 1.5. It is
supposed to move a 16 by 8 sprite across the screen when you
press the arrows. when you press exit it should quit. When
you run it nothing happens. If you press exit a couple of
times the calc freezes and displays garbage, eventualy
shutting off. What is wrong? The code is below and attached.



#include "usgard.h"                      ; ROM_CALLs Galore!

.org 0                                   ; Need this

.db "Sprite Test",0                      ; Sprite test

Pos            =TEXT_MEM                 ; Bin pos

   ld          a, 4                      ; Set Video Mode
   out         (5), a

   ld           a, 60
   ld           (Pos), a

GameLoop:

   call         &EraseSprite
   halt                                  ; save some power
   call         GET_KEY
   cp           K_LEFT
   jr           z, MoveLeft              ; Is it left?
   cp           K_RIGHT
   jr           z, MoveRight             ; Is it right?
   cp           K_EXIT
   ret          z
   call         &DrawBin
   jr           GameLoop

MoveLeft:

   ld           a, (Pos)
   dec          a
   dec          a
   jr           z, GameLoop
   ld           (Pos), a
   jr           GameLoop

MoveRight:

   ld           a, (Pos)
   inc          a
   inc          a
   cp           112
   jr           nc, GameLoop
   ld           (Pos), a
   jr           GameLoop

DrawBin:

   ld          a, (Pos)                  ; Load x pos
   ld          b, a
   ld          c, 30                     ; Load y pos
   ld          hl, &Bin1                 ; Load sprite
   #fncall PSPR_NR
   ld          a, b                      ; Load offset
   add         a, 8
   ld          b, a
   ld          c, 30                     ; Load y pos
   ld          hl, &Bin2                 ; Load sprite
   #fncall PSPR_NR
   ret

EraseSprite:

   ld          a, (Pos)                  ; Load x pos
   ld          b, a
   ld          c, 30                     ; Load y pos
   ld          hl, &Blank                ; Load sprite
   #fncall PSPR_NR
   ld          a, b                      ; Load offset
   add         a, 8
   ld          b, a
   ld          c, 30                     ; Load y pos
   ld          hl, &Blank                ; Load sprite
   #fncall PSPR_NR
   ret

Bin1:

   .db        8,8
   .db        %11111111
   .db        %11111111
   .db        %11111111
   .db        %11111111
   .db        %11111111
   .db        %01111111
   .db        %00111111
   .db        %00001111

Bin2:

   .db        8,8
   .db        %11111111
   .db        %11111111
   .db        %11111111
   .db        %11111111
   .db        %11111111
   .db        %11111110
   .db        %11111100
   .db        %11110000

Blank:

   .db        8,8
   .db        %00000000
   .db        %00000000
   .db        %00000000
   .db        %00000000
   .db        %00000000
   .db        %00000000
   .db        %00000000
   .db        %00000000

.end





------------------------------------------------------------
---------
Michael Cook

MBCook@MBCook.com (website related)
MBCook@Concentric.net (general)
Digi02@aol.com (checked once per month)
------------------------------------------------------------
---------
www.MBCook.com


spritest.asm