yeongJIN_COOL wrote:
I actually did everything until number 4 before reading this post
hahah I'm not suprised other people have done exercises like these, I'm not the most creative sometimes...
Here's code for...
1/2. I just looked at this code and it is BAD. I don't really wanna go back and correct it, so I don't wanna post it here. If anybody thinks itd be THAT valuable, I guess I could fix it up
3.
Code:
.nolist
#include "ti83plus.inc"
.list
.org $9D93
.db t2ByteTok, tAsmCmp
b_call(_ClrLCDFull)
ld a, 0
ld hl, 0
ld (CurCol), a
ld (CurRow), a
ld (AppBackUpScreen), hl
ld (AppBackUpScreen+2), hl
jp disp
while:
b_call(_GetKey)
cp kUp
jr z, up
cp kDown
jr z, down
cp kLeft
jr z, left
cp kRight
jr z, right
cp kClear
jp z, return
jr while
up:
ld a, (AppBackUpScreen+1)
cp 0
jr z, disp
dec a
ld (AppBackUpScreen+1), a
jr collide
down:
ld a, (AppBackUpScreen+1)
cp 7
jr z, disp
inc a
ld (AppBackUpScreen+1), a
jr collide
left:
ld a, (AppBackUpScreen)
cp 0
jr z, disp
dec a
ld (AppBackUpScreen), a
jr collide
right:
ld a, (AppBackUpScreen)
cp 15
jr z, disp
inc a
ld (AppBackUpScreen), a
jr collide
collide:
;Checks to see if 'x' is at the same coords as 'o'
ld hl, AppBackUpScreen+2
ld a, (AppBackUpScreen) ;load x coords into hl and a for comparison
cp (hl)
jr nz, disp ;if x coords are unequal, jump straight to display routine
ld hl, AppBackUpScreen+3
ld a, (AppBackUpScreen+1) ;load y coords into hl and a for comparison
cp (hl)
jr nz, disp ;unequal y coords, jump to disp routine.
;If 'x' coords were equal to 'o' coords, generate new 'o' pos and increment score
ld a, (AppBackUpScreen+4) ;increment score
inc a
ld (AppBackUpScreen+4), a
ld a, r ;"randomize" 'o' pos
and %00001111
ld (AppBackUpScreen+2), a ;x coord
ld a, r
and %00000111
ld (AppBackUpScreen+3), a ;y coord
jr disp
disp:
b_call(_ClrLCDFull)
ld a, (AppBackUpScreen)
ld (CurCol), a
ld a, (AppBackUpScreen+1)
ld (CurRow), a
ld a, 'x'
b_call(_PutC)
ld a, (AppBackUpScreen+2)
ld (CurCol), a
ld a, (AppBackUpScreen+3)
ld (CurRow), a
ld a, 'o'
b_call(_PutC)
jp while
return:
b_call(_NewLine)
b_call(_ClrLCDFull)
ld a, 1
ld (CurRow), a
ld (CurCol), a
ret
.end
.end
4. (still without score)
Code:
.nolist
#include "ti83plus.inc"
.list
.org $9D93
.db t2ByteTok, tAsmCmp
b_call(_ClrLCDFull)
ld a, 0
ld (CurRow), a ;CurRow is y
ld (CurCol), a ;CurCol is x
ld hl, 0
ld (AppBackUpScreen), hl ;position of "character" (a 'u'). (AppBackUpScreen) = x, (AppBackUpScreen+1) = y.
ld (AppBackUpScreen+2), hl ;position of "thing to catch" (an 'o').
ld (AppBackUpScreen+4), hl ;score
ld hl, 3
ld (AppBackUpScreen+5), hl ;lives
ld a, 7
ld (AppBackUpScreen+1), a ;constant y pos of 'u'
ld hl, 0
push hl
waitkey:
b_call(_GetCSC)
cp skLeft
jr z, moveleft
cp skRight
jr z, moveright
cp skClear
jp z, return
pop hl ;Increment hl
inc hl
push hl
ld de, $0500 ;load de with the #of cycles to increment o after.
scf ;set and clear carry flag to make sure sbc hl, de is accurate
ccf
sbc hl, de
jp nc, incr_o ;if hl is greater than $400 (the carry flag is not triggered by subtracting $400 from hl), jump to incr_o
jr waitkey ;otherwise, just jump back to waitkey
moveleft:
ld a, (AppBackUpScreen) ;load the player's x coord into the a register
cp 0
jr z, disp ;if 'u'x is equal to 0, jump to display routine without decrementing the x coordinate to prevent it from going offscreen
dec a ;dec x position
ld (AppBackUpScreen), a
pop hl
ld de, $120 ;increment hl more than usual, the b_calls _PutC and _ClrLCDFull at the disp label will take a lot of time
add hl, de
push hl
jr disp
moveright:
ld a, (AppBackUpScreen) ;load the player's x coord into the a register
cp 14
jr z, disp ;if 'u'x is equal to 14, jump to display routine without incrementing the x coordinate to prevent it from going into that one glitchy spot
inc a ;increment x position
ld (AppBackUpScreen), a
pop hl
ld de, $120 ;increment hl more than usual, the b_calls _PutC and _ClrLCDFull at the disp label will take a lot of time
add hl, de
push hl
jr disp
incr_o: ;routine for incrementing o position
pop hl
ld hl, 0
push hl
ld a, (AppBackUpScreen+3) ;Move down 'o'
inc a
ld (AppBackUpScreen+3), a
;now, check to see if 'o' pos is equal to 'u' pos.
ld a, (AppBackUpScreen+2) ;loading 'o'x into a
ld hl, AppBackUpScreen ;loading &'u'x into hl
cp (hl)
jr nz, chkbottomout ;if 'o'x != 'u'x, then skip to check if o is bottomed out.
ld a, (AppBackUpScreen+3) ;loading 'o'y into a
ld hl, AppBackUpScreen+1 ;loading &'u'y into hl
cp (hl)
jr nz, chkbottomout ;if ('o'x != 'u'x) AND ('o'y != 'u'y), then skip to check if o is bottomed out.
;if we reach this line, then the o and the u occupy the same location. Increment score and generate new o.
ld a, (AppBackUpScreen+4) ;Increment score
inc a
ld (AppBackUpScreen+4), a
jr generate_o ;and jump to new o generation
chkbottomout:
ld a, (AppBackUpScreen+3) ;load 'o'y into a register
cp 8
jr nz, disp ;jump to disp if 'o'y - 9 is not 0.
;If the 'o' was not caught...
ld a, (AppBackUpScreen+5) ;decrement 1 from the lives
dec a
jr z, gameOver ;if a is now 0, all lives are gone. End game.
ld (AppBackUpScreen+5), a
generate_o:
ld a, r ;"Random" number is put into a register
and $0F ;Bitmask "random" int with 00001111 and use if-then to make sure it's not over 14
cp 15
jr nz, good_o
dec a
good_o:
ld (AppBackUpScreen+2), a ;load "random" a into 'o'x
ld a, 0
ld (AppBackUpScreen+3), a
disp:
b_call(_ClrLCDFull)
ld a, (AppBackUpScreen) ;load up curcol and currow. Remember, 'u'x is stored right at AppBackUpScreen
ld (CurCol), a
ld a, 7
ld (CurRow), a
ld a, 'u'
b_call(_PutC) ;print the u
ld a, (AppBackUpScreen+2) ;load up curcol and currow for o's
ld (CurCol), a
ld a, (AppBackUpScreen+3)
ld (CurRow), a
ld a, 'o'
b_call(_PutC) ;print the o
;display score/lives
ld a, 15
ld (CurCol), a
ld a, 5
ld (CurRow), a
ld hl, (AppBackUpScreen+5) ;load lives into hl register
liveswhile:
ld a, 'u' ;put 'u' into a register because we're displaying a 'u'
push hl ;protect hl, yada yada yada
b_call(_PutC)
pop hl
ld a, 15 ;load 15 into curcol
ld (CurCol), a
ld a, (CurRow) ;Load current CurRow-2 into CurRow. CurRow automatically increments when b_call(_PutC) is called, so we have to decrement it not once, but twice.
sub 2
ld (CurRow), a
dec hl ;Decrease # of lives left to render
ld a, h ;Because dec reg16 does not affect the flags, we have to dec hl and then do an or on h and l. Think about it, if (H V L) = 0, then both h and l are 0. To do this, we must first load h (or l) into a.
or l ;thanks Kerm Martian =)
jr nz, liveswhile
jp waitkey
gameOver:
b_call(_ClrLCDFull) ;clear LCD, reset curcol and currow, and display endgame msg.
ld hl, 0
ld (CurRow), hl
ld hl, gameovermsg
b_call(_PutS)
b_call(_GetKey)
return:
b_call(_ClrLCDFull)
pop hl
ret
gameovermsg:
.db "You are a loser =( Press any key toexit", 0
.end
.end
I know the way the timing work is odd, tips on that please.
Criticism is appreciated!! I want all the knowlege this glorious forum has to give.