Advertisement
Guest User

Ugloo

a guest
Feb 23rd, 2012
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vars.asm
  2.  
  3. UGLOO_RAM = $0200
  4.  
  5. FRAME1 = $0C
  6. FRAME2 = $18
  7. FRAME3 = $24
  8. FRAME4 = $30
  9.  
  10.     .rsset $0000
  11. sleeping .rs 1
  12.  
  13. controller .rs 3
  14.  
  15. chrPointer .rs 2
  16.  
  17. frame .rs 1
  18. animation .rs 1
  19. direction .rs 1
  20.  
  21. spritePointer .rs 2 ; 2 bytes for every 4x4 meta sprite
  22. gfxPointer .rs 2
  23. spritePointerIndex .rs 1
  24.  
  25.  
  26.  
  27.  
  28. sprites.asm
  29.  
  30. UglooSprite:
  31.     .db $01, $01, $02, $02, %00000000, %01000000, %00000000, %01000000
  32.     .db $01, $01, $03, $04, %00000000, %01000000, %00000000, %00000000
  33.     .db $01, $01, $04, $03, %00000000, %01000000, %01000000, %01000000
  34.    
  35.  
  36.  
  37.  
  38.  
  39.  
  40. main.asm
  41.  
  42.     .inesprg 2
  43.     .ineschr 0
  44.     .inesmap 0
  45.     .inesmir 1
  46.    
  47.     .include "inc/vars.asm"
  48.     .bank 0
  49.     .org $8000
  50.    
  51. ; VBlank
  52. VBlankWait:
  53.     BIT $2002
  54.     BPL VBlankWait
  55.    
  56.     RTS
  57.  
  58. ; WaitFrame
  59. WaitFrame:
  60.     INC sleeping
  61. .loop:
  62.     LDA sleeping
  63.     BNE .loop
  64.    
  65.     RTS
  66. ; ----------------------------------------
  67.  
  68.  
  69. ; Controller
  70. ReadController:
  71.     LDA controller
  72.     STA controller+1
  73.    
  74.     LDA #$01
  75.     STA $4016
  76.     LDA #$00
  77.     STA $4016
  78.    
  79.     LDX #$08
  80. .loop:
  81.     LDA $4016
  82.     LSR A
  83.     ROL controller
  84.     DEX
  85.     BNE .loop
  86.    
  87.     LDA controller+1
  88.     EOR #%11111111
  89.     AND controller
  90.     STA controller+2
  91.    
  92.     RTS
  93.    
  94. HandleInput:
  95.     LDA controller+2
  96.     AND #%00001111
  97.     BEQ .return
  98.  
  99.     AND #%00000100
  100.     BEQ .return
  101.     JSR MoveDown
  102.    
  103. .return:
  104.     RTS
  105. ; ----------------------------------------
  106.  
  107. ; Load CHR
  108. LoadCHRBank:
  109.     LDA #LOW(SpriteData)
  110.     STA chrPointer
  111.     LDA #HIGH(SpriteData+1)
  112.     STA chrPointer+1
  113.    
  114.     LDY #$00
  115.     LDA $2002
  116.     LDA [chrPointer], Y
  117.     STA $2006
  118.     INC chrPointer
  119.     LDA [chrPointer], Y
  120.     STA $2006
  121.     INC chrPointer
  122.     LDX #$00
  123.     LDY #$00
  124. .loop:
  125.     LDA [chrPointer], Y
  126.     STA $2007
  127.     INY
  128.     CPY #$00
  129.     BNE .loop
  130.     INC chrPointer+1
  131.     INX
  132.     CPX #$10
  133.     BNE .loop
  134.    
  135.     RTS
  136. ; ----------------------------------------
  137.  
  138. Reset:
  139.     SEI
  140.     CLD
  141.     LDX #$40
  142.     STX $4017
  143.     LDX #$FF
  144.     TXS
  145.     INX
  146.     STX $2000
  147.     STX $2001
  148.     STX $4010
  149.    
  150.     BIT $2002
  151.     JSR VBlankWait
  152.    
  153. ClrMem:
  154.     LDA #$00
  155.     STA $0000, X
  156.     STA $0100, X
  157.     STA $0300, X
  158.     STA $0400, X
  159.     STA $0500, X
  160.     STA $0600, X
  161.     STA $0700, X
  162.     LDA #$FE
  163.     STA $0200, X
  164.     INX
  165.     BNE ClrMem
  166.    
  167.     BIT $2002
  168.     JSR VBlankWait
  169.    
  170.     LDA $2002
  171.     LDA #$3F
  172.     STA $2006
  173.     LDA #$10
  174.     STA $2006
  175. LoadPalettes:
  176.     LDA Palettes, X
  177.     STA $2007
  178.     INX
  179.     CPX #$10
  180.     BNE LoadPalettes
  181.    
  182.     LDA #$80
  183.     STA UGLOO_RAM
  184.     STA UGLOO_RAM+3
  185.    
  186.     LDA #LOW(UglooSprite)
  187.     STA spritePointer
  188.     LDA #HIGH(UglooSprite+1)
  189.     STA spritePointer+1
  190.    
  191.     LDA #$00
  192.     STA $2003
  193.    
  194.     LDA #$00
  195.     STA spritePointerIndex
  196.    
  197.     JSR LoadCHRBank
  198.    
  199.     LDA #%10010000
  200.     STA $2000
  201.    
  202. Forever:
  203.     JSR WaitFrame
  204.    
  205.     JSR ReadController
  206.     JSR HandleInput
  207.    
  208.     JSR SpriteAnimation
  209.     JSR SpriteFrameUpdate
  210.    
  211.     JSR UpdateUgloo
  212.    
  213.     JMP Forever
  214.    
  215. Nmi:
  216.     PHA
  217.     TXA
  218.     PHA
  219.     TYA
  220.     PHA
  221.    
  222.     LDA #$02
  223.     STA $4014
  224.    
  225.     LDA #$00
  226.     STA $2005
  227.     STA $2005
  228.     STA $2006
  229.     STA $2006
  230.    
  231.     LDA #%00011110
  232.     STA $2001
  233.    
  234.     LDA #$00
  235.     STA sleeping
  236.    
  237.     PLA
  238.     TAY
  239.     PLA
  240.     TAX
  241.     PLA
  242.    
  243.     RTI
  244.  
  245. Palettes:
  246.     .db $0F, $C2, $08, $21, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F
  247.    
  248.     .bank 1
  249.     .org $A000
  250.    
  251. SpritesDown:
  252.     .db $00, $08, $10
  253.    
  254. MoveDown:
  255.     LDA #$01
  256.     STA direction
  257.    
  258.     LDA UGLOO_RAM
  259.     CLC
  260.     ADC #02
  261.     STA UGLOO_RAM
  262.    
  263.     INC animation
  264.    
  265.     RTS
  266.    
  267. UpdateUgloo:
  268.     LDA UGLOO_RAM
  269.     STA UGLOO_RAM+4
  270.     CLC
  271.     ADC #$08
  272.     STA UGLOO_RAM+8
  273.     STA UGLOO_RAM+12
  274.    
  275.     LDA UGLOO_RAM+3
  276.     STA UGLOO_RAM+11
  277.     CLC
  278.     ADC #$08
  279.     STA UGLOO_RAM+7
  280.     STA UGLOO_RAM+15
  281.    
  282.     RTS
  283.  
  284. SpriteAnimation:
  285.     LDA animation
  286.     CMP #FRAME1
  287.     BEQ .anim1
  288.     CMP #FRAME2
  289.     BEQ .anim2
  290.     CMP #FRAME3
  291.     BEQ .anim1
  292.     CMP #FRAME4
  293.     BEQ .anim3
  294.     JMP .done
  295.    
  296. .anim1:
  297.     LDA #$00
  298.     STA frame
  299.     JMP .done
  300.    
  301. .anim2:
  302.     LDA #$01
  303.     STA frame
  304.     JMP .done
  305.    
  306. .anim3:
  307.     LDA #$02
  308.     STA frame
  309.     JMP .done
  310.  
  311. .done:
  312.     LDA animation
  313.     CMP #FRAME4
  314.     BNE .return
  315.     SEC
  316.     SBC #FRAME4
  317.     STA animation
  318.    
  319. .return:
  320.     RTS
  321.  
  322. SpriteFrameUpdate:
  323.     LDA direction
  324.     BEQ .up
  325.     CMP #$01
  326.     BEQ .down
  327.     CMP #$02
  328.     BEQ .left
  329.     JMP .right
  330.    
  331. .up:
  332.     LDA frame
  333.     TAX
  334.     LDA SpritesDown, X
  335.     TAY
  336.     JSR UpdateCHRRam
  337.  
  338. .down
  339.     LDA frame
  340.     TAX
  341.     LDA SpritesDown, X
  342.     TAY
  343.     JSR UpdateCHRRam
  344.    
  345. .left
  346.     LDA frame
  347.     TAX
  348.     LDA SpritesDown, X
  349.     TAY
  350.     JSR UpdateCHRRam
  351.  
  352. .right
  353.     LDA frame
  354.     TAX
  355.     LDA SpritesDown, X
  356.     TAY
  357.     JSR UpdateCHRRam
  358.  
  359. UpdateCHRRam:
  360.     LDX spritePointerIndex
  361.     LDA spritePointer, X
  362.     STA gfxPointer
  363.     INX
  364.     LDA spritePointer, X
  365.     STA gfxPointer+1
  366.    
  367.     LDA [gfxPointer], Y
  368.     STA UGLOO_RAM+1, X
  369.     INY
  370.     LDA [gfxPointer], Y
  371.     STA UGLOO_RAM+5, X
  372.     INY
  373.     LDA [gfxPointer], Y
  374.     STA UGLOO_RAM+9, X
  375.     INY
  376.     LDA [gfxPointer], Y
  377.     STA UGLOO_RAM+13, X
  378.     INY
  379.     LDA [gfxPointer], Y
  380.     STA UGLOO_RAM+2, X
  381.     INY
  382.     LDA [gfxPointer], Y
  383.     STA UGLOO_RAM+6, X
  384.     INY
  385.     LDA [gfxPointer], Y
  386.     STA UGLOO_RAM+10, X
  387.     INY
  388.     LDA [gfxPointer], Y
  389.     STA UGLOO_RAM+14, X
  390.    
  391.     RTS
  392.  
  393.    
  394.    
  395.     .bank 2
  396.     .org $C000
  397.     .include "inc/sprites.asm"
  398.    
  399.    
  400.     .bank 3
  401.     .org $E000
  402. SpriteData:
  403.     .db $00, $00
  404.     .incbin "inc/crapMeta.chr"
  405.    
  406.     .org $FFFA
  407.     .dw Nmi
  408.     .dw Reset
  409.     .dw 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement