;;; -*- TI-Asm -*- ;;; ;;; Mimas - Assembly language IDE for the TI-83 Plus ;;; ;;; Copyright (C) 2010 Benjamin Moody ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as ;;; published by the Free Software Foundation; either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see . ;; EnumValueToName: ;; ;; Get the name of a builtin constant given its value. ;; ;; Input: ;; - H = expression type ;; - L = value ;; ;; Output: ;; - Zero flag clear and HL preserved if equate is unknown ;; - Otherwise, HL = address (page 1) of a symbol string ;; ;; Destroys: ;; - AF, BC, DE P1_EnumValueToName: ld de,sysEnumByValueTable ld bc,sysEnumByValueTableSize / 2 jr P1_BuiltinAddressToName ;; SysFlagCodeToName: ;; ;; Get the name of a system flag given its address and bit number. ;; ;; Input: ;; - H = IY offset ;; - L = bit number + C0h ;; ;; Output: ;; - Zero flag clear and HL preserved if equate is unknown ;; - Otherwise, HL = address (page 1) of a symbol string ;; ;; Destroys: ;; - AF, BC, DE P1_SysFlagCodeToName: ld de,sysFlagByValueTable ld bc,sysFlagByValueTableSize / 2 jr P1_BuiltinAddressToName ;; SysAddressToName: ;; ;; Get the name of a system ROM/RAM equate given its address. ;; ;; Input: ;; - HL = system address ;; ;; Output: ;; - Zero flag clear and HL preserved if equate is unknown ;; - Otherwise, HL = address (page 1) of a symbol string ;; ;; Destroys: ;; - AF, BC, DE P1_SysAddressToName: ld de,sysAddrByValueTable ld bc,sysAddrByValueTableSize / 2 jr P1_BuiltinAddressToName ;; ROMCallAddressToName: ;; ;; Get the name of a system API routine given its address. ;; ;; Input: ;; - HL = ROM call address ;; ;; Output: ;; - Zero flag clear and HL preserved if routine is unknown ;; - Otherwise, HL = address (page 1) of a symbol string ;; ;; Destroys: ;; - AF, BC, DE P1_ROMCallAddressToName: ld de,romCallByValueTable ld bc,romCallByValueTableSize / 2 P1_BuiltinAddressToName: ld a,(curProgHeader + PROGHEADER_TYPE) cp PROGTYPE_TI83P ret nz push hl push ix ex de,hl ld ix,P1_Compare_ppI16_I16 call P1_BSearch2 ld e,(hl) inc hl ld d,(hl) pop ix pop hl ret nz ex de,hl inc hl inc hl ret P1_Compare_ppI16_I16: ld a,(hl) inc hl ld h,(hl) ld l,a inc hl ld a,(hl) cp d ret nz dec hl ld a,(hl) cp e ret ;; BuiltinNameToSymbol: ;; ;; Convert a string into a builtin constant. ;; ;; Input: ;; - HL = address of a zero-terminated string ;; ;; Output: ;; - If a recognized builtin symbol, zero flag set ;; - If a system flag name (3-bit value), B = 1 and H = value ;; - If a system enumeration (8-bit value), B = 2, H = ;; expression type, and L = value ;; - If a system address (16-bit value), B = 3, H = expression type, ;; L = LSB of value, and C = MSB of value ;; - If symbol is not recognized, then zero flag clear and HL ;; preserved ;; ;; Destroys: ;; - AF, BC, DE P1_BuiltinNameToSymbol: ;; Check if string matches a ROM call name ld a,(hl) cp '_' jr nz,P1_BuiltinNameToSymbol_NotROMCall inc hl call P1_ROMCallNameToAddress ld a,X_ROMCALL jr z,P1_BuiltinNameToSymbol_Enum16 dec hl P1_BuiltinNameToSymbol_NotROMCall: call P1_SysNameToAddress ld a,X_SYSADDR jr z,P1_BuiltinNameToSymbol_Enum16 call P1_EnumNameToValue ld b,2 ret z call P1_SysFlagNameToCode ret nz ld b,1 ld h,l ret P1_BuiltinNameToSymbol_Enum16: ld c,h ld h,a ld b,3 ret ;; EnumNameToValue: ;; ;; Get the expression-type and value of a builtin constant given its ;; name. ;; ;; Input: ;; - HL = address of a zero-terminated string ;; ;; Output: ;; - Zero flag clear and HL preserved if equate is unknown ;; - Otherwise, H = expression type and L = value ;; ;; Destroys: ;; - AF, BC, DE, HL ;; - [OP1-OP3 or so] P1_EnumNameToValue: ld de,sysEnumNames ld bc,sysEnumNamesEnd jr P1_BuiltinNameToAddress ;; SysFlagNameToCode: ;; ;; Get the address of a system flag given its name. ;; ;; Input: ;; - HL = address of a zero-terminated string ;; ;; Output: ;; - Zero flag clear and HL preserved if equate is unknown ;; - Otherwise, H = IY offset and L = bit number + C0h ;; ;; Destroys: ;; - AF, BC, DE, HL ;; - [OP1-OP3 or so] P1_SysFlagNameToCode: ld de,sysFlagNames ld bc,sysFlagNamesEnd jr P1_BuiltinNameToAddress ;; SysNameToAddress: ;; ;; Get the address of a system ROM/RAM equate given its name. ;; ;; Input: ;; - HL = address of a zero-terminated string ;; ;; Output: ;; - Zero flag clear and HL preserved if equate is unknown ;; - Otherwise, HL = system address ;; ;; Destroys: ;; - AF, BC, DE, HL ;; - [OP1-OP3 or so] P1_SysNameToAddress: ld de,sysAddrNames ld bc,sysAddrNamesEnd jr P1_BuiltinNameToAddress ;; ROMCallNameToAddress: ;; ;; Get the address of a system API routine given its name. ;; ;; Input: ;; - HL = address of a zero-terminated string ;; ;; Output: ;; - Zero flag clear and HL preserved if routine is unknown ;; - Otherwise, HL = ROM call address ;; ;; Destroys: ;; - AF, BC, DE, HL ;; - [OP1-OP3 or so] P1_ROMCallNameToAddress: ld de,romCallNames ld bc,romCallNamesEnd P1_BuiltinNameToAddress: ld a,(curProgHeader + PROGHEADER_TYPE) cp PROGTYPE_TI83P ret nz push hl push ix ex de,hl ld ix,P1_SeekCompare_pI16SStr_pZStr call P1_BSearchS ex de,hl pop ix pop hl ret nz ld a,(de) ld l,a inc de ld a,(de) ld h,a ret P1_SeekCompare_pI16SStr_pZStr: ;; seek backwards to find previous byte with low nibble clear dec hl ld a,(hl) and 0Fh jr nz,P1_SeekCompare_pI16SStr_pZStr ;; check if either of the two bytes preceding has low nibble ;; clear (in case we found a value byte rather than the actual ;; end of a symbol) dec hl dec hl P1_SeekCompare_pI16SStr_pZStr_SeekLoop: ld a,(hl) inc hl and 0Fh jr nz,P1_SeekCompare_pI16SStr_pZStr_SeekLoop push hl push de inc hl inc hl call P1_CompareToSymbolString pop de pop hl ret z ccf ret nc inc hl inc hl P1_SeekCompare_pI16SStr_pZStr_Next: ld a,(hl) inc hl and 0Fh jr nz,P1_SeekCompare_pI16SStr_pZStr_Next sub 1 ret