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