;;; -*- 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 . ;; FormatInstruction: ;; ;; Convert an instruction into an editable ASCII string. ;; ;; Input: ;; - HL -> bytecode instruction (in RAM) ;; ;; Output: ;; - edit buffer contains formatted string ;; ;; Destroys: ;; - AF, BC, DE, HL, IX ;; - OP1-OP6 FormatInstruction: push hl pop ix ld hl,FormatInstruction_Error call APP_PUSH_ERRORH call FormatInstructionMain call APP_POP_ERRORH ret FormatInstruction_Error: ld a,'?' call TextBufInsertChar call TextBufInsertChar jq_ TextBufInsertChar FormatInstructionMain: call TextBufClear ld a,(ix) inc ix ld b,a and 3Fh ld c,a inc c ld a,b and 0C0h jr z,FormatInstruction_NormalInstr cp T_LABEL jr z,FormatInstruction_Label cp T_COMMENT jq nz,FormatInstruction_SpecialInstr push ix pop hl ;; we're assuming that the text buffer is large enough ;; (worst case is 128 bytes) ld de,(editTop) ld a,Lsemicolon ld (de),a inc de ld a,' ' ld (de),a inc de call UnpackCommentString ld (editCursor),de ret FormatInstruction_NormalInstr_IYFlag: ld a,(ix) cp X_SYSFLAG jr nz,FormatInstruction_NormalInstr_NotIYFlag ld a,(ix + 2) cp X_DEC6 jr c,FormatInstruction_NormalInstr_NotIYFlag ld l,a ld h,(ix + 1) push de call SysFlagCodeToName pop de jr nz,FormatInstruction_NormalInstr_NotIYFlag call TextBufInsertSymbolString ld a,',' call TextBufInsertChar ld (formatArgPtr0),ix ld ix,templ__iIYpn + 1 jr FormatInstruction_UseTemplate FormatInstruction_Label: inc c ld a,(ix) push af call FormatExprDefault pop af cp X_NEXT_ANON call z,TextBufDeletePrevChar ld a,':' jq_ TextBufInsertChar FormatInstruction_NormalInstr: ;; insert tab and mnemonic inc ix ld l,(ix + -1) ld h,high(normalInstructionMnemonicTable) ld e,(hl) push hl call TextBufInsertNormalMnemonic pop de ld a,e cp I_BIT_n_iIYpn jr z,FormatInstruction_NormalInstr_IYFlag cp I_RES_n_iIYpn jr z,FormatInstruction_NormalInstr_IYFlag cp I_SET_n_iIYpn jr z,FormatInstruction_NormalInstr_IYFlag FormatInstruction_NormalInstr_NotIYFlag: ex de,hl dec h ; -> normalInstructionTemplateHTable ld d,(hl) dec h ; -> normalInstructionTemplateLTable ld e,(hl) inc de FormatInstruction_UseTemplateDefaultArgs: push de call GetInstructionFormatPtrs pop ix FormatInstruction_UseTemplate: ld c,(ix + -1) FormatInstruction_NormalInstrLoop: set formatTemplate,(iy + asm_Flag3) call FormatExprDefault res formatTemplate,(iy + asm_Flag3) jq c,TextBufDeletePrevChar ld a,',' call TextBufInsertChar jr nc,FormatInstruction_NormalInstrLoop ret FormatInstruction_Unknown: ;; throw error back to FormatInstruction_Error BCALL _ErrSyntax ;; UNREACHABLE FormatInstruction_SpecialInstr: ld a,(ix) inc ix push af and 7Fh dec a cp S_last jr nc,FormatInstruction_Unknown ld e,a ld d,0 ld hl,specialInstructionMnemonicTable add hl,de ld e,(hl) ld hl,specialMnemonics add hl,de call TextBufInsertMnemonic pop af SWITCH_BEGIN SWITCH_CASE S_ASCII, FormatInstruction_ASCII SWITCH_CASE S_ASCIZ, FormatInstruction_ASCIZ SWITCH_CASE S_HEX, FormatInstruction_HEX SWITCH_CASE S_INCBIN, FormatInstruction_INCBIN SWITCH_CASE S_BCALL, FormatInstruction_BCALLBJUMP SWITCH_CASE S_BJUMP, FormatInstruction_BCALLBJUMP SWITCH_CASE S_BREAK_ccc, FormatInstruction_BREAK_ccc SWITCH_CASE S_EQU, FormatInstruction_EQU SWITCH_CASE S_JQ_cc_n, FormatInstruction_JQ_cc_n SWITCH_END FormatInstruction_SpecialInstrLoop: call FormatExprDefault jq c,TextBufDeletePrevChar ld a,',' call TextBufInsertChar jr nc,FormatInstruction_SpecialInstrLoop ret FormatInstruction_BREAK_ccc: ld de,templ__ccc + 1 jr FormatInstruction_UseTemplateDefaultArgs FormatInstruction_JQ_cc_n: ld de,templ__cc_n + 1 jr FormatInstruction_UseTemplateDefaultArgs FormatInstruction_EQU: call TextBufClear call FormatExprDefault ld a,' ' call TextBufInsertChar ld a,'=' call TextBufInsertChar ld a,' ' call TextBufInsertChar jq_ FormatExprDefault FormatInstruction_BCALLBJUMP: ld a,(ix) cp X_ROMCALL jq nz,FormatExprDefault ld l,(ix+1) ld h,(ix+2) call ROMCallAddressToName jq z,TextBufInsertSymbolString ld a,'$' call TextBufInsertChar jq_ TextBufInsertHex16 FormatInstruction_ASCII: ld a,Lquote call TextBufInsertChar FormatInstruction_ASCII_Loop: dec c ld a,Lquote jq z,TextBufInsertChar ld a,(ix) inc ix call TextBufInsertQuotedChar jr FormatInstruction_ASCII_Loop FormatInstruction_ASCIZ: call FormatInstruction_ASCII ld a,',' call TextBufInsertChar ld a,'0' jq_ TextBufInsertChar FormatInstruction_HEX: ; ld hl,smnem_DB + specialMnemonics ; call TextBufInsertMnemonic FormatInstruction_HEX_Loop: dec c jq z,TextBufDeletePrevChar ld l,(ix) inc ix call TextBufInsertPrefixedHex8 ld a,',' call TextBufInsertChar jr nc,FormatInstruction_HEX_Loop ret FormatInstruction_INCBIN: ; ld hl,smnem_INCBIN + specialMnemonics ; call TextBufInsertMnemonic ld a,(ix) inc ix dec c SWITCH_BEGIN SWITCH_CASE ProgObj, FormatInstruction_INCBIN_Prog SWITCH_CASE ProtProgObj, FormatInstruction_INCBIN_Prog SWITCH_CASE TempProgObj, FormatInstruction_INCBIN_Prog SWITCH_CASE AppVarObj, FormatInstruction_INCBIN_NotToken SWITCH_CASE GroupObj, FormatInstruction_INCBIN_NotToken SWITCH_END push ix pop hl BCALL _Get_Tok_Strng ld ix,OP3 inc c FormatInstruction_INCBIN_NotToken: jr FormatInstruction_ASCII FormatInstruction_INCBIN_Prog: ld hl,quote_prgmStr call TextBufInsertString jr FormatInstruction_ASCII_Loop ;; GetInstructionFormatPtrs: ;; ;; Split up an expression list into up to 3 instruction arguments. ;; ;; Input: ;; - IX = expression pointer ;; - C = expression byte count + 1 ;; ;; Output: ;; - (formatArgPtr0) = address of first argument ;; - (formatArgPtr1) = address of second argument ;; - (formatArgPtr2) = address of third argument ;; - Carry flag set if fewer than 2 arguments present ;; ;; Destroys: ;; - AF, BC, HL GetInstructionFormatPtrs: push ix pop hl ld (formatArgPtr0),hl call SkipExprHL ld (formatArgPtr1),hl call nc,SkipExprHL ld (formatArgPtr2),hl ret