mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-06 08:10:55 +11:00
34ee91a0d7
This will soon allow use to seek and tell on input, which is necessary for a second pass which is necessary for forward symbol references. This require making `blkSel` a bit more flexible. Rather than having one global selected blkdev, each app can select its own, in its own memory space.
87 lines
1.7 KiB
C
87 lines
1.7 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "libz80/z80.h"
|
|
#include "zasm-kernel.h"
|
|
#include "zasm-user.h"
|
|
|
|
/* zasm is a "pure memory" application. It starts up being told memory location
|
|
* to read and memory location to write.
|
|
*
|
|
*
|
|
* Memory layout:
|
|
*
|
|
* 0x0000 - 0x3fff: ROM code from zasm_glue.asm
|
|
* 0x4000 - 0x47ff: RAM for kernel and stack
|
|
* 0x4800 - 0x57ff: Userspace code
|
|
* 0x5800 - 0xffff: Userspace RAM
|
|
*
|
|
* I/O Ports:
|
|
*
|
|
* 0 - stdin / stdout
|
|
*/
|
|
|
|
// in sync with zasm_glue.asm
|
|
#define USER_CODE 0x4800
|
|
#define STDIO_PORT 0x00
|
|
|
|
static Z80Context cpu;
|
|
static uint8_t mem[0xffff];
|
|
|
|
static uint8_t io_read(int unused, uint16_t addr)
|
|
{
|
|
addr &= 0xff;
|
|
if (addr == STDIO_PORT) {
|
|
int c = getchar();
|
|
if (c == EOF) {
|
|
return 0;
|
|
}
|
|
return c;
|
|
} else {
|
|
fprintf(stderr, "Out of bounds I/O read: %d\n", addr);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
static void io_write(int unused, uint16_t addr, uint8_t val)
|
|
{
|
|
addr &= 0xff;
|
|
if (addr == STDIO_PORT) {
|
|
putchar(val);
|
|
} else {
|
|
fprintf(stderr, "Out of bounds I/O write: %d / %d\n", addr, val);
|
|
}
|
|
}
|
|
|
|
static uint8_t mem_read(int unused, uint16_t addr)
|
|
{
|
|
return mem[addr];
|
|
}
|
|
|
|
static void mem_write(int unused, uint16_t addr, uint8_t val)
|
|
{
|
|
mem[addr] = val;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// initialize memory
|
|
for (int i=0; i<sizeof(KERNEL); i++) {
|
|
mem[i] = KERNEL[i];
|
|
}
|
|
for (int i=0; i<sizeof(USERSPACE); i++) {
|
|
mem[i+USER_CODE] = USERSPACE[i];
|
|
}
|
|
Z80RESET(&cpu);
|
|
cpu.ioRead = io_read;
|
|
cpu.ioWrite = io_write;
|
|
cpu.memRead = mem_read;
|
|
cpu.memWrite = mem_write;
|
|
|
|
while (!cpu.halted) {
|
|
Z80Execute(&cpu);
|
|
}
|
|
fflush(stdout);
|
|
return 0;
|
|
}
|
|
|