jonah: ambidirectional scrolling, 9 levels
[wormy.git] / worm.asm
index 0abad605dc7e56a0cb15cc8478f11a1d7a5883ea..66d354965d57dac704025dd75656d30d94b7c7fd 100644 (file)
--- a/worm.asm
+++ b/worm.asm
@@ -1,42 +1,23 @@
-
 ; -WonderWorm--v0.9-
 ; by Matthew Shepcar
 ; 30th December 1998
 
-#include asm86.h
-#include ti86asm.inc
-#include ti86abs.inc
+; modified by Jonah Cohen 11-14-99
+
+#include "TI86.inc"
 
 .org _asm_exec_ram
-                    
+
   nop
   jp Start
   .dw 0,WormMsg
 Start:
-
-  call _runindicoff
+  ld (SpSave),sp
+  call _runIndicOff
   call _clrLCD
 
   call BuildTrigTables
 
-  ld hl,0FC00h
-  ld de,GreyBuf
-  ld bc,400h
-  ldir
-
-  ld hl,IHandler
-  ld bc,IHandlerEnd-IHandler
-  ld de,0BCBCh
-  ldir
-  ld hl,0BD00h
-  ld (hl),d
-  ld de,0BD01h
-  ld a,d
-  ld bc,256
-  ldir
-  ld i,a
-  im 2
-
   ld a,r
   ld (Seed),a
 
@@ -139,11 +120,6 @@ DrawLines:
 NoLines:
   push hl
 
-  ld hl,ScrBuffer
-  ld de,ScrBuffer+BufSize
-  ld bc,BufSize
-  ldir
-
   ld hl,0
   ld (_penCol),hl
   ld hl,LivesMsg
@@ -189,7 +165,6 @@ ReadyDelay:
   ld de,0
 
 GameLoop:
-
   ld a,c
   sub 29
   jr nc,NotMinScroll
@@ -202,7 +177,7 @@ FieldHeight =$-1
 NotMaxScroll:
   call DisplayField
 
-  ld a,5
+  ld a,9
 Speed =$-1
 Delay:
   halt
@@ -227,10 +202,11 @@ Heading =$-2
   rra
   rra
   jr c,NotRight
+  push af
   ld a,l
   add a,8
   ld l,a
-  inc a
+  pop af
 NotRight:
   rra
   jr c,NotLeft
@@ -306,7 +282,7 @@ PeaX =$-1
   sub l
   inc a
   cp 4
-  jr nc,WormDead
+  jp nc,WormDead
   push bc
   call DrawPea
   ld a,0
@@ -322,12 +298,15 @@ GrowAmt =$-1
   dec (hl)
   jr nz,NotNextLevel
   ld hl,Level
+  ld a,(hl)
   inc (hl)
   pop bc
   pop de
   pop hl
   pop de
-  jp StartLevel
+  cp NUM_LEVELS
+  jp nz,StartLevel
+  jr Exit
 
 NotNextLevel:
   ld a,(hl)
@@ -377,19 +356,18 @@ GrowWorm:
   in a,(1)
   rla
   jr c,NotPaused
-  call _getky
-WaitUnpause:
+  ld bc,$0103
+  out (c),b
   halt
-  call _getky
-  or a
-  jr z,WaitUnpause
-  ld a,128
+  ld b,11
+  out (c),b
 NotPaused:
   pop bc
   pop de
   rla
   jp c,GameLoop
-  push hl
+  jr Exit
+; push hl
 WormDead:
   pop de
   pop hl
@@ -403,6 +381,7 @@ WormDead:
   dec (hl)
   pop hl
   jp nz,NextLife
+Exit:
 
 #if 0
   ld a,(Eaten)
@@ -410,7 +389,7 @@ WormDead:
   cp (hl)
   jr c,NotNewHigh
   ld (hl),a
-  ld hl,Varname-1
+  ld hl,_asapvar
   rst 20h
   rst 10h
   call 460Bh
@@ -422,15 +401,11 @@ WormDead:
   ld (hl),a
 NotNewHigh:
 #endif
+  ld sp,0
+SpSave = $-2
+  jp _clrWindow
 
-  im 1
-  ld a,03Ch
-  out (0),a
-  call _clrScrn
-  call _homeup
-  jp _getky
-
-NewPea:
+NewPea: ;------------------------------procs
   call Random
   ld a,h
   and 7Fh
@@ -502,66 +477,29 @@ noadd16:
   ld a,h
   ret
 
-ResPixel:
+ResPixel: ;at bc
   call FindPixel
   cpl
-  ld d,a
   and (hl)
-  ld (hl),a
-  ld a,d
-  ld de,BufSize
-  add hl,de
-  and (hl)
-  ld (hl),a
+  ld  (hl),a
   ret
 
-SetPixel:
-  push bc
-  push af
-  push af
+SetPixel: ;at bc
   call FindPixel
-  pop de
-  ld e,a
-  rr d
-  jr c,SetGrey1
-  cpl
-  and (hl)
-  ld (hl),a
-SetGrey1:
-  or (hl)
-  ld (hl),a
-  ld bc,BufSize
-  add hl,bc
-  ld a,e
-  rr d
-  jr c,SetGrey2
-  cpl
-  and (hl)
-  ld (hl),a
-SetGrey2:
-  or (hl)
-  ld (hl),a
-  pop af
-  pop bc
+  or  (hl)
+  ld  (hl),a
   ret
 
-CheckPixel:
+CheckPixel: ;at bc in d
   push de
   call FindPixel
-  push af
   and (hl)
-  ld de,BufSize
-  add hl,de
-  ld e,a
-  pop af
-  and (hl)
-  or e
   pop de
   ret z
   dec d
   ret
 
-FindPixel:
+FindPixel: ;bc to ahl + de gone
   push bc
   ld a,b
   and 7
@@ -616,7 +554,7 @@ NotZeroDigit:
 PutNum:
   ld l,a
   ld h,0
-  call UNPACK_HL
+  call _divHLby10
   push af
   ld a,l
   call PutDigit
@@ -628,45 +566,19 @@ PutDigit:
 offsets_table:
   .db 128,64,32,16,8,4,2,1
 
-IHandler:
-  exx
-  ex af,af'
-       in a,(3)
-       bit 1,a
-       jr z,notvbl
-       ld hl,GreyCounter
-       inc (hl)
-       ld a,(hl)
-  cp 3
-       ld a,3Ch
-       jr nz,notpage1
-  ld (hl),0
-  ld a,(GreyBuf/256)-0C0h
-notpage1:
-       out (0),a
-notvbl:
-  jp 3Ah
-IHandlerEnd:
-GreyCounter .db 0
-
 DisplayField:
-  ld l,a
-  ld h,0
+  ld  l,a
+  ld  h,0
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   push bc
   push de
-  ld de,ScrBuffer
-  add hl,de
-  ld de,0FC70h
-  ld bc,00390h
-  ldir
-  ld de,BufSize-390h
+  ld  de,ScrBuffer
   add hl,de
-  ld de,GreyBuf+70h
-  ld bc,00390h
+  ld  de,$FC00+$70
+  ld  bc,$0390
   ldir
   pop de
   pop bc
@@ -678,7 +590,7 @@ DispMsg:
   ld l,4
   ld (_curRow),hl
   ld hl,0FDE0h
-  ld de,0FDE1h 
+  ld de,0FDE1h
   ld (hl),-1
   ld bc,0BFh
   ldir
@@ -687,27 +599,94 @@ DispMsg:
   jp _puts
 
 
+NUM_LEVELS = 9
+
 Levels:
-  .db 5,7           ;5 peas, speed 7
+  .db 5,9           ;5 peas, speed 7
   .db 64,4,0        ;x,y,d
   .db 57            ;field height
   .db 0             ;no additional lines
 
-  .db 8,6
-  .db 4,14,40h
+  .db 8,9
+  .db 4,14,$40
   .db 57
   .db 1
   .db 28,28,100,28
 
-  .db 99,5
-  .db 4,14,40h
-  .db 100
+  .db 9,8
+  .db 4,8,$40
+  .db 57
   .db 2
-  .db 28,28,28,72
-  .db 100,28,100,72
+  .db 28,14,100,14
+  .db 28,41,100,41
 
-#include trigtab.asm
-#include line.asm
+  .db 9,8
+  .db 4,8,$40
+  .db 80
+  .db 2
+  .db 64,14,64,66
+  .db 20,40,108,40
+
+  .db 10,7
+  .db 4,8,$40
+  .db 90
+  .db 3
+  .db 18,20,18,70
+  .db 110,20,110,70
+  .db 18,45,110,45
+
+  .db 7,7
+  .db 64,4,0
+  .db 86
+  .db 6
+  .db 34,13,56,35
+  .db 34,71,56,49
+  .db 72,35,94,13
+  .db 72,49,94,71
+  .db 16,20,16,64
+  .db 110,20,110,64
+
+  .db 9,7
+  .db 4,10,$40
+  .db 82
+  .db 3
+  .db 0,20,74,20
+  .db 54,40,128,40
+  .db 0,60,74,60
+
+  .db 12,7
+  .db 64,4,0
+  .db 90
+  .db 6
+  .db 20,16,54,16
+  .db 74,16,110,16
+  .db 20,16,20,72
+  .db 110,16,110,72
+  .db 20,72,54,72
+  .db 74,72,110,72
+
+  .db 8,7
+  .db 72,52,$c0
+  .db 128
+  .db 13
+  .db 34,56,56,34
+  .db 34,72,56,94
+  .db 72,34,94,56
+  .db 72,94,94,72
+  .db 46,64,80,64
+  .db 22,11,22,33
+  .db 11,22,33,22
+  .db 22,95,22,117
+  .db 11,106,33,106
+  .db 103,11,103,33
+  .db 91,22,115,22
+  .db 103,95,103,117
+  .db 91,106,115,106
+
+
+
+#include "trigtab.asm"
+#include "line.asm"
 
 WormMsg .db "Wonderworm!",0
 LevelMsg .db "Level ",0
@@ -715,7 +694,6 @@ LivesMsg .db "Lives: ",0
 ScoreMsg .db "Score: ",0
 LeftMsg  .db "Food: ",0
 HiScore .db 0
-Varname .db 4,"worm"
 
 Left =$
 Lives =$+1
@@ -723,8 +701,184 @@ Level =$+2
 Score =$+3
 
 SinCosTable =09E00h
-ScrBuffer =8200h
-BufSize =0A00h
-GreyBuf =0F400h
+ScrBuffer =8200h ;size $1400 (at least)
+
+.end
+eft:
+  dec hl
+  rl (hl)
+  djnz ShiftRowLeft
+  pop hl
+  dec c
+  jr nz,ShiftRowsLeft
+  ld bc,-16
+  add hl,bc
+  ex de,hl
+  pop bc
+  djnz ShiftLeftLoop
+  ld a,(ShiftBitsLeft)
+  jr NoShift
+ShiftRight:
+  dec hl
+  ex de,hl
+  ld c,16
+  sbc hl,bc
+  ex de,hl
+  ld b,57
+  cpl
+  add a,9
+  ld (ShiftBitsRight),a
+ShiftRightLoop:
+  push bc
+  ld bc,-32
+  add hl,bc
+  ex de,hl
+  ld a,(de)
+  ld c,0
+ShiftBitsRight = $-1
+ShiftRowsRight:
+  push hl
+  rra
+  ld b,16
+ShiftRowRight:
+  rr (hl)
+  inc hl
+  djnz ShiftRowRight
+  pop hl
+  dec c
+  jr nz,ShiftRowsRight
+  ld bc,-16
+  add hl,bc
+  ex de,hl
+  pop bc
+  djnz ShiftRightLoop
+  ld a,(ShiftBitsRight)
+NoShift:
+  ld hl,DispBuffer
+  ld de,$fc00+$70
+  ld bc,1024-$70
+  ldir
+  cpl
+  add a,8
+  jr z,NoShiftDelay
+ShiftDelay:
+  ld bc,$0005
+ShiftDelayLoop = $-1
+  djnz ShiftDelayLoop
+  dec c
+  jr nz,ShiftDelayLoop
+  dec a
+  jr nz,ShiftDelay
+NoShiftDelay:
+  pop de
+  pop bc
+  ret
+
+
+NUM_LEVELS = 9
+
+Levels:
+  .db 5,2           ;5 peas, speed 9
+  .db 64,4,0        ;x,y,d
+  .db 0,0            ;field width, height
+  .db 0             ;no additional lines
+
+  .db 8,2
+  .db 4,14,$40
+  .db 128,57
+  .db 1
+  .db 28,28,100,28
+
+  .db 9,2
+  .db 4,8,$40
+  .db 128,57
+  .db 2
+  .db 28,14,100,14
+  .db 28,41,100,41
+
+  .db 9,1
+  .db 4,8,$40
+  .db 128,80
+  .db 2
+  .db 64,14,64,66
+  .db 20,40,108,40
+
+  .db 10,1
+  .db 4,8,$40
+  .db 128,90
+  .db 3
+  .db 18,20,18,70
+  .db 110,20,110,70
+  .db 18,45,110,45
+
+  .db 7,1
+  .db 64,4,0
+  .db 128,86
+  .db 6
+  .db 34,13,56,35
+  .db 34,71,56,49
+  .db 72,35,94,13
+  .db 72,49,94,71
+  .db 16,20,16,64
+  .db 110,20,110,64
+
+  .db 9,0
+  .db 4,10,$40
+  .db 128,82
+  .db 3
+  .db 0,20,74,20
+  .db 54,40,128,40
+  .db 0,60,74,60
+
+  .db 12,0
+  .db 64,4,0
+  .db 128,90
+  .db 6
+  .db 20,16,54,16
+  .db 74,16,110,16
+  .db 20,16,20,72
+  .db 110,16,110,72
+  .db 20,72,54,72
+  .db 74,72,110,72
+
+  .db 8,0
+  .db 72,52,$c0
+  .db 128,128
+  .db 13
+  .db 34,56,56,34
+  .db 34,72,56,94
+  .db 72,34,94,56
+  .db 72,94,94,72
+  .db 46,64,80,64
+  .db 22,11,22,33
+  .db 11,22,33,22
+  .db 22,95,22,117
+  .db 11,106,33,106
+  .db 103,11,103,33
+  .db 91,22,115,22
+  .db 103,95,103,117
+  .db 91,106,115,106
+
+
+
+#include "trigtab.asm"
+#include "line.asm"
+
+WormMsg .db "Wonderworm!",0
+LevelMsg .db "Level ",0
+LivesMsg .db "Lives: ",0
+ScoreMsg .db "Score: ",0
+LeftMsg  .db "Food: ",0
+HiScore .db 0
+
+Left =$
+Lives =$+1
+Level =$+2
+Score =$+3
+DispBuffer =$+5
+
+ScrBuffer =$8200 ;32x256 bytes
+SinCosTable =$a200
+WormPos = $b000
 
 .end