8d0bab19e702045dc9706836d894d6a971d05c45
[wormy.git] / worm.asm
1 ; Title                      : Worm
2 ; Version                    : 0.92
3 ; Release Date               : soon (I hope)
4 ; Filename                   : worm.86p
5 ; Author(s)                  : Shiar
6 ; Email Address              : shiar@mailroom.com
7 ; ICQ UIN                    : #43840958
8 ; Web Page                   : www.games3.net/shiar
9 ; Description                : ruling multiplayer game for 86 (most like Nibbles)
10 ; Where to get this game     : games3.net/shiar (home of Worm)
11 ; Other games by author(s)   : Shiar: Nemesis beta
12 ; Additional Credits to      : Matthew Shepcar (wrote original Peaworm, end'98)
13 ;                              Jonah Cohen (wrote some parts of worm)
14
15 ;-----------------------------
16 ;----------- TO-DO -----------
17 ;-----------------------------
18
19 ;       Shiar 23.I .00
20
21 ;Feel like doing something? (name indicates who's working on it)
22 ;  * linkplay TESTING! (+faster)
23 ;  * singleplay ending
24 ;  * titlescreen
25 ;  * make linkplay available for all gametypes (not just deathmatch)
26 ;  * two worms collide with heads -> both should die
27 ;  * bouncing balls :)
28 ;  * game types:
29 ;    * hot pursuit/hunting/kodh: catch the other player and vv
30 ;1)  * ctf: take enemy flag (right-bottom) and return to your flag (left-top)
31 ;1)  * domination?: take control points by running over them and hold them
32 ;  * AI worms?
33 ;1)* sprites for picks instead of blocks
34 ;  * fix linedraw procedure
35 ;  * save hiscore
36
37 ;1) Shiar: working on a new pickup-system allowing more than one "food" and different pickup-handling
38
39 #include "TI86.inc"
40
41 ;-----------------------------
42 ;------- program start -------
43 ;-----------------------------
44
45 .org _asm_exec_ram
46 start:
47   nop
48   jp Start
49   .dw 1
50   .dw WormMsg
51   .dw WormIcon
52
53 WormIcon:
54   .db 9,2
55   .db %10010111,%01101111
56   .db %10110101,%01001011
57   .db %11110111,%01001001
58   .db %00000011,%10000000
59   .db %00000001,%11100000
60   .db %00111000,%11111000
61   .db %01111110,%00111111
62   .db %11101111,%00001111
63   .db %11000011,%10000000
64
65 Start:
66   ld (SpSave),sp
67   call _runIndicOff
68 ;  call _flushAllMenus
69   call _clrLCD
70   res 2,(iy+13) ;appAutoScroll
71
72   ld  a,r
73   ld  (Seed),a
74
75 ;-----------------------------
76 ;----- build trig tables -----
77 ;-----------------------------
78
79   ld hl,TrigPrecalc
80   ld de,SinCosTable
81   push de                        ; >> 1
82   ld bc,65
83   ldir
84   dec hl
85   ld b,63
86 MirrorSineWave:
87   dec hl
88   ld a,(hl)
89   ld (de),a
90   inc de
91   djnz MirrorSineWave
92   pop hl                         ; << 0k
93   ld b,128+64
94 NegativeSineWave:
95   xor a
96   sub (hl)
97   ld (de),a
98   inc hl
99   inc de
100   djnz NegativeSineWave
101
102 ;-----------------------------
103 ;---------- menu -------------
104 ;-----------------------------
105
106 DisplayMenu:
107   ld  a,2
108   ld  (nrworms),a
109 gomainMenu:
110   call _clrWindow
111   ld  hl,txtWelcome
112   call _puts
113   ld  de,$0205
114   ld  (_curRow),de
115   call _puts ;txtOptions
116   dec e ;$0204
117   ld  (_curRow),de
118   ld  hl,(CURtxtGame)
119   call _puts
120
121   xor a
122 mainMenu:
123   call menucall
124   jr  nz,notselect
125 select:
126   ld  a,b
127   or  a
128   jr  nz,gooptionsMenu
129   jp  ThePartyIsOn
130 notselect
131   cp  K_EXIT
132   jp  z,ExitNoStats
133   cp  K_RIGHT
134   ld  a,b
135   jr  nz,mainMenu
136   or  a
137   jr  z,Variation
138
139 gooptionsMenu:
140   call _clrWindow
141   ld  hl,txtWelcome
142   call _puts
143   ld  hl,txtLevel
144   ld  de,$0205
145   ld  (_curRow),de
146   call _puts ;txtLevel
147   dec e ;$0204
148   ld  (_curRow),de
149   call _puts ;txtWorms
150   ld  a,(nrworms)
151   add a,'0'
152   call _putc
153   xor a
154 optionsMenu:
155   call menucall
156   jr  nz,notopselect
157 opselect:
158   ld  a,b
159   or  a
160   jr  nz,changelevel
161 changeworms:
162   ld  hl,nrworms
163   inc (hl)
164   ld  a,4
165   cp  (hl)
166   jr  nc,gooptionsMenu
167   ld  (hl),2
168   jr  gooptionsMenu
169 changelevel:
170   jr  optionsMenu
171
172 notopselect:
173   cp  K_EXIT
174   jr  z,gomainMenu
175   ld  a,b
176   jr  optionsMenu
177
178 Variation:
179   ld  a,0
180 Gametype =$-1
181   ld  hl,txtGame2
182 NEXTtxtGame =$-2
183   inc a
184   and 7 ;mod 8
185   jr  nz,okilydokily
186   ld  hl,txtGame
187 okilydokily:
188   ld  (Gametype),a
189   ld  de,$0204
190   ld  (_curRow),de
191   ld  (CURtxtGame),hl
192   call _puts
193   ld  (NEXTtxtGame),hl
194   ld  a,b
195   jp  mainMenu
196
197 menucall:
198   push af
199   ld  hl,$0004
200   ld  (_curRow),hl
201   ld  a,' '
202   call _putc
203   ld  hl,$0005
204   ld  (_curRow),hl
205   call _putc
206   pop af
207   push af
208   ld  h,0
209   add a,4
210   ld  l,a
211   ld  (_curRow),hl
212   ld  a,'*'
213   call _putc
214   pop af
215   ld  b,a
216 menukeys:
217   halt \ halt
218   call _getcsc
219   or  a
220   jr  z,menukeys
221   cp  K_UP
222   jr  nz,notup
223 updown:
224   ld  a,b
225   xor 1
226   ld  b,a
227   inc a ;nz
228   ret
229 notup:
230   cp  K_DOWN
231   jr  z,updown
232   cp  K_ENTER
233   ret z
234   cp  K_SECOND
235   ret ;z=select
236
237 ;-----------------------------
238 ;-------- start game ---------
239 ;-----------------------------
240
241 ThePartyIsOn:
242   ld  hl,Gametype
243   ld  a,(hl)
244   add a,a
245   add a,(hl)
246   ld  e,a
247   ld  d,0
248   ld  hl,gamesdata
249   add hl,de
250
251   or  a
252   jr  nz,notsingle
253   inc a
254   ld  (nrworms),a
255 notsingle:
256   ld  a,(hl)
257   ld  (gameCar),a
258   push af
259
260   and _datascore
261   ld  de,$FF64
262   jr  z,setscorelimit
263   ld  d,0 ;de=100
264 setscorelimit:
265   ld  (scorelimit),de
266
267   inc hl
268   call _ldHLind
269   pop af
270   push hl
271   and _datalink
272   jr  z,GameOver
273
274 linkmatch:
275   call _clrWindow
276   ld  a,WormVersion
277   call SendByte
278   jr  c,host
279
280 client:
281   ld  hl,txtReceive
282   call _puts
283   call receive
284   cp  WormVersion
285   ret nz
286   jr  multiplayer
287
288 host:
289   ld  hl,txtWaiting
290   call _puts
291   call receive
292   cp  WormVersion
293   ret nz
294   call send
295   ld  hl,SwapPos
296   ld  (hl),$f6
297
298 multiplayer:
299   ld  a,2
300   ld  (nrworms),a
301   ld  de,LevelsDM
302
303 ;-----------------------------
304 ;--------- game over ---------
305 ;-----------------------------
306
307 GameOver:
308   call _clrLCD
309   xor a
310   ld  (worm1+died),a
311   ld  (worm2+died),a
312   ld  (worm3+died),a
313   ld  (worm4+died),a
314   ld  h,a
315   ld  l,a
316   ld  (worm1+score),hl
317   ld  (worm2+score),hl
318   ld  (worm3+score),hl
319   ld  (worm4+score),hl
320   inc a
321   ld  (worm1+delay),a
322   ld  (worm2+delay),a
323   ld  (worm3+delay),a
324   ld  (worm4+delay),a
325   ld  (Level),a
326   ld  hl,worm1set+4
327   ld  de,worm1+lives
328   call _MOV5B ;9xld(de),(hl)
329   call _mov9b
330   ld  hl,worm2set+4
331   ld  de,worm2+lives
332   call _MOV5B
333   call _mov9b
334   ld  hl,worm3set+4
335   ld  de,worm3+lives
336   call _MOV5B
337   call _mov9b
338   ld  hl,worm4set+4
339   ld  de,worm4+lives
340   call _MOV5B
341   call _mov9b
342   pop de
343
344 StartLevel:
345   ld  a,(de)
346   ld  (Left),a
347   inc de
348   ld  a,(de)
349   ld  (Speed),a
350   inc de
351   ld  a,(de)
352   ld  (worm1+grow),a
353   ld  (worm2+grow),a
354   ld  (worm3+grow),a
355   ld  (worm4+grow),a
356   inc de
357
358   ld  (thislevel),de
359   push de
360   ld  hl,worm1set
361   ld  de,worm1+head
362   call _MOV4B
363   ld  hl,worm2set
364   ld  de,worm2+head
365   call _MOV4B
366   ld  hl,worm3set
367   ld  de,worm3+head
368   call _MOV4B
369   ld  hl,worm4set
370   ld  de,worm4+head
371   call _MOV4B
372   pop de
373
374   ld  hl,worm1
375   ld  a,(gameCar)
376   and _datanextl
377   ld  b,1
378   jr  nz,worminit
379   ld  b,4
380 worminit:
381   push bc                        ; >> 1
382   ld  a,(de)
383   ld  (hl),a   ;d
384   inc de
385   inc hl
386   ld  a,SinCosTable/256
387   ld  (hl),a
388   inc hl
389
390   ld  a,(de)
391   ld  (hl),a   ;y
392   inc de
393   inc hl
394   ld  a,(de)
395   ld  (hl),a   ;x
396   inc de
397   inc hl
398
399   xor a
400   ld  (hl),a   ;y2
401   inc hl
402   ld  (hl),a   ;x2
403
404   ld  bc,(worm2-worm1)-5
405   add hl,bc
406   pop bc                         ; << 0k
407   djnz worminit
408
409 ;-------- draw level ---------
410
411   ld  a,(de)
412   inc de
413   sub 128
414   ld  (FieldWidth),a
415   ld  a,(de)
416   inc de
417   sub 57
418   ld  (FieldHeight),a
419   add a,57-5
420   push de                        ; >> levelp
421   ld  l,a
422   ld  h,0
423   add hl,hl
424   add hl,hl
425   add hl,hl
426   add hl,hl
427   add hl,hl
428   ex  de,hl
429
430   ld  hl,ScrBuffer
431   push hl                        ; >> 1
432   push de                        ; >> 2
433   ld  de,ScrBuffer+1
434   ld  bc,63
435   ld  (hl),%11111111
436   ldir
437   inc hl
438   ld  (hl),%11000000
439   inc hl
440   ld  b,31
441 ClearLine:
442   ld  (hl),c
443   inc hl
444   djnz ClearLine
445   push hl                        ; >> 3
446
447   ld  a,(FieldWidth)
448   add a,126
449   push af                        ; >> 4
450   and %11111000
451   rra
452   rra
453   rra
454   ld  l,a
455   ld  h,0
456   add hl,de
457   pop af                         ; << 3
458   and %00000111
459   ld  b,a
460   ld  c,0
461   ld  a,%11000000
462   jr  z,NoVertShift
463 VertShift:
464   rra
465   rr  c
466   djnz VertShift
467 NoVertShift:
468   ld  (hl),a
469   inc hl
470   ld  (hl),c
471
472   ex  de,hl
473   pop de                         ; << 2
474   pop bc                         ; << 1
475   ldir
476   pop hl                         ; << 0k
477   ld  c,64
478   ldir
479
480 ;-draw lines-
481
482   pop hl                         ; << levelp
483   ld  a,(hl)
484   inc hl
485   or  a
486   jr  z,NoLines
487 DrawLines:
488   push af                        ; >> 1
489   call loaddrawdata
490   push hl                        ; >> 2
491   ld  l,(hl)
492   ld  h,a
493   call Line
494   inc d
495   inc h
496   call Line
497   inc e
498   inc l
499   call Line
500   dec d
501   dec h
502   call Line
503   pop hl                         ; << 1
504   inc hl
505   pop af                         ; << 0k
506   dec a
507   jr  nz,DrawLines
508 NoLines:
509
510   ld  a,(hl)
511   inc hl
512   or  a
513   jr  z,noboxes
514 drawboxes:
515   push af
516   call loaddrawdata
517   push hl
518   ld  l,(hl)
519   ld  h,a
520   call drawbox
521   pop hl
522   inc hl
523   pop af
524   dec a
525   jr  nz,drawboxes
526 noboxes:
527
528 ;-----------------------------
529
530   push hl                        ; >> levelp new
531   call showstats
532   ld  a,(gameCar)
533   and _datafood
534   jr  z,nofood
535   call NewPea
536   call DrawPea
537 nofood:
538   ld  bc,(worm1+pos)
539   call DisplayField
540   ld  hl,$FDE0
541   ld  de,$FDE1
542   ld  (hl),%11111111
543   ld  bc,$BF
544   ldir
545   ld  hl,4+(txtposReady*256)
546   ld  (_curRow),hl
547   set 3,(iy+5)
548   ld  hl,txtReady
549   call _puts
550   res 3,(iy+5)
551
552   ld  a,0
553 gameCar =$-1
554   and _datalink
555   jr  z,SwapPos ;no link
556   xor a
557   ld  (worm2+input),a
558   ld  (worm2+left),a
559   ld  (Speed),a
560
561 SwapPos: ;$18 xx -> $F6 xx
562   jr  initfinished
563   inc a
564   ld  (worm2+left),a
565   ld  hl,(worm1+pos)
566   ld  de,(worm2+pos)
567   ld  (worm2+pos),hl
568   ld  (worm1+pos),de
569   ld  a,(worm1+heading)
570   ld  b,a
571   ld  a,(worm2+heading)
572   ld  (worm1+heading),a
573   ld  a,b
574   ld  (worm2+heading),a
575 initfinished:
576
577   ld  b,0
578 ReadyDelay:
579   halt
580   djnz ReadyDelay
581
582 ;-----------------------------
583 ;----------- LOOP ------------
584 ;-----------------------------
585
586 GameLoop:
587   ld  bc,(worm1+pos)
588   call DisplayField
589
590   ld  a,0
591 Speed =$-1
592   or  a
593   jr  z,NoDelay
594 Delay:
595   halt
596   dec a
597   jr  nz,Delay
598 NoDelay:
599
600   ld  ix,worm1
601   ld  a,(nrworms)
602   ld  b,a
603 handleworms:
604   push bc
605   call HandleWorm
606   ld  bc,worm2-worm1
607   add ix,bc
608   pop bc
609   djnz handleworms
610
611 ;-----------------------------
612 ;---------- keys -------------
613 ;-----------------------------
614
615 HandleKeys:
616   ld  a,%10111111
617   out (1),a
618   in  a,(1)
619   rla
620   jr  c,NotPaused
621   ld  bc,$0103
622   out (c),b
623   halt
624   ld  b,11
625   out (c),b
626
627 NotPaused:
628   rla
629   jp  c,GameLoop
630   jr  Exit ;&&
631
632 WormDead:
633   ld  h,(ix+tail+1)
634   ld  l,(ix+tail)
635   push hl
636 removewormloop:
637   ld  c,(hl)
638   inc hl
639   ld  b,(hl)
640   inc hl
641   res resbit,h
642   push hl
643   call res4pixels
644   pop hl
645   ld  a,(ix+head)
646   cp  l
647   jr  nz,removewormloop
648   ld  a,(ix+head+1)
649   cp  h
650   jr  nz,removewormloop
651
652   ;hl=ix+head
653   pop de ;ix+tail
654   or  a
655   sbc hl,de
656   ld  a,l
657   rr  h
658   rra
659   inc a
660   ld  (ix+grow),a
661
662   push ix
663   ld  de,10
664   call DecScore
665   pop ix
666
667   ld  h,(ix+head+1)
668   ld  l,(ix+head)
669   ld  (ix+tail+1),h
670   ld  (ix+tail),l
671   ld  a,50
672   ld  (ix+delay),a
673
674 thislevel =$+1
675   ld  de,0
676   ld  a,(de)
677   inc de
678   ld  (ix+heading),a
679   ld  a,(de)
680   ld  (ix+pos),a
681   inc de
682   ld  a,(de)
683   ld  (ix+pos+1),a
684
685   inc (ix+died)
686   dec (ix+lives)
687   ret nz ;HandleWorm done
688   ld  a,(gameCar)
689   and _datalivel
690   ret z
691
692 Exit:
693   ld  sp,0 ;pop all
694 SpSave = $-2
695   call _clrWindow
696   ld  hl,txtGO
697   call _puts
698   ld  hl,txtGame
699 CURtxtGame =$-2
700   call _puts
701   ld  de,0002
702   ld  (_curRow),de
703   call showLevel
704   ld  de,$0B03
705   ld  (_curRow),de
706   ld  hl,txtDied
707   call _puts
708   call _puts ;txtScore
709   xor a
710   ld  (_curCol),a
711
712   ld  b,2
713 nrworms =$-1
714   ld  hl,worm1+died
715 displayWormStats:
716   push bc
717   push hl
718
719   ld  bc,input-died
720   add hl,bc ;+input
721   xor a
722   cp  (hl)
723   jr  nz,NoLinkIndic
724   ld  b,7
725   inc hl ;+left
726   cp  (hl)
727   jr  z,hostLinkIndic
728   dec b
729 hostLinkIndic:
730   ld  a,8
731   ld  (_curCol),a
732   ld  a,b
733   call _putc
734   xor a
735   ld  (_curCol),a
736   dec hl
737 NoLinkIndic:
738   inc hl
739   inc hl
740   inc hl ;+name
741   call _puts
742
743   pop hl
744   push hl
745   ld  a,13
746   ld  (_curCol),a
747   ld  a,(hl) ;worm+died
748   push hl
749   call showA
750   pop hl
751
752   ld  a,16
753   ld  (_curCol),a
754   inc hl
755   call _ldHLind ;ld hl,(hl)
756   call showHL ;worm+score
757
758   pop hl
759   ld  bc,worm2-worm1
760   add hl,bc
761   pop bc
762   djnz displayWormStats
763
764 waitkey:
765   halt
766   halt
767   call _getcsc
768   cp  K_ENTER
769   jp  z,DisplayMenu
770 ;  cp  K_EXIT
771   jr  nz,waitkey
772
773 ;x123456789012345678901
774 ;1----- GAME OVER -----
775 ;2Multiplayer
776 ;3Level 01
777 ;4           Died Score:
778 ;5NameName     03 00070
779 ;6Worm#02 @    05 00120
780 ;7Worm#03      15 00030
781 ;8Snaky   @    00 04820
782
783 ExitNoStats:
784 ;  ld  a,(Eaten)
785  xor a
786   ld  hl,HiScore
787   cp  (hl)
788   jr  c,NotNewHigh
789   ld  (hl),a
790 NotNewHigh:
791
792   ld  hl,_asapvar
793   rst 20h ;_ABS_MOV10TOOP1
794   rst 10h ;_FINDSYM
795   call _swapt_ ;_ex_ahl_bde
796   ld  de,4
797   add hl,de
798   adc a,0
799   call _SET_ABS_DEST_ADDR
800
801   xor a 
802   ld  hl,start
803   call _SET_ABS_SRC_ADDR
804   ld  hl,end-start
805   call _SET_MM_NUM_BYTES
806   call _MM_LDIR
807
808 ;  xor a
809 ;  ld  (_asapvar+1),a
810   res 4,(iy+9)
811   set 2,(iy+13)
812   jp  _clrWindow
813
814 ;-----------------------------
815 ;----------- worm ------------
816 ;-----------------------------
817
818 inlink:
819   ld  a,0
820 sendbyte =$-1
821   ld  b,(ix+left)
822   dec b
823   jr  z,receivefirst
824   call send
825   call receive
826   ld  l,a
827   ret
828 receivefirst:
829   push af
830   call receive
831   ld   l,a
832   pop  af
833   push hl
834   call send
835   pop  hl
836   ret
837
838 inkeys: ;use jp not call!
839   out (1),a
840   in  a,(1)
841   ld  b,a
842   and (ix+right)
843   jr  z,notright
844   ld  a,l
845   add a,8
846   ld  l,a
847 notright:
848   ld  a,b
849   and (ix+left)
850   jr  z,donediddelydone
851   ld  a,l
852   sub 8
853   ld  l,a
854   jr  donediddelydone
855
856 ;------- handle worm ---------
857
858 HandleWorm:
859   dec (ix+delay)
860   ret nz
861   inc (ix+delay)
862   ld  l,(ix+heading)
863   ld  a,(ix+input)
864   or  a
865   jr  nz,inkeys
866   call inlink
867 donediddelydone:
868   ld  a,l
869   ld  (sendbyte),a
870   ld  (ix+heading),l
871   ld  h,(ix+heading+1)
872
873   ld  c,(ix+pos)
874   ld  b,(ix+pos+1)
875   ld  e,(ix+pos2)
876   ld  d,(ix+pos2+1)
877
878 ;-------- move worm ----------
879
880 Wormmove:
881   push bc                        ; >> pos
882   ld  a,(hl)
883   add a,a
884   add a,d
885   ld  d,a
886   bit 7,(hl)
887   jr  z,notnegX
888   dec b
889 notnegX:
890   jr  nc,notmoveX
891   inc b
892 notmoveX:
893   ld  a,l
894   add a,$40
895   ld  l,a
896   ld  a,(hl)
897   add a,a
898   add a,e
899   ld  e,a
900   bit 7,(hl)
901   jr  z,notnegY
902   dec c
903 notnegY:
904   jr  nc,notmoveY
905   inc c
906 notmoveY: ;bc=newpos
907   ld  (ix+pos2),e
908   ld  (ix+pos2+1),d
909   ld  (ix+pos),c
910   ld  (ix+pos+1),b
911
912 ;-check-
913   pop hl                         ; << pos (old)
914   ld  a,h
915   sub b
916   and 1
917   ld  h,a
918   ld  a,l
919   sub c
920   and 1
921   add a,h
922   ld  d,4
923   jr  z,GotFour
924   xor 3
925   ld  d,a
926 GotFour:
927   call CheckPixel
928   inc b
929   call CheckPixel
930   inc c
931   call CheckPixel
932   dec b
933   call CheckPixel
934   dec c
935   rl  d
936   jp  nc,Drawworm
937
938 ;--------- worm hit ----------
939
940 Hitworm:
941   ld  a,(gameCar)
942   ld  h,a
943   and _datafood
944   jp  z,WormDead
945   ld  a,h
946   and _datahunt
947   call nz,checkhitotherworm
948
949   ld  hl,0
950 PeaY =$-2
951 PeaX =$-1
952   ld  a,b
953   sub h
954   inc a
955   cp  4
956   jp  nc,WormDead
957   ld  a,c
958   sub l
959   inc a
960   cp  4
961   jp  nc,WormDead
962   call DrawPea
963   ld  a,(ix+grow)
964   add a,15
965   ld  (ix+grow),a
966   call NewPea
967   ld  hl,Left
968   dec (hl)
969   push af
970   push ix
971   ld  de,10
972   call IncScore
973   pop ix
974   pop af
975   jr  nz,NotNextLevel
976   ld  a,(gameCar)
977   and _datafoodl
978   jr  z,NotNextLevel
979   ld  hl,Level
980   ld  a,(hl)
981   inc (hl)
982   pop hl                         ; << call
983   pop hl                         ; << call
984   pop de                         ; << levelp new
985 ;  pop hl                         ; << levelp old
986   cp  NUM_LEVELS
987   jp  z,Exit
988   ld  a,(gameCar)
989   and _datanextl
990   jp  nz,StartLevel
991   jp  Exit
992
993 ;-----------------------------
994
995 checkhitotherworm:
996   .db $dd,$7d ;ld a,lx
997   cp  worm2&255
998   ret nz
999
1000   ld  hl,worm1+tail
1001   ld  d,20
1002 nextotherwormbit:
1003   ld  a,b
1004   sub (hl)
1005   inc hl
1006   inc a
1007   cp  4
1008   jr  nc,nothit1 ;no
1009   ld  a,c
1010   sub (hl)
1011   inc a
1012   cp  4
1013   jr  c,otherwormHIT ;yes
1014 nothit1:
1015   inc hl
1016   res resbit,h
1017   push bc
1018   push de
1019   push hl
1020 ;  ld  de,worm1+head
1021 ;  call _cphlde
1022  dec d
1023   pop hl
1024   pop de
1025   pop bc
1026   jr  nz,nextotherwormbit
1027   ret
1028 otherwormHIT:
1029   jp Exit
1030
1031 checkhitlapline:
1032   ld  a,63
1033   sub b
1034   jr  z,nextlaphalf
1035   inc a
1036   ret nz
1037 nextlaphalf:
1038   ld  a,c
1039   and 32 ;>=32?
1040   jr  nz,nolap
1041   cp  (ix+reserv)
1042   jr  z,nolap
1043   push ix
1044   push bc
1045   ld  de,20
1046   call IncScore
1047   pop bc
1048   pop ix
1049   xor a
1050 nolap:
1051   ld  (ix+reserv),a
1052   ret
1053
1054 NotNextLevel:
1055
1056 ;-------- draw worm ----------
1057
1058 Drawworm:
1059   ld  c,(ix+pos)
1060   ld  b,(ix+pos+1)
1061
1062   ld  a,(gameCar)
1063   and _datalaps
1064   call nz,checkhitlapline
1065
1066   ld  l,(ix+head)
1067   ld  h,(ix+head+1)
1068   ld  (hl),c
1069   inc hl
1070   ld  (hl),b
1071   inc hl
1072   res resbit,h
1073   ld  (ix+head),l
1074   ld  (ix+head+1),h
1075
1076   call SetPixel
1077   inc b
1078   call SetPixel
1079   inc c
1080   call SetPixel
1081   dec b
1082   call SetPixel
1083
1084   ld  a,(ix+grow)
1085   dec a
1086   jr  z,removetail
1087   ld  (ix+grow),a
1088   ret
1089
1090 removetail:
1091   ld  l,(ix+tail)
1092   ld  h,(ix+tail+1)
1093   ld  c,(hl)
1094   inc hl
1095   ld  b,(hl)
1096   inc hl
1097   res resbit,h
1098   ld  (ix+tail),l
1099   ld  (ix+tail+1),h
1100
1101 res4pixels:
1102   call ResPixel
1103   inc b
1104   call ResPixel
1105   inc c
1106   call ResPixel
1107   dec b
1108   jp  ResPixel
1109
1110 ;-----------------------------
1111 ;----------- procs -----------
1112 ;-----------------------------
1113
1114 NewPea:
1115 ;random routine
1116   ld hl,0
1117   ld de,12345
1118 Seed =$-2
1119   ld a,7921 & 255
1120   ld bc,1000h+(7921/256)
1121 domult16:
1122   add hl,hl
1123   rla
1124   rl  c
1125   jr  nc,noadd16
1126   add hl,de
1127 noadd16:
1128   djnz domult16
1129   inc hl
1130   ld  (Seed),hl ;seed=(seed*7921+1) MOD 65536
1131
1132   ld  a,(FieldWidth)
1133   add a,123
1134   cp  h
1135   jr c,NewPea
1136   inc h
1137   inc h
1138   ld a,(FieldHeight)
1139   add a,51
1140   cp  l
1141   jr  c,NewPea
1142   inc l
1143   inc l
1144   ld  (PeaY),hl
1145   ld  d,2 ;don't draw
1146   push hl
1147   call CheckPea
1148   pop hl
1149   dec d
1150   jr  z,NewPea
1151
1152 DrawPea: ;hl=(PeaY)
1153   ld  d,0 ;draw
1154 CheckPea:
1155   ld  b,h
1156   ld  c,l
1157   call PeaPixel
1158   inc c
1159   call PeaPixel
1160   inc b
1161   call PeaPixel
1162   dec c
1163 PeaPixel:
1164   push de
1165   call FindPixel
1166   pop de
1167   ld  e,a ;>>
1168   ld  a,d
1169   or  a
1170   ld  a,e ;<<
1171   jr  z,DrawPeaPixel ;d=0:draw
1172   and (hl) ;pixel?
1173   ret z
1174   ld  d,1 ;d=1:yes 2:no
1175   ret
1176 DrawPeaPixel:
1177   xor (hl) ;change pixel
1178   ld  (hl),a
1179   ret
1180
1181 ;-------- pixelprocs ---------
1182
1183 ResPixel: ;at bc
1184   call FindPixel
1185   cpl
1186   and (hl)
1187   ld  (hl),a
1188   ret
1189
1190 SetPixel: ;at bc
1191   call FindPixel
1192   or  (hl)
1193   ld  (hl),a
1194   ret
1195
1196 CheckPixel: ;at bc in d
1197   call FindPixel
1198   and (hl)
1199   ret z
1200   dec d
1201   ret
1202
1203 FindPixel: ;bc to ahl + de gone
1204   push de
1205   push bc
1206   ld  a,b
1207   and 7
1208   add a,offsets_table & 255
1209   ld  e,a
1210   ld  d,offsets_table/256
1211   ld  h,0
1212   ld  l,c
1213   add hl,hl
1214   add hl,hl
1215   add hl,hl
1216   add hl,hl
1217   add hl,hl
1218   ld  a,b
1219   and %11111000
1220   rra
1221   rra
1222   rra
1223   or  l
1224   ld  l,a
1225   ld  a,(de)
1226   ld  de,ScrBuffer
1227   add hl,de
1228   pop bc
1229   pop de
1230   ret
1231
1232 ;----------- score -----------
1233
1234 DecScore:
1235   ld  h,(ix+score+1)
1236   ld  l,(ix+score)
1237   or  a
1238   sbc hl,de
1239   ret c
1240   jr  scorecommon
1241 IncScore:
1242   ld  h,(ix+score+1)
1243   ld  l,(ix+score)
1244   add hl,de
1245 scorecommon:
1246   ld  (ix+score+1),h
1247   ld  (ix+score),l
1248   ld  de,0
1249 scorelimit =$-2
1250   call _cphlde
1251   jp  nc,Exit
1252
1253 showstats:
1254   xor a
1255   sbc hl,hl
1256   ld  (_penCol),hl
1257   ld  a,(nrworms)
1258   ld  b,a
1259   ld  ix,worm1
1260   ld  a,(gameCar)
1261   and _datanextl
1262   jr  nz,showstatsS
1263 showstatloop:
1264   push bc
1265   push ix
1266   call showstat
1267   pop ix
1268   ld  de,worm2-worm1
1269   add ix,de
1270   ld  hl,_penCol
1271   ld  a,(hl)
1272   add a,10
1273   ld  (hl),a
1274   pop bc
1275   djnz showstatloop
1276   ret
1277
1278 showstat:
1279   ld  a,(gameCar)
1280   and _datalivel
1281   jr  nz,showlives
1282 showscore:
1283   ld  h,(ix+score+1)
1284   ld  l,(ix+score)
1285   call _D_HL_DECI
1286   jp  _vputs
1287 showlives:
1288   ld  a,(ix+lives)
1289   add a,'0'
1290   jp  _vputmap
1291
1292 showstatsS:
1293   push ix
1294   ld  hl,txtLevel
1295   call _vputs
1296   ld  a,(Level)
1297   cp  10
1298   jr  c,tilllevel9
1299   ld  l,a
1300   ld  h,0
1301   call _divHLby10
1302   push af
1303   ld  a,l
1304   add a,'0'
1305   call _vputmap
1306   pop af
1307 tilllevel9:
1308   add a,'0'
1309   call _vputmap
1310   pop ix
1311
1312   ld  a,98
1313   ld  (_penCol),a
1314   call showscore
1315   ld  a,123
1316   ld  (_penCol),a
1317   call showlives
1318 showleft:
1319   ld  a,31
1320   ld  (_penCol),a
1321   ld  a,0
1322 Left =$-1
1323   push af
1324   call _divAby10
1325   add a,'0'
1326   call _vputmap
1327   pop af
1328   add a,'0'
1329   call _vputmap
1330   ld  hl,txtLeft
1331   jp _vputs
1332
1333 showLevel:
1334   ld  hl,txtLevel
1335   call _puts
1336   ld  a,(Level)
1337 showA:
1338   cp  10
1339   jr  c,LevelBelowTen
1340   ld  l,a
1341   ld  h,0
1342   call _divHLby10
1343   push af
1344   ld  a,l
1345   add a,'0'
1346   call _putc
1347   pop af
1348 LevelBelowTen:
1349   add a,'0'
1350   jp  _putc
1351
1352 showHL:
1353   call _D_HL_DECI
1354   jp  _puts
1355
1356 _D_HL_DECI:
1357   ld  de,savestr+4
1358   ld  b,5
1359 ldhld:
1360   call _divHLby10
1361   add a,'0'
1362   ld  (de),a
1363   dec de
1364   djnz ldhld
1365   ld  hl,savestr
1366   ret
1367 savestr:
1368   .db "00000",0
1369
1370 ;-----------------------------
1371
1372 offsets_table:
1373   .db 128,64,32,16,8,4,2,1
1374
1375 DisplayField:
1376   ld  a,c
1377   sub 29
1378   jr  nc,NotMinYScroll
1379   xor a
1380 NotMinYScroll:
1381   cp  43
1382 FieldHeight =$-1
1383   jr  c,NotMaxYScroll
1384   ld  a,(FieldHeight)
1385 NotMaxYScroll:
1386   ld  l,a
1387   ld  h,0
1388   add hl,hl
1389   add hl,hl
1390   add hl,hl
1391   add hl,hl
1392   add hl,hl
1393   push bc                        ; >> 1
1394   push de                        ; >> 2
1395   ld  de,ScrBuffer
1396   add hl,de
1397   ld  a,b
1398   sub 64
1399   jr  nc,NotMinXScroll
1400   xor a
1401 NotMinXScroll:
1402   cp 128
1403 FieldWidth = $-1
1404   jr c,NotMaxXScroll
1405   ld a,(FieldWidth)
1406 NotMaxXScroll:
1407   push af                        ; >> 3
1408   and %11111000
1409   rra
1410   rra
1411   rra
1412   ld  c,a
1413   ld  b,0
1414   ld  de,DispBuffer
1415   pop af                         ; << 2
1416   and %00000111
1417   push af                        ; >> 3
1418   cp  6
1419   jr  c,CopyScreen
1420   inc c
1421 CopyScreen:
1422   add hl,bc
1423   ld b,57
1424 CopyScreenLoop:
1425   push bc                        ; >> 4
1426   ld bc,16
1427   ldir
1428   ld c,16
1429   add hl,bc
1430   pop bc                         ; << 3
1431   djnz CopyScreenLoop
1432   pop af                         ; << 2
1433   ld  c,$b7 ;or a
1434 Bit0:
1435   jr  nz,Bit1
1436   halt
1437   halt
1438   jr  AfterShiftDelay
1439 Bit1:
1440   dec a
1441   jr nz,Bit2
1442   call ShiftRight1
1443   jr AfterShiftDelay
1444 Bit2:
1445   dec a
1446   jr nz,Bit3
1447   ld a,2
1448   call ShiftRight
1449   jr AfterShiftDelay
1450 Bit3:
1451   dec a
1452   jr nz,Bit4
1453   call Chunk
1454   call ShiftLeft1
1455   jr AfterShift
1456 Bit4:
1457   dec a
1458   jr nz,Bit5
1459   call Chunk
1460   jr AfterShiftDelay
1461 Bit5:
1462   dec a
1463   jr nz,Bit6
1464   call Chunk
1465   call ShiftRight1
1466   jr AfterShift
1467 Bit6:
1468   dec a
1469   jr nz,Bit7
1470   ld a,2
1471   call ShiftLeft
1472   jr AfterShift
1473 Bit7:
1474   call ShiftLeft
1475 AfterShiftDelay:
1476   halt
1477 AfterShift:
1478   ld hl,DispBuffer
1479   ld de,$fc00+$70
1480   ld bc,1024-$70
1481   ldir
1482   pop de                         ; << 1
1483   pop bc                         ; << 0k
1484   ret
1485
1486 ShiftRight1:
1487   ld a,1
1488 ShiftRight:
1489   ld (ShiftRightCounter),a
1490   ld a,c
1491   ld (ShiftRightChunk),a
1492   ld c,16
1493   add hl,bc
1494   ld b,57
1495 ShiftRightLoop:
1496   push bc
1497   ld bc,-32
1498   add hl,bc
1499   ex de,hl
1500   ld a,(de)
1501 ShiftRightChunk:
1502   or a
1503   call c,_SHLACC
1504   ld c,0
1505 ShiftRightCounter = $-1
1506 ShiftRowsLeft:
1507   push hl
1508   rla
1509   ld b,16
1510 ShiftRowLeft:
1511   dec hl
1512   rl (hl)
1513   djnz ShiftRowLeft
1514   pop hl
1515   dec c
1516   jr nz,ShiftRowsLeft
1517   ld bc,-16
1518   add hl,bc
1519   ex de,hl
1520   pop bc
1521   djnz ShiftRightLoop
1522   ret
1523
1524 ShiftLeft1:
1525   ld a,1
1526 ShiftLeft:
1527   ld (ShiftLeftCounter),a
1528   ld a,c
1529   ld (ShiftLeftChunk),a
1530   rla
1531   jr nc,ShiftLeftSameByte
1532   dec hl
1533 ShiftLeftSameByte:
1534   ex de,hl
1535   ld bc,-16
1536   add hl,bc
1537 NewSprite:
1538   ex de,hl
1539   ld b,57
1540 ShiftLeftLoop:
1541   push bc                        ; >> 1
1542   ld bc,-32
1543   add hl,bc
1544   ex de,hl
1545   ld a,(de)
1546 ShiftLeftChunk:
1547   or a
1548   call c,_SHRACC
1549   ld c,0
1550 ShiftLeftCounter = $-1
1551 ShiftRowsRight:
1552   push hl                        ; >> 2
1553   rra
1554   ld b,16
1555 ShiftRowRight:
1556   rr (hl)
1557   inc hl
1558   djnz ShiftRowRight
1559   pop hl                         ; << 1
1560   dec c
1561   jr nz,ShiftRowsRight
1562   ld bc,-16
1563   add hl,bc
1564   ex de,hl
1565   pop bc                         ; << 0k
1566   djnz ShiftLeftLoop
1567   ret
1568
1569 Chunk:
1570   push hl                        ; >> 1
1571   push de                        ; >> 2
1572   ld  c,16
1573   add hl,bc
1574   ld  b,57
1575 ChunkScreen:
1576   push bc                        ; >> 3
1577   ld  bc,-32
1578   add hl,bc
1579   ex  de,hl
1580   ld  a,(de)
1581   call _SHRACC
1582   ld  b,16
1583 ChunkRow:
1584   dec hl
1585   rld
1586   djnz ChunkRow
1587   ex  de,hl
1588   pop bc                         ; << 2
1589   djnz ChunkScreen
1590   pop de                         ; << 1
1591   pop hl                         ; << 0k
1592   ld  c,$37 ;scf
1593   ret
1594
1595 ;----------- draw ------------
1596
1597 loaddrawdata:
1598   ld  d,(hl)
1599   inc hl
1600   ld  e,(hl)
1601   inc hl
1602   ld  a,(hl)
1603   inc hl
1604   ret
1605
1606 Line: ;draw line from de to hl (d<h)
1607   push hl
1608   push de
1609   ld a,d
1610 ;  cp h
1611 ;  jr c,lineOrdered
1612 ;  ex de,hl
1613 lineOrdered:  
1614   ld  b,d
1615   ld  c,e
1616   push hl
1617   push bc
1618   call FindPixel
1619   pop bc
1620   pop de
1621 connectedLine:
1622   push hl
1623   ld  h,c
1624   ld  c,a
1625   ld  a,d
1626   sub b
1627   ld  b,a
1628   ld  a,e
1629   jr  nz,LineNotPoint
1630   cp  h
1631   jr  nz,LineNotPoint
1632   pop hl
1633   jr  DoneLine
1634 LineNotPoint:
1635   sub h
1636   ld  de,16
1637   jr  nc,LinePositiveY
1638   neg
1639   ld  de,-16
1640 LinePositiveY:  
1641   cp  b
1642   jr  nc,SteepLine
1643   add a,a
1644   ld  (line2sm+1),a
1645   ld  h,a
1646   xor a
1647   sub b
1648   add a,a
1649   ld  (line1sm+1),a
1650   ld  a,h
1651   sub b
1652   pop hl
1653 LineLoopGentle: 
1654   push af
1655   ld  a,(hl)
1656   or  c
1657   ld  (hl),a
1658   rrc c
1659   jr  nc,$+3
1660   inc hl
1661   pop af       
1662   jp  m,line2sm
1663 line1sm:
1664   add a,0
1665   add hl,de
1666 line2sm:
1667   add a,0
1668   djnz LineLoopGentle
1669 DoneLine:
1670   ld  a,(hl)
1671   or  c
1672   ld  (hl),a
1673   pop de
1674   pop hl
1675   ret
1676 SteepLine:
1677   ld  h,a
1678   neg
1679   add a,a
1680   ld  (line3sm+1),a
1681   ld  a,b
1682   add a,a
1683   ld  (line4sm+1),a
1684   sub h
1685   ld  b,h
1686   pop hl
1687 LineLoopSteep: 
1688   push af
1689   ld  a,(hl)
1690   or  c
1691   ld  (hl),a
1692   add hl,de
1693   pop af
1694   jp  m,line4sm
1695 line3sm:
1696   add a,0
1697   rrc c
1698   jr  nc,$+3
1699   inc hl
1700 line4sm:
1701   add a,0
1702   djnz LineLoopSteep
1703   jr  DoneLine
1704
1705 drawbox:
1706  ld  b,h
1707  ld  c,l
1708  call FindPixel
1709 ;  ld  b,a
1710 ;makefirstbyte:
1711 ;  or  b
1712 ;  rr  b
1713 ;  jr  nc,makefirstbyte
1714 ;  or  (hl) ;()
1715 ;  ld  (hl),a
1716
1717   ld  b,e ;yloop
1718 boxloopy:
1719   push bc ;yloop
1720   ld  b,d ;xloop
1721 boxloopx:
1722   ld  a,%11111111
1723   ld  (hl),a
1724   inc hl
1725   djnz boxloopx
1726
1727   ld  b,0
1728   ld  a,16
1729   sub d
1730   ld  c,a
1731   add hl,bc
1732   pop bc ;yloop
1733   djnz boxloopy
1734   ret
1735
1736 ;-----------------------------
1737 ;----------- link ------------
1738 ;-----------------------------
1739
1740 send:
1741   push af ;ld b,a
1742   call _getcsc
1743   cp  K_EXIT
1744   jp  z,Exit
1745   pop af ;ld a,b
1746   call SendByte
1747 ;  jr  c,send
1748   ret
1749
1750 linkfail:
1751   jp  Exit
1752
1753 LinkPrep:
1754   ex  (sp),hl
1755   push bc
1756   push de
1757   set 2,(iy+$12) ;cursorblink
1758   ld  b,8
1759   jp  (hl)
1760
1761 receive:
1762   call checklink
1763   jr  z,linkfail
1764   cp  %11
1765   jr  z,receive
1766 ReceiveByteCont:
1767   call LinkPrep
1768   jr  ReceiveCont
1769 ReceiveByte:
1770   call LinkPrep
1771 ReceiveBits:
1772 WaitRecBit:
1773   call checklink
1774   jr  z,LinkFailed
1775   cp  %11
1776   jr  z,WaitRecBit
1777 ReceiveCont:
1778   sub %10
1779   ld  a,%10 
1780   ld  d,D0lD1h
1781   jr  c,ReceiveLow
1782   rra
1783   ld  d,D0hD1l
1784 ReceiveLow:
1785   rr  c
1786   ld  (AckBit),a
1787   ld  a,d
1788   out (7),a
1789 WaitAckRec:
1790   call checklink
1791   cp  0
1792 AckBit =$-1
1793   jr  nz,WaitAckRec
1794   ld  a,D0hD1h
1795   out (7),a
1796   ld  d,4
1797 WaitReadyRec:
1798   dec d
1799   jr  z,ReadyRec
1800   in  a,(7)
1801   cp  %11
1802   jr  nz,WaitReadyRec
1803 ReadyRec:
1804   djnz ReceiveBits
1805   jr  LinkSuccess
1806
1807 SendByte:
1808   call LinkPrep
1809   ld  c,a
1810   inc b
1811   jr  SendAcked
1812 SendBits:
1813   rr  c
1814
1815 sendbit:
1816   ld  a,D0lD1h
1817   jr  nc,sendselected
1818   ld  a,D0hD1l
1819 sendselected:
1820   out (7),a
1821 waitacknowledge:
1822   call checklink
1823   jr  nz,waitacknowledge
1824 SendAcked:
1825   ld  a,D0hD1h
1826   out (7),a
1827 waitsendready:
1828   call checklink
1829   cp  %11
1830   jr  nz,waitsendready
1831
1832   djnz SendBits
1833 LinkSuccess: ;nc
1834   .db $f6 ;first byte of "or n"
1835 LinkFailed:  ;c
1836   scf
1837   ld  a,c
1838   res 2,(iy+$12) ;noblink
1839   pop de
1840   pop bc
1841   pop hl
1842   ret
1843
1844 linkerror:
1845   jp  Exit
1846
1847 checklink:
1848   ld  a,$BF ;key
1849   call _readkeypad
1850   bit 6,a
1851   jr  z,linkerror
1852
1853   in  a,(7)
1854   and %11
1855   ret
1856
1857 _readkeypad:
1858   out (1),a
1859   in  a,(1)
1860   push af
1861   ld  a,%11111111
1862   out (1),a
1863   pop af
1864   ret
1865
1866 ;-----------------------------
1867 ;---------- levels -----------
1868 ;-----------------------------
1869
1870 LevelsDM:
1871
1872   .db 8,5,15
1873   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
1874   .db 128,57
1875   .db 0,0
1876
1877 LevelsDM2:
1878
1879   .db 8,5,31
1880   .db $40,28,2,$C0,28,125, $00,2,63,$80,54,63
1881   .db 128,57
1882   .db 0
1883   .db 4             ;4 boxes
1884   .db 4,19,16,14    ;xsize,ysize,xpos,ypos
1885   .db 4,19,80,14
1886   .db 4,19,16,34
1887   .db 4,19,80,34
1888
1889 LevelsR:
1890   .db 8,5,24
1891   .db $40,3,2,$40,6,2, $40,9,2,$40,12,2
1892   .db 128,57
1893   .db 0
1894   .db 1
1895   .db 8,29,32,20
1896
1897 NUM_LEVELS = 9
1898
1899 LevelsS:
1900
1901   .db 5,4,15        ;5 peas, speed 5
1902   .db 0,2,63        ;d,y,x
1903   .db 128,57        ;field width, height
1904   .db 0             ;no additional lines
1905   .db 0             ;no boxes
1906
1907   .db 8,4,15
1908   .db $40,14,2
1909   .db 128,57
1910   .db 1
1911   .db 28,28,100,28  ;line coords: x1,y1,x2,y2
1912   .db 0
1913
1914   .db 9,4,15
1915   .db $40,8,2
1916   .db 128,57
1917   .db 2
1918   .db 28,14,100,14
1919   .db 28,41,100,41
1920   .db 0
1921
1922   .db 9,3,15
1923   .db $40,8,2
1924   .db 128,80
1925   .db 2
1926   .db 64,14,64,66
1927   .db 20,40,108,40
1928   .db 0
1929
1930   .db 10,3,15
1931   .db 2,8,$40
1932   .db 128,90
1933   .db 3
1934   .db 18,20,18,70
1935   .db 110,20,110,70
1936   .db 18,45,110,45
1937   .db 0
1938
1939   .db 7,3,15
1940   .db 64,4,0
1941   .db 128,86
1942   .db 6
1943   .db 34,13,56,35
1944   .db 34,71,56,49
1945   .db 72,35,94,13
1946   .db 72,49,94,71
1947   .db 16,20,16,64
1948   .db 110,20,110,64
1949   .db 0
1950
1951   .db 9,2,15
1952   .db 4,10,$40
1953   .db 128,82
1954   .db 3
1955   .db 0,20,74,20
1956   .db 54,40,128,40
1957   .db 0,60,74,60
1958   .db 0
1959
1960   .db 12,2,15
1961   .db 64,4,0
1962   .db 128,90
1963   .db 6
1964   .db 20,16,54,16
1965   .db 74,16,110,16
1966   .db 20,16,20,72
1967   .db 110,16,110,72
1968   .db 20,72,54,72
1969   .db 74,72,110,72
1970   .db 0
1971
1972   .db 8,2,15
1973   .db 72,52,$c0
1974   .db 128,128
1975   .db 13
1976   .db 34,56,56,34
1977   .db 34,72,56,94
1978   .db 72,34,94,56
1979   .db 72,94,94,72
1980   .db 46,64,80,64
1981   .db 22,11,22,33
1982   .db 11,22,33,22
1983   .db 22,95,22,117
1984   .db 11,106,33,106
1985   .db 103,11,103,33
1986   .db 91,22,115,22
1987   .db 103,95,103,117
1988   .db 91,106,115,106
1989   .db 0
1990
1991
1992 ;-----------------------------
1993 ;---------- data -------------
1994 ;-----------------------------
1995
1996 TrigPrecalc:
1997 .db   0,  3,  6,  9, 12, 15, 18, 21
1998 .db  24, 27, 30, 33, 36, 39, 42, 45
1999 .db  48, 51, 54, 57, 59, 62, 65, 67
2000 .db  70, 73, 75, 78, 80, 82, 85, 87
2001 .db  89, 91, 94, 96, 98,100,102,103
2002 .db 105,107,108,110,112,113,114,116
2003 .db 117,118,119,120,121,122,123,123
2004 .db 124,125,125,126,126,126,126,126
2005 .db 127
2006
2007 txtWelcome: .db "Welcome to Worm!! ",
2008             .db "by Shiar",0
2009 txtOptions: .db "Options",0
2010 txtGame:    .db "Singleplayer",0  ;0
2011 txtGame2:   .db "Deathmatch  ",0  ;1
2012             .db "Foodmatch ",0    ;2
2013             .db "LinkMatch",0     ;3 (>options)
2014             .db "Hunting  ",0     ;4
2015             .db "Race   ",0       ;5
2016             .db "CTF ",0          ;6
2017             .db "Domination",0    ;7
2018 txtWaiting: .db "Waiting...",0
2019 txtReceive: .db "Receiving...",0
2020
2021 WormVersion = 092
2022 WormMsg:  .db "WORM by SHIAR -- test version",0
2023 txtLevel: .db "Level ",0
2024 txtWorms: .db "Worms: 0",0 ;follows txtLevel
2025 txtDied:  .db "Died ",0
2026 txtScore: .db "Score",0  ;follows txtDied
2027 txtLeft:  .db " left",0   ;follows txtScore
2028 txtReady: .db "Prepare!",0
2029 txtposReady = 7
2030 txtGO:    .db "----- GAME OVER -----",0
2031 HiScore:  .db 0
2032
2033 gamesdata:
2034
2035 _datalink  = %00000001
2036 _datalivel = %00000010 ;ix+lives=0 limit
2037 _datafoodl = %00000100 ;left=0 limit
2038 _datanextl = %00001000 ;next level if left=0
2039 _datafood  = %00010000 ;food present
2040 _datahunt  = %00100000
2041 _datalaps  = %01000000 ;give lap score
2042 _datascore = %10000000 ;score>=100 limit
2043
2044 datasingle: .db %00011110
2045             .dw LevelsS
2046 datadeathm: .db %00000010
2047             .dw LevelsDM2
2048 datafoodm:  .db %10010000
2049             .dw LevelsDM
2050 datalinkm:  .db %00000011
2051             .dw LevelsDM
2052 datahuntin: .db %00110100
2053             .dw LevelsDM
2054 datarace:   .db %11000000
2055             .dw LevelsR
2056 datactf:    .db %00000000
2057             .dw LevelsDM
2058 datadomin:  .db %00000000
2059             .dw LevelsDM
2060
2061
2062 setdata = 18
2063 resbit  = 2 ;and%11111011
2064 worm1set:  .dw $B000,$B000 ;10110000
2065            .db 3,0,%01111110,%10,%100 ;< >
2066            .db "Worm #1",0
2067 worm2set:  .dw $B800,$B800 ;10111000
2068            .db 3,0,%00111111,%10000,%1000 ;f1 f2
2069            .db "Worm #2",0
2070 worm3set:  .dw $E800,$E800 ;11101000 ;$D748+$1000+
2071            .db 3,0,%01011111,%10,%100 ;sto ,
2072            .db "Worm #3",0
2073 worm4set:  .dw $F000,$F000 ;11110000
2074            .db 3,0,%01111101,%10,%1 ;enter +
2075            .db "Worm #4",0
2076 worm1 = $B400
2077 worm2 = $B430
2078 worm3 = $B460
2079 worm4 = $B490
2080 end:
2081               ;set:
2082 heading = 0   ;level*
2083 pos     = 2   ;level*
2084 pos2    = 4   ;level
2085 grow    = 6   ;level
2086 died    = 8   ;game
2087 delay   = 9   ;game
2088 score   = 10  ;game
2089
2090 head    = 12  ;level
2091 tail    = 14  ;level
2092 lives   = 16  ;game
2093 reserv  = 17  ;loop
2094  ;race=lap
2095 input   = 18  ;&
2096 left    = 19  ;&
2097 right   = 20  ;&
2098 name    = 21  ;game
2099
2100 Level =$+1
2101 DispBuffer =$+2 ;912 bytes
2102
2103 ScrBuffer   = $8200 ;32x256 bytes
2104 SinCosTable = $A200
2105
2106 ;-----------------------------
2107 ;----------- end -------------
2108 ;-----------------------------
2109
2110 .end