;;; -*- 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 . ;; EditProgramSections: ;; ;; Display a full-screen dialog, allowing the user to edit the current ;; program sections. This routine does not return. ;; ;; Input: ;; - curProgFileName = name of program to edit EditProgramSections_Error: ;; if an error occurs in archiving, OS will redisplay ;; textShadow before handing control back to us push af call XBufCpy pop af call ShowErrorPopup EditProgramSections: ;; if current program is invalid, throw error back to the main menu ld hl,curProgFileName rst rMOV9TOOP1 EditProgramSectionsOP1: call LoadProgram ld hl,EditProgramSections_Error call APP_PUSH_ERRORH EditProgramSections_Restart: BCALL _CanAlphIns ld hl,(curProgHeader + PROGHEADER_SECTION_TABLE_START) ld d,h ld e,l EditProgramSections_Loop: VERTICAL_MENU_ALPHA 10, 6, 1, 92, SectionMenuInit, SectionMenuShow, SectionMenuNext, SectionMenuPrev, Invert7Rows, Invert7Rows ld (sectionMenuStart),de ld (sectionMenuCurrent),hl SWITCH_BEGIN SWITCH_CASE kEnter, EditProgramSections_InsOrEdit SWITCH_CASE kClear, EditProgramSections_Quit SWITCH_CASE kDel, EditProgramSections_Delete SWITCH_CASE kIns, EditProgramSections_Insert SWITCH_CASE kQuit, EditProgramSections_Quit SWITCH_CASE kYequ, EditProgramSections_InsOrEdit SWITCH_CASE kWindow, EditProgramSections_Insert SWITCH_CASE kZoom, EditProgramSections_Delete SWITCH_CASE kGraph, EditProgramSections_PopupMenu SWITCH_END EditProgramSections_Continue: ld de,(sectionMenuStart) ld hl,(sectionMenuCurrent) jr EditProgramSections_Loop EditProgramSections_Delete: ;; check that cursor is pointing to an actual section, not ;; the "New Section" item at end of list call LoadSectionAtOffset jr c,EditProgramSections_Continue ;; check that section is empty (can't delete a non-empty ;; section) ld hl,(curSectionHeader + SECTHEADER_DATA_START) ld de,(curSectionHeader + SECTHEADER_DATA_END) or a sbc hl,de ld hl,emsg_SectionNotEmpty call nz,ThrowGeneralError ld hl,(sectionMenuCurrent) ld bc,-SECTHEADER_LENGTH call InsDelProgramSectionMem jr EditProgramSections_Continue EditProgramSections_InsOrEdit: call LoadSectionAtOffset jr c,EditProgramSections_Insert call APP_POP_ERRORH ld hl,(curSectionHeader + SECTHEADER_DATA_START) ld (editStartOffset),hl ld (editLineOffset),hl jq_ EditSectionAsm EditProgramSections_Insert: xor a ld (newSectionHeader + SECTHEADER_NAME),a inc a ld (newSectionHeader + SECTHEADER_SECTION_TYPE),a ld hl,newSectionLabel ld de,insertSectionDlgInfo call ShowDialogScreen jr c,EditProgramSections_Continue ld hl,(sectionMenuCurrent) call LoadSectionAtOffset ld hl,(curProgHeader + PROGHEADER_CODE_END) jr c,EditProgramSections_InsertAtEnd ld hl,(curSectionHeader + SECTHEADER_DATA_START) EditProgramSections_InsertAtEnd: ld (newSectionHeader + SECTHEADER_DATA_START),hl ld (newSectionHeader + SECTHEADER_DATA_END),hl ld bc,SECTHEADER_LENGTH ld hl,(sectionMenuCurrent) call InsDelProgramSectionMem ld hl,newSectionHeader ldir EditProgramSections_Continue_: jr EditProgramSections_Continue EditProgramSections_PopupMenu: SWITCH_NUMBERED_MENU sectionEditMenuInfo SWITCH_CASE 1, SectionEditMenu_Imports SWITCH_CASE 2, SectionEditMenu_CompileProgram SWITCH_CASE 3, SectionEditMenu_ArchiveProgram SWITCH_CASE 4, SectionEditMenu_MainMenu SWITCH_CASE 5, SectionEditMenu_QuitToTIOS SWITCH_END jr EditProgramSections_Continue_ SectionEditMenu_Imports: call EditProgramImports jq_ EditProgramSections_Restart SectionEditMenu_MainMenu: EditProgramSections_Quit: call APP_POP_ERRORH jq_ MainMenu SectionEditMenu_QuitToTIOS: BCALL _JForceCmdNoChar ;; UNREACHABLE SectionEditMenu_ArchiveProgram: call ArchiveProgram ld hl,programArchivedMsg call ShowSuccessPopupMessage jr EditProgramSections_Continue_ SectionEditMenu_CompileProgram: call APP_POP_ERRORH ld hl,curProgFileName BCALL _PushReal ld hl,SectionEditCompileProgram_Error call APP_PUSH_ERRORH call CompileProgramDlg call APP_POP_ERRORH xor a SectionEditCompileProgram_Error: push af BCALL _RunIndicOff ld hl,debugFileName call DelVarIfExists pop af cp E_AppErr1 | 80h jr z,EditProgramSections_GoToError or a call nz,ShowErrorPopup BCALL _PopRealO1 jq_ EditProgramSectionsOP1 EditProgramSections_GoToError: BCALL _PopRealO1 ;; If a line error occurred, the program and section ;; containing the error are already loaded, and ;; (asmLineOffset) is the offset to the error. push af ld hl,(asmLineOffset) ; ld (editStartOffset),hl push hl ld b,3 EditProgramSections_GoToError_BackUpLoop: ex de,hl ld hl,(curSectionHeader + SECTHEADER_DATA_START) call PrevProgramInstr djnz EditProgramSections_GoToError_BackUpLoop ld (editStartOffset),hl dec hl ; cheat so DisplayAsmEditor displays ; everything ld (editLineOffset),hl call DisplayAsmEditor call XBufCpy pop hl ld (editLineOffset),hl pop af call ShowErrorPopup jq_ EditSectionAsm SectionMenuInit: call ClearBufferSetGraph ld a,1 ld (penCol),a ld hl,sectionEditLabel call DisplayGUIString ld hl,curProgFileName + 1 call BufVPutS8 ld a,(curProgStartPage) or a ld a,90 call nz,BufVPutStarAtColumn ld hl,sectionEditSoftKeys jq_ DisplaySoftKeysAndTitlebar SectionMenuShow: call LoadSectionAtOffset ld hl,sectionEditEmptyLabel jq c,DisplayGUIString ld hl,curSectionHeader + SECTHEADER_NAME call BufVPutS8 ld a,60 ld (penCol),a ld a,'(' call BufVPutMap ld a,(curSectionHeader + SECTHEADER_SECTION_TYPE) and 3 ld de,sectionTypeOptions + 1 call DisplayNthGUIString ld a,')' jq_ BufVPutMap SectionMenuNext: ;; note: this intentionally considers the end of the section ;; table a valid offset - it corresponds to the "New Section" ;; entry at the bottom of the menu ld de,(curProgHeader + PROGHEADER_SECTION_TABLE_END) or a sbc hl,de ccf ret c add hl,de ld de,SECTHEADER_LENGTH add hl,de ret SectionMenuPrev: ld de,-SECTHEADER_LENGTH add hl,de ld de,(curProgHeader + PROGHEADER_SECTION_TABLE_START) or a sbc hl,de add hl,de ret