SineAndGraphics.asm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. :BasicUpstart2(start)
  2. //--------------------------------------------
  3. // Functions for calculating vic values and other stuff
  4. // (normally we would put these in a library)
  5. .function screenToD018(addr) { // <- This is how we define a function
  6. .return ((addr&$3fff)/$400)<<4
  7. }
  8. .function charsetToD018(addr) {
  9. .return ((addr&$3fff)/$800)<<1
  10. }
  11. .function toD018(screen, charset) {
  12. .return screenToD018(screen) | charsetToD018(charset) //<- This is how we call functions
  13. }
  14. .function toSpritePtr(addr) {
  15. .return (addr&$3fff)/$40
  16. }
  17. .function sinus(i, amplitude, center, noOfSteps) {
  18. .return round(center+amplitude*sin(toRadians(i*360/noOfSteps)))
  19. }
  20. //--------------------------------------------
  21. *=$2000 "Program"
  22. start: sei
  23. // Print chars to screen
  24. ldx #0
  25. lda #5
  26. !loop: sta screen,x // <- '!' in front of a label means a multilabel (You can have several labels with the same name)
  27. sta screen+$100,x
  28. sta screen+$200,x
  29. sta screen+$300,x
  30. sec
  31. sbc #1
  32. bcs !over+ // <- Referencing forward to the nearest a multilabel called 'over'
  33. lda #5
  34. !over:
  35. inx
  36. bne !loop- // <- Referencing backward to the nearest multilabel called 'loop'
  37. lda #toD018(screen, charset) // <- The d018 value is calculated by a function. You can move graphics around and not worry about d018 is properly set
  38. sta $d018
  39. // Setup some sprites
  40. lda #$0f
  41. sta $d015
  42. ldx #7
  43. !loop: lda spritePtrs,x
  44. sta screen+$3f8,x
  45. txa
  46. lsr
  47. sta $d027,x
  48. dex
  49. bpl !loop-
  50. // Make an effect loop with nonsense sprite movement
  51. ldx #0
  52. ldy #$0
  53. !loop: lda $d012 // Wait for frame
  54. cmp #$ff
  55. bne !loop-
  56. lda sinus,x // Set sprite 1
  57. sta $d000
  58. lda sinus+$40,x
  59. sta $d001
  60. lda sinus,x // Set sprite 2
  61. sta $d002
  62. lda sinus+$30,y
  63. sta $d003
  64. lda #$f0 // Set sprite 3
  65. sta $d004
  66. lda sinus,y
  67. sta $d005
  68. lda sinus+$70,x // Set sprite 4
  69. sta $d006
  70. lda sinus,y
  71. sta $d007
  72. inx
  73. iny
  74. iny
  75. iny
  76. jmp !loop-
  77. //--------------------------------------------
  78. spritePtrs: .byte toSpritePtr(sprite1), toSpritePtr(sprite2) // <- The spritePtr function is use to calculate the spritePtr
  79. .byte toSpritePtr(sprite1), toSpritePtr(sprite2)
  80. .byte 0,0,0,0
  81. sinus: .fill $100, round($a0+$40*sin(toRadians(i*360/$100))) // <- The fill functions takes two argument.
  82. // The number of bytes to fill and an expression to execute for each
  83. // byte. 'i' is the byte number
  84. .fill $100, sinus(i, $40, $a0, $100) //<- Its easier to use a function when you use the expression many times
  85. //--------------------------------------------
  86. .align $0800 // <-- You can use align to align data to memory boundaries
  87. charset: .byte %11111110
  88. .byte %10000010
  89. .byte %10000010
  90. .byte %10000010
  91. .byte %10000010
  92. .byte %10000010
  93. .byte %11111110
  94. .byte %00000000
  95. .byte %00000000
  96. .byte %01111100
  97. .byte %01000100
  98. .byte %01000100
  99. .byte %01000100
  100. .byte %01111100
  101. .byte %00000000
  102. .byte %00000000
  103. .byte %00000000
  104. .byte %00000000
  105. .byte %00111000
  106. .byte %00101000
  107. .byte %00111000
  108. .byte %00000000
  109. .byte %00000000
  110. .byte %00000000
  111. .byte %00000000
  112. .byte %00000000
  113. .byte %00000000
  114. .byte %00010000
  115. .byte %00000000
  116. .byte %00000000
  117. .byte %00000000
  118. .byte %00000000
  119. .byte %00000000
  120. .byte %00000000
  121. .byte %00000000
  122. .byte %00000000
  123. .byte %00000000
  124. .byte %00000000
  125. .byte %00000000
  126. .byte %00000000
  127. .byte %00000000
  128. .byte %00000000
  129. .byte %00000000
  130. .byte %00000000
  131. .byte %00000000
  132. .byte %00000000
  133. .byte %00000000
  134. .byte %00000000
  135. //--------------------------------------------
  136. .align $40
  137. sprite1: .byte %00000000, %11111111, %00000000
  138. .byte %00000001, %11111111, %10000000
  139. .byte %00000011, %11111111, %11000000
  140. .byte %00000111, %11111111, %11100000
  141. .byte %00001111, %11111111, %11110000
  142. .byte %00011111, %11111111, %11111000
  143. .byte %00111111, %11111111, %11111100
  144. .byte %00000011, %11111111, %11000000
  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
  153. .byte %00000000, %00000000, %00000000
  154. .byte %00000000, %00000000, %00000000
  155. .byte %00000000, %00000000, %00000000
  156. .byte %00000000, %00000000, %00000000
  157. .byte %00000000, %00000000, %00000000
  158. .byte $00
  159. sprite2: .byte %01110000, %00000000, %00000000
  160. .byte %11111000, %00000000, %00000000
  161. .byte %11111000, %00000000, %00000000
  162. .byte %01110000, %00000000, %00000000
  163. .byte %00000000, %00000000, %00000000
  164. .byte %00000000, %00000000, %00000000
  165. .byte %00000000, %00000000, %00000000
  166. .byte %00000000, %00000000, %00000000
  167. .byte %00000000, %00000000, %00000000
  168. .byte %00000000, %00000000, %00000000
  169. .byte %00000000, %00000000, %00000000
  170. .byte %00000000, %00000000, %00000000
  171. .byte %00000000, %00000000, %00000000
  172. .byte %00000000, %00000000, %00000000
  173. .byte %00000000, %00000000, %00000000
  174. .byte %00000000, %00000000, %00000000
  175. .byte %00000000, %00000000, %00000000
  176. .byte %00000000, %00000000, %00000000
  177. .byte %00000000, %00000000, %00000000
  178. .byte %00000000, %00000000, %00000000
  179. .byte %00000000, %00000000, %00000000
  180. .byte $00
  181. //--------------------------------------------
  182. * = $3c00 "Virtual data" virtual // <- Data in a virtual block is not entered into memory
  183. screen: .fill $0400, 0