Hi

Well, the code was a sort of 'proof of concept' to test if it is possible to make reasonable sprites in BASIC, and within limits this seems to be the case.

The main trick for speeding up the code is to avoid arrays if possible and to precalculate everything once before using the results in the main loop and plot routine. Common sense really, and it improves the speed by about 50%! You also have to rewrite a few address specifications to get them to work with ZZZIP. All peeking and poking is done using speek/spoke. This minimizes the limitations from ZZZIPs integer code and results in very fast code in ZZZIP.

The code around line 7000 is just there in case you want to implement some code to react to specific events. In the code example below, there are no such events, but you might implement a collision check or whatever, and put it there.

Anyway, here is the BASIC code, if you feel like trying it out.

regards

Jesper

1 PROGRAM "spr_test.bas"

2 !

5 TEXT 80

10 NUMERIC GFX1(1 TO 9) , OFFX1 (1 TO 9,0 TO

, OFFX2 (1 TO 9,0 TO

20 NUMERIC OX,OY,ODX,ODY,OHGT,OWID

30 NUMERIC I,J,CL,ZX,ZY,M1,M2,CH,KOX,DWID,DHGT,SP

40 NUMERIC LPTLOW,LPTHIGH,LPT,LBLOCK

50 NUMERIC LD1LOW,LD1HIGH,LD1(1 TO 2),LD1PAGE(1 TO 2)

60 NUMERIC LD2LOW,LD2HIGH,LD2(1 TO 2),LD2PAGE(1 TO 2)

65 STRING T$*1,ESC$*1,LEFT$*1,RIGHT$*1,UP$*1,DOWN$*1,T1$

70 LET WID=20:LET HGT=10:LET LBLOCK=15

80 LET ODX=1:LET ODY=0:LET OHGT=9:LET OWID=8:LET SP=4

81 LET OX=1:LET OY=1

99 !

100 CALL INIT_VARS

110 CALL INIT_VPAGES

998 LET T1$=TIME$

999 !

1000 DO

1005 IF GET_EVENT THEN CALL EVENT_HANDLER

1010 LET T$=INKEY$

1012 IF T$<>"" THEN

1015 SELECT T$

1020 CASE ESC$

1021 PRINT T1$,TIME$

1025 EXIT DO

1030 CASE LEFT$

1035 LET ODX=MAX(ODX-1,-SP)

1040 CASE RIGHT$

1045 LET ODX=MIN(ODX+1,SP)

1050 CASE UP$

1055 LET ODY=MAX(ODY-1,-SP)

1057 CASE DOWN$

1060 LET ODY=MIN(ODY+1,SP)

1065 END SELECT

1070 END IF

1075 DISPLAY #CH:AT LBLOCK FROM 1 TO HGT

1080 LET CH=1-(CH=1)

1090 CALL PLOT_OBJ

1095 LOOP

1105 END

1199 !

6000 DEF PLOT_OBJ

6001 CLEAR #CH

6005 LET ZX=MIN(DWID-OWID+1,MAX(1,OX+ODX))

6010 LET ZY=MIN(DHGT-OHGT+1,MAX(1,OY+ODY))

6015 LET OX=ZX:LET OY=ZY

6016 IF OY>(DHGT-OHGT) OR OY=1 THEN LET ODY=0

6017 IF OX>(DWID-OWID) OR OX=1 THEN LET ODX=0

6020 LET CL=IP((OX-1)/8)+WID*ZY-WID

6021 LET KOX=MOD(OX-1,8)

6022 FOR K=1 TO OHGT

6023 LET CLX=LD2(CH)+CL+(K-1)*WID

6025 LET M1=OFFX1(K,KOX)

6027 LET M2=OFFX2(K,KOX)

6035 SPOKE LD2PAGE(CH),CLX,M1

6040 SPOKE LD2PAGE(CH),CLX+1,M2

6045 NEXT

6050 END DEF

6099 !

6100 DEF GETLPT

6105 LET LPTLOW=SPEEK(255,16372)

6110 LET LPTHIGH=SPEEK(255,16373)

6115 LET LPT=LPTLOW+MOD(LPTHIGH*128+LPTHIGH*128,16384)

6120 END DEF

6199 !

6200 DEF GETLD1

6205 LET LD1LOW=SPEEK(255,LPT+16*LBLOCK+4)

6210 LET LD1HIGH=SPEEK(255,LPT+16*LBLOCK+5)

6215 LET LD1PAGE(CH)=252+IP((LD1HIGH*128)/8192)

6220 LET LD1(CH)=LD1LOW+MOD(LD1HIGH*128+LD1HIGH*128,16384)

6225 END DEF

6299 !

6300 DEF GETLD2

6305 LET LD2LOW=SPEEK(255,LPT+16*LBLOCK+6)

6310 LET LD2HIGH=SPEEK(255,LPT+16*LBLOCK+7)

6315 LET LD2PAGE(CH)=252+IP((LD2HIGH*128)/8192)

6320 LET LD2(CH)=LD2LOW+MOD(LD2HIGH*128+LD2HIGH*128,16384)

6325 END DEF

6399 !

7000 DEF GET_EVENT

7005 LET GET_EVENT=0

7010 END DEF

7099 !

7100 DEF EVENT_HANDLER

7105 PRINT "Event! ";

7110 END DEF

8099 !

9000 DEF INIT_VARS

9005 RESTORE 9500

9010 FOR I=1 TO 9

9015 READ GFX1(I)

9020 NEXT

9025 FOR I=1 TO OHGT

9030 FOR J=0 TO 8

9033 LET OFFX1(I,J)=IP(GFX1(I)/2^J)

9036 LET OFFX2(I,8-J)=MOD(GFX1(I)*2^J-(2^(8-J)-1)*256,256)

9040 NEXT

9045 NEXT

9050 LET ESC$=CHR$(27):LET LEFT$=CHR$(184):LET RIGHT$=CHR$(188):LET UP$=CHR$(176):LET DOWN$=CHR$(180)

9055 LET DWID=WID*8:LET DHGT=HGT*9

9090 END DEF

9099 !

9100 DEF INIT_VPAGES

9105 SET VIDEO MODE 15

9110 SET VIDEO COLOUR 0

9115 SET VIDEO X WID

9120 SET VIDEO Y HGT

9125 OPEN #1:"VIDEO:"

9130 OPEN #2:"VIDEO:"

9133 CALL GETLPT

9135 FOR CH=1 TO 2

9140 SET #CH:PALETTE RED,GREEN,YELLOW,BLUE,MAGENTA,WHITE,BLACK,243

9145 SET #CH:BIAS 168

9150 DISPLAY #CH:AT LBLOCK FROM 1 TO HGT

9155 CALL GETLD1:CALL GETLD2

9160 NEXT

9165 LET CH=1

9170 SET STATUS OFF

9175 CLEAR SCREEN

9180 END DEF

9199 !

9500 DATA 255,129,129,129,129,129,129,129,255