2068 Code Bytes #4

Authors

Publication

Pub Details

Date

Pages

BASIC Terms

See all articles from SMUG Bytes v10 n4

Fourth installment in Lloyd Dreger’s Z80 machine language series for the Timex/Sinclair 2068, presenting the general menu system used in his CONQUEST wargame. Covers the SetTV and GetTV screen-switching routines, PrintMENU for rendering menu text to screen, MoveCURsor for arrow-key cursor movement, and GETINPut for accepting both keyboard and joystick input. Full assembly listings with addresses and mnemonics are provided throughout.


Although this routine is used in a game it can be used anywhere a menu is desired. Like the previous routines in this set, much use is made of the Basic routines already in ROM–if we have to waste 16k of memory we might as well take advantage of it.

This is a general menu routine that is called with the following registers set:

  • B=# of items in menu
  • C=What column to run the cursor from. The printing will start one column beyond that. Sorry but each menu starts at the top of the screen at line 0. At least you can have left, middle and right menus if you need submenus:
  • DE= address of menu names -1. (What each line will say.) Menu items must be consecutive in this list and must not be so long as run onto a 2nd line of screen. The last letter of each line must have bit 7 set as a flag to indicate the end–see how this is used in PX. FN and PM also use PX but are not used to print the menu.

PrintMENU prints the menu and calls MoveCURsor which runs the ment by moving the cursor up and down and automatically recycling when at the top or bottom.

SetTV sets the screen to top. screen while GetTV returns the screen to the previous setting.

GETINPut is a general input routine that works for both keyboard and joystick.

The routines can be located anywhere. In CONQUEST its located at 60148 and that address is used for the present code:

TVEQU 23612A FLAG IN BASIC VARIABLES
TVFEQU 52359SAVE SPACE IN GAME VARIABLE TABLE
6014858,60,92STVLD A,(TV)
6015150,135,204LD (TVF),A
60154203,135RES 0,AFORCE UPPER SCREEN
6015650,60,92STLD (TV),A
60159201RET
6016058,60,92STVOLD A,(TV)
6016350,135,204LD (TVF),A
60166203,139SET 0,AFORCE LOWER SCREEN
6016824,242JR ST
6017058,135,204GTVLD A,(TVF)
6017350,60,92LD (TV),A
60176201RET
60177 to 60184 is another short routine not used here
6018550,94,235PMENULD (LINE),A
60188205,244,234CALL STV
60191120LD A,B
6019250,93,235LD (JFLAG),A
60195197PUSH BC
60196213PPPUSH DE
60197197PUSH BC
6019862,22LD A,22DO AN AT
60200215RST 16
6020158,92,235LD A,(JFLAG)
6020471LD B,A
6020558,94,235LD A,(LINE)
60208128ADD A,B
60209193POP BC
60210144SUB B
60211197PUSH BC
60212215RST 16
60213193POP BC
60214121LD A,C
60215197PUSH BC
60216215RST 16
60217193POP BC
60218209POP DE
60219197PUSH BC
60220205,80,235CALL PX
60223193POP BC
6022416,226DJNZ PP
60226193POP BC
60227205,96,235CALL MCUR
6023024,194JR GTVEND OF ROUTINE
60232205,32,248PNCALL FINDM+3
6023524,3JR PX
60237205,29,248PMCALL FINDM
6024019PXINC DE
6024126LD A,(DE)
60242203,191RES 7,A
60244213PUSH DE
60245215RST 16
60246209POP DE
6024726LD A,(DE)
60248203,127BIT 7,A
6025040,242JR Z,PX
60252201RET
602530JFLAGDEFB 0
602540LINEDEFB 0
602551COLDEFB 1
60256121MCURLD A,C
6025761DEC A
6025850,85,235LD (COL),A
6026172LD C,B
6026213DEC C
60263175XOR A
6026471LD B,A
6026558,94,235LD A,(LINE)
6026850,93,235LD (JFLAG),A
60271197ERASEPUSH BC
6027262,22LD A,22DO AN AT WITH JFLAG AND COL
60274215RST 16
6027558,92,235LD A,(JFLAG)
60278215RST 16
6027958,95,235LD A,(COL)
60282215RST 16
6028362,32LD A,BLANKPRINT A SPACE
60285215RST 16
6028662,22LD A,22NOW DO AN AT WITH LINE+B AND COL
60288215RST 16
60289193POP BC
6029058,94,235LD A,(LINE)
60293128ADD A,B
6029450,93,235LD (JFLAG),A
60297197PUSH BC
60298215RST 16
6029958,95,235LD A,(COL)
60302215RST 16
6030362,62LD A,”>”
60305215RST 16CURSUR REPRINTED
60306193POP BC
60307205,184,235CJCALL GETINPTHIS ROUTINE WAITS FOR AN INPUT WHICH IS RETURNED IN A. WE WILL ONLY BE INTERESTED IN THE JOYSTICK UP DOWN AND BUTTON COMMANDS.
60310203,79BIT 1,A
6031240,11JR Z, UPA
60314121LD A,C
60315184CP B
6031640,3JR Z,UP1
603184INC B
6031924,206JR ERASE
603216,0UP1LD B,O
6032324,202JR ERASE
60325203,71UPXBIT 0,A
6032740,10JR Z,BUT
60329175XOR A
60330184CP B
6033140,3JR Z,DW1
603335DEC B
6033424,191JR ERASE
6033665DW1LD B,C
6033724,188JR ERASE
60339203,127BUTBIT 7,A
6034140,220JR Z,CJ
60343201RETONLY RETURN IF BUTTON IS PRESSED. YOUR RETURN NOW MUST TAKE THE VALUE OF B WHICH GIVES THE LINE NUMBER (STARTING WITH 0) AND EXECUTE THE COMMAND RELATED TO THAT SELECTED MENU ITEM.
60344175GETINPXOR A
6034550,8,92LD (LASTK),ARESET LASTK TO GET RID OF ANY OLD INPUT
60348118HALTDEBOUNCE
60349118HALT
60350118JLHALT
6035162,14LD A,14CHECK JOYSTICK FIRST
60353211,245OUT (245),A
6035562,3LD A,3CHECK BOTH JOYSTICKS
60357219,246IN A,(246)
60359238,255XOR 255INPUT IS ACTIVE LOW. WE WANT ACTIVE HIGH SO INVERT.
6036132,7JR Z,JMFOUND NO JOYSTICK INPUT SO CHECK KEYBOARD.
6036358,8,92LD A,(LASTK)
60366254,0CP O
6036840,236JR Z,JLFOUND NOTHING SO CHECK AGAIN.
60370201RET

Image Gallery

Source Code

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top