Permalink
Browse files

Merged alt_libn64 with libdragon, updated some comments.

  • Loading branch information...
1 parent 3da7cd9 commit 16e07f42f684152d0895afe2878ec2d5ebbf426e Shaun Taylor committed Feb 11, 2010
Showing with 1,218 additions and 34 deletions.
  1. +6 −0 Makefile
  2. +18 −1 files.in
  3. BIN header
  4. +1 −1 include/audio.h
  5. +48 −2 include/controller.h
  6. +13 −0 include/dma.h
  7. +14 −0 include/interrupt.h
  8. +16 −0 include/libdragon.h
  9. +27 −0 include/n64sys.h
  10. +58 −0 include/regsinternal.h
  11. +99 −0 n64ld.x
  12. +39 −14 src/audio.c
  13. +1 −4 src/console.c
  14. +56 −2 src/controller.c
  15. +2 −3 src/display.c
  16. +30 −0 src/dma.c
  17. +2 −3 src/dragonfs.c
  18. +79 −0 src/entrypoint.S
  19. 0 src/font.c
  20. +0 −1 src/graphics.c
  21. +215 −0 src/interrupt.c
  22. +296 −0 src/inthandler.S
  23. +41 −0 src/n64sys.c
  24. +2 −3 src/rdp.c
  25. +155 −0 src/regs.S
View
@@ -30,14 +30,20 @@ libdragonsys.a: $(OFILES_LDS)
install: libdragon.a libdragonsys.a
install -D --mode=644 libdragon.a $(INSTALLDIR)/lib/libdragon.a
+ install -D --mode=644 n64ld.x $(INSTALLDIR)/lib/n64ld.x
+ install -D --mode=644 header $(INSTALLDIR)/lib/header
install -D --mode=644 libdragonsys.a $(INSTALLDIR)/lib/libdragonsys.a
+ install -D --mode=644 include/n64sys.h $(INSTALLDIR)/include/n64sys.h
+ install -D --mode=644 include/interrupt.h $(INSTALLDIR)/include/interrupt.h
+ install -D --mode=644 include/dma.h $(INSTALLDIR)/include/dma.h
install -D --mode=644 include/dragonfs.h $(INSTALLDIR)/include/dragonfs.h
install -D --mode=644 include/audio.h $(INSTALLDIR)/include/audio.h
install -D --mode=644 include/display.h $(INSTALLDIR)/include/display.h
install -D --mode=644 include/console.h $(INSTALLDIR)/include/console.h
install -D --mode=644 include/controller.h $(INSTALLDIR)/include/controller.h
install -D --mode=644 include/graphics.h $(INSTALLDIR)/include/graphics.h
install -D --mode=644 include/rdp.h $(INSTALLDIR)/include/rdp.h
+ install -D --mode=644 include/libdragon.h $(INSTALLDIR)/include/libdragon.h
install-tools: tools
install -D --mode=755 tools/dumpdfs/dumpdfs $(INSTALLDIR)/bin/dumpdfs
View
@@ -1,13 +1,30 @@
-OFILES_LD = $(CURDIR)/build/dragonfs.o
+OFILES_LD = $(CURDIR)/build/n64sys.o
+OFILES_LD += $(CURDIR)/build/interrupt.o
+OFILES_LD += $(CURDIR)/build/inthandler.o
+OFILES_LD += $(CURDIR)/build/entrypoint.o
+OFILES_LD += $(CURDIR)/build/dragonfs.o
OFILES_LD += $(CURDIR)/build/audio.o
OFILES_LD += $(CURDIR)/build/display.o
OFILES_LD += $(CURDIR)/build/console.o
OFILES_LD += $(CURDIR)/build/controller.o
OFILES_LD += $(CURDIR)/build/graphics.o
OFILES_LD += $(CURDIR)/build/rdp.o
+OFILES_LD += $(CURDIR)/build/dma.o
OFILES_LDS = $(CURDIR)/build/system.o
+# Rules for compiling system stuff
+$(CURDIR)/build/n64sys.o: $(CURDIR)/src/n64sys.c
+ $(CC) $(CFLAGS) -c -o $(CURDIR)/build/n64sys.o $(CURDIR)/src/n64sys.c
+$(CURDIR)/build/interrupt.o: $(CURDIR)/src/interrupt.c
+ $(CC) $(CFLAGS) -c -o $(CURDIR)/build/interrupt.o $(CURDIR)/src/interrupt.c
+$(CURDIR)/build/dma.o: $(CURDIR)/src/dma.c
+ $(CC) $(CFLAGS) -c -o $(CURDIR)/build/dma.o $(CURDIR)/src/dma.c
+$(CURDIR)/build/inthandler.o: $(CURDIR)/src/inthandler.S
+ $(CC) -c -o $(CURDIR)/build/inthandler.o $(CURDIR)/src/inthandler.S
+$(CURDIR)/build/entrypoint.o: $(CURDIR)/src/entrypoint.S
+ $(CC) -c -o $(CURDIR)/build/entrypoint.o $(CURDIR)/src/entrypoint.S
+
# Rules for compiling filesystem
$(CURDIR)/build/dragonfs.o: $(CURDIR)/src/dragonfs.c
$(CC) $(CFLAGS) -c -o $(CURDIR)/build/dragonfs.o $(CURDIR)/src/dragonfs.c
View
BIN header
Binary file not shown.
View
@@ -12,7 +12,7 @@ void audio_init(const int frequency);
void audio_write(const short * const buffer);
/* Return whether or not there is room to write another sample */
-int audio_can_write();
+volatile int audio_can_write();
/* Write silence to the audio system. This is provided as a convenience so the
programmer does not have to allocate a buffer, zero it and then pass it in. */
View
@@ -1,12 +1,58 @@
#ifndef __LIBDRAGON_CONTROLLER_H
#define __LIBDRAGON_CONTROLLER_H
-/* Bridge from libnds to libdragon calling standard */
-#define controller_read controller_Read
+typedef struct SI_condat
+{
+ unsigned : 16;
+ unsigned err : 2; // error status
+ unsigned : 14;
+
+ union
+ {
+ struct
+ {
+ unsigned buttons : 16;
+ unsigned : 16;
+ };
+ struct
+ {
+ unsigned A : 1;
+ unsigned B : 1;
+ unsigned Z : 1;
+ unsigned start : 1;
+ unsigned up : 1;
+ unsigned down : 1;
+ unsigned left : 1;
+ unsigned right : 1;
+ unsigned : 2;
+ unsigned L : 1;
+ unsigned R : 1;
+ unsigned C_up : 1;
+ unsigned C_down : 1;
+ unsigned C_left : 1;
+ unsigned C_right : 1;
+ signed x : 8;
+ signed y : 8;
+ };
+ };
+} _SI_condat;
+
+typedef struct controller_data
+{
+ struct
+ {
+ struct SI_condat c[4];
+ unsigned long unused[4*8]; // to map directly to PIF block
+ };
+} _controller_data;
/* Initialize the controller system. */
void controller_init();
+/* Read the controller status immediately and return results to data. If
+ calling this function, one should not also call controller_scan */
+void controller_read( struct controller_data * data);
+
/* Scan the four controller ports and calculate the buttons state. This
must be called before calling any of the below functions. */
void controller_scan();
View
@@ -0,0 +1,13 @@
+#ifndef __LIBDRAGON_DMA_H
+#define __LIBDRAGON_DMA_H
+
+/* Write to peripheral */
+void dma_write(void * ram_address, unsigned long pi_address, unsigned long len);
+
+/* Read from peripheral */
+void dma_read(void * ram_address, unsigned long pi_address, unsigned long len);
+
+/* Return whether peripheral interface is busy */
+volatile int dma_busy();
+
+#endif
View
@@ -0,0 +1,14 @@
+#ifndef __LIBDRAGON_INTERRUPT_H
+#define __LIBDRAGON_INTERRUPT_H
+
+void register_AI_handler( void (*callback)() );
+void register_VI_handler( void (*callback)() );
+void register_PI_handler( void (*callback)() );
+void register_DP_handler( void (*callback)() );
+void set_AI_interrupt( int active);
+void set_VI_interrupt( int active, unsigned long line );
+void set_PI_interrupt( int active );
+void set_DP_interrupt( int active );
+void set_MI_interrupt( int active, int clear );
+
+#endif
View
@@ -0,0 +1,16 @@
+#ifndef __LIBDRAGON_LIBDRAGON_H
+#define __LIBDRAGON_LIBDRAGON_H
+
+/* Easy include wrapper */
+#include "audio.h"
+#include "console.h"
+#include "controller.h"
+#include "display.h"
+#include "dma.h"
+#include "dragonfs.h"
+#include "graphics.h"
+#include "interrupt.h"
+#include "n64sys.h"
+#include "rdp.h"
+
+#endif
View
@@ -0,0 +1,27 @@
+#ifndef __LIBDRAGON_N64SYS_H
+#define __LIBDRAGON_N64SYS_H
+
+#define UncachedAddr(_addr) ((void *)(((unsigned long)(_addr))|0x20000000))
+#define UncachedShortAddr(_addr) ((short *)(((unsigned long)(_addr))|0x20000000))
+#define UncachedUShortAddr(_addr) ((unsigned short *)(((unsigned long)(_addr))|0x20000000))
+#define UncachedLongAddr(_addr) ((long *)(((unsigned long)(_addr))|0x20000000))
+#define UncachedULongAddr(_addr) ((unsigned long *)(((unsigned long)(_addr))|0x20000000))
+
+#define CachedAddr(_addr) (((void *)(((unsigned long)(_addr))&~0x20000000))
+
+volatile unsigned long read_count(void);
+void data_cache_invalidate(volatile void *, unsigned long);
+void data_cache_writeback(volatile void *, unsigned long);
+void data_cache_writeback_invalidate(volatile void *, unsigned long);
+void inst_cache_invalidate(volatile void *, unsigned long);
+void inst_cache_writeback(volatile void *, unsigned long);
+void inst_cache_writeback_invalidate(volatile void *, unsigned long);
+void enable_interrupts();
+void disable_interrupts();
+
+/* Count register updates at "half maximum instruction issue rate".
+ * This appears to be half the CPU clock.
+ */
+#define COUNTS_PER_SECOND (93750000/2)
+
+#endif
View
@@ -0,0 +1,58 @@
+#ifndef __LIBDRAGON_REGSINTERNAL_H
+#define __LIBDRAGON_REGSINTERNAL_H
+
+typedef struct AI_regs_s {
+ short * address;
+ unsigned long length;
+ unsigned long control;
+ unsigned long status;
+ unsigned long dacrate;
+ unsigned long samplesize;
+} _AI_regs_s;
+
+typedef struct MI_regs_s {
+ unsigned long mode;
+ unsigned long version;
+ unsigned long intr;
+ unsigned long mask;
+} _MI_regs_s;
+
+typedef struct VI_regs_s {
+ unsigned long control;
+ unsigned short int * framebuffer;
+ unsigned long width;
+ unsigned long v_int;
+ unsigned long cur_line;
+ unsigned long timing;
+ unsigned long v_sync;
+ unsigned long h_sync;
+ unsigned long h_sync2;
+ unsigned long h_limits;
+ unsigned long v_limits;
+ unsigned long color_burst;
+ unsigned long h_scale;
+ unsigned long v_scale;
+} _VI_regs_s;
+
+typedef struct PI_regs_s {
+ void * ram_address;
+ unsigned long pi_address;
+ /* the length registers are named from the PI's
+ perspective, thus read_length is the length
+ to read from RAM, write_length is the length
+ to write to RAM */
+ unsigned long read_length;
+ unsigned long write_length;
+ unsigned long status;
+} _PI_regs_s;
+
+typedef struct SI_regs_s {
+ volatile void * DRAM_addr;
+ volatile void * PIF_addr_read; // for a read from PIF RAM
+ unsigned long reserved1,reserved2;
+ volatile void * PIF_addr_write; // for a write to PIF RAM
+ unsigned long reserved3;
+ unsigned long status;
+} _SI_regs_s;
+
+#endif
View
99 n64ld.x
@@ -0,0 +1,99 @@
+/* ========================================================================
+ *
+ * n64ld.x
+ *
+ * GNU Linker script for building an image that is set up for the N64
+ * but still has the data factored into sections. It is not directly
+ * runnable, and it contains the debug info if available. It will need
+ * a 'loader' to perform the final stage of transformation to produce
+ * a raw image.
+ *
+ * Copyright (c) 1999 Ground Zero Development, All rights reserved.
+ * Developed by Frank Somers <frank@g0dev.com>
+ * Modifications by hcs (halleyscometsoftware@hotmail.com)
+ *
+ * $Header: /cvsroot/n64dev/n64dev/lib/alt-libn64/n64ld.x,v 1.2 2006/08/11 15:54:11 halleyscometsw Exp $
+ *
+ * ========================================================================
+ */
+
+OUTPUT_FORMAT ("elf32-bigmips", "elf32-bigmips", "elf32-littlemips")
+OUTPUT_ARCH (mips)
+EXTERN (_start)
+ENTRY (_start)
+
+SECTIONS {
+ /* Start address of code is 1K up in uncached, unmapped RAM. We have
+ * to be at least this far up in order to not interfere with the cart
+ * boot code which is copying it down from the cart
+ */
+
+ . = 0x80000400 ;
+
+ /* The text section carries the app code and its relocation addr is
+ * the first byte of the cart domain in cached, unmapped memory
+ */
+
+ .text : {
+ FILL (0)
+
+ __text_start = . ;
+ *(.init)
+ *(.text)
+ *(.ctors)
+ *(.dtors)
+ *(.rodata)
+ *(.fini)
+ __text_end = . ;
+ }
+
+
+ /* Data section has relocation address at start of RAM in cached,
+ * unmapped memory, but is loaded just at the end of the text segment,
+ * and must be copied to the correct location at startup
+ */
+
+ .data : {
+ /* Gather all initialised data together. The memory layout
+ * will place the global initialised data at the lowest addrs.
+ * The lit8, lit4, sdata and sbss sections have to be placed
+ * together in that order from low to high addrs with the _gp symbol
+ * positioned (aligned) at the start of the sdata section.
+ * We then finish off with the standard bss section
+ */
+
+ FILL (0xaa)
+
+ __data_start = . ;
+ *(.data)
+ *(.lit8)
+ *(.lit4) ;
+ /* _gp = ALIGN(16) + 0x7ff0 ;*/
+/* _gp = . + 0x7ff0; */
+ . = ALIGN(16);
+ _gp = . ;
+ *(.sdata)
+ __data_end = . ;
+/*
+ __bss_start = . ;
+ *(.scommon)
+ *(.sbss)
+ *(COMMON)
+ *(.bss)
+ /* XXX Force 8-byte end alignment and update startup code */
+
+ __bss_end = . ;
+*/
+ }
+
+ .bss (NOLOAD) : {
+ __bss_start = . ;
+ *(.scommon)
+ *(.sbss)
+ *(COMMON)
+ *(.bss)
+ __bss_end = . ;
+ end = . ;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 16e07f4

Please sign in to comment.