Skip to content

Commit e3dd317

Browse files
committed
Removed ASYNCIO from the yailsrv. There is much more to do with that.
The "set server" command was borked due to INTERNAL CODE vs ATASCII mixup. Now converting all tokens to ATASCII before hand.
1 parent 3f13d63 commit e3dd317

File tree

9 files changed

+85
-56
lines changed

9 files changed

+85
-56
lines changed

Makefile.mak

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PRODUCT=YAIL
77
TARGET=atari
88
SRC_DIR=src
99
CFLAGS=-Or
10+
LINKFLAGS=
11+
#LINKFLAGS=--debug-info -Wl --dbgfile,"myapp.dbg"
1012
# -D__SYSTEM_CHECK__=1
1113
LIBRARIES=fujinet-lib/fujinet-atari-2.2.1.lib
1214

@@ -24,7 +26,7 @@ s_files: $(SRC_DIR)\*.s
2426
@$(MAKE) -nologo /f Makefile.mak $(**:.s=.o)
2527

2628
link_files: $(SRC_DIR)\*.o
27-
$(CL65) -t $(TARGET) $(CFLAGS) -o $(PRODUCT).XEX --config $(SRC_DIR)\$(PRODUCT).$(TARGET)-xex.cfg --mapfile $(PRODUCT).map -Ln $(PRODUCT).lbl $(**) $(TARGET).lib $(LIBRARIES)
29+
$(CL65) -t $(TARGET) $(CFLAGS) $(LINKFLAGS) -o $(PRODUCT).XEX --config $(SRC_DIR)\$(PRODUCT).$(TARGET)-xex.cfg --mapfile $(PRODUCT).map -Ln $(PRODUCT).lbl $(**) $(TARGET).lib $(LIBRARIES)
2830

2931
.s.o:
3032
$(CA65) -t $(TARGET) $<

YAIL.XEX

-16 Bytes
Binary file not shown.

server/testclient.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
99

1010
# connect the client
11-
client.connect(('127.0.0.1', 5556))
11+
client.connect(('192.168.1.126', 5556))
1212
client.send(b'search funny\n')
1313

1414
IMAGE_SIZE = 8807
15-
while True:
16-
numbytes = 0
17-
# receive the response data (4096 is recommended buffer size)
18-
while numbytes < IMAGE_SIZE:
19-
response = client.recv(4096)
20-
numbytes += len(response)
2115

22-
if numbytes == 0:
23-
break
16+
numbytes = 0
17+
# receive the response data (4096 is recommended buffer size)
18+
while numbytes < IMAGE_SIZE:
19+
response = client.recv(4096)
20+
numbytes += len(response)
2421

25-
print('\trecv\'d %d bytes (%d)\n' % (len(response), numbytes))
26-
print('\trecv\'d %d bytes (%d)\n' % (len(response), numbytes))
22+
if numbytes == 0:
23+
break
24+
25+
print('\trecv\'d %d bytes (%d)\n' % (len(response), numbytes))
26+
27+
input("Press Enter to continue...")
28+
client.send(b'quit\n')
29+
client.close()
2730

28-
input("Press Enter to continue...")
29-
client.send(b'stop\n')

server/yailsrv.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import requests
66
import re
7-
import json
7+
#import json
88
import time
99
import logging
10-
import urllib
10+
#import urllib
1111
import os
1212
from tqdm import tqdm
1313
import socket
@@ -18,7 +18,7 @@
1818
from pprint import pprint
1919
from PIL import Image
2020
import numpy as np
21-
import asyncio
21+
#import asyncio
2222

2323
GRAPHICS_8 = 2
2424
GRAPHICS_9 = 4
@@ -65,7 +65,6 @@ def search_images(term, max_images=1000):
6565
def hash_string(s):
6666
import hashlib
6767
import binascii
68-
#hsh = bytearray(hashlib.md5(s.encode(encoding="ascii")).digest())
6968
hsh = bytearray(hashlib.shake_256(s.encode(encoding="ascii")).digest(2))
7069
assert len(hsh) == 2
7170
output = \
@@ -284,12 +283,11 @@ def stream_YAI(url, client, gfx_mode):
284283
print('Exception:', e)
285284
return False
286285

287-
# new asyncio loop
288-
286+
# For now this function is not async. It may be in the future.
289287
def handle_client_connection(client_socket):
290288
# Set up a new event loop for this thread
291-
loop = asyncio.new_event_loop()
292-
asyncio.set_event_loop(loop)
289+
#loop = asyncio.new_event_loop()
290+
#asyncio.set_event_loop(loop)
293291

294292
gfx_mode = GRAPHICS_9
295293
try:
@@ -339,7 +337,7 @@ def handle_client_connection(client_socket):
339337

340338
finally:
341339
client_socket.close()
342-
loop.close() # Close the loop when done
340+
#loop.close() # Close the loop when done
343341

344342
def main():
345343
while True:

src/console.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "files.h"
77
#include "consts.h"
88
#include "types.h"
9+
#include "utility.h"
910

1011
#include <atari.h>
1112
#include <conio.h>
@@ -32,8 +33,8 @@ char CONSOLE_BUFF[GFX_0_MEM_LINE * CONSOLE_LINES];
3233
#else
3334
#define CONSOLE_BUFF ((byte*)((ushort*)ORG_SDLIST)[2])
3435
#endif
35-
char* tokens[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; // Maximum of 8 tokens
36-
char server[80] = { "N:TCP://192.168.1.205:9999/\"\0" };
36+
char* tokens[8]; // = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; // Maximum of 8 tokens
37+
char server[80] = { "N:TCP://192.168.1.126:5556/\"\0" };
3738

3839
void reset_console(void)
3940
{
@@ -70,7 +71,7 @@ byte get_tokens(byte* buff, byte endx)
7071
}
7172
}
7273

73-
// Fix last token. For some strange reason, the last token is ending with 0x80
74+
// Fix last token. For some strange reason, the last token is ending with 0x80 (ENTER key?)
7475
i = strlen(tokens[count-1]);
7576
tokens[count-1][i-1] = 0x0;
7677

@@ -86,17 +87,6 @@ byte get_tokens(byte* buff, byte endx)
8687
return count;
8788
}
8889

89-
void fix_chars(char* buff)
90-
{
91-
byte i;
92-
for(i=0;i<MAX_LINE_LEN;++i)
93-
{
94-
if(buff[i]) // leave the null terminator
95-
if(buff[i] <= 63)
96-
buff[i] += 32;
97-
}
98-
}
99-
10090
void process_command(byte ntokens)
10191
{
10292
if(!ntokens)
@@ -128,21 +118,21 @@ void process_command(byte ntokens)
128118
{
129119
switch(tokens[1][0])
130120
{
131-
case 16:
121+
case '0':
132122
setGraphicsMode(GRAPHICS_0);
133123
break;
134-
case 24:
124+
case '8':
135125
setGraphicsMode(GRAPHICS_8);
136126
break;
137-
case 25:
127+
case '9':
138128
setGraphicsMode(GRAPHICS_9);
139129
break;
140-
case 17:
130+
case '1':
141131
switch(tokens[1][1])
142-
{ case 16:
132+
{ case '0':
143133
setGraphicsMode(GRAPHICS_10);
144134
break;
145-
case 17:
135+
case '1':
146136
setGraphicsMode(GRAPHICS_11);
147137
break;
148138
}
@@ -160,7 +150,7 @@ void process_command(byte ntokens)
160150
{
161151
if(ntokens > 1)
162152
{
163-
fix_chars(tokens[1]);
153+
//internal_to_atascii(tokens[1], 40);
164154
load_image_file(tokens[1]);
165155
}
166156
else
@@ -196,9 +186,7 @@ void process_command(byte ntokens)
196186
else
197187
{
198188
if(strncmp(tokens[1], "server", 3) == 0)
199-
{
200189
strncpy(server, tokens[2], 79);
201-
}
202190
}
203191
}
204192

@@ -264,10 +252,11 @@ void start_console(char first_char)
264252
{
265253
// process the tokens
266254
#define WORKING_BUFF_SIZE 80
267-
byte buff[80]; // two lines of data
255+
byte buff[WORKING_BUFF_SIZE]; // two lines of data
268256
byte ntokens = 0;
269257

270258
memcpy(buff, CONSOLE_BUFF, WORKING_BUFF_SIZE);
259+
internal_to_atascii(buff, WORKING_BUFF_SIZE);
271260

272261
#ifdef DEBUG_CONSOLE
273262
gotoxy(0,1);
@@ -312,8 +301,13 @@ void start_console(char first_char)
312301

313302
if(ntokens > 0)
314303
{
304+
byte i;
315305
reset_console();
316306
process_command(ntokens);
307+
308+
// Clear the tokens for the next command
309+
for(i = 0; i < 7; ++i)
310+
tokens[i] = 0x0;
317311
}
318312

319313
reset_console();

src/imgload.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern char server[];
1818

1919
//
2020
//char version[] = "YAIL (Yet Another Image Loader) v1.2.2";
21-
const byte version[] = "\x00\x39\x21\x29\x2C\x00\x08\x39\x65\x74\x00\x21\x6E\x6F\x74\x68\x65\x72\x00\x29\x6D\x61\x67\x65\x00\x2C\x6F\x61\x64\x65\x72\x09\x00\x76\x11\x0E\x12\x0E\x16\x00";
21+
const byte version[] = "\x00\x39\x21\x29\x2C\x00\x08\x39\x65\x74\x00\x21\x6E\x6F\x74\x68\x65\x72\x00\x29\x6D\x61\x67\x65\x00\x2C\x6F\x61\x64\x65\x72\x09\x00\x76\x11\x0E\x12\x0E\x17\x00";
2222
char buff[256]; // A block of memory to be used by all.
2323
bool done = false;
2424

@@ -39,7 +39,7 @@ void process_command_line(int argc, char* argv[])
3939
help();
4040
break;
4141
case 'l':
42-
fix_chars(argv[2]);
42+
internal_to_atascii(argv[2], 40);
4343
load_image_file(argv[2]);
4444
break;
4545
case 'u':

src/netimage.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ void stream_image(char* url, char* args[])
4242
if(FN_ERR_OK != network_init())
4343
{
4444
show_console();
45-
cprintf("Failed to initialize network\n\r");
45+
cputs("Failed to initialize network\n\r");
4646
network_close(url);
4747
return;
4848
}
4949

5050
if(FN_ERR_OK != network_open(url, 12, 0))
5151
{
5252
show_console();
53-
cprintf("Failed to open network\n\r");
53+
cprintf("Failed to open %s\n\r", url);
5454
network_close(url);
5555
return;
5656
}
5757

5858
// Send which graphics mode we are in
5959
memset(buff, 0, 256);
60-
sprintf(buff, "gfx %d", CURRENT_MODE &= ~GRAPHICS_CONSOLE_EN);
61-
if(FN_ERR_OK != network_write(url, buff, 5))
60+
sprintf(buff, "gfx %d ", CURRENT_MODE &= ~GRAPHICS_CONSOLE_EN);
61+
if(FN_ERR_OK != network_write(url, buff, 6))
6262
{
6363
show_console();
64-
cprintf("Unable to write graphics mode\n\r");
64+
cprintf("Unable to write graphics mode \"%s\"\n\r", buff);
6565
network_close(url);
6666
return;
6767
}
@@ -71,7 +71,7 @@ void stream_image(char* url, char* args[])
7171
memcpy(buff, "search \"", 8);
7272
for(i = 0; i < 8; ++i)
7373
{
74-
if(args[i] == 0x0)
74+
if(0x0 == args[i])
7575
break;
7676

7777
if(i > 0)

src/utility.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,32 @@ void pause(const char* message)
1919
break;
2020
}
2121
}
22-
}
22+
}
23+
24+
void internal_to_atascii(char* buff, byte len)
25+
{
26+
byte i;
27+
for(i=0;i<len;++i)
28+
{
29+
if(buff[i]) // leave the null terminator
30+
if(buff[i] < 64)
31+
buff[i] += 32;
32+
else if(buff[i] < 96)
33+
buff[i] -= 64;
34+
// otherwise leave it alone
35+
}
36+
}
37+
38+
void atascii_to_internal(char* buff, byte len)
39+
{
40+
byte i;
41+
for(i=0;i<len;++i)
42+
{
43+
if(buff[i]) // leave the null terminator
44+
if(buff[i] < 32)
45+
buff[i] += 64;
46+
else if(buff[i] < 96)
47+
buff[i] -= 32;
48+
// otherwise leave it alone
49+
}
50+
}

src/utility.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#include "types.h"
77

8+
void pause(const char* message);
9+
void internal_to_atascii(char* buff, byte len);
10+
void atascii_to_internal(char* buff, byte len);
11+
12+
#if 0
813
#include <stdlib.h>
914

1015
typedef struct _MemSeg
@@ -32,5 +37,6 @@ void* malloc_constrianed(size_t size, size_t fence);
3237
size_t allocSegmentedMemory(size_t block_size, size_t num_blocks, size_t boundary, MemSegs* memsegs);
3338
void freeSegmentedMemory(MemSegs* memsegs);
3439
void printMemSegs(const MemSegs* memsegs);
40+
#endif
3541

3642
#endif

0 commit comments

Comments
 (0)