1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 12:18:07 +11:00

Allow file-to-file compilation in the emulated shell

This commit is contained in:
Virgil Dupras 2019-06-05 19:51:19 -04:00
parent fb99f4ad91
commit 3dde51ae98
3 changed files with 27 additions and 22 deletions

View File

@ -5,28 +5,22 @@ from within the shell. What you need is:
* A mounted filesystem with `zasm` on it. * A mounted filesystem with `zasm` on it.
* A block device to read from (can be a file from mounted CFS) * A block device to read from (can be a file from mounted CFS)
* A block device to write to (can theoretically be a file, but technical * A block device to write to (can also be a file).
limitations temporary prevents us that. We'll use a mmap for now).
The emulated shell is already set up with all you need. If you want to run that The emulated shell is already set up with all you need. If you want to run that
on a real machine, you'll have to make sure to provide these requirements. on a real machine, you'll have to make sure to provide these requirements.
The emulated shell has a `hello.asm` file in its mounted filesystem that is The emulated shell has a `hello.asm` file in its mounted filesystem that is
ready to compile. It has two file handles 0 and 1, mapped to blk IDs 1 and 2. ready to compile. It has two file handles 0 and 1, mapped to blk IDs 1 and 2.
We only use file handle 0 (blk ID 1) and then tell zasm to output to mmap which We will open our source file in handle 0 and our dest file in handle 1. Then,
is configured to start at `0xe00` with the power of the `pgm` module, we'll autoload our newly compiled file and
execute it!
Collapse OS Collapse OS
> fopn 0 hello.asm ; open file in handle 0 > fnew 1 dest ; create destination file
> zasm 1 3 ; assemble opened file and spit result in mmap > fopn 0 hello.asm ; open source file in handle 0
> bsel 3 ; select mmap > fopn 1 dest ; open dest binary in handle 1
> mptr e000 ; set memptr to mmap's beginning > zasm 1 3 ; assemble source file into binary file
> peek 5 > dest ; call newly compiled file
210890CD3C ; looking good
> mptr 4200 ; hello.asm is configured to run from 0x4200
> load ff ; load compiled code from mmap
> peek 5
210890CD3C ; looking good
> call 00 0000
Assembled from the shell Assembled from the shell
> ; Awesome! > ; Awesome!

View File

@ -32,9 +32,11 @@
#define FS_DATA_PORT 0x01 #define FS_DATA_PORT 0x01
// Controls what address (24bit) the data port returns. To select an address, // Controls what address (24bit) the data port returns. To select an address,
// this port has to be written to 3 times, starting with the MSB. // this port has to be written to 3 times, starting with the MSB.
// Reading this port returns an out-of-bounds indicator. 0 means addr is within // Reading this port returns an out-of-bounds indicator. Meaning:
// bounds, non zero means either that we're in the middle of an addr-setting // 0 means addr is within bounds
// operation or that the address is not within bounds. // 1 means that we're equal to fsdev size (error for reading, ok for writing)
// 2 means more than fsdev size (always invalid)
// 3 means incomplete addr setting
#define FS_ADDR_PORT 0x02 #define FS_ADDR_PORT 0x02
static Z80Context cpu; static Z80Context cpu;
@ -74,8 +76,11 @@ static uint8_t io_read(int unused, uint16_t addr)
} }
} else if (addr == FS_ADDR_PORT) { } else if (addr == FS_ADDR_PORT) {
if (fsdev_addr_lvl != 0) { if (fsdev_addr_lvl != 0) {
return fsdev_addr_lvl; return 3;
} else if (fsdev_ptr >= fsdev_size) { } else if (fsdev_ptr > fsdev_size) {
fprintf(stderr, "Out of bounds FSDEV addr request at %d / %d\n", fsdev_ptr, fsdev_size);
return 2;
} else if (fsdev_ptr == fsdev_size) {
return 1; return 1;
} else { } else {
return 0; return 0;
@ -101,11 +106,17 @@ static void io_write(int unused, uint16_t addr, uint8_t val)
return; return;
} }
if (fsdev_ptr < fsdev_size) { if (fsdev_ptr < fsdev_size) {
#ifdef DEBUG
fprintf(stderr, "Writing to FSDEV (%d)\n", fsdev_ptr);
#endif
fsdev[fsdev_ptr] = val; fsdev[fsdev_ptr] = val;
} else if ((fsdev_ptr == fsdev_size) && (fsdev_ptr < MAX_FSDEV_SIZE)) { } else if ((fsdev_ptr == fsdev_size) && (fsdev_ptr < MAX_FSDEV_SIZE)) {
// We're at the end of fsdev, grow it // We're at the end of fsdev, grow it
fsdev[fsdev_ptr] = val; fsdev[fsdev_ptr] = val;
fsdev_size++; fsdev_size++;
#ifdef DEBUG
fprintf(stderr, "Growing FSDEV (%d)\n", fsdev_ptr);
#endif
} else { } else {
fprintf(stderr, "Out of bounds FSDEV write at %d\n", fsdev_ptr); fprintf(stderr, "Out of bounds FSDEV write at %d\n", fsdev_ptr);
} }

View File

@ -125,8 +125,8 @@ fsdevPutC:
ld a, l ld a, l
out (FS_ADDR_PORT), a out (FS_ADDR_PORT), a
in a, (FS_ADDR_PORT) in a, (FS_ADDR_PORT)
or a cp 2 ; only A > 1 means error
jr nz, .error jr nc, .error ; A >= 2
pop af pop af
out (FS_DATA_PORT), a out (FS_DATA_PORT), a
cp a ; ensure Z cp a ; ensure Z