'=========================================================================== ' Subject: SPINNING DOTS Date: 06-15-96 (01:37) ' Author: Dave Navarro, Jr. Code: PB ' Origin: comp.lang.basic.misc Packet: GRAPHICS.ABC '=========================================================================== ' Spinning Dots ' Adapted from original Turbo Pascal source of unknown origin ' Converted to PowerBASIC 3.2 by Dave Navarro, Jr. ' Donated to the Public Domain $DIM ALL DIM inPort1 AS SHARED WORD DIM nDots AS SHARED WORD nDots = 21 TYPE Rec x AS WORD y AS WORD sx AS WORD sy AS WORD END TYPE DIM dot( 0 TO nDots - 1 ) AS SHARED Rec SUB waitRetrace() ! mov dx, inPort1; {find crt status REG( INPUT port #1 ) } L1: ! IN al, dx; ! test al, 8; ! jnz L1; {wait FOR no v retrace} L2: ! IN al, dx; ! test al, 8; ! jz L2; {wait FOR v retrace} END SUB %tableWriteIndex = &H3C8 %tableDataRegister = &H3C9 SUB setColor( BYVAL colr AS BYTE, BYVAL r AS BYTE, BYVAL g AS BYTE, BYVAL b AS BYTE ) ! mov dx, %tableWriteIndex ! mov al, colr ! OUT dx, al ! inc dx ! mov al, r ! OUT dx, al ! mov al, g ! OUT dx, al ! mov al, b ! OUT dx, al END SUB 'plot a pixel in mode 13h SUB plot( BYVAL x AS WORD, BYVAL y AS WORD ) ! mov si, y; y ! mov di, x; x ! mov ax, &HA000 ! mov es, ax ! mov ax, 320 ! mul si ! add di, ax ! mov al, es: [di] ! NOT al ! mov es: [di], al END SUB SUB plot4( BYVAL x AS WORD, BYVAL y AS WORD ) DIM f AS WORD f = 60 plot x + f, y plot 199 + f-x, 199-y plot 199 + f-y, x plot y+f, 199-x END SUB SUB click() ! mov dx, &H61 ! IN al, dx ! xor al, 2 ! OUT dx, al END SUB FUNCTION colorFn( BYVAL x AS WORD ) AS BYTE colorFn = 63 - ( ABS( 100 - x ) / 2 ) END FUNCTION SUB moveDots() DIM i AS INTEGER FOR i = 0 TO nDots - 1 plot4 dot(i).x, dot(i).y INCR dot(i).x, dot(i).sx INCR dot(i).y, dot(i).sy IF dot(i).x > 200 THEN dot(i).sx = -dot(i).sx INCR dot(i).x, dot(i).sx click END IF IF dot(i).y > 199 THEN dot(i).sy = -dot(i).sy INCR dot(i).y, dot(i).sy click END IF plot4 dot(i).x, dot(i).y NEXT waitRetrace waitRetrace waitRetrace setcolor 255, colorFn( dot(0).x ), colorFn( dot(3).x ), colorFn( dot(6).x ) END SUB SUB drawdots() DIM i AS INTEGER FOR i = 0 TO nDots - 1 plot4 dot(i).x, dot(i).y NEXT END SUB SUB initDots() DIM i AS INTEGER, j AS WORD, K AS WORD j = 1 k = 1 FOR i = 0 TO nDots - 1 dot(i).x = 100 dot(i).y = 99 dot(i).sx = j dot(i).sy = k INCR j IF j > = k THEN j = 1 INCR k END IF NEXT END SUB FUNCTION readKey() AS STRING readKey = INKEY$ END FUNCTION FUNCTION keyPressed() AS WORD keyPressed = INSTAT < > 0 END FUNCTION DEF SEG = &H40 inPort1 = PEEKI( &H63 ) + 6 DEF SEG OUT &H61, INP( &H61 ) AND ( NOT 1 ) setcolor 255, 60, 60, 63 initDots ASM mov ax, &H13; ASM INT &H10; drawDots DO moveDots LOOP UNTIL keyPressed ReadKey drawDots ASM mov ax, 3 ASM INT &H10 END