Advertisement
Kitomas

kit-8 std/pseudoOps.h v1

Apr 13th, 2023
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.40 KB | Source Code | 0 0
  1. #ifndef _STD_PSEUDOOPS_H
  2. #define _STD_PSEUDOOPS_H
  3. ;std/pseudoOps.h
  4.  #define _SCRATCH_A 0xf0
  5.  #define _SCRATCH_B 0xf1
  6.  #define _SCRATCH_C 0xf2
  7.  #define _SCRATCH_D 0xf3
  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.  #define rts  jpr
  28.  ;bnz (put expression after or it won't work)
  29.  #define bns  tra s && and #,0x80 && bnz
  30.  #define bos  tra s && and #,0x40 && bnz
  31.  #define bds  tra s && and #,0x20 && bnz
  32.  #define bLs  tra s && and #,0x10 && bnz
  33.  #define bes  tra s && and #,0x08 && bnz
  34.   #define beq  bes
  35.  #define bls  tra s && and #,0x04 && bnz
  36.   #define blt  bls
  37.  #define bzs  tra s && and #,0x02 && bnz
  38.  #define bcs  tra s && and #,0x01 && bnz
  39.  #define bnc  tra s && and #,0x80 && xor #,0x80 && bnz
  40.  #define boc  tra s && and #,0x40 && xor #,0x40 && bnz
  41.  #define bdc  tra s && and #,0x20 && xor #,0x20 && bnz
  42.  #define bLc  tra s && and #,0x10 && xor #,0x10 && bnz
  43.  #define bec  tra s && and #,0x08 && xor #,0x08 && bnz
  44.   #define bne  bec
  45.  #define blc  tra s && and #,0x04 && xor #,0x04 && bnz
  46.  #define bzc  tra s && and #,0x02 && xor #,0x02 && bnz
  47.  #define bcc  tra s && and #,0x01 && xor #,0x01 && bnz
  48.  ;multiple flag branches
  49.   #define bgtu  tra s && and #,0b1100 && bzs
  50.   #define bgts  tra s && and #,0b11000 && bzs
  51.  ;long branches
  52.   #define bns_long bnc @+3 jpa
  53.   #define bos_long boc @+3 jpa
  54.   #define bds_long bdc @+3 jpa
  55.   #define bLs_long bLc @+3 jpa
  56.   #define bes_long bec @+3 jpa
  57.   #define bls_long blc @+3 jpa
  58.   #define bzs_long bzc @+3 jpa
  59.   #define bcs_long bcc @+3 jpa
  60.   ;
  61.   #define bnc_long bns @+3 jpa
  62.   #define boc_long bos @+3 jpa
  63.   #define bdc_long bds @+3 jpa
  64.   #define bLc_long bLs @+3 jpa
  65.   #define bec_long bes @+3 jpa
  66.   #define blc_long bls @+3 jpa
  67.   #define bzc_long bzs @+3 jpa
  68.   #define bcc_long bcs @+3 jpa
  69. ;ina
  70.  #define ini  ina i
  71.  #define inl  ina l
  72.  #define inh  ina h
  73.  #define inc  ina c
  74. ;tar
  75.  #define tai  tar i
  76.  #define tal  tar l
  77.  #define tah  tar h
  78.  #define tas  tar s
  79. ;tra
  80.  #define tia  tra i
  81.  #define tla  tra l
  82.  #define tha  tra h
  83.  #define tsa  tra s
  84. ;ldr
  85.  #define ldi  ldr i
  86.   #define ldi_abs ldi #,0 && ldi @,
  87.  #define ldl  ldr l
  88.  #define ldh  ldr h
  89.  #define lda  ldr a
  90.   #define lda_abs_s(_n) \
  91.     sti $,_SCRATCH_A && ldi #,0 &&\
  92.     lda @,_n && ldi @,_SCRATCH_A
  93.  #define ldc_imm(_v16)  ldl #,_l(_v16) && ldh #,_h(_v16)
  94.  #define ldc_abs(_addr) \
  95.     sti $,_SCRATCH_A && ldi #,0     &&\
  96.     ldl @,_addr && ldh @,1+_addr    &&\
  97.     ldi @,_SCRATCH_A
  98. ;str
  99.  #define sti  str i
  100.  #define stl  str l
  101.  #define sth  str h
  102.  #define sta  str a
  103.  #define stc_abs(_addr) stl $,(_addr) && sth $,1+(_addr)
  104. ;ror
  105.  #define rol(_d,_n) ror _d,8-(_n)
  106.  #define shl(_d,_n) ror _d,8-(_n) && and #,_l(0xff<<(_n))
  107.  #define shr(_d,_n) ror _d,(_n) && and #,_l(0xff>>(_n))
  108. ;and
  109. ;ora
  110.  #define ora_abs(_n) \
  111.     sti $,_SCRATCH_A && ldi #,0 &&\
  112.    ora @,_n && ldi @,_SCRATCH_A
  113. ;sys
  114.  #define wait_frame sys #,0x00
  115.  #define wait_frames(_d,_n) lda _d,_n && sys #,0x01
  116.  #define set_canvas(_d,_c) lda _d,_c && sys #,0x02
  117.  #define rand  sys #,0xfe
  118.  #define get_key(_d,_k) lda _d,_k && sys #,0xff
  119.  #define get_key_nc(_d,_k) \
  120.     lda _d,_k               &&\
  121.     stc_abs(_SCRATCH_B)     &&\
  122.     sys #,0xff              &&\
  123.     lda_abs_s(_SCRATCH_B)
  124.  
  125. ;multi byte compare and branch
  126.  #define bcltu_imm(_v16, _dst) \
  127.     tha  &&  cmp #,_h(_v16) &&\
  128.     blt _dst  &&  bgtu @+5  &&\
  129.     tla  &&  cmp #,_l(_v16) &&\
  130.    blt _dst
  131.  #define bceq_imm(_v16, _dst) \
  132.     tha  &&  cmp #,_h(_v16) &&\
  133.     bne @+5                 &&\
  134.     tla  &&  cmp #,_l(_v16) &&\
  135.     beq _dst
  136.  #define bcne_imm(_v16, _dst) \
  137.     tha  &&  cmp #,_h(_v16)  &&  bne _dst   &&\
  138.     tla  &&  cmp #,_l(_v16)  &&  bne _dst
  139.  #define bcnz_imm(_dst) \
  140.    tha && bnz _dst  &&\
  141.     tla && bnz _dst
  142.  
  143. #endif
  144.  
Tags: kit-8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement