Advertisement
Guest User

Flagged! Axiom Source code

a guest
May 10th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ######################## ;
  2. ; #                      # ;
  3. ; #    Flagged! Axiom    # ;
  4. ; #                      # ;
  5. ; ######################## ;
  6.  
  7. ; ReadFlag( : See in Stat -> Calc -> 1st option
  8. ; Reads from flag [arg1] from group [arg2]
  9. ; arg1 ranges from 0 to 7
  10. ; arg2 ranges from 1 to 3 (0 will return arg2)
  11. ; Size : 34 bytes if used at least once, plus 10 bytes each use
  12.  
  13. ; WriteFlag( : See in Stat -> Calc -> 2nd option
  14. ; Writes [arg2] to flag [arg1] from group [arg3]
  15. ; arg1 ranges from 0 to 7
  16. ; arg2 is 0 or 1
  17. ; arg3 ranges from 1 to 3 (0 will return arg2)
  18. ; Size : 35 bytes if used at least once, plus 14 bytes each use
  19.  
  20. ; StoreFlags( : See in Stat -> Calc -> 3rd option
  21. ; Writes [arg1] to group [arg2]
  22. ; arg1 ranges from 0 to 7
  23. ; arg2 ranges from 1 to 3 (0 will return arg2)
  24. ; Size : 14 bytes each use
  25.  
  26. ; GetFlags( : See in Stat -> Calc -> 4th option
  27. ; Stores group [arg1] to hl
  28. ; arg1 ranges  from 1 to 3 (0 will return arg1)
  29. ; Size : 15 bytes each use
  30.  
  31.  
  32.  
  33. ; This Axiom allows to write / read flags (just like assembly) in Axe.
  34. ; This Axiom uses code self-writing, that's why it isn't compatible with Application compiling
  35.  
  36. ; Structure of a bit instruction (4 bytes) :
  37.  
  38. ; +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  39. ; | 31  |  30 |  29 |  28 |  27 |  26 |  25 |  24 |  23 |  22 |  21 |  20 |  19 |  18 |  17 |  16 |  15 |  14 |  13 |  12 |  11 |  10 |  9  |  8  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
  40. ; +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  41. ; |  1  |  1  |  1  |  1  |  1  |  1  |  0  |  1  |  1  |  1  |  0  |  0  |  1  |  0  |  1  |  1  |                   iy offset                   | m 1 | m 2 | b 1 | b 2 | b 3 |  1  |  1  |  0  |
  42. ; +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  43.  
  44. ; compressed denomination : $FD , $CB , iy offset ($20, $21, $22) , %m1_m2_b1_b2_b3_1_1_0
  45.  
  46. ; iy offset will here range from $21 to $23
  47. ; %m1_m2 changes the "mode" : %01 -> bit, %10 -> res, %11 -> set
  48. ; %b1_b2_b3 is the byte's ID (0-7)
  49. ; the last three bytes can be used for autocopy, but not here.
  50.  
  51. #include "Axe.inc"
  52. #include "ti83plus.inc"
  53. #include "tokenhook.inc"
  54.  
  55. .dw AXM_HEADER
  56.  
  57. .dw readFlagEnd + 2 ; +2 because of the two ".org $-1"
  58. .db AXM_NOSTUB  ; shell compatibility : Noshell only
  59.                 ; (I don't know if this is compatible with any shell)
  60. .db tOneVar, $00; token : 1-Var Stats
  61. .db AXM_SUB     ; routine flags
  62. .db AXM_2ARGS   ; 2 arguments
  63.  
  64.  
  65. .org $0000
  66. readFlag:
  67.     ld a, 3
  68.     and l       ; cap the argument to 3
  69.     ret z       ; 0 isn't a legal value
  70.     or $20      ; faster than set 5, a
  71.     .db $49
  72. .org $-1    ; Axe should replace this with an absolute address
  73.     ld (rflag), a
  74.     pop hl      ; this is the return address
  75.     pop af      ; this is the argument
  76.     push hl
  77.     and %111    ; cap the argument
  78.     sll a       ; inserts a 1 as the last bit in a
  79.     sll a       ; also resets the carry
  80.     rla         ; so this instruction shifts a 0 to a MSB
  81.     or $40      ; the first LSB of a must be %01
  82.     .db $49
  83. .org $-1    ; another absolute address replacement
  84.     ld (rflag + 1), a
  85.     ld hl, 0
  86.     .db $FD , $CB; bit ??, (iy+??)
  87. rflag:
  88.     .dw 0       ; this will be replaced with the proper instruction
  89.     ret z       ; if the bit is zero, hl will stay null
  90.     inc hl      ; else increment hl, and return
  91.     ret
  92. readFlagEnd:
  93.  
  94.  
  95.  
  96. .dw writeFlagEnd + 2; +2 because of the two ".org $-1"
  97. .db AXM_NOSTUB  ; shell compatibility : Noshell only
  98.                 ; (I don't know if this is compatible with any shell)
  99. .db tTwoVar, $00; token : 2-Var Stats
  100. .db AXM_SUB     ; routine flags
  101. .db AXM_3ARGS   ; 3 arguments
  102.  
  103.  
  104. .org $0000
  105. writeFlag:
  106.     ld a, 3
  107.     and l       ; cap the argument to 3
  108.     ret z       ; 0 isn't a legal value
  109.     or $20      ; faster than set 5, a
  110.     .db $49
  111. .org $-1    ; Axe should replace this with an absolute address
  112.     ld (wflag), a
  113.     pop de      ; this is the return address
  114.     pop hl      ; do we want to set the flag ?
  115.     pop af      ; which flag do we want to set ?
  116.     push de
  117.     and %111    ; cap the argument
  118.     sll a       ; inserts a 1 as the last bit in a
  119.     sll a       ; also resets the carry
  120.     rla         ; so this instruction shifts a 0 to a MSB
  121.     bit 0, l    ; do we want to SET the flag ?
  122.     jr z, $+2   ; no ? skip the next instruction
  123.     or $40      ; switch to "set" instruction
  124.     or $80      ; switch to a writing instruction
  125.     .db $49
  126. .org $-1    ; another absolute address replacement
  127.     ld (wflag + 1), a
  128.     .db $FD, $CB; bit ??, (iy+??)
  129. wflag:
  130.     .dw 0       ; this will be replaced with the proper instruction
  131.     ret
  132. writeFlagEnd:
  133.  
  134.  
  135.  
  136. .dw storeFlagEnd + 1; +1 because of the ".org $-1"
  137. .db AXM_NOSTUB  ; shell compatibility : Noshell only
  138.                 ; (I don't know if this is compatible with any shell)
  139. .db tMedMed, $00; token : Med-Med
  140. .db AXM_INLINE  ; as this is quite light, it'll be inline
  141. .db AXM_2ARGS   ; 2 arguments
  142.  
  143.  
  144. .org $0000
  145. storeFlag:
  146.     ld a, 3
  147.     and l
  148.     jr z, storeFlagEnd
  149.     or $20
  150.     .db $49
  151. .org $-1
  152.     ld (sflag), a
  153.     pop af
  154.     .db $FD
  155.     ld (hl), a
  156. sflag:
  157.     .db 0
  158. storeFlagEnd:
  159.  
  160.  
  161.  
  162. .dw getFlagEnd + 1; +1 because of the ".org $-1"
  163. .db AXM_NOSTUB  ; shell compatibility : Noshell only
  164.                 ; (I don't know if this is compatible with any shell)
  165. .db tLR1, $00   ; token : LinReg(ax+b)
  166. .db AXM_INLINE  ; as this is quite light, it'll be inline
  167. .db AXM_1ARG    ; 1 argument
  168.  
  169. .org $0000
  170. getFlag:
  171.     ld a, 3
  172.     and l
  173.     jr z, $+10
  174.     or $20
  175.     .db $49
  176. .org $-1
  177.     ld (gflag), a
  178.     .db $FD
  179.     ld l, (hl)
  180. gflag:
  181.     .db 0
  182.     ld h, 0
  183. getFlagEnd:
  184.  
  185.  
  186.  
  187. .dw AXM_END
  188.  
  189. ; Token replacements
  190. .dw hOneVar
  191. .db 9
  192. .db "ReadFlag("
  193.  
  194. .dw hTwoVar
  195. .db 10
  196. .db "WriteFlag("
  197.  
  198. .dw hMedMed
  199. .db 10
  200. .db "StoreFlag("
  201.  
  202. .dw hLR1
  203. .db 8
  204. .db "GetFlag("
  205.  
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement