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