DISKREAD and DISKFILL

Added commands to read/fill a sector on a block device.
This commit is contained in:
Peter Weingartner 2021-10-15 19:05:55 -04:00
parent 22e19bcea6
commit 3af3c42a4a
9 changed files with 2648 additions and 4913 deletions

1
.gitignore vendored
View file

@ -51,3 +51,4 @@ dkms.conf
samples/HelloPGX/hello.pgx
samples/HelloPGX/hello.lst
src/mapfile
src/mapfile

View file

@ -49,6 +49,8 @@ const t_cli_command g_cli_commands[] = {
{ "CLS", "CLS : clear the screen", cmd_cls },
{ "DEL", "DEL <path> : delete a file or directory", cmd_del },
{ "DIR", "DIR <path> : print directory listing", cmd_dir },
{ "DISKFILL", "DISKFILL <drive #> <sector #> <byte value>", cmd_diskfill },
{ "DISKREAD", "DISKREAD <drive #> <sector #>", cmd_diskread },
{ "DUMP", "DUMP <addr> [<count>] : print a memory dump", mem_cmd_dump},
{ "LOAD", "LOAD <path> : load a file into memory", cmd_load },
{ "MKDIR", "MKDIR <path> : create a directory", cmd_mkdir },

View file

@ -12,6 +12,92 @@
#include "dev/kbd_mo.h"
#include "fatfs/ff.h"
/*
* Read a sector off a drive
*
* DISKREAD <drive #> <sector #>
*/
short cmd_diskread(short screen, int argc, char * argv[]) {
unsigned char buffer[512];
short bdev_number = 0;
long lba = 0;
short result;
short i;
if (argc < 3) {
print(screen, "USAGE: DISKREAD <drive #> <sector #>\n");
return -1;
}
bdev_number = (short)cli_eval_number(argv[1]);
lba = cli_eval_number(argv[2]);
sprintf(buffer, "Reading drive #%d, sector 0x%X\n", bdev_number, lba);
print(screen, buffer);
result = bdev_read(bdev_number, lba, buffer, 512);
if (result < 512) {
print(screen, "Unable to read sector: ");
print_hex_32(screen, result);
print(screen, "\n");
return -2;
}
for (i = 0; i < 512; i++) {
if (i % 16 == 0) {
print(screen, "\n");
}
print_hex_8(screen, buffer[i]);
print(screen, " ");
}
print(screen, "\n");
return 0;
}
/*
* Fill a sector of a drive with a byte value
*
* DISKFILL <drive #> <sector #> <value>
*/
short cmd_diskfill(short screen, int argc, char * argv[]) {
unsigned char buffer[512];
unsigned char value;
short bdev_number = 0;
long lba = 0;
short result;
short i;
if (argc < 4) {
print(screen, "USAGE: DISKFILL <drive #> <sector #> <byte value>\n");
return -1;
}
bdev_number = (short)cli_eval_number(argv[1]);
lba = cli_eval_number(argv[2]);
value = (unsigned char)cli_eval_number(argv[3]);
sprintf(buffer, "Filling drive #%d, sector 0x%X with 0x%02X\n", bdev_number, lba, value);
print(screen, buffer);
for (i = 0; i < 512; i++) {
buffer[i] = value;
}
result = bdev_write(bdev_number, lba, buffer, 512);
if (result < 512) {
print(screen, "Unable to write sector: ");
print_hex_32(screen, result);
print(screen, "\n");
return -2;
}
/* Read the sector back for verification */
return cmd_diskread(screen, argc, argv);
}
/*
* Test the IDE interface by reading the MBR
*/

View file

@ -60,4 +60,18 @@ extern short cmd_type(short screen, int argc, char * argv[]);
*/
extern short cmd_load(short screen, int argc, char * argv[]);
/*
* Read a sector off a drive
*
* DISKREAD <drive #> <sector #>
*/
extern short cmd_diskread(short screen, int argc, char * argv[]);
/*
* Fill a sector of a drive with a byte value
*
* DISKFILL <drive #> <sector #> <value>
*/
extern short cmd_diskfill(short screen, int argc, char * argv[]);
#endif

View file

@ -284,6 +284,7 @@ short pata_read(long lba, unsigned char * buffer, short size) {
short pata_write(long lba, const unsigned char * buffer, short size) {
short i;
unsigned short *wptr;
unsigned char status;
TRACE("pata_write");
if (pata_wait_ready_not_busy()) {
@ -302,7 +303,8 @@ short pata_write(long lba, const unsigned char * buffer, short size) {
*PATA_CMD_STAT = PATA_CMD_WRITE_SECTOR; // Issue the WRITE command
// TODO: Wait ~500ns
// Give the controller some time...
for (i = 0; i < 32000; i++) ;
if (pata_wait_ready_not_busy()) {
return DEV_TIMEOUT;
@ -313,7 +315,30 @@ short pata_write(long lba, const unsigned char * buffer, short size) {
*PATA_DATA_16 = *wptr++;
}
return 0;
// Give the controller some time...
for (i = 0; i < 32000; i++) ;
if (pata_wait_ready_not_busy()) {
return DEV_TIMEOUT;
}
// Give the controller some time...
for (i = 0; i < 32000; i++) ;
status = *PATA_CMD_STAT;
if ((status & PATA_STAT_DF) != 0){
log(LOG_ERROR, "pata_write: device fault");
return -1;
}
if ((status & PATA_STAT_ERR) != 0) {
log(LOG_ERROR, "pata_write: error");
return -1;
}
TRACE("PATA WRITE COMPLETE");
return size;
}
//

View file

@ -41,38 +41,38 @@ const unsigned short fg_color_lut [32] = {
0x0000, 0xFF00, // Black (transparent)
0x0000, 0xFF80, // Mid-Tone Red
0x8000, 0xFF00, // Mid-Tone Green
0x0080, 0xFF00, // Mid-Tone Blue
0x8000, 0xFF80, // Mid-Tone Yellow
0x8080, 0xFF00, // Mid-Tone Cian
0x0080, 0xFF00, // Mid-Tone Blue
0x0080, 0xFF80, // Mid-Tone Purple
0x8080, 0xFF00, // Mid-Tone Cian
0x8080, 0xFF80, // 50% Grey
0x4500, 0xFFFF, // Orange? Brown?
0x4513, 0xFF8B, // Orange? Brown?
0x0000, 0xFF20, // 12.5% Red
0x2000, 0xFF00, // 12.5% Green
0x0020, 0xFF00, // 12.5% Blue
0x2020, 0xFF20, // 12.5% Grey
0x4040, 0xFF40, // 25% Grey
0xFFFF, 0xFFFF // 100% Grey = White
0x5555, 0xFF55, // Dark Grey
0x5555, 0xFFFF, // Bright Red
0xFF55, 0xFF55, // Bright Green
0xFF55, 0xFFFF, // Bright Yellow
0x55FF, 0xFF55, // Bright Blue
0x55FF, 0xFFFF, // Bright Purple
0xFFFF, 0xFF55, // Bright Cyan
0xFFFF, 0xFFFF // White
};
const unsigned short bg_color_lut [32] = {
0x0000, 0xFF00, // Black (transparent)
0x0000, 0xFF00, // Black (transparent)
0x0000, 0xFF80, // Mid-Tone Red
0x8000, 0xFF00, // Mid-Tone Green
0x8000, 0xFF80, // Mid-Tone Yellow
0x0080, 0xFF00, // Mid-Tone Blue
0x2000, 0xFF20, // 12.5% Yellow
0x2020, 0xFF00, // 12.5% Cian
0x0020, 0xFF20, // 12.5% Purple
0x2020, 0xFF20, // 12.5% Grey
0x691E, 0xFFD2, // Orange? Brown?
0x4513, 0xFF8B, // Orange? Brown?
0x0000, 0xFF20, // 12.5% Red
0x2000, 0xFF00, // 12.5% Green
0x0020, 0xFF00, // 12.5% Blue
0x1010, 0xFF10, // 6.25% Grey
0x4040, 0xFF40, // 25% Grey
0xFFFF, 0xFFFF // 100% Grey = White
0x0080, 0xFF80, // Mid-Tone Purple
0x8080, 0xFF00, // Mid-Tone Cian
0x8080, 0xFF80, // 50% Grey
0x5555, 0xFF55, // Dark Grey
0x5555, 0xFFFF, // Bright Red
0xFF55, 0xFF55, // Bright Green
0xFF55, 0xFFFF, // Bright Yellow
0x55FF, 0xFF55, // Bright Blue
0x55FF, 0xFFFF, // Bright Purple
0xFFFF, 0xFF55, // Bright Cyan
0xFFFF, 0xFFFF // White
};
/*
@ -104,7 +104,7 @@ int text_init() {
// *chan_a->border_control = 0; /* Set to no border */
chan_a->border_control[0] = 0x00102001; // Enable
chan_a->border_control[1] = 0x00000040; //Dark Blue
chan_a->border_control[1] = 0x00000020; //Dark Blue
/* Set the font for channel A */
@ -114,7 +114,7 @@ int text_init() {
}
text_setsizes(0);
text_set_color(0, 15, 3);
text_set_color(0, 12, 4);
text_clear(0, 2);
text_set_cursor(0, 0xF3, 0xB1, 1, 1);
text_set_xy(0, 0, 0);
@ -132,7 +132,7 @@ int text_init() {
chan_b->border_control[1] = 0x00400000; //Dark Red
text_setsizes(1);
text_set_color(1, 15, 3);
text_set_color(1, 4, 3);
text_clear(1, 2);
text_set_cursor(1, 0xF3, 0xB1, 1, 1);
text_set_xy(1, 0, 0);

View file

@ -26,7 +26,7 @@
#include "snd/sid.h"
#include "fatfs/ff.h"
#include "cli/cli.h"
#include "rsrc/bitmaps/splash_a2560k.h"
/* #include "rsrc/bitmaps/splash_a2560k.h"*/
const char* VolumeStr[FF_VOLUMES] = { "sdc", "fdc", "hdc" };
@ -83,39 +83,39 @@ const char* VolumeStr[FF_VOLUMES] = { "sdc", "fdc", "hdc" };
*LED2_REG = 0x02;
}
/*
* Load and display the splash screen
*/
void load_splashscreen() {
int i;
/* Turn off the screen */
*MasterControlReg_A = VKY3_MCR_BLANK_EN;
/* Copy the splash screen LUT */
for (i = 0; i < sizeof(splash_screen_cmap); i++) {
LUT_0[i] = splash_screen_cmap[i][0];
LUT_0[i+1] = splash_screen_cmap[i][1];
LUT_0[i+2] = splash_screen_cmap[i][2];
}
/* Copy the bitmap to video RAM */
for (i = 0; i < sizeof(splash_screen_bmap); i++) {
VRAM_Bank0[i] = splash_screen_bmap[i];
}
/* Set up the bitmap */
*BM0_Addy_Pointer_Reg = 0;
*BM0_Control_Reg = 1;
/* Turn off the border */
*BorderControlReg_L_A = 0;
/* Display the splashscreen: 320x200 */
*MasterControlReg_A = VKY3_MCR_BITMAP_EN | VKY3_MCR_GRAPH_EN | VKY3_MCR_DOUBLE_EN;
for (i = 0; i < 4096*1024; i++) ;
}
// /*
// * Load and display the splash screen
// */
// void load_splashscreen() {
// int i;
//
// /* Turn off the screen */
// *MasterControlReg_A = VKY3_MCR_BLANK_EN;
//
// /* Copy the splash screen LUT */
// for (i = 0; i < sizeof(splash_screen_cmap); i++) {
// LUT_0[i] = splash_screen_cmap[i][0];
// LUT_0[i+1] = splash_screen_cmap[i][1];
// LUT_0[i+2] = splash_screen_cmap[i][2];
// }
//
// /* Copy the bitmap to video RAM */
// for (i = 0; i < sizeof(splash_screen_bmap); i++) {
// VRAM_Bank0[i] = splash_screen_bmap[i];
// }
//
// /* Set up the bitmap */
// *BM0_Addy_Pointer_Reg = 0;
// *BM0_Control_Reg = 1;
//
// /* Turn off the border */
// *BorderControlReg_L_A = 0;
//
// /* Display the splashscreen: 320x200 */
// *MasterControlReg_A = VKY3_MCR_BITMAP_EN | VKY3_MCR_GRAPH_EN | VKY3_MCR_DOUBLE_EN;
//
// for (i = 0; i < 4096*1024; i++) ;
// }
void print_error(short channel, char * message, short code) {
print(channel, message);

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
RAMSTART = 0x00020000;
RAMSIZE = 0x00040000;
RAMSIZE = 0x00020000;
STACKLEN = 0x400;
MEMORY