wormedit 0.93.1324
[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   ;"greys" 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 -- beta 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 ;don't end game
1446   ld  a,(Gametype)
1447   cp  gametron
1448   jr  nz,anyworm ;if not Tron, quit at any worm's death
1449   ld  a,(nrworms)
1450   ld  b,a ;# of worms
1451   ld  hl,worm1+lives-(worm2-worm1)
1452   ld  de,worm2-worm1
1453   xor a ;check for 0 lives
1454 checklives:
1455   add hl,de ;next worm
1456   cp  (hl) ;lives==0?
1457   ret nz ;any >0: don't exit
1458   dnz checklives
1459 anyworm:
1460   ld  a,$A7 ;exit@end of turn
1461   ld  (CheckExit),a ;set exit state
1462   ret ;finish turn
1463 #endif
1464
1465 Exit:
1466   ld  sp,0 ;pop all
1467 SpSave = $-2
1468   ld  a,D0HD1H
1469   out (7),a
1470   cal _clrWindow
1471   ld  hl,txtGO
1472   cal _puts
1473   ld  hl,$FC00
1474   ld  b,16*8
1475   cal menuinvloop ;invert
1476   inc h ;$FD80
1477   ld  b,16
1478   cal menuinvloop ;<hr>
1479   ld  hl,$FCE0
1480   ld  b,16
1481   cal menuinvloop ;<hr>
1482 ; ld  l,$74
1483 ; ld  b,8
1484 ; cal menuinvloop
1485   ld  hl,_curRow
1486   inc (hl)
1487   ld  hl,txtGame
1488 CURtxtGame =$-2
1489   cal _puts
1490   ld  a,$0D ;$0D02
1491   ld  (_curCol),a
1492   cal showLevel
1493
1494   ld  de,$1901
1495   ld  (_penCol),de
1496   ld  hl,txtName
1497   cal _vputs ;Name
1498   ld  a,$4F
1499   ld  (_penCol),a
1500   cal _vputs ;Died    Score
1501   ld  de,$0004
1502   ld  (_curRow),de
1503
1504   ld  a,(nrworms)
1505   ld  b,a
1506   ld  hl,worm1+died
1507 displayWormStats:
1508   psh bc
1509   psh hl
1510
1511   ld  bc,left-died
1512   add hl,bc ;+left
1513   xor a
1514   cp  (hl)  ;input=0 = link
1515   jr  nz,NoLinkIndic
1516   ld  a,8
1517   ld  (_curCol),a
1518   ld  a,$DC ;-O
1519   cal _putc
1520   xor a
1521   ld  (_curCol),a
1522 NoLinkIndic:
1523   inc hl
1524   inc hl ;+name
1525   cal _puts
1526
1527   pop hl
1528   psh hl
1529   ld  a,13
1530   ld  (_curCol),a
1531   ld  a,(hl) ;worm+died
1532   cal showA
1533   pop hl
1534   psh hl
1535
1536   ld  a,16
1537   ld  (_curCol),a
1538   inc hl ;worm+score
1539   cal _ldHLind ;ld hl,(hl)
1540   cal showHL ;worm+score
1541
1542   pop hl
1543   ld  bc,worm2-worm1
1544   add hl,bc
1545   pop bc
1546   dnz displayWormStats
1547
1548   ld  a,(Gametype)
1549   or  a ;singleplayer (0) only
1550   jr  nz,hilevelcheckdone
1551 checkhilevel:
1552   ld  hl,nrlevels
1553   ld  a,(Level)
1554   cp  (hl)
1555   jr  c,hilevelcheckdone
1556   ld  (hl),a ;save local
1557   ld  c,a
1558   ld  a,0
1559 hilvlposa =$-1
1560   ld  hl,nrlevels
1561 hilvlposhl =$-2 ;save external
1562   cal _writeb_inc_ahl ;ld (ahl),c
1563 hilevelcheckdone:
1564
1565   ld  a,(gameCar)
1566   and _datasingl
1567
1568   jr  z,hiscorecheckdone
1569 checkhiscore:
1570   cal loadhiscoreposinahl
1571   cal _Get_Word_ahl ;de=old_hi
1572  psh de
1573  cal _RAM_PAGE_1 ;&&
1574  pop de
1575   ld  hl,(worm1+score)
1576
1577   ld  a,h           ;New
1578   cp  d             ;Old
1579   jr  c,NotNewHigh  ;New<Old
1580   jr  nz,newhigh    ;New>Old
1581
1582   ld  a,e           ;old
1583   cp  l             ;new
1584   jr  nc,NotNewHigh ;new<old
1585
1586 newhigh:            ;New>=Old
1587   ex  de,hl
1588   cal loadhiscoreposinahl
1589   cal _Set_Word_ahl ;de->(ahl)
1590  cal _RAM_PAGE_1
1591
1592 NotNewHigh: ;de=current hiscore
1593   ld  hl,$0807
1594   ld  (_curRow),hl
1595   ld  hl,txthiscore
1596   cal _puts
1597   ex  de,hl ;pop
1598   cal showHL
1599 hiscorecheckdone:
1600
1601   cal releasekeys
1602 waitkey:
1603   halt
1604   halt
1605   cal GET_KEY
1606   cp  K_ENTER
1607   jp  z,DisplayMenu
1608   cp  K_SECOND
1609   jp  z,DisplayMenu
1610   cp  K_EXIT
1611   jr  nz,waitkey
1612
1613 ;x123456789012345678901
1614 ;>>>>>> GAME OVER <<<<<
1615 ;2Multiplayer
1616 ;3Level 01
1617 ;4           Died Score:
1618 ;5NameName     03 00070
1619 ;6Worm#02 @    05 00120
1620 ;7Worm#03      15 00030
1621 ;8Snaky   @    00 04820
1622
1623 ExitNoStats:
1624   ld  hl,_asapvar
1625   rst 20h ;_ABS_MOV10TOOP1
1626   rst 10h ;_FINDSYM
1627   ld  hl,savestart-_asm_exec_ram+4
1628   xor a
1629   add hl,de
1630   adc a,b ;ahl=bde+4
1631   cal _SET_ABS_DEST_ADDR
1632
1633   xor a
1634   ld  hl,savestart
1635   cal _SET_ABS_SRC_ADDR
1636   ld  hl,saveend-savestart
1637   cal _SET_MM_NUM_BYTES
1638   cal _mm_ldir
1639
1640   cal releasekeys
1641   res 4,(iy+9)
1642   set 2,(iy+13)
1643   im  1 ;remove keyfix
1644   jp  _clrWindow
1645
1646 loadhiscoreposinahl:
1647   ld  a,(Level)
1648   ld  b,a
1649
1650   ld  h,0            ;hl=
1651   ld  a,(nrlevels+1) ;# peaworm lvls
1652   add a,a
1653   ld  l,a
1654
1655   ld  a,(Gametype)
1656   dec a
1657   ld  c,a
1658   dec a              ;z=(Gametype)=2
1659   jr  z,tronhi
1660   ld  l,h            ;hl=0
1661 tronhi:
1662
1663   xor a              ;ahl=0(+x)
1664   psh bc
1665   ld  bc,defhiscrpos
1666 hiscrposhl =$-2
1667   add hl,bc
1668   pop bc
1669   adc a,0
1670 hiscrposa =$-1       ;ahl=saveloc
1671
1672   inc c
1673   ret z              ;(Gametype)=0
1674 addlevelposition:
1675   cal _AHL_PLUS_2_PG3
1676   dnz addlevelposition
1677   ret
1678
1679 ;-----------------------------
1680 ;----------- worm ------------
1681 ;-----------------------------
1682
1683 respawncheck:
1684   cp  respawndelay-1
1685   jr  nz,unnamedlabel
1686   cal saverespawncounter
1687 removeworm:
1688   ld  h,(ix+tail+1)
1689   ld  l,(ix+tail)
1690   ld  d,(ix+head+1)
1691   ld  e,(ix+head)
1692   jr  DoesWormTailEqualsWormHead ;chk4 size=0
1693 removewormloop:
1694   ld  c,(hl)
1695   inc hl
1696   ld  b,(hl)
1697   inc hl
1698   cal resbit
1699   psh hl
1700   cal res4pixels
1701   pop hl
1702   inc (ix+grow)
1703 DoesWormTailEqualsWormHead:
1704   cal _cphlde
1705   jr  nz,removewormloop
1706
1707   ld  a,(gameCar)
1708   and _datasingl
1709   jr  nz,safewormsizedone
1710   ld  a,0
1711 beginsize =$-1
1712   ld  (ix+grow),a
1713 safewormsizedone:
1714
1715   ;de=ix+head
1716   ld  (ix+tail+1),d
1717   ld  (ix+tail),e ;head=tail/size=0
1718   ret
1719
1720 unnamedlabel:
1721   cp  1
1722   ld  h,a
1723   jr  nz,saverespawncounter
1724 respawndue:
1725   ld  l,a
1726   cal inputcall
1727   ld  a,h ;previous
1728   cp  l   ;changed?
1729   ret z
1730   ld  (ix+delay),a ;=0
1731   ret
1732 saverespawncounter:
1733   ld  (ix+delay),a
1734   jr  inputcall
1735 ;  ld  a,(ix+input)
1736 ;  or  a
1737 ;  jr  z,inlink
1738 ;  ret
1739
1740 chkkey: ;key=a
1741   dec a
1742   ld  b,a
1743   srl b
1744   srl b
1745   srl b ;b=a/8
1746   and 7 ;a=a\8
1747   ld  c,a ;push keybit
1748   ld  a,-1
1749   out (1),a
1750   inc b
1751   ld  a,%01111111 ;default
1752 bitmask:
1753   rlca ;rotate left
1754   dnz bitmask ;a/8 times
1755   out (1),a ;send bitmask
1756   in  a,(1) ;input keys
1757   ld  b,c ;pop keybit
1758   inc b
1759 keybit:
1760   rra
1761   dnz keybit ;check match (cf set)
1762   ret
1763
1764 inkeys: ;use jp not call!
1765   cal chkkey
1766   jr  nc,notright
1767   ld  a,l
1768   add a,8
1769   ld  l,a
1770 notright:
1771   ld  a,(ix+right)
1772   cal chkkey
1773   ret nc
1774   ld  a,l
1775   sub 8
1776   ld  l,a
1777   ret
1778 inputcall:
1779   ld  a,(ix+left)
1780   or  a
1781   jr  z,inlink ;input by link
1782   cal inkeys ;input by keys
1783   ld  a,(gameCar)
1784   and _datalink
1785   ret z ;no link
1786   ld  c,l ;send our keys
1787   psh hl
1788   cal Qsend ;Csend
1789   pop hl
1790   ret
1791 inlink:
1792   psh hl
1793   cal Qrecv ;Crecv
1794   pop hl
1795   ld  l,c
1796   ret
1797
1798 ;------- handle worm ---------
1799
1800 HandleWorm:
1801   ld  a,(gameCar)
1802   cpl
1803   and _datalivel
1804   add a,(ix+lives)
1805   or  a
1806   ret z ;dead
1807   ld  a,(ix+delay)
1808   dec a
1809   jp  nz,respawncheck
1810
1811   ld  a,(Gametype)
1812   cp  gametron
1813   jr  nz,notron
1814   ld  de,1
1815   cal IncScore
1816 notron:
1817
1818   ld  l,(ix+heading)
1819   cal inputcall
1820 donediddelydone:
1821   ld  (ix+heading),l
1822   ld  h,(ix+heading+1)
1823
1824   ld  c,(ix+pos)
1825   ld  b,(ix+pos+1)
1826   ld  e,(ix+pos2)
1827   ld  d,(ix+pos2+1)
1828
1829   psh hl
1830   ld  hl,previouspos
1831   ld  (hl),c
1832   inc hl
1833   ld  (hl),b
1834   inc hl
1835   inc hl
1836   ld  (hl),e
1837   inc hl
1838   ld  (hl),d
1839   pop hl
1840
1841 ;-------- move worm ----------
1842
1843 Wormmove:
1844   psh bc                        ; >> pos
1845   ld  a,(hl)
1846   add a,a
1847   add a,d
1848   ld  d,a
1849   bit 7,(hl)
1850   jr  z,notnegX
1851   dec b
1852 notnegX:
1853   jr  nc,notmoveX
1854   inc b
1855 notmoveX:
1856   ld  a,l
1857   add a,$40
1858   ld  l,a
1859   ld  a,(hl)
1860   add a,a
1861   add a,e
1862   ld  e,a
1863   bit 7,(hl)
1864   jr  z,notnegY
1865   dec c
1866 notnegY:
1867   jr  nc,notmoveY
1868   inc c
1869 notmoveY: ;bc=newpos
1870   ld  (ix+pos2),e
1871   ld  (ix+pos2+1),d
1872   ld  (ix+pos),c
1873   ld  (ix+pos+1),b
1874
1875 ;-check-
1876   pop hl                         ; << pos (old)
1877   ld  a,h
1878   sub b
1879   and 1
1880   ld  h,a
1881   ld  a,l
1882   sub c
1883   and 1
1884   add a,h
1885   ld  d,4
1886   jr  z,GotFour
1887   xor 3
1888   ld  d,a
1889 GotFour:
1890   cal chk4pixels
1891   rl  d
1892   jp  nc,Drawworm
1893
1894 ;--------- worm hit ----------
1895
1896 Hitworm:
1897   ld  a,(gameCar)
1898   ld  h,a
1899   and _datadie
1900   cal z,checkhitotherworm
1901   ld  a,h
1902   and _datamultpeas ;&&bit
1903   jr  nz,multiple_peas
1904   ld  a,h
1905   and _datafood
1906   jp  z,WormDead ;no food
1907
1908   ld  hl,0
1909 PeaY =$-2
1910 PeaX =$-1
1911   cal chkpeahit
1912   jp  nc,WormDead
1913   cal DrawPea ;remove pea
1914   ld  a,(ix+grow)
1915   add a,15
1916 peagrowth =$-1
1917   ld  (ix+grow),a
1918   cal NewPea
1919   ld  hl,Left
1920   dec (hl)
1921   psh af
1922   ld  de,10
1923   cal IncScore
1924   pop af
1925   jp  nz,Drawworm ;continue
1926   ld  a,(gameCar)
1927   and _datafoodl
1928   jp  z,Drawworm
1929   ld  a,(Gametype)
1930   or  a
1931   jp  nz,Exit ;stack restored
1932
1933   ld  hl,Level
1934   ld  a,(hl)
1935   inc (hl)
1936   ld  l,a ;hl=Level
1937   ld  h,0
1938   add hl,hl
1939   add hl,hl
1940   cal _HLTIMES10
1941   ex  de,hl
1942   cal IncScore ;score+(40*level)
1943   cal removeworm
1944   pop hl                         ; << call
1945   pop hl                         ; << call
1946   pop hl                         ; << levelp new
1947   ld  (ix+delay),2
1948   jp  StartLevel
1949
1950 chkpeahit: ;hl=peapos
1951   ld  a,(sprsize)
1952   inc a
1953   ld  d,a
1954   ld  a,b
1955   sub h
1956   inc a
1957   cp  d ;=(sprsize)+1
1958   ret nc ;nc=no pea
1959   ld  a,c
1960   sub l
1961   inc a
1962   cp  d
1963   ret ;c=pea
1964
1965 flagcaptured:
1966   psh hl
1967   ld  de,30
1968   cal IncScore
1969   pop hl
1970 sillylabel:
1971   cal WormDead
1972 DrawAllPeas:
1973   ld  hl,(peaspos)
1974   cal DrawPea
1975   ld  hl,(peaspos+2)
1976   jp  DrawPea
1977
1978 multiple_peas:
1979   ld  hl,(peaspos) ;1st pea
1980   psh hl
1981   ld  a,(ix+reserv)
1982   ld  e,a ;push a
1983   and %01
1984   jr  nz,sel_ownpea
1985   ld  hl,(peaspos+2) ;2nd pea
1986 sel_ownpea:
1987   cal chkpeahit
1988   pop hl ;(peapos) 1st pea
1989   jp  c,WormDead ;stopworm ;own pea hit
1990
1991   ld  a,e ;peek a (that's x86 asm for pop\push ;)
1992   and %01
1993   jr  z,sel_otherpea
1994   ld  hl,(peaspos+2) ;2nd pea
1995 sel_otherpea:
1996   cal chkpeahit
1997   jp  c,hitflag
1998
1999 ;no peas hit
2000   ld  a,e
2001   cal flagtoken
2002   jp  z,WormDead
2003   ld  b,a ;%10
2004   srl b   ;%01
2005   add a,b ;%11
2006   ld  (ix+reserv),a
2007   cal DrawPea ;restore own flag
2008   jr  sillylabel ;inv both\die
2009
2010 hitflag: ;correct pea hit
2011   ld  a,e ;pop a
2012   xor %01 ;0=1;1=0
2013   ld  (ix+reserv),a
2014   cal flagtoken
2015   psh af ;safe z-flag
2016   cal DrawPea ;remove
2017   pop af
2018   jr  z,flagcaptured
2019   jr  stopworm
2020
2021 flagtoken:
2022   and %01 ;current
2023   add a,a ;<< for cp
2024   ld  b,a ;in b
2025   ld  a,e
2026   and %10 ;own
2027   cp  b   ;same?
2028   ret ;Z=yes: no flag taken
2029
2030 ;-----------------------------
2031
2032 nextotherwormbit:
2033   ld  a,c
2034   sub (hl)
2035   inc hl
2036   inc a
2037   cp  4
2038   jr  nc,nothit1 ;no
2039   ld  a,b
2040   sub (hl)
2041   inc a
2042   cp  4
2043   ret c ;nz ;yes
2044 nothit1:
2045   inc hl
2046   cal resbit
2047 ChkWorm:
2048   cal _cphlde
2049   jr  nz,nextotherwormbit
2050   ret ;z
2051
2052 checkhitlapline:
2053   ld  a,63
2054   sub b
2055   jr  z,nextlaphalf
2056   inc a
2057   ret nz
2058 nextlaphalf:
2059   ld  a,c
2060   and 32 ;y>=32?
2061   jr  nz,nolap
2062   cp  (ix+reserv)
2063   jr  z,nolap
2064   psh bc
2065   ld  de,20
2066   cal IncScore
2067   pop bc
2068   xor a
2069 nolap:
2070   ld  (ix+reserv),a
2071   ret
2072
2073 checkhitotherworm:
2074  .db  $dd,$7d ;ld a,lx
2075   cp  worm2&255
2076  psh ix
2077  jr nz,chkworm2 ; ret nz
2078   ld  ix,worm1
2079  jr chkworm
2080 chkworm2:
2081  ld ix,worm2
2082
2083 chkworm:
2084  ld h,(ix+tail+1)
2085  ld l,(ix+tail)
2086  ld e,(ix+head)
2087  ld d,(ix+head+1)
2088   cal ChkWorm
2089  pop ix
2090   ret z ;not hit
2091   pop bc ;call
2092 stopworm:
2093   ld  bc,0
2094 previouspos =$-2
2095   ld  de,0
2096   ld  (ix+pos),c
2097   ld  (ix+pos+1),b
2098   ld  (ix+pos2),e
2099   ld  (ix+pos2+1),d
2100   ret
2101
2102 ;-------- draw worm ----------
2103
2104 Drawworm:
2105   ld  c,(ix+pos)
2106   ld  b,(ix+pos+1)
2107
2108   ld  a,(Gametype)
2109   ld  d,a
2110   cp  gamerace
2111   cal z,checkhitlapline
2112
2113   cal set4pixels
2114   dec c
2115   ld  a,d
2116   cp  gametron
2117   ret z ;keep tail in "Tron"
2118
2119   ld  l,(ix+head)
2120   ld  h,(ix+head+1)
2121   ld  (hl),c
2122   inc hl
2123   ld  (hl),b
2124   inc hl
2125   cal resbit
2126   ld  (ix+head),l
2127   ld  (ix+head+1),h
2128
2129   ld  a,(ix+grow)
2130   dec a
2131   jr  z,removetail
2132   ld  (ix+grow),a
2133   ret
2134
2135 removetail:
2136   ld  l,(ix+tail)
2137   ld  h,(ix+tail+1)
2138   ld  c,(hl)
2139   inc hl
2140   ld  b,(hl)
2141   inc hl
2142   cal resbit
2143   ld  (ix+tail),l
2144   ld  (ix+tail+1),h
2145
2146 res4pixels:
2147   cal ResPixel
2148   inc b
2149   cal ResPixel
2150   inc c
2151   cal ResPixel
2152   dec b
2153 ResPixel:
2154   cal FindPixel
2155   cpl
2156   and (hl)
2157   ld  (hl),a
2158   ret
2159
2160 ;-----------------------------
2161 ;---------- ball -------------
2162 ;-----------------------------
2163
2164 handlethoseneatlittleballs:
2165   ld  hl,balls
2166   ld  b,a ;a=(nrballs)
2167 handleballs
2168   psh bc
2169   psh hl
2170   ld  c,(hl)
2171   inc hl
2172   ld  b,(hl)
2173   inc hl
2174   ld  d,(hl)
2175   cal handleball
2176   dec c
2177   pop hl
2178   ld  (hl),c
2179   inc hl
2180   ld  (hl),b
2181   inc hl
2182   ld  (hl),d
2183   inc hl
2184   pop bc
2185   dnz handleballs
2186   ret
2187
2188 handleball:
2189   cal res4pixels
2190   dec c
2191
2192 ballxmove:
2193   bit 0,d ;1=L; 0=R
2194   jr  z,ballright
2195 ballleft:
2196   dec b
2197   cal checkballhit
2198   jr  z,ballymove
2199   inc b ;undo
2200   res 0,d ;go right
2201   jr  ballymove
2202 ballright:
2203   inc b
2204   cal checkballhit
2205   jr  z,ballymove
2206   dec b ;back
2207   set 0,d ;>left
2208
2209 ballymove:
2210   bit 1,d ;1=up; 0=down
2211   jr  z,balldown
2212 ballup:
2213   dec c
2214   cal checkballhit
2215   jr  z,balldone
2216   inc c
2217   res 1,d ;go down
2218   jr  balldone
2219 balldown:
2220   inc c
2221   cal checkballhit
2222   jr  z,balldone
2223   dec c
2224   set 1,d ;up
2225 balldone:
2226
2227 set4pixels: ;@(b,c)
2228   cal SetPixel
2229   inc b
2230   cal SetPixel
2231   inc c
2232   cal SetPixel
2233   dec b
2234 SetPixel: ;at bc
2235   cal FindPixel
2236   or  (hl)
2237   ld  (hl),a
2238   ret
2239
2240 letsmovetheotherway:
2241   ld  a,1
2242   xor (hl)
2243   ld  (hl),a
2244   ret
2245
2246 checkballhit:
2247   psh de
2248   ld  d,0
2249   cal chk4pixels
2250   xor a
2251   cp  d
2252   pop de
2253   ret
2254
2255 ;-----------------------------
2256 ;----------- procs -----------
2257 ;-----------------------------
2258
2259 releasekeys:
2260   halt
2261   ld  a,%10000000    ;all key-masks
2262   out (1),a
2263   in  a,(1)
2264   inc a              ;cp %11111111 (no keys pressed)
2265   jr  nz,releasekeys ;keep waitin
2266   cal GET_KEY        ;clear buffer
2267   ret
2268
2269 resbit:
2270   ld  a,h
2271   and (ix+storepos)
2272   ld  h,a
2273   ret
2274
2275 randompos:
2276   ld  b,a
2277 Random: ;(2..b+2)
2278   ld  a,r
2279 Seed =$+1
2280   add a,0
2281   ld  (Seed),a
2282   and %01111110
2283   cp  b
2284   jr  nc,Random
2285   add a,2
2286   ret
2287
2288 NewPea:
2289   ld  a,(FieldWidth)
2290   add a,127-4
2291   cal randompos
2292   ld  h,a
2293   ld  a,(FieldHeight)
2294   add a,56-4
2295   cal randompos
2296   ld  l,a
2297   ld  (PeaY),hl
2298
2299 CheckPea:
2300   ld  c,l
2301   ld  a,(sprsize)
2302   ld  e,a
2303 chkloopy:
2304   ld  b,h
2305   ld  a,(sprsize)
2306   ld  d,a
2307 chkloopx:
2308   psh hl
2309   cal FindPixel
2310   and (hl)
2311   pop hl
2312   jr  nz,NewPea ;pixel found
2313   inc b
2314   dec d
2315   jr  nz,chkloopx
2316   inc c
2317   dec e
2318   jr  nz,chkloopy
2319 ;all ok; empty space
2320
2321 DrawPea: ;hl=(PeaY)
2322   ld  b,h
2323   ld  c,l
2324   ld  de,0
2325 spritepos =$-2
2326   jp  PutSprite ;||-ed
2327
2328 ;----------- score -----------
2329
2330 _divHLby1000:
2331   psh hl
2332   ld  b,3
2333 divideagain: ;3x
2334   cal _divHLby10
2335   dnz divideagain
2336   ld  a,l ;a=hl/1000
2337   pop hl
2338   ret
2339
2340 IncScore:
2341   ld  h,(ix+score+1)
2342   ld  l,(ix+score)
2343   cal _divHLby1000
2344   ld  c,a
2345   add hl,de
2346   cal _divHLby1000
2347   cp  c
2348   jr  z,scorecommon ;hl/1000 not increased
2349   inc (ix+lives)
2350   jr  scorecommon
2351 DecScore: ;&&&
2352   ld  h,(ix+score+1)
2353   ld  l,(ix+score)
2354   or  a
2355   sbc hl,de
2356   jr  c,showstats ;<0=0
2357 scorecommon:
2358   ld  (ix+score+1),h
2359   ld  (ix+score),l
2360   ld  de,0
2361 scorelimit =$-2
2362   inc e
2363   jr  z,showstats ;de=$FF??=no limit
2364   dec e
2365   cal _cphlde
2366   jp  nc,Exit
2367
2368 showstats:
2369   ld  a,(Gametype)
2370   cp  gametron
2371   ret z
2372 showstatsEven4tron:
2373   psh ix
2374   ld  h,0
2375   ld  l,h
2376   ld  (_penCol),hl
2377   ld  a,(nrworms)
2378   ld  b,a
2379   ld  ix,worm1
2380   ld  a,(gameCar)
2381   and _datanextl
2382   jr  nz,showstatsS
2383 showstatloop:
2384   psh bc
2385   cal showstat
2386   ld  de,worm2-worm1
2387   add ix,de
2388   ld  hl,_penCol
2389   ld  a,(hl)
2390   add a,10
2391   ld  (hl),a
2392   pop bc
2393   dnz showstatloop
2394   pop ix
2395   ret
2396
2397 showstat:
2398   ld  a,(gameCar)
2399   and _datascore
2400   jr  z,showlives
2401 showscore:
2402   ld  h,(ix+score+1)
2403   ld  l,(ix+score)
2404   cal _D_HL_DECI
2405   jr __vputs
2406 showlives:
2407   ld  a,(Gametype)
2408   cp  gametron
2409   jr  z,showscore
2410
2411   ld  a,(ix+lives)
2412   add a,'0'
2413 __vputmap:
2414   psh ix
2415   cal _vputmap
2416   pop ix
2417   ret
2418
2419 showstatsS:
2420   ld  hl,txtLevel
2421   cal __vputs
2422   ld  a,0
2423 Level =$-1
2424   cp  10
2425   jr  c,tilllevel9
2426   ld  l,a
2427   ld  h,0
2428   cal _divHLby10
2429   psh af
2430   ld  a,l
2431   add a,'0'
2432   cal __vputmap
2433   pop af
2434 tilllevel9:
2435   add a,'0'
2436   cal __vputmap
2437
2438   ld  a,98
2439   ld  (_penCol),a
2440   cal showscore
2441   ld  a,123
2442   ld  (_penCol),a
2443   cal showlives
2444   ld  a,(gameCar)
2445   and _datafoodl
2446   pop ix
2447   ret z
2448 showleft:
2449   ld  a,31
2450   ld  (_penCol),a
2451   ld  a,0
2452 Left =$-1
2453   cal cshowA
2454
2455   ld  hl,txtLeft
2456 __vputs:
2457   psh ix
2458   cal _vputs
2459   pop ix
2460   ret
2461
2462 showLevel:
2463   ld  hl,txtLevel
2464   cal _puts
2465   ld  a,(Level)
2466 showA:
2467   ld  l,a
2468   ld  h,0
2469   cal _divHLby10
2470   psh af
2471   ld  a,l
2472   add a,'0'
2473   cal _putc
2474   pop af
2475   add a,'0'
2476   jp  _putc
2477
2478 cshowA:
2479   ld  l,a
2480   ld  h,0
2481   cal _divHLby10
2482   psh af
2483   ld  a,l
2484   add a,'0'
2485   cal __vputmap
2486   pop af
2487   add a,'0'
2488   jp  __vputmap
2489
2490 showHL:
2491   cal _D_HL_DECI
2492   jp  _puts
2493
2494 _D_HL_DECI:
2495   ld  de,savestr+4
2496   ld  b,5
2497 ldhld:
2498   cal _divHLby10
2499   add a,'0'
2500   ld  (de),a
2501   dec de
2502   dnz ldhld
2503   ld  hl,savestr
2504   ret
2505 savestr:
2506   .db "00000",0
2507
2508 ;-----------------------------
2509
2510 DisplayField:
2511   ld  a,c
2512   sub 29
2513   jr  nc,NotMinYScroll
2514   xor a
2515 NotMinYScroll:
2516   cp  43
2517 FieldHeight =$-1
2518   jr  c,NotMaxYScroll
2519   ld  a,(FieldHeight)
2520 NotMaxYScroll:
2521   ld  l,a
2522   ld  h,0
2523   add hl,hl
2524   add hl,hl
2525   add hl,hl
2526   add hl,hl
2527   add hl,hl
2528   psh bc                        ; >> 1
2529   psh de                        ; >> 2
2530   ld  de,ScrBuffer
2531   add hl,de
2532   ld  a,b
2533   sub 64
2534   jr  nc,NotMinXScroll
2535   xor a
2536 NotMinXScroll:
2537   cp  128
2538 FieldWidth = $-1
2539   jr  c,NotMaxXScroll
2540   ld  a,(FieldWidth)
2541 NotMaxXScroll:
2542   psh af                        ; >> 3
2543   and %11111000
2544   rra
2545   rra
2546   rra
2547   ld  c,a
2548   ld  b,0
2549   ld  de,DispBuffer
2550   pop af                         ; << 2
2551   and %00000111
2552   psh af                        ; >> 3
2553   cp  6
2554   jr  c,CopyScreen
2555   inc c
2556 CopyScreen:
2557   add hl,bc
2558   ld  b,57
2559 CopyScreenLoop:
2560   psh bc                        ; >> 4
2561   ld  bc,16
2562   ldir
2563   ld  c,16
2564   add hl,bc
2565   pop bc                         ; << 3
2566   dnz CopyScreenLoop
2567   pop af                         ; << 2
2568   ld  c,$b7 ;or a
2569 Bit0:
2570   jr  nz,Bit1
2571   halt
2572   halt
2573   jr  AfterShiftDelay
2574 Bit1:
2575   dec a
2576   jr  nz,Bit2
2577   cal ShiftRight1
2578   jr  AfterShiftDelay
2579 Bit2:
2580   dec a
2581   jr  nz,Bit3
2582   ld  a,2
2583   cal ShiftRight
2584   jr  AfterShiftDelay
2585 Bit3:
2586   dec a
2587   jr  nz,Bit4
2588   cal Chunk
2589   cal ShiftLeft1
2590   jr  AfterShift
2591 Bit4:
2592   dec a
2593   jr  nz,Bit5
2594   cal Chunk
2595   jr  AfterShiftDelay
2596 Bit5:
2597   dec a
2598   jr  nz,Bit6
2599   cal Chunk
2600   cal ShiftRight1
2601   jr  AfterShift
2602 Bit6:
2603   dec a
2604   jr  nz,Bit7
2605   ld  a,2
2606   cal ShiftLeft
2607   jr  AfterShift
2608 Bit7:
2609   cal ShiftLeft
2610 AfterShiftDelay:
2611   halt
2612 AfterShift:
2613 #ifdef buffer
2614   ld  hl,DispBuffer
2615   ld  de,$fc00+$70
2616   ld  bc,1024-$70
2617   ldir
2618 #endif
2619   pop de                         ; << 1
2620   pop bc                         ; << 0k
2621   ret
2622
2623 ShiftRight1:
2624   ld  a,1
2625 ShiftRight:
2626   ld  (ShiftRightCounter),a
2627   ld  a,c
2628   ld  (ShiftRightChunk),a
2629   ld  c,16
2630   add hl,bc
2631   ld  b,57
2632 ShiftRightLoop:
2633   psh bc
2634   ld  bc,-32
2635   add hl,bc
2636   ex  de,hl
2637   ld  a,(de)
2638 ShiftRightChunk:
2639   or  a
2640   cal c,_SHLACC
2641   ld  c,0
2642 ShiftRightCounter = $-1
2643 ShiftRowsLeft:
2644   psh hl
2645   rla
2646   ld  b,16
2647 ShiftRowLeft:
2648   dec hl
2649   rl  (hl)
2650   dnz ShiftRowLeft
2651   pop hl
2652   dec c
2653   jr  nz,ShiftRowsLeft
2654   ld  bc,-16
2655   add hl,bc
2656   ex  de,hl
2657   pop bc
2658   dnz ShiftRightLoop
2659   ret
2660
2661 ShiftLeft1:
2662   ld  a,1
2663 ShiftLeft:
2664   ld  (ShiftLeftCounter),a
2665   ld  a,c
2666   ld  (ShiftLeftChunk),a
2667   rla
2668   jr  nc,ShiftLeftSameByte
2669   dec hl
2670 ShiftLeftSameByte:
2671   ex  de,hl
2672   ld  bc,-16
2673   add hl,bc
2674 NewSprite:
2675   ex  de,hl
2676   ld  b,57
2677 ShiftLeftLoop:
2678   psh bc                        ; >> 1
2679   ld  bc,-32
2680   add hl,bc
2681   ex  de,hl
2682   ld  a,(de)
2683 ShiftLeftChunk:
2684   or  a
2685   cal c,_SHRACC
2686   ld  c,0
2687 ShiftLeftCounter = $-1
2688 ShiftRowsRight:
2689   psh hl                        ; >> 2
2690   rra
2691   ld  b,16
2692 ShiftRowRight:
2693   rr  (hl)
2694   inc hl
2695   dnz ShiftRowRight
2696   pop hl                         ; << 1
2697   dec c
2698   jr  nz,ShiftRowsRight
2699   ld  bc,-16
2700   add hl,bc
2701   ex  de,hl
2702   pop bc                         ; << 0k
2703   dnz ShiftLeftLoop
2704   ret
2705
2706 Chunk:
2707   psh hl                        ; >> 1
2708   psh de                        ; >> 2
2709   ld  c,16
2710   add hl,bc
2711   ld  b,57
2712 ChunkScreen:
2713   psh bc                        ; >> 3
2714   ld  bc,-32
2715   add hl,bc
2716   ex  de,hl
2717   ld  a,(de)
2718   cal _SHRACC
2719   ld  b,16
2720 ChunkRow:
2721   dec hl
2722   rld
2723   dnz ChunkRow
2724   ex  de,hl
2725   pop bc                         ; << 2
2726   dnz ChunkScreen
2727   pop de                         ; << 1
2728   pop hl                         ; << 0k
2729   ld  c,$37 ;scf
2730   ret
2731
2732 ;----------- draw ------------
2733
2734 ;--- pixel ---
2735
2736 chk4pixels: ;&&
2737   cal CheckPixel
2738   inc b
2739   cal CheckPixel
2740   inc c
2741   cal CheckPixel
2742   dec b
2743   cal CheckPixel
2744   dec c
2745   ret
2746 CheckPixel: ;at bc in d
2747   cal FindPixel
2748   and (hl)
2749   ret z
2750   dec d
2751   ret
2752
2753 ;CLEM's FIND_PIXEL (131+? cycles; 28+4 bytes)
2754 ;(b,c) to hl:a; "destroyes" ahl
2755
2756 FindPixel: ;(b,c) to hl:a
2757   ld  h,0
2758   ld  l,c    ;hl=y
2759   add hl,hl
2760   add hl,hl
2761   ld  a,b    ;a=x
2762   rra
2763   add hl,hl
2764   rra
2765   add hl,hl
2766   add hl,hl  ;hl=32*y
2767   rra        ;a=x/8
2768   or  l
2769   ld  l,a
2770   ld  a,b
2771   and 7
2772   cpl
2773   rlca
2774   rlca
2775   rlca
2776   ld  (FP_Bit),a
2777   xor a
2778 FP_Bit =$+1
2779   set 0,a
2780
2781   psh de ;&&&
2782   ld  de,ScrBuffer
2783   add hl,de
2784   pop de
2785   ret
2786
2787 ;--- sprite ---
2788
2789 PutSprite:  ;||@(b,c)
2790   ;by SHIAR  only ix saved
2791   cal FindPixel
2792 putspr:
2793   ld  (beginbit),a
2794   ld  a,0
2795 sprsize =$-1
2796   ld  b,a ;rows
2797 sprloopy:
2798   psh bc ;rows
2799   psh hl
2800   ld  a,(de)
2801   ld  c,a
2802   inc de
2803   ld  a,(sprsize)
2804   ld  b,a ;width
2805 beginbit =$+1
2806   ld  a,1
2807 sprloopx:
2808   sla c ;draw?
2809   jr  nc,sprnodraw
2810   psh af
2811   xor (hl)
2812   ld  (hl),a
2813   pop af
2814 sprnodraw:
2815   rrca ;next bit
2816   jp  nc,nextbitok
2817   inc hl ;next byte
2818 nextbitok:
2819   dnz sprloopx
2820
2821   pop hl
2822   ld  bc,32 ;next line
2823   add hl,bc
2824   pop bc
2825   dnz sprloopy
2826   ret
2827
2828 ;--- objects ---
2829
2830 drawstuff:
2831   ld  a,(hl)
2832   inc hl
2833   or  a ;0 =
2834   ret z ;no more
2835
2836   ld  d,(hl)
2837   inc hl
2838   ld  e,(hl)
2839   inc hl
2840   ld  b,(hl)
2841   inc hl
2842   psh hl
2843   ld  l,(hl)
2844   ld  h,b
2845
2846   dec a ;1 = line
2847   cal z,drawline
2848   dec a ;2 = fatline
2849   cal z,drawfatline
2850   dec a ;3 = box
2851   cal z,drawbox
2852   dec a ;4 = circle
2853   cal z,drawcircle
2854   dec a ;5 = hline
2855 #ifdef hlines
2856   cal z,drawhline
2857 #else
2858   cal z,drawline
2859 #endif
2860
2861   pop hl
2862   inc hl
2863   jr  drawstuff
2864
2865 drawbox: ;(d,e)-(h,l)
2866   ld  b,l ;Delta-y
2867 #ifdef hlines
2868 boxloop:
2869   cal drawhline
2870   inc e
2871   dnz boxloop
2872   ret
2873 drawhline: ;(d,e)-(h,e)
2874   psh bc
2875   ld  b,d
2876   ld  c,e
2877   psh hl
2878   cal FindPixel
2879   ld  c,a ;starting mask
2880   ld  a,h
2881   sub b
2882   ld  b,a
2883   inc b ;1+x2-x1
2884 hlineloop:
2885   ld  a,(hl)
2886   or  c
2887   ld  (hl),a
2888   rrc c ;mask >>
2889   jr  nc,hlinenext
2890   inc hl ;next byte
2891 hlinenext:
2892   dnz hlineloop
2893   pop hl
2894   pop bc
2895   ret
2896 #else
2897   ld  l,e
2898 boxloop:
2899   cal drawline
2900   inc l
2901   inc e
2902   dnz boxloop
2903   ret
2904 #endif
2905
2906 drawfatline:
2907   cal drawline
2908   inc d
2909   inc h
2910   cal drawline
2911   inc e
2912   inc l
2913   cal drawline
2914   dec d
2915   dec h
2916   jp  drawline
2917
2918 ;LINE (d,e)-(h,l)
2919 ;destroyes a
2920
2921 drawline: ;(d,e)-(h,l)
2922   psh bc  ;destr: a
2923   psh hl
2924   psh de
2925   ld  a,d
2926   cp  h
2927   jr  c,lineOrdered
2928   ex  de,hl
2929 lineOrdered:
2930   ld  b,d
2931   ld  c,e
2932   psh hl
2933   psh bc
2934   cal FindPixel
2935   pop bc
2936   pop de
2937 connectedLine:
2938   psh hl
2939   ld  h,c
2940   ld  c,a
2941   ld  a,d
2942   sub b
2943   ld  b,a
2944   ld  a,e
2945   jr  nz,LineNotPoint
2946   cp  h
2947   jr  nz,LineNotPoint
2948   pop hl
2949   jr  DoneLine
2950 LineNotPoint:
2951   sub h
2952   ld  de,32
2953   jr  nc,LinePositiveY
2954   neg
2955   ld  de,-32
2956 LinePositiveY:
2957   cp  b
2958   jr  nc,SteepLine
2959   add a,a
2960   ld  (line2sm+1),a
2961   ld  h,a
2962   xor a
2963   sub b
2964   add a,a
2965   ld  (line1sm+1),a
2966   ld  a,h
2967   sub b
2968   pop hl
2969 LineLoopGentle:
2970   psh af
2971   ld  a,(hl)
2972   or  c
2973   ld  (hl),a
2974   rrc c
2975   jr  nc,$+3
2976   inc hl
2977   pop af
2978   jp  m,line2sm
2979 line1sm:
2980   add a,0
2981   add hl,de
2982 line2sm:
2983   add a,0
2984   dnz LineLoopGentle
2985 DoneLine:
2986   ld  a,(hl)
2987   or  c
2988   ld  (hl),a
2989   pop de
2990   pop hl
2991   pop bc
2992   ret
2993 SteepLine:
2994   ld  h,a
2995   neg
2996   add a,a
2997   ld  (line3sm+1),a
2998   ld  a,b
2999   add a,a
3000   ld  (line4sm+1),a
3001   sub h
3002   ld  b,h
3003   pop hl
3004 LineLoopSteep:
3005   psh af
3006   ld  a,(hl)
3007   or  c
3008   ld  (hl),a
3009   add hl,de
3010   pop af
3011   jp  m,line4sm
3012 line3sm:
3013   add a,0
3014   rrc c
3015   jr  nc,$+3
3016   inc hl
3017 line4sm:
3018   add a,0
3019   dnz LineLoopSteep
3020   jr  DoneLine
3021
3022 drawcircle: ;(d,e),h    ;de=x,y; h=z
3023   ld  c,h               ;c=yy=z
3024   ld  a,h
3025   neg
3026   ld  l,a               ;l=-z
3027   xor a
3028   ld  b,a               ;b=xx=0
3029   dec a                 ;-$00**
3030   ld  h,a               ;hl=zz=-z
3031 circloop:
3032   psh de                ;x,y
3033   ex  (sp),hl           ;push zz \ pop x,y
3034   cal circledraw        ;(x-xx,y+yy)-(x+xx,y+yy)
3035                         ;(x-xx,y-yy)-(x+xx,y-yy)
3036   cal circledraw        ;(x-yy,y+xx)-(x+yy,y+xx)
3037                         ;(x-yy,y-xx)-(x+yy,y-xx)
3038
3039   ex  (sp),hl           ;push x,y \ pop zz
3040   xor a
3041   ld  d,a               ;d=0
3042   dec a                 ;-256<h<0 = $FF**
3043   cp  h                 ;h<0?
3044   jr  z,circlenext      ;jump if zz<0
3045
3046   ld  a,c               ;yy
3047   dec a                 ;89<a<128
3048   add a,a               ;a=2yy-2 ;nc
3049   ld  e,a               ;de=a
3050   sbc hl,de             ;zz=zz-2yy+2
3051   dec c                 ;yy--
3052 circlenext:
3053   ld  a,b               ;xx
3054   inc a                 ;0<a<92
3055   add a,a               ;2xx+2
3056   inc a
3057   ld  e,a               ;de=a
3058   add hl,de             ;zz=zz+2xx+3
3059
3060   pop de                ;x,y
3061   ld  a,b
3062   cp  c
3063   ret nc                ;xx>=yy
3064   inc b                 ;xx++
3065   jr  circloop
3066
3067 circledraw:             ;destr:de
3068   psh hl
3069   ld  a,h               ;hl=x,y
3070   sub b                 ;bc=xx,yy
3071   ld  d,a               ;d=x-xx
3072   add hl,bc             ;h=x+xx; l=y+yy
3073   ld  e,l               ;e=y+yy
3074   cal drawline          ;(h-b,l+c)-(h+b,l+c)
3075   ld  a,l
3076   sub c                 ;a=y again
3077   sub c
3078   ld  l,a               ;l=y-yy
3079   ld  e,l               ;e=l=y-yy
3080   cal drawline          ;(h-b,l-c)-(h+b,l-c)
3081   ld  a,b               ;swap xx and yy
3082   ld  b,c
3083   ld  c,a               ;ex b,c
3084   pop hl
3085   ret
3086
3087
3088
3089
3090
3091 ;**** link routines ****
3092 ;these are identical in concept to the routines used in ZTetris, ZPong, and probably
3093 ;every other link game out there.  However, these are commented :)
3094 losses: .dw 0
3095 Csend:
3096   ld  b,32
3097 csendwait:
3098   nop
3099   dnz csendwait
3100   cal Qsend
3101   jr  c,Csend
3102   ret
3103 Qsend:
3104 send:
3105 ;inputs: c=byte to send, both wires must be high by default
3106 ;outputs: b=8-number of bits sent, both wires high, goes to game over on certain conditions
3107 ;destroys: af,bc,de
3108         in a,(7)
3109         and %11
3110         jr z,killlink           ;if both lines low, get out of here (game over signal)
3111         ld b,8                          ;sending 8 bits
3112 sendloop:
3113         ld de,$8000                     ;error timer
3114         rl c                            ;force high bit into carry
3115         ld a,%11010100          ;lower the red wire by default (sending 0) ($d4)
3116         jr nc,selected          ;if high bit was 0, use above value
3117         ld a,%11101000          ;if 1, lower the white wire instead ($e8)
3118 selected:
3119         out (7),a                       ;put it out the link port
3120 waitconfirm:
3121         call linktimer
3122         in a,(7)                        ;see what the wires are doing
3123         and %00000011           ;check lower 2 bits
3124         jr nz,waitconfirm       ;if both bits 0, data was received ok (both wires low)
3125         ld a,%11000000
3126         out (7),a                       ;give the ok to raise both wires (one will be done automatically) ($c0)
3127 waitconfirm2:
3128         call linktimer
3129         in a,(7)
3130         and %00000011
3131         cp 3
3132         jr nz,waitconfirm2      ;wait for other calc to raise the other wire
3133         djnz sendloop           ;continue sending
3134         xor a                           ;reset c; ld a,0
3135         ld (losses),a           ;reset number of losses
3136         ret
3137
3138
3139 Crecv:
3140   cal receive
3141   jr  c,Crecv
3142   ret
3143 Qrecv:
3144 receive:
3145 ;inputs: both wires must be high by default
3146 ;outputs: c=byte received, b=8-number of bits received, both wires high
3147 ;       goes to game over on certain conditions
3148 ;destroys: af,bc,de
3149         in a,(7)
3150         and %00000011
3151         jr z,killlink           ;game over signal applies to receiving too
3152         ld b,8                          ;receiving 8 bits
3153 receiveloop:
3154         ld de,$8000                     ;error timer
3155 waitreceive:
3156         call linktimer
3157         in a,(7)
3158         and %11
3159         cp 3                            ;if bits 0 and 1 set, both wires are high
3160         jr z,waitreceive        ;wait for one of the wires to go low
3161         rra                                     ;check red wire status
3162         rl c                            ;if set, red is high (thus white is low), so put the correct bit into c
3163         rra                                     ;now check white wire (since the flags are destroyed)
3164         ld a,%11010100          ;$d4
3165         jr nc,selected2         ;if white is low, lower red and vice versa              
3166         ld a,%11101000          ;$e8
3167 selected2:
3168         out (7),a                       ;so now both wires are low
3169 waitreceive2:
3170         call linktimer
3171         in a,(7)
3172         and %11
3173         jr z,waitreceive2       ;wait for the wire we didn't lower to go high again (the other will remain low)
3174         ld a,%11000000          ;$c0
3175         out (7),a                       ;raise both wires since the other calc will have given the ok sign
3176         djnz receiveloop        ;if not done, wait for next bit
3177         xor a                           ;reset c
3178         ld (losses),a           ;reset number of losses
3179         ret
3180
3181 linktimer:                              ;leave if we have to wait too long (and return an error)
3182         dec de
3183         ld a,d
3184         or e                            ;see if de is 0
3185         ret nz                          ;if not, keep going as usual
3186                                                 ;otherwise we have to deal with a link failure
3187         ld a,%11000000          ;$c0
3188         out (7),a                       ;reset link status (both high)
3189         ld a,(losses)           ;see how many consecutive losses we have
3190         inc a
3191         ld (losses),a           ;add this loss to it
3192         pop de                          ;fix the stack to leave the link routine (de is ok to destroy)
3193         cp 20                           ;see if this is the 20th consecutive failure
3194         ret c                           ;if not, keep playing
3195                                                 ;otherwise, all is probably lost...
3196
3197 killlink2:
3198         jr linkend
3199 killlink:
3200 linkend:
3201   jp  z,Exit
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211 #ifdef 0
3212 ;-----------------------------
3213 ;----------- link ------------
3214 ;-----------------------------
3215
3216 timeout = $800
3217
3218 checklink:
3219   dec de
3220   ld  a,d
3221   or  e
3222   jr  z,linkerror
3223
3224   ld  a,$BF
3225   out (1),a
3226   in  a,(1)
3227   bit 6,a
3228   jp  z,Exit
3229
3230   in  a,(7)
3231   and %11
3232   ret
3233
3234 linkerror:
3235   scf
3236   ld  a,%11
3237   pop hl
3238   ret
3239
3240 ;--------------
3241 ;---- SEND ----
3242 ;--------------
3243
3244 Csend:          ;--- send 8 bits in A --- destr:abcdehl ---
3245   ld  c,a
3246 Csendloop:
3247   cal Qsend
3248   ret nc                ;NC = all ok
3249   ld  a,D0HD1H
3250   out (7),a             ;both high
3251   jr  Csendloop         ;CF = error
3252
3253 Qsend:          ;--- try to send 8 bits in C; CF=error --- destr:abcdehl ---
3254   ld  de,timeout
3255   cal checklink
3256   cp  %11               ;are they?
3257   scf
3258   ret nz                ;nope, wait
3259   ld  b,8               ;bits to send
3260 sendloop:
3261   ld  de,timeout
3262   rl  c                 ;bit to send in cf
3263   ld  a,D0LD1H          ;0: lower white
3264   jr  nc,sendbit
3265   ld  a,D0HD1L          ;1: lower red
3266 sendbit:
3267   out (7),a             ;lower one (send bit)
3268 sendwaitack:
3269   cal checklink         ;other calc must lower other wire
3270   jr  nz,sendwaitack
3271   ld  a,D0HD1H          ;raise one, ok to raise other
3272   out (7),a
3273 sendfinish:
3274   cal checklink
3275   cp  %11               ;both raised (by other calc)
3276   jr  nz,sendfinish
3277   nop \ nop
3278   dnz sendloop          ;repeat for all bits
3279   xor a                 ;nc...
3280   ret                   ;=ok
3281
3282 ;--------------
3283 ;---- RECV ----
3284 ;--------------
3285
3286 Crecv:          ;--- receive 8 bits into A/C --- destr:abcdehl ---
3287   cal Qrecv
3288   ret nc                ;return if all went ok
3289   ld  a,D0HD1H
3290   out (7),a             ;raise both on error
3291   jr  Crecv             ;and try again
3292
3293 Qrecv:          ;--- receive 8 bits into A/C; CF=error --- destr:abcdehl ---
3294   ld  de,timeout
3295   cal checklink
3296   jp  z,Exit            ;both low = error, quit
3297   cp  %11
3298   scf
3299   ret z                 ;both high = nothing yet, wait
3300   ld  b,8               ;bits to receive
3301 recvloop:
3302   ld  de,timeout
3303 recvwait:
3304   cal checklink
3305   cp  %11
3306   jr  z,recvwait        ;both high = nothing sent (yet)
3307   rra                   ;received bit in cf
3308   ld  a,D0LD1H
3309   jr  c,received        ;lower white wire as well
3310   ld  a,D0HD1L          ;lower red
3311 received:
3312   rl  c                 ;save bit in c
3313   out (7),a             ;both wires low
3314 recvwaitack:
3315   cal checklink
3316   jr  z,recvwaitack     ;same wire will be raised again by other calc
3317   ld  a,D0HD1H
3318   out (7),a             ;raise both
3319 recvfinish:
3320   dnz recvloop          ;repeat for all bits
3321   xor a                 ;nc=no error
3322   ld  a,c               ;result in a
3323   ret
3324 #endif
3325
3326 ;-----------------------------
3327 ;---------- levels -----------
3328 ;-----------------------------
3329
3330 LevelDef:
3331   .db 5,4,15,15,0,0     ;peas,speed,growth,begin_size,sprite,balls
3332   .db 0,2,63            ;start d, y, x
3333   .db 128,57            ;field width (128-255), height (57-255)
3334   .db 0                 ;no additional lines, boxes
3335   .db 255
3336    ret
3337
3338 LevelDefM:
3339   .db 8,4,15,15,0,0
3340   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
3341   .db 128,57
3342   .db 0
3343
3344   .db 8,0,18,12,5
3345   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
3346   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
3347   .db 128,57
3348   .db 0
3349
3350   .db 8,5,18,12,0,0
3351   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
3352   .db 128,57
3353  .db 4,40,26,20,0
3354  .db 4,90,40,11,0,0
3355
3356 LevelDefT: ;tron=no delay
3357   .db 8,4,18,12,5
3358   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
3359   .db $40,30,64,$C0,30,64, $00,30,64,$80,30,64
3360   .db 128,57
3361   .db 0
3362
3363 LevelDefC: ;ctf
3364   .db 8,4,18,12,5
3365   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
3366   .db $40,30,64,$C0,30,64, $00,30,64,$80,30,64
3367   .db 128,57
3368   .db 10,10,50,50
3369   .db 0
3370
3371 ;-----------------------------
3372 ;---------- data -------------
3373 ;-----------------------------
3374
3375 wdPicture = 16
3376 wtPicture:
3377 .db %00000000,%00000000,%00000111,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01110000,%00000000,%00000000,%00000000,%00000000,%00000000
3378 .db %00000000,%00000000,%00001111,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01111000,%00000000,%00000000,%00000110,%01111011,%00100000
3379 .db %00000000,%00000000,%00011100,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00011100,%00001110,%00000000,%00001001,%00010011,%01000000
3380 .db %00000000,%00000000,%00011000,%00011111,%00000000,%01111111,%11000000,%00111100,%00011110,%01111000,%00001100,%00011111,%00000000,%10100111,%00110000,%10000000
3381 .db %00000000,%00000000,%00111000,%00111111,%10000000,%11111111,%11100000,%11111110,%00111111,%11111100,%00001100,%00111011,%00000000,%10100001,%00001001,%01100000
3382 .db %00000000,%00000000,%00110000,%01110001,%11000001,%11000000,%01110001,%11100110,%01110011,%11001110,%00001100,%00110001,%10000000,%01001110,%01110010,%01100000
3383 .db %00000000,%00000000,%00110000,%01100000,%11000001,%10000000,%00111001,%10000000,%01100111,%11100110,%00001110,%01110001,%10000000,%00000000,%00000000,%00000000
3384 .db %00000000,%00000000,%00110000,%01100000,%11000001,%10110000,%00011011,%10000000,%11101110,%01110111,%00001110,%01110001,%10000000,%00000000,%00000000,%00000000
3385 .db %00000000,%00000000,%00110000,%01110001,%11000001,%10110000,%00011011,%00000000,%11001100,%00110011,%00000111,%11100001,%10000000,%00000000,%00000000,%00000000
3386 .db %00000000,%00000000,%00110000,%00110001,%10000001,%10110000,%00011011,%00000000,%11001100,%00110011,%00000011,%11000011,%10000000,%00000000,%00000000,%00000000
3387 .db %00000000,%00000000,%00111000,%00111011,%10000011,%10110000,%00011011,%00000000,%11001110,%01110011,%00000000,%00000011,%00110101,%01001001,%10000000,%00000000
3388 .db %00000000,%00000000,%00011000,%00011111,%00000011,%00110000,%00011011,%00000000,%11000111,%11100011,%10000000,%00000011,%01000101,%00010101,%01000011,%01100011
3389 .db %00000000,%00000000,%00011100,%00001110,%00000111,%00111000,%00111011,%10000000,%11000011,%11000001,%10000000,%00000111,%01100101,%01010101,%01000101,%01010100
3390 .db %00000000,%00000000,%00001110,%00111111,%10001110,%00011100,%01110001,%10000000,%11100000,%00000001,%11100000,%00001110,%00110111,%01011101,%10010101,%01100101
3391 .db %00000000,%00000000,%00000111,%11111011,%11111100,%00001111,%11100001,%11000000,%01100000,%00000000,%11111111,%11111100,%00010101,%01010101,%01000101,%01010101
3392 .db %00000000,%00000000,%00000011,%11100000,%11111000,%00000111,%11000000,%11000000,%01100000,%00000000,%00111111,%11111000,%01100101,%01010101,%01000110,%01010011
3393
3394 txtMenu:  .db "Mode",0  ;1st menu item
3395           .db "Level",0 ;2nd
3396           .db "Limit",0 ;...
3397           .db "Worms",0
3398           .db "worm #",0
3399           .db "controls",0
3400 posMenu:  .dw $$2418,$231E,$2524,$1F2A,$1730,$1936
3401 txtGame:  .db "Singleplayer",0
3402 txtGame1: .db "Peaworm",0
3403 txtGame2: .db "Tron",0
3404 txtGame3: .db "Deathmatch",0
3405 txtGame4: .db "Foodmatch",0
3406 txtGame5: .db "LinkMatch",0
3407 txtGame6: .db "Race",0
3408 txtGame7: .db "CTF",0
3409 ;            .db "Domination",0    ;8
3410 posGame:  .db 0,txtGame1-txtGame
3411           .db txtGame2-txtGame
3412           .db txtGame3-txtGame
3413           .db txtGame4-txtGame
3414           .db txtGame5-txtGame
3415           .db txtGame6-txtGame
3416           .db txtGame7-txtGame
3417
3418 txtKeyleft: .db "Left",0
3419 txtKeyright:.db " | Right",0
3420 txtLevsel:  .db $CF," Select levels: ",5,0
3421 txtEName:   .db "Enter name player ",0
3422 txtWaiting: .db "Waiting...",0
3423 txtReceive: .db "Receiving..." ;,0
3424
3425 TrigPrecalc:
3426 .db   0,  3,  6,  9, 12, 15, 18, 21
3427 .db  24, 27, 30, 33, 36, 39, 42, 45
3428 .db  48, 51, 54, 57, 59, 62, 65, 67
3429 .db  70, 73, 75, 78, 80, 82, 85, 87
3430 .db  89, 91, 94, 96, 98,100,102,103
3431 .db 105,107,108,110,112,113,114,116
3432 .db 117,118,119,120,121,122,123,123
3433 .db 124,125,125,126,126,126,126,126
3434 .db 127
3435
3436 txtLevel:  .db "Level ",0
3437 txtWorms:  .db "Worms: 0",0     ;follows txtLevel
3438 txtName:   .db "Name",0
3439 txtDied:   .db "Died    "       ;follows txtName
3440 txtScore:  .db "Score",0        ;follows txtDied
3441 txtLeft:   .db " left",0        ;follows txtScore
3442 txthiscore:.db "HiScore:",0
3443 txtReady:  .db "Prepare!",0
3444 txtposReady = 7
3445 txtGO:     .db 5,5,5,5,5," GAME OVER ",$CF,$CF,$CF,$CF,$CF,0
3446
3447 _datalink  = %00000001 ;linkplay
3448 _datalivel = %00000010 ;lives=0 limit
3449 _datafoodl = %00000100 ;left=0 limit
3450 _datanextl = %00001000 ;next level if left=0
3451 _datasingl = %00001000 ;singleplayer=1
3452                        ;1=hiscore+keep_length
3453 _datafood  = %00010000 ;food present
3454 _datadie   = %01000000 ;worm dies on impact
3455 _datascore = %10000000 ;score>=100 limit
3456 _datamultpeas = %00100000
3457 _datasp    = %01011110
3458
3459 datalevels: .dw LevelDef, LevelDefM
3460             .dw LevelDefT,LevelDefM
3461             .dw LevelDefM,LevelDefM
3462             .dw LevelDefM,LevelDefC
3463 nrlevels:   .db 1,3,1,3,3,3,3,1     ;=defaults
3464
3465 savestart:
3466
3467 gamesingle   =  0
3468 datasingle: .db %01011110,3,1,1 ;3 lives (<must b unique)
3469 gamepeas     =  1
3470 datapeas:   .db %01011010,1,1,1 ;1 "
3471 gametron     =  2
3472 datatron:   .db %01000010,1,1,1
3473 gamedeathm   =  3
3474 datadeathm: .db %01000010,3,2,1
3475 gamefoodm    =  4
3476 datafoodm:  .db %11010000,10,2,1 ;10 score limit (=100)
3477 gamelinkm    =  5
3478 datalinkm:  .db %01000011,3,2,1
3479 gamerace     =  6
3480 datarace:   .db %10000000,10,2,1
3481 gamectf      =  7
3482 datactf:    .db %11100000,9,4,1
3483 ;gamedomin    =  8
3484 ;datadomin:  .db %01100000,3 ;==(8 modes)
3485
3486 worm1set:  .dw worm1p,worm1p
3487            .db %11110111,%00,-01,K_RIGHT,K_LEFT
3488 worm1name: .db "Wormy   ",0
3489 worm2set:  .dw worm2p,worm2p
3490            .db %11111011,%11,-01,K_F2,K_F1
3491 worm2name: .db "Viper   ",0
3492 worm3set:  .dw worm3p,worm3p
3493            .db %11111011,%00,-01,K_COMMA,K_STO
3494 worm3name: .db "Nibbler ",0
3495 worm4set:  .dw worm4p,worm4p
3496            .db %11111011,%00,-01,K_PLUS,K_ENTER
3497 worm4name: .db "Jim     ",0
3498
3499 defhiscrpos:
3500   .dw 0,0,0,0,0,0
3501
3502 saveend:
3503
3504                ;set:
3505 heading  = 0   ;level*
3506 pos      = 2   ;level*
3507 pos2     = 4   ;level
3508 grow     = 6   ;level
3509 died     = 8   ;game
3510 score    = 9   ;game
3511 delay    = 11  ;game
3512                ;19B @game
3513 lives    = 12
3514 head     = 13  ;4B (head=tail)
3515 tail     = 15  ;also@next level
3516 storepos = 17
3517 reserv   = 18  ;loop (race:lap|ctf:pea)
3518 input    = 19
3519 left     = 20
3520 right    = 21
3521 name     = 22
3522 wormsize = 31
3523
3524 startdelay    = 30
3525 respawndelay  = 30
3526 maxnamelength = 8+1
3527
3528 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3529 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3530 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3531 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3532 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3533 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3534 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3535 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3536 .db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
3537 .db "   shiar0@hotmail.com",0
3538
3539 defspritesz = 4
3540 defspriteimg:   .db %01100000
3541                 .db %11110000
3542                 .db %11110000
3543                 .db %01100000
3544
3545 deflevels:
3546   .db "Internal Levels" ;,0
3547
3548   .db 0,deflevels/256,deflevels&255
3549 templevels:
3550
3551 ;-----------------------------
3552 ;----------- end -------------
3553 ;-----------------------------
3554
3555   .end
3556
3557 .end