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
This commit is contained in:
Wei-ju Wu 2016-01-16 13:36:19 -08:00
parent 766df0d2ab
commit 037bf7bb4a
6 changed files with 193 additions and 63 deletions

View File

@ -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 $@

94
requesters/dos13.c Normal file
View File

@ -0,0 +1,94 @@
#include "dos13.h"
#include <stdlib.h>
#include <string.h>
#include <dos/dosextens.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_stdio_protos.h>
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;
}
}

33
requesters/dos13.h Normal file
View File

@ -0,0 +1,33 @@
// dos13 - a module for DOS 1.x interaction
#pragma once
#ifndef __DOS13_H__
#define __DOS13_H__
#include <exec/types.h>
#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

View File

@ -1,4 +1,6 @@
#include <string.h>
#include <intuition/intuition.h>
#include <dos/dosextens.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
@ -7,6 +9,14 @@
#include <clib/alib_stdio_protos.h>
#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;

Binary file not shown.

BIN
requesters/gfx/up11x11.xcf Normal file

Binary file not shown.