Search
lxdream.org :: lxdream/src/dcload.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dcload.c
changeset 102:844a3f2a76ff
next106:9048bac046c3
author nkeynes
date Mon Mar 13 12:38:39 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Refactor bios into more generic syscall structure. Add initial hooks for
dc-load functions
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/dcload.c Mon Mar 13 12:38:39 2006 +0000
1.3 @@ -0,0 +1,87 @@
1.4 +/**
1.5 + * $Id: dcload.c,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
1.6 + *
1.7 + * DC-load syscall implementation.
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include <stdio.h>
1.23 +#include "dream.h"
1.24 +#include "mem.h"
1.25 +#include "syscall.h"
1.26 +#include "sh4/sh4core.h"
1.27 +
1.28 +#define SYS_READ 0
1.29 +#define SYS_WRITE 1
1.30 +#define SYS_OPEN 2
1.31 +#define SYS_CLOSE 3
1.32 +#define SYS_CREAT 4
1.33 +#define SYS_LINK 5
1.34 +#define SYS_UNLINK 6
1.35 +#define SYS_CHDIR 7
1.36 +#define SYS_CHMOD 8
1.37 +#define SYS_LSEEK 9
1.38 +#define SYS_FSTAT 10
1.39 +#define SYS_TIME 11
1.40 +#define SYS_STAT 12
1.41 +#define SYS_UTIME 13
1.42 +#define SYS_ASSIGNWRKMEM 14
1.43 +#define SYS_EXIT 15
1.44 +#define SYS_OPENDIR 16
1.45 +#define SYS_CLOSEDIR 17
1.46 +#define SYS_READDIR 18
1.47 +#define SYS_GETHOSTINFO 19
1.48 +
1.49 +#define SYS_MAGIC 0xDEADBEEF
1.50 +#define SYS_MAGIC_ADDR 0x8c004004
1.51 +#define SYSCALL_ADDR 0x8c004008
1.52 +
1.53 +void dcload_syscall( uint32_t syscall_id )
1.54 +{
1.55 + uint32_t syscall = sh4r.r[4];
1.56 + switch( sh4r.r[4] ) {
1.57 + case SYS_READ:
1.58 + if( sh4r.r[5] == 0 ) {
1.59 + char *buf = mem_get_region( sh4r.r[6] );
1.60 + int length = sh4r.r[7];
1.61 + sh4r.r[0] = read( 0, buf, length );
1.62 + } else {
1.63 + sh4r.r[0] = -1;
1.64 + }
1.65 + break;
1.66 + case SYS_WRITE:
1.67 + if( sh4r.r[5] == 1 || sh4r.r[5] == 2 ) {
1.68 + char *buf = mem_get_region( sh4r.r[6] );
1.69 + int length = sh4r.r[7];
1.70 + sh4r.r[0] = write( sh4r.r[5], buf, length );
1.71 + } else {
1.72 + sh4r.r[0] = -1;
1.73 + }
1.74 + break;
1.75 + case SYS_EXIT:
1.76 + dreamcast_stop();
1.77 + sh4_stop();
1.78 + sh4r.r[0] = 0;
1.79 + break;
1.80 + default:
1.81 + sh4r.r[0] = -1;
1.82 + }
1.83 +
1.84 +}
1.85 +
1.86 +void dcload_install()
1.87 +{
1.88 + syscall_add_hook_vector( 0xF0, SYSCALL_ADDR, dcload_syscall );
1.89 + sh4_write_long( SYS_MAGIC_ADDR, SYS_MAGIC );
1.90 +}
.