Kitomas

KIT-8 Sin/Cos Test

Mar 31st, 2023 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pseudoOps.asm"
  2. #define center (128-18)/2
  3. ;this computes sin by grabbing from sin_table
  4. #define sin8_i_shift(_shft) \
  5.  lda @,sin_table                    &&\
  6.  shr(#,_shft) && sta $,_SCRATCH_C   &&\
  7.  and #,0x80>>_shft && bnz @+2+3     &&\
  8.  lda #,0 && jmp @+3+2               &&\
  9.  lda #,_l(0xff00>>_shft)            &&\
  10.  ora_abs(_SCRATCH_C)
  11.    
  12. ;program start
  13.     jmp 0x200 ;so i can potentially use 0x02 -> 0x1ff for whatever
  14. !@= 0x200
  15.     set_canvas(#,3) ;switch canvas size to 128x128 (16x16 * 2^3)
  16.     :start: ldc_imm(0xc000) ;start of vram
  17.     :loop:
  18.         rand           ;load random byte into A
  19.         sta ^          ;store random byte at address C
  20.         inc            ;increment C
  21.         bcnz_imm(loop) ;break loop if C wraps back to 0
  22.     ldi_abs ball_radians            ;
  23.     sin8_i_shift(2) && add #,center ;
  24.     sta $,ball_sprite               ;
  25.     ini && ini && ini               ;
  26.     sti $,ball_radians              ;;
  27.     ldi_abs ball_radians+1          ;
  28.     sin8_i_shift(2) && add #,center ;
  29.     sta $,ball_sprite+1             ;
  30.     ini && ini && ini && ini        ;
  31.     sti $,ball_radians+1            ;;
  32.     ldc_imm(ball_sprite) && sys #,5 ;blit circle sprite to screen
  33.     get_key(#,'a')   ;put boolean state of keyboard key "a" into A
  34.     bnz .s           ;if boolean true, skip to line 12
  35.     wait_frames(#,1) ;if "a" not pressed, wait additional 8 frames
  36. .s: wait_frames(#,1) ;^^(basically, pressing "a" makes the speed 2x)
  37.     jmp start
  38.  
  39. :ball_radians: !8 64,0 ;for cos,sin; =value * about .025 radians
  40. ;the ball sprite that moves around
  41. #define a 231
  42. #define b 255
  43. #define c 254
  44. #define d 253
  45. #define e 188
  46. #define f 252
  47. #define g 251
  48. #define h 250
  49. #define i 249
  50. #define j 145
  51. :ball_sprite: !8 center,center, 18,18
  52. !8  0,0,0,0,0,0,a,a,a,a,a,a,0,0,0,0,0,0
  53. !8  0,0,0,0,a,a,b,b,b,b,b,b,a,a,0,0,0,0
  54. !8  0,0,0,a,b,b,c,c,c,c,c,c,b,b,a,0,0,0
  55. !8  0,0,a,b,c,c,d,d,d,d,d,d,c,c,b,a,0,0
  56. !8  0,a,b,c,d,d,e,e,e,e,e,e,d,d,c,b,a,0
  57. !8  0,a,b,c,d,e,f,f,f,f,f,f,e,d,c,b,a,0
  58. !8  a,b,c,d,e,f,g,g,g,g,g,g,f,e,d,c,b,a
  59. !8  a,b,c,d,e,f,g,h,i,i,h,g,f,e,d,c,b,a
  60. !8  a,b,c,d,e,f,g,i,j,j,i,g,f,e,d,c,b,a ;
  61. !8  a,b,c,d,e,f,g,i,j,j,i,g,f,e,d,c,b,a ;
  62. !8  a,b,c,d,e,f,g,h,i,i,h,g,f,e,d,c,b,a
  63. !8  a,b,c,d,e,f,g,g,g,g,g,g,f,e,d,c,b,a
  64. !8  0,a,b,c,d,e,f,f,f,f,f,f,e,d,c,b,a,0
  65. !8  0,a,b,c,d,d,e,e,e,e,e,e,d,d,c,b,a,0
  66. !8  0,0,a,b,c,c,d,d,d,d,d,d,c,c,b,a,0,0
  67. !8  0,0,0,a,b,b,c,c,c,c,c,c,b,b,a,0,0,0
  68. !8  0,0,0,0,a,a,b,b,b,b,b,b,a,a,0,0,0,0
  69. !8  0,0,0,0,0,0,a,a,a,a,a,a,0,0,0,0,0,0
  70.  
  71. :sin_table: !bin "gen/sin256_8.bin" ;sin lookup table
  72.  
  73. !savlbl "labels.txt" && !to "program.bin" && !save
Tags: kit-8
Add Comment
Please, Sign In to add comment