├── os ├── dont.delete ├── ram │ ├── todo │ │ ├── crc16.h │ │ ├── tiny-socks.rtf │ │ ├── tinysocks.c │ │ ├── tsocks.c │ │ ├── dl_prot.h │ │ ├── tinysocks.h │ │ ├── crc16.c │ │ ├── dl_prot.c │ │ ├── rect.c │ │ ├── font.c │ │ ├── datalink.h │ │ ├── tsocks.h │ │ ├── font.h │ │ └── datalink.c │ ├── todo.txt │ ├── errors.c │ ├── interrupt.h │ ├── ukernel.h │ ├── debug.h │ ├── hires.h │ ├── ball.h │ ├── lores.h │ ├── errors.h │ ├── queue.h │ ├── rect.h │ ├── handle.h │ ├── color.h │ ├── event.h │ ├── string.c │ ├── string.h │ ├── system.h │ ├── timer.h │ ├── interrupt.c │ ├── serial.c │ ├── types.h │ ├── serial.h │ ├── memory.h │ ├── yx.h │ ├── handle.c │ ├── list.h │ ├── name.h │ ├── event.c │ ├── task.h │ ├── system.c │ ├── queue.c │ ├── driver.h │ ├── timer.c │ ├── Makefile │ ├── driver.c │ ├── name.c │ ├── ukernel.c │ ├── ball.c │ ├── hires.c │ ├── crt0.s │ ├── list.c │ ├── ssend115k.s │ ├── memory.c │ ├── .depend │ └── lores.c └── rom │ ├── net.c │ ├── shell.h │ ├── syslist.h │ ├── rs232.h │ ├── system.h │ ├── console.h │ ├── .depend │ ├── interrupts.h │ ├── kbd.h │ ├── event.h │ ├── timer.h │ ├── syslist.c │ ├── net.h │ ├── types.h │ ├── system.c │ ├── event.c │ ├── list.h │ ├── memory.h │ ├── task.h │ ├── timer.c │ ├── video.s │ ├── Makefile │ ├── shell.c │ ├── interrupts.s │ ├── list.c │ ├── font6x6.s │ ├── crt0.s │ └── memory.c ├── apps ├── template │ ├── .depend │ ├── app.h │ ├── app.c │ ├── types.h │ ├── video.s │ ├── Makefile │ └── crt0.s ├── kbd │ ├── kbd-table.ods │ ├── table_spectrum_keyboard_ports.png │ ├── app.c │ ├── Makefile │ └── crt0.s └── fonts │ ├── app.c │ ├── Makefile │ └── crt0.s ├── doc ├── yx-buddy.pdf ├── yx-logo.png ├── yx-buddy.docx ├── yx-template.docx └── code-samples │ ├── RectsOverlap.alg │ ├── window.c │ ├── messages.c │ ├── getintersect.alg │ ├── subtractrects.alg │ └── affected.alg ├── tools ├── gdb2fuse │ ├── main.h │ ├── main.cpp │ ├── app.h │ ├── Makefile │ ├── fuse_npipe.h │ ├── gdb_ipsvr.h │ ├── app.cpp │ ├── fuse_npipe.cpp │ └── gdb_ipsvr.cpp ├── screenlines │ └── screenlines.cpp ├── gdb-zxspectrum-stub │ ├── serial.c │ ├── serial.h │ ├── Makefile │ ├── fusesend115k.s │ ├── crt0.s │ ├── fuserecv115k.s │ ├── ssend57k.s │ └── srecv57k.s ├── binarize │ └── binarize.cpp ├── makezxbin │ └── makezxbin.c ├── rawserial │ ├── putraw.c │ └── getraw.c ├── relocator │ └── relocator.cpp └── zxserial │ ├── specget.c │ └── specput.c ├── buddy ├── os │ ├── errors.c │ ├── libex.s │ ├── memory.h │ ├── list.h │ ├── Makefile │ ├── yx.c │ ├── list.c │ └── memory.c ├── include │ ├── masks.h │ ├── clipping.h │ ├── vector.h │ ├── errors.h │ ├── yx.h │ ├── bitmap.h │ ├── rect.h │ ├── types.h │ ├── mouse.h │ └── graphics.h ├── app.h ├── graphics │ ├── masks.s │ ├── mouse.c │ ├── Makefile │ ├── video.s │ ├── clipping.s │ ├── glyph.s │ ├── graphics.c │ └── kempston.s ├── app.c ├── stdwnd.h ├── buddy.h ├── message.c ├── message.h ├── Makefile ├── window.h ├── crt0.s └── temp.depo ├── README.md └── .gitignore /os/dont.delete: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/template/.depend: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/yx-buddy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retro-vault/yx/HEAD/doc/yx-buddy.pdf -------------------------------------------------------------------------------- /doc/yx-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retro-vault/yx/HEAD/doc/yx-logo.png -------------------------------------------------------------------------------- /doc/yx-buddy.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retro-vault/yx/HEAD/doc/yx-buddy.docx -------------------------------------------------------------------------------- /doc/yx-template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retro-vault/yx/HEAD/doc/yx-template.docx -------------------------------------------------------------------------------- /apps/kbd/kbd-table.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retro-vault/yx/HEAD/apps/kbd/kbd-table.ods -------------------------------------------------------------------------------- /apps/kbd/table_spectrum_keyboard_ports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retro-vault/yx/HEAD/apps/kbd/table_spectrum_keyboard_ports.png -------------------------------------------------------------------------------- /os/ram/todo/crc16.h: -------------------------------------------------------------------------------- 1 | #ifndef _CRC16_H 2 | #define _CRC16_H 3 | 4 | #define POLY 0x8408 5 | 6 | extern word crc16(byte *data_p, word length); 7 | 8 | #endif // _CRC16_H 9 | -------------------------------------------------------------------------------- /apps/template/app.h: -------------------------------------------------------------------------------- 1 | /* 2 | * app.h 3 | * application 4 | * 5 | * tomaz stih sun aug 2 2015 6 | */ 7 | #ifndef _APP_H 8 | #define _APP_H 9 | 10 | #endif /* _APP_H */ 11 | -------------------------------------------------------------------------------- /os/ram/todo.txt: -------------------------------------------------------------------------------- 1 | TO DO: 2 | 3 | ***** loader to 49151 4 | 5 | ***** move console functions to tty driver 6 | 7 | ***** remove syslist if not needed 8 | 9 | ***** merge list_insert and list_append 10 | -------------------------------------------------------------------------------- /doc/code-samples/RectsOverlap.alg: -------------------------------------------------------------------------------- 1 | algorithm RectsOverlap 2 | input: Rectangle A 3 | Rectangle B 4 | output: Answer yes/no 5 | begin 6 | return !(A.y1 < B.y0 || A.y0 > B.y1 || A.x1 < B.x0 || A.x0 > B.x1) 7 | end 8 | -------------------------------------------------------------------------------- /apps/fonts/app.c: -------------------------------------------------------------------------------- 1 | /* 2 | * app.c 3 | * backbone of yeah application 4 | * 5 | * tomaz stih thu jul 26 2012 6 | */ 7 | 8 | void main() { 9 | unsigned char * vmem = 16384; 10 | (*vmem)=255; 11 | } -------------------------------------------------------------------------------- /os/ram/errors.c: -------------------------------------------------------------------------------- 1 | /* 2 | * errors.c 3 | * system errors 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #include "yx.h" 8 | 9 | result last_error = RESULT_SUCCESS; /* last error, 0 = success */ 10 | -------------------------------------------------------------------------------- /tools/gdb2fuse/main.h: -------------------------------------------------------------------------------- 1 | #ifndef _MAIN_H 2 | #define _MAIN_H 3 | 4 | #include 5 | 6 | #include "app.h" 7 | 8 | extern app *gdb2fuse; 9 | extern void handle_exit (void); 10 | 11 | #endif // _MAIN_H 12 | -------------------------------------------------------------------------------- /buddy/os/errors.c: -------------------------------------------------------------------------------- 1 | /* 2 | * errors.c 3 | * system errors 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #include "types.h" 8 | #include "errors.h" 9 | 10 | result last_error = SUCCESS; /* last error, 0 = success */ 11 | -------------------------------------------------------------------------------- /buddy/os/libex.s: -------------------------------------------------------------------------------- 1 | ;; libex.s 2 | ;; extra functions, usually provided by SDCC 3 | ;; 4 | ;; tomaz stih sun jul 26 2015 5 | .module crt0 6 | 7 | .globl __sdcc_call_hl 8 | 9 | .area _CODE 10 | 11 | __sdcc_call_hl:: 12 | jp (hl) 13 | -------------------------------------------------------------------------------- /os/ram/interrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * interrupt.h 3 | * interrupt processing 4 | * 5 | * tomaz stih wed apr 10 2013 6 | */ 7 | #ifndef _INTERRUPT_H 8 | #define _INTERRUPT_H 9 | 10 | extern void di() __naked; 11 | extern void ei() __naked; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /doc/code-samples/window.c: -------------------------------------------------------------------------------- 1 | typedef struct window_s { 2 | string title; 3 | rectangle_t* window_rectangle; 4 | window_t* first_child; 5 | window_t* next_sibling; 6 | window_t* parent; 7 | (word))(*window_procedure)(window_t *me, word msg, word p1, word p2)); 8 | ... 9 | } window_t; -------------------------------------------------------------------------------- /os/rom/net.c: -------------------------------------------------------------------------------- 1 | /* 2 | * net.c 3 | * network routines 4 | * 5 | * tomaz stih sun sep 6 2015 6 | */ 7 | #include "types.h" 8 | #include "rs232.h" 9 | #include "net.h" 10 | 11 | net_buff_t *ifirst = NULL; 12 | net_buff_t *ofirst = NULL; 13 | 14 | void net_burst() { 15 | 16 | } -------------------------------------------------------------------------------- /os/rom/shell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * shell.h 3 | * micro shell 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #ifndef _SHELL_H 8 | #define _SHELL_H 9 | 10 | #include "types.h" 11 | 12 | extern void shell(); 13 | extern char shell_get_char(); 14 | 15 | #endif /* _SHELL_H */ 16 | 17 | -------------------------------------------------------------------------------- /doc/code-samples/messages.c: -------------------------------------------------------------------------------- 1 | word send_message(window_t *window, word msg, word p1, word p2) { 2 | if (is_window(window)) { 3 | return window->wndproc(window,msg,p1,p2); 4 | } 5 | } 6 | 7 | /* message loop */ 8 | while (get_message(&m) && m.code!=MSG_QUIT) 9 | dispatch_message(m); 10 | -------------------------------------------------------------------------------- /buddy/include/masks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * masks.h 3 | * graphical brushes 4 | * 5 | * tomaz stih thu aug 6 2015 6 | */ 7 | #ifndef _MASKS_H 8 | #define _MASKS_H 9 | 10 | #include "types.h" 11 | 12 | extern byte* msk_empty_8x8; 13 | extern byte* msk_full_8x8; 14 | extern byte* msk_percent50_8x8; 15 | 16 | #endif /* _MASKS_H */ 17 | -------------------------------------------------------------------------------- /os/ram/ukernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ukernel.c 3 | * yx micro kernel header file 4 | * 5 | * tomaz stih thu mar 21 2013 6 | */ 7 | #ifndef _UKERNEL_H 8 | #define _UKERNEL_H 9 | 10 | /* outputs */ 11 | extern void welcome(); 12 | extern void panic(string s); 13 | extern void scheduler() __naked; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![status.badge] 2 | 3 | an experimental preemptive multitasking μkernel for the zx spectrum 48k. and more. 4 | 5 | the **yx** is *transitioning* and will soon live on inside the new **[xyz operating system](https://github.com/tstih/xyz)** 6 | 7 | [status.badge]: https://img.shields.io/badge/status-transitioning-darkorange.svg 8 | -------------------------------------------------------------------------------- /buddy/include/clipping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clipping.h 3 | * clipping math and util functions 4 | * 5 | * tomaz stih tue jun 9 2015 6 | */ 7 | #ifndef _CLIPPING_H 8 | #define _CLIPPING_H 9 | 10 | #include "types.h" 11 | 12 | extern void clip_offset(byte ofsx, byte ofsy, byte* maskin, byte* maskout); 13 | 14 | #endif /* _CLIPPING_H */ 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries. 2 | *.exe 3 | *.rel 4 | *.o 5 | *.lib 6 | *.bin 7 | *.rom 8 | *.tap 9 | a.out 10 | 11 | # Docs. 12 | *.pdf 13 | 14 | # Backup files. 15 | *.*~ 16 | *.bak 17 | 18 | # Compiler output. 19 | *.cdb 20 | *.hex 21 | *.ihx 22 | *.lst 23 | *.asm 24 | *.map 25 | *.rst 26 | *.sym 27 | *.mem 28 | *.lnk 29 | *.noi 30 | *.lk 31 | -------------------------------------------------------------------------------- /os/ram/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * diagnostics 4 | * 5 | * tomaz stih wed apr 3 2013 6 | */ 7 | #ifndef _DEBUG_H 8 | #define _DEBUG_H 9 | 10 | extern void dbg_wtox(word w, string destination); 11 | extern void dbg_memdump(void *heap); 12 | extern void dbg_evtdump(); 13 | extern void dbg_tmrdump(); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /tools/gdb2fuse/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | using namespace std; 4 | 5 | app *gdb2fuse; 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | atexit(handle_exit); 10 | gdb2fuse = new app(); 11 | gdb2fuse->run(argc, argv); 12 | return 0; 13 | } 14 | 15 | void handle_exit (void) 16 | { 17 | delete gdb2fuse; 18 | } 19 | -------------------------------------------------------------------------------- /apps/template/app.c: -------------------------------------------------------------------------------- 1 | /* 2 | * app.c 3 | * application backbone 4 | * 5 | * tomaz stih sun aug 2 2015 6 | */ 7 | #include "types.h" 8 | #include "app.h" 9 | #include "console.h" 10 | 11 | void main() { 12 | 13 | string s="YX OPERATING SYSTEM FOR ZX SPECTRUM 48K\nREADY.\n"; 14 | 15 | con_clrscr(); 16 | con_puts(s); 17 | } 18 | -------------------------------------------------------------------------------- /buddy/app.h: -------------------------------------------------------------------------------- 1 | /* 2 | * app.h 3 | * application 4 | * 5 | * tomaz stih wed apr 29 2015 6 | */ 7 | #ifndef _APP_H 8 | #define _APP_H 9 | 10 | #include "yx.h" 11 | 12 | extern void register_interfaces(); 13 | extern void *current_task; 14 | extern word heap_size; 15 | extern yx_t *yx; 16 | extern void *heap; 17 | 18 | #endif /* _APP_H */ 19 | -------------------------------------------------------------------------------- /doc/code-samples/getintersect.alg: -------------------------------------------------------------------------------- 1 | algorithm GetRectsIntersect 2 | input: Rectangle A 3 | Rectangle B 4 | output: Answer Intersect 5 | Answer yes/no 6 | begin 7 | if call RectsOverlap(A,B) 8 | Intersect.x0 ← max(A.x0,B.x0), Intersect.y0 ← max(A.y0,B.y0) 9 | Intersect.x1 ← min(A.x1,B.x1), Intersect.y1 ← min(A.y1,B.y1) 10 | return yes 11 | else return no 12 | end -------------------------------------------------------------------------------- /os/ram/hires.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hires.h 3 | * high resolution graphics (256x192) 4 | * 5 | * tomaz stih wed mar 20 2013 6 | */ 7 | #ifndef _HIRES_H 8 | #define _HIRES_H 9 | 10 | extern void hires_cls( 11 | color_t back, 12 | color_t fore, 13 | color_t border, 14 | color_mask_t cm) __naked; 15 | extern word hires_vmem_nextrow_addr(word addr) __naked; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /os/rom/syslist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * syslist.h 3 | * system list is a linked list of system objects 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #ifndef _SYSLIST_H 8 | #define _SYSLIST_H 9 | 10 | #include "types.h" 11 | 12 | extern void *syslist_add(void **first, word size, void *owner); 13 | extern void *syslist_delete(void **first, void *e); 14 | 15 | #endif /* _SYSLIST_H */ 16 | -------------------------------------------------------------------------------- /tools/screenlines/screenlines.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int vmem=16384; 7 | int line=0; 8 | int addr=vmem; 9 | int offset=0; 10 | while (line < 192) { 11 | cout << "\t\t.word " << addr + offset << "\t\t\t; screen line "< 5 | 6 | #include "fuse_npipe.h" 7 | #include "gdb_ipsvr.h" 8 | 9 | using namespace std; 10 | 11 | class app 12 | { 13 | public: 14 | app(); 15 | virtual ~app(); 16 | 17 | void run(int argc, char *argv[]); 18 | void usage(); 19 | void error(const string& msg, int code); 20 | 21 | enum { BUFSIZE = 64 }; // Enum hack. 22 | }; 23 | 24 | #endif // _APP_H 25 | -------------------------------------------------------------------------------- /buddy/include/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vector.h 3 | * vector routines 4 | * 5 | * tomaz stih sat jun 6 2015 6 | */ 7 | #ifndef _VECTOR_H 8 | #define _VECTOR_H 9 | 10 | #include "types.h" 11 | 12 | #define MODE_COPY 0 13 | #define MODE_XOR 1 14 | 15 | extern void vector_plotxy(byte x, byte y); 16 | extern void vector_vertline(byte x, byte y0, byte y1, byte pattern, byte mode); 17 | extern void vector_horzline(byte y, byte x0, byte x1, byte pattern, byte mode); 18 | 19 | #endif /* _VECTOR_H */ 20 | -------------------------------------------------------------------------------- /os/rom/system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * system.c 3 | * operating system header file 4 | * 5 | * tomaz stih thu mar 21 2013 6 | */ 7 | #ifndef _SYSTEM_H 8 | #define _SYSTEM_H 9 | 10 | #include "types.h" 11 | 12 | #define SYS_HEAP_END 0x8000 13 | #define USR_HEAP_START SYS_HEAP_END 14 | #define USR_HEAP_END 0xFFFF 15 | 16 | extern void *sys_stack; 17 | extern void *sys_heap; 18 | 19 | extern void sys_tarpit(); /* the tar pit, primordial soup */ 20 | 21 | #endif /* _SYSTEM_H */ 22 | -------------------------------------------------------------------------------- /buddy/include/errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * errors.h 3 | * system error definitions 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #ifndef _ERRORS_H 8 | #define _ERRORS_H 9 | 10 | #include "types.h" 11 | 12 | #define SUCCESS 00 13 | #define NOT_PROCESSED 01 14 | #define DONT_OWN 02 15 | #define OUT_OF_MEMORY 03 16 | #define CANT_LOCK 04 17 | #define INVALID_PARAMETER 05 18 | #define NOT_FOUND 06 19 | 20 | extern result last_error; /* last error, 0 = success */ 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /os/rom/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * console.h 3 | * console 4 | * 5 | * tomaz stih wed aug 26 2015 6 | */ 7 | #ifndef _CONSOLE_H 8 | #define _CONSOLE_H 9 | 10 | #include "types.h" 11 | 12 | extern void* con_font6x6; 13 | extern byte* con_x; 14 | extern byte* con_y; 15 | 16 | extern void con_putcharxy(byte x, byte y, byte ascii); 17 | extern void con_clrscr(); 18 | extern void con_scroll_up(); 19 | extern void con_puts(string s); 20 | extern void con_back(); 21 | 22 | #endif /* _CONSOLE_H */ 23 | -------------------------------------------------------------------------------- /apps/kbd/app.c: -------------------------------------------------------------------------------- 1 | /* 2 | * app.c 3 | * backbone of yeah application 4 | * 5 | * tomaz stih thu jul 26 2012 6 | */ 7 | 8 | typedef struct kbd_buff_s { 9 | char head; 10 | char tail; 11 | char buffer[32]; 12 | } kbd_buff_t; 13 | 14 | kbd_buff_t kbd_buff; 15 | char prev_scan[8]; 16 | 17 | extern void kbd_scan() __naked; 18 | extern void kbd_init() __naked; 19 | 20 | void test(char ch) { 21 | ch='A'; 22 | } 23 | 24 | void main() { 25 | test('c'); 26 | kbd_init(); 27 | while(1) kbd_scan(); 28 | } 29 | -------------------------------------------------------------------------------- /os/ram/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * queue.h 3 | * fifo queue 4 | * 5 | * tomaz stih thu jul 26 2012 6 | */ 7 | #ifndef _QUEUE_H 8 | #define _QUEUE_H 9 | 10 | #define QUE_FL_NORMAL 0x00 11 | 12 | typedef struct queue_s { 13 | byte *buffer; 14 | word size; 15 | word head; 16 | word tail; 17 | byte flags; 18 | } queue_t; 19 | 20 | extern void que_init(queue_t *q, byte *buffer, word size, byte flags); 21 | extern byte que_put(queue_t *q, byte el); 22 | extern byte que_get(queue_t *q, byte *el); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /tools/gdb2fuse/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | CC = g++ 3 | CFLAGS = -std=c++0x 4 | 5 | # Deps. 6 | CSRCS = $(wildcard *.cpp) 7 | OBJS = $(patsubst %.cpp,%.o,$(CSRCS)) 8 | 9 | # Rules. 10 | .PHONY: all clean 11 | 12 | all: depend gdb2fuse 13 | 14 | depend: $(CSRCS) 15 | rm --force .depend 16 | $(CC) -I. $(CSRCS) -MM >> .depend 17 | 18 | -include .depend 19 | 20 | gdb2fuse: $(OBJS) 21 | $(CC) -o gdb2fuse $(OBJS) 22 | 23 | %.o: %.cpp 24 | $(CC) -c -o $@ $< $(CFLAGS) 25 | 26 | clean: 27 | rm -f *.o *~ .depend gdb2fuse 28 | -------------------------------------------------------------------------------- /os/ram/rect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rect.h 3 | * rectangle object 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #ifndef _RECT_H 8 | #define _RECT_H 9 | 10 | #define POPULATE_RECT(_rect_ptr, _x0, _y0, _x1, _y1) \ 11 | _rect_ptr->x0=_x0; \ 12 | _rect_ptr->y0=_y0; \ 13 | _rect_ptr->x1=_x1; \ 14 | _rect_ptr->y1=_y1; 15 | 16 | typedef struct rect_s { 17 | byte x0; 18 | byte y0; 19 | byte x1; 20 | byte y1; 21 | } rect_t; 22 | 23 | extern boolean rct_intersect(rect_t *r1, rect_t *r2) __naked; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /os/rom/.depend: -------------------------------------------------------------------------------- 1 | event.rel: event.c types.h list.h syslist.h event.h 2 | list.rel: list.c types.h list.h 3 | memory.rel: memory.c types.h list.h memory.h 4 | net.rel: net.c types.h rs232.h net.h list.h 5 | shell.rel: shell.c types.h kbd.h console.h 6 | syslist.rel: syslist.c types.h list.h memory.h system.h 7 | system.rel: system.c types.h system.h memory.h list.h interrupts.h task.h \ 8 | event.h timer.h kbd.h net.h shell.h 9 | task.rel: task.c types.h list.h memory.h syslist.h event.h system.h task.h 10 | timer.rel: timer.c types.h syslist.h timer.h list.h 11 | -------------------------------------------------------------------------------- /os/rom/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * interrupts.h 3 | * interrupts 4 | * 5 | * tomaz stih wed mar 20 2013 6 | */ 7 | #ifndef _INTERRUPTS_H 8 | #define _INTERRUPTS_H 9 | 10 | #include "types.h" 11 | 12 | #define RST08 0 13 | #define RST10 1 14 | #define RST18 2 15 | #define RST20 3 16 | #define RST28 4 17 | #define RST30 5 18 | #define RST38 6 19 | #define NMI 7 20 | 21 | extern void intr_enable(); 22 | extern void intr_disable(); 23 | extern void intr_set_vect(void (*handler)(), byte vec_num); 24 | 25 | #endif /* _INTERRUPTS_H */ 26 | -------------------------------------------------------------------------------- /os/ram/todo/tiny-socks.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252 2 | {\pard\plain tiny sockets library\par} 3 | {\pard\plain ================\par} 4 | {\pard\plain extern socket_t* socket();\tab /* always tcp */\par} 5 | {\pard\plain extern result connect(socket_t* s, sockaddr_t* addr);\par} 6 | {\pard\plain extern result name2addr(string name, sockaddr_t* addr);\par} 7 | {\pard\plain extern close(socket_t *s);\par} 8 | {\pard\plain extern result send(socket_t* s, byte* buffer, word blen);\par} 9 | {\pard\plain extern result recv(socket_t* s, byte* buffer, word blen);\par} 10 | } -------------------------------------------------------------------------------- /os/ram/todo/tinysocks.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | connection_t *connect(ipaddr_t *addr) { 4 | rpc_t rpc; 5 | rpc.fn=FN_CONNECT; 6 | /* pack 6 bytes of addr */ 7 | 8 | } 9 | 10 | void disconnect(connection_t *c) { 11 | rpc_t rpc; 12 | rpc.fn=FN_DISCONNECT; 13 | } 14 | 15 | byte send(connection_t* c, byte* buffer, word length) { 16 | rpc_t rpc; 17 | rpc.fn=FN_SEND; 18 | } 19 | 20 | byte recv(connection_t* c, byte* buffer, word length, word *rlength) { 21 | rpc_t rpc; 22 | rpc.fn=FN_RECV; 23 | } 24 | -------------------------------------------------------------------------------- /os/ram/todo/tsocks.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tsocks.c 3 | * tiny sockets interface is a lightweight interface enabling 4 | * zx spectrum 48K to connect to internet via interface 1 / rs232. 5 | * 6 | * tomaz stih thu jul 26 2012 7 | */ 8 | #include "tsocks.h" 9 | 10 | result connect(socket_t* s, string address, word port) { 11 | 12 | } 13 | 14 | void close(socket_t *s) { 15 | } 16 | 17 | result send(socket_t* s, byte* buffer, word length) { 18 | } 19 | 20 | result recv(socket_t* s, byte* buffer, word length, word *rlength) { 21 | } 22 | 23 | 24 | 25 | #endif -------------------------------------------------------------------------------- /os/ram/handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * handle.h 3 | * handle management 4 | * 5 | * tomaz stih sun apr 21 2013 6 | */ 7 | #ifndef _HANDLE_H 8 | #define _HANDLE_H 9 | 10 | typedef struct handle_s { 11 | /* list_header_t compatible header */ 12 | list_header_t hdr; 13 | /* terminate function */ 14 | void ((*terminate)(struct handle_s *me)); 15 | } handle_t; 16 | 17 | extern handle_t *handle_first; 18 | extern handle_t *handle_create( 19 | void *owner, 20 | void ((*terminate)(struct handle_s *me)), 21 | word size); 22 | extern handle_t *handle_destroy(handle_t *e); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /os/rom/kbd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * keyboard.h 3 | * keyboard scanning (hw code is in kbd.s) 4 | * 5 | * tomaz stih thu jul 26 2012 6 | */ 7 | #ifndef _KEYBOARD_H 8 | #define _KEYBOARD_H 9 | 10 | #include "types.h" 11 | 12 | #define KEY_DOWN_BIT 0b01000000 13 | 14 | typedef struct kbd_buff_s { 15 | byte start; 16 | byte end; 17 | byte count; 18 | byte buffer[32]; 19 | } kbd_buff_t; 20 | 21 | extern void *kbd_map; 22 | extern void *kbd_map_symbol; 23 | extern void *kbd_map_shift; 24 | 25 | extern void kbd_init() __naked; 26 | extern void kbd_scan() __naked; 27 | extern byte kbd_read() __naked; 28 | 29 | #endif /* _KEYBOARD_H */ -------------------------------------------------------------------------------- /os/ram/todo/dl_prot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dl_prot.h 3 | * data link protocol implementation 4 | * 5 | * tomaz stih thu jul 26 2012 6 | */ 7 | #ifndef _DL_PROT_H 8 | #define _DL_PROT_H 9 | 10 | #define DLP_FRAME_LEN 32 11 | 12 | #define ACK 0b00000001 13 | #define NAK 0b00000010 14 | #define DATA 0b00000100 15 | 16 | typedef struct dlp_frame_hdr_s { 17 | byte cmd; 18 | } dlp_frame_hdr_t; 19 | 20 | typedef struct dlp_frame_s { 21 | byte sequence; 22 | byte data[DLP_FRAME_LEN]; 23 | word crc16; 24 | } dlp_frame_t; 25 | 26 | extern word crc16(byte *buffer, word length) __naked; 27 | 28 | #endif -------------------------------------------------------------------------------- /os/ram/color.h: -------------------------------------------------------------------------------- 1 | /* 2 | * color.h 3 | * color definitions 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #ifndef _COLOR_H 8 | #define _COLOR_H 9 | 10 | /* 11 | * color masks, use 'or' to merge 12 | */ 13 | #define CM_NONE 0x00 14 | #define CM_BRIGHT 0x40 15 | #define CM_FLASH 0x80 16 | 17 | /* 18 | * colors 19 | */ 20 | #define BLACK 0x00 21 | #define BLUE 0x01 22 | #define RED 0x02 23 | #define MAGENTA 0x03 24 | #define GREEN 0x04 25 | #define CYAN 0x05 26 | #define YELLOW 0x06 27 | #define WHITE 0x07 28 | 29 | typedef byte color_t; 30 | typedef byte color_mask_t; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /os/ram/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * event.h 3 | * events 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #ifndef _EVENT_H 8 | #define _EVENT_H 9 | 10 | typedef enum event_state_e { 11 | nonsignaled, 12 | signaled 13 | } event_state_t; 14 | 15 | typedef struct event_s { 16 | /* list_header_t compatible header */ 17 | list_header_t hdr; 18 | /* event state */ 19 | event_state_t state; 20 | } event_t; 21 | 22 | extern event_t *evt_first; 23 | extern event_t *evt_create(void *owner); 24 | extern event_t *evt_destroy(event_t *e); 25 | extern event_t *evt_set(event_t *e, event_state_t newstate); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /doc/code-samples/affected.alg: -------------------------------------------------------------------------------- 1 | algorithm FindAffectedWindowsRectangles 2 | input: Z-ordered WindowsList 3 | Rectangle Area 4 | output: Messages sent to all affected windows 5 | begin 6 | if Area is null return 7 | Window ← top window from WindowsList 8 | IntersectRect ← intersection between Area and Window 9 | if exists IntersectRect 10 | send repaint message to Window for IntersectRect 11 | remove Window from WindowsList 12 | if WindowsList is empty return 13 | SmallerAreas ← call SubtractRects(IntersectRect, Area) 14 | foreach SmallerArea in SmallerAreas 15 | call FindAffectedWindowsRectangles(WindowsList, SmallerArea) 16 | end 17 | -------------------------------------------------------------------------------- /os/ram/string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * string.c 3 | * string functions 4 | * 5 | * tomaz stih wed apr 10 2013 6 | */ 7 | #include "yx.h" 8 | 9 | /* compare two strings */ 10 | byte strcmp(string s1, string s2) 11 | { 12 | while((*s1 && *s2) && (*s1++ == *s2++)); 13 | return *(--s1) - *(--s2); 14 | } 15 | 16 | /* copy string to destination strings */ 17 | void strcpy(string dest, string src) { 18 | while (*src) (*dest++ = *src++); 19 | (*dest)=0; /* terminate string */ 20 | } 21 | 22 | /* calc string len */ 23 | word strlen(char *str) 24 | { 25 | const char *s; 26 | for (s = str; *s; ++s) /* do nothing */; 27 | return (s - str); 28 | } 29 | -------------------------------------------------------------------------------- /os/ram/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * string.c 3 | * string functions 4 | * 5 | * tomaz stih wed apr 10 2013 6 | */ 7 | #include "yx.h" 8 | 9 | /* compare two strings */ 10 | byte strcmp(string s1, string s2) 11 | { 12 | while((*s1 && *s2) && (*s1++ == *s2++)); 13 | return *(--s1) - *(--s2); 14 | } 15 | 16 | /* copy string to destination strings */ 17 | void strcpy(string dest, string src) { 18 | while (*src) (*dest++ = *src++); 19 | (*dest)=0; /* terminate string */ 20 | } 21 | 22 | /* calc string len */ 23 | word strlen(char *str) 24 | { 25 | const char *s; 26 | for (s = str; *s; ++s) /* do nothing */; 27 | return (s - str); 28 | } 29 | -------------------------------------------------------------------------------- /os/ram/system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * system.h 3 | * system specifics 4 | * 5 | * tomaz stih wed apr 3 2013 6 | */ 7 | #ifndef _SYSTEM_H 8 | #define _SYSTEM_H 9 | 10 | /* 11 | * system owner ID 12 | */ 13 | #define SYS 0x0000 14 | #define KERNEL SYS 15 | 16 | /* 17 | * system and user heap definition 18 | */ 19 | #define SYSHEAP_TOP 0x8000 20 | #define USRHEAP_TOP 0xbfff 21 | extern word get_sysheap() __naked; 22 | extern word get_usrheap() __naked; 23 | 24 | /* 25 | * system lists 26 | */ 27 | extern void *syslist_add(void **first, word size, void *owner); 28 | extern void *syslist_delete(void **first, void *e); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /os/rom/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * event.h 3 | * events 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #ifndef _EVENT_H 8 | #define _EVENT_H 9 | 10 | #include "types.h" 11 | #include "list.h" 12 | 13 | typedef enum event_state_e { 14 | nonsignaled, 15 | signaled 16 | } event_state_t; 17 | 18 | typedef struct event_s { 19 | /* list_header_t compatible header */ 20 | list_header_t hdr; 21 | /* event state */ 22 | event_state_t state; 23 | } event_t; 24 | 25 | extern event_t *evt_first; 26 | extern event_t *evt_create(void *owner); 27 | extern event_t *evt_destroy(event_t *e); 28 | extern event_t *evt_set(event_t *e, event_state_t newstate); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/serial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * serial.c 3 | * serial communication 4 | * 5 | * tomaz stih sun jul 29 2012 6 | */ 7 | #include "serial.h" 8 | 9 | /* input and output buffers */ 10 | byte rs232_ibuff[RS232_IBUFF_SIZE]; 11 | word rs232_ib_beg=0; 12 | word rs232_ib_end=0; 13 | 14 | /* for storing stack pointer */ 15 | word rs232_sp; 16 | 17 | word rs232_getb(byte *b) { 18 | /* buffer empty */ 19 | if (rs232_ib_beg==rs232_ib_end) { 20 | rs232_ib_beg = 0; 21 | rs232_ib_end = rs232_buffered_input(rs232_ibuff); 22 | } 23 | 24 | if (!rs232_ib_end) 25 | return 1; 26 | else { 27 | (*b) = rs232_ibuff[rs232_ib_beg]; 28 | rs232_ib_beg++; 29 | return 0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /os/ram/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.h 3 | * timer management 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #ifndef _TIMER_H 8 | #define _TIMER_H 9 | 10 | #define EVERYTIME 0 11 | 12 | /* 13 | * timer ticks 50 times per second 14 | */ 15 | typedef struct timer_s { 16 | /* list_header_t compatible header */ 17 | list_header_t hdr; 18 | 19 | void (*hook)(); /* hook routine */ 20 | word ticks; /* trigger after ticks */ 21 | word _tick_count; /* count ticks (internal) */ 22 | } timer_t; 23 | 24 | extern timer_t *tmr_first; 25 | extern timer_t *tmr_install(void (*hook)(), word ticks, void *owner); 26 | extern timer_t *tmr_uninstall(timer_t *t); 27 | extern void tmr_chain(); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /tools/gdb2fuse/fuse_npipe.h: -------------------------------------------------------------------------------- 1 | #ifndef _FUSE_NPIPE_H 2 | #define _FUSE_NPIPE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class fuse_npipe 14 | { 15 | public: 16 | virtual ~fuse_npipe(); 17 | static fuse_npipe* create(char *ifname, char *ofname); 18 | int write(char* buffer, int len); 19 | int read(char *buffer, int len); 20 | private: 21 | int ihandle, ohandle; 22 | int escaped; 23 | fuse_npipe() : ihandle(0), ohandle(0), escaped(0) { } 24 | int readbyte(); 25 | }; 26 | 27 | #endif // _FUSE_NPIPE_H 28 | -------------------------------------------------------------------------------- /os/ram/interrupt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * interrupt.c 3 | * interrupt related routines 4 | * 5 | * tomaz stih wed apr 10 2013 6 | */ 7 | #include "yx.h" 8 | 9 | word dicount=0; 10 | 11 | void di() __naked { 12 | __asm 13 | /* disable interrupts with ref counting */ 14 | di 15 | ld hl,#_dicount 16 | inc (hl) 17 | ret 18 | __endasm; 19 | } 20 | 21 | void ei() __naked { 22 | __asm 23 | /* enable interrupts with ref counting */ 24 | ld a,(#_dicount) 25 | or a 26 | jr z,do_ei /* if a==0 then just ei */ 27 | dec a /* if a<>0 then dec a */ 28 | ld (#_dicount),a /* write back to counter */ 29 | or a /* and check for ei */ 30 | jr nz,dont_ei /* not yet... */ 31 | do_ei: ei 32 | dont_ei: ret 33 | __endasm; 34 | } 35 | -------------------------------------------------------------------------------- /os/ram/serial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * serial.c 3 | * serial communication & 115.200-8-N-2 4 | * 5 | * tomaz stih sun jul 29 2012 6 | */ 7 | #include "yx.h" 8 | 9 | /* input and output buffers */ 10 | byte rs232_ibuff[RS232_IBUFF_SIZE]; 11 | word rs232_ib_beg=0; 12 | word rs232_ib_end=0; 13 | 14 | /* for storing stack pointer */ 15 | word rs232_sp; 16 | 17 | result rs232_getb(byte *b) { 18 | /* buffer empty */ 19 | if (rs232_ib_beg==rs232_ib_end) { 20 | rs232_ib_beg = 0; 21 | rs232_ib_end = rs232_buffered_input(rs232_ibuff); 22 | } 23 | 24 | if (!rs232_ib_end) 25 | return RESULT_RS232_NODATA; 26 | else { 27 | (*b) = rs232_ibuff[rs232_ib_beg]; 28 | rs232_ib_beg++; 29 | return RESULT_SUCCESS; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /os/ram/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * types.h 3 | * common types used in code (do not include stdint.h!) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #ifndef _TYPES_H 8 | #define _TYPES_H 9 | 10 | #define NULL (word)0 11 | 12 | /* signed */ 13 | typedef signed char int8_t; 14 | typedef short int int16_t; 15 | typedef long int int32_t; 16 | 17 | /* unsigned */ 18 | typedef unsigned char uint8_t; 19 | typedef unsigned short int uint16_t; 20 | typedef unsigned long int uint32_t; 21 | 22 | /* usual */ 23 | typedef uint8_t byte; 24 | typedef uint16_t word; 25 | typedef uint8_t * string; 26 | typedef uint8_t result; 27 | typedef void * handle; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /buddy/app.c: -------------------------------------------------------------------------------- 1 | /* 2 | * app.c 3 | * backbone of yeah application 4 | * 5 | * tomaz stih thu apr 16 2015 6 | */ 7 | #include "app.h" 8 | #include "window.h" 9 | #include "stdwnd.h" 10 | #include "message.h" 11 | #include "mouse.h" 12 | 13 | void *current_task=NULL; /* will be real in OS environment */ 14 | word heap_size; /* normally calculated inside crt0 */ 15 | 16 | yx_t *yx; 17 | 18 | void main() { 19 | 20 | /* init OS wrapper */ 21 | heap_size=0xffff - (word)&heap; /* calc heap size */ 22 | register_interfaces(); 23 | yx=(yx_t *)query_interface("yx"); 24 | 25 | /* init buddy */ 26 | buddy_init(); 27 | 28 | /* main loop */ 29 | while (TRUE) { 30 | buddy_harvest_events(); 31 | message_dispatch(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /os/ram/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * serial.h 3 | * serial communication & 115.200-8-N-2 4 | * 5 | * tomaz stih sun jul 29 2012 6 | */ 7 | #ifndef _SERIAL_H 8 | #define _SERIAL_H 9 | 10 | /* ports */ 11 | #define RS232_CTL 0xef 12 | #define RS232_DTA 0xf7 13 | 14 | #define RS232_IBUFF_SIZE 0x14 15 | 16 | /* errors */ 17 | #define RESULT_RS232_NODATA 0xe0 18 | 19 | /* for buffered input */ 20 | extern byte rs232_ibuff[]; 21 | extern word rs232_ib_end; 22 | extern word rs232_ib_beg; 23 | 24 | /* stack pointer storage */ 25 | extern word rs232_sp; 26 | 27 | /* raw serial functions */ 28 | extern word rs232_buffered_input(byte* buffer) __naked; 29 | extern result rs232_getb(byte *b); 30 | extern result rs232_putb(byte b); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /os/ram/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * memory.h 3 | * memory management (mem_allocate, mem_free) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #ifndef _MEMORY_H 8 | #define _MEMORY_H 9 | 10 | #define BLK_SIZE (sizeof(struct block_s) - sizeof(byte[1])) 11 | #define MIN_CHUNK_SIZE 4 12 | 13 | /* block status, use as bit operations */ 14 | #define NEW 0x00 15 | #define ALLOCATED 0x01 16 | 17 | typedef struct block_s { 18 | list_header_t hdr; 19 | byte stat; 20 | word size; 21 | byte data[1]; 22 | } block_t; 23 | 24 | extern void mem_init(void *heap, word size); 25 | extern void *mem_allocate(void *heap, word size, void *owner); 26 | extern void *mem_free(void *heap, void *p); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /os/ram/yx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * yx.h 3 | * the mother of all include files 4 | * 5 | * tomaz stih wed mar 20 2013 6 | */ 7 | #ifndef _YX_H 8 | #define _YX_H 9 | 10 | #define VERSION 0x1000 /* 1.0.0.0 (nibbles are digits)*/ 11 | 12 | #include "types.h" 13 | #include "string.h" 14 | #include "errors.h" 15 | #include "interrupt.h" 16 | #include "system.h" 17 | #include "list.h" 18 | #include "name.h" 19 | #include "handle.h" 20 | #include "queue.h" 21 | #include "color.h" 22 | #include "hires.h" 23 | #include "lores.h" 24 | #include "serial.h" 25 | #include "memory.h" 26 | #include "event.h" 27 | #include "timer.h" 28 | #include "driver.h" 29 | #include "task.h" 30 | #include "debug.h" 31 | #include "ball.h" 32 | #include "ukernel.h" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /buddy/include/yx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * yx.h 3 | * os header file 4 | * 5 | * tomaz stih sun jul 26 2015 6 | */ 7 | #ifndef _YX_H 8 | #define _YX_H 9 | 10 | #include "types.h" 11 | 12 | /* API */ 13 | typedef struct yx_s yx_t; 14 | struct yx_s { 15 | 16 | /* system lists */ 17 | void* (*lappend)(void **first, void *el); 18 | void* (*linsert)(void **first, void *el); 19 | void* (*lremove)(void **first, void *el); 20 | void* (*lremfirst)(void **first); 21 | 22 | /* memory management */ 23 | void* (*allocate)(word size); 24 | void (*free)(void *p); 25 | void (*copy)(byte *src, byte *dst, word count); 26 | 27 | /* tasks, events */ 28 | void (*sleep)(word _50); 29 | }; 30 | 31 | extern void *query_interface(string api); 32 | 33 | #endif /* _YX_H */ 34 | -------------------------------------------------------------------------------- /os/rom/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.h 3 | * timer management 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #ifndef _TIMER_H 8 | #define _TIMER_H 9 | 10 | #include "types.h" 11 | #include "list.h" 12 | 13 | #define EVERYTIME 0 14 | 15 | /* 16 | * timer ticks 50 times per second 17 | */ 18 | typedef struct timer_s { 19 | /* list_header_t compatible header */ 20 | list_header_t hdr; 21 | 22 | void (*hook)(); /* hook routine */ 23 | word ticks; /* trigger after ticks */ 24 | word _tick_count; /* count ticks (internal) */ 25 | } timer_t; 26 | 27 | extern timer_t *tmr_first; 28 | extern timer_t *tmr_install(void (*hook)(), word ticks, void *owner); 29 | extern timer_t *tmr_uninstall(timer_t *t); 30 | extern void tmr_chain(); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /os/ram/handle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * handle.c 3 | * handle management 4 | * 5 | * tomaz stih sun apr 21 2013 6 | */ 7 | #include "yx.h" 8 | 9 | /* initialize linked list */ 10 | handle_t *handle_first = NULL; 11 | 12 | /* create new handle */ 13 | handle_t *handle_create( 14 | void *owner, 15 | void ((*terminate)(struct handle_s *me)), 16 | word size) { 17 | 18 | handle_t *h; 19 | if ( h = (handle_t *)syslist_add((void **)&handle_first, size, owner) ) 20 | h->terminate=terminate; 21 | return h; 22 | } 23 | 24 | /* destroy handle, call terminate function on it */ 25 | handle_t *handle_destroy(handle_t *h) { 26 | if (h->terminate) h->terminate(h); /* call terminate if not null */ 27 | return (handle_t *)syslist_delete((void **)&handle_first, (void *)h); 28 | } 29 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * serial.h 3 | * serial communication 4 | * 5 | * tomaz stih sun jul 29 2012 6 | */ 7 | #ifndef _SERIAL_H 8 | #define _SERIAL_H 9 | 10 | /* buffer size */ 11 | #define RS232_IBUFF_SIZE 0x14 12 | 13 | /* errors */ 14 | #define RESULT_RS232_NODATA 0xe0 15 | 16 | /* types */ 17 | typedef unsigned char byte; 18 | typedef unsigned int word; 19 | 20 | /* for buffered input */ 21 | extern byte rs232_ibuff[]; 22 | extern word rs232_ib_end; 23 | extern word rs232_ib_beg; 24 | 25 | /* stack pointer storage */ 26 | extern word rs232_sp; 27 | 28 | /* raw serial functions */ 29 | extern word rs232_buffered_input(byte* buffer) __naked; 30 | extern word rs232_getb(byte *b); 31 | extern word rs232_putb(byte b); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /tools/gdb2fuse/gdb_ipsvr.h: -------------------------------------------------------------------------------- 1 | #ifndef _GDB_IPSVR_H 2 | #define _GDB_IPSVR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | class gdb_ipsvr 18 | { 19 | public: 20 | static gdb_ipsvr* create(char *sport); 21 | virtual ~gdb_ipsvr(); 22 | int write(const char *buffer, int len); 23 | int read(char *buffer, int len); 24 | protected: 25 | private: 26 | gdb_ipsvr() : port(9999), list_sock(0), conn_sock(0) {} 27 | short int port; 28 | int list_sock; 29 | int conn_sock; 30 | }; 31 | 32 | #endif // _GDB_IPSVR_H 33 | -------------------------------------------------------------------------------- /buddy/include/bitmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * bitmap.h 3 | * bitmap structures and functions 4 | * 5 | * tomaz stih wed apr 29 2015 6 | */ 7 | #ifndef _BITMAP_H 8 | #define _BITMAP_H 9 | 10 | #include "types.h" 11 | #include "rect.h" 12 | 13 | typedef struct bitmap_s { 14 | byte x1; /* 0..x1 */ 15 | byte y1; /* 0..y1 */ 16 | byte data; /* followed by data */ 17 | } bitmap_t; 18 | 19 | extern bitmap_t* bmp_get(rect_t *rect, void *mem); 20 | extern void bmp_put( 21 | void *data, /* raw data */ 22 | byte x, /* screen x */ 23 | byte y, /* screen y */ 24 | byte rows, /* how many roads */ 25 | byte cols, /* how many bits i.e. cols */ 26 | byte shift, /* shift each col right by... */ 27 | byte skip); /* how many bytes of data to skip at the end of a row */ 28 | 29 | #endif /* _BITMAP_H */ 30 | -------------------------------------------------------------------------------- /os/rom/syslist.c: -------------------------------------------------------------------------------- 1 | /* 2 | * syslist.c 3 | * system list is a linked list of system objects 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #include "types.h" 8 | #include "list.h" 9 | #include "memory.h" 10 | #include "system.h" 11 | 12 | /* 13 | * adding to system list 14 | */ 15 | void *syslist_add(void **first, word size, void *owner) { 16 | list_header_t *p; 17 | if( p = (list_header_t *)mem_allocate(&sys_heap, size, owner) ) { 18 | list_insert((list_header_t**)first,p); 19 | p->owner=owner; 20 | } 21 | return (void *)p; 22 | } 23 | 24 | /* 25 | * removing from system list 26 | */ 27 | void *syslist_delete(void **first, void *e) { 28 | if ( e = list_remove( (list_header_t **)first, (list_header_t *)e) ) { 29 | e = mem_free(&sys_heap, e); 30 | } 31 | return e; 32 | } 33 | -------------------------------------------------------------------------------- /os/ram/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * list.h 3 | * linked list 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #ifndef _LIST_H 8 | #define _LIST_H 9 | 10 | /* each linked list must start with list_header */ 11 | typedef struct list_header_s { 12 | void *next; 13 | void* owner; 14 | } list_header_t; 15 | 16 | /* match functions */ 17 | extern byte list_match_eq(list_header_t *p, word arg); 18 | 19 | /* functions */ 20 | extern list_header_t *list_find( 21 | list_header_t *first, 22 | list_header_t **prev, 23 | byte (*match)(list_header_t *p, word arg), 24 | word the_arg); 25 | 26 | /* core functions */ 27 | extern list_header_t *list_insert(list_header_t** first, list_header_t *el); 28 | extern list_header_t *list_remove(list_header_t **first, list_header_t *el); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /buddy/stdwnd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stdwnd.h 3 | * standard windows implementation 4 | * 5 | * tomaz stih tue jul 20 2015 6 | */ 7 | #ifndef _STDWND_H 8 | #define _STDWND_H 9 | 10 | #include "yx.h" 11 | #include "window.h" 12 | #include "message.h" 13 | 14 | #define APP_WND_MIN_WIDTH 35 15 | #define APP_WND_MIN_HEIGHT 15 16 | #define APP_WND_TITLE_HEIGHT 10 17 | #define APP_WND_BORDER_WIDTH 3 18 | #define APP_WND_BORDER_HEIGHT 3 19 | 20 | /* default wnd proc */ 21 | extern result desktop_wnd_proc(window_t* wnd, byte id, word param1, word param2); 22 | extern result app_wnd_proc(window_t* wnd, byte id, word param1, word param2); 23 | extern result control_wnd_proc(window_t* wnd, byte id, word param1, word param2); 24 | extern result client_wnd_proc(window_t* wnd, byte id, word param1, word param2); 25 | 26 | #endif /* _STDWND_H */ 27 | -------------------------------------------------------------------------------- /os/rom/net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * net.h 3 | * network routines 4 | * 5 | * tomaz stih sun sep 6 2015 6 | */ 7 | #ifndef _NET_H 8 | #define _NET_H 9 | 10 | #include "types.h" 11 | #include "list.h" 12 | 13 | typedef struct net_buff_s net_buff_t; 14 | typedef struct net_block_s net_block_t; 15 | 16 | struct net_buff_s { 17 | list_header_t hdr; 18 | byte *buffer; 19 | word size; 20 | word pos; 21 | }; 22 | 23 | struct net_block_s { 24 | byte connection:4; 25 | byte block:4; 26 | byte body[14]; 27 | byte status:4; 28 | byte control:4; 29 | }; 30 | 31 | /* input and output buffer queues */ 32 | extern net_buff_t *ifirst; 33 | extern net_buff_t *ofirst; 34 | 35 | /* burst exchange 20 bytes with the "other side" */ 36 | extern void net_burst(); 37 | extern byte net_connect(string address, word port); 38 | extern void net_disconnect(byte cid); 39 | 40 | #endif /* _NET_H */ -------------------------------------------------------------------------------- /tools/binarize/binarize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | template string xxx_to_bin(const T& value) 13 | { 14 | const bitset::digits + 1> bs(value); 15 | const string s(bs.to_string()); 16 | const string::size_type pos(s.find_first_not_of('0')); 17 | return pos == string::npos ? "0" : s.substr(pos); 18 | } 19 | 20 | int main(int argc, char *argv[]) { 21 | 22 | // First argument is filename. 23 | ifstream infile(argv[1],ios::in|ios::binary); 24 | char b; 25 | while (!infile.eof()) { 26 | infile.read(&b,1); 27 | cout << setw(8) << setfill('0') << xxx_to_bin(b) << endl; 28 | } 29 | 30 | infile.close(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /os/ram/todo/tinysocks.h: -------------------------------------------------------------------------------- 1 | #ifndef _TINYSOCKS_H 2 | #define _TINYSOCKS_H 3 | 4 | /* function codes */ 5 | #define FN_CONNECT 1 6 | #define FN_DISCONNECT 2 7 | #define FN_SEND 3 8 | #define FN_RECV 4 9 | 10 | typedef struct ipaddr_s { 11 | byte ip[4]; 12 | word port; 13 | } ipaddr_t; 14 | 15 | typedef struct connection_s { 16 | byte id; /* remote connection identifier */ 17 | ipaddr_t ipaddr; /* address (nice to have) */ 18 | } connection_t; 19 | 20 | typedef struct rpc_s { 21 | byte fn; 22 | } rpc_t; 23 | 24 | extern connection_t *connect(ipaddr_t *addr); 25 | extern void disconnect(connection_t *c); 26 | 27 | extern byte send(connection_t* c, byte* buffer, word length); 28 | extern byte recv(connection_t* c, byte* buffer, word length, word *rlength); 29 | 30 | #endif // _TINYSOCKS_H 31 | -------------------------------------------------------------------------------- /os/ram/name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * name.h 3 | * named resources management 4 | * 5 | * NOTE: no convention is forced but yx uses first four characters 6 | * of name for type and next four for name i.e. /dev/kbd, 7 | * /dev/232, /wnd/top 8 | * 9 | * TODO: binary tree if rom space available 10 | * 11 | * tomaz stih wed apr 10 2013 12 | */ 13 | #ifndef _NAME_H 14 | #define _NAME_H 15 | 16 | #define MAX_NAME_LEN 8 17 | 18 | typedef struct name_s { 19 | list_header_t hdr; /* compatible with list_header_t */ 20 | byte name[MAX_NAME_LEN+1]; /* max sys name length */ 21 | void *resource; /* pointer to named resource */ 22 | } name_t; 23 | 24 | extern name_t *name_first; 25 | 26 | extern name_t *name_link( 27 | void *owner, 28 | string name, 29 | void *resource); 30 | extern name_t *name_unlink(name_t *n); 31 | extern name_t *name_find(string name); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /buddy/include/rect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rect.h 3 | * rectangle type 4 | * 5 | * tomaz stih mon oct 7 2013 6 | */ 7 | #ifndef _RECT_H 8 | #define _RECT_H 9 | 10 | #include "types.h" 11 | 12 | typedef struct rect_s rect_t; 13 | struct rect_s { 14 | byte x0; 15 | byte y0; 16 | byte x1; 17 | byte y1; 18 | }; 19 | 20 | extern boolean rect_contains(rect_t *r, byte x, byte y); 21 | extern boolean rect_overlap(rect_t *a, rect_t *b); 22 | extern rect_t* rect_inflate(rect_t* rect, sbyte dx, sbyte dy) __naked; 23 | extern rect_t* rect_intersect(rect_t *a, rect_t *b, rect_t *intersect); 24 | extern rect_t* rect_rel2abs(rect_t* abs, rect_t* rel, rect_t* out) __naked; 25 | extern void rect_subtract(rect_t *outer, rect_t *inner, rect_t *result, byte *num); 26 | extern void rect_delta_offset(rect_t *rect, byte oldx, byte newx, byte oldy, byte newy, byte size_only); 27 | 28 | #endif /* _RECT_H */ 29 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/Makefile: -------------------------------------------------------------------------------- 1 | OBJS = crt0.rel z80-stub.rel fusesend115k.rel fuserecv115k.rel serial.rel 2 | 3 | CC = sdcc 4 | LD = sdcc 5 | AS = sdasz80 6 | 7 | CFLAGS = --no-std-crt0 -mz80 --no-peep --stack-auto \ 8 | --disable-warning 85 \ 9 | --disable-warning 154 \ 10 | --disable-warning 196 11 | LDFLAGS = -mz80 --no-peep --no-std-crt0 --code-loc 0x007a --data-loc 0x5b00 --stack-auto 12 | ASFLAGS = -gols 13 | 14 | .PHONY: all clean 15 | 16 | all: sdbg 17 | 18 | sdbg: ${OBJS} 19 | sdcc ${LDFLAGS} ${OBJS} 20 | makebin 48.rom 21 | truncate --size 16384 48.rom 22 | 23 | 24 | %.rel: %.s 25 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 26 | 27 | %.rel: %.c 28 | $(CC) $(CFLAGS) -c $< 29 | 30 | clean: 31 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.o \ 32 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 33 | *.lk *.noi 34 | 35 | 36 | -------------------------------------------------------------------------------- /os/ram/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * event.c 3 | * events 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #include "yx.h" 8 | 9 | event_t *evt_first=NULL; 10 | 11 | /* 12 | * creates new event, adds to the list of events 13 | */ 14 | event_t *evt_create(void *owner) { 15 | event_t *e; 16 | if ( e = (event_t *)syslist_add((void **)&evt_first, sizeof(event_t), owner) ) 17 | e->state=nonsignaled; 18 | return e; 19 | } 20 | 21 | /* 22 | * destroys existing event, removes from the list of events 23 | */ 24 | event_t *evt_destroy(event_t *e) { 25 | return (event_t *)syslist_delete((void **)&evt_first, (void *)e); 26 | 27 | } 28 | 29 | /* 30 | * set event state 31 | */ 32 | event_t *evt_set(event_t *e, event_state_t newstate) { 33 | list_header_t *prev; 34 | if ( e = (event_t *)list_find((list_header_t *)evt_first, &prev, list_match_eq, (word)e) ) 35 | e->state=newstate; 36 | return e; 37 | } 38 | -------------------------------------------------------------------------------- /buddy/graphics/mouse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mouse.c 3 | * rectangle type implementation 4 | * 5 | * tomaz stih mon oct 7 2013 6 | */ 7 | #include "types.h" 8 | #include "graphics.h" 9 | #include "mouse.h" 10 | 11 | void* current_cursor; 12 | mouse_info_t mi; 13 | rect_t mouse_rect; 14 | 15 | void calc_mouse_rect(mouse_info_t *mi) { 16 | mouse_rect.x0=mi->x; 17 | mouse_rect.y0=mi->y; 18 | if (SCREEN_MAXX-mi->xx+MOUSE_CURSOR_WIDTH; 19 | if (SCREEN_MAXY-mi->yy+MOUSE_CURSOR_HEIGHT; 20 | } 21 | 22 | void mouse_init() { 23 | /* calibrate */ 24 | mouse_calibrate(SCREEN_MAXX>>1,SCREEN_MAXY>>1); 25 | 26 | /* scan for the first time */ 27 | mouse_scan(&mi); 28 | 29 | /* remember coords */ 30 | calc_mouse_rect(&mi); 31 | 32 | 33 | /* current cursor */ 34 | current_cursor=&cur_std; 35 | } 36 | -------------------------------------------------------------------------------- /os/rom/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * types.h 3 | * common types used in code (do not include stdint.h!) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #ifndef _TYPES_H 8 | #define _TYPES_H 9 | 10 | #define NULL ( (word)0 ) 11 | #define TRUE ( (byte)1 ) 12 | #define FALSE ( (byte)0 ) 13 | 14 | /* signed */ 15 | typedef signed char int8_t; 16 | typedef short int int16_t; 17 | typedef long int int32_t; 18 | 19 | /* unsigned */ 20 | typedef unsigned char uint8_t; 21 | typedef unsigned short int uint16_t; 22 | typedef unsigned long int uint32_t; 23 | 24 | /* usual */ 25 | typedef uint8_t boolean; 26 | typedef uint8_t byte; 27 | typedef uint16_t word; 28 | typedef uint8_t* string; 29 | typedef uint8_t result; 30 | typedef uint16_t handle; 31 | 32 | /* general purpose macros */ 33 | #define MAX(a,b) ( (a>b?a:b) ) 34 | #define MIN(a,b) ( (ab?a:b) ) 34 | #define MIN(a,b) ( (astate=nonsignaled; 21 | return e; 22 | } 23 | 24 | /* 25 | * destroys existing event, removes from the list of events 26 | */ 27 | event_t *evt_destroy(event_t *e) { 28 | return (event_t *)syslist_delete((void **)&evt_first, (void *)e); 29 | } 30 | 31 | /* 32 | * set event state 33 | */ 34 | event_t *evt_set(event_t *e, event_state_t newstate) { 35 | list_header_t *prev; 36 | if ( e = (event_t *)list_find((list_header_t *)evt_first, &prev, list_match_eq, (word)e) ) 37 | e->state=newstate; 38 | return e; 39 | } 40 | -------------------------------------------------------------------------------- /os/rom/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * list.h 3 | * linked list 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #ifndef _LIST_H 8 | #define _LIST_H 9 | 10 | #include "types.h" 11 | 12 | /* each linked list must start with list_header */ 13 | typedef struct list_header_s { 14 | void *next; 15 | void* owner; 16 | } list_header_t; 17 | 18 | /* match functions */ 19 | extern byte list_match_eq(list_header_t *p, word arg); 20 | 21 | /* functions */ 22 | extern list_header_t *list_find( 23 | list_header_t *first, 24 | list_header_t **prev, 25 | byte (*match)(list_header_t *p, word arg), 26 | word the_arg); 27 | 28 | /* core functions */ 29 | extern list_header_t *list_insert(list_header_t** first, list_header_t *el); 30 | extern list_header_t *list_append(list_header_t** first, list_header_t *el); 31 | extern list_header_t *list_remove(list_header_t **first, list_header_t *el); 32 | extern list_header_t *list_remove_first(list_header_t **first); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /buddy/os/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * list.h 3 | * linked list 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #ifndef _LIST_H 8 | #define _LIST_H 9 | 10 | #include "types.h" 11 | 12 | /* each linked list must start with list_header */ 13 | typedef struct list_header_s { 14 | void *next; 15 | void* owner; 16 | } list_header_t; 17 | 18 | /* match functions */ 19 | extern byte list_match_eq(list_header_t *p, word arg); 20 | 21 | /* functions */ 22 | extern list_header_t *list_find( 23 | list_header_t *first, 24 | list_header_t **prev, 25 | byte (*match)(list_header_t *p, word arg), 26 | word the_arg); 27 | 28 | /* core functions */ 29 | extern list_header_t *list_insert(list_header_t** first, list_header_t *el); 30 | extern list_header_t *list_append(list_header_t** first, list_header_t *el); 31 | extern list_header_t *list_remove(list_header_t **first, list_header_t *el); 32 | extern list_header_t *list_remove_first(list_header_t **first); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /os/ram/system.c: -------------------------------------------------------------------------------- 1 | /* 2 | * system.c 3 | * system specifics 4 | * 5 | * tomaz stih wed apr 3 2013 6 | */ 7 | #include "yx.h" 8 | 9 | /* 10 | * system heap 11 | */ 12 | word get_sysheap() __naked { 13 | __asm 14 | ld hl,#sysheap 15 | ret 16 | __endasm; 17 | } 18 | 19 | /* 20 | * user heap 21 | */ 22 | word get_usrheap() __naked { 23 | __asm 24 | ld hl,#0x8000 25 | ret 26 | __endasm; 27 | } 28 | 29 | /* 30 | * adding to system list 31 | */ 32 | void *syslist_add(void **first, word size, void *owner) { 33 | list_header_t *p; 34 | if( p = (list_header_t *)mem_allocate(get_sysheap(), size, owner) ) { 35 | list_insert((list_header_t**)first,p); 36 | p->owner=owner; 37 | } 38 | return (void *)p; 39 | } 40 | 41 | /* 42 | * removing from system list 43 | */ 44 | void *syslist_delete(void **first, void *e) { 45 | if ( e = list_remove( (list_header_t **)first, (list_header_t *)e) ) { 46 | e = mem_free(get_sysheap(), e); 47 | } 48 | return e; 49 | } 50 | -------------------------------------------------------------------------------- /buddy/include/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * types.h 3 | * common types used in code (do not include stdint.h!) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #ifndef _TYPES_H 8 | #define _TYPES_H 9 | 10 | #define NULL ( (word)0 ) 11 | #define TRUE ( (byte)1 ) 12 | #define FALSE ( (byte)0 ) 13 | 14 | /* signed */ 15 | typedef signed char int8_t; 16 | typedef short int int16_t; 17 | typedef long int int32_t; 18 | 19 | /* unsigned */ 20 | typedef unsigned char uint8_t; 21 | typedef unsigned short int uint16_t; 22 | typedef unsigned long int uint32_t; 23 | 24 | /* usual */ 25 | typedef uint8_t boolean; 26 | typedef uint8_t byte; 27 | typedef int8_t sbyte; 28 | typedef uint16_t word; 29 | typedef int16_t sword; 30 | typedef uint8_t* string; 31 | typedef uint8_t result; 32 | typedef uint16_t handle; 33 | 34 | /* general purpose macros */ 35 | #define MAX(a,b) ( (a>b?a:b) ) 36 | #define MIN(a,b) ( (abuffer=buffer; 21 | q->size=size + 1; 22 | q->head=q->tail=0; 23 | q->flags=flags; 24 | } 25 | 26 | byte que_put(queue_t *q, byte el) { 27 | q->buffer[q->tail] = el; 28 | q->tail=increase_pos(q->tail,q->size); 29 | if (q->head == q->tail) { 30 | q->head=increase_pos(q->head,q->size); 31 | return -1; /* overflow */ 32 | } else 33 | return 0; 34 | } 35 | 36 | byte que_get(queue_t *q, byte *el) { 37 | if (q->head != q->tail) { 38 | (*el) = q->buffer[q->head]; 39 | q->head=increase_pos(q->head,q->size); 40 | return 0; 41 | } else 42 | return -1; /* empty queue */ 43 | } 44 | -------------------------------------------------------------------------------- /os/rom/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * memory.h 3 | * memory management (mem_allocate, mem_free) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #ifndef _MEMORY_H 8 | #define _MEMORY_H 9 | 10 | #include "types.h" 11 | #include "list.h" 12 | 13 | #ifndef NONE 14 | #define NONE 0 15 | #endif 16 | 17 | #ifndef SYS 18 | #define SYS 0 19 | #endif 20 | 21 | #define BLK_SIZE (sizeof(struct block_s) - sizeof(byte[1])) 22 | #define MIN_CHUNK_SIZE 4 23 | 24 | /* block status, use as bit operations */ 25 | #define NEW 0x00 26 | #define ALLOCATED 0x01 27 | 28 | typedef struct block_s { 29 | list_header_t hdr; 30 | byte stat; 31 | word size; 32 | byte data[1]; 33 | } block_t; 34 | 35 | extern void *heap; 36 | 37 | extern void mem_init(void *heap, word size); 38 | extern void *mem_allocate(void *heap, word size, void *owner); 39 | extern void *mem_free(void *heap, void *p); 40 | extern void mem_copy(byte *src, byte *dest, word count) __naked; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /buddy/os/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | GNUC = gcc 3 | GNUCFLAGS = -I$(INCLUDE) 4 | CC = sdcc 5 | CFLAGS = -mz80 -I$(INCLUDE) 6 | AS = sdasz80 7 | AR = sdar 8 | ARFLAGS = -rc 9 | ASFLAGS = -xlos -g 10 | LD = sdcc 11 | LDFLAGS = -mz80 12 | 13 | # Deps. 14 | CSRCS = $(wildcard *.c) 15 | SSRCS = $(wildcard *.s) 16 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 17 | 18 | # Rules. 19 | .PHONY: all clean 20 | 21 | all: depend os.lib 22 | 23 | depend: $(CSRCS) 24 | rm --force .depend 25 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 26 | sed -i 's/\.o/\.rel/g' .depend 27 | 28 | -include .depend 29 | 30 | os.lib: $(OBJS) 31 | $(AR) $(ARFLAGS) $(OUTDIR)$@ $^ 32 | 33 | %.rel: %.s 34 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 35 | 36 | %.rel: %.c 37 | $(CC) -c -o $@ $< $(CFLAGS) 38 | 39 | clean: 40 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 41 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 42 | *.noi *.lk *.tap a.out 43 | rm -f $(OUTDIR)os.lib 44 | rm -f .depend 45 | -------------------------------------------------------------------------------- /os/rom/task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * task.h 3 | * task management 4 | * 5 | * tomaz stih sat may 26 2012 6 | */ 7 | #ifndef _TASK_H 8 | #define _TASK_H 9 | 10 | #include "types.h" 11 | #include "list.h" 12 | #include "event.h" 13 | 14 | #define TASK_STATE_RUNNING 0 15 | #define TASK_STATE_WAITING 1 16 | 17 | #define CONTEXT_SIZE 22 18 | 19 | typedef struct task_s { 20 | /* list_header_t compatible header */ 21 | list_header_t hdr; 22 | /* task properties */ 23 | word sp; /* stack pointer. task context is stored on stack. */ 24 | event_t **wait; /* event list or null */ 25 | byte num_events; /* number of events in event list */ 26 | byte state; /* task state (bits 0-1), bits 2-7 are reserved */ 27 | } task_t; 28 | 29 | extern task_t *tsk_current; 30 | extern task_t *tsk_first_running; 31 | extern task_t *tsk_first_waiting; 32 | 33 | extern task_t * tsk_create(void (*entry_point)(), word stack_size); 34 | extern void tsk_wait4events(event_t **events, byte num_events); 35 | extern void tsk_switch() __naked; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /buddy/graphics/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | GNUC = gcc 3 | GNUCFLAGS = -I$(INCLUDE) 4 | CC = sdcc 5 | CFLAGS = -mz80 -I$(INCLUDE) 6 | AS = sdasz80 7 | AR = sdar 8 | ARFLAGS = -rc 9 | ASFLAGS = -xlos -g 10 | LD = sdcc 11 | LDFLAGS = -mz80 12 | 13 | # Deps. 14 | CSRCS = $(wildcard *.c) 15 | SSRCS = $(wildcard *.s) 16 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 17 | 18 | # Rules. 19 | .PHONY: all clean 20 | 21 | all: depend graphics.lib 22 | 23 | depend: $(CSRCS) 24 | rm --force .depend 25 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 26 | sed -i 's/\.o/\.rel/g' .depend 27 | 28 | -include .depend 29 | 30 | graphics.lib: $(OBJS) 31 | $(AR) $(ARFLAGS) $(OUTDIR)$@ $^ 32 | 33 | %.rel: %.s 34 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 35 | 36 | %.rel: %.c 37 | $(CC) -c -o $@ $< $(CFLAGS) 38 | 39 | clean: 40 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 41 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 42 | *.noi *.lk *.tap a.out 43 | rm -f $(OUTDIR)graphics.lib 44 | rm -f .depend 45 | -------------------------------------------------------------------------------- /buddy/buddy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * buddy.h 3 | * main buddy loop, mostly event harvesting 4 | * and message dispatching. 5 | * 6 | * tomaz stih sun jul 2 2015 7 | */ 8 | #ifndef _BUDDY_H 9 | #define _BUDDY_H 10 | 11 | #include "types.h" 12 | #include "window.h" 13 | 14 | /* 15 | * operation in progress (multiple mouse events comms) 16 | */ 17 | #define BUDDY_OP_NONE 0 18 | #define BUDDY_OP_MOVE 1 19 | #define BUDDY_OP_MOVING 2 20 | #define BUDDY_OP_SIZE 3 21 | #define BUDDY_OP_SIZING 4 22 | typedef struct buddy_op_s buddy_op_t; 23 | struct buddy_op_s { 24 | boolean op; /* op code */ 25 | rect_t rect; /* affected */ 26 | window_t *wnd; /* affected wnd */ 27 | byte mx; /* for generic op */ 28 | byte my; /* for generic op */ 29 | byte ix; /* initial x */ 30 | byte iy; /* initial y */ 31 | }; 32 | 33 | extern buddy_op_t buddy_op; 34 | 35 | extern void buddy_init(); 36 | extern void buddy_harvest_events(); 37 | extern void buddy_dispatch(byte id, word param1, word param2); 38 | extern void buddy_xor_op_rect(); 39 | 40 | #endif /* _BUDDY_H */ 41 | -------------------------------------------------------------------------------- /os/ram/driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * driver.h 3 | * device drivers 4 | * 5 | * tomaz stih sun may 12 2013 6 | */ 7 | #ifndef _DRIVER_H 8 | #define _DRIVER_H 9 | 10 | typedef struct driver_s { 11 | list_header_t hdr; 12 | handle_t *(*open)(struct driver_s *d, byte *hint, word attr); 13 | void (*close)(handle_t *h); 14 | byte (*read_async)(handle_t *handle, byte *buffer, word count, event_t *done); 15 | byte (*write_async)(handle_t *handle, byte *buffer, word count, event_t *done); 16 | byte (*ioctl)(handle_t *handle, byte fn, word data); 17 | void (*timer_hook)(); 18 | } driver_t; 19 | 20 | extern driver_t *drv_first; 21 | 22 | extern driver_t *drv_register( 23 | string name, 24 | handle_t *(*open)(struct driver_s *d, byte *hint, word attr), 25 | void (*close)(handle_t *h), 26 | byte (*read_async)(handle_t *handle, byte *buffer, word count, event_t *done), 27 | byte (*write_async)(handle_t *handle, byte *buffer, word count, event_t *done), 28 | byte (*ioctl)(handle_t *handle, byte fn, word data), 29 | void (*timer_hook)() 30 | ); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /os/ram/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.c 3 | * timer management 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #include "yx.h" 8 | 9 | timer_t *tmr_first=NULL; 10 | 11 | /* 12 | * install timer hook 13 | */ 14 | timer_t *tmr_install(void (*hook)(), word ticks, void *owner) { 15 | 16 | timer_t *t; 17 | 18 | if ( t = (timer_t *)syslist_add((void **)&tmr_first, sizeof(timer_t), owner) ) { 19 | t->hook=hook; 20 | t->_tick_count=t->ticks=ticks; 21 | } 22 | 23 | return t; 24 | } 25 | 26 | /* 27 | * remove timer hook 28 | */ 29 | timer_t *tmr_uninstall(timer_t *t) { 30 | return (timer_t *)syslist_delete((void **)&tmr_first, (void *)t); 31 | } 32 | 33 | /* 34 | * chain timers 35 | * note: this is done inside 50 hz interrupt 36 | * so no di/ei calls are needed. 37 | */ 38 | void tmr_chain() { 39 | timer_t *t=tmr_first; 40 | while(t) { 41 | if (t->_tick_count==0) { /* trig it */ 42 | t->_tick_count=t->ticks; 43 | t->hook(); 44 | } else t->_tick_count--; 45 | t=t->hdr.next; 46 | } 47 | last_error=RESULT_SUCCESS; 48 | } 49 | -------------------------------------------------------------------------------- /os/rom/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.c 3 | * timer management 4 | * 5 | * tomaz stih tue may 29 2012 6 | */ 7 | #include "types.h" 8 | #include "syslist.h" 9 | #include "timer.h" 10 | 11 | timer_t *tmr_first=NULL; 12 | 13 | /* 14 | * install timer hook 15 | */ 16 | timer_t *tmr_install(void (*hook)(), word ticks, void *owner) { 17 | timer_t *t; 18 | 19 | if ( t = (timer_t *)syslist_add((void **)&tmr_first, sizeof(timer_t), owner) ) { 20 | t->hook=hook; 21 | t->_tick_count=t->ticks=ticks; 22 | } 23 | 24 | return t; 25 | } 26 | 27 | /* 28 | * remove timer hook 29 | */ 30 | timer_t *tmr_uninstall(timer_t *t) { 31 | return (timer_t *)syslist_delete((void **)&tmr_first, (void *)t); 32 | } 33 | 34 | /* 35 | * chain timers 36 | * note: this is done inside 50 hz interrupt 37 | * so no di/ei calls are needed. 38 | */ 39 | void tmr_chain() { 40 | timer_t *t=tmr_first; 41 | while(t) { 42 | if (t->_tick_count==0) { /* trig it */ 43 | t->_tick_count=t->ticks; 44 | t->hook(); 45 | } else t->_tick_count--; 46 | t=t->hdr.next; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /os/ram/todo/crc16.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /* 4 | // 16 12 5 5 | // this is the CCITT CRC 16 polynomial X + X + X + 1. 6 | // This works out to be 0x1021, but the way the algorithm works 7 | // lets us use 0x8408 (the reverse of the bit pattern). The high 8 | // bit is always assumed to be set, thus we only use 16 bits to 9 | // represent the 17 bit value. 10 | */ 11 | word crc16(byte *data_p, word length) 12 | { 13 | byte i; 14 | word data; 15 | word crc = 0xffff; 16 | 17 | if (length == 0) 18 | return (~crc); 19 | 20 | do 21 | { 22 | for (i=0, data=(word)0xff & *data_p++; 23 | i < 8; 24 | i++, data >>= 1) 25 | { 26 | if ((crc & 0x0001) ^ (data & 0x0001)) 27 | crc = (crc >> 1) ^ POLY; 28 | else crc >>= 1; 29 | } 30 | } while (--length); 31 | 32 | crc = ~crc; 33 | data = crc; 34 | crc = (crc << 8) | (data >> 8 & 0xff); 35 | 36 | return (crc); 37 | } 38 | -------------------------------------------------------------------------------- /buddy/include/mouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mouse.h 3 | * mouse routines header 4 | * 5 | * tomaz stih sat aug 1 2015 6 | */ 7 | #ifndef _MOUSE_H 8 | #define _MOUSE_H 9 | 10 | #include "types.h" 11 | 12 | #define MOUSE_RBUTTON 0x01 /* bit 0 */ 13 | #define MOUSE_LBUTTON 0x02 /* bit 1 */ 14 | #define MOUSE_MBUTTON 0x04 /* bit 2 */ 15 | 16 | #define MOUSE_CURSOR_WIDTH 8 17 | #define MOUSE_CURSOR_HEIGHT 10 18 | 19 | /* mouse info */ 20 | typedef struct mouse_info_s mouse_info_t; 21 | struct mouse_info_s { 22 | byte x; 23 | byte y; 24 | byte button; 25 | byte button_change; 26 | }; 27 | 28 | extern void mouse_init(); 29 | extern void mouse_calibrate(byte x, byte y); 30 | extern void mouse_scan(mouse_info_t *mi); 31 | extern void calc_mouse_rect(mouse_info_t *mi); 32 | extern void mouse_show_cursor(byte x, byte y, void *cursor); 33 | extern void mouse_hide_cursor(); 34 | 35 | /* mouse cursors */ 36 | extern void* current_cursor; 37 | extern void* cur_classic; 38 | extern void* cur_std; 39 | extern void* cur_hand; 40 | extern void* cur_hourglass; 41 | extern void* cur_caret; 42 | 43 | /* mouse global vars */ 44 | extern mouse_info_t mi; 45 | extern rect_t mouse_rect; 46 | 47 | #endif /* _MOUSE_H */ 48 | -------------------------------------------------------------------------------- /os/rom/video.s: -------------------------------------------------------------------------------- 1 | ;; video.s 2 | ;; video memory manipulation routines 3 | ;; 4 | ;; tomaz stih, sun may 20 2012 5 | .module video 6 | 7 | .globl vid_rowaddr 8 | .globl vid_nextrow 9 | 10 | .area _CODE 11 | 12 | 13 | ;; given y (0...191) calc. row addr. in vmem 14 | ;; input: b=y 15 | ;; output: hl=vmem address, a=l 16 | ;; affects: flags, a, hl 17 | vid_rowaddr:: 18 | ld a,b ; get y0-y2 to acc. 19 | and #0x07 ; mask out 00000111 20 | or #0x40 ; vmem addr 21 | ld h,a ; to h 22 | ld a,b ; y to acc. again 23 | rrca 24 | rrca 25 | rrca 26 | and #0x18 ; y6,y7 to correct pos. 27 | or h ; h or a 28 | ld h,a ; store to h 29 | ld a,b ; y back to a 30 | rla ; move y3-y5 to position 31 | rla 32 | and #0xe0 ; mask out 11100000 33 | ld l,a ; to l 34 | ret 35 | 36 | 37 | ;; given hl get next row address in vmem 38 | ;; input: hl=address 39 | ;; output: hl=next row address 40 | ;; affects: flags, a, hl 41 | vid_nextrow:: 42 | inc h 43 | ld a,h 44 | and #7 45 | jr nz,nextrow_done 46 | ld a,l 47 | add a,#32 48 | ld l,a 49 | jr c, nextrow_done 50 | ld a,h 51 | sub #8 52 | ld h,a 53 | nextrow_done: 54 | ret 55 | -------------------------------------------------------------------------------- /apps/template/video.s: -------------------------------------------------------------------------------- 1 | ;; video.s 2 | ;; video memory manipulation routines 3 | ;; 4 | ;; tomaz stih, sun may 20 2012 5 | .module video 6 | 7 | .globl vid_rowaddr 8 | .globl vid_nextrow 9 | 10 | .area _CODE 11 | 12 | 13 | ;; given y (0...191) calc. row addr. in vmem 14 | ;; input: b=y 15 | ;; output: hl=vmem address, a=l 16 | ;; affects: flags, a, hl 17 | vid_rowaddr:: 18 | ld a,b ; get y0-y2 to acc. 19 | and #0x07 ; mask out 00000111 20 | or #0x40 ; vmem addr 21 | ld h,a ; to h 22 | ld a,b ; y to acc. again 23 | rrca 24 | rrca 25 | rrca 26 | and #0x18 ; y6,y7 to correct pos. 27 | or h ; h or a 28 | ld h,a ; store to h 29 | ld a,b ; y back to a 30 | rla ; move y3-y5 to position 31 | rla 32 | and #0xe0 ; mask out 11100000 33 | ld l,a ; to l 34 | ret 35 | 36 | 37 | ;; given hl get next row address in vmem 38 | ;; input: hl=address 39 | ;; output: hl=next row address 40 | ;; affects: flags, a, hl 41 | vid_nextrow:: 42 | inc h 43 | ld a,h 44 | and #7 45 | jr nz,nextrow_done 46 | ld a,l 47 | add a,#32 48 | ld l,a 49 | jr c, nextrow_done 50 | ld a,h 51 | sub #8 52 | ld h,a 53 | nextrow_done: 54 | ret 55 | -------------------------------------------------------------------------------- /buddy/graphics/video.s: -------------------------------------------------------------------------------- 1 | ;; video.s 2 | ;; video memory manipulation routines 3 | ;; 4 | ;; tomaz stih, sun may 20 2012 5 | .module video 6 | 7 | .globl vid_rowaddr 8 | .globl vid_nextrow 9 | 10 | .area _CODE 11 | 12 | 13 | ;; given y (0...191) calc. row addr. in vmem 14 | ;; input: b=y 15 | ;; output: hl=vmem address, a=l 16 | ;; affects: flags, a, hl 17 | vid_rowaddr:: 18 | ld a,b ; get y0-y2 to acc. 19 | and #0x07 ; mask out 00000111 20 | or #0x40 ; vmem addr 21 | ld h,a ; to h 22 | ld a,b ; y to acc. again 23 | rrca 24 | rrca 25 | rrca 26 | and #0x18 ; y6,y7 to correct pos. 27 | or h ; h or a 28 | ld h,a ; store to h 29 | ld a,b ; y back to a 30 | rla ; move y3-y5 to position 31 | rla 32 | and #0xe0 ; mask out 11100000 33 | ld l,a ; to l 34 | ret 35 | 36 | 37 | ;; given hl get next row address in vmem 38 | ;; input: hl=address 39 | ;; output: hl=next row address 40 | ;; affects: flags, a, hl 41 | vid_nextrow:: 42 | inc h 43 | ld a,h 44 | and #7 45 | jr nz,nextrow_done 46 | ld a,l 47 | add a,#32 48 | ld l,a 49 | jr c, nextrow_done 50 | ld a,h 51 | sub #8 52 | ld h,a 53 | nextrow_done: 54 | ret 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /os/ram/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | GNUC = gcc 3 | GNUCFLAGS = -I. 4 | CC = sdcc 5 | CFLAGS = -mz80 --no-std-crt0 -D DEBUG 6 | AS = sdasz80 7 | ASFLAGS = -xlos -g 8 | LD = sdcc 9 | LDFLAGS = -mz80 --no-std-crt0 --code-loc 0xc01f \ 10 | --data-loc 0x5b00 -Wl -b_HEADER=0xbfff -Wl -b_IM2=0xfff0 11 | # Deps. 12 | CSRCS = $(wildcard *.c) 13 | SSRCS = $(wildcard *.s) 14 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 15 | 16 | # Rules. 17 | .PHONY: all clean 18 | 19 | all: depend yx.bin 20 | 21 | depend: $(CSRCS) 22 | rm --force .depend 23 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 24 | 25 | -include .depend 26 | 27 | yx.bin: crt0.rel $(OBJS) 28 | $(LD) $(LDFLAGS) $^ 29 | makezxbin yx.bin 30 | appmake +zx --binfile ./yx.bin --org 49151 31 | fuse-gtk --tape ./yx.tap \ 32 | --interface1 --interface2 \ 33 | --kempston --kempston-mouse \ 34 | --machine 48 --graphics-filter hq2x \ 35 | #--debugger-command "br 0xD25B" 36 | 37 | %.rel: %.s 38 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 39 | 40 | %.rel: %.c 41 | $(CC) -c -o $@ $< $(CFLAGS) 42 | 43 | clean: 44 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 45 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 46 | *.noi *.lk *.tap a.out 47 | -------------------------------------------------------------------------------- /apps/kbd/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | GNUC = gcc 3 | GNUCFLAGS = -I. 4 | CC = sdcc 5 | CFLAGS = -mz80 --no-std-crt0 -D DEBUG 6 | AS = sdasz80 7 | ASFLAGS = -xlos -g 8 | LD = sdcc 9 | LDFLAGS = -mz80 --no-std-crt0 \ 10 | --nostdlib --code-loc 0x8032 \ 11 | --data-loc 0x8200 -Wl -b_HEADER=0x8000 12 | # Deps. 13 | CSRCS = $(wildcard *.c) 14 | SSRCS = $(wildcard *.s) 15 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 16 | 17 | # Rules. 18 | .PHONY: all clean 19 | 20 | all: depend app.bin 21 | 22 | depend: $(CSRCS) 23 | rm --force .depend 24 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 25 | 26 | -include .depend 27 | 28 | app.bin: crt0.rel $(OBJS) 29 | $(LD) $(LDFLAGS) $^ 30 | makezxbin app.bin 31 | appmake +zx --binfile ./app.bin --org 32768 32 | fuse-gtk --tape ./app.tap \ 33 | --interface1 --interface2 \ 34 | --kempston --kempston-mouse \ 35 | --machine 48 --graphics-filter 2x \ 36 | --debugger-command "br 0x80A5" 37 | 38 | %.rel: %.s 39 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 40 | 41 | %.rel: %.c 42 | $(CC) -c -o $@ $< $(CFLAGS) 43 | 44 | clean: 45 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 46 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 47 | *.noi *.lk *.tap a.out 48 | -------------------------------------------------------------------------------- /apps/fonts/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | GNUC = gcc 3 | GNUCFLAGS = -I. 4 | CC = sdcc 5 | CFLAGS = -mz80 --no-std-crt0 -D DEBUG 6 | AS = sdasz80 7 | ASFLAGS = -xlos -g 8 | LD = sdcc 9 | LDFLAGS = -mz80 --no-std-crt0 \ 10 | --nostdlib --code-loc 0x8032 \ 11 | --data-loc 0x8200 -Wl -b_HEADER=0x8000 12 | # Deps. 13 | CSRCS = $(wildcard *.c) 14 | SSRCS = $(wildcard *.s) 15 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 16 | 17 | # Rules. 18 | .PHONY: all clean 19 | 20 | all: depend app.bin 21 | 22 | depend: $(CSRCS) 23 | rm --force .depend 24 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 25 | 26 | -include .depend 27 | 28 | app.bin: crt0.rel $(OBJS) 29 | $(LD) $(LDFLAGS) $^ 30 | makezxbin app.bin 31 | appmake +zx --binfile ./app.bin --org 32768 32 | fuse-gtk --tape ./app.tap \ 33 | --interface1 --interface2 \ 34 | --kempston --kempston-mouse \ 35 | --machine 48 --graphics-filter hq2x \ 36 | # --debugger-command "br 0x8000" 37 | 38 | %.rel: %.s 39 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 40 | 41 | %.rel: %.c 42 | $(CC) -c -o $@ $< $(CFLAGS) 43 | 44 | clean: 45 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 46 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 47 | *.noi *.lk *.tap a.out 48 | -------------------------------------------------------------------------------- /os/rom/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | DIR = $(shell pwd) 3 | GNUC = gcc 4 | GNUCFLAGS = -I$(DIR)/include/ 5 | CC = sdcc 6 | CFLAGS = -mz80 --no-std-crt0 -D DEBUG -I$(DIR)/include/ --reserve-regs-iy 7 | AS = sdasz80 8 | ASFLAGS = -xlos -g 9 | LD = sdcc 10 | LDFLAGS = -mz80 --no-std-crt0 \ 11 | --code-loc 0x0092 \ 12 | --data-loc 0x5b00 13 | # Deps. 14 | CSRCS = $(wildcard *.c) 15 | SSRCS = $(wildcard *.s) 16 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 17 | 18 | # Rules. 19 | .PHONY: all clean 20 | 21 | all: depend 48.rom 22 | 23 | depend: $(CSRCS) 24 | rm --force .depend 25 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 26 | sed -i 's/\.o/\.rel/g' .depend 27 | 28 | -include .depend 29 | 30 | 48.rom: crt0.rel $(OBJS) 31 | $(LD) $(LDFLAGS) $^ 32 | makebin 48.rom 33 | truncate --size=16384 48.rom 34 | fuse-gtk --rom-48 48.rom \ 35 | --interface1 \ 36 | --machine 48 \ 37 | --graphics-filter 2x \ 38 | --no-sound \ 39 | --debugger-command "br 0xffff" 40 | 41 | %.rel: %.s 42 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 43 | 44 | %.rel: %.c 45 | $(CC) -c -o $@ $< $(CFLAGS) 46 | 47 | clean: 48 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 49 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 50 | *.noi *.lk *.tap a.out 51 | rm -f .depend 52 | -------------------------------------------------------------------------------- /os/ram/todo/dl_prot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dl_prot.c 3 | * data link protocol implementation 4 | * 5 | * tomaz stih thu jul 26 2012 6 | */ 7 | #include "dl_prot.h" 8 | 9 | /* current sequence numbers starting with 1 (0...no sequence received yet) */ 10 | byte zx_sequence=0; 11 | byte pc_sequence=0; 12 | 13 | void communicate() { 14 | 15 | 16 | 17 | } 18 | 19 | word crc16(byte *buffer, word length) __naked { 20 | 21 | __asm 22 | 23 | /* 24 | * from - http://wikiti.brandonw.net/index.php?title=Z80_Routines:Security:CRC16 25 | */ 26 | ld iy,#0x0000 27 | add iy,sp /* iy = sp */ 28 | 29 | ld e,2(iy) /* de = buffer address */ 30 | ld d,3(iy) 31 | 32 | ld c,4(iy) /* bc = byte count */ 33 | ld b,5(iy) 34 | 35 | crc16_raw:: 36 | ld hl,#0xFFFF 37 | push bc 38 | 39 | crc16_read: 40 | ld a,(de) 41 | inc de 42 | xor h 43 | ld h,a 44 | ld b,#8 45 | crc16_crcbyte: 46 | add hl,hl 47 | jr nc,crc16_next 48 | ld a,h 49 | xor #0x10 50 | ld h,a 51 | ld a,l 52 | xor #0x21 53 | ld l,a 54 | crc16_next: 55 | djnz crc16_crcbyte 56 | 57 | pop bc 58 | dec bc 59 | push bc 60 | ld a,b 61 | or c 62 | jr nz,crc16_read 63 | 64 | pop bc 65 | ret /* hl holds calculated crc16 */ 66 | 67 | __endasm; 68 | 69 | } 70 | 71 | #endif -------------------------------------------------------------------------------- /os/ram/driver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * driver.c 3 | * device drivers 4 | * 5 | * tomaz stih sun may 12 2013 6 | */ 7 | #include "yx.h" 8 | 9 | driver_t *drv_first=NULL; 10 | 11 | /* 12 | * register a driver 13 | */ 14 | driver_t *drv_register( 15 | string name, 16 | handle_t *(*open)(struct driver_s *d, byte *hint, word attr), 17 | void (*close)(handle_t *h), 18 | byte (*read_async)(handle_t *handle, byte *buffer, word count, event_t *done), 19 | byte (*write_async)(handle_t *handle, byte *buffer, word count, event_t *done), 20 | byte (*ioctl)(handle_t *handle, byte fn, word data), 21 | void (*timer_hook)() 22 | ) { 23 | name_t *n; 24 | driver_t *d; 25 | timer_t *t; 26 | 27 | if ( d = (driver_t *)syslist_add((void **)&drv_first, sizeof(driver_t), SYS) ) { 28 | d->open=open; 29 | d->close=close; 30 | d->read_async=read_async; 31 | d->write_async=write_async; 32 | d->ioctl=ioctl; 33 | /* install timer */ 34 | if (timer_hook) { 35 | if (!(t=tmr_install(timer_hook,EVERYTIME,SYS))) { 36 | /* failed */ 37 | syslist_delete((void **)&drv_first, (void *)d); 38 | return NULL; 39 | } 40 | } 41 | /* link driver name if linking requested */ 42 | if (!name_link(SYS, name, d)) { 43 | syslist_delete((void **)&drv_first, (void *)d); 44 | tmr_uninstall(t); 45 | return NULL; 46 | } 47 | } 48 | return d; 49 | } 50 | -------------------------------------------------------------------------------- /os/rom/shell.c: -------------------------------------------------------------------------------- 1 | /* 2 | * shell.c 3 | * micro shell 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #include "types.h" 8 | #include "kbd.h" 9 | #include "console.h" 10 | 11 | char shell_get_char() { 12 | static byte *map=(byte *)&kbd_map; /* current map */ 13 | byte key; 14 | char ch; 15 | 16 | if (key=kbd_read()) { 17 | ch=map[key&0b00111111]; /* get char */ 18 | if (key&KEY_DOWN_BIT) { /* key down */ 19 | switch(ch) { 20 | case 0x01: /* symbol */ 21 | map=(byte *)&kbd_map_symbol; 22 | break; 23 | case 0x02: /* caps */ 24 | map=(byte *)&kbd_map_shift; 25 | break; 26 | } 27 | return 0; /* no key down shall be propagated */ 28 | } else { /* key up */ 29 | switch(ch) { 30 | case 0x01: /* symbol */ 31 | case 0x02: /* caps */ 32 | map=(byte *)&kbd_map; 33 | return 0; 34 | default: 35 | return ch; 36 | } 37 | } 38 | } else return 0; /* no keys */ 39 | } 40 | 41 | void shell() { 42 | 43 | char ch[]=" "; 44 | 45 | con_clrscr(); 46 | con_puts("YX OS 1.0 FOR SINCLAIR ZX SPECTRUM 48K\nREADY?\n"); 47 | while(TRUE) { 48 | if (ch[0]=shell_get_char()) { /* there are keys in the buffer */ 49 | switch(ch[0]) { 50 | case 0x08: 51 | con_back(); 52 | break; 53 | case 0x0d: 54 | ch[0]='\n'; 55 | con_puts(ch); 56 | break; 57 | default: 58 | con_puts(ch); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /apps/template/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | DIR = $(shell pwd) 3 | GNUC = gcc 4 | GNUCFLAGS = -I$(DIR)/include/ 5 | CC = sdcc 6 | CFLAGS = -mz80 --no-std-crt0 -D DEBUG -I$(DIR)/include/ 7 | AS = sdasz80 8 | ASFLAGS = -xlos -g 9 | LD = sdcc 10 | LDFLAGS = -mz80 --no-std-crt0 \ 11 | --nostdlib --code-loc 0x8032 \ 12 | --data-loc 0xb000 -Wl -b_HEADER=0x8000 13 | # Deps. 14 | CSRCS = $(wildcard *.c) 15 | SSRCS = $(wildcard *.s) 16 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 17 | 18 | # Rules. 19 | .PHONY: all clean 20 | 21 | all: depend app.bin 22 | 23 | depend: $(CSRCS) 24 | rm --force .depend 25 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 26 | sed -i 's/\.o/\.rel/g' .depend 27 | 28 | -include .depend 29 | 30 | app.bin: crt0.rel $(OBJS) 31 | $(LD) $(LDFLAGS) $^ 32 | makezxbin app.bin 33 | appmake +zx --binfile ./app.bin --org 32768 34 | fuse-gtk --tape ./app.tap \ 35 | --interface1 \ 36 | --kempston-mouse \ 37 | --machine 48 --graphics-filter 2x \ 38 | --no-sound \ 39 | --debugger-command "br 0xffff" 40 | 41 | %.rel: %.s 42 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 43 | 44 | %.rel: %.c 45 | $(CC) -c -o $@ $< $(CFLAGS) 46 | 47 | clean: 48 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 49 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 50 | *.noi *.lk *.tap a.out 51 | rm -f .depend 52 | -------------------------------------------------------------------------------- /os/ram/todo/rect.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rect.c 3 | * rectangle object 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #include "test.h" 8 | 9 | boolean rct_intersect(rect_t *r1, rect_t *r2) __naked { 10 | __asm 11 | /* sp to iy */ 12 | ld iy,#0x0000 13 | add iy,sp 14 | 15 | /* r1 to hl, r2 to de */ 16 | ld l,2(iy) 17 | ld h,3(iy) 18 | ld e,4(iy) 19 | ld d,5(iy) 20 | 21 | /* 22 | * rct_intersect_raw 23 | * do r1 and r2 intersect? 24 | * input 25 | * hl ... rect_t *r1 26 | * de ... rect_t *r2 27 | * output 28 | * l ... TRUE or FALSE 29 | * effects 30 | * af 31 | */ 32 | rct_intersect_raw:: 33 | push ix 34 | /* ix=hl, iy=de */ 35 | push hl 36 | push de 37 | pop iy 38 | pop ix 39 | /* do the comparision */ 40 | ld a,(ix) /* a=r1.x0 */ 41 | cp 2(iy) /* compare to r2.x1 */ 42 | jr nc, ri_false /* ? r1.x0 > r2.x1 */ 43 | ld a,2(ix) /* a=r1.x1 */ 44 | cp (iy) /* compare to r2.x0 */ 45 | jr c, ri_false /* ? r1.x1 < r2.x0 */ 46 | ld a,1(ix) /* a=r1.y0 */ 47 | cp 3(iy) /* compare to r2.y1 */ 48 | jr nc, ri_false /* ? r1.y0 > r2.y1 */ 49 | ld a,3(ix) /* a=r1.y1 */ 50 | cp 1(iy) /* compare to r2.y0 */ 51 | jr c,ri_false /* ? r1.y1 < r2.y0 */ 52 | 53 | /* rects intersect */ 54 | ld l,#TRUE 55 | jr ri_end 56 | 57 | ri_false: 58 | ld l,#FALSE 59 | ri_end: 60 | pop ix /* restore ix */ 61 | ret 62 | __endasm; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /os/ram/todo/font.c: -------------------------------------------------------------------------------- 1 | /* 2 | * font.c 3 | * fonts 4 | * 5 | * notes: metrics described at http://en.wikipedia.org/wiki/X-height 6 | * 7 | * tomaz stih mon jul 9 2012 8 | */ 9 | #include "test.h" 10 | 11 | void fnt_get_font_info( 12 | font_t *font, 13 | byte *bytes_per_glyph_line, 14 | byte *glyph_lines, 15 | byte *xmax, 16 | byte *descent, 17 | byte *xmin, 18 | word *first_glyph_addr, 19 | word *glyph_size_in_bytes) 20 | { 21 | 22 | /* 23 | * defaults for generation 0 24 | */ 25 | (*bytes_per_glyph_line) = 1; 26 | (*glyph_lines) = 8; 27 | (*xmax) = 0; 28 | (*descent) = 0; 29 | (*xmin) = 0; 30 | 31 | switch(font->font_generation) { 32 | case FGEN_2: 33 | (*xmin)=font->xmin; 34 | case FGEN_1: 35 | (*bytes_per_glyph_line)=font->bytes_per_glyph_line; 36 | (*glyph_lines)=font->glyph_lines; 37 | (*xmax)=font->xmax; 38 | (*descent)=font->descent; 39 | break; 40 | } 41 | 42 | (*first_glyph_addr) = ((word)font) + (font->font_generation); 43 | (*glyph_size_in_bytes) = ( (*glyph_lines) + 1 ) * (*bytes_per_glyph_line) + 1 ; 44 | 45 | } 46 | 47 | void fnt_measure_string(font_t *font, string string, byte *widths) 48 | { 49 | byte bpg, gl, xmax, descent, xmin; 50 | word addr0, glyph_size; 51 | 52 | /* 53 | * first get font info 54 | */ 55 | fnt_get_font_info(font, &bpg, &gl, &xmax, &descent, &xmin, &addr0, &glyph_size); 56 | 57 | /* 58 | * calculate glyph position 59 | */ 60 | 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /buddy/include/graphics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * graphics.h 3 | * graphics context 4 | * 5 | * tomaz stih mon oct 7 2013 6 | */ 7 | #ifndef _GRAPHICS_H 8 | #define _GRAPHICS_H 9 | 10 | #include "types.h" 11 | #include "rect.h" 12 | #include "bitmap.h" 13 | #include "vector.h" 14 | #include "clipping.h" 15 | 16 | #define NONE 0 17 | #define WORKSPACE 1 /* just workspace area */ 18 | #define WINDOW 2 /* entire window */ 19 | 20 | #define SCREEN_MAXX 255 21 | #define SCREEN_MAXY 191 22 | 23 | typedef struct graphics_s { 24 | rect_t *area; /* abs coord. */ 25 | rect_t *clip; /* ...in abs. coord. and reduced to fit area */ 26 | } graphics_t; 27 | 28 | /* constants */ 29 | extern graphics_t screen_graphics; 30 | extern rect_t screen_area; 31 | extern rect_t screen_clip; 32 | 33 | /* init graphics system */ 34 | extern void graphics_init(); 35 | 36 | /* create graphics */ 37 | extern graphics_t* graphics_create(byte flags); 38 | extern void graphics_destroy(graphics_t* g); 39 | 40 | /* clipping */ 41 | extern void graphics_set_clipping(graphics_t* g, rect_t *clip_rect); 42 | 43 | /* rectangle */ 44 | extern void graphics_fill_rect(graphics_t *g, rect_t *rect, byte* mask, byte mode); 45 | extern void graphics_draw_rect(graphics_t *g, rect_t *rect, byte linemask, byte mode); 46 | 47 | /* bitmaps */ 48 | extern bitmap_t* graphics_get_bitmap(graphics_t *g, rect_t *rect); 49 | extern void graphics_destroy_bitmap(bitmap_t *bmp); 50 | extern void graphics_put_bitmap(graphics_t *g, byte x, byte y, bitmap_t *bmp); 51 | 52 | #endif /* _GRAPHICS_H */ 53 | -------------------------------------------------------------------------------- /os/ram/todo/datalink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * datalink.h 3 | * data link protocol 4 | * 5 | * tomaz stih tue jul 31 2012 6 | */ 7 | #ifndef _DATALINK_H 8 | #define _DATALINK_H 9 | 10 | #define DL_ACK 0x88 11 | #define DL_NAK 0x11 12 | #define DL_YOU 0x24 13 | 14 | #define DL_FRAME_DLEN 32 /* frame + header + body = 32 bytes */ 15 | #define DL_IBUFFER_FRAMES 8 /* input buffer is 8 frames */ 16 | 17 | #define DL_TIMEOUT_HEADER 3 18 | #define DL_TIMEOUT_BODY 3 19 | 20 | typedef struct dl_ibuffer_s { 21 | list_header_t hdr; 22 | byte data[DL_FRAME_LEN]; 23 | } dl_ibuffer_t; 24 | 25 | typedef struct dl_link_s { 26 | list_header_t hdr; 27 | dl_read_t *pending_reads; 28 | dl_write_t *pending_writes; 29 | dl_ibuffer_t *ibuffer; 30 | } dl_link_t; 31 | 32 | extern dl_link_t *dl_link_connect(void *owner, word ibuffer_size); 33 | extern dl_link_t *dl_link_disconnect(dl_link_t *l); 34 | extern dl_write(void *owner, byte *data, word size, event_t *write_done); 35 | extern dl_read(void *owner, byte *data, word size, event_t *read_done); 36 | 37 | typedef struct dl_frame_header_s { 38 | byte sequence; 39 | byte response; 40 | } dl_frame_header_t; 41 | 42 | typedef struct dl_frame_body_s { 43 | dl_link_t *link; /* identifier */ 44 | byte size; 45 | byte data[DL_FRAME_DLEN]; 46 | word crc16; 47 | } dl_frame_body_t; 48 | 49 | extern dl_link_t *dl_link_first; /* start of linked list of data links*/ 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /buddy/message.c: -------------------------------------------------------------------------------- 1 | /* 2 | * message.c 3 | * message 4 | * 5 | * tomaz stih sun oct 27 2013 6 | */ 7 | #include "errors.h" 8 | #include "window.h" 9 | #include "message.h" 10 | #include "mouse.h" 11 | 12 | extern yx_t *yx; 13 | 14 | message_t *message_first; 15 | 16 | /* initialize messaging system */ 17 | void message_init() { 18 | message_first=NULL; 19 | } 20 | 21 | /* remove from queue and free space */ 22 | void message_destroy(message_t *m) { 23 | yx->free((void *)m); 24 | } 25 | 26 | /* call wnd_proc directly */ 27 | result message_send(window_t *wnd, byte id, word param1, word param2) { 28 | return wnd->wnd_proc(wnd, id, param1, param2); 29 | } 30 | 31 | /* queue message */ 32 | result message_post(window_t *wnd, byte id, word param1, word param2) { 33 | 34 | /* create message */ 35 | message_t *m=yx->allocate(sizeof(message_t)); 36 | if (!m) 37 | return(last_error=OUT_OF_MEMORY); 38 | 39 | /* populate it */ 40 | m->window=wnd; 41 | m->id=id; 42 | m->param1=param1; 43 | m->param2=param2; 44 | 45 | /* add it to the msg queue */ 46 | yx->lappend((void **)&message_first, (void *)m); 47 | 48 | /* we did it! */ 49 | return (last_error=SUCCESS); 50 | } 51 | 52 | /* dispatch new events */ 53 | void message_dispatch() { 54 | 55 | message_t *m; 56 | 57 | /* no messages? */ 58 | if (message_first==NULL) return; 59 | m = yx->lremfirst((void **)&message_first); 60 | if (m!=NULL) { 61 | message_send(m->window,m->id,m->param1,m->param2); 62 | message_destroy(m); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /os/ram/name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * name.c 3 | * named resources management 4 | * 5 | * NOTE: no convention is forced but yx uses first four characters 6 | * of name for type and next four for name i.e. /dev/kbd, 7 | * /dev/232, /wnd/top 8 | * 9 | * TODO: binary tree if rom space available 10 | * 11 | * tomaz stih wed apr 10 2013 12 | */ 13 | #include "yx.h" 14 | 15 | /* initialize linked list */ 16 | name_t *name_first = NULL; 17 | 18 | 19 | /* ----- private helpers ----- */ 20 | byte match_name(list_header_t *p, word name) { 21 | name_t *n = (name_t *)p; 22 | return !strcmp(n->name, (string)name); 23 | } 24 | 25 | 26 | /* ----- public interface ----- */ 27 | 28 | /* 29 | * link name with resource 30 | * TODO: exclude duplicates to prevent disaster 31 | */ 32 | name_t *name_link( 33 | void *owner, 34 | string name, 35 | void *resource) { 36 | 37 | name_t *n; 38 | 39 | /* check max length */ 40 | if (strlen(name) > MAX_NAME_LEN) 41 | return NULL; 42 | 43 | if ( n = (name_t *)syslist_add((void **)&name_first, sizeof(name_t), owner) ) { 44 | strcpy(n->name, name); 45 | n->resource=resource; 46 | } 47 | return n; 48 | } 49 | 50 | /* 51 | * unlink name and resource 52 | */ 53 | name_t *name_unlink(name_t *n) { 54 | return (name_t *)syslist_delete((void **)&name_first, (void *)n); 55 | } 56 | 57 | /* 58 | * find a name 59 | */ 60 | name_t *name_find(string name) { 61 | name_t *prev; 62 | return (name_t *)list_find( 63 | (list_header_t *)name_first, 64 | (list_header_t **)&prev, 65 | match_name, 66 | (word)name 67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /os/ram/ukernel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ukernel.c 3 | * yx micro kernel (incl. os entry point) 4 | * 5 | * tomaz stih thu mar 21 2013 6 | */ 7 | #include "yx.h" 8 | 9 | void main() { 10 | 11 | /* 12 | * initialize operating system and user heap 13 | */ 14 | mem_init(get_sysheap(), SYSHEAP_TOP - get_sysheap() + 1); 15 | mem_init(get_usrheap(), USRHEAP_TOP - get_usrheap() + 1); 16 | 17 | /* 18 | * register device drivers 19 | */ 20 | 21 | /* 22 | * initialize scheduler 23 | */ 24 | tmr_install(ball,EVERYTIME,SYS); 25 | tmr_install(set_ball_timeout,3,SYS); 26 | tmr_install(set_ball2_timeout,8,SYS); 27 | 28 | /* 29 | * gui 30 | */ 31 | welcome(); 32 | 33 | ball_timeout=evt_create(SYS); 34 | ball2_timeout=evt_create(SYS); 35 | 36 | //tsk_create(ball_task,256); 37 | //tsk_create(ball2_task,256); 38 | 39 | dbg_memdump(get_usrheap()); 40 | dbg_evtdump(); 41 | dbg_tmrdump(); 42 | dbg_taskdump(); 43 | } 44 | 45 | /* 46 | * display welcome message 47 | */ 48 | void welcome() { 49 | hires_cls(BLACK, GREEN, BLACK, CM_BRIGHT); 50 | lores_puts("yx 1.0.0.0 (build mar 22 2013)\nready?\n_\n"); 51 | } 52 | 53 | /* 54 | * kernel panic function 55 | */ 56 | void panic(string s) { 57 | int i; 58 | hires_cls(BLUE, YELLOW, BLUE, CM_NONE); /* yes, it is the BOD */ 59 | lores_x=lores_y=0; 60 | lores_puts("kernel panic:\n\n\""); 61 | lores_puts(s); 62 | lores_puts("\""); 63 | } 64 | 65 | /* 66 | * scheduler 67 | */ 68 | void scheduler() __naked { 69 | __asm 70 | jp _tsk_switch_improved /* switch task */ 71 | __endasm; 72 | } 73 | -------------------------------------------------------------------------------- /os/ram/todo/tsocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tsocks.h 3 | * tiny sockets interface is a lightweight interface enabling 4 | * zx spectrum 48K to connect to internet via interface 1 / rs232. 5 | * 6 | * tomaz stih thu jul 26 2012 7 | */ 8 | #ifndef _TSOCKS_H 9 | #define _TSOCKS_H 10 | 11 | /* 12 | * public interface 13 | */ 14 | 15 | #define MAX_SBUFF_SIZE 256 16 | 17 | typedef sockaddr_s { 18 | byte ip[4]; 19 | word port; 20 | } sockaddr_t; 21 | 22 | typedef struct socket_s { 23 | sockaddr_t saddr; 24 | byte obuffer[MAX_SBUFF_SIZE]; 25 | word ohead; 26 | word otail; 27 | byte ibuffer[MAX_SBUFF_SIZE]; 28 | word ihead; 29 | word itail; 30 | } socket_t; 31 | 32 | extern result connect(socket_t* s, string address, word port); 33 | extern close(socket_t *s); 34 | extern result send(socket_t* s, byte* buffer, word length); 35 | extern result recv(socket_t* s, byte* buffer, word length, word *rlength); 36 | 37 | /* 38 | * private interface 39 | */ 40 | 41 | #define BLK_DATA_SIZE 32 42 | 43 | #define CMD_ACK 1 /* no block data */ 44 | #define CMD_NAK 2 /* no block data */ 45 | #define CMD_CONNECT 3 46 | #define CMD_CLOSE 4 /* no block data */ 47 | #define CMD_SEND 5 48 | #define CMD_RECV 6 49 | #define CMD_DATA 7 50 | 51 | typedef struct blk_hdr_s { 52 | word owner; /* owner id = socket address */ 53 | byte seq; /* sequence counter (0..0xff) for this owner */ 54 | byte cmd; /* command */ 55 | } blk_hdr_t; 56 | 57 | typedef struct blk_data_s { 58 | byte data[BLK_DATA_SIZE]; 59 | word crc16; /* data + header */ 60 | } blk_data_s; 61 | 62 | #endif -------------------------------------------------------------------------------- /buddy/message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * message.h 3 | * message header 4 | * 5 | * tomaz stih sun oct 27 2013 6 | */ 7 | #ifndef _MESSAGE_H 8 | #define _MESSAGE_H 9 | 10 | #include "yx.h" 11 | #include "window.h" 12 | 13 | #define MSG_SYS_IDLE 0 14 | #define MSG_SYS_QUIT 1 15 | #define MSG_SYS_PAINT 2 /* system paint */ 16 | #define MSG_WND_CREATE 3 17 | #define MSG_WND_DESTROY 4 18 | #define MSG_WND_CLOSE 5 19 | #define MSG_WND_MOVE 6 20 | #define MSG_WND_SIZE 7 /* param1 ... rect_t* to change */ 21 | #define MSG_WND_PAINT 8 /* user paint */ 22 | #define MSG_MOUSE_MOVE 9 23 | #define MSG_MOUSE_LDOWN 10 /* param1 ... x, param2 ... y */ 24 | #define MSG_MOUSE_LUP 11 /* param1 ... x, param2 ... y */ 25 | #define MSG_MOUSE_RDOWN 12 /* param1 ... x, param2 ... y */ 26 | #define MSG_MOUSE_RUP 13 /* param1 ... x, param2 ... y */ 27 | #define MSG_WND_CREATED 14 /* window successfully created */ 28 | #define MSG_MOUSE_CLICK 15 /* param1 ... x, param2 ... y */ 29 | #define MSG_WND_HITTEST 16 /* hit test for system areas, param1=byte* result */ 30 | 31 | #define WND_HIT_NONE 0 32 | #define WND_HIT_TITLE 1 33 | #define WND_HIT_CLOSE 2 34 | #define WND_HIT_RESIZE 3 35 | 36 | typedef struct message_s message_t; 37 | typedef struct message_s { 38 | message_t* next; 39 | word reserved; 40 | window_t *window; 41 | byte id; 42 | word param1; 43 | word param2; 44 | }; 45 | 46 | extern message_t *message_first; 47 | 48 | extern result message_send(window_t *wnd, byte id, word param1, word param2); 49 | extern result message_post(window_t *wnd, byte id, word param1, word param2); 50 | extern void message_dispatch(); 51 | 52 | #endif /* _MESSAGE_H */ 53 | -------------------------------------------------------------------------------- /os/ram/todo/font.h: -------------------------------------------------------------------------------- 1 | /* 2 | * font.h 3 | * fonts 4 | * 5 | * notes: metrics described at http://en.wikipedia.org/wiki/X-height 6 | * 7 | * tomaz stih sat jun 16 2012 8 | */ 9 | #ifndef _FONT_H 10 | #define _FONT_H 11 | 12 | typedef struct font_s { 13 | 14 | /* quick info */ 15 | byte font_generation; /* 0=fixed 8x8, 1=yeah system fonts, 2=advanced proportional fonts */ 16 | 17 | /* scope */ 18 | byte first_ascii; 19 | byte last_ascii; 20 | 21 | /* 22 | * --- ONLY FONT GENERATION 1 AND LATER --- 23 | */ 24 | byte bytes_per_glyph_line; 25 | byte glyph_lines; 26 | byte xmax; 27 | byte descent; 28 | 29 | /* 30 | * --- ONLY FONT GENERATION 2 AND LATER --- 31 | */ 32 | /* advance = xmin+width+xmax, width is per char data */ 33 | byte xmin; 34 | 35 | /* vertical aspects */ 36 | byte ascent; /* font ascent */ 37 | byte cap_height; /* cap height */ 38 | byte x_height; /* corpus size */ 39 | byte baseline; /* baseline */ 40 | 41 | } font_t; 42 | 43 | /* 44 | * each glyph starts with a mask 45 | * followed by glyph data and concluding 46 | * with glyph width 47 | */ 48 | 49 | /* ------------------------------------------------------------ */ 50 | 51 | /* 52 | * get basic metrics 53 | */ 54 | extern void fnt_get_font_info( 55 | font_t *font, 56 | byte *bytes_per_glyph, 57 | byte *glyph_lines, 58 | byte *xmax, 59 | byte *descent, 60 | byte *xmin, 61 | word *first_glyph_addr, 62 | word *glyph_size_in_bytes); 63 | 64 | /* 65 | * measure string 66 | */ 67 | extern void fnt_measure_string(font_t *font, string string, byte *widths); 68 | 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /buddy/os/yx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * yx.c 3 | * operating system wrapper. 4 | * 5 | * tomaz stih sun jul 26 2015 6 | */ 7 | #include "yx.h" 8 | #include "list.h" 9 | #include "memory.h" 10 | 11 | 12 | /* fixed api pointer */ 13 | yx_t yx_api; 14 | 15 | 16 | /* expected OS externals */ 17 | extern void *current_task; 18 | extern void *heap; 19 | extern word heap_size; 20 | 21 | 22 | /* wrapper functions */ 23 | void *allocate(word size) { 24 | return mem_allocate(&heap,size,¤t_task); 25 | } 26 | 27 | void free(void *p) { 28 | mem_free(&heap,p); 29 | } 30 | 31 | void *lappend(void **first, void *el) { 32 | return (void*)list_append((list_header_t**) first, (list_header_t*) el); 33 | } 34 | 35 | void *linsert(void **first, void *el) { 36 | return (void*)list_insert((list_header_t**) first, (list_header_t*) el); 37 | } 38 | 39 | void *lremove(void **first, void *el) { 40 | return (void*)list_remove((list_header_t**) first, (list_header_t*) el); 41 | } 42 | 43 | void *lremfirst(void **first) { 44 | return (void*)list_remove_first((list_header_t**) first); 45 | } 46 | 47 | void sleep(word _50) { 48 | int i; 49 | while (_50--) 50 | for(i=0;i<100;i++); 51 | } 52 | 53 | /* yx interface */ 54 | void register_interfaces() { 55 | 56 | mem_init(&heap,heap_size); 57 | 58 | yx_api.lappend=lappend; 59 | yx_api.lremove=lremove; 60 | yx_api.lremfirst=lremfirst; 61 | yx_api.linsert=linsert; 62 | 63 | yx_api.allocate=allocate; 64 | yx_api.free=free; 65 | yx_api.copy=mem_copy; 66 | 67 | yx_api.sleep=sleep; 68 | } 69 | 70 | void *query_interface(string api) { 71 | api; 72 | return (void *)(&yx_api); 73 | } 74 | -------------------------------------------------------------------------------- /tools/gdb2fuse/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "app.h" 5 | 6 | using namespace std; 7 | 8 | app::app() 9 | { 10 | cout << "gdb2fuse 1.0" << endl; 11 | } 12 | 13 | app::~app() 14 | { 15 | cout << "bye." << endl; 16 | } 17 | 18 | void app::run(int argc, char *argv[]) 19 | { 20 | if (argc!=4) { // Check number of arguments. 21 | usage(); 22 | error("invalid argument(s).", 1); 23 | } 24 | 25 | cout << "initializing..." << endl; 26 | 27 | gdb_ipsvr* ipsvr=gdb_ipsvr::create(argv[1]); 28 | fuse_npipe* npipe=fuse_npipe::create(argv[2],argv[3]); 29 | 30 | // Talk, talk, talk... 31 | char buffer[BUFSIZE]; 32 | int len=0; 33 | while(1) { 34 | if ((len=npipe->read(buffer,BUFSIZE))<0) break; // Read named pipe. 35 | if (len>0) ipsvr->write(buffer,len); // Write ip. 36 | if ((len=ipsvr->read(buffer,BUFSIZE))<0) break; // Read ip. 37 | if (len>0) npipe->write(buffer,len); // Write named pipe. 38 | } 39 | 40 | // If we are here / we have an error. 41 | if (len==-1) 42 | cout << "connection closed..." << endl; 43 | else 44 | cout << "fatal error..." << endl; 45 | } 46 | 47 | void app::usage() { 48 | cout << "usage: gdb2fuse " << endl; 49 | cout << " ... ip port number to listen (i.e. 8080)" << endl; 50 | cout << " ... input named pipe file" << endl; 51 | cout << " ... toutput named pipe file" << endl; 52 | } 53 | 54 | void app::error(const string& msg, int code) 55 | { 56 | cerr << "error: " << msg << endl; 57 | exit(code); 58 | } 59 | -------------------------------------------------------------------------------- /apps/kbd/crt0.s: -------------------------------------------------------------------------------- 1 | ;; crt0.c 2 | ;; zx spectrum ram startup code 3 | ;; 4 | ;; tomaz stih sun may 20 2012 5 | .module crt0 6 | .globl _get_heap 7 | 8 | .area _HEADER(ABS) 9 | 10 | ld (#store_sp),sp ; store SP 11 | ld sp,#stack 12 | 13 | ;; store all regs 14 | push af 15 | push bc 16 | push de 17 | push hl 18 | push ix 19 | push iy 20 | ex af, af' 21 | push af 22 | exx 23 | push bc 24 | push de 25 | push hl 26 | 27 | call gsinit ; init static vars (sdcc style) 28 | 29 | ;; start the os 30 | call _main 31 | 32 | ;; restore all regs 33 | pop hl 34 | pop de 35 | pop bc 36 | pop af 37 | exx 38 | ex af,af' 39 | pop iy 40 | pop ix 41 | pop hl 42 | pop de 43 | pop bc 44 | pop af 45 | 46 | ld sp,(#store_sp) ; restore original SP 47 | ret 48 | 49 | _get_heap:: ld hl,#heap 50 | ret 51 | 52 | ;; (linker documentation:) where specific ordering is desired - 53 | ;; the first linker input file should have the area definitions 54 | ;; in the desired order 55 | .area _HOME 56 | .area _CODE 57 | .area _GSINIT 58 | .area _GSFINAL 59 | .area _DATA 60 | .area _BSS 61 | .area _HEAP 62 | 63 | ;; this area contains data initialization code - 64 | ;; unlike gnu toolchain which generates data, sdcc generates 65 | ;; initialization code for every initialized global 66 | ;; variable. and it puts this code into _GSINIT area 67 | .area _GSINIT 68 | gsinit: 69 | .area _GSFINAL 70 | ret 71 | 72 | .area _DATA 73 | 74 | .area _BSS 75 | store_sp: .word 1 76 | 77 | ;; 1024 bytes of operating system stack 78 | .ds 1024 79 | stack: 80 | .area _HEAP 81 | heap: 82 | -------------------------------------------------------------------------------- /apps/fonts/crt0.s: -------------------------------------------------------------------------------- 1 | ;; crt0.c 2 | ;; zx spectrum ram startup code 3 | ;; 4 | ;; tomaz stih sun may 20 2012 5 | .module crt0 6 | .globl _get_heap 7 | 8 | .area _HEADER(ABS) 9 | 10 | ld (#store_sp),sp ; store SP 11 | ld sp,#stack 12 | 13 | ;; store all regs 14 | push af 15 | push bc 16 | push de 17 | push hl 18 | push ix 19 | push iy 20 | ex af, af' 21 | push af 22 | exx 23 | push bc 24 | push de 25 | push hl 26 | 27 | call gsinit ; init static vars (sdcc style) 28 | 29 | ;; start the os 30 | call _main 31 | 32 | ;; restore all regs 33 | pop hl 34 | pop de 35 | pop bc 36 | pop af 37 | exx 38 | ex af,af' 39 | pop iy 40 | pop ix 41 | pop hl 42 | pop de 43 | pop bc 44 | pop af 45 | 46 | ld sp,(#store_sp) ; restore original SP 47 | ret 48 | 49 | _get_heap:: ld hl,#heap 50 | ret 51 | 52 | ;; (linker documentation:) where specific ordering is desired - 53 | ;; the first linker input file should have the area definitions 54 | ;; in the desired order 55 | .area _HOME 56 | .area _CODE 57 | .area _GSINIT 58 | .area _GSFINAL 59 | .area _DATA 60 | .area _BSS 61 | .area _HEAP 62 | 63 | ;; this area contains data initialization code - 64 | ;; unlike gnu toolchain which generates data, sdcc generates 65 | ;; initialization code for every initialized global 66 | ;; variable. and it puts this code into _GSINIT area 67 | .area _GSINIT 68 | gsinit: 69 | .area _GSFINAL 70 | ret 71 | 72 | .area _DATA 73 | 74 | .area _BSS 75 | store_sp: .word 1 76 | 77 | ;; 1024 bytes of operating system stack 78 | .ds 1024 79 | stack: 80 | .area _HEAP 81 | heap: 82 | -------------------------------------------------------------------------------- /buddy/Makefile: -------------------------------------------------------------------------------- 1 | # Tools. 2 | DIR = $(shell pwd) 3 | GNUC = gcc 4 | GNUCFLAGS = -I$(DIR)/include 5 | CC = sdcc 6 | CFLAGS = -mz80 --no-std-crt0 -D DEBUG -I$(DIR)/include/ 7 | AS = sdasz80 8 | ASFLAGS = -xlos -g 9 | LD = sdcc 10 | LDFLAGS = -mz80 --no-std-crt0 \ 11 | --nostdlib --code-loc 0x8032 \ 12 | --data-loc 0xc000 -Wl -b_HEADER=0x8000 13 | # Deps. 14 | CSRCS = $(wildcard *.c) 15 | SSRCS = $(wildcard *.s) 16 | OBJS = $(patsubst %.c,%.rel,$(CSRCS)) $(patsubst %.s,%.rel,$(SSRCS)) 17 | 18 | # Rules. 19 | .PHONY: all clean 20 | 21 | all: libs graphics depend app.bin 22 | 23 | depend: $(CSRCS) 24 | rm --force .depend 25 | $(GNUC) $(GNUCFLAGS) $(CSRCS) -MM >> .depend 26 | sed -i 's/\.o/\.rel/g' .depend 27 | 28 | -include .depend 29 | 30 | libs: 31 | cd os && $(MAKE) INCLUDE=$(DIR)/include/ OUTDIR=$(DIR)/lib/ 32 | cd graphics && $(MAKE) INCLUDE=$(DIR)/include/ OUTDIR=$(DIR)/lib/ 33 | 34 | app.bin: crt0.rel $(OBJS) 35 | $(LD) $(LDFLAGS) $^ -los -lgraphics -Llib 36 | makezxbin app.bin 37 | appmake +zx --binfile ./app.bin --org 32768 38 | fuse-gtk --tape ./app.tap \ 39 | --interface1 \ 40 | --kempston-mouse \ 41 | --machine 48 --graphics-filter 2x \ 42 | --no-sound \ 43 | --debugger-command "br 0xffff" 44 | 45 | %.rel: %.s 46 | $(AS) $(ASFLAGS) $(basename $*).rel $*.s 47 | 48 | %.rel: %.c 49 | $(CC) -c -o $@ $< $(CFLAGS) 50 | 51 | clean: 52 | cd os && $(MAKE) INCLUDE=$(DIR)/include/ OUTDIR=$(DIR)/lib/ clean 53 | cd graphics && $(MAKE) INCLUDE=$(DIR)/include/ OUTDIR=$(DIR)/lib/ clean 54 | rm -f core *~ \#* *.cdb *.rel *.hex *.ihx *.lst *.asm *.map *.rel \ 55 | *.rst *.sym *.lib *.bin *.mem *.lib kernel.s *.rom *.lnk \ 56 | *.noi *.lk *.tap a.out 57 | rm -f .depend 58 | -------------------------------------------------------------------------------- /buddy/window.h: -------------------------------------------------------------------------------- 1 | /* 2 | * window.h 3 | * basic window 4 | * 5 | * tomaz stih mon oct 7 2013 6 | */ 7 | #ifndef _WINDOW_H 8 | #define _WINDOW_H 9 | 10 | #include "yx.h" 11 | #include "rect.h" 12 | #include "graphics.h" 13 | 14 | /* window flags */ 15 | #define WF_NONE 0x00 16 | #define WF_HASTITLE 0x01 17 | #define WF_HASBORDER 0x02 18 | #define WF_DESKTOP 0x04 19 | 20 | /* window sizes */ 21 | #define WMETR_TITLEHEIGHT 12 22 | #define WMETR_BORDERWIDTH 1 23 | 24 | /* window structure */ 25 | typedef struct window_s window_t; 26 | struct window_s { 27 | window_t *next; 28 | word reserved; 29 | struct window_s *parent; 30 | struct window_s *first_child; 31 | byte flags; 32 | rect_t *rect; 33 | graphics_t *graphics; 34 | result ((*wnd_proc)(window_t* wnd, byte id, word param1, word param2)); 35 | string title; 36 | }; 37 | 38 | /* window drawing */ 39 | extern window_t *window_desktop; 40 | extern void window_init(); 41 | extern graphics_t* window_graphics(window_t* wnd); 42 | extern window_t *window_create( 43 | string title, 44 | window_t* parent, 45 | byte flags, 46 | result ((*wnd_proc)(window_t* wnd, byte id, word param1, word param2)), 47 | byte x0, 48 | byte y0, 49 | byte x1, 50 | byte y1); 51 | extern void window_destroy(window_t *wnd); 52 | extern void window_draw(window_t *wnd); 53 | extern void window_select(window_t *wnd); 54 | extern window_t* window_get_app_wnd(window_t *wnd); 55 | extern window_t *window_find_xy(window_t* root, byte absx, byte absy); 56 | extern void window_move(window_t *wnd, byte dx, boolean lr, byte dy, boolean ud); 57 | extern void window_invalidate(rect_t *area, window_t *root, window_t *first); 58 | 59 | #endif /* _WINDOW_H */ 60 | -------------------------------------------------------------------------------- /apps/template/crt0.s: -------------------------------------------------------------------------------- 1 | ;; crt0.c 2 | ;; zx spectrum ram startup code 3 | ;; 4 | ;; tomaz stih sun may 20 2012 5 | .module crt0 6 | .globl _heap 7 | .globl _stack 8 | 9 | .area _HEADER(ABS) 10 | 11 | di ; no rom anymore 12 | 13 | ld (#store_sp),sp ; store SP 14 | ld sp,#_stack 15 | 16 | ;; store all regs 17 | push af 18 | push bc 19 | push de 20 | push hl 21 | push ix 22 | push iy 23 | ex af, af' 24 | push af 25 | exx 26 | push bc 27 | push de 28 | push hl 29 | 30 | call gsinit ; init static vars (sdcc style) 31 | 32 | ;; start the os 33 | call _main 34 | 35 | ;; restore all regs 36 | pop hl 37 | pop de 38 | pop bc 39 | pop af 40 | exx 41 | ex af,af' 42 | pop iy 43 | pop ix 44 | pop hl 45 | pop de 46 | pop bc 47 | pop af 48 | 49 | ld sp,(#store_sp) ; restore original SP 50 | 51 | ei ; the rom is back 52 | ret 53 | 54 | ;; (linker documentation:) where specific ordering is desired - 55 | ;; the first linker input file should have the area definitions 56 | ;; in the desired order 57 | .area _HOME 58 | .area _CODE 59 | .area _GSINIT 60 | .area _GSFINAL 61 | .area _DATA 62 | .area _BSS 63 | .area _HEAP 64 | 65 | ;; this area contains data initialization code - 66 | ;; unlike gnu toolchain which generates data, sdcc generates 67 | ;; initialization code for every initialized global 68 | ;; variable. and it puts this code into _GSINIT area 69 | .area _GSINIT 70 | gsinit: 71 | .area _GSFINAL 72 | ret 73 | 74 | .area _DATA 75 | 76 | .area _BSS 77 | store_sp: .word 1 78 | 79 | ;; 2048 bytes of operating system stack 80 | .ds 2048 81 | _stack:: 82 | .area _HEAP 83 | _heap:: 84 | -------------------------------------------------------------------------------- /os/ram/ball.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ball.h 3 | * character balls demo 4 | * 5 | * tomaz stih tue may 29 2012 6 | * 7 | */ 8 | #include "yx.h" 9 | 10 | event_t *ball_timeout; 11 | event_t *ball2_timeout; 12 | 13 | byte x=5,y=0; 14 | byte old_x=5, old_y=0; 15 | byte dx=1,dy=1; 16 | 17 | void set_ball_timeout() { 18 | evt_set(ball_timeout, signaled); 19 | } 20 | 21 | void set_ball2_timeout() { 22 | evt_set(ball2_timeout, signaled); 23 | } 24 | 25 | void ball() { 26 | 27 | old_x=x; 28 | old_y=y; 29 | x=x+dx; 30 | y=y+dy; 31 | 32 | if (x>31) { x=31; dx=-1; } 33 | if (x==0) { x=0; dx=1; } 34 | if (y>23) { y=23; dy=-1; } 35 | if (y==0) { y=0; dy=1; } 36 | 37 | lores_putc_xy('o', x, y); 38 | lores_putc_xy(' ', old_x, old_y); 39 | } 40 | 41 | void ball_task() { 42 | 43 | byte x=0,y=7; 44 | byte old_x=0, old_y=7; 45 | byte dx=1,dy=1; 46 | 47 | while (1) { 48 | old_x=x; 49 | old_y=y; 50 | x=x+dx; 51 | y=y+dy; 52 | if (x>31) { x=31; dx=-1; } 53 | if (x==0) { x=0; dx=1; } 54 | if (y>23) { y=23; dy=-1; } 55 | if (y==0) { y=0; dy=1; } 56 | lores_putc_xy('o', x, y); 57 | lores_putc_xy(' ', old_x, old_y); 58 | tsk_wait4events(&ball_timeout, 1); 59 | evt_set(ball_timeout,nonsignaled); 60 | } 61 | } 62 | 63 | void ball2_task() { 64 | 65 | byte x=20,y=20; 66 | byte old_x=0, old_y=7; 67 | byte dx=-1,dy=1; 68 | 69 | while (1) { 70 | old_x=x; 71 | old_y=y; 72 | x=x+dx; 73 | y=y+dy; 74 | if (x>31) { x=31; dx=-1; } 75 | if (x==0) { x=0; dx=1; } 76 | if (y>23) { y=23; dy=-1; } 77 | if (y==0) { y=0; dy=1; } 78 | lores_putc_xy('o', x, y); 79 | lores_putc_xy(' ', old_x, old_y); 80 | tsk_wait4events(&ball2_timeout, 1); 81 | evt_set(ball2_timeout,nonsignaled); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /os/ram/hires.c: -------------------------------------------------------------------------------- 1 | /* 2 | * hires.c 3 | * high resolution graphics (256x192) 4 | * 5 | * tomaz stih wed mar 20 2013 6 | */ 7 | #include "yx.h" 8 | 9 | /* 10 | * clear screen 11 | */ 12 | void hires_cls(color_t back, color_t fore, color_t border, color_mask_t cm) __naked { 13 | __asm 14 | ld iy,#0x0000 15 | add iy,sp 16 | 17 | /* 18 | * first graphics 19 | */ 20 | ld hl,#0x4000 /* vmemory */ 21 | ld bc,#0x1800 /* vmem size */ 22 | ld (hl),l /* l = 0 */ 23 | ld d,h 24 | ld e,#1 25 | ldir /* clear screen */ 26 | 27 | /* 28 | * now attributes 29 | */ 30 | ld a,2(iy) /* paper color to */ 31 | rlca /* bits 3-5 */ 32 | rlca 33 | rlca 34 | or 3(iy) /* ink color to bits 0-2 */ 35 | or 5(iy) /* or mask */ 36 | ld (hl),a 37 | ld bc,#0x02ff /* size of attr */ 38 | ldir 39 | 40 | /* 41 | * and the border 42 | */ 43 | ld a,4(iy) 44 | out (#0xfe),a /* set border */ 45 | 46 | ret 47 | __endasm; 48 | } 49 | 50 | word hires_vmem_nextrow_addr(word addr) __naked { 51 | 52 | __asm 53 | /* get current address to hl */ 54 | ld iy,#0x0000 55 | add iy,sp 56 | ld l,2(iy) 57 | ld h,3(iy) 58 | 59 | /* 60 | * vmem_nextrow_addr_raw 61 | * based on address in vmem, calculate next row address in vmem 62 | * input 63 | * hl address in vmem 64 | * output 65 | * hl next row address in vmem 66 | * effects 67 | * a, flags, c, hl 68 | */ 69 | hires_vmem_nextrow_addr_raw:: 70 | /* calc. next line to hl */ 71 | inc h 72 | ld a,h 73 | and #7 74 | jr nz,nextrow_done 75 | ld a,l 76 | add a,#32 77 | ld l,a 78 | jr c, nextrow_done 79 | ld a,h 80 | sub #8 81 | ld h,a 82 | nextrow_done: 83 | ret 84 | __endasm; 85 | } 86 | -------------------------------------------------------------------------------- /os/ram/crt0.s: -------------------------------------------------------------------------------- 1 | ;; crt0.s 2 | ;; yx ram startup code 3 | ;; 4 | ;; tomaz stih, tue apr 9 2013 5 | .module crt0 6 | 7 | .globl vectbl 8 | .globl sysstack 9 | .globl sysheap 10 | .globl tarpit 11 | 12 | .area _HEADER (ABS) 13 | di ; disable interrupts 14 | init: 15 | ld sp,#sysstack ; now sp to OS stack (on bss) 16 | call gsinit ; init static vars 17 | 18 | ;; start the os 19 | call _main 20 | 21 | ;; install IM2 handler 22 | ld a,#0x39 ; im2 trick 23 | ld i,a 24 | ld hl,#0xffff 25 | ld (hl),#0x18 ; jr upcode 26 | 27 | ;; start the scheduler 28 | im 2 ; im 2, 50Hz interrupt on ZX Spectrum 29 | ei ; enable interrupts 30 | 31 | tarpit: 32 | halt ; halt 33 | jr tarpit 34 | 35 | ;; TODO: rewire temporary handlers 36 | syscall: 37 | ret 38 | 39 | ;; (linker documentation) where specific ordering is desired - 40 | ;; the first linker input file should have the area definitions 41 | ;; in the desired order 42 | .area _HOME 43 | .area _CODE 44 | .area _GSINIT 45 | .area _GSFINAL 46 | .area _DATA 47 | .area _BSS 48 | .area _HEAP 49 | .area _IM2 50 | 51 | ;; this area contains data initialization code - 52 | ;; unlike gnu toolchain which generates data, sdcc generates 53 | ;; initialization code for every initialized global 54 | ;; variable. and it puts this code into _GSINIT area 55 | .area _GSINIT 56 | gsinit: 57 | 58 | .area _GSFINAL 59 | ret 60 | 61 | .area _BSS 62 | ;; 256 bytes of operating system stack 63 | .ds 256 64 | sysstack:: 65 | .area _HEAP 66 | sysheap:: 67 | 68 | .area _IM2 69 | ;; vector jump table at 0xfff0 70 | vectbl:: 71 | jp syscall ; fff0 72 | .db 0 73 | jp _scheduler ; fff4 74 | .db 0 75 | -------------------------------------------------------------------------------- /tools/makezxbin/makezxbin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * makezxbin.c 3 | * fix for makebin to produce proper 4 | * zx spectrum ram image from .IHX 5 | * (intel hex file) 6 | * 7 | * notes: build: gcc -o makezxbin.exe makezxbin.c 8 | * use: makezxbin app.bin 9 | * 10 | * tomaz stih mon oct 21 2013 11 | */ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define FILL_BYTE 0xFF 19 | 20 | uint8_t getnibble(char **p) { 21 | int ret = *((*p)++) - '0'; 22 | if (ret > 9) 23 | ret -= 'A' - '9' - 1; 24 | return ret; 25 | } 26 | 27 | uint8_t getbyte(char **p) 28 | { 29 | return (getnibble(p) << 4) | getnibble(p); 30 | } 31 | 32 | int main(int argc, char **argv) 33 | { 34 | int size = 65536; 35 | uint8_t *rom; 36 | char line[256]; 37 | char *p; 38 | int minaddr = -1, maxaddr = -1; 39 | 40 | rom = malloc(size); 41 | if (rom == NULL) { 42 | fprintf(stderr, "error: couldn't allocate room for the image.\n"); 43 | return -1; 44 | } 45 | 46 | memset(rom, FILL_BYTE, size); 47 | while (fgets(line, 256, stdin) != NULL) { 48 | int nbytes; 49 | int addr; 50 | if (*line != ':') { 51 | fprintf(stderr, "error: invalid IHX line.\n"); 52 | return -2; 53 | } 54 | p = line+1; 55 | nbytes = getbyte(&p); 56 | addr = getbyte(&p)<<8 | getbyte(&p); 57 | getbyte(&p); 58 | 59 | while (nbytes--) { 60 | if (addr < size) { 61 | rom[addr++] = getbyte(&p); 62 | if (addrmaxaddr || maxaddr<0) maxaddr=addr; 64 | } /* if addr < size */ 65 | } /* while (nbytes--) */ 66 | } /* while (fgets) */ 67 | 68 | fwrite(&(rom[minaddr-1]), 1, maxaddr - minaddr + 1, stdout); 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /buddy/crt0.s: -------------------------------------------------------------------------------- 1 | ;; crt0.c 2 | ;; zx spectrum ram startup code 3 | ;; 4 | ;; tomaz stih sun may 20 2012 5 | .module crt0 6 | .globl __sdcc_call_hl 7 | .globl _heap 8 | .globl _stack 9 | 10 | .area _HEADER(ABS) 11 | 12 | di ; no rom anymore 13 | 14 | ld (#store_sp),sp ; store SP 15 | ld sp,#_stack 16 | 17 | ;; store all regs 18 | push af 19 | push bc 20 | push de 21 | push hl 22 | push ix 23 | push iy 24 | ex af, af' 25 | push af 26 | exx 27 | push bc 28 | push de 29 | push hl 30 | 31 | call gsinit ; init static vars (sdcc style) 32 | 33 | ;; start the os 34 | call _main 35 | 36 | ;; restore all regs 37 | pop hl 38 | pop de 39 | pop bc 40 | pop af 41 | exx 42 | ex af,af' 43 | pop iy 44 | pop ix 45 | pop hl 46 | pop de 47 | pop bc 48 | pop af 49 | 50 | ld sp,(#store_sp) ; restore original SP 51 | 52 | ei ; the rom is back 53 | ret 54 | 55 | __sdcc_call_hl:: 56 | jp (hl) 57 | 58 | ;; (linker documentation:) where specific ordering is desired - 59 | ;; the first linker input file should have the area definitions 60 | ;; in the desired order 61 | .area _HOME 62 | .area _CODE 63 | .area _GSINIT 64 | .area _GSFINAL 65 | .area _DATA 66 | .area _BSS 67 | .area _HEAP 68 | 69 | ;; this area contains data initialization code - 70 | ;; unlike gnu toolchain which generates data, sdcc generates 71 | ;; initialization code for every initialized global 72 | ;; variable. and it puts this code into _GSINIT area 73 | .area _GSINIT 74 | gsinit: 75 | .area _GSFINAL 76 | ret 77 | 78 | .area _DATA 79 | 80 | .area _BSS 81 | store_sp: .word 1 82 | 83 | ;; 2048 bytes of operating system stack 84 | .ds 2048 85 | _stack:: 86 | .area _HEAP 87 | _heap:: 88 | -------------------------------------------------------------------------------- /os/rom/interrupts.s: -------------------------------------------------------------------------------- 1 | ;; interrupts.s 2 | ;; zx spectrum interrupts 3 | ;; 4 | ;; note: _intr_set_vect is NOT guarded by ei/di! 5 | ;; 6 | ;; tomaz stih, sun may 20 2012 7 | .module interrupts 8 | 9 | .globl _intr_di_refcount 10 | .globl _intr_set_vect 11 | .globl _intr_enable 12 | .globl _intr_disable 13 | 14 | .area _CODE 15 | 16 | 17 | ;; --------------------------- 18 | ;; extern void intr_disable(); 19 | ;; --------------------------- 20 | _intr_disable:: 21 | di 22 | ld hl,#_intr_di_refcount 23 | inc (hl) 24 | ret 25 | 26 | 27 | ;; -------------------------- 28 | ;; extern void intr_enable(); 29 | ;; -------------------------- 30 | _intr_enable:: 31 | ld a,(#_intr_di_refcount) 32 | or a 33 | jr z,do_ei ; if a==0 then just ei 34 | dec a ; if a<>0 then dec a 35 | ld (#_intr_di_refcount),a ; write back to counter 36 | or a ; and check for ei 37 | jr nz,dont_ei ; not yet... 38 | do_ei: 39 | ei 40 | dont_ei: 41 | ret 42 | 43 | 44 | ;; ----------------------------------------------------------- 45 | ;; extern void intr_set_vect(void (*handler)(), byte vec_num); 46 | ;; ----------------------------------------------------------- 47 | _intr_set_vect:: 48 | pop hl ; ret address / ignore 49 | pop bc ; bc = handler 50 | pop de ; d = undefined, e = vector number 51 | ;; restore stack 52 | push de 53 | push bc 54 | push hl 55 | ld d,#0x00 ; de = 16 bit vector number 56 | ld hl,#_sys_vec_tbl ; vector table start 57 | add hl,de 58 | add hl,de 59 | add hl,de 60 | inc hl ; hl = hl + 3 * de + 1 61 | ;; hl now points to vector address in RAM 62 | ;; so set it to handler value in bc 63 | ld (hl),c 64 | inc hl 65 | ld (hl),b 66 | ret 67 | 68 | 69 | 70 | .area _INITIALIZED 71 | _intr_di_refcount: 72 | .ds 1 73 | 74 | 75 | .area _INITIALIZER 76 | __xinit__intr_di_refcount: 77 | .byte 0 78 | .area _CABS (ABS) 79 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/fusesend115k.s: -------------------------------------------------------------------------------- 1 | ;; fusesend115k.s 2 | ;; rs232 send @ 115.200-8-N-2 baud 3 | ;; 4 | ;; notes: for FUSE only, exploits FUSE bugs! 5 | ;; 6 | ;; tomaz stih, sat jul 12 2014 7 | 8 | .module fusesend115k 9 | .globl _rs232_putb 10 | 11 | ;; consts 12 | RS232_CTL = 0xef 13 | RS232_DTA = 0xf7 14 | CTS_ON = 0xff 15 | CTS_OFF = 0xef 16 | RESULT_SUCCESS = 0x00 17 | 18 | .area _CODE 19 | 20 | _rs232_putb:: 21 | di ; no interrupts for precise timing 22 | 23 | ;; get byte ptr from stack 24 | ld hl,#0x0000 25 | add hl,sp 26 | inc hl 27 | inc hl ; hl points to byte to send 28 | 29 | ;; fuse hack, fuse waiting for down signal 30 | ld a,#0xfe ; signal tx to low 31 | out (RS232_DTA),a 32 | 33 | ;; send the start bit 34 | ld bc,#0x01ff ; b=0x01, c=0xff 35 | ld a,c 36 | ld d,(hl) ; byte to transfer to d 37 | out (RS232_DTA),a ; start bit 38 | 39 | ;; start sending out bits... 40 | srl d ; LSB to carry... 41 | rla ; ...and to LSB of a 42 | xor b ; negate bit 0 43 | out (RS232_DTA),a ; out bit 44 | 45 | srl d 46 | rla 47 | xor b 48 | out (RS232_DTA),a 49 | 50 | srl d 51 | rla 52 | xor b 53 | out (RS232_DTA),a 54 | 55 | srl d 56 | rla 57 | xor b 58 | out (RS232_DTA),a 59 | 60 | srl d 61 | rla 62 | xor b 63 | out (RS232_DTA),a 64 | 65 | srl d 66 | rla 67 | xor b 68 | out (RS232_DTA),a 69 | 70 | srl d 71 | rla 72 | xor b 73 | out (RS232_DTA),a 74 | 75 | srl d 76 | rla 77 | xor b 78 | out (RS232_DTA),a 79 | 80 | ;; emit stop bit 81 | ld a,#0xfe ; load a with stop bit 82 | inc hl 83 | out (RS232_DTA),a ; emit stop bit 84 | out (RS232_DTA),a ; second stop bit 85 | 86 | ;; fuse hack, bit 12 must be 1 87 | ld a,#0xff 88 | out (RS232_DTA),a ; retransmit stop bit 3 times for FUSE 89 | 90 | ld l,#RESULT_SUCCESS ; report success 91 | 92 | ei 93 | ret 94 | 95 | -------------------------------------------------------------------------------- /os/ram/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * list.c 3 | * linked list 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #include "yx.h" 8 | 9 | /* 10 | * check if arg and pointer are equal 11 | */ 12 | byte list_match_eq(list_header_t *p, word arg) { 13 | return ( ((word)p) == arg ); 14 | } 15 | 16 | /* 17 | * find element using match function 18 | * this can be used for all sorts of tasks, for example if you want to find last element 19 | * you seek for element which has element->next==NULL 20 | */ 21 | list_header_t* list_find( 22 | list_header_t *first, 23 | list_header_t **prev, 24 | byte ((*match)(list_header_t *p, word arg)), 25 | word the_arg) 26 | { 27 | /* assume no previous */ 28 | *prev=NULL; 29 | while (first && !match(first,the_arg)) { 30 | *prev=first; 31 | first=first->next; 32 | } 33 | /* result is in first */ 34 | return first; 35 | } 36 | 37 | /* 38 | * insert element into linked list at begining 39 | */ 40 | list_header_t *list_insert(list_header_t** first, list_header_t *el) { 41 | el->next=*first; 42 | *first=el; 43 | return el; 44 | } 45 | 46 | /* 47 | * insert element into linked list at end 48 | */ 49 | list_header_t *list_append(list_header_t** first, list_header_t *el) { 50 | 51 | list_header_t *current; 52 | 53 | el->next=NULL; /* it's always the last element */ 54 | 55 | if (*first==NULL) /* empty list? */ 56 | *first=el; 57 | else { 58 | current=*first; 59 | while (current->next) current=current->next; 60 | current->next=el; 61 | } 62 | return el; 63 | } 64 | 65 | /* 66 | * removes element from linked list 67 | */ 68 | list_header_t *list_remove(list_header_t **first, list_header_t *el) { 69 | list_header_t *prev; 70 | if (el==*first) { 71 | *first=el->next; 72 | } else { 73 | if (!list_find(*first, &prev, list_match_eq, (word) el)) 74 | return NULL; 75 | else /* rewire */ 76 | prev->next=el->next; 77 | } 78 | return el; 79 | } 80 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/crt0.s: -------------------------------------------------------------------------------- 1 | ;; gdb monitor crt0.s for a Z80 2 | .module crt0 3 | .globl _main 4 | .globl _sr 5 | 6 | .area _HEADER (ABS) 7 | ;; Reset vector 8 | .org 0x0000 9 | di 10 | jp init 11 | .db 0,0,0,0 12 | 13 | ;; RST 08 14 | push hl 15 | ld hl,#0x08 16 | jp _sr 17 | .db 0 18 | 19 | ;; rst 10 20 | push hl 21 | ld hl,#0x10 22 | jp _sr 23 | .db 0 24 | 25 | ;; rst 18 26 | push hl 27 | ld hl,#0x18 ;; RST 18, used for breakpoints 28 | jp _sr ;; 18 means a breakpoint was hit, pass it to sr routine 29 | .db 0 30 | 31 | ;; rst 20 32 | push hl 33 | ld hl,#0x20 34 | jp _sr 35 | .db 0 36 | 37 | ;; rst 28 38 | push hl 39 | ld hl,#0x28 40 | jp _sr 41 | .db 0 42 | 43 | ;; rst 30 44 | push hl 45 | ld hl,#0x30 46 | jp _sr 47 | .db 0 48 | 49 | ;; rst 38 50 | reti 51 | .dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 52 | 53 | ;; NMI 54 | push hl 55 | ld hl,#0x66 56 | jp _sr 57 | 58 | init: 59 | ;; Stack at the top of memory. 60 | ld sp, #0x6000 61 | 62 | ;; Initialise global variables 63 | call gsinit 64 | call _main 65 | 66 | ei ; enable interrupts. 67 | jp _exit 68 | 69 | ;; Ordering of segments for the linker. 70 | .area _HOME 71 | .area _CODE 72 | .area _GSINIT 73 | .area _GSFINAL 74 | 75 | .area _DATA 76 | .area _BSS 77 | .area _HEAP 78 | 79 | 80 | .area _CODE 81 | __clock:: 82 | ld a,#2 83 | rst 0x18 84 | ret 85 | 86 | _exit:: 87 | ;; Exit - special code to the emulator 88 | ld a,#0 89 | rst 0x18 90 | 1$: 91 | halt 92 | jr 1$ 93 | 94 | .area _GSINIT 95 | gsinit:: 96 | 97 | .area _GSFINAL 98 | ret 99 | 100 | -------------------------------------------------------------------------------- /buddy/graphics/clipping.s: -------------------------------------------------------------------------------- 1 | ;; clipping.s 2 | ;; clipping utility routines 3 | ;; 4 | ;; tomaz stih, tue jun 9 2015 5 | .module clipping 6 | 7 | .globl _clip_offset 8 | 9 | .area _CODE 10 | 11 | ;;void clip_offset(byte ofsx, byte ofsy, byte* maskin, byte* maskout) 12 | _clip_offset:: 13 | pop hl ; return address 14 | exx ; alt. set 15 | pop bc ; c'=ofsx, b'=ofsy 16 | pop hl ; hl'=maskin 17 | pop de ; de'=maskout 18 | ;; restore stack, ignore order 19 | push bc 20 | push hl 21 | push de 22 | ;; raw clip offset. 23 | ;; NOTES: alt reg set on 24 | ;; this function takes 8x8 bits array and 25 | ;; shifts it horizontally and vertically 26 | ;; by ofsx and ofsy arguments 27 | _clip_offset_raw:: 28 | ld a,b ; ofsy 29 | cp #0 ; finished? 30 | jr nz,_cof_1part 31 | ;; just copy data to maskout 32 | push bc 33 | ld bc,#8 34 | ldir 35 | pop bc 36 | _cof_rot: ;; do the rotate 37 | dec de 38 | dec de 39 | dec de 40 | dec de 41 | dec de 42 | dec de 43 | dec de 44 | dec de 45 | ld a,c ; a=rotate counter 46 | cp #0 ; no rotation? 47 | jr z,_cof_theend ; we're done 48 | ;; we'll need to rotate 49 | ld h,#8 ; 8 rows 50 | _cof_row: 51 | ld b,c ; number of rotations to b 52 | ld a,(de) ; value to a 53 | _cof_col: ;; do the actual rotation 54 | rlca 55 | djnz _cof_col 56 | ld (de),a ; rotated value back 57 | inc de 58 | dec h 59 | jr nz,_cof_row ; next row 60 | jr _cof_theend 61 | _cof_1part: 62 | inc hl 63 | dec a 64 | jr nz,_cof_1part 65 | ;; de points to correct byte, copy 1st half 66 | ;; b=ofsy 67 | ld a,#8 68 | sub b 69 | ld b,a ; first half offses 70 | _cof_1p_cont: 71 | ld a,(hl) 72 | ld (de),a 73 | inc hl 74 | inc de 75 | djnz _cof_1p_cont 76 | 77 | ;; de value is correct, hl is destroyed 78 | pop hl ; get de but ignore it 79 | pop hl ; get real hl 80 | pop bc ; all counters are back 81 | push bc 82 | push hl 83 | push hl ; stack restored 84 | _cof_2part: 85 | ld a,(hl) 86 | ld (de),a 87 | inc hl 88 | inc de 89 | djnz _cof_2part 90 | ;; shift 'em all 91 | jr _cof_rot 92 | _cof_theend: ;; the very end. 93 | exx ; back to normal set 94 | push hl ; ret. address 95 | ret 96 | -------------------------------------------------------------------------------- /tools/rawserial/putraw.c: -------------------------------------------------------------------------------- 1 | // Compile with 2 | // gcc -o putraw putraw.c 3 | 4 | #include /* Standard input/output definitions */ 5 | #include /* Standard library */ 6 | #include /* String function definitions */ 7 | #include /* UNIX standard function definitions */ 8 | #include /* File control definitions */ 9 | #include /* Error number definitions */ 10 | #include /* POSIX terminal control definitions */ 11 | #include 12 | 13 | int open_port(char *device) 14 | { 15 | int fd; 16 | struct termios options; 17 | 18 | fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); 19 | if (fd != -1) { /* Configure port */ 20 | fcntl(fd, F_SETFL, 0); 21 | tcgetattr(fd, &options); 22 | 23 | /* Baud rate for input and output is 115200 or 57600, doesn't work faster */ 24 | cfsetispeed(&options, B57600); 25 | cfsetospeed(&options, B57600); 26 | 27 | options.c_cflag &= ~PARENB; /* No parity */ 28 | options.c_cflag |= CSTOPB; /* Two stop bits! */ 29 | options.c_cflag &= ~CSIZE; /* Mask char size bits */ 30 | options.c_cflag |= CRTSCTS; /* Enable rts cts */ 31 | options.c_cflag |= CS8; /* 8 bit */ 32 | options.c_oflag &= ~OPOST; /* Raw */ 33 | 34 | /* Apply settings now! */ 35 | tcsetattr(fd, TCSANOW, &options); 36 | } 37 | return (fd); 38 | } 39 | 40 | /* Send bytes using manual CTS/RTS */ 41 | void sendbytes(int fd, void *bytes, int len) { 42 | write(fd,bytes,len); 43 | } 44 | 45 | int main(int argc, char **argv) { 46 | 47 | // Check arguments 48 | if (argc!=3) { 49 | printf("usage: putraw \n"); 50 | return 1; 51 | } 52 | 53 | int fd=open_port(argv[1]); 54 | if (fd==-1) { 55 | printf("unable to open device %s\n",argv[1]); 56 | return 2; 57 | } 58 | 59 | /* Get the file */ 60 | unsigned short datalen; 61 | struct stat st; 62 | stat(argv[2], &st); 63 | datalen = st.st_size; 64 | unsigned char *pblock=malloc(datalen); 65 | int ofd=open(argv[2], O_RDONLY|O_SYNC); 66 | int bytes=read(ofd,(void *)pblock,datalen); 67 | printf("Read file %s, length %d\n",argv[2],bytes); 68 | close(ofd); 69 | 70 | /* and file... */ 71 | sendbytes(fd,pblock,datalen); 72 | 73 | printf("Sent bytes %d\n",bytes); 74 | 75 | /* Close serial port */ 76 | close(fd); 77 | 78 | /* Free memory */ 79 | free(pblock); 80 | 81 | printf("The end\n"); 82 | } 83 | -------------------------------------------------------------------------------- /tools/rawserial/getraw.c: -------------------------------------------------------------------------------- 1 | // Compile with 2 | // gcc -o getraw getraw.c 3 | 4 | #include /* Standard input/output definitions */ 5 | #include /* Standard library */ 6 | #include /* String function definitions */ 7 | #include /* UNIX standard function definitions */ 8 | #include /* File control definitions */ 9 | #include /* Error number definitions */ 10 | #include /* POSIX terminal control definitions */ 11 | 12 | int open_port(char *device) 13 | { 14 | int fd; 15 | struct termios options; 16 | 17 | fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); 18 | if (fd != -1) { /* Configure port */ 19 | fcntl(fd, F_SETFL, 0); 20 | tcgetattr(fd, &options); 21 | 22 | /* Baud rate for input and output */ 23 | cfsetispeed(&options, B115200); 24 | cfsetospeed(&options, B115200); 25 | 26 | options.c_cflag &= ~PARENB; /* No parity */ 27 | options.c_cflag &= ~CSTOPB; /* One stop bit */ 28 | options.c_cflag &= ~CSIZE; /* Mask char side bits */ 29 | options.c_cflag |= CS8; /* 8 bit */ 30 | options.c_cflag |= CRTSCTS; /* RTS CTS handshake */ 31 | options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* Raw */ 32 | 33 | /* Apply settings now! */ 34 | tcsetattr(fd, TCSANOW, &options); 35 | } 36 | return (fd); 37 | } 38 | 39 | void read_block(int fd, void *p,int len) { 40 | int bytes; 41 | int totalbytes=0; 42 | while (len) { 43 | bytes=read(fd,p,len); 44 | totalbytes+=bytes; 45 | p+=bytes; 46 | len-=bytes; 47 | printf("read %d bytes, total %d\n",bytes,totalbytes); 48 | } 49 | } 50 | 51 | int main(int argc, char **argv) { 52 | 53 | // Check arguments 54 | if (argc!=4) { 55 | printf("usage: getraw \n"); 56 | return 1; 57 | } 58 | 59 | int fd=open_port(argv[1]); 60 | if (fd==-1) { 61 | printf("unable to open device %s\n",argv[1]); 62 | return 2; 63 | } 64 | 65 | /* Get length */ 66 | int datalen=atoi(argv[3]); 67 | printf ("writing to %s, datalen %d\n",argv[2],datalen); 68 | 69 | /* and data block... */ 70 | unsigned char *pblock=malloc(datalen); 71 | read_block(fd, (void*)pblock,datalen); 72 | 73 | int ofd=open(argv[2], O_RDWR|O_CREAT); 74 | write(ofd,(void *)pblock,datalen); 75 | close(ofd); 76 | printf("file %s saved\n", argv[2]); 77 | 78 | /* Close serial port */ 79 | close(fd); 80 | 81 | /* Free memory */ 82 | free(pblock); 83 | 84 | } 85 | -------------------------------------------------------------------------------- /buddy/os/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * list.c 3 | * linked list 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #include "list.h" 8 | 9 | /* 10 | * check if arg and pointer are equal 11 | */ 12 | byte list_match_eq(list_header_t *p, word arg) { 13 | return ( ((word)p) == arg ); 14 | } 15 | 16 | /* 17 | * find element using match function 18 | * this can be used for all sorts of tasks, for example if you want to find last element 19 | * you seek for element which has element->next==NULL 20 | */ 21 | list_header_t* list_find( 22 | list_header_t *first, 23 | list_header_t **prev, 24 | byte ((*match)(list_header_t *p, word arg)), 25 | word the_arg) 26 | { 27 | /* assume no previous */ 28 | *prev=NULL; 29 | while (first && !match(first,the_arg)) { 30 | *prev=first; 31 | first=first->next; 32 | } 33 | /* result is in first */ 34 | return first; 35 | } 36 | 37 | /* 38 | * insert element into linked list at begining 39 | */ 40 | list_header_t *list_insert(list_header_t** first, list_header_t *el) { 41 | el->next=*first; 42 | *first=el; 43 | return el; 44 | } 45 | 46 | /* 47 | * insert element into linked list at end 48 | */ 49 | list_header_t *list_append(list_header_t** first, list_header_t *el) { 50 | 51 | list_header_t *current; 52 | 53 | el->next=NULL; /* it's always the last element */ 54 | 55 | if (*first==NULL) /* empty list? */ 56 | *first=el; 57 | else { 58 | current=*first; 59 | while (current->next) current=current->next; 60 | current->next=el; 61 | } 62 | return el; 63 | } 64 | 65 | /* 66 | * removes element from linked list 67 | */ 68 | list_header_t *list_remove(list_header_t **first, list_header_t *el) { 69 | list_header_t *prev; 70 | if (el==*first) { 71 | *first=el->next; 72 | } else { 73 | if (!list_find(*first, &prev, list_match_eq, (word) el)) 74 | return NULL; 75 | else /* rewire */ 76 | prev->next=el->next; 77 | } 78 | return el; 79 | } 80 | 81 | /* 82 | * remove first element from linked list 83 | */ 84 | list_header_t *list_remove_first(list_header_t **first) { 85 | list_header_t *result; 86 | if (*first==NULL) return NULL; /* empty list */ 87 | result=*first; 88 | *first = (list_header_t*) ((*first)->next); 89 | return result; 90 | } 91 | -------------------------------------------------------------------------------- /os/rom/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * list.c 3 | * linked list 4 | * 5 | * tomaz stih tue jun 5 2012 6 | */ 7 | #include "types.h" 8 | #include "list.h" 9 | 10 | /* 11 | * check if arg and pointer are equal 12 | */ 13 | byte list_match_eq(list_header_t *p, word arg) { 14 | return ( ((word)p) == arg ); 15 | } 16 | 17 | /* 18 | * find element using match function 19 | * this can be used for all sorts of tasks, for example if you want to find last element 20 | * you seek for element which has element->next==NULL 21 | */ 22 | list_header_t* list_find( 23 | list_header_t *first, 24 | list_header_t **prev, 25 | byte ((*match)(list_header_t *p, word arg)), 26 | word the_arg) 27 | { 28 | /* assume no previous */ 29 | *prev=NULL; 30 | while (first && !match(first,the_arg)) { 31 | *prev=first; 32 | first=first->next; 33 | } 34 | /* result is in first */ 35 | return first; 36 | } 37 | 38 | /* 39 | * insert element into linked list at begining 40 | */ 41 | list_header_t *list_insert(list_header_t** first, list_header_t *el) { 42 | el->next=*first; 43 | *first=el; 44 | return el; 45 | } 46 | 47 | /* 48 | * insert element into linked list at end 49 | */ 50 | list_header_t *list_append(list_header_t** first, list_header_t *el) { 51 | 52 | list_header_t *current; 53 | 54 | el->next=NULL; /* it's always the last element */ 55 | 56 | if (*first==NULL) /* empty list? */ 57 | *first=el; 58 | else { 59 | current=*first; 60 | while (current->next) current=current->next; 61 | current->next=el; 62 | } 63 | return el; 64 | } 65 | 66 | /* 67 | * removes element from linked list 68 | */ 69 | list_header_t *list_remove(list_header_t **first, list_header_t *el) { 70 | list_header_t *prev; 71 | if (el==*first) { 72 | *first=el->next; 73 | } else { 74 | if (!list_find(*first, &prev, list_match_eq, (word) el)) 75 | return NULL; 76 | else /* rewire */ 77 | prev->next=el->next; 78 | } 79 | return el; 80 | } 81 | 82 | /* 83 | * remove first element from linked list 84 | */ 85 | list_header_t *list_remove_first(list_header_t **first) { 86 | list_header_t *result; 87 | if (*first==NULL) return NULL; /* empty list */ 88 | result=*first; 89 | *first = (list_header_t*) ((*first)->next); 90 | return result; 91 | } 92 | -------------------------------------------------------------------------------- /tools/relocator/relocator.cpp: -------------------------------------------------------------------------------- 1 | // relocator.cpp 2 | // compare two binary files compiled to different 3 | // addresses (i.e. 0x0000 and 0x0101) and output 4 | // differences (i.e. relocation table). 5 | // 6 | // notes: build: g++ -o relocator.exe relocator.cpp 7 | // 8 | // tomaz stih mon oct 21 2013 9 | #include 10 | #include 11 | #include // std::ifstream 12 | #include 13 | 14 | using namespace std; 15 | 16 | int compare_files(const std::string &filename1, const std::string &filename2) { 17 | 18 | int size1, size2; 19 | ifstream first, second; 20 | first.open(filename1.c_str(), ios::in | ios::binary); 21 | second.open(filename2.c_str(), ios::in | ios::binary); 22 | vector *rel_table=new vector(); 23 | 24 | // Size must be the same. 25 | first.seekg (0, first.end); 26 | size1= first.tellg(); 27 | first.seekg (0, first.beg); 28 | 29 | second.seekg (0, second.end); 30 | size2= second.tellg(); 31 | second.seekg (0, second.beg); 32 | 33 | if (size1==size2) { 34 | int pos=0; 35 | int prev=-1; 36 | char *b1=new char[size1]; 37 | char *b2=new char[size2]; 38 | first.read(b1,size1); 39 | second.read(b2,size2); 40 | while (pos0 && prev+1==pos) { // Its high byte of word 43 | } else { 44 | if (pos + 1 < size1) { // It must not be the last byte! 45 | // Make sure you write low byte first. 46 | char lo, hi; 47 | lo=pos&0x00FF; 48 | hi=(pos>>8)&0x00FF; 49 | rel_table->push_back(lo); 50 | rel_table->push_back(hi); 51 | } 52 | prev=pos; 53 | } 54 | } 55 | pos++; 56 | } 57 | delete[] b1; 58 | delete[] b2; 59 | 60 | int total_entries=rel_table->size() / 2; 61 | char lo, hi; 62 | lo=total_entries&0x00FF; 63 | hi=(total_entries>>8)&0x00FF; 64 | cout << lo << hi; 65 | 66 | for (int n=0;nsize();n++) { 67 | cout << rel_table->at(n); 68 | } 69 | } // if (size1==size2) 70 | else cerr << "size should be the same" << endl; 71 | 72 | delete rel_table; 73 | 74 | first.close(); 75 | second.close(); 76 | } 77 | 78 | int main(int argc, char *argv[]) 79 | { 80 | if (argc!=3) { 81 | cerr << "invalid command line parameter" << endl << "usage: relocator " << endl; 82 | return 1; 83 | } 84 | compare_files(argv[1], argv[2]); 85 | return 0; 86 | } -------------------------------------------------------------------------------- /os/ram/ssend115k.s: -------------------------------------------------------------------------------- 1 | ;; ssend115k.s 2 | ;; rs232 send @ 115.200-8-N-2 baud 3 | ;; 4 | ;; tomaz stih, thu aug 2 2012 5 | 6 | .module ssend115k 7 | .globl _rs232_putb 8 | 9 | ;; consts 10 | RS232_CTL = 0xef 11 | RS232_DTA = 0xf7 12 | CTS_ON = 0xff 13 | CTS_OFF = 0xef 14 | RESULT_SUCCESS = 0x00 15 | 16 | .area _CODE 17 | 18 | _rs232_putb:: 19 | ;; delay between bits must be 20 | ;; 30.3819 t-states (= 3.500.000 / 115.200) 21 | call _di ; no interrupts for precise timing 22 | 23 | ;; get byte ptr from stack 24 | ld hl,#0x0000 25 | add hl,sp 26 | inc hl 27 | inc hl ; hl points to byte to send 28 | 29 | ;; make sure CTS is off (just to make sure) 30 | ld a,#CTS_OFF 31 | out (RS232_CTL),a 32 | 33 | ;; 1. Send the start bit 34 | ld bc,#0x01ff ; b=0x01, c=0xff | 10 t-states 35 | ld a,c ; 4 t-states 36 | ld d,(hl) ; byte to transfer to d | 7 t-states 37 | out (RS232_DTA),a ; start bit | 11 t-states 38 | 39 | ;; 2. start sending out bits... 40 | srl d ; LSB to carry... | 8 t-states 41 | rla ; ...and to LSB of a | 4 t-states 42 | xor b ; negate bit 0 | 4 t-states 43 | nop ; 4 t-states 44 | out (RS232_DTA),a ; out bit | 11 t-states 45 | ;; 31 t-states...should do */ 46 | 47 | srl d 48 | rla 49 | xor b 50 | nop 51 | out (RS232_DTA),a 52 | 53 | srl d 54 | rla 55 | xor b 56 | nop 57 | out (RS232_DTA),a 58 | 59 | srl d 60 | rla 61 | xor b 62 | nop 63 | out (RS232_DTA),a 64 | 65 | srl d 66 | rla 67 | xor b 68 | nop 69 | out (RS232_DTA),a 70 | 71 | srl d 72 | rla 73 | xor b 74 | nop 75 | out (#0xf7),a 76 | 77 | srl d 78 | rla 79 | xor b 80 | nop 81 | out (RS232_DTA),a 82 | 83 | srl d 84 | rla 85 | xor b 86 | nop 87 | out (RS232_DTA),a 88 | 89 | ;; 3. emit stop bit 90 | ld a,#0xfe ; load a with stop bit | 7 t-states 91 | inc hl ; 6 t-states 92 | nop ; 4 t-states 93 | out (RS232_DTA),a ; emit stop bit || 11 t-states 94 | 95 | ;; what about stop bit duration? 96 | ;; sending start bit takes 31 t-states so even if 97 | ;; one _rs232_write is called after another there is still enough mark time... */ 98 | 99 | ld l,#RESULT_SUCCESS ; report success 100 | 101 | call _ei 102 | ret 103 | 104 | -------------------------------------------------------------------------------- /tools/zxserial/specget.c: -------------------------------------------------------------------------------- 1 | // Compile with 2 | // gcc -o specget specget.c 3 | 4 | #include /* Standard input/output definitions */ 5 | #include /* Standard library */ 6 | #include /* String function definitions */ 7 | #include /* UNIX standard function definitions */ 8 | #include /* File control definitions */ 9 | #include /* Error number definitions */ 10 | #include /* POSIX terminal control definitions */ 11 | 12 | int open_port(char *device) 13 | { 14 | int fd; 15 | struct termios options; 16 | 17 | fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); 18 | if (fd != -1) { /* Configure port */ 19 | fcntl(fd, F_SETFL, 0); 20 | tcgetattr(fd, &options); 21 | 22 | /* Baud rate for input and output */ 23 | cfsetispeed(&options, B2400); 24 | cfsetospeed(&options, B2400); 25 | 26 | options.c_cflag &= ~PARENB; /* No parity */ 27 | options.c_cflag &= ~CSTOPB; /* One stop bit */ 28 | options.c_cflag &= ~CSIZE; /* Mask char side bits */ 29 | options.c_cflag |= CS8; /* 8 bit */ 30 | options.c_cflag |= CRTSCTS; /* RTS CTS handshake */ 31 | options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* Raw */ 32 | 33 | /* Apply settings now! */ 34 | tcsetattr(fd, TCSANOW, &options); 35 | } 36 | return (fd); 37 | } 38 | 39 | void read_block(int fd, void *p,int len) { 40 | int bytes; 41 | while (len) { 42 | bytes=read(fd,p,len); 43 | p+=bytes; 44 | len-=bytes; 45 | } 46 | } 47 | 48 | int main(int argc, char **argv) { 49 | 50 | // Check arguments 51 | if (argc!=3) { 52 | printf("usage: specget \n"); 53 | return 1; 54 | } 55 | 56 | int fd=open_port(argv[1]); 57 | if (fd==-1) { 58 | printf("unable to open device %s\n",argv[1]); 59 | return 2; 60 | } 61 | 62 | /* Get file type (byte 1) */ 63 | unsigned char type; 64 | read(fd,&type,1); 65 | 66 | /* Get data len */ 67 | unsigned short datalen; 68 | read(fd,&datalen,2); 69 | 70 | printf("received zx header\n\ttype=%d\n\tsize=%d\n",type,datalen); 71 | 72 | /* Get two parameters */ 73 | unsigned short par1,par2; 74 | read(fd,&par1,2); 75 | read(fd,&par2,2); 76 | 77 | printf("parameters\n\tpar1=%d\n\tpar2=%d\n",par1,par2); 78 | 79 | /* and data block... */ 80 | unsigned char *pblock=malloc(datalen); 81 | read_block(fd, (void*)pblock,datalen); 82 | 83 | int ofd=open(argv[2], O_RDWR|O_CREAT); 84 | write(ofd,(void *)pblock,datalen); 85 | close(ofd); 86 | printf("file saved\n"); 87 | 88 | /* Close serial port */ 89 | close(fd); 90 | 91 | /* Free memory */ 92 | free(pblock); 93 | 94 | } 95 | -------------------------------------------------------------------------------- /os/ram/todo/datalink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * datalink.c 3 | * data link protocol 4 | * 5 | * tomaz stih tue jul 31 2012 6 | */ 7 | #include "main.h" 8 | 9 | byte dl_next_response=DL_ACK; /* next response, assume ack */ 10 | byte dl_oseq=1, dl_iseq=0; /* input and output sequence number */ 11 | dl_link_t *dl_link_first=NULL; /* pointer to first link */ 12 | 13 | /* 14 | * connect to datalink 15 | */ 16 | dl_link_t *dl_link_connect(void *owner, word ibuffer_size) { 17 | 18 | dl_link_t *l; 19 | 20 | if ( l = (dl_link_t *)syslist_add((void **)&dl_link_first, sizeof(dl_link_t), owner) ) { 21 | /* populate link */ 22 | l->pending_reads=NULL; 23 | l->pending_writes=NULL; 24 | } 25 | 26 | return l; 27 | } 28 | 29 | /* 30 | * disconnect from data link 31 | */ 32 | dl_link_t *dl_link_disconnect(dl_link_t *l) { 33 | return (dl_link_t *)syslist_delete((void **)&dl_link_first, (void *)l); 34 | } 35 | 36 | #ifdef _YES 37 | result dl_loop() { 38 | 39 | result oresult, iresult: 40 | 41 | dl_frame_header_t ofhdr, ifhdr; 42 | dl_frame_body_t ofbody, ifbody; 43 | 44 | /* 45 | * first send data 46 | */ 47 | ofhdr.sequence=dl_oseq; /* current sequence */ 48 | if (que_is_empty(iq)) { /* no data to send */ 49 | ofhdr.response=dl_next_response | DL_YOU; /* create a "you" block */ 50 | oresult = dl_send(&ofhdr,NULL, DL_TIMEOUT_HEADER); 51 | } else { 52 | ofhdr.response=dl_next_response & (~DL_YOU); /* not a "you" block */ 53 | que_peek_bytes(iq, ofbody.data, FRAME_LEN, &(obody.size)); 54 | oresult = dl_send(&ofhdr,&ofbody, DL_TIMEOUT_HEADER + DL_TIMEOUT_BODY); 55 | } 56 | 57 | /* TODO: what if? */ 58 | if (oresult==RESULT_DL_TIMEOUT) { 59 | } 60 | 61 | /* 62 | * now receive data 63 | */ 64 | iresult = dl_receive(&ifhdr, sizeof(dl_frame_header_t), DL_TIMEOUT_HEADER); 65 | if (iresult==RESULT_SUCCESS) { /* got header */ 66 | if (ifhdr.response & DL_ACK) { /* conclude previous block !!! */ 67 | dl_oseq++; /* increase output sequence */ 68 | que_consume_bytes(iq,obody.size); 69 | } 70 | if (!(ifhdr.response & DL_YES)) { 71 | iresult = dl_receive(&ifbody, sizeof(dl_frame_body_t), DL_TIMEOUT_BODY); 72 | if (iresult==RESULT_SUCCESS) { 73 | if (dl_check_data(&ifbody)) { 74 | dl_next_response=DL_ACK; 75 | que_append(oq, ifbody.data, ifbody.size); 76 | } else { 77 | dl_next_response=DL_NAK; 78 | } 79 | } else 80 | dl_next_response=DL_NAK; /* request resend */ 81 | } 82 | } 83 | } 84 | 85 | void dl_send(dl_frame_header_t *hdr, dl_frame_body_t *body) { 86 | /* calc crc */ 87 | } 88 | #endif 89 | -------------------------------------------------------------------------------- /buddy/graphics/glyph.s: -------------------------------------------------------------------------------- 1 | ;; glyph.s 2 | ;; fast font routines 3 | ;; 4 | ;; tomaz stih, thu apr 23 2015 5 | .module glyph 6 | 7 | .globl cur_classic 8 | 9 | 10 | .area _CODE 11 | 12 | ;; put glyph of font at x,y 13 | ;; input: b=y, c=x, hl=font, a=char 14 | ;; output: hl=0 (success), hl=1 (fontgen error) 15 | gyh_putxy:: 16 | ; first get font info 17 | push hl 18 | ; alternate set for in-font calculations 19 | ex af,af' 20 | exx 21 | pop hl 22 | ld a,(hl) ; get font generation/offset to raw data 23 | inc hl 24 | ld d,(hl) ; get first ascii 25 | inc hl 26 | ld e,(hl) ; get last ascii 27 | inc hl 28 | ; hl=font address (for fixed8x8 generation, i.e. gen 3) 29 | cp #3 30 | jr z,gyh_hl_fstart 31 | ld b,(hl) ; b=bytes per glyph line 32 | inc hl 33 | ld c,(hl) ; c=glyph lines 34 | inc hl 35 | ; advance to gen. 7 start 36 | inc hl 37 | inc hl 38 | cp #7 39 | jr z,gyh_hl_fstart 40 | ; font generation unknown 41 | exx 42 | ex af,af' 43 | ld hl,#1 ; error! 44 | ret 45 | ; hl'=font start 46 | ; de'=first and last ascii 47 | ; bc'=bytes per glyph line and glyph lines 48 | ; a=char 49 | gyh_hl_fstart: 50 | push hl ; store font start 51 | ex af,af' 52 | cp d ; char=char-first ascii 53 | jr c,gyh_out_bounds 54 | cp e ; last char 55 | jr z,gyh_bounds_ok ; still fine 56 | jr nc,gyh_out_bounds 57 | gyh_bounds_ok: 58 | ; de' is now free 59 | sub d ; a=a-first char ascii 60 | ld e,a ; store a 61 | ld a,b ; a=bytes per glyph line 62 | cp #1 ; is 1 byte glyph? 63 | jr z,gyh_bytes_1 64 | cp #2 ; is 2 byte glyph 65 | jr z,gyh_bytes_2 66 | ; error!!! 67 | pop hl ; clear stack 68 | exx 69 | ld hl,#3 ; error! 70 | ret 71 | gyh_bytes_1: 72 | ld a,c 73 | jr gyh_charoff 74 | gyh_bytes_2: 75 | ld a,c ; glyph lines to a 76 | sla a ; a=a*2 77 | gyh_charoff: ; a is glyph lines * bytes per glyph line 78 | ; e is char nr. 79 | ; hl = de * a 80 | push bc ; store bytes per glyph and glyph lines 81 | ld d,#0 ; de=0 based char 82 | ld hl,#0 ; use HL to store the product 83 | ld b,#8 ; eight bits to check 84 | gyh_mul: 85 | add hl,hl 86 | rlca ; check MSB of a 87 | jr nc,gyh_mul_skip ; if zero, skip addition 88 | add hl,de 89 | gyh_mul_skip: 90 | djnz gyh_mul 91 | pop bc ; bytes per glyph and glyph lines 92 | pop de ; de=font start 93 | add hl,de ; hl=char start 94 | jr gyh_put 95 | gyh_out_bounds: 96 | pop hl ; clear stack 97 | exx 98 | ld hl,#2 ; error! 99 | ret 100 | gyh_put: ; hl'=actual glyph start 101 | ; stack bc'...byte bytes per glyph, glyph lines 102 | push hl ; glyph start to stack 103 | push bc ; bytes per glyph, glyph lines 104 | exx ; normal reg set. 105 | pop hl ; bytes per glyph, glyph lines 106 | pop de ; addr. to de 107 | call gyh_drawxy ; draw at x,y 108 | ret 109 | 110 | ;; draw glyph at x,y 111 | ;; input: b=y 112 | ;; c=x 113 | ;; de=glyph addr 114 | ;; h=bytes per glyph 115 | ;; l=glyph lines 116 | gyh_drawxy: 117 | ret 118 | -------------------------------------------------------------------------------- /os/ram/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memory.c 3 | * memory management (mem_allocate, mem_free) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #include "yx.h" 8 | 9 | /* 10 | * ---------- private (helpers) ---------- 11 | */ 12 | 13 | byte match_free_block(list_header_t *p, word size) { 14 | block_t *b = (block_t *)p; 15 | return !(b->stat&ALLOCATED) && b->size >= size; 16 | } 17 | 18 | void merge_with_next (block_t *b) { 19 | block_t *bnext=b->hdr.next; 20 | b->size += ( BLK_SIZE + bnext->size ); 21 | b->hdr.next = bnext->hdr.next; 22 | } 23 | 24 | void split ( block_t *b, word size) { 25 | block_t *nw; 26 | nw = (word)(b->data) + size; 27 | nw->hdr.next=b->hdr.next; 28 | nw->size = b->size - (size + BLK_SIZE); 29 | nw->hdr.owner=b->hdr.owner; 30 | nw->stat=b->stat; 31 | /* do not set owner and stat because 32 | they'll be populated later */ 33 | b->size = size; 34 | b->hdr.next = nw; 35 | } 36 | 37 | /* 38 | * ---------- public ---------- 39 | */ 40 | 41 | /* 42 | * initialize memory management 43 | * sample call: 44 | * user_heap=0x8000; 45 | * mem_init(user_heap, 0x8000); 46 | */ 47 | void mem_init(void *heap, word size) { 48 | block_t *first = (block_t *)heap; 49 | first->hdr.next = NULL; 50 | first->size = size - BLK_SIZE; 51 | first->hdr.owner = SYS; 52 | first->stat = NEW; 53 | } 54 | 55 | /* 56 | * allocate memory block for owner 57 | */ 58 | void *mem_allocate(void *heap, word size, void *owner) { 59 | 60 | block_t *prev; 61 | block_t *b; 62 | 63 | b = (block_t *)list_find((list_header_t *)heap, (list_header_t **)&prev, match_free_block, size); 64 | 65 | if (b) { 66 | if (b->size - size > BLK_SIZE + MIN_CHUNK_SIZE) 67 | split(b, size); 68 | b->hdr.owner=owner; 69 | b->stat=ALLOCATED; 70 | return b->data; 71 | } else 72 | return NULL; 73 | } 74 | 75 | /* 76 | * free memory block 77 | * TODO: should check ownership one day 78 | */ 79 | 80 | void *mem_free(void *heap, void *p) { 81 | 82 | block_t *prev; 83 | block_t *b; 84 | 85 | /* calculate block address from pointer */ 86 | b = (block_t *) ( (word)p - BLK_SIZE ); 87 | 88 | /* make sure it is a valid memory block by finding it */ 89 | if (list_find((list_header_t *)heap, (list_header_t **)&prev, list_match_eq, (word)b)) { 90 | b->hdr.owner=SYS; /* reclaim for the heap */ 91 | b->stat=NEW; 92 | /* 93 | * merge 3 blocks if possible 94 | */ 95 | if ( prev && !(prev->stat&ALLOCATED) ) { /* try previous */ 96 | merge_with_next(prev); 97 | b=prev; 98 | } 99 | if ( b->hdr.next && !(((block_t *)(b->hdr.next))->stat&ALLOCATED) ) /* try next */ 100 | merge_with_next(b); 101 | 102 | return b->data; 103 | } else 104 | return NULL; 105 | } 106 | -------------------------------------------------------------------------------- /os/rom/font6x6.s: -------------------------------------------------------------------------------- 1 | ;; font6x6.s 2 | ;; system font 6x6 3 | ;; 4 | ;; note: first ascii is 32, last ascii is 127 5 | ;; there are total 96 chars size 6x6 6 | ;; each char is aligned to byte hence 7 | ;; there are 4 unused bits at the end 8 | ;; of every char as 6x6=36 bits is needed 9 | ;; and 40 bits is used per char. 10 | ;; total "free" space is 48 bytes. 11 | ;; 12 | ;; tomaz stih, thu aug 27 2015 13 | .module font6x6 14 | 15 | .globl _con_font6x6 16 | 17 | .area _CODE 18 | _con_font6x6:: 19 | .byte 0, 0, 0, 0, 0, 32, 130, 0 20 | .byte 32, 0, 73, 32, 0, 0, 0, 83 21 | .byte 229, 62, 80, 0, 35, 238, 14, 248 22 | .byte 128, 203, 66, 22, 152, 0, 98, 143 23 | .byte 40, 216, 0, 32, 128, 0, 0, 0 24 | .byte 33, 4, 16, 32, 0, 32, 65, 4 25 | .byte 32, 0, 34, 167, 42, 32, 0, 0 26 | .byte 2, 28, 32, 0, 0, 0, 0, 33 27 | .byte 0, 0, 0, 62, 0, 0, 0, 0 28 | .byte 0, 32, 0, 8, 66, 16, 128, 0 29 | .byte 114, 106, 178, 112, 0, 33, 130, 8 30 | .byte 112, 0, 112, 39, 32, 248, 0, 114 31 | .byte 35, 34, 112, 0, 49, 73, 62, 16 32 | .byte 0, 250, 15, 2, 240, 0, 114, 15 33 | .byte 34, 112, 0, 248, 33, 8, 32, 0 34 | .byte 114, 39, 34, 112, 0, 114, 39, 130 35 | .byte 112, 0, 0, 2, 0, 32, 0, 0 36 | .byte 2, 0, 33, 0, 0, 2, 16, 32 37 | .byte 0, 0, 15, 128, 248, 0, 0, 2 38 | .byte 4, 32, 0, 114, 35, 0, 32, 0 39 | .byte 114, 235, 160, 120, 0, 114, 40, 190 40 | .byte 136, 0, 242, 47, 34, 240, 0, 114 41 | .byte 40, 34, 112, 0, 242, 40, 162, 240 42 | .byte 0, 250, 15, 32, 248, 0, 250, 15 43 | .byte 32, 128, 0, 122, 11, 162, 120, 0 44 | .byte 138, 47, 162, 136, 0, 112, 130, 8 45 | .byte 112, 0, 8, 32, 162, 112, 0, 138 46 | .byte 78, 36, 136, 0, 130, 8, 32, 248 47 | .byte 0, 139, 106, 162, 136, 0, 139, 42 48 | .byte 166, 136, 0, 114, 40, 162, 112, 0 49 | .byte 242, 40, 188, 128, 0, 114, 42, 166 50 | .byte 120, 0, 242, 40, 188, 136, 0, 114 51 | .byte 7, 2, 240, 0, 248, 130, 8, 32 52 | .byte 0, 138, 40, 162, 112, 0, 138, 40 53 | .byte 148, 32, 0, 138, 42, 182, 136, 0 54 | .byte 137, 66, 20, 136, 0, 138, 39, 8 55 | .byte 32, 0, 248, 66, 16, 248, 0, 113 56 | .byte 4, 16, 112, 0, 129, 2, 4, 8 57 | .byte 0, 112, 65, 4, 112, 0, 33, 64 58 | .byte 0, 0, 0, 0, 0, 0, 248, 0 59 | .byte 64, 128, 0, 0, 0, 1, 200, 162 60 | .byte 120, 0, 131, 200, 162, 240, 0, 1 61 | .byte 200, 160, 120, 0, 9, 232, 162, 120 62 | .byte 0, 1, 201, 168, 120, 0, 24, 135 63 | .byte 8, 32, 0, 1, 232, 190, 11, 192 64 | .byte 131, 200, 162, 136, 0, 32, 6, 8 65 | .byte 112, 0, 32, 6, 8, 33, 0, 130 66 | .byte 74, 52, 136, 0, 96, 130, 8, 112 67 | .byte 0, 3, 202, 170, 168, 0, 3, 200 68 | .byte 162, 136, 0, 1, 200, 162, 112, 0 69 | .byte 3, 200, 162, 242, 0, 1, 232, 162 70 | .byte 120, 32, 2, 204, 160, 128, 0, 0 71 | .byte 230, 6, 240, 0, 33, 194, 8, 24 72 | .byte 0, 2, 40, 162, 120, 0, 2, 40 73 | .byte 148, 32, 0, 2, 42, 170, 80, 0 74 | .byte 1, 66, 20, 136, 0, 2, 40, 158 75 | .byte 11, 192, 3, 225, 24, 248, 0, 56 76 | .byte 142, 8, 56, 0, 32, 130, 8, 32 77 | .byte 0, 224, 131, 136, 224, 0, 41, 64 78 | .byte 0, 0, 0, 250, 46, 162, 248, 0 79 | -------------------------------------------------------------------------------- /tools/gdb2fuse/fuse_npipe.cpp: -------------------------------------------------------------------------------- 1 | #include "fuse_npipe.h" 2 | 3 | using namespace std; 4 | 5 | fuse_npipe* fuse_npipe::create(char *ifname, char *ofname) { 6 | 7 | cout << "opening named pipes..." << endl; 8 | 9 | // for writing first! 10 | cout << "\topening " << ofname << " for writing" << endl; 11 | int output=open(ofname,O_WRONLY); 12 | if (output==-1) { // error. 13 | cout << "\t\terror" << endl; 14 | return nullptr; 15 | } else 16 | cout << "\t\tok" << endl; 17 | 18 | // open file for reading, block. 19 | cout << "\topening " << ifname << " for reading" << endl; 20 | int input=open(ifname, O_RDONLY); 21 | if (input==-1) { 22 | cout << "\t\terror" << endl; 23 | close(output); // already opened. 24 | return nullptr; // error. 25 | } else 26 | cout << "\t\tok" << endl; 27 | 28 | // set as non-blocking for read commands. 29 | fcntl(input, F_SETFL, 30 | fcntl(input, F_GETFL) 31 | | O_NONBLOCK); 32 | cout << "\t\tset " << ifname << " to non-blocking mode" << endl; 33 | 34 | // if everything cool then create fuse_npipe and pass handles. 35 | fuse_npipe* fnp=new fuse_npipe(); 36 | fnp->ihandle=input; 37 | fnp->ohandle=output; 38 | 39 | return fnp; 40 | } 41 | 42 | fuse_npipe::~fuse_npipe() 43 | { 44 | // Close all pipe handles. 45 | cout << "closing named pipes" << endl; 46 | if (ihandle!=0) close(ihandle); 47 | if (ohandle!=0) close(ohandle); 48 | } 49 | 50 | int fuse_npipe::readbyte() { 51 | int b=0; 52 | int n=::read(ihandle,&b,1); 53 | if (n==0) { // pipe not opened on the other side 54 | return -2; 55 | } else if (n==EAGAIN) { // data not available 56 | return -1; 57 | } else if (n==1) { // success 58 | return b; 59 | } else { // error 60 | return -3; 61 | } 62 | } 63 | 64 | int fuse_npipe::read(char *buffer, int len) { 65 | int b=0; 66 | int n=0; 67 | while (n < len && b >= 0) { 68 | int result=readbyte(); 69 | switch(result) { 70 | case -3: // No more data avail. -3 71 | return n; 72 | case -2: // Pipe closed. 73 | if (n==0) 74 | return -1; // No data. 75 | else 76 | return n; // Last data. 77 | break; 78 | default: 79 | if (escaped) { 80 | if ((char)b=='*') buffer[n]=0; 81 | n++; 82 | } else if (result==0) { 83 | escaped=1; 84 | } else { 85 | buffer[n]=result; 86 | n++; 87 | } 88 | } 89 | } 90 | return n; 91 | } 92 | 93 | int fuse_npipe::write(char* buffer,int len) { 94 | static char esc0='*'; 95 | char b; 96 | int n=0; 97 | int result; 98 | while (n=0) 5 | { // Still rects to test? 6 | if (rect.IntersectsWith(_rects[i])) 7 | { 8 | // First get the intersect. 9 | Rectangle intersect; 10 | intersect = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height); 11 | intersect.Intersect(_rects[i]); 12 | 13 | if (_inters.Count == _interCount) return -1; 14 | _inters.Add(new InterRect() { Rectangle = intersect, Brush = _interBrushes[i] }); 15 | 16 | if (i > 0) // Not last rect? 17 | { 18 | // Now get all subrects. 19 | int n = 0; 20 | List subrects = new List(); 21 | SubRects(rect, intersect, subrects, ref n); 22 | if (n == 0) return i; 23 | 24 | // Remove rect that we already tested. 25 | int minDepth = i - 1; 26 | for (int j = 0; j < n; j++) minDepth = Math.Min(minDepth, FindAffected(subrects[j], i - 1)); 27 | i = minDepth; 28 | } 29 | else 30 | { 31 | return -1; 32 | } 33 | } 34 | else i--; // Test next rect. 35 | } 36 | return i; 37 | } 38 | 39 | 40 | /* 41 | 42 | w1=window_create( 43 | "Editor", 44 | window_desktop, 45 | WF_HASTITLE|WF_HASBORDER, 46 | app_wnd_proc, 47 | 2, 48 | 2, 49 | 80, 50 | 50); 51 | w2=window_create( 52 | "Clock", 53 | window_desktop, 54 | WF_HASTITLE|WF_HASBORDER, 55 | app_wnd_proc, 56 | 60, 57 | 35, 58 | 200, 59 | 160); 60 | 61 | window_draw(window_desktop); 62 | */ 63 | 64 | 65 | 66 | /* 67 | mouse_info_t mi; 68 | byte mx,my; 69 | 70 | byte curndx=0; 71 | void* cursors[]={ &cur_std, &cur_classic, &cur_hourglass, &cur_caret, &cur_hand }; 72 | 73 | window_init(); 74 | 75 | mouse_calibrate(SCREEN_MAXX>>1,SCREEN_MAXY>>1); 76 | 77 | mouse_scan(&mi); 78 | mx=mi.x; 79 | my=mi.y; 80 | mouse_show_cursor(mi.x, mi.y, &cur_std); 81 | while (TRUE) { 82 | mouse_scan(&mi); 83 | if (mx!=mi.x || my!=mi.y) { 84 | mouse_hide_cursor(); 85 | mouse_show_cursor(mi.x, mi.y, cursors[curndx]); 86 | mx=mi.x; 87 | my=mi.y; 88 | } 89 | if (mi.button_change) { 90 | curndx++; 91 | if (curndx==5) curndx=0; 92 | } 93 | } 94 | 95 | */ 96 | 97 | 98 | 99 | 100 | 101 | /* 102 | window_t* w11; 103 | window_t* w21; 104 | window_t* wactive; 105 | 106 | w11=window_create( 107 | NULL, 108 | w1, 109 | WF_HASBORDER, 110 | control_wnd_proc, 111 | 20, 112 | 15, 113 | 30, 114 | 35); 115 | 116 | w21=window_create( 117 | NULL, 118 | w2, 119 | WF_HASBORDER, 120 | control_wnd_proc, 121 | 20, 122 | 20, 123 | 40, 124 | 50); 125 | 126 | wactive=w1; 127 | while(TRUE) { 128 | window_select(wactive); 129 | window_draw(window_desktop); 130 | if (wactive==w1) wactive=w2; else wactive=w1; 131 | } 132 | */ 133 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/fuserecv115k.s: -------------------------------------------------------------------------------- 1 | ;; fuserecv115k.s 2 | ;; rs232 receive @ 115.200-8-N-2 baud 3 | ;; 4 | ;; notes: for FUSE only, exploits FUSE bugs! 5 | ;; 6 | ;; tomaz stih, sat jul 12 2014 7 | .module fuserecv115k 8 | .globl _rs232_buffered_input 9 | 10 | ;; consts 11 | RS232_IBUFF_SIZE = 0x14 12 | RS232_CTL = 0xef 13 | RS232_DTA = 0xf7 14 | CTS_ON = 0xff 15 | CTS_OFF = 0xef 16 | BITS = 0x08 17 | 18 | .area _CODE 19 | 20 | _rs232_buffered_input:: 21 | di 22 | 23 | ;; buffer to hl 24 | pop af 25 | pop hl 26 | push hl 27 | push af 28 | 29 | ;; optimization for later ... hl to top of stack 30 | push hl 31 | 32 | ;; initial values 33 | ld a,#CTS_ON ; xxx1xxxx - CTS 34 | ld b,#RS232_IBUFF_SIZE ; b=buffer size 35 | ld c,#RS232_DTA ; c=data port 36 | ld de,#0x8000 ; masks 37 | 38 | ;; intialize SP 39 | ld (#_rs232_sp),sp ; store SP 40 | ld sp,#retm_table ; 20 x same return address 41 | 42 | ;; announce clear to send (CTS) 43 | out (RS232_CTL),a ; 11 t-states 44 | 45 | start_bit: 46 | ;; get start bit, try 3 times before giving up 47 | in a,(c) ; read rs232 bit 48 | ret m ; if start bit 49 | in a,(c) 50 | ret m 51 | in a,(c) 52 | ret m 53 | 54 | ;; no start bit, assume no more data 55 | ld a,#CTS_OFF ; xxx0xxxx (cts off) 56 | out (RS232_CTL),a ; raise CTS 57 | 58 | ld sp,(#_rs232_sp) ; restore stack 59 | 60 | pop de ; original buffer to de 61 | or a ; clear carry flag 62 | sbc hl,de ; count of bytes to hl 63 | ei ; enable interrupts 64 | ret 65 | 66 | data_bits: 67 | ;; fuse hack - 4 start bits, dont even ask. 68 | in a,(c) 69 | in a,(c) 70 | in a,(c) 71 | 72 | ;; start reading data bits, nevermind the timing 73 | in a,(#0xf7) ; bit 0 74 | rla ; lsb to carry 75 | rr e ; and to msb (e) 76 | 77 | in a,(#0xf7) 78 | rla 79 | rr e 80 | 81 | in a,(#0xf7) 82 | rla 83 | rr e 84 | 85 | in a,(#0xf7) 86 | rla 87 | rr e 88 | 89 | in a,(#0xf7) 90 | rla 91 | rr e 92 | 93 | 94 | in a,(#0xf7) 95 | rla 96 | rr e 97 | 98 | in a,(#0xf7) 99 | rla 100 | rr e 101 | 102 | in a,(#0xf7) 103 | rla 104 | rr e 105 | 106 | ;; 2 stop bits ... to prepare for next start bit 107 | ld a,e 108 | cpl ; prepare result in a 109 | ld (hl),a ; write to buffer 110 | inc hl ; increase buff. counter 111 | 112 | ;; tell sender to stop sending (every time you read a byte...) 113 | ld a,#CTS_OFF ; xxx0xxxx (cts) 114 | out (RS232_CTL),a 115 | 116 | djnz start_bit 117 | 118 | ld sp,(#_rs232_sp) ; restore stack 119 | 120 | pop de ; original buffer to de 121 | or a ; clear carry flag 122 | sbc hl,de ; count of bytes to hl 123 | 124 | ei 125 | ret 126 | 127 | retm_table: ;; max 20 bytes -> max 20 returns 128 | .word data_bits, data_bits, data_bits, data_bits 129 | .word data_bits, data_bits, data_bits, data_bits 130 | .word data_bits, data_bits, data_bits, data_bits 131 | .word data_bits, data_bits, data_bits, data_bits 132 | .word data_bits, data_bits, data_bits, data_bits 133 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/ssend57k.s: -------------------------------------------------------------------------------- 1 | ;; ssend57k.s 2 | ;; rs232 send @ 57.600-8-N-2 baud 3 | ;; 4 | ;; tomaz stih, mon mar 25 2013 5 | 6 | .module ssend57k 7 | .globl _rs232_putb 8 | 9 | ;; consts 10 | RS232_CTL = 0xef 11 | RS232_DTA = 0xf7 12 | CTS_ON = 0xff 13 | CTS_OFF = 0xef 14 | RESULT_SUCCESS = 0x00 15 | 16 | .area _CODE 17 | 18 | _rs232_putb:: 19 | ;; delay between bits must be 20 | ;; 60.7 t-states (= 3.500.000 / 57.600) 21 | di ; no interrupts for precise timing 22 | 23 | ;; get byte ptr from stack 24 | ld hl,#0x0000 25 | add hl,sp 26 | inc hl 27 | inc hl ; hl points to byte to send 28 | 29 | ;; make sure CTS is off (just to make sure) 30 | ld a,#CTS_OFF 31 | out (RS232_CTL),a 32 | 33 | ;; 1. Send the start bit 34 | ld bc,#0x01ff ; b=0x01, c=0xff | 10 t-states 35 | ld a,c ; 4 t-states 36 | ld d,(hl) ; byte to transfer to d | 7 t-states 37 | out (RS232_DTA),a ; start bit | 11 t-states 38 | 39 | ;; 2. start sending out bits... 40 | srl d ; LSB to carry... | 8 t-states 41 | rla ; ...and to LSB of a | 4 t-states 42 | xor b ; negate bit 0 | 4 t-states 43 | inc iy ; 10 t-states 44 | dec iy ; 10 t-states 45 | cp #0 ; 7 t-states 46 | nop ; 4 t-states 47 | nop ; 4 t-states 48 | out (RS232_DTA),a ; out bit | 11 t-states 49 | ;; 62 t-states...should do */ 50 | 51 | srl d 52 | rla 53 | xor b 54 | ;; delay 55 | inc iy 56 | dec iy 57 | cp #0 58 | nop 59 | nop 60 | out (RS232_DTA),a 61 | 62 | srl d 63 | rla 64 | xor b 65 | ;; delay 66 | inc iy 67 | dec iy 68 | cp #0 69 | nop 70 | nop 71 | out (RS232_DTA),a 72 | 73 | srl d 74 | rla 75 | xor b 76 | ;; delay 77 | inc iy 78 | dec iy 79 | cp #0 80 | nop 81 | nop 82 | out (RS232_DTA),a 83 | 84 | srl d 85 | rla 86 | xor b 87 | ;; delay 88 | inc iy 89 | dec iy 90 | cp #0 91 | nop 92 | nop 93 | out (RS232_DTA),a 94 | 95 | srl d 96 | rla 97 | xor b 98 | ;; delay 99 | inc iy 100 | dec iy 101 | cp #0 102 | nop 103 | nop 104 | out (#0xf7),a 105 | 106 | srl d 107 | rla 108 | xor b 109 | ;; delay 110 | inc iy 111 | dec iy 112 | cp #0 113 | nop 114 | nop 115 | out (RS232_DTA),a 116 | 117 | srl d 118 | rla 119 | xor b 120 | ;; delay 121 | inc iy 122 | dec iy 123 | cp #0 124 | nop 125 | nop 126 | out (RS232_DTA),a 127 | 128 | ;; 3. emit stop bit 129 | ld a,#0xfe ; load a with stop bit | 7 t-states 130 | inc hl ; 6 t-states 131 | ;; delay 132 | inc iy 133 | dec iy 134 | cp #0 135 | nop 136 | nop 137 | out (RS232_DTA),a ; emit stop bit || 11 t-states 138 | 139 | ;; give at least one stop bit duration 140 | inc iy ; + 60 t-states should do 141 | dec iy 142 | inc iy 143 | dec iy 144 | inc iy 145 | dec iy 146 | 147 | 148 | ;; even if should do 149 | ;; one _rs232_write is called after another there is still time 150 | 151 | ld l,#RESULT_SUCCESS ; report success 152 | 153 | ei 154 | ret 155 | 156 | -------------------------------------------------------------------------------- /os/rom/crt0.s: -------------------------------------------------------------------------------- 1 | ;; crt0.s 2 | ;; zx spectrum rom startup code 3 | ;; 4 | ;; tomaz stih, sun may 20 2012 5 | .module crt0 6 | 7 | .globl _sys_vec_tbl 8 | .globl _sys_stack 9 | .globl _sys_heap 10 | .globl _sys_tarpit 11 | 12 | .area _HEADER (ABS) 13 | .org 0x0000 14 | di ; disable interrupts 15 | jp init ; init 16 | .db 0,0,0,0 17 | 18 | ;; rst 0x08 19 | jp rst8 20 | rst8ret: reti 21 | .db 0,0,0 22 | 23 | ;; rst 0x10 24 | jp rst10 25 | rst10ret: reti 26 | .db 0,0,0 27 | 28 | ;; rst 0x18 29 | jp rst18 30 | rst18ret: reti 31 | .db 0,0,0 32 | 33 | ;; rst 0x20 34 | jp rst20 35 | rst20ret: reti 36 | .db 0,0,0 37 | 38 | ;; rst 0x28 39 | jp rst28 40 | rst28ret: reti 41 | .db 0,0,0 42 | 43 | ;; rst 0x30 44 | jp rst30 45 | rst30ret: reti 46 | .db 0,0,0 47 | 48 | ;; rst 0x38 - im 1 49 | jp rst38 50 | rst38ret: reti 51 | .dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 52 | .db 0 53 | 54 | ;; nmi interrupt 0x66 55 | jp nmi 56 | nmiret: retn 57 | 58 | init: 59 | ld sp,#_sys_stack ; now sp to OS stack (on bss) 60 | call gsinit ; init static vars 61 | 62 | ;; start the os 63 | call _main 64 | 65 | ;; start the scheduler 66 | im 1 ; im 1, 50Hz interrupt on ZX Spectrum 67 | ei ; enable interrupts 68 | 69 | _sys_tarpit:: 70 | halt ; halt 71 | jr _sys_tarpit 72 | 73 | start_vectors: 74 | jp rst8ret 75 | jp rst10ret 76 | jp rst18ret 77 | jp rst20ret 78 | jp rst28ret 79 | jp rst30ret 80 | jp rst38ret 81 | jp nmiret 82 | end_vectors: 83 | ;; (linker documentation) where specific ordering is desired - 84 | ;; the first linker input file should have the area definitions 85 | ;; in the desired order 86 | .area _HOME 87 | .area _CODE 88 | .area _INITIALIZER 89 | .area _INITFINAL 90 | .area _GSINIT 91 | .area _GSFINAL 92 | .area _DATA 93 | .area _INITIALIZED 94 | .area _BSS 95 | .area _HEAP 96 | 97 | ;; static initialization 98 | .area _INITIALIZER 99 | init_rom_start: 100 | .area _INITFINAL 101 | init_rom_end: 102 | 103 | ;; this area contains data initialization code - 104 | ;; unlike gnu toolchain which generates data, sdcc generates 105 | ;; initialization code for initialized global 106 | ;; variables. and it puts this code into _GSINIT area 107 | .area _GSINIT 108 | gsinit: 109 | ;; move vector table to RAM 110 | ld hl,#start_vectors 111 | ld de,#_sys_vec_tbl 112 | ld bc,#end_vectors - #start_vectors 113 | ldir 114 | 115 | ;; init static vars 116 | ld hl,#init_rom_end 117 | ld de,#init_rom_start 118 | sbc hl,de ; hl=hl-de 119 | ld a,h 120 | or l 121 | jr z,no_statics ; no static vars! 122 | push hl 123 | pop bc ; bc=hl 124 | ex de,hl ; hl=init_rom_start 125 | ld de,#init_ram_start 126 | ldir 127 | no_statics: 128 | .area _GSFINAL 129 | ret 130 | 131 | .area _DATA 132 | ;; vector jump table in ram 133 | _sys_vec_tbl:: 134 | rst8: .ds 3 135 | rst10: .ds 3 136 | rst18: .ds 3 137 | rst20: .ds 3 138 | rst28: .ds 3 139 | rst30: .ds 3 140 | rst38: .ds 3 141 | nmi: .ds 3 142 | 143 | .area _INITIALIZED 144 | init_ram_start: 145 | 146 | .area _BSS 147 | ;; 512 bytes of operating system stack 148 | .ds 512 149 | _sys_stack:: 150 | .area _HEAP 151 | _sys_heap:: 152 | -------------------------------------------------------------------------------- /tools/gdb2fuse/gdb_ipsvr.cpp: -------------------------------------------------------------------------------- 1 | #include "gdb_ipsvr.h" 2 | 3 | gdb_ipsvr* gdb_ipsvr::create(char *sport) { 4 | 5 | int list_s, conn_s; 6 | short int port; 7 | struct sockaddr_in servaddr; 8 | int imode=1; 9 | 10 | cout << "configuring tcp/ip server..." << endl; 11 | port = atol(sport); 12 | 13 | // create socket 14 | cout << "\tcreating socket, port=" << port << endl; 15 | if ( (list_s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { 16 | cout << "\t\terror" << endl; 17 | return nullptr; 18 | } else 19 | cout << "\t\tok" << endl; 20 | 21 | // bind socket 22 | memset(&servaddr, 0, sizeof(servaddr)); 23 | servaddr.sin_family = AF_INET; 24 | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 25 | servaddr.sin_port = htons(port); 26 | cout << "\tbinding socket" << endl; 27 | if ( bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) { 28 | cout << "\t\terror" << endl; 29 | close(list_s); 30 | return nullptr; 31 | } else 32 | cout << "\t\tok" << endl; 33 | 34 | cout << "\tentering listening mode" << endl; 35 | if ( listen(list_s, 1) < 0 ) { 36 | cout << "\t\terror" << endl; 37 | close(list_s); 38 | return nullptr; 39 | } else 40 | cout << "\t\tok" << endl; 41 | 42 | cout << "\twaiting for connection" << endl; 43 | if ( (conn_s = accept(list_s, NULL, NULL) ) < 0 ) { 44 | cout << "\t\terror" << endl; 45 | close(list_s); 46 | return nullptr; 47 | } else 48 | cout << "\t\tok" << endl; 49 | 50 | cout << "\tset non-blocking mode" << endl; 51 | ioctl(conn_s, FIONBIO, &imode); 52 | 53 | // if everything cool then create fuse_npipe and pass. 54 | gdb_ipsvr* gisvr=new gdb_ipsvr(); 55 | gisvr->port=port; 56 | gisvr->list_sock=list_s; 57 | gisvr->conn_sock=conn_s; 58 | return gisvr; 59 | } 60 | 61 | gdb_ipsvr::~gdb_ipsvr() 62 | { 63 | // Close all pipe handles. 64 | cout << "closing server socket" << endl; 65 | ::close(list_sock); 66 | ::close(conn_sock); 67 | } 68 | 69 | 70 | int gdb_ipsvr::write(const char *buffer, int len) { 71 | int nleft; 72 | int nwritten; 73 | const char *pbuff; 74 | 75 | pbuff = buffer; 76 | nleft = len; 77 | 78 | while ( nleft > 0 ) { 79 | if ( (nwritten = ::write(conn_sock, pbuff, nleft)) <= 0 ) { 80 | return -1; 81 | } 82 | nleft -= nwritten; 83 | pbuff += nwritten; 84 | } 85 | 86 | return len; 87 | } 88 | 89 | int gdb_ipsvr::read(char *buffer, int len) { 90 | int n, rc; 91 | char c, *pbuff; 92 | 93 | pbuff = buffer; 94 | 95 | for ( n = 1; n < len; n++ ) { 96 | 97 | if ( (rc = ::read(conn_sock, &c, 1)) == 1 ) { 98 | *pbuff++ = c; 99 | } 100 | else { 101 | if ( rc == 0 ) { 102 | if ( n == 1 ) 103 | return -1; // Closed socket, no data. 104 | else 105 | break; // Closed socket in the middle of read. Don't lose data. 106 | } 107 | else { 108 | if ( errno == EAGAIN ) // No data. 109 | break; 110 | return -2; // Other error. 111 | } 112 | } 113 | } 114 | return n-1; 115 | } 116 | -------------------------------------------------------------------------------- /tools/zxserial/specput.c: -------------------------------------------------------------------------------- 1 | // Compile with 2 | // gcc -o specput specput.c 3 | 4 | #include /* Standard input/output definitions */ 5 | #include /* Standard library */ 6 | #include /* String function definitions */ 7 | #include /* UNIX standard function definitions */ 8 | #include /* File control definitions */ 9 | #include /* Error number definitions */ 10 | #include /* POSIX terminal control definitions */ 11 | #include 12 | 13 | /* Convenience macros for the flush cmd argument */ 14 | #define FLUSH_IN 0 15 | #define FLUSH_OUT 1 16 | #define FLUSH_BOTH 2 17 | 18 | int open_port(char *device) 19 | { 20 | int fd; 21 | struct termios options; 22 | 23 | fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); 24 | if (fd != -1) { /* Configure port */ 25 | fcntl(fd, F_SETFL, 0); 26 | tcgetattr(fd, &options); 27 | 28 | /* Baud rate for input and output is 2400, doesn't work faster */ 29 | cfsetispeed(&options, B2400); 30 | cfsetospeed(&options, B2400); 31 | 32 | options.c_cflag &= ~PARENB; /* No parity */ 33 | options.c_cflag &= ~CSTOPB; /* One stop bit */ 34 | options.c_cflag &= ~CSIZE; /* Mask char size bits */ 35 | options.c_cflag |= CS8; /* 8 bit */ 36 | options.c_cflag |= CRTSCTS; /*switch off CTS/RTS handshake */ 37 | options.c_oflag &= ~OPOST; /* Raw */ 38 | 39 | /* Apply settings now! */ 40 | tcsetattr(fd, TCSANOW, &options); 41 | } 42 | return (fd); 43 | } 44 | 45 | /* Send bytes using manual CTS/RTS */ 46 | void sendbytes(int fd, void *bytes, int len, int logging) { 47 | 48 | register int count=0; 49 | if (logging) printf("sending data...\n"); 50 | while (len--) { 51 | write(fd,bytes++,1); 52 | } 53 | 54 | if(logging) printf("complete\n"); 55 | } 56 | 57 | int main(int argc, char **argv) { 58 | 59 | // Check arguments 60 | if (argc!=4) { 61 | printf("usage: specput \n"); 62 | return 1; 63 | } 64 | 65 | int fd=open_port(argv[1]); 66 | if (fd==-1) { 67 | printf("unable to open device %s\n",argv[1]); 68 | return 2; 69 | } 70 | 71 | /* Get the file */ 72 | unsigned short datalen; 73 | struct stat st; 74 | stat(argv[2], &st); 75 | datalen = st.st_size; 76 | unsigned char *pblock=malloc(datalen); 77 | int ofd=open(argv[2], O_RDONLY|O_SYNC); 78 | int bytes=read(ofd,(void *)pblock,datalen); 79 | printf("Read file %s\n",argv[2]); 80 | close(ofd); 81 | 82 | /* Get load address */ 83 | short int addr=atoi(argv[3]); 84 | printf ("Load address is %d, file length is %d\n",addr, bytes); 85 | 86 | /* File type is 3 (code) */ 87 | unsigned char type=3; 88 | printf("Sending file type CODE\n"); 89 | sendbytes(fd,(void *)&type,1,0); 90 | 91 | /* Send data len */ 92 | printf("Sending file len %d\n",datalen); 93 | sendbytes(fd,(void *)&datalen,2,0); 94 | 95 | /* Send two parameters */ 96 | unsigned short par1=addr,par2=65535; 97 | printf("Sending par1 (%d) and par2 (%d)\n",par1, par2); 98 | sendbytes(fd,(void *)&par1,2,0); 99 | sendbytes(fd,(void *)&par2,2,0); 100 | 101 | /* Don't know what to think of this one ... */ 102 | unsigned short dummy=0; 103 | sendbytes(fd,(void *)&dummy,2,0); 104 | 105 | /* and file... */ 106 | sendbytes(fd,pblock,datalen,1); 107 | 108 | printf("Sent bytes %d\n",bytes); 109 | 110 | /* Close serial port */ 111 | close(fd); 112 | 113 | /* Free memory */ 114 | free(pblock); 115 | 116 | printf("The end\n"); 117 | } 118 | -------------------------------------------------------------------------------- /buddy/os/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memory.c 3 | * memory management (mem_allocate, mem_free) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #include "types.h" 8 | #include "list.h" 9 | #include "memory.h" 10 | 11 | /* 12 | * ---------- private (helpers) ---------- 13 | */ 14 | 15 | byte match_free_block(list_header_t *p, word size) { 16 | block_t *b = (block_t *)p; 17 | return !(b->stat&ALLOCATED) && b->size >= size; 18 | } 19 | 20 | void merge_with_next (block_t *b) { 21 | block_t *bnext=b->hdr.next; 22 | b->size += ( BLK_SIZE + bnext->size ); 23 | b->hdr.next = bnext->hdr.next; 24 | } 25 | 26 | void split ( block_t *b, word size) { 27 | block_t *nw; 28 | nw = (block_t *)((word)(b->data) + size); 29 | nw->hdr.next=b->hdr.next; 30 | nw->size = b->size - (size + BLK_SIZE); 31 | nw->hdr.owner=b->hdr.owner; 32 | nw->stat=b->stat; 33 | /* do not set owner and stat because 34 | they'll be populated later */ 35 | b->size = size; 36 | b->hdr.next = nw; 37 | } 38 | 39 | /* 40 | * ---------- public ---------- 41 | */ 42 | 43 | /* 44 | * initialize memory management 45 | * sample call: 46 | * user_heap=0x8000; 47 | * mem_init(user_heap, 0x8000); 48 | */ 49 | void mem_init(void *heap, word size) { 50 | block_t *first = (block_t *)heap; 51 | first->hdr.next = NULL; 52 | first->size = size - BLK_SIZE; 53 | first->hdr.owner = NONE; /* no owner */ 54 | first->stat = NEW; 55 | } 56 | 57 | /* 58 | * allocate memory block for owner 59 | */ 60 | void *mem_allocate(void *heap, word size, void *owner) { 61 | 62 | block_t *prev; 63 | block_t *b; 64 | 65 | b = (block_t *)list_find((list_header_t *)heap, (list_header_t **)&prev, match_free_block, size); 66 | 67 | if (b) { 68 | if (b->size - size > BLK_SIZE + MIN_CHUNK_SIZE) 69 | split(b, size); 70 | b->hdr.owner=owner; 71 | b->stat=ALLOCATED; 72 | return b->data; 73 | } else 74 | return NULL; 75 | } 76 | 77 | /* 78 | * free memory block 79 | */ 80 | void *mem_free(void *heap, void *p) { 81 | 82 | block_t *prev; 83 | block_t *b; 84 | 85 | /* calculate block address from pointer */ 86 | b = (block_t *) ( (word)p - BLK_SIZE ); 87 | 88 | /* make sure it is a valid memory block by finding it */ 89 | if (list_find((list_header_t *)heap, (list_header_t **)&prev, list_match_eq, (word)b)) { 90 | b->hdr.owner=NONE; /* reclaim for the heap */ 91 | b->stat=NEW; 92 | /* 93 | * merge 3 blocks if possible 94 | */ 95 | if ( prev && !(prev->stat&ALLOCATED) ) { /* try previous */ 96 | merge_with_next(prev); 97 | b=prev; 98 | } 99 | if ( b->hdr.next && !(((block_t *)(b->hdr.next))->stat&ALLOCATED) ) /* try next */ 100 | merge_with_next(b); 101 | 102 | return b->data; 103 | } else 104 | return NULL; 105 | } 106 | 107 | void mem_copy(byte *src, byte *dest, word count) __naked { 108 | src, dest, count; /* to prevent unreferenced function argument */ 109 | __asm 110 | exx /* alt set for ret. addr */ 111 | pop hl /* return address */ 112 | exx 113 | pop hl /* hl=src */ 114 | pop de /* de=dest */ 115 | pop bc /* bc=count */ 116 | push bc 117 | push de 118 | push hl 119 | exx 120 | push hl 121 | exx 122 | /* stack is restored*/ 123 | ldir 124 | ret 125 | __endasm; 126 | } 127 | -------------------------------------------------------------------------------- /os/rom/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memory.c 3 | * memory management (mem_allocate, mem_free) 4 | * 5 | * tomaz stih fri may 25 2012 6 | */ 7 | #include "types.h" 8 | #include "list.h" 9 | #include "memory.h" 10 | 11 | static int i=0; 12 | 13 | /* 14 | * ---------- private (helpers) ---------- 15 | */ 16 | 17 | byte match_free_block(list_header_t *p, word size) { 18 | block_t *b = (block_t *)p; 19 | return !(b->stat&ALLOCATED) && b->size >= size; 20 | } 21 | 22 | void merge_with_next (block_t *b) { 23 | block_t *bnext=b->hdr.next; 24 | b->size += ( BLK_SIZE + bnext->size ); 25 | b->hdr.next = bnext->hdr.next; 26 | } 27 | 28 | void split ( block_t *b, word size) { 29 | block_t *nw; 30 | nw = (block_t *)((word)(b->data) + size); 31 | nw->hdr.next=b->hdr.next; 32 | nw->size = b->size - (size + BLK_SIZE); 33 | nw->hdr.owner=b->hdr.owner; 34 | nw->stat=b->stat; 35 | /* do not set owner and stat because 36 | they'll be populated later */ 37 | b->size = size; 38 | b->hdr.next = nw; 39 | } 40 | 41 | /* 42 | * ---------- public ---------- 43 | */ 44 | 45 | /* 46 | * initialize memory management 47 | * sample call: 48 | * user_heap=0x8000; 49 | * mem_init(user_heap, 0x8000); 50 | */ 51 | void mem_init(void *heap, word size) { 52 | block_t *first = (block_t *)heap; 53 | first->hdr.next = NULL; 54 | first->size = size - BLK_SIZE; 55 | first->hdr.owner = NONE; /* no owner */ 56 | first->stat = NEW; 57 | } 58 | 59 | /* 60 | * allocate memory block for owner 61 | */ 62 | void *mem_allocate(void *heap, word size, void *owner) { 63 | 64 | block_t *prev; 65 | block_t *b; 66 | 67 | b = (block_t *)list_find((list_header_t *)heap, (list_header_t **)&prev, match_free_block, size); 68 | 69 | if (b) { 70 | if (b->size - size > BLK_SIZE + MIN_CHUNK_SIZE) 71 | split(b, size); 72 | b->hdr.owner=owner; 73 | b->stat=ALLOCATED; 74 | return b->data; 75 | } else 76 | return NULL; 77 | } 78 | 79 | /* 80 | * free memory block 81 | */ 82 | void *mem_free(void *heap, void *p) { 83 | 84 | block_t *prev; 85 | block_t *b; 86 | 87 | /* calculate block address from pointer */ 88 | b = (block_t *) ( (word)p - BLK_SIZE ); 89 | 90 | /* make sure it is a valid memory block by finding it */ 91 | if (list_find((list_header_t *)heap, (list_header_t **)&prev, list_match_eq, (word)b)) { 92 | b->hdr.owner=NONE; /* reclaim for the heap */ 93 | b->stat=NEW; 94 | /* 95 | * merge 3 blocks if possible 96 | */ 97 | if ( prev && !(prev->stat&ALLOCATED) ) { /* try previous */ 98 | merge_with_next(prev); 99 | b=prev; 100 | } 101 | if ( b->hdr.next && !(((block_t *)(b->hdr.next))->stat&ALLOCATED) ) /* try next */ 102 | merge_with_next(b); 103 | 104 | return b->data; 105 | } else 106 | return NULL; 107 | } 108 | 109 | void mem_copy(byte *src, byte *dest, word count) __naked { 110 | src, dest, count; /* to prevent unreferenced function argument */ 111 | __asm 112 | exx /* alt set for ret. addr */ 113 | pop hl /* return address */ 114 | exx 115 | pop hl /* hl=src */ 116 | pop de /* de=dest */ 117 | pop bc /* bc=count */ 118 | push bc 119 | push de 120 | push hl 121 | exx 122 | push hl 123 | exx 124 | /* stack is restored*/ 125 | ldir 126 | ret 127 | __endasm; 128 | } 129 | -------------------------------------------------------------------------------- /os/ram/.depend: -------------------------------------------------------------------------------- 1 | ball.o: ball.c yx.h types.h string.h errors.h interrupt.h system.h list.h \ 2 | name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 3 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 4 | debug.o: debug.c yx.h types.h string.h errors.h interrupt.h system.h \ 5 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 6 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 7 | driver.o: driver.c yx.h types.h string.h errors.h interrupt.h system.h \ 8 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 9 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 10 | errors.o: errors.c yx.h types.h string.h errors.h interrupt.h system.h \ 11 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 12 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 13 | event.o: event.c yx.h types.h string.h errors.h interrupt.h system.h \ 14 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 15 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 16 | handle.o: handle.c yx.h types.h string.h errors.h interrupt.h system.h \ 17 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 18 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 19 | hires.o: hires.c yx.h types.h string.h errors.h interrupt.h system.h \ 20 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 21 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 22 | interrupt.o: interrupt.c yx.h types.h string.h errors.h interrupt.h \ 23 | system.h list.h name.h handle.h queue.h color.h hires.h lores.h serial.h \ 24 | memory.h event.h timer.h driver.h task.h debug.h ball.h ukernel.h 25 | list.o: list.c yx.h types.h string.h errors.h interrupt.h system.h list.h \ 26 | name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 27 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 28 | lores.o: lores.c yx.h types.h string.h errors.h interrupt.h system.h \ 29 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 30 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 31 | memory.o: memory.c yx.h types.h string.h errors.h interrupt.h system.h \ 32 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 33 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 34 | name.o: name.c yx.h types.h string.h errors.h interrupt.h system.h list.h \ 35 | name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 36 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 37 | queue.o: queue.c yx.h types.h string.h errors.h interrupt.h system.h \ 38 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 39 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 40 | serial.o: serial.c yx.h types.h string.h errors.h interrupt.h system.h \ 41 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 42 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 43 | string.o: string.c yx.h types.h string.h errors.h interrupt.h system.h \ 44 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 45 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 46 | system.o: system.c yx.h types.h string.h errors.h interrupt.h system.h \ 47 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 48 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 49 | task.o: task.c yx.h types.h string.h errors.h interrupt.h system.h list.h \ 50 | name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 51 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 52 | timer.o: timer.c yx.h types.h string.h errors.h interrupt.h system.h \ 53 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 54 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 55 | ukernel.o: ukernel.c yx.h types.h string.h errors.h interrupt.h system.h \ 56 | list.h name.h handle.h queue.h color.h hires.h lores.h serial.h memory.h \ 57 | event.h timer.h driver.h task.h debug.h ball.h ukernel.h 58 | -------------------------------------------------------------------------------- /tools/gdb-zxspectrum-stub/srecv57k.s: -------------------------------------------------------------------------------- 1 | ;; srecv57k.s 2 | ;; rs232 receive @ 57.600-8-N-2 baud 3 | ;; 4 | ;; tomaz stih, thu aug 2 2012 5 | 6 | .module srecv57k 7 | .globl _rs232_buffered_input 8 | 9 | ;; consts 10 | RS232_IBUFF_SIZE = 0x14 11 | RS232_CTL = 0xef 12 | RS232_DTA = 0xf7 13 | CTS_ON = 0xff 14 | CTS_OFF = 0xef 15 | BITS = 0x08 16 | 17 | .area _CODE 18 | 19 | _rs232_buffered_input:: 20 | di 21 | 22 | ld iy,#0x0000 23 | add iy,sp 24 | ld l,2(iy) 25 | ld h,3(iy) 26 | push hl ; store original buffer 27 | 28 | ld b,#RS232_IBUFF_SIZE 29 | ld c,#RS232_DTA 30 | 31 | ;; intialize SP 32 | ld (#_rs232_sp),sp ; store SP 33 | 34 | ;; pulse cts 35 | ld a,#CTS_ON ; xxx0xxxx - CTS | 7 t-states 36 | out (RS232_CTL),a ; CTS 11 t-states 37 | 38 | start_bit: 39 | ld sp,#retm_table ; 10 t-states 40 | 41 | ;; get start bit, try 20 times before giving up 42 | in a,(c) ; read rs232 bit | 12 t-states 43 | ret m ; if start bit | 5/11 t-states 44 | in a,(c) 45 | ret m 46 | in a,(c) 47 | ret m 48 | in a,(c) 49 | ret m 50 | in a,(c) 51 | ret m 52 | in a,(c) 53 | ret m 54 | in a,(c) 55 | ret m 56 | in a,(c) 57 | ret m 58 | in a,(c) 59 | ret m 60 | in a,(c) 61 | ret m 62 | in a,(c) 63 | ret m 64 | in a,(c) 65 | ret m 66 | in a,(c) 67 | ret m 68 | in a,(c) 69 | ret m 70 | in a,(c) 71 | ret m 72 | in a,(c) 73 | ret m 74 | in a,(c) 75 | ret m 76 | in a,(c) 77 | ret m 78 | in a,(c) 79 | ret m 80 | in a,(c) 81 | ret m 82 | in a,(c) 83 | ret m 84 | in a,(c) 85 | ret m 86 | in a,(c) 87 | ret m 88 | in a,(c) 89 | ret m 90 | in a,(c) 91 | ret m 92 | in a,(c) 93 | ret m 94 | in a,(c) 95 | ret m 96 | in a,(c) 97 | ret m 98 | in a,(c) 99 | ret m 100 | in a,(c) 101 | ret m 102 | in a,(c) 103 | ret m 104 | in a,(c) 105 | ret m 106 | in a,(c) 107 | ret m 108 | in a,(c) 109 | ret m 110 | 111 | ;; no start bit, assume no more data 112 | ld a,#CTS_OFF ; xxx1xxxx (cts) | 7 t-states 113 | out (RS232_CTL),a ; deactivate CTS | 11 t-states 114 | 115 | ld sp,(#_rs232_sp) ; restore stack 116 | 117 | pop de ; original buffer to de 118 | or a ; clear carry 119 | sbc hl,de ; count of bytes to hl 120 | 121 | ei ; enable interrupts 122 | ret 123 | 124 | data_bits: 125 | ld d,b ; store b | 4 t-states 126 | ld b,#BITS ; 8 bits to read 127 | 128 | ;; waste t-states 129 | inc iy ; 10 t-states 130 | dec iy ; 10 t-states 131 | inc iy ; 10 t-states 132 | dec iy ; 10 t-states 133 | inc iy ; 10 t-states 134 | dec iy ; 10 t-states 135 | nop ; 4 t-states 136 | nop ; 4 t-states 137 | 138 | read_bit: 139 | ;; start reading data bits 140 | in a,(RS232_DTA) ; bit 0 | 11 t-states 141 | rla ; lsb to carry | 7 t-states 142 | rr e ; and to msb (e) |8 t-states 143 | 144 | ;; waste 20 t-states 145 | inc iy 146 | dec iy 147 | 148 | djnz read_bit ; 13/8 t-states 149 | 150 | ld b,d ; restore b | 4 t-states 151 | 152 | ;; t-states of 2 stop bits ... to prepare for next start bit 153 | ld a,e ; 4 t-states 154 | cpl ; 4 t-states 155 | ld (hl),a ; write to buffer | 7 t-states 156 | inc hl ; increase buff. counter | 6 t-states 157 | 158 | ;; tell sender to stop sending (every time you read a byte...) 159 | ld a,#CTS_OFF ; xxx1xxxx (cts) | 7 t-states 160 | out (RS232_CTL),a ; CTS off | 11 t-states 161 | 162 | djnz jp_sbit ; 13/8 t-states 163 | 164 | ld sp,(#_rs232_sp) ; restore stack 165 | 166 | pop de ; original buffer to de 167 | or a ; clear carry 168 | sbc hl,de ; count of bytes to hl 169 | 170 | ei 171 | ret 172 | 173 | jp_sbit: jp start_bit 174 | retm_table: .word data_bits 175 | -------------------------------------------------------------------------------- /os/ram/lores.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lores.h 3 | * low resolution graphics (text mode) 4 | * 5 | * tomaz stih wed mar 20 2013 6 | */ 7 | #include "yx.h" 8 | 9 | int lores_x=0, lores_y=23; 10 | 11 | /* 12 | * print string 13 | */ 14 | void lores_puts(string s) { 15 | while(*s) { 16 | switch(*s) { 17 | case '\n': 18 | lores_x=0; 19 | lores_y++; 20 | break; 21 | default: 22 | lores_putc_xy(*s, lores_x++, lores_y); 23 | } 24 | if (lores_x>31) { 25 | lores_x=0; 26 | lores_y++; 27 | } 28 | if (lores_y>23) { 29 | lores_y=23; 30 | lores_scrollup(); 31 | } 32 | s++; 33 | } 34 | } 35 | 36 | /* 37 | * print char at x, y using system font 38 | */ 39 | void lores_putc_xy(byte c, byte x, byte y) __naked { 40 | __asm 41 | ld iy,#0x0000 42 | add iy,sp 43 | 44 | /* 45 | * calculate character inside system font 46 | */ 47 | ld a,2(iy) /* get character */ 48 | sub #32 /* a = a-32 */ 49 | ld h,#0x00 /* h=0 */ 50 | ld l,a /* hl=a */ 51 | add hl,hl /* hl=hl*2 */ 52 | add hl,hl /* hl=hl*4 */ 53 | add hl,hl /* hl=hl*8 */ 54 | ld de,#sysfont8x8 /* font address */ 55 | add hl,de /* hl=character address */ 56 | ex de,hl /* into de */ 57 | 58 | /* 59 | * calculate char position in vmem 60 | */ 61 | ld b,3(iy) /* b <- x */ 62 | ld c,4(iy) /* c <- y */ 63 | /* vmem address to hl */ 64 | call lores_vmem_addr_raw 65 | 66 | /* 67 | * loop it 68 | */ 69 | ld b,#8 /* eight lines */ 70 | lpxy_loop: ld a,(de) /* get character byte */ 71 | inc de /* next byte */ 72 | ld (hl),a /* transfer to screen */ 73 | 74 | /* next hires screen line */ 75 | call hires_vmem_nextrow_addr_raw 76 | 77 | djnz lpxy_loop 78 | 79 | ret 80 | 81 | __endasm; 82 | } 83 | 84 | /* 85 | * scroll up 8 lines 86 | */ 87 | void lores_scrollup() __naked { 88 | __asm 89 | ld de,#0x4000 /* scan line 1 */ 90 | ld hl,#0x4020 /* scan line 8, diff is 1 char */ 91 | ld bc,#0x0020 /* bytes to transfer */ 92 | 93 | /* 94 | * move 184 lines (192 - 8) 95 | */ 96 | ld a,#184 97 | ls_loop: 98 | push af 99 | push bc 100 | push de 101 | push hl 102 | ldir /* move scan line */ 103 | pop hl 104 | pop de 105 | call hires_vmem_nextrow_addr_raw 106 | ex de,hl 107 | call hires_vmem_nextrow_addr_raw 108 | ex de,hl 109 | pop bc 110 | pop af 111 | 112 | dec a 113 | jr nz,ls_loop 114 | 115 | /* 116 | * fill last line with zeroes 117 | * note: de already points to correct line 118 | */ 119 | ld a,#8 /* 8 lines */ 120 | ex de,hl /* correct line to hl */ 121 | ls_clr_loop: 122 | push hl /* store hl */ 123 | ld b,#32 /* chars */ 124 | ls_clrlne_loop: 125 | ld (hl),#0 126 | inc hl 127 | djnz ls_clrlne_loop 128 | pop hl 129 | push af 130 | call hires_vmem_nextrow_addr_raw 131 | pop af 132 | dec a 133 | jr nz,ls_clr_loop 134 | 135 | ret 136 | 137 | __endasm; 138 | } 139 | 140 | word lores_vmem_addr(byte x, byte y) __naked { 141 | 142 | __asm 143 | ;; get function parameters from stack 144 | ld iy,#0x0000 145 | add iy,sp /* iy=sp */ 146 | ld b,2(iy) /* b=x */ 147 | ld c,3(iy) /* c=y */ 148 | 149 | /* 150 | * directg_vmem_addr_raw 151 | * based on hires x and hires y, calculate vmem address 152 | * input 153 | * b hires x 154 | * c hires y 155 | * output 156 | * hl cell address in vmem 157 | * effects 158 | * a, flags, c, hl 159 | */ 160 | lores_vmem_addr_raw:: 161 | ld a,c /* get y to acc. */ 162 | and #0x18 /* get bits 3 - 4 */ 163 | add a,#0x40 /* add start of vmem */ 164 | ld h,a /* to high */ 165 | ld a,c /* y to acc. again */ 166 | and #0x07 /* get bits 0 - 2 */ 167 | rrca /* multiply * 32 */ 168 | rrca 169 | rrca 170 | add a,b /* to high */ 171 | ld l,a /* and add x */ 172 | ret 173 | 174 | __endasm; 175 | 176 | } 177 | -------------------------------------------------------------------------------- /buddy/graphics/graphics.c: -------------------------------------------------------------------------------- 1 | /* 2 | * graphics.c 3 | * graphics context 4 | * 5 | * tomaz stih mon oct 14 2013 6 | */ 7 | #include "graphics.h" 8 | 9 | graphics_t screen_graphics; 10 | rect_t screen_area; 11 | rect_t screen_clip; 12 | 13 | /* temp */ 14 | static byte data[512]; 15 | 16 | void graphics_init() { 17 | /* initialize screen graphics */ 18 | screen_graphics.area=&screen_area; 19 | screen_graphics.clip=&screen_clip; 20 | screen_area.x0=screen_clip.x0=screen_area.y0=screen_clip.y0=0; 21 | screen_area.x1=screen_clip.x1=SCREEN_MAXX; 22 | screen_area.y1=screen_clip.y1=SCREEN_MAXY; 23 | } 24 | 25 | graphics_t* graphics_create(byte flags) { 26 | flags; 27 | /* TODO: allocate objects 28 | graphics_t *graphics=malloc(sizeof(graphics_t)); 29 | graphics.area=malloc(sizeof(rect_t)); 30 | graphics.clip=malloc(sizeof(rect_t)); 31 | */ 32 | return NULL; 33 | } 34 | 35 | void graphics_destroy(graphics_t* g) { 36 | g; 37 | /* TODO: free objects 38 | free(graphics.clip); 39 | free(graphics.area); 40 | free(graphics); 41 | */ 42 | } 43 | 44 | /* notes: clip_rect is in relative coordinates */ 45 | void graphics_set_clipping(graphics_t* g, rect_t *clip_rect) { 46 | rect_rel2abs(g->area, clip_rect, g->clip); 47 | } 48 | 49 | void graphics_fill_rect(graphics_t *g, rect_t *rect, byte* mask, byte mode) { 50 | rect_t abs_rect, clipped_rect; 51 | byte row, mskndx, ofx, ofy; 52 | byte maskout[8]; 53 | if (!rect_rel2abs(g->area, rect, &abs_rect)) return; 54 | if (!rect_intersect(&abs_rect,g->clip,&clipped_rect)) return; 55 | /* clip mask */ 56 | ofx=( clipped_rect.x0 - abs_rect.x0 ) & 0x07; 57 | ofy=( clipped_rect.y0 - abs_rect.y0 ) & 0x07; 58 | clip_offset(ofx, ofy, mask, maskout); 59 | /* just draw the intersect */ 60 | mskndx=0; 61 | for (row=clipped_rect.y0; row<=clipped_rect.y1; row++) { 62 | vector_horzline(row,clipped_rect.x0,clipped_rect.x1,maskout[mskndx],mode); 63 | mskndx++; 64 | if (mskndx==8) mskndx=0; 65 | } 66 | } 67 | 68 | void graphics_draw_rect(graphics_t *g, rect_t *rect, byte linemask, byte mode) { 69 | rect_t abs_rect; 70 | byte x0,y0,x1,y1; 71 | 72 | /* convert rel to abs coordinates */ 73 | if (!rect_rel2abs(g->area, rect, &abs_rect)) return; 74 | 75 | /* draw rectangle only if a portion overlaps*/ 76 | if (rect_overlap(&abs_rect,g->clip)) { 77 | /* clip coordinates */ 78 | x0=MAX(abs_rect.x0,g->clip->x0); 79 | x1=MIN(abs_rect.x1,g->clip->x1); 80 | y0=MAX(abs_rect.y0,g->clip->y0); 81 | y1=MIN(abs_rect.y1,g->clip->y1); 82 | 83 | /* now clip lines */ 84 | if (abs_rect.y0 >= g->clip->y0) vector_horzline(y0, x0, x1, linemask, mode); 85 | if (abs_rect.y1 <= g->clip->y1) vector_horzline(y1, x0, x1, linemask, mode); 86 | if (abs_rect.x0 >= g->clip->x0) vector_vertline(x0, y0, y1, linemask, mode); 87 | if (abs_rect.x1 <= g->clip->x1) vector_vertline(x1, y0, y1, linemask, mode); 88 | } 89 | } 90 | 91 | bitmap_t* graphics_get_bitmap(graphics_t *g, rect_t *rect) { 92 | 93 | rect_t abs_rect, clipped_rect; 94 | 95 | /* convert rel to abs coordinates */ 96 | if (!rect_rel2abs(g->area, rect, &abs_rect)) return NULL; 97 | 98 | /* and clip it */ 99 | if (!rect_intersect(&abs_rect,g->clip,&clipped_rect)) return NULL; 100 | 101 | /* we have the correct clip rect */ 102 | return bmp_get(&clipped_rect, data); /* TODO: allocate data */ 103 | } 104 | 105 | void graphics_destroy_bitmap(bitmap_t *bmp) { 106 | bmp; 107 | /* TODO: destroy data */ 108 | } 109 | 110 | void graphics_put_bitmap(graphics_t *g, byte x, byte y, bitmap_t *bmp) { 111 | 112 | rect_t rel_rect, abs_rect, clipped_rect; 113 | byte *bmp_start; 114 | 115 | /* initial rect */ 116 | rel_rect.x0=x; 117 | rel_rect.y0=y; 118 | rel_rect.x1=x+bmp->x1; 119 | rel_rect.y1=y+bmp->y1; 120 | 121 | /* convert rel to abs coordinates */ 122 | if (!rect_rel2abs(g->area, &rel_rect, &abs_rect)) return; 123 | 124 | /* and clip it */ 125 | if (!rect_intersect(&abs_rect,g->clip,&clipped_rect)) return; 126 | 127 | /* calculate clipped start of bitmap */ 128 | bmp_start=(byte *)bmp; 129 | bmp_start+=2; /* skip x,y */ 130 | /* and draw it */ 131 | bmp_put( 132 | bmp_start, /* data */ 133 | clipped_rect.x0, /* x */ 134 | clipped_rect.y0, /* y */ 135 | bmp->y1, /* rows */ 136 | bmp->x1, /* cols */ 137 | x%8, /* shifts */ 138 | 0); /* skip */ 139 | } 140 | -------------------------------------------------------------------------------- /buddy/graphics/kempston.s: -------------------------------------------------------------------------------- 1 | ;; kempston.s 2 | ;; kempston mouse driver 3 | ;; 4 | ;; based on Andrey Rachkin code 5 | ;; http://8bit.yarek.pl/hardware/zx.mouse/kmouse.html 6 | ;; 7 | ;; tomaz stih, tue apr 28 2015 8 | .module kempston 9 | 10 | .globl _mouse_calibrate 11 | .globl _mouse_scan 12 | 13 | .globl kmp_scan_raw 14 | .globl kmp_calib_raw 15 | 16 | 17 | 18 | KMP_BTN_PORT = 0xfadf 19 | KMP_X_PORT = 0xfbdf 20 | KMP_Y_PORT = 0xffdf 21 | 22 | .area _CODE 23 | 24 | 25 | ;; extern void mouse_calibrate(byte x, byte y) 26 | _mouse_calibrate:: 27 | pop hl ; return address 28 | pop bc ; c=y, b=y 29 | 30 | ;; restore stack 31 | push bc 32 | push hl 33 | 34 | ;; calibrate 35 | ;; input: b=start y, c=start x (hint:center) 36 | ;; affets: a, flags, hl, bc 37 | kmp_calib_raw:: 38 | ld hl,#kmp_mcurxy 39 | ld a,c ; x to a 40 | ld (hl),a ; to low cursor pos 41 | inc hl 42 | ld a,b ; y to a 43 | ld (hl),a ; to high cursor pos 44 | inc hl 45 | ld bc,#KMP_X_PORT 46 | in a,(c) ; x to a 47 | ld (hl),a ; and to low hw pos 48 | inc hl 49 | ld bc,#KMP_Y_PORT 50 | in a,(c) ; y to a 51 | ld (hl),a ; to high hw pos 52 | ret 53 | 54 | ;; extern void mouse_scan(mouse_info_t *mi) 55 | _mouse_scan: 56 | call kmp_scan_raw ; scan it 57 | ex af,af' 58 | ld a,d ; store d to a' 59 | ex af,af' 60 | pop de ; return address 61 | pop hl ; pointer to mi 62 | push hl 63 | push de ; restore it all 64 | ex af,af' 65 | ld d,a 66 | ex af,af' 67 | ld (hl),c 68 | inc hl 69 | ld (hl),b 70 | inc hl 71 | ld (hl),a 72 | inc hl 73 | ld (hl),d 74 | ret 75 | 76 | ;; scan kempston mouse 77 | ;; input: 78 | ;; (kmp_mcurxy) ... last cursor coords 79 | ;; (kmp_mbtn) ... last button status 80 | ;; output: 81 | ;; a=mouse buttons 82 | ;; b=y 83 | ;; c=x 84 | ;; d=button chang flags (1=change, 0=no chg.) 85 | ;; affects: flags, a, bc, hl, de 86 | kmp_scan_raw:: 87 | ;; first scan buttons for changes 88 | ld bc,#KMP_BTN_PORT 89 | in a,(c) ; buttons to a 90 | cpl ; complement (so that ... 1=pressed) 91 | and #0x07 ; just the bottom three 92 | ld b,a ; store current buttons 93 | ld a,(kmp_mhwbtn) 94 | xor b ; xor with current buttons 95 | ld (kmp_mbtnchg),a ; store change flags 96 | ld a,b ; a=new button state 97 | ld (kmp_mhwbtn),a ; store 98 | 99 | ;; now scan position for changes 100 | kmp_scanpos: ld hl,(kmp_mcurxy) ; last cursor coords 101 | ld de,(kmp_mhwxy) ; last hardware coords 102 | ld bc,#KMP_X_PORT 103 | in a,(c) ; read x from hw 104 | ld (kmp_mhwxy),a ; immediately write 105 | sub e ; minus prev. coord 106 | jr z,kmp_x_done ; no change to x 107 | jp p,kmp_x_right ; move right 108 | ;; left or overflow 109 | add a,l ; a=old x-new x 110 | jr c,kmp_l_norm ; normal left 111 | xor a ; overflow, a=0 112 | kmp_l_norm: ld l,a ; to l 113 | jr kmp_x_done 114 | kmp_x_right: add a,l ; a=old x + dx 115 | jr c,kmp_r_over ; overflow? 116 | cp #0xff ; max x? 117 | jr c,kmp_r_norm 118 | kmp_r_over: ld a,#0xff ; max x (should it be fe?) 119 | kmp_r_norm: ld l,a ; to l 120 | kmp_x_done: ld b,#0xff 121 | in a,(c) ; read y from hw 122 | ld (kmp_mhwxy+1),a ; immediately write 123 | sub d ; minus old hw y 124 | jr z,kmp_y_done 125 | neg ; reverse coord. 126 | jp p,kmp_u 127 | add a,h ; how much up? 128 | jr c,kmp_u_norm 129 | xor a ; min y coor 130 | kmp_u_norm: ld h,a 131 | jr kmp_y_done 132 | kmp_u: add a,h 133 | jr c,kmp_d_over ; y overflow 134 | cp #0xbf ; 191 (max y) 135 | jr c,kmp_d_norm 136 | kmp_d_over: ld a,#0xbf ; y=max y 137 | kmp_d_norm: ld h,a ; store to h 138 | kmp_y_done: ld (kmp_mcurxy),hl ; store new cursor pos 139 | push hl 140 | pop bc ; bc=hl 141 | ld a,(kmp_mbtnchg) 142 | ld d,a 143 | ld a,(kmp_mhwbtn) ; button state to a 144 | ret 145 | 146 | .area _DATA 147 | 148 | kmp_mcurxy: .word 0 ; last cursor coords 149 | kmp_mhwxy: .word 0 ; last mouse hardware read 150 | kmp_mhwbtn: .byte 0 ; last mouse buttons hardware read 151 | kmp_mbtnchg: .byte 0 ; mouse button changes 152 | --------------------------------------------------------------------------------