1.1 --- a/src/wd279x.h Sun Dec 05 03:55:46 2010 +0000 1.2 +++ b/src/wd279x.h Sun Dec 05 10:17:38 2010 +0000 1.3 @@ -6,13 +6,21 @@ 1.4 #include <stdint.h> 1.5 #include <stdio.h> 1.6 1.7 -enum { 1.8 - WD279X_REG_STATUS = 0, 1.9 - WD279X_REG_COMMAND = 0, 1.10 - WD279X_REG_TRACK = 1, 1.11 - WD279X_REG_SECTOR = 2, 1.12 - WD279X_REG_DATA = 3 1.13 -} WD279X_REG; 1.14 +/// WD279x registers 1.15 +typedef enum { 1.16 + WD2797_REG_STATUS = 0, ///< Status register 1.17 + WD2797_REG_COMMAND = 0, ///< Command register 1.18 + WD2797_REG_TRACK = 1, ///< Track register 1.19 + WD2797_REG_SECTOR = 2, ///< Sector register 1.20 + WD2797_REG_DATA = 3 ///< Data register 1.21 +} WD2797_REG; 1.22 + 1.23 +/// WD279x emulator error codes 1.24 +typedef enum { 1.25 + WD2797_ERR_OK = 0, ///< Operation succeeded 1.26 + WD2797_ERR_BAD_GEOM = -1, ///< Bad geometry, or image file too small 1.27 + WD2797_ERR_NO_MEMORY = -2 ///< Out of memory 1.28 +} WD2797_ERR; 1.29 1.30 typedef struct { 1.31 // Current track, head and sector 1.32 @@ -33,10 +41,78 @@ 1.33 // Last step direction. -1 for "towards zero", 1 for "away from zero" 1.34 int last_step_dir; 1.35 // Data buffer, current DRQ pointer and length 1.36 - uint8_t data[1024]; 1.37 + uint8_t *data; 1.38 size_t data_pos, data_len; 1.39 // Current disc image file 1.40 FILE *disc_image; 1.41 -} WD279X_CTX; 1.42 +} WD2797_CTX; 1.43 + 1.44 +/** 1.45 + * @brief Initialise a WD2797 context. 1.46 + * @param ctx WD2797 context. 1.47 + * 1.48 + * This must be run once when the context is created. 1.49 + */ 1.50 +void wd2797_init(WD2797_CTX *ctx); 1.51 + 1.52 +/** 1.53 + * @brief Reset a WD2797 context. 1.54 + * @param ctx WD2797 context. 1.55 + * 1.56 + * This should be run if the WD2797 needs to be reset (nRST line toggled). 1.57 + */ 1.58 +void wd2797_reset(WD2797_CTX *ctx); 1.59 + 1.60 +/** 1.61 + * Deinitialise a WD2797 context. 1.62 + * @param ctx WD2797 context. 1.63 + */ 1.64 +void wd2797_done(WD2797_CTX *ctx); 1.65 + 1.66 +/** 1.67 + * @brief Read IRQ Rising Edge status. Clears Rising Edge status if it is set. 1.68 + * @note No more IRQs will be sent until the Status Register is read, or a new command is written to the CR. 1.69 + * @param ctx WD2797 context. 1.70 + */ 1.71 +bool wd2797_get_irq(WD2797_CTX *ctx); 1.72 + 1.73 +/** 1.74 + * @brief Read DRQ status. 1.75 + * @param ctx WD2797 context. 1.76 + */ 1.77 +bool wd2797_get_drq(WD2797_CTX *ctx); 1.78 + 1.79 +/** 1.80 + * @brief Assign a disc image to the WD2797. 1.81 + * @param ctx WD2797 context. 1.82 + * @param fp Disc image file, already opened in "r+b" mode. 1.83 + * @param secsz Sector size: either 128, 256, 512 or 1024. 1.84 + * @param spt Sectors per track. 1.85 + * @param heads Number of heads (1 or 2). 1.86 + * @return Error code; WD279X_E_OK if everything worked OK. 1.87 + */ 1.88 +WD2797_ERR wd2797_load(WD2797_CTX *ctx, FILE *fp, int secsz, int spt, int heads); 1.89 + 1.90 +/** 1.91 + * @brief Deassign the current image file. 1.92 + * @param ctx WD2797 context. 1.93 + */ 1.94 +void wd2797_unload(WD2797_CTX *ctx); 1.95 + 1.96 +/** 1.97 + * @brief Read WD279x register. 1.98 + * @param ctx WD2797 context 1.99 + * @param addr Register address (0, 1, 2 or 3) 1.100 + */ 1.101 +uint8_t wd2797_read_reg(WD2797_CTX *ctx, uint8_t addr); 1.102 + 1.103 +/** 1.104 + * @brief Write WD279X register 1.105 + * @param ctx WD2797 context 1.106 + * @param addr Register address (0, 1, 2 or 3) 1.107 + * @param val Value to write 1.108 + */ 1.109 +void wd2797_write_reg(WD2797_CTX *ctx, uint8_t addr, uint8_t val); 1.110 + 1.111 1.112 #endif