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