shithub: psxe

Download patch

ref: 49a2e2abe3a98f0b9c1130f9490f3bd22c21da08
parent: 7b79768480fb0826f4aecbb48657f66987fbb874
author: allkern <lisandroaalarcon@gmail.com>
date: Mon Sep 18 10:32:21 EDT 2023

Start working on XA-ADCPM

--- a/psx/dev/cdrom.c
+++ b/psx/dev/cdrom.c
@@ -8,6 +8,7 @@
 
 #define RESP_PUSH(data) \
     cdrom->rfifo[cdrom->rfifo_index++] = data; \
+    cdrom->rfifo_index &= 15; \
     SET_BITS(status, STAT_RSLRRDY_MASK, STAT_RSLRRDY_MASK);
 
 #define PFIFO_POP (cdrom->pfifo[--cdrom->pfifo_index])
@@ -130,10 +131,6 @@
 
         // Read ongoing
         case CD_STATE_SEND_RESP2: {
-            // log_set_quiet(0);
-            log_fatal("SETLOC WHILE READN");
-            // log_set_quiet(0+0);
-
             int f = PFIFO_POP;
             int s = PFIFO_POP;
             int m = PFIFO_POP;
@@ -321,9 +318,7 @@
             // );
 
             if (cdrom->dfifo[0x12] & 0x20) {
-                // log_set_quiet(0);
                 log_fatal("Unimplemented XA Form2 Sector");
-                // log_set_quiet(0+0);
 
                 // exit(1);
             }
@@ -791,16 +786,12 @@
     }
 }
 void cdrom_cmd_reads(psx_cdrom_t* cdrom) {
-    log_fatal("reads: Unimplemented");
-
-    //exit(1);
-
     cdrom->delayed_command = CDL_NONE;
     cdrom->read_ongoing = 1;
 
     switch (cdrom->state) {
         case CD_STATE_RECV_CMD: {
-            log_fatal("CdlReadN: CD_STATE_RECV_CMD");
+            log_fatal("CdlReadS: CD_STATE_RECV_CMD");
             cdrom->irq_delay = DELAY_1MS;
             cdrom->state = CD_STATE_SEND_RESP1;
             cdrom->delayed_command = CDL_READS;
@@ -807,7 +798,7 @@
         } break;
 
         case CD_STATE_SEND_RESP1: {
-            log_fatal("CdlReadN: CD_STATE_SEND_RESP1");
+            log_fatal("CdlReadS: CD_STATE_SEND_RESP1");
 
             SET_BITS(ifr, IFR_INT, IFR_INT3);
             RESP_PUSH(GETSTAT_MOTOR);
@@ -820,12 +811,10 @@
 
             msf_from_bcd(&msf);
 
-            cdrom->seek_pending = 0;
-
             int err = psx_disc_seek(cdrom->disc, msf);
 
             if (err) {
-                log_fatal("CdlReadN: Out of bounds seek");
+                log_fatal("CdlReadS: Out of bounds seek");
 
                 cdrom->irq_delay = DELAY_1MS * 600;
                 cdrom->delayed_command = CDL_ERROR;
@@ -853,7 +842,7 @@
             // circumvent this detection code, but it will work
             // for most intents and purposes 
             if (!correct_msf) {
-                log_fatal("CdlReadN: Audio read");
+                log_fatal("CdlReadS: Audio read");
 
                 cdrom->irq_delay = DELAY_1MS * 600;
                 cdrom->delayed_command = CDL_ERROR;
@@ -877,7 +866,7 @@
         } break;
 
         case CD_STATE_SEND_RESP2: {
-            log_fatal("CdlReadN: CD_STATE_SEND_RESP2");
+            log_fatal("CdlReadS: CD_STATE_SEND_RESP2");
 
             msf_t msf;
 
@@ -890,21 +879,15 @@
             psx_disc_seek(cdrom->disc, msf);
             psx_disc_read_sector(cdrom->disc, cdrom->dfifo);
 
-            // printf("Sector header: msf=%02x:%02x:%02x, mode=%02x, subheader=%02x,%02x,%02x,%02x\n",
-            //     cdrom->dfifo[0x0c],
-            //     cdrom->dfifo[0x0d],
-            //     cdrom->dfifo[0x0e],
-            //     cdrom->dfifo[0x0f],
-            //     cdrom->dfifo[0x10],
-            //     cdrom->dfifo[0x11],
-            //     cdrom->dfifo[0x12],
-            //     cdrom->dfifo[0x13]
-            // );
+            if (cdrom->mode & MODE_XA_ADPCM) {
+                cdrom->state = CD_STATE_RECV_CMD;
+                cdrom->delayed_command = CDL_NONE;
 
+                return;
+            }
+
             if (cdrom->dfifo[0x12] & 0x20) {
-                // log_set_quiet(0);
                 log_fatal("Unimplemented XA Form2 Sector");
-                // log_set_quiet(0+0);
 
                 // exit(1);
             }
@@ -921,7 +904,7 @@
 
             cdrom->irq_delay = double_speed ? READ_DOUBLE_DELAY : READ_SINGLE_DELAY;
             cdrom->state = CD_STATE_SEND_RESP2;
-            cdrom->delayed_command = CDL_READN;
+            cdrom->delayed_command = CDL_READS;
             cdrom->dfifo_index = 0;
 
             SET_BITS(ifr, IFR_INT, IFR_INT1);
@@ -1069,7 +1052,7 @@
         cdrom->pfifo[4],
         cdrom->pfifo[5]
     );
-    // log_set_quiet(0+0);
+    // log_set_quiet(1);
 
     cdrom->command = value;
     cdrom->state = CD_STATE_RECV_CMD;
--- /dev/null
+++ b/psx/dev/xa.c
@@ -1,0 +1,11 @@
+#include "xa.h"
+
+#include <stdint.h>
+
+void xa_decode_audio(uint8_t* src, uint16_t* dst) {
+    // Not a XA sector
+    if (src[XA_HDR_MODE] != 0x02)
+        return;
+    
+    // uint8_t ci = src[XA_SHDR_CODINGINFO];
+}
\ No newline at end of file
--- /dev/null
+++ b/psx/dev/xa.h
@@ -1,0 +1,69 @@
+#ifndef XA_H
+#define XA_H
+
+/*
+  000h 0Ch  Sync
+  00Ch 4    Header (Minute,Second,Sector,Mode=02h)
+  010h 4    Sub-Header (File, Channel, Submode with bit5=1, Codinginfo)
+  014h 4    Copy of Sub-Header
+  018h 914h Data (2324 bytes)
+  92Ch 4    EDC (checksum accross [010h..92Bh]) (or 00000000h if no EDC)
+*/
+
+enum {
+    XA_HDR_MINUTE = 0x0c,
+    XA_HDR_SECOND,
+    XA_HDR_SECTOR,
+    XA_HDR_MODE,
+    XA_SHDR_FILE,
+    XA_SHDR_CHANNEL,
+    XA_SHDR_SUBMODE,
+    XA_SHDR_CODINGINFO
+};
+
+/*
+  0   End of Record (EOR) (all Volume Descriptors, and all sectors with EOF)
+  1   Video     ;\Sector Type (usually ONE of these bits should be set)
+  2   Audio     ; Note: PSX .STR files are declared as Data (not as Video)
+  3   Data      ;/
+  4   Trigger           (for application use)
+  5   Form2             (0=Form1/800h-byte data, 1=Form2, 914h-byte data)
+  6   Real Time (RT)
+  7   End of File (EOF) (or end of Directory/PathTable/VolumeTerminator)
+*/
+
+enum {
+    XA_SM_EOR   = 0x01,
+    XA_SM_VIDEO = 0x02,
+    XA_SM_AUDIO = 0x04,
+    XA_SM_DATA  = 0x08,
+    XA_SM_TRIG  = 0x10,
+    XA_SM_FORM2 = 0x20,
+    XA_SM_RT    = 0x40,
+    XA_SM_EOF   = 0x80
+};
+
+/*
+  0-1 Mono/Stereo     (0=Mono, 1=Stereo, 2-3=Reserved)
+  2-2 Sample Rate     (0=37800Hz, 1=18900Hz, 2-3=Reserved)
+  4-5 Bits per Sample (0=Normal/4bit, 1=8bit, 2-3=Reserved)
+  6   Emphasis        (0=Normal/Off, 1=Emphasis)
+  7   Reserved        (0)
+*/
+
+enum {
+    XA_CI_MODE       = 0x03,
+    XA_CI_SAMPLERATE = 0x0c,
+    XA_CI_BPS        = 0x30,
+    XA_CI_EMPHASIS   = 0x40,
+    XA_CI_MONO       = 0x00,
+    XA_CI_STEREO     = 0x01,
+    XA_CI_37800HZ    = 0x00,
+    XA_CI_18900HZ    = 0x04,
+    XA_CI_4BIT       = 0x00,
+    XA_CI_8BIT       = 0x10
+};
+
+void xa_decode_sector(void*, void*);
+
+#endif
\ No newline at end of file
--