48f79a6b514064bddd24230a311b9cf8ef1b0305
[nemesis.git] / nemesis.z80
1 ;------------------------------------------------------------------------------
2 ;---------------------- NEMESIS -----------------------------------------------
3 ;------------------------------------------------------------------------------
4 ;       >>> NEMESIS <<<         Version 0.95 BETA       by SHIAR
5 ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 ; Title                         : Nemesis
7 ; Version                       : 0.95
8 ; Release Date                  : 22.X.99
9 ; Filename                      : nemesis.86p (5321)
10 ; Author(s)                     : Shiar
11 ; Email Address                 : shiar0@hotmail.com
12 ; ICQ                           ; #43840958
13 ; Web Page                      : come.to/shiar
14 ; Description                   : cool arcade-shoot-em-up-game (release 12/99)
15 ; Where to get this game        : www.ticalc.org
16 ; Other games by author         : N/A
17
18 ; ABOUT:        This source should only be used for learning practises, do not
19 ;               alter it, and certainly do not distribute an altered version!!
20 ; NOTE:                         &&& marks uncertainties or things to optimize
21
22 ;---------------------- nemesis.z80 start -------------------------------------
23
24 #include        "asm86.h"
25 #include        "ti86asm.inc"   ;standard ti86 romcalls
26 #include        "ti86abs.inc"   ;used to save hiscores and so
27 #include        "ti86un .inc"   ;_dispahl and _shracc
28
29         .org _asm_exec_ram
30
31 #define           cal   call    ;just to make it harder for you to understand
32 #define           psh   push    ; ^:D
33
34 TEXT_MEM        = _textShadow   ;167 bytes ($A7): C0F9-C1A0
35
36 storepos        = $8000         ;120 OF 165
37 storepos2       = $8100         ;141 OF 167
38
39 ;---------------------- in-game vars ------------------------------------------
40
41 temp1           = storepos      ;$C0FA-C0FB     ;temp (2 bytes) bullet
42
43 just_fired      = storepos+2            ; +2    ;counts how long a blast lasts
44 curline         = storepos+2            ; +2    ;used to display SFX
45 menuitem        = storepos+2            ; +2    ;used to store menu location
46 hiscorepos      = storepos+2            ; +2
47 RanPos          = storepos+3            ; +3    ;used for making random values
48 timer           = storepos+4            ; +4    ;frame counter
49                                                 ;--------YOU
50 x               = storepos+5            ; +5    ;your ship's position
51 y               = x+1                   ; +6    ;your y-pos
52 firex           = y+1                   ; +7    ;(1 byte)
53 firey           = firex+1               ; +8    ;(1 byte)
54                                         ; **
55                                                 ;--------LEVEL
56 eventtime       = storepos+10           ;+10    ;enemy frequency
57 eventleft       = eventtime+1           ;+11    ;nr. of enemies still to come
58 nextevent       = eventleft+1           ;+12    ;time to next event
59 pickuptimer     = nextevent+1           ;+13    ;counts when to place a pickup
60 level_enemy     = pickuptimer+1         ;+14            ;enemy type
61 level_move      = level_enemy+1 ;=
62 level_fire      = level_move+1          ;+16
63                                         ; **
64                                                 ;--------OBJECTS
65 spacespace      = storepos+19           ;+19
66 groundinfo      = spacespace+1          ;+20
67 groundpos       = groundinfo+1          ;+21    $10
68 ceilingpos      = groundpos+16          ;+37    $10
69                                         ; ^^    ;--------STARS
70 stars1          = ceilingpos+16         ;+53
71 stars2          = stars1+1              ;+54
72 nrstars1        = 7
73 starx1          = storepos+55           ;+55
74 nrstars2        = 7
75 starx2          = starx1+(nrstars1*2)   ;+69
76                                         ; ^^    ;--------MULTIPLES
77 mx              = starx2+(nrstars2*2)   ;+83    ;position of multiple#1
78 my              = mx+1                  ;+84    ;multiple y-pos
79 m2x             = my+1                  ;+85
80 m2y             = m2x+1                 ;+86
81 your_locpos     = m2y+1                 ;+87    ;position in your_prevpos tabl
82 your_prevpos    = your_locpos+1         ;+88    ;save previous positions (32d)
83
84 ;^-----------------------------------<1 ;-120=$78
85
86 nrenemies       = 10                            ;max. nr of enemies
87 enemies         = storepos2             ; +0    ;info about each enemy (4byt)
88 add2enemy       = nrenemies*4                   ;size of "enemies"
89 enemiesxtra     = enemies+add2enemy     ;+40    ;more info 'bout enemies (4)
90
91 nrybuls         = 10
92 ybullets        = enemiesxtra+add2enemy ;+80    ;60 bytes = 20(state,x,y)
93 nrebuls         = 10
94 ebullets        = ybullets+(nrybuls*3)  ;+110   ;30 bytes = 10(state,x,y)
95
96 ybuls           = ebullets+(nrebuls*3)  ;+140
97
98 ;^-----------------------------------<2 ;-141=$8D
99 ;level_move:
100 ;       %1 (directfire) 1 (ground) 1 (ceiling) 1 (diagfire) 1111 (move)
101 ;enemies:
102 ;       %111111 (HP left) 11 (00=no enemy 01=exploding 10=normal 11=moving)
103 ;       %11111111 (ship type or explosion frame)  %11111111 (x) %11111111 (y)
104 ;enemiesxtra:
105 ;       $11 (move) $11 (fire) $11 (bullettype)
106
107 ;---------------------- introduction ------------------------------------------
108
109          nop                    ;hello yas/ase/rascall/whathever
110          jp init                ;here's the program, but first: a description
111         .dw $0001               ;description type 2 (description + YASicon)
112         .dw Title               ;pointer to description (all shells)
113         .dw Icon                ;pointer to YAS icon
114
115 Title:  .db "Nemesis v0.95 by Shiar",0
116
117 Icon:   .db 8,1                 ;icon for YAS: width = 1byte; height = 9bytes
118         .db %11100000           ; ███
119         .db %01111000           ;  ████
120         .db %00111110           ;   █████
121         .db %01111001           ;  ████  █
122         .db %00111110           ;   █████
123         .db %01111000           ;  ████
124         .db %11100000           ; ███             ;recommend 80x50 screen mode
125         .DB 0   ;clear stupid YAS-line
126
127 ;---------------------- init --------------------------------------------------
128
129 StartFix:
130         im  1
131         ld  hl,$D400
132         ld  de,$D401
133         ld  bc,$0100
134         ld  (hl),$D3
135         ldir
136         ld  hl,int_handler
137         ld  de,$D3D3
138         ld  bc,int_end-int_handler
139         ldir
140         ld  a,$D4
141         ld  i,a
142         im  2
143         ret
144
145 int_handler:
146         ex  af,af'
147         in  a,($03)
148         bit 3,a
149         jp  z,$0039
150         res 0,a
151         out ($03),a
152         jp  $0039
153 int_end:
154
155 init:   cal BUSY_OFF            ;turns the run-indicator off, obviously
156         cal _clrScrn            ;clean the screen
157         xor a                   ;<ld a,0>: reset:
158         ld (iy+13),a            ;don't affect TEXT_MEM and don't scroll screen
159         ld (_asapvar+1),a       ;Asm( thinks it's the first time it runs Nems.
160         cal StartFix
161
162         ld  a,(CONTRAST)        ;load current contrast level
163         cp  $1f                 ;if already at maximum...
164         jr  z,skipdarken        ;...then skip level increase
165         inc a                   ;otherwise increase contrast level
166 skipdarken:
167         out (2),a               ;set it
168
169 ;---------------------- main menu ---------------------------------------------
170
171 LogoPut:
172         xor a                   ;white bitmask (a=0)
173         ld  b,16                ;one line
174         ld  hl,logo_nemesis     ;from...
175         ld  de,VIDEO_MEM+16     ;...to one line from top
176 AboveLogo:
177         ld  (de),a              ;clear/n byte
178         inc de                  ;next
179         djnz AboveLogo          ;repeat for the first line
180
181         ld  bc,16*19            ;logo size
182         ldir                    ;display one line of logo
183
184 ;       ld  hl,GRAPH_MEM        ;cleared line
185 ;       ld  bc,16               ;size=one line
186 ;       ldir                    ;also clear one line below the logo
187
188 ;       ld  a,-1                ;first line is -1+1=0
189 ;       ld  b,21                ;with first 21 lines:
190 ;       cal DoSFX               ;do special effect &&&skip
191
192         ld  hl,VIDEO_MEM+(16*$39)+4     ;$39 rows down, 4 cols right (4*8=$20)
193         ld  b,8                 ;draw 8x one byte = 8*8 = 64 pixels wide
194         ld  a,%11111111         ;horizontal line mask
195 underline:
196         ld  (hl),a              ;draw one piece of the divider-line
197         inc hl                  ;move right (8 pixels = 1 byte)
198         djnz underline          ;repeat
199
200         set 3,(iy+5)            ;set white on black
201         ld  hl,$3320            ;near the bottom of the screen
202         ld  (_penCol),hl
203         ld  hl,txt_about        ;display version and author (yes, that's me!)
204         cal _vputs              ;useful procedure if you want to display somtn
205         res 3,(iy+5)            ;return to default black on white
206
207         ld  hl,$3a1e            ;below previous stuff
208         ld  (_penCol),hl
209         ld  hl,txt_email        ;hey, my e-mail address so SEND ME SOMETHING!!
210         cal _vputs              ;VERY important, so display in small font ?:}
211
212 dispmenu:
213         ld  de,$0304
214         ld  (_curRow),de
215         ld  hl,txt_menu1
216         cal _puts
217         ld  de,$0305
218         ld  (_curRow),de
219         ld  hl,txt_menu2
220         cal _puts
221
222         xor a
223         ld  (menuitem),a
224
225 menuloop:
226         ld  a,(menuitem)
227         ld  h,$01
228         add a,4
229         ld  l,a
230
231         ld  a,5
232         ld  (_curRow),hl
233         cal _putc
234
235         ld  a,(menuitem)
236         ld  h,$01
237         sub 5
238         neg
239         ld  l,a
240
241         ld  a,32
242         ld  (_curRow),hl
243         cal _putc
244
245         halt \ halt \ halt \ halt
246
247         cal GET_KEY             ;wait for keypress
248         cp  K_UP
249         jr  z,menuchange
250         cp  K_DOWN
251         jr  z,menuchange
252         cp  K_EXIT
253         jp  z,game_over_nopop
254         ld  hl,_invert
255         cp  K_F1
256         cal z,undo_invert
257         cp  K_F2
258         cal z,do_invert
259         cp  K_ENTER
260         jr  nz,menuloop
261
262         ld  a,(menuitem)
263         dec a
264         cal z,Story
265         cal New_game            ;prepare level
266         jr  game_main_loop
267
268 menuchange:
269         ld  a,(menuitem)
270         xor 1
271         ld  (menuitem),a
272         jr  menuloop
273
274 do_invert:
275         ld  (hl),$EE
276         ret
277 undo_invert
278         ld  (hl),$E6
279         ret
280
281 ;------------------------------------------------------------------------------
282 ;---------------------- game loop ---------------------------------------------
283 ;------------------------------------------------------------------------------
284
285 game_main_loop:                 ;REPEATS FROM HERE EVERY FRAME
286         ld  hl,timer            ;update time
287         inc (hl)                ;increase by 1
288         ld  b,(hl)              ;new time, save for rand# upd. (no flag change)
289         jr  nz,updaterandom     ;continue when new time <> 0
290         ld  hl,1                ;once every 256 frames, increase score by 1
291         cal scoreInc            ;do it
292
293 updaterandom:
294         ld  hl,RanPos           ;random counter
295         ld  a,r                 ;add r register to randomize
296         add a,(hl)              ;add previous random value
297         add a,b                 ;even more random by adding timer
298         ld  (hl),a              ;save even more random value back
299
300 Clear_screen:
301         ld  hl,GRAPH_MEM        ;move from (hl) = top left
302         ld  (hl),$00            ;first pixel will be copied all over the screen
303         ld  de,GRAPH_MEM+1      ;(de) = next pixel, thus clearing whole screen
304         ld  bc,896              ;loop 896 times = (128/8) * (64-8 for scorebar)
305         ldir                    ;clear!
306
307         ld  a,(timer)
308         and %11
309         jr  z,movestarsdone     ;don't move stars once every 4 frames
310
311         cal movestars1          ;move the stars on the FRONT layer
312         cal movestars2          ;move the distant stars
313
314 movestarsdone:
315         ld  a,(stars1)          ;star positions (the missing byte...)
316         ld  b,nrstars1          ;how many stars? now we know.
317         ld  hl,starx1           ;points to the position of the stars
318         cal DisplayStars        ;display front layer stars
319
320         ld  a,(stars2)          ;weren't you paying attention five lines ago?
321         ld  b,nrstars2          ;that many?! whow!
322         ld  hl,starx2           ;and there they are
323         cal DisplayStars        ;use the same procedure to display back layer
324
325         ld  a,(level_move)      ;level info
326         and %01100000           ;isolate ground&ceiling
327         jr  z,game_stuff        ;both non-present
328         and %00100000           ;bit representing the presence of any ceiling
329         cal nz,Handle_ceiling   ;scroll the ceiling (if any)
330         cal Handle_ground       ;scroll the ground
331
332 game_stuff:
333         ld  a,(your_occ)        ;are you 100% OK?
334         or  a                   ;a=0??
335         jr  nz,_gamestuff1      ;then don't check for movements/fires/...
336
337         ld  a,(level_move)      ;the same level info
338         and %01100000           ;isolate ground&ceiling again
339         jr  z,check_keys        ;no ceiling nor ground
340         and %00100000           ;this bit will tell us if there is a ceiling
341         cal nz,CheckCeiling     ;if there is, check it
342         cal CheckGround         ;check for collision with the ground
343
344 check_keys:
345         cal GET_KEY
346         cp  K_GRAPH
347         cal z,Teacher
348
349         ld  a,%00111111         ;function keys (MORE,EXIT,2ND,F1,F2,F3,F4,F5)
350         out (1),a               ;ask for them
351         nop \ nop               ;delay 8 clocks
352         in  a,(1)               ;get zem!
353
354 check_exitkey:
355         bit 6,a                 ;test bit 6 = exit-key = EXIT
356         jp  z,game_over_nopop   ;<exit> pressed, so be it
357 check_morekey:                  ;another unused label... poor compiler
358         bit 7,a                 ;test bit 7 = more-key = PAUSE
359         cal z,Pause             ;yes, go to pause
360
361 check_firekey:
362         bit 5,a                 ;test bit 5 = 2nd-key = FIRE
363         ld  hl,check_selkey     ;where to continue after executing Fire_bullet
364         psh hl                  ;push hl on stack (instead of cal Fire_bullet)
365         jp  z,Fire_bullet       ;fire smtn (bulletstorplasermultiples+stuff..)
366         pop hl                  ;no cal to Fire_bullet made, so pop stack
367         ld  hl,just_fired       ;no:
368         ld  (hl),0              ;reset just_fired
369
370 check_selkey:
371         ld  a,%01011111         ;look at first column of keys (ALPHA to STO)
372         out (1),a               ;gimme
373         nop \ nop               ;what's taking you so long
374         in  a,(1)               ;at last... our precious keyzzz...
375                                 ;old: <bit 7,a \ cal z,select> now see this:
376         rla                     ;test bit7 so we know f ALPHA has been pressed
377         cal nc,select           ;yeppy, select the currently selected upgrade
378
379         cal Enemies_hit         ;check for collision with enemies
380
381 _gamestuff1:
382         cal Handle_Ship         ;move you
383         cal Handle_bullets      ;move your bullets
384         cal Handle_torp         ;move your torpedo
385
386         cal Handle_enemies      ;move enemies
387         cal Enemy_bullets       ;move enemy bullets
388
389         cal Level_event         ;insert enemies
390         cal Display_Screen      ;display all
391         halt                    ;delay
392
393         jp  game_main_loop      ;LOOP
394
395 ;--------------------------- ground -------------------------------------------
396
397 Handle_ground:
398         ld  a,(timer)
399         and %111                ;once every 8 frames
400         jr  nz,Display_ground   ;otherwise skip the scroll
401         ld  bc,15               ;scroll all 16 bytes minus one (teh new byte)
402         ld  hl,groundpos+1      ;from..
403         ld  de,groundpos        ;to (one byte to the left)
404         ldir                    ;LoaDIncreaseRepeat = scroll!
405
406         ld  a,(groundinfo)      ;what kind of ground
407         dec a                   ;type 1:
408         jr  z,ground_tunnel     ;tunnel effect
409         jr  ground_boring
410
411 ground_tunnel:
412         ld  a,(groundpos+14)
413         ld  (groundpos+15),a
414         ld  hl,spacespace
415
416         ld  a,(RanPos)
417         ld  b,a
418         bit 1,a
419         jr  z,ground_previous
420         bit 2,a
421         jr  z,gtunneldown
422 gtunnelup:
423         ld  a,(hl)
424         or  a
425         jr  z,ground_previous   ;a>=0 (a=0 actually)
426         inc (hl)
427         ld  a,(groundpos+15)
428         inc a
429         jr  newground
430 gtunneldown:
431         ld  a,(groundpos+15)
432         dec a
433         jr  z,ground_previous
434         dec (hl)
435         jr  newground
436
437 ground_previous:
438         ld  a,(groundpos+14)    ;type 1
439         jr  newground
440 ground_boring:
441         ld  a,(groundpos)       ;type 0
442 newground:
443         ld  (groundpos+15),a    ;save new byte on the right
444         ld  a,(hl)
445         cp  -25
446         jr  nc,Display_ground
447         ld  a,b
448         and %1
449         ld  b,0
450         jr  nz,gtunnelup
451
452 Display_ground:
453         ld  b,16                ;screen width
454         ld  de,groundpos-1      ;height of current byte (previous actually)
455         psh de                  ;use later
456         ld  hl,GRAPH_MEM+(56*16)-1 ;screen position
457         psh hl
458
459 groundloopright:
460         ld  c,b                 ;push b for groundloopup
461         pop hl \ inc hl         ;get screen position and go one right
462         pop de \ inc de         ;get height info and set to the next byte
463         psh de \ psh hl         ;save these for the next time
464         ld  a,(de)              ;height of current byte
465         ld  b,a                 ;save in b
466
467         ld  de,16               ;to substract to go one line up
468         ld  a,%11111111         ;bitmask black
469         or  a
470 groundloopup:
471         ld  (hl),a              ;display black byte
472         sbc hl,de               ;go up (sbc must be used for 16-bit sub)
473         djnz groundloopup       ;and loop >groundpos< times
474
475         ld  b,c                 ;pop b used by groundloopup
476         djnz groundloopright    ;loop right for entire screen (16x)
477         pop hl \ pop hl         ;restore stack
478         ret
479
480 CheckGround:                    ;check for collision with the ground
481         ld  a,(x)
482         srl a
483         srl a
484         srl a
485         inc a
486         ld  l,a
487         ld  h,0
488         ld  de,groundpos
489         add hl,de
490         ld  a,(y)
491         sub 57-7
492         neg
493         cp  (hl)
494         ret nc
495         jp  damage_you
496
497 ;--------------------------- ceiling ------------------------------------------
498
499 Handle_ceiling:
500         ld  a,(timer)
501         and %111                ;once every 8 frames
502         jr  nz,Display_ceiling  ;otherwise skip the scroll
503         ld  bc,15               ;scroll all 15 bytes (16th is new position)
504         ld  hl,ceilingpos+1     ;from..
505         ld  de,ceilingpos       ;to (one byte to the left)
506         ld  a,(de)              ;load byte on left (will be lost after scroll)
507         ldir                    ;LoaDIncreaseRepeat = scroll!
508
509         ld  a,(groundinfo)      ;what kind of ceiling
510         dec a                   ;type 1:
511         jr  z,ceiling_tunnel    ;tunnel effect
512         jr  ceiling_boring
513
514 ceiling_tunnel:
515         ld  a,(ceilingpos+14)
516         ld  (ceilingpos+15),a
517         ld  hl,spacespace
518
519         ld  a,(RanPos)
520         ld  b,a
521         bit 4,a
522         jr  z,ceiling_previous
523         bit 5,a
524         jr  z,ctunnelup
525 ctunneldown:
526         ld  a,(hl)
527         or  a
528         jr  z,ceiling_previous
529         inc (hl)
530         ld  a,(ceilingpos+15)
531         inc a
532         jr  newceiling
533 ctunnelup:
534         ld  a,(ceilingpos+15)
535         dec a
536         jr  z,ceiling_previous
537         dec (hl)
538         jr  newceiling
539
540 ceiling_previous:
541         ld  a,(ceilingpos+14)   ;type 1
542         jr  newceiling
543 ceiling_boring:
544         ld  a,(ceilingpos)      ;type 0
545 newceiling:
546         ld  (ceilingpos+15),a   ;save the new byte
547         ld  a,(hl)
548         cp  -25
549         jr  nc,Display_ceiling
550         ld  a,b
551         and %1
552         ld  b,0
553         jr  nz,ctunneldown
554
555 Display_ceiling:
556         ld  b,16                ;screen width
557         ld  de,ceilingpos-1     ;height of current byte
558         psh de                  ;use later
559         ld  hl,GRAPH_MEM-17     ;screen position
560         psh hl
561
562 ceilingloopright:
563         ld  c,b                 ;push b for groundloopup
564         pop hl \ inc hl         ;get screen position and go one right
565         pop de \ inc de         ;get height info and set to the next byte
566         psh de \ psh hl         ;save these for the next time
567         ld  a,(de)              ;height of current byte
568         ld  b,a                 ;save in b
569
570         ld  de,16               ;to substract to go one line up
571         ld  a,%11111111         ;bitmask black
572         or  a
573 ceilingloopdown:
574         ld  (hl),a              ;display black byte
575         add hl,de               ;go down
576         djnz ceilingloopdown    ;and loop >groundpos< times
577
578         ld  b,c                 ;pop b used by groundloopup
579         djnz ceilingloopright   ;loop right for entire screen (16x)
580         pop hl \ pop hl         ;restore stack
581         ret
582
583 CheckCeiling:                   ;check for collision with the ground
584         ld  a,(x)               ;your x
585         srl a                   ;x/2
586         srl a                   ;x/4
587         srl a                   ;x/8 (current ceiling-byte)
588  inc a
589         ld  l,a                 ;hl = a
590         ld  h,0                 ;"
591         ld  de,ceilingpos       ;first ceiling-byte
592         add hl,de               ;current ceiling-byte
593         ld  a,(y)               ;your y-pos
594         inc a
595         cp  (hl)                ;compare with ceiling
596         ret nc                  ;carry if ceiling is above you
597         jp  damage_you          ;otherwise you don't wanna be in that ship
598
599 ;--------------------------- move stars ---------------------------------------
600
601 DisplayStars:                   ;inputs: hl=starx# a=stars# b=nrstars#
602         ld  e,(hl)
603         inc hl
604         ld  d,(hl)
605         ld  (de),a
606         inc hl
607         djnz DisplayStars
608         ret                     ;let's comment this: returns
609
610 movestars2:
611         ld  ix,starx2
612         ld  a,(stars2)
613         rlca
614         ld  (stars2),a
615         ret nc
616         ld  b,nrstars2
617         jr  movestars_loop
618
619 movestars1:
620         ld  ix,starx1
621         ld  a,(timer)
622         rra
623         ld  a,(stars1)
624         ret c
625         rlca
626         ld  (stars1),a
627         ret nc
628         ld  b,nrstars1
629
630 movestars_loop:
631         ld  h,(ix+1)
632         ld  l,(ix)
633         dec hl
634
635         ld  a,l
636         and %00001111
637         cp  9                   ;(GRAPH_MEM&%00001111)-- = $C9FAand15-1 = $A-1
638         jr  nz,newstarok
639         cal Random5016
640
641 newstarok:
642         ld  (ix),l
643         ld  (ix+1),h
644         inc ix \ inc ix
645         djnz movestars_loop
646         ret                     ;for stupid people, here's another comment...
647
648 ;--------------------------- pause --------------------------------------------
649
650 Pause:
651         ld  hl,$0200            ;top left
652         ld  (_curRow),hl
653         ld  hl,txt_pressenter   ;"Enter to continue"
654         cal _puts               ;display message
655 pause:
656         cal _getkey             ;enter low-power mode and wait for key
657         cp  kEnter              ;keypressed = enter?
658         jr  nz,pause            ;no, wait some more
659         ret                     ;continue
660
661 ;--------------------------- teacher ------------------------------------------
662
663 Teacher:
664         ld  (iy+12),5           ;enable flashing cursor
665         cal _clrLCD
666         ld  hl,$0000            ;top left
667         ld  (_curRow),hl
668         ld  hl,txt_teacher
669         cal _puts               ;display message
670
671         ld  hl,TEXT_MEM+15
672         ld  a,(hl)
673         psh af
674         ld  a,(TEXT_MEM+42)
675         psh af
676         ld  a,' '
677         ld  (hl),a
678         ld  (TEXT_MEM+42),a
679
680 teacherloop:
681         cal _getkey             ;enter low-power mode and wait for key
682         cp  kEnter              ;enter pressed?
683         jr  z,teacherans
684         cp  kGrMenu             ;keypressed = graph?
685         jr  nz,teacherloop      ;no, wait some more
686
687         ld  (iy+12),0           ;disable cursor
688         pop af
689         ld  (TEXT_MEM+42),a
690         pop af
691         ld  (TEXT_MEM+15),a
692         cal disp_icons
693         ret                     ;continue
694
695 teacherans:
696         ld  a,' '
697         cal _putc
698
699         ld  hl,$0701
700         ld  (_curRow),hl
701         ld  hl,txt_teacherans
702         cal _puts
703         jr  teacherloop
704
705
706 ;--------------------------- exit ---------------------------------------------
707
708 quit:
709         im  1
710         ld  a,(CONTRAST)        ;load original contrast level
711         out (2),a               ;and set it back
712         ld  (iy+13),3           ;use textshadow (TEXT_MEM) and scrolling
713
714         ld  hl,GRAPH_MEM        ;graph-screen location
715         ld  de,GRAPH_MEM+1
716         ld  (hl),0
717         ld  bc,1024-1           ;do it 1024 times = entire screen
718         ldir
719
720         cal _clrScrn            ;as _clrLCD but also clears TEXT_MEM
721         cal _homeup             ;set cursor to top-left
722         ret                     ;quit Nemesis :(
723
724 ;--------------------------- display ------------------------------------------
725
726 Display_Screen:
727         ld  hl,GRAPH_MEM        ;from storage (top left)
728         ld  de,VIDEO_MEM        ;to screen (top left)
729         ld  c,56                ;display height = 64 bytes (minus 8 for bar)
730 displayloop:
731         ld  b,16                ;display width = 16 bytes (16*8bits=256pixels)
732 displaytloop:
733         ld  a,(hl)              ;copy byte from (hl)
734 _invert:
735         xor $ff                 ;   }   ;invert byte (white<=>black) &&&&
736         ld  (de),a              ;to (de)
737         inc hl \ inc de         ;next byte
738         djnz displaytloop       ;16x hl >> de
739         dec c                   ;next line
740         jr  nz,displayloop      ;loop 64x
741
742         ld  hl,$396b            ;Display Score
743         ld  (_penCol),hl        ;bottom right of screen
744         ld  hl,(score)
745
746 _D_HL_DECI:                     ;------- display 5-digit value -------
747         ld  de,savestr+4        ;savenr saves number string
748         ld  b,5                 ;five digits
749 ldhld:  cal UNPACK_HL           ;one digit of hl
750         add a,'0'               ;make number
751         ld  (de),a              ;save into savenr
752         dec de                  ;point to next digit
753         djnz ldhld              ;repeat for all digits
754
755         ld  hl,savestr          ;we (the program) saved the value righthere
756         cal _vputs              ;the only thing left to do is to display it
757         ret                     ;and we're done again
758
759 savestr:                        ;@here the score will be stored
760         .db "00000",0           ;don't worry, it's just temporary
761
762 ;------------------------- handle ship ----------------------------------------
763
764 Handle_Ship:
765         ld  a,(your_occ)        ;are
766         or  a                   ;you
767         jr  z,ok                ;ok?
768
769         inc a                   ;no! next (explosion)frame
770         ld  (your_occ),a        ;save
771
772         cp  34                  ;last explosion frame?
773         jp  c,exploding_you     ;not yet: display explosion
774         cp  40                  ;delay finished?
775         jp  z,You_die           ;yes = game over
776         ret                     ;don't display anything
777
778 ok:                             ;we are
779         ld  a,%01111110         ;get arrow keys
780         out (1),a               ;it's cold outside
781         ld  hl,y                ;instead of nop\nop do something usefull
782         in  a,(1)               ;come back in
783
784         ld  b,a                 ;psh a (keys)
785         xor %11111111           ;inverted a = 0 if arrow-key has been pressed
786         ld  a,(your_multiples)
787         jr  z,no_adv            ;if so, leave the multiples where they are
788         or  %100                ;set move bit
789         jr  adv_ok
790 no_adv: and %11111011           ;reset move bit
791
792 adv_ok: ld  (your_multiples),a
793         ld  a,b                 ;pop a (keys)
794
795         rra                     ;rotate right (put last bit in c)
796         ld  b,a                 ;we need a later
797
798         jr  c,no_down
799         ld  a,(hl)
800         cp  49                  ;55-6 = bottom of screen
801         jr  z,no_down
802         inc a
803         ld  (hl),a
804 no_down:
805         dec hl
806         rr  b                   ;because we now use b, it's rr instead of rra
807         jr  c,no_left
808         ld  a,(hl)
809         sub 1                   ;<dec a> doesn't affect c-flag
810         jr  c,no_left           ;-1 = left side
811         ld  (hl),a
812 no_left:
813         rr  b
814         jr  c,no_right
815         ld  a,(hl)
816         cp  121                 ;127-6 = right side
817         jr  z,no_right
818         inc a
819         ld  (hl),a
820 no_right:
821         ld  d,(hl)
822         inc hl
823         rr  b
824         jr  c,no_up
825         ld  a,(hl)
826         sub 1                   ;<dec a> doesn't affect carry-flag
827         jr  c,no_up             ;-1 = top of screen
828         ld  (hl),a              ;save new y
829
830 no_up:  ld  e,(hl)
831         ld  ix,spr_ship01       ;ship sprite
832         ld  hl,your_inv         ;invulnerable?
833         ld  a,(hl)              ;load time in a
834         or  a                   ;is it 0?
835         jr  z,handle_multiples  ;yes so ship = normal (display \ continue)
836
837         ld  a,(timer)           ;load frame nr.
838         and %00000111           ;a=0 once every four frames
839         jr  nz,not_time         ;a<>0 = not time to update counter
840         dec (hl)                ;decrease inv-time left
841 not_time:
842         and %00000100           ;a switches 0<->1 every 2 frames
843         jr  z,handle_multiples  ;show normal ship
844 inv_flicker:
845         ld  ix,spr_ship01i      ;don't display ship
846
847 handle_multiples:
848         cal putsprite           ;display your ship
849
850         ld  a,(your_multiples)  ;do you have multiples
851         ld  b,a                 ;save a for 2nd check
852         and %11                 ;no? (last two bits = nr of multiples)
853         ret z                   ;then don't handle them either
854
855         ld  hl,y
856         ld  a,b                 ;restore a (your_multiples)
857         and %100                ;move the multiples???
858         jr  z,mult_adv          ;nope, just let them (saves (y) in y, (x) in x)
859
860         ld  hl,your_locpos      ;location to save this position
861         ld  a,(hl)              ;load a
862         inc a                   ;a=a+1
863         and %00001111           ;if a>15 then a=a-16
864         ld  (hl),a              ;save new a
865         add a,a                 ;a=a*2
866         ld  c,a                 ;bc=2a
867         ld  b,0
868
869         ld  hl,your_prevpos     ;previous positions
870         add hl,bc               ;16 turns ago
871         ld  d,(hl)              ;old x-pos
872         inc hl                  ;and
873         ld  e,(hl)              ;old y-pos
874         ld  (mx),de             ;save multiple position in (mx)
875
876         ld  a,(y)               ;load new y-pos
877         ld  (hl),a              ;save it for 16 turns in the future
878         dec hl                  ;and
879         ld  a,(x)               ;load new x-pos
880         ld  (hl),a              ;save that too
881
882 mult_adv:
883  ld de,(mx)
884         ld  ix,spr_multiple     ;sprite of the multiple
885         jp  putsprite           ;display it + <ret>
886
887 exploding_you:
888         srl a                   ;half the framerate
889         dec a                   ;first frame is 1>inc>srl>dec = 0
890         ld  hl,x-1
891
892 explosion_stuff:
893         rra
894         add a,a
895         add a,a
896         add a,a
897         ld  c,a
898         ld  b,0
899         ld  ix,spr_explosion
900         add ix,bc
901         inc hl
902         ld  d,(hl)
903         inc hl
904         ld  e,(hl)
905         jp  putsprite
906
907 damage_you:
908         ld  a,(your_inv)        ;invulnerability left?
909         or  a
910         ret nz                  ;return if inv>0
911         ld  hl,your_armor       ;armor left
912         ld  a,(hl)              ;check
913         dec a                   ;is it 0?
914         jp  m,no_armor          ;yes, 0hp left so explode
915         ld  (hl),a              ;no, so save decreased hp
916         cal disp_armor          ;and display new value
917
918         ld  a,(your_pickup)     ;how many pickups do you have?
919         dec a                   ;is the armor-icon selected
920         ret nz                  ;return if not
921         psh hl
922         ld  hl,VIDEO_MEM+(16*56)
923         ld  (PutWhere),hl
924         ld  ix,spr_icon         ;if so, highlight armorIcon again
925         ld  de,$1901            ;position
926         cal putwidesprite       ;display icon
927         ld  hl,GRAPH_MEM
928         ld  (PutWhere),hl
929         pop hl
930         ret                     ;and return
931 no_armor:
932         ld  a,%01               ;occ %xxxxxx01 = explode
933         ld  (your_occ),a        ;set to explode
934         ret
935
936 ;------------------------- place multiples ------------------------------------
937
938 Place_multiples:
939         ld  (mx),de             ;set last multiple-position
940         ld  hl,your_prevpos     ;place all previous positions
941         ld  b,16                ;all 16 of them
942 place_multiples:
943         ld  (hl),d              ;set prev-x to d
944         inc hl                  ;next
945         ld  (hl),e              ;set prev-y to e
946         inc hl                  ;next
947         djnz place_multiples    ;repeat
948         ret
949
950 ;------------------------- select upgrade -------------------------------------
951
952 select:
953         ld  hl,your_pickup      ;select pickups
954         ld  a,(hl)              ;load pickups taken so far
955         dec a                   ;is it 1?
956         jr  nz,select2          ;no, carry on
957         ld  (hl),a              ;reset pickups (a=0)
958         ld  hl,your_armor       ;change armor
959         inc (hl)                ;increase HPs by one
960         jp  disp_icons          ;display and return
961 select2:
962         dec a                   ;is it 2?
963         jr  nz,select3          ;no, carry on
964         ld  (hl),a              ;reset pickups
965         inc a                   ;a=1
966         ld  (torp_occ),a        ;ready torpedoes
967         jp  disp_icons          ;display 'n return
968 select3:
969         dec a                   ;is it 3?
970         jr  nz,select4          ;no, carry on
971         ld  (hl),a              ;reset pickups
972         ld  hl,your_weapon
973         ld  a,(hl)
974         inc a
975         cp  10
976         jp  nc,disp_icons       ;>=10
977         ld  (hl),a
978
979         add a,a                 ;weap*2
980         add a,a                 ;    *4
981         add a,a                 ;    *8
982         ld  c,a
983         ld  b,0
984         ld  hl,weapons-7
985         add hl,bc
986         ld  a,(hl)
987         ld  (ybuls),a
988
989         jp  disp_icons          ;display n return
990 select4:
991         dec a                   ;is it 4?
992         jr  nz,select5          ;no, carry on again
993         ld  (hl),a              ;reset pickups
994         inc a                   ;a=1
995         ld  (your_weapon),a     ;ready laser
996         jp  disp_icons          ;display + return
997 select5:
998         dec a                   ;is it 5?
999         jr  nz,select6          ;no, carry on once more
1000         ld  (hl),a              ;reset pickups
1001         inc a
1002         ld  (your_multiples),a
1003         ld  de,(x)
1004         cal Place_multiples
1005         jp  disp_icons          ;display, return
1006 select6:
1007         ld  (hl),0              ;reset pickups
1008         jp  disp_icons          ;display/return
1009
1010 ;------------------------- fire bullet ----------------------------------------
1011
1012 Fire_bullet:
1013         ld  hl,RanPos           ;random
1014         inc (hl)                ;update random counter
1015
1016         ld  hl,just_fired
1017         ld  a,(hl)              ;just_fired
1018         cp  5                   ;already pressed?
1019         ret z                   ;return when already pressed (=5)
1020         inc (hl)                ;otherwise increase counter (0 to 4 >> 1 to 5)
1021         ld  a,(your_weapon)     ;if you have bullets.....
1022         dec a                   ;(1=laser)
1023         jr  z,fireOK
1024         ld  (hl),5              ;.....then can't fire next turn (go to 5 imm.)
1025
1026 fireOK:
1027         ld  hl,(x)              ;yes: first fire from ship position (x)
1028         ld  (firex),hl          ;set firepos
1029         ld  a,(your_multiples)  ;any multiples?
1030         and %11                 ;nope?
1031         jr  z,fireany           ;then just fire somethin'
1032         cal fireany             ;and blast
1033         ld  hl,(my)             ;then, fire from multiple position (mx)
1034         ld  a,(mx)              ;<ex h,l>
1035         ld  h,a                 ; ^^^^^^
1036         ld  (firex),hl          ;set firepos
1037                                 ;blast again and <ret>
1038 fireany:
1039         cal fire_torp           ;&&&
1040
1041         ld  a,(your_weapon)     ;do you have laser?
1042         dec a                   ;1=yes
1043         jr  z,fire_laser
1044
1045         ld  ix,weapons-6
1046         add a,a                 ;weap*2
1047         add a,a                 ;    *4
1048         add a,a                 ;    *8
1049         ld  c,a
1050         ld  b,0
1051         add ix,bc
1052
1053         ld  c,(ix)
1054         cal fire_ybullet
1055         inc ix
1056         inc ix
1057         ld  c,(ix)
1058         xor a
1059         cp  c
1060         cal nz,fire_ybullet
1061         inc ix
1062         inc ix
1063         ld  c,(ix)
1064         xor a
1065         cp  c
1066         jr  nz,fire_ybullet
1067         ret
1068
1069 fire_torp:
1070         ld  de,(firex)
1071         ld  hl,torp_occ         ;torpedo...
1072         ld  a,(hl)              ;load torpInfo
1073         dec a                   ;do you have (unused) torpedoes?
1074         ret nz                  ;nope (a must be 1)
1075         ld  (hl),2              ;yes; use torpedo
1076         ld  (torp_pos),de       ;save torpedo position (in de)
1077         ret
1078
1079
1080 fire_laser:                     ;yes, fire that laser instead
1081         ld  a,(firex)           ;a = your x-pos
1082         ld  d,a
1083
1084         ld  hl,GRAPH_MEM        ;save-location
1085         ld  a,(firey)           ;y-coord
1086         add a,3                 ;at middle of your ship (y+3)
1087         ld  e,a                 ;save laser-y in e
1088         add a,a                 ;y*2
1089         add a,a                 ;y*4
1090         add a,a                 ;y*8
1091         rl  b                   ;b (=0) =b*2+overflow (if y>32 then bc=bc+256)
1092         add a,a                 ;y*16 (width of screen)
1093         rl  b                   ;b=b*2+overflow (if y>64 then bc=bc+512)
1094         inc a                   ;8 pixels to right (a=even so no overflow)
1095
1096         srl d                   ;X/2
1097         srl d                   ;X/4
1098         srl d                   ;X/8
1099         add a,d                 ;a = (Y*16+X/8) mod 256 (c set on overflow)
1100         jr  nc,_nolc            ;jump if no carry = no overflow = a<=255
1101         inc b                   ;a>255 so increase bc by 256
1102 _nolc:  ld  c,a                 ;c = (Y*16+X/8) mod 256
1103         add hl,bc               ;bc = Y*16+X/8
1104
1105         ld  a,15                ;128/8=16=screen width ** minus one (inc a ^^)
1106         sub d                   ;minus x-start (d=X/8)
1107         ld  b,a
1108 drawlaser:
1109         ld  (hl),%11111111
1110         inc hl                  ;Go to next byte
1111         djnz drawlaser
1112
1113         ld  a,(just_fired)      ;fired for how long
1114         cp  4                   ;if 4th turn
1115         ret nz                  ;then do damage, otherwise quit
1116
1117 handle_laser:
1118         ld  a,(firex)
1119         ld  d,a                 ;d was divided, so reload the laser-x
1120
1121 check_laserhits:                ;de = (x,y)
1122         ld  b,nrenemies
1123         ld  hl,enemies
1124
1125 laserhits:                      ;Hits with normal enemies
1126         psh hl
1127
1128         ld  a,(hl)
1129         and %00000010
1130         jr  z,nolashit          ;no hit when enemy_occ <> 2/3
1131
1132         inc hl                  ;enemy type
1133         ld  a,(hl)
1134         or  a                   ;enemy #0 = pickup
1135         jr  z,nolashit          ;yes: don't destroy
1136
1137         inc hl
1138         ld  a,(hl)              ;check x
1139         sub d
1140         jp  m,nolashit          ;no hit when enemy is left of you
1141
1142         inc hl
1143         ld  a,(hl)              ;check y
1144         sub e
1145         jr  z,enemy_lashit      ;a-e=0 = laser on top line of enemy = hit
1146         jr  nc,nolashit         ;a-e>0 = enemy above laser = no hit
1147         add a,5                 ;add enemy height
1148         jp  p,enemy_lashit      ;a-e>0 = hit
1149
1150 nolashit:
1151         pop hl
1152         inc hl                  ;go to next enemy
1153         inc hl
1154         inc hl
1155         inc hl
1156         djnz laserhits          ;check all enemies
1157         ret
1158
1159 enemy_lashit:
1160         cal enemy_hit
1161         jr  nolashit
1162
1163 fire_ybullet:
1164         ld  hl,ybullets
1165         ld  de,3
1166         ld  a,(ybuls)
1167         ld  b,a
1168 find_ybullet:
1169         ld  a,(hl)
1170         or  a
1171         jr  z,found_ybullet     ;0 = no bullet here
1172         add hl,de
1173         djnz find_ybullet       ;look next bullet
1174         ret
1175
1176 found_ybullet:
1177         ld  (hl),c              ;use the bullet and set correct bullet-type
1178         ld  a,(firex)           ;your x-pos
1179         add a,5                 ;place bullet in front of you
1180         inc hl                  ;go to bullet-x
1181         ld  (hl),a              ;set x
1182
1183         ld  a,(firey)           ;your y-pos
1184         add a,(ix+1)            ;place bullet at the middle of your ship
1185         inc hl                  ;go to bullet-y
1186         ld  (hl),a              ;set y
1187         ret
1188
1189 ;------------------------ handle bullets --------------------------------------
1190
1191 bullet_left:
1192         ld  a,125
1193         sub b
1194
1195         cp  (hl)                ;off screen? (x>128-5)
1196         jr  c,remove_bullet
1197         ld  a,(hl)              ;a = X
1198         add a,b                 ;move 2 2 the right
1199         ld  (hl),a              ;save new pos.
1200         ld  d,a                 ;d = X
1201
1202         inc hl                  ;to y-pos
1203         ld  a,c
1204         cal _shracc
1205         dec a
1206         jr  z,bullet_noymove
1207         dec a
1208         jr  z,bullet_up
1209         dec a
1210         jr  z,bullet_halfup
1211         dec a
1212         jr  z,bullet_down
1213
1214 bullet_halfdown:
1215         ld  a,(timer)
1216         and 1
1217         jr  z,bullet_noymove
1218 bullet_down:
1219         ld  a,(hl)
1220         inc a
1221         cp  55
1222         jr  z,bullet_noymove
1223         ld  (hl),a
1224 bullet_halfup:
1225         ld  a,(timer)
1226         and 1
1227         jr  z,bullet_noymove
1228 bullet_up:
1229         ld  a,(hl)
1230         dec a
1231         jr  z,bullet_noymove
1232         ld  (hl),a
1233 bullet_noymove:
1234         ld  e,(hl)              ;e = Y
1235         ret
1236
1237 remove_bullet:
1238         dec hl
1239         ld  (hl),0              ;dump this bullet!
1240         pop hl ;&&&
1241         jr  next_ybullet
1242
1243 Handle_bullets: ;&&&>>
1244         ld  hl,ybullets
1245         ld  a,(ybuls)
1246         ld  b,a
1247 scan_bullets:
1248         psh bc
1249         psh hl
1250         ld  (temp1),hl          ;needed for check_bullethits
1251         ld  a,(hl)
1252         inc hl
1253
1254         or  a
1255         jp  z,next_ybullet      ;bulletType=0 >> no bullet
1256
1257         ld  c,a
1258         and %1111
1259         ld  b,a
1260         cal bullet_left         ;move bullet left
1261
1262 display_bullet:
1263         ld  ix,spr_bullet01
1264         psh de
1265         cal putsprite           ;display bullet
1266         pop de
1267
1268         cal check_bullethits
1269
1270 next_ybullet:
1271         pop hl
1272         pop bc
1273         inc hl
1274         inc hl
1275         inc hl
1276         djnz scan_bullets       ;next bullet (loop)
1277         ret
1278
1279 ;--------------------------- check bullethits --------------------------------
1280
1281 check_bullethits:               ;INPUT: de=X,Y; (temp1)=bullet
1282         ld  b,nrenemies
1283         ld  hl,enemies
1284
1285 hit_enemies:                    ;Hits with normal enemies
1286         psh hl
1287
1288         ld  a,(hl)
1289         and %00000010
1290         jr  z,nohit             ;no hit when enemy_occ <> 2/3
1291
1292         inc hl                  ;enemy type
1293         ld  a,(hl)
1294         or  a                   ;enemy #0 = pickup
1295         jr  z,nohit             ;yes: don't destroy
1296
1297         psh de
1298         cal find_sprite
1299         pop de
1300
1301         inc hl
1302         ld  a,(hl)              ;check x
1303         sub d
1304         sub 5
1305         jp  p,nohit
1306         add a,5
1307         add a,(ix)
1308         jp  m,nohit
1309
1310         inc hl
1311         ld  a,(hl)              ;check y
1312         sub e
1313         sub 3
1314         jp  p,nohit
1315         add a,3
1316         add a,(ix+1)
1317         jp  m,nohit
1318
1319         psh hl
1320         ld  hl,(temp1)
1321         ld  (hl),$00            ;remove bullet
1322         pop hl
1323
1324         cal enemy_hit
1325
1326 nohit:
1327         pop hl
1328         inc hl
1329         inc hl
1330         inc hl
1331         inc hl
1332         djnz hit_enemies        ;check next enemy
1333         ret
1334
1335 enemy_hit:
1336         dec hl
1337         dec hl
1338         dec hl
1339         ld  a,(hl)              ;occ
1340         ld  c,a                 ;psh occ
1341         and %11111100           ;occ/4 = HP left        ;<srl a\srl a
1342         jr  nz,hpleft           ;not zero -> jump
1343         ld  (hl),%01            ;set to explode
1344
1345         ld  a,(pickuptimer)     ;counts enemies destroyed
1346         dec a                   ;enough destroyed for a pickup?
1347         jr  nz,pickupdone       ;otherwise just explode
1348         ld  (hl),%00000110      ;change it into a pickup (with 2 HP)
1349         ld  a,18                ;reset enemies counter (18 hits = next)
1350 pickupdone:
1351         ld  (pickuptimer),a     ;save new enemiescounter value
1352         inc hl
1353         ld  (hl),$00            ;explosionFrame 0
1354
1355         ld  hl,1                ;increase score by one
1356         cal scoreInc
1357         ret
1358
1359 hpleft:
1360         ld  a,c                 ;pop occ
1361         sub %00000100           ;decrease HP by one
1362         ld  (hl),a              ;save
1363         ret
1364
1365 ;--------------------------- handle torpedo ----------------------------------
1366
1367 Handle_torp:
1368         ld  a,(torp_occ)
1369         sub 2
1370         ret m                   ;return if occ=0/1
1371
1372         ld  hl,torp_pos         ;x-position
1373         ld  a,(hl)              ;load in a
1374         inc a                   ;move right
1375         cp  125                 ;right edge reached
1376         jr  nc,remove_torp      ;remove if x>125
1377         ld  (hl),a              ;save new x
1378         ld  d,a
1379
1380         inc hl                  ;y-position
1381         ld  a,(hl)
1382         inc a                   ;move down
1383         cp  56                  ;bottom reached
1384         jr  nc,remove_torp      ;remove if y>40
1385         ld  (hl),a              ;save new y
1386         ld  e,a
1387
1388         ld  ix,spr_bullett1
1389         psh de
1390         cal putsprite           ;display torpedo
1391         pop de
1392         jp  check_bullethits    ;check for hits with enemies
1393
1394 remove_torp:
1395         ld  a,1
1396         ld  (torp_occ),a
1397         ret
1398
1399 ;--------------------------- level events -------------------------------------
1400
1401 Level_event:
1402         ld  hl,nextevent        ;time to next event     <ld  a,(nextevent)
1403         dec (hl)                ;decrease counter       <dec a
1404         ld  a,(hl)              ;look at counter        <ld  (nextevent),a
1405         or  a                   ;has it reached zero?
1406         ret nz                  ;nope: get outta here!
1407
1408         ld  a,(eventtime)       ;enemy frequency (lvl)
1409         ld  (nextevent),a       ;set time to next event
1410         ld  hl,eventleft
1411         dec (hl)                ;update enemy-counter
1412
1413         ld  a,(hl)              ;look at counter
1414         or  a                   ;has it reached 0?
1415         jp  z,Next_level        ;yes: level finished
1416         dec a                   ;has it reached 1?
1417         jr  z,standby_event     ;yes: wait until no enemies present/left
1418         dec a                   ;has it reached 2?
1419         jr  z,place_boss        ;yep: place the BigBossTM!
1420         dec a                   ;has it reached 3?
1421         jr  nz,do_event         ;nope: >3 = place an enemy
1422         inc hl                  ;nextevent located behind eventleft
1423         ld  (hl),123            ;set delay
1424         ret                     ;don't place any more enemies
1425
1426 place_boss: ;&&&
1427         ld  hl,(levelp)
1428         dec hl
1429         ld  a,(hl)
1430         ld  (level_enemy),a     ;set new enemy (boss)
1431         dec hl
1432         ld  a,(hl)
1433         ld  (level_move),a      ;set boss movement (very slow)
1434         dec hl
1435         ld  a,(hl)
1436         ld  (level_fire),a      ;set rapid fire
1437         cal do_event
1438         ret
1439
1440 standby_event:
1441         ld  b,nrenemies
1442         ld  de,enemies-4
1443 chk_enemyleft:
1444         inc de
1445         inc de
1446         inc de
1447         inc de
1448         ld  a,(de)
1449         or  a                   ;0 = no enemy present
1450         jr  nz,enemyleft
1451         djnz chk_enemyleft
1452         ret
1453 enemyleft:
1454         inc (hl)
1455         ret
1456
1457
1458 do_event:
1459         ld  de,enemies-4
1460 chk_noenemy:
1461         inc de
1462         inc de
1463         inc de
1464         inc de
1465         ld  a,(de)
1466         or  a                   ;0 = no enemy present
1467         jr  nz,chk_noenemy
1468
1469 place_enemy:
1470         ld  a,(level_enemy)     ;enemy type to place (lvl)
1471         ld  hl,enemy00          ;enemy 1 specs
1472         add a,a                 ;a=type*2
1473         add a,a                 ;a=type*4
1474         ld  c,a                 ;c=type
1475         ld  b,0                 ;bc = enemy nr.
1476         add hl,bc               ;hl = enemy specs
1477         ld  a,(hl)              ;load hitpoints+occ of this enemy class
1478         ld  (de),a              ;occ
1479
1480         inc hl                  ;next enemyInfo byte
1481         inc de                  ;next byte of current enemy
1482         ld  a,(hl)              ;load enemy class (nr)
1483         ld  (de),a              ;enemy type
1484
1485         inc de                  ;set x-pos
1486         psh de
1487         cal find_sprite
1488         pop de
1489         ld  a,128               ;appear at right edge of screen
1490         sub (ix)                ;minus the width of this enemy (not offscreen)
1491         ld  (de),a              ;= x-position
1492
1493         inc de                  ;set y-pos
1494         inc hl                  ;where to place??
1495         ld  a,(hl)              ;load placeInfo
1496         dec a                   ;is it 1?
1497         jr  z,random_enemy      ;yes: create random value <51 in a
1498         dec a                   ;is it 2?
1499         jr  z,lure_enemy        ;yes: create a 100% luring enemy
1500                                 ;otherwise?
1501 halflure_enemy:                 ;yes (of course it is): pick one (50% lure)
1502         ld  a,(timer)           ;look at frame-number
1503         and %00000001           ;make random if odd frame nr.
1504         jr  nz,random_enemy     ;1st possibility: random enemy
1505 lure_enemy:                     ;2nd possibility: luring enemy
1506         ld  a,(y)               ;place at same y-pos as YOUR ship
1507         jr  ypos_OK
1508
1509 random_enemy:
1510         ld  b,e                 ;b will be added to random-value
1511         cal Random50            ;make a (in a) random value 0-51
1512
1513 ypos_OK:                        ;random value successfully created
1514         ld  (de),a              ;save y-position
1515
1516         ld  hl,add2enemy-3      ;offset to xtra enemy info
1517         add hl,de               ;hl points to <xtra info: move>
1518         ld  (hl),1              ;set move-counter to 1
1519         inc hl                  ;hl to <xtra info: fire>
1520
1521         ld  a,(level_move)
1522         and %00010000
1523         jr  z,ffiredelayed
1524         ld  a,1                 ;set time-to-fire to 1 frame (fires directly)
1525         jr  ffireOK
1526 ffiredelayed:
1527         ld  a,(level_fire)      ;set "ttf" to normal nr of frames
1528 ffireOK:
1529         ld  (hl),a
1530         inc hl                  ;hl to <xtra info: bullettype>
1531         ld  (hl),1              ;type 1
1532         inc hl                  ;hl to <xtra info: bullettype>
1533         ld  a,(RanPos)
1534         and %01111111
1535         ld  (hl),a              ;type 1
1536         ret                     ;return
1537
1538 ;--------------------------- enemy fires --------------------------------------
1539
1540 Enemy_fires:                    ;de = x,y
1541         dec d
1542         dec d                   ;d = x-2
1543         inc e                   ;e = y+1
1544
1545         ld  b,nrebuls
1546         ld  hl,ebullets
1547 find_ebullet:
1548         ld  a,(hl)
1549         or  a
1550         jr  z,found_ebullet     ;0 = not used
1551         inc hl \ inc hl \ inc hl
1552         djnz find_ebullet       ;look next bullet
1553         ret
1554
1555 found_ebullet:
1556         ld  b,%1100
1557         ld  a,(level_move)
1558         and %10000000
1559         jr  z,bulletok
1560
1561         ld  a,(y)
1562         sub e
1563         add a,10
1564         jp  p,bulletnotup
1565         ld  b,%1011             ;yourY-bulY = negative (=bullet below you)
1566         add a,10
1567         jp  p,bulletnotup
1568         ld  b,%1001             ;yourY-bulY = even more negative (going up)
1569
1570 bulletnotup:
1571         sub 20
1572         jp  m,bulletok
1573         ld  b,%1010             ;bullet going down
1574         sub 10
1575         jp  m,bulletok          ;even more going down
1576         ld  b,%1000
1577
1578 bulletok:
1579 ;       ld  a,c                 ;load bullet type
1580 ;       add a,a                 ;type*2                 %..Btype.
1581 ;       add a,a                 ;type*4                 %.Btype..
1582 ;       add a,a                 ;type*8                 %Btype...
1583                                 ;add bullet direction   %BtypeDir
1584         ld  (hl),b              ;set bullet direction
1585         inc hl
1586         ld  (hl),d              ;set x-pos
1587         inc hl
1588         ld  (hl),e              ;set y-pos
1589         ret
1590
1591 ;----------------------------- enemy bullets ----------------------------------
1592
1593 Enemy_bullets:
1594         ld  hl,ebullets
1595         ld  b,nrebuls
1596 handle_bullet:
1597         psh bc
1598         psh hl
1599         ld  a,(hl)              ;load bulletType in a
1600         or  a                   ;is it 0?
1601         jr  nz,enemy_bullet     ;no: handle bullet
1602 next_bullet:
1603         pop hl                  ;do not move the <pop hl>
1604         pop bc
1605         inc hl \ inc hl \ inc hl
1606         djnz handle_bullet
1607         ret
1608
1609 enemy_bullet:
1610         ld  b,a                 ;save type
1611         inc hl                  ;bullet x
1612         ld  a,(hl)              ;check if it has reached the left side of scrn
1613         and %11111110           ;it is <2 (0 or 1)?
1614         jr  z,remove_ebullet    ;yes, remove bullet
1615         dec (hl)                ;move one left
1616         dec (hl)                ;and another one
1617         ld  d,(hl)              ;d=x
1618         inc hl                  ;@y
1619
1620         ld  a,b                 ;restore type
1621         cp %1100                ;&&& use <bit ?,a>
1622         jr  z,ebullet_common    ;type %1100: normal bullet
1623         and %111
1624         jr  z,ebullet_down      ;type %1000: moving down
1625         dec a
1626         jr  z,ebullet_up        ;type %1001: moving up
1627         ld  b,a
1628
1629         ld  a,(timer)
1630         rra
1631         jr  c,ebullet_common
1632
1633         ld  a,b
1634         dec a
1635         jr  z,ebullet_down      ;type %1010: moving down 50%
1636                                 ;type %1011: moving up 50%
1637 ebullet_up:
1638         ld  a,(hl)
1639         dec a
1640         jp  m,ebullet_common
1641         ld  (hl),a
1642         jr  ebullet_common
1643
1644 ebullet_down:
1645         ld  a,(hl)
1646         inc a
1647         cp  55
1648         jr  z,ebullet_common
1649         ld  (hl),a
1650
1651 ebullet_common:
1652         ld  e,(hl)              ;e=y
1653         ld  ix,spr_bullete1     ;display enemy bullet
1654         cal putsprite
1655
1656 ebullet_hits:
1657         ld  a,(your_occ)
1658         or  a
1659         jr  nz,next_bullet      ;0 = you're normal
1660
1661         pop hl
1662         psh hl
1663         inc hl                  ;check x
1664         ld  a,(x)
1665         sub (hl)
1666         add a,6
1667         jp  m,next_bullet
1668         cp  9
1669         jr  nc,next_bullet
1670
1671         inc hl                  ;check y
1672         ld  a,(y)
1673         sub (hl)
1674         add a,6
1675         jp  m,next_bullet
1676         cp  9
1677         jr  nc,next_bullet
1678
1679         cal damage_you          ;HIT!!
1680 remove_ebullet:
1681         pop hl                  ;hl could be destroyed by damage_you
1682         ld  (hl),0              ;bullet > unused
1683         jr  next_bullet+1       ;next bullet (SKIP THE <POP HL> = one byte)
1684
1685 ;--------------------------- handle enemies -----------------------------------
1686
1687 Handle_enemies:
1688         ld  hl,enemies
1689         ld  b,nrenemies         ;handle all enemies
1690
1691 handle_enemy:
1692         psh bc
1693         psh hl
1694
1695         ld  a,(hl)
1696         and %00000011
1697         jr  z,next_enemy        ;occ "no enemy" 0
1698         dec a
1699         jr  z,exploding_enemy   ;occ "exploding" 1
1700         ld  b,a                 ;b=2 if moving, otherwise b=1
1701
1702 normal_enemy:                   ;occ "normal" 2 or "moving" 3
1703         inc hl
1704         ld  c,(hl)              ;c = enemy type = de
1705         cal find_sprite
1706
1707         inc hl
1708         ld  a,(hl)              ;x
1709         dec a                   ;move left
1710         jr  c,remove_enemy      ;off screen
1711         jr  z,remove_enemy      ;"
1712         ld  d,a
1713
1714         inc hl
1715         ld  e,(hl)              ;y
1716         ld  a,b                 ;moving state was stored in b earlier
1717         dec a                   ;is it 1?
1718         cal nz,moving_enemy     ;2 = moving enemy
1719
1720         ld  (hl),e
1721         dec hl                  ;@x
1722         ld  (hl),d              ;store new x
1723         ld  a,c                 ;a = enemy type
1724         or  a                   ;type 0? (pickup)
1725         jr  nz,check_enemyfire  ;no, a normal enemy; let em fire
1726         ld  a,(timer)           ;load time
1727         and %1                  ;move left once every 2 turns
1728         jr  z,firing_done       ;don't move now
1729         inc d                   ;increase x-position (don't move this turn)
1730         inc (hl)                ;and save it
1731         jr  firing_done         ;continue
1732
1733 check_enemyfire:
1734         ld  bc,add2enemy+1-2    ;offset of <xtra enemy info: fire>
1735         add hl,bc               ;go there (@hl)
1736         dec (hl)                ;decrease counter till next blast
1737         ld  a,(hl)              ;load new counter
1738         or  a                   ;has it reached zero?
1739         jr  nz,firing_done      ;finished if not
1740
1741         ld  a,(level_fire)      ;re-set counter for next blast
1742         ld  (hl),a              ;save time to fire
1743         inc hl                  ;next byte = bullettype
1744         ld  c,(hl)              ;c = bullet type
1745         psh de                  ;save registers for firing-use
1746         cal Enemy_fires         ;fires bullet
1747         pop de                  ;restore (destroyed by Enemy_fires)
1748 firing_done:
1749         cal putwidesprite               ;display sprite @ix
1750
1751 next_enemy:
1752         pop hl
1753         ld  bc,$0004
1754         add hl,bc
1755         pop bc
1756         djnz handle_enemy
1757         ret
1758
1759 remove_enemy:
1760         pop hl
1761         ld  (hl),$0000          ;bye bye enemy
1762         psh hl
1763         jr  next_enemy
1764
1765 exploding_enemy:
1766         inc hl
1767         psh hl
1768         ld  a,(hl)
1769         cal explosion_stuff     ;display explosion
1770         pop hl
1771
1772         ld  a,(hl)
1773         cp  15
1774         jr  z,remove_enemy      ;remove when at last frame
1775         inc a
1776         ld  (hl),a              ;next frame
1777         jr  next_enemy
1778
1779 ;--------------------------- moving enemies -----------------------------------
1780
1781 moving_enemy:
1782         ld  a,(level_move)
1783         and %1111
1784         jr  z,movetype_updown   ;type 0
1785         dec a
1786         jr  z,movetype_vslow    ;1
1787         dec a
1788         jr  z,movetype_fast     ;2
1789         dec a
1790         jr  z,movetype_vfast    ;3
1791         dec a
1792         jr  z,movetype_smart    ;4
1793         dec a
1794         jr  z,movetype_lure     ;5
1795         dec a
1796         jr  z,movetype_slowlure ;6
1797         dec a
1798         jr  z,movetype_stoplure ;7
1799 ;       dec a
1800 ;       jr  z,movetype_fulllure ;8
1801
1802 movetype_fulllure:
1803         inc d
1804         ld  a,(timer)
1805         and 1
1806         ret z
1807         cal movetype_lure
1808         ld  a,(x)
1809         cp  d
1810         jr  c,lure_left
1811 lure_right:
1812         inc d
1813         ret
1814 lure_left:
1815         dec d
1816         ret
1817
1818 movetype_stoplure:
1819         inc d
1820         jr  movetype_slowlure
1821
1822 movetype_slowlure:
1823         ld  a,(timer)
1824         and 1
1825         ret z
1826
1827 movetype_lure:
1828         ld  a,(y)
1829         cp  e
1830         jr  c,lure_up
1831 lure_down:
1832         inc e
1833         ret
1834 lure_up:
1835         dec e
1836         ret
1837
1838 movetype_smart:
1839         ld  bc,add2enemy
1840         add hl,bc
1841
1842         ld  a,(timer)
1843         and %1111
1844         ld  a,(hl)
1845         jr  nz,smartupdate
1846         inc a
1847 smartupdate:
1848         ld  (hl),a
1849
1850         or  a                   ;reset carry flag
1851         sbc hl,bc
1852         and %11111100
1853         jr  z,movetype_fast
1854
1855 movetype_vslow:
1856         ld  a,(timer)
1857         and %11
1858         ret z
1859         inc d
1860         ret
1861
1862 movetype_fast:
1863         ld  a,(timer)
1864         and %1
1865         ret z
1866 movetype_vfast:
1867         dec d                   ;move left
1868         ret nz                  ;finished
1869         pop hl                  ;restore stack (no ret used)
1870         jp  remove_enemy        ;remove this enemy (off screen)
1871
1872 movetype_updown:
1873         ld  bc,add2enemy
1874         add hl,bc
1875
1876         ld  a,(hl)
1877         dec a
1878         jr  nz,move_updated
1879         add a,128
1880 move_updated:
1881         ld  (hl),a
1882
1883         or  a                   ;reset carry flag
1884         sbc hl,bc
1885         and %00100000
1886         ld  a,(hl);&&&ld a,e    ;load current y-position
1887         jr  z,movedown
1888
1889 moveup: dec a                   ;decrease y-pos (=move up)
1890         ret m                   ;don't move off the screen (y<0)
1891         dec e                   ;save new y-pos
1892         ret                     ;finish
1893 movedown:
1894         inc a                   ;increase y-pos
1895         cp  55                  ;compare with bottom
1896         ret nc                  ;return if it has passed that line (>40)
1897         inc e                   ;otherwise save new position
1898         ret                     ;and return
1899
1900 ;--------------------------- check collision ----------------------------------
1901
1902 Enemies_hit:
1903         ld  hl,(x)              ;e = X, d = Y
1904         ld  de,$0707            ;add 7 to both d and e
1905         add hl,de
1906         ld  d,h
1907         ld  e,l                 ;e = X+7, d = Y+7
1908
1909         ld  hl,enemies
1910         ld  b,nrenemies         ;check all 20 enemies
1911 check_collision:
1912         psh hl
1913         ld  a,(hl)
1914         and %00000010
1915         jr  z,check_next        ;2 or 3 = ok
1916         inc hl
1917
1918 collide_enemy:                  ;&&& include in Handle_enemy proc
1919         psh de
1920         cal find_sprite
1921         pop de
1922
1923         inc hl
1924         ld  a,(hl)              ;check x match
1925         sub e                   ;enemy position minus yours minus 7
1926         jp  p,check_next
1927         add a,6
1928         add a,(ix)
1929         jp  m,check_next
1930
1931         inc hl
1932         ld  a,(hl)              ;check y match
1933         sub d                   ;same as with x-check
1934         jp  p,check_next
1935         add a,6
1936         add a,(ix+1)
1937         jp  m,check_next
1938         dec hl
1939         dec hl
1940
1941 take_pickup:
1942         psh hl                  ;we need hl
1943         ld  hl,2                ;increase score by 2
1944         cal scoreInc
1945         pop hl                  ;we're done
1946
1947         ld  a,(hl)              ;load enemy type
1948         or  a
1949         jr  nz,collide          ;enemy when <>0
1950
1951         psh hl
1952         ld  hl,your_pickup      ;your pickups
1953         ld  a,(hl)              ;current
1954         inc a                   ;go to next
1955         cp  6                   ;pickups >=6
1956         jr  c,not_maxpickup
1957         ld  a,1                 ;yes: reset to pickup 1
1958 not_maxpickup:
1959         ld  (hl),a              ;save new
1960         cal disp_icons          ;display altered pickupicons
1961         pop hl
1962
1963         dec hl                  ;to enemy occ
1964         xor a                   ;set to 0 = gone
1965         ld  (hl),a              ;remove
1966         jr  check_next          ;all done, next..
1967
1968 destroy_enemy:
1969         ld  (hl),%01            ;set to explode
1970         inc hl
1971         ld  (hl),0              ;explosionFrame 0
1972         jr  collide_done
1973
1974 collide:
1975         dec hl
1976         ld  a,(hl)
1977         and %11111100
1978         jr  z,destroy_enemy
1979         ld  a,(hl)
1980         sub %00000100
1981         ld  (hl),a
1982 collide_done:
1983         cal damage_you
1984
1985 check_next:
1986         pop hl
1987         inc hl
1988         inc hl
1989         inc hl
1990         inc hl
1991         djnz check_collision
1992         ret
1993
1994 ;--------------------------- story -------------------------------------------
1995
1996 storyPage:
1997         psh hl
1998         cal _clrLCD
1999         pop hl
2000 storyLine:
2001         inc hl
2002         ld  e,(hl)
2003         inc hl
2004         ld  d,(hl)
2005         ld  (_penCol),de
2006         inc hl
2007         cal _vputs
2008
2009         ld  a,(hl)
2010         dec a
2011         jr  z,storyLine
2012
2013         psh hl
2014         ld  hl,VIDEO_MEM
2015         ld  de,GRAPH_MEM
2016         ld  bc,1024
2017         ldir
2018         cal _clrLCD
2019         pop hl
2020
2021         inc hl
2022         ld  a,(hl)
2023         inc hl
2024         ld  b,(hl)
2025         psh hl
2026         cal DoSFX
2027         cal _getkey
2028         pop hl
2029         ret
2030
2031 Story:
2032         ld  hl,story01-1
2033         cal storyPage
2034         cal storyPage
2035         cal storyPage
2036         ret
2037
2038 story01:
2039         .db $21,$1d,"Cosmic year 6716"          ,0,0,$1d,$06
2040         .db $1b,$1d,"storyline coming soon..."  ,0,0,$1d,$06
2041         .db $09,$19,"the Nemesis saga continues",0,1
2042         .db $2e,$21,"with NEMESIS 86"           ,0,1
2043         .db $52,$36,"by Shiar"                  ,0,0,$19,$23
2044
2045 ;--------------------------- SFX ---------------------------------------------
2046
2047 CDoSFX:
2048         ld  hl,VIDEO_MEM
2049         ld  de,GRAPH_MEM
2050         ld  bc,1024
2051         ldir
2052         ld  b,64
2053         ld  a,-1
2054
2055 DoSFX:                          ;ins: a=beginLine b=nrOfLines
2056         ld  (curline),a
2057 SFXframe:
2058         psh bc
2059
2060         ld  a,(curline)         ;get line number
2061         inc a                   ;go to the next line
2062         ld  (curline),a         ;update
2063
2064         ld  l,a
2065         ld  h,0
2066         add hl,hl
2067         add hl,hl
2068         add hl,hl
2069         add hl,hl
2070
2071         ld  b,h                 ;save hl for later
2072         ld  c,l
2073
2074         ld  de,VIDEO_MEM
2075         add hl,de               ;go to ymin
2076         ld  d,h
2077         ld  e,l
2078
2079         ld  hl,GRAPH_MEM
2080         add hl,bc               ;hl->logo
2081
2082         ld  a,(curline)         ;Calculate how many lines to draw
2083         ld  c,a
2084         ld  a,64
2085         sub c
2086         ld  b,a
2087
2088 SFXdisp:                        ;display this frame on screen
2089         ld  a,b                 ;psh b (a will not be used)
2090         ld  bc,16               ;one line (=16 bytes, you'd know by now)
2091         ldir                    ;display (copy actually)
2092         ld  bc,-16              ;go up one line (not on screen)
2093         add hl,bc               ;so the same line will be displayed
2094         ld  b,a                 ;pop b
2095         djnz SFXdisp            ;repeat until whole screen is displayed
2096
2097         ld  b,8
2098 SFXdelay:
2099         halt
2100         djnz SFXdelay
2101
2102         pop  bc
2103         djnz SFXframe
2104         ret
2105
2106 ;--------------------------- show icon ----------------------------------------
2107
2108 drawline:
2109         ld  (hl),a              ;draw one piece of the divider-line
2110         inc hl                  ;move right (8 pixels = 1 byte)
2111         djnz drawline           ;repeat (16bytes * 8pixels =128= screen width)
2112         ret
2113
2114 disp_icons:
2115         ld  hl,VIDEO_MEM+(16*56);56 rows down = eight rows from bottom
2116         ld  (PutWhere),hl       ;place icons at bottom of normal screen
2117         ld  b,16                ;draw 16x (screen width)
2118         ld  a,%11111111         ;horizontal line mask
2119         cal drawline            ;draw divider-line
2120
2121         ld  b,16*7              ;draw 16x (screen width) 7x (height)
2122         xor a                   ;blank line mask
2123         cal drawline            ;clear scorebar
2124
2125         cal disp_lives
2126
2127         ld  ix,spr_icon01       ;armorIcon
2128         ld  de,$1901            ;icon #1
2129         cal putwidesprite       ;display icon
2130         cal disp_armor          ;display value
2131
2132         ld  ix,spr_icon00
2133         ld  a,(torp_occ)
2134         or  a
2135         jr  z,no_torp
2136         ld  ix,spr_icon02       ;torpedoIcon
2137 no_torp:
2138         ld  de,$2901            ;icon #2
2139         cal putwidesprite       ;display
2140
2141         ld  ix,spr_icon03       ;bulletIcon
2142         ld  de,$3901            ;icon #3
2143         cal putwidesprite       ;display icon
2144         ld  hl,$3945            ;position to display bullet-type digit
2145         ld  a,(your_weapon)     ;digit
2146         dec a                   ;minus one (1=laser)
2147         cal _disp_armor         ;display digit
2148
2149         ld  ix,spr_icon00       ;emptyIcon
2150         ld  a,(your_weapon)
2151         dec a
2152         jr  nz,no_laser
2153         ld  ix,spr_icon04       ;laserIcon
2154 no_laser:
2155         ld  de,$4901            ;icon #4
2156         cal putwidesprite
2157
2158         ld  ix,spr_icon00       ;emptyIcon
2159         ld  a,(your_multiples)
2160         and %11
2161         jr  z,no_multiples
2162         ld  ix,spr_icon05
2163 no_multiples:
2164         ld  de,$5901            ;icon #5
2165         cal putwidesprite
2166
2167         ld  ix,spr_dividerline
2168         ld  de,$6901
2169         cal putwidesprite
2170
2171         ld  a,(your_pickup)     ;pickups taken
2172         add a,a                 ;picks*2 (sets z-flag)
2173         jr  z,iconsdone         ;return if no pickups
2174         add a,a                 ;picks*4
2175         add a,a                 ;picks*8
2176         add a,a                 ;picks*$10
2177         add a,$09               ;add 0ah
2178         ld  d,a                 ;y-pos = picks * $10 + $0a (19,29,39,49,59)
2179         ld  e,$01               ;x-pos = bottom (1a01,2a01,3a01,4a01,5a01)
2180
2181         ld  ix,spr_icon
2182         cal putwidesprite
2183 iconsdone:
2184         ld  hl,GRAPH_MEM        ;normal game-screen
2185         ld  (PutWhere),hl       ;set sprite-position to normal screen
2186         ret
2187
2188 disp_armor:
2189         ld  hl,$3925            ;Display Armor left
2190         ld  a,(your_armor)      ;load armor left
2191 _disp_armor:
2192         ld  (_penCol),hl        ;place @ armorIcon
2193         add a,'0'               ;make digit
2194         cal _vputmap            ;display char
2195         ret
2196
2197 disp_lives:
2198         ld  hl,$3900            ;display Lives
2199         ld  (_penCol),hl        ;bottom left
2200         ld  hl,savestr+2
2201         ld  (hl),'L'
2202         inc hl
2203         ld  (hl),'x'
2204         inc hl
2205
2206         ld  a,(your_lives)      ;nr of lives in a
2207         add a,'0'               ;make digit
2208         ld  (hl),a
2209         dec hl \ dec hl
2210         cal _vputs              ;display on screen
2211         ret
2212
2213 ;--------------------------- proc ---------------------------------------------
2214
2215 Random5016:
2216         cal Random50            ; a = 0..50
2217         inc a                   ; a = 1..51
2218         ld  h,0
2219         ld  l,a                 ;hl = 1..51
2220         add hl,hl               ;hl = 1..51 * 2
2221         add hl,hl               ;hl = 1..51 * 4
2222         add hl,hl               ;hl = 1..51 * 8
2223         add hl,hl               ;hl = 1..51 * 16 (left side at random y)
2224         dec hl                  ;hl = 1..51 * 16 (" at right side of screen)
2225         ld  de,GRAPH_MEM
2226         add hl,de               ;position on screen
2227         ret
2228
2229 Random50:
2230         cal Random
2231         cp  51                  ;y may not be more than 50
2232         ret c                   ;OK if a<51
2233         and %00111111           ;a = 0..63
2234         sub 13                  ;a = -13..50
2235         ret nc                  ;OK if a>=0
2236         add a,13+(50-12)        ;a = -13..-1 >=> 0..12 >=> 39..50
2237         ret
2238
2239 Random:
2240         ld  a,(RanPos)          ;a handy random-var.
2241         ld  hl,x                ;add your x-coord for randomness
2242         adc a,(hl)
2243         inc hl                  ;add your y-coord for randomness
2244         adc a,(hl)
2245         ld  (RanPos),a          ;save altered random-var
2246         ret                     ;RanPos also in #a
2247
2248 scoreInc:
2249         psh bc
2250         ld  bc,(score)
2251         add hl,bc
2252         ld  (score),hl
2253         pop bc
2254         ret
2255
2256 find_sprite:                    ;destroyed: de ix
2257         psh hl
2258         ld  e,(hl)              ;e = enemy type
2259         ld  d,0                 ;de = e
2260         ld  hl,sprites          ;hl = @sprites offset-table
2261         add hl,de               ;points to offset of current enemy offset
2262         ld  e,(hl)              ;de = @enemy offset
2263         ld  d,0
2264
2265         ld  ix,spr_enemy00      ;first enemy sprite
2266         add ix,de               ;add offset for current enemy
2267         add ix,de               ;twice (offset stored as offset/2)
2268         pop hl
2269         ret
2270
2271 BLACKLCD:
2272         ld  hl,VIDEO_MEM        ;screen location (top left)
2273         ld  de,VIDEO_MEM+1
2274         ld  (hl),%11111111
2275         ld  bc,1024-1           ;do it 1024 times = entire screen
2276         ldir
2277         set 3,(iy+5)            ;set white on black
2278         ret
2279
2280 waitnokeypressed:
2281         halt \ halt
2282         cal GET_KEY
2283         or  a
2284         jr  nz,waitnokeypressed
2285         ret
2286
2287 Decompress:
2288         ld  a,(hl)
2289         bit 7,a
2290         jr  z,Compressed
2291         inc hl
2292         and 01111111b
2293         ld  b,0
2294         ld  c,a
2295         ldir
2296         jr  Decompress
2297 Compressed:
2298         psh af
2299         or  %11111100
2300         ld  b,a
2301         inc hl
2302         ld  c,(hl)
2303         inc hl
2304         pop af
2305         and %01111100
2306         rrca
2307         rrca
2308         or  a
2309         ret z
2310         psh hl
2311         ld  h,d
2312         ld  l,e
2313         add hl,bc
2314         inc a
2315         inc a
2316         ld  b,0
2317         ld  c,a
2318         ldir
2319         pop hl
2320         jr  Decompress
2321
2322 ;--------------------------- game over / new game / death ---------------------
2323 chartable:
2324         .db 0,"!<>^",0,0,0,0
2325         .db 0,"xtoje0",0        ;enter..clear
2326         .db " wsnid9",0         ;(-)..custom
2327         .db "zvrmhc8",0         ;dot..del
2328         .db "yuqlgb7x"          ;0..xvar
2329         .db 0,"-pkfa6'"         ;on..alpha
2330         .db "54321.",0,0        ;F5..more
2331
2332 own_name:
2333         .db 7,"nemesis"
2334
2335 save_hi:
2336         ld  hl,own_name-1       ;find own variable
2337         rst 20h                 ;cal _ABS_MOV10TOOP1
2338         rst 10h                 ;cal _FINDSYM
2339         ret c                   ;not found? who cares...
2340
2341         xor a
2342         ld  hl,4+stored_data_start-_asm_exec_ram
2343         add hl,de               ;hl=pointer to data in original prog
2344         adc a,b
2345         cal _SET_ABS_DEST_ADDR
2346         xor a
2347         ld  hl,stored_data_start
2348         cal _SET_ABS_SRC_ADDR
2349         ld  hl,stored_data_end-stored_data_start
2350         cal _SET_MM_NUM_BYTES
2351         jp  _mm_ldir            ;save done (cal \ ret)
2352
2353 game_over:
2354         pop hl                  ;=ret (game_over was called from a procedure)
2355 game_over_nopop:
2356         cal BLACKLCD            ;clear screen
2357         cal waitnokeypressed
2358         ld  hl,$0603
2359         ld  (_curRow),hl        ;center
2360         ld  hl,txt_gameover
2361         cal _puts               ;display "GAME OVER"
2362
2363         ld  hl,$0007
2364         ld  (_curRow),hl
2365
2366         ld  de,(score)
2367         ld  hl,(hiscore)
2368         cal CP_HL_DE
2369         jr  nc,no_hiscore
2370         ld  (hiscore),de
2371
2372 ask_hiname:
2373         ld  ix,hiname
2374         ld  a,9
2375         ld  (hiscorepos),a
2376 enter_name_loop:
2377         ld  a,'_'
2378         cal _putc
2379         ld  hl,_curCol
2380         dec (hl)
2381 nokeypressed:
2382         halt \ halt
2383         cal GET_KEY
2384         or  a
2385         jr  z,nokeypressed
2386
2387         cp  K_DEL
2388         jr  z,backup
2389         cp  K_ENTER
2390         jr  z,nomore
2391         cp  K_EXIT
2392         jr  z,nomore
2393
2394         ld  hl,hiscorepos
2395         ld  b,(hl)
2396         dec b
2397         jr  z,nokeypressed
2398         ld  (hl),b
2399
2400         ld  hl,chartable
2401         ld  e,a
2402         ld  d,0
2403         add hl,de
2404         ld  a,(hl)
2405         or  a
2406         jr  z,nokeypressed
2407
2408         ld  (ix),a
2409         cal _putc
2410         inc ix
2411         cal waitnokeypressed
2412         jr  enter_name_loop
2413
2414 backup:
2415         ld  hl,hiscorepos
2416         ld  a,(hl)
2417         cp  9
2418         jr  nc,nokeypressed
2419         inc (hl)
2420
2421         dec ix
2422         ld  (ix),' '
2423         ld  a,32
2424         cal _putc
2425         ld  hl,_curCol
2426         dec (hl)
2427         dec (hl)
2428         jr  enter_name_loop
2429
2430 nomore:
2431         ld  a,' '
2432         cal _putc
2433         ld  (ix),0
2434         cal save_hi
2435         jr  hiscoredone
2436
2437 no_hiscore:
2438         ld  hl,hiname
2439         cal _puts
2440
2441 hiscoredone:
2442         xor a                   ;clear a (Ahl will be displayed)
2443         ld  hl,$1006            ;bottom-1 right
2444         ld  (_curRow),hl        ;set
2445         ld  hl,(score)          ;your score
2446         cal _dispahl            ;display it (a=0)
2447
2448         ld  hl,$314b            ;bottom-1 right before score ^^
2449         ld  (_penCol),hl        ;set
2450         ld  hl,txt_score        ;"Score"
2451         cal _vputs              ;display (small)
2452
2453         ld  hl,$1007            ;bottom right
2454         ld  (_curRow),hl        ;set
2455         ld  hl,(hiscore)        ;hi-score
2456         cal _dispahl            ;display
2457         ld  hl,$3946            ;bottom right before hiscore ^^
2458         ld  (_penCol),hl        ;set
2459         ld  hl,txt_hiscore      ;"Hiscore"
2460         cal _vputs              ;display (small)
2461         res 3,(iy+5)
2462
2463         ld  b,16
2464         ld  de,16
2465         ld  hl,VIDEO_MEM+(49*16)-1
2466 restore_line:
2467         set 1,(hl)
2468         add hl,de
2469         djnz restore_line
2470
2471         cal _getkey             ;wait for keypress
2472         jp  quit                ;restore some things and return to TI-OS/shell
2473
2474 New_game:
2475         xor a                   ;score 0
2476         ld  (score),a           ;reset score
2477         ld  (score+1),a         ;reset score
2478         ld  (torp_occ),a        ;no torpedoes
2479         ld  (your_weapon),a     ;no laser
2480         ld  (your_pickup),a     ;reset pickups
2481         ld  (your_multiples),a  ;no multiples
2482         inc a                   ;level #1
2483         ld  (level),a           ;reset level nr
2484         ld  hl,level01          ;set level pointer to level#1
2485         ld  (levelp),hl         ;reset level pointer
2486         inc a                   ;ld a,2
2487         ld  (your_weapon),a     ;default weapon
2488         ld  a,4
2489         ld  (your_lives),a      ;3 lives (4 will be decreased @ You_die)
2490         ld  (pickuptimer),a     ;next pickup after 4 enemies destroyed
2491         inc a                   ;ld a,5
2492         ld  (your_armor),a
2493         ld  a,(weapons+1)       ;max number of bullets (varies per weap.class)
2494         ld  (ybuls),a
2495
2496 You_die:
2497         ld  hl,your_lives
2498         dec (hl)                ;decrease lives
2499         ld  a,(hl)              ;load lives left
2500         inc a                   ;if lives=0ffh then a=0
2501         jp  z,game_over         ;if so, game's over
2502         jr  nonext_level
2503
2504 ;--------------------------- next level ---------------------------------------
2505
2506 Next_level:
2507         ld  hl,level            ;level number
2508         ld  a,(hl)
2509         inc a
2510         ld  (hl),a
2511
2512         ld  hl,(levelp)         ;level pointer
2513         ld  bc,5+32+4+3         ;advance one level
2514         add hl,bc               ;update to point to next level
2515         ld  (levelp),hl         ;save
2516
2517         ld  h,0                 ;increase score....
2518         ld  l,a                 ;by level number
2519         ld  bc,20
2520         add hl,bc               ;plus 20
2521         cal scoreInc            ;update score
2522
2523 nonext_level:
2524         ld  a,80
2525         ld  (nextevent),a       ;time to first enemy appearance
2526
2527         ld  hl,(levelp)         ;level pointer
2528         ld  a,(hl)              ;load new level-enemy type
2529         ld  (level_enemy),a     ;set level-enemy
2530         inc hl
2531         ld  a,(hl)              ;load new appearance-time
2532         ld  (eventtime),a       ;set
2533         inc hl
2534         ld  a,(hl)              ;load nr of enemies in this level
2535         ld  (eventleft),a       ;set nr of events left
2536         inc hl
2537         ld  a,(hl)              ;movement of enemies in this level
2538         ld  (level_move),a      ;do it
2539         inc hl
2540         ld  a,(hl)              ;how frequent the enemies fire a bullet
2541         ld  (level_fire),a      ;consider it done
2542
2543         inc hl
2544         ld  de,spacespace
2545         ld  bc,17+17+2
2546         ldir
2547
2548         ld  ix,starx1
2549         ld  b,nrstars1
2550         cal placestars
2551         ld  hl,RanPos
2552         inc (hl)
2553         ld  ix,starx2
2554         ld  b,nrstars2
2555         cal placestars
2556
2557         xor a
2558         ld  (timer),a           ;reset time
2559         ld  hl,your_occ         ;hl = your_occ
2560         ld  (hl),a              ;reset your ship (not exploding)
2561         inc hl                  ;hl = your_inv
2562         ld  (hl),25             ;set 25*4=100 frames invulnerable
2563         ld  hl,x                ;begin position x=...
2564         ld  (hl),a              ;...=a=0=left
2565         inc hl                  ;y=...
2566         ld  a,24                ;...=24=middle
2567         ld  (hl),a              ;your y
2568
2569         ld  a,(torp_occ)
2570         or  a                   ;no torpedoes?
2571         jr  z,torpsclear        ;then just continue (=0)
2572         ld  a,1                 ;if so, set to "ready to fire" (=1)
2573 torpsclear:
2574
2575         ld  de,$0018            ;x=0, y=24 (like you..)
2576 ;       cal Place_multiples     ;place all multiple-positions at (0,24)
2577
2578         ld  hl,enemies          ;remove all enemies and bullets
2579         ld  (hl),0              ;clear first byte
2580         ld  de,enemies+1        ;copy this to the next byte
2581         ld  bc,(add2enemy*2)+((nrybuls+nrebuls)*3)-1
2582         ldir                    ;clear enemy-info + enemiesxtra + all bullets
2583
2584 ;--------------------------- setup game ---------------------------------------
2585
2586 game_setup:
2587         cal BLACKLCD
2588         ld  hl,$0703
2589         ld  (_curRow),hl        ;center
2590         ld  hl,txt_level
2591         cal _puts               ;display "LEVEL "
2592
2593         ld  a,(level)
2594         ld  l,a
2595         ld  h,$00
2596
2597         cal UNPACK_HL
2598         add a,'0'
2599         ld  b,a
2600         cal UNPACK_HL
2601         add a,'0'
2602         cal _putc               ;display second digit
2603         ld  a,b
2604         cal _putmap             ;display first digit
2605
2606         ld  hl,$0904
2607         ld  (_curRow),hl        ;display lives left below level nr
2608         ld  hl,txt_lives        ;bar text: "Lx0"...
2609         ld  a,(your_lives)      ;lives left
2610         add a,'0'               ;make value
2611         ld  (txt_lives+3),a     ;add to text
2612         cal _puts               ;display the string
2613         res 3,(iy+5)            ;set white on black
2614
2615         cal _getkey             ;wait for keypress
2616
2617         cal CLEARLCD            ;clear screen
2618         cal disp_icons          ;display bottom icons
2619         ret
2620
2621 placestars:
2622         cal Random5016          ;a = (0..50)*16 = random y-pos
2623         ld  a,b                 ;a =  b = star nr. = 1..7
2624         add a,a                 ;a = 2b = 2..14
2625         ld  d,0
2626         ld  e,a                 ;de = a = 2-14
2627         add hl,de               ;add to random y => random pos anywhere
2628
2629         ld  (ix),l              ;save x-pos (l)
2630         ld  (ix+1),h            ;save y-pos (h)
2631         inc ix \ inc ix         ;next star
2632         djnz placestars         ;repeat for all stars
2633         ret
2634
2635 ;--------------------------- putsprite ----------------------------------------
2636 ;--------------------------- de =(X,Y) ----------------------------------------
2637
2638 offsets_table:
2639         .db 128,64,32,%10000,%01000,%00100,%00010,%00001
2640 putsprite:
2641         ld  a,d                 ;a = X
2642         and %00000111           ;a = X mod 8 = bit nr. to mask
2643         ld  hl,offsets_table    ;pixel mask table
2644         ld  c,a                 ;bit nr.
2645         ld  b,0                 ;word
2646         add hl,bc               ;add to table
2647         ld  a,(hl)              ;a = pixel mask
2648         ld  (_smc1+1),a         ;alter pixel mask
2649
2650         ld  hl,GRAPH_MEM        ;save-location
2651         ld  a,e                 ;y-coord
2652         add a,a                 ;y*2
2653         add a,a                 ;y*4
2654         add a,a                 ;y*8
2655         rl  b                   ;b (=0) =b*2+overflow (if y>32 then bc=bc+256)
2656         add a,a                 ;y*16 (width of screen)
2657         rl  b                   ;b=b*2+overflow (if y>64 then bc=bc+512)
2658         srl d                   ;d/2
2659         srl d                   ;d/4
2660         srl d                   ;d/8 (8 bits in byte) ** c is set when overflow
2661         add a,d                 ;a = (Y*16+X/8) mod 256
2662         jr  nc,_n1              ;jump if no carry = no overflow = a<=255
2663         inc b                   ;a>255 so increase bc by 256
2664 _n1:    ld  c,a                 ;c = (Y*16+X/8) mod 256
2665         add hl,bc               ;bc = Y*16+X/8
2666
2667         ld  d,(ix)
2668         ld  b,(ix+1)
2669 _oloop: psh bc                  ;Save # of rows
2670         psh hl                  ;Save screen address
2671         ld  b,d                 ;Load width
2672         ld  c,(ix+2)            ;Load one line of image
2673         inc ix
2674 _smc1:  ld  a,1                 ;Load pixel mask
2675 _iloop: sla c                   ;Test leftmost pixel
2676         jr  nc,_noplot          ;See if a plot is needed
2677         ld  e,a                 ;OR pixel with screen
2678         or  (hl)
2679         ld  (hl),a
2680         ld  a,e
2681 _noplot:rrca
2682         jr  nc,_notedge         ;Test if edge of byte reached
2683         inc hl                  ;Go to next byte
2684 _notedge:
2685         djnz _iloop
2686         pop hl                  ;Restore address
2687         ld  bc,16               ;Go to next line
2688         add hl,bc
2689         pop bc                  ;Restore data
2690         djnz _oloop
2691         ret
2692
2693 ;--------------------------- putbigsprite -------------------------------------
2694
2695 putwidesprite:
2696         ld       a,d
2697         and      7
2698         ld       hl,offsets_table
2699         ld       c,a
2700         ld       b,0
2701         add      hl,bc
2702         ld       a,(hl)
2703         ld       (wsmc1+1),a
2704         ld       (wsmc2+1),a
2705         ld       hl,(PutWhere)
2706
2707         ld       a,e
2708         add      a,a
2709         add      a,a
2710         add      a,a
2711
2712         rl       b
2713         add      a,a
2714         rl       b
2715         srl      d
2716         srl      d
2717         srl      d
2718         add      a,d
2719         jr       nc,n1
2720         inc      b
2721 n1:     ld       c,a
2722         add      hl,bc
2723           
2724         ld       d,(ix)
2725         ld       b,(ix+1)
2726 woloop: psh      bc                         ;Save # of rows
2727         psh      hl                         ;Save screen address
2728         ld       b,d                        ;Load width
2729         ld       c,(ix+2)                   ;Load one line of image
2730         inc      ix
2731 wsmc1:  ld       a,1                        ;Load pixel mask
2732 wiloop: sla      c                          ;Test leftmost pixel
2733         jr       nc,wnoplot                 ;See if a plot is needed
2734         ld       e,a                        ;OR pixel with screen
2735         or       (hl)
2736         ld       (hl),a
2737         ld       a,e
2738 wnoplot:
2739         rrca
2740         jr       nc,wnotedge                ;Test if edge of byte reached
2741         inc      hl                         ;Go to next byte
2742 wnotedge:
2743 wsmc2:  cp       1
2744         jr       z,wover_1
2745
2746         djnz     wiloop
2747         pop      hl                         ;Restore address
2748         ld       bc,16                      ;Go to next line
2749         add      hl,bc
2750         pop      bc                         ;Restore data
2751         djnz     woloop
2752         ret
2753 wover_1:
2754         ld       c,(ix+2)
2755         inc      ix
2756         djnz     wiloop
2757         dec      ix
2758         pop      hl
2759         ld       bc,16
2760         add      hl,bc
2761         pop      bc
2762         djnz     woloop
2763         ret
2764
2765 ;------------------------------------------------------------------------------
2766 ;------------------------------- sprites --------------------------------------
2767 ;------------------------------------------------------------------------------
2768
2769 spr_ship01:
2770         .db 7,7         ;ship alpha class
2771         .db %01111000   ;  ████
2772         .db %11100000   ; ███
2773         .db %01111100   ;  █████
2774         .db %11110010   ; ████  █
2775         .db %01111100   ;  █████
2776         .db %11100000   ; ███
2777         .db %01111000   ;  ████
2778 spr_ship01i:
2779         .db 7,7         ;ship alpha class
2780         .db %00000000   ;
2781         .db %00000000   ;
2782         .db %00000000   ;
2783         .db %00000000   ;
2784         .db %00000000   ;
2785         .db %00000000   ;
2786         .db %00000000   ;
2787
2788         .db %01010000   ;  █ █
2789         .db %10100000   ; █ █
2790         .db %01010100   ;  █ █ █
2791         .db %10100010   ; █ █   █
2792         .db %01010100   ;  █ █ █
2793         .db %10100000   ; █ █
2794         .db %01010000   ;  █ █
2795
2796 spr_ship02:
2797 ;       .db 7,7         ;ship beta class
2798 ;       .db %11100000   ; ███
2799 ;       .db %11110000   ; ████
2800 ;       .db %01111100   ;  █████
2801 ;       .db %01110010   ;  ███  █
2802 ;       .db %01111100   ;  █████
2803 ;       .db %11110000   ; ████
2804 ;       .db %11100000   ; ███
2805 spr_ship02i:
2806 ;       .db 7,7         ;ship beta class
2807 ;       .db %01000000   ;  █
2808 ;       .db %10100000   ; █ █
2809 ;       .db %01010100   ;  █ █ █
2810 ;       .db %00100010   ;   █   █
2811 ;       .db %01010100   ;  █ █ █
2812 ;       .db %10100000   ; █ █
2813 ;       .db %01000000   ;  █
2814
2815 spr_multiple:
2816         .db 6,4         ;multiples
2817         .db %01111000   ;  ████
2818         .db %11111100   ; ██████
2819         .db %11111100   ; ██████
2820         .db %01111000   ;  ████
2821
2822 spr_bullet01:
2823         .db 5,3         ;your bullets
2824         .db %00110000   ;   ░▒▓█▒
2825         .db %11111000   ; ░▒▓████▒
2826         .db %00110000   ;   ░▒▓█▒
2827 spr_bullet02:
2828         .db 5,3
2829         .db %11110000   ; ░▒▓███▒
2830         .db %11111000   ; ░▒▓████▒
2831         .db %11110000   ; ░▒▓███▒
2832 spr_bullett1:
2833         .db 4,3         ;▒▒▒
2834         .db %11100000   ;▒███
2835         .db %11110000   ; ████
2836         .db %01110000   ;  ███
2837
2838 spr_bullete1:
2839         .db 4,3         ;enemy bullets
2840         .db %01100000   ;  ▒█▓▒░
2841         .db %11110000   ; ▒███▓▒░
2842         .db %01100000   ;  ▒█▓▒░
2843
2844 ;---------------------------------------- explosion -------------------------------------------
2845
2846 spr_explosion:
2847         .db 8,6         ;1
2848         .db %00000000
2849         .db %00011100   ;    ███
2850         .db %00111110   ;   █████
2851         .db %01010110   ;  █ █ ██
2852         .db %00111000   ;   ███
2853         .db %00000000
2854
2855         .db 8,6         ;2
2856         .db %00110000   ;   ██
2857         .db %01001110   ;  █ ▒███
2858         .db %10111110   ; █ █████
2859         .db %01001111   ;  █ ▒████
2860         .db %00111000   ;   ███
2861         .db %00011010   ;    ██ █
2862
2863         .db 8,6         ;3
2864         .db %10110000   ; █ ██
2865         .db %01001110   ;  █  ███
2866         .db %10110101   ; █ ██▒█▒█
2867         .db %01000101   ;  █  ▒█▒█
2868         .db %00111110   ;   █████
2869         .db %01011010   ;  █ ██ █
2870
2871         .db 8,6         ;4
2872         .db %00101010   ; ▒ █▒█ █
2873         .db %01000110   ;  █  ▒██
2874         .db %10110101   ; █ ██ █ █
2875         .db %01100110   ;  ██  ██▒
2876         .db %00111100   ;   ████▒
2877         .db %01011001   ;  █ ██ ▒█
2878
2879         .db 8,6         ;5
2880         .db %01000000   ;  █▒ ▒ ▒
2881         .db %00100101   ;  ▒█  █▒█
2882         .db %00010100   ; ▒ ▒█ █ ▒
2883         .db %01000100   ;  █▒  █
2884         .db %00010010   ;   ▒█▒▒█
2885         .db %10011010   ; █▒ ██ █▒
2886
2887         .db 8,6         ;6
2888         .db %01000100   ;  █   █
2889         .db %00100000   ;   ▒█ ▒ ▒
2890         .db %00000001   ;    ▒ ▒ █
2891         .db %01000100   ;  █   █
2892         .db %00100010   ;   █▒  █
2893         .db %01001000   ; ▒█ ▒█ ▒
2894
2895         .db 8,6         ;7
2896         .db %00001000   ;  ▒  █▒
2897         .db %11000010   ; ██ ▒  █
2898         .db %00000000   ;        ▒
2899         .db %00100000   ;  ▒█  ▒
2900         .db %00000001   ;   ▒   ▒█
2901         .db %00110000   ;  ▒██▒
2902
2903         .db 8,6         ;8
2904         .db %00000100   ;     ▒█
2905         .db %00000000   ; ▒▒    ▒
2906         .db %01000000   ;  █
2907         .db %00000000   ;   ▒
2908         .db %00000010   ;       █▒
2909         .db %00100100   ;   █▒ █
2910
2911 spr_yexplosion:
2912         .db 8,6         ;8
2913         .db %00000000   ;
2914         .db %00000000   ;
2915         .db %00000000   ;
2916         .db %00000000   ;
2917         .db %00000000   ;
2918         .db %00000000   ;
2919
2920 ;--------------------------------------- bar -----------------------------------
2921
2922 spr_iconhalf:
2923         .db 16,7        ;selected .......:
2924         .db %11111111           ; ████████
2925         .db %00000001           ;        █
2926         .db %00000001           ;        █
2927         .db %00000001           ;        █
2928         .db %00000001           ;        █
2929         .db %00000001           ;        █
2930         .db %11111111           ; ████████
2931 spr_icon:
2932         .db 16,7        ;selected .......:.......:
2933         .db %11111111,%11111111 ; ████████████████
2934         .db %11000000,%00000001 ; ██             █
2935         .db %11000000,%00000001 ; ██             █
2936         .db %11000000,%00000001 ; ██             █
2937         .db %11000000,%00000001 ; ██             █
2938         .db %11000000,%00000001 ; ██             █
2939         .db %11111111,%11111111 ; ████████████████
2940 spr_icon00:
2941         .db 16,7        ;unused   .......:.......:
2942         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
2943         .db %11010101,%01010101 ; ██ █ █ █ █ █ █ █
2944         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
2945         .db %11010101,%01010101 ; ██ █ █ █ █ █ █ █
2946         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
2947         .db %11010101,%01010101 ; ██ █ █ █ █ █ █ █
2948         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
2949 spr_icon01:
2950         .db 16,7        ;armor  ; .......:.......:
2951         .db %10001111,%10000000 ; █   █████
2952         .db %10010000,%01000000 ; █  █     █  ▒▒▒
2953         .db %10101110,%00100000 ; █ █ ███   █ ▒▒▒
2954         .db %10100111,%10100000 ; █ █  ████ █ ▒▒▒
2955         .db %10101110,%00100000 ; █ █ ███   █ ▒▒▒
2956         .db %10010000,%01000000 ; █  █     █  ▒▒▒
2957         .db %10001111,%10000000 ; █   █████
2958 spr_icon02:
2959         .db 16,7        ;torpedo  .......:.......:
2960         .db %10111000,%00010101 ; █ ███      █ █ █
2961         .db %10011100,%00010101 ; █  ███     █ █ █
2962         .db %10111000,%01001010 ; █ ███    █  █ █
2963         .db %10000000,%11101010 ; █       ███ █ █
2964         .db %11100001,%11100101 ; ███    ████  █ █
2965         .db %10011000,%11110101 ; █  ██   ████ █ █
2966         .db %11100110,%00110010 ; ███  ██   ██  █
2967 spr_icon03:
2968         .db 16,7        ;bullets  .......:.......:
2969         .db %10000000,%11000000 ; █       ██
2970         .db %10000011,%11100000 ; █     █████ ▒▒▒
2971         .db %10011000,%11000000 ; █  ██   ██  ▒▒▒
2972         .db %11111100,%00000000 ; ██████      ▒▒▒
2973         .db %10011000,%11000000 ; █  ██   ██  ▒▒▒
2974         .db %10000011,%11100000 ; █     █████ ▒▒▒
2975         .db %10000000,%11000000 ; █       ██
2976 spr_icon04:
2977         .db 16,7        ;laser    .......:.......:
2978         .db %10000000,%00000000 ; █
2979         .db %10110010,%10000000 ; █ ██  █ █
2980         .db %10111011,%00000000 ; █ ███ ██
2981         .db %10011101,%11111111 ; █  ███ █████████
2982         .db %10111011,%00000000 ; █ ███ ██
2983         .db %10110010,%10000000 ; █ ██  █ █
2984         .db %10000000,%00000000 ; █
2985 spr_icon05:
2986         .db 16,7        ;multiple .......:.......:
2987         .db %10000011,%10000000 ; █     ███
2988         .db %10000001,%11100110 ; █      ████  ██
2989         .db %10000001,%11100000 ; █      ████
2990         .db %10000011,%10000000 ; █     ███
2991         .db %10011000,%00000000 ; █  ██
2992         .db %10111100,%11000011 ; █ ████  ██    ██
2993         .db %10011000,%00000000 ; █  ██
2994 spr_dividerline:
2995         .db 8,7
2996         .db 128,128,128,128,128,128,128 ;128 = %10000000
2997
2998 ;---------------------------- texts -------------------------------------------
2999
3000 txt_about:      .db " v0.95.A22",127,"by Shiar",0
3001 txt_email:      .db "shiar0@hotmail.com",0
3002 txt_menu1:      .db "CONTINUE",0
3003 txt_menu2:      .db "NEW GAME",0
3004
3005 txt_level:      .db "LEVEL ",0
3006 txt_gameover:   .db "GAME OVER!",0
3007 txt_score:      .db "Score",0
3008 txt_hiscore:    .db "Hiscore",0
3009 txt_lives:      .db "Lx0?",0
3010
3011 txt_pressenter: .db "Enter to continue",0
3012 txt_teacher:    .db "(2",Lpi,"*.95)/sin 13",0
3013 txt_teacherans: .db Lneg,"14.2063168184",0
3014
3015 ;---------------------------- save data ---------------------------------------
3016
3017 PutWhere        .dw GRAPH_MEM           ;where to put the wide sprites
3018 level           .db $00                 ;level number
3019 levelp          .dw $0000               ;pointer to level data
3020
3021 score           .dw $0000
3022
3023 stored_data_start:
3024 hiscore         .dw $0000
3025 hiname          .db "Shiar.95",0
3026 stored_data_end:
3027
3028 your_pickup     .db $00
3029 your_occ        .db $00                 ;0=normal 1..16=exploding
3030 your_inv        .db $00                 ;invincibility left
3031 your_armor      .db $05                 ;HP left
3032 your_lives      .db $00                 ;
3033
3034 your_weapon     .db $00                 ;laser avail: 0=no, 1=yes
3035 your_multiples  .db $00                 ;multiples present
3036 torp_occ        .db $00                 ;torp.state: 0=unavail 1=avail 2=presnt
3037 torp_pos        .dw $0000               ;torpedo position (x,y)
3038
3039 #include nemesis0.z80
3040
3041 ;----------------------------- logo -------------------------------------------
3042
3043 logo_nemesis:
3044 .db %11111111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%00001011,%11111111,%11111111,%11111111,%11111000
3045 .db %01111111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%00011011,%11111111,%11111111,%11111111,%11110000
3046 .db %00111111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%00111011,%11111111,%11111111,%11111111,%11100000
3047 .db %00011111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%01111011,%11111111,%11111111,%11111111,%11000000
3048 .db %00000000,%00000000,%00000001,%00011110,%00010000,%00000000,%10000001,%00011110,%00010000,%000000001,%00000000,%00001000,%01000000,%00000000,%00000000,%00000000
3049 .db %00000000,%00000000,%00000011,%00011110,%00110000,%00000001,%10000011,%00011110,%00110000,%000000011,%00000000,%00011000,%11000000,%00000000,%00000000,%00000000
3050 .db %00000000,%00000000,%00000111,%00011110,%01110000,%00000011,%10000111,%00011110,%01110000,%000000111,%00000000,%00111001,%11000000,%00000000,%00000000,%00000000
3051 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3052 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3053 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3054 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3055 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3056 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3057 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3058 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3059 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000111,%11010001
3060 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000001,%00011011
3061 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000001,%00010101
3062 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000001,%00010001
3063
3064 ;----------------------------- end --------------------------------------------
3065
3066         .end
3067 .end
3068
3069
3070 ;------------------------------------------------------------------------------
3071
3072 ; 0.94.A08 -- 08.X.99 -- size 4531 (4456)
3073 ;
3074 ;       + starfield background scrolling left (2 layers (front and back))
3075 ;       * enemies aim their bullets towards you: 5 different directions!
3076 ;       # removed some unintended <add a,a> instructions
3077 ;       * gamefield is now white on black instead of normal black on white!
3078 ;       + enemies can also move slowly, fast, very fast, or 1st fast then slow
3079 ;       # you can't fire when you're exploding
3080 ;       + GROUND scrolling at bottom. You die if you hit the ground (!!!)
3081 ;         (unlike the ground in version 0.925test there are NO bugs)
3082 ;       + ceiling scrolling at top, just like the ground
3083 ;       * ground and ceiling profile are different each level
3084 ;       * ground and/or ceiling can be non-present (speeding up cause skipped)
3085 ;       # no more BIG crash if enemies fire too much bullets ( >10)
3086 ;       + frequency of enemies firing bullets differs per level
3087 ;       * stars scroll at alternate speeds, different than any ship/pick (3/4)
3088 ;       + special effect displaying titlescreen (stole from Spaze Invaders'83)
3089 ;       * enemies can fire either directly on entering the level, or not
3090 ;       + "tunnel" (playfield) can narrow/grow at random (depending on level)
3091 ;       * minimum size of "tunnel" can be different per level
3092 ;       + menu at startup. select "NEW GAME" and "LOAD GAME" with up/down
3093 ;       - nemesis doesn't use the SpazeInvaders effect anymore (took too long)
3094 ;       + choosing new game will display a demo first (text will be displayed
3095 ;         with special effect [SI] saying the storyline will come soon)
3096 ;       * levels altered to be more challenging and different (seven levels)
3097 ;       # the usual bugs that come with new features removed (i think?)
3098 ;       * you get 5 shield-points at start and after death
3099 ;
3100 ; 0.95.A13 -- 13.X.99 -- size 4656
3101 ;
3102 ;       + BOSSES! at the end of a level a huge enemy will appear
3103 ;       * bosses will move towards you, slowly. level=done when boss destroyed
3104 ;       + normal enemies can also try to ram your ship (like bosses do)
3105 ;       * when colliding with an enemy, his armor will decrease (if any)
3106 ;
3107 ; 0.95.A17 -- 17.X.99 -- size 4965
3108 ;
3109 ;       # fix: bullets at right side weren't removed on time (1pix too late)
3110 ;       * each level has it's own boss
3111 ;       + your bullets can have different speeds/directions
3112 ;       + third icon selects bullet-upgrade: single, faster, double, triple
3113 ;       * number of bullets varies per bullet-class (type 1 is max. 2 bullets)
3114 ;       * all temp. vars are stored in TEXT_MEM and TEXT_MEM2 (anti-crash:)
3115 ;
3116 ; 0.95.A18 -- 18.X.99 -- size 5052
3117 ;
3118 ;       # vertical line next to score at game over screen removed (minor)
3119 ;       # some unintended pixels at icon bar now gone (joy, joy)
3120 ;       # number of bullets of a new weapon is loaded correctly
3121 ;       # cleans GRAPH_MEM (Graph-screen) and TEXT_MEM (calculate screen)!
3122 ;       # data not stored at TEXT_MEM2 but now at _asm_exec_ram+5100
3123 ;
3124 ; 0.95.A22 -- 22.X.99 -- size 5321
3125 ;
3126 ;       * total size of enemy-sprites can now be 510 bytes (space = doubled!)
3127 ;       # bullets hit enemies correctly that aren't 6x6; even the 16x10 bosses!
3128 ;       * at g/o or nextlevel checks for keys released instead of waiting abit
3129 ;       + name stored with hiscore (max. 8 chars, Shiar.95 by default)
3130 ;       + when entering hi-name DEL goes back one char (with check 4 no chars)
3131 ;       # program is reloaded at start so some score-bugs solved! (_asapvar=0)
3132 ;       * at death, upgrades and pickups AREN'T removed! (just armor=0)
3133 ;       # bullet is not displayed after being removed anymore
3134 ;       # armor-icon stays hilighted when armor is decreased
3135 ;       * when stars move off screen, they are placed at a NEW y-pos!
3136 ;       * the starting x-positions of stars are not random, so the stars are
3137 ;         spread all over screen. y is still random and changes during game
3138 ;       * make_random functions smaller and used by different procs
3139 ;       # MAJOR BUG! a "random" value was placed somewhere in mem thus
3140 ;         creating bugs like unexplained loss of armor and stuff!
3141 ;
3142 ;
3143 ;        + added        - removed       * changed       # bug fixed
3144