2 'Descp.: A Mode "X" demonstration
\r
3 'Author: Matt Pritchard
\r
4 'Date: 14 April, 1993
\r
6 DECLARE SUB DEMO.RES (Mode%, Xmax%, Ymax%)
\r
7 DECLARE SUB ERROR.OUT (Message$)
\r
8 DECLARE FUNCTION GET.KEY% ()
\r
9 DECLARE SUB LOAD.SHAPES ()
\r
10 DECLARE SUB PAGE.DEMO ()
\r
11 DECLARE SUB PRINT.TEXT (Text$, Xpos%, Ypos%, ColorF%, ColorB%)
\r
12 DECLARE SUB TPRINT.TEXT (Text$, Xpos%, Ypos%, ColorF%)
\r
17 ImgData AS STRING * 512
\r
31 CONST MaxShapes = 32
\r
33 REM $INCLUDE: 'UTILS.BI'
\r
34 REM $INCLUDE: 'MODEX.BI'
\r
36 DIM SHARED Img(32) AS ShapeType
\r
37 COMMON SHARED Img() AS ShapeType
\r
44 CALL DEMO.RES(Mode320x200, 320, 200)
\r
45 CALL DEMO.RES(Mode320x400, 320, 400)
\r
47 CALL DEMO.RES(Mode360x200, 360, 200)
\r
48 CALL DEMO.RES(Mode360x400, 360, 400)
\r
50 CALL DEMO.RES(Mode320x240, 320, 240)
\r
51 CALL DEMO.RES(Mode320x480, 320, 480)
\r
53 CALL DEMO.RES(Mode360x240, 360, 240)
\r
54 CALL DEMO.RES(Mode360x480, 360, 480)
\r
59 DOS.PRINT "THIS MODE X DEMO IS FINISHED"
\r
62 SUB DEMO.RES (Mode, Xmax, Ymax)
\r
64 IF SET.MODEX%(Mode) = 0 THEN
\r
65 ERROR.OUT "Unable to SET_MODEX" + STR$(Mode)
\r
77 DRAW.LINE X1 + Z, Y1 + Z, X2 - Z, Y1 + Z, Colr
\r
78 DRAW.LINE X1 + Z, Y1 + Z, X1 + Z, Y2 - Z, Colr
\r
79 DRAW.LINE X1 + Z, Y2 - Z, X2 - Z, Y2 - Z, Colr
\r
80 DRAW.LINE X2 - Z, Y1 + Z, X2 - Z, Y2 - Z, Colr
\r
86 FOR X = 0 TO XChars - 1
\r
87 TGPRINTC 48 + ((X + 1) MOD 10), X * 10 + 1, 1, 9 + ((X \ 8) MOD 7)
\r
88 DRAW.LINE X * 10 + 9, 0, X * 10 + 9, 3, 15
\r
91 FOR Y = 0 TO YChars - 1
\r
92 TGPRINTC 48 + ((Y + 1) MOD 10), 1, Y * 10 + 1, 9 + ((Y \ 10) MOD 7)
\r
93 DRAW.LINE 0, Y * 10 + 9, 3, Y * 10 + 9, 15
\r
100 SET.DAC.REGISTER 64 + X, N, N, N
\r
101 SET.DAC.REGISTER 128 + X, 0, N, N
\r
103 DRAW.LINE 103 - X, 60, 40 + X, 123, 64 + X
\r
104 DRAW.LINE 40, 60 + X, 103, 123 - X, 128 + X
\r
107 TPRINT.TEXT "LINE TEST", 37, 130, c.BLUE
\r
111 FILL.BLOCK 120, Y, 120 + X, Y + Gap, 64 + X
\r
112 FILL.BLOCK 140 - (15 - X), Y, 150 + X, Y + Gap, 230 + X
\r
113 FILL.BLOCK 170 - (15 - X), Y, 170, Y + Gap, 128 + X
\r
117 TPRINT.TEXT "FILL TEST", 110, 46, c.GREEN
\r
120 FOR X = 190 TO 250 STEP 2
\r
121 FOR Y = 60 TO 122 STEP 2
\r
122 SET.POINT X, Y, X + Y + X + Y
\r
126 TPRINT.TEXT "PIXEL TEST", 182, 130, c.RED
\r
128 FOR X = 190 TO 250 STEP 2
\r
129 FOR Y = 60 TO 122 STEP 2
\r
130 IF READ.POINT(X, Y) <> ((X + Y + X + Y) AND 255) THEN
\r
131 ERROR.OUT "READ.PIXEL Failure"
\r
138 Msg$ = " This is a MODE X demo "
\r
139 PRINT.TEXT Msg$, XCenter - (LEN(Msg$) * 4), 20, c.bRED, c.BLUE
\r
140 Msg$ = "Screen Resolution is by "
\r
141 Xp = XCenter - (LEN(Msg$) * 4)
\r
142 PRINT.TEXT Msg$, Xp, 30, c.bGREEN, c.BLACK
\r
144 PRINT.TEXT LTRIM$(STR$(Xmax)), Xp + 8 * 21, 30, c.bPURPLE, c.BLACK
\r
145 PRINT.TEXT LTRIM$(STR$(Ymax)), Xp + 8 * 28, 30, c.bWHITE, c.BLACK
\r
148 SET.DAC.REGISTER 230 + X, 63 - X * 4, 0, 15 + X * 3
\r
149 DRAW.LINE 30 + X, Ymax - 6 - X, Xmax - 20 - X, Ymax - 6 - X, 230 + X
\r
151 TPRINT.TEXT "Press <ANY KEY> to Continue", XCenter - (26 * 4), Ymax - 18, c.YELLOW
\r
154 IF X = KyESC THEN ERROR.OUT "ABORT"
\r
158 SUB ERROR.OUT (Message$)
\r
178 DIM Grid(1 TO 32, 1 TO 32)
\r
180 FOR Shape = 0 TO MaxShapes - 1
\r
188 Style = RANDOM.INT(6)
\r
189 Colour = 1 + RANDOM.INT(15)
\r
193 CASE 0: ' Solid Box
\r
196 xWidth = 3 + RANDOM.INT(30)
\r
197 yWidth = 3 + RANDOM.INT(30)
\r
198 LOOP UNTIL ((xWidth * yWidth) <= 512)
\r
200 FOR Y = 1 TO yWidth
\r
201 FOR X = 1 TO xWidth
\r
202 Grid(X, Y) = Colour
\r
206 CASE 1: ' Hollow Box
\r
209 xWidth = 5 + RANDOM.INT(28)
\r
210 yWidth = 5 + RANDOM.INT(28)
\r
211 LOOP UNTIL ((xWidth * yWidth) <= 512)
\r
213 FOR Y = 1 TO yWidth
\r
214 FOR X = 1 TO xWidth
\r
215 Grid(X, Y) = Colour
\r
219 HollowX = 1 + RANDOM.INT(xWidth \ 2 - 1)
\r
220 HollowY = 1 + RANDOM.INT(yWidth \ 2 - 1)
\r
222 FOR Y = HollowY + 1 TO yWidth - HollowY
\r
223 FOR X = HollowX + 1 TO xWidth - HollowX
\r
228 CASE 2: ' Solid Diamond
\r
230 xWidth = 3 + 2 * RANDOM.INT(10)
\r
232 Centre = xWidth \ 2
\r
234 FOR Y = 0 TO Centre
\r
236 Grid(Centre - X + 1, Y + 1) = Colour
\r
237 Grid(Centre + X + 1, Y + 1) = Colour
\r
238 Grid(Centre - X + 1, yWidth - Y) = Colour
\r
239 Grid(Centre + X + 1, yWidth - Y) = Colour
\r
244 CASE 3: ' Hollow Diamond
\r
247 xWidth = 3 + 2 * RANDOM.INT(10)
\r
249 Centre = xWidth \ 2
\r
250 sWidth = RANDOM.INT(Centre)
\r
252 FOR Y = 0 TO Centre
\r
254 IF X + (Centre - Y) >= sWidth THEN
\r
255 Grid(Centre - X + 1, Y + 1) = Colour
\r
256 Grid(Centre + X + 1, Y + 1) = Colour
\r
257 Grid(Centre - X + 1, yWidth - Y) = Colour
\r
258 Grid(Centre + X + 1, yWidth - Y) = Colour
\r
265 xWidth = 7 + 2 * RANDOM.INT(8)
\r
267 Centre = 1 + xWidth \ 2
\r
269 FOR Y = 1 TO yWidth
\r
270 FOR X = 1 TO xWidth
\r
271 D = SQR(((Centre - X) * (Centre - X)) + ((Centre - Y) * (Centre - Y)))
\r
272 IF D < Centre THEN Grid(X, Y) = 150 + Colour * 2 + D * 3
\r
279 xWidth = 7 + 2 * RANDOM.INT(8)
\r
281 Centre = 1 + xWidth \ 2
\r
282 sWidth = RANDOM.INT(xWidth)
\r
284 FOR Y = 1 TO yWidth
\r
285 FOR X = 1 TO xWidth
\r
286 D = SQR(((Centre - X) * (Centre - X)) + ((Centre - Y) * (Centre - Y)))
\r
287 IF D < Centre AND D >= sWidth THEN Grid(X, Y) = 150 + Colour * 2 + D * 3
\r
293 Img(Shape).xWidth = xWidth
\r
294 Img(Shape).yWidth = yWidth
\r
296 A$ = STRING$(xWidth * yWidth, nil)
\r
299 FOR Y = 1 TO yWidth
\r
300 FOR X = 1 TO xWidth
\r
301 MID$(A$, c, 1) = CHR$(Grid(X, Y))
\r
306 Img(Shape).ImgData = A$
\r
315 CONST MaxSprites = 64
\r
317 DIM Obj(MaxSprites) AS Sprite
\r
318 DIM LastX(MaxSprites, 1), LastY(MaxSprites, 1)
\r
321 ScreenX = 360: ScreenY = 240
\r
323 IF SET.VGA.MODEX%(Mode320x200, ScreenX, ScreenY, 3) = 0 THEN
\r
324 ERROR.OUT "Unable to SET_VGA_MODEX" + STR$(Mode)
\r
329 CLEAR.VGA.SCREEN c.BLACK
\r
331 PRINT.TEXT "This is a Test of the Following Functions:", 10, 9, c.bWHITE, c.BLACK
\r
333 DRAW.LINE 10, 18, 350, 18, c.YELLOW
\r
334 PRINT.TEXT "SET_ACTIVE_PAGE", 10, 20, c.bBLUE, c.BLACK
\r
335 PRINT.TEXT "SET_DISPLAY_PAGE", 10, 30, c.GREEN, c.BLACK
\r
336 PRINT.TEXT "SET_DAC_REGISTER", 10, 40, c.RED, c.BLACK
\r
337 PRINT.TEXT "CLEAR_VGA_SCREEN", 10, 50, c.CYAN, c.BLACK
\r
339 PRINT.TEXT "TDRAW_BITMAP", 10, 60, c.PURPLE, c.BLACK
\r
340 PRINT.TEXT "COPY_PAGE", 10, 70, c.GREEN, c.BLACK
\r
341 PRINT.TEXT "COPY_BITMAP", 10, 80, c.CYAN, c.BLACK
\r
343 PRINT.TEXT "GPRINTC", 10, 90, c.BLUE, c.BLACK
\r
344 PRINT.TEXT "TGPRINTC", 10, 100, c.GREEN, c.BLACK
\r
345 PRINT.TEXT "SET_WINDOW", 10, 110, c.RED, c.BLACK
\r
347 PRINT.TEXT "VIRTUAL SCREEN SIZES", 190, 20, c.bBLUE, c.BLACK
\r
348 PRINT.TEXT " SMOOTH SCROLLING", 190, 30, c.GREEN, c.BLACK
\r
349 PRINT.TEXT " SPRITE ANIMATION", 190, 40, c.CYAN, c.BLACK
\r
350 PRINT.TEXT " PAGE FLIPPING", 190, 50, c.RED, c.BLACK
\r
351 PRINT.TEXT " COLOR CYCLING", 190, 60, c.PURPLE, c.BLACK
\r
355 SET.DAC.REGISTER 50 + X, 3 + X, 0, 60 - X
\r
356 SET.DAC.REGISTER 150 + X, 3 + X, 0, 60 - X
\r
360 FOR X = 0 TO ScreenX \ 2
\r
361 DRAW.LINE ScreenX \ 2 - 1, ScreenY \ 4, X, ScreenY - 1, c + 50
\r
362 DRAW.LINE ScreenX \ 2, ScreenY \ 4, ScreenX - X - 1, ScreenY - 1, c + 50
\r
364 IF c = 0 OR c = 60 THEN DC = -DC
\r
367 TPRINT.TEXT "Press <ANY KEY> to Continue", 72, 190, c.bWHITE
\r
368 TPRINT.TEXT "< > = Faster < > = Slower", 72, 204, c.bGREEN
\r
369 TPRINT.TEXT "< > = Fewer Shapes < > = More Shapes", 32, 218, c.bCYAN
\r
371 TGPRINTC 43, 80, 204, c.YELLOW
\r
372 TGPRINTC 45, 200, 204, c.YELLOW
\r
374 TGPRINTC 25, 40, 218, c.YELLOW
\r
375 TGPRINTC 24, 200, 218, c.YELLOW
\r
380 FOR X = 1 TO MaxSprites
\r
382 Obj(X).XDir = RANDOM.INT(7) - 3
\r
383 Obj(X).YDir = RANDOM.INT(7) - 3
\r
384 LOOP WHILE (Obj(X).XDir = 0 AND Obj(X).YDir = 0)
\r
386 Obj(X).Shape = X MOD MaxShapes
\r
388 SpriteX = Img(Obj(X).Shape).xWidth
\r
389 SpriteY = Img(Obj(X).Shape).yWidth
\r
391 Obj(X).Xpos = 1 + RANDOM.INT(ScreenX - SpriteX - 2)
\r
392 Obj(X).Ypos = 1 + RANDOM.INT(ScreenY - SpriteY - 2)
\r
394 LastX(X, 0) = Obj(X).Xpos
\r
395 LastX(X, 1) = Obj(X).Xpos
\r
396 LastY(X, 0) = Obj(X).Ypos
\r
397 LastY(X, 1) = Obj(X).Ypos
\r
411 SetColor = 3: SDir = 1
\r
412 PrevColor = 0: PDir = 1
\r
414 VisObjects = MaxSprites \ 2
\r
421 SET.ACTIVE.PAGE CurrentPage
\r
425 FOR X = 1 TO LastObjects(CurrentPage)
\r
427 X1 = LastX(X, CurrentPage) AND &HFFFC
\r
428 Y1 = LastY(X, CurrentPage)
\r
429 X2 = ((LastX(X, CurrentPage) + Img(Obj(X).Shape).xWidth)) OR 3
\r
430 Y2 = Y1 + Img(Obj(X).Shape).yWidth - 1
\r
432 COPY.BITMAP 2, X1, Y1, X2, Y2, CurrentPage, X1, Y1
\r
438 FOR X = 1 TO VisObjects
\r
440 SpriteX = Img(Obj(X).Shape).xWidth
\r
441 SpriteY = Img(Obj(X).Shape).yWidth
\r
446 NewX = Obj(X).Xpos + Obj(X).XDir
\r
447 IF NewX < 0 OR NewX + SpriteX > ScreenX THEN
\r
448 Obj(X).XDir = -Obj(X).XDir
\r
449 IF RANDOM.INT(20) = 1 THEN
\r
451 Obj(X).XDir = RANDOM.INT(7) - 3
\r
452 Obj(X).YDir = RANDOM.INT(7) - 3
\r
453 LOOP WHILE (Obj(X).XDir = 0 AND Obj(X).YDir = 0)
\r
457 Obj(X).Xpos = Obj(X).Xpos + Obj(X).XDir
\r
460 NewY = Obj(X).Ypos + Obj(X).YDir
\r
461 IF NewY < 0 OR NewY + SpriteY > ScreenY THEN
\r
462 Obj(X).YDir = -Obj(X).YDir
\r
463 IF RANDOM.INT(20) = 1 THEN
\r
465 Obj(X).XDir = RANDOM.INT(7) - 3
\r
466 Obj(X).YDir = RANDOM.INT(7) - 3
\r
467 LOOP WHILE (Obj(X).XDir = 0 AND Obj(X).YDir = 0)
\r
471 Obj(X).Ypos = Obj(X).Ypos + Obj(X).YDir
\r
475 TDRAW.BITMAP Img(Obj(X).Shape), Obj(X).Xpos, Obj(X).Ypos, SpriteX, SpriteY
\r
477 LastX(X, CurrentPage) = Obj(X).Xpos
\r
478 LastY(X, CurrentPage) = Obj(X).Ypos
\r
482 LastObjects(CurrentPage) = VisObjects
\r
484 ' Pan Screen Back & Forth
\r
486 ViewCnt = ViewCnt + 1
\r
487 IF ViewCnt >= ViewMax THEN
\r
488 ViewX = ViewX + ViewXD
\r
489 IF ViewX = 0 OR ViewX = 39 THEN ViewXD = -ViewXD
\r
491 ViewY = ViewY + ViewYD
\r
492 IF ViewY = 0 OR ViewY = 39 THEN ViewYD = -ViewYD
\r
495 SET.WINDOW CurrentPage, ViewX, ViewY
\r
499 SET.DISPLAY.PAGE CurrentPage
\r
504 SET.DAC.REGISTER 50 + PrevColor, 3 + PrevColor, 0, 60 - PrevColor
\r
505 SET.DAC.REGISTER 50 + SetColor, SetColor, 10, 63 - SetColor
\r
507 SET.DAC.REGISTER 150 + PrevColor, 3 + PrevColor, 0, 60 - PrevColor
\r
508 SET.DAC.REGISTER 150 + SetColor, 63, 63, SetColor
\r
510 SetColor = SetColor + SDir
\r
511 IF SetColor = 60 OR SetColor = 0 THEN SDir = -SDir
\r
513 PrevColor = PrevColor + PDir
\r
514 IF PrevColor = 60 OR PrevColor = 0 THEN PDir = -PDir
\r
516 CurrentPage = 1 - CurrentPage
\r
518 Code = SCAN.KEYBOARD
\r
520 IF Code = False THEN GOTO DRAW.LOOP
\r
522 IF Code = KyPlus THEN
\r
523 IF ViewMax < 12 THEN ViewMax = ViewMax + 1
\r
527 IF Code = KyMinus THEN
\r
528 IF ViewMax > 1 THEN ViewMax = ViewMax - 1
\r
529 IF ViewCnt >= ViewMax THEN ViewCnt = 0
\r
533 IF Code = KyUp THEN
\r
534 IF VisObjects < MaxSprites THEN VisObjects = VisObjects + 1
\r
538 IF Code = KyDown THEN
\r
539 IF VisObjects > 1 THEN VisObjects = VisObjects - 1
\r
546 SUB PRINT.TEXT (Text$, Xpos, Ypos, ColorF, ColorB)
\r
548 IF LEN(Text$) = 0 THEN EXIT SUB
\r
550 PRINT.STR SSEG(Text$), SADD(Text$), LEN(Text$), Xpos, Ypos, ColorF, ColorB
\r
555 SUB TPRINT.TEXT (Text$, Xpos, Ypos, ColorF)
\r
557 IF LEN(Text$) = 0 THEN EXIT SUB
\r
559 TPRINT.STR SSEG(Text$), SADD(Text$), LEN(Text$), Xpos, Ypos, ColorF
\r