Use MACPTR to speed up loading.

This commit is contained in:
Zachary Hall 2023-11-17 16:15:21 -08:00
parent 03022506a4
commit 5be947dbf3
3 changed files with 43 additions and 7 deletions

5
src/macptr.h Normal file
View file

@ -0,0 +1,5 @@
#ifndef MACPTR_H
#define MACPTR_H
#include <stdint.h>
extern uint16_t __fastcall__ cx16_k_macptr(uint8_t size, void *ptr);
#endif

22
src/macptr.s Normal file
View file

@ -0,0 +1,22 @@
.export _cx16_k_macptr
.import popa
r0 := $02
.segment "CODE"
_cx16_k_macptr:
sta r0
txa
tay
lda r0
tax
jsr popa
clc
jsr $FF44
bcs @error
txa
sty r0
ldx r0
rts
@error:
lda #0
ldx #0
rts

View file

@ -6,6 +6,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "vera.h" #include "vera.h"
#include "macptr.h"
#include "debug.h" #include "debug.h"
uint8_t palette[512]; uint8_t palette[512];
uint8_t *image = BANK_RAM; uint8_t *image = BANK_RAM;
@ -128,13 +129,21 @@ int readfile(const char *filename) {
image_end = (imgdatabytes % 8192) + image; image_end = (imgdatabytes % 8192) + image;
ram_bank_end = (imgdatabytes / 8192) + 1; ram_bank_end = (imgdatabytes / 8192) + 1;
printf("Image: (bank %u, addr %u) => (bank %u, addr %u)\n", ram_bank_begin, image - BANK_RAM, ram_bank_end, image_end - BANK_RAM); printf("Image: (bank %u, addr %u) => (bank %u, addr %u)\n", ram_bank_begin, image - BANK_RAM, ram_bank_end, image_end - BANK_RAM);
for (banki = ram_bank_begin; banki <= ram_bank_end; banki++) { ptr = BANK_RAM;
change_bank(banki); change_bank(ram_bank_begin);
i_max = (banki == ram_bank_end) ? (uint16_t)(image_end - image) : 8192; while (1) {
printf("Writing %u bytes to bank %u\n", i_max, banki); uint16_t bytes_read = cx16_k_macptr(0, ptr);
for (i = 0; i < i_max; i++) { ptr += bytes_read;
ptr = (i % 8192) + image; while (ptr > (void*)0xBFFF) {
*ptr = read8(); ptr -= 0x2000;
}
banki = RAM_BANK;
printf("Wrote %u bytes\n", i_max, banki);
if (bytes_read == 0) {
if (banki == ram_bank_end) {
break;
}
return 1;
} }
} }
cbm_k_clrch(); cbm_k_clrch();