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