version 0.1: collision detection
[nemesis.git] / nemesis.z80
1         .include "asm86.h"           
2         .include "ti86asm.inc"
3         .include "ti86abs.inc"
4         .org _asm_exec_ram
5         nop
6         jp  Start
7         .dw $0000
8         .dw Title
9 Title:  .db "Nemesis v0.1.718 by Shiar",0
10 Start:
11         jr init
12
13 ;-------------------- init ----------------------------------------------------
14
15 init:
16         call _runindicoff
17
18 ;-------------------- main menu -----------------------------------------------
19
20         jp play_game
21
22 ;-------------------- exit ----------------------------------------------------
23
24 exit_game:
25         ret
26
27 ;----------------------- game setup -------------------------------------------
28
29 play_game:
30         ld  hl,stored_data_start
31         ld  bc,variables_end-stored_data_start-1
32
33 ;---------------------- display setup ----------------------------------------
34
35 set_up_display:
36         call _clrLCD
37
38         ld  hl,in_game_text
39         ld  b,3
40 l11:    ld  a,(hl)
41         ld  (_curCol),a
42         inc hl
43         ld  a,(hl)
44         ld  (_curRow),a
45         inc hl
46         call _puts
47         djnz l11
48
49 in_game_text:
50         .db 16,0,"LIVES",0
51         .db 16,3,"LEVEL",0
52         .db 16,6,"SCORE",0
53
54 str_question:
55         .db "-----",0
56
57 ;------------------------------------------------------------------------------
58 ;-------------------------- game loop -----------------------------------------
59 ;------------------------------------------------------------------------------
60
61 game_main_loop:
62         ld  hl,timer            ;update time
63         inc (hl)
64
65 Clear_screen:
66         xor a
67         ld  hl,GRAPH_MEM+(16*12)
68         ld  b,a
69 clearloop:
70         ld  (hl),a
71         inc hl
72         ld  (hl),a
73         inc hl
74         ld  (hl),a
75         inc hl
76         djnz clearloop
77
78 check_exitkey:
79         ld  a,%00111111         ;<exit> pressed?
80         out (1),a
81         nop
82         nop
83         in  a,(1)
84         bit 6,a
85         jr  z,quit              ;yes: quit game
86
87 game_stuff:
88         call Level_event        ;insert enemies
89         call Handle_Ship        ;move you
90         call Handle_enemies     ;move enemies
91         call Enemies_hit        ;check for collision with enemies
92
93         call Display_Screen     ;display all
94 ;       halt \ halt \ halt      ;delay
95         jr   game_main_loop     ;loop
96
97 quit:   ret
98
99 ;---------------------- display -----------------------------------------------
100
101 Display_Screen:
102         ld  a,64                ;Display Image
103         ld  hl,GRAPH_MEM+(16*12)
104         ld  de,$fc00
105 displayloop:
106         ld  bc,12
107         ldir
108         inc de
109         inc de
110         inc de
111         inc de
112         dec a
113         jr  nz,displayloop
114
115 ;       ld  hl,$1007            ;Display Score
116 ;       ld  (_curRow),hl
117 ;       ld  hl,(score)
118 ;       jp  _D_HL_DECI
119         ret
120
121 ;------------------------- handle ship ----------------------------------------
122
123 Handle_Ship:
124         ld  a,(your_status)
125 ;       bit 4,a
126 ;       jr  nz,you_not_normal
127         or  a
128         jr  z,ok
129 ;       dec a
130 ;       ld  (your_status),a
131 ;       ld  hl,(lives)
132 ;       ld  a,l
133 ;       or  h
134 ;       jr  nz,ok
135 ;       pop af
136 ;       ret
137
138 ok:
139         ld  a,%01111110
140         out (1),a
141         ld  hl,y
142         in  a,(1)
143         rra
144         ld  b,a
145
146         jr  c,no_down
147         ld  a,(hl)
148         inc a
149         cp  73                  ;y < 73
150         jr  z,no_down
151         ld  (hl),a
152 no_down:
153         dec hl
154         rr  b
155         jr  c,no_left
156         ld  a,(hl)
157         dec a
158         jr  z,no_left           ;x > 0
159         ld  (hl),a
160 no_left:
161         rr b   
162         jr  c,no_right
163         ld  a,(hl)
164         inc a
165         cp  89                  ;x < 89
166         jr  z,no_right
167         ld  (hl),a
168 no_right:
169         ld d,(hl)
170         inc hl
171         rr  b
172         jr  c,no_up
173         ld  a,(hl)
174         dec a
175         cp  15                  ;y > 15
176         jr  z,no_up
177         ld  (hl),a
178 no_up:  ld  ix,spr_ship
179
180 display_common:
181         ld  e,(hl)
182         jp  drw_spr
183
184 ;you_not_normal:
185 ;       ld       hl,(score)
186 ;       ld       de,-6
187 ;       add      hl,de    
188 ;       ld       a,255
189 ;       cp       h
190 ;       jr       nz,_ok_
191 ;       ld       hl,0
192 ;_ok_:  ld       (score),hl
193 ;       ld       a,(your_status)
194 ;       dec      a
195 ;       ld       (your_status),a
196 ;       inc      a
197 ;       and      14
198 ;       xor      14
199 ;       ld       hl,x-1
200
201 ;explosion_stuff:
202 ;       rra
203 ;       add a,a
204 ;       add a,a
205 ;       add a,a
206 ;       ld  c,a
207 ;       ld  b,0
208 ;       ld  ix,spr_explosion
209 ;       add ix,bc
210 ;       inc hl
211 ;       ld  d,(hl)
212 ;       inc hl
213 ;       jr  display_common
214
215 ;--------------------------- level events -------------------------------------
216
217 Level_event:
218         ld  a,(nextevent)
219         dec a
220         ld  (nextevent),a
221         or  a
222         ret nz
223
224 do_event:
225         ld  hl,(curevent)       ;+1
226         ld  de,enemies-4
227 chk_noenemy:
228         inc de
229         inc de
230         inc de
231         inc de
232         ld  a,(de)
233         or  a
234         jr  nz,chk_noenemy
235
236         ld  a,$01
237         ld  (de),a      ;occ
238         inc de
239
240         ld  a,(hl)
241         ld  (de),a      ;type
242         inc de
243
244         ld  a,$5a
245         ld  (de),a      ;x
246         inc de
247
248         inc hl                  ;+2
249         ld  a,(hl)
250         ld  (de),a      ;y
251
252         inc hl                  ;+0
253         ld  a,(hl)
254         cp  $ff
255         jp  z,Next_level
256         ld  (nextevent),a
257
258         inc hl                  ;+1
259         ld  (curevent),hl
260         ret
261
262 ;--------------------------- handle enemies -----------------------------------
263
264 Handle_enemies:
265         ld  hl,enemies
266
267 handle_enemy:
268         push hl
269
270         ld  a,(hl)
271         cp  1
272         jr  nz,next_enemy
273
274         inc hl
275         ld  c,(hl)              ;type
276         inc hl
277         ld  d,(hl)              ;x
278         inc hl
279         ld  e,(hl)              ;y
280
281         ld  a,d
282         or  a
283         jr  z,next_enemy
284         dec a
285         ld  d,a
286         jr  z,remove_enemy
287
288         ld  (hl),e
289         dec hl
290         ld  (hl),d
291         ld  ix,spr_enemy01
292         ld  b,$00
293         add ix,bc
294         call drw_spr
295         jr  next_enemy
296
297 remove_enemy:
298         dec hl
299         dec hl
300         dec hl
301         ld  (hl),$0000
302
303 next_enemy:
304         pop hl
305         inc hl
306         inc hl
307         inc hl
308         inc hl
309         ld  a,(hl)
310         cp  $ff
311         jr  nz,handle_enemy
312
313         ret
314
315 ;--------------------------- check collision ----------------------------------
316
317 Enemies_hit:
318         ld  de,(x)              ;e = X, d = Y
319         ld  hl,enemies-4
320 check_next:
321         inc hl
322         inc hl
323         inc hl
324         inc hl
325
326         ld  a,(hl)
327         cp  $ff
328         ret z                   ;-1 = no more enemies
329         push hl
330         cp  1
331         jr  nz,nocrash          ;1 = enemy
332
333         inc hl
334         inc hl
335         ld  a,(hl)              ;check x match
336         sub e
337         add a,6
338         jp  m,nocrash
339         cp  12
340         jr  nc,nocrash
341
342         inc hl
343         ld  a,(hl)              ;check y match
344         sub d
345         add a,6
346         jp  m,nocrash
347         cp  12
348         jr  nc,nocrash
349
350         dec hl
351         dec hl
352         ld  (hl),0
353         dec hl
354         ld  (hl),2              ;set to explode
355
356 nocrash:
357         pop hl
358         jr  check_next
359
360 ;--------------------------- next level ---------------------------------------
361
362 Next_level:
363         ld  hl,Leveldata+1
364         ld  (curevent),hl
365         ret
366
367 ;--------------------------- putsprite ----------------------------------------
368
369 offsets_table:
370         .db 128,64,32,16,8,4,2,1
371 drw_spr:
372         ld  a,d
373         and 7
374         ld  hl,offsets_table
375         ld  c,a
376         ld  b,0
377         add hl,bc
378         ld  a,(hl)
379         ld  (_smc1+1),a
380
381         ld  (_smc1+1),a
382         ld  hl,GRAPH_MEM
383         ld  a,e
384         add a,a
385         add a,e
386         add a,a
387         rl  b
388         add a,a
389         rl  b
390         srl d
391         srl d
392         srl d
393         add a,d
394         jr  nc,_n1
395         inc b
396 _n1:    ld  c,a
397         add hl,bc
398           
399         ld  d,(ix)
400         ld  b,(ix+1)
401 _oloop: push bc                 ;Save # of rows
402         push hl                 ;Save screen address
403         ld  b,d                 ;Load width
404         ld  c,(ix+2)            ;Load one line of image
405         inc ix
406 _smc1:  ld  a,1                 ;Load pixel mask
407 _iloop: sla c                   ;Test leftmost pixel
408         jr  nc,_noplot          ;See if a plot is needed
409         ld  e,a                 ;OR pixel with screen
410         or  (hl)
411         ld  (hl),a
412         ld  a,e
413 _noplot: rrca
414         jr  nc,_notedge         ;Test if edge of byte reached
415         inc hl                  ;Go to next byte
416 _notedge:djnz _iloop
417         pop hl                  ;Restore address
418         ld  bc,12               ;Go to next line
419         add hl,bc
420         pop bc                  ;Restore data
421         djnz _oloop
422         ret
423
424
425
426 _D_HL_DECI:
427          push     bc
428          ld       de,up_data+4
429          ld       b,5
430 ldhld:   call     UNPACK_HL
431          add      a,'0'
432          ld       (de),a
433          dec      de
434          djnz     ldhld
435          ld       hl,up_data
436          ld       b,4
437 lis:     ld       a,(hl)
438          cp       '0'
439          jr       nz,dis
440          ld       (hl),' '
441          inc      hl
442          djnz     lis
443 dis:     ld       hl,up_data
444          call     _puts
445          pop      bc
446          ret
447
448 up_data: .db      "PAD98",0
449
450
451
452 ;------------------------------- sprites --------------------------------------
453
454 spr_ship:
455         .db 7,7
456         .db %11111000
457         .db %11000000
458         .db %11111100
459         .db %11111110
460         .db %11111100
461         .db %11000000
462         .db %11111000
463
464 spr_bullet01:
465         .db 5,3
466         .db %11110000
467         .db %11111000
468         .db %11110000
469
470 spr_bullet02:
471         .db 3,3
472         .db %01000000
473         .db %11100000
474         .db %01000000
475
476 spr_enemy01:
477         .db 6,6
478         .db %00111100
479         .db %01110000
480         .db %11110000
481         .db %11110000
482         .db %01110000
483         .db %00111100
484 spr_enemy02:
485         .db 6,6
486         .db %01111100
487         .db %11110000
488         .db %10111000
489         .db %10111000
490         .db %11110000
491         .db %01111100
492
493 spr_explosion:                               
494         .db 8,6
495         .db %00000000
496         .db %00011100
497         .db %00111110
498         .db %01010110
499         .db %00111000
500         .db %00000000
501
502         .db 8,6
503         .db %00110000
504         .db %01001110
505         .db %10111110
506         .db %01001111
507         .db %00111000
508         .db %00011010
509
510         .db 8,6
511         .db %11110011
512         .db %01001110
513         .db %10110101
514         .db %01000101
515         .db %00111110
516         .db %11011010
517
518         .db 8,6
519         .db %11110010
520         .db %01001110
521         .db %10110101
522         .db %01000101
523         .db %00111110
524         .db %01011010
525
526         .db 8,6
527         .db %01000001
528         .db %00100110
529         .db %00010101
530         .db %01000100
531         .db %00010010
532         .db %10011010
533
534         .db 8,6
535         .db %01000100
536         .db %00100000
537         .db %00000001
538         .db %01000100
539         .db %00100010
540         .db %10001000
541
542         .db 8,6
543         .db %00001000
544         .db %11000010
545         .db %00000000
546         .db %00100000
547         .db %00000001
548         .db %00110000
549
550         .db 8,6
551         .db %00000100
552         .db %00000000
553         .db %01000000
554         .db %00000000
555         .db %00000001
556         .db %00100100
557
558 ;---------------------------- level data -------------------------------------
559 Leveldata:
560         .db $10,$00,$40         ;$time (ff=end)    $type    $y-pos
561         .db $10,$08,$30
562         .db $10,$08,$20
563         .db $40,$00,$10
564         .db $ff,$ff,$ff
565
566 ;---------------------------- texts ------------------------------------------
567
568 title_message:
569          .db      "* * NEMESIS * *",0
570
571 ;---------------------------- save data --------------------------------------
572
573 stored_data_start:
574
575 curevent        .dw Leveldata+1         ;next event
576 nextevent       .db (Leveldata)         ;time to next event
577 score           .dw $0000
578 lives           .dw $0003
579 level           .dw $0000
580 x               .db $16
581 y               .db $46
582 shield          .db $00
583 ybullets        .dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
584 ebuls           .dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
585 enemies         .dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
586                 .dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
587                 .dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
588                 .dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$ffff,$ffff
589 ; 0011 2233 >>  0=occupation (0=no enemy 1=normal 2=exploding)
590 ;               1=frame/ship 2=x 3=y
591
592 boss_status     .db 00
593 boss_pwr          .db 00
594 boss_x            .db 00
595 boss_y            .db 00
596 boss_2bytes       .dw 0000
597
598 timer           .dw $0000
599 your_status     .db $00
600                 .db $00
601 warped_status   .db $00
602
603 variables_end:
604
605 stored_data_end:
606
607
608         .end
609
610
611
612
613 ;NEMESIS'86 by Shiar
614
615
616 ; 0.01.717 -- 17.VII.99 -- size 984
617 ;
618 ;       + movement of ship over whole screen
619 ;       + enemies moving from right to left, appearing right at specified times
620 ;
621 ; 0.1.718  -- 18.VII.99 -- size 907
622 ;
623 ;       * no crash when level restarts for the third time
624 ;       * exit-procedure updated, unnecessary stuff/keychecks removed
625 ;       * alot of unused code removed
626 ;       + different types of enemies (just look different)
627 ;       + collision detection!! enemy ships disappear when you hit them
628
629