Initial import
diff --git a/contiki-c64/uip/cs8900a.c b/contiki-c64/uip/cs8900a.c
new file mode 100644
index 0000000..f7c73b0
--- /dev/null
+++ b/contiki-c64/uip/cs8900a.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 2001, 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 C64 RealAudio server demo project.
+ *
+ * $Id: cs8900a.c,v 1.1 2003/03/19 16:26:19 adamdunkels Exp $
+ *
+ */
+
+/* cs8900a.c: device driver for the CS8900a chip in 8-bit mode. Mostly
+ written in 6502 assembler for speed. */
+
+#include "cs8900a.h"
+#include "uip.h"
+#include "uip_arp.h"
+
+#define RXTXREG (*(u16_t *)0xde00)
+#define PACKETPP (*(u16_t *)0xde0a)
+#define PPDATA (*(u16_t *)0xde0c)
+
+static u16_t len;
+static u8_t r;
+
+
+/*-----------------------------------------------------------------------------------*/
+void
+cs8900a_init(void)
+{
+ /* Turn on transmission and reception of frames. */
+ /* PACKETPP = 0x0112;
+ PPDATA = 0x00c0; */
+ asm("lda #$12");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda #$c0");
+ asm("sta $de0c");
+ asm("lda #$00");
+ asm("sta $de0d");
+
+ /* Accept valid unicast+broadcast frames. */
+ /* PACKETPP = 0x0104;
+ PPDATA = 0x0d05; */
+ asm("lda #$04");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda #$05");
+ asm("sta $de0c");
+ asm("lda #$0d");
+ asm("sta $de0d");
+
+ /* Set MAC address. */
+ /* PACKETPP = 0x0158;
+ PPDATA = (ETHADDR1 << 8) | (ETHADDR0); */
+ asm("lda #$58");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda #%b", UIP_ETHADDR0);
+ asm("sta $de0c");
+ asm("lda #%b", UIP_ETHADDR1);
+ asm("sta $de0d");
+
+ /* PACKETPP = 0x015a;
+ PPDATA = (ETHADDR3 << 8) | (ETHADDR2); */
+ asm("lda #$5a");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda #%b", UIP_ETHADDR2);
+ asm("sta $de0c");
+ asm("lda #%b", UIP_ETHADDR3);
+ asm("sta $de0d");
+
+ /* PACKETPP = 0x015c;
+ PPDATA = (ETHADDR5 << 8) | (ETHADDR4); */
+ asm("lda #$5c");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda #%b", UIP_ETHADDR4);
+ asm("sta $de0c");
+ asm("lda #%b", UIP_ETHADDR5);
+ asm("sta $de0d");
+
+}
+/*-----------------------------------------------------------------------------------*/
+void
+cs8900a_send(void)
+{
+ if(uip_len >= UIP_BUFSIZE) {
+ asm("inc $d020");
+ return;
+ }
+
+ /* Transmit command. */
+ asm("lda #$c0");
+ asm("sta $de04");
+ asm("lda #$00");
+ asm("sta $de05");
+ asm("lda _uip_len");
+ asm("sta $de06");
+#if UIP_BUFSIZE > 255
+ asm("lda _uip_len+1");
+#else
+ asm("lda #0");
+#endif
+ asm("sta $de07");
+
+ asm("ldx #8");
+ asm("tryagain:");
+ /* Check for avaliable buffer space. */
+ asm("lda #$38");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda $de0d");
+ asm("and #1");
+ asm("bne send");
+
+ /* No space avaliable, skip a received frame and try again. */
+ asm("lda #$02");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda $de0c");
+ asm("ora #$40");
+ asm("sta $de0c");
+
+ asm("dex");
+ asm("bne tryagain");
+
+ asm("bailout:");
+ return;
+
+ /* Send the frame. */
+ asm("send:");
+
+
+ /* First, send 40+14=54 bytes of header. */
+
+ asm("ldx #54");
+ asm("ldy #0");
+ asm("sendloop1:");
+ asm("lda _uip_buf,y");
+ asm("sta $de00");
+ asm("lda _uip_buf+1,y");
+ asm("sta $de01");
+ asm("iny");
+ asm("iny");
+ asm("dex");
+ asm("dex");
+ asm("bne sendloop1");
+
+ if(uip_len <= 54) {
+ return;
+ }
+
+ /* Next, send rest of the packet. */
+
+ uip_len -= 54;
+
+
+ asm("lda ptr1");
+ asm("pha");
+ asm("lda ptr1+1");
+ asm("pha");
+
+ asm("lda _uip_appdata");
+ asm("sta ptr1");
+ asm("lda _uip_appdata+1");
+ asm("sta ptr1+1");
+
+ asm("sendloop2:");
+ asm("lda _uip_len");
+ asm("tax");
+ asm("and #1");
+ asm("beq noinc");
+ asm("inx");
+ asm("noinc:");
+#if UIP_BUFSIZE > 255
+ asm("lda _uip_len+1");
+#else
+ asm("lda #0");
+#endif
+ asm("beq nozero");
+ asm("ldx #0");
+ asm("nozero:");
+ asm("ldy #0");
+ asm("sendloop:");
+ asm("lda (ptr1),y");
+ asm("sta $de00");
+ asm("iny");
+ asm("lda (ptr1),y");
+ asm("sta $de01");
+ asm("iny");
+ asm("dex");
+ asm("dex");
+ asm("bne sendloop");
+ asm("inc ptr1+1");
+#if UIP_BUFSIZE > 255
+ asm("dec _uip_len+1");
+ asm("bpl sendloop2");
+#endif
+
+ asm("pla");
+ asm("sta ptr1+1");
+ asm("pla");
+ asm("sta ptr1");
+}
+/*-----------------------------------------------------------------------------------*/
+static void
+skip_frame(void)
+{
+ /* PACKETPP = 0x0102;
+ PPDATA = PPDATA | 0x0040; */
+ asm("lda #$02");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda $de0c");
+ asm("ora #$40");
+ asm("sta $de0c");
+}
+/*-----------------------------------------------------------------------------------*/
+u8_t
+cs8900a_poll(void)
+{
+ /* Check receiver event register to see if there are any valid
+ unicast frames avaliable. */
+ /* PACKETPP = 0x0124;
+ if(PPDATA & 0x000d == 0x0000) {
+ return 0;
+ }
+ */
+ asm("lda #$24");
+ asm("sta $de0a");
+ asm("lda #$01");
+ asm("sta $de0b");
+ asm("lda $de0d");
+ asm("and #$0d");
+ asm("cmp #$00");
+ asm("bne noreturn");
+ /* No frame ready. */
+ return 0;
+
+ asm("noreturn:");
+ /* Process the incoming frame. */
+
+ /* Read receiver event and discard it. */
+ /* dummy = RXTXREG; */
+
+ asm("lda $de01");
+ asm("sta _len+1");
+ asm("lda $de00");
+ asm("sta _len");
+
+ /* Read frame length. */
+ /* len = uip_len = RXTXREG; */
+ asm("lda $de01");
+ asm("sta _len+1");
+ asm("sta _uip_len+1");
+ asm("lda $de00");
+ asm("sta _len");
+ asm("sta _uip_len");
+
+
+ if(len > UIP_BUFSIZE) {
+ skip_frame();
+ return 0;
+ }
+
+ /* Read bytes into uip_buf. */
+ asm("lda ptr1");
+ asm("pha");
+ asm("lda ptr1+1");
+ asm("pha");
+
+ asm("lda #<_uip_buf");
+ asm("sta ptr1");
+ asm("lda #>_uip_buf");
+ asm("sta ptr1+1");
+
+ asm("lda _len+1");
+ asm("beq read256");
+
+ /* Read first 256*n bytes. */
+ asm("ldy #0");
+ asm("read256loop:");
+ asm("lda $de00");
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("lda $de01");
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("bne read256loop");
+ asm("inc ptr1+1");
+
+ asm("dec _len+1");
+ asm("bne read256loop");
+
+ /* Read last 255 or less bytes. */
+ asm("read256:");
+ asm("lda _len");
+ asm("lsr");
+ asm("bcc noinc");
+ asm("inc _len");
+ asm("noinc:");
+ asm("ldy #$0");
+ asm("readloop:");
+ asm("lda $de00");
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("lda $de01");
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("cpy _len");
+ asm("bne readloop");
+
+ asm("pla");
+ asm("sta ptr1+1");
+ asm("pla");
+ asm("sta ptr1");
+ return len;
+}
diff --git a/contiki-c64/uip/cs8900a.h b/contiki-c64/uip/cs8900a.h
new file mode 100644
index 0000000..b6f1a4c
--- /dev/null
+++ b/contiki-c64/uip/cs8900a.h
@@ -0,0 +1,10 @@
+#ifndef __CS8900A_H__
+#define __CS8900A_H__
+
+#include "uip_arch.h"
+
+void cs8900a_init(void);
+void cs8900a_send(void);
+u8_t cs8900a_poll(void);
+
+#endif /* __CS8900A_H__ */
diff --git a/contiki-c64/uip/rs232dev.c b/contiki-c64/uip/rs232dev.c
new file mode 100644
index 0000000..f14a8ad
--- /dev/null
+++ b/contiki-c64/uip/rs232dev.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2001, 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 uIP TCP/IP stack.
+ *
+ * $Id: rs232dev.c,v 1.1 2003/03/19 16:26:19 adamdunkels Exp $
+ *
+ */
+
+/*
+ * This is a generic implementation of the SLIP protocol over an RS232
+ * (serial) device. While initially intented for the C64, the code can
+ * easily be ported to other platforms as well.
+ *
+ * Huge thanks to Ullrich von Bassewitz <uz@cc65.org> of cc65 fame for
+ * and endless supply of bugfixes, insightsful comments and
+ * suggestions, and improvements to this code!
+ */
+
+#include <rs232.h>
+#include <time.h>
+#include <string.h>
+
+ /* This will include the system specific header files as well */
+#if defined(__CBM__)
+# include <cbm.h>
+#elif defined(__ATARI__)
+# include <atari.h>
+#endif
+
+#include "uip.h"
+
+#define SLIP_END 0300
+#define SLIP_ESC 0333
+#define SLIP_ESC_END 0334
+#define SLIP_ESC_ESC 0335
+
+
+#define SIO_RECV(c) while(rs232_get(&c) == RS_ERR_NO_DATA)
+#define SIO_POLL(c) (rs232_get(&c) != RS_ERR_NO_DATA)
+#define SIO_SEND(c) rs232_put(c)
+
+#define MAX_SIZE UIP_BUFSIZE
+
+static u8_t slip_buf[MAX_SIZE + 2];
+
+#if MAX_SIZE > 255
+static u16_t len, tmplen;
+#else
+static u8_t len, tmplen;
+#endif /* MAX_SIZE > 255 */
+
+#if 1
+#define printf(x)
+#else
+#include <stdio.h>
+#endif
+
+
+/*-----------------------------------------------------------------------------------*/
+static void
+rs232_err(char err)
+{
+ switch(err) {
+ case RS_ERR_OK:
+ printf("RS232 OK\n");
+ break;
+ case RS_ERR_NOT_INITIALIZED:
+ printf("RS232 not initialized\n");
+ break;
+ case RS_ERR_BAUD_TOO_FAST:
+ printf("RS232 baud too fast\n");
+ break;
+ case RS_ERR_BAUD_NOT_AVAIL:
+ printf("RS232 baud rate not available\n");
+ break;
+ case RS_ERR_NO_DATA:
+ printf("RS232 nothing to read\n");
+ break;
+ case RS_ERR_OVERFLOW:
+ printf("RS232 overflow\n");
+ break;
+ }
+
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_send():
+ *
+ * Sends the packet in the uip_buf and uip_appdata buffers. The first
+ * 40 bytes of the packet (the IP and TCP headers) are read from the
+ * uip_buf buffer, and the following bytes (the application data) are
+ * read from the uip_appdata buffer.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_send(void)
+{
+#if MAX_SIZE > 255
+ u16_t i;
+#else
+ u8_t i;
+#endif /* MAX_SIZE > 255 */
+ u8_t *ptr;
+ u8_t c;
+
+ SIO_SEND(SLIP_END);
+
+ ptr = uip_buf;
+ for(i = 0; i < uip_len; ++i) {
+ if(i == 40) {
+ ptr = uip_appdata;
+ }
+ c = *ptr++;
+ switch(c) {
+ case SLIP_END:
+ SIO_SEND(SLIP_ESC);
+ SIO_SEND(SLIP_ESC_END);
+ break;
+ case SLIP_ESC:
+ SIO_SEND(SLIP_ESC);
+ SIO_SEND(SLIP_ESC_ESC);
+ break;
+ default:
+ SIO_SEND(c);
+ break;
+ }
+ }
+ SIO_SEND(SLIP_END);
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_poll():
+ *
+ * Read all avaliable bytes from the RS232 interface into the slip_buf
+ * buffer. If no more bytes are avaliable, it returns with 0 to
+ * indicate that no packet was immediately ready. When a full packet
+ * has been read into the buffer, the packet is copied into the
+ * uip_buf buffer and the length of the packet is returned.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+#if MAX_SIZE > 255
+u16_t
+#else
+u8_t
+#endif /* MAX_SIZE > 255 */
+rs232dev_poll(void)
+{
+ u8_t c;
+ static u8_t lastc;
+
+ while(SIO_POLL(c)) {
+ /* printf("c %x\n", c);*/
+ switch(c) {
+ case SLIP_ESC:
+ lastc = c;
+ break;
+
+ case SLIP_END:
+ lastc = c;
+ /* End marker found, we copy our input buffer to the uip_buf
+ buffer and return the size of the packet we copied. */
+ memcpy(uip_buf, slip_buf, len);
+ tmplen = len;
+ len = 0;
+ return tmplen;
+
+ default:
+ if(lastc == SLIP_ESC) {
+ lastc = c;
+ /* Previous read byte was an escape byte, so this byte will be
+ interpreted differently from others. */
+ switch(c) {
+ case SLIP_ESC_END:
+ c = SLIP_END;
+ break;
+ case SLIP_ESC_ESC:
+ c = SLIP_ESC;
+ break;
+ }
+ } else {
+ lastc = c;
+ }
+
+
+ slip_buf[len] = c;
+ ++len;
+
+ if(len > MAX_SIZE) {
+ len = 0;
+ }
+
+ break;
+ }
+ }
+ return 0;
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_init():
+ *
+ * Initializes the RS232 device and sets the parameters of the device.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_init(void)
+{
+ char err;
+
+ err = rs232_init(0);
+ rs232_err(err);
+ err = rs232_params(RS_BAUD_9600, RS_PAR_NONE);
+ rs232_err(err);
+
+ len = 0;
+
+ return;
+}
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-c64/uip/rs232dev.h b/contiki-c64/uip/rs232dev.h
new file mode 100644
index 0000000..7fd7a21
--- /dev/null
+++ b/contiki-c64/uip/rs232dev.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2001, 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 uIP TCP/IP stack.
+ *
+ * $Id: rs232dev.h,v 1.1 2003/03/19 16:26:19 adamdunkels Exp $
+ *
+ */
+
+#ifndef __RS232DEV_H__
+#define __RS232DEV_H__
+
+#include "uip.h"
+
+void rs232dev_init(void);
+u8_t rs232dev_read(void);
+void rs232dev_send(void);
+
+#if UIP_BUFSIZE > 255
+u16_t rs232dev_poll(void);
+#else
+u8_t rs232dev_poll(void);
+#endif /* UIP_BUFSIZE > 255 */
+
+#endif /* __RS232DEV_H__ */
diff --git a/contiki-c64/uip/uip_arch.c b/contiki-c64/uip/uip_arch.c
new file mode 100644
index 0000000..d9d5457
--- /dev/null
+++ b/contiki-c64/uip/uip_arch.c
@@ -0,0 +1,424 @@
+/*
+ * Copyright (c) 2001, 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 uIP TCP/IP stack.
+ *
+ * $Id: uip_arch.c,v 1.1 2003/03/19 16:26:19 adamdunkels Exp $
+ *
+ */
+
+
+#include "uip.h"
+#include "uip_arch.h"
+
+#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
+#define IP_PROTO_TCP 6
+
+/*-----------------------------------------------------------------------------------*/
+#if UIP_BUFSIZE > 255
+/*-----------------------------------------------------------------------------------*/
+void
+uip_add32(u8_t *op32, u16_t op16)
+{
+ asm("ldy #3");
+ asm("jsr ldaxysp");
+ asm("sta ptr1");
+ asm("stx ptr1+1");
+ asm("ldy #0");
+ asm("lda (sp),y");
+ asm("ldy #3");
+ asm("clc");
+ asm("adc (ptr1),y");
+ asm("sta _uip_acc32+3");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("ldy #1");
+ asm("adc (sp),y");
+ asm("sta _uip_acc32+2");
+ asm("ldy #1");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+1");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+0");
+}
+/*-----------------------------------------------------------------------------------*/
+void
+uip_add_rcv_nxt(u16_t n) {
+ uip_add32(uip_conn->rcv_nxt, n);
+ uip_conn->rcv_nxt[0] = uip_acc32[0];
+ uip_conn->rcv_nxt[1] = uip_acc32[1];
+ uip_conn->rcv_nxt[2] = uip_acc32[2];
+ uip_conn->rcv_nxt[3] = uip_acc32[3];
+ /* asm("pha");
+ asm("lda _uip_conn");
+ asm("sta ptr1");
+ asm("lda _uip_conn+1");
+ asm("sta ptr1+1");
+ asm("pla");
+ asm("clc");
+ asm("ldy #3");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+ asm("dey");
+ asm("txa");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+ asm("dey");
+ asm("lda #0");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+ asm("dey");
+ asm("lda #0");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+
+ n=n;*/
+}
+/*-----------------------------------------------------------------------------------*/
+#else /* UIP_BUFSIZE > 255 */
+/*-----------------------------------------------------------------------------------*/
+void
+uip_add32(u8_t *op32, u8_t op8)
+{
+ asm("ldy #2");
+ asm("jsr ldaxysp");
+ asm("sta ptr1");
+ asm("stx ptr1+1");
+ asm("ldy #0");
+ asm("lda (sp),y");
+ asm("ldy #3");
+ asm("clc");
+ asm("adc (ptr1),y");
+ asm("sta _uip_acc32+3");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+2");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+1");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+0");
+}
+/*-----------------------------------------------------------------------------------*/
+void
+uip_add_rcv_nxt(u8_t n) {
+ asm("pha");
+ asm("lda _uip_conn");
+ asm("sta ptr1");
+ asm("lda _uip_conn+1");
+ asm("sta ptr1+1");
+ asm("pla");
+ asm("clc");
+ asm("ldy #3");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+ asm("dey");
+ asm("lda #0");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+ asm("dey");
+ asm("lda #0");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+ asm("dey");
+ asm("lda #0");
+ asm("adc (ptr1),y");
+ asm("sta (ptr1),y");
+}
+/*-----------------------------------------------------------------------------------*/
+#endif /* UIP_BUFSIZE > 255 */
+
+static u16_t chksum_ptr, chksum_len, chksum_tmp;
+static u16_t chksum(void);
+/*-----------------------------------------------------------------------------------*/
+u16_t
+chksum(void) {
+
+ asm("lda #0");
+ asm("sta tmp1");
+ asm("sta tmp1+1");
+ asm("lda _chksum_ptr");
+ asm("sta ptr1");
+ asm("lda _chksum_ptr+1");
+ asm("sta ptr1+1");
+
+
+ asm("lda _chksum_len+1");
+ asm("beq chksumlast");
+
+
+ /* If checksum is > 256, do the first runs. */
+ asm("ldy #0");
+ asm("clc");
+ asm("chksumloop_256:");
+ asm("lda (ptr1),y");
+ asm("adc tmp1");
+ asm("sta tmp1");
+ asm("iny");
+ asm("lda (ptr1),y");
+ asm("adc tmp1+1");
+ asm("sta tmp1+1");
+ asm("iny");
+ asm("bne chksumloop_256");
+ asm("inc ptr1+1");
+ asm("dec _chksum_len+1");
+ asm("bne chksumloop_256");
+
+ asm("chksum_endloop_256:");
+ asm("lda tmp1");
+ asm("adc #0");
+ asm("sta tmp1");
+ asm("lda tmp1+1");
+ asm("adc #0");
+ asm("sta tmp1+1");
+ asm("bcs chksum_endloop_256");
+
+ asm("chksumlast:");
+ asm("lda _chksum_len");
+ asm("lsr");
+ asm("bcc chksum_noodd");
+ asm("ldy _chksum_len");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("clc");
+ asm("adc tmp1");
+ asm("sta tmp1");
+ asm("bcc noinc1");
+ asm("inc tmp1+1");
+ asm("bne noinc1");
+ asm("inc tmp1");
+ asm("noinc1:");
+ asm("dec _chksum_len");
+
+ asm("chksum_noodd:");
+ asm("clc");
+ asm("php");
+ asm("ldy _chksum_len");
+ asm("chksum_loop1:");
+ asm("cpy #0");
+ asm("beq chksum_loop1_end");
+ asm("plp");
+ asm("dey");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc tmp1");
+ asm("sta tmp1");
+ asm("iny");
+ asm("lda (ptr1),y");
+ asm("adc tmp1+1");
+ asm("sta tmp1+1");
+ asm("dey");
+ asm("php");
+ asm("jmp chksum_loop1");
+ asm("chksum_loop1_end:");
+ asm("plp");
+
+ asm("chksum_endloop:");
+ asm("lda tmp1");
+ asm("adc #0");
+ asm("sta tmp1");
+ asm("lda tmp1+1");
+ asm("adc #0");
+ asm("sta tmp1+1");
+ asm("bcs chksum_endloop");
+
+ asm("lda tmp1");
+ asm("ldx tmp1+1");
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t
+uip_chksum(u16_t *buf, u16_t len)
+{
+ /* unsigned long sum;
+
+ sum = 0;
+
+ chksum_ptr = (u16_t)buf;
+ while(len >= 256) {
+ chksum_len = 256;
+ sum += chksum();
+ len -= 256;
+ chksum_ptr += 256;
+ }
+
+ if(len < 256) {
+ chksum_len = len;
+ sum += chksum();
+ }
+
+ while((sum >> 16) != 0) {
+ sum = (sum >> 16) + (sum & 0xffff);
+ }
+
+ return sum;*/
+
+ chksum_len = len;
+ chksum_ptr = (u16_t)buf;
+ return chksum();
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t
+uip_ipchksum(void)
+{
+ chksum_ptr = (u16_t)uip_buf + UIP_LLH_LEN;
+ chksum_len = 20;
+ return chksum();
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t
+uip_tcpchksum(void)
+{
+ chksum_ptr = (u16_t)&uip_buf[20 + UIP_LLH_LEN];
+ chksum_len = 20;
+ chksum_tmp = chksum();
+
+ chksum_ptr = (u16_t)uip_appdata;
+#ifdef WITH_TFE
+ asm("lda _uip_buf+3+14");
+#else /* WITH_TFE */
+ asm("lda _uip_buf+3");
+#endif /* WITH_TFE */
+ asm("sec");
+ asm("sbc #40");
+ asm("sta _chksum_len");
+#ifdef WITH_TFE
+ asm("lda _uip_buf+2+14");
+#else /* WITH_TFE */
+ asm("lda _uip_buf+2");
+#endif /* WITH_TFE */
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+ asm("jsr %v", chksum);
+
+ asm("clc");
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("txa");
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+
+ /* Fold carry */
+ /* asm("bcc noinc");
+ asm("inc _chksum_tmp");
+ asm("noinc:");*/
+
+ asm("tcpchksum_loop1:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop1");
+
+
+#ifdef WITH_TFE
+ asm("lda _uip_buf+3+14");
+#else /* WITH_TFE */
+ asm("lda _uip_buf+3");
+#endif /* WITH_TFE */
+ asm("sec");
+ asm("sbc #20");
+ asm("sta _chksum_len");
+#ifdef WITH_TFE
+ asm("lda _uip_buf+2+14");
+#else /* WITH_TFE */
+ asm("lda _uip_buf+2");
+#endif /* WITH_TFE */
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+
+ asm("ldy #$0c");
+ asm("clc");
+ asm("php");
+ asm("tcpchksum_loop2:");
+ asm("plp");
+#ifdef WITH_TFE
+ asm("lda _uip_buf+14,y");
+#else /* WITH_TFE */
+ asm("lda _uip_buf,y");
+#endif /* WITH_TFE */
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("iny");
+#ifdef WITH_TFE
+ asm("lda _uip_buf+14,y");
+#else /* WITH_TFE */
+ asm("lda _uip_buf,y");
+#endif /* WITH_TFE */
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+ asm("iny");
+ asm("php");
+ asm("cpy #$14");
+ asm("bne tcpchksum_loop2");
+
+ asm("plp");
+
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #6"); /* IP_PROTO_TCP */
+ asm("sta _chksum_tmp+1");
+
+
+ asm("lda _chksum_tmp");
+ asm("adc _chksum_len+1");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc _chksum_len");
+ asm("sta _chksum_tmp+1");
+
+
+
+ asm("tcpchksum_loop3:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop3");
+
+
+ return chksum_tmp;
+}
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-c64/uip/uip_arch.h b/contiki-c64/uip/uip_arch.h
new file mode 100644
index 0000000..a3748ac
--- /dev/null
+++ b/contiki-c64/uip/uip_arch.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2001, 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 uIP TCP/IP stack.
+ *
+ * $Id: uip_arch.h,v 1.1 2003/03/19 16:26:19 adamdunkels Exp $
+ *
+ */
+
+#ifndef __UIP_ARCH_H__
+#define __UIP_ARCH_H__
+
+#include "uip.h"
+
+#if UIP_BUFSIZE > 255
+void uip_add_rcv_nxt(u16_t n);
+void uip_add32(u8_t *op32, u16_t op16);
+#else
+void uip_add_rcv_nxt(u8_t n);
+void uip_add32(u8_t *op32, u8_t op8);
+#endif /* UIP_BUFSIZE > 255 */
+
+u16_t uip_chksum(u16_t *data, u16_t len);
+u16_t uip_ipchksum(void);
+u16_t uip_tcpchksum(void);
+
+#endif /* __UIP_ARCH_H__ */