+ ld a,(your_occ) ;are you 100% OK?
+ or a ;a=0??
+ jr nz,_gamestuff1 ;then don't check for movements/fires/...
+
+ ld a,(level_move) ;the same level info
+ and %01100000 ;isolate ground&ceiling again
+ jr z,check_keys ;no ceiling nor ground
+ and %00100000 ;this bit will tell us if there is a ceiling
+ cal nz,CheckCeiling ;if there is, check it
+ cal CheckGround ;check for collision with the ground
+
+check_keys:
+ cal GET_KEY
+ cp K_GRAPH
+ cal z,Teacher
+
+ ld a,%00111111 ;function keys (MORE,EXIT,2ND,F1,F2,F3,F4,F5)
+ out (1),a ;ask for them
+ nop \ nop ;delay 8 clocks
+ in a,(1) ;get zem!
+
+check_exitkey:
+ bit 6,a ;test bit 6 = exit-key = EXIT
+ jp z,game_over_nopop ;<exit> pressed, so be it
+check_morekey: ;another unused label... poor compiler
+ bit 7,a ;test bit 7 = more-key = PAUSE
+ cal z,Pause ;yes, go to pause
+
+check_firekey:
+ bit 5,a ;test bit 5 = 2nd-key = FIRE
+ ld hl,check_selkey ;where to continue after executing Fire_bullet
+ psh hl ;push hl on stack (instead of cal Fire_bullet)
+ jp z,Fire_bullet ;fire smtn (bulletstorplasermultiples+stuff..)
+ pop hl ;no cal to Fire_bullet made, so pop stack
+ ld hl,just_fired ;no:
+ ld (hl),0 ;reset just_fired
+
+check_selkey:
+ ld a,%01011111 ;look at first column of keys (ALPHA to STO)
+ out (1),a ;gimme
+ nop \ nop ;what's taking you so long
+ in a,(1) ;at last... our precious keyzzz...
+ ;old: <bit 7,a \ cal z,select> now see this:
+ rla ;test bit7 so we know f ALPHA has been pressed
+ cal nc,select ;yeppy, select the currently selected upgrade
+
+ cal Enemies_hit ;check for collision with enemies
+
+_gamestuff1:
+ cal Handle_Ship ;move you
+ cal Handle_bullets ;move your bullets
+ cal Handle_torp ;move your torpedo
+
+ cal Handle_enemies ;move enemies
+ cal Enemy_bullets ;move enemy bullets
+
+ cal Level_event ;insert enemies
+ cal Display_Screen ;display all
+ halt ;delay
+
+ jp game_main_loop ;LOOP
+
+;--------------------------- ground -------------------------------------------
+
+Handle_ground:
+ ld a,(timer)
+ and %111 ;once every 8 frames
+ jr nz,Display_ground ;otherwise skip the scroll
+ ld bc,15 ;scroll all 16 bytes minus one (teh new byte)
+ ld hl,groundpos+1 ;from..
+ ld de,groundpos ;to (one byte to the left)
+ ldir ;LoaDIncreaseRepeat = scroll!
+
+ ld a,(groundinfo) ;what kind of ground
+ dec a ;type 1:
+ jr z,ground_tunnel ;tunnel effect
+ jr ground_boring
+
+ground_tunnel:
+ ld a,(groundpos+14)
+ ld (groundpos+15),a
+ ld hl,spacespace
+
+ ld a,(RanPos)
+ ld b,a
+ bit 1,a
+ jr z,ground_previous
+ bit 2,a
+ jr z,gtunneldown
+gtunnelup:
+ ld a,(hl)
+ or a
+ jr z,ground_previous ;a>=0 (a=0 actually)
+ inc (hl)
+ ld a,(groundpos+15)
+ inc a
+ jr newground
+gtunneldown:
+ ld a,(groundpos+15)
+ dec a
+ jr z,ground_previous
+ dec (hl)
+ jr newground
+
+ground_previous:
+ ld a,(groundpos+14) ;type 1
+ jr newground
+ground_boring:
+ ld a,(groundpos) ;type 0
+newground:
+ ld (groundpos+15),a ;save new byte on the right
+ ld a,(hl)
+ cp -25
+ jr nc,Display_ground
+ ld a,b
+ and %1
+ ld b,0
+ jr nz,gtunnelup
+
+Display_ground:
+ ld b,16 ;screen width
+ ld de,groundpos-1 ;height of current byte (previous actually)
+ psh de ;use later
+ ld hl,GRAPH_MEM+(56*16)-1 ;screen position
+ psh hl
+
+groundloopright:
+ ld c,b ;push b for groundloopup
+ pop hl \ inc hl ;get screen position and go one right
+ pop de \ inc de ;get height info and set to the next byte
+ psh de \ psh hl ;save these for the next time
+ ld a,(de) ;height of current byte
+ ld b,a ;save in b
+
+ ld de,16 ;to substract to go one line up
+ ld a,%11111111 ;bitmask black
+ or a
+groundloopup:
+ ld (hl),a ;display black byte
+ sbc hl,de ;go up (sbc must be used for 16-bit sub)
+ djnz groundloopup ;and loop >groundpos< times
+
+ ld b,c ;pop b used by groundloopup
+ djnz groundloopright ;loop right for entire screen (16x)
+ pop hl \ pop hl ;restore stack
+ ret