1 /*
2  *  KCemu -- The emulator for the KC85 homecomputer series and much more.
3  *  Copyright (C) 1997-2010 Torsten Paul
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include "kc/system.h"
21 
22 #include "kc/kc.h"
23 
24 #include "kc/kcnet/socket.h"
25 
26 #include "sys/sysdep.h"
27 
28 #include "libdbg/dbg.h"
29 
SocketData(int len)30 SocketData::SocketData(int len)
31 {
32   _len = len;
33   _idx = 0;
34   _buf = new byte_t[len];
35 }
36 
~SocketData(void)37 SocketData::~SocketData(void)
38 {
39   delete[] _buf;
40 }
41 
42 int
length(void)43 SocketData::length(void)
44 {
45   return _len;
46 }
47 
48 void
put_byte(byte_t val)49 SocketData::put_byte(byte_t val)
50 {
51   if (_idx < _len)
52     {
53       _buf[_idx++] = val;
54     }
55 }
56 
57 void
put_word(word_t val)58 SocketData::put_word(word_t val)
59 {
60   word_t nval = sys_htons(val);
61   put_byte(nval);
62   put_byte(nval >> 8);
63 }
64 
65 void
put_long(dword_t val)66 SocketData::put_long(dword_t val)
67 {
68   word_t nval = sys_htonl(val);
69   put_byte(nval);
70   put_byte(nval >> 8);
71   put_byte(nval >> 16);
72   put_byte(nval >> 24);
73 }
74 
75 void
put_text(const char * text)76 SocketData::put_text(const char *text)
77 {
78   while (*text != 0)
79     put_byte(*text++);
80 }
81 
82 void
put(int idx,byte_t val)83 SocketData::put(int idx, byte_t val)
84 {
85   if (idx < _len)
86     _buf[idx] = val;
87 }
88 
89 byte_t *
get(void)90 SocketData::get(void)
91 {
92   return _buf;
93 }
94 
95 byte_t
get(int idx)96 SocketData::get(int idx)
97 {
98   if (idx < _len)
99     return _buf[idx];
100 
101   return 0xff;
102 }
103