;SameGame v1.1 by Jimmy Mardell ;Ported to Fargo II by Skip Jordan include "flib.h" include "tios.h" xdef _main xdef _comment WriteStr MACRO move.w \3,-(a7) pea \4 move.w \2,-(a7) move.w \1,-(a7) jsr tios::DrawStrXY lea 10(a7),a7 ENDM WriteStrA MACRO move.w \3,-(a7) move.l \4,-(a7) move.w \2,-(a7) move.w \1,-(a7) jsr tios::DrawStrXY lea 10(a7),a7 ENDM WriteChar MACRO move.w #$00FF,-(a7) move.w #$0000,-(a7) move.w #$00FF,-(a7) move.w \3,-(a7) move.w \2,-(a7) move.w \1,-(a7) move.w \4,-(a7) jsr tios::DrawCharXY lea 14(a7),a7 ENDM _main: bsr Init MainMenu: jsr flib::clr_scr move.w #2,-(a7) jsr tios::FontSetSys addq #2,a7 WriteStr #72,#10,#4,_comment move.w #1,-(a7) jsr tios::FontSetSys addq #2,a7 WriteStr #24,#30,#4,author WriteStr #18,#40,#4,porter WriteStr #70,#50,#4,porteremail WriteStr #87,#70,#4,pmodetxt WriteStr #87,#80,#4,amodetxt WriteStr #66,#100,#4,hitxt ChooseMode: lea LCD_MEM+71*30+10,a0 lea ball(PC),a1 add.w mode,a1 bsr PutSpr lea 150(a0),a0 lea ball+5(PC),a1 sub.w mode,a1 bsr PutSpr lea hiscore(PC),a2 tst.w mode beq PuzzleHi addq #6,a2 PuzzleHi: move.w (a2),d0 lea tmpstr+5(PC),a0 moveq #5,d1 bsr ConvStr subq #1,d1 bcs ShowHiscore FillOut: move.b #32,-(a0) dbra d1,FillOut ShowHiscore: WriteStrA #120,#100,#4,a0 addq #2,a2 WriteStrA #156,#100,#4,a2 CM_WaitKey: jsr flib::idle_loop cmp.w #264,d0 beq Done cmp.w #13,d0 beq StartGame cmp.w #338,d0 beq ChgMode cmp.w #344,d0 bne CM_WaitKey ChgMode: eori.w #5,mode bra ChooseMode StartGame: jsr flib::clr_scr clr.w -(a7) jsr tios::FontSetSys WriteStr #5,#123,#4,_comment(PC) lea pmodetxt(PC),a0 tst.w mode beq ShowMode add.w #12,a0 ShowMode: WriteStrA #70,#123,#4,a0 WriteStr #130,#123,#4,scoretxt(PC) addq #2,a7 bsr Randomize move.w #9,x move.w #4,y clr.w score st intflag clr.w delaycnt move.w #200,fdelay move.w fdelay,timer move.w #-1,uscore Main: bsr ShowField tst.w mode bne NoGameOverCheck bsr CheckGameOver bne GameOver NoGameOverCheck: move.w #1000,clrtimer Update: bsr Cursor WaitKey: tst.w mode beq NoBlockFill tst.w timer beq FillBlock NoBlockFill: bsr GetKeyStat move.b keystat,d0 and.b #$F0,d0 cmp.b #$F0,d0 beq NoAKey tst.w keytimer bne WaitKey bsr Cursor move.w #60,keytimer sub.w #30,timer bcc NoCarry clr.w timer NoCarry: btst #4,d0 bne CUp subq.w #1,x bcc CUp move.w #19,x CUp: btst #5,d0 bne CRight subq.w #1,y bcc CRight move.w #9,y CRight: btst #6,d0 bne CDown addq.w #1,x cmp.w #20,x bne CDown clr.w x CDown: btst #7,d0 bne Update addq.w #1,y cmp.w #10,y bne Update clr.w y bra Update NoAKey: btst.b #7,keystat+6 beq Pause btst.b #6,keystat+8 beq GameOver btst.b #1,keystat+9 beq Clear btst.b #4,keystat+6 beq Clear btst.b #3,keystat+6 beq Undo clr.w keytimer clr.w clrtimer bra WaitKey Undo: tst.w mode bne WaitKey cmp.w #-1,uscore beq WaitKey move.w uscore,score move.w #-1,uscore move.l undoB(PC),a0 move.l field(PC),a1 move.w #49,d0 CopyUndo: move.l (a0)+,(a1)+ dbra d0,CopyUndo bra Main Pause: sf intflag lea LCD_MEM,a0 move.w #899,d0 ClearTiles: clr.l (a0)+ dbra d0,ClearTiles lea pausedialog(PC),a6 jsr flib::show_dialog PClearBuf: tst.w (tios::kb_vars+$1C) beq PKeyBufClr clr.w (tios::kb_vars+$1C) bra PClearBuf PKeyBufClr: jsr flib::idle_loop cmp.w #264,d0 beq PKeyBufClr clr.w -(a7) jsr tios::ST_busy addq #2,a7 st intflag bra Main Clear: tst.w clrtimer bne WaitKey move.l cf(PC),a0 moveq #49,d0 ClearCF: clr.l (a0)+ dbra d0,ClearCF move.w y(PC),d0 mulu #20,d0 add.w x(PC),d0 move.l cf(PC),a0 move.l field(PC),a1 move.b 0(a1,d0),d6 beq WaitKey st 0(a0,d0) clr.w d4 CheckConnections: moveq #19,d0 moveq #9,d1 move.w #199,d2 move.w d4,d5 CheckL: tst.b 0(a0,d2) beq CheckNext tst.w d0 beq CheckR cmp.b -1(a1,d2),d6 bne CheckR tst.b -1(a0,d2) bne CheckR st -1(a0,d2) addq #1,d4 CheckR: cmp.w #19,d0 beq CheckU cmp.b 1(a1,d2),d6 bne CheckU tst.b 1(a0,d2) bne CheckU st 1(a0,d2) addq #1,d4 CheckU: tst.w d1 beq CheckD cmp.b -20(a1,d2),d6 bne CheckD tst.b -20(a0,d2) bne CheckD st -20(a0,d2) addq #1,d4 CheckD: cmp.w #9,d1 beq CheckNext cmp.b 20(a1,d2),d6 bne CheckNext tst.b 20(a0,d2) bne CheckNext st 20(a0,d2) addq #1,d4 CheckNext: subq #1,d0 bcc CLoop move.w #19,d0 subq #1,d1 CLoop: dbra d2,CheckL cmp.w d4,d5 bne CheckConnections tst.w d4 beq WaitKey move.w score,uscore mulu d4,d4 add.w d4,score move.l undoB(PC),a4 move.l field(PC),a5 move.w #49,d0 CopyToUndo: move.l (a5)+,(a4)+ dbra d0,CopyToUndo clr.l d0 UpdateField: tst.b 0(a0,d0) beq UF_Next move.w d0,d1 FallDown: sub.w #20,d1 bcs TopReached move.b 0(a1,d1),20(a1,d1) bra FallDown TopReached: clr.b 20(a1,d1) UF_Next: addq #1,d0 cmp.w #200,d0 bne UpdateField moveq #19,d0 move.l a1,a0 adda.w #180,a0 CheckEmptyColumns: tst.b 0(a0,d0) bne CEC_Next moveq #9,d1 move.l a1,a2 add.w d0,a2 MoveRow: move.l a2,a3 moveq #19,d2 sub.w d0,d2 beq MRL_Done MoveRowLeft: move.b 1(a3),(a3)+ subq #1,d2 bne MoveRowLeft MRL_Done: clr.b (a3) add.w #20,a2 dbra d1,MoveRow CEC_Next: dbra d0,CheckEmptyColumns bra Main FillBlock: clr.l d0 moveq #9,d1 move.l field(PC),a0 add.w #180,a0 SearchEmpty: tst.b (a0) beq EmptyFound addq #1,a0 addq #1,d0 cmp.w #20,d0 bne SearchEmpty lea -40(a0),a0 clr.l d0 subq #1,d1 bcc SearchEmpty bra GameOver EmptyFound: lea LCD_MEM,a1 mulu #360,d1 add.w d1,a1 mulu #12,d0 move.w d0,d4 lsr.w #4,d0 lsl.w #1,d0 add.w d0,a1 and.w #$0F,d4 moveq #5,d0 jsr flib::random addq #1,d0 move.w d0,d2 move.b d0,(a0) bsr Cursor bsr PutBlock bsr Cursor move.w fdelay,timer addq.w #1,delaycnt cmp.w #4,delaycnt bne NoBlockFill clr.w delaycnt cmp.w #10,fdelay beq NoBlockFill subq.w #1,fdelay bra NoBlockFill CheckGameOver: move.l field(PC),a0 moveq #19,d0 moveq #9,d1 move.w #199,d2 CGO_Left: move.b 0(a0,d2),d3 beq CGO_Next tst.w d0 beq CGO_Right cmp.b -1(a0,d2),d3 beq NotGameOver CGO_Right: cmp.w #19,d0 beq CGO_Up cmp.b 1(a0,d2),d3 beq NotGameOver CGO_Up: tst.w d1 beq CGO_Down cmp.b -20(a0,d2),d3 beq NotGameOver CGO_Down: cmp.w #9,d1 beq CGO_Next cmp.b 20(a0,d2),d3 beq NotGameOver CGO_Next: subq #1,d0 bcc CGO_Loop move.w #19,d0 subq #1,d1 CGO_Loop: dbra d2,CGO_Left NotGameOver: rts Cursor: movem.l d0-d3/a0-a1,-(a7) lea LCD_MEM,a0 move.w x(PC),d0 move.w y(PC),d1 mulu #360,d1 add.w d1,a0 mulu #12,d0 move.w d0,d1 lsr.w #4,d0 lsl.w #1,d0 add.w d0,a0 and.w #$0F,d1 move.l #$FFF00000,d2 lsr.l d1,d2 moveq #11,d3 InvertLine: eor.l d2,(a0) lea 30(a0),a0 dbra d3,InvertLine movem.l (a7)+,d0-d3/a0-a1 rts ShowField: move.l field(PC),a0 lea LCD_MEM,a1 moveq #9,d0 SFRow: moveq #4,d1 SFCol: clr.l d4 bsr PutTile moveq #12,d4 bsr PutTile addq #2,a1 moveq #8,d4 bsr PutTile moveq #20,d4 bsr PutTile addq #4,a1 dbra d1,SFCol add.w #330,a1 dbra d0,SFRow lea tmpstr+5(PC),a0 move.w score,d0 moveq #5,d1 bsr ConvStr lsl.w #2,d1 add.w #156,d1 WriteStrA d1,#123,#4,a0 rts PutTile: clr.l d2 move.b (a0)+,d2 PutBlock: move.l a1,a3 lea sprites(PC),a2 mulu #24,d2 adda.w d2,a2 move.l #$000FFFFF,d3 ror.l d4,d3 moveq #11,d5 PTLine: clr.l d6 move.w (a2)+,d6 swap d6 lsr.l d4,d6 and.l d3,(a3) or.l d6,(a3) lea 30(a3),a3 dbra d5,PTLine rts PutSpr: moveq #4,d0 PS_Rep: move.b (a1)+,(a0) lea 30(a0),a0 dbra d0,PS_Rep rts GameOver: sf intflag lea gameoverdialog(PC),a6 jsr flib::show_dialog ClearBuf: tst.w (tios::kb_vars+$1C) beq KeyBufEmpty clr.w (tios::kb_vars+$1C) bra ClearBuf KeyBufEmpty: jsr flib::idle_loop lea hiscore(PC),a3 tst.w mode beq CompareHiscore addq #6,a3 CompareHiscore: move.w (a3),d0 cmp.w score,d0 bcc MainMenu move.w score,(a3)+ move.l #$41414100,(a3) lea hiscoredialog(PC),a6 jsr flib::show_dialog move.w #1,-(a7) jsr tios::FontSetSys addq #2,a7 WriteStr #61,#70,#4,entintxt(PC) clr.l d7 EnterInitials: move.l a3,a0 move.w #157,d3 WriteStrA d3,#70,#4,a0 move.w d7,d6 mulu #6,d6 add.w d6,d3 clr.l d0 move.b 0(a3,d7),d0 WriteChar d3,#70,#0,d0 EI_WaitKey: jsr flib::idle_loop cmp.w #13,d0 beq CurRight cmp.w #264,d0 beq MainMenu cmp.w #337,d0 beq CurLeft cmp.w #338,d0 beq LetUp cmp.w #340,d0 beq CurRight cmp.w #344,d0 bne EI_WaitKey move.b 0(a3,d7),d0 subq #1,d0 cmp.b #64,d0 bne StoreLetter move.b #90,d0 StoreLetter: move.b d0,0(a3,d7) bra EnterInitials LetUp: move.b 0(a3,d7),d0 addq #1,d0 cmp.b #91,d0 bne StoreLetter move.b #65,d0 bra StoreLetter CurLeft: tst.w d7 beq EI_WaitKey subq #1,d7 bra EnterInitials CurRight: cmp.w #2,d7 bne MoveCurRight cmp.w #13,d0 bne EI_WaitKey bra MainMenu MoveCurRight: addq #1,d7 bra EnterInitials ConvStr: movem.l d0/d2,-(a7) clr.b (a0) RepConv: 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 RepConv CS_Done: movem.l (a7)+,d0/d2 rts Init: move.l #200,-(a7) jsr tios::HeapAlloc move.w d0,fieldH tios::DEREF d0,a0 move.l a0,field jsr tios::HeapAlloc move.w d0,cfH tios::DEREF d0,a0 move.l a0,cf jsr tios::HeapAlloc move.w d0,undoH tios::DEREF d0,a0 move.l a0,undoB addq #4,a7 clr.w mode sf intflag move.w #$700,d0 trap #1 bclr.b #2,$600001 ;disable mem protection :> move.w d0,-(a7) move.l $64,oldint1 move.l #IntHandler,$64 bset.b #2,$600001 ;re-enable mem protection :< move.w (a7),d0 lea 2(a7),a7 trap #1 ;move.w #$2700,sr ;move.l ($020064),oldint1 ;move.l #IntHandler,($020064) ;move.w #$2000,sr rts Randomize: move.l field(PC),a0 move.w #199,d1 tst.w mode beq RandomSymbol moveq #24,d2 ClrHalf: clr.l (a0)+ dbra d2,ClrHalf moveq #99,d1 RandomSymbol: moveq #5,d0 jsr flib::random addq #1,d0 move.b d0,(a0)+ dbra d1,RandomSymbol rts Done: ;move.w #$2700,sr move.w #$700,d0 trap #1 bclr.b #2,$600001 move.l oldint1,$64 bset.b #2,$600001 trap #1 ;move.l oldint1(PC),($020064) ;move.w #$2000,sr move.w fieldH(PC),-(a7) jsr tios::HeapFree move.w cfH(PC),-(a7) jsr tios::HeapFree move.w undoH(PC),-(a7) jsr tios::HeapFree addq #6,a7 rts IntHandler: tst.w timer beq DecKTimer subq.w #1,timer DecKTimer: tst.w keytimer beq DecCTimer subq.w #1,keytimer DecCTimer: tst.w clrtimer beq CheckFlag subq.w #1,clrtimer CheckFlag: tst.b intflag bne EndInt move.l oldint1(PC),-(a7) rts EndInt: rte GetKeyStat: movem.l d0-d1/a0,-(a7) lea keystat(PC),a0 move.w #$FFFE,d0 moveq #9,d1 GetKeys: move.w d0,$600018 nop nop nop nop nop nop nop nop move.b $60001B,(a0)+ rol.w #1,d0 dbra d1,GetKeys movem.l (a7)+,d0-d1/a0 rts fieldH dc.w 0 field dc.l 0 cfH dc.w 0 cf dc.l 0 undoH dc.w 0 undoB dc.l 0 x dc.w 0 y dc.w 0 score dc.w 0 uscore dc.w 0 mode dc.w 0 timer dc.w 0 fdelay dc.w 0 keytimer dc.w 0 clrtimer dc.w 0 delaycnt dc.w 0 oldint1 dc.l 0 hiscore dc.b 0,1,'YAR',0,0,2,'YAR',0 keystat ds.b 10 scoretxt dc.b "Score:",0 tmpstr ds.b 6 intflag dc.b 0 gotxt dc.b "GAME OVER",0 _comment dc.b "SameGame 1.1",0 author dc.b "by Jimmy Mârdell ",0 pmodetxt dc.b "Puzzle mode",0 amodetxt dc.b "Action mode",0 hitxt dc.b "Hiscore:",0 newhitxt dc.b "A NEW HISCORE!",0 entintxt dc.b "Enter initials:",0 pausetxt dc.b "PAUSE",0 even pausedialog dc.l $00400029,$00AF0051,$0023000F,pausetxt,0 gameoverdialog dc.l $00400029,$00AF0051,$0013000F,gotxt,0 hiscoredialog dc.l $00270020,$00C8005A,$0019000F,newhitxt,0 sprites ds.w 12 dc.w %0000000000000000 dc.w %0001111100000000 dc.w %0011111110000000 dc.w %0111110011000000 dc.w %1111111001100000 dc.w %1111111101100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %0111111111000000 dc.w %0011111110000000 dc.w %0001111100000000 dc.w %0000000000000000 dc.w %0000010000000000 dc.w %0000111000000000 dc.w %0001111100000000 dc.w %0011101110000000 dc.w %0111110111000000 dc.w %1111111111100000 dc.w %0111111111000000 dc.w %0011111110000000 dc.w %0001111100000000 dc.w %0000111000000000 dc.w %0000010000000000 dc.w %0000000000000000 dc.w %1111111111100000 dc.w %1111110000100000 dc.w %1111111110100000 dc.w %1111111110100000 dc.w %1111111110100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %0000000000000000 dc.w %0000010000000000 dc.w %0000111000000000 dc.w %0000111000000000 dc.w %0001101100000000 dc.w %0001110100000000 dc.w %0011110110000000 dc.w %0011111010000000 dc.w %0111111111000000 dc.w %0111111111000000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %0000000000000000 dc.w %0001111100000000 dc.w %0001111100000000 dc.w %0001111100000000 dc.w %1111100011100000 dc.w %1111111011100000 dc.w %1111111011100000 dc.w %1111111111100000 dc.w %1111111111100000 dc.w %0001111100000000 dc.w %0001111100000000 dc.w %0001111100000000 ball: dc.b %00111000 dc.b %01011100 dc.b %01111100 dc.b %01111100 dc.b %00111000 dc.b 0,0,0,0,0 porter: dc.b "Ported to PlusShell by Rusty Wagner",0 porteremail: dc.b "",0 end