home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / diamonds.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  34.7 KB  |  1,813 lines

  1. ;Diamonds 1.3
  2. ;by Jonah Cohen <ComAsYuAre@aol.com>
  3.  
  4. #include "TI86.inc"
  5.  
  6. .org _asm_exec_ram
  7.  
  8.     nop
  9.     jp start
  10.     .dw 1
  11. grayscale_counter = $-1    ;save memory :-)
  12.     .dw description
  13.     .dw icon
  14.  
  15. getkey:
  16.     halt
  17.     call _getcsc
  18.     or a
  19.     jr z,getkey
  20.     ret
  21.  
  22. MultHL:
  23.     xor a
  24.     cp h
  25.     jr z,SetZero
  26.     cp l
  27.     jr z,SetZero
  28.     push bc
  29.     call _HTIMESL
  30.     pop bc
  31.     ret
  32. SetZero:
  33.     ld hl,0
  34.     ret
  35.  
  36. ; modified routine originally by Matthew Shepcar
  37. GetA:
  38.     ld l,a
  39.     ld h,0
  40. GetHL:
  41.     xor a
  42.     ld de,-1
  43.     ld (_curRow),de
  44.     push bc
  45.     call $4a33
  46.     pop bc
  47.     dec hl
  48. DiscardSpaces:
  49.     ld a,(hl)
  50.     inc hl
  51.     cp ' '
  52.     jr z,DiscardSpaces
  53.     dec hl
  54.     ret
  55.  
  56. DispA:
  57.     ld l,a
  58.     ld h,0
  59.     jr DispHL
  60.  
  61. DispAStatus:
  62.     ld l,a
  63.     ld h,0
  64. DispHLStatus:
  65.     ld c,$72
  66. DispHL:
  67.     call GetHL
  68.     push bc
  69.     push hl
  70.     ld bc,10
  71.     xor a
  72.     cpir            ;bc=9-size
  73.     ld a,9
  74.     sub c
  75.     pop hl
  76.     pop bc
  77.     add a,a        ;multiply by 2
  78.     cpl
  79.     add a,c        ;center column
  80.     ld c,a        ;load into current column
  81.     jr vputs
  82.  
  83. vputs_b:
  84.     ld b,(hl)
  85.     inc hl
  86. vputs_loop:
  87.     push bc
  88.     call vputs_
  89.     pop bc
  90.     djnz vputs_loop
  91.     ret
  92.  
  93. vputs_:
  94.     ld c,(hl)
  95.     inc hl
  96.     ld b,(hl)
  97.     inc hl
  98. vputs:
  99.     ld (_penCol),bc
  100.     jp _vputs
  101.  
  102. disp_title:
  103.     ld hl,titlepic
  104.     ld de,buffer_dark
  105.     call DispRLE
  106.     ld de,buffer_light
  107. DispRLE:
  108.     ld bc,256            ; we need to copy 
  109. DispRLEL:
  110.     ld a,(hl)            ; get the next byte
  111.     cp $91            ; is it a run?
  112.     jr z,DispRLERun    ; then we need to decode the run
  113.     ldi                ; copy the byte, and update counters
  114. DispRLEC:
  115.     ld a,b            ; check the low byte and
  116.     or c                ; the high byte for 0
  117.     jr nz,DispRLEL        ; if not, then we're not done either
  118.     ret                ; it's zero, we're done
  119. DispRLERun:
  120.     inc hl                ; move to the run value
  121.     ld a,(hl)            ; get the run value
  122.     inc hl                ; move to the run count
  123.     push hl            ; save source pointer
  124.     ld h,(hl)            ; get the run count
  125.     ex de,hl            ; swap source and destination pointers
  126. DispRLERunL:
  127.     ld (hl),a            ; copy the byte
  128.     inc hl                ; increase destination pointer
  129.     dec bc            ; decrease byte count
  130.     dec d            ; decrease run count
  131.     jr nz,DispRLERunL    ; if we're not done, then loop
  132.     ex de,hl            ; swap pointers back
  133.     pop hl            ; recover source pointer
  134.     inc hl                ; advance the source pointer
  135.     jr DispRLEC        ; check to see if we should loop
  136.  
  137. split:
  138. ;copy from buffer to screen
  139.     ld de,32                ;to get to next row
  140. split_bytes:
  141.     ld a,8                ;8 bits
  142. split_byte:
  143. ;get right-shift addresses (we add 32 before accessing)
  144.     ld hl,screen_light-32
  145.     ld (dest_right),hl
  146.     ld hl,buffer_light+$0f-32
  147. source_right_start = $-2
  148.     ld (source_right),hl
  149. ;get left-shift addresses
  150.     ld hl,screen_light+$1f-32
  151.     ld (dest_left),hl
  152.     ld hl,buffer_light+$10-32
  153. source_left_start = $-2
  154.     ld (source_left),hl
  155. ;split the screen once
  156.     ld b,64                ;number of rows / 2
  157. split_screen:
  158. ;shift left
  159.     ld hl,0
  160. source_left = $-2
  161.     add hl,de                ;next row
  162.     ld (source_left),hl
  163.     rlc (hl)
  164.     push af                ;save carry
  165.     ld hl,0
  166. dest_left = $-2
  167.     add hl,de
  168.     ld (dest_left),hl
  169.     pop af                ;get carry
  170.     call shift_left
  171. ;shift right
  172.     ld hl,0
  173. source_right = $-2
  174.     add hl,de                ;next row
  175.     ld (source_right),hl
  176.     rrc (hl)
  177.     push af                ;save carry
  178.     ld hl,0
  179. dest_right = $-2
  180.     add hl,de                ;next row
  181.     ld (dest_right),hl
  182.     pop af                ;get carry
  183.     call shift_right
  184. ;loop
  185.     djnz split_screen
  186.     dec a
  187.     jr nz,split_byte
  188.     ld hl,source_right_start
  189.     dec (hl)
  190.     ld hl,source_left_start
  191.     inc (hl)
  192.     jr nz,split_bytes
  193.     ld (hl),$f0
  194.     ld hl,source_right_start
  195.     ld (hl),$ef
  196.     ret
  197.  
  198. vert_line
  199.     ld b,62:
  200.     ld de,16
  201. vert_line_loop:
  202.     ld a,c
  203.     or (hl)
  204.     ld (hl),a
  205.     add hl,de
  206.     djnz vert_line_loop
  207.     sbc hl,de
  208.     ret
  209.  
  210. horiz_line:
  211.     ld (hl),%01111111
  212.     ld bc,$0fff
  213. horiz_line_loop:
  214.     inc hl
  215.     ld (hl),c
  216.     djnz horiz_line_loop
  217.     res 0,(hl)
  218.     ret
  219.  
  220. duplicate_buffer:
  221.     ld hl,buffer_dark
  222.     ld de,buffer_light
  223.     ld bc,1024
  224.     jr copy
  225.  
  226. copy_screen:                ;just copy to video mem
  227.     ld hl,buffer_light
  228.     ld de,screen_light
  229.     ld bc,2048
  230. copy:
  231.     ldir
  232.     ret
  233.  
  234. draw_spaces:                ;display d spaces at (b,c)
  235.     push af
  236.     push bc
  237.     push hl
  238.     ld (_penCol),bc
  239. space_loop:
  240.     push de
  241.     call _VPUTBLANK
  242.     pop de
  243.     dec d
  244.     jr nz,space_loop
  245.     pop hl
  246.     pop bc
  247.     pop af
  248.     ret
  249.  
  250. create_shift_loop:
  251.     ld bc,$10cb
  252. create_routine:
  253.     inc hl
  254.     ld (hl),c
  255.     inc hl
  256.     ld (hl),d
  257.     inc hl
  258.     ld (hl),e
  259.     djnz create_routine
  260.     ld (hl),$c9
  261.     ret
  262.  
  263.  
  264. check_level:
  265. ;nz if not a diamonds level
  266.     rst 10h                ;do a _findsym to get bde
  267.     ret c
  268.     call _DATA_SIZE_TO_DE
  269.     call _GETB_AHL        ;get first byte and hl->string now
  270.     cp $dd
  271.     ret nz
  272.     inc hl    
  273.     ld a,(hl)                ;get second byte
  274.     dec a                ;cp $01
  275.     ret
  276.  
  277. load_levels:
  278.     push bc
  279.     ld hl,level_name
  280.     rst 20h                ;move to op1
  281.     rst 10h                ;_findsym
  282.     call _DATA_SIZE_TO_DE    ;de=size, ahl=bde+2
  283.     push de
  284.     call _SET_ABS_SRC_ADDR
  285.     pop hl
  286.     xor a
  287.     call _SET_MM_NUM_BYTES    ;size to copy
  288.     inc a
  289.     ld hl,highscore-2-$8000    ;signature bytes go right before highscore
  290.     call _SET_ABS_DEST_ADDR    ;copy here for now
  291.     call _MM_LDIR
  292.     call _RAM_PAGE_1
  293.     ld hl,num_levels
  294.     pop bc                ;retrieve description
  295.     call vputs                ;display description
  296.     ld a,(hl)                ;get number of levels
  297.     push hl
  298.     ld h,a
  299.     ld l,42
  300.     call MultHL            ;get size
  301.     inc hl
  302.     push hl
  303.     ld de,num_levels
  304.     pop bc                ;retrieve size
  305.     pop hl                ;retrieve pointer to end of string
  306.     ldir                    ;copy over description
  307.     ret
  308.  
  309. resume_game:
  310.     im 2
  311.     ld hl,level_name
  312.     rst 20h
  313.     call check_level
  314.     jr nz,no_resume
  315.     ld c,200                ;off screen
  316.     call load_levels
  317.     ld a,(num_levels)
  318.     ld b,a
  319.     ld a,(level_num)
  320.     cp b
  321.     jr nc,no_resume
  322.     ld hl,bonus
  323.     inc (hl)
  324.     jp start_playing
  325.  
  326. start:
  327.     call _runIndicOff
  328.     call _flushAllMenus
  329.     ld hl,$f7ff-$fbff
  330.     add hl,sp
  331.     ld sp,hl
  332.     ld hl,$fbff
  333.     ld de,$f7ff
  334.     ld bc,256
  335.     lddr
  336.     ld (save_sp),sp            ;save stack pointer
  337.     ld hl,_contrast
  338.     ld a,(hl)
  339.     inc a
  340.     cp $20
  341.     jr nc,no_contrast
  342.     ld (hl),a
  343.     out (2),a
  344. no_contrast:
  345.     ld hl,shift_left-1
  346.     ld de,$162b
  347.     call create_shift_loop
  348.     ld de,$1e23
  349.     call create_shift_loop
  350.     call duplicate_buffer
  351.     call copy_screen
  352.  
  353. ;install grayscale
  354.     ld hl,int_start
  355.     ld de,$f0f0
  356.     ld bc,int_end-int_start
  357.     ldir
  358.     ld hl,int_table
  359.     ld (hl),$f0
  360.     ld de,int_table+1
  361.     inc b
  362.     ldir
  363.     ld a,int_table/256
  364.     ld i,a
  365.  
  366. ;check game saved
  367.     ld hl,resumed
  368.     srl (hl)
  369.     jr c,resume_game
  370. no_resume:
  371.     xor a
  372.     ld (level_num),a            ;a=0, so first level
  373.  
  374. title_screen:
  375.     ld sp,0
  376. save_sp = $-2
  377.  
  378.     im 2
  379.     ld a,$37
  380.     ld (first_screen),a
  381.     call _clrLCD
  382.     call disp_title
  383.     ld hl,name
  384.     ld bc,$1128
  385.     call vputs
  386.     ld hl,level_name            ;load previously saved level
  387.     rst 20h
  388.     call check_level
  389.     jr z,finish_title_screen        ;valid level, so we just keep it
  390. get_new_level:
  391.     ld hl,starting_name
  392.     rst 20h                ;copy starting varname to op1
  393. find_first_level:
  394.     rst 08h                ;op1 to op2
  395.     xor a
  396.     call _findAlphaUp        ;search for string
  397.     jr c,no_levels            ;no strings
  398.     call check_level
  399.     jr z,finish_level_detect        ;valid level
  400. ;now we check if we're getting anywhere in this search
  401.     ld hl,_OP1+1
  402.     ld de,_OP2+1
  403.     call _pstrCmp            ;see if name has changed
  404.     jr nz,find_first_level        ;keep searching if name is changing
  405.  
  406. no_levels:
  407.     ld hl,error_txt
  408.     call vputs_
  409.     call duplicate_buffer
  410.     call split
  411.     call getkey
  412.     jp exit
  413.  
  414. finish_level_detect:
  415.     ld de,level_name
  416.     call _MOVFROP1        ;save level name
  417. finish_title_screen:
  418.     ld hl,menu_txt
  419.     call vputs_b
  420.     ld hl,0
  421.     ld (score),hl            ;starting score
  422. update_level:
  423.     ld bc,$323a
  424.     push bc                ;save coordinates
  425.     ld d,70
  426.     call draw_spaces        ;erase previous description
  427.     pop bc
  428.     call load_levels
  429.     ld bc,$3a52
  430.     push bc
  431.     ld d,40
  432.     call draw_spaces
  433.     pop bc
  434.     ld hl,initials
  435.     call vputs                ;display initials
  436.     call _VPUTBLANK
  437.     call _VPUTBLANK        ;for spacing
  438.     ld hl,(highscore)
  439.     call GetHL
  440.     call _vputs                ;display after initials
  441. update_speed:
  442.     ld a,(speed)
  443.     ld bc,$2a55
  444.     call DispA                ;display speed
  445. update_level_num:
  446.     ld bc,$224c
  447.     push bc
  448.     ld d,15
  449.     call draw_spaces        ;overwrite last level number
  450.     ld a,(level_num)
  451.     inc a
  452.     call GetA
  453.     pop bc                ;retrieve coordinates
  454.     call vputs
  455.     ld hl,buffer_dark+256
  456.     ld de,buffer_light+256
  457.     ld bc,1024-256
  458.     ldir
  459. first_screen:
  460.     scf
  461.     call c,split
  462.     ld a,$b7
  463.     ld (first_screen),a
  464.     call copy_screen
  465. get_selections:
  466.     call getkey
  467.     cp K_EXIT
  468.     jp z,exit
  469.     dec a                ;cp K_DOWN
  470.     jr z,level_down
  471.     sub K_F1-1
  472.     jr z,first_level
  473.     inc a
  474.     jr z,speed_up
  475.     inc a
  476.     jr z,get_next_level
  477.     cp K_UP-K_F3
  478.     jr nz,get_selections
  479.  
  480. level_up:
  481.     ld hl,level_num
  482.     inc (hl)
  483.     ld a,(num_levels)
  484.     cp (hl)                ;check if we're at the max
  485.     jr nz,update_level_num
  486.     ld (hl),0                ;first level
  487.     jr update_level_num
  488.  
  489. level_down:
  490.     ld hl,level_num
  491.     dec (hl)
  492.     ld a,(hl)
  493.     inc a                    ;see if we're at -1
  494.     jr nz,update_level_num
  495.     ld a,(num_levels)
  496.     ld (hl),a                ;go to max
  497.     jr level_down            ;now decrement it once
  498.  
  499. speed_up:
  500.     ld hl,speed
  501.     inc (hl)
  502.     ld a,(hl)
  503.     cp 6
  504.     jp nz,update_speed
  505.     ld (hl),1
  506.     jr update_speed
  507.  
  508. get_next_level:
  509.     xor a
  510.     ld (level_num),a            ;reset level number for new level
  511.     ld hl,level_name
  512.     rst 20h                ;mov10toop1
  513. detect_level:
  514.     ld de,temp_search_name
  515.     call _MOVFROP1
  516.     xor a
  517.     call _findAlphaUp        ;search for string
  518.     ld hl,_OP1+1
  519.     ld de,temp_search_name+1
  520.     call _pstrCmp
  521.     jr z,get_first_level        ;same var, so we're at end of alphabet.
  522.     call check_level
  523.     jr nz,detect_level        ;invalid level
  524. save_new_level:
  525.     ld de,level_name
  526.     call _MOVFROP1        ;copy new name
  527.     jp update_level
  528. ;same name, so we load default name and find first level
  529. get_first_level:
  530.     ld hl,starting_name
  531.     rst 20h                ;copy starting varname to op1
  532. find_a_level:
  533.     xor a
  534.     call _findAlphaUp
  535.     call check_level
  536.     jr nz,find_a_level            ;keep searching until we find something
  537.     jr save_new_level
  538.  
  539. first_level:
  540.     ld a,5
  541.     ld (lives),a                ;starting lives
  542. start_level:
  543.     ld a,(level_num)
  544.     ld h,a
  545.     ld l,42
  546.     call MultHL
  547.     ld de,levels
  548.     add hl,de                ;hl->level data
  549.     ld de,start_coords
  550.     ldi
  551.     ldi                    ;copy ball coordinates
  552.     ld b,40                ;40 bytes to copy
  553.     xor a
  554. decomp_level:
  555.     rld
  556.     ld (de),a
  557.     inc de
  558.     rld
  559.     ld (de),a
  560.     inc de
  561.     inc hl
  562.     djnz decomp_level
  563.  
  564.     ld hl,1*256+61
  565.     ld (bonus),hl            ;the bonus score for the round, direction=down
  566.     xor a
  567.     ld (hit_key),a            ;not active yet
  568.     ld (reverse_mode),a        ;regular keys
  569.     inc a
  570.     ld (brick_mode),a        ;white bricks
  571.     ld hl,(start_coords)
  572.     ld (ball_y),hl
  573.  
  574. start_playing:
  575.     ld hl,speed_table
  576.     ld a,(speed)
  577.     ld e,a
  578.     ld d,0
  579.     add hl,de                ;add offset
  580.     ld h,(hl)                ;get bonus delay
  581.     ld a,5
  582.     sub e                ;get regular delay
  583.     ld l,a
  584.     ld (delay_amount),hl
  585.  
  586.     call _clrLCD
  587.     ld hl,$fc10
  588.     push hl
  589.     ld c,%01000000
  590.     call vert_line
  591.     call horiz_line
  592.     pop hl
  593.     call horiz_line
  594.     ld c,%00000010
  595.     call vert_line
  596.     ld hl,$fc1c
  597.     ld c,%00100000
  598.     call vert_line
  599.     ld de,row_table
  600.     ld h,$fc
  601. draw_rows:
  602.     ld a,(de)
  603.     ld l,a
  604.     inc de
  605.     ld (hl),%00111111
  606.     inc l
  607.     ld (hl),%11111111
  608.     inc l
  609.     ld (hl),%11111111
  610.     inc l
  611.     ld (hl),%11111110
  612.     inc h
  613.     jr nz,draw_rows
  614.     call duplicate_buffer
  615.     bit 3,(iy+5)
  616.     call nz,invert_screen
  617.  
  618.     ld hl,side_txt
  619.     call vputs_b
  620.     call draw_bonus
  621.     ld hl,(score)
  622.     ld b,$24
  623.     call DispHLStatus        ;display starting score
  624.     call draw_lives
  625.  
  626. ;display the level
  627.     ld hl,current_level
  628.     ld bc,$0202    ;start drawing at (2,2)
  629. level_loop:
  630.     push hl
  631.     ld h,(hl)        ;get the current tile
  632.     call put_brick    ;draw the sprite
  633.     pop hl        ;restore map pointer
  634.     inc hl            ;go to next tile
  635.     ld a,b
  636.     add a,12
  637.     ld b,a
  638.     cp 98        ;end of row
  639.     jr nz,level_loop    ;only jump if the row isn't complete
  640.     ld b,2        ;draw at the left again
  641.     ld a,c
  642.     add a,6
  643.     ld c,a        ;move location down a row
  644.     cp 62        ;check if it's done
  645.     jr nz,level_loop    ;jump back to the top if not done
  646.  
  647.     ld a,(level_num)
  648.     inc a
  649.     ld b,$16
  650.     call DispAStatus        ;display the level
  651.     call draw_brick_mode        ;display brick mode
  652.     ld a,1                ;set bonus delay
  653.     ld (bonus_delay),a
  654.     call draw_bonus            ;display bonus
  655.     call draw_ball            ;display the ball
  656.     call split                ;copy to screen
  657.  
  658. new_life:
  659.     call copy_screen        ;show ball
  660.     ld b,80                ;delay with ball showing
  661. start_delay_loop:
  662.     halt
  663.     djnz start_delay_loop
  664.  
  665. ;************************************************main loop
  666.  
  667. main_loop:
  668.     call check_bricks        ;check how many bricks left
  669.     call anim_ball            ;draw the ball
  670.     call draw_bonus            ;display the bonus
  671.     call check_keys            ;check for keys
  672.     call delay                ;speed control
  673.     call copy_screen        ;copy buffer to display
  674.     jr main_loop
  675.  
  676. ;************************************************update lives
  677. draw_lives:
  678.     ld a,(lives)
  679.     ld bc,$642d
  680. ball_draw_loop:
  681.     push af
  682.     call put_ball
  683.     ld a,b
  684.     add a,5
  685.     ld b,a
  686.     pop af
  687.     dec a
  688.     jr nz,ball_draw_loop
  689.     ret
  690.  
  691. ;************************************************update bonus
  692. draw_bonus:
  693.     ld hl,bonus_delay
  694.     dec (hl)
  695.     ret nz
  696.     ld a,(bonus)
  697.     or a
  698.     ret z
  699.     ld a,(bonus_delay_amount)
  700.     ld (hl),a                ;new counter
  701. bonus_skip_delay:            ;skip delay
  702.     ld bc,$086d
  703.     ld hl,bonus
  704.     dec (hl)
  705.     ld a,(hl)
  706.     cp 9
  707.     jr nz,skip_spaces
  708.     ld d,7
  709.     call draw_spaces        ;overwrite old bonus with spaces
  710. skip_spaces:
  711.     jp DispAStatus            ;display the bonus
  712.  
  713. ;************************************************update score
  714. draw_score:
  715. ;increment score and display it
  716.     ld hl,(score)
  717.     inc hl
  718.     ld (score),hl
  719.     push hl
  720.     ld b,$24
  721.     call DispHLStatus
  722.     pop hl
  723.     ld a,(lives)
  724.     cp 5
  725.     ret z                    ;can't have more than 5 lives
  726.     ld de,400
  727. sub_loop:
  728.     or a
  729.     sbc hl,de
  730.     ret c                    ;not divisible by 400
  731.     jr nz,sub_loop            ;not done yet
  732. ;divisible by 400, so we get an extra life
  733.     call draw_lives
  734.     ld hl,lives
  735.     inc (hl)
  736.     jr draw_lives            ;draw new lives
  737.  
  738. ;************************************************check keys
  739. check_keys:
  740.     ld a,%01111101
  741.     out (1),a
  742.     in a,(1)
  743.     cpl
  744.     and 24
  745.     cp 24
  746.     jr z,invert
  747.     ld a,$b7
  748.     ld (invert),a
  749. no_invert:
  750.     ld a,%01111110
  751.     out (1),a
  752.     in a,(1)
  753.     rra \ rra                ;left
  754.     push af
  755.     call nc,move_left
  756.     pop af
  757.     rra                    ;right
  758.     call nc,move_right
  759.     call _getcsc
  760.     cp K_CLEAR
  761.     jp z,lose_life
  762.     cp K_DEL
  763.     jr z,save
  764.     cp K_EXIT
  765.     jp z,check_hiscore
  766.     cp K_MORE
  767.     ret nz                ;2nd
  768.  
  769. pause:
  770.     call getkey
  771.     ld b,1
  772.     cp K_PLUS
  773.     jr z,set_contrast
  774.     ld b,-1
  775.     cp K_MINUS
  776.     ret nz
  777.  
  778. set_contrast:
  779.     ld hl,_contrast
  780.     ld a,(hl)
  781.     add a,b
  782.     cp 32
  783.     jr nc,pause
  784.     ld (hl),a
  785.     out (2),a
  786.     jr pause
  787.  
  788. save:
  789.     ld a,1
  790.     ld (resumed),a
  791.     ld sp,(save_sp)
  792.     jp exit
  793.  
  794. invert:
  795.     or a
  796.     jr c,no_invert
  797.     ld a,$37
  798.     ld (invert),a
  799.     ld hl,_Flags+textFlags
  800.     ld a,(hl)
  801.     xor %00001000            ;toggle inverted text
  802.     ld (hl),a
  803. invert_screen:
  804.     ld hl,buffer_light
  805.     ld bc,8
  806. invert_loop:
  807.     ld a,(hl)
  808.     cpl
  809.     ld (hl),a
  810.     inc hl
  811.     djnz invert_loop
  812.     dec c
  813.     jr nz,invert_loop
  814.     ret
  815.  
  816. ;************************************************check high score
  817. check_hiscore:
  818.     res 3,(iy+5)            ;not inverted text
  819.     ld hl,(highscore)
  820.     ld de,(score)
  821.     call _cphlde
  822.     jp nc,title_screen        ;no high score
  823.     ld (new_highscore),de        ;save new high score
  824.     call _clrScrn
  825.     ld hl,high_score
  826.     call vputs_b
  827.     ld hl,$0904
  828.     ld (_curRow),hl
  829.     call duplicate_buffer
  830.     call split
  831.     im 1
  832.     ld a,(screen_dark/256)-$80
  833.     out (0),a
  834.     ld hl,new_initials
  835.  
  836. get_string:
  837.     push hl
  838.     ld a,(_curCol)
  839.     cp 12
  840.     ld a,'_'
  841.     call nz,_putmap
  842.     call copy_screen
  843. get_hiscore:
  844.     call getkey
  845.     cp K_DEL
  846.     jr z,backspace
  847.     cp K_ENTER
  848.     jr z,name_done
  849.     cp K_SECOND
  850.     jr z,name_done
  851.     cp K_SIGN
  852.     jr nz,checkletter
  853.     ld a,' '
  854.     jr putletter
  855. checkletter:
  856.     ld hl,letters
  857.     ld bc,26
  858.     cpir                ;search for letter
  859.     jr nz,get_hiscore
  860.     ld a,'A'
  861.     add a,c
  862. putletter:
  863.     ld c,a
  864.     ld a,(_curCol)
  865.     cp 12            ;3 letters for initials
  866.     jr z,get_hiscore
  867.     pop hl
  868.     ld (hl),c
  869.     inc hl
  870.     ld a,c
  871.     call _putc
  872.     jr get_string
  873. backspace:
  874.     ld hl,_curCol
  875.     ld a,(hl)
  876.     cp 9
  877.     jr z,get_hiscore
  878.     ld a,' '
  879.     call _putmap
  880.     dec (hl)
  881.     pop hl
  882.     dec hl
  883.     jr get_string
  884. name_done:
  885.     pop hl
  886.     ld (hl),0                ;null terminator
  887. ;now we save it back to the level
  888.     ld hl,level_name
  889.     rst 20h
  890.     rst 10h
  891.     xor a
  892.     ld hl,4
  893.     add hl,de
  894.     adc a,b
  895.     ld b,6                ;6 bytes
  896.     ld de,new_highscore
  897.     call save_data
  898.     jp title_screen
  899.  
  900. ;************************************************exit
  901. exit:
  902.     ld hl,_asapvar
  903.     rst 20h                ;copy to OP1
  904.     rst 10h                ;_findsym
  905.     xor a
  906.     ld hl,data_start-_asm_exec_ram+4        ;offset
  907.     add hl,de                ;hl=pointer to data in original prog
  908.     adc a,b                ;in case we overlapped pages
  909.     ld de,data_start            ;copy from here
  910.     ld b,data_end-data_start
  911.     call save_data
  912.     im 1
  913.     ld a,$7c
  914.     out (0),a                ;restore video mem
  915.     ld hl,_contrast
  916.     ld a,(hl)
  917.     dec (hl)
  918.     ld a,(hl)
  919.     out (2),a
  920.     ld hl,$fbff-$f7ff
  921.     add hl,sp
  922.     ld sp,hl
  923.     ld hl,$f7ff
  924.     ld de,$fbff
  925.     ld bc,256
  926.     lddr
  927.     res 4,(iy+9)
  928.     jp _clrWindow
  929.  
  930. ;************************************************save data
  931. save_data:
  932.     ;ahl->dest
  933.     ;de->src
  934.     ;b=num bytes
  935.     push af
  936.     push hl
  937.     call _GETB_AHL
  938.     ld a,(de)
  939.     ld (hl),a
  940.     pop hl
  941.     pop af
  942.     call _INC_PTR_AHL
  943.     inc de
  944.     djnz save_data
  945.     ret
  946.  
  947. ;************************************************move ball
  948. draw_ball:
  949.     ld bc,(ball_y)
  950.     jp put_ball
  951.  
  952. anim_ball:
  953.     xor a
  954.     ld (collision),a        ;default is no change
  955.     ld a,(ball_y)
  956.     cp 1
  957.     jr z,bounce
  958.     cp 58
  959.     jr nz,no_bounce
  960. bounce:
  961.     ld a,(direction)
  962.     neg
  963.     ld (direction),a
  964. no_bounce:
  965.     call draw_ball        ;erase old ball
  966.     ld a,(direction)        ;get ball direction
  967.     add a,c            ;add to y-coordinate
  968.     ld (ball_y),a        ;update coordinate
  969.     call draw_ball        ;redraw ball at new coordinates
  970.     push bc
  971.     dec b            ;left side
  972.     call check_col
  973.     pop bc
  974.     inc b                ;right side
  975.     call check_col
  976.     ld a,(collision)
  977.     or a
  978.     ret z                ;no collision
  979.     ld a,(direction)
  980.     neg
  981.     ld (direction),a        ;new direction
  982.     ret
  983.  
  984. move_horiz:
  985.     xor a
  986.     ld (collision),a        ;no collision yet
  987.     ld bc,(ball_y)
  988.     ld a,b
  989.     ret
  990.  
  991. move_left:
  992.     ld a,(reverse_mode)
  993.     or a
  994.     jr nz,move_right_nocheck
  995. move_left_nocheck:
  996.     call move_horiz
  997.     dec a
  998.     cp 1
  999.     ret z
  1000.     ld b,a
  1001.     dec b            ;left side
  1002.     call check_col
  1003.     ret nz            ;a collision, so we don't move
  1004.     call draw_ball        ;erase old ball
  1005.     ld hl,ball_x
  1006.     dec (hl)
  1007.     jp draw_ball        ;draw new ball
  1008.  
  1009. move_right:
  1010.     ld a,(reverse_mode)
  1011.     or a
  1012.     jr nz,move_left_nocheck
  1013. move_right_nocheck:
  1014.     call move_horiz
  1015.     inc a
  1016.     cp 94
  1017.     ret z
  1018.     ld b,a
  1019.     inc b                ;right side
  1020.     call check_col
  1021.     ret nz            ;a collision, so we don't move
  1022.     call draw_ball        ;erase old ball
  1023.     ld hl,ball_x
  1024.     inc (hl)
  1025.     jp draw_ball        ;draw new ball
  1026.  
  1027. check_col:
  1028.     ;nz if collision
  1029.     push bc
  1030.     dec c            ;top
  1031.     call check_collision
  1032.     pop bc
  1033.     inc c                ;bottom row
  1034.     call check_collision
  1035.     ld a,(collision)
  1036.     or a
  1037.     ret
  1038.  
  1039. check_collision:
  1040.     ;checks collision at (b,c)
  1041.     ;clears brick if necessary
  1042.     ;activates collision if a collision
  1043.  
  1044.     call GetTile
  1045.     ret c                ;a clear tile
  1046.     ld (collision),a        ;collision (a greater than 0 anyway)
  1047.     ld a,(brick_mode)
  1048.     cp (hl)
  1049.     jr z,clear_tile        ;remove the tile if same mode
  1050.     ld a,(hl)
  1051.     sub 6
  1052.     ret c                ;a regular brick which we can't break
  1053.     jr nz,not_key
  1054.     inc a
  1055.     ld (hit_key),a        ;1=key active
  1056.     jr clear_tile            ;remove the key
  1057. not_key:
  1058.     dec a
  1059.     jr nz,not_lock
  1060.     ld a,(hit_key)
  1061.     or a
  1062.     ret z
  1063.     jr clear_tile            ;remove lock
  1064. not_lock:
  1065.     dec a
  1066.     jp z,lose_life        ;a killer brick
  1067.     dec a
  1068.     ret z                ;solid brick (never breaks)
  1069.     cp 4
  1070.     jr nz,not_reverse
  1071.     ld de,reverse_mode
  1072.     ld a,(de)
  1073.     xor 1                ;toggle reverse mode
  1074.     ld (de),a
  1075.     jr clear_tile
  1076. not_reverse:
  1077.     push af
  1078.     ld a,(brick_mode)
  1079.     cp 5
  1080.     jr nz,normal_brick
  1081.     pop af
  1082.     ret
  1083. normal_brick:
  1084.     call draw_brick_mode    ;remove old mode
  1085.     pop af
  1086.     inc a
  1087.     ld (brick_mode),a    ;new brick mode
  1088.     jp draw_brick_mode    ;draw new mode
  1089.  
  1090.  
  1091. clear_tile:
  1092.     ;erase tile pointed to by hl
  1093.     ld a,(hl)
  1094.     push af
  1095.     ld (hl),0
  1096.     ld de,current_level
  1097.     or a
  1098.     sbc hl,de
  1099.     ld a,8
  1100.     call _divHLbyA        ;separate x and y dimensions
  1101. ;l=y, a=x
  1102.     ld b,a
  1103.     ld h,6
  1104.     call MultHL
  1105.     ld c,l                ;y-coordinate
  1106.     ld l,b
  1107.     ld h,12
  1108.     call MultHL
  1109.     ld b,l                ;x-coordinate
  1110.     inc b
  1111.     inc b
  1112.     inc c
  1113.     inc c
  1114.     pop hl
  1115.     call put_brick        ;clear the tile from the screen
  1116.     jp draw_score        ;increment score and quit
  1117.  
  1118. ; bc = coords to get tile at (x, y)
  1119. ; returns: hl = pointer to map tile
  1120. ; tile = (((y-2) / 6) * 8) + ((x-2) / 12)
  1121. GetTile:
  1122.     ld h,0
  1123.     ld l,b
  1124.     ld a,12
  1125.     push bc
  1126.     call _divHLbyA
  1127.     pop bc
  1128.     ld b,l                ;store x value
  1129.     ld l,c
  1130.     ld a,6            ;divide by 6
  1131.     push bc
  1132.     call _divHLbyA
  1133.     pop bc
  1134.     ld a,l                ;a=y coordinate
  1135.     add a,a
  1136.     add a,a
  1137.     add a,a            ;y*8
  1138.     add a,b            ;add to x
  1139.     ld hl,current_level
  1140.     ld e,a
  1141.     ld d,0
  1142.     add hl,de            ;get offset of tile
  1143.     ld a,(hl)
  1144.     cp 1                ;c flag if solid
  1145.     ret
  1146.  
  1147. draw_brick_mode:
  1148.     ld bc,$6a36
  1149.     ld a,(brick_mode)
  1150.     ld h,a
  1151.     jp put_brick            ;draw the brick
  1152.  
  1153. ;************************************************check bricks
  1154. check_bricks:
  1155.     ld de,0                ;d=number of regular bricks, e=number of weird bricks
  1156.     ld hl,current_level
  1157.     ld b,80                ;size of level
  1158. bricks_loop:
  1159.     ld a,(hl)
  1160.     inc hl
  1161.     dec a
  1162.     cp 7
  1163.     jr nc,bricks_next_loop
  1164.     inc d
  1165.     cp 4                    ;check if it's an ending brick
  1166.     jr nz,bricks_next_loop    
  1167.     dec d
  1168.     inc e
  1169. bricks_next_loop:
  1170.     djnz bricks_loop
  1171.  
  1172.     ld a,d
  1173.     or e
  1174.     jr z,done_level
  1175.  
  1176.     ld a,d
  1177.     or a
  1178.     ret nz                ;still some regular bricks
  1179.  
  1180.     ld a,(brick_mode)
  1181.     cp 5
  1182.     ret z
  1183.  
  1184.     call draw_brick_mode
  1185.     ld a,5
  1186.     ld (brick_mode),a
  1187.     jp draw_brick_mode
  1188.  
  1189. done_level:
  1190.     ld a,(bonus)
  1191.     or a
  1192.     jr z,done_bonus
  1193.     ld b,5
  1194. countdown_delay:
  1195.     halt
  1196.     djnz countdown_delay
  1197.     call bonus_skip_delay    ;decrement bonus
  1198.     call draw_score            ;increment score
  1199.     call copy_screen
  1200.     jr done_level
  1201. done_bonus:
  1202.     ld hl,level_num
  1203.     ld a,(hl)
  1204.     ld b,a
  1205.     ld a,(num_levels)
  1206.     dec a
  1207.     cp b
  1208.     jp z,check_hiscore        ;played all levels
  1209.     inc (hl)
  1210.     jp start_level
  1211.  
  1212. ;************************************************delay
  1213. delay:
  1214.     ld a,(delay_amount)
  1215.     or a
  1216.     ret z
  1217. delay_loop:
  1218.     halt
  1219.     dec a
  1220.     jr nz,delay_loop
  1221.     ret
  1222.  
  1223. ;************************************************dead
  1224. lose_life:
  1225.     call draw_ball            ;erase ball
  1226.     call draw_lives            ;remove lives
  1227.     ld hl,lives
  1228.     dec (hl)
  1229.     jp z,check_hiscore        ;dead
  1230.     call draw_lives
  1231.     ld hl,(start_coords)
  1232.     ld (ball_y),hl
  1233.     ld a,1
  1234.     ld (direction),a
  1235.     call draw_ball
  1236.     call draw_brick_mode
  1237.     ld a,1
  1238.     ld (brick_mode),a
  1239.     call draw_brick_mode
  1240.     jp new_life
  1241.  
  1242. put_ball:                ;bc=coords
  1243.     ld ix,ball
  1244.     jr put_sprite
  1245.  
  1246. put_brick:                ;h=brick number, bc=coords
  1247.     ld l,24
  1248.     call MultHL
  1249.     ld ix,bricks            ;load the start of the sprites
  1250.     ex de,hl
  1251.     add ix,de            ;add together to get correct sprite
  1252.  
  1253. put_sprite:    
  1254. ;16x6 xor-ed grayscale putsprite
  1255. ;ix=sprite
  1256. ;b,c=(x,y)
  1257.     push bc
  1258.     ld h,$fc00/1024
  1259.     ld a,c
  1260.     add a,a
  1261.     add a,a
  1262.     ld l,a
  1263.     ld a,b
  1264.     rra
  1265.     add hl,hl
  1266.     rra
  1267.     add hl,hl
  1268.     rra
  1269.     or l
  1270.     ld l,a
  1271.     ld a,b
  1272.     and 7
  1273.     ld (bit_shift),a
  1274.     ld b,2
  1275. place_sprite:
  1276.     push bc
  1277.     ld b,6
  1278. draw_sprite:
  1279.     ld c,(ix)
  1280.     inc ix
  1281.     ld d,(ix)
  1282.     inc ix
  1283.     ld e,0
  1284.     ld a,0
  1285. bit_shift = $-1
  1286.     or a
  1287.     jr z,no_shift
  1288. shift_bytes:
  1289.     srl c
  1290.     rr d
  1291.     rr e
  1292.     dec a
  1293.     jr nz,shift_bytes
  1294. no_shift:
  1295.     ld a,c
  1296.     xor (hl)
  1297.     ld (hl),a
  1298.     inc hl
  1299.     ld a,d
  1300.     xor (hl)
  1301.     ld (hl),a
  1302.     inc hl
  1303.     ld a,e
  1304.     xor (hl)
  1305.     ld (hl),a
  1306.     ld de,14
  1307.     add hl,de
  1308.     djnz draw_sprite
  1309.     ld de,screen_light-screen_dark-96
  1310.     add hl,de
  1311.     pop bc
  1312.     djnz place_sprite
  1313.     pop bc
  1314.     ret
  1315.  
  1316. int_start:                        ;from bomber bloke
  1317.     exx
  1318.     ex af,af'
  1319.     in a,(3)
  1320.     bit 3,a
  1321.     jr z,no_down_left_bug
  1322.     and %11111110
  1323.     out (3),a
  1324. no_down_left_bug:
  1325.     bit 1,a
  1326.     jr z,no_swap
  1327.     ld hl,grayscale_counter
  1328.     inc (hl)
  1329.     ld a,(hl)
  1330.     cp 3
  1331.     ld a,(screen_dark/256)-$80
  1332.     jr c,set_video_port
  1333.     ld a,(screen_light/256)-$80
  1334.     ld (hl),0
  1335. set_video_port:
  1336.     out (0),a
  1337. no_swap:
  1338.     jp $3a
  1339. int_end:
  1340.  
  1341.  
  1342. ball:
  1343.  .db %01110000,0
  1344.  .db %10111000,0
  1345.  .db %11111000,0
  1346.  .db %11111000,0
  1347.  .db %01110000,0
  1348.  .db %00000000,0
  1349.  .db %01110000,0
  1350.  .db %11011000,0
  1351.  .db %10011000,0
  1352.  .db %11111000,0
  1353.  .db %01110000
  1354.  
  1355.  
  1356. bricks:     ;start of bricks
  1357. ;0
  1358.    
  1359.  .db %00000000, %00000000
  1360.  .db %00000000, %00000000
  1361.  .db %00000000, %00000000
  1362.  .db %00000000, %00000000
  1363.  .db %00000000, %00000000
  1364.  .db %00000000, %00000000
  1365.  .db %00000000, %00000000
  1366.  .db %00000000, %00000000
  1367.  .db %00000000, %00000000
  1368.  .db %00000000, %00000000
  1369.  .db %00000000, %00000000
  1370.  .db %00000000, %00000000
  1371.  
  1372. ;1
  1373.  
  1374.  .db %01111111, %11100000
  1375.  .db %10000000, %00010000
  1376.  .db %10000000, %00010000
  1377.  .db %10000000, %00010000
  1378.  .db %10000000, %00010000
  1379.  .db %01111111, %11100000
  1380.  .db %01111111, %11100000
  1381.  .db %11111111, %11110000
  1382.  .db %11111111, %11110000
  1383.  .db %11111111, %11110000
  1384.  .db %11111111, %11110000
  1385.  .db %01111111, %11100000
  1386.  
  1387. ;2
  1388.  
  1389.  .db %01111111, %11100000
  1390.  .db %10101010, %10110000
  1391.  .db %11010101, %01010000
  1392.  .db %10101010, %10110000
  1393.  .db %11010101, %01010000
  1394.  .db %01111111, %11100000
  1395.  .db %01111111, %11100000
  1396.  .db %10000000, %00010000
  1397.  .db %10000000, %00010000
  1398.  .db %11111111, %11110000
  1399.  .db %11111111, %11110000
  1400.  .db %01111111, %11100000
  1401.  
  1402. ;3
  1403.  
  1404.  .db %01111111, %11100000
  1405.  .db %10000000, %00010000
  1406.  .db %10111111, %11010000
  1407.  .db %10111111, %11010000
  1408.  .db %10000000, %00010000
  1409.  .db %01111111, %11100000
  1410.  .db %01111111, %11100000
  1411.  .db %11111111, %11110000
  1412.  .db %11100110, %01110000
  1413.  .db %11100110, %01110000
  1414.  .db %11111111, %11110000
  1415.  .db %01111111, %11100000
  1416.  
  1417. ;4
  1418.  
  1419.  .db %01111111, %11100000
  1420.  .db %10100100, %10010000
  1421.  .db %10010010, %01010000
  1422.  .db %11001001, %00110000
  1423.  .db %10100100, %10010000
  1424.  .db %01111111, %11100000
  1425.  .db %01111111, %11100000
  1426.  .db %11001001, %00110000
  1427.  .db %10100100, %10010000
  1428.  .db %10010010, %01010000
  1429.  .db %11001001, %00110000
  1430.  .db %01111111, %11100000
  1431.  
  1432. ;5
  1433.  
  1434.  .db %01111111, %11100000
  1435.  .db %11111111, %11110000
  1436.  .db %11100000, %01110000
  1437.  .db %11100000, %01110000
  1438.  .db %11111111, %11110000
  1439.  .db %01111111, %11100000
  1440.  .db %01111111, %11100000
  1441.  .db %11000000, %00110000
  1442.  .db %10000000, %00010000
  1443.  .db %10000000, %00010000
  1444.  .db %11000000, %00110000
  1445.  .db %01111111, %11100000
  1446.  
  1447. ;6
  1448.  
  1449.  .db %01111111, %11100000
  1450.  .db %11111110, %00110000
  1451.  .db %10000000, %10110000
  1452.  .db %11001110, %00110000
  1453.  .db %11111111, %11110000
  1454.  .db %01111111, %11100000
  1455.  .db %01111111, %11100000
  1456.  .db %11000001, %11110000
  1457.  .db %11111111, %01010000
  1458.  .db %10110001, %11010000
  1459.  .db %11000000, %00110000
  1460.  .db %01111111, %11100000
  1461.  
  1462. ;7
  1463.  
  1464.  .db %01111111, %11100000
  1465.  .db %11111001, %11110000
  1466.  .db %11110110, %11110000
  1467.  .db %11110000, %11110000
  1468.  .db %11110000, %11110000
  1469.  .db %01111111, %11100000
  1470.  .db %01111111, %11100000
  1471.  .db %11000110, %00110000
  1472.  .db %10001001, %00010000
  1473.  .db %10001111, %00010000
  1474.  .db %11001111, %00110000
  1475.  .db %01111111, %11100000
  1476.  
  1477. ;8
  1478.  
  1479.  .db %01111111, %11100000
  1480.  .db %11100111, %11110000
  1481.  .db %10000000, %00010000
  1482.  .db %10000000, %00010000
  1483.  .db %11100111, %11110000
  1484.  .db %01111111, %11100000
  1485.  .db %01111111, %11100000
  1486.  .db %11011000, %00110000
  1487.  .db %11111111, %11110000
  1488.  .db %11111111, %11110000
  1489.  .db %11011000, %00110000
  1490.  .db %01111111, %11100000
  1491.  
  1492. ;9
  1493.  
  1494.  .db %01111111, %11100000
  1495.  .db %11011110, %11110000
  1496.  .db %11111011, %11110000
  1497.  .db %11101111, %10110000
  1498.  .db %11111101, %11110000
  1499.  .db %01111111, %11100000
  1500.  .db %01111111, %11100000
  1501.  .db %11100001, %00110000
  1502.  .db %10000100, %00010000
  1503.  .db %10010000, %01010000
  1504.  .db %11000010, %00110000
  1505.  .db %01111111, %11100000
  1506.  
  1507. ;10
  1508.  
  1509.  .db %01111111, %11100000
  1510.  .db %10101011, %11110000
  1511.  .db %11010101, %11110000
  1512.  .db %10101011, %11110000
  1513.  .db %11010101, %11110000
  1514.  .db %01111111, %11100000
  1515.  .db %01111111, %11100000
  1516.  .db %10000001, %11110000
  1517.  .db %10000001, %11110000
  1518.  .db %11111111, %11110000
  1519.  .db %11111111, %11110000
  1520.  .db %01111111, %11100000
  1521.  
  1522. ;11
  1523.  
  1524.  .db %01111111, %11100000
  1525.  .db %10000001, %11110000
  1526.  .db %10111111, %11110000
  1527.  .db %10111111, %11110000
  1528.  .db %10000001, %11110000
  1529.  .db %01111111, %11100000
  1530.  .db %01111111, %11100000
  1531.  .db %11111111, %11110000
  1532.  .db %11100111, %11110000
  1533.  .db %11100111, %11110000
  1534.  .db %11111111, %11110000
  1535.  .db %01111111, %11100000
  1536.  
  1537. ;12
  1538.  
  1539.  .db %01111111, %11100000
  1540.  .db %10100101, %11110000
  1541.  .db %10010011, %11110000
  1542.  .db %11001001, %11110000
  1543.  .db %10100101, %11110000
  1544.  .db %01111111, %11100000
  1545.  .db %01111111, %11100000
  1546.  .db %11001001, %11110000
  1547.  .db %10100101, %11110000
  1548.  .db %10010011, %11110000
  1549.  .db %11001001, %11110000
  1550.  .db %01111111, %11100000
  1551.  
  1552. ;13
  1553.  
  1554.  .db %01111111, %11100000
  1555.  .db %11111111, %10110000
  1556.  .db %11011100, %00010000
  1557.  .db %10000011, %10110000
  1558.  .db %11011111, %11110000
  1559.  .db %01111111, %11100000
  1560.  .db %01111111, %11100000
  1561.  .db %11111111, %11110000
  1562.  .db %11111111, %11110000
  1563.  .db %11111111, %11110000
  1564.  .db %11111111, %11110000
  1565.  .db %01111111, %11100000
  1566.  
  1567.  
  1568.  
  1569. description:    .db "Diamonds 2.0 "
  1570. name:        .db "by Jonah Cohen",0
  1571. menu_txt:        .db 5
  1572.             .db $2c,$1a,"F1 - Start",0
  1573.             .db $2c,$22,30,31," Level:",0            ;30=up, 31=down
  1574.             .db $2c,$2a,"F2 - Speed:",0
  1575.             .db $2c,$32,"F3 -",0
  1576.             .db $2c,$3a,"High score:",0
  1577. error_txt:        .db $22,$25,"No levels detected",0
  1578. side_txt:        .db 3
  1579.             .db $67,$02,"Bonus",0
  1580.             .db $67,$10,"Level",0
  1581.             .db $67,$1e,"Score",0
  1582. high_score:    .db 2
  1583.             .db $1d,$0d,"You have a high score!",0
  1584.             .db $2b,$16,"Enter initials:",0
  1585.  
  1586. speed_table = $-1
  1587.     .db 34
  1588.     .db 40
  1589.     .db 50
  1590.     .db 66
  1591.     .db 90
  1592.  
  1593. row_table:
  1594.     .db $fc,$dc,$bc,$3c
  1595.  
  1596. letters:        ;used in string input
  1597.     .db $19,$21,$0a,$12,$1a,$22,$0b,$13,$1b,$23,$2b,$0c,$14
  1598.     .db $1c,$24,$2c,$0d,$15,$1d,$25,$2d,$0e,$16,$1e,$26,$2e
  1599.  
  1600.  
  1601. starting_name:
  1602.     .db $0c,1,0
  1603.  
  1604. data_start:
  1605.  
  1606. level_name:    .db $0c,7,"dlevels",0,0    ;store the current level name
  1607. speed:        .db 3                    ;1-5
  1608. resumed:        .db 0                    ;1=resumed
  1609. level_num:        .db 0                    ;which level we're on
  1610. score:        .db 0,0                ;player's score
  1611. ball_y:        .db 0                    ;y-coordinate
  1612. ball_x:        .db 0                    ;x-coordinate
  1613. bonus:        .db 0                    ;the bonus score
  1614. direction:        .db 0                    ;1=down, -1=up
  1615. reverse_mode:    .db 0                    ;1=reversed directions
  1616. brick_mode:    .db 0                    ;code of current brick type
  1617. lives:            .db 0                    ;number of balls left
  1618. hit_key:        .db 0                    ;whether they hit the key yet
  1619. start_coords:    .db 0,0                ;initial coordinates for level (2 bytes)
  1620. current_level:    .db 0,0,0,0,0,0,0,0        ;decompressed level
  1621.             .db 0,0,0,0,0,0,0,0
  1622.             .db 0,0,0,0,0,0,0,0
  1623.             .db 0,0,0,0,0,0,0,0
  1624.             .db 0,0,0,0,0,0,0,0
  1625.             .db 0,0,0,0,0,0,0,0
  1626.             .db 0,0,0,0,0,0,0,0
  1627.             .db 0,0,0,0,0,0,0,0
  1628.             .db 0,0,0,0,0,0,0,0
  1629.             .db 0,0,0,0,0,0,0,0
  1630.  
  1631. data_end:
  1632.  
  1633.  
  1634. titlepic:
  1635. #if 0
  1636.  .db $91,$00,$04,$f0,$c0,$91,$00,$05,$c0,$91,$00,$08
  1637.  .db $f8,$c0,$91,$00,$05,$c0,$91,$00,$08,$dc,$91,$00
  1638.  .db $06,$c0,$91,$00,$08,$ce,$c3,$de,$f0,$1e,$1e,$03
  1639.  .db $c3,$c0,$91,$00,$07,$c6,$c7,$df,$f8,$3f,$1f,$07
  1640.  .db $c7,$c0,$91,$00,$07,$c6,$ce,$db,$dc,$73,$9b,$8e
  1641.  .db $ce,$91,$00,$08,$c6,$dc,$d9,$ce,$e1,$d9,$dc,$dc
  1642.  .db $91,$00,$08,$c6,$d8,$d8,$c6,$c0,$91,$d8,$03,$91
  1643.  .db $00,$08,$c6,$d8,$d8,$c6,$c0,$d8,$d8,$df,$c0,$91
  1644.  .db $00,$07,$c6,$d8,$d8,$c6,$c0,$d8,$d8,$df,$c0,$91
  1645.  .db $00,$07,$c6,$d8,$d8,$c6,$c0,$d8,$d8,$c0,$c0,$91
  1646.  .db $00,$07,$ce,$dc,$d8,$c6,$e1,$d8,$dc,$c1,$c0,$91
  1647.  .db $00,$07,$dc,$ce,$d8,$c6,$73,$98,$ce,$c3,$80,$91
  1648.  .db $00,$07,$f8,$c7,$d8,$c6,$3f,$18,$c7,$df,$91,$00
  1649.  .db $08,$f0,$c3,$d8,$c6,$1e,$18,$c3,$de,$91,$00,$14
  1650.  
  1651.  .db $91,$00,$00
  1652. #endif
  1653.  
  1654.  
  1655. #if 1
  1656.  
  1657.  
  1658.  
  1659. Layer1:
  1660.  
  1661.  .db $91,$00,$12,$20,$91,$00,$1F,$90,$1F,$87,$C1,$C3,$9C,$78,$E7,$7E
  1662.  .db $1F,$00,$07,$91,$00,$05,$0F,$C3,$83,$E3,$FC,$FC,$E7,$3F,$3B,$80
  1663.  .db $0F,$80,$00,$00,$07,$20,$0E,$E3,$87,$73,$FD,$CE,$F7,$3B,$BB,$80
  1664.  .db $0F,$80,$00,$00,$0F,$80,$0E,$E3,$87,$73,$FD,$CE,$FF,$3B,$B8,$00
  1665.  .db $0F,$80,$00,$00,$0F,$80,$0E,$E3,$87,$73,$FD,$CE,$FF,$3B,$9E,$00
  1666.  .db $07,$91,$00,$03,$0F,$80,$0E,$E3,$87,$F3,$9D,$CE,$FF,$3B,$87,$00
  1667.  .db $20,$91,$00,$03,$07,$00,$0E,$E3,$87,$73,$9D,$CE,$EF,$3B,$BB,$80
  1668.  .db $04,$91,$00,$05,$0F,$C3,$87,$73,$9C,$FC,$E7,$3F,$3B,$80,$80,$91
  1669.  .db $00,$05,$1F,$87,$C7,$73,$9C,$78,$E7,$7E,$1F,$00,$10,$91,$00,$42
  1670.  
  1671. Layer2:
  1672.  
  1673.  .db $00,$3F,$91,$FF,$0C,$FC,$00,$00,$20,$20,$91,$00,$0B,$04,$00,$00
  1674.  .db $20,$91,$00,$0C,$04,$00,$00,$20,$90,$1F,$87,$C1,$C3,$9C,$78,$E7
  1675.  .db $7E,$1F,$00,$07,$04,$00,$00,$20,$00,$3F,$CF,$83,$E7,$FC,$FD,$EF
  1676.  .db $7F,$3B,$80,$0F,$84,$00,$00,$27,$20,$1E,$E7,$87,$77,$FD,$CF,$FF
  1677.  .db $7B,$FB,$80,$0F,$84,$00,$00,$2F,$80,$1E,$E7,$8F,$77,$FD,$DE,$FF
  1678.  .db $7B,$BA,$00,$0F,$84,$00,$00,$2F,$80,$1E,$E7,$8F,$77,$FD,$DE,$FF
  1679.  .db $7B,$BF,$80,$07,$04,$00,$00,$2F,$80,$1E,$E7,$8F,$F7,$9D,$DE,$FF
  1680.  .db $7B,$B7,$00,$20,$04,$00,$00,$27,$00,$1E,$E7,$8F,$77,$BD,$DE,$EF
  1681.  .db $7B,$BF,$80,$04,$04,$00,$00,$20,$00,$1F,$C7,$8F,$77,$BD,$FC,$EF
  1682.  .db $7F,$3B,$80,$80,$04,$00,$00,$20,$00,$1F,$87,$CF,$77,$BD,$F9,$EF
  1683.  .db $7E,$7F,$00,$10,$04,$00,$00,$20,$00,$30,$0C,$0C,$46,$30,$C1,$8C
  1684.  .db $40,$30,$00,$00,$04,$00,$00,$20,$00,$1F,$87,$C7,$73,$9C,$78,$E7
  1685.  .db $7E,$1F,$00,$00,$04,$00,$00,$20,$91,$00,$0C,$04,$00,$00,$3F,$91
  1686.  .db $FF,$0C,$FC,$00
  1687. #endif
  1688.  
  1689.  
  1690. #if 0
  1691. Layer1:
  1692.  
  1693.  .db $91,$00,$42,$01,$91,$FF,$09,$FC,$91,$00,$05,$03,$91,$FF,$09,$FE
  1694.  .db $91,$00,$05,$03,$91,$FF,$0A,$91,$00,$05,$07,$91,$FF,$0A,$91,$00
  1695.  .db $05,$07,$80,$91,$00,$08,$07,$80,$91,$00,$04,$0F,$91,$00,$09,$03
  1696.  .db $80,$91,$00,$04,$0F,$0C,$0F,$C0,$41,$8C,$1F,$18,$33,$00,$73,$C0
  1697.  .db $91,$00,$04,$1E,$0F,$0F,$C0,$C3,$9C,$7F,$98,$33,$C1,$F9,$C0,$91
  1698.  .db $00,$04,$1E,$1B,$86,$01,$C3,$9C,$E1,$B8,$66,$E1,$81,$E0,$91,$00
  1699.  .db $04,$1C,$19,$86,$03,$C7,$B9,$C1,$BC,$66,$63,$01,$E0,$91,$00,$04
  1700.  .db $1C,$19,$86,$06,$87,$39,$81,$B4,$66,$63,$F0,$E0,$91,$00,$04,$1E
  1701.  .db $31,$8C,$0F,$8D,$7B,$03,$66,$CC,$63,$F0,$E0,$91,$00,$04,$1E,$31
  1702.  .db $8C,$1F,$8F,$DB,$07,$66,$CC,$60,$31,$E0,$91,$00,$04,$0E,$33,$0C
  1703.  .db $31,$9B,$DB,$8E,$63,$CC,$CC,$71,$E0,$91,$00,$04,$0F,$7F,$3E,$31
  1704.  .db $9B,$9B,$FC,$C1,$9F,$CF,$E1,$E0,$91,$00,$04,$07,$3C,$7E,$60,$B3
  1705.  .db $10,$F0,$C1,$8F,$0F,$83,$C0,$91,$00,$04,$07,$80,$91,$00,$08,$03
  1706.  .db $C0,$91,$00,$04,$03,$91,$FF,$0A,$80,$91,$00,$04,$03,$91,$FF,$0A
  1707.  .db $80,$91,$00,$04,$01,$91,$FF,$0A,$91,$00,$06,$91,$FF,$09,$FE,$91
  1708.  .db $00,$73
  1709.  
  1710. Layer2:
  1711.  
  1712.  .db $91,$00,$42,$01,$91,$FF,$09,$FC,$91,$00,$05,$03,$91,$FF,$09,$FE
  1713.  .db $91,$00,$05,$03,$91,$00,$09,$03,$91,$00,$05,$06,$91,$00,$09,$03
  1714.  .db $91,$00,$05,$06,$91,$00,$09,$01,$80,$91,$00,$04,$0C,$91,$00,$09
  1715.  .db $01,$80,$91,$00,$04,$08,$0C,$0F,$C0,$41,$8C,$1F,$18,$33,$00,$70
  1716.  .db $C0,$91,$00,$04,$18,$0F,$0F,$C0,$C3,$9C,$7F,$98,$33,$C1,$F8,$C0
  1717.  .db $91,$00,$04,$10,$1B,$86,$01,$C3,$9C,$E1,$B8,$66,$E1,$80,$60,$91
  1718.  .db $00,$04,$10,$19,$86,$03,$C7,$B9,$C1,$BC,$66,$63,$00,$20,$91,$00
  1719.  .db $04,$10,$19,$86,$06,$87,$39,$81,$B4,$66,$63,$F0,$20,$91,$00,$04
  1720.  .db $10,$31,$8C,$0F,$8D,$7B,$03,$66,$CC,$63,$F0,$20,$91,$00,$04,$18
  1721.  .db $31,$8C,$1F,$8F,$DB,$07,$66,$CC,$60,$30,$20,$91,$00,$04,$08,$33
  1722.  .db $0C,$31,$9B,$DB,$8E,$63,$CC,$CC,$70,$60,$91,$00,$04,$0C,$7F,$3E
  1723.  .db $31,$9B,$9B,$FC,$C1,$9F,$CF,$E0,$60,$91,$00,$04,$04,$3C,$7E,$60
  1724.  .db $B3,$10,$F0,$C1,$8F,$0F,$80,$C0,$91,$00,$04,$06,$91,$00,$0A,$C0
  1725.  .db $91,$00,$04,$03,$91,$00,$09,$01,$80,$91,$00,$04,$03,$91,$00,$09
  1726.  .db $01,$80,$91,$00,$04,$01,$91,$FF,$0A,$91,$00,$06,$91,$FF,$09,$FE
  1727.  .db $91,$00,$73
  1728.  
  1729. #endif
  1730.  
  1731. #if 0
  1732.  
  1733. Layer1:
  1734.  
  1735.  .db $91,$00,$42,$01,$91,$FF,$09,$FC,$91,$00,$05,$03,$91,$FF,$09,$FE
  1736.  .db $91,$00,$05,$03,$91,$00,$09,$03,$91,$00,$05,$06,$91,$00,$09,$03
  1737.  .db $91,$00,$05,$06,$7F,$91,$FF,$08,$F9,$80,$91,$00,$04,$0C,$91,$FF
  1738.  .db $09,$FD,$80,$91,$00,$04,$08,$91,$FF,$09,$FC,$C0,$91,$00,$04,$19
  1739.  .db $91,$FF,$09,$FE,$C0,$91,$00,$04,$11,$91,$FF,$09,$FE,$60,$91,$00
  1740.  .db $04,$13,$91,$FF,$09,$FE,$20,$91,$00,$04,$13,$91,$FF,$0A,$20,$91
  1741.  .db $00,$04,$11,$91,$FF,$0A,$20,$91,$00,$04,$19,$91,$FF,$09,$FE,$20
  1742.  .db $91,$00,$04,$09,$91,$FF,$09,$FE,$60,$91,$00,$04,$0C,$91,$FF,$09
  1743.  .db $FE,$60,$91,$00,$04,$04,$91,$FF,$09,$FC,$C0,$91,$00,$04,$06,$7F
  1744.  .db $91,$FF,$08,$FC,$C0,$91,$00,$04,$03,$91,$00,$09,$01,$80,$91,$00
  1745.  .db $04,$03,$91,$00,$09,$01,$80,$91,$00,$04,$01,$91,$FF,$0A,$91,$00
  1746.  .db $06,$91,$FF,$09,$FE,$91,$00,$73
  1747.  
  1748. Layer2:
  1749.  
  1750.  .db $91,$00,$42,$01,$91,$FF,$09,$FC,$91,$00,$05,$03,$91,$FF,$09,$FE
  1751.  .db $91,$00,$05,$03,$91,$FF,$0A,$91,$00,$05,$07,$91,$FF,$0A,$91,$00
  1752.  .db $05,$07,$80,$91,$00,$08,$07,$80,$91,$00,$04,$0F,$91,$00,$09,$03
  1753.  .db $80,$91,$00,$04,$0F,$0C,$0F,$C0,$41,$8C,$1F,$18,$33,$00,$73,$C0
  1754.  .db $91,$00,$04,$1E,$0F,$0F,$C0,$C3,$9C,$7F,$98,$33,$C1,$F9,$C0,$91
  1755.  .db $00,$04,$1E,$1B,$86,$01,$C3,$9C,$E1,$B8,$66,$E1,$81,$E0,$91,$00
  1756.  .db $04,$1C,$19,$86,$03,$C7,$B9,$C1,$BC,$66,$63,$01,$E0,$91,$00,$04
  1757.  .db $1C,$19,$86,$06,$87,$39,$81,$B4,$66,$63,$F0,$E0,$91,$00,$04,$1E
  1758.  .db $31,$8C,$0F,$8D,$7B,$03,$66,$CC,$63,$F0,$E0,$91,$00,$04,$1E,$31
  1759.  .db $8C,$1F,$8F,$DB,$07,$66,$CC,$60,$31,$E0,$91,$00,$04,$0E,$33,$0C
  1760.  .db $31,$9B,$DB,$8E,$63,$CC,$CC,$71,$E0,$91,$00,$04,$0F,$7F,$3E,$31
  1761.  .db $9B,$9B,$FC,$C1,$9F,$CF,$E1,$E0,$91,$00,$04,$07,$3C,$7E,$60,$B3
  1762.  .db $10,$F0,$C1,$8F,$0F,$83,$C0,$91,$00,$04,$07,$80,$91,$00,$08,$03
  1763.  .db $C0,$91,$00,$04,$03,$91,$FF,$0A,$80,$91,$00,$04,$03,$91,$FF,$0A
  1764.  .db $80,$91,$00,$04,$01,$91,$FF,$0A,$91,$00,$06,$91,$FF,$09,$FE,$91
  1765.  .db $00,$73
  1766.  
  1767. #endif
  1768.  
  1769. icon:
  1770.  .db 15,2
  1771.  .db $0F
  1772.  .db $F8,$0C
  1773.  .db $18,$0F
  1774.  .db $F8,$07
  1775.  .db $F0,$00
  1776.  .db $00,$00
  1777.  .db $00,$00
  1778.  .db $70,$00
  1779.  .db $F8,$00
  1780.  .db $F8,$00
  1781.  .db $F8,$04
  1782.  .db $70,$00
  1783.  .db $00,$10
  1784.  .db $80,$02
  1785.  .db $00,$FF
  1786.  .db $F8
  1787.  
  1788.  
  1789.  
  1790. shift_left            equ        $
  1791. shift_right            equ        shift_left+48
  1792. temp_search_name    equ        shift_right+48            ;name of var in search (11 bytes)
  1793. new_highscore        equ        temp_search_name+11    ;new high score (2 bytes)
  1794. new_initials        equ        new_highscore+2        ;initials (4 bytes)
  1795.  
  1796. screen_light        equ        ((new_initials+3) | $ff)+1    ;next aligned address
  1797. screen_dark        equ        screen_light+1024
  1798. int_table            equ        screen_dark+1024        ;table for im 2 interrupt
  1799.  
  1800. buffer_light            equ        $f800
  1801. buffer_dark            equ        buffer_light+1024
  1802.  
  1803. delay_amount        equ        $8100                ;regular delay speed
  1804. bonus_delay_amount    equ        delay_amount+1        ;bonus delay speed
  1805. bonus_delay        equ        bonus_delay_amount+1    ;countdown for bonus
  1806. collision            equ        bonus_delay+1            ;1=collision
  1807. highscore            equ        collision+1                ;the high score (2 bytes)
  1808. initials            equ        highscore+2            ;initials for high score (4 bytes)
  1809. num_levels        equ        initials+4                ;number of levels
  1810. levels            equ        num_levels+1            ;the entire level string (unlimited size)
  1811.  
  1812. .end
  1813.