-
Notifications
You must be signed in to change notification settings - Fork 202
Add libcart #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add libcart #752
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dd08b7f
git subrepo clone https://github.com/devwizard64/libcart src/libcart
727d1a7
git subrepo commit src/libcart
2a06667
libcart builds
37ac4b8
default libcart to 0
799a811
document libcart
975f106
git subrepo commit src/libcart
b45d0b8
git subrepo commit src/libcart
543d7ad
delete the c files again
7f00c67
git subrepo commit src/libcart
ab073c6
update contributor instructions
55dab0c
remove the files again
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // most stdint types are in ultratypes.h, add any necessary extras here | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <PR/ultratypes.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /build/ | ||
| /lib/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ; DO NOT EDIT (unless you know what you are doing) | ||
| ; | ||
| ; This subdirectory is a git "subrepo", and this file is maintained by the | ||
| ; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme | ||
| ; | ||
| [subrepo] | ||
| remote = https://github.com/devwizard64/libcart | ||
| branch = main | ||
| commit = 948358b8320f49e75b4a9e3b4e792ccaec866e0b | ||
| parent = 543d7add024fea312a8991b29a029a0ac0ed7bef | ||
| method = merge | ||
| cmdver = 0.4.6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Copyright (C) 2022 - 2023 devwizard | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software is furnished to do so. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # libcart - Nintendo 64 flash cartridge library | ||
| Copyright (C) 2022 - 2023 devwizard | ||
|
|
||
| ## About | ||
| This library provides an interface to several Nintendo 64 flash cartridges. It | ||
| automatically detects the hardware in use, and uses the appropriate protocol for | ||
| the hardware. | ||
|
|
||
| ## Supported hardware | ||
| * 64Drive HW1 and HW2 | ||
| * EverDrive-64 V1, V2, V2.5, V3, X7 and X5 | ||
| * ED64Plus / Super 64 | ||
| * SummerCart64 | ||
|
|
||
| [Testing result spreadsheet](https://docs.google.com/spreadsheets/d/19opOv4e_4ABqgOmqRBSREtXLdGy08VzMsymtxWky0NU/edit?usp=sharing) | ||
|
|
||
| ## Features | ||
| * Unlocks the cartridge ROM, making it rewritable. | ||
| * Uses optimised bus timing for faster DMA (EverDrive-64). | ||
| * Memory card access, with I/O between RDRAM and cartridge ROM. | ||
|
|
||
| ## Credits | ||
| Special thanks to Reonu and Meeq for their extensive testing on ED64Plus and | ||
| EverDrive-64 V2. Without them, this project would not be possible. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /*-----------------------------------------------------------------------*/ | ||
| /* Low level disk I/O module for FatFs (libcart) (C)ChaN, 2019 */ | ||
| /* (C)devwizard, 2022-2023 */ | ||
| /*-----------------------------------------------------------------------*/ | ||
|
|
||
| #include "ff.h" /* Obtains integer types */ | ||
| #include "diskio.h" /* Declarations of disk functions */ | ||
| #ifdef _ULTRA64 | ||
| #include <ultra64.h> | ||
| #else | ||
| #include <libdragon.h> | ||
| #endif | ||
| #include <cart.h> | ||
|
|
||
| /* Definitions of physical drive number for each drive */ | ||
| #define DEV_CARD 0 /* Cartridge memory card */ | ||
|
|
||
|
|
||
| static DSTATUS card_status; | ||
|
|
||
| /*-----------------------------------------------------------------------*/ | ||
| /* Get Drive Status */ | ||
| /*-----------------------------------------------------------------------*/ | ||
|
|
||
| DSTATUS disk_status ( | ||
| BYTE pdrv /* Physical drive nmuber to identify the drive */ | ||
| ) | ||
| { | ||
| switch (pdrv) { | ||
| case DEV_CARD : | ||
| return card_status; | ||
| } | ||
| return STA_NOINIT; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /*-----------------------------------------------------------------------*/ | ||
| /* Inidialize a Drive */ | ||
| /*-----------------------------------------------------------------------*/ | ||
|
|
||
| DSTATUS disk_initialize ( | ||
| BYTE pdrv /* Physical drive nmuber to identify the drive */ | ||
| ) | ||
| { | ||
| switch (pdrv) { | ||
| case DEV_CARD : | ||
| return card_status = cart_card_init() ? STA_NOINIT : 0; | ||
| } | ||
| return STA_NOINIT; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /*-----------------------------------------------------------------------*/ | ||
| /* Read Sector(s) */ | ||
| /*-----------------------------------------------------------------------*/ | ||
|
|
||
| DRESULT disk_read ( | ||
| BYTE pdrv, /* Physical drive nmuber to identify the drive */ | ||
| BYTE *buff, /* Data buffer to store read data */ | ||
| LBA_t sector, /* Start sector in LBA */ | ||
| UINT count /* Number of sectors to read */ | ||
| ) | ||
| { | ||
| u32 addr; | ||
|
|
||
| switch (pdrv) { | ||
| case DEV_CARD : | ||
| #ifdef _ULTRA64 | ||
| addr = osVirtualToPhysical(buff); | ||
| #else | ||
| addr = PhysicalAddr(buff); | ||
| #endif | ||
| if (addr < 0x800000) return cart_card_rd_dram(buff, sector, count) ? RES_ERROR : RES_OK; | ||
| else return cart_card_rd_cart(addr, sector, count) ? RES_ERROR : RES_OK; | ||
| } | ||
|
|
||
| return RES_PARERR; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /*-----------------------------------------------------------------------*/ | ||
| /* Write Sector(s) */ | ||
| /*-----------------------------------------------------------------------*/ | ||
|
|
||
| #if FF_FS_READONLY == 0 | ||
|
|
||
| DRESULT disk_write ( | ||
| BYTE pdrv, /* Physical drive nmuber to identify the drive */ | ||
| const BYTE *buff, /* Data to be written */ | ||
| LBA_t sector, /* Start sector in LBA */ | ||
| UINT count /* Number of sectors to write */ | ||
| ) | ||
| { | ||
| u32 addr; | ||
|
|
||
| switch (pdrv) { | ||
| case DEV_CARD : | ||
| #ifdef _ULTRA64 | ||
| addr = osVirtualToPhysical((void *)buff); | ||
| #else | ||
| addr = PhysicalAddr(buff); | ||
| #endif | ||
| if (addr < 0x800000) return cart_card_wr_dram(buff, sector, count) ? RES_ERROR : RES_OK; | ||
| else return cart_card_wr_cart(addr, sector, count) ? RES_ERROR : RES_OK; | ||
| } | ||
|
|
||
| return RES_PARERR; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
|
|
||
| /*-----------------------------------------------------------------------*/ | ||
| /* Miscellaneous Functions */ | ||
| /*-----------------------------------------------------------------------*/ | ||
|
|
||
| DRESULT disk_ioctl ( | ||
| BYTE pdrv, /* Physical drive nmuber (0..) */ | ||
| BYTE cmd, /* Control code */ | ||
| void *buff /* Buffer to send/receive control data */ | ||
| ) | ||
| { | ||
| (void)buff; | ||
|
|
||
| switch (pdrv) { | ||
| case DEV_CARD : | ||
| switch (cmd) { | ||
| #if !FF_FS_READONLY | ||
| case CTRL_SYNC: | ||
| return RES_OK; | ||
| #endif | ||
|
|
||
| #if !FF_FS_READONLY && FF_USE_MKFS | ||
| #if 0 | ||
| case GET_SECTOR_COUNT: | ||
| *(LBA_t *)buff = 0; | ||
| break; | ||
| #endif | ||
| #endif | ||
|
|
||
| #if FF_MAX_SS != FF_MIN_SS | ||
| case GET_SECTOR_SIZE: | ||
| *(WORD *)buff = 512; | ||
| return RES_OK; | ||
| #endif | ||
|
|
||
| #if !FF_FS_READONLY && FF_USE_MKFS | ||
| case GET_BLOCK_SIZE: | ||
| *(DWORD *)buff = 512; | ||
| return RES_OK; | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| return RES_PARERR; | ||
| } | ||
|
|
||
|
|
||
| #if !FF_FS_READONLY && !FF_FS_NORTC | ||
|
|
||
| DWORD get_fattime (void) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| #endif | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /*-----------------------------------------------------------------------/ | ||
| / Low level disk interface modlue include file (C)ChaN, 2019 / | ||
| /-----------------------------------------------------------------------*/ | ||
|
|
||
| #ifndef _DISKIO_DEFINED | ||
| #define _DISKIO_DEFINED | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* Status of Disk Functions */ | ||
| typedef BYTE DSTATUS; | ||
|
|
||
| /* Results of Disk Functions */ | ||
| typedef enum { | ||
| RES_OK = 0, /* 0: Successful */ | ||
| RES_ERROR, /* 1: R/W Error */ | ||
| RES_WRPRT, /* 2: Write Protected */ | ||
| RES_NOTRDY, /* 3: Not Ready */ | ||
| RES_PARERR /* 4: Invalid Parameter */ | ||
| } DRESULT; | ||
|
|
||
|
|
||
| /*---------------------------------------*/ | ||
| /* Prototypes for disk control functions */ | ||
|
|
||
|
|
||
| DSTATUS disk_initialize (BYTE pdrv); | ||
| DSTATUS disk_status (BYTE pdrv); | ||
| DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count); | ||
| DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count); | ||
| DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); | ||
|
|
||
|
|
||
| /* Disk Status Bits (DSTATUS) */ | ||
|
|
||
| #define STA_NOINIT 0x01 /* Drive not initialized */ | ||
| #define STA_NODISK 0x02 /* No medium in the drive */ | ||
| #define STA_PROTECT 0x04 /* Write protected */ | ||
|
|
||
|
|
||
| /* Command code for disk_ioctrl fucntion */ | ||
|
|
||
| /* Generic command (Used by FatFs) */ | ||
| #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ | ||
| #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ | ||
| #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ | ||
| #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ | ||
| #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ | ||
|
|
||
| /* Generic command (Not used by FatFs) */ | ||
| #define CTRL_POWER 5 /* Get/Set power status */ | ||
| #define CTRL_LOCK 6 /* Lock/Unlock media removal */ | ||
| #define CTRL_EJECT 7 /* Eject media */ | ||
| #define CTRL_FORMAT 8 /* Create physical format on the media */ | ||
|
|
||
| /* MMC/SDC specific ioctl command */ | ||
| #define MMC_GET_TYPE 10 /* Get card type */ | ||
| #define MMC_GET_CSD 11 /* Get CSD */ | ||
| #define MMC_GET_CID 12 /* Get CID */ | ||
| #define MMC_GET_OCR 13 /* Get OCR */ | ||
| #define MMC_GET_SDSTAT 14 /* Get SD status */ | ||
| #define ISDIO_READ 55 /* Read data form SD iSDIO register */ | ||
| #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ | ||
| #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ | ||
|
|
||
| /* ATA/CF specific ioctl command */ | ||
| #define ATA_GET_REV 20 /* Get F/W revision */ | ||
| #define ATA_GET_MODEL 21 /* Get model name */ | ||
| #define ATA_GET_SN 22 /* Get serial number */ | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of subrepos over submodules exactly, and is it necessary here? Seems like subrepos aren't an actual part of git, so I'm hesitant to use this unless submodules/subtrees are no good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
submodules are an extra command for the end user which is Bad™ (think changing the required baserom name bad)
maintaining the subrepo is on the contributors with zero work for the end user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is? Cloning a repo with a submodule doesn't also clone the submodule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an end user would have to either run
git clone --recursiveorgit submodule init --updateafter a clone to grab those submodulesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welp...that sucks. What about with subtrees?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those work but i found them harder to maintain (s2dex text engine used to be a subtree here but i just made it part of the main repo eventually)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, whatever then. Could you update the libpl PR to use subrepos then since it sounds like submodules are bad