Page 1 of 1

Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 1:00 pm
by funkheld
Hi good afternoon.
I would like to save the entire screen (all chars with the colors) very quickly in an bank.
and then again very quickly with the colors on the screen.

Thanks.
greeting

Code: Select all

%import textio
%import palette
%import bmx
%option no_sysinit
%zeropage basicsafe
%import syslib
%import math
%import gfx2

main {
	ubyte x
	ubyte y
	ubyte x1
	ubyte y1
	ubyte col
	ubyte new_direction
	
	const uword VERA_CHARSET = $f000        ; $1f000
	const uword VERA_TXTSCREEN = $b000      ; %1b000
    
    sub start() {
    txt.clear_screen()
    makechar()	
    col=0	
	 
    waitkey:	 
       col=col+1	
       sys.waitvsync()
       ubyte key=cbm.GETIN()
       keypress(key)
	goto waitkey
    }
	
         sub screen() {
	    for y1 in 0 to 60 {
              cx16.vaddr_autoincr(1, VERA_TXTSCREEN + y1*$0100, 0, 2)
              for x1 in 0 to 79 {
                  cx16.VERA_DATA0 = 32
               }			
            }
         }	
	
	sub links() {
	  x=x-1
	  if x == $ff
	    x=0
	  
	 txt.plot(x,y)
	 txt.print("@")
	 txt.color(col)	
	}
	
	sub rechts() {
	  x=x+1
	  if x > 79
	    x=79

	 txt.plot(x,y)
	 txt.print("@")
	 txt.color(col)	
	}
	
	sub unten() {
	  y=y+1
	  if y > 58
	    y=58
  		
	 txt.plot(x,y)
	 txt.print("@")
	 txt.color(col)	
	}
	
	sub oben() {
	  y=y-1
	  if y == $ff
	    y=0
		
	 txt.plot(x,y)
	 txt.print("@")
	 txt.color(col)	
	}
		
	sub keypress(ubyte key) {
        when key {
          'q' -> links()
          'e'  -> rechts()
          'w'  -> oben()
          's' -> unten()
		  'r' -> screensave()
		  'r' -> screenload()
        }
    }
	
	sub screensave() {
	   .....
	   .....
	}
	
	sub screenload() {
	   .....
	   .....
	}
	
	
	
	sub makechar() {
		ubyte b
        cx16.vaddr_autoincr(1, VERA_CHARSET, 0, 1)       
            b=255
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b   
			
			b=131
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b   

            b=255
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b   

            b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b    

            b=128+64+2+1
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b    

			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b		
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b          
    }
}

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 6:43 pm
by hstubbs3
Funny, I'm not sure how to do that in C exactly..

in assembler?
( using the terms here - https://github.com/X16Community/x16-doc ... ference.md )

STZ CTRL
LDA #>VERA_SCREEN_ADDR ; VERA_SCREEN_ADDR is constant for addres in VRAM your table is set at .
STA ADDRx_L
LDA #<VERA_SCREEN_ADDR
STA ADDRX_M
LDA #^VERA_SCREEN_ADDR | $10 ; increment by 1 byte -

set your destination bank, set use a 2-byte ZeroPage variable as pointer to write the data to ..
Assuming the layer is <=8192 bytes and don't have to switch banks somewhere. .

just loop -
LDX #num_pages
LDY #0
:
: LDA DATA0
STA (ZeroPage-PTR),y
iny
BNE :-
DEX
BNE ;--

hope that helps, sorry I haven't really looked at anything but assembler for CX16

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 6:46 pm
by hstubbs3
oops... forgot to increment the ZeroPage pointer.. actually, you only need to increment the high byte, because using Y register to index byte for byte -

LDX #num_pages
LDY #0
:
: LDA DATA0
STA (ZeroPage_PTR),y
iny
BNE :-
INC ZeroPage_PTR+1 ; this bit right here or you'll only keep overwriting that first page you're trying to write too.
DEX
BNE ;--

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 7:07 pm
by hstubbs3
another way to think of this ... in C ..
is you already have example that iterates through the visible part of the screen (vs the entire layer table....)
sub screen() does this ... you just need to reverse the assignment and increment a pointer somewhere .. .

sub screensave() {
ubyte *SAVEDSCREEN $someaddress_in_RAM ; // set the pointer here
for y1 in 0 to 60 {
cx16.vaddr_autoincr(1, VERA_TXTSCREEN + y1*$0100, 0, 2)
for x1 in 0 to 79 {
*SAVEDSCREEN = cx16.VERA_DATA0;
SAVEDSCREEN++;
}
}
}

sub screenload() {
ubyte *SAVEDSCREEN = $someaddress_in_RAM ; // set the pointer here
for y1 in 0 to 60 {
cx16.vaddr_autoincr(1, VERA_TXTSCREEN + y1*$0100, 0, 2)
for x1 in 0 to 79 {
cx16.VERA_DATA0 = *SAVEDSCREEN ;
SAVEDSCREEN++;
}
}
}

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 8:01 pm
by funkheld
hello thanks for help.

greeting.

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 10:26 pm
by hstubbs3
Did you get it working OK?

I only realized a bit after i had replied last that your code wasn't C ...
I've been working exclusively with assembler so far on the X16, am getting very good with the graphics..

I'd be interested to see what the correct / working code for this function looks like ..

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 10:45 pm
by desertfish
... this is actually an interesting feature to add to Prog8's textio library (which is what is being used here)

Actually, it looks like the VTUI library already contains exactly what is asked for here: save_rect and rest_rect routines
https://github.com/jimmydansbo/vtuilib? ... -save_rect

And it is possible to use VTUI from Prog8 (see the examples/cx16/vtui directory)

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 11:08 pm
by funkheld
haven't found a solution yet.

but will make further attempts.
prog8 also has vpoke and vpeek.

I don't know if you can read vera with vpeek and write it with vpoke.


greeting

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Mon Mar 11, 2024 11:14 pm
by hstubbs3
is kernal functions for literally that.. but doing it 1 byte at a time and setting address between maybe not _fastest_ option..

https://github.com/X16Community/x16-doc ... C.md#vpeek

VPEEK
TYPE: Integer Function
FORMAT: VPEEK (<bank>, <address>)

Action: Return a byte from the video address space. The video address space has 17 bit addresses, which is exposed as 2 banks of 65536 addresses each.

In addition, VPEEK can reach add-on VERA cards with higher bank numbers.

BANK 2-3 is for IO3 (VERA at $9F60-$9F7F)
BANK 4-5 is for IO4 (VERA at $9F80-$9F9F)

EXAMPLE of VPEEK Function:

PRINT VPEEK(1,$B000) : REM SCREEN CODE OF CHARACTER AT 0/0 ON SCREEN
VPOKE
TYPE: Command
FORMAT: VPOKE <bank>, <address>, <value>

Action: Set a byte in the video address space. The video address space has 17 bit addresses, which is exposed as 2 banks of 65536 addresses each.

In addition, VPOKE can reach add-on VERA cards with higher bank numbers.

BANK 2-3 is for IO3 (VERA at $9F60-$9F7F)
BANK 4-5 is for IO4 (VERA at $9F80-$9F9F)

EXAMPLE of VPOKE Statement:

VPOKE 1,$B000+1,1 * 16 + 2 : REM SETS THE COLORS OF THE CHARACTER
REM AT 0/0 TO RED ON WHITE

Re: Save the entire screen (all chars) super quickly in a bank.

Posted: Wed Mar 13, 2024 7:46 am
by funkheld
Hi good afternoon.

I've read that now.

Thanks.
greeting