Skip to content

Commit

Permalink
In the yeet_to_yail server the gfx_mode is a global variable. This is…
Browse files Browse the repository at this point in the history
… work to fix that.

This also includes some small changes to try to be able to still compile in the file handling code.  Still about 200+ bytes over.
  • Loading branch information
brad-colbert committed Apr 18, 2024
1 parent ce8b628 commit 965e055
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 37 deletions.
1 change: 1 addition & 0 deletions Makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PRODUCT=YAIL
TARGET=atari
SRC_DIR=src
#CFLAGS=-Osri
#CFLAGS=-Os -DYAIL_BUILD_FILE_LOADER
CFLAGS=-Os
LINKFLAGS=-D__SYSTEM_CHECK__=1
#LINKFLAGS=--debug-info -Wl --dbgfile,"myapp.dbg"
Expand Down
39 changes: 20 additions & 19 deletions server/yeet_to_yail.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
mutex = Lock()
yail_data = None

gfx_mode = GRAPHICS_8
#gfx_mode = GRAPHICS_8
connections = 0
camera_thread = None
camera_done = False
filenames = []
camera_name = None

def fix_aspect(image, crop=False):
def fix_aspect(image: Image.Image, crop: bool=False) -> Image.Image:
aspect = YAIL_W/YAIL_H # YAIL aspect ratio
aspect_i = 1/aspect
w = image.size[0]
Expand Down Expand Up @@ -75,14 +75,14 @@ def fix_aspect(image, crop=False):

return image

def dither_image(image):
def dither_image(image: Image.Image) -> Image.Image:
return image.convert('1')

def pack_bits(image):
def pack_bits(image: Image.Image) -> np.ndarray:
bits = np.array(image)
return np.packbits(bits, axis=1)

def pack_shades(image):
def pack_shades(image: Image.Image) -> np.ndarray:
yail = image.resize((int(YAIL_W/4),YAIL_H), Image.LANCZOS)
yail = yail.convert(dither=Image.FLOYDSTEINBERG, colors=16)

Expand All @@ -101,17 +101,17 @@ def pack_shades(image):

return combined.astype('int8')

def show_dithered(image):
def show_dithered(image: Image.Image) -> None:
image.show()

def show_shades(image_data):
def show_shades(image_data: np.ndarray) -> None:
pil_image_yai = Image.fromarray(image_data, mode='L')
pil_image_yai.resize((320,220), resample=None).show()

def convertToYai(image_data):
def convertToYai(image_data: bytearray, gfx_mode: int) -> bytearray:
import struct

global gfx_mode
#global gfx_mode

ttlbytes = image_data.shape[0] * image_data.shape[1]

Expand All @@ -124,17 +124,17 @@ def convertToYai(image_data):

return image_yai

def update_yail_data(data, thread_safe=True):
def update_yail_data(data: np.ndarray, gfx_mode: int, thread_safe: bool = True) -> None:
global yail_data
if thread_safe:
mutex.acquire()
try:
yail_data = convertToYai(data)
yail_data = convertToYai(data, gfx_mode)
finally:
if thread_safe:
mutex.release()

def send_yail_data(client_socket, thread_safe=True):
def send_yail_data(client_socket: socket.socket, thread_safe: bool=True) -> None:
global yail_data

if thread_safe:
Expand All @@ -149,7 +149,7 @@ def send_yail_data(client_socket, thread_safe=True):
client_socket.sendall(data)
logger.info('Sent YAIL data')

def stream_YAI(client: str, gfx_mode: int, url: str = None, filepath: str = None): #url, client, gfx_mode):
def stream_YAI(client: str, gfx_mode: int, url: str = None, filepath: str = None) -> bool:
from io import BytesIO

# download the body of response by chunk, not immediately
Expand Down Expand Up @@ -198,7 +198,7 @@ def stream_YAI(client: str, gfx_mode: int, url: str = None, filepath: str = None
elif gfx_mode == GRAPHICS_9:
image_data = pack_shades(gray)

image_yai = convertToYai(image_data)
image_yai = convertToYai(image_data, gfx_mode)

client.sendall(image_yai)

Expand All @@ -209,7 +209,7 @@ def stream_YAI(client: str, gfx_mode: int, url: str = None, filepath: str = None
return False

# This uses the DuckDuckGo search engine to find images. This is handled by the duckduckgo_search package.
def search_images(term, max_images=1000):
def search_images(term: str, max_images: int=1000) -> list:
logger.info(f"Searching for '{term}'")
with DDGS() as ddgs:
results = L([r for r in ddgs.images(term, max_results=max_images)])
Expand All @@ -220,7 +220,7 @@ def search_images(term, max_images=1000):

return urls

def camera_handler():
def camera_handler(gfx_mode: int) -> None:
import pygame.camera
import pygame.image

Expand Down Expand Up @@ -287,10 +287,11 @@ def camera_handler():

camera_done = False

def handle_client_connection(client_socket):
def handle_client_connection(client_socket: socket.socket) -> None:
# Set up a new event loop for this thread
global connections
global gfx_mode
#global gfx_mode
gfx_mode = GRAPHICS_8
global camera_thread
global camera_done
client_mode = None
Expand Down Expand Up @@ -433,7 +434,7 @@ def main():

# Initialize the image to send with something
initial_image = Image.new("L", (YAIL_W,YAIL_H))
update_yail_data(pack_shades(initial_image))
update_yail_data(pack_shades(initial_image), GRAPHICS_8)

bind_ip = '0.0.0.0'
bind_port = 5556
Expand Down
25 changes: 10 additions & 15 deletions src/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,20 @@ char process_command(byte ntokens)
}
else
{
/*
gotoxy(0,0);
clrscr();
cputs("ERROR: File not specified");
cgetc();
*/
show_error_pause("ERROR: File not specified");
}
#else
/*
gotoxy(0,0);
clrscr();
cputs("ERROR: File loading not supported");
cgetc();
*/
show_error_pause("ERROR: File not specified");
#endif
}

Expand All @@ -204,25 +208,18 @@ char process_command(byte ntokens)

else
{
gotoxy(0,0);
cprintf("ERROR: File not specified");
cgetc();
show_error_pause("ERROR: File not specified");
}
#else
gotoxy(0,0);
clrscr();
cputs("ERROR: File saving not supported");
cgetc();
show_error_pause("ERROR: File saving not supported");
#endif
}

if(strncmp(tokens[0], "set", 3) == 0)
{
if(ntokens < 3)
{
gotoxy(0,0);
cputs("ERROR: Must specify a setting and value");
cgetc();
show_error_pause("ERROR: Must specify a setting and value");
}
else
{
Expand Down Expand Up @@ -259,9 +256,7 @@ char process_command(byte ntokens)
{
if(ntokens < 2)
{
gotoxy(0,0);
cputs("ERROR: URL not specified");
cgetc();
show_error_pause("ERROR: URL not specified");
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ byte imageFileType(const char filename[])

void saveFile(const char filename[])
{
size_t size;
int fd = open(filename, O_WRONLY);

if(fd >= 0)
Expand Down Expand Up @@ -91,6 +92,7 @@ void saveFile(const char filename[])
#define IMAGE_BLOCK_ONE_TWO_SIZE 4080
#define IMAGE_BLOCK_THREE_SIZE 640
b = MEM_TOKEN;
size = IMAGE_BLOCK_ONE_TWO_SIZE;
write(fd, &b, 1);
write(fd, &size, sizeof(size_t));
write(fd, image.data, IMAGE_BLOCK_ONE_TWO_SIZE);
Expand All @@ -99,6 +101,7 @@ void saveFile(const char filename[])
write(fd, &size, sizeof(size_t));
write(fd, (image.data+0x1000), IMAGE_BLOCK_ONE_TWO_SIZE);

size = IMAGE_BLOCK_THREE_SIZE;
write(fd, &b, 1);
write(fd, &size, sizeof(size_t));
write(fd, (image.data+0x2000), IMAGE_BLOCK_THREE_SIZE);
Expand Down
6 changes: 6 additions & 0 deletions src/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ void show_error(const char* message)
{
show_console();
cputs(message);
}

void show_error_pause(const char* message)
{
show_error(message);
cgetc();
}
1 change: 1 addition & 0 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void pause(const char* message);
void internal_to_atascii(char* buff, byte len);
void atascii_to_internal(char* buff, byte len);
void show_error(const char* message);
void show_error_pause(const char* message);
extern void add_attract_disable_vbi();
extern void remove_attract_disable_vbi();
void wait_vbi(void);
Expand Down
6 changes: 3 additions & 3 deletions src/yail.atari-xex.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MEMORY {

# Preinitialization 1 - Disable BASIC
PRE: file = %O, define = no, start = $2000, size = $0200; # init code that runs once and then overwritten (by SCREEN data etc)
PRE_NOSAV: file = "", define = no, start = $2200, size = $0100; # work aread for PRE-INIT routines that will be overwritten and not saved to disk
#PRE_NOSAV: file = "", define = no, start = $2200, size = $0100; # work aread for PRE-INIT routines that will be overwritten and not saved to disk

# "system check" load chunk
#SYSCHKCHNK: file = %O, start = $2E00, size = $0300;
Expand All @@ -35,7 +35,7 @@ SEGMENTS {
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP, type = zp, optional = yes;
INIT: load = PRE, type = ro, define = yes; # initialisation routines that will be overwritten
INIT_NS: load = PRE_NOSAV, type = rw, define = yes; # used as temporary bss-like data area for init routines but will be reused
#INIT_NS: load = PRE_NOSAV, type = rw, define = yes; # used as temporary bss-like data area for init routines but will be reused
#SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes;
STARTUP: load = MAIN, type = ro, define = yes;
LOWBSS: load = MAIN, type = rw, optional = yes; # not zero initialized
Expand All @@ -47,10 +47,10 @@ SEGMENTS {
#INIT: load = MAIN, type = rw, optional = yes;
BSS: load = MAIN, type = bss, define = yes;

GFX8_DL: load = MAIN, type = rw, align = $0400, define = yes;
#GFX8_CONSOLE_DL: load = MAIN, type = rw, align = $0100, define = yes;
#GFX9_CONSOLE_DL: load = MAIN, type = rw, align = $0100, define = yes;
FRAMEBUFFER: load = MAIN, type = rw, align = $1000, define = yes;
GFX8_DL: load = MAIN, type = rw, align = $0400, define = yes;
}
FEATURES {
CONDES: type = constructor,
Expand Down

0 comments on commit 965e055

Please sign in to comment.