VERA PALLETTE UPDATE USING VPOKE.

All aspects of programming on the Commander X16.
User avatar
ahenry3068
Posts: 1132
Joined: Tue Apr 04, 2023 9:57 pm

Re: VERA PALLETTE UPDATE USING VPOKE.

Post by ahenry3068 »

JUST A SMALL CODE UPDATE

JUST CHANGED
45000 RESTORE 50000
45010 BA = $FA00:REM PALLETTE BASE ADDRESS IN VERA RAM
45020 FOR PE = 0 TO 255
45025     READ R:READ GB
45030     VPOKE 1,BA+(PE*2),GB
45035     VPOKE 1,BA+(PE*2)+1, R
45040 NEXT PE
45050 RETURN

TO 

45000 RESTORE 50000
45010 REM LOOP THROUGH THE PALLETTE ADDRESS SPACE
45020 FOR PE = $FA00 TO $FBFE STEP 2
45025     READ R:READ GB
45030     VPOKE 1,PE,GB
45035     VPOKE 1,PE+1, R
45040 NEXT PE
45050 RETURN
It about halfed the time to step through the loop.

NEW CODE

Code: Select all

10 SCREEN $80 
15 C = 0
20 FOR Y = 0 TO 225 STEP 15
30     FOR X = 0 TO 300 STEP 20
40         RECT X, Y, X+19, Y + 14, C
45         TC = 1
50         IF C=$01 OR C=$1D OR C=$1E OR C=$1F OR C=$26 OR C=$41 THEN TC=$10 
55         IF C=$42 OR C=$49 OR C=$50 OR C=$5D OR C=$5E OR C=$65 THEN TC=$10
60         IF C=$6B OR C=$6C OR C=$73 OR C=$79 OR C=$7A OR C=$81 THEN TC=$10
65         IF C=$88 OR C=$8F OR C=$95 OR C=$96 OR C=$9D OR C=$A4 THEN TC=$10
70         IF C=$03 OR C=$07 OR C=$0D OR C=$AB OR C=$B2 OR C=$CE THEN TC=$10
75         IF C=$B1 OR C=$B9 OR C=$EA OR C=$F1 OR C=$F8 OR C=$CE THEN TC=$10
85         CHAR X+4,Y+9,TC,HEX$(C)
90         C = C + 1
95     NEXT X
100 NEXT Y
110 SLEEP 120
110 COLOR 5:PRINT TI
120 GOSUB 45000
130 PRINT TI


150 P1 = 0
160 IF P1 = 0 THEN P2=$FF:GOTO 180
170 P2 = P1 - 1
180 GOSUB 20750
190 P1 = P1 + 1:IF P1>$FF THEN P1=0
200 GET X$:IF X$=CHR$(27) THEN GOSUB 45000:GOTO 8000
240 GOTO 160


8000 GET X$:IF X$<>"" THEN GOTO 8000 : REM FLUSH KEYBOARD BUFFER
8010 GET X$:IF X$="" THEN GOTO 8010 : REM WAIT FOR KEY 
8020 SCREEN 0:END

20749 REM SWAP PALLETTE COLORS AT P1 & P2
20750 A1 = $FA00+(P1*2)
20760 A2 = $FA00+(P2*2)
20770 B1 = VPEEK (1,A1)
20780 B2 = VPEEK (1,A1+1)
20790 B3 = VPEEK (1,A2)
20800 B4 = VPEEK (1,A2+1)
20810 VPOKE 1, A1, B3
20820 VPOKE 1, A1+1, B4
20830 VPOKE 1, A2, B1
20840 VPOKE 1, A2+1, B2
20850 RETURN 

45000 RESTORE 50000
45010 REM LOOP THROUGH THE PALLETTE ADDRESS SPACE
45020 FOR PE = $FA00 TO $FBFE STEP 2
45025     READ R:READ GB
45030     VPOKE 1,PE,GB
45035     VPOKE 1,PE+1, R
45040 NEXT PE
45050 RETURN

49999 REM DEFAULT VERA PALLETTE AS DATA. FROM 0 TO 255 (2 BYTES EACH ENTRY)RGB
50000 DATA $00,$00,$0F,$FF,$08,$00,$0A,$FE,$0C,$4C,$00,$C5,$00,$0A,$0E,$E7,$0D
50005 DATA $85,$06,$40,$0F,$77,$03,$33,$07,$77,$0A,$F6,$00,$8F,$0B,$BB,$00,$00
50010 DATA $01,$11,$02,$22,$03,$33,$04,$44,$05,$55,$06,$66,$07,$77,$08,$88,$09
50015 DATA $99,$0A,$AA,$0B,$BB,$0C,$CC,$0D,$DD,$0E,$EE,$0F,$FF,$02,$11,$04,$33
50020 DATA $06,$44,$08,$66,$0A,$88,$0C,$99,$0F,$BB,$02,$11,$04,$22,$06,$33,$08
50025 DATA $44,$0A,$55,$0C,$66,$0F,$77,$02,$00,$04,$11,$06,$11,$08,$22,$0A,$22
50030 DATA $0C,$33,$0F,$33,$02,$00,$04,$00,$06,$00,$08,$00,$0A,$00,$0C,$00,$0F
50035 DATA $00,$02,$21,$04,$43,$06,$64,$08,$86,$0A,$A8,$0C,$C9,$0F,$EB,$02,$11
50040 DATA $04,$32,$06,$53,$08,$74,$0A,$95,$0C,$B6,$0F,$D7,$02,$10,$04,$31,$06
50045 DATA $51,$08,$62,$0A,$82,$0C,$A3,$0F,$C3,$02,$10,$04,$30,$06,$40,$08,$60
50050 DATA $0A,$80,$0C,$90,$0F,$B0,$01,$21,$03,$43,$05,$64,$07,$86,$09,$A8,$0B
50055 DATA $C9,$0D,$FB,$01,$21,$03,$42,$04,$63,$06,$84,$08,$A5,$09,$C6,$0B,$F7
50060 DATA $01,$20,$02,$41,$04,$61,$05,$82,$06,$A2,$08,$C3,$09,$F3,$01,$20,$02
50065 DATA $40,$03,$60,$04,$80,$05,$A0,$06,$C0,$07,$F0,$01,$21,$03,$43,$04,$65
50070 DATA $06,$86,$08,$A8,$09,$CA,$0B,$FC,$01,$21,$02,$42,$03,$64,$04,$85,$05
50075 DATA $A6,$06,$C8,$07,$F9,$00,$20,$01,$41,$01,$62,$02,$83,$02,$A4,$03,$C5
50080 DATA $03,$F6,$00,$20,$00,$41,$00,$61,$00,$82,$00,$A2,$00,$C3,$00,$F3,$01
50085 DATA $22,$03,$44,$04,$66,$06,$88,$08,$AA,$09,$CC,$0B,$FF,$01,$22,$02,$44
50090 DATA $03,$66,$04,$88,$05,$AA,$06,$CC,$07,$FF,$00,$22,$01,$44,$01,$66,$02
50095 DATA $88,$02,$AA,$03,$CC,$03,$FF,$00,$22,$00,$44,$00,$66,$00,$88,$00,$AA
50100 DATA $00,$CC,$00,$FF,$01,$12,$03,$34,$04,$56,$06,$68,$08,$8A,$09,$AC,$0B
50105 DATA $CF,$01,$12,$02,$24,$03,$46,$04,$58,$05,$6A,$06,$8C,$07,$9F,$00,$02
50110 DATA $01,$14,$01,$26,$02,$38,$02,$4A,$03,$5C,$03,$6F,$00,$02,$00,$14,$00
50115 DATA $16,$00,$28,$00,$2A,$00,$3C,$00,$3F,$01,$12,$03,$34,$05,$46,$07,$68
50120 DATA $09,$8A,$0B,$9C,$0D,$BF,$01,$12,$03,$24,$04,$36,$06,$48,$08,$5A,$09
50125 DATA $6C,$0B,$7F,$01,$02,$02,$14,$04,$16,$05,$28,$06,$2A,$08,$3C,$09,$3F
50130 DATA $01,$02,$02,$04,$03,$06,$04,$08,$05,$0A,$06,$0C,$07,$0F,$02,$12,$04
50135 DATA $34,$06,$46,$08,$68,$0A,$8A,$0C,$9C,$0F,$BE,$02,$11,$04,$23,$06,$35
50140 DATA $08,$47,$0A,$59,$0C,$6B,$0F,$7D,$02,$01,$04,$13,$06,$15,$08,$26,$0A
50145 DATA $28,$0C,$3A,$0F,$3C,$02,$01,$04,$03,$06,$04,$08,$06,$0A,$08,$0C,$09
50150 DATA $0F,$0B
User avatar
ahenry3068
Posts: 1132
Joined: Tue Apr 04, 2023 9:57 pm

Re: VERA PALLETTE UPDATE USING VPOKE.

Post by ahenry3068 »

OK... I have a set of generic GOSUBS for VERA Palette manipulation.

No more updates on this thread. I'm going to start a new thread to post the final set
of GOSUB's.. So its always the Top level Post.
User avatar
ahenry3068
Posts: 1132
Joined: Tue Apr 04, 2023 9:57 pm

Re: VERA PALLETTE UPDATE USING VPOKE.

Post by ahenry3068 »

OK Tried adding a couple more Routines. They appear to work OK.
and all my numbers seem to be coming out right.

The routine in question is at 40300. I'm trying to achieve a FADE in effect.
The target ends up as meant. But it seems the Actual physical screen isn't
updating until the GOSUB Returns. So I'm not getting the fade in effect I want.
The color just changes to the Target when the GOSUB returns.

This is on emulator R43. I'm about to go try it on the DEV Board and see what
happens.

GREAT NOW MY SD ISN'T MOUNTING ON THE DESKTOP :(
Ok it appears my SD card reader on my Dell is getting Wonky... :(
But I got it done and just ran on HARDWARE with the same result...!!
I guess I could have some logic error in my code, but I'm not seeing it.

DOES Anyone have an explanation for this behaviour. ????

THE PROGRAM I'M USING TO TEST

Code: Select all

REM SET OF GOSUBS FOR DIRECT VERA PALLETTE MANIPULATION
REM USES VPOKE & VPEEK
REM FOR THE OTHER ROUTINES TO WORK RELIABLY SHOULD GOSUB 45000
REM FIRST.    ALSO GOSUB 45000 IS USED AT ANY TIME TO RESET
REM THE VERA PALLETTE TO DEFAULT VALUES.
REM ..
REM ...
REM WHEN THE VERA IS INITIALLY SET TO GRAPHICS MODE IT USES THE
REM DEFAULT PALLETTE BUT IF YOU USE VPEEK TO READ IT RETURNS
REM RANDOM GARBAGE...    AFTER YOU VPOKE THEM IT ALL WORKS
REM AS EXPECTED.
REM .
REM ..
REM ...
REM THIS CODE DOES ABSOLUTELY NO ERROR CHECKING !!!!!!
REM IF USING R%,G% OR B% VALUES SHOULD ALWAYS BE BETWEEN
REM 0-15
REM .
REM ..
REM ...
REM WHEN USING P1 AND P2 TO POINT AT PALLETTE ENTRYS THEY SHOULD
REM ALWAYS BE BETWEEN 0 AND 255
REM I HAD ERROR CHECKING CODE WHEN WRITING THESE ROUTINES
REM BUT ERROR CHECKING TAKES CPU CYCLES....   JUST KEEP THE VALUES
REM CORRECT BEFORE CALLING.
REM .
REM ..
REM ...
REM GOSUB 40000..   SETS PALLETTE ENTRY P1 TO R%,G%,B%
REM ..
REM GOSUB 40500..   SWAPS THE PALLETTE VALUES BETWEEN P1 AND P2
REM ..
REM GOSUB 41000..   COPYS PALLETTE ENTRY P1 TO P2.   P1 IS UNCHANGED
REM ..
REM GOSUB 45000..   REPEAT INFORMATION.   SETS THE DEFAULT PALLETTE VALUES
REM .
REM ..
REM ...

10 SCREEN 128
20 GOSUB 45000
21 C1=$FB:C2=$07
30 RECT 0,0,319,239,$10
40 RECT 20,20,60,60,C1
50 RECT 80,80,140,110,C2
60 P2=C2:P1=C1:J=60
65 INPUT X$
70 GOSUB 40200
80 INPUT X$
90 GOSUB 45000
100 INPUT X$
110 SCREEN 1:END


39995 REM SET PALLETTE ENTRY P1 TO R%,G%,B%
39996 REM "NO ERROR CHECKING"..
40000 VPOKE 1,$FA00+(P1*2),(G%*16) + B%
40010 VPOKE 1,$FA00+((P1*2)+1),R%
40020 RETURN

40100 REM READ PALLETTE ENTRY AT P1
40100 REM RETURNED IN %R,%G,%B
40100 A1 = $FA00+(P1*2)
40105 R% = VPEEK(1,A1+1)
40110 GB%= VPEEK(1,A1)
40115 G% = INT(GB%/16)
40120 B% = GB% - INT(GB%/16)*16
40125 RETURN

40199 FADE P2 FROM CURRENT COLOR TO P1 COLOR, J IS JIFFY DELAY
40200 GOSUB 40100
40205 P3=P1
40210 P1=P2
40215 GOSUB 40300
40220 P1=P3
40225 RETURN


40299 REM FADE P1 TO R%,G%,B%, J IS JIFFY DELAY
40300 DR%=R%:DG%=G%:DB%=B%
40305 GOSUB 41000
40310 RI=1:IF DR%<R% THEN RI=-1
40315 GI=1:IF DG%<G% THEN GI=-1
40320 BI=1:IF DB%<B% THEN BI=-1
40325 IF DR%<>R% THEN R%=R%+RI
40330 IF DG%<>G% THEN G%=G%+GI
40335 IF DB%<>B% THEN B%=B%+BI
40340 FOR I = 0 TO J:SLEEP 2:NEXT I
40345 GOSUB 40000
40350 IF DR%=R% AND DG%=G% AND DB%=B% THEN 40360
40355 GOTO 40325
40360 RETURN


40499 REM SWAP PALLETTE COLORS AT P1 & P2
40500 A1 = $FA00+(P1*2)
40505 A2 = $FA00+(P2*2)
40510 B1 = VPEEK (1,A1)
40515 B2 = VPEEK (1,A1+1)
40520 B3 = VPEEK (1,A2)
40525 B4 = VPEEK (1,A2+1)
40530 VPOKE 1, A1, B3
40535 VPOKE 1, A1+1, B4
40450 VPOKE 1, A2, B1
40455 VPOKE 1, A2+1, B2
40560 RETURN

40999 REM COPY P1 PALLETTE ENTRY TO P2.. P1 IS LEFT UNCHANGED.
41000 VPOKE 1,$FA00+(P2*2), VPEEK(1, $FA00+(P1*2))
41010 VPOKE 1,$FA00+(P2*2)+1, VPEEK(1, $FA00+(P1*2)+1)
41020 RETURN


45000 RESTORE 50000
45010 REM LOOP THROUGH THE PALLETTE ADDRESS SPACE
45015 REM AND POKE THE VERA DEFAULT PALLETTE
45020 FOR PE = $FA00 TO $FBFE STEP 2
45025     READ R:READ GB
45030     VPOKE 1,PE,GB
45035     VPOKE 1,PE+1, R
45040 NEXT PE
45050 RETURN

49999 REM DEFAULT VERA PALLETTE AS DATA. FROM 0 TO 255 (2 BYTES EACH ENTRY)RGB
50000 DATA $00,$00,$0F,$FF,$08,$00,$0A,$FE,$0C,$4C,$00,$C5,$00,$0A,$0E,$E7,$0D
50005 DATA $85,$06,$40,$0F,$77,$03,$33,$07,$77,$0A,$F6,$00,$8F,$0B,$BB,$00,$00
50010 DATA $01,$11,$02,$22,$03,$33,$04,$44,$05,$55,$06,$66,$07,$77,$08,$88,$09
50015 DATA $99,$0A,$AA,$0B,$BB,$0C,$CC,$0D,$DD,$0E,$EE,$0F,$FF,$02,$11,$04,$33
50020 DATA $06,$44,$08,$66,$0A,$88,$0C,$99,$0F,$BB,$02,$11,$04,$22,$06,$33,$08
50025 DATA $44,$0A,$55,$0C,$66,$0F,$77,$02,$00,$04,$11,$06,$11,$08,$22,$0A,$22
50030 DATA $0C,$33,$0F,$33,$02,$00,$04,$00,$06,$00,$08,$00,$0A,$00,$0C,$00,$0F
50035 DATA $00,$02,$21,$04,$43,$06,$64,$08,$86,$0A,$A8,$0C,$C9,$0F,$EB,$02,$11
50040 DATA $04,$32,$06,$53,$08,$74,$0A,$95,$0C,$B6,$0F,$D7,$02,$10,$04,$31,$06
50045 DATA $51,$08,$62,$0A,$82,$0C,$A3,$0F,$C3,$02,$10,$04,$30,$06,$40,$08,$60
50050 DATA $0A,$80,$0C,$90,$0F,$B0,$01,$21,$03,$43,$05,$64,$07,$86,$09,$A8,$0B
50055 DATA $C9,$0D,$FB,$01,$21,$03,$42,$04,$63,$06,$84,$08,$A5,$09,$C6,$0B,$F7
50060 DATA $01,$20,$02,$41,$04,$61,$05,$82,$06,$A2,$08,$C3,$09,$F3,$01,$20,$02
50065 DATA $40,$03,$60,$04,$80,$05,$A0,$06,$C0,$07,$F0,$01,$21,$03,$43,$04,$65
50070 DATA $06,$86,$08,$A8,$09,$CA,$0B,$FC,$01,$21,$02,$42,$03,$64,$04,$85,$05
50075 DATA $A6,$06,$C8,$07,$F9,$00,$20,$01,$41,$01,$62,$02,$83,$02,$A4,$03,$C5
50080 DATA $03,$F6,$00,$20,$00,$41,$00,$61,$00,$82,$00,$A2,$00,$C3,$00,$F3,$01
50085 DATA $22,$03,$44,$04,$66,$06,$88,$08,$AA,$09,$CC,$0B,$FF,$01,$22,$02,$44
50090 DATA $03,$66,$04,$88,$05,$AA,$06,$CC,$07,$FF,$00,$22,$01,$44,$01,$66,$02
50095 DATA $88,$02,$AA,$03,$CC,$03,$FF,$00,$22,$00,$44,$00,$66,$00,$88,$00,$AA
50100 DATA $00,$CC,$00,$FF,$01,$12,$03,$34,$04,$56,$06,$68,$08,$8A,$09,$AC,$0B
50105 DATA $CF,$01,$12,$02,$24,$03,$46,$04,$58,$05,$6A,$06,$8C,$07,$9F,$00,$02
50110 DATA $01,$14,$01,$26,$02,$38,$02,$4A,$03,$5C,$03,$6F,$00,$02,$00,$14,$00
50115 DATA $16,$00,$28,$00,$2A,$00,$3C,$00,$3F,$01,$12,$03,$34,$05,$46,$07,$68
50120 DATA $09,$8A,$0B,$9C,$0D,$BF,$01,$12,$03,$24,$04,$36,$06,$48,$08,$5A,$09
50125 DATA $6C,$0B,$7F,$01,$02,$02,$14,$04,$16,$05,$28,$06,$2A,$08,$3C,$09,$3F
50130 DATA $01,$02,$02,$04,$03,$06,$04,$08,$05,$0A,$06,$0C,$07,$0F,$02,$12,$04
50135 DATA $34,$06,$46,$08,$68,$0A,$8A,$0C,$9C,$0F,$BE,$02,$11,$04,$23,$06,$35
50140 DATA $08,$47,$0A,$59,$0C,$6B,$0F,$7D,$02,$01,$04,$13,$06,$15,$08,$26,$0A
50145 DATA $28,$0C,$3A,$0F,$3C,$02,$01,$04,$03,$06,$04,$08,$06,$0A,$08,$0C,$09
50150 DATA $0F,$0B

User avatar
ahenry3068
Posts: 1132
Joined: Tue Apr 04, 2023 9:57 pm

Re: VERA PALLETTE UPDATE USING VPOKE.

Post by ahenry3068 »

MooingLemur helped me find the error.
More of my Dyslexia. I had a GOSUB 41000 where it should have been GOSUB 40100

I'm going to update the other thread soon with these new routines. After a
bit more testing.
Post Reply