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