Advertisement
Redxone

[CC-6502] Lemu Basic Game

Apr 9th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .begin $0A00
  2. ; Simple ASM game by Lewisk3
  3. ; Define key input controls
  4. define key $FF
  5. define rng $FE
  6. define up $11
  7. define down $1F
  8. define left $1E
  9. define right $20
  10. define button_a $1C
  11. define button_b $28
  12. define button_start $2B
  13. define button_select $1B
  14. define ppos_msb $03
  15. define ppos_lsb $62
  16. define last_block $18
  17.  
  18. jmp init
  19. ; Define player graphic, and block graphic
  20. graphics:
  21.     dcb $BF, $'@', $78, $'H'
  22.  
  23. init:
  24.     lda #ppos_lsb           ; Load player locations into memory
  25.     sta $15
  26.     lda #ppos_msb
  27.     sta $16
  28.     jsr drawplayer
  29.     jmp loop
  30.  
  31. undrawplayer:
  32.     ldx #$00
  33.     lda #$FF                    ; Load empty graphic
  34.     sta ($15, x)            ; Store colors on screen
  35.     inx                     ; Increment graphic location
  36.     lda #$00                ; Load empty graphic into A
  37.     ldy #$01                ; Setup to write to next position on screen
  38.     sta ($15), y            ; Write graphic.
  39. rts
  40.  
  41. absadd:                     ; Takes X and Y, overwrites whit result
  42.     pha
  43.     txa
  44.     clc
  45.     adc #$66
  46.     tax
  47.     pla
  48.     bcs absaddmore
  49. rts
  50. absaddmore:
  51.     pha
  52.     tya
  53.     clc
  54.     adc #$01
  55.     tay
  56.     pla
  57. rts
  58.  
  59. abssub:                     ; Takes X and Y, overwrites whit result
  60.     pha
  61.     txa
  62.     sec
  63.     sbc #$66
  64.     tax
  65.     pla
  66.     bcc abssubmore
  67. rts
  68. abssubmore:
  69.     pha
  70.     clc
  71.     tya
  72.     sbc #$01
  73.     tay
  74.     pla
  75. rts
  76.  
  77. placeblock:
  78.     ldx $15         ; Get Player position
  79.     ldy $16    
  80.     jsr abssub      ; Move 1 up
  81.     stx $18         ; Store block coords
  82.     sty $19
  83.     ldx #$02        ; Get block colors
  84.     lda graphics, x ; Load block colors
  85.     ldy #$00        ; Move 0 into X
  86.     sta ($18), y    ; Put block colors on screen
  87.     ldx #$03        ; Get Block char
  88.     lda graphics, x ; Load block char
  89.     ldy #$01
  90.     sta ($18), y    ; Put block on screen
  91.     lda #$00
  92.     sta key
  93. rts
  94.  
  95. breakblock:
  96.     ldx $15         ; Get Player position
  97.     ldy $16    
  98.     jsr abssub      ; Move 1 up
  99.     stx $18         ; Store block coords
  100.     sty $19
  101.     ldx #$02        ; Get block colors
  102.     lda #$FF        ; Load block colors
  103.     ldy #$00        ; Move 0 into X
  104.     sta ($18), y    ; Put block colors on screen
  105.     ldx #$03        ; Get Block char
  106.     lda #$00        ; Load block char
  107.     ldy #$01
  108.     sta ($18), y    ; Put block on screen
  109.     lda #$00
  110.     sta key
  111. rts
  112.  
  113. drawplayer:
  114.     ldy #$00
  115.     ldx #$00
  116.     lda graphics, x         ; Load player graphic
  117.     sta ($15, x)            ; Store player colors on screen
  118.     inx                     ; Increment to player graphic
  119.     lda graphics, x         ; Load player graphic into A
  120.     ldy #$01                ; Setup to write to next position on screen
  121.     sta ($15), y            ; Write player.
  122.     lda #$00
  123.     sta key
  124. rts
  125.  
  126. p_a:
  127.     jsr placeblock
  128. jmp getinput
  129. p_b:
  130.     jsr breakblock
  131. jmp getinput
  132.  
  133. coly:
  134.     ldy #$FF
  135.     rts
  136.  
  137. collide:
  138.     ldy #$00
  139.     ldx #$00
  140.     lda ($15), y
  141.     cmp #$FF
  142.     beq colret
  143.     cmp #$00
  144.     bne coly
  145.  colret:
  146.     rts
  147.  
  148. movedown:
  149.     jsr undrawplayer
  150. movedown_r:
  151.     lda $15
  152.     clc
  153.     adc #$66
  154.     sta $15
  155.     bcs downmore
  156.     jsr collide
  157.     cpy #$FF
  158.     beq moveup_r
  159.     jsr drawplayer
  160.     jmp getinput   
  161. downmore:
  162.     lda $16
  163.     adc #$01
  164.     sta $16
  165.     jsr collide
  166.     cpy #$FF
  167.     beq moveup_r
  168.     jsr drawplayer
  169.     jmp getinput
  170.  
  171. getinput:
  172.     lda key                     ; Load key input
  173.     cmp #up
  174.     beq moveup
  175.     cmp #down
  176.     beq movedown
  177.     cmp #left
  178.     beq moveleft
  179.     cmp #right
  180.     beq moveright
  181.     cmp #button_a
  182.     beq p_a
  183.     cmp #button_b
  184.     beq p_b
  185. ;   cmp #button_start
  186. ;   beq p_start
  187. ;   cmp #button_select
  188. ;   beq p_select
  189.     rts
  190.  
  191.     moveup:
  192.         jsr undrawplayer
  193.      moveup_r:
  194.         lda $15
  195.         sec
  196.         sbc #$66
  197.         sta $15
  198.         bcc upmore
  199.         jsr collide
  200.         cpy #$FF
  201.         beq movedownbranch
  202.         jsr drawplayer
  203.         rts
  204.     upmore:
  205.         lda $16
  206.         clc
  207.         sbc #$01
  208.         sta $16
  209.         jsr collide
  210.         cpy #$FF
  211.         beq movedownbranch
  212.         jsr drawplayer
  213.         rts
  214.     moveright:
  215.         jsr undrawplayer
  216.     moveright_r:
  217.         lda $15
  218.         clc
  219.         adc #$02
  220.         sta $15
  221.         bcs rightmore
  222.         jsr collide
  223.         cpy #$FF
  224.         beq moveleft_r
  225.         jsr drawplayer
  226.         rts
  227.     rightmore:
  228.         lda $16
  229.         clc
  230.         adc #$01
  231.         sta $16
  232.         jsr collide
  233.         cpy #$FF
  234.         beq moveleft_r
  235.         jsr drawplayer
  236.         rts
  237.     moveleft:
  238.         jsr undrawplayer
  239.     moveleft_r:
  240.         lda $15
  241.         sec
  242.         sbc #$02
  243.         sta $15
  244.         bcc leftmore
  245.         jsr collide
  246.         cpy #$FF
  247.         beq moveright_r
  248.         jsr drawplayer
  249.         rts
  250.     leftmore:
  251.         lda $16
  252.         sbc #$01
  253.         sta $16
  254.         jsr collide
  255.         cpy #$FF
  256.         beq moveright_r
  257.         jsr drawplayer
  258.         rts
  259.     movedownbranch:
  260.         jmp movedown_r
  261.    
  262.  
  263. loop:
  264.     jsr getinput
  265. jmp loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement