initial commit

This commit is contained in:
2014-01-18 15:06:11 +01:00
parent 3fabb8dcf8
commit 768bec39b3
408 changed files with 171325 additions and 2 deletions

38
demo/src9/Makefile Normal file
View File

@@ -0,0 +1,38 @@
export PATH := $(DEVKITARM)/bin:$(PATH)
AS = arm-eabi-gcc
CC = arm-eabi-gcc
LD = arm-eabi-ld
OBJCOPY = arm-eabi-objcopy
ARCH = -mthumb -mthumb-interwork
CFLAGS = -Wall -Os -DARM9 -march=armv5te -mtune=arm946e-s
CFLAGS += -nostdlib -nodefaultlibs -nostartfiles -fomit-frame-pointer
INCLUDE = -Isrc -I$(DEVKITPRO)/libnds/include
ASFLAGS = -x assembler-with-cpp -I src
LDFLAGS = -mno-fpu -specs=ds_arm9.specs
LDFLAGS += -nostdlib -nodefaultlibs -nostartfiles
LDFLAGS += -Wl,-Map,arm9.map
ASMFILES = $(wildcard src/*.s)
CFILES = $(wildcard src/*.c)
OBJS = $(CFILES:.c=.o) $(ASMFILES:.s=.o)
#TODO : add auto asm dump
.c.o: %.c
@echo Compiling $<
@$(CC) $(ARCH) $(CFLAGS) $(INCLUDE) -o $@ -c $<
.s.o: %.s
@echo Assembling $<
@$(AS) $(ASFLAGS) -o $@ -c $<
bin: elf
@$(OBJCOPY) -O binary $< $@
elf: $(OBJS)
@echo -e '\e[1;33mLinking...\e[0m'
@$(CC) $(ARCH) $(LDFLAGS) -o $@ $(OBJS)
clean:
rm -f elf bin $(OBJS)

73
demo/src9/src/3D.h Normal file
View File

@@ -0,0 +1,73 @@
#ifndef _3D_H_
#define _3D_H_
#include <nds.h>
// Commands
#define CMTXMODE 0x10
#define CMTXPUSH 0x11
#define CMTXPOP 0x12
#define CMTXIDENTITY 0x15
#define CMTXLOAD4x4 0x16
#define CMTXLOAD4x3 0x17
#define CMTXMULT3x3 0x1A
#define CMTXSCALE 0x1B
#define CMTXTRANSLATE 0x1C
#define CCOLOR 0x20
#define CNORMAL 0x21
#define CVERTEX 0x24
#define CPOLYATTR 0x29
#define CDIFAMB 0x30
#define CLIGHTVECTOR 0x32
#define CLIGHTCOLOR 0x33
#define CBEGIN 0x40
#define CVIEWPORT 0x60
// Parameters
#define PROJECTION 0
#define MODELVIEW 2
#define QUAD 1
#define NORMAL(x,y,z) (((x)&0x3FF)|(((y)&0x3FF)<<10)|(((z)&0x3FF)<<20))
#define VERTEX(x,y,z) \
(((x)&0x3FF)|(((y)&0x3FF)<<10)|(((z)&0x3FF)<<20))
#define DIFAMB(dif,amb) ((dif)|((amb)<<16))
#define VIEWPORT(x1,y1,x2,y2) ((x1)|((y1)<<8)|((x2)<<16)|((y2)<<24))
// Polygon attributes
#define LIGHT0 BIT(0)
#define POLYFRONT BIT(7)
#define POLYBACK BIT(6)
#define SOLID (31<<16)
#define ALPHA(a) ((a)<<16)
#define WIREFRAME (0<<16)
// GX FIFO command packer
#define COMMAND(a,b,c,d) \
(((a)&0xFF)|(((b)&0xFF)<<8)|(((c)&0xFF)<<16)|(((d)&0xFF)<<24))
void call_list(u32 * list, int size);
#define push() MATRIX_PUSH = 0
#define pop() MATRIX_POP = 1
#define identity() MATRIX_IDENTITY = 0
#define swap() GFX_FLUSH = 0
#define translate(x, y, z) \
MATRIX_TRANSLATE = x; \
MATRIX_TRANSLATE = y; \
MATRIX_TRANSLATE = z
#define scale(x, y, z) \
MATRIX_SCALE = x; \
MATRIX_SCALE = y; \
MATRIX_SCALE = z
void rotate(int angle, int v);
#define rotateX(angle) rotate(angle, 1)
#define rotateY(angle) rotate(angle, 2)
#define rotateZ(angle) rotate(angle, 3)
#endif // _3D_H_

25
demo/src9/src/3D.s Normal file
View File

@@ -0,0 +1,25 @@
.arch armv5te
.thumb
.text
.align 2
.global call_list
.thumb_func
.type call_list, %function
call_list:
ldr r3, dmasrc
str r0, [r3]
ldr r2, fifo
str r2, [r3, #4]
ldr r2, param
orr r1, r2
str r1, [r3, #8]
busy:
ldr r2, [r3, #8]
cmp r2, #0
blt busy
bx lr
.L6:
.align 2
dmasrc: .word 0x40000B0
fifo: .word 0x4000400
param: .word (1<<31)|(7<<27)|(1<<22)|(1<<26) @; enable, startfifo, destfix, 32bit

View File

@@ -0,0 +1,203 @@
#include "options.h"
@--------------------------------------------------------------------------------
@ DS processor selection
@--------------------------------------------------------------------------------
.arch armv5te
.cpu arm946e-s
@--------------------------------------------------------------------------------
#define PAGE_4K (0b01011 << 1)
#define PAGE_8K (0b01100 << 1)
#define PAGE_16K (0b01101 << 1)
#define PAGE_32K (0b01110 << 1)
#define PAGE_64K (0b00111 << 1)
#define PAGE_128K (0b10000 << 1)
#define PAGE_256K (0b10001 << 1)
#define PAGE_512K (0b10010 << 1)
#define PAGE_1M (0b10011 << 1)
#define PAGE_2M (0b10100 << 1)
#define PAGE_4M (0b10101 << 1)
#define PAGE_8M (0b10110 << 1)
#define PAGE_16M (0b10111 << 1)
#define PAGE_32M (0b11000 << 1)
#define PAGE_64M (0b11001 << 1)
#define PAGE_128M (0b11010 << 1)
#define PAGE_256M (0b11011 << 1)
#define PAGE_512M (0b11100 << 1)
#define PAGE_1G (0b11101 << 1)
#define PAGE_2G (0b11110 << 1)
#define PAGE_4G (0b11111 << 1)
#define ITCM_LOAD (1<<19)
#define ITCM_ENABLE (1<<18)
#define DTCM_LOAD (1<<17)
#define DTCM_ENABLE (1<<16)
#define DISABLE_TBIT (1<<15)
#define ROUND_ROBIN (1<<14)
#define ALT_VECTORS (1<<13)
#define ICACHE_ENABLE (1<<12)
#define BIG_ENDIAN (1<<7)
#define DCACHE_ENABLE (1<<2)
#define PROTECT_ENABLE (1<<0)
#if SAFE
.equ _libnds_argv,0x027FFF70
#endif
@--------------------------------------------------------------------------------
.section ".init"
.global _start
@--------------------------------------------------------------------------------
.align 4
.arm
@--------------------------------------------------------------------------------
_start:
@--------------------------------------------------------------------------------
#if SAFE
mov r0, #0x04000000 @ IME = 0;
str r0, [r0, #0x208]
@--------------------------------------------------------------------------------
@ turn the power on for M3
@--------------------------------------------------------------------------------
ldr r1, =0x8203
add r0,r0,#0x304
strh r1, [r0]
ldr r1, =0x00002078 @ disable TCM and protection unit
mcr p15, 0, r1, c1, c0
@--------------------------------------------------------------------------------
@ Protection Unit Setup added by Sasq
@--------------------------------------------------------------------------------
@ Disable cache
mov r0, #0
mcr p15, 0, r0, c7, c5, 0 @ Instruction cache
mcr p15, 0, r0, c7, c6, 0 @ Data cache
@ Wait for write buffer to empty
mcr p15, 0, r0, c7, c10, 4
ldr r0, =__dtcm_start
orr r0,r0,#0x0a
mcr p15, 0, r0, c9, c1,0 @ DTCM base = __dtcm_start, size = 16 KB
mov r0,#0x20
mcr p15, 0, r0, c9, c1,1 @ ITCM base = 0 , size = 32 MB
@--------------------------------------------------------------------------------
@ Setup memory regions similar to Release Version
@--------------------------------------------------------------------------------
@------------------------------------------------------------------------
@ Region 0 - IO registers
@------------------------------------------------------------------------
ldr r0,=( PAGE_64M | 0x04000000 | 1)
mcr p15, 0, r0, c6, c0, 0
@------------------------------------------------------------------------
@ Region 1 - Main Memory
@------------------------------------------------------------------------
ldr r0,=( PAGE_4M | 0x02000000 | 1)
mcr p15, 0, r0, c6, c1, 0
@------------------------------------------------------------------------
@ Region 2 - alternate vector base
@------------------------------------------------------------------------
ldr r0,=( PAGE_4K | 0x00000000 | 1)
mcr p15, 0, r0, c6, c2, 0
@------------------------------------------------------------------------
@ Region 3 - DS Accessory (GBA Cart)
@------------------------------------------------------------------------
ldr r0,=( PAGE_128M | 0x08000000 | 1)
mcr p15, 0, r0, c6, c3, 0
@------------------------------------------------------------------------
@ Region 4 - DTCM
@------------------------------------------------------------------------
ldr r0,=__dtcm_start
orr r0,r0,#(PAGE_16K | 1)
mcr p15, 0, r0, c6, c4, 0
@------------------------------------------------------------------------
@ Region 5 - ITCM
@------------------------------------------------------------------------
ldr r0,=__itcm_start
@ align to 32k boundary
mov r0,r0,lsr #15
mov r0,r0,lsl #15
orr r0,r0,#(PAGE_32K | 1)
mcr p15, 0, r0, c6, c5, 0
@------------------------------------------------------------------------
@ Region 6 - System ROM
@------------------------------------------------------------------------
ldr r0,=( PAGE_32K | 0xFFFF0000 | 1)
mcr p15, 0, r0, c6, c6, 0
@------------------------------------------------------------------------
@ Region 7 - non cacheable main ram
@------------------------------------------------------------------------
ldr r0,=( PAGE_4M | 0x02400000 | 1)
mcr p15, 0, r0, c6, c7, 0
@------------------------------------------------------------------------
@ Write buffer enable
@------------------------------------------------------------------------
ldr r0,=0b00000010
mcr p15, 0, r0, c3, c0, 0
#endif
@------------------------------------------------------------------------
@ DCache & ICache enable
@------------------------------------------------------------------------
ldr r0,=0b01000010
#if SAFE
mcr p15, 0, r0, c2, c0, 0
#endif
mcr p15, 0, r0, c2, c0, 1
#if SAFE
@------------------------------------------------------------------------
@ IAccess
@------------------------------------------------------------------------
ldr r0,=0x36636633
mcr p15, 0, r0, c5, c0, 3
@------------------------------------------------------------------------
@ DAccess
@------------------------------------------------------------------------
ldr r0,=0x36333633
mcr p15, 0, r0, c5, c0, 2
#endif
@------------------------------------------------------------------------
@ Enable ICache, DCache, ITCM & DTCM
@------------------------------------------------------------------------
mrc p15, 0, r0, c1, c0, 0
#if SAFE
ldr r1,= ITCM_ENABLE | DTCM_ENABLE | ICACHE_ENABLE | DCACHE_ENABLE | PROTECT_ENABLE
#else
ldr r1, =ICACHE_ENABLE|DCACHE_ENABLE|PROTECT_ENABLE
#endif
orr r0,r0,r1
mcr p15, 0, r0, c1, c0, 0
#if SAFE
mov r0, #0x12 @ Switch to IRQ Mode
msr cpsr, r0
ldr sp, =__sp_irq @ Set IRQ stack
mov r0, #0x13 @ Switch to SVC Mode
msr cpsr, r0
ldr sp, =__sp_svc @ Set SVC stack
mov r0, #0x1F @ Switch to System Mode
msr cpsr, r0
ldr sp, =__sp_usr @ Set user stack
#endif
ldr r3, =Main
blx r3 @ jump to user code

52
demo/src9/src/init.s Normal file
View File

@@ -0,0 +1,52 @@
.arch armv5te
.thumb
.global Init
.text
.thumb_func
.type Init, %function
Init:
@; POWERCNT = POWER_ALL
ldr r0, =0x04000304
ldr r1, =0x20F
strh r1, [r0]
@; GFX_CLEAR_COLOR = black, opaque, id=63
ldr r0, =0x04000350
ldr r1, =0x3F1F0000
str r1, [r0]
@; GFX_CLEAR_DEPTH = 0x7FFF
ldr r1, =0x7FFF
strh r1, [r0, #4]
@; DISPCNT = MODE 0, BG0, 3D
ldr r0, =0x04000000
ldr r1, =0x10000|(1<<8)|(1<<3)
str r1, [r0]
@; GFX_CONTROL = ANTIALIAS, BLEND
ldr r0, =0x04000060
ldr r1, =(1<<3)|(1<<4)
strh r1, [r0]
@; DISPCNT_SUB = MODE 5, BG3, SPR, SPR_2D_BMP_256
ldr r0, =0x04001000
ldr r1, =0x10005|(1<<11)|(1<<12)|(2<<4)
str r1, [r0]
@; BG3CNT_SUB = BMP16 256x256
ldr r1, =0x4084
strh r1, [r0, #0x0E]
@; BG3PA_SUB = 256
ldr r1, =256
strh r1, [r0, #0x30]
@; BG3PD_SUB = 256
strh r1, [r0, #0x36]
bx lr
.align 2
.pool

573
demo/src9/src/main.c Normal file
View File

@@ -0,0 +1,573 @@
#include <nds.h>
#include "options.h"
#include "trig.h"
#include "3D.h"
#define FADES 1 // ~128 bytes... (packed)
#if FADES
#define BRIGHT (1<<14)
#define DARK (2<<14)
int fade_current = 31 << 2; // starts white
int fade_target = 16 << 2;
#endif
u32 cubelist[] =
{
COMMAND(CDIFAMB, CBEGIN, CNORMAL, CVERTEX),
DIFAMB(RGB15(16, 16, 16), RGB15(8, 8, 8)),
QUAD,
NORMAL(0, 512, 0),
VERTEX(-64,-64,-64),
COMMAND(CVERTEX, CVERTEX, CVERTEX, CNORMAL),
VERTEX( 64,-64,-64),
VERTEX( 64,-64, 64),
VERTEX(-64,-64, 64),
NORMAL(0, 511, 0),
COMMAND(CVERTEX, CVERTEX, CVERTEX, CVERTEX),
VERTEX(-64, 64,-64),
VERTEX(-64, 64, 64),
VERTEX( 64, 64, 64),
VERTEX( 64, 64,-64),
COMMAND(CNORMAL, CVERTEX, CVERTEX, CVERTEX),
NORMAL(512, 0, 0),
VERTEX(-64,-64,-64),
VERTEX(-64,-64, 64),
VERTEX(-64, 64, 64),
COMMAND(CVERTEX, CNORMAL, CVERTEX, CVERTEX),
VERTEX(-64, 64,-64),
NORMAL(511, 0, 0),
VERTEX( 64,-64,-64),
VERTEX( 64, 64,-64),
COMMAND(CVERTEX, CVERTEX, CNORMAL, CVERTEX),
VERTEX( 64, 64, 64),
VERTEX( 64,-64, 64),
NORMAL( 0, 0, 512),
VERTEX(-64,-64,-64),
COMMAND(CVERTEX, CVERTEX, CVERTEX, CNORMAL),
VERTEX(-64, 64,-64),
VERTEX( 64, 64,-64),
VERTEX( 64,-64,-64),
NORMAL( 0, 0, 511),
COMMAND(CVERTEX, CVERTEX, CVERTEX, CVERTEX),
VERTEX(-64,-64, 64),
VERTEX( 64,-64, 64),
VERTEX( 64, 64, 64),
VERTEX(-64, 64, 64),
};
#define cube() call_list(cubelist, sizeof(cubelist)/sizeof(u32))
u32 initlist[] =
{
COMMAND(CVIEWPORT, CMTXMODE, CMTXLOAD4x4, 0),
VIEWPORT(0, 0, 255, 191), // full screen
PROJECTION, // matrix mode
// Projection matrix Perspective(fov=50<35>, near=0.1, far=40, ratio=1.33)
6587, 0, 0, 0,
0, 8783, 0, 0,
0, 0, -4116, -4096,
0, 0, -821, 0,
COMMAND(CMTXMODE, CMTXIDENTITY, CLIGHTVECTOR, CLIGHTCOLOR),
MODELVIEW, // matrix mode
NORMAL(-96, -144, -482), // light vector
RGB15(31, 31, 31), // light color
};
#define init() call_list(initlist, sizeof(initlist)/sizeof(u32))
void rotate(int angle, int v)
{
int s = sin(angle);
int c = cos(angle);
if ( v == 1 ) {
MATRIX_MULT3x3 = 1<<12;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = c;
MATRIX_MULT3x3 = s;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = -s;
MATRIX_MULT3x3 = c;
} else if ( v == 2 ) {
MATRIX_MULT3x3 = c;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = -s;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = 1<<12;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = s;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = c;
} else {
MATRIX_MULT3x3 = c;
MATRIX_MULT3x3 = s;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = -s;
MATRIX_MULT3x3 = c;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = 0;
MATRIX_MULT3x3 = 1<<12;
}
}
void arms(int t, int m)
{
push();
// translate(0.24f*m, 0.4f, 0);
translate(983*m, 1638, 0);
// rotateZ(30<33>*m);
rotateZ(2145*m);
// rotateX(cos(t)*20<32>+180<38>);
rotateX(((cos(t)*1430)>>12)+12868);
// translate(0, 0.3, 0);
translate(0, 1229, 0);
push();
// scale(0.1, 0.3, 0.1);
scale(410, 1229, 410);
cube();
pop();
// translate(0, 0.22, 0);
translate(0, 901, 0);
// rotateY(abs(cos(t))*16*m);
int act = cos(t)*1144;
if ( act < 0 )
act = -act;
rotateY((act>>12)*m);
// rotateX(100<30>);
rotateX(7149);
// rotateZ(165<36>*m);
rotateZ(11796*m);
// translate(0, 0.21, 0);
translate(0, 860, 0);
push();
// scale(0.09, 0.27, 0.09);
scale(369, 1106, 369);
cube();
pop();
pop();
}
void legs(int t, int m)
{
push();
// translate(0.19*m, 0, -0.015);
translate(778*m, 0, -61);
// rotateX(cos(t)*13<31>-2.5);
rotateX(((cos(t)*929)>>12)-228); // 929->1024 = -12 bytes !
// translate(0, -0.7, 0);
translate(0, -2867, 0);
push();
// scale(0.1, 0.25, 0.1);
scale(410, 1024, 410);
cube();
pop();
// float d = -min(0, cos(t+3.14157/2));
int d = -cos(t+6434);
if ( d < 0 )
d = 0;
// translate(0, d*0.15-0.52, d*0.015-0.06);
translate(0, ((d*512)>>12)-2130, ((d*61)>>12)-246);
// rotateX(10<31>);
rotateX(715);
push();
// scale(0.1, 0.3, 0.1);
scale(410, 1229, 410);
cube();
pop();
// translate(0, -0.3, 0.1);
translate(0, -1229, 410);
push();
// scale(0.1, 0.03, 0.2);
scale(410, 123, 819);
cube();
pop();
pop();
}
void robot(int t, int T)
{
#define robot_fall_speed 2048
#define robot_start 40
t *= 402;
// ast = |sin(t)|
int ast = sin(t);
if ( ast < 0 )
ast = -ast;
// act = |cos(t)|
int act = cos(t);
if ( act < 0 )
act = -act;
int fall;
// head
push();
// translate(0, 0.71+0.05*abs(sin(t)), 0.04);
fall = (robot_start+88)*robot_fall_speed - T*robot_fall_speed;
if ( fall < 0 )
fall = 0;
translate(0, 2908+((ast*204)>>12)+fall, 164);
// rotateX(-5<>+10<31>*abs(cos(t)));
rotateX((-357+715*act)>>12);
// scale(0.2, 0.2, 0.2);
scale(819, 819, 819);
cube();
pop();
// body
push();
// translate(0, 0.05*abs(sin(t)), 0);
fall = (robot_start+48)*robot_fall_speed - T*robot_fall_speed;
if ( fall < 0 )
fall = 0;
translate(0, ((ast*204)>>12)+fall, 0);
// rotateY(2.5<EFBFBD>-5<>*cos(t));
rotateY(179-((357*cos(t))>>12));
// scale(0.3, 0.5, 0.17);
scale(1229, 2048, 696);
cube();
pop();
// left side
push();
fall = (robot_start+56)*robot_fall_speed - T*robot_fall_speed;
if ( fall < 0 )
fall = 0;
translate(0, fall, 0);
arms(t, -1);
pop();
push();
fall = (robot_start+8)*robot_fall_speed - T*robot_fall_speed;
if ( fall < 0 )
fall = 0;
translate(0, fall, 0);
legs(t, -1);
pop();
// right side
t += 12868;
push();
fall = (robot_start+64)*robot_fall_speed - T*robot_fall_speed;
if ( fall < 0 )
fall = 0;
translate(0, fall, 0);
arms(t, 1);
pop();
push();
fall = (robot_start+24)*robot_fall_speed - T*robot_fall_speed;
if ( fall < 0 )
fall = 0;
translate(0, fall, 0);
legs(t, 1);
pop();
}
// r * cos((x*pi/2)/r) * cos((y*pi/2)/r) - r
// returns a fixed point altitude value in fx.6
int f(int x, int y)
{
const int r = 32;
// const int _r = (int)((0.5f/(float)r)*64.0f); // == 1 ...
// x = (x*_r);
// y = (y*_r);
return ((r * (uber_cos(x) * uber_cos(y))>>18)) - (r<<6);
}
void sonic(int t)
{
int i = 0;
int y, x;
rotateX(-1024);
if ( t < 256 )
t = 0;
else
t = -(t*2)&127;
for ( y = -7*64+t ; y < 6*64+t ; y += 64 ) {
for ( x = -7*64 ; x < 6*64 ; x += 64 ) {
GFX_VERTEX10 = VERTEX(x, f(x, y), y);
GFX_VERTEX10 = VERTEX(x, f(x, y+64), y+64);
GFX_VERTEX10 = VERTEX(x+64, f(x+64, y+64), y+64);
GFX_VERTEX10 = VERTEX(x+64, f(x+64, y), y);
GFX_COLOR = (i&1) ? RGB15(29, 15, 4) : RGB15(4, 11, 28);
i++;
}
//i++;
}
}
void spot(int c1, int c2, int w, int h)
{
GFX_BEGIN = QUAD;
GFX_COLOR = c1;
GFX_VERTEX10 = VERTEX(-64, h, 0);
GFX_VERTEX10 = VERTEX( 64, h, 0);
GFX_COLOR = c2;
GFX_VERTEX10 = VERTEX( 64+w, 64, 0);
GFX_VERTEX10 = VERTEX(-64-w, 64, 0);
}
void robot_solo(int t)
{
int T = t;
if ( t < 256 ) {
// stopped for the intro
t = 0;
} else if ( t > 1152 ) {
// tracted by the flying saucer
int y;
y = (t-1152)*58;
if ( y > 22528 )
y = 22528;
translate(0, y, 0);
y = (8*4096-y)/8;
scale(y, y, y);
t = 0;
}
robot(t, T);
}
int jump(int t)
{
if ( t < 512 )
return 0;
t = t%64;
t = t*8-384+128;
t = 3072-t*t;
if ( t < 0 )
return 0;
return t;
}
void robot_clone_wars(int t)
{
#define SPACE_FLOOR 1
#define FINAL_WALK_ON 1
#define LINES 6
#define SPACING 16384
int i, j;
//rotateX(2560);
if ( (t & 1) == 0 ) { // different camera for different screens
translate(5120, 44032, 20480);
rotateZ(1792);
} else {
rotateX(2560);
}
#if SPACE_FLOOR
push();
translate(0, -6144, -4096*4);
rotateX(-12867/2);
scale(4096*16, 4096*10, 4096*10);
spot(RGB15(0, 7, 3), RGB15(0, 2, 1), 0, -64);
pop();
#endif
#if SPACE_FLOOR
int z = t*256-16384;
#else
int z = t*256*8-16384*8;
#endif
if ( z > 0 )
z = 0;
int lines = (t-192+8)/8;
if ( lines < 2 )
lines = 2;
else if ( lines > LINES )
lines = LINES;
for ( i = 1 ; i < lines ; i++ ) {
translate(0, 0, -8192);
for ( j = 0 ; j < i ; j++ ) {
if ( j == 2 && i == 5 )
continue;
push();
translate(j * SPACING - ((i-1)*SPACING)/2, jump(t-i*4)+z, 0);
#if FINAL_WALK_ON
if ( t < 512 )
robot(8, 256);
else
robot(8+t-512, 256);
#else
robot(8);
#endif
pop();
}
}
}
void background(int t)
{
#if FADES
if ( t == 1536 ) {
fade_current = 0;
fade_target = 16<<2;
}
#endif
if ( t < 1536 )
spot(RGB15(31, 31, 31), RGB15(12, 12, 31), 0, -64);
else
spot(RGB15(1, 5, 2), RGB15(0, 0, 0), 0, -64);
}
void fs(int t)
{
static int h[9] = { 64, 58, 51, 32, 26, 19, 10, 1, 0 };
static int r[9] = { 0, 819, 1229, 1638, 3276, 4096, 3276, 2048, 0 };
int y = 1024*32-t*32;
if ( y < 0 )
y = 0;
translate(y, y, -y);
GFX_COLOR = RGB15(15, 15, 15);
int i, j;
for ( i = 0 ; i < 8 ; i++ ) {
for ( j = 0 ; j < 8192 ; j += 512 ) {
GFX_NORMAL = VERTEX((uber_cos(j) * r[i])>>18, h[i], (uber_sin(j) * r[i])>>18);
GFX_VERTEX10 = VERTEX((uber_cos(j) * r[i])>>18, h[i], (uber_sin(j) * r[i])>>18);
GFX_VERTEX10 = VERTEX((uber_cos(j+512) * r[i])>>18, h[i], (uber_sin(j+512) * r[i])>>18);
GFX_VERTEX10 = VERTEX((uber_cos(j+512) * r[i+1])>>18, h[i+1], (uber_sin(j+512) * r[i+1])>>18);
GFX_VERTEX10 = VERTEX((uber_cos(j) * r[i+1])>>18, h[i+1], (uber_sin(j) * r[i+1])>>18);
}
}
}
void fs_beam(int t)
{
int h = 64+8+384-t*4;
if ( h < 0 )
h = 0;
GFX_POLY_FORMAT = LIGHT0|POLYFRONT|ALPHA(15);
spot(RGB15(0, 31, 4), RGB15(0, 31, 4), -32, h-384);
}
typedef struct {
void (*draw)(int time);
s16 start, end;
s8 ty, tz;
s8 s;
} Drawable;
Drawable demo[] =
{
// draw start, end ty, tz scale
{ robot_solo, 0, 1536, 1, -15, 4 },
{ sonic, 0, 1536, -8, -24, 4 },
{ fs, 0, 1536, 21, -15, 4 },
{ robot_clone_wars, 1536, 2576, -4, -16, 2 },
{ background, 0, 2576, 9, -44, 32 },
{ fs_beam, 1024, 1536, 18, -13, 4 },
};
void Main()
{
extern void Init();
Init();
init();
// Init sprites to display like a big bitmap background
//VRAM_D_CR = VRAM_D_SUB_SPRITE | VRAM_ENABLE;
int y, x;
u16 * ptr = OAM_SUB;
for ( y = 0 ; y < 3 ; y++ ) {
for ( x = 0 ; x < 4 ; x++ ) {
// attribute 0
*ptr++ = ATTR0_BMP | (y*64);
// attribute 1
*ptr++ = ATTR1_SIZE_64 | (x*64);
// attribute 2
*ptr++ = ATTR2_ALPHA(15) | (x*8+y*256);
// pad (matrix)
ptr++;
}
}
int t = 0;
while ( t < 2576 ) {
#if FADES
if ( fade_current < fade_target )
fade_current++;
else if ( fade_current > fade_target )
fade_current--;
int v = 0;
if ( fade_current < (16 << 2) )
v = DARK | (16 - (fade_current >> 2));
else if ( fade_current > (16 << 2) )
v = BRIGHT | ((fade_current >> 2) - 16);
REG_MASTER_BRIGHT = v;
REG_MASTER_BRIGHT_SUB = v;
#endif
identity();
// Dual screen 3D
if ( t&1 ) {
REG_POWERCNT &= ~POWER_SWAP_LCDS; // main on bottom
VRAM_C_CR = VRAM_ENABLE;
VRAM_D_CR = VRAM_D_SUB_SPRITE | VRAM_ENABLE;
REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
} else {
REG_POWERCNT |= POWER_SWAP_LCDS; // main on top
VRAM_C_CR = VRAM_C_SUB_BG | VRAM_ENABLE;
VRAM_D_CR = VRAM_ENABLE;
REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
translate(0, -5*4096, 0);
}
// Reset polygon attributes
GFX_POLY_FORMAT = LIGHT0|POLYFRONT|SOLID;
// Lightweight 3D player -olol
int i;
for ( i = 0 ; i < sizeof(demo)/sizeof(Drawable) ; i++ ) {
if ( t >= demo[i].start && t < demo[i].end ) {
push();
translate(0, demo[i].ty*1024, demo[i].tz*1024);
scale(demo[i].s*1024, demo[i].s*1024, demo[i].s*1024);
demo[i].draw(t-demo[i].start);
pop();
}
}
t++;
swap();
}
extern void seeya();
seeya();
}

BIN
demo/src9/src/msg Normal file

Binary file not shown.

68
demo/src9/src/msg.s Normal file
View File

@@ -0,0 +1,68 @@
.arch armv5te
.align 2
.text
.thumb
.global seeya
.thumb_func
.type seeya, %function
seeya:
@; dispcnt = mode 0, bg0 active
ldr r0, =0x04000000
ldr r1, =0x10000 | (1<<8)
str r1, [r0]
@; bg0cnt = tilebase=1, mapbase=0
ldr r1, =(1<<2)
str r1, [r0, #8]
@; scroll text horizontally
ldr r1, =256-108
strh r1, [r0, #0x10]
@; scroll text vertically
ldr r1, =256-92
strh r1, [r0, #0x12]
@; enable vram A in bg mode @0x06000000
ldr r0, =0x04000240
ldr r1, =(1<<7)|1
str r1, [r0]
@; bg palette color 1 = white
ldr r0, =0x05000002
ldr r1, =(1<<15)-1
strh r1, [r0]
@; fill map
ldr r0, =0x06000000
mov r1, #0
textloop:
strh r1, [r0]
add r0, #2
add r1, #1
cmp r1, #(msgend-msg)/8
bne textloop
@; unpack tiles directly to vram
ldr r0, =msg
ldr r1, =0x06004000
ldr r2, =unpackinfo
swi 0x10
@; infinite wait (interrupts aren't enabled ;)
swi 0x05
.align 2
.pool
.align 2
msg:
.incbin "msg"
msgend:
.align 2
unpackinfo:
.hword msgend-msg
.byte 1
.byte 4
.word 0

8
demo/src9/src/options.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _OPTIONS_H_
#define _OPTIONS_H_
#define STDLIB 0
#define CAMERA 0
#define SAFE 0
#endif // _OPTIONS_H_

12
demo/src9/src/trig.c Normal file
View File

@@ -0,0 +1,12 @@
#include "trig.h"
#include <nds.h>
int uber_sin(int x)
{
// TODO this may be simplified
x = 4096 - (x & 0x1FFF);
int ax = x;
if ( ax < 0 )
ax = -ax;
return 4 * x - ((4 * x * ax) >> 12);
}

17
demo/src9/src/trig.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef _TRIG_H_
#define _TRIG_H_
// approximation of sin with pi=4096
//
// pi-(x mod 2pi) then
// 4.x - 4.x.|x|
int uber_sin(int x);
#define uber_cos(x) uber_sin(x + 0x800)
// Conversion from old cos/sin to new uber cos/sin
// The old was working with real value of pi in fixed point 12 (pi = 12867)
// while the new one uses pi = 4096
#define sin(x) uber_sin((((x) * 325) >> 10))
#define cos(x) uber_cos((((x) * 325) >> 10))
#endif // _TRIG_H_