From 037bf7bb4a8d64b90f99947defad18f9bfc7ead1 Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Sat, 16 Jan 2016 13:36:19 -0800 Subject: [PATCH] added integration with DOS 1.x found out how to access the current volume list in AmigaDOS and added a way to read this list, currently displays a portion of the assign list in the file list --- requesters/Makefile | 2 +- requesters/dos13.c | 94 ++++++++++++++++++++++++++ requesters/dos13.h | 33 +++++++++ requesters/filereq.c | 127 ++++++++++++++++++----------------- requesters/gfx/down11x11.xcf | Bin 0 -> 726 bytes requesters/gfx/up11x11.xcf | Bin 0 -> 726 bytes 6 files changed, 193 insertions(+), 63 deletions(-) create mode 100644 requesters/dos13.c create mode 100644 requesters/dos13.h create mode 100644 requesters/gfx/down11x11.xcf create mode 100644 requesters/gfx/up11x11.xcf diff --git a/requesters/Makefile b/requesters/Makefile index 63e0796..0c8bb60 100644 --- a/requesters/Makefile +++ b/requesters/Makefile @@ -7,6 +7,6 @@ all: main clean: rm -f *.o main -main: main.o filereq.o +main: main.o filereq.o dos13.o $(CC) $(CFLAGS) $^ -lamiga -lauto -o $@ diff --git a/requesters/dos13.c b/requesters/dos13.c new file mode 100644 index 0000000..b8a3d4e --- /dev/null +++ b/requesters/dos13.c @@ -0,0 +1,94 @@ +#include "dos13.h" + +#include +#include + +#include + +#include +#include +#include + +extern struct Library *DOSBase; + +/* + accessing the list of logical volumes is hairy under AmigaOS 1.x - it is + "hidden" in the DosBase structure, and shared among all tasks. + + Effectively this means, we need to nest the retrieval of the assigns into + Forbid()/Permit() calls to lock the assign list to prevent possible + race conditions. + + Reminder: We need to do some BCPL->C conversion here + BPTR are address pointers divided by 4, use BADDR to convert + BSTR are BPTRs to 0-terminated ASCII char arrays with a prefix length byte + + For now, we will omit device typed entries, because writing/reading to them + usually doesn't make too much sense. +*/ +struct FileListEntry *scan_current_dir() +{ + struct DosLibrary *dosbase = (struct DosLibrary *) DOSBase; + Forbid(); + struct DosInfo *dosinfo = BADDR(dosbase->dl_Root->rn_Info); + struct DevInfo *dev_head = BADDR(dosinfo->di_DevInfo); + struct DevInfo *current = dev_head; + struct FileListEntry *cur_entry = NULL, *result = NULL, *tmp; + char fname_len; + + while (current) { + if (current->dvi_Type != DLT_DEVICE) { + tmp = calloc(1, sizeof(struct FileListEntry)); + tmp->file_type = FILETYPE_VOLUME; + strncpy(tmp->name, ((char *) BADDR(current->dvi_Name)) + 1, MAX_FILENAME_LEN); + fname_len = strlen(tmp->name); + // add the colon character to point out that we have a logical volume + if (fname_len < MAX_FILENAME_LEN) tmp->name[fname_len] = ':'; + if (!cur_entry) result = cur_entry = tmp; + else { + cur_entry->next = tmp; + cur_entry = tmp; + } + } + current = BADDR(current->dvi_Next); + } + Permit(); + /* scan current directory */ + /* + on AmigaOS versions before 36 (essentially all 1.x versions), the + function GetCurrentDirName() does not exist, but it's obtainable + by calling Cli() and querying the returned CommandLineInterface + structure + */ + /* + puts("scanning directory..."); + // on AmigaOS 1.x, this function does not exist !!! + GetCurrentDirName(dirname, PATHBUFFER_SIZE); + printf("current dir: '%s'\n", dirname); + flock = Lock(dirname, SHARED_LOCK); + if (Examine(flock, &fileinfo)) { + while (ExNext(flock, &fileinfo)) { + print_fileinfo(&fileinfo); + } + error = IoErr(); + if (error != ERROR_NO_MORE_ENTRIES) { + puts("unknown I/O error, TODO handle"); + } + } + UnLock(flock); + */ + /* The result is an unsorted list, which is usually not what we want. + TODO: sort the list + */ + return result; +} + +void free_file_list(struct FileListEntry *entries) +{ + struct FileListEntry *cur = entries, *next; + while (cur) { + next = cur->next; + free(cur); + cur = next; + } +} diff --git a/requesters/dos13.h b/requesters/dos13.h new file mode 100644 index 0000000..2e7d3ad --- /dev/null +++ b/requesters/dos13.h @@ -0,0 +1,33 @@ +// dos13 - a module for DOS 1.x interaction +#pragma once +#ifndef __DOS13_H__ +#define __DOS13_H__ + +#include + +#define FILETYPE_FILE 0 +#define FILETYPE_DIR 1 +#define FILETYPE_VOLUME 2 + +// This file requester is only for 1.x, so 31 characters is the +// maximum +#define MAX_FILENAME_LEN 31 + +/* + * Store file list entries in these entries. + */ +struct FileListEntry { + struct FileListEntry *next; + UWORD file_type; + char name[MAX_FILENAME_LEN + 1]; +}; + +/* + * scan the current directory + */ +extern struct FileListEntry *scan_current_dir(); + +/* free the resources allocated in the specified entry list */ +void free_file_list(struct FileListEntry *entries); + +#endif diff --git a/requesters/filereq.c b/requesters/filereq.c index a5e6847..d05b5c2 100644 --- a/requesters/filereq.c +++ b/requesters/filereq.c @@ -1,4 +1,6 @@ +#include #include +#include #include #include @@ -7,6 +9,14 @@ #include #include "filereq.h" +#include "dos13.h" + +#define LABEL_DRAWER 0 +#define LABEL_FILE 1 +#define LABEL_PARENT 2 +#define LABEL_DRIVES 3 +#define LABEL_OPEN 4 +#define LABEL_CANCEL 5 #define REQWIN_WIDTH 260 #define REQWIN_HEIGHT 180 @@ -86,15 +96,15 @@ static UWORD __chip down_imdata[] = { 65504, 32800, 32800, 32800, 39712, 36384, 32800, 32800, 65504 }; static struct Image down_image = { 0, 0, 11, 11, 1, down_imdata, 1, 0, NULL }; -static struct IntuiText drawer_str_label = {1, 0, JAM2, STR_LABEL_XOFFSET, STR_LABEL_YOFFSET, NULL, - "Drawer", NULL}; -static struct IntuiText file_str_label = {1, 0, JAM2, STR_LABEL_XOFFSET, STR_LABEL_YOFFSET, NULL, - "File", NULL}; -static struct IntuiText parent_button_label = {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Parent", NULL}; -static struct IntuiText drives_button_label = {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Drives", NULL}; -static struct IntuiText ok_button_label = {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Open", NULL}; -static struct IntuiText cancel_button_label = {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, - "Cancel", NULL}; +static struct IntuiText labels[] = { + {1, 0, JAM2, STR_LABEL_XOFFSET, STR_LABEL_YOFFSET, NULL, "Drawer", NULL}, + {1, 0, JAM2, STR_LABEL_XOFFSET, STR_LABEL_YOFFSET, NULL, "File", NULL}, + {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Parent", NULL}, + {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Drives", NULL}, + {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Open", NULL}, + {1, 0, JAM2, BUTTON_TEXT_XOFFSET, BUTTON_TEXT_YOFFSET, NULL, "Cancel", NULL} +}; + static WORD ok_border_points[] = {0, 0, OK_BUTTON_WIDTH, 0, OK_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0}; @@ -166,40 +176,43 @@ static struct Gadget list_vslider = {&list_up, LIST_VSLIDER_X, LIST_VSLIDER_Y, static struct Gadget file_text = {&list_vslider, FILE_GADGET_X, FILE_GADGET_Y, PATH_GADGET_WIDTH, PATH_GADGET_HEIGHT, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, - &str_gadget_border, NULL, &file_str_label, 0, &strinfo2, + &str_gadget_border, NULL, &labels[LABEL_FILE], 0, &strinfo2, REQ_FILE_TEXT_ID, NULL}; static struct Gadget dir_text = {&file_text, DRAWER_GADGET_X, DRAWER_GADGET_Y, PATH_GADGET_WIDTH, PATH_GADGET_HEIGHT, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_STRGADGET, &str_gadget_border, - NULL, &drawer_str_label, 0, &strinfo1,REQ_DIR_TEXT_ID, NULL}; + NULL, &labels[LABEL_DRAWER], 0, &strinfo1,REQ_DIR_TEXT_ID, NULL}; // Note: Cancel does not specify the GACT_ENDGADGET flag, it seems that // IDCMP_REQCLEAR is not fired when Intuition closes the requester automatically static struct Gadget cancel_button = {&dir_text, CANCEL_BUTTON_X, BUTTON_Y, CANCEL_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &cancel_button_border, NULL, - &cancel_button_label, 0, NULL, REQ_CANCEL_BUTTON_ID, NULL}; + &labels[LABEL_CANCEL], 0, NULL, REQ_CANCEL_BUTTON_ID, NULL}; static struct Gadget parent_button = {&cancel_button, PARENT_BUTTON_X, BUTTON_Y, PARENT_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, - &parent_button_border, NULL, &parent_button_label, 0, NULL, + &parent_button_border, NULL, + &labels[LABEL_PARENT], 0, NULL, REQ_PARENT_BUTTON_ID, NULL}; static struct Gadget drives_button = {&parent_button, DRIVES_BUTTON_X, BUTTON_Y, DRIVES_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, - &drives_button_border, NULL, &drives_button_label, 0, NULL, + &drives_button_border, NULL, + &labels[LABEL_DRIVES], 0, NULL, REQ_DRIVES_BUTTON_ID, NULL}; static struct Gadget ok_button = {&drives_button, OK_BUTTON_X, BUTTON_Y, OK_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, - &ok_button_border, NULL, &ok_button_label, 0, NULL, + &ok_button_border, NULL, + &labels[LABEL_OPEN], 0, NULL, REQ_OK_BUTTON_ID, NULL}; static int filelist_bm_depth = 1; @@ -211,7 +224,9 @@ static char dirname[PATHBUFFER_SIZE + 1]; static BPTR flock; static LONG error; static struct FileInfoBlock fileinfo; + static struct TextFont *reqwin_font; +static UWORD font_baseline, font_height; static void print_fileinfo(struct FileInfoBlock *fileinfo) { @@ -271,6 +286,36 @@ static void cleanup() } } + +void draw_list() +{ + struct FileListEntry *files = scan_current_dir(), *cur; + + // Note that we need to render into the requester + // layer's rastport, because it is rendered on top of the + // parent window and obscures the content + struct RastPort *src_rp = &filelist_rastport; + struct RastPort *dst_rp = requester.ReqLayer->rp; + + // make sure drawing is clipped, otherwise it will + // draw somewhere else into memory + SetAPen(src_rp, 1); + int ypos = 10; + + cur = files; + while (cur) { + Move(src_rp, 8, ypos); + Text(src_rp, cur->name, strlen(cur->name)); + cur = cur->next; + ypos += font_height; + if (ypos > FILE_LIST_BM_HEIGHT) break; + } + BltBitMapRastPort(&filelist_bitmap, 0, 0, dst_rp, + FILE_LIST_BM_X, FILE_LIST_BM_Y, FILE_LIST_BM_WIDTH, FILE_LIST_BM_HEIGHT, + 0xc0); + free_file_list(files); +} + void open_file(struct Window *window) { BOOL result; @@ -287,8 +332,10 @@ void open_file(struct Window *window) requester.ReqText = NULL; reqwin_font = req_window->IFont; - printf("Font ysize: %d, baseline: %d\n", (int) reqwin_font->tf_YSize, - (int) reqwin_font->tf_Baseline); + font_height = reqwin_font->tf_YSize; + font_baseline = reqwin_font->tf_Baseline; + + printf("Font ysize: %d, baseline: %d\n", (int) font_height, (int) font_baseline); InitBitMap(&filelist_bitmap, filelist_bm_depth, FILE_LIST_BM_WIDTH, FILE_LIST_BM_HEIGHT); for (int i = 0; i < filelist_bm_depth; i++) filelist_bitmap.Planes[i] = NULL; @@ -304,52 +351,8 @@ void open_file(struct Window *window) InitRastPort(&filelist_rastport); filelist_rastport.BitMap = &filelist_bitmap; - /* scan current directory */ - /* - on AmigaOS versions before 36 (essentially all 1.x versions), the - function GetCurrentDirName() does not exist, but it's obtainable - by calling Cli() and querying the returned CommandLineInterface - structure - */ - //puts("scanning directory..."); - /* - // on AmigaOS 1.x, this function does not exist !!! - GetCurrentDirName(dirname, PATHBUFFER_SIZE); - printf("current dir: '%s'\n", dirname); - flock = Lock(dirname, SHARED_LOCK); - if (Examine(flock, &fileinfo)) { - while (ExNext(flock, &fileinfo)) { - print_fileinfo(&fileinfo); - } - error = IoErr(); - if (error != ERROR_NO_MORE_ENTRIES) { - puts("unknown I/O error, TODO handle"); - } - } - UnLock(flock); - */ if (req_opened = Request(&requester, req_window)) { - // Note that we need to render into the requester - // layer's rastport, because it is rendered on top of the - // parent window and obscures the content - struct RastPort *src_rp = &filelist_rastport; - struct RastPort *dst_rp = requester.ReqLayer->rp; - - // make sure drawing is clipped, otherwise it will - // draw somewhere else into memory - SetAPen(src_rp, 1); - Move(src_rp, 8, 10); - Text(src_rp, "filename1.txt", 13); - Move(src_rp, 8, 20); - Text(src_rp, "filename2.txt", 13); - /* - BltBitMap(&filelist_bitmap, 0, 0, - req_window->RPort->BitMap, 10, 10, FILE_LIST_WIDTH, FILE_LIST_HEIGHT, - 0xc0, 0xff, 0); // Minterm, mask, TempA - */ - BltBitMapRastPort(&filelist_bitmap, 0, 0, dst_rp, - FILE_LIST_BM_X, FILE_LIST_BM_Y, FILE_LIST_BM_WIDTH, FILE_LIST_BM_HEIGHT, - 0xc0); + draw_list(); handle_events(); CloseWindow(req_window); req_window = NULL; diff --git a/requesters/gfx/down11x11.xcf b/requesters/gfx/down11x11.xcf new file mode 100644 index 0000000000000000000000000000000000000000..21bafd64e820adc06ef7e7cc3a8c2d72aa9a9820 GIT binary patch literal 726 zcmZ`%OHRWu5Ou;Yv{d|AvG6io1f^Ffi;4vjS4b1bwaBMRQb_N>f&*|B?$s6HO|VNU z!bnf^{AQl*WGq#>NTg)x1bs~6~Cn_2b z+*pQrk{8@PI{|Q;^av6jwlYC;%g1GJzwdSodRdJPt z3sI6kkK&s%{cSW2ibH^=(*TaJ4KRWy>rV!#eo6nuQ{`4{GcYV_O=*I@@D)b@9I-YgMemNT*7S-C0O(_9bo3U#Geh zI*k^xAb%Feg)Ey3lKXG!H?wP{|6swtoI-TtIwCy@qZgHD>$LuDG!4QrNYgQ3*J_&1 ziPZ?~uBCe|P1}=~a0)s-Xz4R(+Sh?zjO%N^3|sdqE8Nv_Pw#y<=Y7(;VtvzPyx{@+ XHh5#)c+3O2;oz1Td>GhiI{W4akV