;;; -*- 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 . ;; FindAsmGlobalSymbol: ;; ;; Search for a symbol with a given name. ;; ;; Input: ;; - AHL = address of compressed symbol string (in RAM) ;; ;; Output: ;; - If a matching symbol was found, DE = debug file offset and carry ;; flag set ;; - If no matching symbol was found, HL = location in hash table ;; where link should be made, and carry flag clear ;; ;; Destroys: ;; - AF, BC, DE ;; - OP1-OP6 FindAsmGlobalSymbol: ld de,OP1 call SymbolStringToRAM FindAsmGlobalSymbolOP1: ;; get hash of string ld hl,OP1 ld c,1 FindAsmGlobalSymbol_HashLoop: ld c,a add a,a add a,a xor c xor (hl) inc hl djnz FindAsmGlobalSymbol_HashLoop ;; find corresponding bin add a,a ld l,a sbc a,a ld h,a ld bc,asmHashBins + 256 add hl,bc FindAsmGlobalSymbol_SearchLoop: ;; get next entry in this bin ld e,(hl) inc hl ld a,(hl) ld d,a add a,a ret nc ex de,hl ; HL = hash table cell ld c,(hl) inc hl ld b,(hl) ; BC = debug file offset for this symbol push hl ld hl,(debugFileStartPtr) add hl,bc push bc ld a,(hl) inc hl ld e,(hl) inc hl ld d,(hl) ; ADE = address of this symbol string ex de,hl ;; A = FFh for an alias symbol (shouldn't happen) ;; or FEh for a constant symbol cp 0FDh jr nc,FindAsmGlobalSymbol_SkipCompare ;; note: packed symbol strings can be at most 33 bytes ld de,OP4 push de call SymbolStringToRAM pop hl ld de,OP1 call CompStrsN FindAsmGlobalSymbol_SkipCompare: pop de pop hl jr nz,FindAsmGlobalSymbol_SearchLoop scf ret ;; AddAsmGlobalSymbol: ;; ;; Add a global symbol to the hash table. ;; ;; Input: ;; - BC = debug file offset ;; - HL = location where link should be made (returned by ;; FindAsmGlobalSymbol) ;; ;; Destroys: ;; - AF, DE, HL AddAsmGlobalSymbol: push bc push hl ld bc,0 BCALL _Push2BOper pop hl ld de,(OPS) dec de ld (hl),d dec hl ld (hl),e pop bc BCALL _Push2BOper ret ;; SymbolStringToRAM: ;; ;; Copy a symbol string to RAM. ;; ;; Input: ;; - AHL = address of string ;; - DE = destination buffer ;; ;; Output: ;; - DE = byte following end of destination buffer ;; - B = number of bytes in string ;; ;; Destroys: ;; - AF, BC, HL SymbolStringToRAM: ld c,0 bit 7,h jr z,SymbolStringToRAM_FromFlash SymbolStringToRAM_RAMLoop: ld a,(hl) ldi and 0Fh jr nz,SymbolStringToRAM_RAMLoop sub c ld b,a ret SymbolStringToRAM_FromFlash: RAM_CODE_BEGIN SymbolStringToRAM_end out (6),a SymbolStringToRAM_FlashLoop: ld a,(hl) ldi bit 7,h jr z,SymbolStringToRAM_NoPageFlip ld h,a in a,(6) inc a out (6),a ld a,h ld h,40h SymbolStringToRAM_NoPageFlip: and 0Fh jr nz,SymbolStringToRAM_FlashLoop sub c ld b,a ret SymbolStringToRAM_end: ;; SymbolStringsEqual: ;; ;; Check if two symbol strings are equal. ;; ;; Input: ;; - AHL = address of first string ;; - DE = address of second string ;; ;; Output: ;; - Zero flag set, and carry flag reset, if strings match ;; ;; Destroys: ;; - AF, DE, HL ; SymbolStringsEqual: ; bit 7,h ; jr z,SymbolStringsEqual_FromFlash ; SymbolStringsEqual_RAMLoop: ; ld a,(de) ; cp (hl) ; ret nz ; and 0Fh ; ret z ; inc de ; inc hl ; jr SymbolStringsEqual_RAMLoop ; SymbolStringsEqual_FromFlash: ; RAM_CODE_BEGIN SymbolStringsEqual_end ; out (6),a ; SymbolStringsEqual_FlashLoop: ; ld a,(de) ; cp (hl) ; ret nz ; and 0Fh ; ret z ; inc hl ; inc de ; bit 7,h ; jr z,SymbolStringsEqual_FlashLoop ; in a,(6) ; inc a ; out (6),a ; ld h,40h ; jr SymbolStringsEqual_FlashLoop ; SymbolStringsEqual_end: