Skip to content

Commit

Permalink
refactored yail to read local hrg file create test file
Browse files Browse the repository at this point in the history
  • Loading branch information
dillera committed Jun 30, 2024
1 parent 13106fc commit 5d6c2a6
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 69 deletions.
49 changes: 49 additions & 0 deletions apple2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generic CC65 TARGETS makefile++
#
# Set the TARGETS and PROGRAM values as required.
# See makefiles/build.mk for details on directory structure for src files and how to add custom extensions to the build.

TARGETS = apple2enh
PROGRAM := yail

SUB_TASKS := clean disk test release
.PHONY: all help $(SUB_TASKS)

all:
@for target in $(TARGETS); do \
echo "-------------------------------------"; \
echo "Building $$target"; \
echo "-------------------------------------"; \
$(MAKE) --no-print-directory -f ../../fujinet-build-tools/makefiles/build.mk CURRENT_TARGET=$$target PROGRAM=$(PROGRAM) $(MAKECMDGOALS); \
done

# if disk images were built show them
@if [ -d ./dist ]; then \
echo "Contents of dist:"; \
ls -1 ./dist; \
fi

@echo "";
@echo "Build Complete";
@echo "";


$(SUB_TASKS): _do_all
$(SUB_TASKS):
@:

_do_all: all

help:
@echo "Makefile for $(PROGRAM)"
@echo ""
@echo "Available tasks:"
@echo "all - do all compilation tasks, create app in build directory"
@echo "clean - remove all build artifacts"
@echo "release - create a release of the executable in the build/ dir"
@echo "disk - generate platform specific disk images in dist/ dir"
@echo "deploy - deploy dist/ images to a local TNFS or other server platform"
@echo "test - run application in emulator for given platform."
@echo " specific platforms may expose additional variables to run with"
@echo " different emulators, see makefiles/custom-<platform>.mk"

9 changes: 9 additions & 0 deletions apple2/application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
################################################################
# COMPILE FLAGS

# reserved memory for graphics
# LDFLAGS += -Wl -D,__RESERVED_MEMORY__=0x2000

CFLAGS = -Os -DBUILD_APPLE2 --include-dir src/common
#LDFLAGS += -C src/apple2-hgrtext.cfg -m $(PROGRAM).map --ld-args -D,__HIMEM__=0xBF00 apple2-iobuf-0800.o
#LDFLAGS += -C src/apple2-hgrtext.cfg -m $(PROGRAM).map apple2-iobuf-0800.o
23 changes: 23 additions & 0 deletions apple2/src/common/appkey.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "fujinet-fuji.h"
#include "weatherui.h"
#include "appkey.h"

extern char appkey[];
//extern char default_key[];

void get_appkey() {

uint16_t len;
bool status;

fuji_set_appkey_details(APPKEY_CREATOR, APPKEY_APPL, 32);
status = fuji_read_appkey(APPKEY_ID, &len, (unsigned char *)appkey);
if ((!status) || (len == 0)) {
//strcpy(appkey, default_key);
disp_nokey();
exit(1);
}
}
10 changes: 10 additions & 0 deletions apple2/src/common/appkey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef APPKEY_H
#define APPKEY_H
#define APPKEY_CREATOR 0x5600
#define APPKEY_APPL 01
#define APPKEY_ID 01

void get_appkey();


#endif
68 changes: 68 additions & 0 deletions apple2/src/common/fuji_typedefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifdef BUILD_APPLE2
/**
* CONFIG custom types
*/

#ifndef FUJI_TYPEDEFS_H
#define FUJI_TYPEDEFS_H

#define FILE_MAXLEN 36

#define MODE_READ 1
#define MODE_WRITE 2

typedef unsigned short DirectoryPosition;

/**
* Returned info for a single SSID entry
* from a WiFi scan
*/
typedef struct {
char ssid[33];
signed char rssi;
} SSIDInfo;

/**
* The current wifi SSID and password
*/
typedef struct
{
char ssid[33];
char password[64];
} NetConfig;

/**
* The current network adapter configuration
*/
typedef struct
{
char ssid[33];
char hostname[64];
unsigned char localIP[4];
unsigned char gateway[4];
unsigned char netmask[4];
unsigned char dnsIP[4];
unsigned char macAddress[6];
unsigned char bssid[6];
char fn_version[15];
} AdapterConfig;

typedef unsigned char HostSlot[32];

typedef struct {
unsigned char hostSlot;
unsigned char mode;
unsigned char file[FILE_MAXLEN];
} DeviceSlot;

typedef struct
{
unsigned short numSectors;
unsigned short sectorSize;
unsigned char hostSlot;
unsigned char deviceSlot;
char filename[256];
} NewDisk;

#endif /* FUJI_TYPEDEFS_H */
#endif
200 changes: 131 additions & 69 deletions apple2/src/yail.c
Original file line number Diff line number Diff line change
@@ -1,84 +1,146 @@
// YAAIL - Yet Another Apple Image Loader
// Based off of Brad's YAIL for Atari
//

#include "fujinet-network.h"
#include "yail.h"

#define HGR_SCREEN_ADDRESS ((unsigned char*)0x2000)

char buffer[8192];
char result[1024];
char *version = "v1.3.14";
char *my_version = "v1.0.0";
char *url;
char* image_url = "n:http://fujinet.diller.org/APPLE/black.gr";
char* image_data;
uint8_t err = 0;
uint16_t conn_bw;
uint8_t connected;
uint8_t conn_err;
uint8_t trans_type = OPEN_TRANS_CRLF;

void debug() {}

void setup() {
uint8_t init_r = 0;
bzero(buffer, 8192);
bzero(result, 1024);
gotox(0);
init_r = network_init();
printf("init: %d, derr: %d\n", init_r, fn_device_error);
#ifdef BUILD_APPLE2
printf("nw: %d\n", sp_network);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <apple2.h>
#include <conio.h>
#include <string.h>

// Function prototypes
void init_text_mode(void);
void display_menu(void);
void init_graphics(void);
void load_local_image(const char *filename);
void load_remote_image(const char *image_url, unsigned char *image_data);
void display_image(void);
void handle_err(const char *msg);

unsigned char *image_buffer;

int main() {
char choice;

// Initialize text mode and display menu
init_text_mode();
display_menu();

// Wait for user input
choice = cgetc();

if (choice == 'L' || choice == 'l') {
// Initialize graphics
init_graphics();

// Load the local test image
load_local_image("test.hrg");

// Display the image
display_image();
} else if (choice == 'F' || choice == 'f') {
// Initialize graphics
init_graphics();

// Allocate memory for the image
image_buffer = (unsigned char *)malloc(8192);
if (!image_buffer) {
printf("Error: Could not allocate memory for image\n");
exit(1);
}

// Load the remote image
load_remote_image("http://example.com/test.hrg", image_buffer);

// Display the image
display_image();
} else {
printf("Invalid choice.\n");
}

// Wait for a key press before exiting
while (!kbhit()) {}

// Free the allocated image buffer
if (image_buffer) {
free(image_buffer);
}

return 0;
}

void handle_err(char *reason) {
if (err) {
printf("Error: %d (d: %d) %s\n", err, fn_device_error, reason);
cgetc();
void init_text_mode() {
// Set the text mode
text();
home();
clrscr();
}

void display_menu() {
// Print the menu
cputs("Welcome to Yet Another Image Loader for Apple\n");
cputs("L - Press to load local HRG image\n");
cputs("F - Press to load remote HRG with FujiNet\n");
}

void init_graphics() {
// Set the graphics mode to HiRes
hires();
}

void load_local_image(const char *filename) {
FILE *file;
long file_size;

// Open the file
file = fopen(filename, "rb");
if (!file) {
printf("Error: Could not open file %s\n", filename);
exit(1);
}

// Get the file size
fseek(file, 0, SEEK_END);
file_size = ftell(file);
fseek(file, 0, SEEK_SET);

// Allocate memory for the image
image_buffer = (unsigned char *)malloc(file_size);
if (!image_buffer) {
printf("Error: Could not allocate memory for image\n");
fclose(file);
exit(1);
}

// Read the file into the buffer
fread(image_buffer, 1, file_size, file);

// Close the file
fclose(file);
}

// Function to load the image from a remote URL
void load_image(const char* image_url, unsigned char* image_data) {
void load_remote_image(const char *image_url, unsigned char *image_data) {
const char *url;
int err;

// Placeholder function to simulate loading an image from a remote URL
// This function will need to be replaced with actual FujiNet network code

url = (const char *)image_url;
err = network_open(url, OPEN_MODE_HTTP_GET, 0);
handle_err("open");
err = network_read(url, buffer, 8192);
err = network_read(url, image_data, 8192);
handle_err("read");
network_close(url);
printf("simple read (same as GET):\n");
handle_err("get:close");
printf("Image loaded from URL: %s\n", image_url);
}

// Function to display the image on the Apple II screen
void display_image(const unsigned char* image_data) {
// Set the graphics mode to Hi-Res
*(unsigned char*)0xC050 = 0;
*(unsigned char*)0xC057 = 0;
// Copy the image data to the Hi-Res screen buffer
// Assuming the image size is 280x192 pixels (8192 bytes)
memcpy(HGR_SCREEN_ADDRESS, image_data, 8192);
// Wait for a key press before exiting
cgetc();
void display_image() {
// Copy the image buffer to the graphics screen
unsigned char *screen = (unsigned char *)0x2000;
for (int i = 0; i < 8192; i++) {
screen[i] = image_buffer[i];
}
}

int main() {
setup();
// Allocate memory for the image data
// Assuming the image size is 280x192 pixels (8192 bytes)
image_data = (char*)malloc(8192);
printf("yaail %s\n", my_version);
printf("fn-lib %s\n", version);
printf("Base URL: %s\n", image_url);
// Load the image from the remote URL
load_image(image_url, image_data);
// Display the image on the Apple II screen
display_image(image_data);
// Free the allocated memory
free(image_data);
return 0;
}
void handle_err(const char *msg) {
// Placeholder function to handle network errors
printf("Error: %s\n", msg);
exit(1);
}
Loading

0 comments on commit 5d6c2a6

Please sign in to comment.