@@ -196,6 +196,66 @@ void bmem_copy_to_vmem(bmemptr_t src, vmemptr_t dst, uint32_t len);
196196 */
197197void bmem_bload_s (bmemptr_t src );
198198
199+ /**
200+ * Load a `BSAVE` formatted binary in banked memory into RAM.
201+ *
202+ * A `BSAVE` formatted binary must consist of a 7-byte header followed by the
203+ * data body, as follows:
204+ *
205+ * | address | contents |
206+ * |---------------|----------------------------|
207+ * | `src+0` | `0xFE` |
208+ * | `src+1` | lo-byte of `start` address |
209+ * | `src+2` | hi-byte of `start` address |
210+ * | `src+3` | lo-byte of `end` address |
211+ * | `src+4` | hi-byte of `end` address |
212+ * | `src+5` | lo-byte of `run` address |
213+ * | `src+6` | hi-byte of `run` address |
214+ * | `src+7` | `body[0]` |
215+ * | ... | ... |
216+ * | `src+7 + N-1` | `body[N-1]` |
217+ *
218+ * where `N == end - start + 1`, and `start <= end`.
219+ *
220+ * `start` and `end` are the range of addresses where the data body was, and
221+ * `run` is the address of the entry point (ignored by libmsx).
222+ *
223+ * This function copies the body of the data to the specified buffer starting
224+ * with `buf`.
225+ *
226+ * Do nothing in the following cases
227+ * - The data pointed by `src` is not a `BSAVE` formatted binary.
228+ * - Buffer size is too small.
229+ *
230+ * \param src Address of `BSAVE` foramtted binary in banked memory.
231+ * \param buf Pointer to the RAM buffer.
232+ * \param buf_size Buffer size (i.e., capacity) in bytes.
233+ *
234+ * \note
235+ * This function is supposed to copy from banked memory to page 3 of main RAM.
236+ * Thus the buffer specified by `buf` and `buf_size` must be in range of
237+ * `0xc000` to `0xfffe`. In `libmsx`, the `DATA` segment and stack areas are
238+ * placed on page 3 so this is reasonable.
239+ *
240+ * \note
241+ * In particular, page 2 is used to access banked memory so the buffer cannot be
242+ * in page 2. Page 0 is MAIN ROM, page 1 is `CODE` segment, and the library code
243+ * itself is included in `CODE` segment. So these areas cannot be specified as
244+ * the buffer.
245+ *
246+ * \note
247+ * Address `0xffff` is not memory, that is "extended slot selector" register.
248+ *
249+ * \attention
250+ * Stack areas and work areas are overridden if they intersect the buffer
251+ * specified by `buf` and `buf_size`. Unfortunately, however, the library cannot
252+ * determine the appropriate bounds. The application programmer must deal with
253+ * this.
254+ *
255+ * \sa bmem_read()
256+ */
257+ void bmem_bload (bmemptr_t src , void * buf , size_t buf_size );
258+
199259/** @} */
200260
201261#endif // BMEM_H_
0 commit comments