mirror of
https://github.com/dschmenk/apple2pi.git
synced 2024-11-24 12:31:30 +00:00
6951ff78d7
The Raspberry Pi Pico is connected to the Linux computer via its USB port, so every Linux computer with USB 1.1 ACM CDC virtual serial port (usually exposed as /dev/ttyACM0) support can be used. For the Apple2Pi card v6.x see https://youtu.be/WHq4d5E-5p8?t=1083
94 lines
3.2 KiB
C
94 lines
3.2 KiB
C
/*
|
|
|
|
MIT License
|
|
|
|
Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/)
|
|
|
|
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, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
#include "bus.pio.h"
|
|
|
|
extern const __attribute__((aligned(4))) uint8_t firmware[];
|
|
|
|
static bool __not_in_flash( "active") active;
|
|
static uint32_t __not_in_flash("command") command;
|
|
static uint32_t __not_in_flash("control") control;
|
|
|
|
void __not_in_flash_func(board)() {
|
|
while (true) {
|
|
uint32_t enbl = pio_sm_get_blocking(pio0, sm_enbl);
|
|
uint32_t addr = enbl & 0x0FFF;
|
|
uint32_t io = enbl & 0x0F00; // IOSTRB or IOSEL
|
|
uint32_t strb = enbl & 0x0800; // IOSTRB
|
|
uint32_t read = enbl & 0x1000; // R/W
|
|
|
|
if (addr == 0x0FFF) {
|
|
active = false;
|
|
}
|
|
|
|
if (read) {
|
|
if (!io) { // DEVSEL
|
|
switch (addr & 0xF) {
|
|
case 0x8:
|
|
pio_sm_put(pio0, sm_read, sio_hw->fifo_rd);
|
|
break;
|
|
case 0x9:
|
|
// SIO_FIFO_ST_VLD_BITS _u(0x00000001)
|
|
// SIO_FIFO_ST_RDY_BITS _u(0x00000002)
|
|
pio_sm_put(pio0, sm_read, (sio_hw->fifo_st & 3) << 3);
|
|
break;
|
|
case 0xA:
|
|
pio_sm_put(pio0, sm_read, command);
|
|
break;
|
|
case 0xB:
|
|
pio_sm_put(pio0, sm_read, control);
|
|
break;
|
|
}
|
|
} else {
|
|
if (!strb || active) {
|
|
pio_sm_put(pio0, sm_read, firmware[addr]);
|
|
}
|
|
}
|
|
} else {
|
|
uint32_t data = pio_sm_get_blocking(pio0, sm_write);
|
|
if (!io) { // DEVSEL
|
|
switch (addr & 0xF) {
|
|
case 0x8:
|
|
sio_hw->fifo_wr = data;
|
|
break;
|
|
case 0xA:
|
|
command = data;
|
|
break;
|
|
case 0xB:
|
|
control = data;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (io && !strb) {
|
|
active = true;
|
|
}
|
|
|
|
gpio_put(gpio_led, active);
|
|
}
|
|
}
|