wormy 0.97.103
[wormy.git] / wormy.z80
index 22fc9186eee1171cdf216892eebe266110189862..26d374f60d594d24140cb4a24a9707a40bc56e4b 100644 (file)
--- a/wormy.z80
+++ b/wormy.z80
@@ -1,39 +1,52 @@
-; Title                      : Wormy
-; Version                    : 96% (0.96.C14)
-; Release Date               : UUHHhhh... soon?!?
-; Filename                   : wormy.86p (5kb)
-; Author(s)                  : Shiar
-; Email Address              : wormy@shiar.org
-; Web Page                   : www.shiar.org
-; Description                : ruling Nibbles-like game 1-4 players
-; Where to get this game     : www.shiar.org (home of Wormy)
-; Other games by author(s)   : Nemesis beta
-; Additional Credits to      : Matthew Shepcar (wrote original Peaworm, end'98)
-;                              Jonah Cohen (helped writing worm)
+;   ����                                                        ����
+;  ����                                                         �����
+; ���                                                            ����     ����
+;���      �����          ��������       �����     ����  ����      ���     �����
+;���     �������       �����������     �������   �������������     ��    ��� ���
+;��     ���   ���     �����    ����   ����  ��� ���  ����  ���     ���  ���� ���
+;��     ��     ��     ��  �      ��� ����      ���  ������  ���    ���  ���   ��
+;��     ��     ��     �� ��      ��� ���       ��� ���� ��� ���    ��� ����   ��
+;��     ���   ���     �� ��       �� ���       �������   ��� ��     �������   ��
+;��     ���   ���    ��� ��       �� ��        �� ���    ��� ���     �����   ���
+;���     ��� ���     ��� ��       �� ���       �� ����  ���� ���             ���
+;���      �����     ���  ���     ��� ���       ��  ��������  ���            ���
+; ���      ���      ���  ���     ��� ���       ���  ������   ���            ���
+;  ����  �������  ����    ���   ���  ����      ���            �����       ����
+;   �������� ��������     ���������   ���      ���             ���������������
+;    �����     �����       �������     ��       ���              �����������
+;
+; Version                  : 97% (0.97.13)
+; Release Date             : UUHHhhh... soon?!?
+; Author(s)                : Shiar
+; Email Address            : wormy@shiar.org
+; Web Page                 : www.shiar.org
+; Description              : ruling Nibbles-like game 1-4 players
+; Where to get this game   : www.shiar.org (home of Wormy)
+; Other games by author(s) : Nemesis beta
+; Additional Credits to    : Matthew Shepcar (wrote original Peaworm, end'98)
+;                            Jonah Cohen (helped writing worm)
+; Files                    : wormy.z80 (80898 bytes) 1234
 
 ;-----------------------------
 ;----------- TO-DO -----------
 ;-----------------------------
 
-; 96% = DONE
+; 97% = DONE
 
-;    [* internal levels         ]
-;    [  * check levels/gametype ]
-;    [  * enough hiscore saves! ]
-;    [* complete readme         ]
-;  1% * misc (pollish, bugs, &&&)
-;  1% * long length save (level#6)
-;     * mem at worm #4
+;  1% * misc (bugs, &&&, pollish, &&, &)
+;     * score >9 dispay
+;     * mem at worm #4 (still 12 bytes or so.. or more? or less?)
+;     * look at init-z in line routine again
 ;   * LINK
-;  1% * transmit game/level data
-;      Xfirst packet loss?? or vti onlyXXXXX
-;      X1/3 worms over linkXXXX
-;      Xsend new peas' positionsXXXXX
+;  1% * fix transmit game/level data (?)
+;     * >Somehow do a lot of testing with 2 calcs< *sigh*
 
 ;100% = bugs fixed + levels done
 
-; MAYBE: sound
-; NO:   coop
+;      arrow to offscreen peas
+;      multiple peas in sp level
+;>110%:        sound, startpos (?)
+;>120%:        coop (DON'T COUNT ON IT)
 
 ;-----------------------------
 ;-----------------------------
 ;-----------------------------
 ;-----------------------------
 
+;NOTES:
+;* Use for LEARNING practises ONLY!
+;   Don't ever release altered code w/o permission!
+;* Code was originally by Scabby (Matthew Shepcar),
+;   a few lines by Jonah Cohen,
+;    and everything else by me - Shiar (Mischa Poslawsky).
+;* Although I've commented quite some stuff, I can't guarantee
+;   everybody will understand it. This is probably not the best source
+;    to learn z80 from. w00t the Shyer Way (tm).
+;* Don't scroll down if you get scared easily.
+
 #define buffer      ;use display buffer (otherwise write directly to screen)
 #define readymask   ;"greys" out the field before starting a level
 #define coolzgfx    ;nice graphics for game over screen
+multpeas
 
+;#define intlevels  ;internal levels
 ;#define readytext  ;displays "prepare" before level starts
 ;#define invincible ;worms cannot die =)
 ;#define optdie     ;in race games worms don't die when they run into each other
@@ -55,7 +81,6 @@
 
 #include "asm86.h"
 #include "ti86asm.inc"
-
 _SHRACC            = $4383 ;4x srl a
 _SHLACC            = $438B ;4x sll a
 _divHLby10         = $4044 ;hl=hl/10
@@ -102,20 +127,20 @@ worm3       = $AC3E ;-AC59 (1F)
 worm4       = $AC5D ;-AC77 (1F)
 balls       = $AC7C ;-ACFF (3x43d)
 SinCosTable = $AD00 ;-AE00 (4*40)
-        ;free $AE01 ;-AFFF (1FF)
+turn10      = $AE01 ;-AE01 (1) (counter)
+peaspos     = $AE02 ;-AE05 (4+) (peas)
+;free       = $AE06 ;-AFFF (1FA)
 worm1p      = $B000 ;-B7FF (800)      %1011O000
 worm3p      = $B800 ;-BBFF (400)      %10111O00
-        ;free $BF91 ;-BFFF (6F)
-     ;program $D748 ;-EFFF (186D+4A)
+;free       = $BF91 ;-BFFF (6F)
+;program    = $D748 ;-EFFF (186D+4A)           ;6327
 worm4p      = $F000 ;-F3FF (400)      %11110O00
 leveldata   = $F400 ;-FA70 (<=671)
+       ;can you believe i actually left $269 bytes of memory unused?!?
 
-turn10      = $AE01 ;      (1) (counter)
-peaspos     = $AE02 ;-AE05 (4) (peas)
-
-;MEM|8---9---A---B---C---D---E---F---|
-;   |..[------]||[]|......[-----]|[].|
-;   |   SCREEN 2* 13      PRGM   4LV |
+;MEM|8---9---A---B---C---D---E---F---| ;there's something wrong
+;   |..[------]||[]|......[-----]|[].| ;if you still understand
+;   |   SCREEN 2* 13      PRGM   4LV | ;after looking at this
 
 ;--- temporary
 
@@ -126,36 +151,44 @@ DispBuffer  = $BC00 ;(10x57d)    @game
 #else
 DispBuffer  = $FC70
 #endif
+lefttotalb  = $AFFF
 
 ;-----------------------------
 ;------- program start -------
 ;-----------------------------
 
-.org _asm_exec_ram
+ .org %1101011101001000
 
-wormVhost   = 095
-wormVclient = 195
-
-start:
-  nop
+start:         ;turn back NOW!
+  nop      ;and so it begins...
   jp  Start
-  .db 1
-  nop
-  .dw WormTxt
-  .dw WormIcon
-
-WormTxt:
-  .db "WORMY by SHIAR -- 96% C14",0
+  ld  bc,$5242
+  rst 10h
+ .dw  WormIcon
+  ld  d,a
+  ld  c,a
+  ld  d,d
+  ld  c,l
+  ld  e,c
+  jr  nz,$+100
+  ld  a,c
+  jr  nz,$+$55
+  ld  c,b
+ .dw  16713
+ .db  %1010010
+  jr  nz,$+47
+  dec l
+ .db  " 97% .13",0
 WormIcon:
 .db 8,2
 .db %00000000,%00111100
 .db %00000000,%01010010
 .db %00000000,%01100001
 .db %01100011,%10011001
 .db %10010100,%01101001
 .db %10011001,%00011001
 .db %01000010,%11000001
 .db %00111100,%00111110
.db  8,2
.db  %00000000,%00111100
.db  %00000000,%01010010
.db  %00000000,%01100001
.db  %01100011,%10011001
.db  %10010100,%01101001
.db  %10011001,%00011001
.db  %01000010,%11000001
.db  %00111100,%00111110
 
 levelhead  = 'w'
 levelhead2 = 95 ;wormy levels header = "95"
@@ -193,7 +226,7 @@ Start:
   ldir
   inc a   ;ld a,$D4
   ld  i,a
-  im  2
+  im  2 ;...it *does* work ;)
 
   cal _RAM_PAGE_7
   ld  hl,$BFFF ;VAT start
@@ -248,7 +281,7 @@ stringfound:
   inc ix
 _searchnext:
   cal _RAM_PAGE_7
-  jr searchnext
+  jr  searchnext
 
 loadgametype:
   psh de
@@ -270,8 +303,16 @@ searchcomplete:
   ld  a,255
   ld  (ix),a ;end mark
 
+#ifdef intlevels
   ld  ix,templevels-6
-levelselectmenu:
+#else
+  ld  ix,templevels-3
+#endif
+  cp  (ix+3) ;1st=255
+  jp  z,ExitNoStats ;->no lvls
+  cp  (ix+6) ;2nd=255
+  jr  z,loadlevel1 ;->1 lvl
+levelselectmenu: ;load next page
   psh ix ;offset
   ld  a,-2
   ld  (availevels),a
@@ -288,7 +329,9 @@ levelselectmenu:
   ld  hl,$0601 ;x=1
   ld  (_penCol),hl
 dispnextlevel:
-  ld  a,(ix+3)
+  ld  de,3
+  add ix,de
+  ld  a,(ix)
   ld  b,a
   inc a ;cp 255
   jr  z,__levselect
@@ -301,8 +344,6 @@ displevel:
   ld  (hl),a ;y+6
   cp  49 ;bottom of screen
   jr  nc,_levselect
-  ld  de,3
-  add ix,de
   ld  hl,availevels
   inc (hl)
   ld  a,b ;(ix+0)
@@ -312,8 +353,14 @@ displevel:
   cal _vputs
   jr  dispnextlevel
 
+loadlevel1:
+  psh ix
+  pop hl
+  ld  b,-2
+  jr  loadlevel
+
 readylevelfile: ;selected level at ahl
-; ld  hl,templevels-3
+; ld  hl,templevels-3/0
   ld  a,b
   add a,3 ;sellev+3 (#0==-3)
   ld  e,a
@@ -375,7 +422,11 @@ levdescclearloop:
   cal _vputs
   jr  levselectmenu+1
 __levselect:
+#ifdef intlevels
   ld  ix,templevels-6 ;reset 2 1st page
+#else
+  ld  ix,templevels-3
+#endif
 _levselect:
   ld  b,-2 ;level selected
   jr  levselect
@@ -408,12 +459,12 @@ loadlevel:
   cal _Get_Word_ahl
   ld  (leveldataSize),de
 
-  ld  d,8 ;counter
+  ld  d,9 ;counter
   ld  bc,datalevels
   cal loadgametype
   ld  (hilvlposa),a ;singleplayer levels
   ld  (hilvlposhl),hl
-  ld  d,4
+  ld  d,5
   cal loadgametype
 
   cal _SET_ABS_SRC_ADDR ;levelsstart
@@ -452,11 +503,11 @@ setdeflevels:
 ;----- build trig tables -----
 ;-----------------------------
 
-  ld  hl,TrigPrecalc
-  ld  de,SinCosTable
-  psh de
-  ld  bc,65
-  ldir
+  ld  hl,TrigPrecalc ;I believe this
+  ld  de,SinCosTable  ;is one of the few
+  psh de              ;pieces of original
+  ld  bc,65            ;Peaworm code still
+  ldir                  ;left intact..
   dec hl
   ld  b,63
 MirrorSineWave:
@@ -493,11 +544,9 @@ DisplayMenu: ;---draw menu---
   ld  hl,$FC00+$3E0 ;(*,62)
   cal hr
 dispmainmenu:
-  ld  hl,Gametype
-  ld  a,(hl)
+  ld  a,(Gametype)
   dec a ;will be inced @changegame
-  and 7
-  ld  (hl),a
+  cal changedgame
   ld  hl,changegame ;dispmenusets ;mainMenu
   psh hl ;jump here after ret
   ld  hl,txtMenu
@@ -533,12 +582,9 @@ dispmenuloop:
 ; ld  b,0 ;b=menu#
   ret
 
-;hr: ;draw horizontal line at hl
-;  ld  b,16
-;  jp  menuinvloop
-
-hr:
+hr: ;draw horizontal line at hl
   ld  b,16
+; jp  menuinvloop ;shorter but not good for pausescreen
 hrloop:
   ld  (hl),-1
   inc hl
@@ -776,6 +822,17 @@ select:   ;2nd/enter
   dec a ;6th: controls
   jp  z,changekeys
   jp  LetsGetThisPartyOn ;otherwise
+
+changenrworms:
+  cal change4spOnly
+  ld  a,(hl) ;hl=nrworms
+  inc a
+  cp  5
+  jr  nc,mainMenu ;may not be >4
+changednrworms:
+  ld  (hl),a
+  jr  _dispmenusets ;mainMenu
+
 notselect
   cp  K_EXIT
   jp  z,ExitNoStats
@@ -831,15 +888,6 @@ bchangecurworm:
   jr  nz,changedcurworm ;save >0
   jr  mainMenu
 
-changenrworms:
-  cal change4spOnly
-  ld  a,(hl) ;hl=nrworms
-  inc a
-  cp  5
-  jr  nc,mainMenu ;may not be >4
-changednrworms:
-  ld  (hl),a
-  jr  _dispmenusets ;mainMenu
 changenrwormsInit:
   ld  a,(Gametype)
   cp  3
@@ -879,7 +927,12 @@ changegame:
   jr  z,changegame
   jr  dispmenusets ;mainMenu
 changedgame:
-  and 7 ;mod 8
+  cp  9
+  jr  c,changedgameok
+  sub 255-8 ;-1 -> 8
+  jr  nc,changedgameok
+  xor a ;9 -> 0
+changedgameok:
   ld  (Gametype),a
   cal getnrlevels
   xor a
@@ -1199,7 +1252,7 @@ hlatlevel: ;d must be 0
   add a,a ;nc
   add a,e
   add a,a ;8->2bytes
-  add a,24+1 ;go to datalevels
+  add a,28+1 ;go to datalevels
   ld  e,a ;=de
   sbc hl,de ;datalevels
   cal _ldHLind ;ld hl,(hl)
@@ -1255,10 +1308,13 @@ skipballs:
 
 skipflags:
   ld  a,(Gametype)
+  cp  gamerace
+  jr  z,skiplaps
   cp  gamectf
   jr  nz,noflagstoskip
   inc hl
   inc hl
+skiplaps:
   inc hl
   inc hl
 noflagstoskip:
@@ -1304,18 +1360,48 @@ LetsGetThisPartyOn:
   ld  a,$17 ;no exit
   ld  (CheckExit),a ;set exit state
 
+setupworms:
+  ld  hl,worm1set
+  ld  de,worm1
+  ld  a,4 ;4x (all worms)
+createwormsloop:
+  ex  de,hl
+  ld  bc,died ;0008
+  add hl,bc
+; ld  b,0
+  ld  (hl),b ;died=0
+  inc hl
+  ld  (hl),b ;score=0
+  inc hl
+  ld  (hl),b ;score+1=0
+  inc hl
+  ld  (hl),2 ;delay=2
+  inc hl
+  ld  (hl),3 ;lives=x
+wormbeglives =$-1
+  inc hl
+  ex  de,hl  ;de=wormX+head
+  ld  bc,18
+  ldir       ;copy 18 bytes
+  dec a      ;loop
+  jr  nz,createwormsloop
+
+OhMyGodItsALabel:      ;pj34r my coding skillz
   cal loadgamecar
-  psh hl
+  psh hl ;datatype
   cal hlatlevel
   ex  (sp),hl ;pop \ psh leveldata
   psh hl ;psh loadgamecar
   ld  a,0
 gameCar =$-1
   rra ;and _datalink
-  jp  nc,StartLevel ;&&&jr
+  jr  nc,_StartLevel
 
 ;--------- link ------------
 
+wormVhost   = 095
+wormVclient = 195
+
 linkmatch:
   cal _clrWindow
   ld  c,wormVhost
@@ -1359,15 +1445,22 @@ setclient:
   ld  hl,worm2+name
   ld  b,9
   cal sendstuff
-  pop hl
-  pop de
+  pop hl ;loadgamecar
+  pop de ;leveldata
   psh de
-  psh hl
-  ld  b,168
+  psh hl ;loadgamecar
+  ld  b,8
+  cal sendstuff
+  ld  hl,gameCar
+  ld  b,1
+  cal sendstuff
+  ld  hl,Gametype
+  ld  b,1
   cal sendstuff
   ex  de,hl
-  ld  b,8
+  ld  b,168
   cal sendstuff
+_StartLevel:
   jr  StartLevel
 sendstuff:
   psh de
@@ -1409,16 +1502,22 @@ sethost:
   ld  hl,worm2+name
   ld  b,9
   cal recvstuff
-  pop hl
-  pop de
-  ld  hl,templevels
+  pop hl ;loadgamecar
+  pop de ;leveldata
+  ld  hl,templevels ;&&&&&&&
   ld  de,datalink
   psh de
-  psh hl
-  ld  b,168
+  psh hl ;loadgamecar
+  ld  b,8
+  cal recvstuff
+  ld  hl,gameCar
+  ld  b,1
+  cal recvstuff
+  ld  hl,Gametype
+  ld  b,1
   cal recvstuff
   ex  de,hl
-  ld  b,8
+  ld  b,168
   cal recvstuff
 
 ;-------- load level ---------
@@ -1444,35 +1543,17 @@ StartLevel:
   inc hl
   ld  l,(hl)
   ld  h,0
+  ld  a,(gameCar)
+  rla
+  ld  a,0 ;(Left)=256
+  jr  nc,setscorelimit
+  ld  a,l
+  ld  l,h
+setscorelimit:
+  ld  (customleft),a
   cal _HLTIMES10 ;hl=10*(hl)
   ld  (scorelimit),hl
 
-setupworms:
-  ld  hl,worm1set
-  ld  de,worm1
-  ld  a,4 ;4x (all worms)
-createwormsloop:
-  ex  de,hl
-  ld  bc,died ;8
-  add hl,bc
-; ld  b,0
-  ld  (hl),b ;died=0
-  inc hl
-  ld  (hl),b ;score=0
-  inc hl
-  ld  (hl),b ;score+1=0
-  inc hl
-  ld  (hl),2 ;delay=2
-  inc hl
-  ld  (hl),3 ;lives=x
-wormbeglives =$-1
-  inc hl
-  ex  de,hl  ;de=wormX+head
-  ld  bc,18
-  ldir       ;copy 18 bytes
-  dec a      ;loop
-  jr  nz,createwormsloop
-
 Nextlevel:
   cal _clrWindow
   pop hl ;begin of current level
@@ -1495,8 +1576,25 @@ donextlevel:
   or  a ;gamesingle
   psh af
   cal nz,skiplvltitle
-  ld  de,Left
-  ldi
+  ld  a,(hl)
+  and 127
+  jr  nz,setleft
+customleft =$+1
+  ld  a,0
+setleft:
+  ld  (Left),a
+  inc a
+  ld  (lefttotal),a
+  dec a
+  xor (hl) ;bit (hl),7
+  ld  bc,gameCar
+  ld  a,(bc)
+  jr  z,leftloaded
+  or  128+32
+leftloaded:
+  ld  (bc),a
+  inc de
+  inc hl
   ld  de,Speed
   ld  a,0
 customspeed =$-1
@@ -1575,8 +1673,11 @@ worminit:
   ld  (hl),a ;y2
   inc hl
   ld  (hl),a ;x2
+  inc hl
+  inc hl
+  ld  (hl),a ;growH=0
 
-  ld  bc,(worm2-worm1)-5
+  ld  bc,(worm2-worm1)-7
   add hl,bc
   pop bc ;<0
   dnz worminit
@@ -1723,11 +1824,14 @@ maskline:
 #endif
 
   ld  a,(gameCar)
-  and _datafood
-  jr  z,nofood
-  ld  ix,worm1
+  bit _bitfood,a
+  jr  nz,nofood
+;  ld  ix,worm1
   cal NewPea
+  xor a
 nofood:
+  rla ;bit _bitmultpeas,a
+  cal c,multnewpea
   ld  bc,(worm1+pos)
   cal DisplayField
 
@@ -2246,6 +2350,8 @@ removewormloop:
   cal res4pixels
   pop hl
   inc (ix+grow)
+  jr  nz,DoesWormTailEqualsWormHead
+  inc (ix+grow+1) ;+256
 DoesWormTailEqualsWormHead:
   cal _cphlde
   jr  nz,removewormloop
@@ -2256,6 +2362,7 @@ DoesWormTailEqualsWormHead:
   ld  a,0
 beginsize =$-1
   ld  (ix+grow),a
+  ld  (ix+grow+1),0 ;high
 safewormsizedone:
 
   ;de=ix+head
@@ -2375,6 +2482,7 @@ donediddelydone:
   ld  e,(ix+pos2)
   ld  d,(ix+pos2+1)
 
+#ifdef optdie
   psh hl
   ld  hl,previouspos
   ld  (hl),c
@@ -2386,6 +2494,7 @@ donediddelydone:
   inc hl
   ld  (hl),d
   pop hl
+#endif
 
 ;-------- move worm ----------
 
@@ -2446,37 +2555,45 @@ Hitworm:
   ld  a,(gameCar)
   ld  h,a
 #ifdef optdie
-  and _datadie
-  cal z,checkhitotherworm
+; if race - originally
+  cal checkhitotherworm
   ld  a,h
 #endif
-  and _datamultpeas ;&&bit
+  and _datactfpeas ;&&bit
   jr  nz,chkctfpeas
   ld  a,h
+  and _datamultpeas ;&&bit
+  jp  nz,chkmultpeas
+  ld  a,h
   and _datafood
-  jp  z,WormDead ;no food
+  jp  nz,WormDead ;no food
 
   ld  hl,0
 PeaY =$-2
 PeaX =$-1
   cal chkpeahit
   jp  nc,WormDead
+pickpea:
   cal DrawPea ;remove pea
+  cal NewPea
+pickpea_:
   ld  a,(ix+grow)
   add a,15
 peagrowth =$-1
   ld  (ix+grow),a
-  cal NewPea
+  jr  nc,wormset2grow
+  inc (ix+grow+1)
+wormset2grow:
   ld  hl,Left
-  dec (hl)
+  dec (hl) ;dec left before display
   psh af
   ld  e,10
   cal IncScore
   pop af
   jp  nz,Drawworm ;continue
-  ld  a,(gameCar)
-  and _datafoodl
-  jp  z,Drawworm
+; ld  a,(gameCar) ;(Left)>256
+; and _datafoodl
+; jp  z,Drawworm
   ld  a,(Gametype)
   or  a
   jp  nz,Exit ;stack restored
@@ -2559,6 +2676,34 @@ hitflag: ;correct pea hit
   ld  (drawctfpea2),a ;..both flags
   jr  Drawworm
 
+chkmultpeas:
+  ld  de,peaspos-1
+  ld  hl,lefttotalb
+lefttotal =$+1
+  ld  (hl),0
+chkmultpealoop:
+  ex  de,hl
+  inc hl
+  ld  e,(hl)
+  inc hl
+  ld  d,(hl)
+  ex  de,hl
+  psh de
+  cal chkpeahit
+  pop de
+  jr  c,pickmultpea
+  ld  hl,lefttotalb
+  dec (hl)
+  jr  nz,chkmultpealoop
+  jp  WormDead
+pickmultpea:
+  ld  a,247
+  ld  (de),a
+  dec de
+  ld  (de),a
+  cal DrawPea
+  jp  pickpea_
+
 ;-----------------------------
 
 nextotherwormbit:
@@ -2608,37 +2753,6 @@ checklap:
   pop bc
   ret
 
-#ifdef optdie
-checkhitotherworm:
- .db  $dd,$7d ;ld a,lx
-  cp  worm2&255
- psh ix
- jr nz,chkworm2 ; ret nz
-  ld  ix,worm1
- jr chkworm
-chkworm2:
- ld ix,worm2
-
-chkworm:
- ld h,(ix+tail+1)
- ld l,(ix+tail)
- ld e,(ix+head)
- ld d,(ix+head+1)
-  cal ChkWorm
- pop ix
-  ret z ;not hit
-  pop bc ;call
-#endif
-stopworm:
-  ld  bc,0
-previouspos =$-2
-  ld  de,0
-  ld  (ix+pos),c
-  ld  (ix+pos+1),b
-  ld  (ix+pos2),e
-  ld  (ix+pos2+1),d
-  ret
-
 ;-------- draw worm ----------
 
 Drawworm:
@@ -2665,10 +2779,14 @@ Drawworm:
   ld  (ix+head),l
   ld  (ix+head+1),h
 
-  ld  a,(ix+grow)
-  dec a
+  ld  l,(ix+grow)
+  ld  h,(ix+grow+1)
+  dec hl
+  ld  a,h
+  or  l
   jr  z,removetail
-  ld  (ix+grow),a
+  ld  (ix+grow),l
+  ld  (ix+grow+1),h
   ret
 
 removetail:
@@ -2681,6 +2799,13 @@ removetail:
   cal resbit
   ld  (ix+tail),l
   ld  (ix+tail+1),h
+  psh hl
+  cal res4pixels
+  pop hl
+  ld  c,(hl)
+  inc hl
+  ld  b,(hl)
+  jr  set4pixels
 
 res4pixels:
   cal ResPixel
@@ -2827,7 +2952,7 @@ Seed =$+1
 WormDead:
 #ifdef invincible
   jp  stopworm
-#else
+#endif
   ld  a,2
   ld  (flashtime),a
   ld  (ix+delay),respawndelay
@@ -2880,6 +3005,37 @@ anyworm:
   ld  a,$A7 ;exit@end of turn
   ld  (CheckExit),a ;set exit state
   ret ;finish turn
+
+#ifdef optdie
+checkhitotherworm:
+ .db  $dd,$7d ;ld a,lx
+  cp  worm2&255
+ psh ix
+ jr nz,chkworm2 ; ret nz
+  ld  ix,worm1
+ jr chkworm
+chkworm2:
+ ld ix,worm2
+
+chkworm:
+ ld h,(ix+tail+1)
+ ld l,(ix+tail)
+ ld e,(ix+head)
+ ld d,(ix+head+1)
+  cal ChkWorm
+ pop ix
+  ret z ;not hit
+  pop bc ;call
+
+stopworm:
+  ld  bc,0
+previouspos =$-2
+  ld  de,0
+  ld  (ix+pos),c
+  ld  (ix+pos+1),b
+  ld  (ix+pos2),e
+  ld  (ix+pos2+1),d
+  ret
 #endif
 
 CheckPea: ;@hl; destr:abcde
@@ -2918,22 +3074,20 @@ tryDrawPea: ;hl=peapos;bc=dopea
   jr  z,DrawPea
   ret
 
-sendnewpeaoverlink:
-  ld  a,(gameCar)
-  rra ;and _datalink
-  ret nc ;no link
-  ld  a,(ix+left)
-  or  a
-  jr  z,receivenewpeaoverlink
-  ld  c,l ;send pea's pos
-  cal Qsend
-  ld  c,h
-  jp  Qsend ;&&&possible jr
-receivenewpeaoverlink:
-  cal Qrecv ;Crecv
-  ld  l,c
-  cal Qrecv ;Crecv
-  ld  h,c
+multnewpea:
+  ld  de,peaspos
+  ld  a,(Left)
+  ld  b,a
+multpealoop:
+  psh bc
+  psh de
+  cal NewPea
+  pop de
+  ld  hl,PeaY
+  ldi
+  ldi
+  pop bc
+  dnz multpealoop
   ret
 
 NewPea:
@@ -3012,7 +3166,7 @@ chktimematchover:
   jr  z,nneexxtt ;yourself
   cp  (hl)
   ret nz ;someone else still alive
-  dec hl ;+delay
+  dec hl ;+del0ay
   dec hl ;+score+1
   ld  a,(hl)
   cp  (ix+score+1)
@@ -3249,9 +3403,9 @@ savestr:
 
 ;-----------------------------
 
-DisplayField:
-  ld  a,c
-  sub 29
+DisplayField:  ;all done by Jonah Cohen iirc. (-scrolling is scary-)
+  ld  a,c      ;not the fastest routine outthere, but it does get the job done.
+  sub 29       ;if something doesn't work, I probably _did_ alter it ;)
   jr  nc,NotMinYScroll
   xor a
 NotMinYScroll:
@@ -3520,7 +3674,7 @@ FindPixel: ;(b,c) to hl:a
 FP_Bit =$+1
   set 0,a
 
-  psh de ;&&&
+  psh de ;&&& C`MON! THIS IS UGLY! *hit myself*
   ld  de,ScrBuffer
   add hl,de
   pop de
@@ -3558,6 +3712,12 @@ drawsmtn:
 ; dec a ;4 = circle
 ; jp  z,drawcircle
 
+;IMHO, one weery nice routine. Oh lemme be proud just *once*.
+;Not perfect since it uses a screwy lineroutine to draw stuff
+;but, just _look_ at it. Ain't it grand? Z80 at its best.
+;Nice comments, also. So here we go: Shiar's Circle Routine:
+;(using the Bresenham method)
+
 drawcircle: ;(d,e),h   ;de=x,y; h=z
   ld  c,h              ;c=yy=z
   ld  a,h
@@ -3621,7 +3781,7 @@ circledraw:               ;destr:de
   ld  b,c
   ld  c,a              ;ex b,c
   pop hl
-  ret
+  ret                  ;thats it
 
 drawbox: ;(d,e)-(h,l)
   ld  b,l ;Delta-y
@@ -3645,110 +3805,127 @@ drawfatline:
   dec h
 ; jp  drawline
 
-;LINE (d,e)-(h,l)
-;destroyes a
+;A lot like Scabby's line routine in Wonderworm (dunno whether he wrote it
+;himself tho.) I did make a few optimizations and commented the thing.
+;A nice routine (also Bresenham), but for Wormy not perfect since really
+;large lines (>128 pixels in length or something) won't be flawless.
 
 drawline: ;(d,e)-(h,l)
   psh bc  ;destr: a
   psh hl
   psh de
-  ld  a,d
-  cp  h
-  jr  c,lineOrdered
-  ex  de,hl
-lineOrdered:
+  ld  a,d              ;a=d=x
+  cp  h                        ;h=xx
+  jr  c,lineXincs      ;if x>xx
+  ex  de,hl            ;make x<xx
+lineXincs:             ;deltax=|deltax|
   ld  b,d
-  ld  c,e
-  psh hl
-  psh bc
-  cal FindPixel
-  pop bc
-  pop de
-connectedLine:
-  psh hl
-  ld  h,c
-  ld  c,a
-  ld  a,d
-  sub b
-  ld  b,a
-  ld  a,e
-  jr  nz,LineNotPoint
-  cp  h
-  jr  nz,LineNotPoint
-  pop hl
-  jr  DoneLine
-LineNotPoint:
-  sub h
-  ld  de,32
-  jr  nc,LinePositiveY
-  neg
-  ld  de,-32
-LinePositiveY:
-  cp  b
-  jr  nc,SteepLine
-  add a,a
-  ld  (line2sm+1),a
+  ld  c,e              ;bc=x,y
+  psh hl               ;hl=xx,yy
+  cal FindPixel                ;  (ahl=x+y)
+  ex  (sp),hl          ;       :hl>
+  ld  c,a              ;c=mask (always)
+  ld  a,h              ;a=xx
+  sub b                        ;xx-x
+  ld  b,a              ;b=deltax (always>0)
+  ld  a,l              ;a=yy
+  jr  nz,lineexists    ;deltax!=0
+  cp  e                        ;yy==y
+  jr  nz,lineexists    ;deltay!=0
+  pop hl               ;       :<hl
+  jr  DoneLine         ;line is 1 pixel
+lineexists:
+  sub e                        ;a=deltay
+  ld  de,32            ;go down (def)
+  jr  nc,lineYincs     ;cf = deltay<0
+  neg                  ;a=|deltay|
+  ld  de,-32           ;go up
+lineYincs:             ;lets assume y incs as well
+  cp  b                
+  jr  nc,SteepLine     ;deltay<deltax?
+  ld  (line2sm+1),a    ;a=deltay
   ld  h,a
   xor a
   sub b
-  add a,a
-  ld  (line1sm+1),a
-  ld  a,h
-  sub b
-  pop hl
-LineLoopGentle:
-  psh af
+  ld  (line1sm+1),a    ;a=-deltax
+  rra
+  add a,h              ;a=deltay-deltax/2
+  pop hl               ;       :<hl
+
+linedrawxloop:
+  psh af               ;init z=dy-dx
   ld  a,(hl)
-  or  c
+  or  c                        ;|c:hl
   ld  (hl),a
   rrc c
   jr  nc,$+3
-  inc hl
+  inc hl               ;(x++,y)
   pop af
-  jp  m,line2sm
+  jp  m,line2sm                ;z<0
 line1sm:
-  add a,0
-  add hl,de
+  add a,0              ;z-=deltax
+  add hl,de            ;(x,y++)
 line2sm:
-  add a,0
-  dnz LineLoopGentle
+  add a,0              ;z+=deltay
+  dnz linedrawxloop    ;|deltax| times
+
 DoneLine:
   ld  a,(hl)
-  or  c
-  ld  (hl),a
+  or  c                        ;|c:hl
+  ld  (hl),a           ;draw end
   pop de
   pop hl
   pop bc
   ret
+
 SteepLine:
-  ld  h,a
-  neg
-  add a,a
+  ld  h,a              ;h=deltay
+  neg                  ;a=-deltay
   ld  (line3sm+1),a
   ld  a,b
-  add a,a
-  ld  (line4sm+1),a
-  sub h
-  ld  b,h
-  pop hl
-LineLoopSteep:
-  psh af
+  ld  (line4sm+1),a    ;a=deltax
+  sub h                        ;a=deltax-deltay
+  ld  b,h              ;b=deltay
+  pop hl               ;       :<hl
+linedrawyloop:
+  psh af               ;init z=2(dx-dy)
   ld  a,(hl)
-  or  c
+  or  c                        ;|c:hl
   ld  (hl),a
-  add hl,de
+  add hl,de            ;(x,y++)
   pop af
-  jp  m,line4sm
+  jp  m,line4sm                ;z<0
 line3sm:
-  add a,0
+  add a,0              ;z-=deltay
   rrc c
   jr  nc,$+3
-  inc hl
+  inc hl               ;(x++,y)
 line4sm:
-  add a,0
-  dnz LineLoopSteep
+  add a,0              ;z+=deltax
+  dnz linedrawyloop    ;|deltay| times
   jr  DoneLine
 
+
+;--- foo ---
+;wild insert
+receivenewpeaoverlink:
+  cal Qrecv ;Crecv
+  ld  l,c
+  cal Qrecv ;Crecv
+  ld  h,c
+  ret
+sendnewpeaoverlink:
+  ld  a,(gameCar)
+  rra ;and _datalink
+  ret nc ;no link
+  ld  a,(ix+left)
+  or  a
+  jr  z,receivenewpeaoverlink
+  ld  c,l ;send pea's pos
+  cal Qsend
+  ld  c,h
+; jr  Qsend ;that's why it's here
+
 ;..and last but not least..:
 ;-----------------------------
 ;----------- link ------------
@@ -3757,38 +3934,6 @@ line4sm:
 timeout = $8000
 lossout = 20
 
-linkok:
-  ld  a,D0HD1H
-  out (7),a            ;raise both wires = link ok
-  ret
-
-checklink:             ;load wires in A and check for timeout
-  dec de               ;decrease timer
-  ld  a,d
-  or  e
-  jr  z,linktimeout    ;timeout if de==0
-linktest:
-  ld  a,$BF
-  out (1),a            ;select keys
-  in  a,(1)            ;input
-  bit 6,a              ;exit key
-  jp  z,Exit           ;break!
-linkfine:
-  in  a,(7)
-  and %11
-  ret
-linktimeout: ;de==0
-  cal linkok
-  ld a,0               ;losses so far
-linklosses =$-1
-  inc a                ;and this is another one
-  ld (linklosses),a
-  pop de               ;return from link
-  cp  lossout          ;quit if too many errors
-  ret c                ;otherwise just continue
-linkerr:
-  jp  Exit
-
 ;---- SEND ----
 
 Qsend:         ;--- try to send 8 bits in C; CF=error --- destr:abcde ---
@@ -3853,12 +3998,46 @@ recvfinish:
   ld (linklosses),a    ;reset number of losses
   ret
 
+;---- COMMON ----
+
+linkok:
+  ld  a,D0HD1H
+  out (7),a            ;raise both wires = link ok
+  ret
+
+checklink:             ;load wires in A and check for timeout
+  dec de               ;decrease timer
+  ld  a,d
+  or  e
+  jr  z,linktimeout    ;timeout if de==0
+linktest:
+  ld  a,$BF
+  out (1),a            ;select keys
+  in  a,(1)            ;input
+  bit 6,a              ;exit key
+  jp  z,Exit           ;break!
+linkfine:
+  in  a,(7)
+  and %11
+  ret
+linktimeout: ;de==0
+  cal linkok
+  ld a,0               ;losses so far
+linklosses =$-1
+  inc a                ;and this is another one
+  ld (linklosses),a
+  pop de               ;return from link
+  cp  lossout          ;quit if too many errors
+  ret c                ;otherwise just continue
+linkerr:
+  jp  Exit
+
+#ifdef intlevels
 
 ;-----------------------------
 ;---------- levels -----------
 ;-----------------------------
 
-;&&&&& 99%
 LevelDef:
   .db 5,4,15,15,0,0    ;peas,speed,growth,begin_size,sprite,balls
   .db 0,2,63           ;start d, y, x
@@ -3870,13 +4049,13 @@ LevelDef:
 
 LevelDefM:
   .db "Empty Arena",0
-  .db 8,4,15,15,0,0
+  .db 5,4,15,15,0,0
   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
   .db 128,57
   .db 0
 
   .db "Fast Fun :))",0
-  .db 8,0,18,12,5
+  .db 8+128,0,18,12,5
   .db %1110000,%10001000,%10001000,%10001000,%1110000,0
   .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64
   .db 128,57
@@ -3915,6 +4094,8 @@ LevelDefC: ;ctf
   .db 27,8,27,116
   .db 0
 
+#endif
+
 ;-----------------------------
 ;---------- data -------------
 ;-----------------------------
@@ -3975,9 +4156,10 @@ txtGame1: .db "Peaworm",0
 txtGame2: .db "Tron",0
 txtGame3: .db "Deathmatch",0
 txtGame4: .db "Foodmatch",0
-txtGame5: .db "Timematch",0
-txtGame6: .db "Race",0
-txtGame7: .db "CTF" ;,0
+txtGame5: .db "Multifoodmatch",0
+txtGame6: .db "Timematch",0
+txtGame7: .db "Race",0
+txtGame8: .db "CTF" ;,0
 
 posGame:  .db 0
          .db txtGame1-txtGame
@@ -3987,6 +4169,7 @@ posGame:  .db 0
          .db txtGame5-txtGame
          .db txtGame6-txtGame
          .db txtGame7-txtGame
+         .db txtGame8-txtGame
 
 txtNone:   .db "None",0
 txtDef:    .db "Default",0
@@ -4026,45 +4209,54 @@ txtposReady = 7
 txtGO:     .db 5,5,5,5,5," GAME OVER ",$CF,$CF,$CF,$CF,$CF,0
 #endif
 
+#ifdef intlevels
 datalevels: .dw LevelDef, LevelDefM
             .dw LevelDefT,LevelDefM
-            .dw LevelDefM,LevelDefM
+            .dw LevelDefM,LevelDefM,LevelDefM
             .dw LevelDefR,LevelDefC
-nrlevels:   .db 0,3,1,3,3,3,3,1     ;=defaults
-
-_datalink      = %0000001 ;linkplay
-_datafoodl     = %0000010 ;left=0 limit
-_datasingl     = %0000100 ;singleplayer=1 (=hiscore+keep_length+nextlevel)
-_datamultpeas  = %0001000 ;multiple peas=1
-_datatime      = %0010000 ;time incs score (timematch)
-_datafood      = %0100000 ;food present
-_datadie       = %1000000 ;worm dies on impact
-;reserved       %10000000 ;for future use
-
-savestart:        ;     �game info (see above)
-                  ;     | �lives (0=unlimited)
-                  ;     | | �nrworms (can be altered by user)
-                  ;     | | | �level (reset to 1 at startup)
-                  ;     | | | |  �speed/delay (-1=def)
-                  ;     | | | |  |  �grow speed (-1=none; 0=continuous)
-                  ;     | | | |  |  |  �turn speed (8=def)
-                  ;     | | | |  |  |  |  �score limit (0=none)
-gamesingle   =  0 ;used | | | |  |  |  |  |
-datasingle: .db  %1100110,3,1,1,-1,-1, 8, 0 ;Singleplayer (SP; 3 lives)
+nrlevels:   .db 2,3,1,3,3,3,3,3,1,0     ;=defaults
+#else
+datalevels: .dw 0,0,0,0,0,0,0,0,0
+nrlevels:   .dw 0,0,0,0,0
+#endif
+
+_datalink      = %00000001 ;linkplay
+_datafoodl     = %00000010 ;left=0 limit
+_datasingl     = %00000100 ;singleplayer=1 (=hiscore+keep_length+nextlevel)
+_datactfpeas   = %00001000 ;ctf peas=1
+_datatime      = %00010000 ;time incs score (timematch)
+_datafood      = %00100000 ;food present=0
+_bitfood       = 5
+_datamultpeas  = %10000000 ;multiple peas=1 (no _datafood)
+_bitmultpeas   = 7
+;reserved        %01000000 ;for future use
+
+savestart:        ;      �game info (see above)
+                  ;      | �lives (0=unlimited)
+                  ;      | | �nrworms (can be altered by user)
+                  ;      | | | �level (reset to 1 at startup)
+                  ;      | | | |  �speed/delay (-1=def)
+                  ;      | | | |  |  �grow speed (-1=none; 0=continuous)
+                  ;      | | | |  |  |  �turn speed (8=def)
+                  ;      | | | |  |  |  |  �score limit (0=none)
+gamesingle   =  0 ;      | | | |  |  |  |  |
+datasingle: .db  %01000110,3,1,1,-1,-1, 8, 0 ;Singleplayer (SP; 3 lives)
 gamepeas     =  1
-datapeas:   .db  %1100100,1,1,1,-1,-1, 8, 0 ;Peaworm (SP; 1 live)
+datapeas:   .db  %01000100,1,1,1,-1,-1, 8, 0 ;Peaworm (SP; 1 live)
 gametron     =  2
-datatron:   .db  %1010100,1,1,1,-1, 0, 8, 0 ;Tron (SP; 1 live, cont.growth)
-gamedeathm   =  3 ;used
-datadeathm: .db  %1000000,3,2,1,-1,49, 8, 0 ;Deathmatch (3 lives, 50 growth)
+datatron:   .db  %01110100,1,1,1,-1, 0, 8, 0 ;Tron (SP; 1 live, cont.growth)
+gamedeathm   =  3
+datadeathm: .db  %01100000,3,2,1,-1,49, 8, 0 ;Deathmatch (3 lives, 50 growth)
 gamefoodm    =  4
-datafoodm:  .db  %1100000,0,2,1,-1,-1, 8,10 ;Foodmatch (100 score)
-gametimem    =  5
-datatimem:  .db  %1010000,1,2,1,-1, 0, 8, 0 ;Timematch (tron, 100 score)
-gamerace     =  6 ;used
-datarace:   .db  %0000000,0,2,1,-1,-1, 8,10 ;Race (100 score, no collision)
-gamectf      =  7 ;used
-datactf:    .db  %1001000,0,4,1,-1,-1, 8,10 ;CTF (100 score)
+datafoodm:  .db  %01000000,0,2,1,-1,-1, 8,10 ;Foodmatch (100 score)
+gamemfoodm   =  5
+datamfoodm: .db  %11100010,0,2,1,-1,-1, 8,10 ;MuchFoodmatch (10 peas))
+gametimem    =  6
+datatimem:  .db  %01110000,1,2,1,-1, 0, 8, 0 ;Timematch (tron, 100 score)
+gamerace     =  7
+datarace:   .db  %01100000,0,2,1,-1,-1, 8,10 ;Race (100 score)
+gamectf      =  8
+datactf:    .db  %01001000,0,4,1,-1,-1, 8,10 ;CTF (100 score)
 
 worm1set:  .dw worm1p,worm1p
            .db %11110111,1,-01,K_RIGHT,K_LEFT
@@ -4080,11 +4272,13 @@ worm4set:  .dw worm4p,worm4p
 worm4name: .db "JIM     ",0
 
 defhiscrpos:
+#ifdef intlevels
   .db 0,0,"SHI"
   .db 0,0,"SHI"
   .db 0,0,"SHI"
   .db 0,0,"SHI"
   .db 0,0,"SHI"
+#endif
 
 Gametype:  .db 0 ;last gamemode
 
@@ -4114,50 +4308,19 @@ startdelay    = 30
 respawndelay  = 30
 maxnamelength = 8+1
 
-;bla space (reserved for internal levels)
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "WWW.SHIAR.ORG  WWW.SHIAR.ORG  "
-.db "   wormy@shiar.org",0
-
 defspritesz = 4
 defspriteimg:  .db %01100000
                .db %11110000
                .db %11110000
                .db %01100000
 
+#ifdef intlevels
 deflevels:
   .db "Internal Levels",0
-  .db "by SHIAR -- still t"
-  .db "o be added...." ;,0
+  .db "by Shiar" ;,0
 
   .db 0,deflevels/256,deflevels&255
+#endif
 templevels:
 
 ;-----------------------------