Just a coding trick

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
puromtec
New Member
Posts: 43
Joined: Fri 07 May, 2010 11:00 pm

Just a coding trick

Post by puromtec »

Well, I don't know if this is a trick, but I'd like to get a little feed-back. Give me thumbs up, down or WTF is that for?

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

King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: Just a coding trick

Post by King Harold »

I sometimes put a jp (hl) somewhere just so I can call it (to get, in effect, a call (hl) )
Post Reply