I wanted an easy way to map menu item text strings with a routine AND I wanted the routines to be callable so they could just end with the "ret". This is the solution I came up with:
Code: Select all
(IN A GLOBAL VARIABLE PLACE)
.struct Address
.var byte, cmd
.var uword, target
.endstruct
.var Address, JpAddy
ld a, c3h ; jp command
ld (JpAddy.cmd), a
(SOMEWHERE IN THE REST OF THE CODE)
MainRoutine:
; hard code a call to the first menu item
ld de, RootMenuItems
ldDEind() ; load 16 bit address to de which it is pointing to
ld a, e
ld (JpAddy.target), a
ld a, d
ld (JpAddy.target+1), a
call JpAddy
ret
SomeWorkRoutine:
;just some code that does stuff
ld hl, Strings.AlphaCondition
ld (StatusMessage.MessagePtr), hl
call noname.DisplayStatus
ret
AnotherRoutine:
ret
RootMenuItems:
.dw SomeWorkRoutine
.db "Work Routine A",0
.dw AnotherRoutine
.db "Another Routine",0