b58bfe54836dded9f33b3148f62af318c444638d
[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   ld  a,(gameCar)
677   and _dataMulti
678   jr  nz,safewormsizedone
679 ;  or  a
680   sbc hl,de
681   ld  a,l
682   rr  h
683   rra
684   inc a
685   ld  (ix+grow),a
686 safewormsizedone:
687
688   ld  h,(ix+head+1)
689   ld  l,(ix+head)
690   ld  (ix+tail+1),h
691   ld  (ix+tail),l
692   ld  a,50
693   ld  (ix+delay),a
694
695 thislevel =$+1
696   ld  de,0
697   ld  a,(de)
698   inc de
699   ld  (ix+heading),a
700   ld  a,(de)
701   ld  (ix+pos),a
702   inc de
703   ld  a,(de)
704   ld  (ix+pos+1),a
705
706   inc (ix+died)
707   dec (ix+lives)
708   push af
709   ld  de,10
710   call DecScore
711   pop af
712   ret nz ;HandleWorm done
713   ld  a,(gameCar)
714   and _datalivel
715   ret z
716
717 Exit:
718   ld  sp,0 ;pop all
719 SpSave = $-2
720   call _clrWindow
721   ld  hl,txtGO
722   call _puts
723   ld  hl,txtGame
724 CURtxtGame =$-2
725   call _puts
726   ld  de,0002
727   ld  (_curRow),de
728   call showLevel
729   ld  de,$0B03
730   ld  (_curRow),de
731   ld  hl,txtDied
732   call _puts
733   call _puts ;txtScore
734   xor a
735   ld  (_curCol),a
736
737   ld  b,2
738 nrworms =$-1
739   ld  hl,worm1+died
740 displayWormStats:
741   push bc
742   push hl
743
744   ld  bc,input-died
745   add hl,bc ;+input
746   xor a
747   cp  (hl)
748   jr  nz,NoLinkIndic
749   ld  b,7
750   inc hl ;+left
751   cp  (hl)
752   jr  z,hostLinkIndic
753   dec b
754 hostLinkIndic:
755   ld  a,8
756   ld  (_curCol),a
757   ld  a,b
758   call _putc
759   xor a
760   ld  (_curCol),a
761   dec hl
762 NoLinkIndic:
763   inc hl
764   inc hl
765   inc hl ;+name
766   call _puts
767
768   pop hl
769   push hl
770   ld  a,13
771   ld  (_curCol),a
772   ld  a,(hl) ;worm+died
773   push hl
774   call showA
775   pop hl
776
777   ld  a,16
778   ld  (_curCol),a
779   inc hl ;worm+score
780   call _ldHLind ;ld hl,(hl)
781   call showHL ;worm+score
782
783   pop hl
784   ld  bc,worm2-worm1
785   add hl,bc
786   pop bc
787   djnz displayWormStats
788
789 waitkey:
790   halt
791   halt
792   call _getcsc
793   cp  K_ENTER
794   jp  z,DisplayMenu
795 ;  cp  K_EXIT
796   jr  nz,waitkey
797
798 ;x123456789012345678901
799 ;1----- GAME OVER -----
800 ;2Multiplayer
801 ;3Level 01
802 ;4           Died Score:
803 ;5NameName     03 00070
804 ;6Worm#02 @    05 00120
805 ;7Worm#03      15 00030
806 ;8Snaky   @    00 04820
807
808 ExitNoStats:
809 ;  ld  a,(Eaten)
810  xor a
811   ld  hl,HiScore
812   cp  (hl)
813   jr  c,NotNewHigh
814   ld  (hl),a
815 NotNewHigh:
816
817   ld  hl,_asapvar
818   rst 20h ;_ABS_MOV10TOOP1
819   rst 10h ;_FINDSYM
820   call _swapt_ ;_ex_ahl_bde
821   ld  de,4
822   add hl,de
823   adc a,0
824   call _SET_ABS_DEST_ADDR
825
826   xor a 
827   ld  hl,start
828   call _SET_ABS_SRC_ADDR
829   ld  hl,end-start
830   call _SET_MM_NUM_BYTES
831   call _MM_LDIR
832
833 ;  xor a
834 ;  ld  (_asapvar+1),a
835   res 4,(iy+9)
836   set 2,(iy+13)
837   jp  _clrWindow
838
839 ;-----------------------------
840 ;----------- worm ------------
841 ;-----------------------------
842
843 inlink:
844   ld  a,0
845 sendbyte =$-1
846   ld  b,(ix+left)
847   dec b
848   jr  z,receivefirst
849   call send
850   call receive
851   ld  l,a
852   ret
853 receivefirst:
854   push af
855   call receive
856   ld   l,a
857   pop  af
858   push hl
859   call send
860   pop  hl
861   ret
862
863 inkeys: ;use jp not call!
864   out (1),a
865   in  a,(1)
866   ld  b,a
867   and (ix+right)
868   jr  z,notright
869   ld  a,l
870   add a,8
871   ld  l,a
872 notright:
873   ld  a,b
874   and (ix+left)
875   jr  z,donediddelydone
876   ld  a,l
877   sub 8
878   ld  l,a
879   jr  donediddelydone
880
881 ;------- handle worm ---------
882
883 HandleWorm:
884   dec (ix+delay)
885   ret nz
886   inc (ix+delay)
887   ld  l,(ix+heading)
888   ld  a,(ix+input)
889   or  a
890   jr  nz,inkeys
891   call inlink
892 donediddelydone:
893   ld  a,l
894   ld  (sendbyte),a
895   ld  (ix+heading),l
896   ld  h,(ix+heading+1)
897
898   ld  c,(ix+pos)
899   ld  b,(ix+pos+1)
900   ld  e,(ix+pos2)
901   ld  d,(ix+pos2+1)
902
903 ;-------- move worm ----------
904
905 Wormmove:
906   push bc                        ; >> pos
907   ld  a,(hl)
908   add a,a
909   add a,d
910   ld  d,a
911   bit 7,(hl)
912   jr  z,notnegX
913   dec b
914 notnegX:
915   jr  nc,notmoveX
916   inc b
917 notmoveX:
918   ld  a,l
919   add a,$40
920   ld  l,a
921   ld  a,(hl)
922   add a,a
923   add a,e
924   ld  e,a
925   bit 7,(hl)
926   jr  z,notnegY
927   dec c
928 notnegY:
929   jr  nc,notmoveY
930   inc c
931 notmoveY: ;bc=newpos
932   ld  (ix+pos2),e
933   ld  (ix+pos2+1),d
934   ld  (ix+pos),c
935   ld  (ix+pos+1),b
936
937 ;-check-
938   pop hl                         ; << pos (old)
939   ld  a,h
940   sub b
941   and 1
942   ld  h,a
943   ld  a,l
944   sub c
945   and 1
946   add a,h
947   ld  d,4
948   jr  z,GotFour
949   xor 3
950   ld  d,a
951 GotFour:
952   call CheckPixel
953   inc b
954   call CheckPixel
955   inc c
956   call CheckPixel
957   dec b
958   call CheckPixel
959   dec c
960   rl  d
961   jp  nc,Drawworm
962
963 ;--------- worm hit ----------
964
965 Hitworm:
966   ld  a,(gameCar)
967   ld  h,a
968   and _datafood
969   jp  z,WormDead
970   ld  a,h
971   and _datahunt
972   call nz,checkhitotherworm
973
974   ld  hl,0
975 PeaY =$-2
976 PeaX =$-1
977   ld  a,b
978   sub h
979   inc a
980   cp  4
981   jp  nc,WormDead
982   ld  a,c
983   sub l
984   inc a
985   cp  4
986   jp  nc,WormDead
987   call DrawPea
988   ld  a,(ix+grow)
989   add a,15
990   ld  (ix+grow),a
991   call NewPea
992   ld  hl,Left
993   dec (hl)
994   push af
995   ld  de,10
996   call IncScore
997   pop af
998   jr  nz,still_alive_not_dead
999   ld  a,(gameCar)
1000   and _datafoodl
1001   jr  z,still_alive_not_dead
1002   ld  hl,Level
1003   ld  a,(hl)
1004   inc (hl)
1005   pop hl                         ; << call
1006   pop hl                         ; << call
1007   pop de                         ; << levelp new
1008   cp  NUM_LEVELS
1009   jp  z,Exit
1010   ld  a,(gameCar)
1011   and _datanextl
1012   jp  nz,StartLevel
1013   jp  Exit
1014
1015 ;-----------------------------
1016
1017 checkhitotherworm:
1018   .db $dd,$7d ;ld a,lx
1019   cp  worm2&255
1020   ret nz
1021 ThisIsJustASillyUselessLabel:
1022   ld  hl,(worm1+tail)
1023   ld  de,(worm1+head)
1024 nextotherwormbit:
1025   ld  a,c
1026   sub (hl)
1027   inc hl
1028   inc a
1029   cp  4
1030   jr  nc,nothit1 ;no
1031   ld  a,b
1032   sub (hl)
1033   inc a
1034   cp  4
1035   jr  c,otherwormHIT ;yes
1036 nothit1:
1037   inc hl
1038   res resbit,h
1039   call _cphlde
1040   jr  nz,nextotherwormbit
1041   ret
1042
1043 checkhitlapline:
1044   ld  a,63
1045   sub b
1046   jr  z,nextlaphalf
1047   inc a
1048   ret nz
1049 nextlaphalf:
1050   ld  a,c
1051   and 32 ;y>=32?
1052   jr  nz,nolap
1053   cp  (ix+reserv)
1054   jr  z,nolap
1055   push bc
1056   ld  de,20
1057   call IncScore
1058   pop bc
1059   xor a
1060 nolap:
1061   ld  (ix+reserv),a
1062   ret
1063
1064 otherwormHIT:
1065   push ix
1066   ld  de,10
1067   call IncScore
1068   ld  ix,worm1
1069   call WormDead
1070   pop ix
1071   pop bc
1072 still_alive_not_dead:
1073
1074 ;-------- draw worm ----------
1075
1076 Drawworm:
1077   ld  a,(gameCar)
1078   and _datahunt
1079   call nz,HuntingTimeScore
1080
1081   ld  c,(ix+pos)
1082   ld  b,(ix+pos+1)
1083
1084   ld  a,(gameCar)
1085   and _datalaps
1086   call nz,checkhitlapline
1087
1088   ld  l,(ix+head)
1089   ld  h,(ix+head+1)
1090   ld  (hl),c
1091   inc hl
1092   ld  (hl),b
1093   inc hl
1094   res resbit,h
1095   ld  (ix+head),l
1096   ld  (ix+head+1),h
1097
1098   call SetPixel
1099   inc b
1100   call SetPixel
1101   inc c
1102   call SetPixel
1103   dec b
1104   call SetPixel
1105
1106   ld  a,(ix+grow)
1107   dec a
1108   jr  z,removetail
1109   ld  (ix+grow),a
1110   ret
1111
1112 removetail:
1113   ld  l,(ix+tail)
1114   ld  h,(ix+tail+1)
1115   ld  c,(hl)
1116   inc hl
1117   ld  b,(hl)
1118   inc hl
1119   res resbit,h
1120   ld  (ix+tail),l
1121   ld  (ix+tail+1),h
1122
1123 res4pixels:
1124   call ResPixel
1125   inc b
1126   call ResPixel
1127   inc c
1128   call ResPixel
1129   dec b
1130   jp  ResPixel
1131
1132 ;-----------------------------
1133 ;----------- procs -----------
1134 ;-----------------------------
1135
1136 NewPea:
1137 ;random routine
1138   ld hl,0
1139   ld de,12345
1140 Seed =$-2
1141   ld a,7921 & 255
1142   ld bc,1000h+(7921/256)
1143 domult16:
1144   add hl,hl
1145   rla
1146   rl  c
1147   jr  nc,noadd16
1148   add hl,de
1149 noadd16:
1150   djnz domult16
1151   inc hl
1152   ld  (Seed),hl ;seed=(seed*7921+1) MOD 65536
1153
1154   ld  a,(FieldWidth)
1155   add a,123
1156   cp  h
1157   jr c,NewPea
1158   inc h
1159   inc h
1160   ld a,(FieldHeight)
1161   add a,51
1162   cp  l
1163   jr  c,NewPea
1164   inc l
1165   inc l
1166   ld  (PeaY),hl
1167   ld  d,2 ;don't draw
1168   push hl
1169   call CheckPea
1170   pop hl
1171   dec d
1172   jr  z,NewPea
1173
1174 DrawPea: ;hl=(PeaY)
1175   ld  d,0 ;draw
1176 CheckPea:
1177   ld  b,h
1178   ld  c,l
1179   call PeaPixel
1180   inc c
1181   call PeaPixel
1182   inc b
1183   call PeaPixel
1184   dec c
1185 PeaPixel:
1186   push de
1187   call FindPixel
1188   pop de
1189   ld  e,a ;>>
1190   ld  a,d
1191   or  a
1192   ld  a,e ;<<
1193   jr  z,DrawPeaPixel ;d=0:draw
1194   and (hl) ;pixel?
1195   ret z
1196   ld  d,1 ;d=1:yes 2:no
1197   ret
1198 DrawPeaPixel:
1199   xor (hl) ;change pixel
1200   ld  (hl),a
1201   ret
1202
1203 ;-------- pixelprocs ---------
1204
1205 ResPixel: ;at bc
1206   call FindPixel
1207   cpl
1208   and (hl)
1209   ld  (hl),a
1210   ret
1211
1212 SetPixel: ;at bc
1213   call FindPixel
1214   or  (hl)
1215   ld  (hl),a
1216   ret
1217
1218 CheckPixel: ;at bc in d
1219   call FindPixel
1220   and (hl)
1221   ret z
1222   dec d
1223   ret
1224
1225 ;------------------------------------------------------
1226 ;  CLEM's FIND_PIXEL
1227 ;  by Clem
1228 ;
1229 ;  131 cycles  28 bytes    (b,c) to hl:a  destroyes: none
1230 ;------------------------------------------------------
1231
1232 FindPixel:
1233         ld h,ScrBuffer/$800
1234         ld a,c
1235         add a,a
1236         add a,a
1237         ld l,a    ;hl=$3f00+4*y
1238         ld a,b
1239         rra
1240         add hl,hl
1241         rra
1242         add hl,hl ;hl=$fc00+16*y
1243         add hl,hl
1244         rra       ;a=x/8
1245         or l
1246         ld l,a
1247         ld a,b
1248         and 7
1249         cpl
1250         rlca
1251         rlca
1252         rlca
1253         ld (FP_Bit),a
1254         xor a
1255 FP_Bit =$+1
1256         set 0,a
1257         ret
1258
1259 ;FindPixel: ;bc to ahl + de gone
1260   push de
1261   push bc
1262   ld  a,b
1263   and 7
1264   add a,offsets_table & 255
1265   ld  e,a
1266   ld  d,offsets_table/256
1267   ld  h,0
1268   ld  l,c
1269   add hl,hl ;2y
1270   add hl,hl ;4y
1271   add hl,hl ;8y
1272   add hl,hl ;16y
1273   add hl,hl ;32y
1274   ld  a,b
1275   and %11111000
1276   rra
1277   rra
1278   rra
1279   or  l
1280   ld  l,a
1281   ld  a,(de)
1282   ld  de,ScrBuffer
1283   add hl,de
1284   pop bc
1285   pop de
1286   ret
1287
1288 ;----------- score -----------
1289
1290 HuntingTimeScore:
1291   .db $dd,$7d ;ld a,lx
1292   cp  worm2&255
1293   ret z ;=worm#2
1294   dec (ix+reserv)
1295   ret nz
1296   ld  de,10
1297
1298 IncScore:
1299   ld  h,(ix+score+1)
1300   ld  l,(ix+score)
1301   add hl,de
1302   jr  scorecommon
1303 DecScore: ;&&&
1304   ld  h,(ix+score+1)
1305   ld  l,(ix+score)
1306   or  a
1307   sbc hl,de
1308   ret c
1309 scorecommon:
1310   ld  (ix+score+1),h
1311   ld  (ix+score),l
1312   ld  de,0
1313 scorelimit =$-2
1314   call _cphlde
1315   jp  nc,Exit
1316
1317 showstats:
1318   push ix
1319   ld  h,0
1320   ld  l,h
1321   ld  (_penCol),hl
1322   ld  a,(nrworms)
1323   ld  b,a
1324   ld  ix,worm1
1325   ld  a,(gameCar)
1326   and _datanextl
1327   jr  nz,showstatsS
1328 showstatloop:
1329   push bc
1330 ;  push ix
1331   call showstat
1332 ;  pop ix
1333   ld  de,worm2-worm1
1334   add ix,de
1335   ld  hl,_penCol
1336   ld  a,(hl)
1337   add a,10
1338   ld  (hl),a
1339   pop bc
1340   djnz showstatloop
1341   pop ix
1342   ret
1343
1344 showstat:
1345   ld  a,(gameCar)
1346   and _datalivel
1347   jr  nz,showlives
1348 showscore:
1349   ld  h,(ix+score+1)
1350   ld  l,(ix+score)
1351   call _D_HL_DECI
1352   jr __vputs
1353 showlives:
1354   ld  a,(ix+lives)
1355   add a,'0'
1356 __vputmap:
1357   push ix
1358   call _vputmap
1359   pop ix
1360   ret
1361
1362 showstatsS:
1363   ld  hl,txtLevel
1364   call __vputs
1365   ld  a,(Level)
1366   cp  10
1367   jr  c,tilllevel9
1368   ld  l,a
1369   ld  h,0
1370   call _divHLby10
1371   push af
1372   ld  a,l
1373   add a,'0'
1374   call __vputmap
1375   pop af
1376 tilllevel9:
1377   add a,'0'
1378   call __vputmap
1379
1380   ld  a,98
1381   ld  (_penCol),a
1382   call showscore
1383   ld  a,123
1384   ld  (_penCol),a
1385   call showlives
1386 showleft:
1387   ld  a,31
1388   ld  (_penCol),a
1389   ld  a,0
1390 Left =$-1
1391   push af
1392   call _divAby10
1393   add a,'0'
1394   call __vputmap
1395   pop af
1396   add a,'0'
1397   call __vputmap
1398   ld  hl,txtLeft
1399   pop ix
1400 __vputs:
1401   push ix
1402   call _vputs
1403   pop ix
1404   ret
1405
1406 showLevel:
1407   ld  hl,txtLevel
1408   call _puts
1409   ld  a,(Level)
1410 showA:
1411   cp  10
1412   jr  c,LevelBelowTen
1413   ld  l,a
1414   ld  h,0
1415   call _divHLby10
1416   push af
1417   ld  a,l
1418   add a,'0'
1419   call _putc
1420   pop af
1421 LevelBelowTen:
1422   add a,'0'
1423   jp  _putc
1424
1425 showHL:
1426   call _D_HL_DECI
1427   jp  _puts
1428
1429 _D_HL_DECI:
1430   ld  de,savestr+4
1431   ld  b,5
1432 ldhld:
1433   call _divHLby10
1434   add a,'0'
1435   ld  (de),a
1436   dec de
1437   djnz ldhld
1438   ld  hl,savestr
1439   ret
1440 savestr:
1441   .db "00000",0
1442
1443 ;-----------------------------
1444
1445 offsets_table:
1446   .db 128,64,32,16,8,4,2,1
1447
1448 DisplayField:
1449   ld  a,c
1450   sub 29
1451   jr  nc,NotMinYScroll
1452   xor a
1453 NotMinYScroll:
1454   cp  43
1455 FieldHeight =$-1
1456   jr  c,NotMaxYScroll
1457   ld  a,(FieldHeight)
1458 NotMaxYScroll:
1459   ld  l,a
1460   ld  h,0
1461   add hl,hl
1462   add hl,hl
1463   add hl,hl
1464   add hl,hl
1465   add hl,hl
1466   push bc                        ; >> 1
1467   push de                        ; >> 2
1468   ld  de,ScrBuffer
1469   add hl,de
1470   ld  a,b
1471   sub 64
1472   jr  nc,NotMinXScroll
1473   xor a
1474 NotMinXScroll:
1475   cp 128
1476 FieldWidth = $-1
1477   jr c,NotMaxXScroll
1478   ld a,(FieldWidth)
1479 NotMaxXScroll:
1480   push af                        ; >> 3
1481   and %11111000
1482   rra
1483   rra
1484   rra
1485   ld  c,a
1486   ld  b,0
1487   ld  de,DispBuffer
1488   pop af                         ; << 2
1489   and %00000111
1490   push af                        ; >> 3
1491   cp  6
1492   jr  c,CopyScreen
1493   inc c
1494 CopyScreen:
1495   add hl,bc
1496   ld b,57
1497 CopyScreenLoop:
1498   push bc                        ; >> 4
1499   ld bc,16
1500   ldir
1501   ld c,16
1502   add hl,bc
1503   pop bc                         ; << 3
1504   djnz CopyScreenLoop
1505   pop af                         ; << 2
1506   ld  c,$b7 ;or a
1507 Bit0:
1508   jr  nz,Bit1
1509   halt
1510   halt
1511   jr  AfterShiftDelay
1512 Bit1:
1513   dec a
1514   jr nz,Bit2
1515   call ShiftRight1
1516   jr AfterShiftDelay
1517 Bit2:
1518   dec a
1519   jr nz,Bit3
1520   ld a,2
1521   call ShiftRight
1522   jr AfterShiftDelay
1523 Bit3:
1524   dec a
1525   jr nz,Bit4
1526   call Chunk
1527   call ShiftLeft1
1528   jr AfterShift
1529 Bit4:
1530   dec a
1531   jr nz,Bit5
1532   call Chunk
1533   jr AfterShiftDelay
1534 Bit5:
1535   dec a
1536   jr nz,Bit6
1537   call Chunk
1538   call ShiftRight1
1539   jr AfterShift
1540 Bit6:
1541   dec a
1542   jr nz,Bit7
1543   ld a,2
1544   call ShiftLeft
1545   jr AfterShift
1546 Bit7:
1547   call ShiftLeft
1548 AfterShiftDelay:
1549   halt
1550 AfterShift:
1551   ld hl,DispBuffer
1552   ld de,$fc00+$70
1553   ld bc,1024-$70
1554   ldir
1555   pop de                         ; << 1
1556   pop bc                         ; << 0k
1557   ret
1558
1559 ShiftRight1:
1560   ld a,1
1561 ShiftRight:
1562   ld (ShiftRightCounter),a
1563   ld a,c
1564   ld (ShiftRightChunk),a
1565   ld c,16
1566   add hl,bc
1567   ld b,57
1568 ShiftRightLoop:
1569   push bc
1570   ld bc,-32
1571   add hl,bc
1572   ex de,hl
1573   ld a,(de)
1574 ShiftRightChunk:
1575   or a
1576   call c,_SHLACC
1577   ld c,0
1578 ShiftRightCounter = $-1
1579 ShiftRowsLeft:
1580   push hl
1581   rla
1582   ld b,16
1583 ShiftRowLeft:
1584   dec hl
1585   rl (hl)
1586   djnz ShiftRowLeft
1587   pop hl
1588   dec c
1589   jr nz,ShiftRowsLeft
1590   ld bc,-16
1591   add hl,bc
1592   ex de,hl
1593   pop bc
1594   djnz ShiftRightLoop
1595   ret
1596
1597 ShiftLeft1:
1598   ld a,1
1599 ShiftLeft:
1600   ld (ShiftLeftCounter),a
1601   ld a,c
1602   ld (ShiftLeftChunk),a
1603   rla
1604   jr nc,ShiftLeftSameByte
1605   dec hl
1606 ShiftLeftSameByte:
1607   ex de,hl
1608   ld bc,-16
1609   add hl,bc
1610 NewSprite:
1611   ex de,hl
1612   ld b,57
1613 ShiftLeftLoop:
1614   push bc                        ; >> 1
1615   ld bc,-32
1616   add hl,bc
1617   ex de,hl
1618   ld a,(de)
1619 ShiftLeftChunk:
1620   or a
1621   call c,_SHRACC
1622   ld c,0
1623 ShiftLeftCounter = $-1
1624 ShiftRowsRight:
1625   push hl                        ; >> 2
1626   rra
1627   ld b,16
1628 ShiftRowRight:
1629   rr (hl)
1630   inc hl
1631   djnz ShiftRowRight
1632   pop hl                         ; << 1
1633   dec c
1634   jr nz,ShiftRowsRight
1635   ld bc,-16
1636   add hl,bc
1637   ex de,hl
1638   pop bc                         ; << 0k
1639   djnz ShiftLeftLoop
1640   ret
1641
1642 Chunk:
1643   push hl                        ; >> 1
1644   push de                        ; >> 2
1645   ld  c,16
1646   add hl,bc
1647   ld  b,57
1648 ChunkScreen:
1649   push bc                        ; >> 3
1650   ld  bc,-32
1651   add hl,bc
1652   ex  de,hl
1653   ld  a,(de)
1654   call _SHRACC
1655   ld  b,16
1656 ChunkRow:
1657   dec hl
1658   rld
1659   djnz ChunkRow
1660   ex  de,hl
1661   pop bc                         ; << 2
1662   djnz ChunkScreen
1663   pop de                         ; << 1
1664   pop hl                         ; << 0k
1665   ld  c,$37 ;scf
1666   ret
1667
1668 ;----------- draw ------------
1669
1670 loaddrawdata:
1671   ld  d,(hl)
1672   inc hl
1673   ld  e,(hl)
1674   inc hl
1675   ld  a,(hl)
1676   inc hl
1677   ret
1678
1679 Line: ;draw line from de to hl (d<h)
1680   push hl
1681   push de
1682   ld a,d
1683 ;  cp h
1684 ;  jr c,lineOrdered
1685 ;  ex de,hl
1686 lineOrdered:  
1687   ld  b,d
1688   ld  c,e
1689   push hl
1690   push bc
1691   call FindPixel
1692   pop bc
1693   pop de
1694 connectedLine:
1695   push hl
1696   ld  h,c
1697   ld  c,a
1698   ld  a,d
1699   sub b
1700   ld  b,a
1701   ld  a,e
1702   jr  nz,LineNotPoint
1703   cp  h
1704   jr  nz,LineNotPoint
1705   pop hl
1706   jr  DoneLine
1707 LineNotPoint:
1708   sub h
1709   ld  de,16
1710   jr  nc,LinePositiveY
1711   neg
1712   ld  de,-16
1713 LinePositiveY:  
1714   cp  b
1715   jr  nc,SteepLine
1716   add a,a
1717   ld  (line2sm+1),a
1718   ld  h,a
1719   xor a
1720   sub b
1721   add a,a
1722   ld  (line1sm+1),a
1723   ld  a,h
1724   sub b
1725   pop hl
1726 LineLoopGentle: 
1727   push af
1728   ld  a,(hl)
1729   or  c
1730   ld  (hl),a
1731   rrc c
1732   jr  nc,$+3
1733   inc hl
1734   pop af       
1735   jp  m,line2sm
1736 line1sm:
1737   add a,0
1738   add hl,de
1739 line2sm:
1740   add a,0
1741   djnz LineLoopGentle
1742 DoneLine:
1743   ld  a,(hl)
1744   or  c
1745   ld  (hl),a
1746   pop de
1747   pop hl
1748   ret
1749 SteepLine:
1750   ld  h,a
1751   neg
1752   add a,a
1753   ld  (line3sm+1),a
1754   ld  a,b
1755   add a,a
1756   ld  (line4sm+1),a
1757   sub h
1758   ld  b,h
1759   pop hl
1760 LineLoopSteep: 
1761   push af
1762   ld  a,(hl)
1763   or  c
1764   ld  (hl),a
1765   add hl,de
1766   pop af
1767   jp  m,line4sm
1768 line3sm:
1769   add a,0
1770   rrc c
1771   jr  nc,$+3
1772   inc hl
1773 line4sm:
1774   add a,0
1775   djnz LineLoopSteep
1776   jr  DoneLine
1777
1778 drawbox:
1779  ld  b,h
1780  ld  c,l
1781  call FindPixel
1782 ;  ld  b,a
1783 ;makefirstbyte:
1784 ;  or  b
1785 ;  rr  b
1786 ;  jr  nc,makefirstbyte
1787 ;  or  (hl) ;()
1788 ;  ld  (hl),a
1789
1790   ld  b,e ;yloop
1791 boxloopy:
1792   push bc ;yloop
1793   ld  b,d ;xloop
1794 boxloopx:
1795   ld  a,%11111111
1796   ld  (hl),a
1797   inc hl
1798   djnz boxloopx
1799
1800   ld  b,0
1801   ld  a,16
1802   sub d
1803   ld  c,a
1804   add hl,bc
1805   pop bc ;yloop
1806   djnz boxloopy
1807   ret
1808
1809 ;-----------------------------
1810 ;----------- link ------------
1811 ;-----------------------------
1812
1813 send:
1814   push af ;ld b,a
1815   call _getcsc
1816   cp  K_EXIT
1817   jp  z,Exit
1818   pop af ;ld a,b
1819   call SendByte
1820 ;  jr  c,send
1821   ret
1822
1823 linkfail:
1824   jp  Exit
1825
1826 LinkPrep:
1827   ex  (sp),hl
1828   push bc
1829   push de
1830   set 2,(iy+$12) ;cursorblink
1831   ld  b,8
1832   jp  (hl)
1833
1834 receive:
1835   call checklink
1836   jr  z,linkfail
1837   cp  %11
1838   jr  z,receive
1839 ReceiveByteCont:
1840   call LinkPrep
1841   jr  ReceiveCont
1842 ReceiveByte:
1843   call LinkPrep
1844 ReceiveBits:
1845 WaitRecBit:
1846   call checklink
1847   jr  z,LinkFailed
1848   cp  %11
1849   jr  z,WaitRecBit
1850 ReceiveCont:
1851   sub %10
1852   ld  a,%10 
1853   ld  d,D0lD1h
1854   jr  c,ReceiveLow
1855   rra
1856   ld  d,D0hD1l
1857 ReceiveLow:
1858   rr  c
1859   ld  (AckBit),a
1860   ld  a,d
1861   out (7),a
1862 WaitAckRec:
1863   call checklink
1864   cp  0
1865 AckBit =$-1
1866   jr  nz,WaitAckRec
1867   ld  a,D0hD1h
1868   out (7),a
1869   ld  d,4
1870 WaitReadyRec:
1871   dec d
1872   jr  z,ReadyRec
1873   in  a,(7)
1874   cp  %11
1875   jr  nz,WaitReadyRec
1876 ReadyRec:
1877   djnz ReceiveBits
1878   jr  LinkSuccess
1879
1880 SendByte:
1881   call LinkPrep
1882   ld  c,a
1883   inc b
1884   jr  SendAcked
1885 SendBits:
1886   rr  c
1887
1888 sendbit:
1889   ld  a,D0lD1h
1890   jr  nc,sendselected
1891   ld  a,D0hD1l
1892 sendselected:
1893   out (7),a
1894 waitacknowledge:
1895   call checklink
1896   jr  nz,waitacknowledge
1897 SendAcked:
1898   ld  a,D0hD1h
1899   out (7),a
1900 waitsendready:
1901   call checklink
1902   cp  %11
1903   jr  nz,waitsendready
1904
1905   djnz SendBits
1906 LinkSuccess: ;nc
1907   .db $f6 ;first byte of "or n"
1908 LinkFailed:  ;c
1909   scf
1910   ld  a,c
1911   res 2,(iy+$12) ;noblink
1912   pop de
1913   pop bc
1914   pop hl
1915   ret
1916
1917 linkerror:
1918   jp  Exit
1919
1920 checklink:
1921   ld  a,$BF ;key
1922   call _readkeypad
1923   bit 6,a
1924   jr  z,linkerror
1925
1926   in  a,(7)
1927   and %11
1928   ret
1929
1930 _readkeypad:
1931   out (1),a
1932   in  a,(1)
1933   push af
1934   ld  a,%11111111
1935   out (1),a
1936   pop af
1937   ret
1938
1939 ;-----------------------------
1940 ;---------- levels -----------
1941 ;-----------------------------
1942
1943 LevelsDM:
1944
1945   .db 8,5,15
1946   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
1947   .db 128,57
1948   .db 0,0
1949
1950 LevelsDM2:
1951
1952   .db 8,5,31
1953   .db $40,28,2,$C0,28,125, $00,2,63,$80,54,63
1954   .db 128,57
1955   .db 0
1956   .db 4             ;4 boxes
1957   .db 4,19,16,14    ;xsize,ysize,xpos,ypos
1958   .db 4,19,80,14
1959   .db 4,19,16,34
1960   .db 4,19,80,34
1961
1962 LevelsR:
1963   .db 8,5,24
1964   .db $40,3,2,$40,6,2, $40,9,2,$40,12,2
1965   .db 128,57
1966   .db 0
1967   .db 1
1968   .db 8,29,32,20
1969
1970 LevelsH:
1971
1972   .db 8,5,5
1973 huntersize = 31
1974   .db $40,28,2,$C0,28,125, $00,2,63,$80,54,63
1975   .db 128,57
1976   .db 0
1977   .db 4
1978   .db 4,19,16,14
1979   .db 4,19,80,14
1980   .db 4,19,16,34
1981   .db 4,19,80,34
1982
1983 NUM_LEVELS = 9
1984
1985 LevelsS:
1986
1987   .db 5,4,15        ;peas,speed,begin_size
1988   .db 0,2,63        ;d,y,x
1989   .db 128,57        ;field width, height
1990   .db 0             ;no additional lines
1991   .db 0             ;no boxes
1992
1993   .db 8,4,15
1994   .db $40,14,2
1995   .db 128,57
1996   .db 1
1997   .db 28,28,100,28  ;line coords: x1,y1,x2,y2
1998   .db 0
1999
2000   .db 9,4,15
2001   .db $40,8,2
2002   .db 128,57
2003   .db 2
2004   .db 28,14,100,14
2005   .db 28,41,100,41
2006   .db 0
2007
2008   .db 9,3,15
2009   .db $40,8,2
2010   .db 128,80
2011   .db 2
2012   .db 64,14,64,66
2013   .db 20,40,108,40
2014   .db 0
2015
2016   .db 10,3,15
2017   .db 2,8,$40
2018   .db 128,90
2019   .db 3
2020   .db 18,20,18,70
2021   .db 110,20,110,70
2022   .db 18,45,110,45
2023   .db 0
2024
2025   .db 7,3,15
2026   .db 64,4,0
2027   .db 128,86
2028   .db 6
2029   .db 34,13,56,35
2030   .db 34,71,56,49
2031   .db 72,35,94,13
2032   .db 72,49,94,71
2033   .db 16,20,16,64
2034   .db 110,20,110,64
2035   .db 0
2036
2037   .db 9,2,15
2038   .db 4,10,$40
2039   .db 128,82
2040   .db 3
2041   .db 0,20,74,20
2042   .db 54,40,128,40
2043   .db 0,60,74,60
2044   .db 0
2045
2046   .db 12,2,15
2047   .db 64,4,0
2048   .db 128,90
2049   .db 6
2050   .db 20,16,54,16
2051   .db 74,16,110,16
2052   .db 20,16,20,72
2053   .db 110,16,110,72
2054   .db 20,72,54,72
2055   .db 74,72,110,72
2056   .db 0
2057
2058   .db 8,2,15
2059   .db 72,52,$c0
2060   .db 128,128
2061   .db 13
2062   .db 34,56,56,34
2063   .db 34,72,56,94
2064   .db 72,34,94,56
2065   .db 72,94,94,72
2066   .db 46,64,80,64
2067   .db 22,11,22,33
2068   .db 11,22,33,22
2069   .db 22,95,22,117
2070   .db 11,106,33,106
2071   .db 103,11,103,33
2072   .db 91,22,115,22
2073   .db 103,95,103,117
2074   .db 91,106,115,106
2075   .db 0
2076
2077
2078 ;-----------------------------
2079 ;---------- data -------------
2080 ;-----------------------------
2081
2082 TrigPrecalc:
2083 .db   0,  3,  6,  9, 12, 15, 18, 21
2084 .db  24, 27, 30, 33, 36, 39, 42, 45
2085 .db  48, 51, 54, 57, 59, 62, 65, 67
2086 .db  70, 73, 75, 78, 80, 82, 85, 87
2087 .db  89, 91, 94, 96, 98,100,102,103
2088 .db 105,107,108,110,112,113,114,116
2089 .db 117,118,119,120,121,122,123,123
2090 .db 124,125,125,126,126,126,126,126
2091 .db 127
2092
2093 txtWelcome: .db "Welcome to Worm!! ",
2094             .db "by Shiar",0
2095 txtOptions: .db "Options",0
2096 txtGame:    .db "Singleplayer",0  ;0
2097 txtGame2:   .db "Deathmatch  ",0  ;1
2098             .db "Foodmatch ",0    ;2
2099             .db "LinkMatch",0     ;3 (>options)
2100             .db "Hunting  ",0     ;4
2101             .db "Race   ",0       ;5
2102             .db "CTF ",0          ;6
2103             .db "Domination",0    ;7
2104 txtWaiting: .db "Waiting...",0
2105 txtReceive: .db "Receiving...",0
2106
2107 WormVersion = 092
2108 WormMsg:  .db "WORM by SHIAR -- test version",0
2109 txtLevel: .db "Level ",0
2110 txtWorms: .db "Worms: 0",0 ;follows txtLevel
2111 txtDied:  .db "Died ",0
2112 txtScore: .db "Score",0  ;follows txtDied
2113 txtLeft:  .db " left",0   ;follows txtScore
2114 txtReady: .db "Prepare!",0
2115 txtposReady = 7
2116 txtGO:    .db "----- GAME OVER -----",0
2117 HiScore:  .db 0
2118
2119 gamesdata:
2120
2121 _datalink  = %00000001
2122 _datalivel = %00000010 ;ix+lives=0 limit
2123 _datafoodl = %00000100 ;left=0 limit
2124 _datanextl = %00001000 ;next level if left=0
2125 _datafood  = %00010000 ;food present
2126 _datahunt  = %00100000
2127 _datalaps  = %01000000 ;give lap score
2128 _datascore = %10000000 ;score>=100 limit
2129
2130 datasingle: .db %00011110
2131             .dw LevelsS
2132 datadeathm: .db %00000010
2133             .dw LevelsDM2
2134 datafoodm:  .db %10010000
2135             .dw LevelsDM
2136 datalinkm:  .db %00000011
2137             .dw LevelsDM
2138 datahuntin: .db %00110100
2139             .dw LevelsH
2140 datarace:   .db %11000000
2141             .dw LevelsR
2142 datactf:    .db %00000000
2143             .dw LevelsDM
2144 datadomin:  .db %00000000
2145             .dw LevelsDM
2146
2147
2148 setdata = 18
2149 resbit  = 2 ;and%11111011
2150 worm1set:  .dw $B000,$B000 ;%10110000
2151            .db 3,0,%01111110,%10,%100 ;< >
2152            .db "Worm #1",0
2153 worm2set:  .dw $B800,$B800 ;%10111000
2154            .db 3,0,%00111111,%10000,%1000 ;f1 f2
2155            .db "Worm #2",0
2156 worm3set:  .dw $E800,$E800 ;%11101000 ;$D748+$1000+
2157            .db 3,0,%01011111,%10,%100 ;sto ,
2158            .db "Worm #3",0
2159 worm4set:  .dw $F000,$F000 ;%11110000
2160            .db 3,0,%01111101,%10,%1 ;enter +
2161            .db "Worm #4",0
2162 worm1 = $B400
2163 worm2 = $B430
2164 worm3 = $B460
2165 worm4 = $B490
2166 end:
2167               ;set:
2168 heading = 0   ;level*
2169 pos     = 2   ;level*
2170 pos2    = 4   ;level
2171 grow    = 6   ;level
2172 died    = 8   ;game
2173 score   = 9   ;game
2174 delay   = 11  ;game
2175
2176 head    = 12  ;level
2177 tail    = 14  ;level
2178 lives   = 16  ;game
2179 reserv  = 17  ;loop
2180  ;race:lap
2181  ;hunt:time
2182 input   = 18  ;&
2183 left    = 19  ;&
2184 right   = 20  ;&
2185 name    = 21  ;game
2186
2187 Level =$+1
2188 DispBuffer =$+2 ;912 bytes
2189
2190 ScrBuffer   = $8000 ;-$A1FF (32x256)
2191 SinCosTable = $A200 ;-$A300 (4x64)
2192
2193 ;-----------------------------
2194 ;----------- end -------------
2195 ;-----------------------------
2196
2197 .end