Seventh installment of the Z80 series, presenting the map-cursor and map-editor routine for CONQUEST. Covers PRCURS and PRCUR (cursor initialization and main loop), PIXLOC (screen address from XY coordinates), ATTR (attribute address calculation), PRCHA (print character), INTJOY (joystick-to-cursor translation), TRANS (cursor-to-map coordinate conversion), PUTX (place map element), DOIT (dispatch table using JP(HL)), and four scroll routines (SCROLL L/R/U/D). Full assembly listings.
We continue our discussion of routines from the game Conquest. Up to this point we have discussed in:
We continue with a map cursor. Whenever one uses a joystick (for that matter a mouse) to direct the movement of various units one needs a cursor to indicate the desired direction. We use a capitol X for the cursor symbol.
We need to store the screen coordinates of the cursor in two variables called Curx and Cury. The cursor should not run off the map or be allowed to run over the map coordinates which are down the left side and line 22 acrossed the bottom. Therefore, Curx can be from 1 to 31 (in Basic notation) and Cury from o to 21.
The input from this routine not only moves the cursor but also must determine when the joystick button has been pushed as well as interpret all the keyboard commands. Since the keyboard is interpreted differently for the game than in map drawing, 2 different print cursor routines are necessary. The simplest of the two is the one for the map editor which is given below and found in Conquest at 61018.
DOEQU 52388not printed as an EQU; taken from the operand at 61314
CURYEQU 52394not printed as an EQU; taken from the operands at 61023 and 61073
CURXEQU 52395not printed as an EQU; taken from the operand at 61020
MAPCOYEQU 52396not printed as an EQU; taken from the operand at 61274
MAPCOXEQU 52397not printed as an EQU; taken from the operand at 61285
6101862,1PRCURSLD A,1INITILIZE CURX AND CURY
6102050,171,204LD (CURX),A
6102350,170,204LD (CURY),A
61026205,63,236CALL PRMAPP
61029237,75,179,204PRCURLD BC,(CURY)THIS IS THE RETURN FOR REPEATS OF THE ROUTINE IN CASE THE INPUT WAS MERELY A MOVE OF THE CURSOR.
61033205,240,238CALL PIXLOCTRANSLATE THE X AND Y INTO THE FIRST PIXEL OF THE SCREEN FILE.
61036235EX DE,HL
6103762,88LD A,”X”
61039205,18,239CALL PRCHAPRINT THE CURSOR
61042205,255,238CALL ATTR
61045126LD A,(HL)
61046230,248AND 248SAVE THE PAPER COLOR
61048198,7ADD A,7MAKE THE INK WHITE.
61050119LD (HL),A
61051205,184,235CALL GETINP(SEE 2068 CODE BYTES #2 FOR THE ROUTINE.)
61054203,119BIT 6,A
6105632,39JR NZ,KEYBOARDA KEY WAS PRESSED.
61058203,127BIT 7,A
6106040,5JR Z,MOVE
61062205,130,239CALL DOIT
6106524,218JR PRCUR
61067229MOVEPUSH HLOLD ATTR ADDR
61068213PUSH DEOLD SCR ADDR
61069197PUSH BCOLD CUR POSN
61070205,48,239CALL INTJOYCHANGE BC TO NEW POSITION OF CURSOR
61073237,67,170,204LD (CURY),BCSAVE NEW COORDINATES OF CURSOR
61077193POP BC
61078205,90,239CALL TRANS
61081205,26,236CALL PMO
61084126LD A,(HL)ERASE OLD CURSOR
61085209POP DEREPRINT OLD POSITION. SEE #5 AND #6 FOR ROUTINE.
61086205,119,237CALL PRUDG
61089126LD A,(HL)
61090205,254,236CALL FINDAT
61093225POP HL
61094119LD (HL),A
6109524,189JR PRCUR
61097254,99KBCP 99“c”
6109932,5JR NZ,KBF
61101205,167,240CALL CENCURIN EDIT MODE, IT CENTERS MAP ON THE CURSOR. IN GAME MODE, ON THE UNIT TO BE MOVED.
6110424,179JR PRCUR
61106254,102KBFCP 102“f”
6110832,5JR NZ,KBGF,G,T AND V ARE THE 4 SCROLLS
61110205,35,238CALL SCROLL
6111324,170JR PRCUR
61115254,103KBGCP 103“g”
6111732,5JR NZ,KBI
61119205,53,238CALL SCROLR
6112224,161JR PRCUR
61124254,105KBICP 105“i”
6112632,5JR NZ,KBM
61128205,244,246CALL IDENTIFY
6113124,152JR PRCUR
61133254,109KBMCP 109“m”
61135200RET ZM AND Q RETURN
61136254,113CP 113“q”
61138200RET Z
61139254,116CP 116“t”
6114132,5JR NZ,KBV
61143205,78,238CALL SCROLU
6114624,137JR PRCUR
61148254,118KBVCP 118“v”
6115032,5JR NZ,KBA
61152205,63,238CALL SCROLD
6115524,128JR PRCUR
61157254,97KBACP 97“a”
61159194,101,238JP PRCURIF MORE KEYS NEED TO BE READ THEY WOULD BE INSERTED HERE.
61162205,120,240CALL WORLD
61165195,101,238JP PRCUR
61168120PIXLOCLD A,B
61169230,248AND 248
61171198,64ADD A,64
61173103LD H,A
61174120LD A,B
61175230,7AND 7
6117715RRCA
6117815RRCA
6117915RRCA
61180129ADD A,C
61181111LD L,AHL NOW SCREEN FILE ADDRESS OF BC COORDINATES.
61182201RET
61183120ATTRLD A,B
61184203,47SRA A
61186203,47SRA A
61188203,47SRA A
61190198,88ADD A,88
61192103LD H,A
61193120LD A,B
61194230,7AND 7
6119615RRCA
6119715RRCA
6119815RRCA
61199129ADD A,C
61200111LD L,AHL NOW ATTR ADDR OF BC
61201201RET
61202197PRACHAPUSH BC
61203229PUSH HL
61204213PUSH DE
6120538,0LD H,0
61207167AND A
6120823RLA
6120923RLA
61210203,20RL H
6121223RLA
61213203,20RL H
61215111LD L,A
61216124LD A,H
61217198,60ADD A,60
61219103LD H,AHL NOW AT PIXELS FOR CHARACTER
612206,8LD B,8
61222126PRCLD A,(HL)
6122318LD (DE),A
6122435INC HL
6122520INC D
6122616,250DJNZ PRC
61228209POP DE
61229225POP HL
61230193POP BC
61231201RET
61232203,71INTJOYBIT 0,A
6123440,1JR Z,IJ1
612365DEC B
61237203,79IJ1BIT 1,A
6123940,1JR Z,IJ2
612414INC B
61242203,87IJ2BIT 2,A
6124440,1JR Z,IJ3
6124613DEC C
61247203,95IJ3BIT 3,A
6124940,1JR Z,IJ4
6125112INC CNOW CHECK BC TO MAKE SURE NOT OFF SCREEN AS DISCUSSED ABOVE
61252120IJ4LD A,B
61253254,255CP 255
6125532,1JR NZ,IJ5
612575INC B
61258254,22IJ5CP 22
6126032,1JR NZ,IJ6
612624DEC B
61263121IJ6LD A,C
61264254,0CP 0
6126632,1JR NZ,IJ7
6126812INC C
61269254,32IJ7CP 32
61271192RET NZ
6127213DEC C
61273201RET
6127458,172,204TRANSLD A,(MAPCOY)
61277129ADD A,C
61278254,65CP 65
6128056,2JR C,TR
61282214,64SUB 64
6128479TRLD C,A
6128558,173,204LD A,(MAPCOX)
61288128ADD A,B
61289254,65CP 65
6129156,2JR C,TR1
61293214,64SUB 64
6129571LD B,ABC NOW IN MAPCOORDINATES
61296201RET
61297205,90,239PUTXCALL TRANS
61300205,26,236CALL PMO
6130358,26,236LD A,(DO)
61306205,7,241CALL SETST
61309216RET C
61310119LD (HL),A
61311195,63,236JP PRMAPP
6131458,164,204DOITLD A,(DO)
61317254,0CP 0
61319200RET Z
6132017,158,239LD DE,TABLE
61323254,6CP 6
6132556,9JR C,D1
61327214,5SUB 5
6132938,0LD H,0
61331167AND A
6133223RLA
61333111LD L,A
6133425ADD HL,DE
61335235D1EX DE,HL
6133626LD A,(DE)
61337111LD L,A
6133819INC DE
6133926LD A,(DE)
61340103LD H,A
61341233JP (HL)
61342113,239TABLEDEFW PUTX
61344168,239DEFW BLOTCH
61346168,239DEFW BLOTCH
61348218,240DEFW GROW
61350218,240DEFW GROW