Advertisement
Er0l

PreCalcVector

Dec 9th, 2016
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. BasicUpstart2(start)
  2.  
  3. //----------------------------------------------------------
  4. //----------------------------------------------------------
  5. // Pre Calculated Vector
  6. //----------------------------------------------------------
  7. //----------------------------------------------------------
  8.  
  9.  
  10. * = $1000 "Main Program"
  11. start:
  12. sei
  13.  
  14. lda #<irq1
  15. sta $0314
  16. lda #>irq1
  17. sta $0315
  18. asl $d019
  19. lda #$7b
  20. sta $dc0d
  21. lda #$81
  22. sta $d01a
  23. lda #$1b
  24. sta $d011
  25. lda #$20
  26. sta $d012
  27. lda #$00
  28. sta $d020
  29. sta $d021
  30. jsr InitSprites
  31.  
  32. cli
  33. jmp *
  34.  
  35. //----------------------------------------------------------
  36. irq1:
  37. asl $d019
  38. inc $d020
  39.  
  40. ldx frameNr
  41. jsr PlaceSprites
  42. inc frameNr
  43. lda #0
  44. sta $d020
  45.  
  46. pla
  47. tay
  48. pla
  49. tax
  50. pla
  51. rti
  52. frameNr: .byte 0
  53.  
  54. InitSprites:
  55. lda #$ff // Turn on Sprites
  56. sta $d015
  57.  
  58. lda #$00 // Set single color
  59. sta $d01c
  60.  
  61.  
  62. lda #$00 // No x and y expansion
  63. sta $d017
  64. sta $d01d
  65.  
  66. ldx #7
  67. !loop:
  68. lda #$f // Set sprite color
  69. sta $d027,x
  70. lda #$0fc0/$40 // Set sprite image
  71. sta $07f8,x
  72. dex
  73. bpl !loop-
  74. rts
  75.  
  76. PlaceSprites:
  77.  
  78. .for (var i=0; i<8;i++) {
  79. lda cubeCoords+i*$200,x
  80. sta $d000+i*2
  81. lda cubeCoords+$100+i*$200,x
  82. sta $d001+i*2
  83. }
  84. rts
  85.  
  86.  
  87. //--------------------------------------------------------------------------------
  88. // Objects
  89. //--------------------------------------------------------------------------------
  90. .var Cube = List().add(
  91. Vector(1,1,1), Vector(1,1,-1), Vector(1,-1,1), Vector(1,-1,-1),
  92. Vector(-1,1,1), Vector(-1,1,-1), Vector(-1,-1,1), Vector(-1,-1,-1))
  93. //--------------------------------------------------------------------------------
  94. // Macro for doing the precalculation
  95. //--------------------------------------------------------------------------------
  96. .macro PrecalcObject(object, animLength, nrOfXrot, nrOfYrot, nrOfZrot) {
  97. // Rotate the coordinate and place the coordinates of each frams in a list
  98. .var frames = List()
  99. .for(var frameNr=0; frameNr<animLength;frameNr++) {
  100. // Set up the transform matrix
  101. .var aX = toRadians(frameNr*360*nrOfXrot/animLength)
  102. .var aY = toRadians(frameNr*360*nrOfYrot/animLength)
  103. .var aZ = toRadians(frameNr*360*nrOfZrot/animLength)
  104. .var zp = 2.5 // z-coordinate for the projection plane
  105. .var m = ScaleMatrix(120,120,0)*PerspectiveMatrix(zp)*MoveMatrix(0,0,zp+5)* RotationMatrix(aX,aY,aZ)
  106. // Transform the coordinates
  107. .var coords = List()
  108. .for (var i=0; i<object.size(); i++) {
  109. .eval coords.add(m*object.get(i))
  110. }
  111. .eval frames.add(coords)
  112. }
  113. // Dump the list to the memory
  114. .for (var coordNr=0; coordNr<object.size(); coordNr++) {
  115. .for (var xy=0;xy<2; xy++) {
  116. .fill animLength, $80+round(frames.get(i).get(coordNr).get(xy))
  117. }
  118. }
  119. }
  120. //--------------------------------------------------------------------------------
  121. // The vector data
  122. //--------------------------------------------------------------------------------
  123. .align $100
  124. cubeCoords: PrecalcObject(Cube,256,2,-1,1)
  125. //--------------------------------------------------------------------------------
  126.  
  127. //-------------------------------------------------------------------------------
  128. // Sprite bob
  129. //-----------------------------------------------------------------------------------------
  130. *= $0fc0 "Sprite data"
  131.  
  132. .byte %01110000, %00000000, %00000000
  133. .byte %11111000, %00000000, %00000000
  134. .byte %11111000, %00000000, %00000000
  135. .byte %01110000, %00000000, %00000000
  136. .byte %00000000, %00000000, %00000000
  137. .byte %00000000, %00000000, %00000000
  138. .byte %00000000, %00000000, %00000000
  139. .byte %00000000, %00000000, %00000000
  140. .byte %00000000, %00000000, %00000000
  141. .byte %00000000, %00000000, %00000000
  142. .byte %00000000, %00000000, %00000000
  143. .byte %00000000, %00000000, %00000000
  144. .byte %00000000, %00000000, %00000000
  145. .byte %00000000, %00000000, %00000000
  146. .byte %00000000, %00000000, %00000000
  147. .byte %00000000, %00000000, %00000000
  148. .byte %00000000, %00000000, %00000000
  149. .byte %00000000, %00000000, %00000000
  150. .byte %00000000, %00000000, %00000000
  151. .byte %00000000, %00000000, %00000000
  152. .byte %00000000, %00000000, %00000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement