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