From e4e0d057cccbac640f653340a4dc152571ce3faf Mon Sep 17 00:00:00 2001 From: Astoria Date: Mon, 16 Jan 2023 21:52:13 -0600 Subject: [PATCH] Sortron shenanigans --- IOX/Makefile | 19 ++++++++++-- IOX/conio.c | 73 ++++++++++++++++++++++++++++++++++++++++++----- IOX/conio.h | 12 ++++++++ IOX/emu65el02.ini | 10 +++++++ IOX/sort_test.c | 0 IOX/sort_test.h | 0 IOX/test_iox.c | 21 ++++++++------ include/console.h | 5 +++- include/sortron.h | 34 +++++++++++++++++++++- 9 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 IOX/emu65el02.ini create mode 100644 IOX/sort_test.c create mode 100644 IOX/sort_test.h diff --git a/IOX/Makefile b/IOX/Makefile index 55f852f..87390cd 100644 --- a/IOX/Makefile +++ b/IOX/Makefile @@ -2,6 +2,7 @@ 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) @@ -32,9 +33,23 @@ all: $(IMAGES) clean: rm *.o *.s -.PHONY: test +.PHONY: testemu -test: test_iox.img +testemu: test_iox.img emu65el02 test_iox.img + +.PHONY: testgame + +testgame: test_iox.img + touch /home/astoria/.local/share/PolyMC/instances/WOAHITSBACK/.minecraft/saves/New\ World-/redpower/disk_09e74aca3d58e92a.img + rm /home/astoria/.local/share/PolyMC/instances/WOAHITSBACK/.minecraft/saves/New\ World-/redpower/disk_09e74aca3d58e92a.img + cp test_iox.img /home/astoria/.local/share/PolyMC/instances/WOAHITSBACK/.minecraft/saves/New\ World-/redpower/disk_09e74aca3d58e92a.img + +.PHONY: devgame + +devgame: test_iox.img + touch /home/astoria/Downloads/redpower/saves/New\ World/redpower/disk_b2f279b88ec3d8f5.img + rm /home/astoria/Downloads/redpower/saves/New\ World/redpower/disk_b2f279b88ec3d8f5.img + cp test_iox.img /home/astoria/Downloads/redpower/saves/New\ World/redpower/disk_b2f279b88ec3d8f5.img .SUFFIXES: \ No newline at end of file diff --git a/IOX/conio.c b/IOX/conio.c index 3c4467a..c5d93ed 100644 --- a/IOX/conio.c +++ b/IOX/conio.c @@ -1,12 +1,10 @@ #include "conio.h" #include -#include -#include -#define redbus 0x0300 -int conid = 0x01; -Console* con = (Console*)redbus; + +//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++){ @@ -14,10 +12,10 @@ char * strinv(char str[]) { } 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; + con->line = y % 50; memcpy(con->display + x, str, strlen(str)); } @@ -35,21 +33,82 @@ struct cursor_pos { }; 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 : + fill(' ', 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; } \ No newline at end of file diff --git a/IOX/conio.h b/IOX/conio.h index 6f03ad2..68af138 100644 --- a/IOX/conio.h +++ b/IOX/conio.h @@ -1,9 +1,21 @@ #ifndef CONIO_H #define CONIO_H + +#include +#include + +#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 \ No newline at end of file diff --git a/IOX/emu65el02.ini b/IOX/emu65el02.ini new file mode 100644 index 0000000..40e9ba4 --- /dev/null +++ b/IOX/emu65el02.ini @@ -0,0 +1,10 @@ +default_monitor_id=1 +default_drive_id=2 +cpu_speed=1x +mmu_type=original +io_penality=on +drive_boost=off +memory_size=8kb +spbugfix=disabled +dev_1=2 +dev_2=3 diff --git a/IOX/sort_test.c b/IOX/sort_test.c new file mode 100644 index 0000000..e69de29 diff --git a/IOX/sort_test.h b/IOX/sort_test.h new file mode 100644 index 0000000..e69de29 diff --git a/IOX/test_iox.c b/IOX/test_iox.c index 71d2552..7c8fe66 100644 --- a/IOX/test_iox.c +++ b/IOX/test_iox.c @@ -4,8 +4,9 @@ #include #include #include "test_iox.h" -#include -#include "conio.c" +#include "conio.h" +#include +#include #define redbus 0x0300 #define IOXID 0x03 @@ -15,12 +16,16 @@ Iox* expand; int* output; void main() { + Sortron* sort = (Sortron*)redbus; + int status; rb_set_window((void*)redbus); + rb_map_device(0x04); rb_enable(); - expand = (Iox*)redbus; - rb_map_device(IOXID); - expand->out = 0; - output = (int*)expand->in; - conprint("aeiou FANTASTIQUE!", 0, 0); - set_cursor_pos(5,5); + sort->slot = 1; + sort->quantity = 5; + sort->command = EJECT; + rb_map_device(conid); + conprint("f", 0, 5); + conprint(itoa(sizeof(long), 0, 10), 0, 0); + } \ No newline at end of file diff --git a/include/console.h b/include/console.h index b385290..fb7eef5 100644 --- a/include/console.h +++ b/include/console.h @@ -14,7 +14,7 @@ // 0x07 blit mode (1: fill, 2: invert; 3: shift) // 0x08 blit x start / fill value -// 0x09 blit y start +// 0x09 blit y start / fill color // 0x0A blit x offset // 0x0B blit y offset // 0x0C blit width @@ -43,11 +43,14 @@ typedef struct Console { unsigned int padding; char display[0x50]; + char colors[0x50]; + } Console; //character with inverted colors #define inv(c) ((c) | 0x80) +//Originally commented out? Not sure why, there is a working blit in the test programs. Ive copied that over to conio.h so, this will stay commented out. //void blit(char command, char x, char y, char xo, char yo, char w, char h); #define fill(b, x, y, w, h) blit(1, b, 0, x, y, w, h) diff --git a/include/sortron.h b/include/sortron.h index 361b08f..421e672 100644 --- a/include/sortron.h +++ b/include/sortron.h @@ -1,3 +1,5 @@ +#ifndef RB_SORTRON +#define RB_SORTRON // sortron.h // SORTRON DOCUMENTATION @@ -30,4 +32,34 @@ // $0C: output color // 0 is none, 1-16 is white-black -// $0D: input color \ No newline at end of file +// $0D: input color + +typedef enum { + IDLE = (char)0, + GETSLOTS = (char)1, + GETMETA = (char)2, + EJECT = (char)3, + ACCEPT = (char)4, + FAIL = (char)0xFF +} SortCommand; + +typedef struct Sortron { + //0 + char command; + // 1 + char quantity; + // 2 3 + int slot; + // 4 5 6 7 + unsigned long id; + // 8 9 + unsigned int damage; + // A B + unsigned int max_damage; + // C + char colorout; + // D + char colorin; +} Sortron; + +#endif \ No newline at end of file