Initial revision
diff --git a/contiki-cpc/loader/cfs-cpc.c b/contiki-cpc/loader/cfs-cpc.c
new file mode 100644
index 0000000..a3fa655
--- /dev/null
+++ b/contiki-cpc/loader/cfs-cpc.c
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: cfs-cpc.c,v 1.1 2006/04/17 15:02:35 kthacker Exp $
+ */
+#include "contiki.h"
+
+#include "log.h"
+#include "cfs.h"
+#include "cfs-service.h"
+
+extern void _readdir(void *);
+
+struct cpc_dir
+{
+ char *buffer;
+ char *ptr;
+};
+
+//#include <cbm.h>
+#include <string.h>
+
+static int s_open(const char *n, int f);
+static void s_close(int f);
+static int s_read(int f, char *b, unsigned int l);
+static int s_write(int f, char *b, unsigned int l);
+static int s_opendir(struct cfs_dir *p, const char *n);
+static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e);
+static int s_closedir(struct cfs_dir *p);
+
+static const struct cfs_service_interface interface =
+ {
+ CFS_SERVICE_VERSION,
+ s_open,
+ s_close,
+ s_read,
+ s_write,
+ s_opendir,
+ s_readdir,
+ s_closedir
+ };
+
+EK_EVENTHANDLER(cpc_cfs_eventhandler, ev, data);
+EK_PROCESS(proc, CFS_SERVICE_NAME ": KERNAL", EK_PRIO_NORMAL,
+ cpc_cfs_eventhandler, NULL, (void *)&interface);
+
+/*---------------------------------------------------------------------------*/
+EK_PROCESS_INIT(cfs_cpc_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(CFS_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(cpc_cfs_eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ log_message("Starting KERNAL CFS", "");
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, &interface);
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_open(const char *n, int f)
+{
+ // if(cbm_open(2, 8, f, n) == 0) {
+ // return 2;
+ // }
+ return -1;
+}
+/*---------------------------------------------------------------------------*/
+static void
+s_close(int f)
+{
+ // cbm_close(f);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_read(int f, char *b, unsigned int l)
+{
+ return 0; //return cbm_read(f, b, l);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_write(int f, char *b, unsigned int l)
+{
+ return 0; // return cbm_write(f, b, l);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_opendir(struct cfs_dir *p, const char *n)
+{
+ struct cpc_dir *cpcdir = (struct cpc_dir *)p;
+
+ char *buffer = malloc(2048);
+
+ if (buffer)
+ {
+ cpcdir->buffer = buffer;
+ cpcdir->ptr = buffer;
+ _readdir(buffer);
+ return 0;
+ }
+ return 1;
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_readdir(struct cfs_dir *p, struct cfs_dirent *e)
+{
+ int i;
+ int size;
+ int npos;
+ struct cpc_dir *cpcdir = (struct cpc_dir *)p;
+ char *ptr = cpcdir->ptr;
+
+ if (ptr[0]!=0xff)
+ return 1;
+
+ ptr++;
+
+ npos = 0;
+ for (i=0; i<8; i++)
+ {
+ char ch = ptr[0]&0x07f;
+ ptr++;
+ e->name[npos] = ch;
+ npos++;
+ }
+ e->name[npos] = '.';
+ npos++;
+ for (i=0; i<3; i++)
+ {
+ char ch = ptr[0]&0x07f;
+ ptr++;
+ e->name[npos] = ch;
+ npos++;
+ }
+ e->name[npos] = '\0';
+
+ size = (ptr[0]&0x0ff) + ((ptr[1]&0x0ff)<<8);
+ size = size*1024;
+ ptr+=2;
+ e->size = size;
+ cpcdir->ptr = ptr;
+
+ return 0;
+
+/* 1 = if no more dir entries
+ 0 = more dir entries */
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_closedir(struct cfs_dir *p)
+{
+ struct cpc_dir *cpcdir = (struct cpc_dir *)p;
+ free(cpcdir->buffer);
+ return 1;
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/loader/cfs-cpc.h b/contiki-cpc/loader/cfs-cpc.h
new file mode 100644
index 0000000..18f94e8
--- /dev/null
+++ b/contiki-cpc/loader/cfs-cpc.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: cfs-cpc.h,v 1.1 2006/04/17 15:02:35 kthacker Exp $
+ */
+#ifndef __CFS_CPC_H__
+#define __CFS_CPC_H__
+
+#include "ek.h"
+
+EK_PROCESS_INIT(cfs_cpc_init, arg);
+
+#endif /* __CFS_CBM_H__ */
diff --git a/contiki-cpc/loader/dir.s b/contiki-cpc/loader/dir.s
new file mode 100644
index 0000000..2de266a
--- /dev/null
+++ b/contiki-cpc/loader/dir.s
@@ -0,0 +1,99 @@
+;; This example shows how to perform a directory of a disc
+;; and extract the filenames.
+;;
+;; This code is public domain and can freely be used in your
+;; own programs.
+;;
+;; Written by Kevin Thacker. 2002
+
+
+
+;;------------------------------------------------------------------
+
+;; firmware function to catalog a disc or cassette
+cas_catalog == 0xbc9b
+;; firmware function to disable text output
+txt_vdu_enable == 0xbb54
+;; firmware function to enable text output
+txt_vdu_disable == 0xbb57
+;; firmware function to find a RSX
+kl_find_command == 0xbcd4
+
+ .globl __readdir
+ .area _CODE
+
+;;------------------------------------------------------------------
+;; find BIOS SET MESSAGE command
+;; this is used to disable disc messages.
+;; this is compatible with other DOSs that also provide this command
+__readdir::
+
+ld hl,#cmd_bios_set_message
+call kl_find_command
+ret nc
+
+;; command found
+
+;; store address of command
+ld (bios_set_message),hl
+ld a,c
+;; store "rom select" of command
+ld (bios_set_message+2),a
+
+;;------------------------------------------------------------------
+
+;; do CAT
+ld hl,#2
+add hl,sp
+ld e,(hl)
+inc hl
+ld d,(hl)
+call fetch_directory
+ret
+
+
+;;------------------------------------------------------------------
+;; display files from data generated by CAS CATALOG function
+
+;; perform a CAT command
+
+fetch_directory::
+push de
+;; disable disc messages. Error messages will not be displayed.
+ld a,#0xff
+rst 0x018 ;; KL FAR CALL
+.dw bios_set_message
+
+;; disable text output
+call txt_vdu_disable
+
+pop de
+
+;; initialise in case of an error
+xor a
+ld (de),a
+
+;; do catalog
+call cas_catalog
+
+;; enable text output
+call txt_vdu_enable
+
+;; enable disc messages. Error messages will be displayed
+ld a,#0x0
+rst 0x018 ;; KL FAR CALL
+.dw bios_set_message
+ret
+
+
+;;------------------------------------------------------------------
+
+;; this is initialised when the "BIOS SET MESSAGE" RSX has been found.
+bios_set_message:
+.dw 0 ;; address of function
+.db 0 ;; "rom select" for function
+
+
+cmd_bios_set_message:
+.db #0x01+#0x80 ;; this is the "BIOS SET MESSAGE" RSX
+
diff --git a/contiki-cpc/loader/loader-arch-cpc.c b/contiki-cpc/loader/loader-arch-cpc.c
new file mode 100644
index 0000000..84d12be
--- /dev/null
+++ b/contiki-cpc/loader/loader-arch-cpc.c
@@ -0,0 +1,93 @@
+#include "loader-arch.h"
+#include "rel.h"
+#include <stddef.h>
+#include <malloc.h>
+
+extern void *progend;
+
+struct prg_hdr {
+ char *relocatedata;
+ char arch[8];
+ char version[8];
+ char initfunc[1];
+};
+
+struct dsc_hdr {
+ char *relocatedata;
+ struct dsc dscdata;
+};
+
+unsigned char loader_arch_load(const char *name, char *arg)
+{
+ char *loadaddr;
+ struct prg_hdr *prghdr;
+ int length;
+
+ /* get length of file */
+ length = get_file_length(name);
+ if (length==0)
+ return LOADER_ERR_OPEN;
+
+ /* allocate memory */
+ loadaddr = malloc(length);
+ if (loadaddr==NULL)
+ return LOADER_ERR_MEM;
+
+ /* load the file */
+ load_file(name,loadaddr);
+
+ prghdr = (struct prg_hdr *)loadaddr;
+
+ /* relocate it */
+ relocate(prghdr->relocatedata,loadaddr);
+
+ ((void (*)(char *))prghdr->initfunc)(arg);
+
+ return LOADER_OK;
+}
+
+struct dsc *loader_arch_load_dsc(const char *name)
+{
+ char *loadaddr;
+ struct dsc_hdr *dschdr;
+ int length;
+
+ /* get length of file */
+ length = get_file_length(name);
+ if (length==0)
+ return NULL;
+
+ /* allocate memory */
+ loadaddr = malloc(length);
+ if (loadaddr==NULL)
+ return NULL;
+
+ /* load the file */
+ load_file(name, loadaddr);
+
+ dschdr = (struct dsc_hdr *)loadaddr;
+ /* relocate it */
+ relocate(dschdr->relocatedata, loadaddr);
+
+ return &dschdr->dscdata;
+}
+
+void loader_arch_free(void *loadaddr)
+{
+ /* free module */
+ /* we're given the start of 'arch' member of the prg_hdr,
+ calculate the real start address and then free the block */
+ void *header = (void *)((char *)loadaddr - offsetof(struct prg_hdr,arch));
+ free(header);
+}
+
+void loader_arch_free_dsc(struct dsc *dscdata)
+{
+ /* we're given the start of 'dsc' member of the dsc_hdr,
+ calculate the real start address and then free the block */
+ void *header = (void *)((char *)dscdata - 2);
+//offsetof(struct
+//dsc_hdr,dscdata));
+ free(header);
+}
+
diff --git a/contiki-cpc/loader/loader-arch-module.s b/contiki-cpc/loader/loader-arch-module.s
new file mode 100644
index 0000000..2539b86
--- /dev/null
+++ b/contiki-cpc/loader/loader-arch-module.s
@@ -0,0 +1,16 @@
+;; This is the header for Contiki program files
+;;
+;; This must always be at at the start of the file
+;; The order of the data must not change.
+;;
+.globl _loader_appinit
+ .area _CODE
+
+_loader_arch_loadaddr::
+arch: .byte 0,0,0,0,0,1,1,1
+version: .byte 0,0,0,0,0,1,1,1
+
+;; The position of the init function can be anywhere in the file.
+;; This jump is always in the same place, and points to the actual init function.
+ call gsinit
+ jp _loader_appinit
diff --git a/contiki-cpc/loader/loader-arch.h b/contiki-cpc/loader/loader-arch.h
new file mode 100644
index 0000000..ad970a0
--- /dev/null
+++ b/contiki-cpc/loader/loader-arch.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop OS
+ *
+ * $Id: loader-arch.h,v 1.1 2006/04/17 15:02:35 kthacker Exp $
+ *
+ */
+#ifndef __LOADER_ARCH_H__
+#define __LOADER_ARCH_H__
+
+#include "dsc.h"
+
+unsigned char loader_arch_load(const char *name, char *arg);
+struct dsc *loader_arch_load_dsc(const char *name);
+void loader_arch_free(void *addr);
+void loader_arch_free_dsc(struct dsc *);
+
+extern void *loader_arch_loadaddr;
+
+#define LOADER_LOAD_DSC(name) loader_arch_load_dsc(name)
+#define LOADER_LOAD(name, arg) loader_arch_load(name, arg)
+#define LOADER_UNLOAD() loader_arch_free(&loader_arch_loadaddr)
+#define LOADER_UNLOAD_DSC(dsc) loader_arch_free_dsc(dsc)
+
+#endif /* __LOADER_ARCH_H__ */
diff --git a/contiki-cpc/loader/rel.h b/contiki-cpc/loader/rel.h
new file mode 100644
index 0000000..fd3c264
--- /dev/null
+++ b/contiki-cpc/loader/rel.h
@@ -0,0 +1,3 @@
+int get_file_length(const char *);
+void load_file(const char *, void *);
+void relocate(void *relocate_data, void *base);
diff --git a/contiki-cpc/loader/rel.s b/contiki-cpc/loader/rel.s
new file mode 100644
index 0000000..be8f085
--- /dev/null
+++ b/contiki-cpc/loader/rel.s
@@ -0,0 +1,219 @@
+ .area _CODE
+ .globl _get_file_length
+ .globl _load_file
+;;----------------------------------------------------------------------------
+;; get length of file on disc. Assumption file has a AMSDOS header
+;;
+;; int get_file_length(const char *filename);
+
+_get_file_length::
+ ld hl,#2
+ add hl,sp
+ ld a,(hl)
+ inc hl
+ ld h,(hl)
+ ld l,a
+
+ ;; HL = address of null terminated string
+ call count_string_length
+ ld de,#0x0c000 ;; points to unused 2k buffer
+ call 0x0bc77 ;; cas in open
+ push bc ;; BC = length of file
+ call 0x0bc7d ;; cas in abandon
+ pop hl
+ ret
+
+;;---------------------------------------------------------------------
+
+count_string_length:
+ push hl
+ ld b,#0
+csl: ld a,(hl)
+ or a
+ jr z,csl2
+ inc hl
+ inc b
+ jr csl
+csl2:
+ pop hl
+ ret
+
+;;---------------------------------------------------------------------------
+;; void load_file(const char *filename, void *addr)
+
+_load_file::
+ ld hl,#5
+ add hl,sp
+ ld d,(hl)
+ dec hl
+ ld e,(hl)
+ dec hl
+
+ push de
+ ld a,(hl)
+ dec hl
+ ld l,(hl)
+ ld h,a
+
+ call count_string_length
+ ld de,#0x0c000
+ call 0x0bc77 ;; cas in open
+ pop hl ;; load address
+ call 0x0bc83 ;; cas in direct
+ call 0x0bc7a ;; cas in close
+ ret
+
+;; void relocate(void *addr,void *base)
+
+;; IX = address of relocate data
+_relocate::
+ ld hl,#5
+ add hl,sp
+ push ix
+ ld b,(hl) ;; base address
+ dec hl
+ ld c,(hl)
+ dec hl
+ ld a,(hl)
+ .db #0x0dd
+ ld h,a
+ dec hl
+ ld a,(hl)
+ .db #0x0dd
+ ld l,a ;; IX is offset of table from start of loaded file
+ add ix,bc ;; relocate IX to give absolute address of table.
+
+ push bc
+ pop hl
+ call relocate_16bit
+ push bc
+ pop hl
+ call relocate_8bitl ;; lower byte
+ push bc
+ pop hl
+ call relocate_8bith ;; upper byte
+ pop ix
+ ret
+
+;;--------------------------------------------------------------------------
+;; Relocate 8-bit values (e.g. where low and high parts of an address
+;; are loaded seperatly into registers)
+;;
+;; IX = list of 16-bit addresses. Each address identifies an 8-bit
+;; value
+;;
+relocate_8bith:
+ld a,0(ix)
+inc ix
+or a
+ret z
+cp #0x0ff
+jr nz,r8bh
+ld e,0(ix)
+inc ix
+ld d,0(ix)
+inc ix
+add hl,de
+jr relocate_8bith
+
+r8bh:
+;; add offset
+add a,l
+ld l,a
+ld a,h
+adc a,#0x0
+ld h,a
+
+;; get low byte of address
+ld e,0(ix)
+inc ix
+
+;; get high byte to relocate
+ld d,(hl)
+ex de,hl
+add hl,bc
+ex de,hl
+ld (hl),d
+jr relocate_8bith
+
+relocate_8bitl:
+ld a,0(ix)
+inc ix
+or a
+ret z
+cp #0x0ff
+jr nz,r8bl
+ld e,0(ix)
+inc ix
+ld d,0(ix)
+inc ix
+add hl,de
+jr relocate_8bitl
+
+r8bl:
+add a,l
+ld l,a
+ld a,h
+adc a,#0x0
+ld h,a
+
+ld e,(hl)
+ld d,#0x0
+ex de,hl
+add hl,bc
+ex de,hl
+ld (hl),e
+jr relocate_8bitl
+
+;;--------------------------------------------------------------------------
+;; Relocate 16-bit values
+;;
+;; Entry conditions:
+;;
+;; IX = list of 16-bit addresses. Each address identifies a 16-bit
+;; value to relocate.
+;;
+;; BC = base address
+;;
+;; NOTE:
+;; - Relocatable 16-bit values come from CALL and JP instructions and
+;; loading a 16-bit register.
+
+relocate_16bit:
+ld a,0(ix) ;; number of items to relocate
+inc ix
+or a
+ret z
+cp #0x0ff
+jr nz,r16
+ld e,0(ix)
+inc ix
+ld d,0(ix)
+inc ix
+add hl,de
+jr relocate_16bit
+
+r16:
+;; add offset
+add a,l
+ld l,a
+ld a,h
+adc a,#0x0
+ld h,a
+
+;; get the 16-bit value
+ld e,(hl)
+inc hl
+ld d,(hl)
+
+
+;; add base address; therefore relocating it.
+ex de,hl
+add hl,bc
+ex de,hl
+;; write relocated value
+ld (hl),d
+dec hl
+ld (hl),e
+jr relocate_16bit
+
diff --git a/contiki-cpc/loader/unused/c64-dio-asm.S b/contiki-cpc/loader/unused/c64-dio-asm.S
new file mode 100644
index 0000000..86b9639
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-dio-asm.S
@@ -0,0 +1,505 @@
+
+
+ .export _c64_dio_asm_init
+ .export _c64_dio_asm_read_block
+ .export _c64_dio_asm_write_block
+
+ .export _c64_dio_asm_track, _c64_dio_asm_sector
+
+ .export _c64_dio_asm_ptr
+
+ .importzp ptr1, ptr2
+
+ ;; job code $80 read, $90 write
+
+
+ciout = $ffa8
+listen = $ffb1
+second = $ff93
+unlsn = $ffae
+
+nbytes = 34
+esc = $42
+
+blockread = 1
+blockwrite = 2
+
+errok = 0
+errerr = 1
+
+.data
+_c64_dio_asm_track: .byte 0
+_c64_dio_asm_sector: .byte 0
+_c64_dio_asm_ptr: .byte 0,0
+
+.code
+;---------------------------------------
+_c64_dio_asm_read_block:
+
+ lda #blockread
+ jsr send
+
+ lda _c64_dio_asm_track
+ jsr send
+ lda _c64_dio_asm_sector
+ jsr send
+
+
+ jsr recv
+ cmp #errok
+ bne readerr
+
+ lda _c64_dio_asm_ptr
+ sta ptr1
+ lda _c64_dio_asm_ptr+1
+ sta ptr1+1
+ ldy #0
+readl:
+ jsr recv
+ sta (ptr1),y
+ iny
+ bne readl
+ clc
+ lda #0
+ tax
+ rts
+readerr:
+ ; sta $07c0
+ jsr recv
+ ; sta $07c1
+ ldx #0
+ rts
+;---------------------------------------
+_c64_dio_asm_write_block:
+
+ lda #blockwrite
+ jsr send
+
+ lda _c64_dio_asm_track
+ jsr send
+ lda _c64_dio_asm_sector
+ jsr send
+
+
+ lda _c64_dio_asm_ptr
+ sta ptr1
+ lda _c64_dio_asm_ptr+1
+ sta ptr1+1
+ ldy #0
+writel:
+ lda (ptr1),y
+ jsr send
+ iny
+ bne writel
+
+ jsr recv
+ cmp #errok
+ bne writeerr
+ lda #0
+ tax
+ rts
+
+writeerr:
+ ; sta $07c0
+ jsr recv
+ ; sta $07c1
+ ldx #0
+ rts
+;---------------------------------------
+_c64_dio_asm_init:
+ sta devnr
+ lda #$00
+ sta drvmem
+ lda #$05
+ sta drvmem+1
+
+ lda #<drive
+ sta ptr1
+ lda #>drive
+ sta ptr1+1
+
+ ; lda devnr
+ ; ldx #<icmd
+ ; ldy #>icmd
+ ; jsr drvcmd
+ ; jsr unlsn
+
+mwl:
+ lda devnr
+ ldx #<mwcmd
+ ldy #>mwcmd
+ jsr drvcmd
+
+ ldy #0
+ lda (ptr1),y
+ jsr ciout
+ iny
+ cpy #nbytes
+ bne *-8
+
+ jsr unlsn
+
+ lda drvmem
+ clc
+ adc #nbytes
+ sta drvmem
+ lda drvmem+1
+ adc #0
+ sta drvmem+1
+
+ lda ptr1
+ clc
+ adc #nbytes
+ sta ptr1
+ tax
+ lda ptr1+1
+ adc #0
+ sta ptr1+1
+ cpx #<driveend
+ sbc #>driveend
+ bcc mwl
+
+ lda devnr
+ ldx #<mecmd
+ ldy #>mecmd
+ jsr drvcmd
+ jsr unlsn
+
+ rts
+;---------------------------------------
+drvcmd:
+ stx ptr2
+ sty ptr2+1
+ jsr listen
+ lda #$6f
+ jsr second
+
+ ldy #0
+ lda (ptr2),y
+ sta drvcmdcmp+1
+ inc ptr2
+ bne *+4
+ inc ptr2+1
+
+ ldy #0
+ lda (ptr2),y
+ jsr ciout
+ iny
+drvcmdcmp: cpy #0
+ bne *-8
+ rts
+;---------------------------------------
+devnr: .byte 8
+mwcmd: .byte 6
+ .byte $4d, $2d, $57
+drvmem: .word $0500
+ .byte nbytes
+ .byte 0
+mecmd: .byte 2
+ .byte $55, $33
+ .byte 0
+;---------------------------------------
+send:
+
+ sta ptr2
+ ldx #7
+sendl:
+ lsr ptr2
+
+
+ lda $dd00
+ and #$df
+ ora #$10
+ bcc *+4
+ eor #$30
+ sta $dd00
+
+ lda #$c0
+ bit $dd00
+ bne *-3
+
+ lda $dd00
+ and #$cf
+ sta $dd00
+
+ lda $dd00
+ and #$c0
+ eor #$c0
+ bne *-7
+
+ dex
+ bpl sendl
+
+ ldx $d020
+ lda #1
+ sta $d020
+ stx $d020
+
+ rts
+;---------------------------------------
+recv:
+ ldx $d020
+ lda #0
+ sta $d020
+ stx $d020
+
+ ldx #7
+recvl:
+ lda $dd00
+ and #$c0
+ eor #$c0
+ beq *-7
+ asl a
+
+ lda $dd00
+ and #$df
+ ora #$10
+ bcs *+4
+ eor #$30
+ sta $dd00
+ ror ptr2
+
+ lda #$c0
+ bit $dd00
+ beq *-3
+
+ lda $dd00
+ and #$cf
+ sta $dd00
+
+ dex
+ bpl recvl
+ lda ptr2
+ rts
+;---------------------------------------
+
+;---------------------------------------
+;the code residing in the drive:
+;---------------------------------------
+dtmp = $46
+dtmp2 = $97
+dbuf = $0300
+dbufcmd = $00
+dbuftrack = $06
+dbufsect = $07
+
+retries = 10
+bretries = 2
+;---------------------------------------
+drive :
+ .org $0500
+
+
+
+ cld
+ tsx
+ stx dstack
+ sei
+ jsr ledoff
+
+drivel:
+ jsr dload
+ jsr ledoff
+ cli
+ jmp drivel
+;---------------------------------------
+ledon:
+ lda $1c00
+ ora #$08
+ sta $1c00
+ rts
+ledoff:
+ lda $1c00
+ and #$f7
+ sta $1c00
+ rts
+;---------------------------------------
+drecv:
+ ldx #7
+drecvl:
+ lda $1800
+ bmi atn
+ and #5
+ beq *-7
+ lsr a
+ lda #2
+ bcc *+4
+ lda #8
+ sta $1800
+ ror dtmp
+ lda $1800
+ bmi atn
+ and #5
+ eor #5
+ beq *-9
+ lda #0
+ sta $1800
+ dex
+ bpl drecvl
+ lda dtmp
+ rts
+;---------------------------------------
+atn:
+ ldx dstack
+ txs
+ cli
+ rts
+;---------------------------------------
+dsend:
+ sta dtmp
+ ldx #7
+dsendl:
+ lsr dtmp
+ lda #2
+ bcs *+4
+ lda #8
+ sta $1800
+
+ lda $1800
+ bmi atn
+ and #5
+ eor #5
+ bne *-9
+
+ sta $1800
+
+ lda #5
+ bit $1800
+ bne *-3
+ dex
+ bpl dsendl
+ rts
+;---------------------------------------
+dload:
+ ldy #0
+
+ jsr drecv
+ sta dcmd
+
+ jsr ledon
+
+ jsr drecv
+ sta dbuftrack
+
+ jsr drecv
+ sta dbufsect
+
+ lda dcmd
+ cmp #blockwrite
+ bne dblockread
+dblockwrite:
+ ldy #0
+drecvpl:
+ jsr drecv
+ sta dbuf,y
+ iny
+ bne drecvpl
+
+ jmp dputsect
+
+dblockread:
+ jsr dgetsect
+
+dsendpage:
+ ldy #0
+dsendpl:
+ lda dbuf,y
+ jsr dsend
+ iny
+ bne dsendpl
+ rts
+;---------------------------------------
+dgetsect:
+ ; stx dbuftrack
+ ; sty dbufsect
+ ldx #retries
+dgetsectl:
+ lda #$80
+ sta dbufcmd
+
+ cli
+:
+ lda dbufcmd
+ bmi :-
+ sei
+ cmp #1
+ beq dgsnoerr
+
+ cpx #0
+ beq dgsserr
+ dex
+ cpx #bretries
+ bcs dgetsectl
+ pha
+ lda #$c0
+ sta dbufcmd
+ cli
+:
+ lda dbufcmd
+ bmi :-
+ pla
+ cpx #0
+ bne dgetsectl
+
+dgsserr:
+ pha
+ lda #errerr
+ jsr dsend
+ pla
+ jsr dsend
+ rts
+dgsnoerr:
+ lda #errok
+ jsr dsend
+ rts
+;---------------------------------------
+dputsect:
+ ; stx dbuftrack
+ ; sty dbufsect
+ ldx #retries
+dputsectl:
+ lda #$90
+ sta dbufcmd
+
+ cli
+:
+ lda dbufcmd
+ bmi :-
+ sei
+ cmp #1
+ beq dpsnoerr
+
+ cpx #0
+ beq dpsserr
+ dex
+ cpx #bretries
+ bcs dputsectl
+ pha
+ lda #$c0
+ sta dbufcmd
+ cli
+:
+ lda dbufcmd
+ bmi :-
+ pla
+ cpx #0
+ bne dputsectl
+
+dpsserr:
+ pha
+ lda #errerr
+ jsr dsend
+ pla
+ jsr dsend
+ rts
+dpsnoerr:
+ lda #errok
+ jsr dsend
+ rts
+;---------------------------------------
+led: .byte 0,0
+dstack: .byte 0
+dcmd: .byte 0
+.RELOC
+driveend:
+
diff --git a/contiki-cpc/loader/unused/c64-dio-asm.h b/contiki-cpc/loader/unused/c64-dio-asm.h
new file mode 100644
index 0000000..5f4b076
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-dio-asm.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop OS
+ *
+ * $Id: c64-dio-asm.h,v 1.1 2006/04/17 15:02:36 kthacker Exp $
+ *
+ */
+#ifndef __C64_DIO_ASM_H__
+#define __C64_DIO_ASM_H__
+
+extern unsigned char c64_dio_asm_track,
+ c64_dio_asm_sector;
+
+extern unsigned char *c64_dio_asm_ptr;
+
+void __fastcall__ c64_dio_asm_init(unsigned char drive);
+unsigned char c64_dio_asm_read_block(void);
+unsigned char c64_dio_asm_write_block(void);
+
+#endif /* __C64_DIO_H__ */
diff --git a/contiki-cpc/loader/unused/c64-dio.c b/contiki-cpc/loader/unused/c64-dio.c
new file mode 100644
index 0000000..99161d9
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-dio.c
@@ -0,0 +1,119 @@
+/**
+ * \addtogroup c64fs
+ * @{
+ *
+ */
+
+/**
+ * \file
+ * C64 direct disk I/O.
+ * \author Adam Dunkels <adam@dunkels.com>
+ *
+ */
+
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop OS
+ *
+ * $Id: c64-dio.c,v 1.1 2006/04/17 15:02:36 kthacker Exp $
+ *
+ */
+
+#include "c64-dio.h"
+#include "c64-dio-asm.h"
+
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Read a block of data (256 bytes) from the disk.
+ *
+ * \param track The track of the disk block to be read.
+ *
+ * \param sector The sector of the disk block to be read.
+ *
+ * \param ptr A pointer to a buffer than must be able to accomodate
+ * 256 bytes of data.
+ *
+ * \return An error code or C64_DIO_OK if the data was successfully
+ * read.
+ */
+/*-----------------------------------------------------------------------------------*/
+unsigned char
+c64_dio_read_block(unsigned char track,
+ unsigned char sector,
+ unsigned char *ptr)
+{
+ c64_dio_asm_track = track;
+ c64_dio_asm_sector = sector;
+ c64_dio_asm_ptr = ptr;
+ return c64_dio_asm_read_block();
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Write a block of data (256 bytes) to the disk.
+ *
+ * \param track The track of the disk block to be written.
+ *
+ * \param sector The sector of the disk block to be written.
+ *
+ * \param ptr A pointer to a buffer containing the 256 bytes of data
+ * to be written.
+ *
+ * \return An error code or C64_DIO_OK if the data was successfully
+ * written.
+ */
+/*-----------------------------------------------------------------------------------*/
+unsigned char
+c64_dio_write_block(unsigned char track,
+ unsigned char sector,
+ unsigned char *ptr)
+{
+ c64_dio_asm_track = track;
+ c64_dio_asm_sector = sector;
+ c64_dio_asm_ptr = ptr;
+ return c64_dio_asm_write_block();
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Initialize the direct disk I/O routines for a particular disk drive.
+ *
+ * This function must be called before any of the other direct disk
+ * I/O functions can be used.
+ *
+ * \param drive The drive number of the disk drive for which the
+ * direct disk I/O should be enabled.
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+c64_dio_init(unsigned char drive)
+{
+ c64_dio_asm_init(drive);
+}
+/*-----------------------------------------------------------------------------------*/
+/** @} */
diff --git a/contiki-cpc/loader/unused/c64-dio.h b/contiki-cpc/loader/unused/c64-dio.h
new file mode 100644
index 0000000..328f092
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-dio.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop OS
+ *
+ * $Id: c64-dio.h,v 1.1 2006/04/17 15:02:36 kthacker Exp $
+ *
+ */
+#ifndef __C64_DIO_H__
+#define __C64_DIO_H__
+
+void c64_dio_init(unsigned char drive);
+
+unsigned char c64_dio_read_block(unsigned char track,
+ unsigned char sector,
+ unsigned char *buf);
+
+unsigned char c64_dio_write_block(unsigned char track,
+ unsigned char sector,
+ unsigned char *buf);
+
+#define C64_DIO_OK 0
+
+#endif /* __C64_DIO_H__ */
diff --git a/contiki-cpc/loader/unused/c64-fs-raw.c b/contiki-cpc/loader/unused/c64-fs-raw.c
new file mode 100644
index 0000000..939812c
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-fs-raw.c
@@ -0,0 +1,205 @@
+/**
+ * \addtogroup c64fs
+ * @{
+ */
+
+/**
+ * \file
+ * "Raw" C64 file system access.
+ * \author Adam Dunkels <adam@dunkels.com>
+ *
+ * This file provides functions that allow reading data from files
+ * without updating the file descriptor pointer. The functions are not
+ * automatically included in the core Contiki code and therefore
+ * application programs that use tham must manually link with this
+ * file.
+ *
+ */
+
+
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop environment
+ *
+ * $Id: c64-fs-raw.c,v 1.1 2006/04/17 15:02:37 kthacker Exp $
+ *
+ */
+
+#include "c64-fs-raw.h"
+
+#include <string.h>
+
+struct directory_entry {
+ unsigned char type;
+ unsigned char track, sect;
+ unsigned char name[16];
+ unsigned char reltrack, relsect, relreclen;
+ unsigned char unused1, unused2, unused3, unused4;
+ unsigned char tmptrack, tmpsect;
+ unsigned char blockslo, blockshi;
+};
+
+
+extern unsigned char _c64_fs_dirbuf[256];
+extern unsigned char _c64_fs_dirbuftrack, _c64_fs_dirbufsect;
+
+extern unsigned char _c64_fs_filebuf[256];
+extern unsigned char _c64_fs_filebuftrack, _c64_fs_filebufsect;
+
+void _c64_fs_readdirbuf(unsigned char track, unsigned char sect);
+
+
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Read data from a file without updating the file descriptor pointer.
+ *
+ * This function reads data from an open file into a buffer than must
+ * be allocated by the caller, but does not update the file
+ * description pointer like the c64_fs_read() function does.
+ *
+ * \param f A pointer to a file descriptor structure that must have
+ * been opened with c64_fs_open().
+ *
+ * \param buf A pointer to the buffer in which the data should be placed.
+ *
+ * \param len The maxiumum amount of bytes to read.
+ *
+ * \return The number of bytes that actually was read, or 0 if an end
+ * of file was encountered.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+int __fastcall__
+c64_fs_read_raw(register struct c64_fs_file *f, char *buf, int len)
+{
+ int i;
+ unsigned char fptr, ftrack, fsect;
+
+ /* Check if current block is already in buffer, and if not read it
+ from disk. */
+ if(_c64_fs_filebuftrack != f->track ||
+ _c64_fs_filebufsect != f->sect) {
+ _c64_fs_filebuftrack = f->track;
+ _c64_fs_filebufsect = f->sect;
+ c64_dio_read_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect, _c64_fs_filebuf);
+ }
+
+ if(_c64_fs_filebuf[0] == 0 &&
+ f->ptr == _c64_fs_filebuf[1]) {
+ return 0; /* EOF */
+ }
+
+ fptr = f->ptr;
+ ftrack = f->track;
+ fsect = f->sect;
+
+ for(i = 0; i < len; ++i) {
+ *buf = _c64_fs_filebuf[fptr];
+
+ ++fptr;
+ if(_c64_fs_filebuf[0] == 0) {
+ if(fptr == _c64_fs_filebuf[1]) {
+ /* End of file reached, we return the amount of bytes read so
+ far. */
+ return i + 1;
+ }
+ } else if(fptr == 0) {
+
+ /* Read new block into buffer and set buffer state
+ accordingly. */
+ _c64_fs_filebuftrack = ftrack = _c64_fs_filebuf[0];
+ _c64_fs_filebufsect = fsect = _c64_fs_filebuf[1];
+ fptr = 2;
+ c64_dio_read_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect, _c64_fs_filebuf);
+ }
+
+ ++buf;
+ }
+ return i;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Move the file descriptior pointer forward in the file.
+ *
+ *
+ * \param f A pointer to a file descriptor structure that must have
+ * been opened with c64_fs_open().
+ *
+ * \param len The number of bytes the pointer should be moved forward.
+ *
+ * \return The number of bytes that the pointer actually was moved, or
+ * 0 if an end of file was encountered.
+ */
+/*-----------------------------------------------------------------------------------*/
+int
+c64_fs_read_next(register struct c64_fs_file *f, int len)
+{
+ int i;
+
+ /* Check if current block is already in buffer, and if not read it
+ from disk. */
+ if(_c64_fs_filebuftrack != f->track ||
+ _c64_fs_filebufsect != f->sect) {
+ _c64_fs_filebuftrack = f->track;
+ _c64_fs_filebufsect = f->sect;
+ c64_dio_read_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect, _c64_fs_filebuf);
+ }
+
+ if(_c64_fs_filebuf[0] == 0 &&
+ f->ptr == _c64_fs_filebuf[1]) {
+ return 0; /* EOF */
+ }
+
+ for(i = 0; i < len; ++i) {
+
+ ++f->ptr;
+ if(_c64_fs_filebuf[0] == 0) {
+ if(f->ptr == _c64_fs_filebuf[1]) {
+ /* End of file reached, we return the amount of bytes read so
+ far. */
+ return i + 1;
+ }
+ } else if(f->ptr == 0) {
+ /* Read new block into buffer and set buffer state
+ accordingly. */
+ _c64_fs_filebuftrack = f->track = _c64_fs_filebuf[0];
+ _c64_fs_filebufsect = f->sect = _c64_fs_filebuf[1];
+ f->ptr = 2;
+ c64_dio_read_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect, _c64_fs_filebuf);
+ }
+ }
+ return i;
+}
+/*-----------------------------------------------------------------------------------*/
+/** @} */
diff --git a/contiki-cpc/loader/unused/c64-fs-raw.h b/contiki-cpc/loader/unused/c64-fs-raw.h
new file mode 100644
index 0000000..7364452
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-fs-raw.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop environment
+ *
+ * $Id: c64-fs-raw.h,v 1.1 2006/04/17 15:02:37 kthacker Exp $
+ *
+ */
+#ifndef __C64_FS_RAW_H__
+#define __C64_FS_RAW_H__
+
+#include "c64-fs.h"
+
+int __fastcall__ c64_fs_read_raw(struct c64_fs_file *f,
+ char *buf, int len);
+
+int c64_fs_read_next(struct c64_fs_file *f, int len);
+
+
+#endif /* __C64_FS_H__ */
diff --git a/contiki-cpc/loader/unused/c64-fs-write.c b/contiki-cpc/loader/unused/c64-fs-write.c
new file mode 100644
index 0000000..ce67f51
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-fs-write.c
@@ -0,0 +1,121 @@
+/**
+ * \addtogroup c64fs
+ * @{
+ */
+
+/**
+ * \file
+ * Implementation of C64 file writes.
+ * \author Adam Dunkels <adam@dunkels.com>
+ *
+ * The functions in this file are not included in the core Contiki
+ * code, but must be explicitly linked by an application that that
+ * wishes to be able to write to files.
+ */
+
+
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop environment
+ *
+ * $Id: c64-fs-write.c,v 1.1 2006/04/17 15:02:37 kthacker Exp $
+ *
+ */
+
+#include "c64-dio.h"
+#include "c64-fs.h"
+#include <string.h>
+
+/* An *UGLY* implementation of c64_fs_write that only can be used to
+ overwrite a single block file. */
+
+extern unsigned char _c64_fs_filebuf[256];
+extern unsigned char _c64_fs_filebuftrack,
+ _c64_fs_filebufsect;
+
+
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Write data to an open file.
+ *
+ * \note This function currently does not support writing to other than a single block file (cannot be more than 254 bytes long).
+ *
+ * \param f A pointer to a file descriptor previously opened with c64_fs_open().
+ *
+ * \param buf A pointer to a buffer with data that should be written
+ * to the file.
+ *
+ * \param len The length of the data that should be written.
+ *
+ * \return The number of bytes actually written.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+int __fastcall__
+c64_fs_write(register struct c64_fs_file *f, char *buf, int len)
+{
+ int i;
+
+ if(len <= 0) {
+ return 0;
+ }
+
+ /* Check if current block is already in buffer, and if not read it
+ from disk. */
+ if(_c64_fs_filebuftrack != f->track ||
+ _c64_fs_filebufsect != f->sect) {
+ _c64_fs_filebuftrack = f->track;
+ _c64_fs_filebufsect = f->sect;
+ c64_dio_read_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect,
+ _c64_fs_filebuf);
+ }
+
+ i = 256 - f->ptr;
+ if(len < i) {
+ i = len;
+ }
+
+ memcpy(&_c64_fs_filebuf[f->ptr], buf, i);
+
+ f->ptr += i;
+ if(_c64_fs_filebuf[0] == 0 &&
+ f->ptr > _c64_fs_filebuf[1]) {
+ _c64_fs_filebuf[1] = f->ptr;
+ }
+
+ c64_dio_write_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect,
+ _c64_fs_filebuf);
+
+ return i;
+}
+/*-----------------------------------------------------------------------------------*/
+/** @} */
diff --git a/contiki-cpc/loader/unused/c64-fs.c b/contiki-cpc/loader/unused/c64-fs.c
new file mode 100644
index 0000000..139e6ef
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-fs.c
@@ -0,0 +1,411 @@
+/**
+ * \defgroup c64fs C64 file system and disk functions.
+ * @{
+ *
+ * The C64 file system functions are divided into two categories:
+ * those that deal with C64 files and the C64 disk directory, and
+ * those that allow direct block access to the disk. The former
+ * functions can be used for accessing regular files, whereas the
+ * latter functions are used e.g. to download D64 files onto 1541
+ * disks.
+ *
+ * \note The C64 filesystem functions currently only work with the
+ * 1541/1541-II/1571 and compatible drives, and not with the IDE64
+ * hard disks or the 1581/FD2000 3.5" drives.
+ *
+ *
+ */
+
+/**
+ * \file
+ * C64 file system operations interface for Contiki.
+ * \author Adam Dunkels <adam@dunkels.com>
+ *
+ */
+
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop environment
+ *
+ * $Id: c64-fs.c,v 1.1 2006/04/17 15:02:37 kthacker Exp $
+ *
+ */
+
+#include "c64-dio.h"
+#include "c64-dio-asm.h"
+#include "c64-fs.h"
+
+#include <string.h>
+#include <stdio.h>
+
+struct directory_entry {
+ unsigned char type;
+ unsigned char track, sect;
+ unsigned char name[16];
+ unsigned char reltrack, relsect, relreclen;
+ unsigned char unused1, unused2, unused3, unused4;
+ unsigned char tmptrack, tmpsect;
+ unsigned char blockslo, blockshi;
+};
+
+unsigned char _c64_fs_dirbuf[256];
+unsigned char _c64_fs_dirbuftrack = 0, _c64_fs_dirbufsect = 0;
+
+unsigned char _c64_fs_filebuf[256];
+unsigned char _c64_fs_filebuftrack = 0, _c64_fs_filebufsect = 0;
+
+static struct c64_fs_dirent lastdirent;
+
+static struct c64_fs_dir opendir;
+static struct c64_fs_dirent opendirent;
+
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Open a file.
+ *
+ * The file description must be allocated by the caller and a pointer
+ * to it is passed to this function.
+ *
+ * \param name A pointer to the name of the file to be opened.
+ * \param f A pointer to the file descriptor struct.
+ *
+ * \retval 0 If the file was successfully opened.
+ * \retval -1 If the file does not exist.
+ */
+/*-----------------------------------------------------------------------------------*/
+int
+c64_fs_open(const char *name, register struct c64_fs_file *f)
+{
+ /* First check if we already have the file cached. If so, we don't
+ need to do an expensive directory lookup. */
+ if(strncmp(lastdirent.name, name, 16) == 0) {
+ f->track = lastdirent.track;
+ f->sect = lastdirent.sect;
+ f->ptr = 2;
+ return 0;
+ }
+
+ /* Not in cache, so we walk through directory instead. */
+ c64_fs_opendir(&opendir);
+
+ do {
+ c64_fs_readdir_dirent(&opendir, &opendirent);
+ if(strncmp(opendirent.name, name, 16) == 0) {
+ f->track = opendirent.track;
+ f->sect = opendirent.sect;
+ f->ptr = 2;
+ return 0;
+ }
+ } while(c64_fs_readdir_next(&opendir) == 0);
+
+ /* The file was not found in the directory. We flush the directory
+ buffer cache now in order to prevent a nasty problem from
+ happening: If the first directory block of an empty disk was
+ cached, *all* subsequent file opens would return "file not
+ found". */
+ _c64_fs_dirbuftrack = 0; /* There are no disk blocks on track 0. */
+ return -1;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Read data from an open file.
+ *
+ * This function reads data from an open file into a buffer than must
+ * be allocated by the caller.
+ *
+ * \param f A pointer to a file descriptor structure that must have
+ * been opened with c64_fs_open().
+ *
+ * \param buf A pointer to the buffer in which the data should be placed.
+ *
+ * \param len The maxiumum amount of bytes to read.
+ *
+ * \return The number of bytes that actually was read, or 0 if an end
+ * of file was encountered.
+ */
+/*-----------------------------------------------------------------------------------*/
+#if !NOASM
+#pragma optimize(push, off)
+#endif /* !NOASM */
+int __fastcall__
+c64_fs_read(register struct c64_fs_file *f, char *buf, int len)
+{
+ static int i;
+
+ /* Check if current block is already in buffer, and if not read it
+ from disk. */
+
+#if NOASM
+ if(f->track != _c64_fs_filebuftrack ||
+ _c64_fs_filebufsect != f->sect) {
+ _c64_fs_filebuftrack = f->track;
+ _c64_fs_filebufsect = f->sect;
+ c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect,
+ _c64_fs_filebuf);
+ }
+#else /* NOASM */
+ asm("ldy #%b", offsetof(struct c64_fs_file, track));
+ asm("lda (regbank+%b),y", 4);
+ asm("cmp %v", _c64_fs_filebuftrack);
+ asm("bne doblock");
+
+ asm("ldy #%b", offsetof(struct c64_fs_file, sect));
+ asm("lda (regbank+%b),y", 4);
+ asm("cmp %v", _c64_fs_filebufsect);
+ asm("bne doblock");
+
+ asm("jmp noblock");
+
+ asm("doblock:");
+
+ asm("ldy #%b", offsetof(struct c64_fs_file, track));
+ asm("lda (regbank+%b),y", 4);
+ asm("sta %v", _c64_fs_filebuftrack);
+ asm("sta %v", c64_dio_asm_track);
+
+ asm("ldy #%b", offsetof(struct c64_fs_file, sect));
+ asm("lda (regbank+%b),y", 4);
+ asm("sta %v", _c64_fs_filebufsect);
+ asm("sta %v", c64_dio_asm_sector);
+
+ asm("lda #<(%v)", _c64_fs_filebuf);
+ asm("sta %v", c64_dio_asm_ptr);
+ asm("lda #>(%v)", _c64_fs_filebuf);
+ asm("sta %v+1", c64_dio_asm_ptr);
+
+ asm("jsr %v", c64_dio_asm_read_block);
+
+ asm("noblock:");
+
+#endif /* NOASM */
+
+ if(_c64_fs_filebuf[0] == 0 &&
+ f->ptr == _c64_fs_filebuf[1]) {
+ return 0; /* EOF */
+ }
+
+ for(i = 0; i < len; ++i) {
+#if NOASM
+ *buf = _c64_fs_filebuf[f->ptr];
+ ++f->ptr;
+#else /* NOASM */
+ asm("ldy #%o+1", buf);
+ asm("jsr ldaxysp");
+ asm("sta ptr2");
+ asm("stx ptr2+1");
+
+ asm("ldy #%b", offsetof(struct c64_fs_file, ptr));
+ asm("lda (regbank+%b),y", 4);
+ asm("tax");
+
+ asm("ldy #0");
+ asm("lda %v,x", _c64_fs_filebuf);
+ asm("sta (ptr2),y");
+
+ asm("inx");
+ asm("txa");
+ asm("ldy #%b", offsetof(struct c64_fs_file, ptr));
+ asm("sta (regbank+%b),y", 4);
+#endif /* NOASM */
+
+
+ if(_c64_fs_filebuf[0] == 0) {
+ if(f->ptr == _c64_fs_filebuf[1]) {
+ /* End of file reached, we return the amount of bytes read so
+ far. */
+ return i + 1;
+ }
+ } else if(f->ptr == 0) {
+
+ /* Read new block into buffer and set buffer state
+ accordingly. */
+ _c64_fs_filebuftrack = f->track = _c64_fs_filebuf[0];
+ _c64_fs_filebufsect = f->sect = _c64_fs_filebuf[1];
+ f->ptr = 2;
+ c64_dio_read_block(_c64_fs_filebuftrack,
+ _c64_fs_filebufsect, _c64_fs_filebuf);
+ }
+
+ ++buf;
+ }
+ return i;
+}
+#if !NOASM
+#pragma optimize(pop)
+#endif /* !NOASM */
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Close an open file.
+ *
+ * \param f A pointer to a file descriptor struct that previously has
+ * been opened with c64_fs_open().
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+c64_fs_close(struct c64_fs_file *f)
+{
+
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * \internal
+ * Read a directory buffer into the _c64_fs_dirbuf buffer.
+ *
+ * This function is shared between this and the c64-fs-raw module.
+ *
+ * \param track The track of the directory block.
+ * \param sect The sector of the directory block.
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+_c64_fs_readdirbuf(unsigned char track, unsigned char sect)
+{
+ if(_c64_fs_dirbuftrack == track &&
+ _c64_fs_dirbufsect == sect) {
+ /* Buffer already contains requested block, return. */
+ return;
+ }
+ c64_dio_read_block(track, sect, _c64_fs_dirbuf);
+ _c64_fs_dirbuftrack = track;
+ _c64_fs_dirbufsect = sect;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Open the disk directory for reading.
+ *
+ * The caller must supply a pointer to a directory descriptor.
+ *
+ * \param d A pointer to a directory description that must be
+ * allocated by the caller.
+ */
+/*-----------------------------------------------------------------------------------*/
+unsigned char
+c64_fs_opendir(register struct c64_fs_dir *d)
+{
+ d->track = 18;
+ d->sect = 1;
+ d->ptr = 2;
+
+ return 0;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Read the current directory entry.
+ *
+ * This function reads the directory entry to which the directory
+ * descriptor currently points into a struct c64_fs_dirent supplied by
+ * the caller.
+ *
+ * The function c64_fs_readdir_next() is used to move the directory
+ * entry pointer forward in the directory.
+ *
+ * \param d A pointer to a directory descriptor previously opened with c64_fs_opendir().
+ *
+ * \param f A pointer to a directory entry that must have been
+ * previously allocated by the caller.
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+c64_fs_readdir_dirent(register struct c64_fs_dir *d,
+ register struct c64_fs_dirent *f)
+{
+ struct directory_entry *de;
+ int i;
+ register char *nameptr;
+
+ _c64_fs_readdirbuf(d->track, d->sect);
+ de = (struct directory_entry *)&_c64_fs_dirbuf[d->ptr];
+ nameptr = de->name;
+ for(i = 0; i < 16; ++i) {
+ if(*nameptr == 0xa0) {
+ *nameptr = 0;
+ break;
+ }
+ ++nameptr;
+ }
+ strncpy(f->name, de->name, 16);
+ f->track = de->track;
+ f->sect = de->sect;
+ f->size = de->blockslo + (de->blockshi >> 8);
+ memcpy(&lastdirent, f, sizeof(struct c64_fs_dirent));
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Move the directory pointer forward.
+ *
+ * This function moves the directory entry pointer in the directory
+ * descriptor forward so that it points to the next file.
+ *
+ * \param d A pointer to a directory descriptor previously opened with
+ * c64_fs_opendir().
+ *
+ * \retval 1 If there are no more directory entried in the directory.
+ * \retval 0 There were more directory entries and the pointer has
+ * been moved to point to the next one.
+ */
+/*-----------------------------------------------------------------------------------*/
+unsigned char
+c64_fs_readdir_next(struct c64_fs_dir *d)
+{
+ struct directory_entry *de;
+ again:
+ _c64_fs_readdirbuf(d->track, d->sect);
+ if(d->ptr == 226) {
+ if(_c64_fs_dirbuf[0] == 0) {
+ return 1;
+ }
+ d->track = _c64_fs_dirbuf[0];
+ d->sect = _c64_fs_dirbuf[1];
+ d->ptr = 2;
+ } else {
+ d->ptr += 32;
+ }
+
+ de = (struct directory_entry *)&_c64_fs_dirbuf[d->ptr];
+ if(de->type == 0) {
+ goto again;
+ }
+ return 0;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Close a directory descriptor previously opened by c64_fs_opendir().
+ *
+ * \param d A poitner to a directory descriptor previously opened with
+ * c64_fs_opendir().
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+c64_fs_closedir(struct c64_fs_dir *d)
+{
+
+}
+/*-----------------------------------------------------------------------------------*/
+/** @} */
diff --git a/contiki-cpc/loader/unused/c64-fs.h b/contiki-cpc/loader/unused/c64-fs.h
new file mode 100644
index 0000000..b4346c1
--- /dev/null
+++ b/contiki-cpc/loader/unused/c64-fs.h
@@ -0,0 +1,97 @@
+/**
+ * \addtogroup c64fs
+ * @{
+ */
+
+/**
+ * \file
+ * Header file for the C64 filesystem functions.
+ * \author Adam Dunkels <adam@dunkels.com>
+ *
+ */
+
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop environment
+ *
+ * $Id: c64-fs.h,v 1.1 2006/04/17 15:02:37 kthacker Exp $
+ *
+ */
+#ifndef __C64_FS_H__
+#define __C64_FS_H__
+
+#include "c64-dio.h"
+
+/**
+ * An opaque structure with no user visible elements that represents
+ * an open file.
+ */
+struct c64_fs_file {
+ unsigned char track, sect, ptr;
+};
+
+int c64_fs_open(const char *name, struct c64_fs_file *f);
+void c64_fs_close(struct c64_fs_file *f);
+int __fastcall__ c64_fs_read(struct c64_fs_file *f,
+ char *buf, int len);
+
+int __fastcall__ c64_fs_write(struct c64_fs_file *f,
+ char *buf, int len);
+
+/**
+ * An opaque structure with no user visible elements that represents a
+ * directory descriptor.
+ */
+struct c64_fs_dir {
+ unsigned char track, sect, ptr;
+};
+
+/**
+ * A C64 directory entry.
+ */
+struct c64_fs_dirent {
+ char name[17]; /**< The name of the directory entry. */
+ unsigned short size; /**< The size of the directory entry in 256 byte blocks. */
+ unsigned char track,
+ sect;
+};
+
+
+unsigned char c64_fs_opendir(struct c64_fs_dir *d);
+
+void c64_fs_readdir_dirent(struct c64_fs_dir *d,
+ struct c64_fs_dirent *f);
+unsigned char c64_fs_readdir_next(struct c64_fs_dir *d);
+
+void c64_fs_closedir(struct c64_fs_dir *d);
+
+/** @} */
+
+#endif /* __C64_FS_H__ */
diff --git a/contiki-cpc/loader/unused/cfs-cbm.c b/contiki-cpc/loader/unused/cfs-cbm.c
new file mode 100644
index 0000000..5f3b45c
--- /dev/null
+++ b/contiki-cpc/loader/unused/cfs-cbm.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: cfs-cbm.c,v 1.1 2006/04/17 15:02:38 kthacker Exp $
+ */
+#include "contiki.h"
+
+#include "log.h"
+#include "cfs.h"
+#include "cfs-service.h"
+
+#include <cbm.h>
+#include <string.h>
+
+static int s_open(const char *n, int f);
+static void s_close(int f);
+static int s_read(int f, char *b, unsigned int l);
+static int s_write(int f, char *b, unsigned int l);
+static int s_opendir(struct cfs_dir *p, const char *n);
+static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e);
+static int s_closedir(struct cfs_dir *p);
+
+static const struct cfs_service_interface interface =
+ {
+ CFS_SERVICE_VERSION,
+ s_open,
+ s_close,
+ s_read,
+ s_write,
+ s_opendir,
+ s_readdir,
+ s_closedir
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_PROCESS(proc, CFS_SERVICE_NAME ": KERNAL", EK_PRIO_NORMAL,
+ eventhandler, NULL, (void *)&interface);
+
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(cfs_cbm_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(CFS_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ log_message("Starting KERNAL CFS", "");
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, &interface);
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_open(const char *n, int f)
+{
+ if(cbm_open(2, 8, f, n) == 0) {
+ return 2;
+ }
+ return -1;
+}
+/*---------------------------------------------------------------------------*/
+static void
+s_close(int f)
+{
+ cbm_close(f);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_read(int f, char *b, unsigned int l)
+{
+ return cbm_read(f, b, l);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_write(int f, char *b, unsigned int l)
+{
+ return cbm_write(f, b, l);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_opendir(struct cfs_dir *p, const char *n)
+{
+ return cbm_opendir(4, 8);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_readdir(struct cfs_dir *p, struct cfs_dirent *e)
+{
+ struct cbm_dirent ce;
+ int ret;
+ ret = cbm_readdir(4, &ce);
+ strncpy(e->name, ce.name, sizeof(ce.name));
+ e->size = ce.size;
+ return ret;
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_closedir(struct cfs_dir *p)
+{
+ cbm_closedir(4);
+ return 1;
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/loader/unused/cfs-cbm.h b/contiki-cpc/loader/unused/cfs-cbm.h
new file mode 100644
index 0000000..174137a
--- /dev/null
+++ b/contiki-cpc/loader/unused/cfs-cbm.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: cfs-cbm.h,v 1.1 2006/04/17 15:02:38 kthacker Exp $
+ */
+#ifndef __CFS_CBM_H__
+#define __CFS_CBM_H__
+
+#include "ek.h"
+
+EK_PROCESS_INIT(cfs_cbm_init, arg);
+
+#endif /* __CFS_CBM_H__ */
diff --git a/contiki-cpc/loader/unused/cfs-init.c b/contiki-cpc/loader/unused/cfs-init.c
new file mode 100644
index 0000000..450d22a
--- /dev/null
+++ b/contiki-cpc/loader/unused/cfs-init.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: cfs-init.c,v 1.1 2006/04/17 15:02:38 kthacker Exp $
+ */
+#include "contiki.h"
+
+#include "cfs.h"
+#include "cfs-service.h"
+
+#include <cbm.h>
+#include <string.h>
+
+static int s_open(const char *n, int f);
+static void s_close(int f);
+static int s_read(int f, char *b, unsigned int l);
+static int s_write(int f, char *b, unsigned int l) {return -1;}
+static int s_opendir(struct cfs_dir *p, const char *n) {return -1;}
+static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e) {return -1;}
+static int s_closedir(struct cfs_dir *p) {return -1;}
+
+static const struct cfs_service_interface interface =
+ {
+ CFS_SERVICE_VERSION,
+ s_open,
+ s_close,
+ s_read,
+ s_write,
+ s_opendir,
+ s_readdir,
+ s_closedir
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_PROCESS(proc, CFS_SERVICE_NAME ": init", EK_PRIO_NORMAL,
+ eventhandler, NULL, (void *)&interface);
+
+/*---------------------------------------------------------------------------*/
+EK_PROCESS_INIT(cfs_init_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(CFS_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, &interface);
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_open(const char *n, int f)
+{
+ if(cbm_open(2, 8, CBM_READ, n) == 0) {
+ return 2;
+ }
+ return -1;
+}
+/*---------------------------------------------------------------------------*/
+static void
+s_close(int f)
+{
+ cbm_close(f);
+}
+/*---------------------------------------------------------------------------*/
+static int
+s_read(int f, char *b, unsigned int l)
+{
+ return cbm_read(f, b, l);
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/loader/unused/cfs-init.h b/contiki-cpc/loader/unused/cfs-init.h
new file mode 100644
index 0000000..4d3326d
--- /dev/null
+++ b/contiki-cpc/loader/unused/cfs-init.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: cfs-init.h,v 1.1 2006/04/17 15:02:38 kthacker Exp $
+ */
+#ifndef __CFS_INIT_H__
+#define __CFS_INIT_H__
+
+#include "ek.h"
+
+EK_PROCESS_INIT(cfs_init_init, arg);
+
+#endif /* __CFS_INIT_H__ */
diff --git a/contiki-cpc/loader/unused/loader-arch-cpc.h b/contiki-cpc/loader/unused/loader-arch-cpc.h
new file mode 100644
index 0000000..9a2a22e
--- /dev/null
+++ b/contiki-cpc/loader/unused/loader-arch-cpc.h
@@ -0,0 +1,19 @@
+int cpc_load(char *name, char *arg);
+void cpc_unload();
+struct dsc *cpc_load_dsc(char *name);
+void cpc_unload_dsc(struct dsc *dsc);
+
+#define LOADER_LOAD(name,arg) \
+ cpc_load(name, arg)
+
+#define LOADER_UNLOAD() \
+ cpc_unload()
+
+#define LOADER_LOAD_DSC(name) \
+ cpc_load_dsc(name)
+
+#define LOADER_UNLOAD_DSC(dsc) \
+ cpc_unload_dsc(dsc)
+
+
+
diff --git a/contiki-cpc/loader/unused/loader-arch.c b/contiki-cpc/loader/unused/loader-arch.c
new file mode 100644
index 0000000..d1a7807
--- /dev/null
+++ b/contiki-cpc/loader/unused/loader-arch.c
@@ -0,0 +1,185 @@
+/**
+ * \file
+ * File loader implementation.
+ * \author Adam Dunkels <adam@dunkels.com>
+ *
+ * This file implements dynamically loadable files for Contiki using
+ * the cc65 module loading system. The actual file operations are
+ * implemented in other files.
+ */
+
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop OS
+ *
+ * $Id: loader-arch.c,v 1.1 2006/04/17 15:02:38 kthacker Exp $
+ *
+ */
+
+#include <stdlib.h>
+#include "modload.h"
+
+#ifndef NULL
+#define NULL (void *)0
+#endif /* NULL */
+
+#include "cfs.h"
+
+#include "loader.h"
+
+#include "loader-arch.h"
+
+static int __fastcall__
+do_read(int f, char *buf, unsigned int len)
+{
+ return cfs_read(f, buf, len);
+}
+
+static struct mod_ctrl ctrl = {
+ (void *)do_read /* Read from disk */
+};
+
+
+struct loader_arch_hdr {
+ char arch[8];
+ char version[8];
+
+ char initfunc[1];
+};
+
+/*-----------------------------------------------------------------------------------*/
+/**
+ * \internal
+ * Load a program from disk and execute it.
+ *
+ * Code originally written by Ullrich von Bassewitz.
+ */
+/*-----------------------------------------------------------------------------------*/
+static unsigned char
+load(const char *name)
+{
+ unsigned char res;
+
+ /* Now open the file */
+ ctrl.callerdata = cfs_open(name, 0);
+ if(ctrl.callerdata < 0) {
+ /* Could not open the file, display an error and return */
+ /* ### */
+ return LOADER_ERR_OPEN;
+ }
+
+ /* Load the module */
+ res = mod_load(&ctrl);
+
+ /* Close the input file */
+ cfs_close(ctrl.callerdata);
+
+ /* Check the return code */
+ if(res != MLOAD_OK) {
+ /* Wrong module, out of memory or whatever. Print an error
+ * message and return.
+ */
+ /* ### */
+ return res;
+ }
+
+ /* We've successfully loaded the module. */
+
+ return LOADER_OK;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Load and start a program.
+ *
+ * \param name The name of the program file.
+ * \param arg A pointer that will be passed to the new process.
+ */
+/*-----------------------------------------------------------------------------------*/
+unsigned char
+loader_arch_load(const char *name, char *arg)
+{
+ unsigned char r;
+ struct loader_arch_hdr *hdr;
+
+ r = load(name);
+ if(r != MLOAD_OK) {
+ return r;
+ }
+ hdr = (struct loader_arch_hdr *)ctrl.module;
+
+ /* Check the program header and see that version and architecture
+ matches. */
+
+ /* Call the init function. */
+ ((void (*)(char *))hdr->initfunc)(arg);
+
+ return LOADER_OK;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Load a DSC file into memory.
+ *
+ * The memory must be deallocated with the loader_arch_free() function
+ * after is has been used.
+ *
+ * \param name The name of the DSC file.
+ *
+ * \return A pointer to the struct dsc or NULL if the DSC file could
+ * not be loaded.
+ */
+/*-----------------------------------------------------------------------------------*/
+struct dsc *
+loader_arch_load_dsc(const char *name)
+{
+ unsigned char r;
+
+ r = load(name);
+ if(r == MLOAD_OK) {
+ return (struct dsc *)ctrl.module;
+ }
+ return NULL;
+}
+/*-----------------------------------------------------------------------------------*/
+/**
+ * Deallocate memory previously allocated by the loader.
+ *
+ * The loader allocates memory when it loads programs or DSC
+ * files. All such memory must be deallocated with this function. Memory for programs is automatically deallocated when calling the LOADER_UNLOAD() function, but memory for DSCs must be explicitly deallcated with this function.
+ *
+ * \param addr A pointer to memory allocated by the loader.
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+loader_arch_free(void *addr)
+{
+ mod_free(addr);
+}
+/*-----------------------------------------------------------------------------------*/
+
diff --git a/contiki-cpc/loader/unused/loader-arch.c.old b/contiki-cpc/loader/unused/loader-arch.c.old
new file mode 100644
index 0000000..c6fcbeb
--- /dev/null
+++ b/contiki-cpc/loader/unused/loader-arch.c.old
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgement:
+ * This product includes software developed by Adam Dunkels.
+ * 4. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the Contiki desktop OS
+ *
+ * $Id: loader-arch.c.old,v 1.1 2006/04/17 15:02:38 kthacker Exp $
+ *
+ */
+
+#include <stdlib.h>
+#include <modload.h>
+
+#ifndef NULL
+#define NULL (void *)0
+#endif /* NULL */
+
+#include "cpc-fs.h"
+
+#include "loader.h"
+
+#include "loader-arch.h"
+
+struct loader_arch_hdr {
+ char arch[8];
+ char version[8];
+
+ char initfunc[1];
+};
+
+/*-----------------------------------------------------------------------------------*/
+/* load(name)
+ *
+ * Loads a program from disk and executes it. Code originally written by
+ * Ullrich von Bassewitz.
+ */
+/*-----------------------------------------------------------------------------------*/
+static unsigned char
+load(const char *name)
+{
+ unsigned char res;
+ int ret;
+
+ /* Now open the file */
+ ret = cpc_fs_open(name);
+ if(ret < 0) {
+ /* Could not open the file, display an error and return */
+ /* ### */
+ return LOADER_ERR_OPEN;
+ }
+/* ctrl.callerdata = (int)&file; */
+
+ /* Load the module */
+ res = cpc_fs_read();
+
+ /* Close the input file */
+ cpc_fs_close();
+
+ /* Check the return code */
+ if(res != MLOAD_OK) {
+ /* Wrong module, out of memory or whatever. Print an error
+ * message and return.
+ */
+ /* ### */
+ return res;
+ }
+
+ /* We've successfully loaded the module. */
+
+ return LOADER_OK;
+}
+/*-----------------------------------------------------------------------------------*/
+unsigned char
+loader_arch_load(const char *name, char *arg)
+{
+ unsigned char r;
+ struct loader_arch_hdr *hdr;
+
+ r = load(name);
+ if(r != MLOAD_OK) {
+ return r;
+ }
+// hdr = (struct loader_arch_hdr *)ctrl.module;
+
+ /* Check the program header and see that version and architecture
+ matches. */
+
+ /* Call the init function. */
+
+ ((void (*)(char *))hdr->initfunc)(arg);
+
+ return LOADER_OK;
+}
+/*-----------------------------------------------------------------------------------*/
+struct dsc *
+loader_arch_load_dsc(const char *name)
+{
+ unsigned char r;
+
+ r = load(name);
+ if(r == MLOAD_OK) {
+ return (struct dsc *)ctrl.module;
+ }
+ return NULL;
+}
+/*-----------------------------------------------------------------------------------*/
+void
+loader_arch_free(void *addr)
+{
+ mod_free(addr);
+}
+/*-----------------------------------------------------------------------------------*/
+
diff --git a/contiki-cpc/loader/unused/modload.c b/contiki-cpc/loader/unused/modload.c
new file mode 100644
index 0000000..9c33b16
--- /dev/null
+++ b/contiki-cpc/loader/unused/modload.c
@@ -0,0 +1,12 @@
+#include "modload.h"
+
+void mod_free(struct dsc *d)
+{
+
+
+}
+
+int mod_load(struct mod_ctrl *ctrl)
+{
+ return MLOAD_OK;
+}
diff --git a/contiki-cpc/loader/unused/modload.h b/contiki-cpc/loader/unused/modload.h
new file mode 100644
index 0000000..ff0dc41
--- /dev/null
+++ b/contiki-cpc/loader/unused/modload.h
@@ -0,0 +1,13 @@
+void mod_free(struct dsc *);
+
+struct mod_ctrl
+{
+ void *read;
+ void *module;
+ int callerdata;
+};
+
+#define MLOAD_OK 0
+
+int mod_load(struct mod_ctrl *);
+
diff --git a/contiki-cpc/loader/unused/rel-old.s b/contiki-cpc/loader/unused/rel-old.s
new file mode 100644
index 0000000..8b03baa
--- /dev/null
+++ b/contiki-cpc/loader/unused/rel-old.s
@@ -0,0 +1,167 @@
+ .area _CODE
+ .globl _get_file_length
+ .globl _load_file
+;;----------------------------------------------------------------------------
+;; get length of file on disc. Assumption file has a AMSDOS header
+;;
+;; int get_file_length(const char *filename);
+
+_get_file_length::
+ ld hl,#2
+ add hl,sp
+ ld a,(hl)
+ inc hl
+ ld h,(hl)
+ ld l,a
+
+ ;; HL = address of null terminated string
+ call count_string_length
+ ld de,#0x0c000 ;; points to unused 2k buffer
+ call 0x0bc77 ;; cas in open
+ push bc ;; BC = length of file
+ call 0x0bc7d ;; cas in abandon
+ pop hl
+ ret
+
+;;---------------------------------------------------------------------
+
+count_string_length:
+ push hl
+ ld b,#0
+csl: ld a,(hl)
+ or a
+ jr z,csl2
+ inc hl
+ inc b
+ jr csl
+csl2:
+ pop hl
+ ret
+
+;;---------------------------------------------------------------------------
+;; void load_file(const char *filename, void *addr)
+
+_load_file::
+ ld hl,#5
+ add hl,sp
+ ld d,(hl)
+ dec hl
+ ld e,(hl)
+ dec hl
+
+ push de
+ ld a,(hl)
+ dec hl
+ ld l,(hl)
+ ld h,a
+
+ call count_string_length
+ ld de,#0x0c000
+ call 0x0bc77 ;; cas in open
+ pop hl ;; load address
+ call 0x0bc83 ;; cas in direct
+ call 0x0bc7a ;; cas in close
+ ret
+
+;; void relocate(void *addr,void *base)
+
+;; IX = address of relocate data
+_relocate::
+ ld hl,#5
+ add hl,sp
+ push ix
+ ld b,(hl) ;; base address
+ dec hl
+ ld c,(hl)
+ dec hl
+ ld a,(hl)
+ .db #0x0dd
+ ld h,a
+ dec hl
+ ld a,(hl)
+ .db #0x0dd
+ ld l,a ;; IX is offset of table from start of loaded file
+ add ix,bc ;; relocate IX to give absolute address of table.
+ call relocate_16bit
+ ld e,c
+ call relocate_8bit ;; lower byte
+ ld e,b
+ call relocate_8bit ;; upper byte
+ pop ix
+ ret
+
+;;--------------------------------------------------------------------------
+;; Relocate 8-bit values (e.g. where low and high parts of an address
+;; are loaded seperatly into registers)
+;;
+;; IX = list of 16-bit addresses. Each address identifies an 8-bit
+;; value
+;;
+relocate_8bit:
+ ld a,0(ix)
+ or a
+ ret z
+ inc ix
+rel8bit: push af
+ ld l,0(ix)
+ inc ix
+ ld h,0(ix)
+inc ix
+add hl,bc
+ld a,(hl)
+add e
+ld (hl),a
+pop af
+dec a
+jr nz,rel8bit
+ret
+
+
+;;--------------------------------------------------------------------------
+;; Relocate 16-bit values
+;;
+;; Entry conditions:
+;;
+;; IX = list of 16-bit addresses. Each address identifies a 16-bit
+;; value to relocate.
+;;
+;; BC = base address
+;;
+;; NOTE:
+;; - Relocatable 16-bit values come from CALL and JP instructions and
+;; loading a 16-bit register.
+
+relocate_16bit:
+ld a,0(ix) ;; number of items to relocate
+or a
+ret z
+
+inc ix
+
+rel16bit:
+push af
+;; get offset (from start of file) of 16-bit value to relocate
+ld l,0(ix)
+inc ix
+ld h,0(ix)
+inc ix
+add hl,bc
+;; get the 16-bit value
+ld e,(hl)
+inc hl
+ld d,(hl)
+
+
+;; add base address; therefore relocating it.
+ex de,hl
+add hl,bc
+ex de,hl
+;; write relocated value
+ld (hl),d
+dec hl
+ld (hl),e
+pop af
+dec a
+jr nz,rel16bit
+ret
+