include "tios.h" include "util.h" include "graphlib.h" xdef _main xdef _comment xdef _ti89 DrawRect MACRO move.w \1,d0 move.w \2,d1 move.w \3,d2 move.w \4,d3 move.w \5,d4 jsr graphlib::fill ENDM ;************************************MACRO FOR PRINTING STRINGS WriteStr MACRO move.w \3,-(a7) pea \4(pc) move.w \2,-(a7) move.w \1,-(a7) jsr tios::DrawStrXY lea 10(a7),a7 ENDM ;***********************************MACRO FOR PRINTING D0 AS A STRING print_d0 MACRO lea strend(PC),a0 move.w #3,d1 bsr ConvStr move.w \3,-(a7) move.l a0,-(a7) move.w \2,-(a7) move.w \1,-(a7) jsr tios::DrawStrXY lea 10(a7),a7 ENDM SetFont MACRO move.w \1,-(a7) jsr tios::FontSetSys ; set the font add.l #2,a7 ; clean up the stack ENDM ;***************************************START _main: ;***************************************VARIABLE INIT ini_vars: move.w #78,ballx move.w #44,bally move.w #1,ballxdir move.w #1,ballydir move.w #40,p1y move.w #40,p2y move.w #0,escflag move.w #0,p1score move.w #0,p2score move.w #0,delay_len move.w #0,b1x move.w #0,b1y move.w #0,b2x move.w #0,b2y ;***************************************TITLE SCREEN title_scr: jsr graphlib::clr_scr2 SetFont #2 WriteStr #50,#10,#1,title SetFont #0 WriteStr #44,#30,#1,author WriteStr #40,#40,#1,weburl WriteStr #45,#80,#1,version SetFont #1 WriteStr #20,#60,#1,speed_sel title_repeat: jsr util::idle_loop cmp #268,d0 beq speed1 cmp #269,d0 beq speed2 cmp #270,d0 beq speed3 cmp #271,d0 beq speed4 cmp #272,d0 beq speed5 cmp #264,d0 beq escape bra title_repeat escape: move.w #1,escflag rts speed1: add.w #4500,delay_len speed2: add.w #2500,delay_len speed3: add.w #3500,delay_len speed4: add.w #500,delay_len speed5: add.w #1000,delay_len SetFont #2 ;****************************************MAIN LOOP prog_loop: bsr check_wall bsr check_paddle bsr check_bullets bsr move_ball bsr move_bullets bsr calc_ai bsr GetKeyStat bsr key_test bsr draw_screen bsr delay bsr check_scores cmp.w #0,escflag beq prog_loop rts ;*****************************************CHECK SCORES check_scores: cmp #10,p1score beq victory cmp #10,p2score beq failure rts victory: jsr graphlib::clr_scr2 WriteStr #50,#10,#1,win_message move.w #50000,delay_len bsr delay bsr delay bsr delay bsr delay bsr delay move.w #1,escflag rts failure: jsr graphlib::clr_scr2 WriteStr #50,#10,#1,lose_message move.w #50000,delay_len bsr delay bsr delay bsr delay bsr delay bsr delay move.w #1,escflag rts ;*****************************************BOUNCING BALL move_ball: cmp #1,ballxdir beq move_ball_right sub.w #2,ballx bra move_ball_2 move_ball_right: add.w #2,ballx move_ball_2: cmp #1,ballydir beq move_ball_down sub.w #2,bally rts move_ball_down: add.w #2,bally rts ;***************************************BALL COLLISIONS check_paddle: cmp #4,ballx beq check_paddle_1 cmp #152,ballx beq check_paddle_2 rts check_paddle_1: cmp #1,ballxdir beq cancel move.w bally,d0 add.w #3,d0 cmp p1y,d0 blt cancel sub.w #3,d0 move.w p1y,d1 add.w #11,d1 cmp d0,d1 blt cancel bsr bounce_x rts check_paddle_2: cmp #0,ballxdir beq cancel move.w bally,d0 add.w #3,d0 cmp p2y,d0 blt cancel sub.w #3,d0 move.w p2y,d1 add.w #11,d1 cmp d0,d1 blt cancel bsr bounce_x rts cancel: rts check_wall: bsr check_x bsr made_point2 bsr check_y bsr made_point1 rts made_point2: cmp #5,d0 beq add_point2 rts add_point2: add.w #1,p2score move.w #0,d0 rts made_point1: cmp #5,d0 beq add_point1 rts add_point1: add.w #1,p1score move.w #0,d0 rts check_x: cmp #0,ballx beq bounce_x cmp #156,ballx beq bounce_x rts check_y: cmp #0,bally beq bounce_y cmp #88,bally beq bounce_y rts bounce_x: move.w #1,d0 sub.w ballxdir,d0 move.w d0,ballxdir move.w #5,d0 rts bounce_y: move.w #1,d0 sub.w ballydir,d0 move.w d0,ballydir rts ;******************************************SCREEN OUTPUT draw_screen: jsr graphlib::clr_scr2 move.w ballx,d0 move.w bally,d1 move.l #ball_sprite,a0 jsr graphlib::put_sprite move.w #0,d0 move.w p1y,d1 move.l #p1_paddle,a0 jsr graphlib::put_sprite move.w #152,d0 move.w p2y,d1 move.l #p2_paddle,a0 jsr graphlib::put_sprite bsr draw_bullets move.w p1score,d0 print_d0 #40,#40,#1 move.w p2score,d0 print_d0 #80,#40,#1 rts rts ;****************************************CALC AI calc_ai: cmp #1,ballxdir beq calc_follow cmp #0,ballxdir beq calc_hunt rts calc_hunt: move p2y,d0 cmp p1y,d0 bgt p2_up cmp p1y,d0 blt p2_down rts calc_follow: cmp #75,ballx bgt do_follow cmp #40,p2y bgt p2_up cmp #40,p2y blt p2_down rts do_follow: move.w ballx,d0 ;store ballx in d0 for future use move.w bally,d1 ;store bally in d1 for future use move.w #0,d2 ;clear d2 for the next "do while d2=0" follow_while: ;this routine "looks into the future" to see ;where the ball might end up so the cpu ;knows exactly where to go bsr move_ball ;changes ballx and bally cmp #0,bally ;these lines checks if the ball hits a ble found_it ;boundary and if it does, goes to found_it cmp #88,bally bge found_it cmp #156,ballx bge found_it cmp #0,d2 ;"do while d2=0" beq follow_while rts found_it: move.w d0,ballx ;return the old value of ballx move.w bally,d0 ;store the "predicted" value of bally to d0 move.w d1,bally ;return the old value of bally move.w p2y,d2 ;move p2y to d2 add.w #6,d2 ;add 6 to d2 (center of paddle) cmp d0,d2 ;if d0 is greater than d2, move paddle up bgt p2_up cmp d0,d2 ;if d0 is less than d2, move paddle down blt p2_down rts ;if d0 is equal to d2, return p2_up: cmp #0,p2y bgt do_p2_up rts do_p2_up: sub.w #1,p2y rts p2_down: cmp #80,p2y blt do_p2_down rts do_p2_down: add.w #1,p2y rts ;****************************************BULLET COLLISIONS check_bullets: bsr check_b1 bsr check_b2 rts check_b1: cmp #156,b1x bne cancel move.w p2y,d0 sub.w #1,d0 cmp b1y,d0 bgt cancel add.w #12,d0 cmp b1y,d0 blt cancel bsr kill_b1 bsr add_point1 rts check_b2: cmp #156,b2x bne cancel move.w p1y,d0 sub.w #1,d0 cmp b2y,d0 bgt cancel add.w #12,d0 cmp b2y,d0 blt cancel bsr kill_b2 bsr add_point2 ;****************************************BULLETS draw_bullets: bsr draw_b1 bsr draw_b2 rts draw_b1: cmp #0,b1x beq no_bullet move.w b1x,d0 move.w b1y,d1 move.l #bullet_sprite,a0 jsr graphlib::put_sprite rts draw_b2: cmp #0,b2x beq no_bullet move.w #156,d1 sub.w b2x,d1 move.w d1,d0 move.w b2y,d1 move.l #bullet_sprite,a0 jsr graphlib::put_sprite rts move_bullets: bsr move_b1 bsr move_b2 rts move_b1: cmp #0,b1x beq no_bullet add.w #4,b1x cmp #160,b1x beq kill_b1 rts move_b2: cmp #0,b2x beq fire_p2 add.w #4,b2x cmp #160,b2x beq kill_b2 rts kill_b1: move.w #0,b1x rts kill_b2: move.w #0,b2x no_bullet: rts fire_p2: move.w p2y,d0 add.w #5,d0 move.w d0,b2y move.w #4,b2x rts ;****************************************KEYBOARD STUFF GetKeyStat: movem.l d0-d1/a0,-(a7) lea keystat(PC),a0 move.w #$FFFE,d0 moveq #6,d1 GetKeys: move.w d0,$600018 nop nop nop nop nop nop move.b $60001B,(a0)+ rol.w #1,d0 dbra d1,GetKeys movem.l (a7)+,d0-d1/a0 rts key_test: btst.b #6,keystat+1 beq escape btst.b #0,keystat beq move_p1_up btst.b #2,keystat beq move_p1_down key_test_2: bsr GetKeyStat btst.b #4,keystat beq fire_p1 move.w #0,d1 nothing_delay: add.w #1,d1 cmp #3500,d1 bne nothing_delay rts fire_p1: cmp #0,b1x bne cancel move.w p1y,d0 add.w #5,d0 move.w d0,b1y move.w #4,b1x move_p1_up: bsr key_test_2 cmp #0,p1y bne move_p1_up_2 rts move_p1_up_2: sub.w #1,p1y rts move_p1_down: bsr key_test_2 cmp #80,p1y bne move_p1_down_2 rts move_p1_down_2: add.w #1,p1y rts ;***********************************DELAY delay: move.w #0,d0 delay_repeat: add.w #1,d0 cmp delay_len,d0 bne delay_repeat rts ;*******************************CONVERT D0 TO A STRING ConvStr: movem.l d0-d2,-(a7) clr.b (a0) conv_repeat: divu #10,d0 move.l d0,d2 swap d2 add.b #48,d2 move.b d2,-(a0) subq #1,d1 and.l #$FFFF,d0 bne conv_repeat tst.w d1 beq conv_done subq #1,d1 fillout: move.b #32,-(a0) dbra d1,fillout conv_done: movem.l (a7)+,d0-d2 rts ;**************************************SPRITES p1_paddle: dc.w 12 dc.w 1 dc.b %11110000 dc.b %11010000 dc.b %10110000 dc.b %11010000 dc.b %10110000 dc.b %11010000 dc.b %10110000 dc.b %11010000 dc.b %10110000 dc.b %11010000 dc.b %10110000 dc.b %11110000 mask_1: dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 dc.b %11110000 p2_paddle: dc.w 12 dc.w 1 dc.b %00001111 dc.b %00001101 dc.b %00001011 dc.b %00001101 dc.b %00001011 dc.b %00001101 dc.b %00001011 dc.b %00001101 dc.b %00001011 dc.b %00001101 dc.b %00001011 dc.b %00001111 mask_2: dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 dc.b %00001111 ball_sprite: dc.w 4 dc.w 1 dc.b %01100000 dc.b %11110000 dc.b %11110000 dc.b %01100000 mask_3: dc.b %01100000 dc.b %11110000 dc.b %11110000 dc.b %01100000 bullet_sprite: dc.w 2 dc.w 1 dc.b %11111000 dc.b %11111000 mask_4: dc.b %11111000 dc.b %11111000 ;*********************************VARIABLE AND STUFF str ds.b 16 strend keystat ds.b 7 keyscan dc.w 0,0,0,0,0 ballx dc.w 0 bally dc.w 0 ballxdir dc.w 0 ballydir dc.w 0 p1y dc.w 0 p2y dc.w 0 p1score dc.w 0 p2score dc.w 0 escflag dc.w 0 delay_len dc.w 0 b1x dc.w 0 b1y dc.w 0 b2x dc.w 0 b2y dc.w 0 title dc.b "CraPong!",0 author dc.b "by blowh0le@aol.com",0 weburl dc.b "http://blowhole.cjb.net",0 speed_sel dc.b "Select Speed (F1-F5)",0 version dc.b "Version 2.1 1/6/99",0 win_message dc.b "You Won!",0 lose_message dc.b "You Lost",0 _comment dc.b "CraPong! v2.1 by Jeff Min",0 end