Parcourir la source

zasm: have a whole kernel in emulation instead of a simple wrapper

zasm is going to need to call to kernel code...
pull/10/head
Virgil Dupras il y a 5 ans
Parent
révision
88cee235b1
5 fichiers modifiés avec 35 ajouts et 29 suppressions
  1. +1
    -1
      apps/zasm/emul/.gitignore
  2. +3
    -3
      apps/zasm/emul/Makefile
  3. +22
    -0
      apps/zasm/emul/glue.asm
  4. +0
    -15
      apps/zasm/emul/wrapper.asm
  5. +9
    -10
      apps/zasm/emul/zasm.c

+ 1
- 1
apps/zasm/emul/.gitignore Voir le fichier

@@ -1,4 +1,4 @@
libz80
wrapper.h
kernel.h
zasm.h
zasm

+ 3
- 3
apps/zasm/emul/Makefile Voir le fichier

@@ -1,11 +1,11 @@
zasm: zasm.c libz80/libz80.so wrapper.h zasm.h
zasm: zasm.c libz80/libz80.so kernel.h zasm.h
cc $< -l z80 -L./libz80 -Wl,-rpath ./libz80 -o $@

libz80/libz80.so: libz80/Makefile
make -C libz80

wrapper.h: wrapper.asm
scas -o - $< | ./bin2c.sh WRAPPER > $@
kernel.h: glue.asm
scas -o - $< | ./bin2c.sh KERNEL > $@

zasm.h: ../zasm.asm
scas -o - $< | ./bin2c.sh ZASM > $@

+ 22
- 0
apps/zasm/emul/glue.asm Voir le fichier

@@ -0,0 +1,22 @@
; Glue code for the emulated environment
RAMSTART .equ 0x8000
RAMEND .equ 0xffff
ZASM_CODE .equ RAMSTART
ZASM_INPUT .equ 0xa000
ZASM_OUTPUT .equ 0xd000

jr init
init:
di
ld hl, RAMEND
ld sp, hl
ld hl, ZASM_INPUT
ld de, ZASM_OUTPUT
call ZASM_CODE
; signal the emulator we're done
; BC contains the number of written bytes
ld a, b
out (c), a
halt

#include "core.asm"

+ 0
- 15
apps/zasm/emul/wrapper.asm Voir le fichier

@@ -1,15 +0,0 @@
; setup the stack
ld hl, 0xffff
ld sp, hl
; zasm input
ld hl, 0x9000
; zasm output
ld de, 0xc000
call zasm
; signal the emulator we're done
; BC contains the number of written bytes
ld a, b
out (c), a
halt
zasm:
; beginning of the code

+ 9
- 10
apps/zasm/emul/zasm.c Voir le fichier

@@ -1,7 +1,7 @@
#include <stdint.h>
#include <stdio.h>
#include "libz80/z80.h"
#include "wrapper.h"
#include "kernel.h"
#include "zasm.h"

/* zasm is a "pure memory" application. It starts up being told memory location
@@ -12,9 +12,10 @@
* spit the contents of the dest memory to stdout.
*/

// in sync with wrapper.asm
#define READFROM 0x9000
#define WRITETO 0xc000
// in sync with glue.asm
#define READFROM 0xa000
#define WRITETO 0xd000
#define ZASM_CODE_OFFSET 0x8000

static Z80Context cpu;
static uint8_t mem[0xffff];
@@ -48,13 +49,11 @@ static void mem_write(int unused, uint16_t addr, uint8_t val)
int main()
{
// initialize memory
int wrapperlen = sizeof(WRAPPER);
for (int i=0; i<wrapperlen; i++) {
mem[i] = WRAPPER[i];
for (int i=0; i<sizeof(KERNEL); i++) {
mem[i] = KERNEL[i];
}
int zasm = sizeof(ZASM);
for (int i=0; i<zasm; i++) {
mem[i+wrapperlen] = ZASM[i];
for (int i=0; i<sizeof(ZASM); i++) {
mem[i+ZASM_CODE_OFFSET] = ZASM[i];
}
int ptr = READFROM;
int c = getchar();


Chargement…
Annuler
Enregistrer