Sekiz Equ 08H Ellibin Equ 65536-50000 EksiBir Equ 00000000B-00000001B random Equ 7;Try to make head of snake with random Org 0H SJMP MAIN Org 03h IncreaseTimer:;Dont need max and min,think as a loop Inc R5 ;Double inc cuz #0FFH can be a problem Inc R5 ;if we use interrupts for timers Reti Org 13H DecreaseTimer: ;^^Same above^^ Dec R5 Dec R5 reti Org 30h Main: Mov R7,#78H;End of snake Mov R6,#08H;Computing Value for direction on matrix(Odd/Even Lines for x) Mov R5,#0FEH;The Timer //Emulator is slow!! Mov R4,#00H;The Yem Mov R3,#01H;Mod of Direction --->=1 <---=-1 Mov R2,#2;Lenght of Snake Mov R1,0;Temp Container Mov R0,#79H; Head of Snake ;initialize Snake Mov Acc,R2 Mov @R0,Acc Mov B,r7 Dec Acc Mov R1,B Mov @R1,Acc ;^^End of initialize Snake^^ Start: acall settimer; acall RefreshYem acall DRIVER ACall movesnake acall Eat; Wait:JNB tf0,Wait SJMP Start ;Carry Back of Snake ClearSnake: Mov R1,#7FH Control:CJNE @R1,#0,CarrySnake Decrease: Dec R1 CJNE R1,#3FH,Control RET;EXIT IS HERE CarrySnake: Dec @R1 CJNE @R1,#1,DECREASE Mov B,r1 Mov r7,B SJMP Decrease ;^^End of Cary Back of Snake^^ ;Move ahead MoveSnake: Mov A,R0 Add A,R3 acall LINEADAPTER;A alıp a döndürüyor olması lazım Mov R0,A ;Burda yılanın sonunu silsek? Mov B,R7 Mov R1,B Mov @R1,#00H ;Test asamasında sorun olursa buraya bak acall checkcrash Mov A,R2 Inc A Mov @R0,A RET ;^^End of Move ahead^^ ;OverLine Adapter LineAdapter:;//Can be lesser code but more confusing One:CJNE R3,#01H,NotOne Mov B,#00001111B Anl B,A Mov R1,B CJNE R1,#00H,Sonra; Mov B,R6 ;Clr C; need clear c? Subb A,B sjmp endol Sonra: CJNE R1,#08H,endol Mov B,#8h ;Clr C; need clear c? Subb A,B sjmp endol NotOne:CJNE R3,#0FFH,NotMinusOne Mov B,#00001111B Anl B,A Mov R1,B CJNE R1,#0FH,Sonra2; Mov B,R6 Add A,B sjmp endol Sonra2: CJNE R1,#07H,endol Mov B,#0F8h Clr C;GRRRRRRRR Subb A,B sjmp endol NotMinusOne:CJNE R3,#08H,NotEight Mov B,#11110000B Anl B,A Mov R1,B CJNE R1,#80H,endol; Mov B,#40h Clr C;GRRRRRRRR Subb A,B sjmp endol NotEight:CJNE R3,#0F8H,NotMinusEight Mov B,#11110000B Anl B,A Mov R1,B CJNE R1,#30H,endol; Mov B,#0C0h Clr C;GRRRRRRRR Subb A,B sjmp endol NotMinusEight: ENDOL:RET;^^End of OverLine Adapter ;Metod to choose way Driver Driver: jb p2.0,NOTA CJNE R3,#0FFH,THISISA;do nothing SJMP endofdriver ThisisA: Mov R3,#01H NotA:jb p2.1,NOTB CJNE R3,#01H,ThisisB;do nothing SJMP endofdriver ThisisB: Mov R3,#0FFH NotB:jb p2.2,NOTC CJNE R3,#08H,ThisisC;do nothing SJMP endofdriver ThisisC: Mov R3,#0F8H NotC:jb p2.3,NOTD CJNE R3,#0F8H,ThisisD;do nothing SJMP endofdriver ThisisD: Mov R3,#08H NotD: EndofDriver: RET;^^End of Driver RefreshYem: Cjne R4,#00H,endofrefreshyem StartRefreshing: Mov A,tl0;taking fake random number setb A.6;Ajusting the number to be between 40 and 7F Clr A.7;Ajusting the number to be between 40 and 7F Mov R1,A Mov A,@R1 CJNE A,#00H,refreshyem Mov A,R1 Mov R4,A; Mov @R1,#0FFH; endofrefreshyem:Ret;^^End Of Refresh Yem Eat: Mov A,R4 Mov B,R0 Clr C Subb A,B jnz ENDOFEAT Mov R4,#00H;Burdaysak yemi yemişiz. acall REFRESHYEM Inc R2 RET Endofeat: acall clearsnake RET;^^End of Eat SetTimer: Jb P2.4,isF Inc R5 isF: Jb P2.5,starttimer Dec R5 StartTimer: Clr tf0 Mov Tmod,#01H Mov TL0,#000H Mov TH0,R5 Setb tr0 Ret;^^End oF SeTimer^^ CheckCrash: CJNE @R0,#00h,crashing sjmp endofcheckcrash Crashing: Mov A,R0 Mov B,R4 Clr c Subb A,B Jnz mainend EndofCheckCrash: Ret;^^End of Check Crash^^ MainEND: ;Say the game is over End