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