Copy pc86 platform to nes platform, and make change accordingly.
This commit is contained in:
committed by
Manoël Trapier
parent
dccecc5d45
commit
45121f6d87
19
plat/nes/libsys/_hol0.s
Normal file
19
plat/nes/libsys/_hol0.s
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
.sect .bss
|
||||
|
||||
! This data block is used to store information about the current line number
|
||||
! and file.
|
||||
|
||||
.define hol0
|
||||
.comm hol0, 8
|
||||
23
plat/nes/libsys/_sys_rawread.s
Normal file
23
plat/nes/libsys/_sys_rawread.s
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
.sect .text
|
||||
|
||||
! Reads a single byte.
|
||||
|
||||
.define __sys_rawread
|
||||
__sys_rawread:
|
||||
xorb ah, ah
|
||||
int 0x16
|
||||
xorb ah, ah
|
||||
ret
|
||||
|
||||
29
plat/nes/libsys/_sys_rawwrite.s
Normal file
29
plat/nes/libsys/_sys_rawwrite.s
Normal file
@@ -0,0 +1,29 @@
|
||||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
.sect .text
|
||||
|
||||
! Writes a single byte to the console.
|
||||
|
||||
.define __sys_rawwrite
|
||||
.extern __sys_rawwrite
|
||||
|
||||
__sys_rawwrite:
|
||||
push bp
|
||||
mov bp, sp
|
||||
|
||||
movb al, 4(bp)
|
||||
movb ah, 0x0E
|
||||
mov bx, 0x0007
|
||||
int 0x10
|
||||
jmp .cret
|
||||
|
||||
43
plat/nes/libsys/brk.c
Normal file
43
plat/nes/libsys/brk.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
|
||||
#define STACK_BUFFER 128 /* number of bytes to leave for stack */
|
||||
|
||||
extern char _end[1];
|
||||
static char* current = _end;
|
||||
|
||||
int brk(void* newend)
|
||||
{
|
||||
/* This variable is used to figure out the current stack pointer,
|
||||
* by taking its address. */
|
||||
char dummy;
|
||||
char* p = newend;
|
||||
|
||||
if ((p > (&dummy - STACK_BUFFER)) ||
|
||||
(p < _end))
|
||||
return -1;
|
||||
|
||||
current = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* sbrk(intptr_t increment)
|
||||
{
|
||||
char* old;
|
||||
|
||||
if (increment == 0)
|
||||
return current;
|
||||
|
||||
old = current;
|
||||
if (brk(old + increment) < 0)
|
||||
return OUT_OF_MEMORY;
|
||||
|
||||
return old;
|
||||
}
|
||||
14
plat/nes/libsys/close.c
Normal file
14
plat/nes/libsys/close.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
15
plat/nes/libsys/creat.c
Normal file
15
plat/nes/libsys/creat.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
int open(const char* path, int access, ...)
|
||||
{
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
28
plat/nes/libsys/errno.s
Normal file
28
plat/nes/libsys/errno.s
Normal file
@@ -0,0 +1,28 @@
|
||||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
#define D(e) .define e; e
|
||||
|
||||
.sect .data
|
||||
|
||||
! Define various ACK error numbers. Note that these are *not* ANSI C
|
||||
! errnos, and are used for different purposes.
|
||||
|
||||
D(ERANGE) = 1
|
||||
D(ESET) = 2
|
||||
D(EIDIVZ) = 6
|
||||
D(EHEAP) = 17
|
||||
D(EILLINS) = 18
|
||||
D(EODDZ) = 19
|
||||
D(ECASE) = 20
|
||||
D(EBADMON) = 25
|
||||
|
||||
13
plat/nes/libsys/getpid.c
Normal file
13
plat/nes/libsys/getpid.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pid_t getpid(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
4
plat/nes/libsys/hello.c
Normal file
4
plat/nes/libsys/hello.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int hello(void)
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
13
plat/nes/libsys/isatty.c
Normal file
13
plat/nes/libsys/isatty.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int isatty(int fd)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
14
plat/nes/libsys/kill.c
Normal file
14
plat/nes/libsys/kill.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int kill(pid_t pid, int sig)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
16
plat/nes/libsys/libsys.h
Normal file
16
plat/nes/libsys/libsys.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#ifndef LIBSYS_H
|
||||
#define LIBSYS_H
|
||||
|
||||
extern void _sys_rawwrite(unsigned char b);
|
||||
extern unsigned char _sys_rawread(void);
|
||||
|
||||
extern void _sys_write_tty(char c);
|
||||
|
||||
/* extern int _sys_ttyflags; */
|
||||
|
||||
#endif
|
||||
14
plat/nes/libsys/lseek.c
Normal file
14
plat/nes/libsys/lseek.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
14
plat/nes/libsys/open.c
Normal file
14
plat/nes/libsys/open.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
int creat(const char* path, int mode)
|
||||
{
|
||||
return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
|
||||
}
|
||||
31
plat/nes/libsys/pmfile
Normal file
31
plat/nes/libsys/pmfile
Normal file
@@ -0,0 +1,31 @@
|
||||
-- $Source$
|
||||
-- $State$
|
||||
-- $Revision$
|
||||
|
||||
local d = ROOTDIR.."plat/nes/libsys/"
|
||||
|
||||
libsys_nes = acklibrary {
|
||||
ACKBUILDFLAGS = {PARENT, "-ansi"},
|
||||
ACKINCLUDES = {"%BINDIR%include"},
|
||||
|
||||
-- ackfile (d.."errno.s"),
|
||||
-- ackfile (d.."_hol0.s"),
|
||||
-- ackfile (d.."_sys_rawread.s"),
|
||||
-- ackfile (d.."_sys_rawwrite.s"),
|
||||
-- ackfile (d.."open.c"),
|
||||
-- ackfile (d.."creat.c"),
|
||||
-- ackfile (d.."close.c"),
|
||||
-- ackfile (d.."read.c"),
|
||||
-- ackfile (d.."write.c"),
|
||||
-- ackfile (d.."brk.c"),
|
||||
-- ackfile (d.."getpid.c"),
|
||||
-- ackfile (d.."kill.c"),
|
||||
-- ackfile (d.."isatty.c"),
|
||||
-- ackfile (d.."lseek.c"),
|
||||
-- ackfile (d.."time.c"),
|
||||
-- ackfile (d.."signal.c"),
|
||||
|
||||
ackfile (d.."hello.c"),
|
||||
|
||||
install = pm.install("%BINDIR%lib/%PLATFORM%/libsys.a"),
|
||||
}
|
||||
43
plat/nes/libsys/read.c
Normal file
43
plat/nes/libsys/read.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
int read(int fd, void* buffer, size_t count)
|
||||
{
|
||||
char i;
|
||||
|
||||
/* We're only allowed to read from fd 0, 1 or 2. */
|
||||
|
||||
if ((fd < 0) || (fd > 2))
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Empty buffer? */
|
||||
|
||||
if (count == 0)
|
||||
return 0;
|
||||
|
||||
/* Read one byte. */
|
||||
|
||||
i = _sys_rawread();
|
||||
#if 0
|
||||
if ((i == '\r') && !(_sys_ttyflags & RAW))
|
||||
i = '\n';
|
||||
if (_sys_ttyflags & ECHO)
|
||||
_sys_write_tty(i);
|
||||
#endif
|
||||
if (i == '\r')
|
||||
i = '\n';
|
||||
_sys_write_tty(i);
|
||||
|
||||
*(char*)buffer = i;
|
||||
return 1;
|
||||
}
|
||||
15
plat/nes/libsys/signal.c
Normal file
15
plat/nes/libsys/signal.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "libsys.h"
|
||||
|
||||
sighandler_t signal(int signum, sighandler_t handler)
|
||||
{
|
||||
return SIG_DFL;
|
||||
}
|
||||
17
plat/nes/libsys/time.c
Normal file
17
plat/nes/libsys/time.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "libsys.h"
|
||||
|
||||
time_t time(time_t* t)
|
||||
{
|
||||
if (t)
|
||||
*t = 0;
|
||||
return 0;
|
||||
}
|
||||
48
plat/nes/libsys/write.c
Normal file
48
plat/nes/libsys/write.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
void _sys_write_tty(char c)
|
||||
{
|
||||
_sys_rawwrite(c);
|
||||
#if 0
|
||||
if ((c == '\n') && !(_sys_ttyflags & RAW))
|
||||
_sys_rawwrite('\r');
|
||||
#endif
|
||||
if (c == '\n')
|
||||
_sys_rawwrite('\r');
|
||||
}
|
||||
|
||||
int write(int fd, void* buffer, size_t count)
|
||||
{
|
||||
int i;
|
||||
char* p = buffer;
|
||||
|
||||
/* We're only allowed to write to fd 0, 1 or 2. */
|
||||
|
||||
if ((fd < 0) || (fd > 2))
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Write all data. */
|
||||
|
||||
i = 0;
|
||||
while (i < count)
|
||||
{
|
||||
_sys_write_tty(*p++);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
/* No failures. */
|
||||
|
||||
return count;
|
||||
}
|
||||
Reference in New Issue
Block a user