new file: shared/usb_commands.h
-shared .h files used in both firmware and host app modified: firmware/Makefile modified: host/Makefile -added shared dependency to copy shared files to source prior to building modified: host/source/usb_operations.h modified: firmware/source/main.c -removing usb commands (now in shared) modified: host/include/dbg.h -adding SUCCESS defintion modified: host/source/inlprog.c -calling write file if write arg sent new file: host/source/write_operations.c new file: host/source/write_operations.h -creation of write operations files -opens file and reads header -some skeleton comments -lots of work left to do here new file: roms/nrom_v_test.nes -adding NROM test rom file
This commit is contained in:
parent
6a370d3893
commit
b8be4b768a
|
|
@ -55,7 +55,7 @@ clean:
|
||||||
|
|
||||||
# file targets:
|
# file targets:
|
||||||
|
|
||||||
main.elf: $(OBJECTS)
|
main.elf: shared $(OBJECTS)
|
||||||
$(COMPILE) -o main.elf $(OBJECTS)
|
$(COMPILE) -o main.elf $(OBJECTS)
|
||||||
|
|
||||||
main.hex: main.elf
|
main.hex: main.elf
|
||||||
|
|
@ -70,3 +70,7 @@ disasm: main.elf
|
||||||
|
|
||||||
cpp:
|
cpp:
|
||||||
$(COMPILE) -E main.c
|
$(COMPILE) -E main.c
|
||||||
|
|
||||||
|
#copy shared .h files which are used in host and firmware
|
||||||
|
shared:
|
||||||
|
cp -r ../shared/* source/
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@
|
||||||
|
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
#include "usb_commands.h"
|
||||||
#define REQ_LED_ON 1
|
|
||||||
#define REQ_LED_OFF 2
|
|
||||||
|
|
||||||
|
|
||||||
//USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]);
|
//USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]);
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
|
||||||
TARGET=inlretro
|
TARGET=inlretro
|
||||||
|
|
||||||
#default to windows build
|
#default to windows build
|
||||||
all:
|
all: shared
|
||||||
$(CC) $(INCLUDE) $(SOURCES) -o $(TARGET) $(WINLIB) $(CFLAGS) $(LIBUSB)
|
$(CC) $(INCLUDE) $(SOURCES) -o $(TARGET) $(WINLIB) $(CFLAGS) $(LIBUSB)
|
||||||
|
|
||||||
#unix build doesn't need winlib directory as libusb should be installed on OS.
|
#unix build doesn't need winlib directory as libusb should be installed on OS.
|
||||||
#sudo apt-get install libusb-1.0-0-dev
|
#sudo apt-get install libusb-1.0-0-dev
|
||||||
unix:
|
unix: shared
|
||||||
$(CC) $(INCLUDE) $(SOURCES) -o $(TARGET) $(CFLAGS) $(LIBUSB)
|
$(CC) $(INCLUDE) $(SOURCES) -o $(TARGET) $(CFLAGS) $(LIBUSB)
|
||||||
|
|
||||||
# "make debug" will build program with debug print messages
|
# "make debug" will build program with debug print messages
|
||||||
|
|
@ -29,6 +29,11 @@ debug: all
|
||||||
unixdebug: CFLAGS += -DDEBUG -g
|
unixdebug: CFLAGS += -DDEBUG -g
|
||||||
unixdebug: unix
|
unixdebug: unix
|
||||||
|
|
||||||
|
|
||||||
|
#copy shared .h files which are used in host and firmware
|
||||||
|
shared:
|
||||||
|
cp -r ../shared/* source/
|
||||||
|
|
||||||
#clean on unix and windows(.exe)
|
#clean on unix and windows(.exe)
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGET) $(TARGET).exe $(OBJECTS)
|
rm -f $(TARGET) $(TARGET).exe $(OBJECTS)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define SUCCESS 0
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n",\
|
#define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n",\
|
||||||
__FILE__, __LINE__, ##__VA_ARGS__)
|
__FILE__, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,14 @@
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
|
|
||||||
#include "usb_operations.h"
|
#include "usb_operations.h"
|
||||||
|
#include "usb_commands.h"
|
||||||
|
#include "write_operations.h"
|
||||||
|
|
||||||
|
|
||||||
// vendor requests also defined in firmware
|
// vendor requests also defined in firmware
|
||||||
// TODO put in combined .h file for both host and fw
|
// TODO put in combined .h file for both host and fw
|
||||||
#define REQ_LED_ON 1
|
//#define REQ_LED_ON 1
|
||||||
#define REQ_LED_OFF 2
|
//#define REQ_LED_OFF 2
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
@ -45,33 +47,15 @@ int main(int argc, char *argv[])
|
||||||
while( (rv = getopt( argc, argv, "ofemw:d:s:i:b:")) != -1) {
|
while( (rv = getopt( argc, argv, "ofemw:d:s:i:b:")) != -1) {
|
||||||
|
|
||||||
switch(rv) {
|
switch(rv) {
|
||||||
case 'o':
|
case 'o': o_flag = 1; break;
|
||||||
o_flag = 1;
|
case 'f': f_flag = 1; break;
|
||||||
break;
|
case 'e': e_flag = 1; break;
|
||||||
case 'f':
|
case 'm': m_flag = 1; break;
|
||||||
f_flag = 1;
|
case 'w': w_value = optarg; break;
|
||||||
break;
|
case 'd': d_value = optarg; break;
|
||||||
case 'e':
|
case 's': s_value = optarg; break;
|
||||||
e_flag = 1;
|
case 'i': i_value = optarg; break;
|
||||||
break;
|
case 'b': b_value = optarg; break;
|
||||||
case 'm':
|
|
||||||
m_flag = 1;
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
w_value = optarg;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
d_value = optarg;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
s_value = optarg;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
i_value = optarg;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
b_value = optarg;
|
|
||||||
break;
|
|
||||||
case '?':
|
case '?':
|
||||||
if ( optopt == 'w' ) {
|
if ( optopt == 'w' ) {
|
||||||
log_err("Option -%c requires an argument.", optopt);
|
log_err("Option -%c requires an argument.", optopt);
|
||||||
|
|
@ -126,6 +110,11 @@ int main(int argc, char *argv[])
|
||||||
REQ_LED_OFF, (unsigned char *)buffer254, sizeof(buffer254) );
|
REQ_LED_OFF, (unsigned char *)buffer254, sizeof(buffer254) );
|
||||||
printf("total bytes xfrd: %d \n", xfr_cnt);
|
printf("total bytes xfrd: %d \n", xfr_cnt);
|
||||||
}
|
}
|
||||||
|
if (w_value) { //OFF send REQ_LED_OFF
|
||||||
|
check( write_file( rprog_handle, w_value, i_value, b_value) == SUCCESS,
|
||||||
|
"Failed to write file: %s", w_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
close_usb( context, rprog_handle);
|
close_usb( context, rprog_handle);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define _usb_operations_h
|
#define _usb_operations_h
|
||||||
|
|
||||||
#include "usb_operations.h"
|
#include "usb_operations.h"
|
||||||
|
#include "usb_commands.h"
|
||||||
|
|
||||||
//control transfer request types
|
//control transfer request types
|
||||||
//uint8_t libusb_control_setup::bmRequestType
|
//uint8_t libusb_control_setup::bmRequestType
|
||||||
|
|
@ -23,11 +24,6 @@
|
||||||
//LIBUSB_ENDPOINT_IN In: device-to-host.
|
//LIBUSB_ENDPOINT_IN In: device-to-host.
|
||||||
//LIBUSB_ENDPOINT_OUT Out: host-to-device.
|
//LIBUSB_ENDPOINT_OUT Out: host-to-device.
|
||||||
|
|
||||||
// vendor requests also defined in firmware
|
|
||||||
// TODO put in combined .h file for both host and fw
|
|
||||||
#define REQ_LED_ON 1
|
|
||||||
#define REQ_LED_OFF 2
|
|
||||||
|
|
||||||
//USB timeout
|
//USB timeout
|
||||||
#define SEC_5 5000
|
#define SEC_5 5000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libusb.h>
|
||||||
|
|
||||||
|
//uncomment to DEBUG this file alone
|
||||||
|
#define DEBUG
|
||||||
|
//"make debug" to get DEBUG msgs on entire program
|
||||||
|
#include "dbg.h"
|
||||||
|
|
||||||
|
#include "write_operations.h"
|
||||||
|
#include "usb_operations.h"
|
||||||
|
#include "usb_commands.h"
|
||||||
|
|
||||||
|
#define SIZE_NES_HEADER 16
|
||||||
|
#define SIZE_PRG_BANK 16384
|
||||||
|
#define SIZE_CHR_BANK 8192
|
||||||
|
|
||||||
|
int write_file( libusb_device_handle *usbhandle, char *filename, char *ines_mapper, char *board_config )
|
||||||
|
{
|
||||||
|
int rv = 0;
|
||||||
|
int index = 0;
|
||||||
|
FILE *fileptr = NULL;
|
||||||
|
uint8_t data[128];
|
||||||
|
|
||||||
|
//first open file
|
||||||
|
fileptr = fopen( filename, "rb");
|
||||||
|
//returns file ptr on success, NULL on fail
|
||||||
|
check( fileptr, "Unable to open file: %s in read binary mode", filename);
|
||||||
|
|
||||||
|
//then determine file type
|
||||||
|
uint8_t header[SIZE_NES_HEADER];
|
||||||
|
//size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||||
|
rv = fread( header, sizeof(header[0]), (sizeof(header)/sizeof(header[0])), fileptr);
|
||||||
|
check( rv = sizeof(header), "Unable to read NES header");
|
||||||
|
|
||||||
|
for ( index = 0; index < SIZE_NES_HEADER; index++ ) {
|
||||||
|
debug("header byte #%d = %x", index, header[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//0-3: Constant $4E $45 $53 $1A ("NES" followed by MS-DOS end-of-file)
|
||||||
|
//4: Size of PRG ROM in 16 KB units
|
||||||
|
//5: Size of CHR ROM in 8 KB units (Value 0 means the board uses CHR RAM)
|
||||||
|
//6: Flags 6
|
||||||
|
//7: Flags 7
|
||||||
|
//8: Size of PRG RAM in 8 KB units (Value 0 infers 8 KB for compatibility; see PRG RAM circuit)
|
||||||
|
//9: Flags 9
|
||||||
|
//10: Flags 10 (unofficial)
|
||||||
|
//11-15: Zero filled
|
||||||
|
uint8_t num_prg_banks = header[4];
|
||||||
|
uint8_t num_chr_banks = header[5];
|
||||||
|
|
||||||
|
int prg_size = num_prg_banks * SIZE_PRG_BANK;
|
||||||
|
int chr_size = num_chr_banks * SIZE_CHR_BANK;
|
||||||
|
|
||||||
|
//next check board inserted
|
||||||
|
|
||||||
|
//determine if file is compatible with board
|
||||||
|
|
||||||
|
//load script file
|
||||||
|
|
||||||
|
//load retro-prog commands
|
||||||
|
|
||||||
|
//check if erased, erase as needed, and verify
|
||||||
|
|
||||||
|
//write proper data from file to board proper location on board
|
||||||
|
|
||||||
|
//close file
|
||||||
|
//int fclose(FILE *fp);
|
||||||
|
check( fclose(fileptr) == SUCCESS, "Unable to close file");
|
||||||
|
fileptr = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
|
||||||
|
if (fileptr) {
|
||||||
|
fclose(fileptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef _write_operations_h
|
||||||
|
#define _write_operations_h
|
||||||
|
|
||||||
|
#include "write_operations.h"
|
||||||
|
|
||||||
|
int write_file( libusb_device_handle *usbhandle, char *filename, char *ines_mapper, char *board_config );
|
||||||
|
|
||||||
|
#endif
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef _usb_commands_h
|
||||||
|
#define _usb_commands_h
|
||||||
|
|
||||||
|
#define REQ_LED_ON 1
|
||||||
|
#define REQ_LED_OFF 2
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue