323344414bba2471eefb78421d7a3db08144d5b1
[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       = 6
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 ;       [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
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
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-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-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         inc hl                  ;next enemyInfo byte
1524         inc de                  ;next byte of current enemy
1525         ld  a,(hl)              ;load enemy class (nr)
1526         ld  (de),a              ;save enemy type
1527
1528         inc de                  ;set x-pos
1529         psh de
1530         cal find_sprite
1531         pop de
1532         ld  a,128               ;appear at right edge of screen
1533         sub (ix)                ;minus the width of this enemy (not offscreen)
1534         ld  (de),a              ;= x-position (save)
1535
1536         inc de                  ;set y-pos
1537         inc hl                  ;where to place??
1538         ld  a,(hl)              ;load placeInfo
1539         dec a                   ;is it 1?
1540         jr  z,random_enemy      ;yes: create random value <51 in a
1541         dec a                   ;is it 2?
1542         jr  z,lure_enemy        ;yes: create a 100% luring enemy
1543                                 ;otherwise?
1544 halflure_enemy:                 ;yes (of course it is): pick one (50% lure)
1545         ld  a,(timer)           ;look at frame-number
1546         and %00000001           ;make random if odd frame nr.
1547         jr  nz,random_enemy     ;1st possibility: random enemy
1548 lure_enemy:                     ;2nd possibility: luring enemy
1549         ld  a,(y)               ;place at same y-pos as YOUR ship
1550         jr  ypos_OK
1551
1552 random_enemy:
1553         ld  b,e                 ;b will be added to random-value
1554         cal Random50            ;make a (in a) random value 0-51
1555
1556 ypos_OK:                        ;random value successfully created
1557         ld  (de),a              ;save y-position
1558
1559         inc de                  ;set move
1560         ld  a,1                 ;movecounter = 1
1561         ld  (de),a              ;&&&(hl),1 better?
1562
1563         inc de                  ;set fire
1564         ld  a,(level_info)
1565         and %00000001           ;bit meaning directfire
1566         jr  nz,ffireOK          ;(a=time-to-fire) = 1 frame (fires directly)
1567         ld  a,(level_fire)      ;set ttf to normal nr of frames
1568 ffireOK:ld  (de),a              ;save fire
1569         ret                     ;return
1570
1571 ;--------------------------- enemy fires --------------------------------------
1572
1573 Enemy_fires:                    ;de = x,y
1574         dec d
1575         dec d                   ;d = x-2
1576         inc e                   ;e = y+1
1577
1578         ld  b,nrebuls
1579         ld  hl,ebullets
1580 find_ebullet:
1581         ld  a,(hl)
1582         or  a
1583         jr  z,found_ebullet     ;0 = not used
1584         inc hl \ inc hl \ inc hl
1585         dnz find_ebullet        ;look next bullet
1586         ret
1587
1588 found_ebullet:
1589         ld  b,%1100
1590         ld  a,(level_info)
1591         and %00001000
1592         jr  z,bulletok
1593
1594         ld  a,(y)
1595         sub e
1596         add a,10
1597         jp  p,bulletnotup
1598         ld  b,%1011             ;yourY-bulY = negative (=bullet below you)
1599         add a,10
1600         jp  p,bulletnotup
1601         ld  b,%1001             ;yourY-bulY = even more negative (going up)
1602
1603 bulletnotup:
1604         sub 20
1605         jp  m,bulletok
1606         ld  b,%1010             ;bullet going down
1607         sub 10
1608         jp  m,bulletok          ;even more going down
1609         ld  b,%1000
1610
1611 bulletok:
1612         ld  a,(level_info)
1613         and %11110000
1614         or  b
1615         ld  (hl),a              ;set bullet direction
1616         inc hl
1617         ld  (hl),d              ;set x-pos
1618         inc hl
1619         ld  (hl),e              ;set y-pos
1620         ret
1621
1622 ;----------------------------- enemy bullets ----------------------------------
1623
1624 Enemy_bullets:
1625         ld  hl,ebullets
1626         ld  b,nrebuls
1627 handle_bullet:
1628         psh bc
1629         psh hl
1630         ld  a,(hl)              ;load bulletType in a
1631         and %1111               ;select direction-bits
1632         jr  nz,enemy_bullet     ;non-0: handle bullet
1633 next_bullet:
1634         pop hl                  ;do not move the <pop hl>
1635         pop bc
1636         inc hl \ inc hl \ inc hl
1637         dnz handle_bullet
1638         ret
1639
1640 enemy_bullet:
1641         ld  b,a                 ;save type&%1111
1642         inc hl                  ;bullet x
1643         ld  a,(hl)              ;check if it has reached the left side of scrn
1644         and %11111110           ;it is <2 (0 or 1)?
1645         jr  z,remove_ebullet    ;yes, remove bullet
1646         dec (hl)                ;move one left
1647         dec (hl)                ;and another one
1648         ld  d,(hl)              ;d=x
1649         inc hl                  ;@y
1650
1651         ld  a,b                 ;restore type
1652         cp %1100                ;is it a normal bullet? (cp = faster than bit)
1653         jr  z,ebullet_common    ;type %1100: normal bullet
1654         and %111                ;isolate important bits
1655         jr  z,ebullet_down      ;type %1000: moving down
1656         dec a
1657         jr  z,ebullet_up        ;type %1001: moving up
1658         ld  b,a
1659
1660         ld  a,(timer)
1661         rra
1662         jr  c,ebullet_common
1663
1664         ld  a,b
1665         dec a
1666         jr  z,ebullet_down      ;type %1010: moving down 50%
1667                                 ;type %1011: moving up 50%
1668 ebullet_up:
1669         ld  a,(hl)
1670         dec a
1671         jp  m,ebullet_common
1672         ld  (hl),a
1673         jr  ebullet_common
1674
1675 ebullet_down:
1676         ld  a,(hl)
1677         inc a
1678         cp  55
1679         jr  z,ebullet_common
1680         ld  (hl),a
1681
1682 ebullet_common:
1683         ld  e,(hl)              ;e=y
1684         ld  ix,spr_bullete1     ;display enemy bullet
1685         cal putsprite
1686
1687 ebullet_hits:
1688         ld  a,(your_occ)
1689         or  a
1690         jr  nz,next_bullet      ;0 = you're normal
1691
1692         pop hl
1693         psh hl
1694         inc hl                  ;check x
1695         ld  a,(x)
1696         sub (hl)
1697         add a,6
1698         jp  m,next_bullet
1699         cp  9
1700         jr  nc,next_bullet
1701
1702         inc hl                  ;check y
1703         ld  a,(y)
1704         sub (hl)
1705         add a,6
1706         jp  m,next_bullet
1707         cp  9
1708         jr  nc,next_bullet
1709
1710         pop hl                  ;points to bullettype again
1711         psh hl                  ;and save it again (ivm call to damage_you)
1712         ld  a,(hl)              ;load bullettype
1713         cal _shracc             ;isolate damage-bits (%1111???? -> %00001111)
1714         ld  b,a                 ;set damage-amount
1715         cal damage_you          ;HIT!!
1716 remove_ebullet:
1717         pop hl                  ;hl could be destroyed by damage_you
1718         ld  (hl),0              ;bullet > unused
1719         jr  next_bullet+1       ;next bullet (SKIP THE <POP HL> = one byte)
1720
1721 ;--------------------------- handle enemies -----------------------------------
1722
1723 Handle_enemies:
1724         ld  hl,enemies
1725         ld  b,nrenemies         ;handle all enemies
1726
1727 handle_enemy:
1728         psh bc
1729         psh hl
1730
1731         ld  a,(hl)
1732         and %00000011
1733         jr  z,next_enemy        ;occ "no enemy" 0
1734         dec a
1735         jr  z,exploding_enemy   ;occ "exploding" 1
1736         ld  b,a                 ;b=2 if moving, otherwise b=1
1737
1738 normal_enemy:                   ;occ "normal" 2 or "moving" 3
1739         inc hl
1740         ld  c,(hl)              ;c = enemy type = de
1741         cal find_sprite
1742
1743         inc hl
1744         ld  a,(hl)              ;x
1745         dec a                   ;move left
1746         jr  c,remove_enemy      ;off screen
1747         jr  z,remove_enemy      ;"
1748         ld  d,a
1749
1750         inc hl
1751         ld  e,(hl)              ;y
1752         ld  a,b                 ;moving state was stored in b earlier
1753         dec a                   ;is it 1?
1754         cal nz,moving_enemy     ;2 = moving enemy
1755
1756         ld  (hl),e
1757         dec hl                  ;@x
1758         ld  (hl),d              ;store new x
1759         ld  a,c                 ;a = enemy type
1760         or  a                   ;type 0? (pickup)
1761         jr  nz,check_enemyfire  ;no, a normal enemy; let em fire
1762         ld  a,(timer)           ;load time
1763         and %1                  ;move left once every 2 turns
1764         jr  z,firing_done       ;don't move now
1765         inc d                   ;increase x-position (don't move this turn)
1766         inc (hl)                ;and save it
1767         jr  firing_done         ;continue
1768
1769 check_enemyfire:
1770         inc hl                  ;go to <y>
1771         inc hl                  ;go to <move>
1772         inc hl                  ;go to <fire>
1773         dec (hl)                ;decrease counter till next blast
1774         ld  a,(hl)              ;&&&doesn't seem efficient to me
1775         or  a                   ;has it reached zero?
1776         jr  nz,firing_done      ;finished if not
1777
1778         ld  a,(level_fire)      ;re-set counter for next blast
1779         ld  (hl),a              ;save time to fire
1780         inc hl                  ;next byte = bullettype &&&
1781         psh de                  ;save registers for firing-use
1782         cal Enemy_fires         ;fires bullet
1783         pop de                  ;restore (destroyed by Enemy_fires)
1784 firing_done:
1785         cal putwidesprite       ;display sprite @ix
1786
1787 next_enemy:
1788         pop hl
1789         ld  bc,enemysize
1790         add hl,bc
1791         pop bc
1792         dnz handle_enemy
1793         ret
1794
1795 remove_enemy:
1796         pop hl
1797         ld  (hl),$0000          ;bye bye enemy
1798         jr  next_enemy+1        ;continue AFTER pop hl (already done)
1799
1800 exploding_enemy:
1801         inc hl
1802         psh hl
1803         ld  a,(hl)
1804         cal explosion_stuff     ;display explosion
1805         pop hl
1806
1807         ld  a,(hl)
1808         cp  15
1809         jr  z,remove_enemy      ;remove when at last frame
1810         inc a
1811         ld  (hl),a              ;next frame
1812         jr  next_enemy
1813
1814 ;--------------------------- moving enemies -----------------------------------
1815
1816 moving_enemy:
1817         ld  a,(level_move)
1818         and a
1819         jr  z,movetype_updown   ;type 0
1820         dec a
1821         jr  z,movetype_vslow    ;1
1822         dec a
1823         jr  z,movetype_fast     ;2
1824         dec a
1825         jr  z,movetype_vfast    ;3
1826         dec a
1827         jr  z,movetype_smart    ;4
1828         dec a
1829         jr  z,movetype_lure     ;5
1830         dec a
1831         jr  z,movetype_slowlure ;6
1832         dec a
1833         jr  z,movetype_stoplure ;7
1834 ;       dec a
1835 ;       jr  z,movetype_fulllure ;8
1836
1837 movetype_fulllure:
1838         inc d
1839         ld  a,(timer)
1840         and 1
1841         ret z
1842         cal movetype_lure
1843         ld  a,(x)
1844         cp  d
1845         jr  c,lure_left
1846 lure_right:
1847         inc d
1848         ret
1849 lure_left:
1850         dec d
1851         ret
1852
1853 movetype_stoplure:
1854         inc d
1855         jr  movetype_slowlure
1856
1857 movetype_slowlure:
1858         ld  a,(timer)
1859         and 1
1860         ret z
1861
1862 movetype_lure:
1863         ld  a,(y)
1864         cp  e
1865         jr  c,lure_up
1866 lure_down:
1867         inc e
1868         ret
1869 lure_up:
1870         dec e
1871         ret
1872
1873 movetype_smart:
1874         inc hl                  ;hl =@ <move>
1875         ld  a,(timer)
1876         and %1111               ;     |
1877         ld  a,(hl)              ;&&& \|/
1878         jr  nz,smartupdate
1879         inc a
1880 smartupdate:
1881         ld  (hl),a
1882
1883         or  a                   ;reset carry flag
1884         dec hl                  ;reset hl to <y>
1885         and %11111100
1886         jr  z,movetype_fast
1887
1888 movetype_vslow:
1889         ld  a,(timer)
1890         and %11
1891         ret z
1892         inc d
1893         ret
1894
1895 movetype_fast:
1896         ld  a,(timer)
1897         and %1
1898         ret z
1899 movetype_vfast:
1900         dec d                   ;move left
1901         ret nz                  ;finished
1902         pop hl                  ;restore stack (no ret used)
1903         jp  remove_enemy        ;remove this enemy (off screen)
1904
1905 movetype_updown:
1906         inc hl                  ;@ <move>
1907         ld  a,(hl)
1908         dec a
1909         jr  nz,move_updated
1910         add a,128
1911 move_updated:
1912         ld  (hl),a
1913
1914         or  a                   ;reset carry flag
1915         dec hl                  ;@ <y>
1916         and %00100000
1917         ld  a,(hl);&&&ld a,e    ;load current y-position
1918         jr  z,movedown
1919
1920 moveup: dec a                   ;decrease y-pos (=move up)
1921         ret m                   ;don't move off the screen (y<0)
1922         dec e                   ;save new y-pos
1923         ret                     ;finish
1924 movedown:
1925         inc a                   ;increase y-pos
1926         cp  55                  ;compare with bottom
1927         ret nc                  ;return if it has passed that line (>40)
1928         inc e                   ;otherwise save new position
1929         ret                     ;and return
1930
1931 ;--------------------------- check collision ----------------------------------
1932
1933 Enemies_hit:
1934         ld  hl,(x)              ;e = X, d = Y
1935         ld  de,$0707            ;add 7 to both d and e
1936         add hl,de
1937         ld  d,h
1938         ld  e,l                 ;e = X+7, d = Y+7
1939
1940         ld  hl,enemies
1941         ld  b,nrenemies         ;check all 20 enemies
1942 check_collision:
1943         psh hl
1944         ld  a,(hl)
1945         and %00000010
1946         jr  z,check_next        ;2 or 3 = ok
1947         inc hl
1948
1949 collide_enemy:                  ;&&& include in Handle_enemy proc
1950         psh de
1951         cal find_sprite
1952         pop de
1953
1954         inc hl
1955         ld  a,(hl)              ;check x match
1956         sub e                   ;enemy position minus yours minus 7
1957         jp  p,check_next
1958         add a,6
1959         add a,(ix)
1960         jp  m,check_next
1961
1962         inc hl
1963         ld  a,(hl)              ;check y match
1964         sub d                   ;same as with x-check
1965         jp  p,check_next
1966         add a,6
1967         add a,(ix+1)
1968         jp  m,check_next
1969         dec hl
1970         dec hl
1971
1972 take_pickup:
1973         psh hl                  ;we need hl
1974         ld  hl,2                ;increase score by 2
1975         cal scoreInc
1976         pop hl                  ;we're done
1977
1978         ld  a,(hl)              ;load enemy type
1979         or  a
1980         jr  nz,collide          ;enemy when <>0
1981
1982         psh hl
1983         ld  hl,your_pickup      ;your pickups
1984         ld  a,(hl)              ;current
1985         inc a                   ;go to next
1986         cp  6                   ;pickups >=6
1987         jr  c,not_maxpickup
1988         ld  a,1                 ;yes: reset to pickup 1
1989 not_maxpickup:
1990         ld  (hl),a              ;save new
1991         cal disp_icons          ;display altered pickupicons
1992         pop hl
1993
1994         dec hl                  ;to enemy occ
1995         xor a                   ;set to 0 = gone
1996         ld  (hl),a              ;remove
1997         jr  check_next          ;all done, next..
1998
1999 destroy_enemy:
2000         ld  (hl),%01            ;set to explode
2001         inc hl
2002         ld  (hl),0              ;explosionFrame 0
2003         jr  collide_done
2004
2005 collide:
2006         dec hl
2007         ld  a,(hl)
2008         and %11111100
2009         jr  z,destroy_enemy
2010         ld  a,(hl)
2011         sub %00000100
2012         ld  (hl),a
2013 collide_done:
2014         ld  b,4                 ;damage
2015         cal damage_you
2016
2017 check_next:
2018         pop hl
2019         ld  a,b                 ;psh bc
2020         ld  bc,enemysize
2021         add hl,bc
2022         ld  b,a                 ;pop bc
2023         dnz check_collision
2024         ret
2025
2026 ;--------------------------- story -------------------------------------------
2027
2028 storyPage:
2029         psh hl
2030         cal _clrLCD
2031         pop hl
2032 storyLine:
2033         inc hl
2034         ld  e,(hl)
2035         inc hl
2036         ld  d,(hl)
2037         ld  (_penCol),de
2038         inc hl
2039         cal _vputs
2040
2041         ld  a,(hl)
2042         dec a
2043         jr  z,storyLine
2044
2045         psh hl
2046         ld  hl,VIDEO_MEM
2047         ld  de,GRAPH_MEM
2048         ld  bc,1024
2049         ldir
2050         cal _clrLCD
2051         pop hl
2052
2053         inc hl
2054         ld  a,(hl)
2055         inc hl
2056         ld  b,(hl)
2057         psh hl
2058         cal DoSFX
2059         cal _getkey
2060         pop hl
2061         ret
2062
2063 dostory:
2064         cal storyPage                   ;do some story
2065         inc hl                          ;look at next hl
2066         ld  a,(hl)                      ;load in a
2067         dec hl                          ;restory hl
2068         inc a                           ;set z-flag if a = $ff
2069         jr  nz,dostory                  ;otherwise loop
2070
2071         ld  bc,5                        ;story ends
2072         add hl,bc                       ;set hl to beginning of the level
2073         ld  (levelp),hl                 ;set the level-pointer
2074         ret                             ;and return
2075
2076 ;--------------------------- SFX ---------------------------------------------
2077
2078 CDoSFX:
2079         ld  hl,VIDEO_MEM
2080         ld  de,GRAPH_MEM
2081         ld  bc,1024
2082         ldir
2083         ld  b,64
2084         ld  a,-1
2085
2086 DoSFX:                          ;ins: a=beginLine b=nrOfLines
2087         ld  (curline),a
2088 SFXframe:
2089         psh bc
2090
2091         ld  a,(curline)         ;get line number
2092         inc a                   ;go to the next line
2093         ld  (curline),a         ;update
2094
2095         ld  l,a
2096         ld  h,0
2097         add hl,hl
2098         add hl,hl
2099         add hl,hl
2100         add hl,hl
2101
2102         ld  b,h                 ;save hl for later
2103         ld  c,l
2104
2105         ld  de,VIDEO_MEM
2106         add hl,de               ;go to ymin
2107         ld  d,h
2108         ld  e,l
2109
2110         ld  hl,GRAPH_MEM
2111         add hl,bc               ;hl->logo
2112
2113         ld  a,(curline)         ;Calculate how many lines to draw
2114         ld  c,a
2115         ld  a,64
2116         sub c
2117         ld  b,a
2118
2119 SFXdisp:                        ;display this frame on screen
2120         ld  a,b                 ;psh b (a will not be used)
2121         ld  bc,16               ;one line (=16 bytes, you'd know by now)
2122         ldir                    ;display (copy actually)
2123         ld  bc,-16              ;go up one line (not on screen)
2124         add hl,bc               ;so the same line will be displayed
2125         ld  b,a                 ;pop b
2126         dnz SFXdisp             ;repeat until whole screen is displayed
2127
2128         ld  b,8
2129 SFXdelay:
2130         halt
2131         dnz SFXdelay
2132
2133         pop  bc
2134         dnz SFXframe
2135         ret
2136
2137 ;--------------------------- show icon ----------------------------------------
2138
2139 drawline:
2140         ld  (hl),a              ;draw one piece of the divider-line
2141         inc hl                  ;move right (8 pixels = 1 byte)
2142         dnz drawline            ;repeat (16bytes * 8pixels =128= screen width)
2143         ret
2144
2145 disp_icons:
2146  psh bc \ psh de \ psh hl \ psh ix ;&&&
2147
2148         ld  hl,VIDEO_MEM+(16*56);56 rows down = eight rows from bottom
2149         ld  (PutWhere),hl       ;place icons at bottom of normal screen
2150         ld  b,16                ;draw 16x (screen width)
2151         ld  a,%11111111         ;horizontal line mask
2152         cal drawline            ;draw divider-line
2153
2154         ld  b,16*7              ;draw 16x (screen width) 7x (height)
2155         xor a                   ;blank line mask
2156         cal drawline            ;clear scorebar
2157
2158         cal disp_lives
2159
2160         ld  ix,spr_icon01       ;armorIcon
2161         ld  de,$1901            ;icon #1
2162         cal putwidesprite       ;display icon
2163         cal disp_armor          ;display bar
2164
2165         ld  ix,spr_icon00
2166         ld  a,(torp_occ)
2167         or  a
2168         jr  z,no_torp
2169         ld  ix,spr_icon02       ;torpedoIcon
2170 no_torp:
2171         ld  de,$2901            ;icon #2
2172         cal putwidesprite       ;display
2173
2174         ld  ix,spr_icon03       ;bulletIcon
2175         ld  de,$3901            ;icon #3
2176         cal putwidesprite       ;display icon
2177         ld  hl,$3945            ;position to display bullet-type digit
2178         ld  a,(your_weapon)     ;digit
2179         dec a                   ;minus one (1=laser)
2180         ld  (_penCol),hl        ;set location
2181         add a,'0'               ;make digit
2182         cal _vputmap            ;display char
2183
2184         ld  ix,spr_icon00       ;emptyIcon
2185         ld  a,(your_weapon)
2186         dec a
2187         jr  nz,no_laser
2188         ld  ix,spr_icon04       ;laserIcon
2189 no_laser:
2190         ld  de,$4901            ;icon #4
2191         cal putwidesprite
2192
2193         ld  ix,spr_icon00       ;emptyIcon
2194         ld  a,(your_multiples)
2195         and %11
2196         jr  z,no_multiples
2197         ld  ix,spr_icon05
2198 no_multiples:
2199         ld  de,$5901            ;icon #5
2200         cal putwidesprite
2201
2202         ld  ix,spr_dividerline
2203         ld  de,$6901
2204         cal putwidesprite
2205
2206         ld  a,(your_pickup)     ;pickups taken
2207         add a,a                 ;picks*2 (sets z-flag)
2208         jr  z,iconsdone         ;return if no pickups
2209         add a,a                 ;picks*4
2210         add a,a                 ;picks*8
2211         add a,a                 ;picks*$10
2212         add a,$09               ;add 0ah
2213         ld  d,a                 ;y-pos = picks * $10 + $0a (19,29,39,49,59)
2214         ld  e,$01               ;x-pos = bottom (1a01,2a01,3a01,4a01,5a01)
2215
2216         ld  ix,spr_icon
2217         cal putwidesprite
2218 iconsdone:
2219         ld  hl,GRAPH_MEM        ;normal game-screen
2220         ld  (PutWhere),hl       ;set sprite-position to normal screen
2221
2222  pop ix \ pop hl \ pop de \ pop bc
2223         ret
2224
2225 disp_armor:
2226         ld  hl,(57*16)+VIDEO_MEM+3
2227         ld  b,3
2228 armorbarclr:
2229         dec hl
2230         ld  (hl),0
2231         dnz armorbarclr
2232
2233         ld  a,(your_armor)      ;load your armor
2234         ld  c,a                 ;psh a
2235         srl a                   ;/2
2236         srl a                   ;/4
2237         srl a                   ;/8: don't display last 2 bits of a (later)
2238         jr  z,noarmorbar        ;if a=0 then it would loop 256x so skip it
2239         ld  b,a                 ;loop b=a times
2240 armorbar:                       ;starting at ($39*16)+VIDEO_MEM
2241         ld  (hl),%11111111      ;draw a piece of the bar
2242         inc hl                  ;next position
2243         dnz armorbar            ;loop it b times
2244
2245 noarmorbar:
2246         ld  a,c                 ;pop a
2247         and %111                ;display last bits of armor
2248         ret z                   ;if armor=0 then bit = %00000000 (don't disp)
2249         ld  b,a                 ;into B
2250         xor a                   ;bit = %00000000
2251 armorbarbit:
2252         scf                     ;set carry flag
2253         rra                     ;rotates A right and sets bit 7 (c-flag)
2254         dnz armorbarbit         ;repeat B times (so if B=6 then a=%11111100)
2255 armorbarready:                  ;               (an if B=3 then a=%11100000)
2256         ld  (hl),a              ;draw this last byte
2257         ret
2258
2259 disp_lives:
2260         ld  hl,$3A00            ;display Lives
2261         ld  (_penCol),hl        ;bottom left
2262         ld  hl,savestr+2
2263         ld  (hl),'L'
2264         inc hl
2265         ld  (hl),'x'
2266         inc hl
2267
2268         ld  a,(your_lives)      ;nr of lives in a
2269         add a,'0'               ;make digit
2270         ld  (hl),a
2271         dec hl \ dec hl
2272         jp  _vputs              ;display on screen +ret
2273
2274 ;--------------------------- proc ---------------------------------------------
2275
2276 Random5016:
2277         cal Random50            ; a = 0..50
2278         inc a                   ; a = 1..51
2279         ld  h,0
2280         ld  l,a                 ;hl = 1..51
2281         add hl,hl               ;hl = 1..51 * 2
2282         add hl,hl               ;hl = 1..51 * 4
2283         add hl,hl               ;hl = 1..51 * 8
2284         add hl,hl               ;hl = 1..51 * 16 (left side at random y)
2285         dec hl                  ;hl = 1..51 * 16 (" at right side of screen)
2286         ld  de,GRAPH_MEM
2287         add hl,de               ;position on screen
2288         ret
2289
2290 Random50:
2291         cal Random
2292         cp  51                  ;y may not be more than 50
2293         ret c                   ;OK if a<51
2294         and %00111111           ;a = 0..63
2295         sub 13                  ;a = -13..50
2296         ret nc                  ;OK if a>=0
2297         add a,13+(50-12)        ;a = -13..-1 >=> 0..12 >=> 39..50
2298         ret
2299
2300 Random:
2301         ld  a,(RanPos)          ;a handy random-var.
2302         ld  hl,x                ;add your x-coord for randomness
2303         adc a,(hl)
2304         inc hl                  ;add your y-coord for randomness
2305         adc a,(hl)
2306         ld  (RanPos),a          ;save altered random-var
2307         ret                     ;RanPos also in #a
2308
2309 scoreInc:
2310         psh bc
2311         ld  bc,(score)
2312         add hl,bc
2313         ld  (score),hl
2314         pop bc
2315         ret
2316
2317 find_sprite:                    ;destroyed: de ix
2318         psh hl
2319         ld  e,(hl)              ;e = enemy type
2320         ld  d,0                 ;de = e
2321         ld  hl,XLenemytable     ;hl = @sprites offset-table
2322         add hl,de               ;points to offset of current enemy offset
2323         ld  e,(hl)              ;de = @enemy offset
2324         ld  d,0
2325
2326         ld  ix,XLsprenemies     ;first enemy sprite
2327         add ix,de               ;add offset for current enemy
2328         add ix,de               ;twice (offset stored as offset/2)
2329         pop hl
2330         ret
2331
2332 BLACKLCD:
2333         ld  hl,VIDEO_MEM        ;screen location (top left)
2334         ld  de,VIDEO_MEM+1
2335         ld  (hl),%11111111
2336         ld  bc,1024-1           ;do it 1024 times = entire screen
2337         ldir
2338         set 3,(iy+5)            ;set white on black
2339         ret
2340
2341 waitnokeypressed:
2342         halt \ halt
2343         cal GET_KEY
2344         or  a
2345         jr  nz,waitnokeypressed
2346         ret
2347
2348 Decompress:                     ;hl=source(compressed) de=dest(decompressed)
2349         ld  a,(hl)
2350         bit 7,a
2351         jr  z,compressed
2352         inc hl
2353         and %01111111
2354         ld  b,0
2355         ld  c,a
2356         ldir
2357         jr  Decompress
2358 compressed:
2359         psh af
2360         or  %11111100
2361         ld  b,a
2362         inc hl
2363         ld  c,(hl)
2364         inc hl
2365         pop af
2366         and %01111100
2367         rrca
2368         rrca
2369         or  a
2370         ret z
2371         psh hl
2372         ld  h,d
2373         ld  l,e
2374         add hl,bc
2375         inc a
2376         inc a
2377         ld  b,0
2378         ld  c,a
2379         ldir
2380         pop hl
2381         jr  Decompress
2382
2383 ;--------------------------- game over / new game / death ---------------------
2384 chartable:
2385         .db 0,"!<>^",0,0,0,0
2386         .db 0,"xtoje0",0        ;enter..clear
2387         .db " wsnid9",0         ;(-)..custom
2388         .db "zvrmhc8",0         ;dot..del
2389         .db "yuqlgb7x"          ;0..xvar
2390         .db 0,"-pkfa6'"         ;on..alpha
2391         .db "54321.",0,0        ;F5..more
2392
2393 own_name:
2394         .db 7,"nemesis"
2395
2396 save_hi:
2397         ld  hl,own_name-1       ;find own variable
2398         rst 20h                 ;cal _ABS_MOV10TOOP1
2399         rst 10h                 ;cal _FINDSYM
2400         ret c                   ;not found? who cares...
2401
2402         xor a
2403         ld  hl,4+storehi_start-_asm_exec_ram
2404         add hl,de               ;hl=pointer to data in original prog
2405         adc a,b
2406         cal _SET_ABS_DEST_ADDR
2407         xor a
2408         ld  hl,storehi_start
2409         cal _SET_ABS_SRC_ADDR
2410         ld  hl,storehi_end-storehi_start
2411         cal _SET_MM_NUM_BYTES
2412         jp  _mm_ldir            ;save done (cal \ ret)
2413
2414 save_lvl:
2415         ld  hl,own_name-1       ;find own variable
2416         rst 20h                 ;cal _ABS_MOV10TOOP1
2417         rst 10h                 ;cal _FINDSYM
2418         ret c                   ;not found? who cares...
2419
2420         xor a
2421         ld  hl,4+storesave_start-_asm_exec_ram
2422         add hl,de               ;hl=pointer to data in original prog
2423         adc a,b
2424         cal _SET_ABS_DEST_ADDR
2425         xor a
2426         ld  hl,storesave_start
2427         cal _SET_ABS_SRC_ADDR
2428         ld  hl,storesave_end-storesave_start
2429         cal _SET_MM_NUM_BYTES
2430         jp  _mm_ldir            ;save done (cal \ ret)
2431         ret
2432
2433 game_over:
2434         pop hl                  ;=ret (game_over was called from a procedure)
2435 game_over_nopop:
2436         cal BLACKLCD            ;clear screen
2437         cal waitnokeypressed
2438         ld  hl,$0603
2439         ld  (_curRow),hl        ;center
2440         ld  hl,txt_gameover
2441         cal _puts               ;display "GAME OVER"
2442
2443         ld  hl,$0007
2444         ld  (_curRow),hl
2445
2446         ld  de,(score)
2447         ld  hl,(hiscore)
2448         cal CP_HL_DE
2449         jr  nc,no_hiscore
2450         ld  (hiscore),de
2451
2452 ask_hiname:
2453         ld  ix,hiname
2454         ld  a,9
2455         ld  (hiscorepos),a
2456 enter_name_loop:
2457         ld  a,'_'
2458         cal _putc
2459         ld  hl,_curCol
2460         dec (hl)
2461 nokeypressed:
2462         halt \ halt
2463         cal GET_KEY
2464         or  a
2465         jr  z,nokeypressed
2466
2467         cp  K_DEL
2468         jr  z,backup
2469         cp  K_ENTER
2470         jr  z,nomore
2471         cp  K_EXIT
2472         jr  z,nomore
2473
2474         ld  hl,hiscorepos
2475         ld  b,(hl)
2476         dec b
2477         jr  z,nokeypressed
2478         ld  (hl),b
2479
2480         ld  hl,chartable
2481         ld  e,a
2482         ld  d,0
2483         add hl,de
2484         ld  a,(hl)
2485         or  a
2486         jr  z,nokeypressed
2487
2488         ld  (ix),a
2489         cal _putc
2490         inc ix
2491         cal waitnokeypressed
2492         jr  enter_name_loop
2493
2494 backup:
2495         ld  hl,hiscorepos
2496         ld  a,(hl)
2497         cp  9
2498         jr  nc,nokeypressed
2499         inc (hl)
2500
2501         dec ix
2502         ld  (ix),' '
2503         ld  a,32
2504         cal _putc
2505         ld  hl,_curCol
2506         dec (hl)
2507         dec (hl)
2508         jr  enter_name_loop
2509
2510 nomore:
2511         ld  a,' '
2512         cal _putc
2513         ld  (ix),0
2514         cal save_hi
2515         jr  hiscoredone
2516
2517 no_hiscore:
2518         ld  hl,hiname
2519         cal _puts
2520
2521 hiscoredone:
2522         xor a                   ;clear a (Ahl will be displayed)
2523         ld  hl,$1006            ;bottom-1 right
2524         ld  (_curRow),hl        ;set
2525         ld  hl,(score)          ;your score
2526         cal _dispahl            ;display it (a=0)
2527
2528         ld  hl,$314b            ;bottom-1 right before score ^^
2529         ld  (_penCol),hl        ;set
2530         ld  hl,txt_score        ;"Score"
2531         cal _vputs              ;display (small)
2532
2533         ld  hl,$1007            ;bottom right
2534         ld  (_curRow),hl        ;set
2535         ld  hl,(hiscore)        ;hi-score
2536         cal _dispahl            ;display
2537         ld  hl,$3946            ;bottom right before hiscore ^^
2538         ld  (_penCol),hl        ;set
2539         ld  hl,txt_hiscore      ;"Hiscore"
2540         cal _vputs              ;display (small)
2541         res 3,(iy+5)
2542
2543         ld  b,16
2544         ld  de,16
2545         ld  hl,VIDEO_MEM+(49*16)-1
2546 restore_line:
2547         set 1,(hl)
2548         add hl,de
2549         dnz restore_line
2550
2551         cal _getkey             ;wait for keypress
2552         jp  quit                ;restore some things and return to TI-OS/shell
2553
2554 Continue_game:
2555         jr  nonext_level
2556
2557 New_game:
2558         xor a                   ;ld a,0
2559         ld  (score),a           ;reset score
2560         ld  (score+1),a         ;reset score (0)
2561         ld  (torp_occ),a        ;no torpedoes
2562         ld  (your_weapon),a     ;no laser
2563         ld  (your_pickup),a     ;reset pickups
2564         ld  (your_multiples),a  ;no multiples
2565         inc a                   ;ld a,1
2566         ld  (level),a           ;reset level nr (#1)
2567         ld  hl,XLlevelsdata     ;set level pointer to level#1
2568         ld  (levelp),hl         ;reset level pointer
2569         inc a                   ;ld a,2
2570         ld  (your_weapon),a     ;default weapon
2571         ld  a,4
2572         ld  (your_lives),a      ;3 lives (4 will be decreased @ You_die)
2573         ld  (pickuptimer),a     ;next pickup after 4 enemies destroyed
2574
2575         xor a
2576         cp  (hl)
2577         cal z,dostory
2578
2579 You_die:
2580         ld  a,12
2581         ld  (your_armor),a      ;5 HPs/shields
2582         ld  hl,your_lives
2583         dec (hl)                ;decrease lives
2584         ld  a,(hl)              ;load lives left
2585         inc a                   ;if lives=0ffh then a=0
2586         jp  z,game_over         ;if so, game's over
2587         jr  nonext_level
2588
2589 ;--------------------------- next level ---------------------------------------
2590
2591 Next_level:
2592         ld  hl,level            ;level number
2593         ld  a,(hl)
2594         inc a
2595         ld  (hl),a
2596
2597         add a,a
2598         add a,a
2599         ld  h,0                 ;increase score....
2600         ld  l,a                 ;by level number * 4
2601         ld  bc,20
2602         add hl,bc               ;plus 20
2603         cal scoreInc            ;update score
2604
2605         ld  hl,(levelp)         ;level pointer
2606         ld  bc,5+32+4+4         ;advance one level
2607         add hl,bc               ;update to point to next level
2608         ld  (levelp),hl         ;save
2609
2610         xor a
2611         cp  (hl)
2612         cal z,dostory
2613
2614 nonext_level:
2615         ld  a,(your_weapon)
2616         add a,a                 ;weap*2
2617         add a,a                 ;    *4
2618         add a,a                 ;    *8
2619         ld  c,a
2620         ld  b,0
2621         ld  hl,XLweapondata-7
2622         add hl,bc
2623         ld  a,(hl)
2624         ld  (ybuls),a           ;max number of bullets (varies per weap.class)
2625
2626         ld  a,80
2627         ld  (nextevent),a       ;time to first enemy appearance
2628
2629         ld  hl,(levelp)         ;level pointer
2630         ld  a,(hl)              ;load new level-enemy type
2631         ld  (level_enemy),a     ;set level-enemy
2632         inc hl
2633         ld  a,(hl)              ;load new appearance-time
2634         ld  (eventtime),a       ;set
2635         inc hl
2636         ld  a,(hl)              ;load nr of enemies in this level
2637         ld  (eventleft),a       ;set nr of events left
2638         inc hl
2639         ld  a,(hl)              ;
2640         ld  (level_info),a      ;
2641         inc hl
2642         ld  a,(hl)              ;movement of enemies in this level
2643         ld  (level_move),a      ;do it
2644         inc hl
2645         ld  a,(hl)              ;how frequent the enemies fire a bullet
2646         ld  (level_fire),a      ;consider it done
2647
2648         inc hl
2649         ld  de,spacespace
2650         ld  bc,17+17+2
2651         ldir
2652
2653         ld  ix,starx1
2654         ld  b,nrstars1
2655         cal placestars
2656         ld  hl,RanPos
2657         inc (hl)
2658         ld  ix,starx2
2659         ld  b,nrstars2
2660         cal placestars
2661
2662         xor a
2663         ld  (timer),a           ;reset time
2664         ld  hl,your_occ         ;hl = your_occ
2665         ld  (hl),a              ;reset your ship (not exploding)
2666         inc hl                  ;hl = your_inv
2667         ld  (hl),25             ;set 25*4=100 frames invulnerable
2668         ld  hl,x                ;begin position x=...
2669         ld  (hl),a              ;...=a=0=left
2670         inc hl                  ;y=...
2671         ld  a,24                ;...=24=middle
2672         ld  (hl),a              ;your y
2673
2674         ld  a,(torp_occ)
2675         or  a                   ;no torpedoes?
2676         jr  z,torpsclear        ;then just continue (=0)
2677         ld  a,1                 ;if so, set to "ready to fire" (=1)
2678 torpsclear:
2679
2680         ld  de,$0018            ;x=0, y=24 (like you..)
2681 ;       cal Place_multiples     ;place all multiple-positions at (0,24)
2682
2683         ld  hl,enemies          ;remove all enemies and bullets
2684         ld  (hl),0              ;clear first byte
2685         ld  de,enemies+1        ;copy this to the next byte
2686         ld  bc,(nrenemies*enemysize)+((nrybuls+nrebuls)*3)-1
2687         ldir                    ;clear enemies + bullets (y/e)
2688
2689 ;--------------------------- setup game ---------------------------------------
2690
2691 game_setup:
2692         cal BLACKLCD
2693         ld  hl,$0703
2694         ld  (_curRow),hl        ;center
2695         ld  hl,txt_level
2696         cal _puts               ;display "LEVEL "
2697
2698         ld  a,(level)
2699         ld  l,a
2700         ld  h,$00
2701
2702         cal UNPACK_HL
2703         add a,'0'
2704         ld  b,a
2705         cal UNPACK_HL
2706         add a,'0'
2707         cal _putc               ;display second digit
2708         ld  a,b
2709         cal _putmap             ;display first digit
2710
2711         ld  hl,$0904
2712         ld  (_curRow),hl        ;display lives left below level nr
2713         ld  hl,txt_lives        ;bar text: "Lx0"...
2714         ld  a,(your_lives)      ;lives left
2715         add a,'0'               ;make value
2716         ld  (txt_lives+3),a     ;add to text
2717         cal _puts               ;display the string
2718         res 3,(iy+5)            ;set white on black
2719
2720         cal _getkey             ;wait for keypress
2721         cp  kF1
2722         cal z,save_lvl
2723
2724         cal _clrLCD             ;clear screen
2725         jp  disp_icons          ;display bottom icons +ret
2726
2727 placestars:
2728         cal Random5016          ;a = (0..50)*16 = random y-pos
2729         ld  a,b                 ;a =  b = star nr. = 1..7
2730         add a,a                 ;a = 2b = 2..14
2731         ld  d,0
2732         ld  e,a                 ;de = a = 2-14
2733         add hl,de               ;add to random y => random pos anywhere
2734
2735         ld  (ix),l              ;save x-pos (l)
2736         ld  (ix+1),h            ;save y-pos (h)
2737         inc ix \ inc ix         ;next star
2738         dnz placestars          ;repeat for all stars
2739         ret
2740
2741 ;--------------------------- putsprite ----------------------------------------
2742 ;--------------------------- de =(X,Y) ----------------------------------------
2743
2744 offsets_table:
2745         .db 128,64,32,%10000,%01000,%00100,%00010,%00001
2746 putsprite:
2747         ld  a,d                 ;a = X
2748         and %00000111           ;a = X mod 8 = bit nr. to mask
2749         ld  hl,offsets_table    ;pixel mask table
2750         ld  c,a                 ;bit nr.
2751         ld  b,0                 ;word
2752         add hl,bc               ;add to table
2753         ld  a,(hl)              ;a = pixel mask
2754         ld  (_smc1+1),a         ;alter pixel mask
2755
2756         ld  hl,GRAPH_MEM        ;save-location
2757         ld  a,e                 ;y-coord
2758         add a,a                 ;y*2
2759         add a,a                 ;y*4
2760         add a,a                 ;y*8
2761         rl  b                   ;b (=0) =b*2+overflow (if y>32 then bc=bc+256)
2762         add a,a                 ;y*16 (width of screen)
2763         rl  b                   ;b=b*2+overflow (if y>64 then bc=bc+512)
2764         srl d                   ;d/2
2765         srl d                   ;d/4
2766         srl d                   ;d/8 (8 bits in byte) ** c is set when overflow
2767         add a,d                 ;a = (Y*16+X/8) mod 256
2768         jp  nc,_n1              ;jump if no carry = no overflow = a<=255
2769         inc b                   ;a>255 so increase bc by 256
2770 _n1:    ld  c,a                 ;c = (Y*16+X/8) mod 256
2771         add hl,bc               ;bc = Y*16+X/8
2772
2773         ld  d,(ix)
2774         ld  b,(ix+1)
2775 _oloop: psh bc                  ;Save # of rows
2776         psh hl                  ;Save screen address
2777         ld  b,d                 ;Load width
2778         ld  c,(ix+2)            ;Load one line of image
2779         inc ix
2780 _smc1:  ld  a,1                 ;Load pixel mask
2781 _iloop: sla c                   ;Test leftmost pixel
2782         jp  nc,_noplot          ;See if a plot is needed
2783         ld  e,a                 ;OR pixel with screen
2784         or  (hl)
2785         ld  (hl),a
2786         ld  a,e
2787 _noplot:rrca
2788         jp  nc,_notedge         ;Test if edge of byte reached
2789         inc hl                  ;Go to next byte
2790 _notedge:
2791         dnz _iloop
2792         pop hl                  ;Restore address
2793         ld  bc,16               ;Go to next line
2794         add hl,bc
2795         pop bc                  ;Restore data
2796         dnz _oloop
2797         ret                     ;<jp>s are used instead of <jr> = faster
2798
2799 ;--------------------------- putbigsprite -------------------------------------
2800
2801 putwidesprite:
2802         ld  a,d
2803         and 7
2804         ld  hl,offsets_table
2805         ld  c,a
2806         ld  b,0
2807         add hl,bc
2808         ld  a,(hl)
2809         ld  (wsmc1+1),a
2810         ld  (wsmc2+1),a
2811         ld  hl,(PutWhere)
2812
2813         ld  a,e
2814         add a,a
2815         add a,a
2816         add a,a
2817
2818         rl  b
2819         add a,a
2820         rl  b
2821         srl d
2822         srl d
2823         srl d
2824         add a,d
2825         jr  nc,n1
2826         inc b
2827 n1:     ld  c,a
2828         add hl,bc
2829
2830         ld  d,(ix)
2831         ld  b,(ix+1)
2832 woloop: psh bc                  ;Save # of rows
2833         psh hl                  ;Save screen address
2834         ld  b,d                 ;Load width
2835         ld  c,(ix+2)            ;Load one line of image
2836         inc ix
2837 wsmc1:  ld  a,1                 ;Load pixel mask
2838 wiloop: sla c                   ;Test leftmost pixel
2839         jr  nc,wnoplot          ;See if a plot is needed
2840         ld  e,a                 ;OR pixel with screen
2841         or  (hl)
2842         ld  (hl),a
2843         ld  a,e
2844 wnoplot:
2845         rrca
2846         jr  nc,wnotedge         ;Test if edge of byte reached
2847         inc hl                  ;Go to next byte
2848 wnotedge:
2849 wsmc2:  cp  1
2850         jr  z,wover_1
2851
2852         dnz wiloop
2853         pop hl                  ;Restore address
2854         ld  bc,16               ;Go to next line
2855         add hl,bc
2856         pop bc                  ;Restore data
2857         dnz woloop
2858         ret
2859 wover_1:
2860         ld  c,(ix+2)
2861         inc ix
2862         dnz wiloop
2863         dec ix
2864         pop hl
2865         ld  bc,16
2866         add hl,bc
2867         pop bc
2868         dnz woloop
2869         ret
2870
2871 ;------------------------------------------------------------------------------
2872 ;------------------------------- sprites --------------------------------------
2873 ;------------------------------------------------------------------------------
2874
2875 spr_ship01:
2876         .db 7,7         ;ship alpha class
2877         .db %01111000   ;  ████
2878         .db %11100000   ; ███
2879         .db %01111100   ;  █████
2880         .db %11110010   ; ████  █
2881         .db %01111100   ;  █████
2882         .db %11100000   ; ███
2883         .db %01111000   ;  ████
2884 spr_ship01i:
2885         .db 7,7         ;ship alpha class
2886         .db %00000000   ;
2887         .db %00000000   ;
2888         .db %00000000   ;
2889         .db %00000000   ;
2890         .db %00000000   ;
2891         .db %00000000   ;
2892         .db %00000000   ;
2893
2894         .db %01010000   ;  █ █
2895         .db %10100000   ; █ █
2896         .db %01010100   ;  █ █ █
2897         .db %10100010   ; █ █   █
2898         .db %01010100   ;  █ █ █
2899         .db %10100000   ; █ █
2900         .db %01010000   ;  █ █
2901
2902 spr_ship02:
2903 ;       .db 7,7         ;ship beta class
2904 ;       .db %11100000   ; ███
2905 ;       .db %11110000   ; ████
2906 ;       .db %01111100   ;  █████
2907 ;       .db %01110010   ;  ███  █
2908 ;       .db %01111100   ;  █████
2909 ;       .db %11110000   ; ████
2910 ;       .db %11100000   ; ███
2911 spr_ship02i:
2912 ;       .db 7,7         ;ship beta class
2913 ;       .db %01000000   ;  █
2914 ;       .db %10100000   ; █ █
2915 ;       .db %01010100   ;  █ █ █
2916 ;       .db %00100010   ;   █   █
2917 ;       .db %01010100   ;  █ █ █
2918 ;       .db %10100000   ; █ █
2919 ;       .db %01000000   ;  █
2920
2921 spr_multiple:
2922         .db 6,4         ;multiples
2923         .db %01111000   ;  ████
2924         .db %11111100   ; ██████
2925         .db %11111100   ; ██████
2926         .db %01111000   ;  ████
2927
2928 spr_bullet01:
2929         .db 5,3         ;your bullets
2930         .db %00110000   ;   ░▒▓█▒
2931         .db %11111000   ; ░▒▓████▒
2932         .db %00110000   ;   ░▒▓█▒
2933 spr_bullet02:
2934         .db 5,3
2935         .db %11110000   ; ░▒▓███▒
2936         .db %11111000   ; ░▒▓████▒
2937         .db %11110000   ; ░▒▓███▒
2938 spr_bullett1:
2939         .db 4,3         ;▒▒▒
2940         .db %11100000   ;▒███
2941         .db %11110000   ; ████
2942         .db %01110000   ;  ███
2943
2944 spr_bullete1:
2945         .db 4,3         ;enemy bullets
2946         .db %01100000   ;  ▒█▓▒░
2947         .db %11110000   ; ▒███▓▒░
2948         .db %01100000   ;  ▒█▓▒░
2949
2950 ;---------------------------------------- explosion -------------------------------------------
2951
2952 spr_explosion:
2953         .db 8,6         ;1
2954         .db %00000000
2955         .db %00011100   ;    ███
2956         .db %00111110   ;   █████
2957         .db %01010110   ;  █ █ ██
2958         .db %00111000   ;   ███
2959         .db %00000000
2960
2961         .db 8,6         ;2
2962         .db %00110000   ;   ██
2963         .db %01001110   ;  █ ▒███
2964         .db %10111110   ; █ █████
2965         .db %01001111   ;  █ ▒████
2966         .db %00111000   ;   ███
2967         .db %00011010   ;    ██ █
2968
2969         .db 8,6         ;3
2970         .db %10110000   ; █ ██
2971         .db %01001110   ;  █  ███
2972         .db %10110101   ; █ ██▒█▒█
2973         .db %01000101   ;  █  ▒█▒█
2974         .db %00111110   ;   █████
2975         .db %01011010   ;  █ ██ █
2976
2977         .db 8,6         ;4
2978         .db %00101010   ; ▒ █▒█ █
2979         .db %01000110   ;  █  ▒██
2980         .db %10110101   ; █ ██ █ █
2981         .db %01100110   ;  ██  ██▒
2982         .db %00111100   ;   ████▒
2983         .db %01011001   ;  █ ██ ▒█
2984
2985         .db 8,6         ;5
2986         .db %01000000   ;  █▒ ▒ ▒
2987         .db %00100101   ;  ▒█  █▒█
2988         .db %00010100   ; ▒ ▒█ █ ▒
2989         .db %01000100   ;  █▒  █
2990         .db %00010010   ;   ▒█▒▒█
2991         .db %10011010   ; █▒ ██ █▒
2992
2993         .db 8,6         ;6
2994         .db %01000100   ;  █   █
2995         .db %00100000   ;   ▒█ ▒ ▒
2996         .db %00000001   ;    ▒ ▒ █
2997         .db %01000100   ;  █   █
2998         .db %00100010   ;   █▒  █
2999         .db %01001000   ; ▒█ ▒█ ▒
3000
3001         .db 8,6         ;7
3002         .db %00001000   ;  ▒  █▒
3003         .db %11000010   ; ██ ▒  █
3004         .db %00000000   ;        ▒
3005         .db %00100000   ;  ▒█  ▒
3006         .db %00000001   ;   ▒   ▒█
3007         .db %00110000   ;  ▒██▒
3008
3009         .db 8,6         ;8
3010         .db %00000100   ;     ▒█
3011         .db %00000000   ; ▒▒    ▒
3012         .db %01000000   ;  █
3013         .db %00000000   ;   ▒
3014         .db %00000010   ;       █▒
3015         .db %00100100   ;   █▒ █
3016
3017 spr_yexplosion:
3018         .db 8,6         ;8
3019         .db %00000000   ;
3020         .db %00000000   ;
3021         .db %00000000   ;
3022         .db %00000000   ;
3023         .db %00000000   ;
3024         .db %00000000   ;
3025
3026 ;--------------------------------------- bar -----------------------------------
3027
3028 spr_iconhalf:
3029         .db 16,7        ;selected .......:
3030         .db %11111111           ; ████████
3031         .db %00000001           ;        █
3032         .db %00000001           ;        █
3033         .db %00000001           ;        █
3034         .db %00000001           ;        █
3035         .db %00000001           ;        █
3036         .db %11111111           ; ████████
3037 spr_icon:
3038         .db 16,7        ;selected .......:.......:
3039         .db %11111111,%11111111 ; ████████████████
3040         .db %11000000,%00000001 ; ██             █
3041         .db %11000000,%00000001 ; ██             █
3042         .db %11000000,%00000001 ; ██             █
3043         .db %11000000,%00000001 ; ██             █
3044         .db %11000000,%00000001 ; ██             █
3045         .db %11111111,%11111111 ; ████████████████
3046 spr_icon00:
3047         .db 16,7        ;unused   .......:.......:
3048         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
3049         .db %11010101,%01010101 ; ██ █ █ █ █ █ █ █
3050         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
3051         .db %11010101,%01010101 ; ██ █ █ █ █ █ █ █
3052         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
3053         .db %11010101,%01010101 ; ██ █ █ █ █ █ █ █
3054         .db %10101010,%10101010 ; █ █ █ █ █ █ █ █
3055 spr_icon01:
3056         .db 16,7        ;armor  ; .......:.......:
3057         .db %10000111,%11110000 ; █    ███████
3058         .db %10011000,%00001100 ; █  ██       ██
3059         .db %10110011,%11000110 ; █ ██  ████   ██
3060         .db %10110000,%11110110 ; █ ██    ████ ██
3061         .db %10110011,%11000110 ; █ ██  ████   ██
3062         .db %10011000,%00001100 ; █  ██       ██
3063         .db %10000111,%11110000 ; █    ███████
3064 spr_icon02:
3065         .db 16,7        ;torpedo  .......:.......:
3066         .db %10111000,%00010101 ; █ ███      █ █ █
3067         .db %10011100,%00010101 ; █  ███     █ █ █
3068         .db %10111000,%01001010 ; █ ███    █  █ █
3069         .db %10000000,%11101010 ; █       ███ █ █
3070         .db %11100001,%11100101 ; ███    ████  █ █
3071         .db %10011000,%11110101 ; █  ██   ████ █ █
3072         .db %11100110,%00110010 ; ███  ██   ██  █
3073 spr_icon03:
3074         .db 16,7        ;bullets  .......:.......:
3075         .db %10000000,%11000000 ; █       ██
3076         .db %10000011,%11100000 ; █     █████ ▒▒▒
3077         .db %10011000,%11000000 ; █  ██   ██  ▒▒▒
3078         .db %11111100,%00000000 ; ██████      ▒▒▒
3079         .db %10011000,%11000000 ; █  ██   ██  ▒▒▒
3080         .db %10000011,%11100000 ; █     █████ ▒▒▒
3081         .db %10000000,%11000000 ; █       ██
3082 spr_icon04:
3083         .db 16,7        ;laser    .......:.......:
3084         .db %10000000,%00000000 ; █
3085         .db %10110010,%10000000 ; █ ██  █ █
3086         .db %10111011,%00000000 ; █ ███ ██
3087         .db %10011101,%11111111 ; █  ███ █████████
3088         .db %10111011,%00000000 ; █ ███ ██
3089         .db %10110010,%10000000 ; █ ██  █ █
3090         .db %10000000,%00000000 ; █
3091 spr_icon05:
3092         .db 16,7        ;multiple .......:.......:
3093         .db %10000011,%10000000 ; █     ███
3094         .db %10000001,%11100110 ; █      ████  ██
3095         .db %10000001,%11100000 ; █      ████
3096         .db %10000011,%10000000 ; █     ███
3097         .db %10011000,%00000000 ; █  ██
3098         .db %10111100,%11000011 ; █ ████  ██    ██
3099         .db %10011000,%00000000 ; █  ██
3100 spr_dividerline:
3101         .db 8,7
3102         .db 128,128,128,128,128,128,128 ;128 = %10000000
3103
3104 ;---------------------------- texts -------------------------------------------
3105
3106 txt_about:      .db " v0.96.A30",127,"by Shiar",0
3107 txt_email:      .db "shiar0@hotmail.com",0
3108 txt_menu1:      .db "NEW GAME",0
3109 txt_menu2:      .db "CONTINUE",0
3110
3111 txt_level:      .db "LEVEL ",0
3112 txt_gameover:   .db "GAME OVER!",0
3113 txt_score:      .db "Score",0
3114 txt_hiscore:    .db "Hiscore",0
3115 txt_lives:      .db "Lx0?",0
3116
3117 txt_pressenter: .db "Enter to continue",0
3118 txt_teacher:    .db "(2",Lpi,"*.95)/sin 13",0
3119 txt_teacherans: .db Lneg,"14.2063168184",0
3120
3121 ;---------------------------- save data ---------------------------------------
3122
3123 PutWhere        .dw GRAPH_MEM           ;where to put the wide sprites
3124 laserlasts      .db 5
3125
3126 storehi_start:
3127 hiscore         .dw $0000
3128 hiname          .db "Shiar.96",0
3129 storehi_end:
3130
3131 storesave_start:
3132 level           .db $01                 ;level number
3133 levelp          .dw XLlevelsdata+4      ;pointer to level data
3134 pickuptimer     .db $04                 ;counts when to place a pickup
3135 score           .dw $0000
3136
3137 your_pickup     .db $00
3138 your_occ        .db $00                 ;0=normal 1..16=exploding
3139 your_inv        .db $00                 ;invincibility left
3140 your_armor      .db $0a                 ;HP left
3141 your_lives      .db $03                 ;
3142
3143 your_weapon     .db $02                 ;laser avail: 0=no, 1=yes
3144 your_multiples  .db $00                 ;multiples present
3145 torp_occ        .db $00                 ;torp.state: 0=unavail 1=avail 2=presnt
3146 torp_pos        .dw $0000               ;torpedo position (x,y)
3147 storesave_end:
3148
3149 ;----------------------------- logo -------------------------------------------
3150
3151 logo_nemesis:
3152 .db %11111111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%00001011,%11111111,%11111111,%11111111,%11111000
3153 .db %01111111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%00011011,%11111111,%11111111,%11111111,%11110000
3154 .db %00111111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%00111011,%11111111,%11111111,%11111111,%11100000
3155 .db %00011111,%11111111,%11111111,%11111110,%11111111,%11110111,%11111111,%11111110,%11111111,%111101111,%11111111,%01111011,%11111111,%11111111,%11111111,%11000000
3156 .db %00000000,%00000000,%00000001,%00011110,%00010000,%00000000,%10000001,%00011110,%00010000,%000000001,%00000000,%00001000,%01000000,%00000000,%00000000,%00000000
3157 .db %00000000,%00000000,%00000011,%00011110,%00110000,%00000001,%10000011,%00011110,%00110000,%000000011,%00000000,%00011000,%11000000,%00000000,%00000000,%00000000
3158 .db %00000000,%00000000,%00000111,%00011110,%01110000,%00000011,%10000111,%00011110,%01110000,%000000111,%00000000,%00111001,%11000000,%00000000,%00000000,%00000000
3159 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3160 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3161 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3162 .db %00000000,%00000000,%00001111,%00011110,%11111111,%00000111,%10001111,%00011110,%11111111,%000001111,%11111111,%01111011,%11111111,%11000000,%00000000,%00000000
3163 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3164 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3165 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3166 .db %00000000,%00000000,%00001111,%00011110,%11110000,%00000111,%10001111,%00011110,%11110000,%000000000,%00001111,%01111000,%00000011,%11000000,%00000000,%00000000
3167 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000111,%11010001
3168 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000001,%00011011
3169 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000001,%00010101
3170 .db %00000000,%00000000,%00001111,%00011110,%11111111,%11110111,%10001111,%00011110,%11111111,%111101111,%11111111,%01111011,%11111111,%11000000,%00000001,%00010001
3171
3172 ;----------------------------- end --------------------------------------------
3173
3174         .end
3175 .end
3176
3177
3178 ;------------------------------------------------------------------------------
3179
3180 ; 0.95.A22 -- 22.X.99 -- size 5321
3181 ;
3182 ;       * total size of enemy-sprites can now be 510 bytes (space = doubled!)
3183 ;       # bullets hit enemies correctly that aren't 6x6; even the 16x10 bosses!
3184 ;       * at g/o or nextlevel checks for keys released instead of waiting abit
3185 ;       + name stored with hiscore (max. 8 chars, Shiar.95 by default)
3186 ;       + when entering hi-name DEL goes back one char (with check 4 no chars)
3187 ;       # program is reloaded at start so some score-bugs solved! (_asapvar=0)
3188 ;       * at death, upgrades and pickups AREN'T removed! (just armor=0)
3189 ;       # bullet is not displayed after being removed anymore
3190 ;       # armor-icon stays hilighted when armor is decreased
3191 ;       * when stars move off screen, they are placed at a NEW y-pos!
3192 ;       * the starting x-positions of stars are not random, so the stars are
3193 ;         spread all over screen. y is still random and changes during game
3194 ;       * make_random functions smaller and used by different procs
3195 ;       # MAJOR BUG! a "random" value was placed somewhere in mem thus
3196 ;         creating bugs like unexplained loss of armor and stuff! (I think)
3197 ;
3198 ; 0.96.A31 -- 31.X.99 -- size 4836 + 888
3199 ;
3200 ;       # if you were hit when armor-icon selected, prog did weird stuff
3201 ;       + armor-bar (shows armor as a black line left at bottom)
3202 ;       # bugs involving armor-bar changing armor to a wrong value
3203 ;       # YES!!! the saving-bugs were caused by mmldir: it reset all data
3204 ;         at mem $8000, so data is now stored at asmexecram+6000 instead!
3205 ;       * external levels. All leveldata is loaded from "nemesis0"-var
3206 ;       * some optimization (like cal\ret>jp + unused code removed/shortened)
3207 ;       * storyline is loaded from level-file (will be compressed later..)
3208 ;       + story can be _between_ levels, not only at the start of a new game
3209 ;       * "new game" and "continue" in main menu are swapped (new comes 1st)
3210 ;       * enemy bullets can do more than one damage: differs per level
3211 ;       * collision does 4 damage, ground does 5, you start with 12 armor
3212 ;       # running the level-file no longer crashes your calc but just returns
3213 ;       * you now move 1.5 pixels per frame! this way you can outrun enemies
3214 ;       * hellofajob but enemy-data is now stored at one location in 6 bytes,
3215 ;         instead of two 4-byte spaces 40 bytes apart! (cleaner code; faster)
3216 ;       * ground/ceiling/stars are continued when at boss (c00l level 3 boss)
3217 ;
3218 ;
3219 ;        + added        - removed       * changed       # bug fixed
3220