Skip to content

Commit

Permalink
Added first bunch of docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kochise committed Mar 26, 2017
1 parent 030746c commit fd52e73
Show file tree
Hide file tree
Showing 198 changed files with 19,340 additions and 0 deletions.
542 changes: 542 additions & 0 deletions AICA/DOCS/aica.txt

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions AICA/SRCS/sound/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

ARMCC = arm-elf-gcc
ARMAS = arm-elf-as -marm7
ARMLD = arm-elf-ld

ARMCFLAGS = -mcpu=arm7 -ffreestanding -fomit-frame-pointer -O4

AS = sh-elf-as -little
LD = sh-elf-ld -EL
CC = sh-elf-gcc -ml


music.srec : crt0.o dcmain.o
$(CC) -o $@ -Wl,--oformat,srec,-Ttext,0x8c010000 \
-nostartfiles crt0.o dcmain.o -lgcc

dcmain.o : dcmain.c music.h

crt0.o : crt0.s

music.h : music.bin
./bintohex.pl < $< > $@

music.bin : music.elf
arm-elf-objcopy -O binary $< $@

music.elf : base.o music.o aica.o
$(ARMCC) $(ARMCFLAGS) -Wl,-Ttext=0 -nostartfiles -nostdlib -o $@ base.o music.o aica.o -lgcc

base.o : base.s
$(ARMAS) -o $@ $<

music.o : music.c aica.h bwv784.h
$(ARMCC) $(ARMCFLAGS) -c -o $@ $<

aica.o : aica.c aica.h
$(ARMCC) $(ARMCFLAGS) -c -o $@ $<


clean :
-rm -f *.o *.bin *.elf *.srec
-rm -f music.h

66 changes: 66 additions & 0 deletions AICA/SRCS/sound/aica.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "aica.h"

#define AICA(n) ((volatile unsigned int *)(void*)(0x800000+(n)))

void aica_reset()
{
int i, j;
volatile unsigned int *hwptr = AICA(0);

*AICA(0x2800) = 0;

/* Reset all 64 channels to a silent state */
for(i=0; i<64; i++) {
hwptr[0] = 0x8000;
hwptr[5] = 0x1f;
hwptr[1] = 0;
hwptr[2] = 0;
hwptr[3] = 0;
hwptr[4] = 0;
for(j=6; j<32; j++)
hwptr[j] = 0;
hwptr += 32;
}

*AICA(0x2800) = 15;
}

void play_sound(int channel, void *data, int mode, int nsamp, int freq,
int vol, int pan)
{
volatile unsigned int *hwptr = AICA(channel<<7);
unsigned long freq_lo, freq_base = 5644800;
int freq_hi = 7;

/* Set sample format and buffer address */
hwptr[0] = 0x4200 | (mode<<7) | (((unsigned long)data)>>16);
hwptr[1] = ((unsigned long)data) & 0xffff;
/* Number of samples */
hwptr[3] = nsamp;
/* Need to convert frequency to floating point format
(freq_hi is exponent, freq_lo is mantissa).
Formula is freq = 44100*2^freq_hi*(1+freq_lo/1024) */
while(freq < freq_base && freq_hi > -8) {
freq_base >>= 1;
--freq_hi;
}
freq_lo = (freq<<10)/freq_base;
/* Write resulting values */
hwptr[6] = (freq_hi<<11)|(freq_lo&1023);
/* Set volume, pan, and some other stuff */
((volatile unsigned char *)(hwptr+9))[4] = 0x24;
((volatile unsigned char *)(hwptr+9))[1] = 0xf;
((volatile unsigned char *)(hwptr+9))[5] = vol;
((volatile unsigned char *)(hwptr+9))[0] = pan;
hwptr[4] = 0x1f;
/* Enable playback */
hwptr[0] |= 0xc000;
}

void stop_sound(int channel)
{
volatile unsigned int *hwptr = AICA(channel<<7);

/* Disable playback */
hwptr[0] = (hwptr[0] & ~0x4000) | 0x8000;
}
19 changes: 19 additions & 0 deletions AICA/SRCS/sound/aica.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Sample formats */
#define MODE_16BIT 0
#define MODE_8BIT 1
#define MODE_ADPCM 3

/* Volume 0 is max, higher is lower */
#define VOL_MAX 0x00
#define VOL_MIN 0xff

/* Pan is 5 bit sign-value (it seems) */
#define PAN_LEFT 0x1f
#define PAN_RIGHT 0x0f
#define PAN_CENTER 0x00

/* Prototypes */
extern void aica_reset(void);
extern void play_sound(int channel, void *data, int mode, int nsamp, int freq,
int vol, int pan);
extern void stop_sound(int channel);
109 changes: 109 additions & 0 deletions AICA/SRCS/sound/base.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#
# Generic startup and interrupt handler for ARM7 CPU.
#
# Note: Stack is allocated at 0xf000, keep the binary short. :-)
#

.globl _start, timer

.text


# Exception vectors
_start:
b reset
b undef
b softint
b pref_abort
b data_abort
b rsrvd
b irq


# "Fast interrupt" handler
fiq:

# Check type of interrupt

ldr r8,intreq
ldr r9,[r8]
and r9,r9,#7
cmp r9,#2
bne fiq_done

# Type 2 is timer interrupt.

# Increment timer variable

adr r8,timer
ldr r9,[r8]
add r9,r9,#1
str r9,[r8]

# Request a new timer interrupt in about
# one millisecond

ldr r8,fooaddr
mov r9,#256-(44100/1000)
str r9,[r8,#0x10]
mov r9,#0x40
str r9,[r8,#0x24]
b fiq_done

# Return from interrupt

fiq_done:
ldr r8,intclr
mov r9,#1
str r9,[r8]
str r9,[r8]
str r9,[r8]
str r9,[r8]
subs pc,r14,#4


intreq:
.long 0x802d00
intclr:
.long 0x802d04
fooaddr:
.long 0x802880
timer:
.long 0


# No-op handlers for the remaining vectors

undef:
softint:
movs pc,r14

pref_abort:
irq:
rsrvd:
subs pc,r14,#4

data_abort:
subs pc,r14,#8


# Reset entry point

reset:
# Disable IRQ and enable FIQ
mrs r0,CPSR
orr r0,r0,#0x80
bic r0,r0,#0x40
msr CPSR,r0
# Set stack
mov sp,#0xf000

# Call main
bl main

# Done. Stay put.
done: b done


.end

4 changes: 4 additions & 0 deletions AICA/SRCS/sound/bintohex.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/local/bin/perl
undef $/;$z=<>;print "static unsigned char the_code[] = {";
for($i=0;$i<length($z);$i++){if(!(7&$i)){print "\n";}
printf " 0x%02x,",ord(substr($z,$i,1));}print "\n};\n";
Loading

0 comments on commit fd52e73

Please sign in to comment.