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