Advertisement
Kitomas

pseudoOps.asm (for KIT-8)

Mar 31st, 2023 (edited)
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.51 KB | Source Code | 0 0
  1. #ifndef PSEUDOOPS_ASM
  2. #define PSEUDOOPS_ASM
  3.  
  4. ;pseudoOps.asm
  5.  #define _SCRATCH_A 0xf0
  6.  #define _SCRATCH_B 0xf1
  7.  #define _SCRATCH_C 0xf2
  8.  
  9.  ;flags
  10.   #define sen  tra s && ora #,0x80 && tar s
  11.   #define seo  tra s && ora #,0x40 && tar s
  12.   #define sed  tra s && ora #,0x20 && tar s
  13.   #define seL  tra s && ora #,0x10 && tar s
  14.   #define see  tra s && ora #,0x08 && tar s
  15.   #define sel  tra s && ora #,0x04 && tar s
  16.   #define sez  tra s && ora #,0x02 && tar s
  17.   #define sec  tra s && ora #,0x01 && tar s
  18.   #define cln  tra s && and #,0x7f && tar s
  19.   #define clo  tra s && and #,0xbf && tar s
  20.   #define cld  tra s && and #,0xdf && tar s
  21.   #define clL  tra s && and #,0xef && tar s
  22.   #define cle  tra s && and #,0xf7 && tar s
  23.   #define cll  tra s && and #,0xfb && tar s
  24.   #define clz  tra s && and #,0xfd && tar s
  25.   #define clc  tra s && and #,0xfe && tar s
  26.  #define brk  hcf
  27.  ;bnz (put expression after or it won't work)
  28.  #define bns  tra s && and #,0x80 && bnz
  29.  #define bos  tra s && and #,0x40 && bnz
  30.  #define bds  tra s && and #,0x20 && bnz
  31.  #define bLs  tra s && and #,0x10 && bnz
  32.  #define bes  tra s && and #,0x08 && bnz
  33.   #define beq  bes
  34.  #define bls  tra s && and #,0x04 && bnz
  35.   #define blt  bls
  36.  #define bzs  tra s && and #,0x02 && bnz
  37.  #define bcs  tra s && and #,0x01 && bnz
  38.  #define bnc  tra s && and #,0x80 && xor #,0x80 && bnz
  39.  #define boc  tra s && and #,0x40 && xor #,0x40 && bnz
  40.  #define bdc  tra s && and #,0x20 && xor #,0x20 && bnz
  41.  #define bLc  tra s && and #,0x10 && xor #,0x10 && bnz
  42.  #define bec  tra s && and #,0x08 && xor #,0x08 && bnz
  43.   #define bne  bec
  44.  #define blc  tra s && and #,0x04 && xor #,0x04 && bnz
  45.  #define bzc  tra s && and #,0x02 && xor #,0x02 && bnz
  46.  #define bcc  tra s && and #,0x01 && xor #,0x01 && bnz
  47.  ;multiple flag branches
  48.   #define bgtu  tra s && and #,0b1100 && bzs
  49. ;ina
  50.  #define ini  ina i
  51.  #define inl  ina l
  52.  #define inh  ina h
  53.  #define inc  ina c
  54. ;tar
  55.  #define tai  tar i
  56.  #define tal  tar l
  57.  #define tah  tar h
  58.  #define tas  tar s
  59. ;tra
  60.  #define tia  tra i
  61.  #define tla  tra l
  62.  #define tha  tra h
  63.  #define tsa  tra s
  64. ;ldr
  65.  #define ldi  ldr i
  66.   #define ldi_abs ldi #,0 && ldi @,
  67.  #define ldl  ldr l
  68.  #define ldh  ldr h
  69.  #define lda  ldr a
  70.   #define lda_abs_s(_n) \
  71.     sti $,_SCRATCH_A && ldi #,0 &&\
  72.     lda @,_n && ldi @,_SCRATCH_A
  73. ;str
  74.  #define sti  str i
  75.  #define stl  str l
  76.  #define sth  str h
  77.  #define sta  str a
  78. ;ror
  79.  #define rol(_d,_n) ror _d,8-_n
  80.  #define shl(_d,_n) ror _d,8-_n && and #,0xff<<_n
  81.  #define shr(_d,_n) ror _d,_n && and #,0xff>>_n
  82. ;ora
  83.  #define ora_abs(_n) \
  84.     sti $,_SCRATCH_A && ldi #,0 &&\
  85.    ora @,_n && ldi @,_SCRATCH_A
  86. ;sys
  87.  #define wait_frame sys #,0x00
  88.  #define wait_frames(_d,_n) lda _d,_n && sys #,0x01
  89.  #define set_canvas(_d,_c) lda _d,_c && sys #,0x02
  90.  #define rand  sys #,0xfe
  91.  #define get_key(_d,_k) lda _d,_k && sys #,0xff
  92.  
  93. #define ldc_imm(_v16)  ldl #,_l(_v16) && ldh #,_h(_v16)
  94. ;multi byte compare and branch (replace _skip with raw offset)
  95.  #define bcltu_imm(_v16, _dst, _skip) \
  96.     tha  &&  cmp #,_h(_v16)     &&\
  97.     blt _dst  &&  bgtu _skip    &&\
  98.     tla  &&  cmp #,_l(_v16)     &&\
  99.    blt _dst
  100.  #define bceq_imm(_v16, _dst, _skip) \
  101.     tha  &&  cmp #,_h(_v16)     &&\
  102.     bne _skip                   &&\
  103.     tla  &&  cmp #,_l(_v16)     &&\
  104.     beq _dst
  105.  #define bcne_imm(_v16, _dst) \
  106.     tha  &&  cmp #,_h(_v16)  &&  bne _dst   &&\
  107.     tla  &&  cmp #,_l(_v16)  &&  bne _dst
  108.  #define bcnz_imm(_dst) \
  109.    tha && bnz _dst  &&\
  110.     tla && bnz _dst
  111. ;\pseudoOps.asm
  112. #endif
  113.  
Tags: kit-8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement