;Cosmo 1.2 ;(C) Tim Gerla, timg@climax.polaristel.net ;thanks to BubbaGump for the name! ;thanks to Jimmy Mardell (Yarin) for the great sprite routines and proggie. ;Those bad guys can be sped up if they are too slow... ;To do: ; Clean up the sloppy code! ; better looking sprites, they are kinda ugly :) ; the clrsprite routine is incredibly huge and bloated... I just copied it ;from the sprite routine and hacked it, it could be about half the size :) @program prog_code,prog_name include macros.h include cosmo.h prog_code: jsr graylib[on] ; Turn greyscale on move.l a6,greyplane ; A6 holds the address to the greyscale plane. It's top: bsr ClearScreen ; Clear the screen. You must make your own clear moveq #50,d6 bsr puttitle SetFont #1 WriteStr #80,#28,#1,ver WriteStr #60,#48,#1,menu1 WriteStr #60,#58,#1,menu2 WriteStr #60,#68,#1,menu3 WriteStr #60,#78,#1,menu4 WriteStr #60,#88,#1,esc bsr bottomline menu: jsr flib[idle_loop] cmp.w #264,d0 beq exit cmp.w #268,d0 beq go cmp.w #269,d0 beq help cmp.w #270,d0 beq about cmp.w #271,d0 beq changefk bra menu go: bsr pickship bsr ClearScreen moveq #50,d6 DrawBox #185,#0,#186,#127 SetFont #1 WriteStr #190,#5,#1,scorename bsr updatescore main_loop: move.w gamelen,d0 move.w enemies,d1 cmp d0,d1 bgt endgame move d6,d0 ; Setting the X coordinate of the sprite moveq #110,d1 ; Setting the Y coordinate of the sprite move cur_ship,d2 ; We want to put the first sprite lea ships(PC),a0 bsr PutSprite ; Put the sprite! cmp.w #1,is_gun bne no_gun bsr gun no_gun: bsr enemy test_key: tst.w ($75B0) beq skip_start clr.w ($75B0) move.w ($75B2),d0 cmp.w #$108,d0 beq top cmp.w #1,is_gun beq skip_start cmp.w shoot_key,d0 bne skip_start bsr start_gun skip_start: cmp.w #1,is_en beq test_arrow bsr start_en test_arrow: move.w ($75A0),d0 move.w d0,d1 and.w #$FFF0,d1 cmp.w #$0050,d1 bne waitvbl testleft: btst #2,d0 bne testright sub.w #1,d6 bcc testright clr.w d6 testright: btst #0,d0 bne waitvbl add.w #1,d6 cmp.w #164,d6 bcs waitvbl move.w #164,d6 waitvbl: move #1000,d5 wait: dbra d5,wait bra main_loop ;================== exit: clr.w is_gun clr.w is_en clr.w en_x clr.w en_y clr.w gun_x clr.w gun_y clr.w score clr.w enemies jsr graylib[off] ; Turn off greyscale rts ; And return to Fargo (or the Home screen) ;================= gun: movem.l d0-d7/a0-a6,-(a7) cmp #10,gun_y bgt yok ;gun done clr.w is_gun move gun_x,d0 ; Setting the X coordinate of the sprite move gun_y,d1 ; Setting the Y coordinate of the sprite bsr ClrSprite ; Put the sprite! movem.l (a7)+,d0-d7/a0-a6 rts yok: MOVE.w gun_x,D6 MOVE.w gun_y,D5 MOVE.w en_x,D4 MOVE.w en_y,D3 ; ; Line 4: if( gun_x > en_x && gun_x+16 < en_x+8 && gun_y > en_y && gun_y+16 < en_y+8) killguy(); ; MOVE.L D4,D0 SUB.L #$0B,D0 CMP.L D0,D6 BLE L_0 MOVE.L D4,D0 ADDI.L #$8,D0 CMP.L D0,D6 BGE L_0 CMP.L D3,D5 BLE L_0 MOVE.L D3,D0 ADDI.L #$4,D0 CMP.L D0,D5 BGE L_0 MOVE.L A7,A0 collision: add.w #1,score bsr updatescore move gun_x,d0 ; Setting the X coordinate of the sprite move gun_y,d1 ; Setting the Y coordinate of the sprite bsr ClrSprite ; Put the sprite! move en_x,d0 ; Setting the X coordinate of the sprite move en_y,d1 ; Setting the Y coordinate of the sprite bsr ClrSprite ; Put the sprite! clr.w is_gun clr.w is_en clr.w en_x clr.w en_y clr.w gun_x clr.w gun_y movem.l (a7)+,d0-d7/a0-a6 rts L_0: sub #1,gun_y move gun_x,d0 ; Setting the X coordinate of the sprite move gun_y,d1 ; Setting the Y coordinate of the sprite moveq #1,d2 ; We want to put the first sprite lea sprites(PC),a0 bsr PutSprite ; Put the sprite! movem.l (a7)+,d0-d7/a0-a6 rts ;================== start_gun: movem.l d0-d7/a0-a6,-(a7) move.w d6,gun_x move.w #110,gun_y move.w #1,is_gun movem.l (a7)+,d0-d7/a0-a6 rts ;=================================================== enemy: movem.l d0-d7/a0-a6,-(a7) cmp.w #3,en_wait bge goen add.w #1,en_wait movem.l (a7)+,d0-d7/a0-a6 rts goen: clr.w en_wait cmp #111,en_y blt yoke ;en done clr.w is_en move en_x,d0 ; Setting the X coordinate of the sprite move en_y,d1 ; Setting the Y coordinate of the sprite bsr ClrSprite ; Put the sprite! movem.l (a7)+,d0-d7/a0-a6 rts yoke: add #1,en_y move en_x,d0 ; Setting the X coordinate of the sprite move en_y,d1 ; Setting the Y coordinate of the sprite move cur_eship,d2 ; We want to put the first sprite lea enemys(PC),a0 bsr PutSprite ; Put the sprite! movem.l (a7)+,d0-d7/a0-a6 rts ;================== start_en: movem.l d0-d7/a0-a6,-(a7) add.w #1,enemies move.w #164,d0 jsr flib[random] move.w d0,en_x move.w #0,en_y move.w #1,is_en move.w #4,d0 jsr flib[random] move d0,cur_eship move #0,d0 ; Setting the X coordinate of the sprite move #1,d1 ; Setting the Y coordinate of the sprite bsr ClrSprite ; Put the sprite! movem.l (a7)+,d0-d7/a0-a6 rts ;-------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;; lea sprites(PC),a0 PutSprite: ; Puts sprite D2 at D0,D1 movem.l d0-d3/a0-a2,-(a7) lsl.l #6,d2 adda.l d2,a0 lsl.w #1,d1 move.l d1,d2 lsl.w #4,d2 sub.w d1,d2 move.b d0,d1 and.w #$FFF0,d0 lsr.b #3,d0 add.w d0,d2 and.b #$0F,d1 sub.b #16,d1 neg d1 moveq #15,d0 lea $4440,a1 move.l greyplane,a2 adda.l d2,a1 adda.l d2,a2 move.l #$FFFF0000,d3 rol.l d1,d3 PS_PutRow: clr.l d2 move.w (a0)+,d2 lsl.l d1,d2 and.l d3,(a1) or.l d2,(a1) clr.l d2 move.w (a0)+,d2 lsl.l d1,d2 and.l d3,(a2) or.l d2,(a2) lea 30(a1),a1 lea 30(a2),a2 dbra d0,PS_PutRow movem.l (a7)+,d0-d3/a0-a2 rts lea sprites(PC),a0 ClearScreen: ; Clears both bitplanes, doesn't change any registers movem.l d0/a0-a1,-(a7) ; Push all registers used move.l #959,d0 ; The screen is $F00 bytes = 960 longwords. move.l greyplane,a0 ; Make A0 point at the greyscale plane (plane 1) move.l #$4440,a1 ; and A1 to the LCD memory (plane 0) RepClr: clr.l (a0)+ ; Clear a longword, increase A0 with 4 clr.l (a1)+ ; Clear a longword, increase A1 with 4 dbra d0,RepClr ; Repeat movem.l (a7)+,d0/a0-a1 ; Pop the registers rts ;------------------------------------------- ClrSprite: ; clrs a 16x16 square movem.l d0-d3/a0-a2,-(a7) lsl.l #6,d2 lsl.w #1,d1 move.l d1,d2 lsl.w #4,d2 sub.w d1,d2 move.b d0,d1 and.w #$FFF0,d0 lsr.b #3,d0 add.w d0,d2 and.b #$0F,d1 sub.b #16,d1 neg d1 moveq #15,d0 lea $4440,a1 move.l greyplane,a2 adda.l d2,a1 adda.l d2,a2 move.l #$FFFF0000,d3 rol.l d1,d3 PS_PutRow1: clr.l d2 move.w #0,d2 lsl.l d1,d2 and.l d3,(a1) or.l d2,(a1) clr.l d2 move.w #0,d2 lsl.l d1,d2 and.l d3,(a2) or.l d2,(a2) lea 30(a1),a1 lea 30(a2),a2 dbra d0,PS_PutRow1 movem.l (a7)+,d0-d3/a0-a2 rts ;------------------------------------------------- pause: wait2: dbra d5,wait bra main_loop ;---------------------------------------------- puttitle: movem.l d0-d2/a0-a6,-(a7) ; Push all registers used lea sprites(pc),a0 move #64,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #80,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #7,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #96,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #8,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #112,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #9,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #128,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #10,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #144,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #11,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #160,d0 ; Setting the X coordinate of the sprite moveq #10,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! movem.l (a7)+,d0-d2/a0-a6 ; Pop the registers rts ;===================================================== about: bsr ClearScreen bsr bottomline lea sprites(pc),a0 move #0,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #224,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! SetFont #2 WriteStr #75,#3,#1,abut1 WriteStr #35,#30,#1,abut3 SetFont #1 WriteStr #50,#20,#1,abut2 WriteStr #40,#60,#1,abut4 WriteStr #40,#70,#1,abut5 WriteStr #40,#80,#1,abut6 WriteStr #40,#90,#1,abut7 SetFont #0 WriteStr #40,#100,#1,exitkey jsr flib[idle_loop] bra top ;===================================================== help: bsr ClearScreen bsr bottomline lea sprites(pc),a0 moveq #0,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #224,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! SetFont #2 WriteStr #65,#3,#1,help1 SetFont #1 WriteStr #40,#20,#1,help2 WriteStr #40,#30,#1,help3 WriteStr #40,#40,#1,help4 SetFont #0 WriteStr #40,#50,#1,exitkey jsr flib[idle_loop] bra top ;===================================================== changefk: bsr ClearScreen bsr bottomline lea sprites(pc),a0 move #0,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #224,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! SetFont #2 WriteStr #60,#3,#1,ck1 SetFont #1 WriteStr #45,#20,#1,ck2 WriteStr #45,#30,#1,ck3 get: jsr flib[idle_loop] cmp.w #264,d0 beq get cmp.w #340,d0 beq get cmp.w #337,d0 beq get move.w d0,shoot_key bra top ;======================================================= endgame: sub.w #1,enemies clr.w ($75B0) bsr ClearScreen bsr bottomline lea sprites(pc),a0 move #0,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! move #224,d0 ; Setting the X coordinate of the sprite moveq #0,d1 ; Setting the Y coordinate of the sprite moveq #2,d2 ; We want to put the first sprite bsr PutSprite ; Put the sprite! SetFont #2 WriteStr #60,#3,#1,end1 SetFont #1 WriteStr #30,#40,#0,endkey WriteStr #30,#20,#1,end2 move.w enemies,-(a7) ; push argument 1 move.w score,-(a7) ; push argument 1 pea endfmt(PC) ; format string pea endtemp(PC) ; output buffer jsr romlib[sprintf] lea 12(a7),a7 move.w #0001,-(a7) ; color pea endtemp(PC) ; Variable of string to print move.w #30,-(a7) ; y move.w #30,-(a7) ; x jsr romlib[puttext] ; ROM call to puttext lea 10(a7),a7 ; restore the stack pointer escque: jsr flib[idle_loop] cmp.w #264,d0 bne escque bra exit ;===================================================== updatescore: move.w #31,-(a7) move.w #206,-(a7) move.w #15,-(a7) move.w #190,-(a7) jsr flib[erase_rect] lea 8(a7),a7 SetFont #1 move.w score,-(a7) ; push argument 1 pea scrfmt(PC) ; format string pea scrtemp(PC) ; output buffer jsr romlib[sprintf] lea 10(a7),a7 move.w #0001,-(a7) ; color pea scrtemp(PC) ; Variable of string to print move.w #15,-(a7) ; y move.w #190,-(a7) ; x jsr romlib[puttext] ; ROM call to puttext lea 10(a7),a7 ; restore the stack pointer rts ;===================================================== pickship: bsr ClearScreen lea sprites(pc),a0 move #0,d0 moveq #0,d1 moveq #2,d2 bsr PutSprite move #224,d0 moveq #0,d1 moveq #2,d2 bsr PutSprite SetFont #2 WriteStr #15,#3,#1,pick1 SetFont #1 WriteStr #14,#30,#1,pick2 SetFont #1 WriteStr #14,#70,#1,pick3 DrawBox #12,#28,#216,#62 DrawBox #12,#68,#216,#102 pickloop: lea ships(pc),a0 move #96,d0 moveq #45,d1 move cur_ship,d2 bsr PutSprite move.w #100,-(a7) move.w #140,-(a7) move.w #80,-(a7) move.w #110,-(a7) jsr flib[erase_rect] lea 8(a7),a7 ClearBox #94,#80,#140,#100 SetFont #1 move.w gamelen,-(a7) ; push argument 1 pea glenfmt(PC) ; format string pea glentemp(PC) ; output buffer jsr romlib[sprintf] lea 10(a7),a7 move.w #0001,-(a7) ; color pea glentemp(PC) ; Variable of string to print move.w #90,-(a7) ; y move.w #97,-(a7) ; x jsr romlib[puttext] ; ROM call to puttext lea 10(a7),a7 ; restore the stack pointer jsr flib[idle_loop] cmp.w #340,d0 beq add cmp.w #337,d0 beq sub cmp.w #338,d0 beq addt cmp.w #344,d0 beq subt cmp.w #13,d0 beq pd bra pickloop pd: rts add: cmp.w #3,cur_ship beq down add.w #1,cur_ship bra pickloop down: move.w #0,cur_ship bra pickloop sub: cmp.w #0,cur_ship beq up sub.w #1,cur_ship bra pickloop up: move.w #3,cur_ship bra pickloop addt: cmp.w #1000,gamelen beq downt add.w #5,gamelen bra pickloop downt: move.w #0,gamelen bra pickloop subt: cmp.w #0,gamelen beq upt sub.w #5,gamelen bra pickloop upt: move.w #1000,gamelen bra pickloop rts ;===================================================== bottomline: SetFont #0 WriteStr #0,#122,#1,copyright rts ;===================================================== sprites INCBIN cosmo.bin enemys INCBIN enemy.bin ships INCBIN ships.bin greyplane dc.l 0 is_gun dc.w 0 gun_x dc.w 0 gun_y dc.w 0 is_en dc.w 0 en_x dc.w 0 en_y dc.w 0 en_wait dc.w 0 score dc.w 0 cur_ship dc.w 0 cur_eship dc.w 1 enemies dc.w 0 gamelen dc.w 20 shoot_key dc.w 32 prog_name dc.b "Cosmo 1.2",0 scorename dc.b "Score:",0 ver dc.b "Version 1.2",0 copyright dc.b "COSMO Copyright (c) 1996 Tim Gerla",0 help1 dc.b "HELP FOR COSMO",0 help2 dc.b "Arrows - Move Ship",0 help3 dc.b "Space - Fire Guns (default)",0 help4 dc.b "Escape - Exit the Game",0 ;exit key abut1 dc.b "ABOUT COSMO",0 abut2 dc.b "Programming and art by:",0 abut3 dc.b "Tim Gerla aka. Tyball",0 abut4 dc.b "Thanks to:",0 abut5 dc.b "Jimmy Mardell - Sprmaker",0 abut6 dc.b "Rick Schilg - Game Title",0 abut7 dc.b "David Ellsworth - Fargo",0 ck1 dc.b "CHANGE FIRE KEY",0 ck2 dc.b "Press the key for FIRE,",0 ck3 dc.b 17,", ",18," and ESC not valid.",0 exitkey dc.b "(press any key to exit...)",0 scrfmt dc.b "%d",0 scrtemp dc.b " ",0 glenfmt dc.b "%d",0 glentemp dc.b " ",0 endfmt dc.b "You shot %d out of %d ships.",0 endtemp dc.b " ",0 end1 dc.b "Congratulations!",0 end2 dc.b "You finished the game!",0 endkey dc.b "(press ESC to exit...)",0 menu1 dc.b "[F1] - Start Game",0 menu2 dc.b "[F2] - Help",0 menu3 dc.b "[F3] - About",0 menu4 dc.b "[F4] - Change fire key",0 esc dc.b "[ESC]- Quit",0 pick1 dc.b "Please choose game options",0 pick2 dc.b 17," and ",18," change the ship.",0 pick3 dc.b 19," and ",20," change the game length.",0 ;===================================================== reloc_open add_library flib add_library graylib add_library romlib reloc_close end