From a73902d32dcb5b6820ee0fce42b04f418118a4d3 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Mon, 6 Jun 2022 13:56:54 +0200 Subject: [PATCH] copy to ram and initialze sprite from c --- Makefile | 12 +++++++-- src/init.s | 35 +++++++++++++++++++------ src/main.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 118 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 9403cf9..de9a494 100644 --- a/Makefile +++ b/Makefile @@ -3,20 +3,28 @@ INC=./inc CC=bcc LD=ld86 AS=nasm +MED=mednafen #$(LD) -M src/*.o # -d delete headers # -s strip symbols all: - $(LD) src/*.o -d -s -o test.wsc + $(LD) -T0x0 -D0xF000 src/*.o -d -s -o test.wsc # use -x to for -ffreestanding c-files: - $(CC) -O -c src/*.c -I$(INC) + $(CC) -0 -c src/*.c -I$(INC) init: $(AS) -fas86 src/*.s -i $(INC) +add: + cp test.wsc tools/ + cd tools && ./romheader + +run: + $(MED) tools/test.wsc + clean: rm -rf src/*.o test.wsc diff --git a/src/init.s b/src/init.s index 3a36e09..004c231 100644 --- a/src/init.s +++ b/src/init.s @@ -2,7 +2,10 @@ %include "WonderSwan.inc" extern _main -extern __end +extern _test_copy +extern __etext +extern __edata +extern __end MYSEGMENT equ 0xF000 @@ -33,7 +36,7 @@ sprtable equ bgmap-SPR_TABLE_SIZE mov di,ax mov ds,ax ; Clear Segments mov es,ax - + mov bp,ax ; Setup stack mov ss,ax mov sp,WS_STACK @@ -44,7 +47,7 @@ sprtable equ bgmap-SPR_TABLE_SIZE mov sp,WSC_STACK ; New stack - call _main + ;call _main xor ax,ax ; Clear Ram mov di,0x100 @@ -53,6 +56,9 @@ sprtable equ bgmap-SPR_TABLE_SIZE out IO_SRAM_BANK,al + + ;mov cx, 0x100 + ; Video Init in al,IO_VIDEO_MODE or al,VMODE_16C_CHK | VMODE_CLEANINIT @@ -106,11 +112,15 @@ sprtable equ bgmap-SPR_TABLE_SIZE ;-------------------------------- ; Set Segments for Copy - mov ax,MYSEGMENT + mov ax,0xF000 mov ds,ax xor ax,ax mov es,ax + mov si, 0xF000 + mov di, 0x1000 + mov cx, 50 + rep movsb ; Make BG mov si,TileGfx @@ -118,10 +128,16 @@ sprtable equ bgmap-SPR_TABLE_SIZE mov cx,(TileGfxE-TileGfx)/2 rep movsw - mov si,TilePal - mov di,WSC_PALETTES - mov cx,16 - rep movsw + ;mov si,TilePal + ;mov di,WSC_PALETTES + ;mov cx,32 + ;rep movsb +;back: + call _main + ;call _main + ;call _test_copy + ;call _test_copy + ;jmp back mov ax,BG_CHR(0,0,0,0,0) ; Initial Tile, Pal 0, Bank 0 mov di,bgmap @@ -132,6 +148,9 @@ sprtable equ bgmap-SPR_TABLE_SIZE mov al,BG_ON | FG_ON out IO_DISPLAY_CTRL,al +blaat: + jmp blaat + ; Loop Read Buttons loop: mov al,KEYPAD_READ_BUTTONS diff --git a/src/main.c b/src/main.c index 375b587..3763f3c 100644 --- a/src/main.c +++ b/src/main.c @@ -13,14 +13,89 @@ void outport(c) #endasm } -int main() +static unsigned char data[] = { +0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, +0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f +}; + +static unsigned char data2[] = { +0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, +0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f +}; + +static unsigned char data3[] = { +0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, +0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f +}; + + + +unsigned short *memcpy(dest, src, cnt) + unsigned short *dest; + unsigned short *src; + int cnt; { - while(1) { - /* outport(0x15EE); */ - unsigned reg = 0x15; - unsigned val = 0xEE; - outport((reg << 8) | val); + int i; +#asm + ;push ds + ;push es + mov ax, 0x0 + mov ds, ax + xor ax, ax + mov es, ax +#endasm + for (i = 0; i < cnt; ++i) { + *dest++ = *src++; + //*dest++ = 0x66; } +#asm + ;pop es + ;pop ds + mov ds, 0xF000 +#endasm + return dest; +} + +void test_copy() +{ +#asm + ;mov ds, 0 +#endasm + +// unsigned short dest = 0xFE00; +// unsigned * ptr = dest; +// *ptr++ = 0xDEAD; +// *ptr++ = 0xAAAA; +// *ptr++ = 0xDEAD; + memcpy(0xFE00, 0x1000, 16); +#asm + ;mov ds, 0xF000 +#endasm + //wmemcpy(WSC_PALETTES, 0x2F000, 32); + return; +} + +int main() +{ + unsigned short data_seg = 0xF000; + unsigned short data_ram = 0x1000; + unsigned short rel_ram = data_seg - data_ram; + + /* dummy */ + memcpy(0x0, 0x0, 0); + + memcpy(0xFE00, data - rel_ram, 16); + //memcpy(0xFE00, data_seg + data, 16); + + //while(1) { + // /* outport(0x15EE); */ + // unsigned reg = 0x15; + // unsigned val = 0xEE; + // outport((reg << 8) | val); + + //} + + return 0; } -- 2.7.4