#no_data Copyright Nick Fisk 2010 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . 'Changelog 'v0.99 - Finished implementing score downloads 'v1.00 - All features as planned have been implemented 'v1.01 - Fixed a bug where being reset after death didn't update the mode variable and the gun still thought you were dead ' - Fixed a bug where a shotgun could never enter the receiving code loop if one of the reload buttons where held 'v1.02 - Scores now send in blocks of 4 to allow up to 16 players to upload scores (hit limit of variables on 08m in scorebox) 'v1.03 - Added support to communicate to CTF base. Supports recharging and exchanging flags ' - modified batt level code ' - added dead display mode ' - need to charge to 50 health before respawn ' - can only get hit when dead 'v1.04 -Fixed bug where player can't die ' -don't alllow flag carryers to respawn ' -need to charge to 50 health before respawn 'v1.05 -Changed flag variables to use bits of b1 instead of using masks ' -Showed player that killed you when you die ' -Mode Button now shows alternate screen, press trigger to change firing modes whilst in this mode ' -Battery is shown in alternate mode 'v1.06 -Added game modes ' -Changed GameID to Header which is static ' -Added Zombie Mode ' -Shots and gamemode are shown in alternate mode 'v1.07 ' -Fixed a problem where output power was setting wrong pin ' -Minigun defaults to fully automatic 'v1.08 ' -Added support for Browning M2 'v1.09 ' -Changed recharge health to +20 and respawn limit to 50 'v1.10 ' -Fixed big bug where in zombie mode the virtual bullet was not recalculated when changing teams SYMBOL RS = 2 ; 0 = Command 1 = Data SYMBOL E = 3 ; 0 = Idle 1 = Active SYMBOL DB4 = 4 ; LCD Data Line 4 SYMBOL DB5 = 5 ; LCD Data Line 5 SYMBOL DB6 = 6 ; LCD Data Line 6 SYMBOL DB7 = 7 ; LCD Data Line 7 SYMBOL RSCMDmask = %00000000 ; Select Command register SYMBOL RSDATmask = %00000100 ; Select Data register SYMBOL DirtyAmmoDisplay = bit0 ' Ready to Fire SYMBOL FullAuto = bit1 SYMBOL BurstMode = bit2 SYMBOL TriggerReset =bit3 SYMBOL ShotGunReload1 =bit4 SYMBOL ShotGunReload2 =bit5 SYMBOL carryflag = bit6 'Do not use b0 SYMBOL roundtimer = b2 SYMBOL bullets = b3 SYMBOL Health = b4 SYMBOL PlayerID = b5 SYMBOL TeamID = b6 SYMBOL OutputPower = b7 SYMBOL ShotsCounter = w4 'b8-b9 SYMBOL GunType = b10 SYMBOL counter = b11 SYMBOL sendbyte = b12 SYMBOL rsbit = b13 SYMBOL shotmode = b14 SYMBOL clips = b15 SYMBOL BurstCounter =b16 SYMBOL shotbyte = b17 SYMBOL recievebyte = b18 SYMBOL mode = b22 SYMBOL sensorcounter = b23 SYMBOL GameMode =b24 '0=Normal 1=CTF 2=Zombie SYMBOL Header = 170 'tune 0, 6,($03,$6A,$C3,$6C,$68,$2A,$23,$6C,$67,$6A,$43,$6A,$45,$C3,$6C,$41,$40,$6A,$68,$EA) 'Store Data in EEPROM ' Nibble commands - To initialise 4-bit mode on LCD EEPROM 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit EEPROM 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit 'Byte commands - To configure the LCD EEPROM 2,( $28 ) ; %00101000 %001LNF00 Display Format EEPROM 3,( $0C ) ; %00001100 %00001DCB Display On EEPROM 4,( $06 ) ; %00000110 %000001IS Cursor Move ; L : 0 = 4-bit Mode 1 = 8-bit Mode ; N : 0 = 1 Line 1 = 2 Lines ; F : 0 = 5x7 Pixels 1 = N/A ; D : 0 = Display Off 1 = Display On ; C : 0 = Cursor Off 1 = Cursor On ; B : 0 = Cursor Steady 1 = Cursor Flash ; I : 0 = Dec Cursor 1 = Inc Cursor ; S : 0 = Cursor Move 1 = Display Shift EEPROM 5,( $01 ) ; Clear Screen 'Strings stored in EEPROM EEPROM 6,("Welcome") ;Welcome string EEPROM 13,("T ID Hlth Rnds M") ;Main Status String EEPROM 29,("Plyr") EEPROM 33,("Cfg") EEPROM 36,("Gun") EEPROM 39,("BAT") EEPROM 42,("Team") EEPROM 46,("ID") EEPROM 48,("To Libre Tag") '59 EEPROM 60,("Reloading") '68 EEPROM 69,("V1.10") '73 EEPROM 74,("Check Sensor") '85 EEPROM 86,("Out Pwr") '92 EEPROM 93,("Dead") '97 EEPROM 98,("Shts") '101 EEPROM 102,("Mode") '105 'Game Defaults EEPROM 200,(1) ;PlayerID EEPROM 201,(1) ;TeamID EEPROM 202,(30) ;Ammo per clip EEPROM 203,(100) ;Health EEPROM 204,(100) ;Output Power % EEPROM 205,(1) ;Gun type 1=MGun 2=Gatling 3=Shotgun EEPROM 206,(5) ;clips EEPROM 207,(1) ;First Run EEPROM 210,(0) ;Game Mode - Normal 'Below is just for reference 'EEPROM 206 ;ammo ' 'EEPROM 208 ;health 'EEPROM 209 ;carryflag PowerOnReset: 'Initialise pins and hardware low portc 4 setfreq m8 BurstMode=1 'high 1 'Force full power mode for now 'pwmout 1 , 25, 53 'pwmout 1 , 19, 40 'let b0=85 hsersetup B2400_8,%11 GOSUB InitialiseLcd 'Display welcome string FOR counter = 6 TO 12 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=$8B GOSUB SendInitCmdByte FOR counter = 69 TO 73 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=$C0 GOSUB SendInitCmdByte pause 20 FOR counter = 48 TO 59 READ counter,sendbyte GOSUB SendDataByte NEXT 'Read Game variables out of EEPROM PlayerID=1 TeamID=1 Health=100 gosub configureGun read 207,b27 'Read first run state if b27=0 then 'If its NOT the first time we are ruuning since being flashed read 206,clips read 202,bullets read 203,Health read 201,TeamID read 200,PlayerID read 208,mode read 209,carryflag read 210,GameMode endif shotmode=shotmode | %11001 'Set shotgun to need reload write 207,0 'clips=5 high portc 2 sound 0,(5,60) low portc 2 high portc 3 sound 0,(50,60) high portc 2 sound 0,(85,60) low portc 2 low portc 3 pause 1000 IF portA pin2 = 1 then IF portA pin1 = 1 then sound 0,(120,10) mode=10 pause 1000 GOTO CalculateShotByte endif endif Gosub DisplayStatus GOTO CalculateShotByte 'END ConfigureGun: read 205,GunType 'Read gun type into temp Select Case GunType case 1 'Machine Gun poke 80,30 poke 81,10 poke 82,6 bullets=30 clips=10 case 2 'Mini Gun poke 80,200 poke 81,10 poke 82,1 bullets=200 clips=10 fullauto=1 burstmode=0 case 3 'Shotgun poke 80,2 poke 81,1 poke 82,1 bullets=2 clips=1 case 4 'Browning M2 poke 80,60 poke 81,20 poke 82,3 bullets=60 clips=20 fullauto=1 burstmode=0 EndSelect read 204,OutputPower Select Case OutputPower case 20 pwmout 1 , 41, 83 low 1 case 40 pwmout 1 , 43, 89 low 1 case 60 pwmout 1 , 46, 93 low 1 case 80 pwmout 1 , 49, 100 low 1 case 100 ' pwmout 1 , 25, 53 pwmout 1 , 52, 105 high 1 EndSelect Return 'LCD Routines InitialiseLcd: FOR counter = 0 TO 5 READ counter,sendbyte GOSUB SendInitCmdByte NEXT RETURN SendInitCmdByte: PAUSE 15 ; Delay 15mS SendCmdByte: 'rsbit = RSCMDmask ; Send to Command register rsbit = outpins rsbit = rsbit & %11 goto sendCmdOrDataByte SendDataByte: rsbit = outpins rsbit = rsbit & %11 | RSDATmask ; Send to Data register next SendCmdOrDataByte: pins = sendbyte & %11110000 | rsbit ; Put MSB out first PULSOUT E,1 ; Give a 10uS pulse on E pins = sendbyte * %00010000 | rsbit ; Put LSB out second PULSOUT E,1 RETURN ; Give a 10uS pulse on E CalculateShotBytesub: 'No point calculating it every shot, it never changes 'Shift the variables into a byte (PPPPTTxp) P=Player T=Team x=unused p=parity b25=playerid<<4 ;Move playerid 4 bits to the left b26=teamid<<2 ;Move teamid 2 bits to the left shotbyte=b25|b26 ;Add them together 'sertxd (#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0,cr,lf) 'b25=shotbyte 'shotbyte=0 'Calculate the Parity 'FOR b27=1 TO 7 ' shotbyte=shotbyte^b25 ' shotbyte=shotbyte<<1 'NEXT 'bit7=bit6^bit5^bit4^bit3^bit2^bit1^bit0 'shotbyte=b25|bit7 ;Add the parity to the byte Return CalculateShotByte: gosub CalculateShotBytesub: main: IF portA pin0 = 1 AND mode = 0 then ;Has trigger button been pressed 'b27=shotmode & %01 'b26=shotmode & %10 IF roundtimer=0 AND TriggerReset=0 then ;Has the delay between shots expired Shotgunreload1=1 ShotgunReload2=1 TriggerReset=1 IF bullets > 0 then ;Do we have any bullets ;Flash the muzzle 'sertxd (#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0,cr,lf) high portc 4 hserout 0,(Header,shotbyte,shotbyte) ;Send the byte ShotsCounter=ShotsCounter+1 peek 82,roundtimer ;Delay the next shot bullets=bullets-1 ;Decrement the number of bullets 'sound 0,(140,1,160,1) if guntype <> 3 then sound 0,(20,2,250,2) else sound 0,(240,15) endif low portc 4 if FullAuto=1 OR BurstMode=1 then TriggerReset=0 if BurstMode=1 then if burstcounter<2 then BurstCounter=burstcounter+1 else TriggerReset=1 BurstCounter=0 endif endif endif 'Update remaining ammo on the LCD if roundtimer<>0 then gosub displayammo else DirtyAmmoDisplay=1 endif else sound 0,(255,1) endif endif endif if carryflag=1 then if portA pin0 =0 and roundtimer=0 then roundtimer=10 endif if roundtimer <2 then if teamID=1 then high portc 3 else high portc 2 endif pause 250 low portc 2 low portc 3 endif endif if GameMode=2 and TeamID=2 then if BurstCounter=0 then high portc 3 pause 250 low portc 3 BurstCounter=20 endif BurstCounter=BurstCounter-1 endif if portA pin0=1 and mode=255 and roundtimer=0 then 'If you are dead send scores b27=Header-3 hserout 0,(b27) pause 50 hserout 0,(shotbyte,shotbyte,ShotsCounter,ShotsCounter) roundtimer=20 pause 200 b25=201 gosub sendscores pause 200 b25=205 gosub sendscores pause 200 b25=209 gosub sendscores pause 200 b25=213 gosub sendscores endif if portA pin0=0 then 'Detect trigger released 'b27=shotmode & %100 if DirtyAmmodisplay=1 then DirtyAmmodisplay=0 gosub displayammo endif TriggerReset=0 if GameMode<>2 and TeamID<>2 then BurstCounter=0 endif endif 'Countdown until next shot if roundtimer>0 then roundtimer=roundtimer-1 if roundtimer>=200 then if roundtimer=200 then roundtimer=0 GOSUB DisplayStatus endif if roundtimer>200 then b27=roundtimer-180%3 if b27=0 then sendbyte="#" GOSUB SendDataByte endif pause 120 if roundtimer=201 then sound 0,(120,20) pause 20 sound 0,(120,20) endif endif endif endif readadc10 3,w13 'debug if w13<50 then w13=670 endif if w13<612 then write 203,health write 202,bullets write 206,clips write 208,mode write 209,carryflag sendbyte=$C0 GOSUB SendCmdByte FOR counter = 39 TO 41 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte FOR counter = 86 TO 92 READ counter,sendbyte GOSUB SendDataByte NEXT b27=0 lowbatt: pause 100 'sertxd("A") b27=b27+1 if b27>20 then readadc10 3,w13 if w13>612 then gosub displaystatus goto checksensor endif endif goto lowbatt endif 'Anti cheat sensor check CheckSensor: if portc pin7 = 0 AND hserinflag = 0 AND sensorcounter < 100 then sensorcounter=sensorcounter+1 elseif sensorcounter > 0 then sensorcounter=sensorcounter-1 endif if sensorcounter = 100 then sertxd("Check Sensor") sendbyte=$01 GOSUB SendCmdByte sendbyte=$C0 GOSUB SendCmdByte FOR counter = 74 TO 85 READ counter,sendbyte GOSUB SendDataByte NEXT 'Pause 500 if portc pin7 =1 then GOSUB DisplayStatus sensorcounter=0 endif goto CheckSensor endif IF mode<50 AND mode>0 then GoSub Menu endif if guntype <> 3 then if portA pin2 =1 AND mode=0 then 'Show Alternate Screen SensorCounter=110 sendbyte=$01 GOSUB SendCmdByte pause 10 FOR counter = 98 TO 101 READ counter,sendbyte GOSUB SendDataByte NEXT bintoascii shotscounter,b25,b25,b25,b26,b27 sendbyte=":" GOSUB SendDataByte sendbyte=b25 GOSUB SendDataByte sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte sendbyte=" " GOSUB SendDataByte FOR counter = 102 TO 105 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=":" GOSUB SendDataByte bintoascii gamemode,b25,b26,b27 sendbyte=b25 GOSUB SendDataByte gosub battery pause 100 if portA pin0 =1 and GameMode <>2 then 'Toggle between single, full auto and burst if FullAuto=0 and BurstMode=0 then FullAuto=1 goto endchoice1 endif if Fullauto=1 and BurstMode=0 then FullAuto=0 BurstMode=1 goto endchoice1 endif if FullAuto=0 and BurstMode=1 then BurstMode=0 endif endchoice1: sound 0,(100,20) GOSUB displayammo2 pause 300 GOSUB CalculateShotBytesub endif endif IF portA pin1 =1 AND mode=0 AND clips>0 then 'Reload sound 0,(180,6) pause 200 sound 0,(250,6) pause 1000 sound 0,(250,20) peek 80,bullets roundtimer=250 sendbyte=$01 clips=clips-1 GOSUB SendCmdByte pause 10 FOR counter = 60 TO 68 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=$C0 GOSUB SendCmdByte pause 10 endif else 'b26=shotmode & %01000 'b27=shotmode & %10000 'debug if portA pin2 =1 AND mode=0 AND ShotgunReload1=1 then if portA pin1=0 then sound 0,(180,2) pause 50 sound 0,(250,2) ShotgunReload1=0 endif endif if portA pin1 =1 AND mode=0 AND ShotgunReload2=1 AND ShotgunReload1=0 then sound 0,(180,2) pause 50 sound 0,(250,2) ShotgunReload2=0 bullets=2 endif TriggerReset=0 GOSUB displayammo endif if mode=255 then high portc 2 pause 60 low portc 2 pause 60 high portc 3 pause 60 low portc 3 if roundtimer = 0 then gosub displaydead roundtimer=10 endif endif 'Receiving Code IF hserinflag = 1 then pause 10 hserinflag=0;Reset data waiting flag ptr=0 'Retrieve Bytes b26=0 DO if ptr=2 then if recievebyte <> @ptr then sound 0,(126,8,80,1) goto endrecieve endif endif recievebyte=@ptrinc 'sertxd(#recievebyte,",") if ptr=1 then if recievebyte<>Header then 'sertxd("Wrg3",cr,lf) goto endrecieve endif endif LOOP UNTIL ptr=3 b26=ptr ptr=0 @ptr=0 ptr=b26 'sertxd (#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0," ",#bit15,#bit14,#bit13,#bit12,#bit11,#bit10,#bit9,#bit8,cr,lf) 'sertxd(cr,lf) 'b25=recievebyte 'recievebyte=0 'Calculate Parity 'FOR b27=1 to 7 ' recievebyte=recievebyte<<1 ' recievebyte=recievebyte^b25 'NEXT 'bit15=bit14^bit13^bit12^bit11^bit10^bit9^bit8 'b26=b25 & %11111110 ;Remove Parity for to test 'sertxd(#bit15) 'recievebyte=b26|bit15 ;Add the calculated parity on 'if recievebyte=b25 then ;If the calculate byte is the same as the recieved on, we are good to go 'sertxd("Parity Correct ",#bit15,#bit14,#bit13,#bit12,#bit11,#bit10,#bit9,#bit8,cr,lf) b25=recievebyte>>4 ;Shift the data back to its original position b26=recievebyte>>2 b26=b26 & %00000011 if b25!=15 then ;Small check to rule out any obvious false packets - player 16 should never exist 'sertxd(#b25,",",#b26) if b25=0 then 'We are recieving a system command recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,20) goto EndRecieve Endif sound 0,(255,1) 'sound 0,(20,60,120,30) ptr=ptr+1 SELECT recievebyte CASE 1 'Reset command peek 80,bullets peek 81,clips health=100 write 203,health write 202,bullets write 206,clips write 204,outputpower write 205,guntype mode=0 write 208,mode reset CASE 2 'Reset Health command health=100 mode=0 gosub flashled CASE 3 'Reset Ammo command peek 80,bullets peek 81,clips gosub flashled CASE 4 'End Game health=0 mode=255 CASE 5 'respawn health=100 mode=0 gosub flashled CASE 6 recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,100) goto EndRecieve endif playerid=recievebyte gosub flashled gosub CalculateShotBytesub: write 200,PlayerID CASE 7 recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,100) goto EndRecieve endif teamid=recievebyte gosub flashled gosub CalculateShotBytesub: write 201,TeamID CASE 8 recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,100) goto EndRecieve endif guntype=recievebyte write 205,recievebyte ptr=ptr+1 recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,100) goto EndRecieve endif outputpower=recievebyte write 204,OutputPower gosub ConfigureGun gosub DisplayAmmo gosub flashled CASE 10 if b26=teamID then if health < 100 then if GameMode<>2 or teamID=2 then health=health+20 endif endif peek 81,b27 if clips 10 and b26=teamID and carryflag=0 then if GameMode<>2 or teamID=2 then mode = 0 health = 100 peek 81,b27 clips=b27 sound 0,(40,30,60,30,80,30,100,30,120,60) gosub flashled endif endif CASE 11 if b26 <> teamID or carryflag=1 or mode=255 and GameMode=1 then 'flag transfer code b27=0 if mode=0 then if b26 <> teamID then b27=playerID+128 endif if carryflag=1 and b26 = teamID then b27=playerID+64 endif endif if mode=255 then if carryflag=0 then goto endrecieve else b27=playerID+32 endif endif if b27=0 then goto endrecieve hserout 0,(playerID,b27,b27) pause 100 hserptr=0 ptr=0 hserinflag=0 'pause 200 for b27=0 to 15 pause 50 'ptr=0 'hserptr=0 'sertxd(#b27) if hserinflag>0 then goto flag_1 next flag_1: 'sertxd(#recievebyte,",",#@ptrinc,",",#@ptrinc,",",#@ptrinc,",",#hserinflag,",",#hserptr,"-") 'ptr=1 recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,50) 'sertxd("wrong",#recievebyte,",",#@ptrinc,",",#@ptrinc,",",#@ptrinc,",",#hserinflag,",",#hserptr,cr,lf) goto EndRecieve endif if recievebyte=246 then if b26 <> teamID then carryflag=1 sound 0,(80,50,80,50,80,50) hserout 0,(246,246) else hserout 0,(245,245) if mode = 0 then carryflag=0 tune 0, 12,($03,$6A,$C3,$6C,$68,$2A,$23,$6C,$67,$6A,$43,$6A,$45,$C3,$6C,$41,$40,$6A,$68,$EA) else mode = 0 health = 10 carryflag=0 sound 0,(40,30,60,30,80,30,100,30,120,60) gosub flashled endif endif else carryflag=0 sound 0,(20,50) 'sertxd("wrong2",#recievebyte,",",#@ptrinc,",",#@ptrinc,",",#@ptrinc,",",#hserinflag,",",#hserptr,cr,lf) goto EndRecieve endif endif CASE 12 recievebyte=@ptrinc if recievebyte <> @ptr then sound 0,(20,100) goto EndRecieve endif GameMode=recievebyte gosub flashled write 210,GameMode ENDSELECT gosub displaystatus else if b25!=playerID then ;Check shooter is not the same player (Reflection) if b26!=teamID OR teamID=0 then 'sertxd("enemy hit") ptr=199 @ptr=b25 ptr=ptr+b25 @ptr=@ptr+1 if mode=0 then if teamID=1 OR GameMode=2 then high portc 2 else high portc 3 endif sound 0,(60,2) if health <= 5 then sound 0,(80,60,30,60,2,120) if GameMode=2 and TeamID=1 then TeamID=2 GOSUB CalculateShotBytesub endif health=0 mode=255 else health=health-5 endif endif gosub displayhealth low portc 2 ;Turn off hit light low portc 3 else 'sertxd("friendly fire") endif endif endif else 'sertxd("wrg2",cr,lf) endif 'else 'sertxd("Wrg",cr,lf) ' sound 0,(255,10,80,1) 'endif endrecieve: 'endif hserptr=0 recievebyte=0 endif goto main displayhealth: bintoascii Health,b25,b26,b27 if Health > 85 then sendbyte=$C5 GOSUB SendCmdByte sendbyte=b25 GOSUB SendDataByte else sendbyte=$C6 GOSUB SendCmdByte endif sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte RETURN displaydead: sendbyte=$01 GOSUB SendCmdByte pause 10 'The headers FOR counter = 29 TO 32 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=$85 GOSUB SendCmdByte pause 10 FOR counter = 93 TO 96 READ counter,sendbyte GOSUB SendDataByte NEXT ptr=199 b25=@ptr bintoascii b25,b26,b26,b27 sendbyte=$C1 GOSUB SendCmdByte sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte GOSUB DisplayHealth RETURN displayammo: bintoascii bullets,b25,b26,b27 if roundtimer <=1 then sendbyte=$C9 GOSUB SendCmdByte sendbyte=b25 GOSUB SendDataByte else sendbyte=$CA GOSUB SendCmdByte endif sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte RETURN displayammo2: 'shotmode and clips sendbyte=$CC GOSUB SendCmdByte 'b26=shotmode & %10 if FullAuto=0 then sendbyte="S" else sendbyte="A" endif if BurstMode=1 then sendbyte="B" endif if carryflag=1 then sendbyte="F" endif GOSUB SendDataByte sendbyte=$CE GOSUB SendCmdByte bintoascii clips,b25,b26,b27 sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte RETURN displaystatus: 'Display Status Screen sendbyte=$01 GOSUB SendCmdByte pause 10 'The headers FOR counter = 13 TO 28 READ counter,sendbyte GOSUB SendDataByte NEXT 'And then the data sendbyte=$C0 GOSUB SendCmdByte if GameMode=0 OR GameMode=1 then 'Normal or CTF bintoascii TeamID,b25,b26,b27 sendbyte=b27 GOSUB SendDataByte endif if GameMode=2 then if teamID=1 then sendbyte="H" else sendbyte="Z" endif GOSUB SendDataByte endif sendbyte=$C2 GOSUB SendCmdByte bintoascii PlayerID,b25,b26,b27 sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte GOSUB displayammo2 GOSUB displayhealth GOSUB displayammo RETURN flashled: high portc 3 pause 50 high portc 2 pause 50 low portc 3 pause 50 low portc 2 sound 0,(80,40) return sendscores: for b26=1 to 2 ptr=b25 'b27=200 hserout 0,(b25) for counter=1 to 4 b27=@ptrinc 'b27=counter hserout 0,(b27) next pause 50 next RETURN Menu: 'debug b27=mode % 10 IF portA pin2 = 1 then roundtimer=0 sound 0,(120,10) pause 250 if b27=0 then mode=mode+10 else mode=mode+1 endif if mode=13 then mode=10 endif if mode=22 then mode=20 endif if mode=30 then mode=0 write 201,TeamID write 200,PlayerID write 204,OutputPower GOSUB DisplayStatus GOTO CalculateShotByte endif endif IF portA pin1 =1 then roundtimer=0 sound 0,(120,10) pause 250 Select Case Mode case 11 if PlayerID<14 then PlayerID=PlayerID+1 else PlayerID=1 endif case 12 if TeamID<2 then TeamID=TeamID+1 else TeamID=1 endif case 21 if OutputPower<100 then OutputPower=OutputPower+20 else OutputPower=20 endif 'change the pwm frequency Select Case OutputPower case 20 pwmout 1 , 20, 42 case 40 pwmout 1 , 21, 44 case 60 pwmout 1 , 23, 48 case 80 pwmout 1 , 24, 50 case 100 pwmout 1 , 25, 53 EndSelect EndSelect IF b27=0 then mode=mode+1 endif endif if roundtimer = 0 then 'pause 500 sendbyte=$01 GOSUB SendCmdByte pause 10 select case mode case 10 goto menu10 case 11 goto menu11 case 12 goto menu12 case 20 goto menu20 case 21 goto menu21 endselect 'we are in menu mode 'The headers menu10: FOR counter = 29 TO 32 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte FOR counter = 33 TO 35 READ counter,sendbyte GOSUB SendDataByte NEXT goto battery menu11: 'PlayerID FOR counter = 29 TO 32 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte FOR counter = 46 TO 47 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte bintoascii PlayerID,b25,b26,b27 sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte goto battery menu12: 'TeamID FOR counter = 42 TO 45 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte FOR counter = 46 TO 47 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte bintoascii TeamID,b25,b26,b27 sendbyte=b27 GOSUB SendDataByte goto battery menu20: FOR counter = 36 TO 38 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte FOR counter = 33 TO 35 READ counter,sendbyte GOSUB SendDataByte NEXT goto battery menu21: FOR counter = 86 TO 92 READ counter,sendbyte GOSUB SendDataByte NEXT sendbyte=" " GOSUB SendDataByte bintoascii OutputPower,b25,b26,b27 sendbyte=b25 GOSUB SendDataByte sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte sendbyte="%" GOSUB SendDataByte gosub battery roundtimer=50 endif Return battery: sendbyte=$C0 GOSUB SendCmdByte FOR counter = 39 TO 41 READ counter,sendbyte GOSUB SendDataByte NEXT readadc10 3,w13 if w13=0 then w13=670 endif b20=w13-615 b20=b20/2 bintoascii b20,b25,b26,b27 sendbyte=":" GOSUB SendDataByte sendbyte=b26 GOSUB SendDataByte sendbyte=b27 GOSUB SendDataByte sendbyte="%" GOSUB SendDataByte readadc10 3,w13 if w13=0 then w13=670 endif 'w13=w13-650 'w13=w13/20 'debug 'FOR b20=1 to w13 ' sendbyte="#" ' GOSUB SendDataByte 'NEXT Return