mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 20:30:56 +11:00
Compare commits
3 Commits
beaea6f978
...
9ec71ecfee
Author | SHA1 | Date | |
---|---|---|---|
|
9ec71ecfee | ||
|
fcee98ee4e | ||
|
fb93fcd6e6 |
43
recipes/rc2014/eeprom/usr.asm
Normal file
43
recipes/rc2014/eeprom/usr.asm
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
; If you find youself needing to write to an EEPROM through a shell that isn't
|
||||||
|
; built for this, compile this dependency-less code (change memory offsets as
|
||||||
|
; needed) and run it in a USR-like fashion.
|
||||||
|
|
||||||
|
ld bc, 0x1000 ; bytecount to write
|
||||||
|
ld de, 0xd000 ; source data
|
||||||
|
ld hl, 0x2000 ; dest EEPROM memory mapping
|
||||||
|
|
||||||
|
loop:
|
||||||
|
ld a, (de)
|
||||||
|
ld (hl), a
|
||||||
|
push de ; --> lvl 1
|
||||||
|
push bc ; --> lvl 2
|
||||||
|
ld bc, 0x2000 ; Should be plenty enough to go > 10ms
|
||||||
|
ld e, a ; save expected data for verification
|
||||||
|
wait:
|
||||||
|
; as long as writing operation is running, IO/6 will toggle at each
|
||||||
|
; read attempt and IO/7 will be the opposite of what was written. Simply
|
||||||
|
; wait until the read operation yields the same value as what we've
|
||||||
|
; written
|
||||||
|
ld a, (hl)
|
||||||
|
cp e
|
||||||
|
jr z, waitend
|
||||||
|
dec bc
|
||||||
|
ld a, b
|
||||||
|
or c
|
||||||
|
jr nz, wait
|
||||||
|
; mismatch
|
||||||
|
pop bc ; <-- lvl 2
|
||||||
|
pop de ; <-- lvl 1
|
||||||
|
ld a, 1 ; nonzero
|
||||||
|
or a ; unset Z
|
||||||
|
ret
|
||||||
|
waitend:
|
||||||
|
pop bc ; <-- lvl 2
|
||||||
|
pop de ; <-- lvl 1
|
||||||
|
inc hl
|
||||||
|
inc de
|
||||||
|
dec bc
|
||||||
|
ld a, b
|
||||||
|
or c
|
||||||
|
jr nz, loop
|
||||||
|
ret ; Z already set
|
2
tools/.gitignore
vendored
2
tools/.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
|
*.o
|
||||||
/memdumpb
|
/memdumpb
|
||||||
|
/uploadb
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
CFLAGS ?= -Wall
|
|
||||||
|
|
||||||
MEMDUMP_TGT = memdumpb
|
MEMDUMP_TGT = memdumpb
|
||||||
MEMDUMP_SRC = memdump.c
|
MEMDUMP_SRC = memdump.c
|
||||||
|
UPLOAD_TGT = uploadb
|
||||||
|
UPLOAD_SRC = upload.c
|
||||||
|
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT)
|
||||||
|
OBJS = common.o
|
||||||
|
|
||||||
all: ${MEMDUMP_TGT}
|
all: $(TARGETS)
|
||||||
|
|
||||||
${MEMDUMP_TGT}: ${MEMDUMP_SRC}
|
.SUFFIXES: .c .o
|
||||||
${CC} ${CFLAGS} ${MEMDUMP_SRC} -o ${MEMDUMP_TGT}
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(MEMDUMP_TGT): $(MEMDUMP_SRC) $(OBJS)
|
||||||
|
$(CC) $(CFLAGS) $(MEMDUMP_SRC) $(OBJS) -o $@
|
||||||
|
|
||||||
|
$(UPLOAD_TGT): $(UPLOAD_SRC) $(OBJS)
|
||||||
|
$(CC) $(CFLAGS) $(UPLOAD_SRC) $(OBJS) -o $@
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f ${MEMDUMP_TGT}
|
rm -f $(TARGETS) $(OBJS)
|
||||||
|
19
tools/common.c
Normal file
19
tools/common.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void sendcmd(int fd, char *cmd)
|
||||||
|
{
|
||||||
|
char junk[2];
|
||||||
|
while (*cmd) {
|
||||||
|
write(fd, cmd, 1);
|
||||||
|
read(fd, &junk, 1);
|
||||||
|
cmd++;
|
||||||
|
// The other side is sometimes much slower than us and if we don't let
|
||||||
|
// it breathe, it can choke.
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
write(fd, "\n", 1);
|
||||||
|
read(fd, &junk, 2); // sends back \r\n
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
|
2
tools/common.h
Normal file
2
tools/common.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
void sendcmd(int fd, char *cmd);
|
||||||
|
|
1
tools/emul/.gitignore
vendored
1
tools/emul/.gitignore
vendored
@ -8,4 +8,3 @@
|
|||||||
/cfsin/ed
|
/cfsin/ed
|
||||||
/cfsin/basic
|
/cfsin/basic
|
||||||
/cfsin/user.h
|
/cfsin/user.h
|
||||||
*.o
|
|
||||||
|
@ -3,26 +3,12 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
/* Read specified number of bytes at specified memory address through a BASIC
|
/* Read specified number of bytes at specified memory address through a BASIC
|
||||||
* remote shell and dump it to stdout.
|
* remote shell and dump it to stdout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void sendcmd(int fd, char *cmd)
|
|
||||||
{
|
|
||||||
char junk[2];
|
|
||||||
while (*cmd) {
|
|
||||||
write(fd, cmd, 1);
|
|
||||||
read(fd, &junk, 1);
|
|
||||||
cmd++;
|
|
||||||
// The other side is sometimes much slower than us and if we don't let
|
|
||||||
// it breathe, it can choke.
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
write(fd, "\n", 1);
|
|
||||||
read(fd, &junk, 2); // sends back \r\n
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
@ -50,17 +36,12 @@ int main(int argc, char **argv)
|
|||||||
for (int i=0; i<bytecount; i++) {
|
for (int i=0; i<bytecount; i++) {
|
||||||
sendcmd(fd, "peek m");
|
sendcmd(fd, "peek m");
|
||||||
read(fd, s, 2); // read prompt
|
read(fd, s, 2); // read prompt
|
||||||
sendcmd(fd, "print a");
|
sendcmd(fd, "puth a");
|
||||||
for (int j=0; j<3; j++) {
|
read(fd, s, 2); // read hex pair
|
||||||
read(fd, s+j, 1);
|
s[2] = 0; // null terminate
|
||||||
s[j+1] = 0; // always null-terminate
|
unsigned char c = strtol(s, NULL, 16);
|
||||||
if (s[j] < '0') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsigned char c = strtol(s, NULL, 10);
|
|
||||||
putchar(c);
|
putchar(c);
|
||||||
read(fd, s, 3); // read \r\n + prompt - last char
|
read(fd, s, 2); // read prompt
|
||||||
sendcmd(fd, "m=m+1");
|
sendcmd(fd, "m=m+1");
|
||||||
read(fd, s, 2); // read prompt
|
read(fd, s, 2); // read prompt
|
||||||
}
|
}
|
||||||
|
65
tools/upload.c
Normal file
65
tools/upload.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
/* Push specified file to specified device **running the BASIC shell** and verify
|
||||||
|
* that the sent contents is correct.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc != 4) {
|
||||||
|
fprintf(stderr, "Usage: ./upload device memptr fname\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
unsigned int memptr = strtol(argv[2], NULL, 16);
|
||||||
|
FILE *fp = fopen(argv[3], "r");
|
||||||
|
if (!fp) {
|
||||||
|
fprintf(stderr, "Can't open %s.\n", argv[3]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
unsigned int bytecount = ftell(fp);
|
||||||
|
fprintf(stderr, "memptr: 0x%04x bytecount: 0x%04x.\n", memptr, bytecount);
|
||||||
|
if (memptr+bytecount > 0xffff) {
|
||||||
|
fprintf(stderr, "memptr+bytecount out of range.\n");
|
||||||
|
fclose(fp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
rewind(fp);
|
||||||
|
int fd = open(argv[1], O_RDWR|O_NOCTTY);
|
||||||
|
char s[0x10];
|
||||||
|
sprintf(s, "m=0x%04x", memptr);
|
||||||
|
sendcmd(fd, s);
|
||||||
|
read(fd, s, 2); // read prompt
|
||||||
|
|
||||||
|
while (fread(s, 1, 1, fp)) {
|
||||||
|
putchar('.');
|
||||||
|
fflush(stdout);
|
||||||
|
unsigned char c = s[0];
|
||||||
|
sendcmd(fd, "getc");
|
||||||
|
write(fd, &c, 1);
|
||||||
|
read(fd, s, 2); // read prompt
|
||||||
|
sendcmd(fd, "puth a");
|
||||||
|
read(fd, s, 2); // read hex pair
|
||||||
|
s[2] = 0; // null terminate
|
||||||
|
unsigned char c2 = strtol(s, NULL, 16);
|
||||||
|
read(fd, s, 2); // read prompt
|
||||||
|
if (c != c2) {
|
||||||
|
// mismatch!
|
||||||
|
unsigned int pos = ftell(fp);
|
||||||
|
fprintf(stderr, "Mismatch at byte %d! %d != %d.\n", pos, c, c2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
sendcmd(fd, "poke m a");
|
||||||
|
read(fd, s, 2); // read prompt
|
||||||
|
sendcmd(fd, "m=m+1");
|
||||||
|
read(fd, s, 2); // read prompt
|
||||||
|
}
|
||||||
|
printf("Done!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -1,79 +0,0 @@
|
|||||||
#!/usr/bin/perl
|
|
||||||
# Push specified file to specified device **running the BASIC shell** and verify
|
|
||||||
# that the sent contents is correct.
|
|
||||||
use strict;
|
|
||||||
use Fcntl;
|
|
||||||
|
|
||||||
if (@ARGV != 3) {
|
|
||||||
print "Usage: ./uploadb.pl device memptr filename\n";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my ($device, $memptr, $fname) = @ARGV;
|
|
||||||
|
|
||||||
if (hex($memptr) >= 0x10000) { die "memptr is out of range"; }
|
|
||||||
|
|
||||||
if (! -e $fname) { die "${fname} does not exist"; }
|
|
||||||
my $fsize = -s $fname;
|
|
||||||
my $maxsize = 0x10000 - hex($memptr);
|
|
||||||
if ($fsize > $maxsize) { die "File too big. ${maxsize} bytes max"; }
|
|
||||||
|
|
||||||
my $fh;
|
|
||||||
unless (open($fh, '<', $fname)) { die "Can't open $fname"; }
|
|
||||||
|
|
||||||
my $devh;
|
|
||||||
unless (sysopen($devh, $device, O_RDWR|O_NOCTTY)) { die "Can't open $device"; }
|
|
||||||
|
|
||||||
sub sendcmd {
|
|
||||||
# The serial link echoes back all typed characters and expects us to read
|
|
||||||
# them. We have to send each char one at a time.
|
|
||||||
my $junk;
|
|
||||||
foreach my $char (split //, shift) {
|
|
||||||
syswrite $devh, $char;
|
|
||||||
sysread $devh, $junk, 1;
|
|
||||||
}
|
|
||||||
syswrite $devh, "\n";
|
|
||||||
sysread $devh, $junk, 2; # send back \r\n
|
|
||||||
}
|
|
||||||
|
|
||||||
sendcmd("m=0x${memptr}");
|
|
||||||
|
|
||||||
my $rd;
|
|
||||||
sysread $devh, $rd, 2; # read prompt
|
|
||||||
|
|
||||||
# disable buffering
|
|
||||||
$| = 1;
|
|
||||||
|
|
||||||
while (sysread $fh, my $char, 1) {
|
|
||||||
print ".";
|
|
||||||
for (my $i=0; $i<5; $i++) { # try 5 times
|
|
||||||
sendcmd("getc");
|
|
||||||
syswrite $devh, $char;
|
|
||||||
sysread $devh, $rd, 2; # read prompt
|
|
||||||
sendcmd("print a");
|
|
||||||
my $s = "";
|
|
||||||
while (1) {
|
|
||||||
sysread $devh, $rd, 1;
|
|
||||||
if ($rd !~ /\d/) { last; }
|
|
||||||
$s .= $rd;
|
|
||||||
}
|
|
||||||
sysread $devh, $rd, 3; # read prompt
|
|
||||||
if ($s == ord($char)) {
|
|
||||||
last;
|
|
||||||
} else {
|
|
||||||
if ($i < 4) {
|
|
||||||
print "Mismatch at byte ${i}! ${s} != ${ord($char)}. Retrying.\n";
|
|
||||||
} else {
|
|
||||||
die "Maximum retries reached, abort.\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendcmd("poke m a");
|
|
||||||
sysread $devh, $rd, 2; # read prompt
|
|
||||||
sendcmd("m=m+1");
|
|
||||||
sysread $devh, $rd, 2; # read prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
print "Done!\n";
|
|
||||||
close $fh;
|
|
||||||
close $devh;
|
|
Loading…
Reference in New Issue
Block a user