- split up monolith main.c into several files
- implementation of the following commands: #define CMD_RD_PARTAB 0x28 /* P8000 Command: read Parameter block from WDC RAM */ #define CMD_WR_PARTAB 0x78 /* P8000 Command: write Parameter block to WDC RAM */ #define CMD_DL_BTTAB 0x48 /* P8000 Command: delete Bad Track Table from WDC RAM */ #define CMD_RD_BTTAB 0x58 /* P8000 Command: read Bad Track Table from WDC RAM */ #define CMD_WR_BTTAB 0x68 /* P8000 Command: write Bad Track Table to WDC RAM */
This commit is contained in:
parent
b1fcd9fe44
commit
aba33f9830
|
|
@ -36,7 +36,10 @@ SUBDIRS :=
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
C_SRCS += \
|
C_SRCS += \
|
||||||
../main.c \
|
../main.c \
|
||||||
../uart.c
|
../uart.c \
|
||||||
|
../wdc_if_pio.c \
|
||||||
|
../wdc_if_sdcard.c \
|
||||||
|
../wdc_ram.c
|
||||||
|
|
||||||
|
|
||||||
PREPROCESSING_SRCS +=
|
PREPROCESSING_SRCS +=
|
||||||
|
|
@ -47,22 +50,34 @@ ASM_SRCS +=
|
||||||
|
|
||||||
OBJS += \
|
OBJS += \
|
||||||
main.o \
|
main.o \
|
||||||
uart.o
|
uart.o \
|
||||||
|
wdc_if_pio.o \
|
||||||
|
wdc_if_sdcard.o \
|
||||||
|
wdc_ram.o
|
||||||
|
|
||||||
|
|
||||||
OBJS_AS_ARGS += \
|
OBJS_AS_ARGS += \
|
||||||
main.o \
|
main.o \
|
||||||
uart.o
|
uart.o \
|
||||||
|
wdc_if_pio.o \
|
||||||
|
wdc_if_sdcard.o \
|
||||||
|
wdc_ram.o
|
||||||
|
|
||||||
|
|
||||||
C_DEPS += \
|
C_DEPS += \
|
||||||
main.d \
|
main.d \
|
||||||
uart.d
|
uart.d \
|
||||||
|
wdc_if_pio.d \
|
||||||
|
wdc_if_sdcard.d \
|
||||||
|
wdc_ram.d
|
||||||
|
|
||||||
|
|
||||||
C_DEPS_AS_ARGS += \
|
C_DEPS_AS_ARGS += \
|
||||||
main.d \
|
main.d \
|
||||||
uart.d
|
uart.d \
|
||||||
|
wdc_if_pio.d \
|
||||||
|
wdc_if_sdcard.d \
|
||||||
|
wdc_ram.d
|
||||||
|
|
||||||
|
|
||||||
OUTPUT_FILE_PATH +=P8000_WDC_Emulator.elf
|
OUTPUT_FILE_PATH +=P8000_WDC_Emulator.elf
|
||||||
|
|
@ -79,10 +94,16 @@ OUTPUT_FILE_DEP:= ./makedep.mk
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
./%.o: .././%.c
|
./%.o: .././%.c
|
||||||
@echo Building file: $<
|
@echo Building file: $<
|
||||||
@echo Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.0_663) 4.6.2
|
@echo Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.0_663) 4.6.2
|
||||||
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -Werror -pedantic -pedantic-errors -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mmcu=atmega1284p -o"$@" "$<"
|
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -Wundef -Werror -pedantic -pedantic-errors -c -std=gnu99 -save-temps -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mmcu=atmega1284p -o"$@" "$<"
|
||||||
@echo Finished building: $<
|
@echo Finished building: $<
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,9 @@ main.c
|
||||||
|
|
||||||
uart.c
|
uart.c
|
||||||
|
|
||||||
|
wdc_if_pio.c
|
||||||
|
|
||||||
|
wdc_if_sdcard.c
|
||||||
|
|
||||||
|
wdc_ram.c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,11 @@
|
||||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
||||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||||
|
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
|
||||||
<avrgcc.compiler.warnings.WarningsAsErrors>True</avrgcc.compiler.warnings.WarningsAsErrors>
|
<avrgcc.compiler.warnings.WarningsAsErrors>True</avrgcc.compiler.warnings.WarningsAsErrors>
|
||||||
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
|
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
|
||||||
<avrgcc.compiler.warnings.PedanticWarningsAsErrors>True</avrgcc.compiler.warnings.PedanticWarningsAsErrors>
|
<avrgcc.compiler.warnings.PedanticWarningsAsErrors>True</avrgcc.compiler.warnings.PedanticWarningsAsErrors>
|
||||||
|
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||||
<avrgcc.linker.libraries.Libraries>
|
<avrgcc.linker.libraries.Libraries>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>m</Value>
|
<Value>m</Value>
|
||||||
|
|
@ -83,6 +85,24 @@
|
||||||
<Compile Include="uart.h">
|
<Compile Include="uart.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="wdc_if_pio.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="wdc_if_pio.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="wdc_if_sdcard.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="wdc_if_sdcard.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="wdc_ram.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="wdc_ram.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_if_disk.c,v 1.1 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void wdc_init_sdcard()
|
||||||
|
{
|
||||||
|
asm("nop");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_if_disk.h,v 1.1 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WDC_IF_SDCARD_H_
|
||||||
|
#define WDC_IF_SDCARD_H_
|
||||||
|
|
||||||
|
void wdc_init_sdcard();
|
||||||
|
|
||||||
|
#endif /* WDC_IF_SDCARD_H_ */
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_if_p8000.c,v 1.1 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include "wdc_if_pio.h"
|
||||||
|
|
||||||
|
void wdc_init_ports()
|
||||||
|
{
|
||||||
|
configure_pin_status0();
|
||||||
|
configure_pin_status1();
|
||||||
|
configure_pin_status2();
|
||||||
|
configure_pin_astb();
|
||||||
|
configure_pin_te();
|
||||||
|
configure_pin_wdardy();
|
||||||
|
configure_pin_tr();
|
||||||
|
configure_pin_reset();
|
||||||
|
|
||||||
|
configure_port_data_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_wait_for_reset()
|
||||||
|
{
|
||||||
|
while ( !isset_info_reset() ) {
|
||||||
|
port_data_set ( DATA_CLEAR );
|
||||||
|
port_info_set ( INFO_CLEAR );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_read_data_from_p8k ( uint8_t *buffer, uint16_t count, uint8_t wdc_status )
|
||||||
|
{
|
||||||
|
uint16_t datacnt;
|
||||||
|
|
||||||
|
_delay_us ( DELAY_PIO_US );
|
||||||
|
|
||||||
|
configure_port_data_read();
|
||||||
|
datacnt = 0;
|
||||||
|
port_info_set ( wdc_status );
|
||||||
|
while ( !isset_info_te() );
|
||||||
|
while ( !isset_info_wdardy() );
|
||||||
|
do {
|
||||||
|
while ( isset_info_wdardy() );
|
||||||
|
port_info_set ( INFO_ASTB | wdc_status );
|
||||||
|
buffer[datacnt] = ( uint8_t ) port_data_get();
|
||||||
|
port_info_set ( wdc_status );
|
||||||
|
while ( !isset_info_wdardy() );
|
||||||
|
datacnt++;
|
||||||
|
} while ( datacnt < count );
|
||||||
|
port_info_set ( INFO_CLEAR );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_write_data_to_p8k ( uint8_t *buffer, uint16_t count, uint8_t wdc_status )
|
||||||
|
{
|
||||||
|
uint16_t datacnt = 0;
|
||||||
|
|
||||||
|
_delay_us ( DELAY_PIO_US );
|
||||||
|
|
||||||
|
port_info_set ( INFO_TR | wdc_status );
|
||||||
|
while ( isset_info_te() );
|
||||||
|
configure_port_data_write();
|
||||||
|
while ( !isset_info_wdardy() );
|
||||||
|
do {
|
||||||
|
while ( isset_info_wdardy() );
|
||||||
|
port_info_set ( INFO_TR | INFO_ASTB | wdc_status );
|
||||||
|
port_data_set ( buffer[datacnt] );
|
||||||
|
port_info_set ( INFO_TR | wdc_status );
|
||||||
|
while ( !isset_info_wdardy() );
|
||||||
|
|
||||||
|
datacnt++;
|
||||||
|
} while ( datacnt < count );
|
||||||
|
while ( isset_info_wdardy() );
|
||||||
|
port_info_set ( INFO_TR | INFO_ASTB | wdc_status );
|
||||||
|
asm ( "nop" );
|
||||||
|
asm ( "nop" );
|
||||||
|
port_info_set ( INFO_TR | wdc_status );
|
||||||
|
configure_port_data_read();
|
||||||
|
while ( !isset_info_wdardy() );
|
||||||
|
port_info_set ( INFO_CLEAR );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_receive_cmd ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
wdc_read_data_from_p8k ( buffer
|
||||||
|
, count
|
||||||
|
, INFO_STAT_GCMD
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_receive_data ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
wdc_read_data_from_p8k ( buffer
|
||||||
|
, count
|
||||||
|
, INFO_STAT_RDATA
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_send_data ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
wdc_write_data_to_p8k ( buffer
|
||||||
|
, count
|
||||||
|
, INFO_STAT_WDATA
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_send_error()
|
||||||
|
{
|
||||||
|
uint8_t data_buffer[1];
|
||||||
|
|
||||||
|
data_buffer[0] = 0x01;
|
||||||
|
|
||||||
|
wdc_write_data_to_p8k ( data_buffer
|
||||||
|
, 1
|
||||||
|
, INFO_STAT_ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_if_p8000.h,v 1.1 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WDC_IF_PIO_H_
|
||||||
|
#define WDC_IF_PIO_H_
|
||||||
|
|
||||||
|
#define DELAY_PIO_US 500
|
||||||
|
|
||||||
|
#define configure_port_data_read() DDR_DATA = 0x00 /* programs the DATA-Port as Input-only for reading from the P8000*/
|
||||||
|
#define configure_port_data_write() DDR_DATA = 0xff /* programs the DATA-Port as Out-only for writing to the P8000*/
|
||||||
|
|
||||||
|
#define configure_pin_status0() DDR_INFO |= (1 << PIN_INFO_STATUS0)
|
||||||
|
#define configure_pin_status1() DDR_INFO |= (1 << PIN_INFO_STATUS1)
|
||||||
|
#define configure_pin_status2() DDR_INFO |= (1 << PIN_INFO_STATUS2)
|
||||||
|
#define configure_pin_astb() DDR_INFO |= (1 << PIN_INFO_ASTB)
|
||||||
|
#define configure_pin_te() DDR_INFO &= ~(1 << PIN_INFO_TE)
|
||||||
|
#define configure_pin_wdardy() DDR_INFO &= ~(1 << PIN_INFO_WDARDY)
|
||||||
|
#define configure_pin_tr() DDR_INFO |= (1 << PIN_INFO_TR)
|
||||||
|
#define configure_pin_reset() DDR_INFO &= ~(1 << PIN_INFO_RST)
|
||||||
|
|
||||||
|
#define port_data_set(x) (PORT_DATA = (x))
|
||||||
|
#define port_info_set(x) (PORT_INFO = (x))
|
||||||
|
#define port_data_get(x) PIN_DATA
|
||||||
|
#define port_info_get(x) PIN_INFO
|
||||||
|
|
||||||
|
/* input pin handling */
|
||||||
|
#define isset_info_reset() ((PIN_INFO) & (1 << PIN_INFO_RST))
|
||||||
|
#define isset_info_te() ((PIN_INFO) & (1 << PIN_INFO_TE))
|
||||||
|
#define isset_info_wdardy() ((PIN_INFO) & (1 << PIN_INFO_WDARDY))
|
||||||
|
|
||||||
|
/* output pin handling */
|
||||||
|
#define DATA_CLEAR 0x00
|
||||||
|
#define INFO_CLEAR 0x00
|
||||||
|
|
||||||
|
#define INFO_ASTB (1 << PIN_INFO_ASTB) /* 0x08 */
|
||||||
|
#define INFO_STAT_GCMD (1 << PIN_INFO_STATUS0) /* 0x01 */
|
||||||
|
#define INFO_STAT_RDATA (1 << PIN_INFO_STATUS1) /* 0x02 */
|
||||||
|
#define INFO_STAT_WDATA ((1 << PIN_INFO_STATUS0) | (1 << PIN_INFO_STATUS1)) /* 0x03 */
|
||||||
|
#define INFO_STAT_ERROR ((1 << PIN_INFO_STATUS0) | (1 << PIN_INFO_STATUS1) | (1 << PIN_INFO_STATUS2)) /* 0x07 */
|
||||||
|
#define INFO_TR (1 << PIN_INFO_TR) /* 0x40 */
|
||||||
|
|
||||||
|
void wdc_init_ports();
|
||||||
|
void wdc_wait_for_reset();
|
||||||
|
void wdc_receive_cmd(uint8_t *buffer, uint16_t count);
|
||||||
|
void wdc_receive_data(uint8_t *buffer, uint16_t count);
|
||||||
|
void wdc_send_data(uint8_t *buffer, uint16_t count);
|
||||||
|
void wdc_send_error();
|
||||||
|
|
||||||
|
#endif /* WDC_IF_PIO_H_ */
|
||||||
|
|
@ -1,79 +1,72 @@
|
||||||
/*
|
/*
|
||||||
* P8000 WDC Emulator
|
* P8000 WDC Emulator
|
||||||
*
|
*
|
||||||
* $Id: wdc_main.c,v 1.4 2012/05/30 20:07:10 olivleh1 Exp $
|
* $Id: wdc_main.c,v 1.5 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <avr/sleep.h>
|
#include <avr/sleep.h>
|
||||||
#include <avr/io.h>
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "wdc_ram.h"
|
||||||
|
#include "wdc_if_pio.h"
|
||||||
|
#include "wdc_if_sdcard.h"
|
||||||
|
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
void atmega_setup ( void );
|
void atmega_setup ( void );
|
||||||
void wdc_read_data_from_p8k(uint8_t **data_buffer, uint8_t data_count);
|
|
||||||
void wdc_write_data_to_ram(uint8_t **data_buffer, uint16_t data_address, uint8_t data_count);
|
|
||||||
|
|
||||||
int main ( void )
|
int main ( void )
|
||||||
{
|
{
|
||||||
uint8_t cmdbuffer[9];
|
uint16_t cmd_counter = 9;
|
||||||
uint8_t cmdcnt;
|
|
||||||
uint8_t buffer[9];
|
|
||||||
uint8_t datacnt;
|
|
||||||
uint16_t data_counter;
|
uint16_t data_counter;
|
||||||
uint16_t data_address;
|
|
||||||
uint8_t *data_buffer = NULL;
|
uint8_t *data_buffer = NULL;
|
||||||
|
uint8_t *cmd_buffer = NULL;
|
||||||
|
|
||||||
atmega_setup();
|
atmega_setup();
|
||||||
|
|
||||||
uart_puts_p ( PSTR ( "P8000 WDC Emulator 0.01\n" ) );
|
uart_puts_p ( PSTR ( "P8000 WDC Emulator 0.01\n" ) );
|
||||||
|
|
||||||
while(1)
|
while ( 1 ) {
|
||||||
{
|
|
||||||
|
|
||||||
while( !isset_info_reset() )
|
wdc_wait_for_reset();
|
||||||
{
|
|
||||||
port_data_set( DATA_CLEAR );
|
|
||||||
port_info_set( INFO_CLEAR );
|
|
||||||
}
|
|
||||||
|
|
||||||
configure_port_data_read();
|
cmd_buffer = malloc ( cmd_counter * sizeof ( *cmd_buffer ) );
|
||||||
cmdcnt = 0;
|
|
||||||
port_info_set( INFO_STAT_GCMD );
|
|
||||||
|
|
||||||
while ( !isset_info_te() );
|
wdc_receive_cmd ( cmd_buffer
|
||||||
while ( !isset_info_wdardy() );
|
, cmd_counter
|
||||||
while ( cmdcnt < 9 )
|
);
|
||||||
{
|
|
||||||
while ( isset_info_wdardy() );
|
|
||||||
port_info_set( INFO_ASTB | INFO_STAT_GCMD );
|
|
||||||
cmdbuffer[cmdcnt] = port_data_get();
|
|
||||||
port_info_set( INFO_STAT_GCMD );
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
cmdcnt++;
|
|
||||||
}
|
|
||||||
port_info_set( INFO_CLEAR );
|
|
||||||
|
|
||||||
switch( cmdbuffer[0] )
|
|
||||||
{
|
#ifdef DEBUG
|
||||||
|
uart_puts_p ( PSTR ( " CMD Buffer:" ) );
|
||||||
|
uart_putc_hex ( cmd_buffer[0] );
|
||||||
|
uart_putc_hex ( cmd_buffer[1] );
|
||||||
|
uart_putc_hex ( cmd_buffer[2] );
|
||||||
|
uart_putc_hex ( cmd_buffer[3] );
|
||||||
|
uart_putc_hex ( cmd_buffer[4] );
|
||||||
|
uart_putc_hex ( cmd_buffer[5] );
|
||||||
|
uart_putc_hex ( cmd_buffer[6] );
|
||||||
|
uart_putc_hex ( cmd_buffer[7] );
|
||||||
|
uart_putc_hex ( cmd_buffer[8] );
|
||||||
|
uart_putc ( '\n' );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch ( cmd_buffer[0] ) {
|
||||||
case CMD_WR_WDC_RAM:
|
case CMD_WR_WDC_RAM:
|
||||||
|
|
||||||
data_counter = (cmdbuffer[7]<<8)|cmdbuffer[6];
|
data_counter = ( cmd_buffer[7] << 8 ) | cmd_buffer[6];
|
||||||
|
data_buffer = malloc ( data_counter * sizeof ( *data_buffer ) );
|
||||||
|
|
||||||
wdc_read_data_from_p8k(&data_buffer
|
wdc_receive_data ( data_buffer
|
||||||
, data_counter
|
, data_counter
|
||||||
);
|
);
|
||||||
|
|
||||||
wdc_write_data_to_ram(&data_buffer
|
wdc_write_data_to_ram ( data_buffer
|
||||||
,convert_ram_address((cmdbuffer[2]<<8)+cmdbuffer[1])
|
, convert_ram_address ( ( cmd_buffer[2] << 8 ) | cmd_buffer[1] )
|
||||||
, data_counter
|
, data_counter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -82,75 +75,93 @@ int main(void)
|
||||||
|
|
||||||
case CMD_RD_WDC_RAM:
|
case CMD_RD_WDC_RAM:
|
||||||
|
|
||||||
data_counter = (cmdbuffer[7]<<8)|cmdbuffer[6];
|
data_counter = ( cmd_buffer[7] << 8 ) | cmd_buffer[6];
|
||||||
data_address = convert_ram_address((cmdbuffer[2]<<8)+cmdbuffer[1]);
|
data_buffer = malloc ( data_counter * sizeof ( *data_buffer ) );
|
||||||
do
|
|
||||||
{
|
|
||||||
data_counter--;
|
|
||||||
buffer[+data_counter] = wdc_ram[data_address+data_counter];
|
|
||||||
} while (data_counter > 0);
|
|
||||||
|
|
||||||
_delay_us(560);
|
wdc_read_data_from_ram ( data_buffer
|
||||||
|
, convert_ram_address ( ( cmd_buffer[2] << 8 ) | cmd_buffer[1] )
|
||||||
|
, data_counter
|
||||||
|
);
|
||||||
|
|
||||||
data_counter = (cmdbuffer[7]<<8)|cmdbuffer[6];
|
wdc_send_data ( data_buffer
|
||||||
datacnt = 0;
|
, data_counter
|
||||||
|
);
|
||||||
|
|
||||||
port_info_set( INFO_TR |INFO_STAT_WDATA );
|
free ( data_buffer );
|
||||||
while ( isset_info_te() );
|
break;
|
||||||
configure_port_data_write();
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
while ( datacnt < data_counter )
|
|
||||||
{
|
|
||||||
while ( isset_info_wdardy() );
|
|
||||||
port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_WDATA );
|
|
||||||
port_data_set(buffer[datacnt]);
|
|
||||||
port_info_set( INFO_TR |INFO_STAT_WDATA );
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
|
|
||||||
datacnt++;
|
case CMD_RD_PARTAB:
|
||||||
}
|
|
||||||
while ( isset_info_wdardy() );
|
data_counter = ( cmd_buffer[7] << 8 ) | cmd_buffer[6];
|
||||||
port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_WDATA );
|
data_buffer = malloc ( data_counter * sizeof ( *data_buffer ) );
|
||||||
asm("nop");
|
|
||||||
port_info_set( INFO_TR |INFO_STAT_WDATA );
|
wdc_read_partab ( data_buffer
|
||||||
configure_port_data_read();
|
, data_counter );
|
||||||
port_info_set( INFO_CLEAR );
|
|
||||||
|
wdc_send_data ( data_buffer
|
||||||
|
, data_counter
|
||||||
|
);
|
||||||
|
|
||||||
|
free ( data_buffer );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_WR_PARTAB:
|
||||||
|
|
||||||
|
data_counter = ( cmd_buffer[7] << 8 ) | cmd_buffer[6];
|
||||||
|
data_buffer = malloc ( data_counter * sizeof ( *data_buffer ) );
|
||||||
|
|
||||||
|
wdc_receive_data ( data_buffer
|
||||||
|
, data_counter
|
||||||
|
);
|
||||||
|
|
||||||
|
wdc_write_partab ( data_buffer
|
||||||
|
, data_counter );
|
||||||
|
|
||||||
|
free ( data_buffer );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_DL_BTTAB:
|
||||||
|
|
||||||
|
wdc_del_bttab();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_RD_BTTAB:
|
||||||
|
|
||||||
|
data_counter = ( cmd_buffer[7] << 8 ) | cmd_buffer[6];
|
||||||
|
data_buffer = malloc ( data_counter * sizeof ( *data_buffer ) );
|
||||||
|
|
||||||
|
wdc_read_bttab ( data_buffer
|
||||||
|
, data_counter );
|
||||||
|
|
||||||
|
wdc_send_data ( data_buffer
|
||||||
|
, data_counter
|
||||||
|
);
|
||||||
|
|
||||||
|
free ( data_buffer );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_WR_BTTAB:
|
||||||
|
|
||||||
|
data_counter = ( cmd_buffer[7] << 8 ) | cmd_buffer[6];
|
||||||
|
data_buffer = malloc ( data_counter * sizeof ( *data_buffer ) );
|
||||||
|
|
||||||
|
wdc_receive_data ( data_buffer
|
||||||
|
, data_counter
|
||||||
|
);
|
||||||
|
|
||||||
|
wdc_write_bttab ( data_buffer
|
||||||
|
, data_counter );
|
||||||
|
|
||||||
|
free ( data_buffer );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_delay_us(560);
|
|
||||||
port_info_set( INFO_TR | INFO_STAT_ERROR );
|
wdc_send_error();
|
||||||
while ( isset_info_te() );
|
|
||||||
configure_port_data_write();
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
while ( isset_info_wdardy() );
|
|
||||||
port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_ERROR );
|
|
||||||
port_data_set(0x01);
|
|
||||||
port_info_set( INFO_TR | INFO_STAT_ERROR );
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
while ( isset_info_wdardy() );
|
|
||||||
port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_ERROR );
|
|
||||||
asm("nop");
|
|
||||||
asm("nop");
|
|
||||||
port_info_set( INFO_TR | INFO_STAT_ERROR );
|
|
||||||
configure_port_data_read();
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
port_info_set( INFO_CLEAR );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
uart_puts_p(PSTR(" CMD Buffer:"));
|
free ( cmd_buffer );
|
||||||
uart_putc_hex(cmdbuffer[0]);
|
|
||||||
uart_putc_hex(cmdbuffer[1]);
|
|
||||||
uart_putc_hex(cmdbuffer[2]);
|
|
||||||
uart_putc_hex(cmdbuffer[3]);
|
|
||||||
uart_putc_hex(cmdbuffer[4]);
|
|
||||||
uart_putc_hex(cmdbuffer[5]);
|
|
||||||
uart_putc_hex(cmdbuffer[6]);
|
|
||||||
uart_putc_hex(cmdbuffer[7]);
|
|
||||||
uart_putc_hex(cmdbuffer[8]);
|
|
||||||
uart_putc('\n');
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -158,52 +169,7 @@ int main(void)
|
||||||
void atmega_setup ( void )
|
void atmega_setup ( void )
|
||||||
{
|
{
|
||||||
set_sleep_mode ( SLEEP_MODE_IDLE );
|
set_sleep_mode ( SLEEP_MODE_IDLE );
|
||||||
|
wdc_init_ports();
|
||||||
configure_pin_status0();
|
wdc_init_sdcard();
|
||||||
configure_pin_status1();
|
|
||||||
configure_pin_status2();
|
|
||||||
configure_pin_astb();
|
|
||||||
configure_pin_te();
|
|
||||||
configure_pin_wdardy();
|
|
||||||
configure_pin_tr();
|
|
||||||
configure_pin_reset();
|
|
||||||
|
|
||||||
configure_port_data_read();
|
|
||||||
|
|
||||||
uart_init();
|
uart_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wdc_read_data_from_p8k(uint8_t **data_buffer, uint8_t data_count)
|
|
||||||
{
|
|
||||||
int datacnt = 0;
|
|
||||||
|
|
||||||
(*data_buffer) = (uint8_t *)malloc(data_count);
|
|
||||||
|
|
||||||
_delay_us(560);
|
|
||||||
|
|
||||||
configure_port_data_read();
|
|
||||||
port_info_set( INFO_STAT_RDATA );
|
|
||||||
while ( !isset_info_te() );
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
do
|
|
||||||
{
|
|
||||||
while ( isset_info_wdardy() );
|
|
||||||
port_info_set( INFO_ASTB | INFO_STAT_RDATA );
|
|
||||||
(*data_buffer)[datacnt] = port_data_get();
|
|
||||||
port_info_set( INFO_STAT_RDATA );
|
|
||||||
while ( !isset_info_wdardy() );
|
|
||||||
|
|
||||||
datacnt++;
|
|
||||||
} while ( datacnt < data_count );
|
|
||||||
|
|
||||||
port_info_set( INFO_CLEAR );
|
|
||||||
}
|
|
||||||
|
|
||||||
void wdc_write_data_to_ram(uint8_t **data_buffer, uint16_t data_address, uint8_t data_count)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
data_count--;
|
|
||||||
wdc_ram[data_address+data_count] = (*data_buffer)[data_count];
|
|
||||||
} while (data_count > 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* P8000 WDC Emulator
|
* P8000 WDC Emulator
|
||||||
*
|
*
|
||||||
* $Id: wdc_main.h,v 1.4 2012/05/30 16:41:00 olivleh1 Exp $
|
* $Id: wdc_main.h,v 1.5 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -9,43 +9,12 @@
|
||||||
#ifndef MAIN_H_
|
#ifndef MAIN_H_
|
||||||
#define MAIN_H_
|
#define MAIN_H_
|
||||||
|
|
||||||
#define configure_port_data_read() DDR_DATA = 0x00 /* programs the DATA-Port as Input-only for reading from the P8000*/
|
|
||||||
#define configure_port_data_write() DDR_DATA = 0xff /* programs the DATA-Port as Out-only for writing to the P8000*/
|
|
||||||
|
|
||||||
#define configure_pin_status0() DDR_INFO |= (1 << PIN_INFO_STATUS0)
|
|
||||||
#define configure_pin_status1() DDR_INFO |= (1 << PIN_INFO_STATUS1)
|
|
||||||
#define configure_pin_status2() DDR_INFO |= (1 << PIN_INFO_STATUS2)
|
|
||||||
#define configure_pin_astb() DDR_INFO |= (1 << PIN_INFO_ASTB)
|
|
||||||
#define configure_pin_te() DDR_INFO &= ~(1 << PIN_INFO_TE)
|
|
||||||
#define configure_pin_wdardy() DDR_INFO &= ~(1 << PIN_INFO_WDARDY)
|
|
||||||
#define configure_pin_tr() DDR_INFO |= (1 << PIN_INFO_TR)
|
|
||||||
#define configure_pin_reset() DDR_INFO &= ~(1 << PIN_INFO_RST)
|
|
||||||
|
|
||||||
#define port_data_set(x) (PORT_DATA = x)
|
|
||||||
#define port_info_set(x) (PORT_INFO = x)
|
|
||||||
#define port_data_get(x) PIN_DATA
|
|
||||||
#define port_info_get(x) PIN_INFO
|
|
||||||
|
|
||||||
/* input pin handling */
|
|
||||||
#define isset_info_reset() ((PIN_INFO) & (1 << PIN_INFO_RST))
|
|
||||||
#define isset_info_te() ((PIN_INFO) & (1 << PIN_INFO_TE))
|
|
||||||
#define isset_info_wdardy() ((PIN_INFO) & (1 << PIN_INFO_WDARDY))
|
|
||||||
|
|
||||||
/* output pin handling */
|
|
||||||
#define DATA_CLEAR 0x00
|
|
||||||
#define INFO_CLEAR 0x00
|
|
||||||
|
|
||||||
#define INFO_ASTB (1 << PIN_INFO_ASTB)
|
|
||||||
#define INFO_STAT_GCMD (1 << PIN_INFO_STATUS0) /* 0x01 */
|
|
||||||
#define INFO_STAT_RDATA (1 << PIN_INFO_STATUS1) /* 0x02 */
|
|
||||||
#define INFO_STAT_WDATA ((1 << PIN_INFO_STATUS0) | (1 << PIN_INFO_STATUS1)) /* 0x03 */
|
|
||||||
#define INFO_STAT_ERROR ((1 << PIN_INFO_STATUS0) | (1 << PIN_INFO_STATUS1) | (1 << PIN_INFO_STATUS2)) /* 0x07 */
|
|
||||||
#define INFO_TR 0x40
|
|
||||||
|
|
||||||
#define CMD_WR_WDC_RAM 0x18 /* P8000 Command: write data to WDC RAM */
|
#define CMD_WR_WDC_RAM 0x18 /* P8000 Command: write data to WDC RAM */
|
||||||
#define CMD_RD_WDC_RAM 0x08 /* P8000 Command: read data from WDC RAM */
|
#define CMD_RD_WDC_RAM 0x08 /* P8000 Command: read data from WDC RAM */
|
||||||
|
#define CMD_RD_PARTAB 0x28 /* P8000 Command: read Parameter block from WDC RAM */
|
||||||
|
#define CMD_WR_PARTAB 0x78 /* P8000 Command: write Parameter block to WDC RAM */
|
||||||
|
#define CMD_DL_BTTAB 0x48 /* P8000 Command: delete Bad Track Table from WDC RAM */
|
||||||
|
#define CMD_RD_BTTAB 0x58 /* P8000 Command: read Bad Track Table from WDC RAM */
|
||||||
|
#define CMD_WR_BTTAB 0x68 /* P8000 Command: write Bad Track Table to WDC RAM */
|
||||||
|
|
||||||
unsigned char wdc_ram[2048];
|
|
||||||
#define convert_ram_address(x) ((x) - 0x2000) /* The S-RAM of the original WDC hardware starts at 0x2000.
|
|
||||||
We use an array as RAM here and no direct RAM access */
|
|
||||||
#endif /* MAIN_H_ */
|
#endif /* MAIN_H_ */
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_ram.c,v 1.1 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
uint8_t par_table[200] = { 'W', 'D', 'C', '_', '4', '.', '2', 0x00, 'R', 'O', 'B', ' ', 'K', '5', '5', '0',
|
||||||
|
'4', '.', '5', '0', 0x00, 0x00, 0x00, 0x00, 0x04, 0x05, 0x12, 0x00, 0x04, 0x01, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x01, 0x00, 0x01, 0x01,
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
uint8_t bt_table[125];
|
||||||
|
unsigned char wdc_ram[2048];
|
||||||
|
|
||||||
|
|
||||||
|
void wdc_write_data_to_ram ( uint8_t *buffer, uint16_t address, uint16_t count )
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
count--;
|
||||||
|
wdc_ram[address + count] = buffer[count];
|
||||||
|
} while ( count > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_read_data_from_ram ( uint8_t *buffer, uint16_t address, uint16_t count )
|
||||||
|
{
|
||||||
|
|
||||||
|
do {
|
||||||
|
count--;
|
||||||
|
buffer[count] = wdc_ram[address + count];
|
||||||
|
} while ( count > 0 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_read_partab ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
count--;
|
||||||
|
buffer[count] = par_table[count];
|
||||||
|
} while ( count > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_write_partab ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
count--;
|
||||||
|
par_table[count + 8] = buffer[count];
|
||||||
|
} while ( count > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_del_bttab()
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for ( i = 0; i < 125; i++ )
|
||||||
|
bt_table[i] = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_read_bttab ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
count--;
|
||||||
|
buffer[count] = bt_table[count];
|
||||||
|
} while ( count > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wdc_write_bttab ( uint8_t *buffer, uint16_t count )
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
count--;
|
||||||
|
bt_table[count] = buffer[count];
|
||||||
|
} while ( count > 0 );
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_ram.h,v 1.1 2012/05/31 20:21:51 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WDC_RAM_H_
|
||||||
|
#define WDC_RAM_H_
|
||||||
|
|
||||||
|
void wdc_write_data_to_ram ( uint8_t *buffer, uint16_t address, uint16_t count );
|
||||||
|
void wdc_read_data_from_ram ( uint8_t *buffer, uint16_t address, uint16_t count );
|
||||||
|
|
||||||
|
void wdc_read_partab ( uint8_t *buffer, uint16_t count );
|
||||||
|
void wdc_write_partab ( uint8_t *buffer, uint16_t count );
|
||||||
|
|
||||||
|
void wdc_del_bttab();
|
||||||
|
void wdc_read_bttab ( uint8_t *buffer, uint16_t count );
|
||||||
|
void wdc_write_bttab ( uint8_t *buffer, uint16_t count );
|
||||||
|
|
||||||
|
#define convert_ram_address(x) ((x) - 0x2000) /* The S-RAM of the original WDC hardware starts at 0x2000. We use an array as RAM here and no direct RAM access */
|
||||||
|
|
||||||
|
#endif /* WDC_RAM_H_ */
|
||||||
Loading…
Reference in New Issue