Skip to content

Commit e841e44

Browse files
author
TheLemonMan
committed
Imported ipc/dldi/input driver. Rewritten display driver to not use framebuffer mode. Imported a new font. The dldi stub cant be compiled into the bootloader still.
1 parent c4f719c commit e841e44

33 files changed

+1768
-133
lines changed

Makefile

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11

22
PATH := $(DEVKITARM)/bin:$(PATH)
33

4-
GAME_TITLE := Prex
5-
GAME_SUBTITLE1 := www.devkitpro.org
6-
GAME_SUBTITLE2 := cyril.lugan.info
4+
GAME_TITLE := PrexDS
5+
GAME_SUBTITLE1 := Realtime OS
6+
GAME_SUBTITLE2 := On the DS
77
GAME_ICON := ./icon.bmp
88

99
all : prex.nds
1010

11-
prex.nds : prex.arm9
12-
@ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)"
11+
prex.nds : prex.arm7 prex.arm9
12+
@ndstool -c $@ -7 prex.arm7 -9 prex.arm9 -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)"
13+
@dlditool r4tf.dldi prex.nds
1314

14-
.PHONY : prex.arm9 clean
15+
.PHONY : prex.arm7 prex.arm9 clean
16+
17+
prex.arm7 :
18+
@$(MAKE) -C prex_7
19+
mv prex_7/prex_7.arm7 prex.arm7
1520

1621
prex.arm9 :
1722
./configure --target=arm-nds_arm9 --cross-prefix=arm-eabi-
1823
@$(MAKE) --file=prex.mk
1924
mv prexos prex.arm9
2025

2126
clean :
22-
rm prex.nds
23-
@$(MAKE) --file=prex.mk clean
27+
rm prex.arm7 prex.arm9 prex.nds
28+
@$(MAKE) --file=prex.mk clean
29+
@$(MAKE) -C prex_7 clean
30+

bsp/boot/arm/arch/boot.ld

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SECTIONS {
2424
*(.bss)
2525
*(COMMON)
2626
}
27-
. = CONFIG_LOADER_TEXT + 0x1fff;
27+
. = CONFIG_LOADER_TEXT + 0x1FFF;
2828
.tail : {
2929
*(.tail)
3030
}

bsp/boot/arm/nds_arm9/dldi_stub.S

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@---------------------------------------------------------------------------------
2+
.align 4
3+
.arm
4+
.global _io_dldi_stub
5+
@---------------------------------------------------------------------------------
6+
.equ FEATURE_MEDIUM_CANREAD, 0x00000001
7+
.equ FEATURE_MEDIUM_CANWRITE, 0x00000002
8+
.equ FEATURE_SLOT_GBA, 0x00000010
9+
.equ FEATURE_SLOT_NDS, 0x00000020
10+
11+
.equ DLDI_ALLOCATED_SPACE, 32768
12+
13+
_io_dldi_stub:
14+
15+
dldi_start:
16+
17+
@---------------------------------------------------------------------------------
18+
@ Driver patch file standard header -- 16 bytes
19+
.word 0xBF8DA5ED @ Magic number to identify this region
20+
.asciz " Chishm" @ Identifying Magic string (8 bytes with null terminator)
21+
.byte 0x01 @ Version number
22+
.byte 0x0F @32KiB @ Log [base-2] of the size of this driver in bytes.
23+
.byte 0x00 @ Sections to fix
24+
.byte 0x0F @32KiB @ Log [base-2] of the allocated space in bytes.
25+
26+
@---------------------------------------------------------------------------------
27+
@ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes
28+
.align 4
29+
.asciz "Default (No interface)"
30+
31+
@---------------------------------------------------------------------------------
32+
@ Offsets to important sections within the data -- 32 bytes
33+
.align 6
34+
.word dldi_start @ data start
35+
.word dldi_end @ data end
36+
.word 0x00000000 @ Interworking glue start -- Needs address fixing
37+
.word 0x00000000 @ Interworking glue end
38+
.word 0x00000000 @ GOT start -- Needs address fixing
39+
.word 0x00000000 @ GOT end
40+
.word 0x00000000 @ bss start -- Needs setting to zero
41+
.word 0x00000000 @ bss end
42+
43+
@---------------------------------------------------------------------------------
44+
@ DISC_INTERFACE data -- 32 bytes
45+
.ascii "DLDI" @ ioType
46+
.word 0x00000000 @ Features
47+
.word _DLDI_startup @
48+
.word _DLDI_isInserted @
49+
.word _DLDI_readSectors @ Function pointers to standard device driver functions
50+
.word _DLDI_writeSectors @
51+
.word _DLDI_clearStatus @
52+
.word _DLDI_shutdown @
53+
54+
@---------------------------------------------------------------------------------
55+
56+
_DLDI_startup:
57+
_DLDI_isInserted:
58+
_DLDI_readSectors:
59+
_DLDI_writeSectors:
60+
_DLDI_clearStatus:
61+
_DLDI_shutdown:
62+
mov r0, #0x00 @ Return false for every function
63+
bx lr
64+
65+
66+
67+
@---------------------------------------------------------------------------------
68+
.align
69+
.pool
70+
71+
dldi_data_end:
72+
73+
@ Pad to end of allocated space
74+
.space DLDI_ALLOCATED_SPACE - (dldi_data_end - dldi_start)
75+
76+
dldi_end:
77+
.end
78+
@---------------------------------------------------------------------------------

bsp/boot/arm/nds_arm9/head.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ boot_entry:
5555
/* to make the bootloader size 0x1FFF (see boot/arm/arch/boot.ld) */
5656
.section .tail,"ax"
5757
dummy:
58-
.byte 0xff
58+
.byte 0xff
5959

6060
.end

bsp/boot/arm/nds_arm9/startup.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include <sys/bootinfo.h>
3232
#include <boot.h>
3333

34+
#define EXMEMCNT (*(volatile uint16_t *)0x04000204)
35+
#define OPERA_IO_CR (*(volatile uint16_t *)0x08240000)
36+
3437
/*
3538
* Setup boot information.
3639
*/
@@ -44,14 +47,22 @@ bootinfo_init(void)
4447
*/
4548
bi->video.text_x = 42;
4649
bi->video.text_y = 16;
50+
51+
bi->nr_rams = 0;
52+
53+
/*
54+
* Card bus (GBA/NDS) set to ARM9
55+
*/
56+
57+
EXMEMCNT &= ~((1 << 7) | (1 << 11) | (1 << 15));
4758

4859
/*
49-
* Main ram - 4M
50-
*/
51-
bi->ram[0].base = 0x2000000;
52-
bi->ram[0].size = 0x0400000;
53-
bi->ram[0].type = MT_USABLE;
54-
bi->nr_rams = 1;
60+
* Main ram - 4M
61+
*/
62+
bi->ram[0].base = 0x2000000;
63+
bi->ram[0].size = 0x0400000;
64+
bi->ram[0].type = MT_USABLE;
65+
bi->nr_rams++;
5566
}
5667

5768
void

bsp/boot/common/main.c

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ main(void)
100100
void
101101
panic(const char *msg)
102102
{
103-
104103
DPRINTF(("Panic: %s\n", msg));
105104

106105
for (;;) ;

bsp/drv/arm/nds_arm9/Makefile.inc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2-
SRCS-$(CONFIG_LCD)+= arm/nds_arm9/lcd.c \
2+
SRCS-$(CONFIG_LCD)+= arm/nds_arm9/ipc.c \
3+
arm/nds_arm9/lcd.c \
34
arm/nds_arm9/font.c \
5+
arm/nds_arm9/dldi.c \
6+
arm/nds_arm9/input.c \
47
arm/nds_arm9/screen.c

bsp/drv/arm/nds_arm9/dldi.c

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* DS DLDI driver
3+
* 2010 (C) The Lemon Man
4+
*/
5+
6+
#include <driver.h>
7+
8+
#include "dldi.h"
9+
10+
static int dldi_init (struct driver *);
11+
static int dldi_read (device_t, char *, size_t *, int);
12+
13+
struct dldi_softc {
14+
device_t dev;
15+
irq_t irq;
16+
};
17+
18+
static struct devops dldi_devops = {
19+
/* open */ no_open,
20+
/* close */ no_close,
21+
/* read */ dldi_read,
22+
/* write */ no_write,
23+
/* ioctl */ no_ioctl,
24+
/* devctl */no_devctl,
25+
};
26+
27+
struct driver dldi_driver = {
28+
/* name */ "dldi",
29+
/* devops */&dldi_devops,
30+
/* devsz */ sizeof(struct dldi_softc),
31+
/* flags */ 0,
32+
/* probe */ NULL,
33+
/* init */ dldi_init,
34+
/* shutdown */ NULL,
35+
};
36+
37+
static DLDI_INTERFACE *dldi_if = (DLDI_INTERFACE *)0x02000100;
38+
static DISC_INTERFACE *disc_if = &((DLDI_INTERFACE *)0x02000100)->ioInterface;
39+
40+
int dldi_valid ()
41+
{
42+
return (dldi_if->magicNumber == DLDI_MAGIC);
43+
}
44+
45+
static int
46+
dldi_read (device_t dev, char *buf, size_t *nbyte, int blkno)
47+
{
48+
char *secbuf = kmem_map(buf, *nbyte);
49+
50+
if (!dldi_if->ioInterface.readSectors(blkno, (*nbyte) / 512, secbuf))
51+
{
52+
*nbyte = 0;
53+
printf("DLDI cant read\n");
54+
return 1;
55+
}
56+
57+
return 0;
58+
}
59+
60+
static int
61+
dldi_init (struct driver *self)
62+
{
63+
struct dldi_softc *sc;
64+
device_t dev;
65+
66+
if (!dldi_valid())
67+
{
68+
printf("DLDI driver not valid\n");
69+
return 1;
70+
}
71+
72+
dev = device_create(self, "dldi", D_REM);
73+
sc = device_private(dev);
74+
75+
printf("Driver : %s\n", dldi_if->friendlyName);
76+
printf("%x %x\n", disc_if->startup, dldi_if->ioInterface.startup);
77+
78+
if (!disc_if->startup())
79+
{
80+
printf("Cannot initialize the driver\n");
81+
return 1;
82+
}
83+
84+
printf("Startup sent\n");
85+
86+
return 0;
87+
}

bsp/drv/arm/nds_arm9/dldi.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef DLDI_H
2+
#define DLDI_H
3+
4+
#include <types.h>
5+
6+
#define DLDI_MAGIC_STRING_LEN 8
7+
#define DLDI_FRIENDLY_NAME_LEN 48
8+
9+
#define DLDI_MAGIC 0xBF8DA5ED
10+
11+
#define FEATURE_MEDIUM_CANREAD 0x00000001
12+
#define FEATURE_MEDIUM_CANWRITE 0x00000002
13+
#define FEATURE_SLOT_GBA 0x00000010
14+
#define FEATURE_SLOT_NDS 0x00000020
15+
16+
typedef uint32_t sec_t;
17+
18+
typedef int (* FN_MEDIUM_STARTUP)(void) ;
19+
typedef int (* FN_MEDIUM_ISINSERTED)(void) ;
20+
typedef int (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ;
21+
typedef int (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ;
22+
typedef int (* FN_MEDIUM_CLEARSTATUS)(void) ;
23+
typedef int (* FN_MEDIUM_SHUTDOWN)(void) ;
24+
25+
typedef struct DISC_INTERFACE {
26+
unsigned long ioType ;
27+
unsigned long features ;
28+
FN_MEDIUM_STARTUP startup ;
29+
FN_MEDIUM_ISINSERTED isInserted ;
30+
FN_MEDIUM_READSECTORS readSectors ;
31+
FN_MEDIUM_WRITESECTORS writeSectors ;
32+
FN_MEDIUM_CLEARSTATUS clearStatus ;
33+
FN_MEDIUM_SHUTDOWN shutdown ;
34+
} DISC_INTERFACE;
35+
36+
typedef struct DLDI_INTERFACE {
37+
uint32_t magicNumber;
38+
char magicString [DLDI_MAGIC_STRING_LEN];
39+
uint8_t versionNumber;
40+
uint8_t driverSize; /* log-2 of driver size in bytes */
41+
uint8_t fixSectionsFlags;
42+
uint8_t allocatedSize; /* log-2 of the allocated space in bytes */
43+
44+
char friendlyName [DLDI_FRIENDLY_NAME_LEN];
45+
46+
/* Pointers to sections that need address fixing */
47+
void* dldiStart;
48+
void* dldiEnd;
49+
void* interworkStart;
50+
void* interworkEnd;
51+
void* gotStart;
52+
void* gotEnd;
53+
void* bssStart;
54+
void* bssEnd;
55+
56+
/* Original I/O interface data */
57+
DISC_INTERFACE ioInterface;
58+
} DLDI_INTERFACE;
59+
60+
#endif

bsp/drv/arm/nds_arm9/font.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "font.h"
2-
#include "screen.h"
1+
/*#include "font.h"
2+
#include "screen.h"*/
33

44
static const char font[] = {
55
/* */ 0x00,
@@ -1238,9 +1238,9 @@ static const char font[] = {
12381238
/* */ 0x00
12391239
};
12401240

1241-
void font_print_char(char c, unsigned char x, unsigned char y)
1241+
void font_print_char(int screen, char c, unsigned char x, unsigned char y)
12421242
{
1243-
unsigned char dx, dy, id;
1243+
/*unsigned char dx, dy, id;
12441244
12451245
if (c >= 0x20 && c <= 0x7F) {
12461246
id = c - 0x20;
@@ -1249,12 +1249,12 @@ void font_print_char(char c, unsigned char x, unsigned char y)
12491249
id = 0;
12501250
}
12511251
1252-
for(dy = 0; dy < FONT_HEIGHT; dy++)
1253-
for(dx = 0; dx < FONT_WIDTH; dx++){
1254-
if((font[id*FONT_HEIGHT + dy] >> dx) & 1) {
1252+
for(dy = 0; dy < FONT_H; dy++)
1253+
for(dx = 0; dx < FONT_W; dx++){
1254+
if((font[id*FONT_H + dy] >> dx) & 1) {
12551255
screen_plot(x+dx, y+dy, 0xffffff);
12561256
} else{
12571257
screen_plot(x+dx, y+dy, 0x000000);
12581258
}
1259-
}
1259+
}*/
12601260
}

0 commit comments

Comments
 (0)