Tutorial #7

Tutorial #7

2-1-99

Direct Input!

Ok, now for something useful! Here is a program that I made that when you press a key the sprite will move! Now this tutorial will be long and complex...So just read all of the comments and study the code and you should be fine... The only thing that you don't need to understand is the Sprite Routine by Movax...Don't read that because it will confuse you.... Its the code that makes the sprite move...

.NOLIST

#DEFINE equ .equ

#DEFINE EQU .equ

#DEFINE end .end

#INCLUDE "ti83asm.inc"

#INCLUDE "tokens.inc"

.LIST

.org 9327h

#DEFINE ShipX 8265h	;This is a variable we need to define the address is 8265h
#DEFINE ShipY 8266h	;This is a variable we need to define the address is 8266h
	call _clrLCDFull	;Clears the screen
	call _runIndicOff	;Turn off the Run Indicator
	call _grbufclr		;Clears the Graph Buffer (Graph Screen)
	call _homeup		;Coords 0,0
	ld a,35			;Coords 35 for X axes
	ld (ShipX),a		;Loads the coords from above into the X Axes
	ld a,40			;Loads 40 for Y axes
	ld (ShipY),a		;Loads the coords from above into Y axes
	jr moveloop		;Goto moveloop (Little jump)
moveloop:
	call putship		;Calls putship
	jr getk			;Jump to the input variable (Little jump)
getk:
	ld a,0ffh		;Resets the key port
	out (1),a		;Output I guess?
	ld a,0feh		;Loads the keyport for right, left, up, down
	out (1),a		;Output I guess?
	in a,(1)		;Input, waits for key press
	cp 251			;Was the key pressed right?
	jp z,right		;Yes? Jump to variable right
	cp 253			;Was the key pressed left?
	jp z,left		;Yes? Jump to variable left
	cp 247			;Was the key pressed down?
	jp z,down		;Yes? Jump to variable down
	cp 254			;Was the key pressed up?
	jp z,up			;Yes? Jump to variable up
	ld a,0ffh		;Resets keyport
	out (1),a		;Output I guess?
	ld a,0fdh		;Loads keyport for Clear
	out (1),a		;Output I guess?
	in a,(1)		;Input waits for keypress
	cp 191			;Was key pressed Clear?
	jp z,quit		;Yes? Jump to quit
	jp getk			;No keypressed go back to getk
left:
	call putship		;Puts the ship on screen
	ld a,(ShipX)		;Loads the ship into a
	dec a			;Decreases a
	ld (ShipX),a		;Loads a into Ship
	jp moveloop		;Goto moveloop
right:
	call putship		;Puts the ship on screen
	ld a,(ShipX)		;Loads the ship into a
	inc a			;Increases a
	ld (ShipX),a		;Loads a into ship
	jp moveloop		;Goto moveloop
down:
	call putship		;Puts the ship on screen
	ld a,(ShipY)		;Loads the ship into a
	dec a			;Decreases a
	ld (ShipY),a		;Loads a into ship
	jp moveloop		;Goto moveloop
up:
	call putship		;Puts the ship on screen
	ld a,(ShipY)		;Loads the ship into a
	inc a			;Decreases a
	ld (ShipY),a		;Loads a into ship
	jp moveloop		;Goto moveloop
putship:
	ld a,(ShipY)		;Loads ship into a
	ld e,a			;Loads the coords
	ld a,(ShipX)		;Loads shipX into a
	ld bc,ship		;Loads the sprite
	call SPRXOR		;Calls the Routine that Moves the sprite when key is pressed
	call _grbufcpy_v	;Copys to graph screen
	ret			;Returns to what it was doing
quit:
	call _clrLCDFull	;Clears the screen
	call _grbufclr		;Clears the Graph Buffer (Graph Screen)
	call _dispDONE		;Displays Done (I think)
	ret			;Returns to what it was doing
;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿
;³ÛÛÛÛÛ Z80 ÛÛÛÛÛÛ³    Sprite83    ³ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ³ movax ³ÛÛÛÛÛÛÛÛÛÛÛÛ³
;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ

; Sprite xor routine v1.0
; Coded by Hannes Edfeldt in 1997

; This routine uses xor to draw the sprite, therefore you can erase the sprite
; by just drawing it again at the same x and y coordinates. See xordemo.z80
; for an example of how to use this routine.

; Feel free to use this routine in your own productions as long as you give me
; some credit.

; This file should of course be viewed in a DOS texteditor ;)

; Hannes Edfeldt -+- movax@algonet.se -+- http://www.algonet.se/~movax


;ÜÛÛÛÛÛÛÛÛÛÛÛÛß SPRXOR ßÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
;³ Xor 8x8 sprite þ a=x, e=y, bc=sprite address                               ³
;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
SPRXOR:

        push    bc              ; Save sprite address

;ÛÛÛÛ   Calculate the address in graphbuf   ÛÛÛÛ

        ld      hl,0            ; Do y*12
        ld      d,0
        add     hl,de
        add     hl,de
        add     hl,de
        add     hl,hl
        add     hl,hl

        ld      d,0             ; Do x/8
        ld      e,a
        srl     e
        srl     e
        srl     e
        add     hl,de

        ld      de,8e29h
        add     hl,de           ; Add address to graphbuf

        ld      b,00000111b     ; Get the remainder of x/8
        and     b
        cp      0               ; Is this sprite aligned to 8*n,y?
        jp      z,ALIGN


;ÛÛÛÛ   Non aligned sprite blit starts here   ÛÛÛÛ

        pop     ix              ; ix->sprite
        ld      d,a             ; d=how many bits to shift each line

        ld      e,8             ; Line loop
LILOP:  ld      b,(ix+0)        ; Get sprite data

        ld      c,0             ; Shift loop
        push    de
SHLOP:  srl     b
        rr      c
        dec     d
        jp      nz,SHLOP
        pop     de

        ld      a,b             ; Write line to graphbuf
        xor     (hl)
        ld      (hl),a
        inc     hl
        ld      a,c
        xor     (hl)
        ld      (hl),a

        ld      bc,11           ; Calculate next line address
        add     hl,bc
        inc     ix              ; Inc spritepointer

        dec     e
        jp      nz,LILOP        ; Next line

        jp      DONE1


;ÛÛÛÛ   Aligned sprite blit starts here   ÛÛÛÛ

ALIGN:                          ; Blit an aligned sprite to graphbuf
        pop     de              ; de->sprite
        ld      b,8
ALOP1:  ld      a,(de)
        xor     (hl)
        ld      (hl),a
        inc     de
        push    bc
        ld      bc,12
        add     hl,bc
        pop     bc
        djnz    ALOP1

DONE1:
        ret
;ÜÛÛÛÛÛÛÛÛÛÛÛÛÜ SPRXOR ÜÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿
;³ÛÛÛÛÛ Z80 ÛÛÛÛÛÛ³    Sprite83    ³ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ³ movax ³ÛÛÛÛÛÛÛÛÛÛÛÛ³
;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ
ship:
 .db %00000000
 .db %00000000
 .db %00001000
 .db %00011100
 .db %01111111
 .db %11111110
 .db %11111100
 .db %01111000
.end		;Ends program
END		;Needed for TASM

 

Whew...That was a lot...Ok first you see all those 1's and 0's in the label ship? Well, thats the sprite, 1 means the pixel is turned on and 0 means the pixel is turned off. The Sprite Routine by Movax will confuse you if you read it beacause you don't know many of the commands he used, that routine he made makes the sprite move when you press a key...Its very good, and a lot of games use it... If you studyed the comments you should know what all those commands do now... Compile it and send it to yer calc and using the arrow keys you can move that little ship thing I made...You should be proud of yourself, you made something useful!! Edit those 1's and 0's to make your own object! Try it!!

Now remember that part of the code that said 0ffh, and it reset the keyport...Well I'm gonna provide you a list that shows you the labels of each key and its keyport... If you have any questions e-mail me...

0feh:

kDown .equ 254

kLeft .equ 253

kRight .equ 251

kUp .equ 247

 

0fdh:

kEnter .equ 254

kPlus .equ 253

kMinus .equ 251

kMul .equ 247

kDiv .equ 239

kPower .equ 223

kClear .equ 191

 

0fbh:

kMinus2 .equ 254

kThree .equ 253

kSix .equ 251

kNine .equ 247

kRbracket .equ 239

kTan .equ 223

kVars .equ 191

 

0f7h:

kPoint .equ 254

kTwo .equ 253

kFive .equ 251

kEight .equ 247

kLbracket .equ 239

kCos .equ 223

kPrgm .equ 191

kStat .equ 127

 

0efh:

kZero .equ 254

kOne .equ 253

kFour .equ 251

kSeven .equ 247

kComma .equ 239

kSin .equ 223

kMatrx .equ 191

kX .equ 127

 

0dfh:

.equ 254

kSto .equ 253

kLn .equ 251

kLog .equ 247

kX2 .equ 239

kX-1 .equ 223

kMath .equ 191

kAlpha .equ 127

 

0bfh:

kGraph .equ 254

kTrace .equ 253

kZoom .equ 251

kWindow .equ 247

kY .equ 239

k2nd .equ 223

kMode .equ 191

kDel .equ 127

 

Thats about it for this tutorial...You learned a lot in this one so the next one you will learn how to put pictures in ASM format into your calc!

(KSA)Tekken (uncool3@juno.com)