Skip to content

Commit

Permalink
Removed ASYNCIO from the yailsrv. There is much more to do with that.
Browse files Browse the repository at this point in the history
The "set server" command was borked due to INTERNAL CODE vs ATASCII mixup.  Now converting all tokens to ATASCII before hand.
  • Loading branch information
colbertb committed Feb 29, 2024
1 parent 3f13d63 commit e3dd317
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 56 deletions.
4 changes: 3 additions & 1 deletion Makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PRODUCT=YAIL
TARGET=atari
SRC_DIR=src
CFLAGS=-Or
LINKFLAGS=
#LINKFLAGS=--debug-info -Wl --dbgfile,"myapp.dbg"
# -D__SYSTEM_CHECK__=1
LIBRARIES=fujinet-lib/fujinet-atari-2.2.1.lib

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

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

.s.o:
$(CA65) -t $(TARGET) $<
Expand Down
Binary file modified YAIL.XEX
Binary file not shown.
27 changes: 14 additions & 13 deletions server/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# connect the client
client.connect(('127.0.0.1', 5556))
client.connect(('192.168.1.126', 5556))
client.send(b'search funny\n')

IMAGE_SIZE = 8807
while True:
numbytes = 0
# receive the response data (4096 is recommended buffer size)
while numbytes < IMAGE_SIZE:
response = client.recv(4096)
numbytes += len(response)

if numbytes == 0:
break
numbytes = 0
# receive the response data (4096 is recommended buffer size)
while numbytes < IMAGE_SIZE:
response = client.recv(4096)
numbytes += len(response)

print('\trecv\'d %d bytes (%d)\n' % (len(response), numbytes))
print('\trecv\'d %d bytes (%d)\n' % (len(response), numbytes))
if numbytes == 0:
break

print('\trecv\'d %d bytes (%d)\n' % (len(response), numbytes))

input("Press Enter to continue...")
client.send(b'quit\n')
client.close()

input("Press Enter to continue...")
client.send(b'stop\n')
16 changes: 7 additions & 9 deletions server/yailsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import requests
import re
import json
#import json
import time
import logging
import urllib
#import urllib
import os
from tqdm import tqdm
import socket
Expand All @@ -18,7 +18,7 @@
from pprint import pprint
from PIL import Image
import numpy as np
import asyncio
#import asyncio

GRAPHICS_8 = 2
GRAPHICS_9 = 4
Expand Down Expand Up @@ -65,7 +65,6 @@ def search_images(term, max_images=1000):
def hash_string(s):
import hashlib
import binascii
#hsh = bytearray(hashlib.md5(s.encode(encoding="ascii")).digest())
hsh = bytearray(hashlib.shake_256(s.encode(encoding="ascii")).digest(2))
assert len(hsh) == 2
output = \
Expand Down Expand Up @@ -284,12 +283,11 @@ def stream_YAI(url, client, gfx_mode):
print('Exception:', e)
return False

# new asyncio loop

# For now this function is not async. It may be in the future.
def handle_client_connection(client_socket):
# Set up a new event loop for this thread
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
#loop = asyncio.new_event_loop()
#asyncio.set_event_loop(loop)

gfx_mode = GRAPHICS_9
try:
Expand Down Expand Up @@ -339,7 +337,7 @@ def handle_client_connection(client_socket):

finally:
client_socket.close()
loop.close() # Close the loop when done
#loop.close() # Close the loop when done

def main():
while True:
Expand Down
42 changes: 18 additions & 24 deletions src/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "files.h"
#include "consts.h"
#include "types.h"
#include "utility.h"

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

void reset_console(void)
{
Expand Down Expand Up @@ -70,7 +71,7 @@ byte get_tokens(byte* buff, byte endx)
}
}

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

Expand All @@ -86,17 +87,6 @@ byte get_tokens(byte* buff, byte endx)
return count;
}

void fix_chars(char* buff)
{
byte i;
for(i=0;i<MAX_LINE_LEN;++i)
{
if(buff[i]) // leave the null terminator
if(buff[i] <= 63)
buff[i] += 32;
}
}

void process_command(byte ntokens)
{
if(!ntokens)
Expand Down Expand Up @@ -128,21 +118,21 @@ void process_command(byte ntokens)
{
switch(tokens[1][0])
{
case 16:
case '0':
setGraphicsMode(GRAPHICS_0);
break;
case 24:
case '8':
setGraphicsMode(GRAPHICS_8);
break;
case 25:
case '9':
setGraphicsMode(GRAPHICS_9);
break;
case 17:
case '1':
switch(tokens[1][1])
{ case 16:
{ case '0':
setGraphicsMode(GRAPHICS_10);
break;
case 17:
case '1':
setGraphicsMode(GRAPHICS_11);
break;
}
Expand All @@ -160,7 +150,7 @@ void process_command(byte ntokens)
{
if(ntokens > 1)
{
fix_chars(tokens[1]);
//internal_to_atascii(tokens[1], 40);
load_image_file(tokens[1]);
}
else
Expand Down Expand Up @@ -196,9 +186,7 @@ void process_command(byte ntokens)
else
{
if(strncmp(tokens[1], "server", 3) == 0)
{
strncpy(server, tokens[2], 79);
}
}
}

Expand Down Expand Up @@ -264,10 +252,11 @@ void start_console(char first_char)
{
// process the tokens
#define WORKING_BUFF_SIZE 80
byte buff[80]; // two lines of data
byte buff[WORKING_BUFF_SIZE]; // two lines of data
byte ntokens = 0;

memcpy(buff, CONSOLE_BUFF, WORKING_BUFF_SIZE);
internal_to_atascii(buff, WORKING_BUFF_SIZE);

#ifdef DEBUG_CONSOLE
gotoxy(0,1);
Expand Down Expand Up @@ -312,8 +301,13 @@ void start_console(char first_char)

if(ntokens > 0)
{
byte i;
reset_console();
process_command(ntokens);

// Clear the tokens for the next command
for(i = 0; i < 7; ++i)
tokens[i] = 0x0;
}

reset_console();
Expand Down
4 changes: 2 additions & 2 deletions src/imgload.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern char server[];

//
//char version[] = "YAIL (Yet Another Image Loader) v1.2.2";
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";
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";
char buff[256]; // A block of memory to be used by all.
bool done = false;

Expand All @@ -39,7 +39,7 @@ void process_command_line(int argc, char* argv[])
help();
break;
case 'l':
fix_chars(argv[2]);
internal_to_atascii(argv[2], 40);
load_image_file(argv[2]);
break;
case 'u':
Expand Down
12 changes: 6 additions & 6 deletions src/netimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ void stream_image(char* url, char* args[])
if(FN_ERR_OK != network_init())
{
show_console();
cprintf("Failed to initialize network\n\r");
cputs("Failed to initialize network\n\r");
network_close(url);
return;
}

if(FN_ERR_OK != network_open(url, 12, 0))
{
show_console();
cprintf("Failed to open network\n\r");
cprintf("Failed to open %s\n\r", url);
network_close(url);
return;
}

// Send which graphics mode we are in
memset(buff, 0, 256);
sprintf(buff, "gfx %d", CURRENT_MODE &= ~GRAPHICS_CONSOLE_EN);
if(FN_ERR_OK != network_write(url, buff, 5))
sprintf(buff, "gfx %d ", CURRENT_MODE &= ~GRAPHICS_CONSOLE_EN);
if(FN_ERR_OK != network_write(url, buff, 6))
{
show_console();
cprintf("Unable to write graphics mode\n\r");
cprintf("Unable to write graphics mode \"%s\"\n\r", buff);
network_close(url);
return;
}
Expand All @@ -71,7 +71,7 @@ void stream_image(char* url, char* args[])
memcpy(buff, "search \"", 8);
for(i = 0; i < 8; ++i)
{
if(args[i] == 0x0)
if(0x0 == args[i])
break;

if(i > 0)
Expand Down
30 changes: 29 additions & 1 deletion src/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,32 @@ void pause(const char* message)
break;
}
}
}
}

void internal_to_atascii(char* buff, byte len)
{
byte i;
for(i=0;i<len;++i)
{
if(buff[i]) // leave the null terminator
if(buff[i] < 64)
buff[i] += 32;
else if(buff[i] < 96)
buff[i] -= 64;
// otherwise leave it alone
}
}

void atascii_to_internal(char* buff, byte len)
{
byte i;
for(i=0;i<len;++i)
{
if(buff[i]) // leave the null terminator
if(buff[i] < 32)
buff[i] += 64;
else if(buff[i] < 96)
buff[i] -= 32;
// otherwise leave it alone
}
}
6 changes: 6 additions & 0 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

#include "types.h"

void pause(const char* message);
void internal_to_atascii(char* buff, byte len);
void atascii_to_internal(char* buff, byte len);

#if 0
#include <stdlib.h>

typedef struct _MemSeg
Expand Down Expand Up @@ -32,5 +37,6 @@ void* malloc_constrianed(size_t size, size_t fence);
size_t allocSegmentedMemory(size_t block_size, size_t num_blocks, size_t boundary, MemSegs* memsegs);
void freeSegmentedMemory(MemSegs* memsegs);
void printMemSegs(const MemSegs* memsegs);
#endif

#endif

0 comments on commit e3dd317

Please sign in to comment.