Add downloader

master
Astoria 1 year ago
parent 810fbec303
commit bb0aec649a

@ -0,0 +1,35 @@
LD = ../bin/ld65
AS = ../bin/ca65
CC = ../bin/cc65
AL = ../bin/align
DA = /home/astoria/bin/da65
CINCLUDE = -I../include
CFLAGS = -t none --cpu $(CPU)
LFLAGS = -C ../lib/rpc8e.cfg
LLIBS = ../lib/rpc8e.lib
#gonna leave this here for now
CPU = 65c02
IMAGES = downloader.img
.PHONY: all
all: $(IMAGES)
%.s: %.c
$(CC) $(CFLAGS) -Oi $(CINCLUDE) $<
%.o: %.s
$(AS) $(CFLAGS) $<
%.img: %.o conio.o
$(LD) $(LFLAGS) $< conio.o $(LLIBS) -o $@
$(AL) $@
clean:
rm *.o *.s
.SUFFIXES:

@ -0,0 +1,114 @@
#include "conio.h"
#include <string.h>
//Slow, find how str function does it and apply to whole string at once?
//Technically could be void, but with returning string allows you to use it easy.
char * strinv(char str[]) {
int i;
for(i = 0; i < strlen(str); i++){
str[i] = inv(str[i]);
}
return str;
}
//This is currently unable to screenwrap. Improve in the future.
void conprint(char * str, int x, int y){
rb_map_device(conid);
con->line = y % 50;
memcpy(con->display + x, str, strlen(str));
}
void set_conid(int id){
conid = id;
}
int get_conid(){
return conid;
}
struct cursor_pos {
int x;
int y;
};
void set_cursor_pos(int x, int y) {
rb_map_device(conid);
con->cursor_x = x;
con->cursor_y = y;
}
struct cursor_pos get_cursor_pos() {
struct cursor_pos cursor;
rb_map_device(conid);
cursor.x = con->cursor_x;
cursor.y = con->cursor_y;
return cursor;
}
void set_cursor_mode(int mode) {
rb_map_device(conid);
con->cursor_mode = mode;
}
int get_cursor_mode() {
rb_map_device(conid);
return con->cursor_mode;
}
void conclear(){
rb_map_device(conid);
blit(1, ' ', (char)0xBD, 0, 0, 80, 50);
set_cursor_pos(0,0);
}
void blit(char command, char x, char y, char xo, char yo, char w, char h) {
con->blit_start_x = x;
con->blit_start_y = y;
con->blit_offset_x = xo;
con->blit_offset_y = yo;
con->blit_width = w;
con->blit_height = h;
con->blit_mode = command;
while(con->blit_mode != 0) ; //WAI
}
#define LF 13
#define BSP 8
char * read_keyboard() {
int pos = 0;
char buf[128];
int breakpoint = 1;
int cursorp;
rb_map_device(conid);
memset(buf, 0, 128);
cursorp = con->cursor_x;
con->line = con->cursor_y;
while(breakpoint) {
while(con->kb_pos != con->kb_start && breakpoint) {
switch(con->kb_key) {
case LF :
blit(1, ' ', (char)0xBD, cursorp, con->cursor_y, con->cursor_x, 1);
con->cursor_x = cursorp;
breakpoint = 0;
con->kb_start++;
break;
case BSP :
con->kb_pos--;
con->cursor_x--;
pos--;
buf[pos] = ' ';
con->display[con->cursor_x] = ' ';
break;
default :
buf[pos] = con->kb_key;
con->display[con->cursor_x] = con->kb_key;
con->cursor_x++;
con->kb_start++;
pos++;
break;
}
}
}
return buf;
}

@ -0,0 +1,21 @@
#ifndef CONIO_H
#define CONIO_H
#include <redbus.h>
#include <console.h>
#define redbus 0x0300
int conid = 0x01;
Console* con = (Console*)redbus;
char * strinv(char str[]);
void conprint(char * str, int x, int y);
void set_conid(int id);
int get_conid();
void set_cursor_pos(int x, int y);
void set_cursor_mode(int mode);
int get_cursor_mode();
void conclear();
void blit(char command, char x, char y, char xo, char yo, char w, char h);
char * read_keyboard();
#endif

@ -0,0 +1,70 @@
// Internet Downloader
#include <redbus.h>
#include <console.h>
#include <internet.h>
#include <stdlib.h>
#include <string.h>
#include <disk.h>
#include "conio.h"
#include "downloader.h"
#define redbus 0x0300
void download_file(char* file) {
unsigned int i;
unsigned int x;
con->cursor_mode = 0;
conprint("Downloading file, please wait warmly.", 0, 6);
rb_map_device(0x05);
memset(internet->url, 0, 50);
strcpy(internet->url, buffer);
internet->command = 1;
while(internet->command == 1);
if(internet->command == 0xFF){
conprint("Error in file download, please try again", 0, 7);
} else {
sectorcount = internet->sector_count;
conprint(strcat(strcat("The file downloaded is of size ", itoa(sectorcount, 0, 10)), " Kilobytes"), 0, 7);
conprint("Transferring data", 0, 8);
for(i = 0; i <= sectorcount; ++i){
rb_map_device(0x05);
internet->sector_num = i;
memcpy(databuf, internet->webbuf, 128);
rb_map_device(0x02);
disk->sector_num = i;
memcpy(disk->sector, databuf, 128);
disk->command = (char)5;
while(disk->command != 0x00 && disk->command != 0xFF);
}
conprint("Data transferred!", 0, 8);
}
}
void main() {
memset(buffer, 0, 50);
memset(ynbuf, 0, 50);
memset(databuf, 0, 50);
internet = (Internet*)redbus;
disk = (Disk*)redbus;
con = (Console*)redbus;
rb_set_window((void*)redbus);
rb_enable();
conclear();
conprint("Internet Disk Retrieval System V1.3", 0, 0);
conprint("Please remove disk now", 0, 1);
conprint("Enter a URL to download from: ", 0, 2);
con->cursor_y = 3;
strcpy(buffer, read_keyboard());
conprint("You are trying to download a file from: ", 0, 3);
conprint(buffer, 0, 4);
con->cursor_x = 23;
con->cursor_y = 5;
conprint("Is this correct? (Y/N)", 0, 5);
memset(ynbuf, 0, 50);
strcpy(ynbuf, read_keyboard());
if(ynbuf[0] == 'Y' || ynbuf[0] == 'y') {
download_file(buffer);
} else{
conprint("Download cancelled", 0, 6);
}
}

@ -0,0 +1,7 @@
// downloader.h
Internet* internet;
Disk* disk;
unsigned char buffer[50];
unsigned char ynbuf[50];
char databuf[128];
unsigned int sectorcount;

@ -0,0 +1,30 @@
//internet.h
// 0x00-0x7F: Disk sector buffer
// 0x80-0x81: Sector number
// 0x82: Disk command:
// 0: Idle/success
// 1: Read Disk Name
// 2: Write Disk Name
// 3: Read Disk Serial
// 4: Read Disk Sector
// 5: Write Disk Sector
// 0xFF: Command failure
typedef enum {
INTERNET_IDLE = 0,
DOWNLOAD_WEBSITE = 1,
CLEAR_WEBSITE = 2,
INTERNET_FAIL = 0xFF
} InternetCommand;
typedef struct Internet {
//RAM
char command;
char url[50];
unsigned int sector_num;
//ROM
unsigned int sector_count;
char webbuf[0x80];
} Internet;
Loading…
Cancel
Save