/*
ACTVCODE.h
Copyright (C) 2009 Paul C. Pratt
You can redistribute this file and/or modify it under the terms
of version 2 of the GNU General Public License as published by
the Free Software Foundation. You should have received a copy
of the license along with this file; see the file COPYING.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
license for more details.
*//*
ACTiVation CODE
*/LOCALFUNCuimrKeyFun0(uimrx,uimry,uimrm){uimrr=x+y;if((r>=m)||(r<x)){r-=m;}returnr;}LOCALFUNCuimrKeyFun1(uimrx,uimry,uimrm){uimrr=0;uimrt=x;uimrs=y;while(s>0){if(0!=(s&1)){r=KeyFun0(r,t,m);}t=KeyFun0(t,t,m);s>>=1;}returnr;}LOCALFUNCuimrKeyFun2(uimrx,uimry,uimrm){uimrr=1;uimrt=x;uimrs=y;while(s>0){if(0!=(s&1)){r=KeyFun1(r,t,m);}t=KeyFun1(t,t,m);s>>=1;}returnr;}LOCALFUNCblnrCheckActvCode(ui3pp,blnr*Trial){blnrIsOk=falseblnr;uimrv0=do_get_mem_long(p);uimrv1=do_get_mem_long(p+4);if(v0>KeyCon2){/* v0 too big */}elseif(v1>KeyCon4){/* v1 too big */}else{uimrt0=KeyFun0(v0,KeyCon0,KeyCon2);uimrt1=KeyFun2(KeyCon1,t0,KeyCon2);uimrt2=KeyFun2(v1,KeyCon3,KeyCon4);uimrt3=KeyFun0(t2,KeyCon4-t1,KeyCon4);uimrt4=KeyFun0(t3,KeyCon4-KeyCon5,KeyCon4);if((0==(t4>>8))&&(t4>=KeyCon6)){*Trial=falseblnr;IsOk=trueblnr;}elseif(0==t4){*Trial=trueblnr;IsOk=trueblnr;}}returnIsOk;}/* user interface */LOCALFUNCblnrKey2Digit(intkey,ui3r*r){ui3rv;switch(key){caseMKC_0:caseMKC_KP0:v=0;break;caseMKC_1:caseMKC_KP1:v=1;break;caseMKC_2:caseMKC_KP2:v=2;break;caseMKC_3:caseMKC_KP3:v=3;break;caseMKC_4:caseMKC_KP4:v=4;break;caseMKC_5:caseMKC_KP5:v=5;break;caseMKC_6:caseMKC_KP6:v=6;break;caseMKC_7:caseMKC_KP7:v=7;break;caseMKC_8:caseMKC_KP8:v=8;break;caseMKC_9:caseMKC_KP9:v=9;break;default:returnfalseblnr;break;}*r=v;returntrueblnr;}#define ActvCodeMaxLen 20LOCALVARui4rActvCodeLen=0;LOCALVARui3bActvCodeDigits[ActvCodeMaxLen];#define ActvCodeFileLen 8#if UseActvFileFORWARDFUNCtMacErrActvCodeFileSave(ui3pp);FORWARDFUNCtMacErrActvCodeFileLoad(ui3pp);#endifLOCALVARui3bCurActvCode[ActvCodeFileLen];LOCALPROCDoActvCodeModeKey(intkey){ui3rdigit;ui3rL;inti;blnrTrial;if(MKC_BackSpace==key){if(ActvCodeLen>0){--ActvCodeLen;NeedWholeScreenDraw=trueblnr;}}elseif(Key2Digit(key,&digit)){if(ActvCodeLen<(ActvCodeMaxLen-1)){ActvCodeDigits[ActvCodeLen]=digit;++ActvCodeLen;NeedWholeScreenDraw=trueblnr;L=ActvCodeDigits[0]+(1+9);if(ActvCodeLen==L){uimrv0=0;uimrv1=0;for(i=1;i<(ActvCodeDigits[0]+1);++i){v0=v0*10+ActvCodeDigits[i];}for(;i<ActvCodeLen;++i){v1=v1*10+ActvCodeDigits[i];}do_put_mem_long(&CurActvCode[0],v0);do_put_mem_long(&CurActvCode[4],v1);if(CheckActvCode(CurActvCode,&Trial)){SpecialModeClr(SpclModeActvCode);NeedWholeScreenDraw=trueblnr;#if UseActvFileif(Trial){MacMsg("Using temporary code.","Thank you for trying Mini vMac!",falseblnr);}else{if(mnvm_noErr!=ActvCodeFileSave(CurActvCode)){MacMsg("Oops","I could not save the activation code"" to disk.",falseblnr);}else{MacMsg("Activation succeeded.","Thank you!",falseblnr);}}#elseMacMsg("Thank you for trying Mini vMac!","sample variation : ^v",falseblnr);#