1 // 11.0592MHz=>921600 T0 clk=>112.5 ops=2.27`5s time
3 public BaudRate equ 2400 // Communication speed
4 public StackSiz51 equ 24 // LaserGun stack size required
5 MagicRAMw equ 0x53AC // RAM-check
6 TestChar equ 't' // For Ph_Test
8 MaxDecimal equ 99 // If dec>99
9 BauDiv equ 28800/BaudRate // 3=9600, 6=4800, 12=2400 (PCON=0)
14 Gx-Game mode: A=Anarchy, G=Green team, R=Red team
17 Fn-Shot from friend detected
18 En-Shot from enemy detected but already dead
25 /******************************/
34 // 0='s';1=PktType;2=SwConfigX;3=PktData;4=XSumH;5=XSumL;6='e'
37 TimPhase: rb 1 // Timer for current phase
38 TimLED4: rb 1 // 4-LED period
39 TimScroll: rb 1 // Scroll advance to next char
41 ScrollPtr: rb 1 // Scroll-text start rel. ScrBase
42 SeriCnt: rb 1 // Shots in current series
43 CAPktEnd: rb 1 // End of ConfigReq being answered (or 0)
44 WDogCnt: rb 1 // WatchDog timer count-down
45 Phase: rb 1 // Current phase # (see below)
46 Ph_CfgDump equ 0 // Configuration to display dump [Phase1=sub-phase]
47 Ph_Ammo equ 1 // Normal Ammo display
48 Ph_Laser equ 2 // Laser on
49 Ph_Delay equ 3 // Laser off, laser button disabled
50 Ph_First equ 4 // Additional first-in-series delay
51 // Laser allowed boundary
52 Ph_Reload equ 5 // Reload countdown period [Phase1=cdown]
53 Ph_Dead equ 6 // Dead-state countdown period [Phase1=cdown]
54 Ph_Test equ 7 // Test mode with transmit/receive of 'T'
55 Phase1: rb 1 // Sub-phase
57 CD_Bootup equ 0 // Right after boot-up
58 CD_PNum equ 1 // Player no. (P#)
59 CD_GMode equ 2 // Game mode (G#: Anarchy, Green, Red)
60 CD_LEDs equ 3 // BBS_QuietL [Ld]
61 CD_Sound equ 4 // BBS_QuietS [Sd]
62 CD_WDogs equ 5 // WDogsCnt (dr, TU)
63 CD_WDogsN equ 6 // {TU}
64 CD_RSwChg equ 7 // RSwChgs (SC, TU)
65 CD_RSwChgN equ 8 // {TU}
66 CD_TotSh equ 9 // TotShotsW (FS, [TH], TU)
67 CD_TotShM equ 10 // {[TH]}
68 CD_TotShN equ 11 // {TU}
69 CD_Grave0 equ 12 // GraveW #0 (d#, [TH], TU)
70 CD_GraveL equ 60 // GraveW #++F(d#, [TH], TU)
72 // Ph_Reload: Reload cycles countdown
73 // Ph_Dead: Dead cycles countdown
75 CurPktE: rb 1 // +1 of last L2 packet byte received
76 XMitNib: rb 1 // Transmit-remaining nibble (or 0)
77 PktNibble: rb 1 // Recevied L2 packet hex nibble
78 CurPktS: rb 1 // Addr of size of L2 packet being received
79 UserPktS: rb 1 // Addr of size of 1st L2 packet in user queue
80 TimedL: rb 1 // Left digit of TimedDisp
81 TimedR: rb 1 // Right digit of TimedDisp
82 ConvDecW1: // For use by ConvDecW
83 RxChkXSumW: rw 1 // Computed xsum of incoming L2 packet
84 XMitXSumW: rw 1 // XSum being computed during XMit
85 XMitType: rb 1 // Actual XMit L3 Pkt type - One of PktN_* below
89 public TotShotsW: rw 1 // Fire statistics
90 public RSwChgs: rb 1 // Run-Time switch configuration change #
91 public WDogsCnt: rb 1 // # of gurus-WatchDog restarts since power-on
93 public SwConfigXA equ $-DataStart // Address of SwConfigX
94 SwConfigX: rb 1 // Copy of SwitchP
95 SysFlagsX: rb 1 // [XMittedN|XMitByte|XMit1stNib|XMitHaveP|TimedDisp|XMitting|PktGotNib|PktRcvng]
96 PktRcvng bit SysFlagsX.0 // Currently receiving packet (after 's')
97 PktGotNib bit SysFlagsX.1 // Already got one hex nibble in PktNibble
98 XMitting bit SysFlagsX.2 // Background packet transmit in progress
99 TimedDisp bit SysFlagsX.3 // Generated 2-digit display override
100 XMitHaveP bit SysFlagsX.4 // XMitNib is prepared and filled
101 XMit1stNib bit SysFlagsX.5 // Transmit 1st nibble from XMitNib
102 XMitByte bit SysFlagsX.6 // Transmitting byte instead of two nibbles
103 XMittedN bit SysFlagsX.7 // Sth was already xmitted this round
104 public UsrFlagsX: rb 1 // [RFU:2|FastFireRD|FullFireT|DisRSwChg|DispDotTR|DispDotRD|UnConfig]
105 UnConfig bit UsrFlagsX.0 // Ignore all further configuration attempts
106 DispDotRD bit UsrFlagsX.1 // Display LDot & RDot when [R]eload/[D]ead
107 DispDotTR bit UsrFlagsX.2 // Display LDot & RDot when [T]ransmit/[R]eceive
108 DisRSwChg bit UsrFlagsX.3 // Disable run-time switch reconfiguration
109 FullFireT bit UsrFlagsX.4 // Transmit full 10B packets for fires (safer)
110 FastFireRD bit UsrFlagsX.5 // Receive disable for FastFires (see FullFireT)
112 /******************************/
113 public Mark_Start equ 's' // L1 layer packet start
114 public Mark_End equ 'e' // L1 layer packet end
115 public XSum_Base equ 0xB3A7 // L2 packet xsumming base number
116 public XSum_Mul equ 13 // L2 packet xsumming advance multiply
117 public PktN_Fire equ 'S' // L3 packet ID for fire
118 public PktN_CfgR equ 'R' // L3 packet ID for configuration request
119 public PktN_CfgA equ 'A' // L3 packet ID for configuration answer
128 BBD_DOT equ DispP.BND_DOT
129 BMD_DOT equ 1<<BND_DOT
140 BMM_LED0 equ 0x08 // RED ^ - cable up
141 BMM_LED1 equ 0x10 // GREEN <
142 BMM_LED2 equ 0x20 // RED >
144 BMM_LED3 equ 1<<BNM_LED3 // GREEN v
145 BMM_LEDM equ BMM_LED0|BMM_LED1|BMM_LED2|BMM_LED3
150 BMS_IdentM equ 0x0F // However defined, hard-coded
152 BBS_IsTeam equ SwConfigX.BNS_IsTeam
153 BNS_TeamN equ 5 // 1=Green
154 BBS_TeamN equ SwConfigX.BNS_TeamN
155 BBS_QuietL equ SwConfigX.6 // 1=LEDs off
156 BBS_QuietS equ SwConfigX.7 // 1=Disable
162 /******************************/
164 Font_0 equ low~(0|BMD_U|BMD_UL|BMD_UR |BMD_BL|BMD_BR|BMD_B)
165 Font_1 equ low~(0 |BMD_UR |BMD_BR )
166 Font_2 equ low~(0|BMD_U |BMD_UR|BMD_M|BMD_BL |BMD_B)
167 Font_3 equ low~(0|BMD_U |BMD_UR|BMD_M |BMD_BR|BMD_B)
168 Font_4 equ low~(0 |BMD_UL|BMD_UR|BMD_M |BMD_BR )
169 Font_5 equ low~(0|BMD_U|BMD_UL |BMD_M |BMD_BR|BMD_B)
170 Font_6 equ low~(0|BMD_U|BMD_UL |BMD_M|BMD_BL|BMD_BR|BMD_B)
171 Font_7 equ low~(0|BMD_U |BMD_UR |BMD_BR )
172 Font_8 equ low~(0|BMD_U|BMD_UL|BMD_UR|BMD_M|BMD_BL|BMD_BR|BMD_B)
173 Font_9 equ low~(0|BMD_U|BMD_UL|BMD_UR|BMD_M |BMD_BR|BMD_B)
174 Font_A equ low~(0|BMD_U|BMD_UL|BMD_UR|BMD_M|BMD_BL|BMD_BR )
175 Font_B equ low~(0 |BMD_UL |BMD_M|BMD_BL|BMD_BR|BMD_B)
176 Font_C equ low~(0|BMD_U|BMD_UL |BMD_BL |BMD_B)
177 Font_c_ equ low~(0 |BMD_M|BMD_BL |BMD_B)
178 Font_D equ low~(0 |BMD_UR|BMD_M|BMD_BL|BMD_BR|BMD_B)
179 Font_E equ low~(0|BMD_U|BMD_UL |BMD_M|BMD_BL |BMD_B)
180 Font_F equ low~(0|BMD_U|BMD_UL |BMD_M|BMD_BL )
181 Font_G equ low~(0|BMD_U|BMD_UL |BMD_BL|BMD_BR|BMD_B)
182 Font_H equ low~(0 |BMD_UL|BMD_UR|BMD_M|BMD_BL|BMD_BR )
183 Font_I equ low~(0 |BMD_UL |BMD_BL )
184 Font_L equ low~(0 |BMD_UL |BMD_BL |BMD_B)
185 Font_N equ low~(0 |BMD_M|BMD_BL|BMD_BR )
186 Font_O equ low~(0|BMD_U|BMD_UL|BMD_UR |BMD_BL|BMD_BR|BMD_B)
187 Font_P equ low~(0|BMD_U|BMD_UL|BMD_UR|BMD_M|BMD_BL )
188 Font_R equ low~(0 |BMD_M|BMD_BL )
189 Font_S equ low~(0|BMD_U|BMD_UL |BMD_M |BMD_BR|BMD_B)
190 Font_T equ low~(0 |BMD_UL |BMD_M|BMD_BL |BMD_B)
191 Font_U equ low~(0 |BMD_UL|BMD_UR |BMD_BL|BMD_BR|BMD_B)
192 Font_Y equ low~(0 |BMD_UL|BMD_UR|BMD_M |BMD_BR|BMD_B)
193 Font_MIN equ low~(0 |BMD_M )
194 Font_ equ low~(0|BMD_U|BMD_UL|BMD_UR|BMD_M|BMD_BL|BMD_BR|BMD_B)
196 /******************************/
197 public GraveWA equ $-DataStart // GraveW address
198 public GraveW: rw 16 // Kills by players #0..#F
201 public ReloadN: rb 1 // Reload countdown
202 public DeadN: rb 1 // Dead state countdown
203 public SeriC_Max: rb 1 // Maximum # of shots per one series
204 public Ammo_Max: rb 1 // Ammo # in one clip
205 public Ammo: rb 1 // Remaining ammo in the current clip
206 public DeadDivN: rb 1 // 4LED-Dead -> Dead cycle divisor
207 public T_Start: rb 1 // Startup info cycle delay
208 public T_Reload: rb 1 // Reload cycle delay
209 public T_Laser: rb 1 // Laser firing
210 public T_Delay: rb 1 // Inter-Laser delay
211 public T_First: rb 1 // Additional series start delay period
212 public T_LED4: rb 1 // 1 of RY-LED switch period
213 public T_Scroll: rb 1 // Scroll of one letter
214 public T_ScrollF: rb 1 // Scroll of 1st two letters
215 public T_Dead: rb 1 // 4LED-Dead (and Dead) cycle delay
216 public T_TimedD: rb 1 // TimedDisp delay (temporary, non-scrolling)
217 public AddrSpace equ $-DataStart // +1 of remote configurable address space
218 LoadPartS equ $-LoadPart
219 MagicRAM: rw 1 // Contains MagicRAMw for RAM-check
220 public RxBufSiz equ 0x80+DataStart-$-StackSiz51 // Receive buffer size
221 RxBuf: rb RxBufSiz // Receive buffer
222 StackBtm: // Start of stack
224 /******************************/
227 org 0x0 // Reset, SUsage=6
230 mov a,#high MagicRAMw
235 org 0xB // T0, SUsage=4
242 inc WDogsCnt // Failing!
243 WarmBoot: mov r0,#ClearTop-1 // Mustn't reset RAM
250 org 0x23 // Ser, SUsage=14
251 SerInt: ajmp SerICont
253 SwRConfig: inc RSwChgs
256 ResCont: mov a,#low MagicRAMw
259 BadRAM: mov MagicRAM,#high MagicRAMw
260 mov MagicRAM+1,#low MagicRAMw
270 ColdBoot: mov r0,#LoadPart-1
280 mov SwConfigX,SwitchP
289 mov MiscP,#~(BMM_DispL|BMM_DispR)
297 0: mov MiscP,#~BMM_DispR
299 mov UsrFlagsX,#0x03 //DEBUG!!!
302 mov IP,#0x10 // Pri: Ser=1
308 mov TMOD,#0x20 // T1=m2, T0=m0
309 mov PCON,a // SerSpd=normal
310 mov SCON,#0x50 // 8N1, T1, clr
311 mov TCON,#0x50 // T1+T0=run, clr
313 mov IE,#0x92 // Int: Ser+T0
318 MainLoop: mov WDogCnt,#0 // Reset WatchDog
319 // Check run-time change of configuration
328 xrl MiscP,#BMM_DispL|BMM_DispR
362 jb BBS_QuietL,NoLED4Fr
370 mov a,#BMM_LED0|BMM_LED2
372 mov a,#BMM_LED1|BMM_LED3
379 jb acc.(BNM_LED3+1),4f
381 4: orl MiscP,#BMM_LEDM
387 // Fire series maintenance
391 /*** Here end mandatory MainLoop routines ***/
413 2: cjne a,#Ph_First-Ph_Ammo,CantFire
417 0: jb BPI_Fire,CantFire
424 // Fire one shot NOW!
471 GotNoSerS: ajmp GotNoSer
481 jb XMitting,GotNoSerS
484 subb a,#RxBuf+RxBufSiz
499 mov @r1,#low XSum_Base
501 mov @r1,#high XSum_Base
509 FailRPktN: jnz FailRPktS
524 cjne r3,#PktN_Fire,NoPFire
526 // Fire packet received, @R0=remote SwConfigX
528 jnb BBS_IsTeam,ShotDown // We're anarchy
529 jnb acc.BNS_IsTeam,ShotDown // From anarchy one
531 jnb acc.BNS_TeamN,FriendS // One of our team
533 ShotDown: xrl a,SwConfigX
536 // Really shot by enemy
551 0: mov TimedL,#Font_S
560 FriendS: mov TimedL,#Font_F
571 FailRPktS: sjmp FailRPkt
573 NoPFire: cjne r3,#PktN_CfgR,NoPCfgR
604 jb UnConfig,SkipWrite
625 NoPCfgR: cjne r3,#PktN_CfgA,FailRPkt
627 ScrRPkt: acall DoScroll
628 FailRPkt: pop UserPktS
634 /******************************/
636 db PhCfgDump-PhaseTab
641 db PhReload -PhaseTab
645 PhCfgDump: mov a,T_TimedD
654 JmpByTab: movc a,@a+dptr
657 PhLaser: orl MiscP,#BMM_Laser|BMM_Sound
664 jz PD_Reload // Do Reload
668 PhTest: jb XMitting,PT_WaitTI
681 mov a,#ReloadS-ScrBase
692 PhDead: xrl MiscP,#BMM_LEDM
696 NxtDead: mov B,DeadDivN
704 StartTimP: mov r0,#TimPhase
705 StartTimS: ajmp StartTim
707 RAmmonLED: acall InitLED4
709 NormAmmo: mov Phase,#Ph_Ammo
710 PhAmmo: // PhAmmo shouldn't happen <= no timer
713 CDGrave: cjne a,#CD_Last-CD_Grave0,1f
730 PutHexFnR: mov dptr,#FontHex
753 CDPNum: mov DispL,#Font_P
758 CDGMode: mov DispL,#Font_G
760 jnb BBS_IsTeam,DoGaMode
762 jnb BBS_TeamN,DoGaMode
764 DoGaMode: mov DispR,a
767 CDLEDs: jnb BBS_QuietL,SkpCDumpS
772 CDSound: jnb BBS_QuietS,SkpCDumpS
777 CDWDogs: mov a,WDogsCnt
785 SkpCDumpS: ajmp SkpCDump
787 CDWDogsN: mov a,WDogsCnt
790 CDRSwChg: mov a,RSwChgs
796 CDRSwChgN: mov a,RSwChgs
797 DispDecS: ajmp DispDec
799 CDTotSh: mov a,TotShotsW
806 CDTotShM: mov r0,#TotShotsW
811 CDTotShN: mov r0,#TotShotsW
813 DispHexS: ajmp DispHex
814 /******************************/
819 RetryRI: jbc RI,GotRI
820 RetryTI: jbc TI,GotTI
826 /******************************/
829 jb FastFireRD,ScratchRI
841 5: cjne a,#Mark_Start,0f
852 0: cjne a,#Mark_End,1f
854 jb PktGotNib,ScratchRI
867 // Successfuly received packet
870 1: jnb PktRcvng,RetryRI
880 ScratchRI: clr PktRcvng
881 RetryRIS: sjmp RetryRI
882 /******************************/
883 GotTI: jnb XMitting,RetryTI
885 jnb XMitHaveP,PrepXMit
887 SendPrepd: jb XMittedN,RetryTIS
888 jbc XMitByte,XMitByteC
889 jnb XMit1stNib,Have2ndN
891 Have2ndN: anl a,#0x0F
899 XMitByteC: mov SBUF,a
905 RetryTIS: ajmp RetryTI
906 /******************************/
926 DoneFNRI: cpl PktGotNib
928 /******************************/
929 PrepXMit: mov a,XMitPhase
934 PhXMitTab: db XPStart -PhXMitTab
936 db XPSwCfg -PhXMitTab
938 db XPXSumH -PhXMitTab
939 db XPXSumL -PhXMitTab
941 db XPFinish-PhXMitTab
943 InvalCR: mov CAPktEnd,a
944 XPFinish: clr XMitting
947 XPStart: mov a,XMitType
953 1: xrl a,#TestChar^PktN_Fire
959 2: mov XMitPhase,#6 //XPFinish-1
963 ContXMitB: setb XMitByte
966 ContXMit: setb XMitHaveP
970 XPType: mov XMitXSumW ,#high XSum_Base
971 mov XMitXSumW+1,#low XSum_Base
973 XMitXHexP: inc XMitPhase
974 XMitXHex: push 1 //r1
984 XMitHex: clr XMitByte
988 XPSwCfg: mov a,SwConfigX
991 XPData: mov a,XMitType
1004 jz InvalCR // Invalid CfgReq
1013 DoneBlock: acall RxBufInc
1018 DoneAns: mov CAPktEnd,a // Cancel CfgA pending alert
1022 XPDatDone: inc XMitPhase
1023 XPXSumH: mov a,XMitXSumW
1024 XMitHexP: inc XMitPhase
1027 XPXSumL: mov a,XMitXSumW+1
1030 XPEnd: mov a,#Mark_End
1033 /******************************/
1034 StartXMiX: mov XMitType,a
1039 setb TI // Start XMit now!
1041 /******************************/
1042 // I: A=text offset, O: Filled DispL+DispR, D: A,R0,R2
1043 DoScroll: mov ScrollPtr,a
1047 /******************************/
1048 // O: Filled DispL+DispR, D: A,B,R2
1049 DispAmmo: mov a,Ammo
1050 // I: A=decimal, O: Filled DispL+DispR, D: A,B,R2
1061 // I: A=hexadecimal, O: Filled DispL+DispR, D: A,R2
1062 DispHex: mov dptr,#FontHex
1070 PutFontR: movc a,@a+dptr
1073 /******************************/
1074 InitLED4: orl MiscP,#BMM_LEDM
1076 anl MiscP,#~BMM_LED0
1079 xrl MiscP,#BMM_LED0|BMM_LED1
1082 /******************************/
1083 // I: R0=addr of byte, A=min time, O: @R0!=0, D:A
1084 StartTim: add a,Timer
1089 /******************************/
1090 // I: R0=addr of byte, C=1->success, D:A
1100 /******************************/
1102 // I: R0=RxAddr, O: R0=RxAddr+1
1104 cjne r0,#RxBuf+RxBufSiz,0f
1107 /******************************/
1108 // I: @R1/W=xsum, A=Byte, O: @R1/W=xsum+Byte, D:A,B,R3
1109 AddXSum: push 2 //r2
1136 // I: R0=SrcWord, O: R0=ConvDecW1, A=LOW [R0/W], D:R1,R2
1189 /******************************/
1191 ScrBase: // Every text offset must >0 !!!
1192 FontHex: db Font_0,Font_1,Font_2,Font_3,Font_4,Font_5,Font_6,Font_7
1193 db Font_8,Font_9,Font_A,Font_B,Font_C,Font_D,Font_E,Font_F
1194 ReloadS: db Font_R,Font_E,Font_L,Font_O,Font_A,Font_D,0
1195 CfgAS: db Font_C,Font_O,Font_N,Font_F,Font_I,Font_G
1196 db Font_A,Font_N,Font_S,0
1197 CfgRS: db Font_C,Font_O,Font_N,Font_F,Font_I,Font_G
1198 db Font_U,Font_R,Font_E,Font_D,0
1199 if ($-ScrBase>=0x100) ScrBase equ 0
1200 /******************************/
1201 CDW_Tab: dw 1000,100,10,1
1204 db 12 // Reload countdown
1205 db 40 // Dead state countdown
1206 db 15 // Maximum # of shots per one series
1207 db 40 // Ammo # in one clip
1208 db 40 // Remaining ammo in the current clip
1209 db 4 // 4LED-Dead -> Dead cycle divisor
1210 db 100 // Startup info cycle delay
1211 db 48 // Reload cycle delay
1212 db 8 // Laser firing
1213 db 2 // Inter-Laser delay
1214 db 24 // Additional series start delay period
1215 db 32 // 1 of RY-LED switch period
1216 db 25 // Scroll of one letter
1217 db 50 // Scroll of 1st two letters
1218 db 24 // 4LED-Dead (and Dead) cycle delay
1219 db 110 // TimedDisp delay (temporary, non-scrolling)
1220 if ($-LoadContn!=LoadPartS) LoadPartS equ 0