--- title: "2068 Code Bytes #5" type: "article" slug: "2068-code-bytes-5" url: "http://localhost/article/2068-code-bytes-5/" markdown_url: "http://localhost/article/2068-code-bytes-5.md" published_at: "2026-03-12T18:32:29+00:00" modified_at: "2026-07-25T23:35:04+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "Fifth installment of the Z80 machine language series, presenting the world-map printing routine for CONQUEST. Covers FMO (find map start based on player position), PMAP (print map to screen), WRAP (horizontal and vertical wrapping logic for a 64x64 toroidal map), FINDAT (attribute address calculation), and PRUDG (print User Defined Graphic characters for map symbols). Full…" 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-7" issues_articles: - id: 50216 title: "SMUG Bytes v10 n4-7" type: "issue" url: "http://localhost/issue/smug-bytes-v10-n4-7/" pages: "3" pubdate: "August - November 1993" related_articles: - id: 64989 title: "2068 Code Bytes #3" type: "article" url: "http://localhost/article/2068-code-bytes-3/" - id: 64991 title: "2068 Code Bytes #4" type: "article" url: "http://localhost/article/2068-code-bytes-4/" - 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 #5 Fifth installment of the Z80 machine language series, presenting the world-map printing routine for CONQUEST. Covers FMO (find map start based on player position), PMAP (print map to screen), WRAP (horizontal and vertical wrapping logic for a 64×64 toroidal map), FINDAT (attribute address calculation), and PRUDG (print User Defined Graphic characters for map symbols). Full assembly listings with addresses and mnemonics. *** A routine to print a map that wraps in both directions, i.e., go off the map westward puts you on the eastern edge, northward on the southern edge or vise versa. The map itself is 64×64. We have two variables called Mapcox and Mapcoy (stored at 52396/7) which define what map coordinates (starting with 1,1) is being printed in the upper left corner of the screen. Since this routine also prints the player maps, it uses the variable Player (at 31539). The master map is stored at 32000. Each map requires 4096 bytes of space so player 1’s map starts at 36096, etc. We need a special variable called WRAPF (at 52389). The routine is entered at 60475 preceded by PMO which is a routine that finds the correct space in memory to start from. The Findat routine depends upon how you set the various UDG characters on your map. For Conquest they are: 0 blank, 1 sea, 2 land, 3 mountain, 4 shoal, 5 city, 6-15 units whose color will be yellow, red and white for players 1 to 3 respectively. For cities and units ownership is designated in the top 2 bits. We are running out of space so we will finish this routine in the next installment. PLAYEREQU 31539from article prose WRAPFEQU 52389from article prose PRUDGEQU 60791printed at this address in issue #6 P1EQU 60726issue #6 resumes the listing here MAPCOYEQU 52396issue #6 gives MAPCOX as 52397, so 52396 is MAPCOY 60442120PMOLD A,BBC=MAPCOX,MAPCOY 6044361DEC A 6044438,0LD H,0 60446167AND A 6044723RLA 6044823RLA 6044923RLA 60450203,20RL H 6045223RLA 60453203,20RL H 6045523RLA 60456203,20RL H 6045823RLAinserted per the correction in issue #6 60459203,20RL Hinserted per the correction in issue #6 60461111LD L,ATHE RIGHT STARTING POINT OF ANY MAP NOW FIND OUT WHOS MAP 6046258,51,123LD A,(PLAYER) 60465167AND A 6046623RLA 6046723RLA 6046823RLA 6046923RLA 60470132ADD A,H 60471198,125ADD A,125ADD THE OFFSET TO MAP ZERO (MASTER) 60473103LD H,A 60474121LD A,C 6047561DEC A 60476133ADD A,L 60477111LD L,A 60478201RET 60479237,75,172,204PMAPLD BC,(MAPCOY) 60483205,26,236CALL PMO 60486175XOR A 6048750,165,204LD (WRAPF),ARESET WRAP FLAG 60490229PUSH HLSAVE HL ADDRESS FOR CALC. ATTR 6049117,0,64LD DE,16384SET DE TO TOP OF SCREEN 604946,3LD B,3WE ARE GOING TO PRINT ALL 24 LINES OF THE SCREEN, NOT JUST THE FIRST 21 60496197NEXTPUSH BCSAVE COUNT 6049714,8LD C,88 LINES 604996,32NEXT1LD B,3232/LINE 60501126NEXT2LD A,(HL)GET USER DEFINED CHARACTER 60502205,119,237CALL PRUDGPRUDG CONVERTS THE CHARACTER CODE TO THE CORRECT SPOT IN THE UDG TABLE AND PRINTS IT TO THE SCREEN 60505205,232,236CALL WRAPTHIS SUBROUTINE DOES THE ACTUAL DETERMINATION OF WHEN WE ARE AT A SEAM AND ADJUSTS HL ACCORDINGLY. A=WRAPF, 0=NO WRAP, 255=WRAP 60508254,255CP 255 6051032,8JR NZ,PM1 60512213PUSH DESAVE POINT ON SCREEN 6051317,64,0LD DE,64 60516167AND A 60517237,82SBC HL,DE 60519209POP DE 6052035PM1INC HLNOW RESET DE 60521122LD A,D 60522214,8SUB 8 6052487LD D,A 6052519INC DE 6052616,229DJNZ NEXT2 60528213PUSH DE 6052958,165,204LD A,(WRAPF) 60532254,0CP 0 6053440,5JR Z,AD-3AT END OF LINE WE HAVE TO ADD EITHER 96 OR 32 TO HL 6053617,96,0LD DE,96 6053924,3JR AD 6054117,32,0LD DE,32 6054425ADADD HL,DE 6054558,51,123LD A,(PLAYER) 60548167AND A 6054923RLA 6055023RLA 6055123RLA 6055223RLA 60553198,141ADD A,141 6055587LD D,A 60556124LD A,H 60557186CP D 6055832,3JR NZ,PM2RESET TO TOP OF MAP 60560214,16SUB 16 60562103LD H,A 60563209PM2POP DE 6056413DEC C 6056532,188JR NZ,NEXT1ADJUST DE TO NEXT SET OF 8 60567122LD A,D 60568198,7ADD A,7 6057087LD D,A 60571193POP BC 6057216,178DJNZ NEXT NOW DO ATTRIBUTES 60574225POP HL 6057517,0,88LD DE,22528 6057814,24LD C,24 605806,32NEXT3LD B,32 60582197NEXT4PUSH BC 60583126LD A,(HL) 60584205,254,236CALL FINDATTHIS ROUTINE CALCULATES BOTH INK AND PAPER FOR THE CHARACTER AND STORES IT IN A 6058718LD (DE),A 60588205,232,236CALL WRAP 60591254,255CP 255 6059332,8JR NZ,NIX 60595213PUSH DE 6059617,64,0LD DE,64 60599167AND A 60600237,82SBC HL,DE 60602209POP DE 6060319NIXINC DE 6060435INC HL 60605193POP BC 6060616,230DJNZ NEXT4 60608213PUSH DE 6060958,165,204LD A,(WRAPF) 60612254,0CP 0 6061440,5JR Z,A1-3 6061617,96,0LD DE,96 6061924,3JR A1 6062117,32,0LD DE,32 6062425A1ADD HL,DE 6062558,51,123LD A,(PLAYER) 60628167AND A 6062923RLA 6063023RLA 6063123RLA 6063223RLA 60633198,141ADD A,141 6063587LD D,A 60636124LD A,H 60637186CP D 6063832,3JR NZ, PR3 60640216,16SUB 16 60642103LD H,A 60643209PR3POP DE 6064413DEC C 6064532,189JR NZ,NEXT3 60647201RET 60648125WRAPLD A,L 60649254,63CP 63NOTE: 63, 127, 191 AND 255 FOR L INDICATE THE EASTERN EDGE OF THE MAP 6065140,11JR Z,CONT 60653254,127CP 127 6065540,7JR Z,CONT 60657254,191CP 191 6065940,3JR Z,CONT 60661254,255CP 255 60663192RET NZ 6066462,255CONTLD A,255 6066650,165,204LD (WRAPF),A 60669201RET 60670254,0FINDATCP 0 6067232,3JR NZ,AT1 6067462,7LD A,7P=BK,I=W 60676201RET 60677254,1AT1CP 1 6067932,3JR NZ,AT2 6068162,15LD A,15P=BL,I=W 60683201RET 60684254,4AT2CP 4 6068648,3JR NC,AT4 6068862,32LD A,32P=GR,I=BK 60690201RET 60691254,4AT4CP 4 6069332,3JR NZ,AT5 6069562,41LD A,41P=AQ,I=BL 60697201RET 60698254,5AT5CP 5 6070032,3JR NZ,C2 6070262,59LD A,59P=W,I=MG 60704201RET 60705254,69C2CP 69PLAYER1? 6070732,3JR NZ,C3 6070962,48LD A,48P=BK,I=Y 60711201RET 60712254,133C3CP 133PLAYER2? 6071432,3JR NZ,C4 6071662,16LD A,16P=BK,I=R 60718201RET 60719254,197CP 197PLAYER3? 6072132,3JR NZ,P1 6072362,56LD A,56P=BK,I=W 60725201RETprinted at 60721 in issue #5; two bytes at the previous line put it here *** #### 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: 173 lines carried both bytes and mnemonics and were cross-checked against each other. 2 lines could not be reconciled: the address, byte and mnemonic columns disagree, so the listing as printed cannot be correct at these points. Which column is at fault is noted in each case. - **60640**, should read `214,16` — 216 is RET C, a single byte; the parallel code at 60560 prints 214,16 and the address column requires two bytes here. Not covered by the correction in issue #6 - **60714**, printed as `JR NZ,C4` — the label C4 belongs on line 60719, which is printed without it; the jump itself is correct Anyone typing this listing in should expect to work through these before it will run, and should treat the surrounding code with some caution: where a listing has demonstrably been disturbed in one place, quieter faults elsewhere are plausible even though nothing here detected them.