home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / spazesrc.z80 < prev    next >
Encoding:
Text File  |  2001-07-01  |  90.3 KB  |  3,354 lines

  1. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  2. ;│█████ Z80 ██████│ Spaze Invaders │█████████████████████│ movax │████████████│
  3. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  4.  
  5. ; Spaze Invaders v1.1 by Hannes Edfeldt
  6.  
  7. ; Here's the source code to my game Spaze Invaders. I've released it to help
  8. ; other budding TI-83 asm programmers to get started. Don't forget to give me
  9. ; some credit if you use anything from my code. Have a nice day! =)
  10.  
  11. ; Hannes Edfeldt * movax@algonet.se * http://www.algonet.se
  12.  
  13.         .org     9327h
  14.  
  15. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  16. ;│█████ Z80 ██████│      MAIN      │█████████████████████│ movax │████████████│
  17. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  18.  
  19. START:
  20.         call    INIT            ; Init
  21.         call    INTRO           ; Intro
  22.         call    MENU01          ; Menu, wait for 2nd
  23.         call    MENU02          ; Menu, choose difficulty
  24.         call    LVINIT          ; Level init
  25.  
  26. MAIN:                           ; Normal level
  27.         call    KEYS            ; Read keys
  28.         call    SHIP            ; Update ship
  29.         call    LASER           ; Update laser
  30.         call    ALIENS          ; Move the aliens
  31.         call    ALASR           ; Alien laser
  32.         call    COLDT1          ; Collision detection between alien and laser
  33.         call    COLDT2          ; Collision detection between player and laser
  34.         call    COLDT3          ; Collision detection between barrier and laser
  35.         call    BUFCOPY         ; Copy graphbuf to LCD
  36.         call    ALIENY          ; Check if aliens has moved down to the bottom
  37.  
  38.         jp      MAIN
  39.  
  40. MBOSS:                          ; Boss level
  41.         call    KEYS            ; Read keys
  42.         call    BOSS            ; Manage boss an related stuff
  43.         call    SHIP            ; Update ship
  44.         call    COLDT2          ; Collision detection between player and laser
  45.         call    BUFCOPY         ; Copy graphbuf to LCD
  46.  
  47.         ld      a,(BOSSf)       ; Check if boss still is alive
  48.         cp      1
  49.         jp      z,MBOSS
  50.  
  51.         call    BOSSKILL        ; If not, call boss killed routine
  52.  
  53. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  54. ;│█████ Z80 ██████│   PROCEDURES   │█████████████████████│ movax │████████████│
  55. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  56.  
  57. ;▄████████████▀ NEWGAME ▀██████████████████████████████████████████████████████
  58. ;┌────────────────────────────────────────────────────────────────────────────┐
  59. ;│ Init for a new game                                                        │
  60. ;└────────────────────────────────────────────────────────────────────────────┘
  61. NEWGAME:
  62.         inc     sp              ; Don't return to GAMEOVER
  63.         inc     sp
  64.  
  65.         inc     sp              ; Don't return to ALIENY/COLDT2
  66.         inc     sp
  67.  
  68.         inc     sp              ; Don't return to MAIN/MBOSS
  69.         inc     sp
  70.  
  71.         ld      hl,858fh+100    ; -- Restore the variables start values
  72.         ld      de,SHIPx
  73.         ld      bc,DBYTES
  74.         ldir
  75.  
  76.         ld      a,0
  77.         ld      (SCOREb),a
  78.         ld      (SCOREb+1),a
  79.         ld      (STARTy),a
  80.  
  81.         ld      a,'0'
  82.         ld      (SCR1),a
  83.         ld      (SCR2),a
  84.         ld      (SCR3),a
  85.         ld      (SCR4),a
  86.  
  87.         ld      a,'1'
  88.         ld      (LEVELa),a
  89.  
  90.         ld      a,1
  91.         ld      (LEVELb),a
  92.         ld      (TIME),a
  93.  
  94.         ld      a,3
  95.         ld      (LIVESb),a
  96.         ld      a,'3'
  97.         ld      (LIVESa),a
  98.  
  99.         ld      hl,START        ; Make program ret to START
  100.         push    hl
  101.  
  102.         ret
  103. ;▄████████████▄ NEWGAME ▄██████████████████████████████████████████████████████
  104.  
  105.  
  106. ;▄████████████▀ INTRO ▀████████████████████████████████████████████████████████
  107. ;┌────────────────────────────────────────────────────────────────────────────┐
  108. ;│ Intro                                                                      │
  109. ;└────────────────────────────────────────────────────────────────────────────┘
  110. INTRO:
  111.  
  112.  
  113. ;████   Initiate for intro   ████
  114.  
  115.         call    BUFCLR          ; Clear the graphbuf
  116.         call    BUFCOPY         ; Copy graphbuf to LCD
  117.  
  118.         ld      hl,8e29h        ; Clear safe ram area
  119.         ld      de,8265h
  120.         ld      bc,768
  121.         ldir
  122.  
  123.         ld      hl,8e29h        ; Clear top of safe ram area 2
  124.         ld      de,858fh
  125.         ld      bc,80
  126.         ldir
  127.  
  128.  
  129. ;████   Alien Code text   ████
  130.  
  131.         res     7,(iy+20)
  132.  
  133.         ld      hl,0191eh       ; Print "Alien Code"
  134.         ld      (08252H),hl     ; Update cursorslocation
  135.         ld      hl,TXT6
  136.         call    04781h          ; Vputs
  137.  
  138.         ld      hl,01f22h       ; Print "presents"
  139.         ld      (08252H),hl     ; Update cursorslocation
  140.         ld      hl,TXT7
  141.         call    04781h          ; Vputs
  142.  
  143.         ld      b,4
  144. WAITL6:
  145.         push    bc
  146.         ld      hl,65535
  147.         call    WAIT
  148.         pop     bc
  149.         djnz    WAITL6
  150.  
  151.  
  152. ;████   Copy logo to graphbuf   ████
  153.  
  154. LOGO:
  155.         ld      hl,SPZLOGO      ; Copy logo to graphbuf
  156.         ld      de,8e29h+38
  157.  
  158.         ld      b,17
  159. YLOP1:  push    bc
  160.  
  161.         ld      b,8
  162. XLOP1:  ld      a,(hl)
  163.         ld      (de),a
  164.         inc     hl
  165.         inc     de
  166.         djnz    XLOP1
  167.  
  168.         pop     bc
  169.  
  170.         inc     de
  171.         inc     de
  172.         inc     de
  173.         inc     de
  174.  
  175.         djnz    YLOP1
  176.  
  177.  
  178. ;████   Do logo fx   ████
  179.  
  180. LOGOFX:
  181.         set     7,(iy+20)
  182.  
  183.         ld      hl,01413h       ; Print "By Hannes Edfeldt"
  184.         ld      (08252H),hl     ; Update cursorslocation
  185.         ld      hl,TXT1
  186.         call    04781h          ; Vputs
  187.  
  188.         ld      hl,8e29h        ; Copy graphbuf to safe ram area
  189.         ld      de,8265h
  190.         ld      bc,768
  191.         ldir
  192.  
  193.         ld      b,27
  194. FXLOP2: push    bc
  195.  
  196.         ld      a,(LOGOl)       ; Get line number
  197.         ld      e,a
  198.         ld      d,0
  199.  
  200.         ld      hl,0            ; Do hl=de*12
  201.         add     hl,de
  202.         add     hl,de
  203.         add     hl,de
  204.         add     hl,hl
  205.         add     hl,hl
  206.  
  207.         push    hl
  208.  
  209.         ld      bc,8e29h
  210.         add     hl,bc
  211.         ld      (TEMP),hl
  212.         ld      de,(TEMP)       ; de->graphbuf
  213.  
  214.         pop     hl
  215.  
  216.         ld      bc,8265h
  217.         add     hl,bc           ; hl->spzlogo
  218.  
  219.         ld      a,(LOGOl)       ; Calculate how many lines to draw
  220.         ld      c,a
  221.         ld      a,64
  222.         sub     c
  223.         ld      b,a
  224. FXLOP1: push    bc              ; Copy one line
  225.         ld      bc,12
  226.         ldir
  227.         ld      bc,-12
  228.         add     hl,bc
  229.         pop     bc
  230.         djnz    FXLOP1
  231.  
  232.         ld      hl,LOGOl        ; Update logoline counter
  233.         inc     (hl)
  234.  
  235.         call    BUFCOPY
  236.         ld      hl,12500
  237.         call    WAIT
  238.  
  239.         pop     bc
  240.         djnz    FXLOP2
  241.  
  242.         ld      hl,01e10h+7     ; - Print highscore text
  243.         ld      (08252H),hl     ; Update cursorslocation
  244.         ld      hl,HSCORE
  245.         call    04781h          ; Vputs
  246.  
  247.         ld      hl,01e34h+7     ; - Print highscore number
  248.         ld      (08252H),hl     ; Update cursorslocation
  249.         ld      hl,HSCR4
  250.         call    04781h          ; Vputs
  251.  
  252.         ld      hl,03a51h       ; Print "vX.X" (version number)
  253.         ld      (08252H),hl     ; Update cursorslocation
  254.         ld      hl,VERt
  255.         call    04781h          ; Vputs
  256.  
  257.         ret
  258. ;▄████████████▄ INTRO ▄████████████████████████████████████████████████████████
  259.  
  260.  
  261. ;▄████████████▀ MENU01 ▀███████████████████████████████████████████████████████
  262. ;┌────────────────────────────────────────────────────────────────────────────┐
  263. ;│ Menu part 1                                                                │
  264. ;└────────────────────────────────────────────────────────────────────────────┘
  265. MENU01:
  266.  
  267. ;████   Prepare for textflash   ████
  268.  
  269.         ld      hl,8e29h        ; Copy graphbuf to safe ram area
  270.         ld      de,8265h
  271.         ld      bc,768
  272.         ldir
  273.  
  274.         ld      hl,00011h       ; - Print "PRESS 2nd TO START"
  275.         ld      (08252H),hl     ; Update cursorlocation
  276.         ld      hl,TXT2
  277.         call    04781h          ; Vputs
  278.  
  279.         ld      hl,8e29h        ; Copy top of graphbuf to safe ram area 2
  280.         ld      de,858fh
  281.         ld      bc,72
  282.         ldir
  283.  
  284.         ld      de,8e29h        ; Copy safe ram area to graphbuf
  285.         ld      hl,8265h
  286.         ld      bc,768
  287.         ldir
  288.  
  289.  
  290. ;████████   Menu loop   ████
  291.  
  292. MENUL:
  293.  
  294.  
  295. ;████   Textflash   ████
  296.  
  297.         ld      a,(FLASHt)      ; Time to flash text?
  298.         inc     a
  299.         ld      (FLASHt),a
  300.         cp      32
  301.         jp      nz,SKP13
  302.  
  303.         ld      a,0
  304.         ld      (FLASHt),a
  305.  
  306.         ld      a,(FLASHf)      ; Get flashflag
  307.         cp      1
  308.         jp      z,ERASE1
  309.  
  310. DRAW1:  ld      hl,858fh
  311.         ld      de,8e29h+540
  312.         ld      bc,72
  313.         ldir
  314.         ld      a,1
  315.         ld      (FLASHf),a
  316.         jp      SKP13
  317.  
  318. ERASE1: ld      hl,8e29h+612
  319.         ld      de,8e29h+540
  320.         ld      bc,72
  321.         ldir
  322.         ld      a,0
  323.         ld      (FLASHf),a
  324. SKP13:
  325.  
  326.         call    BUFCOPY
  327.  
  328. SKP29:
  329.         ld      a,0ffh          ; Reset the keyport (kinda)
  330.         out     (1),a
  331.         ld      a,0bfh          ; Enable the row with 2nd
  332.     out    (1),a
  333.     in    a,(1)
  334.         cp      223             ; Has anyone pressed 2nd?
  335.         jp      nz,MENUL
  336.  
  337.         ret
  338. ;▄████████████▄ MENU01 ▄███████████████████████████████████████████████████████
  339.  
  340.  
  341. ;▄████████████▀ MENU02 ▀███████████████████████████████████████████████████████
  342. ;┌────────────────────────────────────────────────────────────────────────────┐
  343. ;│ Menu part 2                                                                │
  344. ;└────────────────────────────────────────────────────────────────────────────┘
  345. MENU02:
  346.  
  347.  
  348. ;████   Prepare for diff. menu   ████
  349.  
  350.         call    READKEY         ; Fetch last 2nd press
  351.  
  352.         ld      hl,9009h        ; Erase "PRESS 2nd TO START" msg
  353.         ld      de,8e29h+540
  354.         ld      bc,72
  355.         ldir
  356.  
  357.         ld      hl,02629h       ; - Print "EASY"
  358.         ld      (08252H),hl     ; Update cursorlocation
  359.         ld      hl,TXT3
  360.         call    04781h          ; Vputs
  361.  
  362.         ld      hl,02d25h       ; - Print "MEDIUM"
  363.         ld      (08252H),hl     ; Update cursorlocation
  364.         ld      hl,TXT4
  365.         call    04781h          ; Vputs
  366.  
  367.         ld      hl,03429h       ; - Print "HARD"
  368.         ld      (08252H),hl     ; Update cursorlocation
  369.         ld      hl,TXT5
  370.         call    04781h          ; Vputs
  371.  
  372.         ld      hl,38*12+8e29h
  373.         ld      b,7
  374. INVL2:  ld      de,4            ; Invert loop
  375.         add     hl,de
  376.         ld      a,(hl)
  377.         cpl
  378.         and     01111111b
  379.         ld      (hl),a
  380.         inc     hl
  381.         ld      a,(hl)
  382.         cpl
  383.         ld      (hl),a
  384.         inc     hl
  385.         ld      a,(hl)
  386.         cpl
  387.         ld      (hl),a
  388.         inc     hl
  389.         ld      a,(hl)
  390.         cpl
  391.         ld      (hl),a
  392.         ld      de,5
  393.         add     hl,de
  394.         djnz    INVL2
  395.  
  396.         call    BUFCOPY
  397.  
  398.  
  399. ;████████   Menu loop 2   ████
  400.  
  401. MENUL2:
  402.         ld      a,0ffh          ; Reset the keyport (kinda)
  403.         out     (1),a
  404.         ld      a,0fdh          ; Enable the row with clear
  405.     out    (1),a
  406.     in    a,(1)
  407.         cp      191             ; Check for clear
  408.         jp      nz,NOCLR_3
  409.  
  410.         inc     sp
  411.         inc     sp
  412.         call    XIT
  413.  
  414. NOCLR_3:
  415.         ld      hl,MENUt        ; Time to check for new arrowpress?
  416.         ld      a,(hl)
  417.         cp      12
  418.         jp      nz,SKP33
  419.  
  420.  
  421.         ld      a,0ffh          ; Reset the keyport (kinda)
  422.         out     (1),a
  423.         ld      a,0feh          ; Enable the arrows
  424.         out     (1),a
  425.         in      a,(1)
  426.  
  427.         cp      247             ; Pressed up?
  428.         jp      nz,NOUP
  429.  
  430.         ld      hl,MENUt        ; Reset timer
  431.         ld      (hl),0
  432.  
  433.         ld      a,(MENUc)       ; Update old menu choice
  434.         ld      (MENUoc),a
  435.  
  436.         ld      hl,MENUc        ; Move bar
  437.         dec     (hl)
  438.         ld      a,(hl)
  439.         cp      0
  440.         jp      nz,NOUP
  441.         ld      (hl),3          ; Warp
  442.  
  443. NOUP:
  444.         cp      254             ; Pressed down?
  445.         jp      nz,NODOWN
  446.  
  447.         ld      hl,MENUt        ; Reset timer
  448.         ld      (hl),0
  449.  
  450.         ld      a,(MENUc)       ; Update old menu choice
  451.         ld      (MENUoc),a
  452.  
  453.         ld      hl,MENUc        ; Move bar
  454.         inc     (hl)
  455.         ld      a,(hl)
  456.         cp      4
  457.         jp      nz,NODOWN
  458.         ld      (hl),1          ; Warp
  459.  
  460. NODOWN:
  461.         ld      a,(MENUt)       ; Has the bar moved?
  462.         cp      0
  463.         jp      nz,SKP33
  464.  
  465.         ld      hl,MENUc
  466.         ld      b,2             ; Loop to do two inverts (old and new bar)
  467. BARL1:
  468.         ld      a,(hl)
  469.         dec     a
  470.         ld      l,a
  471.         ld      h,84
  472.         push    bc
  473.         call    HTIMESL
  474.         pop     bc
  475.         ld      de,(38*12)+8e29h
  476.         add     hl,de
  477.  
  478.         push    bc
  479.         ld      b,7             ; Invert loop
  480. BARL2:  ld      de,4
  481.         add     hl,de
  482.         ld      a,(hl)
  483.         cpl
  484.         and     01111111b
  485.         ld      (hl),a
  486.         inc     hl
  487.         ld      a,(hl)
  488.         cpl
  489.         ld      (hl),a
  490.         inc     hl
  491.         ld      a,(hl)
  492.         cpl
  493.         ld      (hl),a
  494.         inc     hl
  495.         ld      a,(hl)
  496.         cpl
  497.         ld      (hl),a
  498.         ld      de,5
  499.         add     hl,de
  500.         djnz    BARL2
  501.  
  502.         pop     bc
  503.         ld      hl,MENUc
  504.         inc     hl
  505.         djnz    BARL1
  506.  
  507.  
  508. SKP33:
  509.         call    BUFCOPY
  510.         ld      hl,MENUt
  511.         ld      a,(hl)
  512.         cp      12
  513.         jp      z,SKP32
  514.         inc     (hl)
  515.  
  516. SKP32:
  517.         call    READKEY         ; Look for a 2nd press
  518.         call    OP2TOP1
  519.         call    CONVOP1
  520.         cp      21
  521.         jp      nz,MENUL2
  522.  
  523.         ld      a,(MENUc)       ; Set difficulty after menu choice
  524.         ld      (DIFF),a
  525.  
  526.         ret
  527. ;▄████████████▄ MENU02 ▄███████████████████████████████████████████████████████
  528.  
  529.  
  530. ;▄████████████▀ OUTRO ▀████████████████████████████████████████████████████████
  531. ;┌────────────────────────────────────────────────────────────────────────────┐
  532. ;│ Outro                                                                      │
  533. ;└────────────────────────────────────────────────────────────────────────────┘
  534. OUTRO:
  535.         call    BUFCLR          ; Clear the graphbuf
  536.         call    BUFCOPY
  537.  
  538.         set     7,(iy+20)
  539.  
  540.         ld      hl,00010h       ; - Print "CONGRATULATIONS!!!"
  541.         ld      (08252h),hl     ; Update cursorslocation
  542.         ld      hl,MSG06
  543.         call    04781h          ; Vputs
  544.  
  545.         ld      hl,0070ch       ; - Print "You have saved all the"
  546.         ld      (08252h),hl     ; Update cursorslocation
  547.         ld      hl,MSG07
  548.         call    04781h          ; Vputs
  549.  
  550.         ld      hl,00d09h       ; - Print "hamsters on earth from"
  551.         ld      (08252h),hl     ; Update cursorslocation
  552.         ld      hl,MSG08
  553.         call    04781h          ; Vputs
  554.  
  555.         ld      hl,0130dh       ; - Print "the evil aliens' claws"
  556.         ld      (08252h),hl     ; Update cursorslocation
  557.         ld      hl,MSG09
  558.         call    04781h          ; Vputs
  559.  
  560.         ld      hl,01c16h+7     ; - Print score text
  561.         ld      (08252H),hl     ; Update cursorslocation
  562.         ld      hl,SCORE
  563.         call    04781h          ; Vputs
  564.  
  565.         ld      hl,01c2dh+7     ; - Print score number
  566.         ld      (08252H),hl     ; Update cursorslocation
  567.         ld      hl,SCR4
  568.         call    04781h          ; Vputs
  569.  
  570.         ld      hl,02417h       ; - Print "Have a nice day!"
  571.         ld      (08252h),hl     ; Update cursorslocation
  572.         ld      hl,MSG10
  573.         call    04781h          ; Vputs
  574.  
  575.         ld      hl,02d1eh       ; - Print "ALIEN CODE"
  576.         ld      (08252h),hl     ; Update cursorslocation
  577.         ld      hl,TXT6
  578.         call    04781h          ; Vputs
  579.  
  580.         ld      hl,03311h       ; - Print "movax@algonet.se"
  581.         ld      (08252h),hl     ; Update cursorslocation
  582.         ld      hl,MSG11
  583.         call    04781h          ; Vputs
  584.  
  585.         ld      hl,03905h       ; - Print "www.algonet.se/~movax"
  586.         ld      (08252h),hl     ; Update cursorslocation
  587.         ld      hl,MSG12
  588.         call    04781h          ; Vputs
  589.  
  590.         ld      hl,8e29h        ; Copy graphbuf to safe ram area
  591.         ld      de,8265h
  592.         ld      bc,768
  593.         ldir
  594.  
  595.         call    BUFCLR          ; Clear the graphbuf
  596.  
  597.         ld      hl,0            ; Bytes to write
  598.         ld      (TEMP),hl
  599.  
  600.         ld      hl,8e29h+768    ; Destination
  601.         ld      (TEMP2),hl
  602.  
  603.         ld      b,64
  604. YSCRLL: push    bc
  605.         ld      bc,12           ; - Update bytes to write
  606.         ld      hl,(TEMP)
  607.         add     hl,bc
  608.         ld      (TEMP),hl
  609.  
  610.         ld      bc,-12          ; - Update destination
  611.         ld      hl,(TEMP2)
  612.         add     hl,bc
  613.         ld      (TEMP2),hl
  614.  
  615.         ld      de,(TEMP2)
  616.         ld      hl,8265h
  617.         ld      bc,(TEMP)
  618.         ldir
  619.  
  620.         ld      b,8             ; Wait for a while
  621. WAITL5:
  622.         push    bc
  623.         call    BUFCOPY
  624.         pop     bc
  625.         djnz    WAITL5
  626.  
  627.         pop     bc
  628.         djnz    YSCRLL
  629.  
  630.         call    WAIT2ND
  631.         call    GAMEOVER
  632.  
  633.         ret
  634. ;▄████████████▄ OUTRO ▄████████████████████████████████████████████████████████
  635.  
  636.  
  637. ;▄████████████▀  BOSS  ▀███████████████████████████████████████████████████████
  638. ;┌────────────────────────────────────────────────────────────────────────────┐
  639. ;│ Manage the boss and related stuff                                          │
  640. ;└────────────────────────────────────────────────────────────────────────────┘
  641. BOSS:
  642.  
  643.  
  644. ;████   Boss shot part 1 ████
  645.  
  646.         ld      a,(ALASRt)      ; Is timer 0 yet?
  647.         cp      0
  648.         jp      z,SKP56
  649.  
  650.         ld      hl,ALASRt       ; Nope, update timer
  651.         dec     (hl)
  652.         jp      SKP57
  653.  
  654. SKP56:
  655.         ld      hl,BOSSlt
  656.         inc     (hl)
  657.  
  658.         ld      a,(ALASRf)      ; Look for boss shot
  659.         cp      1
  660.         jp      z,UPBLSR1       ; Jump to update shot if there already is one
  661.  
  662.         ld      a,(SHIPx)       ; Move ship x value to boss shot destination
  663.         add     a,6
  664.         ld      (BOSSld),a
  665.  
  666.         ld      a,1             ; Set laserflag
  667.         ld      (ALASRf),a
  668.  
  669.         ld      a,(BOSSx)       ; Boss shot init x-coordinate
  670.         add     a,12
  671.         ld      (ALASRx),a
  672.  
  673.         ld      a,40            ; Boss shot init y-coordinate
  674.         ld      (ALASRy),a
  675.  
  676.         jp      SKP57
  677.  
  678. UPBLSR1:
  679.         ld      a,(ALASRy)      ; Erase old laserbeam
  680.         ld      e,a
  681.         ld      a,(ALASRx)
  682.         ld      hl,25*8+SPRITES
  683.         call    CLRSPR
  684.  
  685.         ld      a,(ALASRy)      ; Update boss shot y-coordinate
  686.         ld      b,a
  687.         ld      a,(BOSSlt)
  688.         and     00000001b
  689.         cp      0
  690.         jp      nz,SKP59
  691.         ld      a,b
  692.         inc     a
  693.         ld      (ALASRy),a
  694.         cp      57              ; Has boss shot reached the bottom?
  695.         jp      nz,SKP59
  696.  
  697.         ld      a,0             ; Reset laserflag
  698.         ld      (ALASRf),a
  699.  
  700.         ld      a,16
  701.         ld      (ALASRt),a
  702.         jp      SKP57
  703.  
  704. SKP59:  ld      a,(BOSSlt)
  705.         and     00000001b
  706.         cp      1
  707.         jp      nz,SKP57
  708.  
  709.         ld      a,(BOSSld)      ; -- Update boss shot x-coordinate
  710.         ld      b,a
  711.         ld      a,(ALASRx)
  712.         cp      b
  713.         jp      nz,SKP61
  714.  
  715.         jp      SKP57
  716.  
  717. SKP61:
  718.         cp      b
  719.         jp      c,SKP60
  720.  
  721.         dec     a
  722.         ld      (ALASRx),a
  723.         jp      SKP57
  724.  
  725. SKP60:  inc     a
  726.         ld      (ALASRx),a
  727.  
  728. SKP57:
  729.  
  730. ;████   Ship laser part 1 ████
  731.  
  732.         ld      a,(LTIMER)      ; Has timer reached zero yet?
  733.         cp      0
  734.         jp      z,SKP50
  735.         ld      hl,LTIMER       ; Update laser timer
  736.         dec     (hl)
  737.  
  738. SKP50:
  739.         ld      a,(SLASRy)      ; Is there a laserbeam to update?
  740.         cp      252
  741.         jp      z,SKP52
  742.  
  743.         ld      a,(SLASRy)      ; Erase old laserbeam
  744.         ld      e,a
  745.         ld      a,(SLASRx)
  746.         ld      hl,80+SPRITES
  747.         call    CLRSPR
  748.  
  749. SKP52:
  750.  
  751. ;████   Boss movement   ████
  752.  
  753.         ld      hl,BOSSmc       ; Time to move boss?
  754.         inc     (hl)
  755.         ld      a,(hl)
  756.         cp      4
  757.         jp      nz,SKP41
  758.  
  759.         ld      (hl),0
  760.  
  761.         ld      hl,BOSSxc       ; Time to change direction?
  762.         inc     (hl)
  763.         ld      a,(hl)
  764.         cp      64
  765.         jp      nz,SKP40
  766.  
  767.         ld      (hl),0          ; Change direction
  768.         ld      a,(BOSSmd)
  769.         neg
  770.         ld      (BOSSmd),a
  771.  
  772. SKP40:  ld      a,(BOSSmd)
  773.         cp      1
  774.         jp      nz,MOVLEFT
  775.  
  776. MOVRGTH:
  777.         ld      hl,8e29h+96     ; Move right
  778.         ld      b,32
  779. BMOVL1: push    bc
  780.  
  781.         ld      b,12
  782.         and     a
  783. BMOVL2: ld      a,(hl)
  784.         rr      a
  785.         ld      (hl),a
  786.         inc     hl
  787.         djnz    BMOVL2
  788.  
  789.         pop     bc
  790.         djnz    BMOVL1
  791.  
  792.         ld      hl,BOSSx
  793.         inc     (hl)
  794.  
  795.         jp      SKP41
  796.  
  797.  
  798. MOVLEFT:
  799.         ld      hl,8e29h+383+96 ; Move left
  800.         ld      b,32
  801. BMOVL3: push    bc
  802.  
  803.         ld      b,12
  804.         and     a
  805. BMOVL4: ld      a,(hl)
  806.         rl      a
  807.         ld      (hl),a
  808.         dec     hl
  809.         djnz    BMOVL4
  810.  
  811.         pop     bc
  812.         djnz    BMOVL3
  813.  
  814.         ld      hl,BOSSx
  815.         dec     (hl)
  816.  
  817. SKP41:
  818.  
  819.  
  820. ;████   Boss and laser collision   ████
  821.  
  822.         ld      a,(SLASRy)      ; Check y
  823.         cp      41
  824.         jp      nc,SKP54
  825.  
  826.         ld      a,(SLASRx)      ; Check x left edge
  827.         ld      b,a
  828.         inc     b
  829.         ld      a,(BOSSx)
  830.         cp      b
  831.         jp      nc,SKP54
  832.  
  833.         add     a,32            ; Check x right edge
  834.         cp      b
  835.         jp      c,SKP54
  836.  
  837.         ld      hl,BOSShl
  838.         dec     (hl)
  839.         ld      a,(hl)
  840.         cp      0
  841.         jp      nz,SKP55
  842.  
  843.         ld      a,(DIFF)
  844.         ld      (hl),a
  845.  
  846.         ld      b,3             ; Three pixels wide health point to erase
  847. HPL4:   push    bc
  848.  
  849.         ld      hl,8e29h+23     ; Erase health point
  850.         ld      b,4
  851. HPL2:   push    bc
  852.  
  853.         and     a
  854.         ld      b,12
  855. HPL3:   ld      a,(hl)
  856.         rl      a
  857.         ld      (hl),a
  858.         dec     hl
  859.         djnz    HPL3
  860.  
  861.         ld      bc,24
  862.         add     hl,bc
  863.  
  864.         pop     bc
  865.         djnz    HPL2
  866.  
  867.         pop     bc
  868.         djnz    HPL4
  869.  
  870.         ld      hl,BOSShp       ; Update boss health points
  871.         dec     (hl)
  872.         ld      a,(hl)
  873.         cp      0
  874.         jp      nz,SKP55
  875.  
  876.         ld      a,0
  877.         ld      (BOSSf),a
  878.  
  879. SKP55:
  880.  
  881.         ld      a,240           ; Make boss freeze for a while
  882.         ld      (BOSSmc),a
  883.  
  884.         ld      a,32            ; Initiate laser timer
  885.         ld      (LTIMER),a
  886.  
  887.         ld      a,252           ; Stop shiplaserbeam
  888.         ld      (SLASRy),a
  889.  
  890.         call    USCORE          ; Update score
  891.  
  892. SKP54:
  893.  
  894.  
  895. ;████   Ship laser part 2   ████
  896.  
  897.         ld      a,(SLASRy)      ; Is there a laserbeam to update?
  898.         cp      252
  899.         jp      z,SKP53
  900.  
  901.         ld      a,(SLASRy)      ; Has the laserbeam reached the top yet?
  902.         cp      6
  903.         jp      nz,SKP51
  904.  
  905.         ld      a,252
  906.         ld      (SLASRy),a
  907.         jp      SKP53
  908.  
  909. SKP51:
  910.         ld      hl,SLASRy       ; Move laserbeam two pixels up
  911.         dec     (hl)
  912.         dec     (hl)
  913.  
  914.         ld      a,(SLASRy)      ; Draw new laserbeam
  915.         ld      e,a
  916.         ld      a,(SLASRx)
  917.         ld      hl,80+SPRITES
  918.         call    SPRITE
  919.  
  920. SKP53:
  921.  
  922. ;████   Boss shot part 2 ████
  923.  
  924.         ld      a,(ALASRf)
  925.         cp      1
  926.         jp      nz,SKP58
  927.  
  928.         ld      a,(ALASRy)      ; Draw new laserbeam
  929.         ld      e,a
  930.         ld      a,(ALASRx)
  931.         ld      hl,25*8+SPRITES
  932.         call    SPRITE
  933.  
  934. SKP58:
  935.         ret
  936. ;▄████████████▄  BOSS  ▄███████████████████████████████████████████████████████
  937.  
  938.  
  939. ;▄████████████▀ BOSSKILL ▀█████████████████████████████████████████████████████
  940. ;┌────────────────────────────────────────────────────────────────────────────┐
  941. ;│ Boss killed                                                                │
  942. ;└────────────────────────────────────────────────────────────────────────────┘
  943. BOSSKILL:
  944.  
  945.         ld      ix,BOSSkr       ; Get pointer to boss kill random
  946.  
  947.         ld      b,16
  948. BKILL2:                         ; Loop to erase boss with cross sprite
  949.         ld      a,(BOSSx)
  950.         add     a,(ix+0)
  951.         inc     ix
  952.         ld      e,(ix+0)
  953.         inc     ix
  954.  
  955.         push    ix
  956.         push    bc
  957.  
  958.         push    af
  959.         push    de
  960.         ld      hl,SPRITES
  961.         call    CLRSPR          ; Clear a 8x8 part of the boss
  962.         pop     de
  963.         pop     af
  964.  
  965.         push    af
  966.         push    de
  967.         ld      hl,SPRITES+72
  968.         call    SPRITE          ; Put the cross
  969.         call    BUFCOPY
  970.         ld      hl,24000
  971.         call    WAIT            ; Wait for a while
  972.         pop     de
  973.         pop     af
  974.  
  975.         ld      hl,SPRITES
  976.         call    CLRSPR          ; Clear cross
  977.  
  978.         pop     bc
  979.         pop     ix
  980.  
  981.         djnz    BKILL2
  982.  
  983.         call    BUFCOPY
  984.         ld      hl,40000
  985.         call    WAIT            ; Wait for a while
  986.  
  987.         call    STGCLR
  988.  
  989.         ret
  990. ;▄████████████▄ BOSSKILL ▄█████████████████████████████████████████████████████
  991.  
  992.  
  993. ;▄████████████▀ ALIENY ▀███████████████████████████████████████████████████████
  994. ;┌────────────────────────────────────────────────────────────────────────────┐
  995. ;│ Check if aliens has reached the last line                                  │
  996. ;└────────────────────────────────────────────────────────────────────────────┘
  997. ALIENY:
  998.         ld      a,(ALIENmy)     ; Look for alien movement change
  999.         cp      0
  1000.         ret     nz
  1001.  
  1002.         ld      c,26            ; Get right y-value to compare with
  1003.         ld      hl,ALIENr4
  1004.         ld      b,3
  1005. GETYL:  ld      a,(hl)
  1006.         cp      0
  1007.         jp      nz,LXIT01
  1008.         ld      a,c
  1009.         add     a,10
  1010.         ld      c,a
  1011.         dec     hl
  1012.         djnz    GETYL
  1013.  
  1014. LXIT01:
  1015.         ld      a,(ALIENli)
  1016.         cp      c
  1017.         jp      nz,DONE9
  1018.  
  1019.  
  1020. ;████   Aliens has reached bottom   ████
  1021.  
  1022.         ld      b,6
  1023. INVL5:
  1024.         push    bc
  1025.         call    INVERT
  1026.         pop     bc
  1027.         djnz    INVL5
  1028.  
  1029.         ld      a,0
  1030.         ld      (LIVESb),a
  1031.         ld      a,'0'
  1032.         ld      (LIVESa),a
  1033.  
  1034.         call    STAT            ; Show stats in a box and wait for 2nd
  1035.  
  1036.         ld      hl,02621h       ; - Print msg to press 2nd
  1037.         ld      (08252h),hl     ; Update cursorslocation
  1038.         ld      hl,MSG01
  1039.         call    04781h          ; Vputs
  1040.  
  1041.         call    WAIT2ND         ; Wait for 2nd to be pressed
  1042.  
  1043.         ld      de,8e29h        ; Copy safe ram area to graphbuf
  1044.         ld      hl,8265h
  1045.         ld      bc,768
  1046.         ldir
  1047.  
  1048.         call    GAMEOVER
  1049.  
  1050. DONE9:
  1051.         ret
  1052. ;▄████████████▄ ALIENY ▄███████████████████████████████████████████████████████
  1053.  
  1054.  
  1055. ;▄████████████▀  MATH  ▀███████████████████████████████████████████████████████
  1056. ;┌────────────────────────────────────────────────────────────────────────────┐
  1057. ;│ Mathsteacher key                                                           │
  1058. ;└────────────────────────────────────────────────────────────────────────────┘
  1059. MATH:
  1060.         ld      hl,8e29h        ; Copy graphbuf to safe ram area
  1061.         ld      de,8265h
  1062.         ld      bc,768
  1063.         ldir
  1064.  
  1065.         call    BUFCLR          ; Clear graphbuf
  1066.         call    BUFCOPY
  1067.  
  1068.         call    HOMEUP
  1069.  
  1070.         ld      hl,MSG05
  1071.         call    STRING
  1072.  
  1073.         call    READKEY         ; Fetch first MATH press
  1074.  
  1075. KEYL3:
  1076.         call    READKEY         ; Wait for MATH press
  1077.         call    OP2TOP1
  1078.         call    CONVOP1
  1079.         cp      41
  1080.         jp      nz,KEYL3
  1081.  
  1082.         ld      de,8e29h        ; Copy safe ram area to graphbuf
  1083.         ld      hl,8265h
  1084.         ld      bc,768
  1085.         ldir
  1086.  
  1087.         call    BUFCOPY
  1088.  
  1089.         ld      hl,65000
  1090.         call    WAIT
  1091.  
  1092.         ret
  1093. ;▄████████████▄  MATH  ▄███████████████████████████████████████████████████████
  1094.  
  1095.  
  1096. ;▄████████████▀ STGCLR ▀███████████████████████████████████████████████████████
  1097. ;┌────────────────────────────────────────────────────────────────────────────┐
  1098. ;│ Stage cleared                                                              │
  1099. ;└────────────────────────────────────────────────────────────────────────────┘
  1100. STGCLR:
  1101.         inc     sp              ; Don't return to ALIENS/BOSSKILL
  1102.         inc     sp
  1103.  
  1104.         inc     sp              ; Don't return to MAIN/MBOSS
  1105.         inc     sp
  1106.  
  1107.  
  1108. ;████   Draw a box and print info   ████
  1109.  
  1110.         ld      a,20            ; Draw a box
  1111.         ld      e,12
  1112.         ld      b,5
  1113.         ld      c,2
  1114.         call    BOX
  1115.  
  1116.         set     7,(iy+20)
  1117.  
  1118.         ld      hl,01018h       ; - Print Stage Cleared!
  1119.         ld      (08252H),hl     ; Update cursorslocation
  1120.         ld      hl,MSG04
  1121.         call    04781h          ; Vputs
  1122.  
  1123.         ld      hl,01920h       ; - Print "BONUS:"
  1124.         ld      (08252H),hl     ; Update cursorslocation
  1125.         ld      hl,BONUS
  1126.         call    04781h          ; Vputs
  1127.  
  1128.         ld      hl,01935h       ; - Print bonus points
  1129.         ld      (08252H),hl     ; Update cursorslocation
  1130.         ld      hl,BONUS3
  1131.         call    04781h          ; Vputs
  1132.  
  1133.         call    BUFCOPY
  1134.  
  1135. ;████   Bonus counter   ████
  1136.  
  1137.         ld      a,(BONUSt2)     ; Get number of bonus points
  1138.         cp      0
  1139.         jp      z,SKP84
  1140.         ld      b,a
  1141. SCRL4:  push    bc
  1142.  
  1143.         ld      hl,(SCOREb)       ; Give player one point
  1144.         inc     hl
  1145.         ld      (SCOREb),hl
  1146.  
  1147.         ld      hl,SCR1         ; -- Update the ascii score
  1148.         inc     (hl)
  1149.  
  1150.         ld      b,3             ; Look for overflow loop
  1151. SCRL3:  ld      a,(hl)
  1152.         cp      ':'
  1153.         jp      nz,SKP80
  1154.         ld      (hl),'0'
  1155.         dec     hl
  1156.         inc     (hl)
  1157.         djnz    SCRL3
  1158.  
  1159. SKP80:
  1160.         ld      hl,BONUS1       ; -- Update the bonus score
  1161.         inc     (hl)
  1162.  
  1163.         ld      b,3             ; Look for overflow loop
  1164. SCRL5:  ld      a,(hl)
  1165.         cp      ':'
  1166.         jp      nz,SKP81
  1167.         ld      (hl),'0'
  1168.         dec     hl
  1169.         inc     (hl)
  1170.         djnz    SCRL5
  1171.  
  1172. SKP81:
  1173.         ld      hl,01935h       ; - Print bonus points
  1174.         ld      (08252H),hl     ; Update cursorslocation
  1175.         ld      hl,BONUS3
  1176.         call    04781h          ; Vputs
  1177.  
  1178.         call    BUFCOPY
  1179.  
  1180.         pop     bc
  1181.         djnz    SCRL4
  1182.  
  1183. SKP84:
  1184.         ld      hl,02221h       ; - Print msg to press 2nd
  1185.         ld      (08252H),hl     ; Update cursorslocation
  1186.         ld      hl,MSG01
  1187.         call    04781h          ; Vputs
  1188.  
  1189.         call    BUFCOPY
  1190.         call    WAIT2ND
  1191.  
  1192.  
  1193. ;████   Update variables   ████
  1194.  
  1195.         ld      hl,858fh+100    ; Restore the variables start values
  1196.         ld      de,SHIPx
  1197.         ld      bc,DBYTES
  1198.         ldir
  1199.  
  1200.         ld      hl,TIME         ; Time for a boss level?
  1201.         inc     (hl)
  1202.         ld      a,(hl)
  1203.         cp      3
  1204.         jp      nz,SKP70
  1205.         ld      (hl),0
  1206.         ld      a,1
  1207.         ld      (BOSSf),a
  1208.         jp      SKP71
  1209.  
  1210. SKP70:
  1211.         ld      a,(STARTy)
  1212.         add     a,2
  1213.         ld      (STARTy),a
  1214.         ld      c,a
  1215.         ld      ix,ALIENd1+2    ; - Update aliens y-coordinates
  1216.         ld      (ALIENli),a     ; Update nr of lines aliens has moved down
  1217.         ld      de,3
  1218.         ld      b,32
  1219. LOOP01: ld      a,(ix+0)
  1220.         add     a,c
  1221.         ld      (ix+0),a
  1222.         add     ix,de
  1223.         djnz    LOOP01
  1224.  
  1225. SKP71:
  1226.         ld      hl,LEVELa       ; Increase level
  1227.         inc     (hl)
  1228.         ld      hl,LEVELb
  1229.         inc     (hl)
  1230.  
  1231.         ld      a,(hl)          ; Last level?
  1232.         cp      10
  1233.         jp      nz,SKP75
  1234.  
  1235.         call    OUTRO           ; Then call outro
  1236.  
  1237. SKP75:
  1238.         call    LVINIT
  1239.  
  1240.         ret
  1241. ;▄████████████▄ STGCLR ▄███████████████████████████████████████████████████████
  1242.  
  1243.  
  1244. ;▄████████████▀ COLDT3 ▀███████████████████████████████████████████████████████
  1245. ;┌────────────────────────────────────────────────────────────────────────────┐
  1246. ;│ Collision detection between barrier and laser                              │
  1247. ;└────────────────────────────────────────────────────────────────────────────┘
  1248. COLDT3:
  1249.  
  1250. ;████   Alien laser and barrier   ████
  1251.  
  1252.         ld      a,(ALASRf)      ; Is there an alien laser beam?
  1253.         cp      0
  1254.         jp      z,SKP20
  1255.  
  1256.         ld      a,(ALASRy)      ; Has the laserbeam reached the barriersection?
  1257.         add     a,7
  1258.         cp      47
  1259.         jp      c,SKP20
  1260.  
  1261.         ld      a,(ALASRy)      ; Has the laserbeam left the barriersection?
  1262.         add     a,7
  1263.         cp      55
  1264.         jp      nc,SKP20
  1265.  
  1266.         ld      a,(ALASRy)      ; Get laser y-coordinate
  1267.         add     a,7
  1268.         ld      e,a
  1269.  
  1270.         ld      hl,0            ; Do y*12
  1271.         ld      d,0
  1272.         add     hl,de
  1273.         add     hl,de
  1274.         add     hl,de
  1275.         add     hl,hl
  1276.         add     hl,hl
  1277.  
  1278.         ld      a,(ALASRx)      ; Get laser x-coordinate
  1279.         ld      e,a
  1280.  
  1281.         ld      d,0             ; Do x/8
  1282.         srl     e
  1283.         srl     e
  1284.         srl     e
  1285.         add     hl,de
  1286.  
  1287.         ld      bc,8e29h+12     ; Add graphbuf address + one line
  1288.         add     hl,bc
  1289.  
  1290.         ld      c,10000000b     ; Initiate laserpoint
  1291.  
  1292.         ld      a,(ALASRx)
  1293.         ld      b,00000111b     ; Get the remainder of x/8
  1294.         and     b
  1295.         cp      0               ; Is the beam aligned to 8*n,y?
  1296.         jp      z,SKP21
  1297.  
  1298.         ld      b,a
  1299. SHLOP3: srl     c               ; Shift the point to get right pixel bit
  1300.         djnz    SHLOP3
  1301.  
  1302. SKP21:  ld      a,(hl)          ; Get barrier byte
  1303.         and     c               ; And with laser point
  1304.         cp      0
  1305.         jp      z,SKP20
  1306.  
  1307.         ld      a,(hl)
  1308.         xor     c
  1309.         ld      (hl),a
  1310.  
  1311.         ld      a,(ALASRy)      ; Erase alien laser
  1312.         ld      e,a
  1313.         ld      a,(ALASRx)
  1314.         ld      hl,80+SPRITES
  1315.         call    CLRSPR
  1316.  
  1317.         ld      ix,(ALASRp)     ; Redraw alien
  1318.         ld      l,(ix+0)
  1319.         ld      a,0
  1320.         cp      l
  1321.         jp      z,SKP27
  1322.         ld      h,0
  1323.         ld      bc,SPRITES
  1324.         add     hl,bc
  1325.         ld      a,(ix+1)
  1326.         ld      e,(ix+2)
  1327.         call    SPRITE
  1328.  
  1329. SKP27:
  1330.         ld      a,0             ; Reset the alien laser flag
  1331.         ld      (ALASRf),a
  1332.  
  1333. SKP20:
  1334.  
  1335. ;████   Player laser and barrier   ████
  1336.  
  1337.         ld      a,(SLASRy)      ; Is there an alien laser beam?
  1338.         cp      252
  1339.         jp      z,SKP22
  1340.  
  1341.         ld      a,(SLASRy)      ; Has the laserbeam reached the barriersection?
  1342.         cp      57
  1343.         jp      nc,SKP22
  1344.  
  1345.         ld      a,(SLASRy)      ; Has the laserbeam left the barriersection?
  1346.         cp      48
  1347.         jp      c,SKP22
  1348.  
  1349.         ld      a,(SLASRy)      ; Get laser y-coordinate
  1350.         ld      e,a
  1351.  
  1352.         ld      hl,0            ; Do y*12
  1353.         ld      d,0
  1354.         add     hl,de
  1355.         add     hl,de
  1356.         add     hl,de
  1357.         add     hl,hl
  1358.         add     hl,hl
  1359.  
  1360.         ld      a,(SLASRx)      ; Get laser x-coordinate
  1361.         ld      e,a
  1362.  
  1363.         ld      d,0             ; Do x/8
  1364.         srl     e
  1365.         srl     e
  1366.         srl     e
  1367.         add     hl,de
  1368.  
  1369.         ld      bc,8e29h-12     ; Add graphbuf address - one line
  1370.         add     hl,bc
  1371.  
  1372.         ld      c,10000000b     ; Initiate laserpoint
  1373.  
  1374.         ld      a,(SLASRx)
  1375.         ld      b,00000111b     ; Get the remainder of x/8
  1376.         and     b
  1377.         cp      0               ; Is the beam aligned to 8*n,y?
  1378.         jp      z,SKP23
  1379.  
  1380.         ld      b,a
  1381. SHLOP4: srl     c               ; Shift the point to get right pixel bit
  1382.         djnz    SHLOP4
  1383.  
  1384. SKP23:  ld      a,(hl)          ; Get barrier byte
  1385.         and     c               ; And with laser point
  1386.         cp      0
  1387.         jp      z,SKP22
  1388.  
  1389.         ld      a,(hl)
  1390.         xor     c
  1391.         ld      (hl),a
  1392.  
  1393.         ld      a,(SLASRy)      ; Erase player laser
  1394.         ld      e,a
  1395.         ld      a,(SLASRx)
  1396.         ld      hl,80+SPRITES
  1397.         call    CLRSPR
  1398.  
  1399.         ld      a,16            ; Initiate laser timer
  1400.         ld      (LTIMER),a
  1401.  
  1402.         ld      a,252           ; Reset the alien laser flag
  1403.         ld      (SLASRy),a
  1404.  
  1405. SKP22:
  1406.  
  1407.         ret
  1408. ;▄████████████▄ COLDT3 ▄███████████████████████████████████████████████████████
  1409.  
  1410.  
  1411. ;▄████████████▀ GAMEOVER ▀█████████████████████████████████████████████████████
  1412. ;┌────────────────────────────────────────────────────────────────────────────┐
  1413. ;│ Game Over                                                                  │
  1414. ;└────────────────────────────────────────────────────────────────────────────┘
  1415. GAMEOVER:
  1416.  
  1417.         ld      a,24
  1418.         ld      e,24
  1419.         ld      b,4
  1420.         ld      c,0
  1421.         call    BOX
  1422.  
  1423.         set     7,(iy+20)       ; Enable text-direct-to-lcd
  1424.  
  1425.         ld      hl,01d1fh       ; - Print Game Over
  1426.         ld      (08252H),hl     ; Update cursorslocation
  1427.         ld      hl,MSG02
  1428.         call    04781h          ; Vputs
  1429.  
  1430.  
  1431.         ld      a,(SCOREb+1)    ; Check for new highscore
  1432.         ld      b,a
  1433.         ld      a,(HSCOREb+1)
  1434.         cp      b
  1435.         jp      c,HIGH
  1436.         jp      z,NXT03
  1437.         jp      NOHIGH
  1438.  
  1439. NXT03:
  1440.         ld      a,(SCOREb)
  1441.         ld      b,a
  1442.         ld      a,(HSCOREb)
  1443.         cp      b
  1444.         jp      c,HIGH
  1445.         jp      NOHIGH
  1446.  
  1447. HIGH:                           ; Update highscore
  1448.         ld      hl,(SCOREb)
  1449.         ld      (HSCOREb),hl
  1450.         ld      a,(SCR1)
  1451.         ld      (HSCR1),a
  1452.         ld      a,(SCR2)
  1453.         ld      (HSCR2),a
  1454.         ld      a,(SCR3)
  1455.         ld      (HSCR3),a
  1456.         ld      a,(SCR4)
  1457.         ld      (HSCR4),a
  1458.  
  1459. NOHIGH:
  1460.  
  1461.         ld      b,100           ; Wait for a while
  1462. WAITL7: push    bc
  1463.         call    BUFCOPY
  1464.         pop     bc
  1465.         djnz    WAITL7
  1466.  
  1467.         call    NEWGAME
  1468.  
  1469. ;▄████████████▄ GAMEOVER ▄█████████████████████████████████████████████████████
  1470.  
  1471.  
  1472. ;▄████████████▀  STAT  ▀███████████████████████████████████████████████████████
  1473. ;┌────────────────────────────────────────────────────────────────────────────┐
  1474. ;│ Print player status in a box and wait for 2nd                              │
  1475. ;└────────────────────────────────────────────────────────────────────────────┘
  1476. STAT:
  1477.         ld      hl,8e29h        ; Copy graphbuf to safe ram area
  1478.         ld      de,8265h
  1479.         ld      bc,768
  1480.         ldir
  1481.  
  1482.         ld      a,16            ; Draw a box
  1483.         ld      e,8
  1484.         ld      b,6
  1485.         ld      c,3
  1486.         call    BOX
  1487.  
  1488.         res     7,(iy+20)       ; Print text to LCD only
  1489.  
  1490.         ld      hl,00b16h       ; - Print title text
  1491.         ld      (08252H),hl     ; Update cursorslocation
  1492.         ld      hl,PRGNAME
  1493.         call    04781h          ; Vputs
  1494.  
  1495.         ld      hl,01316h+7     ; - Print score text
  1496.         ld      (08252H),hl     ; Update cursorslocation
  1497.         ld      hl,SCORE
  1498.         call    04781h          ; Vputs
  1499.  
  1500.         ld      hl,0132dh+7     ; - Print score number
  1501.         ld      (08252H),hl     ; Update cursorslocation
  1502.         ld      hl,SCR4
  1503.         call    04781h          ; Vputs
  1504.  
  1505.         ld      hl,01916h+7     ; - Print level text
  1506.         ld      (08252H),hl     ; Update cursorslocation
  1507.         ld      hl,LEVEL
  1508.         call    04781h          ; Vputs
  1509.  
  1510.         ld      hl,01939h+7     ; - Print level number
  1511.         ld      (08252H),hl     ; Update cursorslocation
  1512.         ld      hl,LEVELa
  1513.         call    04781h          ; Vputs
  1514.  
  1515.         ld      hl,01f16h+7     ; - Print lives text
  1516.         ld      (08252H),hl     ; Update cursorslocation
  1517.         ld      hl,LIVES
  1518.         call    04781h          ; Vputs
  1519.  
  1520.         ld      hl,01f39h+7     ; - Print lives number
  1521.         ld      (08252H),hl     ; Update cursorslocation
  1522.         ld      hl,LIVESa
  1523.         call    04781h          ; Vputs
  1524.  
  1525.         ret
  1526. ;▄████████████▄  STAT  ▄███████████████████████████████████████████████████████
  1527.  
  1528.  
  1529. ;▄████████████▀ COLDT2 ▀███████████████████████████████████████████████████████
  1530. ;┌────────────────────────────────────────────────────────────────────────────┐
  1531. ;│ Collision detection between alien laser and player                         │
  1532. ;└────────────────────────────────────────────────────────────────────────────┘
  1533. COLDT2:
  1534.  
  1535.         ld      a,(ALASRf)      ; Is there an alien laser beam?
  1536.         cp      0
  1537.         ret     z
  1538.  
  1539.  
  1540. ;████   Scan in y   ████
  1541.  
  1542.         ld      a,(BOSSf)
  1543.         cp      1
  1544.         jp      nz,SKP64
  1545.  
  1546.         ld      a,(ALASRy)      ; Reached the player in y-level yet?
  1547.         add     a,7
  1548.         cp      59
  1549.         ret     c
  1550.         jp      SKP65
  1551.  
  1552. SKP64:
  1553.         ld      a,(ALASRy)      ; Reached the player in y-level yet?
  1554.         add     a,7
  1555.         cp      59
  1556.         ret     c
  1557.  
  1558. SKP65:
  1559.  
  1560.  
  1561. ;████   Scan in x   ████
  1562.  
  1563.         ld      a,(BOSSf)
  1564.         cp      1
  1565.         jp      nz,SKP66
  1566.  
  1567.         ld      a,(ALASRx)      ; Get boss shot x-coordinate
  1568.         add     a,7
  1569.         ld      c,a
  1570.         ld      a,(SHIPx)       ; Get player x-coordinate
  1571.         cp      c
  1572.         ret     nc              ; Return if not above
  1573.         jp      SKP67
  1574.  
  1575. SKP66:
  1576.         ld      a,(ALASRx)      ; Get alien laserbeam x-coordinate
  1577.         inc     a
  1578.         ld      c,a
  1579.         ld      a,(SHIPx)       ; Get player x-coordinate
  1580.         cp      c
  1581.         ret     nc              ; Return if not above
  1582.  
  1583. SKP67:
  1584.         ld      a,(ALASRx)      ; Get alien laserbeam x-coordinate
  1585.         inc     a
  1586.         ld      c,a
  1587.         ld      a,(SHIPx)       ; Get player x-coordinate+13
  1588.         add     a,13
  1589.         cp      c
  1590.         ret     c               ; Return if above
  1591.  
  1592.  
  1593. ;████   !!! HIT !!!   ████
  1594.  
  1595.         ld      a,(BOSSf)
  1596.         cp      1
  1597.         jp      z,SKP62
  1598.  
  1599.         ld      a,(ALASRy)      ; Erase alien laser
  1600.         ld      e,a
  1601.         ld      a,(ALASRx)
  1602.         ld      hl,80+SPRITES
  1603.         call    CLRSPR
  1604.  
  1605.         ld      a,128           ; Init alien laser timer
  1606.         ld      (ALASRt),a
  1607.  
  1608.         jp      SKP63
  1609.  
  1610. SKP62:
  1611.         ld      a,(ALASRy)      ; Erase alien laser
  1612.         ld      e,a
  1613.         ld      a,(ALASRx)
  1614.         ld      hl,25*8+SPRITES
  1615.         call    CLRSPR
  1616.  
  1617.         ld      a,32
  1618.         ld      (ALASRt),a
  1619.  
  1620. SKP63:
  1621.         ld      a,0             ; Reset the alien laser flag
  1622.         ld      (ALASRf),a
  1623.  
  1624.         ld      e,56
  1625.         ld      a,(OSHIPx)      ; Load x-coordinate
  1626.         ld      hl,88+SPRITES
  1627.         call    CLRSPR          ; Erase ship
  1628.         ld      e,56
  1629.         ld      a,(OSHIPx)      ; Load x-coordinate
  1630.         add     a,8
  1631.         ld      hl,96+SPRITES
  1632.         call    CLRSPR          ; Erase ship
  1633.  
  1634.         ld      e,56
  1635.         ld      a,(SHIPx)       ; Load x-coordinate
  1636.         ld      hl,176+SPRITES
  1637.         call    SPRITE          ; Draw wreck
  1638.         ld      e,56
  1639.         ld      a,(SHIPx)       ; Load x-coordinate
  1640.         add     a,8
  1641.         ld      hl,184+SPRITES
  1642.         call    SPRITE          ; Draw wreck
  1643.  
  1644.         ld      a,(BOSSf)       ; Don't redraw alien if it was a boss shot
  1645.         cp      1
  1646.         jp      z,SKP26
  1647.  
  1648.         ld      ix,(ALASRp)     ; Redraw alien
  1649.         ld      l,(ix+0)
  1650.         ld      a,0
  1651.         cp      l
  1652.         jp      z,SKP26
  1653.         ld      h,0
  1654.         ld      bc,SPRITES
  1655.         add     hl,bc
  1656.         ld      a,(ix+1)
  1657.         ld      e,(ix+2)
  1658.         call    SPRITE
  1659.  
  1660. SKP26:
  1661.         ld      hl,LIVESa       ; Decrement lives left
  1662.         dec     (hl)
  1663.         ld      hl,LIVESb
  1664.         dec     (hl)
  1665.  
  1666.         call    INVERT
  1667.         call    INVERT
  1668.  
  1669.         call    STAT            ; Show stats in a box and wait for 2nd
  1670.  
  1671.         ld      hl,02621h       ; - Print msg to press 2nd
  1672.         ld      (08252h),hl     ; Update cursorslocation
  1673.         ld      hl,MSG01
  1674.         call    04781h          ; Vputs
  1675.  
  1676.         call    WAIT2ND         ; Wait for 2nd to be pressed
  1677.  
  1678.         ld      de,8e29h        ; Copy safe ram area to graphbuf
  1679.         ld      hl,8265h
  1680.         ld      bc,768
  1681.         ldir
  1682.  
  1683.         ld      hl,LIVESb       ; Last life?
  1684.         ld      a,(hl)
  1685.         cp      0
  1686.         jp      nz,SKP18
  1687.  
  1688.         call    GAMEOVER
  1689.  
  1690. SKP18:
  1691.         ld      a,16            ; Initiate laser timer
  1692.         ld      (LTIMER),a
  1693.  
  1694.         ld      a,0
  1695.         ld      (SHIPx),a
  1696.  
  1697. DONE8:
  1698.         ret
  1699. ;▄████████████▄ COLDT2 ▄███████████████████████████████████████████████████████
  1700.  
  1701.  
  1702. ;▄████████████▀ ALASR ▀████████████████████████████████████████████████████████
  1703. ;┌────────────────────────────────────────────────────────────────────────────┐
  1704. ;│ Alien laser                                                                │
  1705. ;└────────────────────────────────────────────────────────────────────────────┘
  1706. ALASR:
  1707.         ld      a,(ALASRt)      ; Alien laser timer = 0 yet?
  1708.         cp      0
  1709.         jp      z,SKP24
  1710.  
  1711.         ld      hl,ALASRt       ; Update alien laser timer
  1712.         dec     (hl)
  1713.         ret
  1714.  
  1715. SKP24:
  1716.         ld      a,(ALASRf)      ; Look for alien laserbeam
  1717.         cp      1
  1718.         jp      z,UPLASR        ; Jump to update laser if there already is one
  1719.  
  1720.         ld      a,(DIFF)        ; If DIFF=3, shoot now
  1721.         cp      3
  1722.         jp      z,SKP74
  1723.  
  1724.         ld      a,(ALIENc)      ; Has every single alien moved yet?
  1725.         cp      0
  1726.         ret     nz
  1727.  
  1728. SKP74:
  1729.  
  1730. ;████   Look for ship in alien x area   ████
  1731.  
  1732.         ld      ix,ALAST
  1733.  
  1734. SCNX1:                          ; Scan x
  1735.         ld      b,32            ; 32 possible aliens
  1736. SCNXL1: ld      a,(ix)          ; Pointer to the alien line data
  1737.         cp      0               ; Is the alien dead?
  1738.         jp      z,NXT02
  1739.  
  1740.         ld      a,(SHIPx)       ; Get player x-coordinate
  1741.         add     a,4
  1742.         ld      c,(ix+1)        ; Get alien x-coordinate
  1743.         cp      c
  1744.         jp      c,NXT02         ; Jump if below
  1745.  
  1746.         ld      a,(ix+1)        ; Get alien x-coordinate+8
  1747.         add     a,8
  1748.         ld      c,a
  1749.         ld      a,(SHIPx)       ; Get player x-coordinate
  1750.         cp      c
  1751.         jp      nc,NXT02        ; Jump if not below
  1752.  
  1753.         jp      CFREE
  1754.  
  1755. NXT02:  dec     ix              ; Next alien in datalist
  1756.         dec     ix
  1757.         dec     ix
  1758.         djnz    SCNXL1
  1759.  
  1760.         jp      DONE6           ; No ship in any alien x area
  1761.  
  1762. CFREE:  ld      (TEMP),ix
  1763.         ld      hl,(TEMP)
  1764.         ld      de,-ALIENd1
  1765.         add     hl,de
  1766.         ld      (TEMP2),hl
  1767.         ld      de,(TEMP2)
  1768.         ld      c,e
  1769.         ld      hl,(TEMP)
  1770.  
  1771.         ld      de,24
  1772.         ld      b,4             ; Check if there's an alien under
  1773. FREEL:  ld      a,c
  1774.         add     a,24
  1775.         cp      96
  1776.         jp      nc,LXIT02
  1777.         ld      c,a
  1778.         add     hl,de
  1779.         ld      a,(hl)
  1780.         cp      0
  1781.         jp      nz,NOFREE
  1782.         djnz    FREEL
  1783.  
  1784. NOFREE: jp      DONE6           ; There's at least one alien under, don't shoot
  1785.  
  1786. LXIT02:                         ; No alien under, shoot!
  1787.  
  1788. ;████   Initiate alien laser   ████
  1789.  
  1790. FIRE:   ld      a,r             ; Init alien laser
  1791.         srl     a
  1792.         and     00000001b
  1793.         ld      b,a
  1794.         ld      a,(ix+1)
  1795.         add     a,4
  1796.         add     a,b
  1797.         ld      (ALASRx),a
  1798.         ld      a,(ix+2)
  1799.         ld      (ALASRy),a
  1800.         ld      a,1
  1801.         ld      (ALASRf),a
  1802.         ld      (ALASRp),ix
  1803.  
  1804.         jp      DONE6
  1805.  
  1806.  
  1807. ;████   Update alien laser   ████
  1808.  
  1809. UPLASR:
  1810.         ld      a,(ALASRy)      ; Erase old alien laser
  1811.         ld      e,a
  1812.         ld      a,(ALASRx)
  1813.         ld      hl,80+SPRITES
  1814.         call    CLRSPR
  1815.  
  1816.         ld      a,(ALASRy)      ; Update alien laser y-coordinate
  1817.         inc     a
  1818.         ld      (ALASRy),a
  1819.  
  1820.         cp      57              ; Has alien laser reached the bottom?
  1821.         jp      nz,SKP16
  1822.  
  1823.         ld      a,0             ; If so, reset the alien laser flag
  1824.         ld      (ALASRf),a
  1825.  
  1826.         jp      DONE6
  1827.  
  1828. SKP16:
  1829.         ld      e,a             ; Draw new alien laser
  1830.         ld      a,(ALASRx)
  1831.         ld      hl,80+SPRITES
  1832.         call    SPRITE
  1833.  
  1834.         ld      ix,(ALASRp)     ; Draw alien over laser
  1835.  
  1836.         ld      a,(ix)
  1837.         cp      0
  1838.         jp      z,DONE6
  1839.  
  1840.         ld      h,0
  1841.         ld      l,(ix)
  1842.         ld      bc,SPRITES
  1843.         add     hl,bc
  1844.         ld      a,(ix+1)
  1845.         ld      e,(ix+2)
  1846.         call    SPRITE
  1847.  
  1848. DONE6:
  1849.         ret
  1850. ;▄████████████▄ ALASR ▄████████████████████████████████████████████████████████
  1851.  
  1852.  
  1853. ;▄████████████▀ ALIENS ▀███████████████████████████████████████████████████████
  1854. ;┌────────────────────────────────────────────────────────────────────────────┐
  1855. ;│ Move the aliens                                                            │
  1856. ;└────────────────────────────────────────────────────────────────────────────┘
  1857. ALIENS:
  1858.  
  1859. ;████   Check if alien is RIP'ing   ████
  1860.  
  1861.         ld      a,(RIPt)
  1862.         cp      0
  1863.         jp      z,NXT01
  1864.  
  1865.         cp      1
  1866.         jp      nz,SKP14
  1867.  
  1868.         ld      ix,(RIPp)       ; Erase RIP
  1869.         ld      (ix+0),0
  1870.         ld      a,(ix+1)        ; Get x-coordinate for alien
  1871.         ld      e,(ix+2)        ; Get y-coordinate for alien
  1872.         ld      hl,72+SPRITES
  1873.         call    CLRSPR
  1874.  
  1875.         ld      a,(ALIENk)      ; Last alien?
  1876.         cp      32
  1877.         jp      nz,SKP14
  1878.  
  1879.         call    STGCLR
  1880.  
  1881. SKP14:
  1882.         ld      a,(RIPt)
  1883.         dec     a
  1884.         ld      (RIPt),a
  1885.         ret
  1886.  
  1887.  
  1888. ;████   Calculate pointer to alien data   ████
  1889.  
  1890. NXT01:
  1891.         ld      ix,ALIENd1      ; Get pointer to alien data
  1892.         ld      a,(ALIENc)      ; Get current offset in alien data
  1893.         ld      c,a             ; Do c*3
  1894.         add     a,c
  1895.         add     a,c
  1896.         ld      c,a
  1897.         ld      b,0
  1898.         add     ix,bc
  1899.  
  1900.  
  1901. ;████   Check if alien is dead   ████
  1902.  
  1903.         ld      a,(ix+0)        ; Check if alien is dead
  1904.         cp      0
  1905.         jp      nz,SKP11
  1906.         ld      hl,ALIENc       ; Update alien counter
  1907.         inc     (hl)
  1908.         ld      a,(hl)
  1909.         cp      32              ; Time to reset counter?
  1910.         jp      nz,NXT01
  1911.         jp      RESC1           ; Reset counter and return to main
  1912.  
  1913.  
  1914. ;████   Erase old alien   ████
  1915.  
  1916. SKP11:
  1917.         ld      l,a             ; Erase old alien
  1918.         ld      h,0
  1919.         ld      bc,SPRITES
  1920.         add     hl,bc
  1921.         ld      a,(ix+1)
  1922.         ld      e,(ix+2)
  1923.         push    ix
  1924.         call    CLRSPR
  1925.         pop     ix
  1926.  
  1927.  
  1928. ;████   Update alien data   ████
  1929.  
  1930.         ld      a,(ALIENa)      ; Anim frame
  1931.         add     a,(ix+0)
  1932.         ld      (ix+0),a
  1933.  
  1934.         ld      a,(ALIENmy)     ; Y-coordinate
  1935.         add     a,(ix+2)
  1936.         ld      (ix+2),a
  1937.  
  1938.         ld      a,(ALIENmy)     ; Skip x movement if y movement
  1939.         cp      0
  1940.         jp      nz,NOXMOV
  1941.  
  1942.         ld      a,(ALIENm)      ; X-coordinate
  1943.         add     a,(ix+1)
  1944.         ld      (ix+1),a
  1945.  
  1946.         cp      88              ; Aliens reached the right edge?
  1947.         jp      nz,SKP9
  1948.         ld      a,1
  1949.         ld      (ALIENmc),a
  1950.         jp      SKP10
  1951.  
  1952. SKP9:
  1953.         cp      0               ; Aliens reached the left edge?
  1954.         jp      nz,SKP10
  1955.         ld      a,1
  1956.         ld      (ALIENmc),a     ; Set movement change flag
  1957.  
  1958. NOXMOV:
  1959.  
  1960. ;████   Draw new alien   ████
  1961.  
  1962. SKP10:
  1963.         ld      l,(ix+0)        ; Draw new alien
  1964.         ld      h,0
  1965.         ld      bc,SPRITES
  1966.         add     hl,bc
  1967.         ld      a,(ix+1)
  1968.         ld      e,(ix+2)
  1969.         call    SPRITE
  1970.  
  1971.  
  1972. ;████   Update alien counter   ████
  1973.  
  1974. SKP8:
  1975.         ld      hl,ALIENc       ; Update alien counter
  1976.         inc     (hl)
  1977.         ld      a,(hl)
  1978.         cp      32              ; Time to reset counter?
  1979.         jp      nz,DONE3
  1980.  
  1981. RESC1:
  1982.         ld      (hl),0          ; Reset alien counter
  1983.  
  1984.         ld      a,(ALIENa)      ; Change anim frame add
  1985.         neg
  1986.         ld      (ALIENa),a
  1987.  
  1988.         ld      a,0
  1989.         ld      (ALIENmy),a     ; Reset alien y movement flag
  1990.  
  1991.  
  1992. ;████   Look for alien movement change   ████
  1993.  
  1994.         ld      a,(ALIENmc)     ; Look for alien movement change
  1995.         cp      1
  1996.         jp      nz,DONE3
  1997.  
  1998.         ld      a,(ALIENm)      ; Change direction in movement
  1999.         neg
  2000.         ld      (ALIENm),a
  2001.  
  2002.         ld      a,(ALIENys)     ; Get alien y speed
  2003.         ld      (ALIENmy),a     ; Set alien y movement flag
  2004.  
  2005.         ld      b,a
  2006.         ld      a,(ALIENli)
  2007.         add     a,b
  2008.         ld      (ALIENli),a     ; Increase lines alien has moved down
  2009.  
  2010.         ld      a,0             ; Reset alien movement change flag
  2011.         ld      (ALIENmc),a
  2012.  
  2013. DONE3:
  2014.         ret
  2015. ;▄████████████▄ ALIENS ▄███████████████████████████████████████████████████████
  2016.  
  2017.  
  2018. ;▄████████████▀ COLDT1 ▀███████████████████████████████████████████████████████
  2019. ;┌────────────────────────────────────────────────────────────────────────────┐
  2020. ;│ Collision detection between alien and laser                                │
  2021. ;└────────────────────────────────────────────────────────────────────────────┘
  2022. COLDT1:
  2023.         ld      a,(SLASRy)      ; Is there a laserbeam on screen?
  2024.         cp      252
  2025.         ret     z
  2026.  
  2027.  
  2028. ;████   Scan y-coordinates   ████
  2029.  
  2030. TROW1:
  2031.         ld      a,(ALIENli)     ; Get number of lines the aliens has moved down
  2032.         add     a,8
  2033.         ld      b,a
  2034.         ld      a,(SLASRy)      ; Get laserbeam y-coordinate
  2035.         cp      b
  2036.         jp      nc,TROW2        ; Jump if not below
  2037.  
  2038.         ld      ix,ALIENd1
  2039.         ld      hl,ALIENr1
  2040.         jp      SCAN1
  2041.  
  2042. TROW2:
  2043.         ld      a,(ALIENli)     ; Get number of lines the aliens has moved down
  2044.         add     a,18
  2045.         ld      b,a
  2046.         ld      a,(SLASRy)      ; Get laserbeam y-coordinate
  2047.         cp      b
  2048.         jp      nc,TROW3        ; Jump if not below
  2049.  
  2050.         ld      ix,ALIENd2
  2051.         ld      hl,ALIENr2
  2052.         jp      SCAN1
  2053.  
  2054. TROW3:
  2055.         ld      a,(ALIENli)     ; Get number of lines the aliens has moved down
  2056.         add     a,28
  2057.         ld      b,a
  2058.         ld      a,(SLASRy)      ; Get laserbeam y-coordinate
  2059.         cp      b
  2060.         jp      nc,TROW4        ; Jump if not below
  2061.  
  2062.         ld      ix,ALIENd3
  2063.         ld      hl,ALIENr3
  2064.         jp      SCAN1
  2065.  
  2066. TROW4:
  2067.         ld      a,(ALIENli)     ; Get number of lines the aliens has moved down
  2068.         add     a,38
  2069.         ld      b,a
  2070.         ld      a,(SLASRy)      ; Get laserbeam y-coordinate
  2071.         cp      b
  2072.         jp      nc,DONE2        ; Jump if not below
  2073.  
  2074.         ld      ix,ALIENd4
  2075.         ld      hl,ALIENr4
  2076.         jp      SCAN1
  2077.  
  2078.  
  2079. ;████   Scan x-coordinates   ████
  2080.  
  2081. SCAN1:
  2082.         ld      b,8             ; Eight possible aliens
  2083. SCAN1L: ld      a,(ix)          ; Pointer to the alien line data
  2084.         cp      0               ; Is the alien dead?
  2085.         jp      z,NXT0
  2086.  
  2087.         ld      a,(SLASRx)      ; Get laserbeam x-coordinate
  2088.         ld      c,(ix+1)        ; Get alien x-coordinate
  2089.         cp      c
  2090.         jp      c,NXT0          ; Jump if below
  2091.  
  2092.         ld      a,(ix+1)        ; Get alien x-coordinate+8
  2093.         add     a,8
  2094.         ld      c,a
  2095.         ld      a,(SLASRx)      ; Get laserbeam x-coordinate
  2096.         cp      c
  2097.         jp      nc,NXT0         ; Jump if not below
  2098.  
  2099.         jp      HIT
  2100.  
  2101. NXT0:   inc     ix
  2102.         inc     ix
  2103.         inc     ix
  2104.         djnz    SCAN1L
  2105.  
  2106.         jp      DONE2
  2107.  
  2108. ;████   Erase the alien and the laserbeam   ████
  2109. HIT:
  2110.         dec     (hl)            ; ALIENrX=ALIENrX-1
  2111.  
  2112.         ld      h,0             ; -- Erase the alien and the laserbeam
  2113.         ld      l,(ix+0)
  2114.         ld      bc,SPRITES
  2115.         add     hl,bc
  2116.  
  2117.         ld      (ix+0),72       ; Erase alien in alien datalist (72=RIP)
  2118.  
  2119.         ld      a,(ix+1)        ; Get x-coordinate for alien
  2120.         ld      e,(ix+2)        ; Get y-coordinate for alien
  2121.         push    ix
  2122.         call    CLRSPR
  2123.         pop     ix
  2124.  
  2125.         ld      a,(SLASRy)      ; Erase laserbeam
  2126.         ld      e,a
  2127.         ld      a,(SLASRx)
  2128.         ld      hl,80+SPRITES
  2129.         push    ix
  2130.         call    CLRSPR
  2131.         pop     ix
  2132.  
  2133.         ld      a,252
  2134.         ld      (SLASRy),a
  2135.  
  2136.         call    USCORE
  2137.  
  2138.         ld      hl,ALIENk       ; Update number of killed aliens
  2139.         inc     (hl)
  2140.  
  2141.         ld      a,16            ; Initiate laser timer
  2142.         ld      (LTIMER),a
  2143.  
  2144. ;████   R.I.P. alien   ████
  2145.  
  2146.         ld      a,(ix+1)        ; Get x-coordinate for alien
  2147.         ld      e,(ix+2)        ; Get y-coordinate for alien
  2148.         ld      hl,72+SPRITES
  2149.         push    ix
  2150.         call    SPRITE          ; Blit RIP
  2151.         pop     ix
  2152.  
  2153.         ld      (RIPp),ix       ; Init pointer and counter
  2154.         ld      a,16
  2155.         ld      (RIPt),a
  2156.  
  2157. DONE2:
  2158.         ret
  2159. ;▄████████████▄ COLDT1 ▄███████████████████████████████████████████████████████
  2160.  
  2161.  
  2162. ;▄████████████▀ SCORE ▀████████████████████████████████████████████████████████
  2163. ;┌────────────────────────────────────────────────────────────────────────────┐
  2164. ;│ Update score                                                               │
  2165. ;└────────────────────────────────────────────────────────────────────────────┘
  2166. USCORE:
  2167.  
  2168. ;████   Update score   ████
  2169.  
  2170.         ld      a,(DIFF)
  2171.         ld      b,a
  2172. POINTL: push    bc              ; Point loop based on DIFF
  2173.  
  2174.         ld      hl,(SCOREb)     ; Give player point(s)
  2175.         inc     hl
  2176.         ld      (SCOREb),hl
  2177.  
  2178.         ld      hl,SCR1         ; -- Update the ascii score
  2179.         inc     (hl)
  2180.  
  2181.         ld      b,3             ; Look for overflow loop
  2182. SCRL:   ld      a,(hl)
  2183.         cp      ':'
  2184.         jp      nz,SKP17
  2185.         ld      (hl),'0'
  2186.         dec     hl
  2187.         inc     (hl)
  2188.         djnz    SCRL
  2189.  
  2190. SKP17:
  2191.         pop     bc
  2192.         djnz    POINTL
  2193.  
  2194.         ret
  2195. ;▄████████████▄ SCORE ▄████████████████████████████████████████████████████████
  2196.  
  2197.  
  2198. ;▄████████████▀ LASER ▀████████████████████████████████████████████████████████
  2199. ;┌────────────────────────────────────────────────────────────────────────────┐
  2200. ;│ Update the ship's laserbeam                                                │
  2201. ;└────────────────────────────────────────────────────────────────────────────┘
  2202. LASER:
  2203.         ld      a,(LTIMER)      ; Has timer reached zero yet?
  2204.         cp      0
  2205.         jp      z,SKP12
  2206.         ld      hl,LTIMER       ; Update laser timer
  2207.         dec     (hl)
  2208.  
  2209. SKP12:
  2210.         ld      a,(SLASRy)      ; Is there a laserbeam to update?
  2211.         cp      252
  2212.         ret     z
  2213.  
  2214.         ld      a,(SLASRy)      ; Erase old laserbeam
  2215.         ld      e,a
  2216.         ld      a,(SLASRx)
  2217.         ld      hl,80+SPRITES
  2218.         call    CLRSPR
  2219.  
  2220.         ld      a,(SLASRy)      ; Has the laserbeam reached the top yet?
  2221.         cp      0
  2222.         jp      nz,SKP01
  2223.  
  2224.         ld      a,252
  2225.         ld      (SLASRy),a
  2226.         ret
  2227.  
  2228. SKP01:
  2229.         ld      hl,SLASRy       ; Move laserbeam two pixels up
  2230.         dec     (hl)
  2231.         dec     (hl)
  2232.  
  2233.         ld      a,(SLASRy)      ; Draw new laserbeam
  2234.         ld      e,a
  2235.         ld      a,(SLASRx)
  2236.         ld      hl,80+SPRITES
  2237.         call    SPRITE
  2238.  
  2239. DONE4:
  2240.         ret
  2241. ;▄████████████▄ LASER ▄████████████████████████████████████████████████████████
  2242.  
  2243.  
  2244. ;▄████████████▀  SHIP  ▀███████████████████████████████████████████████████████
  2245. ;┌────────────────────────────────────────────────────────────────────────────┐
  2246. ;│ Update the ship                                                            │
  2247. ;└────────────────────────────────────────────────────────────────────────────┘
  2248. SHIP:
  2249.  
  2250.  
  2251. ;████   Update the ship   ████
  2252.  
  2253.         ld      e,56
  2254.         ld      a,(OSHIPx)      ; Load old x-coordinate
  2255.         ld      hl,88+SPRITES
  2256.         call    CLRSPR          ; Erase last ship
  2257.  
  2258.         ld      e,56
  2259.         ld      a,(OSHIPx)      ; Load old x-coordinate
  2260.         add     a,8
  2261.         ld      hl,96+SPRITES
  2262.         call    CLRSPR          ; Erase last ship
  2263.  
  2264.         ld      e,56
  2265.         ld      a,(SHIPx)       ; Load x-coordinate
  2266.         ld      hl,88+SPRITES
  2267.         call    SPRITE          ; Draw new ship
  2268.  
  2269.         ld      e,56
  2270.         ld      a,(SHIPx)       ; Load x-coordinate
  2271.         add     a,8
  2272.         ld      hl,96+SPRITES
  2273.         call    SPRITE          ; Draw new ship
  2274.  
  2275.         ld      a,(SHIPx)       ; Update coordinates
  2276.         ld      (OSHIPx),a
  2277.  
  2278.  
  2279. ;████   Update bonus   ████
  2280.  
  2281.         ld      a,(BONUSt2)     ; If bonus = 0, don't dec any more
  2282.         cp      0
  2283.         jp      z,SKP83
  2284.  
  2285.         ld      hl,BONUSdc
  2286.         dec     (hl)
  2287.         ld      a,(hl)
  2288.         cp      0
  2289.         jp      nz,SKP83
  2290.  
  2291.         ld      a,(DIFF)
  2292.         ld      (BONUSdc),a
  2293.  
  2294.         ld      hl,BONUSt1      ; Dec lower byte
  2295.         dec     (hl)
  2296.         ld      a,(hl)
  2297.         cp      0
  2298.         jp      nz,SKP83
  2299.  
  2300.         ld      (hl),20
  2301.         inc     hl              ; Dec higher byte (the actual bonus score)
  2302.         dec     (hl)
  2303.  
  2304. SKP83:
  2305.         ret
  2306. ;▄████████████▄  SHIP  ▄███████████████████████████████████████████████████████
  2307.  
  2308.  
  2309. ;▄████████████▀  KEYS  ▀███████████████████████████████████████████████████████
  2310. ;┌────────────────────────────────────────────────────────────────────────────┐
  2311. ;│ Look for keypress                                                          │
  2312. ;└────────────────────────────────────────────────────────────────────────────┘
  2313. KEYS:
  2314.         ld      a,0ffh          ; Reset the keyport (kinda)
  2315.         out     (1),a
  2316.         ld      a,0feh          ; Enable the arrows
  2317.         out     (1),a
  2318.         in      a,(1)
  2319.  
  2320.         cp      253             ; Has anyone pressed left?
  2321.         jp      nz,NOLEFT
  2322.         ld      hl,SHIPx
  2323.         ld      a,(hl)
  2324.         cp      0               ; Check for left edge
  2325.         jp      z,NOLEFT
  2326.         dec     (hl)            ; Decrease SHIPx
  2327.  
  2328. NOLEFT:
  2329.         cp      251             ; Has anyone pressed right?
  2330.         jp      nz,NORIGHT
  2331.         ld      hl,SHIPx
  2332.         ld      a,(hl)
  2333.         cp      83              ; Check for right edge
  2334.         jp      z,NORIGHT
  2335.         inc     (hl)            ; Increase SHIPx
  2336.  
  2337. NORIGHT:
  2338.         ld      a,0ffh          ; Reset the keyport (kinda)
  2339.         out     (1),a
  2340.         ld      a,0bfh          ; Enable the row with 2nd
  2341.         out     (1),a
  2342.         in      a,(1)
  2343.  
  2344.         cp      223             ; Has anyone pressed 2nd
  2345.         jp      nz,NO2nd
  2346.  
  2347.         ld      a,(SLASRy)      ; Check if there already is a laserbeam
  2348.         cp      252
  2349.         jp      nz,NO2nd
  2350.  
  2351.         ld      a,(LTIMER)      ; Ok to fire laser?
  2352.         cp      0
  2353.         jp      nz,NO2nd
  2354.  
  2355.         ld      a,(SHIPx)       ; Initiate laser
  2356.         add     a,6
  2357.         ld      (SLASRx),a
  2358.         ld      a,58
  2359.         ld      (SLASRy),a
  2360.  
  2361. NO2nd:
  2362.         cp      191             ; Has anyone pressed MODE?
  2363.         jp      nz,NOMODE
  2364.         call    PAUSE
  2365.  
  2366. NOMODE:
  2367.         ld      a,0ffh          ; Reset the keyport (kinda)
  2368.         out     (1),a
  2369.         ld      a,0fdh          ; Enable the row with CLEAR
  2370.         out     (1),a
  2371.         in      a,(1)
  2372.         cp      191             ; Check for CLEAR
  2373.         jp      nz,NOCLR        ; Exit if clear is pressed
  2374.         inc     sp              ; Adjust stack
  2375.         inc     sp
  2376.         call    XIT
  2377.  
  2378. NOCLR:
  2379.         ld      a,0ffh          ; Reset the keyport (kinda)
  2380.         out     (1),a
  2381.         ld      a,0dfh          ; Enable the row with MATH
  2382.         out     (1),a
  2383.         in      a,(1)
  2384.  
  2385.         cp      191             ; Has anyone pressed MATH
  2386.         jp      nz,NOMATH
  2387.         call    MATH
  2388.  
  2389. NOMATH:
  2390.  
  2391.         ret
  2392. ;▄████████████▄  KEYS  ▄███████████████████████████████████████████████████████
  2393.  
  2394.  
  2395. ;▄████████████▀ WAIT2ND ▀██████████████████████████████████████████████████████
  2396. ;┌────────────────────────────────────────────────────────────────────────────┐
  2397. ;│ Wait for 2nd to be pressed                                                 │
  2398. ;└────────────────────────────────────────────────────────────────────────────┘
  2399. WAIT2ND:
  2400.  
  2401.         call    READKEY         ; Fetch first 2nd press
  2402.  
  2403. KEYL2:
  2404.         call    READKEY         ; Wait for 2nd press
  2405.         call    OP2TOP1
  2406.         call    CONVOP1
  2407.         cp      21
  2408.         jp      nz,KEYL2
  2409.  
  2410.         ret
  2411. ;▄████████████▄ WAIT2ND ▄██████████████████████████████████████████████████████
  2412.  
  2413.  
  2414. ;▄████████████▀ INVERT ▀███████████████████████████████████████████████████████
  2415. ;┌────────────────────────────────────────────────────────────────────────────┐
  2416. ;│ Inverts the graphbuf                                                       │
  2417. ;└────────────────────────────────────────────────────────────────────────────┘
  2418. INVERT:
  2419.  
  2420.         ld      de,8e29h        ; Invert graphbuf
  2421.         ld      hl,768
  2422.         ld      bc,-1
  2423. INVL1:  ld      a,(de)
  2424.         cpl
  2425.         ld      (de),a
  2426.         inc     de
  2427.         add     hl,bc
  2428.         jp      c,INVL1
  2429.  
  2430.         ld      b,8
  2431. WAITL2:
  2432.         push    bc
  2433.         call    BUFCOPY
  2434.         pop     bc
  2435.         djnz    WAITL2
  2436.  
  2437.         ret
  2438. ;▄████████████▄ INVERT ▄███████████████████████████████████████████████████████
  2439.  
  2440.  
  2441. ;▄████████████▀ PAUSE ▀████████████████████████████████████████████████████████
  2442. ;┌────────────────────────────────────────────────────────────────────────────┐
  2443. ;│ Pause and show stats                                                       │
  2444. ;└────────────────────────────────────────────────────────────────────────────┘
  2445. PAUSE:
  2446.         call    STAT
  2447.  
  2448.         ld      hl,0261fh       ; - Print msg to press MODE
  2449.         ld      (08252H),hl     ; Update cursorslocation
  2450.         ld      hl,MSG03
  2451.         call    04781h          ; Vputs
  2452.  
  2453.         call    READKEY         ; Fetch first mode press
  2454.  
  2455. KEYL1:
  2456.         call    READKEY         ; Wait for mode press
  2457.         call    OP2TOP1
  2458.         call    CONVOP1
  2459.         cp      22
  2460.         jp      nz,KEYL1
  2461.  
  2462.         ld      de,8e29h        ; Copy safe ram area to graphbuf
  2463.         ld      hl,8265h
  2464.         ld      bc,768
  2465.         ldir
  2466.  
  2467.         ld      b,16            ; Wait for a while
  2468. WAITL1:
  2469.         push    bc
  2470.         call    BUFCOPY
  2471.         pop     bc
  2472.         djnz    WAITL1
  2473.  
  2474.         ret
  2475. ;▄████████████▄ PAUSE  ▄████████████████████████████████████████████████████████
  2476.  
  2477.  
  2478. ;▄████████████▀  BOX  ▀████████████████████████████████████████████████████████
  2479. ;┌────────────────────────────────────────────────────────────────────────────┐
  2480. ;│ Draws a box @ a,e with size b,c                                            │
  2481. ;└────────────────────────────────────────────────────────────────────────────┘
  2482. BOX:
  2483.  
  2484.         ld      (BOXx),a
  2485.         ld      (TEMP),a
  2486.         ld      a,e
  2487.         ld      (BOXy),a
  2488.         ld      a,b
  2489.         ld      (BOXxs),a
  2490.         ld      a,c
  2491.         ld      (BOXys),a
  2492.  
  2493.  
  2494.         ld      bc,13*8         ; - Left upper corner
  2495.         ld      (BOXp),bc
  2496.         call    DBOX
  2497.         ld      a,(BOXx)
  2498.         add     a,8
  2499.         ld      (BOXx),a
  2500.  
  2501.         ld      bc,14*8         ; - Middle of first row
  2502.         ld      (BOXp),bc
  2503.         ld      a,(BOXxs)
  2504.         ld      b,a
  2505. BOXL1:  push    bc
  2506.         call    DBOX
  2507.         pop     bc
  2508.         ld      a,(BOXx)
  2509.         add     a,8
  2510.         ld      (BOXx),a
  2511.         djnz    BOXL1
  2512.  
  2513.         ld      bc,15*8         ; - Right upper corner
  2514.         ld      (BOXp),bc
  2515.         call    DBOX
  2516.         ld      a,(TEMP)
  2517.         ld      (BOXx),a
  2518.         ld      a,(BOXy)
  2519.         add     a,8
  2520.         ld      (BOXy),a
  2521.  
  2522.  
  2523.         ld      a,(BOXys)
  2524.         cp      0
  2525.         jp      z,SKP19
  2526.         ld      b,a
  2527. BOXL2:  push    bc
  2528.  
  2529.         ld      bc,16*8         ; - Left edge
  2530.         ld      (BOXp),bc
  2531.         call    DBOX
  2532.         ld      a,(BOXx)
  2533.         add     a,8
  2534.         ld      (BOXx),a
  2535.  
  2536.         ld      bc,21*8         ; - Middle of box
  2537.         ld      (BOXp),bc
  2538.         ld      a,(BOXxs)
  2539.         ld      b,a
  2540. BOXL3:  push    bc
  2541.         call    DBOX
  2542.         pop     bc
  2543.         ld      a,(BOXx)
  2544.         add     a,8
  2545.         ld      (BOXx),a
  2546.         djnz    BOXL3
  2547.  
  2548.         ld      bc,17*8         ; - Right edge
  2549.         ld      (BOXp),bc
  2550.         call    DBOX
  2551.         ld      a,(TEMP)
  2552.         ld      (BOXx),a
  2553.         ld      a,(BOXy)
  2554.         add     a,8
  2555.         ld      (BOXy),a
  2556.  
  2557.         pop     bc
  2558.         djnz    BOXL2
  2559.  
  2560. SKP19:
  2561.         ld      bc,18*8         ; - Left lower corner
  2562.         ld      (BOXp),bc
  2563.         call    DBOX
  2564.         ld      a,(BOXx)
  2565.         add     a,8
  2566.         ld      (BOXx),a
  2567.  
  2568.         ld      bc,19*8         ; - Middle of last row
  2569.         ld      (BOXp),bc
  2570.         ld      a,(BOXxs)
  2571.         ld      b,a
  2572. BOXL4:  push    bc
  2573.         call    DBOX
  2574.         pop     bc
  2575.         ld      a,(BOXx)
  2576.         add     a,8
  2577.         ld      (BOXx),a
  2578.         djnz    BOXL4
  2579.  
  2580.         ld      bc,20*8         ; - Right lower corner
  2581.         ld      (BOXp),bc
  2582.         call    DBOX
  2583.  
  2584.  
  2585.         jp      DONE7
  2586.  
  2587. DBOX:   ld      a,(BOXy)        ; -- Erase area under and draw boxsprite
  2588.         ld      e,a
  2589.         ld      a,(BOXx)
  2590.         ld      hl,SPRITES
  2591.         call    CLRSPR
  2592.  
  2593.         ld      a,(BOXy)
  2594.         ld      e,a
  2595.         ld      a,(BOXx)
  2596.         ld      hl,(BOXp)
  2597.         ld      bc,SPRITES
  2598.         add     hl,bc
  2599.         call    SPRITE
  2600.         ret
  2601.  
  2602. DONE7:
  2603.         call    BUFCOPY
  2604.  
  2605.         ret
  2606. ;▄████████████▄  BOX  ▄████████████████████████████████████████████████████████
  2607.  
  2608.  
  2609. ;▄████████████▀ SPRITE ▀███████████████████████████████████████████████████████
  2610. ;┌────────────────────────────────────────────────────────────────────────────┐
  2611. ;│ Blit or erase sprite ■ a=x, e=y, hl=sprite address                         │
  2612. ;└────────────────────────────────────────────────────────────────────────────┘
  2613. SPRITE:
  2614.  
  2615.         push    hl              ; Save sprite address
  2616.  
  2617. ;████   Calculate the address in graphbuf   ████
  2618.  
  2619.         ld      hl,0            ; Do y*12
  2620.         ld      d,0
  2621.         add     hl,de
  2622.         add     hl,de
  2623.         add     hl,de
  2624.         add     hl,hl
  2625.         add     hl,hl
  2626.  
  2627.         ld      d,0             ; Do x/8
  2628.         ld      e,a
  2629.         srl     e
  2630.         srl     e
  2631.         srl     e
  2632.         add     hl,de
  2633.  
  2634.         ld      de,8e29h
  2635.         add     hl,de           ; Add address to graphbuf
  2636.  
  2637.         ld      b,00000111b     ; Get the remainder of x/8
  2638.         and     b
  2639.         cp      0               ; Is this sprite aligned to 8*n,y?
  2640.         jp      z,ALIGN
  2641.  
  2642.  
  2643. ;████   Non aligned sprite blit starts here   ████
  2644.  
  2645.         pop     ix              ; ix->sprite
  2646.         ld      d,a             ; d=how many bits to shift each line
  2647.  
  2648.         ld      e,8             ; Line loop
  2649. LILOP:  ld      b,(ix+0)        ; Get sprite data
  2650.  
  2651.         ld      c,0             ; Shift loop
  2652.         push    de
  2653. SHLOP:  srl     b
  2654.         rr      c
  2655.         dec     d
  2656.         jp      nz,SHLOP
  2657.         pop     de
  2658.  
  2659.         ld      a,b             ; Write line to graphbuf
  2660.         or      (hl)
  2661.         ld      (hl),a
  2662.         inc     hl
  2663.         ld      a,c
  2664.         or      (hl)
  2665.         ld      (hl),a
  2666.  
  2667.         ld      bc,11           ; Calculate next line address
  2668.         add     hl,bc
  2669.         inc     ix              ; Inc spritepointer
  2670.  
  2671.         dec     e
  2672.         jp      nz,LILOP        ; Next line
  2673.  
  2674.         jp      DONE1
  2675.  
  2676.  
  2677. ;████   Aligned sprite blit starts here   ████
  2678.  
  2679. ALIGN:                          ; Blit an aligned sprite to graphbuf
  2680.         pop     de              ; de->sprite
  2681.         ld      b,8
  2682. ALOP1:  ld      a,(de)
  2683.         or      (hl)            ; xor=erase/blit
  2684.         ld      (hl),a
  2685.         inc     de
  2686.         push    bc
  2687.         ld      bc,12
  2688.         add     hl,bc
  2689.         pop     bc
  2690.         djnz    ALOP1
  2691.  
  2692. DONE1:
  2693.         ret
  2694. ;▄████████████▄ SPRITE ▄███████████████████████████████████████████████████████
  2695.  
  2696.  
  2697. ;▄████████████▀ CLRSPR ▀███████████████████████████████████████████████████████
  2698. ;┌────────────────────────────────────────────────────────────────────────────┐
  2699. ;│ Blit or erase sprite ■ a=x, e=y, hl=sprite address                         │
  2700. ;└────────────────────────────────────────────────────────────────────────────┘
  2701. CLRSPR:
  2702.         push    hl              ; Save sprite address
  2703.  
  2704. ;████   Calculate the address in graphbuf   ████
  2705.  
  2706.         ld      hl,0            ; Do y*12
  2707.         ld      d,0
  2708.         add     hl,de
  2709.         add     hl,de
  2710.         add     hl,de
  2711.         add     hl,hl
  2712.         add     hl,hl
  2713.  
  2714.         ld      d,0             ; Do x/8
  2715.         ld      e,a
  2716.         srl     e
  2717.         srl     e
  2718.         srl     e
  2719.         add     hl,de
  2720.  
  2721.         ld      de,8e29h
  2722.         add     hl,de           ; Add address to graphbuf
  2723.  
  2724.         ld      b,00000111b     ; Get the remainder of x/8
  2725.         and     b
  2726.         cp      0               ; Is this sprite aligned to 8*n,y?
  2727.         jp      z,ALIGN2
  2728.  
  2729.  
  2730. ;████   Non aligned sprite erase starts here   ████
  2731.  
  2732.         pop     ix              ; ix->sprite
  2733.         ld      d,a             ; d=how many bits to shift each line
  2734.  
  2735.         ld      e,8             ; Line loop
  2736. LILOP2: ld      b,(ix+0)        ; Get sprite data
  2737.  
  2738.         ld      c,0             ; Shift loop
  2739.         push    de
  2740. SHLOP2: srl     b
  2741.         rr      c
  2742.         dec     d
  2743.         jp      nz,SHLOP2
  2744.         pop     de
  2745.  
  2746.         ld      a,b             ; Write line to graphbuf
  2747.         cpl
  2748.         and     (hl)
  2749.         ld      (hl),a
  2750.         inc     hl
  2751.         ld      a,c
  2752.         cpl
  2753.         and     (hl)
  2754.         ld      (hl),a
  2755.  
  2756.         ld      bc,11           ; Calculate next line address
  2757.         add     hl,bc
  2758.         inc     ix              ; Inc spritepointer
  2759.  
  2760.         dec     e
  2761.         jp      nz,LILOP2       ; Next line
  2762.  
  2763.         jp      DONE5
  2764.  
  2765.  
  2766. ;████   Aligned sprite erase starts here   ████
  2767.  
  2768. ALIGN2:                         ; Erase an aligned sprite in graphbuf
  2769.         pop     de              ; de->sprite
  2770.         ld      b,8
  2771. ALOP2:  ld      a,(de)
  2772.         cpl
  2773.         and     (hl)
  2774.         ld      (hl),a
  2775.         inc     de
  2776.         push    bc
  2777.         ld      bc,12
  2778.         add     hl,bc
  2779.         pop     bc
  2780.         djnz    ALOP2
  2781.  
  2782. DONE5:
  2783.         ret
  2784. ;▄████████████▄ CLRSPR ▄███████████████████████████████████████████████████████
  2785.  
  2786.  
  2787. ;▄████████████▀  WAIT  ▀███████████████████████████████████████████████████████
  2788. ;┌────────────────────────────────────────────────────────────────────────────┐
  2789. ;│ Wait for a while ■ hl=times to do waitloop                                 │
  2790. ;└────────────────────────────────────────────────────────────────────────────┘
  2791. WAIT:
  2792.     push    bc
  2793.  
  2794.         ld      bc,-1
  2795. WAITL:  ld      (TEMP),bc       ; This instruction takes 20 cycles to execute
  2796.  
  2797.         add     hl,bc
  2798.         jp      c,WAITL
  2799.  
  2800.         pop     bc
  2801.     ret
  2802. ;▄████████████▄  WAIT  ▄███████████████████████████████████████████████████████
  2803.  
  2804.  
  2805. ;▄████████████▀ LVINIT ▀███████████████████████████████████████████████████████
  2806. ;┌────────────────────────────────────────────────────────────────────────────┐
  2807. ;│ Level init                                                                 │
  2808. ;└────────────────────────────────────────────────────────────────────────────┘
  2809. LVINIT:
  2810.  
  2811.         call    BUFCLR          ; Clear the graphbuf
  2812.  
  2813.         ld      a,'0'           ; - Init bonus variables
  2814.         ld      (BONUS1),a
  2815.         ld      (BONUS2),a
  2816.         ld      (BONUS3),a
  2817.         ld      a,20
  2818.         ld      (BONUSt1),a
  2819.         ld      a,128
  2820.         ld      (BONUSt2),a
  2821.         ld      a,(DIFF)
  2822.         ld      (BONUSdc),a
  2823.  
  2824.         ld      a,(BOSSf)
  2825.         cp      1
  2826.         jp      z,BOSSINI
  2827.  
  2828.  
  2829. ;████   Initiate barrier   ████
  2830.  
  2831.         ld      a,8             ; Initiate barrier 1
  2832.         ld      e,48
  2833.         ld      hl,SPRITES+8
  2834.         call    SPRITE
  2835.         ld      a,16
  2836.         ld      e,48
  2837.         ld      hl,SPRITES+16
  2838.         call    SPRITE
  2839.  
  2840.         ld      a,40            ; Initiate barrier 2
  2841.         ld      e,48
  2842.         ld      hl,SPRITES+8
  2843.         call    SPRITE
  2844.         ld      a,48
  2845.         ld      e,48
  2846.         ld      hl,SPRITES+16
  2847.         call    SPRITE
  2848.  
  2849.         ld      a,72            ; Initiate barrier 3
  2850.         ld      e,48
  2851.         ld      hl,SPRITES+8
  2852.         call    SPRITE
  2853.         ld      a,80
  2854.         ld      e,48
  2855.         ld      hl,SPRITES+16
  2856.         call    SPRITE
  2857.  
  2858. ;████   Initiate aliens   ████
  2859.  
  2860.         ld      a,8             ; -- Initiate aliens
  2861.         ld      e,0
  2862.         ld      ix,ALIENd1
  2863.  
  2864. ALIENL: ld      a,(ix+0)
  2865.         cp      255
  2866.         jp      z,SKP25
  2867.  
  2868.         ld      l,(ix+0)
  2869.         ld      h,0
  2870.         ld      bc,SPRITES
  2871.         add     hl,bc
  2872.  
  2873.         ld      a,(ix+1)
  2874.         ld      e,(ix+2)
  2875.         push    ix
  2876.         call    SPRITE
  2877.         pop     ix
  2878.         inc     ix
  2879.         inc     ix
  2880.         inc     ix
  2881.  
  2882.         jp      ALIENL
  2883.  
  2884.         jp      SKP25
  2885.  
  2886.  
  2887. ;████   Initiate boss   ████
  2888.  
  2889. BOSSINI:
  2890.         ld      a,(LEVELb)      ; Initiate values for current boss
  2891.         cp      3
  2892.         jp      z,BOSSNR1
  2893.  
  2894.         cp      6
  2895.         jp      z,BOSSNR2
  2896.  
  2897.         jp      BOSSNR3
  2898.  
  2899. BOSSNR1:                        ; Init for boss number 1
  2900.         ld      hl,56
  2901.         ld      a,9
  2902.         ld      (BOSShp),a
  2903.         ld      a,3
  2904.         ld      (BOSShs),a
  2905.         ld      a,160
  2906.         ld      (BONUSt2),a
  2907.  
  2908.         jp      ENLARGE
  2909.  
  2910. BOSSNR2:                        ; Init for boss number 2
  2911.         ld      hl,40
  2912.         ld      a,18
  2913.         ld      (BOSShp),a
  2914.         ld      a,6
  2915.         ld      (BOSShs),a
  2916.         ld      a,192
  2917.         ld      (BONUSt2),a
  2918.  
  2919.         jp      ENLARGE
  2920.  
  2921. BOSSNR3:                        ; Init for boss number 3
  2922.         ld      hl,24
  2923.         ld      a,27
  2924.         ld      (BOSShp),a
  2925.         ld      a,9
  2926.         ld      (BOSShs),a
  2927.         ld      a,255
  2928.         ld      (BONUSt2),a
  2929.  
  2930.  
  2931. ENLARGE:
  2932.         ld      bc,SPRITES      ; hl contains sprite_nr*8 to enlarge
  2933.         add     hl,bc
  2934.         ld      de,8265h
  2935.  
  2936.         ld      b,8
  2937. BINIL2: push    bc
  2938.  
  2939.         ld      c,10000000b
  2940.         ld      b,4
  2941. BINIL1: ld      a,(hl)          ; x-enlarge loop
  2942.         and     c
  2943.         cp      0
  2944.         jp      z,SKP43
  2945.         ld      a,11110000b
  2946.         ld      (de),a
  2947.         jp      SKP44
  2948. SKP43:
  2949.         ld      a,0
  2950.         ld      (de),a
  2951. SKP44:
  2952.         srl     c
  2953.         ld      a,(hl)
  2954.         and     c
  2955.         cp      0
  2956.         jp      z,SKP45
  2957.  
  2958.         ld      a,(de)
  2959.         or      00001111b
  2960.         ld      (de),a
  2961.         jp      SKP46
  2962.  
  2963. SKP45:
  2964.         ld      a,(de)
  2965.         and     11110000b
  2966.         ld      (de),a
  2967.  
  2968. SKP46:
  2969.         srl     c
  2970.         inc     de
  2971.         djnz    BINIL1
  2972.  
  2973.         pop     bc
  2974.         inc     de
  2975.         inc     de
  2976.         inc     de
  2977.         inc     de
  2978.         inc     de
  2979.         inc     de
  2980.         inc     de
  2981.         inc     de
  2982.         inc     hl
  2983.  
  2984.         djnz    BINIL2
  2985.  
  2986.         ld      hl,8265h
  2987.         ld      ix,8e29h+96+4
  2988.  
  2989.         ld      b,8
  2990. BINIL4: push    bc
  2991.  
  2992.         ld      b,4
  2993. BINIL3: ld      a,(hl)          ; y-enlarge loop
  2994.         ld      (ix+0),a
  2995.         ld      (ix+12),a
  2996.         ld      (ix+24),a
  2997.         ld      (ix+36),a
  2998.         inc     ix
  2999.         inc     hl
  3000.         djnz    BINIL3
  3001.  
  3002.         ld      bc,44
  3003.         add     ix,bc
  3004.  
  3005.         ld      bc,8
  3006.         add     hl,bc
  3007.  
  3008.         pop     bc
  3009.         djnz    BINIL4
  3010.  
  3011.         ld      hl,24*8+SPRITES
  3012.         ld      a,(BOSShs)
  3013.         ld      b,a
  3014.         ld      a,0
  3015. HPL:    ld      e,0             ; Blit out boss health points
  3016.         push    af
  3017.         push    bc
  3018.         push    hl
  3019.         call    SPRITE
  3020.         pop     hl
  3021.         pop     bc
  3022.         pop     af
  3023.         add     a,9
  3024.         djnz    HPL
  3025.  
  3026.         ld      a,(DIFF)
  3027.         ld      (BOSShl),a
  3028.  
  3029.         ld      a,32
  3030.         ld      (ALASRt),a
  3031.  
  3032.  
  3033. ;████   Print stats and wait for 2nd  ████
  3034.  
  3035. SKP25:
  3036.         call    STAT
  3037.  
  3038.         ld      hl,02621h       ; - Print msg to press 2nd
  3039.         ld      (08252H),hl     ; Update cursorslocation
  3040.         ld      hl,MSG01
  3041.         call    04781h          ; Vputs
  3042.  
  3043.         call    WAIT2ND
  3044.  
  3045.         ld      de,8e29h        ; Copy safe ram area to graphbuf
  3046.         ld      hl,8265h
  3047.         ld      bc,768
  3048.         ldir
  3049.  
  3050.  
  3051. ;████   Init variables   ████
  3052.  
  3053.         ld      a,16            ; Initiate laser timer
  3054.         ld      (LTIMER),a
  3055.  
  3056.         ld      a,(DIFF)        ; Set right difficulty
  3057.         and     00000010b
  3058.         srl     a
  3059.         ld      b,a
  3060.         ld      a,(ALIENys)
  3061.         add     a,b
  3062.         ld      (ALIENys),a
  3063.  
  3064.         inc     sp              ; Adjust stack
  3065.         inc     sp
  3066.  
  3067.         ld      a,(BOSSf)
  3068.         cp      1
  3069.         jp      nz,SKP73
  3070.  
  3071.         ld      hl,MBOSS
  3072.         push    hl
  3073.         jp      DONE0
  3074.  
  3075. SKP73:  ld      hl,MAIN
  3076.         push    hl
  3077.  
  3078. DONE0:
  3079.         ret
  3080. ;▄████████████▄ LVINIT ▄███████████████████████████████████████████████████████
  3081.  
  3082.  
  3083. ;▄████████████▀  INIT  ▀███████████████████████████████████████████████████████
  3084. INIT:
  3085.         call    RINDOFF         ; Runindicator off
  3086.         call    BUFCLR          ; Clear the graphbuf
  3087.  
  3088.         res     0,(iy+20)       ; Reset G-T mode and hor. split mode
  3089.         res     1,(iy+20)
  3090.  
  3091.         ld      de,858fh+100    ; Make backup of the variables start values
  3092.         ld      hl,SHIPx
  3093.         ld      bc,DBYTES
  3094.         ldir
  3095.  
  3096.         ret
  3097. ;▄████████████▄  INIT  ▄███████████████████████████████████████████████████████
  3098.  
  3099.  
  3100. ;▄████████████▀  XIT  ▀████████████████████████████████████████████████████████
  3101. ;┌────────────────────────────────────────────────────────────────────────────┐
  3102. ;│ Exit program and clean up                                                  │
  3103. ;└────────────────────────────────────────────────────────────────────────────┘
  3104. XIT:
  3105.         ld      bc,HSCR4
  3106.  
  3107.         ld      a,c
  3108.         sub     27h
  3109.         ld      c,a
  3110.  
  3111.         ld      a,b
  3112.         sbc     a,93h
  3113.         ld      b,a
  3114.  
  3115.         ld      hl,(PROGPTR)
  3116.         add     hl,bc
  3117.  
  3118.         ld      a,(HSCR4)
  3119.         ld      (hl),a
  3120.         inc     hl
  3121.         ld      a,(HSCR3)
  3122.         ld      (hl),a
  3123.         inc     hl
  3124.         ld      a,(HSCR2)
  3125.         ld      (hl),a
  3126.         inc     hl
  3127.         ld      a,(HSCR1)
  3128.         ld      (hl),a
  3129.         inc     hl
  3130.         inc     hl
  3131.  
  3132.         ld      a,(HSCOREb)
  3133.         ld      (hl),a
  3134.         inc     hl
  3135.         ld      a,(HSCOREb+1)
  3136.         ld      (hl),a
  3137.  
  3138.         call    CLRTSHD         ; Clear textshadow
  3139.         call    GOHOME          ; Leave graphscreen and go to homescreen
  3140.         call    BUFCLR          ; Clear the graphbuf
  3141.         call    READKEY         ; Catch the clear press
  3142.         call    HOMEUP          ; Place cursor at home
  3143.  
  3144.         inc     sp              ; Adjust stack
  3145.         inc     sp
  3146.  
  3147.         res     7,(iy+20)       ; Enable text-direct-to-lcd
  3148.  
  3149.         res     6,(iy+9)        ; Reset statsvalid (I've used safe ram area 2)
  3150.  
  3151.         ei                      ; Enable interrupts
  3152.  
  3153.         ret                     ; Exit program
  3154. ;▄████████████▄  XIT  ▄████████████████████████████████████████████████████████
  3155.  
  3156. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  3157. ;│█████ Z80 ██████│     EQUALS     │█████████████████████│ movax │████████████│
  3158. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  3159.  
  3160. WAITKEY .equ     4CFEh  ; Wait for a key and read
  3161. BUFCLR  .equ     515Bh  ; Clear the graph backup
  3162. BUFCOPY .equ     5164h  ; Copy the graph backup to the screen
  3163. RINDOFF .equ     4795h  ; Turn off runindicator
  3164. PRINTHL .equ     4709h  ; Print HL in dec. on the screen
  3165. OP2TOP1 .equ     41C2h  ; Move OP2 to OP1
  3166. CONVOP1 .equ     4EFCh  ; Convert fp value in OP1 to a 2 byte hex
  3167. READKEY .equ     4A18h  ; Read key and place it in OP2 as a fp value
  3168. GOHOME  .equ     47A1h  ; Go to home screen (finish gfx program)
  3169. CLRTSHD .equ     4765h  ; Clear text shadow
  3170. HOMEUP  .equ     4775h  ; Place cursor at home
  3171. STRING  .equ     470Dh  ; Print 0 terminated string to screen (hl->string)
  3172. HTIMESL .equ     4382h  ; hl=h*l
  3173.  
  3174. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  3175. ;│█████ Z80 ██████│      DATA      │█████████████████████│ movax │████████████│
  3176. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  3177.  
  3178. .include sprites.db
  3179. .include spzlogo.db
  3180.  
  3181. PRGNAME .db     "Spaze Invaders",0
  3182. PROGPTR .dw     0
  3183.  
  3184. DIFF    .db     1               ; Difficulty (1=easy, 2=medium, 3=hard)
  3185.  
  3186. HSCORE  .db     "HighScore:",0  ; HighScore text
  3187. HSCR4   .db     "0"             ; Multiples of thousand in ascii
  3188. HSCR3   .db     "3"             ; Multiples of hundred in ascii
  3189. HSCR2   .db     "0"             ; Multiples of ten in ascii
  3190. HSCR1   .db     "3",0           ; Multiples of one in ascii
  3191. HSCOREb .dw     303             ; HighScore in binary
  3192.  
  3193. MSG01   .db     "Press 2nd",0
  3194. MSG02   .db     "Game Over",0
  3195. MSG03   .db     "Press MODE",0
  3196. MSG04   .db     "Stage Cleared!",0
  3197. MSG05   .db     "cos(42)*sin(303)",0
  3198. MSG06   .db     "CONGRATULATIONS!!!",0
  3199. MSG07   .db     "You have saved all the",0
  3200. MSG08   .db     "hamsters on earth from",0
  3201. MSG09   .db     "the evil aliens",39," claws",0
  3202. MSG10   .db     "Have a nice day!",0
  3203. MSG11   .db     "movax@algonet.se",0
  3204. MSG12   .db     "www.algonet.se/~movax",0
  3205.  
  3206. TXT1    .db     "By Hannes Edfeldt",0
  3207. TXT2    .db     "PRESS 2nd TO START",0
  3208. TXT3    .db     "EASY",0
  3209. TXT4    .db     "MEDIUM",0
  3210. TXT5    .db     "HARD",0
  3211. TXT6    .db     "ALIEN CODE",0
  3212. TXT7    .db     "presents",0
  3213.  
  3214. VERt    .db     "v1.0"  ; Version text
  3215.  
  3216. LEVEL   .db     "Level:",0      ; Level text
  3217. LEVELa  .db     "1",0           ; Level in ascii
  3218. LEVELb  .db     1               ; Level in binary
  3219.  
  3220. SCORE   .db     "Score:",0      ; Score text
  3221. SCR4    .db     "0"             ; Multiples of thousand in ascii
  3222. SCR3    .db     "0"             ; Multiples of hundred in ascii
  3223. SCR2    .db     "0"             ; Multiples of ten in ascii
  3224. SCR1    .db     "0",0           ; Multiples of one in ascii
  3225. SCOREb  .dw     0               ; Player score in binary
  3226.  
  3227. LIVES   .db     "Lives:",0      ; Lives text
  3228. LIVESa  .db     "3",0           ; Lives in ascii
  3229. LIVESb  .db     3               ; Lives left in binary
  3230.  
  3231. BONUS   .db     "Bonus:",0      ; Bonus text
  3232. BONUS3  .db     "0"
  3233. BONUS2  .db     "0"
  3234. BONUS1  .db     "0",0
  3235. BONUSt1 .db     20              ; Bonus timer 1
  3236. BONUSt2 .db     128             ; Bonus timer 2 (the actual bonus to get)
  3237. BONUSdc .db     0               ; Bonus decrement timer
  3238.  
  3239. BOXx    .db     0       ; Box x-coordinate
  3240. BOXy    .db     0       ; Box y-coordinate
  3241. BOXxs   .db     0       ; Box x-size
  3242. BOXys   .db     0       ; Box y-size
  3243. BOXp    .dw     0       ; Box sprite ptr
  3244.  
  3245. TEMP    .db     0       ; Temp store
  3246.         .db     0       ; Extra temp byte
  3247. TEMP2   .db     0       ; Temp store 2
  3248.         .db     0       ; Extra temp byte
  3249.  
  3250. TIME    .db     1       ; Time for a boss level?
  3251.  
  3252. STARTy  .db     0       ; y-coordinate for aliens to start at
  3253.  
  3254.  
  3255.  
  3256. SHIPx   .db     0       ; Ship x-coordinate
  3257. OSHIPx  .db     0       ; Old ship x-coordinate
  3258.  
  3259. SLASRx  .db     0       ; Ship laser x-coordinate
  3260. SLASRy  .db     252     ; Ship laser y-coordinate (252=no laserbeam)
  3261. LTIMER  .db     0       ; 0=ok to fire laser, >0=wait
  3262.  
  3263. ALIENm  .db     2       ; Alien x movement speed
  3264. ALIENys .db     1       ; Alien y movement speed (based on DIFF)
  3265. ALIENmy .db     0       ; Alien movement y (0=no movement, 1=movement)
  3266. ALIENmc .db     0       ; Alien movement change (0=no change, 1=time to change)
  3267. ALIENli .db     0       ; How many lines down has aliens moved yet
  3268. ALIENc  .db     0       ; Alien counter (which alien to move)
  3269. ALIENa  .db     8       ; Alien anim frame add
  3270. ALIENk  .db     0       ; Number of aliens killed
  3271.  
  3272. ALIENr1 .db     8       ; Aliens left in row 1
  3273. ALIENr2 .db     8       ; Aliens left in row 2
  3274. ALIENr3 .db     8       ; Aliens left in row 3
  3275. ALIENr4 .db     8       ; Aliens left in row 4
  3276.  
  3277. RIPt    .db     0       ; RIP timer
  3278. RIPp    .dw     0       ; RIP pointer
  3279.  
  3280. ALASRx  .db     0       ; Alien laser x coordinate
  3281. ALASRy  .db     0       ; Alien laser y coordinate
  3282. ALASRf  .db     0       ; Alien laser flag
  3283. ALASRt  .db     0       ; Alien laser timer
  3284. ALASRp  .dw     0       ; Pointer to the alien who shot the last beam
  3285.  
  3286. BOSSx   .db     32      ; Boss x-coordinate
  3287. BOSSmd  .db     1       ; Boss movement direction
  3288. BOSSxc  .db     31      ; Boss x-movement counter
  3289. BOSSmc  .db     0       ; Boss "time-to-move?" counter
  3290. BOSSf   .db     0       ; Is this a boss level? / Boss alive?
  3291. BOSShp  .db     03      ; Boss health points
  3292. BOSShs  .db     01      ; Boss health point sprites
  3293. BOSSld  .db     0       ; Boss shot destination
  3294. BOSSlt  .db     0       ; Boss shot timer
  3295. BOSShl  .db     0       ; Hits left before boss lose on hp
  3296. BOSSkr  .db     16,8,8,32,16,24,24,8    ; Boss kill random
  3297.         .db     0,16,24,32,0,8,16,16
  3298.         .db     24,24,8,8,0,32,8,24
  3299.         .db     24,16,16,32,8,16,0,24
  3300.  
  3301. MENUc   .db     1       ; Menu choice (1=easy, 2=medium, 3=hard)
  3302. MENUoc  .db     1       ; Menu old choice
  3303. MENUt   .db     12      ; Menu timer
  3304.  
  3305. FLASHt  .db     16      ; Flash timer
  3306. FLASHf  .db     0       ; Flash flag
  3307.  
  3308. LOGOl   .db     0       ; Logo line in fx process
  3309.  
  3310. ALIENd1 .db     24,8,0  ; First line of alien data (sprite address,x,y)
  3311.         .db     24,18,0
  3312.         .db     24,28,0
  3313.         .db     24,38,0
  3314.         .db     24,48,0
  3315.         .db     24,58,0
  3316.         .db     24,68,0
  3317.         .db     24,78,0
  3318.  
  3319. ALIENd2 .db     40,8,10 ; Second line of alien data (sprite address,x,y)
  3320.         .db     40,18,10
  3321.         .db     40,28,10
  3322.         .db     40,38,10
  3323.         .db     40,48,10
  3324.         .db     40,58,10
  3325.         .db     40,68,10
  3326.         .db     40,78,10
  3327.  
  3328. ALIENd3 .db     56,8,20 ; Third line of alien data (sprite address,x,y)
  3329.         .db     56,18,20
  3330.         .db     56,28,20
  3331.         .db     56,38,20
  3332.         .db     56,48,20
  3333.         .db     56,58,20
  3334.         .db     56,68,20
  3335.         .db     56,78,20
  3336.  
  3337. ALIENd4 .db     56,8,30 ; Fourth line of alien data (sprite address,x,y)
  3338.         .db     56,18,30
  3339.         .db     56,28,30
  3340.         .db     56,38,30
  3341.         .db     56,48,30
  3342.         .db     56,58,30
  3343.         .db     56,68,30
  3344. ALAST:  .db     56,78,30
  3345.  
  3346.         .db     255     ; End of alien data
  3347.  
  3348. DBYTES  .equ    ($-SHIPx-1)
  3349.  
  3350. .end
  3351. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  3352. ;│█████ Z80 ██████│ Spaze Invaders │█████████████████████│ movax │████████████│
  3353. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  3354.