Hello everyone, accurate name here Razz !
First question:
How do I color text and its background?
Because I am still a noob, could you provide an example with some basic context?
Thanks in advance!
You can take a look at textBGColor and textFGColor Smile
You can also take a look here, which shows how to change the forground color.
I believe you have a ti-84 + CSE, which means you can use the DCSE libs. There is a celtic command to do that which is det(12,...). Documentation about this can be found in the DCSE 8 SDK.
Hello again, and thanks for the previous replies!
Question two:
The following code works as it should, except that the cursor leaves "residue." When moving the cursor down, I see a part that was not erased. I cannot figure out what is preventing curErase from clearing it, and it is starting to get a bit of a nuisance.

Code:

; Program Name:
; Author(s):
; Description:

.nolist
#include "ti84pcse.inc"
#define PutMapFlags $4a
#define PutMapUseColor 4
.list
.db tExtTok,tAsm84CCmp
.org userMem
menuStart:                       ;Start of menu routine
   
    bcall(_maybe_ClrLCDFull)        ;Display the Header
   
    ld b,1                     ;Which group is being displayed
     
dispMenu:                     ;display the menu
   
    ld c,1                     ;Which item is highlighted
    push bc
   
    ld hl,txtHeader               ;display the header
    call dispHeader
   
    ld a,b
   
    cp 1
    jr nz,dispMenu2
   
    ld b,3
    ld hl,txtItem1_1               ;Display Items in GA
    call dispItems
   
    jr dispMenu4
   
dispMenu2:
   
    cp 2
    jr nz,dispMenu3
   
    ld b,3
    ld hl,txtItem2_1            ;Display Items in GB
    call dispItems
    jr dispMenu4
   
dispMenu3:
   
    ld b,3
    ld hl,txtItem3_1            ;Display Items in GC
    call dispItems
   
dispMenu4:                     ;Since every group has a quit, display it here
    bcall(_NewLine)
    ld hl,txtItemQuit
    bcall(_PutS)
   
    pop bc
   
menuLoop:                       ;Scan key loop to get user input
      
    call curDraw
    push bc                        ;save BC for later
   
    bcall(_GetKey)
   
    pop bc                        ;we'll need this for some routines with the new                                            keypresses
    cp kleft
    jr z,mLeft
   
    cp kright
    jr z,mRight
   
    cp kup
    jr z, mUp
   
    cp kdown
    jr z, mDown
   
    cp kenter
    jr z, selection
   
    cp k1                        ;If user pressed 1, do action 1
    jr z,item1
   
    cp k2                        ;If user pressed 2, do action 2
    jr z,item2
   
    cp k3                        ;If user pressed 3, do action 3
    jp z,item3
   
    cp k4                        ;If user pressed 4, quit
    jp z,quit
   
    jr menuLoop                    ;Else, invalid input. Wait for user to input new key
   
mUp:
   
    call curErase                  ;erase the cursor
   
    ld a,c                         ;check if the cursor is out of bounds
    cp 1
    jr z,menuLoop
   
    dec c                        ;if not, decrease and return
    jr menuLoop
   
mDown:
   
    call curErase                  ;erase the cursor
   
    ld a,c                         ;check if the cursor is out of bounds
    cp 4
    jr z,menuLoop
   
    inc c                         ;if not, increase and return
    jr menuLoop
   
mRight:                        ;change group
   
    ld a,b                     ;check if already as far right as possible
    cp 3
    jr z,menuLoop
   
    inc b
   
    jp dispMenu
   
mLeft:                        ;change group
   
    ld a,b                     ;check if already as far right as possible
    cp 1
    jr z,menuLoop
   
    dec b
   
    jp dispMenu                  
   
selection:
   
    ld a,c
   
    cp 1
    jr z,item1                     
   
    cp 2
    jr z,item2                  
   
    cp 3
    jr z,item3
   
    jp quit
   
item1:                           ;Action 1
   
    push bc
    bcall(_maybe_ClrLCDFull)
    pop bc
   
    ld de,0
    ld (curRow),de               
   
    ld a,b
    cp 1
    jr nz,item1B
   
    ld hl,txtSelect1_1            ;action 1 for group A
   
    jr item1Done
item1B:
    cp 2
    jr nz,item1C
   
    ld hl,txtSelect2_1            ;action 1 for group B
   
    jr item1Done
   
item1C:
   
    ld hl,txtSelect3_1            ;action 1 for group C
   
item1Done:
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
    bcall(_PutS)               ;we'll display the text now
   
    bcall(_GetKey)
   
    jp menuStart
   
item2:                           ;Action 2
   
    push bc
    bcall(_maybe_ClrLCDFull)
    pop bc
   
    ld de,0
    ld (curRow),de
   
    ld a,b
    cp 1
    jr nz,item2B
   
    ld hl,txtSelect1_2            ;action 2 for group A
   
    jr item2Done
item2B:
    cp 2
    jr nz,item2C
   
    ld hl,txtSelect2_2            ;action 2 for group B
   
    jr item2Done
   
item2C:
   
    ld hl,txtSelect3_2            ;action 2 for group C
   
item2Done:

   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
    bcall(_PutS)
   
    bcall(_GetKey)
   
    jp menuStart
   
item3:                           ;Action 3
   
    push bc
    bcall(_maybe_ClrLCDFull)
    pop bc
   
    ld de,0
    ld (curRow),de
   
    ld a,b
    cp 1
    jr nz,item3B
   
    ld hl,txtSelect1_3            ;action 3 for group A
   
    jr item2Done
item3B:
    cp 2
    jr nz,item3C
   
    ld hl,txtSelect2_3            ;action 3 for group B
   
    jr item1Done
   
item3C:
   
    ld hl,txtSelect3_3            ;action 3 for group C
   
item3Done:

   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
    bcall(_PutS)
   
    bcall(_GetKey)
   
    jp menuStart
   
quit:                           ;quit the program
   
    bcall(_maybe_ClrLCDFull)
   
    ret
   
   ;dispHeader
   ;
   ;displays the header centered and at the top
   ;
   ;Inputs: HL points to null-terminating string
   ;
   ;Output: text displayed, with the current group in inverse text
   ;
   ;Destroyed: a,de,hl
   ;
   ;Note: text string must be large text and take up the full line
   ;(use blank spaces to fill in gaps)
   ;
   
dispHeader:                         ;displays the header centered and at the top
   
    ld de,0
    ld (curRow),de
   
    ld a,b
    cp 1
    jr nz,dispHeader1
    set textInverse,(IY+TextFlags)
   
dispHeader1:                  ;group A
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
    res textInverse,(IY+TextFlags)
   
   push af
   
    ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
   
    cp 2
    jr nz,dispHeader2
    set textInverse,(IY+TextFlags)
   
dispHeader2:                  ;group B
   
   push af
   
    ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
    res textInverse,(IY+TextFlags)
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
   
    cp 3
    jr nz,dispHeader3
   
    set textInverse,(IY+TextFlags)
   
dispHeader3:                  ;group C
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
    res textInverse,(IY+TextFlags)
   
    ld hl,0
    ld (curRow),hl
   
    ret
   
   ;dispItems
   ;
   ;displays menu items at the start of the next line
   ;
   ;Inputs: HL points to null-terminating string
   ;
   ;Output: text displayed
   ;
   ;Destroyed: all
   ;
   
dispItems:                         ;displays menu items at the start of the next line
   
    push bc
    push hl
    bcall(_NewLine)
    pop hl
    pop bc
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
   
    djnz dispItems               
   
    ret
   
   ;curDraw
   ;
   ;Draws the cursor
   ;
   ;Inputs: C holds the highlighted item
   ;
   ;Outputs: Cursor displayed      
   ;
   ;Destroyed: A
   ;
   
curDraw:
    set textInverse,(IY+TextFlags)  ;set inverse text
   
   push af
   
   ld a,5
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    xor a
    ld (curCol),a
    ld a,c
    ld (curRow),a
   
    add a,$30                      ;Character offset
   
    bcall(_PutC)
   
    ld a,':'
    bcall(_PutC)
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    res textInverse,(IY+TextFlags)
    ret
   
   ;curErase
   ;
   ;Erase the cursor
   ;
   ;Inputs: C highlighted item
   ;
   ;Ouputs: Cursor erased
   ;
   ;Destroyed: A
   ;
   
curErase:
    xor a
    ld (curCol),a
    ld a,c
    ld (curRow),a
   
    add a,$30                      ;Character offset
   
    bcall(_PutC)
   
    ld a,':'
    bcall(_PutC)
   
    ret
   
   ;========================================
   ;data
   ;========================================
   
txtHeader:
    .db "GA",0
    .db "     ",0               ;space x 5
    .db "GB",0
    .db "     ",0
    .db "GC",0
   
txtItem1_1:
    .db "1:A1",0
   
txtItem1_2:
    .db "2:A2",0
   
txtItem1_3:
    .db "3:A3",0
   
txtItem2_1:
    .db "1:B1",0
   
txtItem2_2:
    .db "2:B2",0
   
txtItem2_3:
    .db "3:B3",0
   
txtItem3_1:
    .db "1:C1",0
   
txtItem3_2:
    .db "2:C2",0
   
txtItem3_3:
    .db "3:C3",0
   
txtSelect1_1:
    .db "You selected A1",0
   
txtSelect1_2:
    .db "You selected A2",0
   
txtSelect1_3:
    .db "You selected A3",0
   
txtSelect2_1:
    .db "You selected B1",0
   
txtSelect2_2:
    .db "You selected B2",0
   
txtSelect2_3:
    .db "You selected B3",0
   
txtSelect3_1:
    .db "You selected C1",0
   
txtSelect3_2:
    .db "You selected C2",0
   
txtSelect3_3:
   .db "You selected C3",0
   
txtItemQuit:
   .db "4:Quit",0
   ret
.end
.end
Because you don't erase the cursor, you just display the number+colon again Wink
So does that mean that the cursor is larger than the text?
In that case, I'll try to move the text slightly left...
No, curDraw and curErase are basically the same, if I look right.
Got the erase to work by doing a 4D44h bcall (ClearRect, too lazy to look for name in the .inc). For reference:

Code:

; Program Name:
; Author(s):
; Description:

.nolist
#include "ti84pcse.inc"
#define PutMapFlags $4a
#define PutMapUseColor 4
.list
.db tExtTok,tAsm84CCmp
.org userMem
menuStart:                       ;Start of menu routine
   
    bcall(_maybe_ClrLCDFull)        ;Display the Header
   
    ld b,1                     ;Which group is being displayed
     
dispMenu:                     ;display the menu
   
    ld c,1                     ;Which item is highlighted
    push bc
   
    ld hl,txtHeader               ;display the header
    call dispHeader
   
    ld a,b
   
    cp 1
    jr nz,dispMenu2
   
    ld b,3
    ld hl,txtItem1_1               ;Display Items in GA
    call dispItems
   
    jr dispMenu4
   
dispMenu2:
   
    cp 2
    jr nz,dispMenu3
   
    ld b,3
    ld hl,txtItem2_1            ;Display Items in GB
    call dispItems
    jr dispMenu4
   
dispMenu3:
   
    ld b,3
    ld hl,txtItem3_1            ;Display Items in GC
    call dispItems
   
dispMenu4:                     ;Since every group has a quit, display it here
    bcall(_NewLine)
    ld hl,txtItemQuit
    bcall(_PutS)
   
    pop bc
   
menuLoop:                       ;Scan key loop to get user input
      
    call curDraw
    push bc                        ;save BC for later
   
    bcall(_GetKey)
   
    pop bc                        ;we'll need this for some routines with the new                                            keypresses
    cp kleft
    jr z,mLeft
   
    cp kright
    jr z,mRight
   
    cp kup
    jr z, mUp
   
    cp kdown
    jr z, mDown
   
    cp kenter
    jr z, selection
   
    cp k1                        ;If user pressed 1, do action 1
    jr z,item1
   
    cp k2                        ;If user pressed 2, do action 2
    jp z,item2
   
    cp k3                        ;If user pressed 3, do action 3
    jp z,item3
   
    cp k4                        ;If user pressed 4, quit
    jp z,quit
   
    jr menuLoop                    ;Else, invalid input. Wait for user to input new key
   
mUp:
   
    call curErase1                  ;erase the cursor
   
    ld a,c                         ;check if the cursor is out of bounds
    cp 1
    jr z,menuLoop
   
    dec c                        ;if not, decrease and return
    jr menuLoop
   
mDown:
   
    call curErase1                  ;erase the cursor
   
    ld a,c                         ;check if the cursor is out of bounds
    cp 4
    jr z,menuLoop
   
    inc c                         ;if not, increase and return
    jr menuLoop
   
mRight:                        ;change group
      
   call curErase2
    ld a,b                     ;check if already as far right as possible
    cp 3
    jr z,menuLoop
   
    inc b
   
    jp dispMenu
   
mLeft:                        ;change group
   
   call curErase2
    ld a,b                     ;check if already as far right as possible
    cp 1
    jr z,menuLoop
   
    dec b
   
    jp dispMenu                  
   
selection:
   
    ld a,c
   
    cp 1
    jr z,item1                     
   
    cp 2
    jr z,item2                  
   
    cp 3
    jr z,item3
   
    jp quit
   
item1:                           ;Action 1
   
    push bc
    bcall(_maybe_ClrLCDFull)
    pop bc
   
    ld de,0
    ld (curRow),de               
   
    ld a,b
    cp 1
    jr nz,item1B
   
    ld hl,txtSelect1_1            ;action 1 for group A
   
    jr item1Done
item1B:
    cp 2
    jr nz,item1C
   
    ld hl,txtSelect2_1            ;action 1 for group B
   
    jr item1Done
   
item1C:
   
    ld hl,txtSelect3_1            ;action 1 for group C
   
item1Done:
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
    bcall(_PutS)               ;we'll display the text now
   
    bcall(_GetKey)
   
    jp menuStart
   
item2:                           ;Action 2
   
    push bc
    bcall(_maybe_ClrLCDFull)
    pop bc
   
    ld de,0
    ld (curRow),de
   
    ld a,b
    cp 1
    jr nz,item2B
   
    ld hl,txtSelect1_2            ;action 2 for group A
   
    jr item2Done
item2B:
    cp 2
    jr nz,item2C
   
    ld hl,txtSelect2_2            ;action 2 for group B
   
    jr item2Done
   
item2C:
   
    ld hl,txtSelect3_2            ;action 2 for group C
   
item2Done:

   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
    bcall(_PutS)
   
    bcall(_GetKey)
   
    jp menuStart
   
item3:                           ;Action 3
   
    push bc
    bcall(_maybe_ClrLCDFull)
    pop bc
   
    ld de,0
    ld (curRow),de
   
    ld a,b
    cp 1
    jr nz,item3B
   
    ld hl,txtSelect1_3            ;action 3 for group A
   
    jr item2Done
item3B:
    cp 2
    jr nz,item3C
   
    ld hl,txtSelect2_3            ;action 3 for group B
   
    jr item1Done
   
item3C:
   
    ld hl,txtSelect3_3            ;action 3 for group C
   
item3Done:

   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
    bcall(_PutS)
   
    bcall(_GetKey)
   
    jp menuStart
   
quit:                           ;quit the program
   
    bcall(_maybe_ClrLCDFull)
   
    ret
   
   ;dispHeader
   ;
   ;displays the header centered and at the top
   ;
   ;Inputs: HL points to null-terminating string
   ;
   ;Output: text displayed, with the current group in inverse text
   ;
   ;Destroyed: a,de,hl
   ;
   ;Note: text string must be large text and take up the full line
   ;(use blank spaces to fill in gaps)
   ;
   
dispHeader:                         ;displays the header centered and at the top
   
    ld de,0
    ld (curRow),de
   
    ld a,b
    cp 1
    jr nz,dispHeader1
    set textInverse,(IY+TextFlags)
   
dispHeader1:                  ;group A
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
    res textInverse,(IY+TextFlags)
   
   push af
   
    ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
   
    cp 2
    jr nz,dispHeader2
    set textInverse,(IY+TextFlags)
   
dispHeader2:                  ;group B
   
   push af
   
    ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
    res textInverse,(IY+TextFlags)
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
   
    cp 3
    jr nz,dispHeader3
   
    set textInverse,(IY+TextFlags)
   
dispHeader3:                  ;group C
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
    res textInverse,(IY+TextFlags)
   
    ld hl,0
    ld (curRow),hl
   
    ret
   
   ;dispItems
   ;
   ;displays menu items at the start of the next line
   ;
   ;Inputs: HL points to null-terminating string
   ;
   ;Output: text displayed
   ;
   ;Destroyed: all
   ;
   
dispItems:                         ;displays menu items at the start of the next line
   
    push bc
    push hl
    bcall(_NewLine)
    pop hl
    pop bc
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    bcall(_PutS)
   
    djnz dispItems               
   
    ret
   
   ;curDraw
   ;
   ;Draws the cursor
   ;
   ;Inputs: C holds the highlighted item
   ;
   ;Outputs: Cursor displayed      
   ;
   ;Destroyed: A
   ;
   
curDraw:
    set textInverse,(IY+TextFlags)  ;set inverse text
   
   push af
   
   ld a,5
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    xor a
    ld (curCol),a
    ld a,c
    ld (curRow),a
   
    add a,$30                      ;Character offset
   
    bcall(_PutC)
   
    ld a,':'
    bcall(_PutC)
   
   push af
   
   ld a,1
   
   bcall(_GetColorValue)           ;from a to de
   
   ld (textFGcolor),de
   
   set PutMapUseColor,(iy+PutMapFlags)
   
   pop af
   
    res textInverse,(IY+TextFlags)
    ret
   
   ;curErase1
   ;
   ;Erase the cursor on list
   ;
   ;Inputs: C highlighted item
   ;
   ;Ouputs: Cursor erased
   ;
   ;Destroyed: A
   ;
   
curErase1:                     ;erase list
    xor a
    ld (curCol),a
    ld a,c
    ld (curRow),a
   
    add a,$30                      ;Character offset
   
    bcall(_PutC)
   
    ld a,':'
    bcall(_PutC)
    res textInverse,(IY+TextFlags)
   push hl
   push de
   push bc
   ld hl,0
   ld de,1
   ld b,55
   ld c,160
   bcall(4D44h)               ;ClearRect
   pop bc
   pop de
   pop hl
    ret
   
   ;curErase2
   ;
   ;Erase the cursor on header
   ;
   ;Inputs: C highlighted item
   ;
   ;Ouputs: Cursor erased
   ;
   ;Destroyed: A
   ;
   
curErase2:                     ;erase header
    xor a
    ld (curCol),a
    ld a,c
    ld (curRow),a
   
    add a,$30                      ;Character offset
   
    bcall(_PutC)
   
    ld a,':'
    bcall(_PutC)
    res textInverse,(IY+TextFlags)
   push hl
   push de
   push bc
   ld hl,0
   ld de,1
   ld b,30
   ld c,160
   bcall(4D44h)               ;ClearRect
   pop bc
   pop de
   pop hl
    ret
   
   ;========================================
   ;data
   ;========================================
   
txtHeader:
    .db "GA",0
    .db "     ",0               ;space x 5
    .db "GB",0
    .db "     ",0
    .db "GC",0
   
txtItem1_1:
    .db "1:A1",0
   
txtItem1_2:
    .db "2:A2",0
   
txtItem1_3:
    .db "3:A3",0
   
txtItem2_1:
    .db "1:B1",0
   
txtItem2_2:
    .db "2:B2",0
   
txtItem2_3:
    .db "3:B3",0
   
txtItem3_1:
    .db "1:C1",0
   
txtItem3_2:
    .db "2:C2",0
   
txtItem3_3:
    .db "3:C3",0
   
txtSelect1_1:
    .db "You selected A1",0
   
txtSelect1_2:
    .db "You selected A2",0
   
txtSelect1_3:
    .db "You selected A3",0
   
txtSelect2_1:
    .db "You selected B1",0
   
txtSelect2_2:
    .db "You selected B2",0
   
txtSelect2_3:
    .db "You selected B3",0
   
txtSelect3_1:
    .db "You selected C1",0
   
txtSelect3_2:
    .db "You selected C2",0
   
txtSelect3_3:
   .db "You selected C3",0
   
txtItemQuit:
   .db "4:Quit",0
   ret
.end
.end
I found another menu format, and I might use it later. It is fully functioning as is, however something odd seems to occur if I stick to the original code http://wikiti.brandonw.net/index.php?title=83Plus:OS:Dialog_context. I ended up fixing it using a dummy .db (and converting header to 84pcse format), though I was wondering what is causing the problem and if there is another way to fix it.

My code:

Code:
.nolist
#include "ti84pcse.inc"
.list
.db tExtTok,tAsm84CCmp
hookBackup              equ     appBackUpScreen
_StartDialog            equ     4BEEh
_DialogInit             equ     4BF1h
_GetDialogNumOP1        equ     4BF4h
.org userMem
        .db 0BBh,6Dh
        ld hl,rawKeyHookPtr
        ld de,hookBackup
        ld bc,4
        ldir
        ld a,(flags+34h)
        ld (de),a
        ld a,(cxCurApp)
        push af
        ld a,58h
        ld (cxCurApp),a
        ld hl,structStart
        ld de,ramCode
        ld bc,structEnd-structStart
        ldir
        ld hl,dialogCallback
        in a,(6)
        bcall(_DialogInit)
        bcall(_maybe_RunIndicOff)
        bcall(_StartDialog)
        bcall(_cursorOff)
        bcall(_maybe_ClrLCDFull)
        res appCurWord,(iy+appFlags)
        bcall(_maybe_ClrTxtShd)
        ld hl,cmdShadow
        ld de,cmdShadow+1
        ld (hl),' '
        ld bc,127
        ldir
        pop af
        ld (cxCurApp),a
        ld hl,hookBackup
        ld de,rawKeyHookPtr
        ld bc,4
        ldir
        ld a,(hl)
        ld (flags+34h),a
        xor a
        bcall(_GetDialogNumOP1)
        ld hl,0
        ld (penCol),hl
        ld a,9
        bcall(_maybe_DispOP1A)
dialogCallback:
        xor a
        ret
structStart:
        .db 1
        .db 1
        .db 1
        .dw sOptions-structStart

        .db 5
        .db 1
        .db 1
        .dw sItem-structStart

        .db 5
        .db 1
        .db 2
        .dw sItem2-structStart

        .db 2
        .db 3
        .db 1
        .dw sSelect-structStart
        .dw sOpt1-structStart
        .dw sOpt2-structStart

        .db 3
        .db 1
        .db 0
        .dw sNum-structStart

        .db 4
        .db 1
        .db 1
        .dw sDone-structStart

      
        .db 0
sOptions:
        .db 7,"OPTIONS"
sDummy   .db 0,"   "       ;any .db in this location gets screwed up
sItem2: .db 7,"Item2  "  ;changing length didnt do anything
sItem:  .db 5,"Item1"     ;switching order does not fix problem
sSelect:
        .db 6,"Opts: "
sOpt1:  .db 4,"Opt1"
sOpt2:  .db 4,"Opt2"
sNum:   .db 4,"Num="
sDone:  .db 4,"Done"
structEnd:
.end
Hey everyone, another question:

I am using a .db to store a text string, and using it to display a string. However, there are some characters I want to use that are found in certain areas of ram. I was wondering how I would display something like:

Code:
eq3:   .db 12,"V²=Vo²+2aΔX "
;12=number of characters, the space is used to match other strings' lengths


EDIT:
Never mind, it turns out it is as simple as inserting a few commas and the hex code.

Code:
eq3:   .db 12,"V",$12,"=V",$80,$12,"+2a",$BE,"X "
Hey everyone (again),

I found a font hook thingy and I was wondering how I would go about using a custom character instead of $80 in:

Code:
eq3:   .db 12,"V",$12,"=V",$80,$12,"+2a",$BE,"X "
Well, at the bottom of that page is a very nice example of custom displaying the small A, you can very easy modify that routine to create your custom character. What about this?


Code:
  .db 83h
  or a, a
  jr z, +_
  cp a, a
  ret
_:ld a, h
  or a, l
  rrca
  rrca
  rrca
  cp a, $80
  ret nz
  ld hl, customCharacter
  ld de, sFont_record
  ld bc, 8
  ldir
  ld hl, customCharacter
  cp a, a
  ret
customCharacter:
<stuff>
Do I have to replace $80 eventually if I do not want to permanently modify the font? (If I don't, when does it get replaced?)
You can disable it by either running bcall(_ClrFontHook) or so, or reset your calc Razz
I tried the code above and the code on the wikiti page, but it does not seem to work the way I implemented it. I've tried for a few hours and could not get it to store customCharacter to $80.

Code:
      .db 83h
  bcall(_SetFontHook)
 
  ld hl,disp
  ld a,h
  or a,l
  rrca
  rrca
  rrca
  cp $80
  ;ret nz
  ld hl, customCharacter
  ld de, sFont_record
  ld bc,8
  ldir
  ld hl, sFont_record
  cp a
  ;ret
customCharacter:
       .db 00000000b
       .db 00001100b
       .db 00010110b
       .db 00011110b
       .db 00010110b
       .db 00010110b
       .db 00000000b

   ld hl,disp
   bcall(_PutS)
   bcall(_GetKey)   
disp:
   .db $80,0
   ret
What happens instead? What happened when you tried tracing it with an emulator? Were you able to find where it diverged from the expected behavior?
This code will display the original $80 without any modifications. I tried it without the semicolons in front of the rets, it did not display anything.
You certainly need the rets. It seems like you have some fundamental misunderstandings about how hooks work:
  1. You put the hook code in a stable, safe location (commonly, in Flash inside an App). That code must start with .db 83h, as a flag indicating that this is a hook.
  2. You call bcall(_SetBlahHook), pointing at the address and page of your hook
  3. Your program ends (or continues); the OS will call your hook whenever necessary.
I've done all the research I could, but I am still not completely understanding the hook. I attempted to implement a few things at the beginning of the program that seemed to work for other hooks, but the font hook does not seem to be working as expected. Anyways, what I've got so far:

Code:
.nolist
#include "ti84pcse.inc"
#define PutMapFlags $4a
#define PutMapUseColor 4
.list
.db tExtTok,tAsm84CCmp
hookBackup              equ     appBackUpScreen
;anything else that needs to be here?
.org userMem
        .db 0BBh,6Dh   
      ld hl,FontHook
      in a,(6)                    ;is this the right port?
      bcall(_SetFontHook)
      bcall(_CallFontHook) ;Wikiti was vague on inputs
      bcall(_PutS)             ;I'm not sure what to do with hl at this point...
      bcall(_GetKey)         ;pause

FontHook:
       .db 83h             ; Required for all hooks
  or a                        ; from PT_'s code
  jr z,+_
  cp a
  ret
_:
  ld a,h
  or a,l
  rrca
  rrca
  rrca
  cp $80
  ret nz
  ld hl,customCharacter
  ld de,sFont_record
  ld bc,8
  ldir
  ld hl,customCharacter
  cp a
  ret
customCharacter:             
;      .db 5
       .db %00000000
       .db %00001100
       .db %00010110
       .db %00011110
       .db %00010110
       .db %00010110
       .db %00000000
eq3:   
      .db "V",$12,"=V",$80,$12,"+2a",$BE,"X ",0 ;to be displayed by PutS, $80 is the character to be modded
      ret
WikiTI reference for the casual reader who is not familiar with it.

Going through piece by piece, there are a number of mistakes that suggest you're copying code from elsewhere without really understanding why any particular thing is done the way it is!

Code:
.nolist
#include "ti84pcse.inc"
#define PutMapFlags $4a
#define PutMapUseColor 4
.list
.db tExtTok,tAsm84CCmp
hookBackup              equ     appBackUpScreen
;anything else that needs to be here?
.org userMem
You're a RAM program targeting the CSE. Okay; this will be important later.

Code:
        .db 0BBh,6Dh

You already have type bytes (tAsm84CCmp) so this is redundant and wrong (these values are the "old" tAsmCmp), but happens to correspond to harmless code (cp e \ ld l,l).

Code:
      ld hl,FontHook
      in a,(6)                    ;is this the right port?
      bcall(_SetFontHook)
Hook set inputs are the flash page and address, so that's correct. You're a RAM program so the flash page is unimportant, but specifying the one that happens to be active is harmless.

Code:
      bcall(_CallFontHook) ;Wikiti was vague on inputs
Unnecessary but harmless. There's no need to invoke the hook manually (it's automatic when installed and the OS goes to display text), but you don't do anything with the outputs* so it's merely wasteful to call now.

* The registers when you call the hook will probably be such that it returns without setting HL, but it could conceivably set it. In either case you end up trying to display arbitrary memory contents as a string. The load before _PutS below is important.

Code:
    ld hl, eq3
      bcall(_PutS)             ;I'm not sure what to do with hl at this point...
      bcall(_GetKey)         ;pause
    ret
Looks like you want to display your equation, so HL should point to it. This is supposed to be the end of the program, so I added a ret because otherwise you're falling through to the hook code which is harmless but not reasonable to do.

Code:
FontHook:
       .db 83h             ; Required for all hooks
  or a                        ; from PT_'s code
  jr z,+_
Check if a small-font bitmap is requested, return with "process as normal" if not. Should probably handle case 2 (requesting the width of a small-font character), but I don't know if that will cause wrong behavior or not.

Code:
  cp a
  ret
_:
If not case 0, set Z (A always equals itself) and return. Unhandled characters should return NZ, so omit the cp- the immediately preceding conditional jump guarantees the zero flag is reset when returning.

Code:
  ld a,h
  or a,l
  rrca
  rrca
  rrca
  cp $80
  ret nz
Divide the 11-bit value in HL by 8 (getting the desired character value) and return if not the target one. Fine, and I see mostly copied from the WikiTI example code.

Code:
  ld hl,customCharacter
  ld de,sFont_record
  ld bc,8
  ldir
Unnecessary to copy the bitmap to RAM because it's already in RAM because you're not an app.

Code:
  ld hl,customCharacter
  cp a
  ret
Return a pointer to the bitmap and flag that you're providing it. Fine.

Code:
customCharacter:             
       .db 5
       .db %00000000
       .db %00001100
       .db %00010110
       .db %00011110
       .db %00010110
       .db %00010110
       .db %00000000
eq3:   
      .db "V",$12,"=V",$80,$12,"+2a",$BE,"X ",0 ;to be displayed by PutS, $80 is the character to be modded
Data. Fine, but the initial width byte should be present otherwise this data is telling it that the width of the character is zero.

Code:
      ret
Useless stray ret that was probably supposed to be at the end of the actual program code where I inserted one above.



If this program is meant to only display your equation and not override that character in general use you should also disable the hook after displaying the string. Leaving it active is going to be wrong since it will continue trying to execute until there's no longer the check value (0x83) at the address you had it at, such as if another program is run. If another program that happens to have the check value at the same address were to be run, it could easily crash or cause incorrect rendering.

I also observe that the hook only handles the small font but you try to display the equation with _PutS and therefore large font. Either use _VPutS for small font (setting curRow, curCol as appropriate) or handle hook case 1 for fixed-width large font instead.

It may be simpler to manually display what you want rather than installing a hook and making the OS display your bitmap as a character, depending on what you actually want out of a final program. Note as well that this will remove any existing font hook, so you need to save and restore one (optionally chaining to it) that might be active if you want to be robust against such a situation.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement