2014 Retrochallenge Winter Warmup, Retrochallenge

2014 Retrochallenge Winter Warmup – Post 05

(This is part five of the chronicle of my 2014 Retrochallenge Winter Warmup submission.  The mediocrity starts here.)

Success!

Source code and disk image available at A2MP3-Xfer Project at Bitbucket

Next

Still have two other projects I’d like to complete before the end of the month:

  • Super Sunday XLVIII – Reverse engineer and alter the American football team/player data for the Apple II game program “Super Sunday” (currently contains teams from 1966-1981) to contain 2013 season teams, players, and statistics. Then simulate the upcoming Super Bowl XLVIII once the teams are decided.
  • Aquarius Tape Library – Create a personal cassette tape library of the games available for the tragic Mattel Aquarius home computer.
Advertisement
2014 Retrochallenge Winter Warmup, Retrochallenge

2014 Retrochallenge Winter Warmup – Post 04

(This is part four of the chronicle of my 2014 Retrochallenge Winter Warmup submission. The mediocrity starts here.)

And Back Again.

Last weekend I was successful in transferring a physical floppy diskette to a .DSK disk image file on the USB thumb drive mounted to the A2MP3 card in my Apple II. To complete the challenge, I also wanted to make the return trip work, too. That is, to transfer a .DSK disk image file found on the USB thumb drive to a physical floppy diskette.

If you would’ve asked me, I would’ve bet good wages that I’d have this working in a day or so. However, most of the week has been instead spent butting my head against the wall fighting silly mistakes.

The French and Endian War

When reading the disk image data and comparing it to what was being written to the floppy, I became convinced the VMusic2 MP3 encoder was sending the bytes as Big Endian 16-Bit words and I needed to swap the byte order to restore it to a stream of single bytes.

The evidence:

1) when peeking at the USB-sourced disk image data being read in the Apple II’s memory, it looked like this:

<START>$44 $01 $a5 $27 $c9 $09 $d0 $18 $a5 ...

2) when examining a disk image file under Linux, the first few bytes looked like this:

$ hexdump -x A2MP3XFR.DSK | head
0000000    a501    c927    d009    a518    ...

So besides the spurious ‘D’ ($44)  at the beginning of the stream in the Apple II’s memory, I concluded the Apple II program was receiving bytes from the VMusic2 controller in a slightly jumbled order. And I spent days fighting this.

Then yesterday, in an act as desperate as a trapped miner banging a pipe, I happened to run this command:

$ echo "ABCDE" | hexdump -xc
0000000    4241    4443    0a45

0000000   A   B   C   D   E  n

What the what? This shows the hexdump command was the one guilty of transposing bytes.

Hold on. I need to compose a letter….

Dear hexdump authors,
I hate you.
Sincerely,
Me

Spurious D and the Pick of Destiny

Now that the byte order problem had been un-solved, next was to get rid of that 0x44 appearing at the head of the data streamed from the VMusic2 controller. I won’t go through all the failed solutions, but I eventually found a way to skip the D. And I had my first successful USB to physical floppy transfer – and life was grand.

In my moment of elation, I went through all the functions that the program currently performs: A) this week’s Transferring from USB to floppy, Yea!, B) this week’s Formatting a blank floppy, Yea!, C) last week’s Transferring from floppy to USB, What? (From observing the blinking lights, activity was normal about 1/6th of the transfer and then the little flicker normally seen when a file is being closed. Then USB activity ceased).

In my focus on getting the USB to floppy feature working, I had not tested the floppy to USB function in many days. What had I done to break it? I had made so many changes for the red-herring byte transposing.

In the end, it was indeed the changes regarding the Spurious D that was causing the new problems. An option (SKIPREAD) was added so that, when needed, a command sent to the VMusic2 controller would not always jump immediately to the code that read the VMusic2’s response.

Stick a Fork in It

So, now that the program is able to successfully transfer disk images to and from physical floppies, I am happy with its current state and declare “Success!”.

A2MP3-Xfer Project at Bitbucket

A video to follow.

2014 Retrochallenge Winter Warmup, Retrochallenge

2014 Retrochallenge Winter Warmup – Post 02

(This is part two of the chronicle of my 2014 Retrochallenge Winter Warmup submission.  The mediocrity starts here.)

Talking to the 6551

R6551
Si. We make all kind of chips: Tortillas, Papas y Plátanos, Silicio.

In order to send or receive data from the Apple II to the VMusic2 USB controller attached to the A2MP3 card, I need to understand how to communicate with, in this case, the Rockwell International R6551 ACIA (Asynchronous Communication Interface Adapter). This handy integrated circuit was designed to enable serial communications for 6502-based systems.

R6551-ds-cover
Link to R6551 Datasheet

The R6551’s four internal registers on the A2MP3 card are exposed to the Apple II’s 6502 at four addresses. The exact four are dependent on which slot the A2MP3 card is inserted.

Assuming the A2MP3 card is inserted in Slot #3, the addresses and registers are:

Address R6551 Register Description
$C0B0 DATA
  • Contains the current byte being sent to/received from the VMusic2 controller
$C0B1 STATUS
  • When sending a byte, indicates when the current one has been read from the DATA register by VMusic2 controller.
  • When receiving a byte, indicates when the next one is ready for grabbing from the DATA register
$C0B2 COMMAND Used in order to:

  • Set parity
$C0B3 CONTROL Used in order to:

  • Set BAUD rate
  • Set number of stop bits.

The registers provide several other functions, such as setting the clock source, detecting interrupts and errors but I’ve listed only those needed for this project. Regarding the addresses, if the card were in Slot #4, then the addresses would start at $C0C0, Slot #5: $C0D0, and so on.

Initializing the 6551

For the assembly language portion of my project, I started off with Vince Briel’s original code provided with the A2MP3 kit. Especially for the initialization since I’m making no hardware changes. Assuming the datasheet I found applies to the R6551P (and I’m interpreting it correctly), the predefined baud rates max out at 19.2k and Vince is using the external clock to get to 115k.

ACIA_DAT    equ $C0B0          ; 6551 DATA REGISTER
ACIA_SR     equ $C0B1          ; 6551 STATUS REGISTER
ACIA_CMD    equ $C0B2          ; 6551 COMMAND REGISTER
ACIA_CTRL   equ $C0B3          ; 6551 CONTROL REGISTER

;-------------------------------------------------------------------
; INITIALIZE THE 6551 CHIP
;-------------------------------------------------------------------
INIT        LDA     #$10       ; $10 = 1/16x EXTNL CLOCK; 1 STOP BIT
            STA     ACIA_CTRL  ; STORE IN 6551 CONTROL REGISTER
            LDA     #$0B       ; PARITY DISABLED, NO IRQS, DTR READY
            STA     ACIA_CMD   ; STORE IN 6551 COMMAND REGISTER
            RTS

Sending Bytes

To send a byte from the Apple II to the VMusic2 controller via the 6551, the process is:

  1. Poke the payload byte into the 6551’s DATA register
  2. Peek at bit 4 of the STATUS register, if it’s set then send is complete. Otherwise check again.
;-------------------------------------------------------------------
; SEND CHAR TO 6551
;-------------------------------------------------------------------
SENDCH      STA     ACIA_DAT   ; SEND BYTE TO 6551 DATA REG
NOT_EMPTY   LDA     ACIA_SR    ; TEST "TRANSMIT DATA REG EMPTY" FLG
            AND     #$10       ; IN STATUS REG 0=NOT_EMPTY 1=EMPTY
            BEQ     NOT_EMPTY  ; WAIT FOR "EMPTY"
            RTS

Reading Bytes

To read a byte delivered from the VMusic2 card to the Apple II via the 6551, the process is:

  1. Peek at bit 3 of the STATUS register. If it’s set then the reception is complete. Otherwise check again. Give up it’s its been a while.
  2. Peek the payload byte from the DATA register.
;-------------------------------------------------------------------
; READ CHAR FROM 6551
;-------------------------------------------------------------------
READCH      LDX     #$00
NEXTCHAR    CPX     #$E9       ; NO RESP IN A WHILE. ASSUME DONE
            BEQ     BAIL     
            INX
            LDA     ACIA_SR    ; TEST "RECV DATA REG FULL" FLG IN
            AND     #$08       ; STATUS REG (BIT3) 0=NEXTCHAR 1=FULL
            BEQ     NEXTCHAR   ; WAIT UNTIL "FULL"
            LDA     ACIA_DAT   ; GET CHAR FROM 6551
BAIL        RTS

From Here

In the final project code, there’s a little more going on. I currently have subroutines to:

  • Send an arbirary null-terminated string of characters to the VMusic2 controller (for sending Vinculum commands)
  • Send exactly 256 bytes of memory to the VMusic2 controller (for sending one DOS 3.3 sector)

Both of these call the SENDCH routine described above.

I’ll also need subroutines to:

  • Read an arbitrary double-$0D-terminated string from the VMusic2 controller (for retrieving command responses or error messages).
  • Read exactly 256 bytes from the VMusic2 controller (for reading one DOS 3.3 sector)

Next, a work-in-progress demonstration video of me transferring a floppy image to the A2MP3 and a brief explanation of calling Apple’s RWTS (Read Write Track Sector)

2014 Retrochallenge Winter Warmup, Retrochallenge

2014 Retrochallenge Winter Warmup – Post 01

(This is part one of the chronicle of my 2014 Retrochallenge Winter Warmup submission.  The mediocrity starts here.)

A2MP3 Project: Synopsis

The A2MP3 is a creation of retro-engineer Vince Briel. It’s a peripheral card for the Apple II/II+/IIe/IIgs and allows the Apple II to programmatically control an embedded VMusic2 MP3 player created by Future Technology Devices International Ltd which itself is plugged onto the back of the A2MP3 card. (whew). Audio files are stored on a USB storage device such as a thumb drive. Audio output is sent to a phone jack on the VMusic2. The intermediary between the Apple II and the MP3 player is the workhorse 6551 chip – created to enable UART serial communications for 6502-based systems.

A2MP3The VMusic2 device is a member of F.T.D.I’s Vinculum family of the USB host controller devices. These devices listen for and respond to control commands delivered across its UART signal lines. For example, the command “V3A” will tell the VMusic2 to play all tracks; “VP” will pause playback.

A2MP3-backIncluded with Briel’s A2MP3 kit is a sample Applesoft program and an assembly-language program that work together to provide a menu-driven user interface and sends MP3-specific commands to the VMusic2 device.

However the 15 or so MP3-specific commands are a superset of the commands common to all devices in the Vinculum family. Most interesting to me are commands related to file operations on the USB storage device, such as “MKD” to create a directory or “OPW” to open a file for writing. Just look at all the other commands available in the firmware.

Vinculum Firmware User Manual

With this knowledge it seems possible to transfer a disk image from a physical floppy disk to the USB storage device on the VMusic2 using the following process:

  1. Open a file for writing on the VMusic2 USB storage device using its “OPW” command.
  2. Read a sector from the Apple II floppy disk into RAM using the Read Write Track Sector (RWTS) API included in Apple’s DOS 3.3
  3. Write the data from the Apple’s RAM to the VMusic2 USB storage device using its “WRF” command
  4. Repeat steps #3, #4 for all tracks/sectors on a floppy
  5. Close the file on the VMusic2 USB storage device