Synthpopalooza Posted August 7, 2009 Share Posted August 7, 2009 I am trying to write a VBI routine to do page flipping of up to three registers at a time ... this is in an attempt to do an interlace text mode. My plan is to use 6 of the 7 free page zero locations (203-208) to hold the values that I want to flip between ... for example: 203-204 hold the two values for CHBAS to flip between 205-206 hold two values for GTPRIOR for flipping between GTIA modes 9 and 11 207-208 hold two other values for a third register (for example, if I wanted to toggle COLBK for a GTIA 9-11 toggle) And of course, this would be customizable, as in being able to change which register I am toggling from within the VBI code. (say if I only wanted a CHBAS toggle for Super IRG, then I could set the other two toggle registers to $ffff which would do nothing). I know some assembly (LDX $CB STX CHBAS, etc.) but it's figuring how to get the routine to toggle between those two locations each VBLANK. Any ideas? Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 7, 2009 Share Posted August 7, 2009 (edited) Better idea - just keep the data embedded at the end of the routine and copy to z-page as needed. Something like... VBI ldx #14 ; allow up to 8 register changes checkloop lda regtable,x sta 203 lda regtable+1,x sta 204 ora 203 beq nochange ; zero value in reg table = no change lda 20 ; low byte of RTCLOCK and #1 sta temp1 txa ora temp1 tay ; Y will equal X or X+1, cycles each VBI lda valuetable,y ldy #0 sta (203),y nochange dex dex bpl checkloop jmp $e45f ; continue VBlank temp1 .byte 0 regtable .word $2fc,$2c4,0,0 .word 0,0,0,0 ; CHBAS, COLPF0, 6 blank entries valuetable .byte $60,$64 ; 2 values to toggle through CHBAS .byte $34,$36 ; 2 values to toggle through COLPF0 .byte 0,0 .byte 0,0 .byte 0,0 .byte 0,0 .byte 0,0 .byte 0,0 ; 6 unused entries You could even take it a step further and save/restore the zero page locations so you can use them elsewhere. If you wanted this routine to be relocatable, you could just put the temp and tables somewhere else... like end of Page 6, or in the cassette buffer. Edited August 7, 2009 by Rybags Quote Link to comment Share on other sites More sharing options...
MaPa Posted August 7, 2009 Share Posted August 7, 2009 If you are changing just two values in these registers I would do simple EORing of that registers. You set up the initial values and in the VBI do sometnig like: lda CHBAS eor 203 sta CHBAS lda GPRIOR eor 204 ... The values in 203, 204 .. registers is CHBAS1 value EOR CHBAS2 value etc. If you don't want to flip it, just put 0 (zero) there. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 12, 2009 Author Share Posted August 12, 2009 Better idea - just keep the data embedded at the end of the routine and copy to z-page as needed. Something like... VBI ldx #14 ; allow up to 8 register changes checkloop lda regtable,x sta 203 lda regtable+1,x sta 204 ora 203 beq nochange ; zero value in reg table = no change lda 20 ; low byte of RTCLOCK and #1 sta temp1 txa ora temp1 tay ; Y will equal X or X+1, cycles each VBI lda valuetable,y ldy #0 sta (203),y nochange dex dex bpl checkloop jmp $e45f ; continue VBlank temp1 .byte 0 regtable .word $2fc,$2c4,0,0 .word 0,0,0,0 ; CHBAS, COLPF0, 6 blank entries valuetable .byte $60,$64 ; 2 values to toggle through CHBAS .byte $34,$36 ; 2 values to toggle through COLPF0 .byte 0,0 .byte 0,0 .byte 0,0 .byte 0,0 .byte 0,0 .byte 0,0 ; 6 unused entries You could even take it a step further and save/restore the zero page locations so you can use them elsewhere. If you wanted this routine to be relocatable, you could just put the temp and tables somewhere else... like end of Page 6, or in the cassette buffer. I am new to assembler language, and I tried to enter this code into MAC/65 assembler. For some reason, when I enter any immediate LDX or LDA commands (e.g. LDA #14, ldy #0) the assembler reports it as an error. Any idea what I am doing wrong? I am entering these with line numbers as this seems to be what Mac/65 expects Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 12, 2009 Share Posted August 12, 2009 Make sure you always put 2 spaces after the line number for Instructions. With NUM mode, the editor automatically gives the first space. Only labels or comments ";" start with only 1 space after the line number. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 12, 2009 Author Share Posted August 12, 2009 Make sure you always put 2 spaces after the line number for Instructions. With NUM mode, the editor automatically gives the first space. Only labels or comments ";" start with only 1 space after the line number. Sorted. When I do the ASM, I get 4 phase errors (ERROR 13) for the following labels: NOCHANGE REGTABLE TEMP1 VALUETABLE Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 12, 2009 Share Posted August 12, 2009 Phase Errors are an absolute PITA and often totally illogical. The manual has some hints. It often helps if the labels are defined at the start of the program. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 12, 2009 Author Share Posted August 12, 2009 (edited) Phase Errors are an absolute PITA and often totally illogical. The manual has some hints. It often helps if the labels are defined at the start of the program. So, say for instance, I wanted the regtable to be at $400, I would do: REGTABLE = $400 at the beginning of the program, right? Also, I noticed this: regtable .word $2fc,$2c4,0,0 That should actually be $2f4 for chbas, not $2fc? Edited August 12, 2009 by Synthpopalooza Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 12, 2009 Share Posted August 12, 2009 I think Phase errors are more common with zero-page stuff. They also seem to sometimes happen for Branch targets. I don't bother with Mac-65 anymore... just use one of the cross-platform Assemblers, much easier and you can see much more of what you're editing. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 12, 2009 Author Share Posted August 12, 2009 I think Phase errors are more common with zero-page stuff. They also seem to sometimes happen for Branch targets. I don't bother with Mac-65 anymore... just use one of the cross-platform Assemblers, much easier and you can see much more of what you're editing. Well, I actually got the thing to compile, finally. Here's the listing I used: 0100 *=600 0108 VBI 0109 LDX #14 0110 CHECKLOOP 0120 LDA REGTABLE,X 0130 STA 203 0140 LDA REGTABLE+1,X 0150 STA 204 0160 ORA 203 0170 BEQ NOCHANGE 0180 LDA 20 0190 AND #1 0200 STA TEMP1 0210 TXA 0220 ORA TEMP1 0230 TAY 0240 LDA VALUETABLE,Y 0250 LDY #0 0260 STA (203),Y 0270 NOCHANGE = * 0280 DEX 0290 DEX 0300 BPL CHECKLOOP 0310 JMP $E45F 0320 TEMP1 = * 0330 .BYTE 0 0340 REGTABLE = * 0350 .WORD $02F4,$02C4,0,0 0360 .WORD 0,0,0,0 0370 VALUETABLE = * 0380 .BYTE $60,64 0390 .BYTE $34,$36 0400 .BYTE 0,0 0410 .BYTE 0,0 0420 .BYTE 0,0 0430 .BYTE 0,0 0440 .BYTE 0,0 0450 .BYTE 0,0 I've now generated an .obj file from this. What is the method for using this in BASIC and setting up the custom VBI? Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 12, 2009 Share Posted August 12, 2009 (edited) It's a short routine, you could probably just squeeze it into a DATA statements as strings. First, load it from DOS, then do something like. 10 GR. 0 : L=11000:FOR A=1536 TO 1791 STEP 64 20 ? L;"DATA ";:FOR B=A TO A+63:? "<esc><esc>";CHR$(PEEK(B));:NEXT B 30 ? :NEXT A Run that, then move cursor up and enter the lines the program's generated. You'll probably get lots of Heart symbols, just trim off all the ones from the end except the last 2 or so. Change the last statement to something like 11090 DATA -1 Then to use it in a subroutine, something like: 10000 RESTORE 11000:A=1536:DIM A$(120) 10010 READ A$:IF A$="-1" THEN RETURN 10020 L=LEN(A$):FOR B=0 TO L-1:POKE A+B,ASC(A$(B+1)):NEXT B:A=A+B:GOTO 10010 Edited August 12, 2009 by Rybags Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 16, 2009 Author Share Posted August 16, 2009 (edited) Ok, I got a step further: 10 DIM HX$(2) 11 DIM SETVBV$(10) 12 FOR I=1 TO 10:READ HX$:SETVBV$(LEN(SETVBV$)+1)=CHR$(DEC(HX$)):NEXT I 20 FOR I=1 TO 40:READ HX$:POKE 1535+I,DEC(HX$) : ? DEC(HX$):NEXT I 50 POKE 1024,DEC("02"):POKE 1025,DEC("F4"):POKE 1026,DEC("02"):POKE 1027,DEC("C4") 51 POKE 1040,DEC("60"):POKE 1041,DEC("40") 52 POKE 1042,DEC("34"):POKE 1041,DEC("36") 59 X=USR(ADR(SETVBV$)) 60 END 65 DATA A0,00,A2,06,A9,06,20,5C,E4,60 70 REM DATA AD,F4,02,45,CB,8D,F4,02,AD,6F,02,45,CC,8D,6F,02,4C,5F,E4 80 DATA A2,0E,BD,00,04,85,CB,BD,01,04,85,CC,05,CB,F0,13,A5,14,29,01,85,CD,8A,05,CD,A8,B9 ,10,04,A0,00,91,CB 85 DATA CA,CA,10,DD,4C,EF,E4 This is in turbobasic. SETVBV$ is of course the routine to set DPEEK(546) to point to the customized flip VBI stored at page 6. Problem now is, when I run the program, the emulator crashes. Any ideas what I am doing wrong? Edited August 16, 2009 by Synthpopalooza Quote Link to comment Share on other sites More sharing options...
kenfused Posted August 16, 2009 Share Posted August 16, 2009 Ok, I got a step further: 10 DIM HX$(2) 11 DIM SETVBV$(10) 12 FOR I=1 TO 10:READ HX$:SETVBV$(LEN(SETVBV$)+1)=CHR$(DEC(HX$)):NEXT I 20 FOR I=1 TO 40:READ HX$:POKE 1535+I,DEC(HX$) : ? DEC(HX$):NEXT I 50 POKE 1024,DEC("02"):POKE 1025,DEC("F4"):POKE 1026,DEC("02"):POKE 1027,DEC("C4") 51 POKE 1040,DEC("60"):POKE 1041,DEC("40") 52 POKE 1042,DEC("34"):POKE 1041,DEC("36") 59 X=USR(ADR(SETVBV$)) 60 END 65 DATA A0,00,A2,06,A9,06,20,5C,E4,60 70 REM DATA AD,F4,02,45,CB,8D,F4,02,AD,6F,02,45,CC,8D,6F,02,4C,5F,E4 80 DATA A2,0E,BD,00,04,85,CB,BD,01,04,85,CC,05,CB,F0,13,A5,14,29,01,85,CD,8A,05,CD,A8,B9 ,10,04,A0,00,91,CB 85 DATA CA,CA,10,DD,4C,EF,E4 This is in turbobasic. SETVBV$ is of course the routine to set DPEEK(546) to point to the customized flip VBI stored at page 6. Problem now is, when I run the program, the emulator crashes. Any ideas what I am doing wrong? Be sure you are doing a PLA in your routine you are calling with USR. BASIC pushes the argument count (of additional parameters to USR) onto the stack. The count value you pull off will be 0 if you are not passing any additional arguments but you still have to pull it. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 16, 2009 Author Share Posted August 16, 2009 (edited) Ok, I got a step further: 10 DIM HX$(2) 11 DIM SETVBV$(10) 12 FOR I=1 TO 10:READ HX$:SETVBV$(LEN(SETVBV$)+1)=CHR$(DEC(HX$)):NEXT I 20 FOR I=1 TO 40:READ HX$:POKE 1535+I,DEC(HX$) : ? DEC(HX$):NEXT I 50 POKE 1024,DEC("02"):POKE 1025,DEC("F4"):POKE 1026,DEC("02"):POKE 1027,DEC("C4") 51 POKE 1040,DEC("60"):POKE 1041,DEC("40") 52 POKE 1042,DEC("34"):POKE 1041,DEC("36") 59 X=USR(ADR(SETVBV$)) 60 END 65 DATA A0,00,A2,06,A9,06,20,5C,E4,60 70 REM DATA AD,F4,02,45,CB,8D,F4,02,AD,6F,02,45,CC,8D,6F,02,4C,5F,E4 80 DATA A2,0E,BD,00,04,85,CB,BD,01,04,85,CC,05,CB,F0,13,A5,14,29,01,85,CD,8A,05,CD,A8,B9 ,10,04,A0,00,91,CB 85 DATA CA,CA,10,DD,4C,EF,E4 This is in turbobasic. SETVBV$ is of course the routine to set DPEEK(546) to point to the customized flip VBI stored at page 6. Problem now is, when I run the program, the emulator crashes. Any ideas what I am doing wrong? Be sure you are doing a PLA in your routine you are calling with USR. BASIC pushes the argument count (of additional parameters to USR) onto the stack. The count value you pull off will be 0 if you are not passing any additional arguments but you still have to pull it. Sorted! It was a typo in line 85. EF,F4, should be 5F,E4. otherwise, crash! Routine working fine now, except now when I press RESET, the emulator crashes. Edited August 16, 2009 by Synthpopalooza Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 26, 2009 Author Share Posted August 26, 2009 (edited) Ok, this is the latest version of my VBI code in turbobasic: 4000 DIM HX$(2) 4010 DIM SETVBV$(11),OLDVBV$(11) 4020 FOR I=1 TO 11:READ HX$:SETVBV$(LEN(SETVBV$)+1)=CHR$(DEC(HX$)):NEXT I 4030 OLDVBV$=SETVBV$:OLDVBV$(3,3)=CHR$(PEEK(546)):OLDVBV$(5,5)=CHR$(PEEK(547)) 4040 FOR I=1 TO 40:READ HX$:POKE 1535+I,DEC(HX$):NEXT I 4050 DPOKE 1024,756:DPOKE 1026,623:DPOKE 1028,712 4051 DPOKE 1030,65535:DPOKE 1032,65535:DPOKE 1034,65535:DPOKE 1036,65535:DPOKE 103,65535 4060 POKE 1040,226:POKE 1041,204:POKE 1042,64:POKE 1043,192:POKE 1044,0:POKE 1045,4 4070 X=USR(ADR(SETVBV$)) 4071 ? 4080 FOR I=0 TO 128:PUT 27:PUT I:NEXT I 4090 END 4100 DATA 68,A0,00,A2,06,A9,06,20,5C,E4,60 4110 DATA A2,0E,BD,00,04,85,CB,BD,01,04,85,CC,05,CB,F0,13,A5,14,29,01,85,CD,8A,05,CD,A8,B9,10,04,A0,00,91,CB 4120 DATA CA,CA,10,DD,4C,5F,E4 This code does a simulation of APAC (gr 9/gr 11 256 color GTIA) mode in Graphics 0, toggling the GTIA register, CHBAS (between 226 and 204) and COLBK (712) between 0 and 4. I noticed that when I used this routine, that pressing reset causes the computer to crash. However, adding line 4051 seems to have fixed the problem, as it seems the BEQ instruction, which is supposed to cause the routine to skip the register flip when both registers are equal, wasn't working. Originally, what it was doing was POKEing a 0 at 0 at least 10 times per VBI. Changing the registers (starting at 1028) to 65535 causes a harmless POKE into ROM. What I was wondering is if someone could disassemble what I have done and see if there is anyway to fix the BEQ to where it works properly. Edited August 26, 2009 by Synthpopalooza Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 26, 2009 Share Posted August 26, 2009 4051 DPOKE 1030,65535:DPOKE 1032,65535:DPOKE 1034,65535:DPOKE 1036,65535:DPOKE 103,65535 That's not right. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted August 26, 2009 Author Share Posted August 26, 2009 4051 DPOKE 1030,65535:DPOKE 1032,65535:DPOKE 1034,65535:DPOKE 1036,65535:DPOKE 103,65535 That's not right. Should be DPOKE 1038,65535 ... typo. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.