Re: Prog8 language and compiler topic
Posted: Tue Mar 12, 2024 9:53 pm
Funkheld
6502 CPU only has few registers... Accumulator (often called A), X and Y.. each is 1 byte - 0 to 255..
Multiple instructions allow indexing into memory using X or Y register ...
Actually, I gave some example of that in the other forum post, where you had asked about prog8 to save/load the current screen..
This bit here - uses X as a counter to track pages, y to index each byte of the page, and ZeroPage_PTR is 2 consecutive bytes in zero page of RAM ( $0000-$00FF ) set to some address like $HH00... the start of a page of memory..
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 ;--
random index into array > 256 requires altering the highbyte... one _could_ create an array of arrays to manage the high byte themselves... IE say for 60 lines on screen, make an array sized 120 (60*2 bytes) to hold pointers to arrays with 160 bytes each (80 characters across the screen, char code + color data )
Then ... what line do you want? ... say 31... double it => 64 ... get bytes 64 and 65 into your pointer / memory address ... that would be the array to index for the other data ..
or if the arrays always start at beginning of page, would only need 1 byte for the first array, and access via the setting some ZP to $HH00 to index... but in this example, that would waste 96 bytes per line in memory...
(that bit -might- be more for desertfish to consider supporting a '2d' array of X pages... maybe in a way to span banks??? they are writing a compiler alone... it may be a bit much to ask )
I had provided some code for saving/loading the screen - maybe someone here could fill in the vars and such I wasn't sure on??
viewtopic.php?t=7266
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++;
}
}
}
6502 CPU only has few registers... Accumulator (often called A), X and Y.. each is 1 byte - 0 to 255..
Multiple instructions allow indexing into memory using X or Y register ...
Actually, I gave some example of that in the other forum post, where you had asked about prog8 to save/load the current screen..
This bit here - uses X as a counter to track pages, y to index each byte of the page, and ZeroPage_PTR is 2 consecutive bytes in zero page of RAM ( $0000-$00FF ) set to some address like $HH00... the start of a page of memory..
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 ;--
random index into array > 256 requires altering the highbyte... one _could_ create an array of arrays to manage the high byte themselves... IE say for 60 lines on screen, make an array sized 120 (60*2 bytes) to hold pointers to arrays with 160 bytes each (80 characters across the screen, char code + color data )
Then ... what line do you want? ... say 31... double it => 64 ... get bytes 64 and 65 into your pointer / memory address ... that would be the array to index for the other data ..
or if the arrays always start at beginning of page, would only need 1 byte for the first array, and access via the setting some ZP to $HH00 to index... but in this example, that would waste 96 bytes per line in memory...
(that bit -might- be more for desertfish to consider supporting a '2d' array of X pages... maybe in a way to span banks??? they are writing a compiler alone... it may be a bit much to ask )
I had provided some code for saving/loading the screen - maybe someone here could fill in the vars and such I wasn't sure on??
viewtopic.php?t=7266
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++;
}
}
}