1 /* Nitfol - z-machine interpreter using Glk for output.
2 Copyright (C) 1999 Evin Robertson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
18 The author can be reached at nitfol@deja.com
23 glui32 fillstruct(strid_t stream, const unsigned *info, glui32 *dest,
24 glui32 (*special)(strid_t))
26 unsigned char buffer[4];
30 for(e = 0; info[e]; e++) {
31 if(info[e] == 0x8000) {
32 *dest++ = special(stream);
35 else if(info[e] > 4) {
37 for(i = 0; i < info[e]; i++) {
38 *dest++ = glk_get_char_stream(stream);
42 glk_get_buffer_stream(stream, (char *) buffer, info[e]);
45 case 1: *dest = MSBdecode1(buffer); break;
46 case 2: *dest = MSBdecode2(buffer); break;
47 case 3: *dest = MSBdecode3(buffer); break;
48 case 4: *dest = MSBdecode4(buffer); break;
57 glui32 emptystruct(strid_t stream, const unsigned *info, const glui32 *src)
59 unsigned char buffer[4];
63 for(e = 0; info[e]; e++) {
66 for(i = 0; i < info[e]; i++) {
67 glk_put_char_stream(stream, *src++);
72 case 1: MSBencode1(buffer, *src); break;
73 case 2: MSBencode2(buffer, *src); break;
74 case 3: MSBencode3(buffer, *src); break;
75 case 4: MSBencode4(buffer, *src); break;
78 w_glk_put_buffer_stream(stream, (char *) buffer, info[e]);