Re: A89: Exit routine
[Prev][Next][Index][Thread]
Re: A89: Exit routine
If you are talking about your tic tac toe program, I fixed that. I rewrote
your program to learn 68k asm. Thank you for writeing it. It was small
enough for me not to get lost in. If you are intrested you can look at what
I came up with.
Thx a lot
Matt.
>From: S43R80@aol.com
>Reply-To: assembly-89@lists.ticalc.org
>To: assembly-89@lists.ticalc.org
>Subject: Re: A89: Exit routine
>Date: Wed, 25 Aug 1999 18:00:01 EDT
>
>
>In a message dated 99-08-25 17:49:56 EDT, you write:
>
>I really don't think that this is his problem...i can't think of any reason
>why anyone would bsr to the exit routine...It probably does have something
>to
>do w/ your bra(s) though...I know I had a problem where I had to press exit
>2
>or 3 times before my game would officially exit...
>-Steven
_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com
; Tic Tac Toe
;
; Created By : Steven Reagan
; Rewritten By : Matt Baker
include "tios.h" ;included for ti rom calls
include "util.h" ;included for clr_scr, and idle_loop
include "linelib.h" ;included for fline
include "graphlib.h" ;included for put_sprite2
xdef _main ;program starts at main
xdef _comment
xdef _ti89 ;defines what calc is used
_main: ;code starts here
jsr util::clr_scr ;lib function which clears the screen
move.w #1,-(a7) ;set to normal font
jsr tios::FontSetSys ;calls tios romcall which sets the desired font
add.l #2,a7 ;fixes stack because a word(2 bytes) was pushed
move.w #4,-(a7) ;set to black on white
pea by(pc) ;pushes address of string on the stack
move.w #12,-(a7) ;pushes y-coord on the stack
move.w #70,-(a7) ;pushes x-coord on the stack
jsr tios::DrawStrXY ;calls tios romcall which displays a string
add.l #10,a7 ;fixes stack, (word + word + word + long word = 10)
move.w #2,-(a7) ;set to large font
jsr tios::FontSetSys ;calls tios romcall which sets the desired font
add.l #2,a7 ;fixes stack because a word(2 bytes) was pushed
move.w #4,-(a7) ;set to black on white
pea tic(pc) ;pushes address of string on the stack
move.w #0,-(a7) ;pushes y-coord on the stack
move.w #0,-(a7) ;pushes x-coord on the stack
jsr tios::DrawStrXY ;calls tios romcall which displays a string
add.l #8,a7 ;fixes stack 3 words and one longword were pushed,
;but I only push 8 back on cuz I want to keep the last
;word for the next call to DrawStrXY
;The only reason I do this is to save a few bytes in
;reference to the program size.
pea scr(pc) ;pushes address of string on the stack
move.w #22,-(a7) ;pushes y-coord on the stack
move.w #25,-(a7) ;pushes x-coord on the stack
jsr tios::DrawStrXY ;calls tios romcall which displays a string
add.l #10,a7 ;10 because I make up for the word I did not fix last time
bsr title_screen_grid ;draws grid seen at title screen
jsr util::idle_loop ;calls idle loop which waits for a key press and stores
;the keycode in d0
Begin: ;game jumps back here after a win or tie (new game)
bsr clear_vars ;clears all vars that may have been left by last game
jsr util::clr_scr ;after key pressed (title screen exited) then clear the
;screen for the game
bsr drawgrid ;calls sub routine which draws the grid using fline
move.b #1,turn ;x goes first
bsr disp_box_sprite ;since the starting point for the box was already initilized
;in clear_vars, go ahaid and display the box in its initial
;position
loop: ;game jumps back here when it needs another key to be pressed
jsr util::idle_loop ;waits for keypress/stores keycode in d0
test_esc:
cmp.w #264,d0 ;compare key that was pressed to 264(esc character code)
bne test_up ;if it is not an escape go to test_up
rts ;if it is an escape then return from game to shell/home
test_up:
cmp.w #337,d0 ;compare key that was pressed to 337(up character code)
bne test_down ;if it is not an up then go to test_down
bsr box_erase ;since we are going to move the box erase the previous one
cmp.b #15,box_y ;15 will be the value of box_y if the box is in the top row
bne normal_up ;if it is not in the top row then just move it up normaly
move.b #81,box_y ;since we were at the top we want to go to the bottom
;I set it to 22+the bottom since it will have 22 subtracted
move.b #3,coord_y ;set the coord to 1 + the bottom one, since I am going to
;let it fall out. ( it will have 1 subtracted )
normal_up:
sub.b #22,box_y ;subtract 22 from the y position of the box
sub.b #1,coord_y ;subtract 1 from the y coord
bsr disp_box_sprite ;display new box
test_down:
cmp.w #340,d0 ;compare key that was pressed to 340(down character code)
bne test_right ;if it is not an down then go to test_right
bsr box_erase ;since we are going to move the box erase the previous one
cmp.b #59,box_y ;59 will be the value of box_y if it is in the last row
bne normal_down ;if it is not in the bottom row then move it normally
move.b #-7,box_y ;it is in the bottom row so I set it to -7 so I can let
;it fall out
move.b #-1,coord_y ;same here I set it to -1 so I can let it fall out
normal_down:
add.b #22,box_y ;add 22 from the y position of the box
add.b #1,coord_y ;add 1 from the y coord
bsr disp_box_sprite ;display the new box
test_right:
cmp.w #344,d0 ;compare key that was pressed to 344(right character code)
bne test_left ;if it is not an right then go to test_left
bsr box_erase ;since we are going to move the box erase the previous one
cmp.b #93,box_x ;if it is in the right most col then box_x will be 93
bne normal_right ;if it is not in the right most col then move it normally
move.b #27,box_x ;it is in the right most col so I set it to 27 so it can
;just fall out
move.b #-1,coord_x ;same here I set it to -1 so I can let it fall out
normal_right:
add.b #22,box_x ;add 22 from the x position of the box
add.b #1,coord_x ;add 1 from the x coord
bsr disp_box_sprite ;display the new box
test_left:
cmp.w #338,d0 ;compare key that was pressed to 338(left character code)
bne test_F1 ;if it is not a left then go to test_F1
bsr box_erase ;since we are going to move the box erase the previous one
cmp.b #49,box_x ;if it is in the left most col then box_x will be 49
bne normal_left ;if it is not in the left most col then move normally
move.b #115,box_x ;it is in the left most col so I set it to 115 so it can
;yep you guessed it fall out
move.b #3,coord_x ;same here I set it to 3 so I can let it fall out
normal_left:
sub.b #22,box_x ;subtract 22 from the x position of the box
sub.b #1,coord_x ;subtract 1 from the x coord
bsr disp_box_sprite ;display the new box
test_F1:
cmp.w #268,d0 ;compare key that was pressed to 268(F1 character code)
bne loop ;if none of these keys were pressed loop again
clr.l d0 ;clear the data registers that I want to work with.
clr.l d1
clr.l d2
lea board(pc),a0 ;move the address of the board to a0
move.b coord_y,d1 ;move coord_y to d1
move.b coord_x,d2 ;move coord_x to d2
mulu #3,d1 ;mult d1 by 3 because there are 3 spots in each row
adda d1,a0 ;add offset to the address of the board
move.b 0(a0,d2),d0 ;move the contence of the spot in question to d0
tst.b d0 ;test it to see if it is occupied
bne loop ;If it is not zero, spot is taken so go back to loop
move.b turn,0(a0,d2) ;place piece in the spot
move.b box_x,d0 ;I want to print the x or o,and the x or o is 2 off from the
;coords, so I load d0 and d1 with the box coords
move.b box_y,d1 ;same as above
add.w #2,d0 ;Add 2 so I get coords of where to put the x or o
add.w #2,d1 ;same as above
cmp.b #1,turn ;compare to 1(x turn) to see who's turn it is
bne oturn ;if it is not equal then it is o's turn so goto oturn
lea x_sprite(pc),a0 ;load address of o sprite
move.b #4,turn ;since it was x's turn switch it to o's turn (4)
move.b #3,d7 ;it was x's turn, and in memory I represent x as the number
;one if I added 3 x's up the total would be 3. I use this
;in my check for win code.
bra skipover ;I don't want to do o's stuff so skip over
oturn:
lea o_sprite(pc),a0 ;load address of o sprite
move.b #1,turn ;since is was o's turn switch it to x's turn (1)
move.b #12,d7 ;it was o's turn, and in memory I represent o as the number
;four. If I added 3 o's up the total would be 12. I use this
;in my check for win code.
skipover:
jsr graphlib::put_sprite ;display the x or o
;begin of check win code
;check horzontal
clr.l d1 ;clear d1 so I can use it in check horzontal
move.b coord_y,d1 ;load the current coord_y into d1 (last spot piece was put)
lea board(pc),a0 ;laad address to the board into a0
mulu #3,d1 ;get offset to the row that the piece was put in
adda d1,a0 ;add offset to to the address of the board to get the start of
;the row
move.b (a0)+,d2 ;move the first one in the row to d2
add.b (a0)+,d2 ;add the second one in the row
add.b (a0)+,d2 ;add the third one in the row
bsr win ;go to win to see if there is a win
;check vertical
clr.l d0 ;clear d0 so I can use it with check vertical
move.b coord_x,d0 ;load the current coord_x into d0 (last spot piece was put)
lea board(pc),a0 ;load the address to the board into a0
adda d0,a0 ;add the offset to the first piece to the board address
move.b (a0),d2 ;move the first piece into d2
add.w #3,a0 ;add the offset to the second piece to the board address
add.b (a0),d2 ;add the second piece to d2
add.w #3,a0 ;add the offset to the third piece to the board address
add.b (a0),d2 ;add the third piece to d2
bsr win ;go to win to see if there is a win
;check diagonal #1
lea board(pc),a0 ;load the address of the board into a0
move.b (a0),d2 ;move the first piece into d2
add.w #4,a0 ;add the offset to the second piece to the board address
add.b (a0),d2 ;add the second piece to d2
add.w #4,a0 ;add the offset to the third piece to the board address
add.b (a0),d2 ;add the third piece to d2
bsr win ;go to win to see if there is a win
;check diagonal #2
lea board(pc),a0 ;load the address of the board into a0
add.w #2,a0 ;add the offset to the first piece to the board address
move.b (a0),d2 ;move the first piece to d2
add.w #2,a0 ;add the offset to the second piece to the board address
add.b (a0),d2 ;add the second piece to d2
add.w #2,a0 ;add the offset to the third piece to the board address
add.b (a0),d2 ;add the third piece to d3
bsr win ;go to win to se if there is a win
;check cat game
clr.l d1
move.l #8,d0
lea board(pc),a0
daloop:
move.b (a0)+,d1
cmp 0,d1
beq loop ;if no winner and no cat game loop again
dbra d0,daloop
out:
move.w #4,-(a7)
pea itsatie(pc)
move.w #42,-(a7)
move.w #40,-(a7)
jsr tios::DrawStrXY
add.l #10,a7
jsr util::idle_loop
bra Begin
win:
cmp.b d2,d7
beq skip
rts
skip:
move.w #4,-(a7)
cmp.b #3,d7
beq x_wins
pea owins(pc)
bra skip_over
x_wins:
pea xwins(pc)
skip_over:
move.w #42,-(a7)
move.w #56,-(a7)
jsr tios::DrawStrXY
add.l #14,a7 ;10 plus the address from the bsr coming here
jsr util::idle_loop
bra Begin
disp_box_sprite:
move.b box_x,d0 ;put x-coord in d0
move.b box_y,d1 ;put y-coord in d0
ext.w d0 ;since put_sprite2 expects a word I sign extend to a word
ext.w d1 ;same as above
lea box_sprite(pc),a0 ;address of sprite
lea masknobox(pc),a2 ;address of mask
jsr graphlib::put_sprite2 ;calls put_sprite which will create the box
rts
box_erase:
move.b box_x,d0 ;x-coordinate in d0
move.b box_y,d1 ;y-coordinate in d1
ext.w d0 ;since put_sprite2 expects a word I sign extend to a word
ext.w d1 ;same as above
lea box_empty_sprite(pc),a0 ;erases box
lea maskbox(pc),a2
jsr graphlib::put_sprite2 ;calls putsprite which will ultimately delete the old box
rts ;returns from subroutine
clear_vars:
lea board(PC),a0
move.l #0,(a0)+
move.l #0,(a0)+
move.b #0,(a0)+
move.b #49,box_x ;set coord for box position one
move.b #15,box_y
move.b #0,coord_x
move.b #0,coord_y
rts
drawgrid: ;draws 4 lines (the grid)
move.l #LCD_MEM,a0 ;line 1
move.w #47,d0 ;x1
move.w #57,d1 ;y1
move.w #113,d2 ;x2
move.w #57,d3 ;y2
jsr linelib::fline ;calls library function to display a line
move.l #LCD_MEM,a0 ;line 2
move.w #47,d0
move.w #35,d1
move.w #113,d2
move.w #35,d3
jsr linelib::fline
move.l #LCD_MEM,a0 ;line 3
move.w #69,d0
move.w #79,d1
move.w #69,d2
move.w #13,d3
jsr linelib::fline
move.l #LCD_MEM,a0 ;line 4
move.w #91,d0
move.w #79,d1
move.w #91,d2
move.w #13,d3
jsr linelib::fline
rts ;returns from subroutine
title_screen_grid: ;draws the grid you see during the title screen
move.l #LCD_MEM,a0 ;line 1
move.w #75,d0 ;x1
move.w #35,d1 ;y1
move.w #65,d2 ;x2
move.w #90,d3 ;y2
jsr linelib::fline ;calls library function
move.l #LCD_MEM,a0 ;line 2
move.w #95,d0
move.w #35,d1
move.w #85,d2
move.w #90,d3
jsr linelib::fline
move.l #LCD_MEM,a0 ;line 3
move.w #45,d0
move.w #60,d1
move.w #120,d2
move.w #45,d3
jsr linelib::fline
move.l #LCD_MEM,a0 ;line 4
move.w #45,d0
move.w #80,d1
move.w #120,d2
move.w #65,d3
jsr linelib::fline
rts ;return
;--------------------------------------DATA SEGMENT-----------------------------------------
; sprites, strings, board and turn
;----------------------------------------SPRITES--------------------------------------------
x_sprite: ;the X sprite
dc.w 15
dc.w 2
dc.b %10000000,%00000010;1
dc.b %01000000,%00000100
dc.b %00100000,%00001000
dc.b %00010000,%00010000
dc.b %00001000,%00100000
dc.b %00000100,%01000000
dc.b %00000010,%10000000
dc.b %00000001,%00000000
dc.b %00000010,%10000000
dc.b %00000100,%01000000;10
dc.b %00001000,%00100000
dc.b %00010000,%00010000
dc.b %00100000,%00001000
dc.b %01000000,%00000100
dc.b %10000000,%00000010;15
o_sprite: ;the O sprite
dc.w 15
dc.w 2
dc.b %00000111,%11000000;1
dc.b %00011000,%00110000
dc.b %00100000,%00001000
dc.b %01000000,%00000100
dc.b %01000000,%00000100
dc.b %10000000,%00000010
dc.b %10000000,%00000010
dc.b %10000000,%00000010
dc.b %10000000,%00000010
dc.b %10000000,%00000010;10
dc.b %01000000,%00000100
dc.b %01000000,%00000100
dc.b %00100000,%00001000
dc.b %00011000,%00110000
dc.b %00000111,%11000000;15
box_sprite:
dc.w 19 ;height of box_sprite
dc.w 3 ;width of box_sprite
maskbox:
dc.b %11111111,%11111111,%11100000 ;1
dc.b %10000000,%00000000,%00100000 ;this is the box that is moved around
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000 ;10
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %10000000,%00000000,%00100000
dc.b %11111111,%11111111,%11100000 ;19
_comment:
dc.b "Tic Tac Toe by: S43R80@aol.com",0 ;description of the program
;Yes it is out of place, but I needed a odd
;byte string to make the next sprite start on
;an even address, so it would not barf
box_empty_sprite: ;this sprite is used to remove the box
dc.w 19
dc.w 3
masknobox:
dc.b %00000000,%00000000,%00000000 ;all 0's lets the box be transparent
dc.b %00000000,%00000000,%00000000 ;so the x's and o's will not be erased
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000 ;10
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000
dc.b %00000000,%00000000,%00000000 ;19
;----------------------------KEEP TRACK OF POSITIONS BEING USED-----------------------------
turn dc.b 0 ;keeps track of whos turn it is. It is placed above board
;because I need board to start on an even address.
board:
dc.b 0,0,0,0,0,0,0,0,0 ;9 bytes represent the board
;-----------------------------------COORDINATES---------------------------------------------
box_x dc.b 0 ;x-coordinate of box either (49, 71, 93)
box_y dc.b 0 ;y-coordinate of box either (15, 37, 59)
coord_x dc.b 0 ;x-coordinate of current selection either (0, 1, 2)
coord_y dc.b 0 ;y-coordinate of current selection either (0, 1, 2)
;-------------------------------------STRINGS-----------------------------------------------
itsatie:
dc.b "Nobody Wins",0
xwins:
dc.b "X Wins",0
owins:
dc.b "O Wins",0
tic:
dc.b "T i c T a c T o e",0 ;words displayed at title screen
by:
dc.b "By:",0
scr:
dc.b "Steven Reagan",0 ;the author
end
Follow-Ups: