Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ######################## ;
- ; # # ;
- ; # Flagged! Axiom # ;
- ; # # ;
- ; ######################## ;
- ; ReadFlag( : See in Stat -> Calc -> 1st option
- ; Reads from flag [arg1] from group [arg2]
- ; arg1 ranges from 0 to 7
- ; arg2 ranges from 1 to 3 (0 will return arg2)
- ; Size : 34 bytes if used at least once, plus 10 bytes each use
- ; WriteFlag( : See in Stat -> Calc -> 2nd option
- ; Writes [arg2] to flag [arg1] from group [arg3]
- ; arg1 ranges from 0 to 7
- ; arg2 is 0 or 1
- ; arg3 ranges from 1 to 3 (0 will return arg2)
- ; Size : 35 bytes if used at least once, plus 14 bytes each use
- ; StoreFlags( : See in Stat -> Calc -> 3rd option
- ; Writes [arg1] to group [arg2]
- ; arg1 ranges from 0 to 7
- ; arg2 ranges from 1 to 3 (0 will return arg2)
- ; Size : 14 bytes each use
- ; GetFlags( : See in Stat -> Calc -> 4th option
- ; Stores group [arg1] to hl
- ; arg1 ranges from 1 to 3 (0 will return arg1)
- ; Size : 15 bytes each use
- ; This Axiom allows to write / read flags (just like assembly) in Axe.
- ; This Axiom uses code self-writing, that's why it isn't compatible with Application compiling
- ; Structure of a bit instruction (4 bytes) :
- ; +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
- ; | 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 |
- ; +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
- ; | 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 |
- ; +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
- ; compressed denomination : $FD , $CB , iy offset ($20, $21, $22) , %m1_m2_b1_b2_b3_1_1_0
- ; iy offset will here range from $21 to $23
- ; %m1_m2 changes the "mode" : %01 -> bit, %10 -> res, %11 -> set
- ; %b1_b2_b3 is the byte's ID (0-7)
- ; the last three bytes can be used for autocopy, but not here.
- #include "Axe.inc"
- #include "ti83plus.inc"
- #include "tokenhook.inc"
- .dw AXM_HEADER
- .dw readFlagEnd + 2 ; +2 because of the two ".org $-1"
- .db AXM_NOSTUB ; shell compatibility : Noshell only
- ; (I don't know if this is compatible with any shell)
- .db tOneVar, $00; token : 1-Var Stats
- .db AXM_SUB ; routine flags
- .db AXM_2ARGS ; 2 arguments
- .org $0000
- readFlag:
- ld a, 3
- and l ; cap the argument to 3
- ret z ; 0 isn't a legal value
- or $20 ; faster than set 5, a
- .db $49
- .org $-1 ; Axe should replace this with an absolute address
- ld (rflag), a
- pop hl ; this is the return address
- pop af ; this is the argument
- push hl
- and %111 ; cap the argument
- sll a ; inserts a 1 as the last bit in a
- sll a ; also resets the carry
- rla ; so this instruction shifts a 0 to a MSB
- or $40 ; the first LSB of a must be %01
- .db $49
- .org $-1 ; another absolute address replacement
- ld (rflag + 1), a
- ld hl, 0
- .db $FD , $CB; bit ??, (iy+??)
- rflag:
- .dw 0 ; this will be replaced with the proper instruction
- ret z ; if the bit is zero, hl will stay null
- inc hl ; else increment hl, and return
- ret
- readFlagEnd:
- .dw writeFlagEnd + 2; +2 because of the two ".org $-1"
- .db AXM_NOSTUB ; shell compatibility : Noshell only
- ; (I don't know if this is compatible with any shell)
- .db tTwoVar, $00; token : 2-Var Stats
- .db AXM_SUB ; routine flags
- .db AXM_3ARGS ; 3 arguments
- .org $0000
- writeFlag:
- ld a, 3
- and l ; cap the argument to 3
- ret z ; 0 isn't a legal value
- or $20 ; faster than set 5, a
- .db $49
- .org $-1 ; Axe should replace this with an absolute address
- ld (wflag), a
- pop de ; this is the return address
- pop hl ; do we want to set the flag ?
- pop af ; which flag do we want to set ?
- push de
- and %111 ; cap the argument
- sll a ; inserts a 1 as the last bit in a
- sll a ; also resets the carry
- rla ; so this instruction shifts a 0 to a MSB
- bit 0, l ; do we want to SET the flag ?
- jr z, $+2 ; no ? skip the next instruction
- or $40 ; switch to "set" instruction
- or $80 ; switch to a writing instruction
- .db $49
- .org $-1 ; another absolute address replacement
- ld (wflag + 1), a
- .db $FD, $CB; bit ??, (iy+??)
- wflag:
- .dw 0 ; this will be replaced with the proper instruction
- ret
- writeFlagEnd:
- .dw storeFlagEnd + 1; +1 because of the ".org $-1"
- .db AXM_NOSTUB ; shell compatibility : Noshell only
- ; (I don't know if this is compatible with any shell)
- .db tMedMed, $00; token : Med-Med
- .db AXM_INLINE ; as this is quite light, it'll be inline
- .db AXM_2ARGS ; 2 arguments
- .org $0000
- storeFlag:
- ld a, 3
- and l
- jr z, storeFlagEnd
- or $20
- .db $49
- .org $-1
- ld (sflag), a
- pop af
- .db $FD
- ld (hl), a
- sflag:
- .db 0
- storeFlagEnd:
- .dw getFlagEnd + 1; +1 because of the ".org $-1"
- .db AXM_NOSTUB ; shell compatibility : Noshell only
- ; (I don't know if this is compatible with any shell)
- .db tLR1, $00 ; token : LinReg(ax+b)
- .db AXM_INLINE ; as this is quite light, it'll be inline
- .db AXM_1ARG ; 1 argument
- .org $0000
- getFlag:
- ld a, 3
- and l
- jr z, $+10
- or $20
- .db $49
- .org $-1
- ld (gflag), a
- .db $FD
- ld l, (hl)
- gflag:
- .db 0
- ld h, 0
- getFlagEnd:
- .dw AXM_END
- ; Token replacements
- .dw hOneVar
- .db 9
- .db "ReadFlag("
- .dw hTwoVar
- .db 10
- .db "WriteFlag("
- .dw hMedMed
- .db 10
- .db "StoreFlag("
- .dw hLR1
- .db 8
- .db "GetFlag("
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement