Advertisement
Kitomas

crewmate code that uses the new libraries

Apr 13th, 2023
2,680
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "std/pseudoOps.h"
  2. #include "std/l1_sub.h"
  3. #define MATH_USE_ADD
  4. #include "std/math.h"
  5.  
  6. ;.1*256 = 25.6 ~= 26
  7. ;vel and pos are fixed point numbers with 8 bits of fraction
  8. #define accel (.1*256)
  9. #define current_canvas 3
  10. ;pitch is how many pixels across the current canvas is
  11. #define pitch (16*2**current_canvas)
  12. #define vram_start (0x8000-pitch**2)
  13.  
  14. ;program start
  15.     set_canvas(#,current_canvas)
  16.     jmp 0x200
  17. !@= 0x200 ;loop start
  18.    
  19.     ;key event velocity change
  20.            get_key(#,'w') && bzs no_w   ;if 'w' key pressed,
  21.         add8s_16(#,-accel, vel_y)       ;^^vel_y -= accel
  22.     :no_w: get_key(#,'a') && bzs no_a   ;if 'a' key pressed,
  23.         add8s_16(#,-accel, vel_x)       ;^^vel_x -= accel
  24.     :no_a: get_key(#,'s') && bzs no_s   ;if 's' key pressed,
  25.         add8s_16(#,accel, vel_y)        ;^^vel_y += accel
  26.     :no_s: get_key(#,'d') && bzs no_d   ;if 'd' key pressed,
  27.         add8s_16(#,accel, vel_x)        ;^^vel_x += accel
  28.     :no_d:
  29.    
  30.     add16_16(pos_x_low, vel_x)  ;add x velocity to x position
  31.     add16_16(pos_y_low, vel_y)  ;add y velocity to y position
  32.    
  33.     ldi #,0                             ;set index register to 0
  34.     lda @,pos_x                         ;put x&y into sprites' x&y
  35.     sta $,amoog && sta $,amoog_flip     ;^^
  36.     lda @,pos_y                         ;^^
  37.     sta $,amoog+1 && sta $,amoog_flip+1 ;^^
  38.    
  39.     lda #,0                     ;set every pixel of canvas to palette color 0
  40.     sys #,0x05                  ;^^
  41.     lda @,vel_x+1 && and #,0x80 ;if x velocity negative,
  42.     bnz .f                      ;^^blit the horizontally-flipped sprite instead
  43.     ldc_imm(amoog) && jmp .r    ;^^
  44. .f: ldc_imm(amoog_flip)         ;^^
  45. .r: sys #,0x06                  ;^^(sys #6 blits the sprite at address C (L&H))
  46.    
  47.     ldh @,pos_x         ;this doesn't do anything other than put
  48.     ldl @,pos_y         ;^^the position into L&H as a sort of debug print
  49.     wait_frame
  50.    
  51.     jmp 0x200 ;go to start of loop
  52.    
  53.  
  54. ;pitch/2-(w or h)/2 = centered
  55. :pos_x_low: !8 0 && :pos_x: !8 pitch/2-4
  56. :pos_y_low: !8 0 && :pos_y: !8 pitch/2-4
  57. :vel_x: !16 0  &&  :vel_y: !16 0
  58. #define rd 196 //palette color red
  59. #define bl 80  //palette color blue
  60. #define wh 231 //palette color white
  61. ;x,y, w,h, pixel data...
  62. :amoog: !8  0,0, 8,8
  63. !8   0, 0,rd,rd,rd,rd,rd,rd
  64. !8   0, 0,rd,rd,rd,rd,rd,rd
  65. !8  rd,rd,rd,rd,bl,wh,wh,wh
  66. !8  rd,rd,rd,rd,bl,bl,bl,bl
  67. !8  rd,rd,rd,rd,rd,rd,rd,rd
  68. !8  rd,rd,rd,rd,rd,rd,rd,rd
  69. !8   0, 0,rd,rd, 0, 0,rd,rd
  70. !8   0, 0,rd,rd, 0, 0,rd,rd
  71. :amoog_flip: !8  0,0, 8,8
  72. !8  rd,rd,rd,rd,rd,rd, 0, 0
  73. !8  rd,rd,rd,rd,rd,rd, 0, 0
  74. !8  wh,wh,wh,bl,rd,rd,rd,rd
  75. !8  bl,bl,bl,bl,rd,rd,rd,rd
  76. !8  rd,rd,rd,rd,rd,rd,rd,rd
  77. !8  rd,rd,rd,rd,rd,rd,rd,rd
  78. !8  rd,rd, 0, 0,rd,rd, 0, 0
  79. !8  rd,rd, 0, 0,rd,rd, 0, 0
  80.  
  81. #include "std/math.asm"
  82. !savlbl "labels.txt" && !to "program.bin" && !save
Tags: kit-8
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement