--- title: "2068 Code Bytes #4" type: "article" slug: "2068-code-bytes-4" url: "http://localhost/article/2068-code-bytes-4/" markdown_url: "http://localhost/article/2068-code-bytes-4.md" published_at: "2026-03-12T18:30:29+00:00" modified_at: "2026-07-25T23:34:38+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "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…" category: - name: "SMUG Bytes" slug: "smug-bytes" taxonomy: "category" url: "http://localhost/category/periodicals/smug-bytes/" post_tag: - name: "Best of Timex/Sinclair 2068 Articles and Documents" slug: "ts2068best" taxonomy: "post_tag" url: "http://localhost/tag/ts2068best/" - name: "Machine language programming" slug: "machine-language" taxonomy: "post_tag" url: "http://localhost/tag/machine-language/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Lloyd Dreger" slug: "lloyd-dreger" taxonomy: "indiv" url: "http://localhost/indiv/lloyd-dreger/" publication_r: id: 37935 title: "SMUG Bytes" type: "periodical" url: "http://localhost/periodical/smug-bytes/" authors_r: - name: "Lloyd Dreger" slug: "lloyd-dreger" taxonomy: "indiv" url: "http://localhost/indiv/lloyd-dreger/" volume: "10" issue: "4" issues_articles: - id: 50217 title: "SMUG Bytes v10 n4" type: "issue" url: "http://localhost/issue/smug-bytes-v10-n4/" pages: "3" pubdate: "July 1993" related_articles: - id: 64989 title: "2068 Code Bytes #3" type: "article" url: "http://localhost/article/2068-code-bytes-3/" - id: 64994 title: "2068 Code Bytes #5" type: "article" url: "http://localhost/article/2068-code-bytes-5/" - id: 64996 title: "2068 Code Bytes #6" type: "article" url: "http://localhost/article/2068-code-bytes-6/" - id: 64998 title: "2068 Code Bytes #7" type: "article" url: "http://localhost/article/2068-code-bytes-7/" archive_link: false --- # 2068 Code Bytes #4 Fourth installment in [Lloyd Dreger’s](http://localhost/indiv/lloyd-dreger/) Z80 machine language series for the Timex/Sinclair 2068, presenting the general menu system used in his [CONQUEST](http://localhost/product/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 *** #### About this transcription This listing was transcribed from the original scan and checked line by line. The published address column, object-byte column and mnemonics each independently determine the program, so all three were cross-referenced against one another: 126 lines carried both bytes and mnemonics and were fully verified. The bytes are authoritative where they disagree with the printed mnemonics. 2 such discrepancies were found: - **60312**, printed as `JR Z, UPA`, should read `JR Z,UPX` — no label UPA appears anywhere in the article; the jump lands on UPX - **60361**, printed as `JR Z,JM`, should read `JR NZ,JM` — byte 32 is JR NZ; the target label JM is not printed in the listing Typesetting artefacts at 60321, 60366 (the letter O set for the digit 0) have been silently corrected; the object bytes were never in doubt. The following could not be resolved from the available scan and are reproduced as printed: 60166, 60201, 60250, 60258, 60275. If you have a cleaner copy of this issue, corrections are welcome. 5 symbols and jump targets referenced here are defined outside the published excerpt and could not be verified.