Skip to content

Commit f457a75

Browse files
committed
Add dragon support
Add runtime detection of dragon to fujinet-lib for coco.
1 parent 5ba6fb3 commit f457a75

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

coco/src/bus/bus_ready.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
#include <dw.h>
1212
#include <fujinet-fuji-coco.h>
1313

14+
15+
#define DWWRT_VEC_DRG 0xD941
16+
#define DWREAD_VEC_DRG 0xD93F
17+
#define DWWRT_VEC_COCO 0xFA00
18+
#define DWREAD_VEC_COCO 0xF9FE
19+
20+
static gbDWInited = false;
21+
// default to coco read/write if not inited.
22+
dwvec dwreadvec = DWREAD_VEC_COCO;
23+
dwvec dwwritevec = DWWRT_VEC_COCO;
24+
25+
// detection logic for dragon stolen from: https://exileinparadise.com/tandy_color_computer:keyscn2
26+
//
27+
const uint16_t* RESET = 0xFFFE; // Address of MPU Reset Vector
28+
const uint16_t VECCOCO = 0xA027; // CoCo 1/2 reset vector value
29+
const uint16_t VECDRGN = 0xB3B4; // Dragon32/64 reset vector value
30+
const uint16_t VECCOCO3 = 0x8C1B; // CoCo3 reset vector value
31+
1432
void bus_ready(void)
1533
{
1634
struct _readycmd
@@ -19,6 +37,16 @@ void bus_ready(void)
1937
uint8_t command;
2038
} rc;
2139

40+
if (!gbDWInited)
41+
{
42+
if (*RESET==VECDRGN)
43+
{
44+
dwreadvec = DWREAD_VEC_DRG;
45+
dwwritevec = DWWRT_VEC_DRG;
46+
}
47+
gbDWInited = true;
48+
}
49+
2250
uint8_t z=0, r;
2351

2452
rc.opcode = OP_FUJI;

coco/src/bus/dwread.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
#include <cmoc.h>
9-
10-
typedef unsigned char byte;
9+
#include <coco.h>
10+
#include "dw.h"
1111

1212
byte dwread(byte *s, int l)
1313
{
@@ -16,7 +16,7 @@ byte dwread(byte *s, int l)
1616
pshs x,y
1717
ldx :s
1818
ldy :l
19-
jsr [0xD93F]
19+
jsr [dwreadvec]
2020
puls y,x
2121
tfr cc,b
2222
lsrb

coco/src/bus/dwwrite.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <cmoc.h>
99
#include <coco.h>
10+
#include "dw.h"
11+
1012

1113
byte dwwrite(byte *s, int l)
1214
{
@@ -15,7 +17,7 @@ byte dwwrite(byte *s, int l)
1517
pshs x,y
1618
ldx :s
1719
ldy :l
18-
jsr [0xD941]
20+
jsr [dwwritevec]
1921
tfr cc,d
2022
puls y,x
2123
}

coco/src/include/dw.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#define OP_FUJI 0xE2
1111
#define OP_NET 0xE3
1212

13+
typedef unsigned char (*dwvec)(unsigned char);
14+
15+
extern dwvec dwreadvec;
16+
extern dwvec dwwritevec;
17+
18+
1319
/**
1420
* @brief Read string to s from DriveWire with expected length l
1521
* @param s pointer to string buffer

0 commit comments

Comments
 (0)