Don't know how to do fast 16 bit loops in 65c02 ASM...

This commit is contained in:
Zachary Hall 2023-11-17 19:37:25 -08:00
parent 53ae70890a
commit c18918f5fb
3 changed files with 27 additions and 31 deletions

View file

@ -1,5 +1,5 @@
#ifndef FILL_H #ifndef FILL_H
#define FILL_H #define FILL_H
#include <stdint.h> #include <stdint.h>
extern void __fastcall__ fill_vera(uint16_t count, uint8_t data); extern void __fastcall__ fill_vera(uint8_t count, uint8_t data);
#endif #endif

View file

@ -3,40 +3,27 @@ r0l := $02
r0h := $03 r0h := $03
vera_data0 := $9f23 vera_data0 := $9f23
.export _fill_vera .export _fill_vera
.import popax .import popa
.segment "CODE" .segment "CODE"
_fill_vera: _fill_vera:
sta vera_fill_data sta vera_fill_data
jsr popax jsr popa
sta max sta max
stx max+1
lda max lda max
cmp #0 cmp #0
bne @fill
@max_l_zero:
lda max+1
cmp #0
beq @end beq @end
@fill: @fill:
ldx #0 ldx #0
lda vera_fill_data lda vera_fill_data
@loopx: @loop:
ldy #0
@loopy:
sta vera_data0 sta vera_data0
iny
cpy max
bne @loopy
@loopxend:
inx inx
cpx max+1 cpx max
bne @loopx bne @loop
@end: @end:
rts rts
.segment "BSS" .segment "BSS"
tmp:
.res 2
max: max:
.res 2 .res 1
vera_fill_data: vera_fill_data:
.res 1 .res 1

View file

@ -77,6 +77,8 @@ int uploadimage(const char *filename) {
size_t vera_w = 320, vera_h = 240; size_t vera_w = 320, vera_h = 240;
uint16_t vera_max = 0; uint16_t vera_max = 0;
uint32_t tmp = 0, vera_max_32 = 0; uint32_t tmp = 0, vera_max_32 = 0;
uint16_t vera_adr_bak;
uint8_t vera_adr_h_bak;
bool vera_max_bank = 1; bool vera_max_bank = 1;
uint8_t config = 0b00000100; uint8_t config = 0b00000100;
uint16_t bytes_read; uint16_t bytes_read;
@ -161,28 +163,35 @@ int uploadimage(const char *filename) {
} }
// Upload the bitmap // Upload the bitmap
for (x = 0; VERA.address < vera_max || (vera_max_bank & 0b1) != (VERA.address_hi & 0b1);) { for (x = 0; VERA.address < vera_max || (vera_max_bank & 0b1) != (VERA.address_hi & 0b1);) {
tmp = (((uint32_t)VERA.address) + ((uint32_t)(VERA.address_hi & 0b1) << 16)); tmp = ((((uint32_t)VERA.address) + ((uint32_t)(VERA.address_hi & 0b1) << 16)));
x = tmp % (uint32_t)(vera_w/pixels_per_byte); x = (tmp % (uint32_t)(vera_w/pixels_per_byte))*pixels_per_byte;
y = tmp / (uint32_t)(vera_w/pixels_per_byte); y = tmp / (uint32_t)(vera_w/pixels_per_byte);
#if 0
vera_adr_bak = VERA.address;
vera_adr_h_bak = VERA.address_hi;
printf("Y: %u, X: %u, tmp: %lu,\nvera_w: %u\nvera_adr: %u, vera_adr_h: %s\n", y, x, tmp, vera_w, vera_adr_bak, (vera_adr_h_bak & 1) ? "1" : "0");
VERA.address = vera_adr_bak;
VERA.address_hi = vera_adr_h_bak;
#endif
if (y >= height) { if (y >= height) {
break; break;
} }
if (x < width && y < height) { if (x < width && y < height) {
bytes_read = cx16_k_macptr((width - x)/pixels_per_byte, false, &VERA.data0); bytes_read = cx16_k_macptr((((width) - x))/pixels_per_byte, false, &VERA.data0);
if (bytes_read == 0) {
printf("Error reading file!\n");
return 1;
}
} else { } else {
for (; x < vera_w/pixels_per_byte; x++) { //VERA.data0 = value;
VERA.data0 = value; tmp = (vera_w-x)/pixels_per_byte;
if (tmp >= ((uint32_t)1 << 8)) {
fill_vera(0xFF, value);
} else {
fill_vera(tmp, value);
} }
} }
} }
for (; VERA.address < vera_max || (vera_max_bank & 0b1) != (VERA.address_hi & 0b1);) { for (; VERA.address < vera_max || (vera_max_bank & 0b1) != (VERA.address_hi & 0b1);) {
tmp = vera_max_32 - (((uint32_t)VERA.address) | ((uint32_t)(VERA.address_hi & 0b1) << 16)); tmp = vera_max_32 - (((uint32_t)VERA.address) | ((uint32_t)(VERA.address_hi & 0b1) << 16));
if (tmp & ((uint32_t)1 << 16)) { if (tmp >= ((uint32_t)1 << 8)) {
fill_vera(0xFFFF, value); fill_vera(0xFF, value);
} else { } else {
fill_vera(tmp, value); fill_vera(tmp, value);
} }