Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions coco/src/bus/bus_ready.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
#include <dw.h>
#include <fujinet-fuji-coco.h>


#define DWWRT_VEC_DRG 0xD941
#define DWREAD_VEC_DRG 0xD93F
#define DWWRT_VEC_COCO 0xFA00
#define DWREAD_VEC_COCO 0xF9FE

static gbDWInited = false;
// default to coco read/write if not inited.
dwvec dwreadvec = DWREAD_VEC_COCO;
dwvec dwwritevec = DWWRT_VEC_COCO;

// detection logic for dragon stolen from: https://exileinparadise.com/tandy_color_computer:keyscn2
//
const uint16_t* RESET = 0xFFFE; // Address of MPU Reset Vector
const uint16_t VECCOCO = 0xA027; // CoCo 1/2 reset vector value
const uint16_t VECDRGN = 0xB3B4; // Dragon32/64 reset vector value
const uint16_t VECCOCO3 = 0x8C1B; // CoCo3 reset vector value

void bus_ready(void)
{
struct _readycmd
Expand All @@ -19,6 +37,16 @@ void bus_ready(void)
uint8_t command;
} rc;

if (!gbDWInited)
{
if (*RESET==VECDRGN)
{
dwreadvec = DWREAD_VEC_DRG;
dwwritevec = DWWRT_VEC_DRG;
}
gbDWInited = true;
}

uint8_t z=0, r;

rc.opcode = OP_FUJI;
Expand Down
6 changes: 3 additions & 3 deletions coco/src/bus/dwread.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

#include <cmoc.h>

typedef unsigned char byte;
#include <coco.h>
#include "dw.h"

byte dwread(byte *s, int l)
{
Expand All @@ -16,7 +16,7 @@ byte dwread(byte *s, int l)
pshs x,y
ldx :s
ldy :l
jsr [0xD93F]
jsr [dwreadvec]
puls y,x
tfr cc,b
lsrb
Expand Down
4 changes: 3 additions & 1 deletion coco/src/bus/dwwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <cmoc.h>
#include <coco.h>
#include "dw.h"


byte dwwrite(byte *s, int l)
{
Expand All @@ -15,7 +17,7 @@ byte dwwrite(byte *s, int l)
pshs x,y
ldx :s
ldy :l
jsr [0xD941]
jsr [dwwritevec]
tfr cc,d
puls y,x
}
Expand Down
6 changes: 6 additions & 0 deletions coco/src/include/dw.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#define OP_FUJI 0xE2
#define OP_NET 0xE3

typedef unsigned char (*dwvec)(unsigned char);

extern dwvec dwreadvec;
extern dwvec dwwritevec;


/**
* @brief Read string to s from DriveWire with expected length l
* @param s pointer to string buffer
Expand Down