04-07-2004, 06:00 PM
I was planning to make a RPG map making tool that you can scroll the map while editing it, but I ran into quite abit of a problem, it seems that some of the code for mouse displayer and screen scroller are in some sort of conflict somewhere in a memory buffer and I dont have a clue to how to make the nessessary changes to resolve that. So ill paste some of the code and see if anyone would like to resolve the conflict.
Do note, that its still abit messy at the moment as I was doing abit of copy and pasting the mouse and screen scrolling parts together...
Do note, that its still abit messy at the moment as I was doing abit of copy and pasting the mouse and screen scrolling parts together...
Code:
DEFINT A-Z
'$DYNAMIC
DECLARE SUB mouse (cx, dx, bx)
DECLARE SUB mouse2 (cx, dx, bx)
DECLARE SUB mousepointer (SW)
DIM SHARED a(9) 'Set up array for code
DEF SEG = VARSEG(a(0)) 'Get array segment (nnnn: )
' (two 8 bit)
FOR i = 0 TO 17 'length of DATA to
READ r 'read
POKE VARPTR(a(0)) + i, r 'into array/2 (nnnn:iiii) (one 8 bit)
NEXT i 'until 17
'**************************** Machine Code *********************************
DATA &HB8,&H00,&H00 : ' mov AX,[n] [Swap code-(L),(H)] in AX
DATA &H55 : ' push BP Save BP
DATA &H8B,&HEC : ' mov BP,SP Get BP to c Seg
DATA &HCD,&H33 : ' int 33 Interrupt 33
DATA &H92 : ' xchg AX,[reg] [Swap code-reg] in AX
DATA &H8B,&H5E,&H06 : ' mov BX,[BP+6] Point to (variable)
DATA &H89,&H07 : ' mov [BX],AX Put AX in (variable)
DATA &H5D : ' pop BP Restore BP
DATA &HCA,&H02,&H00 : ' ret 2 Far return
RANDOMIZE TIMER
'**************** Notes ***********************
' call MOUSE sub checks x,y of mouse pos and see if a button has
' been clicked.
' cx= is y pos of mouse when call MOUSE sub is called
' dx= is x pos of mouse when call MOUSE sub is called
' bx= is mouse button pressed?(0,1,2 or 3"
'****************************** Mouse set up ******************************
arr$(1) = "c14 u3f3bl6e3df2l4e"
arr$(2) = "c14 d3e3bl6f3uhulr4g"
arr$(3) = "c14 l3f3bu6g3re2d4h" ' just some pointer icons that change
arr$(4) = "c14 r3g3bu6f3lhlud4e" ' colors when clicked on to scroll the
arr$(5) = "c15 u3f3bl6e3df2l4e" ' map.
arr$(6) = "c15 d3e3bl6f3uhulr4g"
arr$(7) = "c15 l3f3bu6g3re2d4h"
arr$(8) = "c15 r3g3bu6f3lhlud4e"
1 DIM tile(119, 226)
2 DIM map(9999)
3 CLS
4 LOCATE 15, 1: INPUT "Enter size of map to create(156,156 is max)"; xmax, ymax
5 CLS
6 num = 0
7 filename$ = "maps\Wldmap" + LTRIM$(STR$(num)) + ".WLD"
8 ON ERROR GOTO 100
9 OPEN filename$ FOR INPUT AS #1
10 PRINT filename$ + " already exists."
11 CLOSE #1
12 num = num + 1
13 filename$ = "maps\Wldmap" + LTRIM$(STR$(num)) + ".WLD"
14 GOTO 9
15 PRINT "The filename will be "; filename$; "."
16 PRINT : PRINT
17 PRINT "Initializing "; filename$; " for editing"
18 td = 0
19 FOR y = 1 TO ymax
20 FOR x = 1 TO xmax
21 IF x = xmax THEN
PRINT #1, LTRIM$(STR$(td))
ELSE
PRINT #1, LTRIM$(STR$(td) + ",");
END IF
22 NEXT x
23 NEXT y
24 CLOSE #1
25 OPEN "TILEINFO.txt" FOR INPUT AS #2
26 FOR j = 0 TO 109
27 FOR i = 0 TO 224
28 INPUT #2, t: tile(j, i) = t
29 NEXT
30 NEXT
31 SCREEN 13
32 fx = 5: fx2 = 315: fy = 5: fy2 = 97
33 FOR d = 1 TO 5: LINE (fx, fy)-(fx2, fy2), 9, B
34 fx = fx - 1: fy = fy - 1: fx2 = fx2 + 1: fy2 = fy2 + 1: NEXT d
35 PSET (160, 5): DRAW arr$(1): PSET (160, 97): DRAW arr$(2)
36 PSET (5, 50): DRAW arr$(3): PSET (315, 50): DRAW arr$(4)
37 OPEN "MapData.txt" FOR INPUT AS #3
38 FOR i = 0 TO 9999
39 INPUT #3, m: map(i) = m: NEXT: GOSUB 200
40 CALL mousepointer(0)
41 CALL mousepointer(1)
42 CALL mousepointer(3)
43 CALL mouse(cx, dx, bx)
44 key$ = INKEY$: IF UCASE$(key$) = "q" THEN END
45 IF key$ = "4" OR cx >= 47 AND cx <= 53 AND dx >= 0 AND dx <= 5 AND bx = 1 THEN ' <
PSET (5, 50): DRAW arr$(7)
ELSE
PSET (5, 50): DRAW arr$(3)
END IF
46 IF key$ = "6" OR cx >= 47 AND cx <= 53 AND dx >= 315 AND dx <= 320 AND bx = 1 THEN ' >
PSET (315, 50): DRAW arr$(8)
ELSE
PSET (315, 50): DRAW arr$(4)
END IF
47 IF key$ = "8" OR cx >= 0 AND cx <= 5 AND dx >= 157 AND dx <= 163 AND bx = 1 THEN ' ^
PSET (160, 5): DRAW arr$(5)
ELSE
PSET (160, 5): DRAW arr$(1)
END IF
48 IF key$ = "4" OR cx >= 97 AND cx <= 101 AND dx >= 157 AND dx <= 163 AND bx = 1 THEN ' V
PSET (160, 97): DRAW arr$(6)
ELSE
PSET (160, 97): DRAW arr$(2)
END IF
49 LOCATE 14, 1: PRINT USING "Cx=### Dx=### Bx=###"; cx; dx; bx;
50 LOCATE 14, 23: PRINT "Key="; key$
FOR d = 1 TO 8
PSET (80 + (d * 10), 150): DRAW arr$(d): NEXT d
GOTO 43
END
'CALL mousepointer(2)
END
100 IF ERR = 53 THEN
OPEN filename$ FOR OUTPUT AS #1
RESUME 15
END IF
198 PRINT 'if unknown error occurs then display
PRINT "error"; ERR; "occured at line"; ERL: END 'error code no. and line no.
199 RESUME
200 DEF SEG = &HA000
201 hScroll = 0'These variables will keep track of
202 vScroll = 0'how far the screen has scrolled
203 verticalVal = vScroll
204 tileX = hScroll \ 15'Calculate all original values
205 tileY = verticalVal \ 15
206 mapElem = tileY * 20 + tileX
207 spriteX = hScroll MOD 15
208 spriteY = vScroll MOD 15
209 spriteElem = spriteY * 15 + spriteX
210 WAIT &H3DA, 8'Wait for vertical retrace
211 FOR screenY = 40 TO 130
212 offset& = screenY * 320& + 100
213 FOR screenX = 119 TO 229
214 POKE offset&, tile(map(mapElem), spriteElem)
215 offset& = offset& + 1
216 spriteElem = spriteElem + 1
217 IF spriteElem MOD 15 = 0 THEN
218 spriteElem = spriteElem - 15
219 mapElem = mapElem + 1
220 END IF
221 NEXT
222 verticalVal = verticalVal + 1
223 tileY = verticalVal \ 15
224 mapElem = tileY * 20 + tileX
225 spriteY = spriteY + 1
226 IF spriteY = 15 THEN spriteY = 0
227 spriteElem = spriteY * 15 + spriteX
228 NEXT
end
'****************************** SUBS **********************************************
'****** Note none of subs is on the same module ***********************************
REM $STATIC
SUB mouse (cx, dx, bx)
POKE VARPTR(a(4)), &H92 'Swap code,Get CX setup
CALL absolute(cx, VARPTR(a(0))) 'Run Code
cx = cx 'Adjust 25x80
POKE VARPTR(a(4)), &H91 'Swap code,Get DX setup
CALL absolute(dx, VARPTR(a(0))) 'Run Code
dx = dx / 2 'Adjust 25x80
POKE VARPTR(a(4)), &H93 'Swap code,Get BX setup
CALL absolute(bx, VARPTR(a(0))) 'Run Code
'Note :
'Remove the /8
'for graphics modes.
END SUB
SUB mouse2 (cx, dx, bx) 'Duplicate mouse call is for tile selector
POKE VARPTR(a(4)), &H92 'Swap code,Get CX setup
CALL absolute(cx, VARPTR(a(0))) 'Run Code
cx = cx / 16 'Adjust 25x80
POKE VARPTR(a(4)), &H91 'Swap code,Get DX setup
CALL absolute(dx, VARPTR(a(0))) 'Run Code
dx = dx / 16.5 'Adjust 25x80
POKE VARPTR(a(4)), &H93 'Swap code,Get BX setup
CALL absolute(bx, VARPTR(a(0))) 'Run Code
'Note :
'Remove the /8
'for graphics modes.
END SUB
SUB mousepointer (SW)
POKE VARPTR(a(0)) + 1, SW 'Swap code,Set AX = (SW)
CALL absolute(c, VARPTR(a(0))) 'Run Code
'Note:
'SW = 0-reset
'SW = 1-on
'SW = 2-off
'SW = 3-coordinates
END SUB