brainfuck workaround for byte swapping. also cocks
This commit is contained in:
parent
e999d052f0
commit
787786c37b
@ -84,6 +84,22 @@ hdma_math_src .byt 1
|
||||
.byt 1
|
||||
.byt $00, $e0
|
||||
.byt 0
|
||||
hello .byt "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ultrices pharetra libero et ultricies. Proin massa arcu, mattis eu gravida in, tempor sed magna. Mauris molestie purus urna, ut venenatis lorem. Nam nunc lorem, lacinia vel porta quis, sodales eleifend turpis. Aliquam nunc elit, consequat in malesuada vel, elementum eget ipsum. Duis eu lectus nec ipsum imperdiet adipiscing a ac nulla. Mauris risus nisi, posuere nec mollis ac, blandit quis lacus. Donec a sapien felis, ut tempus quam. Nunc semper erat et ipsum accumsan in condimentum enim adipiscing. Sed lobortis accumsan venenatis. Donec euismod mauris gravida risus convallis commodo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis vehicula sem sit amet arcu luctus rhoncus. Etiam sed vulputate ligula. Etiam mauris lectus, eleifend nec fermentum id, bibendum sit amet purus. Pellentesque sollicitudin turpis in leo pharetra vulputate. Sed consequat mattis tortor vitae consectetur. Nullam quis ante in nisl venenatis dignissim. Duis mattis lacus euismod leo volutpat. ", 0
|
||||
hello
|
||||
.byt " _ "
|
||||
.byt " \\`*-. "
|
||||
.byt " ) _`-. "
|
||||
.byt " . : `. . "
|
||||
.byt " : _ ' \\ "
|
||||
.byt " ",$3b," *` _. `*-._ "
|
||||
.byt " `-.-' `-. "
|
||||
.byt " ",$3b," ` `. "
|
||||
.byt " :. . \\ "
|
||||
.byt " . \\ . : .-' . "
|
||||
.byt " ' `+.",$3b," ",$3b," ' : "
|
||||
.byt " : ' | ",$3b," ",$3b,"-. "
|
||||
.byt " ",$3b," ' : :`-: _.`* ",$3b," "
|
||||
.byt " [bug] .*' / .*' ",$3b," .*`- +' `*' "
|
||||
.byt " `*-* `*-* `*-*' ", 0
|
||||
|
||||
lohello .byt "Miau", 0
|
||||
|
||||
|
||||
@ -2,11 +2,21 @@
|
||||
#include "dma.i65"
|
||||
|
||||
GAME_MAIN:
|
||||
sep #$20 : .as
|
||||
jsr snes_init
|
||||
jsr setup_gfx
|
||||
jsr setup_hdma
|
||||
jsr tests
|
||||
jsr colortest
|
||||
lda #$01
|
||||
sta @$306000
|
||||
inc
|
||||
sta @$306001
|
||||
inc
|
||||
sta @$306002
|
||||
inc
|
||||
sta @$306003
|
||||
|
||||
jmp @infloop ;infinite loop in WRAM
|
||||
|
||||
colortest:
|
||||
@ -143,6 +153,14 @@ tests:
|
||||
lda #8
|
||||
sta print_y
|
||||
jsr loprint
|
||||
lda #3
|
||||
sta print_y
|
||||
stz print_x
|
||||
lda #$C0
|
||||
ldx #$B000
|
||||
sta print_bank
|
||||
stx print_src
|
||||
jsr loprint
|
||||
rts
|
||||
|
||||
snes_init:
|
||||
|
||||
@ -29,7 +29,7 @@ NMI_ROUTINE:
|
||||
stx $2116
|
||||
DMA0(#$01, #64*10, #^BG2_TILE_BUF, #!BG2_TILE_BUF, #$18);
|
||||
|
||||
lda bar_pos
|
||||
lda bar_y
|
||||
inc
|
||||
bne +
|
||||
inc
|
||||
@ -38,7 +38,7 @@ NMI_ROUTINE:
|
||||
bne +
|
||||
lda #1
|
||||
+
|
||||
sta bar_pos
|
||||
sta bar_y
|
||||
cmp #113
|
||||
bcs lower_half
|
||||
sta hdma_math
|
||||
|
||||
@ -41,6 +41,8 @@ uint16_t scan_dir(char* path, char mkdb) {
|
||||
static uint16_t crc;
|
||||
static uint32_t db_tgt;
|
||||
static uint32_t dir_tgt;
|
||||
static uint32_t dir_end = 0;
|
||||
static uint8_t was_empty = 0;
|
||||
uint32_t dir_tgt_save, dir_tgt_next;
|
||||
uint16_t numentries;
|
||||
uint32_t dirsize;
|
||||
@ -55,19 +57,33 @@ uint16_t scan_dir(char* path, char mkdb) {
|
||||
|
||||
fno.lfn = lfn;
|
||||
numentries=0;
|
||||
dir_tgt_next=0;
|
||||
for(pass = 0; pass < 2; pass++) {
|
||||
if(pass) {
|
||||
dprintf("path=%s depth=%d ptr=%lx entries=%d next subdir @%lx\n", path, depth, db_tgt, numentries, numentries*4+dir_tgt);
|
||||
_delay_ms(50);
|
||||
dirsize = 4*(numentries);
|
||||
dir_tgt_next = dir_tgt + dirsize + 4; // number of entries + end marker
|
||||
if(dir_tgt_next > dir_end) {
|
||||
dir_end = dir_tgt_next;
|
||||
}
|
||||
dprintf("path=%s depth=%d ptr=%lx entries=%d next subdir @%lx\n", path, depth, db_tgt, numentries, dir_tgt_next);
|
||||
_delay_ms(50);
|
||||
if(mkdb) {
|
||||
dprintf("d=%d Saving %lX to Address %lX [end]\n", depth, 0L, dir_tgt_next - 4);
|
||||
_delay_ms(50);
|
||||
sram_writelong(0L, dir_tgt_next - 4);
|
||||
}
|
||||
}
|
||||
dirsize = 4*(numentries+1);
|
||||
dir_tgt_next = dir_tgt + dirsize;
|
||||
res = f_opendir(&dir, (unsigned char*)path);
|
||||
if (res == FR_OK) {
|
||||
len = strlen((char*)path);
|
||||
for (;;) {
|
||||
res = f_readdir(&dir, &fno);
|
||||
if (res != FR_OK || fno.fname[0] == 0) break;
|
||||
if (res != FR_OK || fno.fname[0] == 0) {
|
||||
if(pass) {
|
||||
if(!numentries) was_empty=1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
fn = *fno.lfn ? fno.lfn : fno.fname;
|
||||
// dprintf("%s\n", fn);
|
||||
// _delay_ms(100);
|
||||
@ -84,18 +100,23 @@ uint16_t scan_dir(char* path, char mkdb) {
|
||||
// write element pointer to current dir structure
|
||||
dprintf("d=%d Saving %lX to Address %lX [dir]\n", depth, db_tgt, dir_tgt_save);
|
||||
_delay_ms(50);
|
||||
sram_writeblock((uint8_t*)&db_tgt, dir_tgt_save, sizeof(dir_tgt_save));
|
||||
sram_writelong(db_tgt, dir_tgt_save);
|
||||
// sram_writeblock((uint8_t*)&db_tgt, dir_tgt_save, sizeof(dir_tgt_save));
|
||||
|
||||
// save element:
|
||||
// - path name
|
||||
// - pointer to sub dir structure
|
||||
dprintf(" Saving dir descriptor to %lX, tgt=%lX, path=%s\n", db_tgt, dir_tgt, path);
|
||||
_delay_ms(100);
|
||||
sram_writeblock(path, db_tgt, 256);
|
||||
sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
|
||||
sram_writelong(dir_tgt|((uint32_t)0x80<<24), db_tgt+256);
|
||||
// sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
|
||||
db_tgt += 0x200;
|
||||
}
|
||||
scan_dir(path, mkdb);
|
||||
dir_tgt = dir_tgt_save;
|
||||
dir_tgt += 4;
|
||||
dir_tgt = dir_tgt_save + 4;
|
||||
if(was_empty)dir_tgt_next += 4;
|
||||
was_empty = 0;
|
||||
depth--;
|
||||
path[len]=0;
|
||||
}
|
||||
@ -121,7 +142,8 @@ uint16_t scan_dir(char* path, char mkdb) {
|
||||
// write element pointer to current dir structure
|
||||
dprintf("d=%d Saving %lX to Address %lX [file]\n", depth, db_tgt, dir_tgt);
|
||||
_delay_ms(50);
|
||||
sram_writeblock((uint8_t*)&db_tgt, dir_tgt, sizeof(db_tgt));
|
||||
sram_writelong(db_tgt, dir_tgt);
|
||||
// sram_writeblock((uint8_t*)&db_tgt, dir_tgt, sizeof(db_tgt));
|
||||
dir_tgt += 4;
|
||||
// save element:
|
||||
// - SNES header information
|
||||
@ -154,6 +176,7 @@ uint16_t scan_dir(char* path, char mkdb) {
|
||||
// dprintf("%x\n", crc);
|
||||
// _delay_ms(50);
|
||||
sram_writeblock(&db_tgt, SRAM_WORK_ADDR+4, sizeof(db_tgt));
|
||||
sram_writeblock(&dir_end, SRAM_WORK_ADDR+8, sizeof(dir_end));
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
@ -166,10 +166,12 @@ int main(void) {
|
||||
_delay_ms(50);
|
||||
curr_dir_id = scan_dir(fs_path, 1); // then rebuild database
|
||||
sram_writeblock(&curr_dir_id, SRAM_WORK_ADDR, 2);
|
||||
uint32_t endaddr;
|
||||
uint32_t endaddr, direndaddr;
|
||||
sram_readblock(&endaddr, SRAM_WORK_ADDR+4, 4);
|
||||
dprintf("%lx\n", endaddr);
|
||||
sram_readblock(&direndaddr, SRAM_WORK_ADDR+8, 4);
|
||||
dprintf("%lx %lx\n", endaddr, direndaddr);
|
||||
save_sram("/sd2snes/sd2snes.db", endaddr-SRAM_WORK_ADDR, SRAM_WORK_ADDR);
|
||||
save_sram("/sd2snes/sd2snes.dir", direndaddr-(SRAM_WORK_ADDR+0x100000), SRAM_WORK_ADDR+0x100000);
|
||||
dprintf("done\n");
|
||||
}
|
||||
uart_putc('[');
|
||||
@ -180,9 +182,9 @@ int main(void) {
|
||||
load_rom("/test.smc");
|
||||
uart_putc(')');
|
||||
|
||||
|
||||
set_busy_led(0);
|
||||
set_avr_ena(1);
|
||||
|
||||
_delay_ms(100);
|
||||
uart_puts_P(PSTR("SNES GO!\n"));
|
||||
snes_reset(0);
|
||||
|
||||
34
src/memory.c
34
src/memory.c
@ -19,6 +19,32 @@
|
||||
|
||||
char* hex = "0123456789ABCDEF";
|
||||
|
||||
void sram_writelong(uint32_t val, uint32_t addr) {
|
||||
set_avr_addr(addr);
|
||||
spi_fpga();
|
||||
spiTransferByte(0x91); // WRITE
|
||||
spiTransferByte(val&0xff); // 7-0
|
||||
spiTransferByte((val>>8)&0xff); // 15-8
|
||||
spiTransferByte((val>>16)&0xff); // 23-15
|
||||
spiTransferByte((val>>24)&0xff); // 31-24
|
||||
spiTransferByte(0x00); // dummy
|
||||
spi_none();
|
||||
}
|
||||
|
||||
uint32_t sram_readlong(uint32_t addr) {
|
||||
set_avr_addr(addr);
|
||||
spi_fpga();
|
||||
spiTransferByte(0x81);
|
||||
spiTransferByte(0x00);
|
||||
|
||||
uint32_t val = spiTransferByte(0x00);
|
||||
val |= ((uint32_t)spiTransferByte(0x00)<<8);
|
||||
val |= ((uint32_t)spiTransferByte(0x00)<<16);
|
||||
val |= ((uint32_t)spiTransferByte(0x00)<<24);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void sram_readblock(void* buf, uint32_t addr, uint16_t size) {
|
||||
uint16_t count=size;
|
||||
uint8_t* tgt = buf;
|
||||
@ -33,15 +59,13 @@ void sram_readblock(void* buf, uint32_t addr, uint16_t size) {
|
||||
}
|
||||
|
||||
void sram_writeblock(void* buf, uint32_t addr, uint16_t size) {
|
||||
uint16_t count=size>>1;
|
||||
uint16_t* src = buf;
|
||||
uint16_t count=size;
|
||||
uint8_t* src = buf;
|
||||
set_avr_addr(addr);
|
||||
spi_fpga();
|
||||
spiTransferByte(0x91); // WRITE
|
||||
while(count--) {
|
||||
spiTransferByte((*src)>>8);
|
||||
spiTransferByte((*src)&0xff);
|
||||
src++;
|
||||
spiTransferByte(*src++);
|
||||
}
|
||||
spiTransferByte(0x00); // dummy
|
||||
spi_none();
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
uint32_t load_rom(char* filename);
|
||||
uint32_t load_sram(char* filename);
|
||||
uint32_t sram_readlong(uint32_t addr);
|
||||
void sram_writelong(uint32_t val, uint32_t addr);
|
||||
void sram_readblock(void* buf, uint32_t addr, uint16_t size);
|
||||
void sram_writeblock(void* buf, uint32_t addr, uint16_t size);
|
||||
void save_sram(char* filename, uint32_t sram_size, uint32_t base_addr);
|
||||
|
||||
@ -122,7 +122,7 @@ always @(posedge clk) begin
|
||||
AVR_WRITE_BUF <= 1'b0;
|
||||
else
|
||||
AVR_WRITE_BUF <= 1'b1;
|
||||
|
||||
|
||||
if ((spi_bit_cnt == 3'h7) & (cmd_data[7:4] == 4'h8) & (spi_byte_cnt > 32'h0))
|
||||
AVR_READ_BUF <= 1'b0;
|
||||
else
|
||||
|
||||
@ -46,7 +46,7 @@ wire [7:0] FROM_SRAM_BYTE;
|
||||
|
||||
assign SNES_DATA = SNES_READ ? 8'bZ : SNES_OUT_MEM;
|
||||
|
||||
assign FROM_SRAM_BYTE = (SRAM_ADDR0 ? SRAM_DATA[7:0] : SRAM_DATA[15:8]);
|
||||
assign FROM_SRAM_BYTE = ((SRAM_ADDR0 ^ !AVR_ENA) ? SRAM_DATA[7:0] : SRAM_DATA[15:8]);
|
||||
|
||||
assign AVR_OUT_DATA = !AVR_ENA ? (FROM_SRAM_BYTE)
|
||||
: (AVR_OUT_MEM);
|
||||
|
||||
@ -49,11 +49,11 @@ module main(
|
||||
output SPI_MISO,
|
||||
input SPI_SS,
|
||||
input SPI_SCK,
|
||||
input AVR_ENA,
|
||||
input AVR_ENA
|
||||
|
||||
/* debug */
|
||||
output DCM_IN_STOPPED,
|
||||
output DCM_FX_STOPPED
|
||||
//output DCM_IN_STOPPED,
|
||||
//output DCM_FX_STOPPED
|
||||
//input DCM_RST
|
||||
);
|
||||
wire [7:0] spi_cmd_data;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user