;;; -*- 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 . ;; ShowDialogScreen: ;; ;; Display a full-screen dialog, allowing the user to alter various ;; settings. The values to be edited must be located in static RAM, ;; and must have been initialized by the caller (D_OPTION fields must ;; be set to a value less than the number of options; D_TEXT fields ;; must contain a zero-terminated string.) ;; ;; The dialog structure is a sequence of 7-byte entries representing ;; fields to be edited. ;; - The first byte is the field type (D_END, D_OPTION, or D_TEXT.) ;; - The next two bytes are the address of a packed GUI string to be ;; used as a label. ;; - The next two bytes are the address, in static RAM, where the ;; value to be edited is stored. For D_OPTION fields, this is a ;; single unsigned byte. For D_TEXT fields, this must be a buffer ;; large enough to hold the longest permitted string plus a zero ;; terminator. ;; - The final two bytes provide additional information about the ;; field. In the case of D_OPTION fields, these bytes contain a ;; pointer to the option list (one byte giving the maximum allowed ;; value for the field, followed by a series of packed GUI strings ;; giving the corresponding text labels.) In the case of D_TEXT ;; fields, the final two bytes contain editing flags (0: ;; editVarName, 3: lwrCaseActive, 4-7: shiftFlags) and the maximum ;; length of the string (i.e., 1 less than the size of the buffer.) ;; ;; Input: ;; - HL = address of compressed title string ;; - DE = address of dialog structure ;; ;; Output: ;; - Carry flag set if user cancelled dialog (by pressing Clear, ;; 2nd+Quit, or F1.) ;; ;; Destroys: ;; - AF, BC, DE, HL ;; - OP1-OP6 ;; - penRow, penCol ;; - Text edit buffer ;; - Contents of LCD, plotSScreen, and saveSScreen ShowDialogScreen: ld (dialogTitle),hl ld h,d ld l,e ld a,SCREEN_WIDTH - 1 ld (textEditXEnd),a res appWantAlphaUpDn,(iy + alphaUpDnFlag) ShowDialogScreen_ChangeField: ;; DE -> start of dialog ;; HL -> current field BCALL _CanAlphIns ShowDialogScreen_Redisplay: push de ; start of dialog push hl ; current field call RedisplayDialogScreen ShowDialogScreen_KeyLoop: pop hl push hl ld a,(hl) dec a jr z,ShowDialogScreen_EditOptionMenu ld a,(OP6 + 10) ld (penRow),a call EditTextLineStart call TextBufToZTStr ShowDialogScreen_CommonKeys: pop hl pop de ld bc,7 SWITCH_BEGIN SWITCH_CASE kUp, ShowDialogScreen_Up SWITCH_CASE kDown, ShowDialogScreen_Down SWITCH_CASE kEnter, ShowDialogScreen_Next SWITCH_CASE kClear, ShowDialogScreen_Cancel SWITCH_CASE kQuit, ShowDialogScreen_Cancel SWITCH_CASE kYequ, ShowDialogScreen_Cancel SWITCH_CASE kGraph, ShowDialogScreen_Finished SWITCH_END ShowDialogScreen_NoRedisplay: push de push hl jr ShowDialogScreen_KeyLoop ShowDialogScreen_EditOptionMenu: call XBufCpy call GetKey pop hl push hl inc hl inc hl inc hl ld e,(hl) inc hl ld d,(hl) ; DE = address of value to edit inc hl ld b,(hl) inc hl ld h,(hl) ld l,b ; HL = address of option list cp kLeft jr z,ShowDialogScreen_EditOptionMenuDec cp kRight jr nz,ShowDialogScreen_CommonKeys ld a,(de) cp (hl) inc a jr c,ShowDialogScreen_EditOptionMenuSet xor a ShowDialogScreen_EditOptionMenuSet: ld (de),a pop hl pop de jr ShowDialogScreen_Redisplay ShowDialogScreen_EditOptionMenuDec: ld a,(de) sub 1 jr nc,ShowDialogScreen_EditOptionMenuSet ld a,(hl) jr ShowDialogScreen_EditOptionMenuSet ShowDialogScreen_Cancel: scf ShowDialogScreen_Finished: jq_ CanAlphIns ShowDialogScreen_Down: add hl,bc ld a,(hl) or a jr nz,ShowDialogScreen_ChangeField ShowDialogScreen_Up: sbc hl,de add hl,de jr z,ShowDialogScreen_NoRedisplay ShowDialogScreen_UpOK: sbc hl,bc jr ShowDialogScreen_ChangeField ShowDialogScreen_Next: add hl,bc ld a,(hl) or a ret z jr ShowDialogScreen_ChangeField ;; RedisplayDialogScreen: ;; ;; Display a dialog screen, highlighting the selected field (if an ;; option menu) or setting up the text editor (if a text entry field.) ;; ;; Input: ;; - DE = start of dialog ;; - HL = currently selected field ;; ;; Output: ;; - If a text entry field is selected, (textBufferTop), ;; (textBufferBtm), (textBufferCursor), (textBufferTail), and ;; (textEditXStart) are initialized, the shift flags are set ;; appropriately, and (OP6 + 10) = pen row for text editor ;; ;; Destroys: ;; - AF, BC, DE, HL RedisplayDialogScreen: push hl push de call DialogInit pop hl ld a,1 ld (penRow),a RedisplayDialogScreen_Loop: ld bc,penCol xor a ld (bc),a inc bc ld a,(bc) add a,8 ld (bc),a pop de ;; HL = field to display ;; DE = currently selected field ld a,(hl) or a ret z ;; check if this field is selected sbc hl,de add hl,de push de push af ;; display the field's label inc hl ld e,(hl) inc hl ld d,(hl) inc hl push hl ex de,hl call DisplayGUIString pop hl pop af push af dec a jr nz,RedisplayDialogScreen_TextEntry RedisplayDialogScreen_OptionMenu: ;; set textInverse if field is selected pop af jr nz,RedisplayDialogScreen_InactiveOptionMenu set textInverse,(iy + textFlags) RedisplayDialogScreen_InactiveOptionMenu: ld c,(hl) inc hl ld b,(hl) ; BC = address of value to be edited inc hl ld e,(hl) inc hl ld d,(hl) ; DE = address of option list inc hl push hl ;; display left arrow ld hl,dialogOptionArrowStr call BufVPutS push hl ld a,(bc) inc de call DisplayNthGUIString pop hl ;; display right arrow call BufVPutS pop hl res textInverse,(iy + textFlags) jr RedisplayDialogScreen_Loop RedisplayDialogScreen_TextEntry: ;; Text field: HL -> (word) address of buffer, (byte) editing ;; flags, and (byte) buffer length ld e,(hl) inc hl ld d,(hl) inc hl pop af jr z,RedisplayDialogScreen_SelectedTextEntry RedisplayDialogScreen_InactiveText: ;; move forward 4 pixels (to make text appear in the same ;; place it would if the field were being edited) ld a,SFourSpaces call BufVPutMapSave inc hl inc hl ex de,hl call BufVPutS ex de,hl RedisplayDialogScreen_Loop_: jr RedisplayDialogScreen_Loop RedisplayDialogScreen_SelectedTextEntry: ;; don't display anything now; simply set up text edit ;; configuration, for later, and save current cursor row in ;; OP6+10 ld a,(penCol) inc a ld (textEditXStart),a ld a,(penRow) ld (OP6 + 10),a ld (editTop),de ;; bit 0: editVarName flag (disallow all chars other than ;; 0-9, A-Z, theta) ld a,(hl) and 1 ld (flags + asm_Flag3),a ;; bit 3: lwrCaseActive flag (allow lowercase letters) ;; (don't want to disturb any other bits in this flag byte) ld bc,flags + appLwrCaseFlag ld a,(bc) xor (hl) and 0F7h xor (hl) ld (bc),a ;; bits 4-7: shift flags (alpha, alpha-lock, etc.; the only ;; other flags on this byte are indic flags, which should ;; all be cleared anyway) ld a,(hl) and 0F0h ld (flags + shiftFlags),a inc hl push hl ld l,(hl) xor a ld h,a ; HL = BC = maximum string length add hl,de ; HL = last allowed character in buffer ld (editBtm),hl ld (editTail),hl ;; search for zero terminator ex de,hl ld b,a ld c,a cpir ; HL -> byte after zero terminator dec hl ld (editCursor),hl pop hl inc hl jr RedisplayDialogScreen_Loop_ ;; DisplayNthGUIString: ;; ;; Display one in a series of compressed GUI strings. ;; ;; Input: ;; - DE = address of first string ;; - A = index of string to display ;; ;; Destroys: ;; - AF, B, DE, HL DisplayNthGUIString: ld b,a inc b DisplayNthGUIString_Loop: ex de,hl call UnpackGUIString djnz DisplayNthGUIString_Loop jq_ BufVPutS