From 66b99dc952d149134aa5862e3d5e95cfb9f15138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Wed, 6 May 2026 23:16:41 -0300 Subject: [PATCH 01/13] document ACUART params Added parameters section with descriptions and example usage. --- iop/arcade/acuart/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/iop/arcade/acuart/README.md b/iop/arcade/acuart/README.md index 017bf3002e6a..db504cffb41e 100644 --- a/iop/arcade/acuart/README.md +++ b/iop/arcade/acuart/README.md @@ -22,3 +22,18 @@ The UART is easily accesible through the white JST 3 pin connector located on th From left to right, the pins are: RX, TX, GND. An USB to RS232 (usually with DB9 connector) is recommended + +## Parameters + +param | parameter | description +----- | ----------- | --------- +`-x` | number | size of output buffer +`-r` | number | size of input buffer +`-l` | none | enables loopback +`-b` | number | sets baud +`-f` | number | fifo + +example +```c +const char* args = "-x" "\0" "2048" "\0" "-b" "\0" "115200"; +``` From 6f4e230c01fd6b380b13d31184d89462f1518e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sun, 10 May 2026 23:28:57 -0300 Subject: [PATCH 02/13] acmeme: more readability on it's only available parameter --- iop/arcade/acmeme/src/meme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iop/arcade/acmeme/src/meme.c b/iop/arcade/acmeme/src/meme.c index df3bd9431e5f..7b26472e921e 100644 --- a/iop/arcade/acmeme/src/meme.c +++ b/iop/arcade/acmeme/src/meme.c @@ -528,11 +528,11 @@ int acMemeModuleStart(int argc, char **argv) while ( index < argc ) { opt = *v8; - if ( **v8 == 45 ) + if ( **v8 == '-' ) { v10 = opt[1]; opt_v7 = opt + 2; - if ( v10 == 112 ) + if ( v10 == 'p' ) { value = strtol(opt_v7, &next, 0); if ( next != opt_v7 ) From 6cc91665f0af6554f9616e574d02f1f40f70382c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:11:12 -0300 Subject: [PATCH 03/13] propagate more ata macros --- iop/arcade/acata/src/atapicmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index 7fefe2c3e331..d2092fc10215 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -86,7 +86,7 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) *((volatile acUint16 *)0xB6060000) = flag & 0x10; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; *((volatile acUint16 *)0xB6010000) = flag & 1; - *((volatile acUint16 *)0xB6070000) = 160; // ATA_STAT_BUSY|ATA_STAT_READY? + *((volatile acUint16 *)0xB6070000) = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? tmout = 999; v6 = 1000; // cppcheck-suppress knownConditionTrueFalse @@ -534,7 +534,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) v6 = 0; if ( (flag & 2) != 0 ) { - while ( (*((volatile acUint16 *)0xB6160000) & 0x81) == ATA_STAT_BUSY ) + while ( (*((volatile acUint16 *)0xB6160000) & (ATA_STAT_BUSY|ATA_STAT_ERR) == ATA_STAT_BUSY ) { if ( SleepThread() ) { @@ -548,7 +548,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) int tmout; tmout = 99999; - while ( (*((volatile acUint16 *)0xB6070000) & 0x81) == ATA_STAT_BUSY ) + while ( (*((volatile acUint16 *)0xB6070000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( tmout < 0 ) { From af442a6d948068bf2bcee055d69040ed9ec64af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:13:23 -0300 Subject: [PATCH 04/13] implement names for ACATA regs --- iop/arcade/acata/src/acata_internal.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/iop/arcade/acata/src/acata_internal.h b/iop/arcade/acata/src/acata_internal.h index 202288cbb9e3..dd0919208d65 100644 --- a/iop/arcade/acata/src/acata_internal.h +++ b/iop/arcade/acata/src/acata_internal.h @@ -14,6 +14,22 @@ #include #include +#define ACATA_A_DATA 0xB6000000 // Read/Write PIO data bytes + +#define ACATA_R_DATA *((acAtaReg)0xB6000000) // Read/Write PIO data bytes +#define ACATA_R_FEATURES *((acAtaReg)0xB6010000) // [W] Used to control command specific interface features. +#define ACATA_R_ERROR ACATA_R_FEATURES // [R] Used to retrieve any error generated by the last ATA command executed. +#define ACATA_R_SECCNT *((acAtaReg)0xB6020000) // Number of sectors to read/write (0 is a special value). +#define ACATA_R_SECNUM *((acAtaReg)0xB6030000) // This is CHS / LBA28 / LBA48 specific. +#define ACATA_R_CYL_LOW *((acAtaReg)0xB6040000) // Partial Disk Sector address. +#define ACATA_R_CYL_HIGH *((acAtaReg)0xB6050000) // Partial Disk Sector address. +#define ACATA_R_DRIVE_HEAD *((acAtaReg)0xB6060000) // Used to select a drive and/or head. Supports extra address/flag bits. [`ACATA_UNIT0`, `ACATA_UNIT1`] +#define ACATA_R_STATUS *((acAtaReg)0xB6070000) // [R] Used to read the current status. +#define ACATA_R_COMMAND ACATA_R_STATUS // [W] Used to send ATA commands to the device. +#define ACATA_R_ALT_STATUS *((acAtaReg)0xB6160000) // [R] Used to read the current status. +#define ACATA_R_ALT_COMMAND ACATA_R_ALT_STATUS // [W] Used to send ATA commands to the device. + + struct ata_softc { acQueueHeadData requestq; From 78dc6d99f59bd27e8c34f06c4a3b46bff8808620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:40:01 -0300 Subject: [PATCH 05/13] acata: propagate macro for DATA register in form of reg (vu16 dereference included on macro) and address --- iop/arcade/acata/src/ata.c | 2 +- iop/arcade/acata/src/atacmd.c | 10 +++++----- iop/arcade/acata/src/atapicmd.c | 18 +++++++++--------- iop/arcade/acatad/src/acatad.c | 2 +- iop/arcade/accore/src/dma.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index 7d3105a05638..9a90d6c36472 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -304,7 +304,7 @@ int acAtaModuleStart(int argc, char **argv) Atac.requestq.q_next = 0; DelayThread(delay); ChangeThreadPriority(0, 123); - index_v12 = ata_probe((acAtaReg)0xB6000000); + index_v12 = ata_probe((acAtaReg)ACATA_A_DATA); Atac.active = index_v12; if ( index_v12 == 0 ) { diff --git a/iop/arcade/acata/src/atacmd.c b/iop/arcade/acata/src/atacmd.c index 6d743e187a2e..39b97d73e108 100644 --- a/iop/arcade/acata/src/atacmd.c +++ b/iop/arcade/acata/src/atacmd.c @@ -29,7 +29,7 @@ static int ata_dma_xfer(acDmaT dma, int intr, acDmaOp op) if ( dmatmp->ad_state == 31 ) { dmatmp->ad_result = dmatmp->ad_ata->ac_h.a_size; - return op(dma, (void *)0xB6000000, dmatmp->ad_ata->ac_h.a_buf, dmatmp->ad_ata->ac_h.a_size); + return op(dma, (void *)ACATA_A_DATA, dmatmp->ad_ata->ac_h.a_buf, dmatmp->ad_ata->ac_h.a_size); } thid = dmatmp->ad_thid; dmatmp->ad_state = 3; @@ -151,7 +151,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) int data; data = *cmd++; - *(acUint16 *)(((2 * ((data >> 8) & 8) + ((data >> 8) & 7)) << 16) + 0xB6000000) = data & 0xFF; + *(acUint16 *)(((2 * ((data >> 8) & 8) + ((data >> 8) & 7)) << 16) + ACATA_A_DATA) = data & 0xFF; --count; if ( ((data >> 8) & 0xF) == 7 ) { @@ -209,7 +209,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) ret_v17 = *a_buf; a_buf++; } - *((volatile acUint16 *)0xB6000000) = ret_v17; + ACATA_R_DATA = ret_v17; --xlen_v16; } if ( (flag_v8 & 2) != 0 ) @@ -290,7 +290,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) { if ( xlen_v30 >= 0 ) { - *buf_v23 = *((volatile acUint16 *)0xB6000000); + *buf_v23 = ACATA_R_DATA; buf_v23++; } --xlen_v30; @@ -403,7 +403,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) break; *cmd_v36 = ((((int)*cmd_v36 >> 12) & 0xF) << 12) - | ((*(acUint16 *)(((2 * (((int)*cmd_v36 >> 12) & 8) + (((int)*cmd_v36 >> 12) & 7)) << 16) + 0xB6000000)) & 0xFF); + | ((*(acUint16 *)(((2 * (((int)*cmd_v36 >> 12) & 8) + (((int)*cmd_v36 >> 12) & 7)) << 16) + ACATA_A_DATA)) & 0xFF); ++cmd_v36; } return 6 - rest_v37; diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index d2092fc10215..a745bf82b4e9 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -31,7 +31,7 @@ static int atapi_dma_xfer(acDmaT dma, int intr, acDmaOp op) if ( dmatmp->ad_state == 31 ) { dmatmp->ad_result = dmatmp->ad_atapi->ap_h.a_size; - return op(dma, (void *)0xB6000000, dmatmp->ad_atapi->ap_h.a_buf, dmatmp->ad_atapi->ap_h.a_size); + return op(dma, (void *)ACATA_A_DATA, dmatmp->ad_atapi->ap_h.a_buf, dmatmp->ad_atapi->ap_h.a_size); } thid = dmatmp->ad_thid; dmatmp->ad_state = 3; @@ -112,7 +112,7 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) --count; if ( count < 0 ) break; - *((volatile acUint16 *)0xB6000000) = pkt->u_h[0]; + ACATA_R_DATA = pkt->u_h[0]; pkt = (acAtapiPacketData *)((char *)pkt + 2); } return 0; @@ -174,7 +174,7 @@ static int atapi_pio_read(acAtaReg atareg, acUint16 *buf, int count, int flag) while ( xlen_v8 >= 0 ) { --xlen_v8; - *buf++ = *((volatile acUint16 *)0xB6000000); + *buf++ = ACATA_R_DATA; } sr_v9 = drop + 1; for ( drop_v10 = sr_v9 / 2 - 1; drop_v10 >= 0; --drop_v10 ) @@ -257,7 +257,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) if ( ret_v5 < 0 ) return ret_v5; ChangeThreadPriority(0, cmdpri); - ret_v5 = atapi_packet_send((acAtaReg)0xB6000000, &atapi->ap_packet, flag); + ret_v5 = atapi_packet_send((acAtaReg)ACATA_A_DATA, &atapi->ap_packet, flag); if ( ret_v5 >= 0 ) { int v12; @@ -294,7 +294,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) v15 = (acUint16 *)atah->a_buf; if ( (flag & 4) == 0 ) { - ret_v5 = atapi_pio_read((acAtaReg)0xB6000000, a_buf, atah->a_size, flag); + ret_v5 = atapi_pio_read((acAtaReg)ACATA_A_DATA, a_buf, atah->a_size, flag); } else { @@ -352,12 +352,12 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) xlen_v17 = (xlen_v15 + 1) / 2 - 1; for ( sr_v18 = drop + 1; xlen_v17 >= 0; sr_v18 = drop + 1 ) { - *((volatile acUint16 *)0xB6000000) = *v15; + ACATA_R_DATA = *v15; v15++; --xlen_v17; } for ( drop_v20 = sr_v18 / 2 - 1; drop_v20 >= 0; --drop_v20 ) - *((volatile acUint16 *)0xB6000000) = 0; + ACATA_R_DATA = 0; sr = flag & 2; if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) == 0 ) { @@ -515,7 +515,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) u.lun = atapi->ap_packet.u_b[1]; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; *((volatile acUint16 *)0xB6010000) = 0; - v3 = atapi_packet_send((acAtaReg)0xB6000000, &u.pkt, flag); + v3 = atapi_packet_send((acAtaReg)ACATA_A_DATA, &u.pkt, flag); if ( v3 < 0 ) { ret = v3; @@ -525,7 +525,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) int v4; int v5; - v4 = atapi_pio_read((acAtaReg)0xB6000000, (acUint16 *)&sense, sizeof(sense), flag); + v4 = atapi_pio_read((acAtaReg)ACATA_A_DATA, (acUint16 *)&sense, sizeof(sense), flag); v5 = v4; if ( v4 > 0 ) { diff --git a/iop/arcade/acatad/src/acatad.c b/iop/arcade/acatad/src/acatad.c index 5b92c107cefd..e4186c4fda0a 100644 --- a/iop/arcade/acatad/src/acatad.c +++ b/iop/arcade/acatad/src/acatad.c @@ -203,7 +203,7 @@ ata_devinfo_t *sceAtaInit(int device) int ident_err; u32 total_sectors[2]; - probe_res = ata_probe((acAtaReg)0xB6000000); + probe_res = ata_probe((acAtaReg)ACATA_A_DATA); g_devinfo.has_packet = 0; g_devinfo.exists = device == probe_res - 1; if ( device != probe_res - 1 ) diff --git a/iop/arcade/accore/src/dma.c b/iop/arcade/accore/src/dma.c index f56263f0b6c0..eaee800d0d87 100644 --- a/iop/arcade/accore/src/dma.c +++ b/iop/arcade/accore/src/dma.c @@ -88,7 +88,7 @@ static int dma_xfer(acDmaT dma, void *ioptr, void *buf, int count) attr = dma->d_attr; v12 = GetAcIoDelayReg() & 0x80FFDFFF; v13 = 0x62000000; - if ( ioptr == (void *)0xB6000000 ) + if ( ioptr == (void *)ACATA_A_DATA ) v13 = 0x24000000; SetAcIoDelayReg(v12 | v13); dmac_ch_set_dpcr(8u, (unsigned int)attr >> 5); From a2da94a63babec648e6dc4162b6aa0d22e25ce24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:41:33 -0300 Subject: [PATCH 06/13] acata: propagate macro for FEATURES/ERROR reg --- iop/arcade/acata/src/ata.c | 2 +- iop/arcade/acata/src/atacmd.c | 8 ++++---- iop/arcade/acata/src/atapicmd.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index 9a90d6c36472..b24e0eb02a81 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -201,7 +201,7 @@ int ata_probe(acAtaReg atareg) active = 0; unit = 0; *((volatile acUint16 *)0xB6160000) = 2; - *((volatile acUint16 *)0xB6010000) = 0; + ACATA_R_FEATURES = 0; count = 0; while ( unit < 2 ) { diff --git a/iop/arcade/acata/src/atacmd.c b/iop/arcade/acata/src/atacmd.c index 39b97d73e108..4b33ed6a2625 100644 --- a/iop/arcade/acata/src/atacmd.c +++ b/iop/arcade/acata/src/atacmd.c @@ -145,7 +145,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) flag_v8 = atah->a_flag; *((volatile acUint16 *)0xB6060000) = flag_v8 & 0x10; *((volatile acUint16 *)0xB6160000) = (flag_v8 & 2) ^ 2; - *((volatile acUint16 *)0xB6010000) = 0; + ACATA_R_FEATURES = 0; while ( count >= 0 ) { int data; @@ -320,7 +320,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) "acata:A:dma_iowait: TIMEDOUT %04x:%02x:%02x\n", state, *((volatile acUint16 *)0xB6160000), - *((volatile acUint16 *)0xB6010000)); + ACATA_R_ERROR); if ( state < 1023 ) acDmaCancel(&dma_data.ad_dma, -116); ret = 0; @@ -382,7 +382,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } sr_v34 = *((volatile acUint16 *)0xB6070000); if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_ERR) != 0 ) - return -((sr_v34 << 8) + *((volatile acUint16 *)0xB6010000)); + return -((sr_v34 << 8) + ACATA_R_ERROR); if ( atah->a_state < 0x1FFu ) { atah->a_state = 127; @@ -395,7 +395,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) cmd_v36 = ata->ac_command; if ( ret_v35 < 0 ) { - return -((sr_v34 << 8) + *((volatile acUint16 *)0xB6010000)); + return -((sr_v34 << 8) + ACATA_R_ERROR); } for ( rest_v37 = 6; rest_v37 > 0; --rest_v37 ) { diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index a745bf82b4e9..01082d249266 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -85,7 +85,7 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) *((volatile acUint16 *)0xB6040000) = 64; *((volatile acUint16 *)0xB6060000) = flag & 0x10; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; - *((volatile acUint16 *)0xB6010000) = flag & 1; + ACATA_R_FEATURES = flag & 1; *((volatile acUint16 *)0xB6070000) = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? tmout = 999; v6 = 1000; @@ -437,7 +437,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) "acata:P:dma_iowait: TIMEDOUT %04x:%02x:%02x\n", ret_v23, *((volatile acUint16 *)0xB6160000), - *((volatile acUint16 *)0xB6010000)); + ACATA_R_ERROR); if ( ret_v23 < 1023 ) acDmaCancel(&dma_data.ad_dma, -116); ad_result = 0; @@ -463,7 +463,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) if ( ret_v5 < 0 ) return ret_v5; if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_ERR) != 0 ) - return -((*((volatile acUint16 *)0xB6070000) << 8) + *((volatile acUint16 *)0xB6010000)); + return -((*((volatile acUint16 *)0xB6070000) << 8) + ACATA_R_ERROR); if ( atah->a_state >= 0x1FFu ) { return -116; @@ -514,7 +514,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) u.len = 0x12; u.lun = atapi->ap_packet.u_b[1]; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; - *((volatile acUint16 *)0xB6010000) = 0; + ACATA_R_FEATURES = 0; v3 = atapi_packet_send((acAtaReg)ACATA_A_DATA, &u.pkt, flag); if ( v3 < 0 ) { From 85e961bc85a9212fdbe925802463f0d4a1e142e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:42:55 -0300 Subject: [PATCH 07/13] acata: propagate macro for SECTOR_COUNT reg --- iop/arcade/acata/src/ata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index b24e0eb02a81..2fa61b5628ef 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -190,9 +190,9 @@ int ata_probe(acAtaReg atareg) (void)atareg; while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) != 0 ) ; - *((volatile acUint16 *)0xB6020000) = 4660; + ACATA_R_SECCNT = 4660; // cppcheck-suppress knownConditionTrueFalse - if ( *((volatile acUint16 *)0xB6020000) != 52 ) + if ( ACATA_R_SECCNT != 52 ) return 0; *((volatile acUint16 *)0xB6030000) = 18; // cppcheck-suppress knownConditionTrueFalse From 25e7cc60da77681bd69f803532d8d30bb57b4c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:43:10 -0300 Subject: [PATCH 08/13] acata: propagate macro for SECTOR_NUM reg --- iop/arcade/acata/src/ata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index 2fa61b5628ef..bbaa9e75c01f 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -194,9 +194,9 @@ int ata_probe(acAtaReg atareg) // cppcheck-suppress knownConditionTrueFalse if ( ACATA_R_SECCNT != 52 ) return 0; - *((volatile acUint16 *)0xB6030000) = 18; + ACATA_R_SECNUM = 18; // cppcheck-suppress knownConditionTrueFalse - if ( *((volatile acUint16 *)0xB6030000) != 18 ) + if ( ACATA_R_SECNUM != 18 ) return 0; active = 0; unit = 0; From 6456b0d474a7f68359df57c815703637931ba6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:44:35 -0300 Subject: [PATCH 09/13] acata: propagate macro for CYLINDER regs --- iop/arcade/acata/src/atapicmd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index 01082d249266..8746af02724d 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -81,8 +81,8 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) (void)atareg; count = 6; - *((volatile acUint16 *)0xB6050000) = 0; - *((volatile acUint16 *)0xB6040000) = 64; + ACATA_R_CYL_HIGH = 0; + ACATA_R_CYL_LOW = 64; *((volatile acUint16 *)0xB6060000) = flag & 0x10; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; ACATA_R_FEATURES = flag & 1; @@ -163,7 +163,7 @@ static int atapi_pio_read(acAtaReg atareg, acUint16 *buf, int count, int flag) return sr_v5; if ( (sr_v5 & 8) == 0 ) break; - xlen_v6 = (*((volatile acUint16 *)0xB6050000) << 8) + *((volatile acUint16 *)0xB6040000); + xlen_v6 = (ACATA_R_CYL_HIGH << 8) + ACATA_R_CYL_LOW; drop = xlen_v6 - rest; if ( rest >= xlen_v6 ) drop = 0; @@ -342,7 +342,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) ret_v5 = size - a_size; break; } - xlen_v15 = (*((volatile acUint16 *)0xB6050000) << 8) + *((volatile acUint16 *)0xB6040000); + xlen_v15 = (ACATA_R_CYL_HIGH << 8) + ACATA_R_CYL_LOW; drop = xlen_v15 - a_size; if ( a_size >= xlen_v15 ) drop = 0; From 6de27d4a658adfbbe2a809c1ddc221f0d165e8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:45:37 -0300 Subject: [PATCH 10/13] acata: propagate macro for DRIVE/HEAD reg --- iop/arcade/acata/src/ata.c | 2 +- iop/arcade/acata/src/atacmd.c | 2 +- iop/arcade/acata/src/atapicmd.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index bbaa9e75c01f..08eebfaab975 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -205,9 +205,9 @@ int ata_probe(acAtaReg atareg) count = 0; while ( unit < 2 ) { - *((volatile acUint16 *)0xB6060000) = 16 * (unit != 0); *((volatile acUint16 *)0xB6070000) = 0; *((volatile acUint16 *)0xB6070000) = 0; + ACATA_R_DRIVE_HEAD = 16 * (unit != 0); while ( count <= 1999999 ) { // cppcheck-suppress knownConditionTrueFalse diff --git a/iop/arcade/acata/src/atacmd.c b/iop/arcade/acata/src/atacmd.c index 4b33ed6a2625..205ff4de4de2 100644 --- a/iop/arcade/acata/src/atacmd.c +++ b/iop/arcade/acata/src/atacmd.c @@ -143,7 +143,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) cmd = ata->ac_command; count = 5; flag_v8 = atah->a_flag; - *((volatile acUint16 *)0xB6060000) = flag_v8 & 0x10; + ACATA_R_DRIVE_HEAD = flag_v8 & 0x10; *((volatile acUint16 *)0xB6160000) = (flag_v8 & 2) ^ 2; ACATA_R_FEATURES = 0; while ( count >= 0 ) diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index 8746af02724d..7c643b3461f1 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -83,7 +83,7 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) count = 6; ACATA_R_CYL_HIGH = 0; ACATA_R_CYL_LOW = 64; - *((volatile acUint16 *)0xB6060000) = flag & 0x10; + ACATA_R_DRIVE_HEAD = flag & 0x10; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; ACATA_R_FEATURES = flag & 1; *((volatile acUint16 *)0xB6070000) = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? From 8e149e063b1fab38a2de86436743a9cf83fb163d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 00:52:42 -0300 Subject: [PATCH 11/13] acata: propagate macro for STATUS/CMD reg --- iop/arcade/acata/src/ata.c | 8 ++++---- iop/arcade/acata/src/atacmd.c | 24 ++++++++++++------------ iop/arcade/acata/src/atapicmd.c | 28 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index 08eebfaab975..ea1b4ca6f64b 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -188,7 +188,7 @@ int ata_probe(acAtaReg atareg) int count; (void)atareg; - while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) != 0 ) + while ( (ACATA_R_STATUS & ATA_STAT_BUSY) != 0 ) ; ACATA_R_SECCNT = 4660; // cppcheck-suppress knownConditionTrueFalse @@ -205,13 +205,13 @@ int ata_probe(acAtaReg atareg) count = 0; while ( unit < 2 ) { - *((volatile acUint16 *)0xB6070000) = 0; - *((volatile acUint16 *)0xB6070000) = 0; ACATA_R_DRIVE_HEAD = 16 * (unit != 0); + ACATA_R_COMMAND = 0; + ACATA_R_COMMAND = 0; while ( count <= 1999999 ) { // cppcheck-suppress knownConditionTrueFalse - if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) == 0 ) + if ( (ACATA_R_STATUS & ATA_STAT_BUSY) == 0 ) break; ++count; } diff --git a/iop/arcade/acata/src/atacmd.c b/iop/arcade/acata/src/atacmd.c index 205ff4de4de2..8e93fa7a5d6e 100644 --- a/iop/arcade/acata/src/atacmd.c +++ b/iop/arcade/acata/src/atacmd.c @@ -183,7 +183,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) int a_size; a_size = atah->a_size; - while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) != 0 ) + while ( (ACATA_R_STATUS & ATA_STAT_BUSY) != 0 ) ; while ( a_size > 0 ) { @@ -199,7 +199,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) a_size -= xlen; xlen_v15 = (unsigned int)xlen >> 1; xlen_v16 = xlen_v15 - 1; - while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_DRQ) != 0 ) + while ( (ACATA_R_STATUS & ATA_STAT_DRQ) != 0 ) { int ret_v17; @@ -226,10 +226,10 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } else { - ret_v20 = *((volatile acUint16 *)0xB6070000); + ret_v20 = ACATA_R_STATUS; while ( (ret_v20 & ATA_STAT_BUSY) != 0 ) { - sr = *((volatile acUint16 *)0xB6070000); + sr = ACATA_R_STATUS; ret_v20 = sr & 0xFF; } } @@ -268,10 +268,10 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } else { - sr_v25 = *((volatile acUint16 *)0xB6070000); + sr_v25 = ACATA_R_STATUS; while ( (sr_v25 & ATA_STAT_BUSY) != 0 ) { - sr_v25 = *((volatile acUint16 *)0xB6070000); + sr_v25 = ACATA_R_STATUS; sr_v25 = sr_v25 & 0xFF; } } @@ -284,9 +284,9 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) xlen_v28 = (unsigned int)xlen_v27 >> 1; if ( (sr_v25 & 1) != 0 ) xlen_v28 = 0; - (void)(*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY); + (void)(ACATA_R_STATUS & ATA_STAT_BUSY); xlen_v30 = xlen_v28 - 1; - while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_DRQ) != 0 ) + while ( (ACATA_R_STATUS & ATA_STAT_DRQ) != 0 ) { if ( xlen_v30 >= 0 ) { @@ -295,7 +295,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } --xlen_v30; } - ret_v29 = *((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY; + ret_v29 = ACATA_R_STATUS & ATA_STAT_BUSY; if ( !ret_v29 ) break; } @@ -361,7 +361,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) int tmout; tmout = 99999; - while ( (*((volatile acUint16 *)0xB6070000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( tmout < 0 ) { @@ -380,8 +380,8 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) { return ret; } - sr_v34 = *((volatile acUint16 *)0xB6070000); - if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_ERR) != 0 ) + sr_v34 = ACATA_R_STATUS; + if ( (ACATA_R_STATUS & ATA_STAT_ERR) != 0 ) return -((sr_v34 << 8) + ACATA_R_ERROR); if ( atah->a_state < 0x1FFu ) { diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index 7c643b3461f1..b1bfbbe6df07 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -86,11 +86,11 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) ACATA_R_DRIVE_HEAD = flag & 0x10; *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; ACATA_R_FEATURES = flag & 1; - *((volatile acUint16 *)0xB6070000) = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? + ACATA_R_COMMAND = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? tmout = 999; v6 = 1000; // cppcheck-suppress knownConditionTrueFalse - while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) != 0 ) + while ( (ACATA_R_STATUS & ATA_STAT_BUSY) != 0 ) { if ( tmout < 0 ) { @@ -107,7 +107,7 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) return -116; } // cppcheck-suppress knownConditionTrueFalse - while ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_DRQ) != 0 ) + while ( (ACATA_R_STATUS & ATA_STAT_DRQ) != 0 ) { --count; if ( count < 0 ) @@ -140,10 +140,10 @@ static int atapi_pio_read(acAtaReg atareg, acUint16 *buf, int count, int flag) if ( !sr ) { - sr_v5 = *((volatile acUint16 *)0xB6070000); + sr_v5 = ACATA_R_STATUS; while ( (sr_v5 & ATA_STAT_BUSY) != 0 ) { - xlen = *((volatile acUint16 *)0xB6070000); + xlen = ACATA_R_STATUS; sr_v5 = xlen & 0xFF; } } @@ -180,7 +180,7 @@ static int atapi_pio_read(acAtaReg atareg, acUint16 *buf, int count, int flag) for ( drop_v10 = sr_v9 / 2 - 1; drop_v10 >= 0; --drop_v10 ) ; sr = v6 & 2; - if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) == 0 ) + if ( (ACATA_R_STATUS & ATA_STAT_BUSY) == 0 ) { break; } @@ -327,10 +327,10 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } else { - sr_v14 = *((volatile acUint16 *)0xB6070000); + sr_v14 = ACATA_R_STATUS; while ( (sr_v14 & ATA_STAT_BUSY) != 0 ) { - xlen = *((volatile acUint16 *)0xB6070000); + xlen = ACATA_R_STATUS; sr_v14 = xlen & 0xFF; } } @@ -359,7 +359,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) for ( drop_v20 = sr_v18 / 2 - 1; drop_v20 >= 0; --drop_v20 ) ACATA_R_DATA = 0; sr = flag & 2; - if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_BUSY) == 0 ) + if ( (ACATA_R_STATUS & ATA_STAT_BUSY) == 0 ) { ret_v5 = size - a_size; break; @@ -404,7 +404,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) int tmout; tmout = 99999; - while ( (*((volatile acUint16 *)0xB6070000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( tmout < 0 ) { @@ -462,8 +462,8 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } if ( ret_v5 < 0 ) return ret_v5; - if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_ERR) != 0 ) - return -((*((volatile acUint16 *)0xB6070000) << 8) + ACATA_R_ERROR); + if ( (ACATA_R_STATUS & ATA_STAT_ERR) != 0 ) + return -((ACATA_R_STATUS << 8) + ACATA_R_ERROR); if ( atah->a_state >= 0x1FFu ) { return -116; @@ -505,7 +505,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) acAtapiT atapi; atapi = (acAtapiT)atah; - if ( (*((volatile acUint16 *)0xB6070000) & ATA_STAT_ERR) == 0 ) + if ( (ACATA_R_STATUS & ATA_STAT_ERR) == 0 ) return ret; memset(&sense, 0, sizeof(sense)); memset(&u, 0, sizeof(u)); @@ -548,7 +548,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) int tmout; tmout = 99999; - while ( (*((volatile acUint16 *)0xB6070000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( tmout < 0 ) { From e75e31bf91a661f72b4d41d3c660ee0a7f4d395d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 01:02:05 -0300 Subject: [PATCH 12/13] acata: propagate macro for ALT_STATUS/DEVCTRL reg --- iop/arcade/acata/src/acata_internal.h | 4 ++-- iop/arcade/acata/src/ata.c | 2 +- iop/arcade/acata/src/atacmd.c | 20 ++++++++++---------- iop/arcade/acata/src/atapicmd.c | 22 +++++++++++----------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/iop/arcade/acata/src/acata_internal.h b/iop/arcade/acata/src/acata_internal.h index dd0919208d65..da9571e33515 100644 --- a/iop/arcade/acata/src/acata_internal.h +++ b/iop/arcade/acata/src/acata_internal.h @@ -26,8 +26,8 @@ #define ACATA_R_DRIVE_HEAD *((acAtaReg)0xB6060000) // Used to select a drive and/or head. Supports extra address/flag bits. [`ACATA_UNIT0`, `ACATA_UNIT1`] #define ACATA_R_STATUS *((acAtaReg)0xB6070000) // [R] Used to read the current status. #define ACATA_R_COMMAND ACATA_R_STATUS // [W] Used to send ATA commands to the device. -#define ACATA_R_ALT_STATUS *((acAtaReg)0xB6160000) // [R] Used to read the current status. -#define ACATA_R_ALT_COMMAND ACATA_R_ALT_STATUS // [W] Used to send ATA commands to the device. +#define ACATA_R_ALT_STATUS *((acAtaReg)0xB6160000) // [R] A duplicate of the Status Register which does not affect interrupts. +#define ACATA_R_DEVCONTROL ACATA_R_ALT_STATUS // [W] Used to reset the bus or enable/disable interrupts. struct ata_softc diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index ea1b4ca6f64b..3d4a98498fe2 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -200,7 +200,7 @@ int ata_probe(acAtaReg atareg) return 0; active = 0; unit = 0; - *((volatile acUint16 *)0xB6160000) = 2; + ACATA_R_DEVCONTROL = 2; ACATA_R_FEATURES = 0; count = 0; while ( unit < 2 ) diff --git a/iop/arcade/acata/src/atacmd.c b/iop/arcade/acata/src/atacmd.c index 8e93fa7a5d6e..058d3939f4e6 100644 --- a/iop/arcade/acata/src/atacmd.c +++ b/iop/arcade/acata/src/atacmd.c @@ -144,7 +144,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) count = 5; flag_v8 = atah->a_flag; ACATA_R_DRIVE_HEAD = flag_v8 & 0x10; - *((volatile acUint16 *)0xB6160000) = (flag_v8 & 2) ^ 2; + ACATA_R_DEVCONTROL = (flag_v8 & 2) ^ 2; ACATA_R_FEATURES = 0; while ( count >= 0 ) { @@ -214,14 +214,14 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } if ( (flag_v8 & 2) != 0 ) { - sr = *((volatile acUint16 *)0xB6160000); + sr = ACATA_R_ALT_STATUS; ret_v20 = sr & 0xFF; - while ( (ret_v20 & 0x80) != 0 ) + while ( (ret_v20 & ATA_STAT_BUSY) != 0 ) { ret_v20 = -116; if ( SleepThread() != 0 ) break; - ret_v20 = *((volatile acUint16 *)0xB6160000); + ret_v20 = ACATA_R_ALT_STATUS; } } else @@ -256,14 +256,14 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) if ( (flag_v8 & 2) != 0 ) { - sr_v25 = *((volatile acUint16 *)0xB6160000); + sr_v25 = ACATA_R_ALT_STATUS; sr_v25 = sr_v25 & 0xFF; while ( (sr_v25 & 0x80) != 0 ) { sr_v25 = -116; if ( SleepThread() ) break; - sr_v25 = *((volatile acUint16 *)0xB6160000); + sr_v25 = ACATA_R_ALT_STATUS; } } else @@ -313,13 +313,13 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) { int v38; - v38 = *((volatile acUint16 *)0xB6160000) & 1; + v38 = ACATA_R_ALT_STATUS & ATA_STAT_ERR; if ( v38 || state >= 511 ) { printf( "acata:A:dma_iowait: TIMEDOUT %04x:%02x:%02x\n", state, - *((volatile acUint16 *)0xB6160000), + ACATA_R_ALT_STATUS, ACATA_R_ERROR); if ( state < 1023 ) acDmaCancel(&dma_data.ad_dma, -116); @@ -329,7 +329,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) break; } state = dma_data.ad_state; - if ( (*((volatile acUint16 *)0xB6160000) & 0x80) == 0 && (int)dma_data.ad_state >= 64 ) + if ( (ACATA_R_ALT_STATUS & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 ) { ret = dma_data.ad_result; break; @@ -347,7 +347,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) ret = 0; if ( v16 ) { - while ( (*((volatile acUint16 *)0xB6160000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_ALT_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( SleepThread() ) { diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index b1bfbbe6df07..a7738fe44c84 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -84,7 +84,7 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) ACATA_R_CYL_HIGH = 0; ACATA_R_CYL_LOW = 64; ACATA_R_DRIVE_HEAD = flag & 0x10; - *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; + ACATA_R_DEVCONTROL = (flag & 2) ^ 2; ACATA_R_FEATURES = flag & 1; ACATA_R_COMMAND = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? tmout = 999; @@ -149,14 +149,14 @@ static int atapi_pio_read(acAtaReg atareg, acUint16 *buf, int count, int flag) } else { - xlen = *((volatile acUint16 *)0xB6160000); + xlen = ACATA_R_ALT_STATUS; sr_v5 = xlen & 0xFF; while ( (sr_v5 & 0x80) != 0 ) { sr_v5 = -116; if ( SleepThread() != 0 ) break; - sr_v5 = *((volatile acUint16 *)0xB6160000); + sr_v5 = ACATA_R_ALT_STATUS; } } if ( sr_v5 < 0 ) @@ -315,14 +315,14 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) if ( sr ) { - xlen = *((volatile acUint16 *)0xB6160000); + xlen = ACATA_R_ALT_STATUS; sr_v14 = xlen & 0xFF; while ( (sr_v14 & 0x80) != 0 ) { sr_v14 = -116; if ( SleepThread() != 0 ) break; - sr_v14 = *((volatile acUint16 *)0xB6160000); + sr_v14 = ACATA_R_ALT_STATUS; } } else @@ -390,7 +390,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) v32 = 0; if ( (flag & 2) != 0 ) { - while ( (*((volatile acUint16 *)0xB6160000) & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_ALT_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( SleepThread() ) { @@ -430,13 +430,13 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) { int v30; - v30 = *((volatile acUint16 *)0xB6160000) & 1; + v30 = ACATA_R_ALT_STATUS & ATA_STAT_ERR; if ( v30 || ret_v23 >= 511 ) { printf( "acata:P:dma_iowait: TIMEDOUT %04x:%02x:%02x\n", ret_v23, - *((volatile acUint16 *)0xB6160000), + ACATA_R_ALT_STATUS, ACATA_R_ERROR); if ( ret_v23 < 1023 ) acDmaCancel(&dma_data.ad_dma, -116); @@ -446,7 +446,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) break; } ret_v23 = dma_data.ad_state; - if ( (*((volatile acUint16 *)0xB6160000) & 0x80) == 0 && (int)dma_data.ad_state >= 64 ) + if ( (ACATA_R_ALT_STATUS & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 ) { ad_result = dma_data.ad_result; break; @@ -513,7 +513,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) u.opcode = 0x03; u.len = 0x12; u.lun = atapi->ap_packet.u_b[1]; - *((volatile acUint16 *)0xB6160000) = (flag & 2) ^ 2; + ACATA_R_DEVCONTROL = (flag & 2) ^ 2; ACATA_R_FEATURES = 0; v3 = atapi_packet_send((acAtaReg)ACATA_A_DATA, &u.pkt, flag); if ( v3 < 0 ) @@ -534,7 +534,7 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) v6 = 0; if ( (flag & 2) != 0 ) { - while ( (*((volatile acUint16 *)0xB6160000) & (ATA_STAT_BUSY|ATA_STAT_ERR) == ATA_STAT_BUSY ) + while ( (*(volatile acUint16 *)0xB6160000) & (ATA_STAT_BUSY|ATA_STAT_ERR) == ATA_STAT_BUSY ) { if ( SleepThread() ) { From a116d24ab08394d24b4614c7b9747d35c40cc567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 14 May 2026 08:48:08 -0300 Subject: [PATCH 13/13] streamline acata regs naming with atahw.h --- common/include/atahw.h | 21 ++++++++++------- iop/arcade/acata/src/acata_internal.h | 22 ++++++++--------- iop/arcade/acata/src/ata.c | 14 +++++------ iop/arcade/acata/src/atacmd.c | 22 ++++++++--------- iop/arcade/acata/src/atapicmd.c | 34 +++++++++++++-------------- 5 files changed, 58 insertions(+), 55 deletions(-) diff --git a/common/include/atahw.h b/common/include/atahw.h index 9b2dc5fc02ff..045737cd213e 100644 --- a/common/include/atahw.h +++ b/common/include/atahw.h @@ -48,14 +48,14 @@ typedef struct _ata_hwport (ata_hwport_t *)ATA_AIF_HDD_BASE /* r_error bits. */ -#define ATA_ERR_MARK 0x01 -#define ATA_ERR_TRACK0 0x02 -#define ATA_ERR_ABORT 0x04 -#define ATA_ERR_MCR 0x08 -#define ATA_ERR_ID 0x10 -#define ATA_ERR_MC 0x20 -#define ATA_ERR_ECC 0x40 -#define ATA_ERR_ICRC 0x80 +#define ATA_ERR_MARK 0x01 // bit 0 [AMNF] Address mark not found. +#define ATA_ERR_TRACK0 0x02 // bit 1 [TKZNF] Track zero not found. +#define ATA_ERR_ABORT 0x04 // bit 2 [ABRT] Aborted command. +#define ATA_ERR_MCR 0x08 // bit 3 [MCR] Media change request. +#define ATA_ERR_ID 0x10 // bit 4 [IDNF] ID not found. +#define ATA_ERR_MC 0x20 // bit 5 [MC] Media changed. +#define ATA_ERR_ECC 0x40 // bit 6 [UNC] Uncorrectable data error. +#define ATA_ERR_ICRC 0x80 // bit 7 [BBK] Bad Block detected. /* r_status bits. */ #define ATA_STAT_ERR 0x01 @@ -68,7 +68,10 @@ typedef struct _ata_hwport #define ATA_STAT_BUSY 0x80 /* r_select bits. */ -#define ATA_SEL_LBA 0x40 +/// In CHS addressing, bits 0 to 3 of the head. In LBA addressing, bits 24 to 27 of the block number. +/// bits 5 and 7 are supposed to be always set +#define ATA_SEL_DRV 0x10 // bit 4 [DRV] Selects the drive number. +#define ATA_SEL_LBA 0x40 // bit 6 [LBA] Uses CHS addressing if clear or LBA addressing if set. /** ATA command codes. */ enum ATA_C_CODES { diff --git a/iop/arcade/acata/src/acata_internal.h b/iop/arcade/acata/src/acata_internal.h index da9571e33515..0d4bce05aa31 100644 --- a/iop/arcade/acata/src/acata_internal.h +++ b/iop/arcade/acata/src/acata_internal.h @@ -17,17 +17,17 @@ #define ACATA_A_DATA 0xB6000000 // Read/Write PIO data bytes #define ACATA_R_DATA *((acAtaReg)0xB6000000) // Read/Write PIO data bytes -#define ACATA_R_FEATURES *((acAtaReg)0xB6010000) // [W] Used to control command specific interface features. -#define ACATA_R_ERROR ACATA_R_FEATURES // [R] Used to retrieve any error generated by the last ATA command executed. -#define ACATA_R_SECCNT *((acAtaReg)0xB6020000) // Number of sectors to read/write (0 is a special value). -#define ACATA_R_SECNUM *((acAtaReg)0xB6030000) // This is CHS / LBA28 / LBA48 specific. -#define ACATA_R_CYL_LOW *((acAtaReg)0xB6040000) // Partial Disk Sector address. -#define ACATA_R_CYL_HIGH *((acAtaReg)0xB6050000) // Partial Disk Sector address. -#define ACATA_R_DRIVE_HEAD *((acAtaReg)0xB6060000) // Used to select a drive and/or head. Supports extra address/flag bits. [`ACATA_UNIT0`, `ACATA_UNIT1`] -#define ACATA_R_STATUS *((acAtaReg)0xB6070000) // [R] Used to read the current status. -#define ACATA_R_COMMAND ACATA_R_STATUS // [W] Used to send ATA commands to the device. -#define ACATA_R_ALT_STATUS *((acAtaReg)0xB6160000) // [R] A duplicate of the Status Register which does not affect interrupts. -#define ACATA_R_DEVCONTROL ACATA_R_ALT_STATUS // [W] Used to reset the bus or enable/disable interrupts. +#define ACATA_R_FEATURE *((acAtaReg)0xB6010000) // [W] Used to control command specific interface features. +#define ACATA_R_ERROR ACATA_R_FEATURE // [R] Used to retrieve any error generated by the last ATA command executed. +#define ACATA_R_NSECTOR *((acAtaReg)0xB6020000) // Number of sectors to read/write (0 is a special value). +#define ACATA_R_SECTOR *((acAtaReg)0xB6030000) // This is CHS / LBA28 / LBA48 specific. +#define ACATA_R_LCYL *((acAtaReg)0xB6040000) // Partial Disk Sector address. +#define ACATA_R_HCYL *((acAtaReg)0xB6050000) // Partial Disk Sector address. +#define ACATA_R_SELECT *((acAtaReg)0xB6060000) // Used to select a drive and/or head. Supports extra address/flag bits. [`ACATA_UNIT0`, `ACATA_UNIT1`] +#define ACATA_R_STATUS *((acAtaReg)0xB6070000) // [R] Used to read the current status. +#define ACATA_R_COMMAND ACATA_R_STATUS // [W] Used to send ATA commands to the device. +#define ACATA_R_STATUS_ALT *((acAtaReg)0xB6160000) // [R] A duplicate of the Status Register which does not affect interrupts. +#define ACATA_R_CONTROL ACATA_R_STATUS_ALT // [W] Used to reset the bus or enable/disable interrupts. struct ata_softc diff --git a/iop/arcade/acata/src/ata.c b/iop/arcade/acata/src/ata.c index 3d4a98498fe2..41d68bc1e60b 100644 --- a/iop/arcade/acata/src/ata.c +++ b/iop/arcade/acata/src/ata.c @@ -190,22 +190,22 @@ int ata_probe(acAtaReg atareg) (void)atareg; while ( (ACATA_R_STATUS & ATA_STAT_BUSY) != 0 ) ; - ACATA_R_SECCNT = 4660; + ACATA_R_NSECTOR = 4660; // cppcheck-suppress knownConditionTrueFalse - if ( ACATA_R_SECCNT != 52 ) + if ( ACATA_R_NSECTOR != 52 ) return 0; - ACATA_R_SECNUM = 18; + ACATA_R_SECTOR = 18; // cppcheck-suppress knownConditionTrueFalse - if ( ACATA_R_SECNUM != 18 ) + if ( ACATA_R_SECTOR != 18 ) return 0; active = 0; unit = 0; - ACATA_R_DEVCONTROL = 2; - ACATA_R_FEATURES = 0; + ACATA_R_CONTROL = 2; + ACATA_R_FEATURE = 0; count = 0; while ( unit < 2 ) { - ACATA_R_DRIVE_HEAD = 16 * (unit != 0); + ACATA_R_SELECT = 16 * (unit != 0); ACATA_R_COMMAND = 0; ACATA_R_COMMAND = 0; while ( count <= 1999999 ) diff --git a/iop/arcade/acata/src/atacmd.c b/iop/arcade/acata/src/atacmd.c index 058d3939f4e6..510ca89bae34 100644 --- a/iop/arcade/acata/src/atacmd.c +++ b/iop/arcade/acata/src/atacmd.c @@ -143,9 +143,9 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) cmd = ata->ac_command; count = 5; flag_v8 = atah->a_flag; - ACATA_R_DRIVE_HEAD = flag_v8 & 0x10; - ACATA_R_DEVCONTROL = (flag_v8 & 2) ^ 2; - ACATA_R_FEATURES = 0; + ACATA_R_SELECT = flag_v8 & 0x10; + ACATA_R_CONTROL = (flag_v8 & 2) ^ 2; + ACATA_R_FEATURE = 0; while ( count >= 0 ) { int data; @@ -214,14 +214,14 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) } if ( (flag_v8 & 2) != 0 ) { - sr = ACATA_R_ALT_STATUS; + sr = ACATA_R_STATUS_ALT; ret_v20 = sr & 0xFF; while ( (ret_v20 & ATA_STAT_BUSY) != 0 ) { ret_v20 = -116; if ( SleepThread() != 0 ) break; - ret_v20 = ACATA_R_ALT_STATUS; + ret_v20 = ACATA_R_STATUS_ALT; } } else @@ -256,14 +256,14 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) if ( (flag_v8 & 2) != 0 ) { - sr_v25 = ACATA_R_ALT_STATUS; + sr_v25 = ACATA_R_STATUS_ALT; sr_v25 = sr_v25 & 0xFF; while ( (sr_v25 & 0x80) != 0 ) { sr_v25 = -116; if ( SleepThread() ) break; - sr_v25 = ACATA_R_ALT_STATUS; + sr_v25 = ACATA_R_STATUS_ALT; } } else @@ -313,13 +313,13 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) { int v38; - v38 = ACATA_R_ALT_STATUS & ATA_STAT_ERR; + v38 = ACATA_R_STATUS_ALT & ATA_STAT_ERR; if ( v38 || state >= 511 ) { printf( "acata:A:dma_iowait: TIMEDOUT %04x:%02x:%02x\n", state, - ACATA_R_ALT_STATUS, + ACATA_R_STATUS_ALT, ACATA_R_ERROR); if ( state < 1023 ) acDmaCancel(&dma_data.ad_dma, -116); @@ -329,7 +329,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) break; } state = dma_data.ad_state; - if ( (ACATA_R_ALT_STATUS & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 ) + if ( (ACATA_R_STATUS_ALT & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 ) { ret = dma_data.ad_result; break; @@ -347,7 +347,7 @@ static int ata_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) ret = 0; if ( v16 ) { - while ( (ACATA_R_ALT_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_STATUS_ALT & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( SleepThread() ) { diff --git a/iop/arcade/acata/src/atapicmd.c b/iop/arcade/acata/src/atapicmd.c index a7738fe44c84..99eaf6b9f583 100644 --- a/iop/arcade/acata/src/atapicmd.c +++ b/iop/arcade/acata/src/atapicmd.c @@ -81,11 +81,11 @@ static int atapi_packet_send(acAtaReg atareg, acAtapiPacketData *pkt, int flag) (void)atareg; count = 6; - ACATA_R_CYL_HIGH = 0; - ACATA_R_CYL_LOW = 64; - ACATA_R_DRIVE_HEAD = flag & 0x10; - ACATA_R_DEVCONTROL = (flag & 2) ^ 2; - ACATA_R_FEATURES = flag & 1; + ACATA_R_HCYL = 0; + ACATA_R_LCYL = 64; + ACATA_R_SELECT = flag & 0x10; + ACATA_R_CONTROL = (flag & 2) ^ 2; + ACATA_R_FEATURE = flag & 1; ACATA_R_COMMAND = ATA_C_PACKET; // ATA_STAT_BUSY|ATA_STAT_READY? tmout = 999; v6 = 1000; @@ -149,21 +149,21 @@ static int atapi_pio_read(acAtaReg atareg, acUint16 *buf, int count, int flag) } else { - xlen = ACATA_R_ALT_STATUS; + xlen = ACATA_R_STATUS_ALT; sr_v5 = xlen & 0xFF; while ( (sr_v5 & 0x80) != 0 ) { sr_v5 = -116; if ( SleepThread() != 0 ) break; - sr_v5 = ACATA_R_ALT_STATUS; + sr_v5 = ACATA_R_STATUS_ALT; } } if ( sr_v5 < 0 ) return sr_v5; if ( (sr_v5 & 8) == 0 ) break; - xlen_v6 = (ACATA_R_CYL_HIGH << 8) + ACATA_R_CYL_LOW; + xlen_v6 = (ACATA_R_HCYL << 8) + ACATA_R_LCYL; drop = xlen_v6 - rest; if ( rest >= xlen_v6 ) drop = 0; @@ -315,14 +315,14 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) if ( sr ) { - xlen = ACATA_R_ALT_STATUS; + xlen = ACATA_R_STATUS_ALT; sr_v14 = xlen & 0xFF; while ( (sr_v14 & 0x80) != 0 ) { sr_v14 = -116; if ( SleepThread() != 0 ) break; - sr_v14 = ACATA_R_ALT_STATUS; + sr_v14 = ACATA_R_STATUS_ALT; } } else @@ -342,7 +342,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) ret_v5 = size - a_size; break; } - xlen_v15 = (ACATA_R_CYL_HIGH << 8) + ACATA_R_CYL_LOW; + xlen_v15 = (ACATA_R_HCYL << 8) + ACATA_R_LCYL; drop = xlen_v15 - a_size; if ( a_size >= xlen_v15 ) drop = 0; @@ -390,7 +390,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) v32 = 0; if ( (flag & 2) != 0 ) { - while ( (ACATA_R_ALT_STATUS & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) + while ( (ACATA_R_STATUS_ALT & (ATA_STAT_BUSY|ATA_STAT_ERR)) == ATA_STAT_BUSY ) { if ( SleepThread() ) { @@ -430,13 +430,13 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) { int v30; - v30 = ACATA_R_ALT_STATUS & ATA_STAT_ERR; + v30 = ACATA_R_STATUS_ALT & ATA_STAT_ERR; if ( v30 || ret_v23 >= 511 ) { printf( "acata:P:dma_iowait: TIMEDOUT %04x:%02x:%02x\n", ret_v23, - ACATA_R_ALT_STATUS, + ACATA_R_STATUS_ALT, ACATA_R_ERROR); if ( ret_v23 < 1023 ) acDmaCancel(&dma_data.ad_dma, -116); @@ -446,7 +446,7 @@ static int atapi_ops_command(struct ac_ata_h *atah, int cmdpri, int pri) break; } ret_v23 = dma_data.ad_state; - if ( (ACATA_R_ALT_STATUS & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 ) + if ( (ACATA_R_STATUS_ALT & ATA_STAT_BUSY) == 0 && (int)dma_data.ad_state >= 64 ) { ad_result = dma_data.ad_result; break; @@ -513,8 +513,8 @@ static int atapi_ops_error(struct ac_ata_h *atah, int ret) u.opcode = 0x03; u.len = 0x12; u.lun = atapi->ap_packet.u_b[1]; - ACATA_R_DEVCONTROL = (flag & 2) ^ 2; - ACATA_R_FEATURES = 0; + ACATA_R_CONTROL = (flag & 2) ^ 2; + ACATA_R_FEATURE = 0; v3 = atapi_packet_send((acAtaReg)ACATA_A_DATA, &u.pkt, flag); if ( v3 < 0 ) {