wormy 0.93.1331: overhaul levelset selection
[wormy.git] / wormy.z80
1 ; Title                      : Wormy
2 ; Version                    : 93%
3 ; Release Date               : summer 2001
4 ; Filename                   : wormy.86p (5kb)
5 ; Author(s)                  : Shiar
6 ; Email Address              : shiar0@hotmail.com
7 ; ICQ UIN                    : #43840958
8 ; Web Page                   : www.shiar.org
9 ; Description                : ruling Nibbles-like game 1-4 players
10 ; Where to get this game     : www.shiar.org (home of Wormy)
11 ; Other games by author(s)   : Nemesis beta
12 ; Additional Credits to      : Matthew Shepcar (wrote original Peaworm, end'98)
13 ;                              Jonah Cohen (helped writing worm)
14
15 ;-----------------------------
16 ;----------- TO-DO -----------
17 ;-----------------------------
18
19 ; 93% = DONE
20
21 ;     * internal levels
22 ;       * check levels/gametype
23 ;       * enough hiscore saves!
24 ;     * complete readme
25 ;  1% * misc (pollish, bugs, &&&)
26 ;   * LINK
27 ;  2% * fix deaths linkplay and transmit game/level data
28 ;  2% * make linkplay available for all gametypes (not just deathmatch)
29 ;   * CTF
30 ;  1% * fix pea XOR problem in ctf (+dom?)
31 ;     * fix wormstop
32 ;  1% * domination?: take control points by running over them and hold them
33
34 ;100% = bugs fixed + levels done
35
36 ;-----------------------------
37 ;-----------------------------
38 ;---------  W O R M  ---------
39 ;-----------------------------
40 ;-----------------------------
41
42 #define buffer      ;use display buffer (otherwise write directly to screen)
43 #define readymask   ;"grays" out the field before starting a level
44 ;#define hlines     ;horizontal-line routine for more speed drawing boxes
45
46 ;#define readytext  ;displays "prepare" before level starts
47 ;#define invincible ;worms cannot die =)
48
49 #define cal call
50 #define psh push
51 #define dnz djnz
52
53 #include "asm86.h"
54 #include "ti86asm.inc"
55
56 _SHRACC            = $4383
57 _SHLACC            = $438B
58 _divHLby10         = $4044 ;hl=hl/10
59 _divAby10          = $4DAF ;a=a/10
60 _HLTIMES10         = $41BF ;hl=hl*10
61 _cphlde            = $403C
62 _clrWindow         = $4A86 ;clear screen
63 _asapvar           = $D6FC ;own name (worm)
64 _MOV4B             = $429B ;4x ld (de),(hl)
65 _MOV5B             = $4297 ;5x ld (de),(hl)
66 _mov9b             = $4283 ;9x ld (de),(hl)
67 _ldHLind           = $4010 ;ld hl,(hl)
68 _swapt_            = $45F3 ;ex_ahl_bde
69 _Get_Word_ahl      = $521D ;ld de,(ahl)
70 _Set_Word_ahl      = $5221 ;ld (ahl),de
71 _INC_PTR_AHL       = $4637 ;ahl=ahl+1
72 _AHL_PLUS_2_PG3    = $4C3F ;ahl=ahl+2
73 _SET_ABS_SRC_ADDR  = $4647 ;set source for mm.ldir =ahl
74 _LOAD_ABS_SRC_ADDR = $5209 ;ahl = mm.ldir source
75 _SET_ABS_DEST_ADDR = $5285 ;set destination for mm.ldir = ahl
76 _SET_MM_NUM_BYTES  = $464F ;number of bytes for mm.ldir = ahl
77 _mm_ldir           = $52ED ;24bit ldir
78 _RAM_PAGE_1        = $47E3 ;set $8000+ to page 1
79 _RAM_PAGE_7        = $47F3
80 _PTEMP_END         = $D29A ;end of VAT
81 _load_ram_ahl      = $462F ;ahl->page+hl
82 _writeb_inc_ahl    = $5567 ;ld (ahl),c
83 _jforce            = $409C ;TI-OS stack restored
84 _EXLP              = $4493 ;swap (hl),(de) b times
85 _GETB_AHL          = $46C3 ;a=(ahl) \ hl=ahl
86
87 ;-----------------------------
88 ;------- data  storage -------
89 ;-----------------------------
90
91 ;--- permanent
92
93 ScrBuffer   = $8820 ;-A7FF (20*FF=1FE0)
94 worm2p      = $A800 ;-ABFF (400)      %10101O00
95 worm1       = $AC00 ;-AC1D (31d)
96 worm2       = $AC1F ;-AC3B (1F)
97 worm3       = $AC3E ;-AC59 (1F)
98 worm4       = $AC5D ;-AC77 (1F)
99 balls       = $AC7C ;-ACFF (3x43d)
100 SinCosTable = $AD00 ;-AE00 (4x40)
101         ;free $AE01 ;-AFFF (1FF)
102 worm1p      = $B000 ;-B7FF (800)      %1011O000
103 worm3p      = $B800 ;-BBFF (400)      %10111O00
104         ;free $BF91 ;-BFFF (6F)
105
106      ;program $D748 ;-E7FF (106D+4A)
107         ;free $E800 ;-EFFF (800)
108 worm4p      = $F000 ;-F3FF (400)      %11110O00
109 leveldata   = $F400 ;-FA70 (<=671)
110
111 peaspos = $AE01
112
113 ;--- temporary
114
115 namelength  = $BC00 ;(1)         @menu
116 #ifdef buffer
117 DispBuffer  = $BC00 ;(10x57d)    @game
118 #else
119 DispBuffer  = $FC70
120 #endif
121
122 ;-----------------------------
123 ;------- program start -------
124 ;-----------------------------
125
126 .org _asm_exec_ram
127
128 wormVhost   = 093
129 wormVclient = 193
130
131 start:
132   nop
133   jp Start
134   .dw 1
135   .dw WormTxt
136   .dw WormIcon
137
138 WormTxt:
139   .db "WORMY by SHIAR -- alpha 93%",0
140 WormIcon:
141   .db 9,2
142   .db %10010110,%01101111
143   .db %10110101,%01001011
144   .db %01110011,%01001001
145   .db %00000011,%10000000
146   .db %00000001,%11100000
147   .db %00111000,%11111000
148   .db %01111110,%00111111
149   .db %11101111,%00001111
150   .db %11000011,%10000000
151
152 levelhead  = 'w'
153 levelhead2 = 93 ;wormy levels header = "93"
154
155 int_handler:
156   ex af,af'
157   in a,($03)
158   bit 3,a
159   jp z,$0039
160   res 0,a
161   out ($03),a
162   jp $0039
163 int_end:
164
165 Start:
166   ld  (SpSave),sp
167   cal _runindicoff
168   cal _flushallmenus
169
170   im  1
171   ld  a,$D4
172   ld  h,a
173   ld  l,0     ;ld hl,$D400
174   ld  d,a
175   ld  e,1     ;ld de,$D401
176   ld  b,e
177   ld  c,l     ;ld bc,$0100
178   dec a       ;ld a,$D3
179   ld  (hl),a
180   ldir
181   ld  hl,int_handler
182   ld  d,a
183   ld  e,a     ;ld de,$D3D3
184   ld  bc,int_end-int_handler
185   ldir
186   inc a       ;ld a,$D4
187   ld  i,a
188   im  2
189
190   cal _RAM_PAGE_7
191   ld  hl,$BFFF ;VAT start
192   ld  ix,templevels
193 searchloop:
194   ld  de,(_PTEMP_END+1) ;VAT end
195   or  a ;nc
196   sbc hl,de ;hl<de?
197   jr  c,searchcomplete
198   add hl,de
199   psh hl
200   ld  a,(hl)
201   cp  $0C ;string
202   jr  z,stringfound
203 searchnext:
204   pop hl
205   dec hl ;5x
206   dec hl
207   dec hl
208   dec hl
209   dec hl
210   ld  b,(hl) ;name size
211   inc b
212 skipname:
213   dec hl
214   dnz skipname
215   jr  searchloop
216
217 stringfound:
218   dec hl
219   ld  e,(hl)
220   dec hl
221   ld  d,(hl)
222   dec hl
223   ld  a,(hl)
224   ex  de,hl ;ld ahl,(hl)
225   cal _AHL_PLUS_2_PG3 ;string id
226   cal _Get_Word_ahl ;ld de,(ahl)
227   ld (ix),a
228   ld  a,levelhead
229   cp  e
230   jr  nz,_searchnext ;not worm
231   ld  a,levelhead2
232   cp  d
233   jr  nz,_searchnext
234   inc ix ;save level's ahl
235   ld a,h
236   ld (ix),a
237   inc ix
238   ld a,l
239   ld (ix),a
240   inc ix
241 _searchnext:
242   cal _RAM_PAGE_7
243   jr searchnext
244
245 loadgametype:
246   psh de
247   inc bc
248   inc bc
249   cal _Get_Word_ahl ;ld de,(ahl++)
250   psh af
251   ld  a,d
252   or  e
253   jr  z,defaultlevels
254   ld  a,e ;set new level
255   ld  (bc),a
256   inc bc
257   ld  a,d
258   ld  (bc),a
259   dec bc
260 defaultlevels:
261   pop af
262   pop de ;counter
263   dec d ;8x
264   jr  nz,loadgametype
265   ret
266
267 searchcomplete:
268   ld  a,255
269   ld  (ix),a ;end mark
270
271   cal _clrWindow
272   ld  hl,templevels-3
273   psh hl
274   ld  hl,$0020
275   ld  (_penCol),hl
276   ld  hl,txtLevsel
277   cal _vputs ;"< Select levels: >"
278   ld  hl,$0601 ;x=1
279   ld  (_penCol),hl
280   pop hl
281 dispnextlevel:
282   ld  a,(hl)
283   inc a ;cp 255
284   jr  z,_levselect
285   ld  a,(hl) ;ade=(hl)
286 displevel:
287   inc hl
288   ld  d,(hl)
289   inc hl
290   ld  e,(hl)
291   inc hl
292   psh hl
293   ex  de,hl ;ahl=ade=(hl)
294   cal _load_ram_ahl ;hl=ahl
295   ld  b,(hl) ;b=title size
296   cal _vputs
297   ld  hl,_penCol
298   ld  (hl),$01 ;x=1
299   inc hl
300   ld  a,(hl)
301   add a,6
302   ld  (hl),a ;y+6
303   ld  hl,availevels
304   inc (hl)
305   pop hl
306   jr  dispnextlevel
307
308 levup:
309   cal menupos
310   dec b ;up
311   ld  a,b
312   cp  -4
313   jr  nz,levselected
314   inc b ;undo
315   jr  levselected
316 levdown:
317   cal menupos
318   inc b ;down
319   ld  a,b
320   cp  -3
321 availevels =$-1
322   jr  nz,levselected
323   dec b ;back up
324 levselected:
325   jp  menupos
326
327 _levselect:
328   ld  b,-3 ;level selected
329   cal menupos
330 levselect:
331   halt \ halt
332   psh bc
333   cal GET_KEY
334   pop bc ;GET_KEY destr. b
335   cp  K_UP
336   cal z,levup
337   dec a ;K_DOWN
338   cal z,levdown
339   cp  K_SECOND-1
340   jr  z,loadlevel
341   cp  K_EXIT-1
342   ret z
343   cp  K_ENTER-1
344   jr  nz,levselect
345 ; jr  z,loadlevel
346
347 loadlevel:
348   ld  a,b
349   add a,3 ;sellev+3 (#0==-3)
350   ld  e,a
351   add a,a ;*2
352   add a,e ;*3
353   ld  e,a
354   ld  d,0 ;de=sellev*3
355   ld  hl,templevels-3
356   add hl,de
357   ld  a,(hl) ;ade=(hl)
358   or  a ;levelfile on page 0 (=internal)
359   jr  z,levelloaded
360
361   inc hl
362   ld  d,(hl)
363   inc hl
364   ld  e,(hl)
365   ex  de,hl ;ahl=ade
366 skiptitle:
367   ld  b,a ;psh ahl
368   psh hl
369   cal _GETB_AHL ;ld a,(ahl)
370   pop hl
371   or  a
372   ld  a,b ;pop ahl
373   psh af
374   cal _INC_PTR_AHL ;ahl++
375   pop af ;cp 0
376   jr  nz,skiptitle ;goto #0-terminator
377
378   cal _Get_Word_ahl
379   ld  (leveldataSize),de
380   ld  d,8 ;counter
381   ld  bc,datalevels-2
382   cal loadgametype
383   ld  (hilvlposa),a
384   ld  (hilvlposhl),hl
385   ld  d,4
386   cal loadgametype
387
388   cal _SET_ABS_SRC_ADDR ;levelsstart
389   xor a
390   ld  hl,leveldata
391   cal _SET_ABS_DEST_ADDR ;store in mem.
392   ld  hl,0
393 leveldataSize =$-2
394   cal _SET_MM_NUM_BYTES
395   cal _mm_ldir
396
397   cal _LOAD_ABS_SRC_ADDR ;->ahl
398   ld  (hiscrposa),a
399   ld  (hiscrposhl),hl
400   cal _RAM_PAGE_1
401
402   ld  hl,leveldata
403   ld  de,defsprsize
404   ldi ;(de),(hl)\inc hl
405   ld  (defsprite),hl
406 levelloaded:
407   cal _RAM_PAGE_1
408
409   res 2,(iy+13) ;appAutoScroll
410   ld  a,r
411   ld  (Seed),a
412
413   ld  hl,datasingle+3
414   ld  b,8
415 setdeflevels:
416   ld  (hl),1 ;def=level#1
417   inc hl
418   inc hl
419   inc hl
420   inc hl
421   dnz setdeflevels
422
423 ;-----------------------------
424 ;----- build trig tables -----
425 ;-----------------------------
426
427   ld  hl,TrigPrecalc
428   ld  de,SinCosTable
429   psh de                        ; >> 1
430   ld  bc,65
431   ldir
432   dec hl
433   ld  b,63
434 MirrorSineWave:
435   dec hl
436   ld  a,(hl)
437   ld  (de),a
438   inc de
439   dnz MirrorSineWave
440   pop hl                         ; << 0k
441   ld  b,128+64
442 NegativeSineWave:
443   xor a
444   sub (hl)
445   ld  (de),a
446   inc hl
447   inc de
448   dnz NegativeSineWave
449
450 ;-----------------------------
451 ;---------- menu -------------
452 ;-----------------------------
453
454 DisplayMenu: ;---draw menu---
455   cal _clrWindow
456   ld  de,$FC40 ;(0,4)
457   ld  hl,wtPicture
458   ld  bc,16*16
459   ldir
460
461   ld  hl,txtMenu
462   ld  ix,posMenu
463   ld  b,6
464 dispmenuloop:
465   ld  d,(ix)
466   inc ix
467   ld  e,(ix)
468   inc ix
469   ld  (_penCol),de
470   cal _vputs ;Mode \ Level \ Limit \ Worms \ worm # \ controls
471   dnz dispmenuloop
472
473   ld  b,0 ;b=menu#
474   jr  _dispmenusets ;mainMenu
475
476 ;--- menu loop ---
477
478 mainMenu:
479   cal menupos
480   cal menucall
481   jr  nz,notselect
482 select:   ;2nd/enter
483   cal menupos
484   ld  a,b
485   sub 4 ;4th item?
486   jp  z,changeworms
487   dec a ;5th?
488   jp  z,changekeys
489   jp  LetsGetThisPartyOn ;1/2/3/5
490 notselect
491   cp  K_EXIT
492   jp  z,ExitNoStats
493   psh af
494   cal menupos
495   cal loadgamecar
496   inc hl
497   pop af
498   cp  K_LEFT
499   jr  z,selleft
500   cp  K_RIGHT
501   ld  a,b
502   jr  nz,mainMenu
503
504 selright:
505   or  a
506   jr  z,changegame
507   dec a
508   jp  z,changelevel ;&&&jr??
509   dec a
510   jr  z,changelives
511   dec a
512   jr  z,changenrworms
513 ; dec a
514 ; jr  z,changecurworm
515
516 changecurworm:
517 ; hl=nrworms
518   ld  a,(curworm)
519   cp  (hl)
520   jr  nc,mainMenu ;may not become >(nrworms)
521   inc a
522 changedcurworm:
523   ld  (curworm),a
524   jr  _dispmenusets ;mainMenu
525
526 selleft:
527   ld  a,b
528   or  a
529   jr  z,bchangegame
530   dec a
531   jr  z,bchangelevel
532   dec a
533   jr  z,bchangelives
534   dec a
535   jr  z,bchangenrworms
536 ; dec a
537 ; jr  z,bchangecurworm
538
539 bchangecurworm:
540   ld  a,(curworm)
541   dec a ;0-3
542   jr  nz,changedcurworm ;save >0
543   jr  mainMenu
544
545 changenrworms:
546   ld  a,(Gametype)
547   cp  2
548   jr  c,mainMenu ;type 0/1
549   ;hl=nrworms
550   ld  a,(hl)
551   inc a
552   cp  5
553   jr  nc,mainMenu ;may not be >4
554 changednrworms:
555   ld  (hl),a
556 _dispmenusets:
557   jr  dispmenusets ;mainMenu
558 bchangenrworms:
559   ;hl=nrworms
560   ld  a,(hl)
561   dec a ;0-3
562   jr  nz,changednrworms ;save >0
563 _mainMenu:
564   jr  mainMenu
565
566 changegame:
567   ld  a,0
568 Gametype =$-1
569   inc a
570 changedgame:
571   and 7 ;mod 8
572   ld  (Gametype),a
573   jr  dispmenusets ;mainMenu
574 bchangegame:
575   ld  a,(Gametype)
576   dec a
577   jr  changedgame
578
579 changelives:
580   cal changelivesInit
581   inc a
582   cp  100
583   jr  nc,_mainMenu ;&& _?
584 changedlives:
585   ld  (hl),a
586   jr  dispmenusets ;mainMenu
587 bchangelives:
588   cal changelivesInit
589   dec a
590   jr  z,_mainMenu
591   jr  changedlives
592 changelivesInit:
593   cal loadgamecar ;c=(gameCar)
594 ;a=(hl)=(Gametype+1)=(wormbeglives)
595   ld  a,(Gametype) ;&&&
596   cp  3
597   ld  a,(hl)
598   ret nc ;change lives
599   pop hl ;restore stack
600   jr  _mainMenu ;singleplayer (no limit)
601
602 changelevel:
603   inc hl ;hl=loadgamecar+2
604   psh hl
605   ld  a,(hl) ;(curlevel)
606   ld  hl,Gametype
607   ld  d,0
608   ld  e,(hl)
609   ld  hl,nrlevels
610   add hl,de
611   cp  (hl) ;max level for sel.game
612   pop hl
613   jr  z,_mainMenu
614   inc a
615 changedlevel:
616   ld  (hl),a
617   jr  dispmenusets ;mainMenu
618 bchangelevel:
619   inc hl
620   ld  a,(hl) ;(curlevel)
621   dec a
622   jr  nz,changedlevel
623   jr  _mainMenu
624
625 getcustomkey:
626   cal _vputs
627   dec ix
628 waitcustomkey:
629   halt \ halt
630   psh hl
631   cal GET_KEY
632   pop hl
633   or  a
634   jr  z,waitcustomkey
635   cp  K_EXIT
636   ret z
637   cp  K_MORE
638   jr  z,waitcustomkey
639   ld  (ix),a
640   ret
641
642 changekeys:
643   cal getwormname
644   ld  hl,txtKeyleft
645   cal getcustomkey ;left
646   cal getcustomkey ;right
647 ; jr  dispmenusets
648
649 ;---display current settings---
650
651 dispmenusets:
652   ld  hl,$FD97 ;begin pos
653   ld  de,7 ;bytes to add
654   ld  a,35 ;nr of lines
655 clroldsettings:
656   ld  c,9 ;bytes to clear
657 clroldsetsloop:
658   ld  (hl),d ;=0
659   inc hl
660   dec c
661   jr  nz,clroldsetsloop
662   add hl,de
663   dec a
664   jr  nz,clroldsettings
665
666   ld  de,$183E
667   ld  (_penCol),de
668   ld  d,0
669   ld  a,(Gametype)
670   ld  e,a
671   ld  hl,posGame
672   add hl,de ;hl=posGame+(Gametype)
673   ld  a,(hl) ;str.offset
674   ld  e,a ;^d=0^
675   ld  hl,txtGame
676   add hl,de ;txtGameX
677   ld  (CURtxtGame),hl ;save for g/o
678   cal _vputs ;Singleplayer
679
680   cal loadgamecar
681   psh hl
682   ld  hl,$243E
683   ld  (_penCol),hl
684   cal cshowA ;liveslimit
685   sub '0' ;original A
686   ld  l,a
687   ld  a,c
688   and _datascore
689   ld  a,' '
690   jr  z,limitok
691   ld  a,'0'
692 limitok:
693   cal _vputmap ;x10
694
695   ld  hl,$2A3E ;worms
696   ld  (_penCol),hl
697   pop hl ;cal loadgamecar
698   inc hl
699   psh hl
700   ld  a,(hl)
701   add a,'0'
702   cal _vputmap
703
704   ld  hl,$1E3E ;level
705   ld  (_penCol),hl
706   pop hl ;loadgamecar; hl++
707   inc hl
708   ld  a,(hl) ;(curlevel)
709   cal cshowA
710
711   ld  hl,$3032
712   ld  (_penCol),hl
713   ld  a,1
714 curworm =$-1
715   add a,'0'
716   cal _vputmap
717   ld  hl,$303E
718   ld  (_penCol),hl
719   cal getwormname
720   ld  hl,worm1name-18
721   add hl,de
722   cal _vputs
723   ld  hl,$363E ;controls
724   ld  (_penCol),hl
725 ;  ld  hl,txtMenu
726 ;  cal _vputs
727   jp  mainMenu
728
729 ;--- handle menukeys ---
730
731 menucall:
732   psh bc
733 menuwaitkey:
734   halt \ halt
735   cal GET_KEY
736   or  a
737   jr  z,menuwaitkey
738   pop bc ;GET_KEY destr. b
739   cp  K_UP
740   cal z,menuup
741   cp  K_DOWN
742   cal z,menudown
743   cp  K_ENTER
744   ret z
745   cp  K_SECOND
746   ret ;z=select
747
748 menupos: ;highlight #b
749   ld  c,b ;psh b
750   ld  a,b
751   add a,3
752   add a,a
753   add a,a
754   sub b
755   add a,a
756   add a,a
757   add a,a ;*24
758   ld  h,$FC/4
759   ld  l,a
760   add hl,hl
761   add hl,hl ;$FD20+item*96
762   ld  b,16*7
763 menuinvloop:
764   ld  a,(hl)
765   cpl
766   ld  (hl),a
767   inc hl
768   dnz menuinvloop
769   ld  b,c ;pop b
770   ret ;a=-1
771 menudown:
772   cal menupos
773   inc b
774   jr  menuupdown
775 menuup:
776   cal menupos
777   dec b
778 menuupdown:
779   ld  a,b
780   cp  6
781   jr  nz,menunewchk
782   xor a ;6=0
783 menunewchk:
784   inc b
785   jr  nz,menunewok
786   ld  a,5 ;-1=5
787 menunewok:
788   ld  b,a
789   jr  menupos
790
791 ;--- change name ---
792 ; of worm#(curworm)
793
794 getwormname: ;of (curworm)
795   ld  a,(curworm)
796   add a,a  ;2x
797   ld  e,a
798   add a,a  ;4x
799   add a,a  ;8x
800   add a,a ;16x
801   add a,e ;18x
802   ld  e,a
803   ld  d,0 ;de=a
804
805   ld  ix,worm1name-18
806   add ix,de
807   ret
808
809 changeworms:
810   cal _clrWindow
811   ld  hl,txtEName
812   cal _puts ;"Enter name player "
813   ld  a,(curworm)
814   add a,'0'
815   cal _putc
816
817   cal getwormname
818   ld  a,maxnamelength
819   cal entername
820   ld  (ix),0 ;end mark
821   jp  DisplayMenu
822
823 entername:
824   ld  h,1
825   ld  l,h ;)
826   ld  (_curRow),hl
827   ld  (namelength),a
828 enternameloop:
829   ld  a,'_'
830   cal _putc
831   ld  hl,_curCol
832   dec (hl)
833 nokeypressed:
834   halt
835   cal GET_KEY
836   or  a
837   jr  z,nokeypressed
838
839   cp  K_DEL
840   jr  nz,continue
841 backspace:
842   ld  hl,namelength
843   ld  a,(hl)
844   cp  maxnamelength
845   jr  nc,nokeypressed
846   inc (hl)
847
848   dec ix
849   ld  a,' '
850   ld  (ix),a
851   cal _putc
852   ld  hl,_curCol
853   dec (hl)
854   dec (hl)
855   jr  enternameloop
856 continue:
857   cp  K_ENTER
858   ret z
859   cp  K_EXIT
860   ret z
861
862   ld  hl,namelength
863   dec (hl)
864   ret z
865
866   ld  hl,chartable
867   ld  e,a
868   ld  d,0
869   add hl,de
870   ld  a,(hl)
871   or  a
872   jr  z,nokeypressed
873
874   ld  (ix),a
875   cal _putc
876   inc ix
877   cal releasekeys
878   jr  enternameloop
879
880
881 chartable:
882   .db 0,".<>!",0,0,0,0  ;down,L,R,up
883   .db 0,"XTOJE0",0      ;enter..clear
884   .db " WSNID9",0       ;(-)..custom
885   .db "ZVRMHC8",0       ;dot..del
886   .db "YUQLGB7#"        ;0..xvar
887   .db $D9,"-PKFA6'"     ;on..alpha
888   .db "54321*",0,$D0    ;F5..more
889
890 ;--proc
891
892 skiplevel: ;@hl - destr:ab - alter:hl
893   inc hl
894   inc hl
895   inc hl
896   inc hl ;skip 4
897   ld  b,(hl) ;spritesize
898   inc b
899 skipsprite:
900   inc hl
901   dnz skipsprite
902   ld  b,(hl) ;balls
903   inc b
904   inc b ;skip 6
905   ld  a,c
906   cp  _datasp
907   jr  z,skipworms
908   inc b ;multiplayer lvl
909   inc b
910   inc b ;skip other 3 worms (9 bytes)
911 skipworms:
912   ld  a,b
913   add a,a
914   add a,b
915   ld  b,a ;3x(balls+2)
916 skipballs:
917   inc hl
918   dnz skipballs
919
920 skipflags:
921   ld  a,(Gametype)
922   cp  gamectf
923   jr  nz,noflagstoskip
924   inc hl
925   inc hl
926   inc hl
927   inc hl
928 noflagstoskip:
929
930 skipobjects:
931   ld  a,(hl)
932   inc hl
933   or  a
934   ret z ;0=end
935   inc hl
936   inc hl
937   inc hl
938   inc hl
939   jr  skipobjects
940
941 loadgamecar:
942 ;in:    (Gametype)
943 ;out:   Gametype+1=hl
944 ;build: c=(gameCar)=(hl-1)
945 ;       a=(wormbeglives)=(hl)
946 ;destr: acdehl
947   ld  hl,datasingle
948   ld  a,(Gametype)
949   add a,a
950   add a,a
951   ld  e,a
952   ld  d,0
953   add hl,de
954   ld  a,(hl)
955   ld  (gameCar),a
956   ld  c,a
957   inc hl
958   ld  a,(hl)
959   ld  (wormbeglives),a
960   ret
961
962 ;-----------------------------
963 ;-------- start game ---------
964 ;-----------------------------
965
966 LetsGetThisPartyOn:
967   ld  a,$17 ;no exit
968   ld  (CheckExit),a ;set exit state
969
970   cal loadgamecar
971   ld  b,a ;psh a
972   inc hl ;nrworms
973   ld  a,(hl)
974   ld  (nrworms),a
975   ld  l,b ;pop a
976   ld  h,0             ;hl=a
977   cal _HLTIMES10      ;hl=10*(hl)
978   ld  (scorelimit),hl ;set limit
979
980   cal loadgamecar ;nc
981   psh hl
982   ld  a,(Gametype) ;4bytes -> 3bytes
983   add a,a ;3->2bytes
984   add a,24+1 ;go to datalevels
985   ld  e,a ;=de
986   sbc hl,de ;datalevels
987
988   ld  a,c ;(gameCar)
989   and _datascore
990   jr  nz,scorelimitset
991   dec a ;ld a,$FF ;=no_limit
992   ld  (scorelimit),a
993 scorelimitset:
994
995   cal _ldHLind ;ld hl,(hl)
996   pop de ;de=loadgamecar
997   inc de \ inc de
998   ld  a,(de) ;(curlevel)
999   ld  (Level),a
1000   ld  d,a ;begin level
1001 skiplevelloop:
1002   dec d ;levels to skip
1003   jr  z,levelsskipped
1004   cal skiplevel
1005   jr  skiplevelloop
1006 levelsskipped:
1007
1008   psh hl  ;1st level
1009   ld  a,c
1010   and _datalink
1011   jr  z,GameOver
1012
1013 linkmatch:
1014   cal _clrWindow
1015   ld  c,wormVhost
1016   cal Qsend
1017   ld  hl,txtWaiting
1018   cal _puts
1019   cal Crecv
1020   ld  a,c
1021   cp  wormVclient
1022   jr  z,client
1023   cp  wormVhost
1024   jr  nz,linkiniterror
1025 host:
1026   ld  c,wormVclient
1027   cal Qsend
1028   ld  a,$18
1029   jr  multiplayer
1030
1031 linkiniterror:
1032   pop hl
1033   jp  DisplayMenu
1034
1035 client:
1036   ld  hl,txtReceive
1037   cal _puts
1038   ld  a,$E6
1039 multiplayer:
1040   ld  (SwapPos),a
1041   ld  a,2
1042   ld  (nrworms),a
1043
1044 ;-----------------------------
1045 ;--------- game over ---------
1046 ;-----------------------------
1047
1048 GameOver:
1049   ld  a,%11000000
1050   out (7),a ;link normal
1051   cal _clrLCD
1052   ld  hl,worm1set
1053   ld  de,worm1
1054   ld  a,4 ;4x (all worms)
1055 createwormsloop:
1056   ex  de,hl
1057   ld  bc,died
1058   add hl,bc
1059   ld  (hl),0 ;died=0
1060   inc hl
1061   ld  (hl),0 ;score=0
1062   inc hl
1063   ld  (hl),0 ;score+1=0
1064   inc hl
1065   ld  (hl),2 ;delay=2
1066   inc hl
1067   ld  (hl),3 ;lives=x
1068 wormbeglives =$-1
1069   inc hl
1070   ex  de,hl  ;de=wormX+head
1071   ld  bc,18
1072   ldir       ;copy 18 bytes
1073   dec a      ;loop
1074   jr  nz,createwormsloop
1075
1076   pop hl ;begin of current level
1077
1078 StartLevel:
1079   ld  de,Left
1080   ld  a,(hl)
1081   inc a ;=255?
1082   jp  nz,nextlevel
1083
1084   ld  hl,Level
1085   dec (hl) ;curlevel-- (not beyond last lvl)
1086   psh hl
1087   cal releasekeys
1088   cal _clrWindow
1089   pop hl
1090 ;show end msg or smtn
1091   ld  bc,Exit
1092   psh bc   ;where to go afterwards
1093   inc hl   ;location of ending-code
1094   jp  (hl) ;go there ("call")
1095 nextlevel:
1096   ldi
1097   ld  de,Speed
1098   ldi
1099   ld  de,peagrowth
1100   ldi
1101   ld  a,(hl)
1102   ld  (worm1+grow),a
1103   ld  (worm2+grow),a
1104   ld  (worm3+grow),a
1105   ld  (worm4+grow),a
1106   ld  (beginsize),a
1107   inc hl
1108
1109   ld  a,(hl)
1110   inc hl
1111   or  a
1112   jr  z,defaultsprite
1113   ld  d,h
1114   ld  e,l ;ld de,hl
1115   ld  c,a
1116   ld  b,0 ;bc=sprite size
1117   add hl,bc ;hl=behind sprite
1118   jr  setsprite
1119 defaultsprite:
1120   ld  a,defspritesz
1121 defsprsize =$-1
1122 defsprite  =$+1
1123   ld  de,defspriteimg
1124 setsprite: ;de=@sprite ;a=sprsize
1125   ld  (sprsize),a
1126   ld  (spritepos),de
1127
1128   ld  a,(hl)
1129   inc hl
1130   ld  (nrballs),a
1131   or  a
1132   jr  z,toobad_noballs
1133   ld  c,a
1134   add a,a
1135   add a,c
1136   ld  c,a
1137   ld  b,0
1138   ld  de,balls
1139   ldir
1140 toobad_noballs:
1141
1142   ex  de,hl
1143 #ifndef invincible
1144   ld  (thislevel),de
1145 #endif
1146
1147   ld  hl,worm1
1148   ld  a,(gameCar)
1149   cp  _datasp
1150   ld  b,1
1151   jr  z,worminit
1152   ld  b,4
1153 worminit:
1154   psh bc                        ; >> 1
1155   ex  de,hl
1156   ldi          ;d
1157   ld  a,SinCosTable/256
1158   ld  (de),a
1159   inc de
1160   ldi          ;y
1161   ldi          ;x
1162   ex  de,hl
1163
1164   xor a
1165   ld  (hl),a   ;y2
1166   inc hl
1167   ld  (hl),a   ;x2
1168
1169   ld  bc,(worm2-worm1)-5
1170   add hl,bc
1171   pop bc                         ; << 0k
1172   dnz worminit
1173
1174 ;-------- draw level ---------
1175
1176   ld  a,(de)
1177   inc de
1178   sub 128
1179   jr  nc,setfieldx
1180   xor a ;fieldx<128
1181 setfieldx:
1182   ld  (FieldWidth),a
1183   ld  a,(de)
1184   inc de
1185   ld  l,a
1186   sub 57
1187   jr  nc,setfieldy
1188   xor a ;fieldy<57
1189 setfieldy:
1190   ld  (FieldHeight),a
1191   psh de                        ; >> levelp
1192   ld  a,l ;pop
1193   sub 5
1194   ld  l,a
1195   ld  h,0
1196   add hl,hl
1197   add hl,hl
1198   add hl,hl
1199   add hl,hl
1200   add hl,hl
1201   ex  de,hl
1202
1203   ld  hl,ScrBuffer
1204   psh hl                        ; >> 1
1205   psh de                        ; >> 2
1206   ld  de,ScrBuffer+1
1207   ld  bc,63
1208   ld  (hl),%11111111
1209   ldir
1210   inc hl
1211   ld  (hl),%11000000
1212   inc hl
1213   ld  b,31
1214 ClearLine:
1215   ld  (hl),c
1216   inc hl
1217   dnz ClearLine
1218   psh hl                        ; >> 3
1219
1220   ld  a,(FieldWidth)
1221   add a,126
1222   psh af                        ; >> 4
1223   and %11111000
1224   rra
1225   rra
1226   rra
1227   ld  l,a
1228   ld  h,0
1229   add hl,de
1230   pop af                         ; << 3
1231   and %00000111
1232   ld  b,a
1233   ld  c,0
1234   ld  a,%11000000
1235   jr  z,NoVertShift
1236 VertShift:
1237   rra
1238   rr  c
1239   dnz VertShift
1240 NoVertShift:
1241   ld  (hl),a
1242   inc hl
1243   ld  (hl),c
1244
1245   ex  de,hl
1246   pop de                         ; << 2
1247   pop bc                         ; << 1
1248   ldir
1249   pop hl                         ; << 0k
1250   ld  c,64
1251   ldir
1252
1253
1254   pop hl                         ; << levelp
1255   ld  a,(Gametype)
1256   cp  gamectf
1257   jr  nz,noctf
1258   ld  de,peaspos
1259   ld  bc,4
1260   ldir
1261   psh hl
1262   cal DrawAllPeas
1263   pop hl
1264 noctf:
1265
1266   cal drawstuff
1267
1268 ;-----------------------------
1269
1270   psh hl                        ; >> levelp new
1271   cal showstats
1272   ld  a,(gameCar)
1273   and _datafood
1274   jr  z,nofood
1275   cal NewPea
1276 nofood:
1277   ld  bc,(worm1+pos)
1278   cal DisplayField
1279
1280 #ifdef readymask
1281   ld  hl,$FC70
1282   ld  d,%10101010
1283   ld  c,56
1284 maskloop:
1285   ld  a,d
1286   xor %11111111
1287   ld  d,a
1288   ld  b,$10
1289 maskline:
1290   ld  a,(hl)
1291   or  d
1292   ld  (hl),a
1293   inc hl
1294   dnz maskline
1295   dec c
1296   jr  nz,maskloop
1297 #endif
1298
1299 #ifdef readytext
1300   ld  hl,$FDE0
1301   ld  de,$FDE1
1302   ld  (hl),%11111111
1303   ld  bc,$BF
1304   ldir
1305   ld  hl,4+(txtposReady*256)
1306   ld  (_curRow),hl
1307   set 3,(iy+5)
1308   ld  hl,txtReady
1309   cal _puts
1310   res 3,(iy+5)
1311 #endif
1312
1313   ld  a,0
1314 gameCar =$-1
1315   and _datalink
1316   jr  z,initfinished ;no link
1317   xor a
1318   ld  (Speed),a ;max.speed
1319 SwapPos: ;$18 xx -> $E6 xx
1320          ; jr xx -> and xx
1321   jr  sethost
1322 setclient:
1323   ld  (worm1+left),a ;worm 1 via link
1324   jr  initfinished
1325 sethost:
1326   ld  (worm2+left),a ;worm 2 via link
1327 initfinished:
1328
1329   ld  b,startdelay
1330 ReadyDelay:
1331   halt
1332   dnz ReadyDelay
1333   cal releasekeys
1334
1335 ;-----------------------------
1336 ;----------- LOOP ------------
1337 ;-----------------------------
1338
1339 GameLoop:
1340   ld  bc,(worm1+pos)
1341   cal DisplayField
1342
1343   ld  a,1
1344 flashtime =$-1
1345   dec a
1346   jr  z,noflash
1347   ld  (flashtime),a
1348   ld  hl,$fc00+(16*7)
1349 screeninvertloop:
1350   ld  a,(hl)
1351   cpl
1352   ld  (hl),a
1353   inc hl
1354   xor a
1355   cp  h
1356   jr  nz,screeninvertloop
1357 noflash:
1358
1359   ld  a,0
1360 Speed =$-1
1361   or  a
1362   jr  z,NoDelay
1363 Delay:
1364   halt
1365   dec a
1366   jr  nz,Delay
1367 NoDelay:
1368
1369   ld  (handledworm),a ;=0
1370
1371   ld  a,0
1372 nrballs =$-1
1373   or  a
1374   cal nz,handlethoseneatlittleballs
1375
1376   ld  ix,worm1
1377   ld  a,1
1378 nrworms =$-1
1379   ld  b,a
1380 handleworms:
1381   psh bc
1382   cal HandleWorm
1383   ld  bc,worm2-worm1
1384   add ix,bc
1385   pop bc
1386   ld  hl,handledworm
1387   inc (hl) ;1..nrworms
1388   dnz handleworms
1389
1390 ;-----------------------------
1391 ;---------- keys -------------
1392 ;-----------------------------
1393
1394 HandleKeys:
1395   ld  a,%10111111
1396   out (1),a
1397   in  a,(1)
1398   rla ;MORE?
1399   jr  c,CheckExit
1400   ld  bc,$0103
1401   out (c),b
1402   halt ;pause/off
1403   ld  b,11
1404   out (c),b
1405
1406 CheckExit:
1407   rla  ;=$17 (c=EXIT-key)
1408       ;or$A7 (c=0)
1409   jp  c,GameLoop
1410   jr  Exit
1411
1412 WormDead:
1413 #ifdef invincible
1414   jp  stopworm
1415 #else
1416   ld  a,2
1417   ld  (flashtime),a
1418   ld  (ix+delay),respawndelay
1419
1420 thislevel =$+1
1421   ld  hl,0
1422   ld  de,0
1423 handledworm =$-2
1424   add hl,de
1425   add hl,de
1426   add hl,de
1427   ld  a,(hl)
1428   inc hl
1429   ld  (ix+heading),a
1430   ld  a,(hl)
1431   ld  (ix+pos),a
1432   inc hl
1433   ld  a,(hl)
1434   ld  (ix+pos+1),a
1435
1436   inc (ix+died)
1437   dec (ix+lives)
1438   psh af
1439   ld  de,10
1440   cal DecScore
1441   pop af
1442   ret nz ;HandleWorm done
1443   ld  a,(gameCar)
1444   and _datalivel
1445   ret z
1446   ld  a,$A7 ;exit@end of turn
1447   ld  (CheckExit),a ;set exit state
1448   ret ;finish turn
1449 #endif
1450
1451 Exit:
1452   ld  sp,0 ;pop all
1453 SpSave = $-2
1454   ld  a,D0HD1H
1455   out (7),a
1456   cal _clrWindow
1457   ld  hl,txtGO
1458   cal _puts
1459   ld  hl,$FC00
1460   ld  b,16*8
1461   cal menuinvloop ;invert
1462   inc h ;$FD80
1463   ld  b,16
1464   cal menuinvloop ;<hr>
1465   ld  hl,$FCE0
1466   ld  b,16
1467   cal menuinvloop ;<hr>
1468 ; ld  l,$74
1469 ; ld  b,8
1470 ; cal menuinvloop
1471   ld  hl,_curRow
1472   inc (hl)
1473   ld  hl,txtGame
1474 CURtxtGame =$-2
1475   cal _puts
1476   ld  a,$0D ;$0D02
1477   ld  (_curCol),a
1478   cal showLevel
1479
1480   ld  de,$1901
1481   ld  (_penCol),de
1482   ld  hl,txtName
1483   cal _vputs ;Name
1484   ld  a,$4F
1485   ld  (_penCol),a
1486   cal _vputs ;Died    Score
1487   ld  de,$0004
1488   ld  (_curRow),de
1489
1490   ld  a,(nrworms)
1491   ld  b,a
1492   ld  hl,worm1+died
1493 displayWormStats:
1494   psh bc
1495   psh hl
1496
1497   ld  bc,left-died
1498   add hl,bc ;+left
1499   xor a
1500   cp  (hl)  ;input=0 = link
1501   jr  nz,NoLinkIndic
1502   ld  a,8
1503   ld  (_curCol),a
1504   ld  a,$DC ;-O
1505   cal _putc
1506   xor a
1507   ld  (_curCol),a
1508 NoLinkIndic:
1509   inc hl
1510   inc hl ;+name
1511   cal _puts
1512
1513   pop hl
1514   psh hl
1515   ld  a,13
1516   ld  (_curCol),a
1517   ld  a,(hl) ;worm+died
1518   cal showA
1519   pop hl
1520   psh hl
1521
1522   ld  a,16
1523   ld  (_curCol),a
1524   inc hl ;worm+score
1525   cal _ldHLind ;ld hl,(hl)
1526   cal showHL ;worm+score
1527
1528   pop hl
1529   ld  bc,worm2-worm1
1530   add hl,bc
1531   pop bc
1532   dnz displayWormStats
1533
1534   ld  a,(Gametype)
1535   or  a ;singleplayer (0) only
1536   jr  nz,hilevelcheckdone
1537 checkhilevel:
1538   ld  hl,nrlevels
1539   ld  a,(Level)
1540   cp  (hl)
1541   jr  c,hilevelcheckdone
1542   ld  (hl),a ;save local
1543   ld  c,a
1544   ld  a,0
1545 hilvlposa =$-1
1546   ld  hl,nrlevels
1547 hilvlposhl =$-2 ;save external
1548   cal _writeb_inc_ahl ;ld (ahl),c
1549 hilevelcheckdone:
1550
1551   ld  a,(gameCar)
1552   and _datasingl
1553
1554   jr  z,hiscorecheckdone
1555 checkhiscore:
1556   cal loadhiscoreposinahl
1557   cal _Get_Word_ahl ;de=old_hi
1558  psh de
1559  cal _RAM_PAGE_1 ;&&
1560  pop de
1561   ld  hl,(worm1+score)
1562
1563   ld  a,h           ;New
1564   cp  d             ;Old
1565   jr  c,NotNewHigh  ;New<Old
1566   jr  nz,newhigh    ;New>Old
1567
1568   ld  a,e           ;old
1569   cp  l             ;new
1570   jr  nc,NotNewHigh ;new<old
1571
1572 newhigh:            ;New>=Old
1573   ex  de,hl
1574   cal loadhiscoreposinahl
1575   cal _Set_Word_ahl ;de->(ahl)
1576  cal _RAM_PAGE_1
1577
1578 NotNewHigh: ;de=current hiscore
1579   ld  hl,$0807
1580   ld  (_curRow),hl
1581   ld  hl,txthiscore
1582   cal _puts
1583   ex  de,hl ;pop
1584   cal showHL
1585 hiscorecheckdone:
1586
1587   cal releasekeys
1588 waitkey:
1589   halt
1590   halt
1591   cal GET_KEY
1592   cp  K_ENTER
1593   jp  z,DisplayMenu
1594   cp  K_SECOND
1595   jp  z,DisplayMenu
1596   cp  K_EXIT
1597   jr  nz,waitkey
1598
1599 ;x123456789012345678901
1600 ;>>>>>> GAME OVER <<<<<
1601 ;2Multiplayer
1602 ;3Level 01
1603 ;4           Died Score:
1604 ;5NameName     03 00070
1605 ;6Worm#02 @    05 00120
1606 ;7Worm#03      15 00030
1607 ;8Snaky   @    00 04820
1608
1609 ExitNoStats:
1610   ld  hl,_asapvar
1611   rst 20h ;_ABS_MOV10TOOP1
1612   rst 10h ;_FINDSYM
1613   ld  hl,savestart-_asm_exec_ram+4
1614   xor a
1615   add hl,de
1616   adc a,b ;ahl=bde+4
1617   cal _SET_ABS_DEST_ADDR
1618
1619   xor a
1620   ld  hl,savestart
1621   cal _SET_ABS_SRC_ADDR
1622   ld  hl,saveend-savestart
1623   cal _SET_MM_NUM_BYTES
1624   cal _mm_ldir
1625
1626   cal releasekeys
1627   res 4,(iy+9)
1628   set 2,(iy+13)
1629   im  1 ;remove keyfix
1630   jp  _clrWindow
1631
1632 loadhiscoreposinahl:
1633   ld  a,(Level)
1634   ld  b,a
1635
1636   ld  h,0            ;hl=
1637   ld  a,(nrlevels+1) ;# peaworm lvls
1638   add a,a
1639   ld  l,a
1640
1641   ld  a,(Gametype)
1642   dec a
1643   ld  c,a
1644   dec a              ;z=(Gametype)=2
1645   jr  z,tronhi
1646   ld  l,h            ;hl=0
1647 tronhi:
1648
1649   xor a              ;ahl=0(+x)
1650   psh bc
1651   ld  bc,defhiscrpos
1652 hiscrposhl =$-2
1653   add hl,bc
1654   pop bc
1655   adc a,0
1656 hiscrposa =$-1       ;ahl=saveloc
1657
1658   inc c
1659   ret z              ;(Gametype)=0
1660 addlevelposition:
1661   cal _AHL_PLUS_2_PG3
1662   dnz addlevelposition
1663   ret
1664
1665 ;-----------------------------
1666 ;----------- worm ------------
1667 ;-----------------------------
1668
1669 respawncheck:
1670   cp  respawndelay-1
1671   jr  nz,unnamedlabel
1672   cal saverespawncounter
1673 removeworm:
1674   ld  h,(ix+tail+1)
1675   ld  l,(ix+tail)
1676   ld  d,(ix+head+1)
1677   ld  e,(ix+head)
1678   jr  DoesWormTailEqualsWormHead ;chk4 size=0
1679 removewormloop:
1680   ld  c,(hl)
1681   inc hl
1682   ld  b,(hl)
1683   inc hl
1684   cal resbit
1685   psh hl
1686   cal res4pixels
1687   pop hl
1688   inc (ix+grow)
1689 DoesWormTailEqualsWormHead:
1690   cal _cphlde
1691   jr  nz,removewormloop
1692
1693   ld  a,(gameCar)
1694   and _datasingl
1695   jr  nz,safewormsizedone
1696   ld  a,0
1697 beginsize =$-1
1698   ld  (ix+grow),a
1699 safewormsizedone:
1700
1701   ;de=ix+head
1702   ld  (ix+tail+1),d
1703   ld  (ix+tail),e ;head=tail/size=0
1704   ret
1705
1706 unnamedlabel:
1707   cp  1
1708   ld  h,a
1709   jr  nz,saverespawncounter
1710 respawndue:
1711   ld  l,a
1712   cal inputcall
1713   ld  a,h ;previous
1714   cp  l   ;changed?
1715   ret z
1716   ld  (ix+delay),a ;=0
1717   ret
1718 saverespawncounter:
1719   ld  (ix+delay),a
1720   jr  inputcall
1721 ;  ld  a,(ix+input)
1722 ;  or  a
1723 ;  jr  z,inlink
1724 ;  ret
1725
1726 chkkey: ;key=a
1727   dec a
1728   ld  b,a
1729   srl b
1730   srl b
1731   srl b ;b=a/8
1732   and 7 ;a=a\8
1733   ld  c,a ;push keybit
1734   ld  a,-1
1735   out (1),a
1736   inc b
1737   ld  a,%01111111 ;default
1738 bitmask:
1739   rlca ;rotate left
1740   dnz bitmask ;a/8 times
1741   out (1),a ;send bitmask
1742   in  a,(1) ;input keys
1743   ld  b,c ;pop keybit
1744   inc b
1745 keybit:
1746   rra
1747   dnz keybit ;check match (cf set)
1748   ret
1749
1750 inkeys: ;use jp not call!
1751   cal chkkey
1752   jr  nc,notright
1753   ld  a,l
1754   add a,8
1755   ld  l,a
1756 notright:
1757   ld  a,(ix+right)
1758   cal chkkey
1759   ret nc
1760   ld  a,l
1761   sub 8
1762   ld  l,a
1763   ret
1764 inputcall:
1765   ld  a,(ix+left)
1766   or  a
1767   jr  z,inlink ;input by link
1768   cal inkeys ;input by keys
1769   ld  a,(gameCar)
1770   and _datalink
1771   ret z ;no link
1772   ld  c,l ;send our keys
1773   psh hl
1774   cal Qsend ;Csend
1775   pop hl
1776   ret
1777 inlink:
1778   psh hl
1779   cal Qrecv ;Crecv
1780   pop hl
1781   ld  l,c
1782   ret
1783
1784 ;------- handle worm ---------
1785
1786 HandleWorm:
1787   ld  a,(ix+delay)
1788   dec a
1789   jp  nz,respawncheck
1790
1791   ld  a,(Gametype)
1792   cp  gametron
1793   jr  nz,notron
1794   ld  de,1
1795   cal IncScore
1796 notron:
1797
1798   ld  l,(ix+heading)
1799   cal inputcall
1800 donediddelydone:
1801   ld  (ix+heading),l
1802   ld  h,(ix+heading+1)
1803
1804   ld  c,(ix+pos)
1805   ld  b,(ix+pos+1)
1806   ld  e,(ix+pos2)
1807   ld  d,(ix+pos2+1)
1808
1809   psh hl
1810   ld  hl,previouspos
1811   ld  (hl),c
1812   inc hl
1813   ld  (hl),b
1814   inc hl
1815   inc hl
1816   ld  (hl),e
1817   inc hl
1818   ld  (hl),d
1819   pop hl
1820
1821 ;-------- move worm ----------
1822
1823 Wormmove:
1824   psh bc                        ; >> pos
1825   ld  a,(hl)
1826   add a,a
1827   add a,d
1828   ld  d,a
1829   bit 7,(hl)
1830   jr  z,notnegX
1831   dec b
1832 notnegX:
1833   jr  nc,notmoveX
1834   inc b
1835 notmoveX:
1836   ld  a,l
1837   add a,$40
1838   ld  l,a
1839   ld  a,(hl)
1840   add a,a
1841   add a,e
1842   ld  e,a
1843   bit 7,(hl)
1844   jr  z,notnegY
1845   dec c
1846 notnegY:
1847   jr  nc,notmoveY
1848   inc c
1849 notmoveY: ;bc=newpos
1850   ld  (ix+pos2),e
1851   ld  (ix+pos2+1),d
1852   ld  (ix+pos),c
1853   ld  (ix+pos+1),b
1854
1855 ;-check-
1856   pop hl                         ; << pos (old)
1857   ld  a,h
1858   sub b
1859   and 1
1860   ld  h,a
1861   ld  a,l
1862   sub c
1863   and 1
1864   add a,h
1865   ld  d,4
1866   jr  z,GotFour
1867   xor 3
1868   ld  d,a
1869 GotFour:
1870   cal chk4pixels
1871   rl  d
1872   jp  nc,Drawworm
1873
1874 ;--------- worm hit ----------
1875
1876 Hitworm:
1877   ld  a,(gameCar)
1878   ld  h,a
1879   and _datadie
1880   cal z,checkhitotherworm
1881   ld  a,h
1882   and _datamultpeas ;&&bit
1883   jr  nz,multiple_peas
1884   ld  a,h
1885   and _datafood
1886   jp  z,WormDead ;no food
1887
1888   ld  hl,0
1889 PeaY =$-2
1890 PeaX =$-1
1891   cal chkpeahit
1892   jp  nc,WormDead
1893   cal DrawPea ;remove pea
1894   ld  a,(ix+grow)
1895   add a,15
1896 peagrowth =$-1
1897   ld  (ix+grow),a
1898   cal NewPea
1899   ld  hl,Left
1900   dec (hl)
1901   psh af
1902   ld  de,10
1903   cal IncScore
1904   pop af
1905   jp  nz,Drawworm ;continue
1906   ld  a,(gameCar)
1907   and _datafoodl
1908   jp  z,Drawworm
1909   ld  a,(Gametype)
1910   or  a
1911   jp  nz,Exit ;stack restored
1912
1913   ld  hl,Level
1914   ld  a,(hl)
1915   inc (hl)
1916   ld  l,a ;hl=Level
1917   ld  h,0
1918   add hl,hl
1919   add hl,hl
1920   cal _HLTIMES10
1921   ex  de,hl
1922   cal IncScore ;score+(40*level)
1923   cal removeworm
1924   pop hl                         ; << call
1925   pop hl                         ; << call
1926   pop hl                         ; << levelp new
1927   ld  (ix+delay),2
1928   jp  StartLevel
1929
1930 chkpeahit: ;hl=peapos
1931   ld  a,(sprsize)
1932   inc a
1933   ld  d,a
1934   ld  a,b
1935   sub h
1936   inc a
1937   cp  d ;=(sprsize)+1
1938   ret nc ;nc=no pea
1939   ld  a,c
1940   sub l
1941   inc a
1942   cp  d
1943   ret ;c=pea
1944
1945 flagcaptured:
1946   psh hl
1947   ld  de,30
1948   cal IncScore
1949   pop hl
1950 sillylabel:
1951   cal WormDead
1952 DrawAllPeas:
1953   ld  hl,(peaspos)
1954   cal DrawPea
1955   ld  hl,(peaspos+2)
1956   jp  DrawPea
1957
1958 multiple_peas:
1959   ld  hl,(peaspos) ;1st pea
1960   psh hl
1961   ld  a,(ix+reserv)
1962   ld  e,a ;push a
1963   and %01
1964   jr  nz,sel_ownpea
1965   ld  hl,(peaspos+2) ;2nd pea
1966 sel_ownpea:
1967   cal chkpeahit
1968   pop hl ;(peapos) 1st pea
1969   jp  c,WormDead ;stopworm ;own pea hit
1970
1971   ld  a,e ;peek a (that's x86 asm for pop\push ;)
1972   and %01
1973   jr  z,sel_otherpea
1974   ld  hl,(peaspos+2) ;2nd pea
1975 sel_otherpea:
1976   cal chkpeahit
1977   jp  c,hitflag
1978
1979 ;no peas hit
1980   ld  a,e
1981   cal flagtoken
1982   jp  z,WormDead
1983   ld  b,a ;%10
1984   srl b   ;%01
1985   add a,b ;%11
1986   ld  (ix+reserv),a
1987   cal DrawPea ;restore own flag
1988   jr  sillylabel ;inv both\die
1989
1990 hitflag: ;correct pea hit
1991   ld  a,e ;pop a
1992   xor %01 ;0=1;1=0
1993   ld  (ix+reserv),a
1994   cal flagtoken
1995   psh af ;safe z-flag
1996   cal DrawPea ;remove
1997   pop af
1998   jr  z,flagcaptured
1999   jr  stopworm
2000
2001 flagtoken:
2002   and %01 ;current
2003   add a,a ;<< for cp
2004   ld  b,a ;in b
2005   ld  a,e
2006   and %10 ;own
2007   cp  b   ;same?
2008   ret ;Z=yes: no flag taken
2009
2010 ;-----------------------------
2011
2012 nextotherwormbit:
2013   ld  a,c
2014   sub (hl)
2015   inc hl
2016   inc a
2017   cp  4
2018   jr  nc,nothit1 ;no
2019   ld  a,b
2020   sub (hl)
2021   inc a
2022   cp  4
2023   ret c ;nz ;yes
2024 nothit1:
2025   inc hl
2026   cal resbit
2027 ChkWorm:
2028   cal _cphlde
2029   jr  nz,nextotherwormbit
2030   ret ;z
2031
2032 checkhitlapline:
2033   ld  a,63
2034   sub b
2035   jr  z,nextlaphalf
2036   inc a
2037   ret nz
2038 nextlaphalf:
2039   ld  a,c
2040   and 32 ;y>=32?
2041   jr  nz,nolap
2042   cp  (ix+reserv)
2043   jr  z,nolap
2044   psh bc
2045   ld  de,20
2046   cal IncScore
2047   pop bc
2048   xor a
2049 nolap:
2050   ld  (ix+reserv),a
2051   ret
2052
2053 checkhitotherworm:
2054  .db  $dd,$7d ;ld a,lx
2055   cp  worm2&255
2056  psh ix
2057  jr nz,chkworm2 ; ret nz
2058   ld  ix,worm1
2059  jr chkworm
2060 chkworm2:
2061  ld ix,worm2
2062
2063 chkworm:
2064  ld h,(ix+tail+1)
2065  ld l,(ix+tail)
2066  ld e,(ix+head)
2067  ld d,(ix+head+1)
2068   cal ChkWorm
2069  pop ix
2070   ret z ;not hit
2071   pop bc ;call
2072 stopworm:
2073   ld  bc,0
2074 previouspos =$-2
2075   ld  de,0
2076   ld  (ix+pos),c
2077   ld  (ix+pos+1),b
2078   ld  (ix+pos2),e
2079   ld  (ix+pos2+1),d
2080   ret
2081
2082 ;-------- draw worm ----------
2083
2084 Drawworm:
2085   ld  c,(ix+pos)
2086   ld  b,(ix+pos+1)
2087
2088   ld  a,(Gametype)
2089   ld  d,a
2090   cp  gamerace
2091   cal z,checkhitlapline
2092
2093   cal set4pixels
2094   dec c
2095   ld  a,d
2096   cp  gametron
2097   ret z ;keep tail in "Tron"
2098
2099   ld  l,(ix+head)
2100   ld  h,(ix+head+1)
2101   ld  (hl),c
2102   inc hl
2103   ld  (hl),b
2104   inc hl
2105   cal resbit
2106   ld  (ix+head),l
2107   ld  (ix+head+1),h
2108
2109   ld  a,(ix+grow)
2110   dec a
2111   jr  z,removetail
2112   ld  (ix+grow),a
2113   ret
2114
2115 removetail:
2116   ld  l,(ix+tail)
2117   ld  h,(ix+tail+1)
2118   ld  c,(hl)
2119   inc hl
2120   ld  b,(hl)
2121   inc hl
2122   cal resbit
2123   ld  (ix+tail),l
2124   ld  (ix+tail+1),h
2125
2126 res4pixels:
2127   cal ResPixel
2128   inc b
2129   cal ResPixel
2130   inc c
2131   cal ResPixel
2132   dec b
2133 ResPixel:
2134   cal FindPixel
2135   cpl
2136   and (hl)
2137   ld  (hl),a
2138   ret
2139
2140 ;-----------------------------
2141 ;---------- ball -------------
2142 ;-----------------------------
2143
2144 handlethoseneatlittleballs:
2145   ld  hl,balls
2146   ld  b,a ;a=(nrballs)
2147 handleballs
2148   psh bc
2149   psh hl
2150   ld  c,(hl)
2151   inc hl
2152   ld  b,(hl)
2153   inc hl
2154   ld  d,(hl)
2155   cal handleball
2156   dec c
2157   pop hl
2158   ld  (hl),c
2159   inc hl
2160   ld  (hl),b
2161   inc hl
2162   ld  (hl),d
2163   inc hl
2164   pop bc
2165   dnz handleballs
2166   ret
2167
2168 handleball:
2169   cal res4pixels
2170   dec c
2171
2172 ballxmove:
2173   bit 0,d ;1=L; 0=R
2174   jr  z,ballright
2175 ballleft:
2176   dec b
2177   cal checkballhit
2178   jr  z,ballymove
2179   inc b ;undo
2180   res 0,d ;go right
2181   jr  ballymove
2182 ballright:
2183   inc b
2184   cal checkballhit
2185   jr  z,ballymove
2186   dec b ;back
2187   set 0,d ;>left
2188
2189 ballymove:
2190   bit 1,d ;1=up; 0=down
2191   jr  z,balldown
2192 ballup:
2193   dec c
2194   cal checkballhit
2195   jr  z,balldone
2196   inc c
2197   res 1,d ;go down
2198   jr  balldone
2199 balldown:
2200   inc c
2201   cal checkballhit
2202   jr  z,balldone
2203   dec c
2204   set 1,d ;up
2205 balldone:
2206
2207 set4pixels: ;@(b,c)
2208   cal SetPixel
2209   inc b
2210   cal SetPixel
2211   inc c
2212   cal SetPixel
2213   dec b
2214 SetPixel: ;at bc
2215   cal FindPixel
2216   or  (hl)
2217   ld  (hl),a
2218   ret
2219
2220 letsmovetheotherway:
2221   ld  a,1
2222   xor (hl)
2223   ld  (hl),a
2224   ret
2225
2226 checkballhit:
2227   psh de
2228   ld  d,0
2229   cal chk4pixels
2230   xor a
2231   cp  d
2232   pop de
2233   ret
2234
2235 ;-----------------------------
2236 ;----------- procs -----------
2237 ;-----------------------------
2238
2239 releasekeys:
2240   halt
2241   ld  a,%10000000    ;all key-masks
2242   out (1),a
2243   in  a,(1)
2244   inc a              ;cp %11111111 (no keys pressed)
2245   jr  nz,releasekeys ;keep waitin
2246   cal GET_KEY        ;clear buffer
2247   ret
2248
2249 resbit:
2250   ld  a,h
2251   and (ix+storepos)
2252   ld  h,a
2253   ret
2254
2255 randompos:
2256   ld  b,a
2257 Random: ;(2..b+2)
2258   ld  a,r
2259 Seed =$+1
2260   add a,0
2261   ld  (Seed),a
2262   and %01111110
2263   cp  b
2264   jr  nc,Random
2265   add a,2
2266   ret
2267
2268 NewPea:
2269   ld  a,(FieldWidth)
2270   add a,127-4
2271   cal randompos
2272   ld  h,a
2273   ld  a,(FieldHeight)
2274   add a,56-4
2275   cal randompos
2276   ld  l,a
2277   ld  (PeaY),hl
2278
2279 CheckPea:
2280   ld  c,l
2281   ld  a,(sprsize)
2282   ld  e,a
2283 chkloopy:
2284   ld  b,h
2285   ld  a,(sprsize)
2286   ld  d,a
2287 chkloopx:
2288   psh hl
2289   cal FindPixel
2290   and (hl)
2291   pop hl
2292   jr  nz,NewPea ;pixel found
2293   inc b
2294   dec d
2295   jr  nz,chkloopx
2296   inc c
2297   dec e
2298   jr  nz,chkloopy
2299 ;all ok; empty space
2300
2301 DrawPea: ;hl=(PeaY)
2302   ld  b,h
2303   ld  c,l
2304   ld  de,0
2305 spritepos =$-2
2306   jp  PutSprite ;||-ed
2307
2308 ;----------- score -----------
2309
2310 _divHLby1000:
2311   psh hl
2312   ld  b,3
2313 divideagain: ;3x
2314   cal _divHLby10
2315   dnz divideagain
2316   ld  a,l ;a=hl/1000
2317   pop hl
2318   ret
2319
2320 IncScore:
2321   ld  h,(ix+score+1)
2322   ld  l,(ix+score)
2323   cal _divHLby1000
2324   ld  c,a
2325   add hl,de
2326   cal _divHLby1000
2327   cp  c
2328   jr  z,scorecommon ;hl/1000 not increased
2329   inc (ix+lives)
2330   jr  scorecommon
2331 DecScore: ;&&&
2332   ld  h,(ix+score+1)
2333   ld  l,(ix+score)
2334   or  a
2335   sbc hl,de
2336   jr  c,showstats ;<0=0
2337 scorecommon:
2338   ld  (ix+score+1),h
2339   ld  (ix+score),l
2340   ld  de,0
2341 scorelimit =$-2
2342   inc e
2343   jr  z,showstats ;de=$FF??=no limit
2344   dec e
2345   cal _cphlde
2346   jp  nc,Exit
2347
2348 showstats:
2349   ld  a,(Gametype)
2350   cp  gametron
2351   ret z
2352 showstatsEven4tron:
2353   psh ix
2354   ld  h,0
2355   ld  l,h
2356   ld  (_penCol),hl
2357   ld  a,(nrworms)
2358   ld  b,a
2359   ld  ix,worm1
2360   ld  a,(gameCar)
2361   and _datanextl
2362   jr  nz,showstatsS
2363 showstatloop:
2364   psh bc
2365   cal showstat
2366   ld  de,worm2-worm1
2367   add ix,de
2368   ld  hl,_penCol
2369   ld  a,(hl)
2370   add a,10
2371   ld  (hl),a
2372   pop bc
2373   dnz showstatloop
2374   pop ix
2375   ret
2376
2377 showstat:
2378   ld  a,(gameCar)
2379   and _datascore
2380   jr  z,showlives
2381 showscore:
2382   ld  h,(ix+score+1)
2383   ld  l,(ix+score)
2384   cal _D_HL_DECI
2385   jr __vputs
2386 showlives:
2387   ld  a,(Gametype)
2388   cp  gametron
2389   jr  z,showscore
2390
2391   ld  a,(ix+lives)
2392   add a,'0'
2393 __vputmap:
2394   psh ix
2395   cal _vputmap
2396   pop ix
2397   ret
2398
2399 showstatsS:
2400   ld  hl,txtLevel
2401   cal __vputs
2402   ld  a,0
2403 Level =$-1
2404   cp  10
2405   jr  c,tilllevel9
2406   ld  l,a
2407   ld  h,0
2408   cal _divHLby10
2409   psh af
2410   ld  a,l
2411   add a,'0'
2412   cal __vputmap
2413   pop af
2414 tilllevel9:
2415   add a,'0'
2416   cal __vputmap
2417
2418   ld  a,98
2419   ld  (_penCol),a
2420   cal showscore
2421   ld  a,123
2422   ld  (_penCol),a
2423   cal showlives
2424   ld  a,(gameCar)
2425   and _datafoodl
2426   pop ix
2427   ret z
2428 showleft:
2429   ld  a,31
2430   ld  (_penCol),a
2431   ld  a,0
2432 Left =$-1
2433   cal cshowA
2434
2435   ld  hl,txtLeft
2436 __vputs:
2437   psh ix
2438   cal _vputs
2439   pop ix
2440   ret
2441
2442 showLevel:
2443   ld  hl,txtLevel
2444   cal _puts
2445   ld  a,(Level)
2446 showA:
2447   ld  l,a
2448   ld  h,0
2449   cal _divHLby10
2450   psh af
2451   ld  a,l
2452   add a,'0'
2453   cal _putc
2454   pop af
2455   add a,'0'
2456   jp  _putc
2457
2458 cshowA:
2459   ld  l,a
2460   ld  h,0
2461   cal _divHLby10
2462   psh af
2463   ld  a,l
2464   add a,'0'
2465   cal __vputmap
2466   pop af
2467   add a,'0'
2468   jp  __vputmap
2469
2470 showHL:
2471   cal _D_HL_DECI
2472   jp  _puts
2473
2474 _D_HL_DECI:
2475   ld  de,savestr+4
2476   ld  b,5
2477 ldhld:
2478   cal _divHLby10
2479   add a,'0'
2480   ld  (de),a
2481   dec de
2482   dnz ldhld
2483   ld  hl,savestr
2484   ret
2485 savestr:
2486   .db "00000",0
2487
2488 ;-----------------------------
2489
2490 DisplayField:
2491   ld  a,c
2492   sub 29
2493   jr  nc,NotMinYScroll
2494   xor a
2495 NotMinYScroll:
2496   cp  43
2497 FieldHeight =$-1
2498   jr  c,NotMaxYScroll
2499   ld  a,(FieldHeight)
2500 NotMaxYScroll:
2501   ld  l,a
2502   ld  h,0
2503   add hl,hl
2504   add hl,hl
2505   add hl,hl
2506   add hl,hl
2507   add hl,hl
2508   psh bc                        ; >> 1
2509   psh de                        ; >> 2
2510   ld  de,ScrBuffer
2511   add hl,de
2512   ld  a,b
2513   sub 64
2514   jr  nc,NotMinXScroll
2515   xor a
2516 NotMinXScroll:
2517   cp  128
2518 FieldWidth = $-1
2519   jr  c,NotMaxXScroll
2520   ld  a,(FieldWidth)
2521 NotMaxXScroll:
2522   psh af                        ; >> 3
2523   and %11111000
2524   rra
2525   rra
2526   rra
2527   ld  c,a
2528   ld  b,0
2529   ld  de,DispBuffer
2530   pop af                         ; << 2
2531   and %00000111
2532   psh af                        ; >> 3
2533   cp  6
2534   jr  c,CopyScreen
2535   inc c
2536 CopyScreen:
2537   add hl,bc
2538   ld  b,57
2539 CopyScreenLoop:
2540   psh bc                        ; >> 4
2541   ld  bc,16
2542   ldir
2543   ld  c,16
2544   add hl,bc
2545   pop bc                         ; << 3
2546   dnz CopyScreenLoop
2547   pop af                         ; << 2
2548   ld  c,$b7 ;or a
2549 Bit0:
2550   jr  nz,Bit1
2551   halt
2552   halt
2553   jr  AfterShiftDelay
2554 Bit1:
2555   dec a
2556   jr  nz,Bit2
2557   cal ShiftRight1
2558   jr  AfterShiftDelay
2559 Bit2:
2560   dec a
2561   jr  nz,Bit3
2562   ld  a,2
2563   cal ShiftRight
2564   jr  AfterShiftDelay
2565 Bit3:
2566   dec a
2567   jr  nz,Bit4
2568   cal Chunk
2569   cal ShiftLeft1
2570   jr  AfterShift
2571 Bit4:
2572   dec a
2573   jr  nz,Bit5
2574   cal Chunk
2575   jr  AfterShiftDelay
2576 Bit5:
2577   dec a
2578   jr  nz,Bit6
2579   cal Chunk
2580   cal ShiftRight1
2581   jr  AfterShift
2582 Bit6:
2583   dec a
2584   jr  nz,Bit7
2585   ld  a,2
2586   cal ShiftLeft
2587   jr  AfterShift
2588 Bit7:
2589   cal ShiftLeft
2590 AfterShiftDelay:
2591   halt
2592 AfterShift:
2593 #ifdef buffer
2594   ld  hl,DispBuffer
2595   ld  de,$fc00+$70
2596   ld  bc,1024-$70
2597   ldir
2598 #endif
2599   pop de                         ; << 1
2600   pop bc                         ; << 0k
2601   ret
2602
2603 ShiftRight1:
2604   ld  a,1
2605 ShiftRight:
2606   ld  (ShiftRightCounter),a
2607   ld  a,c
2608   ld  (ShiftRightChunk),a
2609   ld  c,16
2610   add hl,bc
2611   ld  b,57
2612 ShiftRightLoop:
2613   psh bc
2614   ld  bc,-32
2615   add hl,bc
2616   ex  de,hl
2617   ld  a,(de)
2618 ShiftRightChunk:
2619   or  a
2620   cal c,_SHLACC
2621   ld  c,0
2622 ShiftRightCounter = $-1
2623 ShiftRowsLeft:
2624   psh hl
2625   rla
2626   ld  b,16
2627 ShiftRowLeft:
2628   dec hl
2629   rl  (hl)
2630   dnz ShiftRowLeft
2631   pop hl
2632   dec c
2633   jr  nz,ShiftRowsLeft
2634   ld  bc,-16
2635   add hl,bc
2636   ex  de,hl
2637   pop bc
2638   dnz ShiftRightLoop
2639   ret
2640
2641 ShiftLeft1:
2642   ld  a,1
2643 ShiftLeft:
2644   ld  (ShiftLeftCounter),a
2645   ld  a,c
2646   ld  (ShiftLeftChunk),a
2647   rla
2648   jr  nc,ShiftLeftSameByte
2649   dec hl
2650 ShiftLeftSameByte:
2651   ex  de,hl
2652   ld  bc,-16
2653   add hl,bc
2654 NewSprite:
2655   ex  de,hl
2656   ld  b,57
2657 ShiftLeftLoop:
2658   psh bc                        ; >> 1
2659   ld  bc,-32
2660   add hl,bc
2661   ex  de,hl
2662   ld  a,(de)
2663 ShiftLeftChunk:
2664   or  a
2665   cal c,_SHRACC
2666   ld  c,0
2667 ShiftLeftCounter = $-1
2668 ShiftRowsRight:
2669   psh hl                        ; >> 2
2670   rra
2671   ld  b,16
2672 ShiftRowRight:
2673   rr  (hl)
2674   inc hl
2675   dnz ShiftRowRight
2676   pop hl                         ; << 1
2677   dec c
2678   jr  nz,ShiftRowsRight
2679   ld  bc,-16
2680   add hl,bc
2681   ex  de,hl
2682   pop bc                         ; << 0k
2683   dnz ShiftLeftLoop
2684   ret
2685
2686 Chunk:
2687   psh hl                        ; >> 1
2688   psh de                        ; >> 2
2689   ld  c,16
2690   add hl,bc
2691   ld  b,57
2692 ChunkScreen:
2693   psh bc                        ; >> 3
2694   ld  bc,-32
2695   add hl,bc
2696   ex  de,hl
2697   ld  a,(de)
2698   cal _SHRACC
2699   ld  b,16
2700 ChunkRow:
2701   dec hl
2702   rld
2703   dnz ChunkRow
2704   ex  de,hl
2705   pop bc                         ; << 2
2706   dnz ChunkScreen
2707   pop de                         ; << 1
2708   pop hl                         ; << 0k
2709   ld  c,$37 ;scf
2710   ret
2711
2712 ;----------- draw ------------
2713
2714 ;--- pixel ---
2715
2716 chk4pixels: ;&&
2717   cal CheckPixel
2718   inc b
2719   cal CheckPixel
2720   inc c
2721   cal CheckPixel
2722   dec b
2723   cal CheckPixel
2724   dec c
2725   ret
2726 CheckPixel: ;at bc in d
2727   cal FindPixel
2728   and (hl)
2729   ret z
2730   dec d
2731   ret
2732
2733 ;CLEM's FIND_PIXEL (131+? cycles; 28+4 bytes)
2734 ;(b,c) to hl:a; "destroyes" ahl
2735
2736 FindPixel: ;(b,c) to hl:a
2737   ld  h,0
2738   ld  l,c    ;hl=y
2739   add hl,hl
2740   add hl,hl
2741   ld  a,b    ;a=x
2742   rra
2743   add hl,hl
2744   rra
2745   add hl,hl
2746   add hl,hl  ;hl=32*y
2747   rra        ;a=x/8
2748   or  l
2749   ld  l,a
2750   ld  a,b
2751   and 7
2752   cpl
2753   rlca
2754   rlca
2755   rlca
2756   ld  (FP_Bit),a
2757   xor a
2758 FP_Bit =$+1
2759   set 0,a
2760
2761   psh de ;&&&
2762   ld  de,ScrBuffer
2763   add hl,de
2764   pop de
2765   ret
2766
2767 ;--- sprite ---
2768
2769 PutSprite:  ;||@(b,c)
2770   ;by SHIAR  only ix saved
2771   cal FindPixel
2772 putspr:
2773   ld  (beginbit),a
2774   ld  a,0
2775 sprsize =$-1
2776   ld  b,a ;rows
2777 sprloopy:
2778   psh bc ;rows
2779   psh hl
2780   ld  a,(de)
2781   ld  c,a
2782   inc de
2783   ld  a,(sprsize)
2784   ld  b,a ;width
2785 beginbit =$+1
2786   ld  a,1
2787 sprloopx:
2788   sla c ;draw?
2789   jr  nc,sprnodraw
2790   psh af
2791   xor (hl)
2792   ld  (hl),a
2793   pop af
2794 sprnodraw:
2795   rrca ;next bit
2796   jp  nc,nextbitok
2797   inc hl ;next byte
2798 nextbitok:
2799   dnz sprloopx
2800
2801   pop hl
2802   ld  bc,32 ;next line
2803   add hl,bc
2804   pop bc
2805   dnz sprloopy
2806   ret
2807
2808 ;--- objects ---
2809
2810 drawstuff:
2811   ld  a,(hl)
2812   inc hl
2813   or  a ;0 =
2814   ret z ;no more
2815
2816   ld  d,(hl)
2817   inc hl
2818   ld  e,(hl)
2819   inc hl
2820   ld  b,(hl)
2821   inc hl
2822   psh hl
2823   ld  l,(hl)
2824   ld  h,b
2825
2826   dec a ;1 = line
2827   cal z,drawline
2828   dec a ;2 = fatline
2829   cal z,drawfatline
2830   dec a ;3 = box
2831   cal z,drawbox
2832   dec a ;4 = circle
2833   cal z,drawcircle
2834   dec a ;5 = hline
2835 #ifdef hlines
2836   cal z,drawhline
2837 #else
2838   cal z,drawline
2839 #endif
2840
2841   pop hl
2842   inc hl
2843   jr  drawstuff
2844
2845 drawbox: ;(d,e)-(h,l)
2846   ld  b,l ;Delta-y
2847 #ifdef hlines
2848 boxloop:
2849   cal drawhline
2850   inc e
2851   dnz boxloop
2852   ret
2853 drawhline: ;(d,e)-(h,e)
2854   psh bc
2855   ld  b,d
2856   ld  c,e
2857   psh hl
2858   cal FindPixel
2859   ld  c,a ;starting mask
2860   ld  a,h
2861   sub b
2862   ld  b,a
2863   inc b ;1+x2-x1
2864 hlineloop:
2865   ld  a,(hl)
2866   or  c
2867   ld  (hl),a
2868   rrc c ;mask >>
2869   jr  nc,hlinenext
2870   inc hl ;next byte
2871 hlinenext:
2872   dnz hlineloop
2873   pop hl
2874   pop bc
2875   ret
2876 #else
2877   ld  l,e
2878 boxloop:
2879   cal drawline
2880   inc l
2881   inc e
2882   dnz boxloop
2883   ret
2884 #endif
2885
2886 drawfatline:
2887   cal drawline
2888   inc d
2889   inc h
2890   cal drawline
2891   inc e
2892   inc l
2893   cal drawline
2894   dec d
2895   dec h
2896   jp  drawline
2897
2898 ;LINE (d,e)-(h,l)
2899 ;destroyes a
2900
2901 drawline: ;(d,e)-(h,l)
2902   psh bc  ;destr: a
2903   psh hl
2904   psh de
2905   ld  a,d
2906   cp  h
2907   jr  c,lineOrdered
2908   ex  de,hl
2909 lineOrdered:
2910   ld  b,d
2911   ld  c,e
2912   psh hl
2913   psh bc
2914   cal FindPixel
2915   pop bc
2916   pop de
2917 connectedLine:
2918   psh hl
2919   ld  h,c
2920   ld  c,a
2921   ld  a,d
2922   sub b
2923   ld  b,a
2924   ld  a,e
2925   jr  nz,LineNotPoint
2926   cp  h
2927   jr  nz,LineNotPoint
2928   pop hl
2929   jr  DoneLine
2930 LineNotPoint:
2931   sub h
2932   ld  de,32
2933   jr  nc,LinePositiveY
2934   neg
2935   ld  de,-32
2936 LinePositiveY:
2937   cp  b
2938   jr  nc,SteepLine
2939   add a,a
2940   ld  (line2sm+1),a
2941   ld  h,a
2942   xor a
2943   sub b
2944   add a,a
2945   ld  (line1sm+1),a
2946   ld  a,h
2947   sub b
2948   pop hl
2949 LineLoopGentle:
2950   psh af
2951   ld  a,(hl)
2952   or  c
2953   ld  (hl),a
2954   rrc c
2955   jr  nc,$+3
2956   inc hl
2957   pop af
2958   jp  m,line2sm
2959 line1sm:
2960   add a,0
2961   add hl,de
2962 line2sm:
2963   add a,0
2964   dnz LineLoopGentle
2965 DoneLine:
2966   ld  a,(hl)
2967   or  c
2968   ld  (hl),a
2969   pop de
2970   pop hl
2971   pop bc
2972   ret
2973 SteepLine:
2974   ld  h,a
2975   neg
2976   add a,a
2977   ld  (line3sm+1),a
2978   ld  a,b
2979   add a,a
2980   ld  (line4sm+1),a
2981   sub h
2982   ld  b,h
2983   pop hl
2984 LineLoopSteep:
2985   psh af
2986   ld  a,(hl)
2987   or  c
2988   ld  (hl),a
2989   add hl,de
2990   pop af
2991   jp  m,line4sm
2992 line3sm:
2993   add a,0
2994   rrc c
2995   jr  nc,$+3
2996   inc hl
2997 line4sm:
2998   add a,0
2999   dnz LineLoopSteep
3000   jr  DoneLine
3001
3002 drawcircle: ;(d,e),h    ;de=x,y; h=z
3003   ld  c,h               ;c=yy=z
3004   ld  a,h
3005   neg
3006   ld  l,a               ;l=-z
3007   xor a
3008   ld  b,a               ;b=xx=0
3009   dec a                 ;-$00**
3010   ld  h,a               ;hl=zz=-z
3011 circloop:
3012   psh de                ;x,y
3013   ex  (sp),hl           ;push zz \ pop x,y
3014   cal circledraw        ;(x-xx,y+yy)-(x+xx,y+yy)
3015                         ;(x-xx,y-yy)-(x+xx,y-yy)
3016   cal circledraw        ;(x-yy,y+xx)-(x+yy,y+xx)
3017                         ;(x-yy,y-xx)-(x+yy,y-xx)
3018
3019   ex  (sp),hl           ;push x,y \ pop zz
3020   xor a
3021   ld  d,a               ;d=0
3022   dec a                 ;-256<h<0 = $FF**
3023   cp  h                 ;h<0?
3024   jr  z,circlenext      ;jump if zz<0
3025
3026   ld  a,c               ;yy
3027   dec a                 ;89<a<128
3028   add a,a               ;a=2yy-2 ;nc
3029   ld  e,a               ;de=a
3030   sbc hl,de             ;zz=zz-2yy+2
3031   dec c                 ;yy--
3032 circlenext:
3033   ld  a,b               ;xx
3034   inc a                 ;0<a<92
3035   add a,a               ;2xx+2
3036   inc a
3037   ld  e,a               ;de=a
3038   add hl,de             ;zz=zz+2xx+3
3039
3040   pop de                ;x,y
3041   ld  a,b
3042   cp  c
3043   ret nc                ;xx>=yy
3044   inc b                 ;xx++
3045   jr  circloop
3046
3047 circledraw:             ;destr:de
3048   psh hl
3049   ld  a,h               ;hl=x,y
3050   sub b                 ;bc=xx,yy
3051   ld  d,a               ;d=x-xx
3052   add hl,bc             ;h=x+xx; l=y+yy
3053   ld  e,l               ;e=y+yy
3054   cal drawline          ;(h-b,l+c)-(h+b,l+c)
3055   ld  a,l
3056   sub c                 ;a=y again
3057   sub c
3058   ld  l,a               ;l=y-yy
3059   ld  e,l               ;e=l=y-yy
3060   cal drawline          ;(h-b,l-c)-(h+b,l-c)
3061   ld  a,b               ;swap xx and yy
3062   ld  b,c
3063   ld  c,a               ;ex b,c
3064   pop hl
3065   ret
3066
3067
3068
3069
3070
3071 ;**** link routines ****
3072 ;these are identical in concept to the routines used in ZTetris, ZPong, and probably
3073 ;every other link game out there.  However, these are commented :)
3074 losses: .dw 0
3075 Csend:
3076   ld  b,32
3077 csendwait:
3078   nop
3079   dnz csendwait
3080   cal Qsend
3081   jr  c,Csend
3082   ret
3083 Qsend:
3084 send:
3085 ;inputs: c=byte to send, both wires must be high by default
3086 ;outputs: b=8-number of bits sent, both wires high, goes to game over on certain conditions
3087 ;destroys: af,bc,de
3088         in a,(7)
3089         and %00000011
3090         jr z,killlink           ;if both lines low, get out of here (game over signal)
3091         ld b,8                          ;sending 8 bits
3092 sendloop:
3093         ld de,$8000                     ;error timer
3094         rl c                            ;force high bit into carry
3095         ld a,%11010100          ;lower the red wire by default (sending 0) ($d4)
3096         jr nc,selected          ;if high bit was 0, use above value
3097         ld a,%11101000          ;if 1, lower the white wire instead ($e8)
3098 selected:
3099         out (7),a                       ;put it out the link port
3100 waitconfirm:
3101         call linktimer
3102         in a,(7)                        ;see what the wires are doing
3103         and %00000011           ;check lower 2 bits
3104         jr nz,waitconfirm       ;if both bits 0, data was received ok (both wires low)
3105         ld a,%11000000
3106         out (7),a                       ;give the ok to raise both wires (one will be done automatically) ($c0)
3107 waitconfirm2:
3108         call linktimer
3109         in a,(7)
3110         and %00000011
3111         cp 3
3112         jr nz,waitconfirm2      ;wait for other calc to raise the other wire
3113         djnz sendloop           ;continue sending
3114         xor a                           ;reset c; ld a,0
3115         ld (losses),a           ;reset number of losses
3116         ret
3117
3118
3119 Crecv:
3120   cal receive
3121   jr  c,Crecv
3122   ret
3123 Qrecv:
3124 receive:
3125 ;inputs: both wires must be high by default
3126 ;outputs: c=byte received, b=8-number of bits received, both wires high
3127 ;       goes to game over on certain conditions
3128 ;destroys: af,bc,de
3129         in a,(7)
3130         and %00000011
3131         jr z,killlink           ;game over signal applies to receiving too
3132         ld b,8                          ;receiving 8 bits
3133 receiveloop:
3134         ld de,$8000                     ;error timer
3135 waitreceive:
3136         call linktimer
3137         in a,(7)
3138         and %11
3139         cp 3                            ;if bits 0 and 1 set, both wires are high
3140         jr z,waitreceive        ;wait for one of the wires to go low
3141         rra                                     ;check red wire status
3142         rl c                            ;if set, red is high (thus white is low), so put the correct bit into c
3143         rra                                     ;now check white wire (since the flags are destroyed)
3144         ld a,%11010100          ;$d4
3145         jr nc,selected2         ;if white is low, lower red and vice versa              
3146         ld a,%11101000          ;$e8
3147 selected2:
3148         out (7),a                       ;so now both wires are low
3149 waitreceive2:
3150         call linktimer
3151         in a,(7)
3152         and %11
3153         jr z,waitreceive2       ;wait for the wire we didn't lower to go high again (the other will remain low)
3154         ld a,%11000000          ;$c0
3155         out (7),a                       ;raise both wires since the other calc will have given the ok sign
3156         djnz receiveloop        ;if not done, wait for next bit
3157         xor a                           ;reset c
3158         ld (losses),a           ;reset number of losses
3159         ret
3160
3161 linktimer:                              ;leave if we have to wait too long (and return an error)
3162         dec de
3163         ld a,d
3164         or e                            ;see if de is 0
3165         ret nz                          ;if not, keep going as usual
3166                                                 ;otherwise we have to deal with a link failure
3167         ld a,%11000000          ;$c0
3168         out (7),a                       ;reset link status (both high)
3169         ld a,(losses)           ;see how many consecutive losses we have
3170         inc a
3171         ld (losses),a           ;add this loss to it
3172         pop de                          ;fix the stack to leave the link routine (de is ok to destroy)
3173         cp 20                           ;see if this is the 20th consecutive failure
3174         ret c                           ;if not, keep playing
3175                                                 ;otherwise, all is probably lost...
3176
3177 killlink2:
3178         jr linkend
3179 killlink:
3180 linkend:
3181   jp  z,Exit
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191 #ifdef 0
3192 ;-----------------------------
3193 ;----------- link ------------
3194 ;-----------------------------
3195
3196 timeout = $800
3197
3198 checklink:
3199   dec de
3200   ld  a,d
3201   or  e
3202   jr  z,linkerror
3203
3204   ld  a,$BF
3205   out (1),a
3206   in  a,(1)
3207   bit 6,a
3208   jp  z,Exit
3209
3210   in  a,(7)
3211   and %11
3212   ret
3213
3214 linkerror:
3215   scf
3216   ld  a,%11
3217   pop hl
3218   ret
3219
3220 ;--------------
3221 ;---- SEND ----
3222 ;--------------
3223
3224 Csend:          ;--- send 8 bits in A --- destr:abcdehl ---
3225   ld  c,a
3226 Csendloop:
3227   cal Qsend
3228   ret nc                ;NC = all ok
3229   ld  a,D0HD1H
3230   out (7),a             ;both high
3231   jr  Csendloop         ;CF = error
3232
3233 Qsend:          ;--- try to send 8 bits in C; CF=error --- destr:abcdehl ---
3234   ld  de,timeout
3235   cal checklink
3236   cp  %11               ;are they?
3237   scf
3238   ret nz                ;nope, wait
3239   ld  b,8               ;bits to send
3240 sendloop:
3241   ld  de,timeout
3242   rl  c                 ;bit to send in cf
3243   ld  a,D0LD1H          ;0: lower white
3244   jr  nc,sendbit
3245   ld  a,D0HD1L          ;1: lower red
3246 sendbit:
3247   out (7),a             ;lower one (send bit)
3248 sendwaitack:
3249   cal checklink         ;other calc must lower other wire
3250   jr  nz,sendwaitack
3251   ld  a,D0HD1H          ;raise one, ok to raise other
3252   out (7),a
3253 sendfinish:
3254   cal checklink
3255   cp  %11               ;both raised (by other calc)
3256   jr  nz,sendfinish
3257   nop \ nop
3258   dnz sendloop          ;repeat for all bits
3259   xor a                 ;nc...
3260   ret                   ;=ok
3261
3262 ;--------------
3263 ;---- RECV ----
3264 ;--------------
3265
3266 Crecv:          ;--- receive 8 bits into A/C --- destr:abcdehl ---
3267   cal Qrecv
3268   ret nc                ;return if all went ok
3269   ld  a,D0HD1H
3270   out (7),a             ;raise both on error
3271   jr  Crecv             ;and try again
3272
3273 Qrecv:          ;--- receive 8 bits into A/C; CF=error --- destr:abcdehl ---
3274   ld  de,timeout
3275   cal checklink
3276   jp  z,Exit            ;both low = error, quit
3277   cp  %11
3278   scf
3279   ret z                 ;both high = nothing yet, wait
3280   ld  b,8               ;bits to receive
3281 recvloop:
3282   ld  de,timeout
3283 recvwait:
3284   cal checklink
3285   cp  %11
3286   jr  z,recvwait        ;both high = nothing sent (yet)
3287   rra                   ;received bit in cf
3288   ld  a,D0LD1H
3289   jr  c,received        ;lower white wire as well
3290   ld  a,D0HD1L          ;lower red
3291 received:
3292   rl  c                 ;save bit in c
3293   out (7),a             ;both wires low
3294 recvwaitack:
3295   cal checklink
3296   jr  z,recvwaitack     ;same wire will be raised again by other calc
3297   ld  a,D0HD1H
3298   out (7),a             ;raise both
3299 recvfinish:
3300   dnz recvloop          ;repeat for all bits
3301   xor a                 ;nc=no error
3302   ld  a,c               ;result in a
3303   ret
3304 #endif
3305
3306 ;-----------------------------
3307 ;---------- levels -----------
3308 ;-----------------------------
3309
3310 LevelDef:
3311   .db 5,4,15,15,0,0     ;peas,speed,growth,begin_size,sprite,balls
3312   .db 0,2,63            ;start d, y, x
3313   .db 128,57            ;field width (128-255), height (57-255)
3314   .db 0                 ;no additional lines, boxes
3315   .db 255
3316    ret
3317
3318 LevelDefM:
3319   .db 8,4,15,15,0,0
3320   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
3321   .db 128,57
3322   .db 0
3323
3324   .db 8,0,18,12,5
3325   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
3326   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
3327   .db 128,57
3328   .db 0
3329
3330   .db 8,5,18,12,0,0
3331   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
3332   .db 128,57
3333  .db 4,40,26,20,0
3334  .db 4,90,40,11,0,0
3335
3336 LevelDefT: ;tron=no delay
3337   .db 8,4,18,12,5
3338   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
3339   .db $40,30,64,$C0,30,64, $00,30,64,$80,30,64
3340   .db 128,57
3341   .db 0
3342
3343 LevelDefC: ;ctf
3344   .db 8,4,18,12,5
3345   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
3346   .db $40,30,64,$C0,30,64, $00,30,64,$80,30,64
3347   .db 128,57
3348   .db 10,10,50,50
3349   .db 0
3350
3351 ;-----------------------------
3352 ;---------- data -------------
3353 ;-----------------------------
3354
3355 wdPicture = 16
3356 wtPicture:
3357 .db %01001010,%00101001,%00000111,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01110000,%00000000,%00000000,%00000000,%01000000,%00000000
3358 .db %10001010,%10101000,%10001111,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01111000,%00000000,%00000000,%00000000,%10100100,%01000000
3359 .db %10101010,%10101010,%10011100,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00011100,%00001110,%00000000,%00000000,%10101010,%10100000
3360 .db %01010001,%01000101,%00011000,%00011111,%00000000,%01111111,%11000000,%00111100,%00011110,%01111000,%00001100,%00011111,%00000000,%00000000,%11001001,%10100000
3361 .db %00000000,%00000000,%00111000,%00111111,%10000000,%11111111,%11100000,%11111110,%00111111,%11111100,%00001100,%00111011,%10000000,%00000011,%10001000,%00100000
3362 .db %01101010,%10010011,%00110000,%01110001,%11000001,%11000000,%01110001,%11100110,%01110011,%11001110,%00001100,%00110001,%10000000,%00000000,%10010000,%00100000
3363 .db %10001010,%00101010,%10110000,%01100000,%11000001,%10000000,%00111001,%10000000,%01100111,%11100110,%00001110,%01110001,%10000000,%00000000,%01100000,%01000000
3364 .db %11101110,%10111011,%00110000,%01100000,%11000001,%10110000,%00011011,%10000000,%11101110,%01110111,%00001110,%01110001,%10000011,%11100000,%00000011,%10000000
3365 .db %00101010,%10101010,%10110000,%01110001,%11000001,%10110000,%00011011,%00000000,%11001100,%00110011,%00000111,%11100001,%10001100,%00011000,%00010000,%00000000
3366 .db %11001010,%10101010,%10110000,%00110001,%10000001,%10110000,%00011011,%00000000,%11001100,%00110011,%00000011,%11000011,%10010000,%00000100,%00100011,%00001100
3367 .db %00000000,%00000000,%00111000,%00111011,%10000011,%10110000,%00011011,%00000000,%11001110,%01110011,%00000000,%00000011,%00010011,%00000100,%00100100,%10010010
3368 .db %00111001,%11000111,%00011000,%00011111,%00000011,%00110000,%00011011,%00000000,%11000111,%11100011,%10000000,%00000011,%00001100,%10000100,%00101000,%10010100
3369 .db %01100101,%00101000,%00011100,%00001110,%00000111,%00111000,%00111011,%10000000,%11000011,%11000001,%10000000,%00000111,%00000000,%01001110,%00101000,%10011000
3370 .db %01001101,%11001011,%00001110,%00111111,%10001110,%00011100,%01110001,%10000000,%11100000,%00000001,%11100000,%00001110,%00000000,%01010101,%00101000,%10011000
3371 .db %00111001,%01100111,%00000111,%11111011,%11111100,%00001111,%11100001,%11000000,%01100000,%00000000,%11111111,%11111100,%00000000,%10010101,%00100110,%00010100
3372 .db %00000000,%00000000,%00000011,%11100000,%11111000,%00000111,%11000000,%11000000,%01100000,%00000000,%00111111,%11111000,%11111111,%00001000,%11000001,%11100011
3373
3374 txtMenu:  .db "Mode",0  ;1st menu item
3375           .db "Level",0 ;2nd
3376           .db "Limit",0 ;...
3377           .db "Worms",0
3378           .db "worm #",0
3379           .db "controls",0
3380 posMenu:  .dw $$2418,$231E,$2524,$1F2A,$1730,$1936
3381 txtGame:  .db "Singleplayer",0
3382 txtGame1: .db "Peaworm",0
3383 txtGame2: .db "Tron",0
3384 txtGame3: .db "Deathmatch",0
3385 txtGame4: .db "Foodmatch",0
3386 txtGame5: .db "LinkMatch",0
3387 txtGame6: .db "Race",0
3388 txtGame7: .db "CTF",0
3389 ;            .db "Domination",0    ;8
3390 posGame:  .db 0,txtGame1-txtGame
3391           .db txtGame2-txtGame
3392           .db txtGame3-txtGame
3393           .db txtGame4-txtGame
3394           .db txtGame5-txtGame
3395           .db txtGame6-txtGame
3396           .db txtGame7-txtGame
3397
3398 txtKeyleft: .db "Left",0
3399 txtKeyright:.db " | Right",0
3400 txtLevsel:  .db $CF," Select levels: ",5,0
3401 txtEName:   .db "Enter name player ",0
3402 txtWaiting: .db "Waiting...",0
3403 txtReceive: .db "Receiving..." ;,0
3404
3405 TrigPrecalc:
3406 .db   0,  3,  6,  9, 12, 15, 18, 21
3407 .db  24, 27, 30, 33, 36, 39, 42, 45
3408 .db  48, 51, 54, 57, 59, 62, 65, 67
3409 .db  70, 73, 75, 78, 80, 82, 85, 87
3410 .db  89, 91, 94, 96, 98,100,102,103
3411 .db 105,107,108,110,112,113,114,116
3412 .db 117,118,119,120,121,122,123,123
3413 .db 124,125,125,126,126,126,126,126
3414 .db 127
3415
3416 txtLevel:  .db "Level ",0
3417 txtWorms:  .db "Worms: 0",0     ;follows txtLevel
3418 txtName:   .db "Name",0
3419 txtDied:   .db "Died    "       ;follows txtName
3420 txtScore:  .db "Score",0        ;follows txtDied
3421 txtLeft:   .db " left",0        ;follows txtScore
3422 txthiscore:.db "HiScore:",0
3423 txtReady:  .db "Prepare!",0
3424 txtposReady = 7
3425 txtGO:     .db 5,5,5,5,5," GAME OVER ",$CF,$CF,$CF,$CF,$CF,0
3426
3427 _datalink  = %00000001 ;linkplay
3428 _datalivel = %00000010 ;lives=0 limit
3429 _datafoodl = %00000100 ;left=0 limit
3430 _datanextl = %00001000 ;next level if left=0
3431 _datasingl = %00001000 ;singleplayer=1
3432                        ;1=hiscore+keep_length
3433 _datafood  = %00010000 ;food present
3434 _datadie   = %01000000 ;worm dies on impact
3435 _datascore = %10000000 ;score>=100 limit
3436 _datamultpeas = %00100000
3437 _datasp    = %01011110
3438
3439 datalevels: .dw LevelDef, LevelDefM
3440             .dw LevelDefT,LevelDefM
3441             .dw LevelDefM,LevelDefM
3442             .dw LevelDefM,LevelDefC
3443 nrlevels:   .db 1,3,1,3,3,3,3,1     ;=defaults
3444
3445 savestart:
3446
3447 gamesingle   =  0
3448 datasingle: .db %01011110,3,1,1 ;3 lives (<must b unique)
3449 gamepeas     =  1
3450 datapeas:   .db %01011010,1,1,1 ;1 "
3451 gametron     =  2
3452 datatron:   .db %01000010,1,2,1
3453 gamedeathm   =  3
3454 datadeathm: .db %01000010,3,2,1
3455 gamefoodm    =  4
3456 datafoodm:  .db %11010000,10,2,1 ;10 score limit (=100)
3457 gamelinkm    =  5
3458 datalinkm:  .db %01000011,3,2,1
3459 gamerace     =  6
3460 datarace:   .db %10000000,10,2,1
3461 gamectf      =  7
3462 datactf:    .db %11100000,9,4,1
3463 ;gamedomin    =  8
3464 ;datadomin:  .db %01100000,3 ;==(8 modes)
3465
3466 worm1set:  .dw worm1p,worm1p
3467            .db %11110111,%00,-01,K_RIGHT,K_LEFT
3468 worm1name: .db "Wormy   ",0
3469 worm2set:  .dw worm2p,worm2p
3470            .db %11111011,%11,-01,K_F2,K_F1
3471 worm2name: .db "Viper   ",0
3472 worm3set:  .dw worm3p,worm3p
3473            .db %11111011,%00,-01,K_COMMA,K_STO
3474 worm3name: .db "Nibbler ",0
3475 worm4set:  .dw worm4p,worm4p
3476            .db %11111011,%00,-01,K_PLUS,K_ENTER
3477 worm4name: .db "Jim     ",0
3478
3479 defhiscrpos:
3480   .dw 0,0,0,0,0,0
3481
3482 saveend:
3483
3484                ;set:
3485 heading  = 0   ;level*
3486 pos      = 2   ;level*
3487 pos2     = 4   ;level
3488 grow     = 6   ;level
3489 died     = 8   ;game
3490 score    = 9   ;game
3491 delay    = 11  ;game
3492                ;19B @game
3493 lives    = 12
3494 head     = 13  ;4B (head=tail)
3495 tail     = 15  ;also@next level
3496 storepos = 17
3497 reserv   = 18  ;loop (race:lap|ctf:pea)
3498 input    = 19
3499 left     = 20
3500 right    = 21
3501 name     = 22
3502 wormsize = 31
3503
3504 startdelay    = 30
3505 respawndelay  = 30
3506 maxnamelength = 8+1
3507
3508 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3509 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3510 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3511 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3512 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3513 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3514 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3515 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3516 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3517 .db "   shiar0@hotmail.com",0
3518
3519 defspritesz = 4
3520 defspriteimg:   .db %01100000
3521                 .db %11110000
3522                 .db %11110000
3523                 .db %01100000
3524
3525 deflevels:
3526   .db "Internal Levels" ;,0
3527
3528   .db 0,deflevels/256,deflevels&255
3529 templevels:
3530
3531 ;-----------------------------
3532 ;----------- end -------------
3533 ;-----------------------------
3534
3535   .end
3536
3537 .end