Advertisement
slydogstudios

My First Ever 6502 Project... AWFUL CODE haha

Sep 10th, 2017
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; NO ONE EVER USE THIS, IT IS HORRIBLE. I am just
  2. ; saving it here so I can look back at it and laugh : )
  3.  
  4. a_punch         =   $01
  5. b_punch         =   $02
  6. select_punch    =   $04
  7. start_punch     =   $08
  8. up_punch        =   $10
  9. down_punch      =   $20
  10. left_punch      =   $40
  11. right_punch     =   $80
  12. sprite          =   $200
  13. sprite2         =   $204
  14. sprite3         =   $208
  15. sprite4         =   $20c
  16. sprite5         =   $210
  17. sprite6         =   $214
  18. sprite7         =   $218
  19. sprite8         =   $21c
  20. sprite9         =   $220
  21. sprite10        =   $224
  22. sprite11        =   $228
  23. init            =   $898a
  24. play            =   $8977
  25.  
  26. .segment "ZEROPAGE"
  27.  
  28. control_pad: .res 1
  29. control_old: .res 1
  30. nmi_num:     .res 1
  31. on_title:    .res 1
  32. on_instr:    .res 1
  33. on_game:     .res 1
  34.  
  35. .segment "CODE"
  36.  
  37. .incbin "music\ncat.nsf"
  38.  
  39. reset:
  40.     sei
  41.     cld
  42.     ldx #$00
  43.     stx $4015
  44.     ldx #$40
  45.     stx $4017
  46.     ldx #$ff
  47.     txs
  48.     inx
  49.     stx $2000
  50.     stx $2001
  51.  
  52. :   bit $2002
  53.     bpl :-
  54. :   bit $2002
  55.     bpl :-
  56.  
  57.     txa
  58. clrmem:
  59.     sta $000,x
  60.     sta $100,x
  61.     sta $200,x
  62.     sta $300,x
  63.     sta $400,x
  64.     sta $500,x
  65.     sta $600,x
  66.     sta $700,x
  67.     inx
  68.     bne clrmem
  69.  
  70. :   bit $2002
  71.     bpl :-
  72.  
  73.     ldx #$ff
  74.     txs
  75.  
  76.     jsr PPU_off
  77.     jsr graphics
  78.     jsr init
  79.     jsr song1
  80.     jsr PPU_with_sprites
  81.  
  82. loop:
  83.     jsr wait_for_nmi
  84.     jmp loop
  85.  
  86. graphics:
  87.  
  88.     ldx #$0                     ; Pull in bytes for sprites and their
  89. :   lda orig_sprite_data,x      ; attributes which are stored in
  90.     sta sprite,x                ; the_sprites. Use X as an index
  91.     inx                         ; to load and store each byte, which
  92.     cpx #$04                    ; get stored starting in $200, where
  93.     bne :-                      ; 'sprite' is located at.
  94.  
  95.     lda #$3F
  96.     ldx #$00
  97.     sta $2006
  98.     stx $2006
  99. :   lda palette,x
  100.     sta $2007
  101.     inx
  102.     cpx #$20
  103.     bne :-
  104.  
  105.     jsr title_screen
  106.     rts
  107.  
  108. song1:
  109.     lda #$0
  110.     ldx #$00
  111.     jsr init
  112.     lda #%10000000
  113.     sta $2000
  114.     rts
  115.  
  116. song2:
  117.     lda #$1
  118.     ldx #$00
  119.     jsr init
  120.     lda #%10000000
  121.     sta $2000
  122.     rts
  123.  
  124. shift_sprite_down:
  125.     lda #$85
  126.     sta sprite
  127.     rts
  128. shift_sprite_up:
  129.     lda #$75
  130.     sta sprite
  131.     rts
  132.  
  133. title_screen:
  134.     lda #$01
  135.     sta on_title
  136.     jsr PPU_off
  137.     ldy #$00
  138.     sty on_game
  139.     sty on_instr
  140.     ldx #$04
  141.     lda #<title
  142.     sta $10
  143.     lda #>title
  144.     sta $11
  145.     lda #$20
  146.     sta $2006
  147.     lda #$00
  148.     sta $2006
  149. :   lda ($10),y
  150.     sta $2007
  151.     iny
  152.     bne :-
  153.     inc $11
  154.     dex
  155.     bne :-
  156.     jsr PPU_no_sprites
  157.     jsr PPU_with_sprites
  158.     lda #$00
  159.     sta $2006
  160.     sta $2006
  161.     sta $2005
  162.     sta $2005
  163.     rts
  164.  
  165. game_area:
  166.     lda #$01
  167.     sta on_game
  168.     jsr PPU_off
  169.     ldy #$00
  170.     sty on_title
  171.     sty on_instr
  172.     ldx #$04
  173.     lda #<room
  174.     sta $10
  175.     lda #>room
  176.     sta $11
  177.     lda #$20
  178.     sta $2006
  179.     lda #$00
  180.     sta $2006
  181. :   lda ($10),y
  182.     sta $2007
  183.     iny
  184.     bne :-
  185.     inc $11
  186.     dex
  187.     bne :-
  188.     jsr song2
  189.     jsr PPU_no_sprites
  190.     ldx #$00                    ; Pull in bytes for sprites and their
  191. :   lda orig_sprite_data+4,x        ; attributes which are stored in
  192.     sta sprite,x                ; the_sprites. Use X as an index
  193.     inx                         ; to load and store each byte, which
  194.     cpx #$2c                    ; get stored starting in $200, where
  195.     bne :-                      ; 'sprite' is located at.
  196.     jsr PPU_with_sprites
  197.     lda #$00
  198.     sta $2006
  199.     sta $2006
  200.     sta $2005
  201.     sta $2005
  202.     rts
  203.  
  204. instructions:
  205.     lda #$01
  206.     sta on_instr
  207.     jsr PPU_off
  208.     ldy #$00
  209.     sty on_game
  210.     sty on_title
  211.     ldx #$04
  212.     lda #<instr
  213.     sta $10
  214.     lda #>instr
  215.     sta $11
  216.     lda #$20
  217.     sta $2006
  218.     lda #$00
  219.     sta $2006
  220. :   lda ($10),y
  221.     sta $2007
  222.     iny
  223.     bne :-
  224.     inc $11
  225.     dex
  226.     bne :-
  227.     jsr PPU_no_sprites
  228.     lda #$00
  229.     sta $2006
  230.     sta $2006
  231.     sta $2005
  232.     sta $2005
  233.     rts
  234.  
  235. title_control:                  ; Control routine for the title screen
  236.     jsr control_update
  237.                                 ; Start button
  238.     lda control_pad
  239.     eor control_old
  240.     and control_pad
  241.     and #start_punch
  242.     beq no_start_punch
  243.     lda sprite
  244.     cmp #$77
  245.     bne load_instr
  246.     jsr game_area
  247.     jmp no_start_punch
  248. load_instr:
  249.     jsr instructions
  250.      
  251.  
  252. no_start_punch:                 ; Select button
  253.     lda control_pad
  254.     eor control_old
  255.     and control_pad
  256.     and #select_punch
  257.     beq no_select_punch
  258.     lda sprite
  259.     cmp #$77
  260.     beq move_up
  261.     sec
  262.     lda sprite
  263.     sbc #$10
  264.     sta sprite
  265.     jmp no_select_punch
  266. move_up:
  267.     clc
  268.     lda sprite
  269.     adc #$10
  270.     sta sprite 
  271. no_select_punch:
  272.     rts
  273.  
  274. instr_control:
  275.     jsr control_update
  276.  
  277.     lda control_pad
  278.     eor control_old
  279.     and control_pad
  280.     and #b_punch
  281.     beq no_b_punch
  282.     jsr title_screen
  283.  
  284. no_b_punch:
  285.     rts
  286.  
  287. game_control:
  288.     jsr control_update
  289.  
  290.     lda control_pad             ; Down button
  291.     eor control_old
  292.     and control_pad
  293.     and #down_punch
  294.     beq no_down_punch
  295.     lda sprite
  296.     cmp #$d7
  297.     beq at_bottom
  298.     clc
  299.     lda sprite
  300.     adc #$0a
  301.     sta sprite
  302. ;   jmp no_down_punch
  303. at_bottom:
  304.     jmp no_down_punch
  305. ;   lda control_pad             ; Down button
  306. ;   eor control_old
  307. ;   and control_pad
  308. ;   and #$06
  309. ;   jmp no_down_punch
  310.  
  311. no_down_punch:                  ; Up button
  312.     lda control_pad
  313.     eor control_old
  314.     and control_pad
  315.     and #up_punch
  316.     beq no_up_punch
  317.     lda sprite
  318.     cmp #$af
  319.     beq at_top
  320.     sec
  321.     lda sprite
  322.     sbc #$0a
  323.     sta sprite
  324. ;   jmp no_up_punch
  325. at_top:
  326.     jmp no_up_punch
  327.  
  328. no_up_punch:                    ; A button
  329.     lda control_pad
  330.     eor control_old
  331.     and control_pad
  332.     and #a_punch
  333.  
  334.     rts
  335.  
  336. control_update:
  337.     lda #$01
  338.     sta $4016
  339.     lda #$00
  340.     sta $4016
  341.     lda control_pad
  342.     sta control_old
  343.     ldx #$08
  344. :
  345.     lda $4016
  346.     lsr A
  347.     ror control_pad
  348.     dex
  349.     bne :-
  350.     rts
  351.  
  352. sprite_cram:
  353.     lda #>sprite
  354.     sta $4014
  355.     rts
  356.  
  357. PPU_off:
  358.     lda #$00
  359.     sta $2000
  360.     sta $2001
  361.     rts
  362.  
  363. PPU_with_sprites:
  364.     lda #%10010000
  365.     sta $2000
  366.     lda #%00011110
  367.     sta $2001
  368.     rts
  369.  
  370. PPU_no_sprites:
  371.     lda #%10010000
  372.     sta $2000
  373.     lda #%00001110
  374.     sta $2001
  375.     rts
  376.  
  377. wait_for_nmi:
  378.     lda nmi_num
  379. @check:
  380.     cmp nmi_num
  381.     beq @check
  382.     rts
  383.  
  384. nmi:
  385.     pha
  386.     txa
  387.     pha
  388.     tya
  389.     pha
  390.     inc nmi_num
  391.     lda on_title
  392.     beq try_instr
  393.     jsr title_control
  394.     jmp continue_nmi
  395. try_instr:
  396.     lda on_instr
  397.     beq try_game
  398.     jsr instr_control
  399.     jmp continue_nmi
  400. try_game:
  401.     lda on_game
  402.     beq continue_nmi
  403.     jsr game_control
  404.     jmp continue_nmi
  405. continue_nmi:
  406.     jsr sprite_cram
  407.     jsr play
  408.     lda #$00
  409.     sta $2005
  410.     sta $2005
  411. end_nmi:   
  412.     pla
  413.     tay
  414.     pla
  415.     tax
  416.     pla
  417.     rti
  418.  
  419. irq:
  420.     rti
  421.  
  422. palette:
  423. .incbin "palettes\ncat.pal"
  424.  
  425. ; *********************************************************
  426. ; The .bytes below are setup for the sprites to be used   *
  427. ; .byte (Y-Pos),(Tile Number),(Attributes),(X-Pos)        *
  428. ; *********************************************************
  429. orig_sprite_data:
  430.     .byte $77,$01,$01,$4d           ; title sprite
  431.     .byte $af,$02,$02,$09           ; menu sprite
  432.     .byte $90,$03,$01,$80
  433.     .byte $90,$04,$01,$88
  434.     .byte $90,$05,$01,$90
  435.     .byte $90,$06,$01,$98
  436.     .byte $98,$13,$01,$80
  437.     .byte $98,$14,$01,$88
  438.     .byte $98,$15,$01,$90
  439.     .byte $98,$16,$01,$98
  440.     .byte $98,$17,$01,$a0
  441.  
  442. ; *********************************************************
  443. ; Include all of the nametables for the game below        *
  444. ; *********************************************************
  445. title:
  446. .incbin "nametables\ncat_title.nam"
  447. instr:
  448. .incbin "nametables\ncat_instr.nam"
  449. room:
  450. .incbin "nametables\ncat_room.nam"
  451.  
  452. .segment "VECTORS"
  453.     .addr nmi
  454.     .addr reset
  455.     .addr irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement