Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bartman/0x10c-tools
base: 6b348de816
...
head fork: bartman/0x10c-tools
compare: 2a7bfd3ae1
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
53 include/dcpu_lem1802.h
@@ -0,0 +1,53 @@
+#ifndef __included_dcpu_lem1802_h__
+#define __included_dcpu_lem1802_h__
+
+#include <stdio.h>
+
+#include "dcpu_def.h"
+#include "dcpu_hw.h"
+#include "dcpu_fifo.h"
+
+struct dcpu_vcpu;
+
+#define DCPU_LEM1802_VENDOR_ID 0x1c6c8b36 // NYA_ELEKTRISKA
+#define DCPU_LEM1802_DEVICE_ID 0x7349f615
+#define DCPU_LEM1802_VERSION 0x1802
+
+#define DCPU_LEM1802_CMD_MEM_MAP_SCREEN 0 // maps 386 words from B as video RAM
+#define DCPU_LEM1802_CMD_MEM_MAP_FONT 1 // maps 256 words from B as font RAM
+#define DCPU_LEM1802_CMD_MEM_MAP_PALETTE 2 // maps 16 words from B as palette RAM
+#define DCPU_LEM1802_CMD_SET_BORDER_COLOR 3 // sets border to B & 0xF
+#define DCPU_LEM1802_CMD_MEM_DUMP_FONT 4 // copies 386 words of font data to [B]
+#define DCPU_LEM1802_CMD_MEM_DUMP_PALETTE 5 // copies 16 words of palette data to [B]
+
+#define DCPU_LEM1802_SCREEN_COLS 32
+#define DCPU_LEM1802_SCREEN_LINES 12
+#define DCPU_LEM1802_VIDEO_RAM_SIZE \
+ (DCPU_LEM1802_SCREEN_COLS * DCPU_LEM1802_SCREEN_LINES)
+#define DCPU_LEM1802_FONT_RAM_SIZE 256
+#define DCPU_LEM1802_PALETTE_RAM_SIZE 16
+
+struct dcpu_lem1802 {
+ struct dcpu_hw hw;
+
+ dcpu_word video_ram_base;
+ dcpu_word font_ram_base;
+ dcpu_word palette_ram_base;
+ dcpu_word border_color;
+};
+
+static inline struct dcpu_lem1802 * dcpu_hw_to_lem1802(struct dcpu_hw *hw)
+{
+ return container_of(hw, struct dcpu_lem1802, hw);
+}
+
+// create a new lem1802 and return it
+extern struct dcpu_lem1802 * dcpu_lem1802_new(void);
+
+// create a new lem1802 and register it with a vcpu
+// returns the hw_id or negative on error
+extern int dcpu_add_lem1802(struct dcpu_vcpu *vcpu);
+
+
+
+#endif // __included_dcpu_lem1802_h__
View
7 include/dcpu_vcpu.h
@@ -65,6 +65,7 @@ extern struct dcpu_vcpu * dcpu_vcpu_new(void);
#define dcpu_vcpu_cycles(vcpu) ((vcpu)->st.cycles)
#define dcpu_vcpu_gr(vcpu) (&(vcpu)->st.gr)
#define dcpu_vcpu_sr(vcpu) (&(vcpu)->st.sr)
+#define dcpu_vcpu_ram(vcpu) (&(vcpu)->ram)
// accept an interrupt
static inline void dcpu_vcpu_accept_interrupt(struct dcpu_vcpu *vcpu,
@@ -109,5 +110,11 @@ extern int dcpu_vcpu_unregister_hw(struct dcpu_vcpu *vcpu, struct dcpu_hw *hw);
// find a piece of hardware by ID
extern struct dcpu_hw *dcpu_vcpu_find_hw(struct dcpu_vcpu *vcpu, dcpu_word id);
+// copy to/from ram with wraparound
+extern void dcpu_vcpu_copy_to_ram(struct dcpu_vcpu *vcpu,
+ dcpu_word ram_dst, const void *src, dcpu_word len);
+extern void dcpu_vcpu_copy_from_ram(const struct dcpu_vcpu *vcpu,
+ void *dst, dcpu_word ram_src, dcpu_word len);
+
#endif // __included_dcpu_vcpu_h__
View
2  lib/Makefile
@@ -1,6 +1,6 @@
TARGET = libdcpu.a
SRCS = dcpu_isn.c dcpu_parser.c dcpu_generator.c dcpu_exec.c dcpu_vcpu.c \
- dcpu_clock.c dcpu_keyboard.c
+ dcpu_clock.c dcpu_keyboard.c dcpu_lem1802.c
OBJS = ${SRCS:.c=.o}
DEPS = $(SRCS:%=.%.dep)
View
127 lib/dcpu_lem1802.c
@@ -0,0 +1,127 @@
+#include <stdlib.h>
+#include <errno.h>
+
+#include "dcpu_lem1802.h"
+#include "dcpu_vcpu.h"
+
+static dcpu_word dcpu_lem1802_default_font[DCPU_LEM1802_FONT_RAM_SIZE] = {
+ 0 /* TODO: put something here */
+};
+static dcpu_word dcpu_lem1802_default_palette[DCPU_LEM1802_PALETTE_RAM_SIZE] = {
+ 0 /* TODO: put something here */
+};
+
+struct dcpu_hw_ops dcpu_lem1802_ops;
+
+// create a new lem1802 and return it
+struct dcpu_lem1802 * dcpu_lem1802_new(void)
+{
+ struct dcpu_lem1802 *lem;
+
+ lem = calloc(1, sizeof(*lem));
+
+ dcpu_hw_init(&lem->hw);
+
+ lem->hw.hw_version = DCPU_LEM1802_VERSION;
+ lem->hw.hw_vendor_id = DCPU_LEM1802_VENDOR_ID;
+ lem->hw.hw_device_id = DCPU_LEM1802_DEVICE_ID;
+
+ lem->video_ram_base = 0;
+ lem->font_ram_base = 0;
+ lem->palette_ram_base = 0;
+
+ lem->hw.ops = dcpu_lem1802_ops;
+
+ return lem;
+
+}
+
+// create a new lem1802 and register it with a vcpu
+// returns the hw_id or negative on error
+int dcpu_add_lem1802(struct dcpu_vcpu *vcpu)
+{
+ struct dcpu_lem1802 *lem;
+ int rc;
+
+ lem = dcpu_lem1802_new();
+ if (!lem)
+ return -ENOMEM;
+
+ rc = dcpu_vcpu_register_hw(vcpu, &lem->hw);
+ if (rc >= 0)
+ return lem->hw.hw_id;
+
+ dcpu_vcpu_unregister_hw(vcpu, &lem->hw);
+
+ lem->hw.ops.delete(&lem->hw);
+
+ return rc;
+}
+
+static int dcpu_lem1802_poke (struct dcpu_hw *hw)
+{
+ /* should do something like update the display */
+
+ return 0;
+}
+
+static int dcpu_lem1802_handle_interrupt (struct dcpu_hw *hw)
+{
+ struct dcpu_lem1802 *lem = dcpu_hw_to_lem1802(hw);
+ struct dcpu_vcpu *vcpu = lem->hw.vcpu;
+ dcpu_cycles_t b;
+
+ switch (dcpu_vcpu_gr(vcpu)->a) {
+ case DCPU_LEM1802_CMD_MEM_MAP_SCREEN: // maps 386 words from B as video RAM
+ b = dcpu_vcpu_gr(vcpu)->b;
+ lem->video_ram_base = b;
+ break;
+
+ case DCPU_LEM1802_CMD_MEM_MAP_FONT: // maps 256 words from B as font RAM
+ b = dcpu_vcpu_gr(vcpu)->b;
+ lem->font_ram_base = b;
+ break;
+
+ case DCPU_LEM1802_CMD_MEM_MAP_PALETTE: // maps 16 words from B as palette RAM
+ b = dcpu_vcpu_gr(vcpu)->b;
+ lem->palette_ram_base = b;
+ break;
+
+ case DCPU_LEM1802_CMD_SET_BORDER_COLOR: // sets border to B & 0xF
+ b = dcpu_vcpu_gr(vcpu)->b;
+ lem->border_color = b & 0xF;
+ break;
+
+ case DCPU_LEM1802_CMD_MEM_DUMP_FONT: // copies 386 words of font data to [B]
+ b = dcpu_vcpu_gr(vcpu)->b;
+ dcpu_vcpu_copy_to_ram(vcpu, b, dcpu_lem1802_default_font,
+ DCPU_LEM1802_FONT_RAM_SIZE);
+ break;
+
+ case DCPU_LEM1802_CMD_MEM_DUMP_PALETTE: // copies 16 words of palette data to [B]
+ b = dcpu_vcpu_gr(vcpu)->b;
+ dcpu_vcpu_copy_to_ram(vcpu, b, dcpu_lem1802_default_palette,
+ DCPU_LEM1802_PALETTE_RAM_SIZE);
+ break;
+
+ default:
+ // ignore
+ break;
+ }
+
+ return 0;
+}
+
+static void dcpu_lem1802_delete (struct dcpu_hw *hw)
+{
+ struct dcpu_lem1802 *lem = dcpu_hw_to_lem1802(hw);
+
+ free(lem);
+}
+
+struct dcpu_hw_ops dcpu_lem1802_ops = {
+ .poke = dcpu_lem1802_poke,
+ .handle_interrupt = dcpu_lem1802_handle_interrupt,
+ .delete = dcpu_lem1802_delete,
+};
+
View
42 lib/dcpu_vcpu.c
@@ -334,3 +334,45 @@ struct dcpu_hw *dcpu_vcpu_find_hw(struct dcpu_vcpu *vcpu, dcpu_word id)
}
+void dcpu_vcpu_copy_to_ram(struct dcpu_vcpu *vcpu,
+ dcpu_word ram_dst, const void *src, dcpu_word len)
+{
+ uint fits;
+ uint copy;
+
+ fits = (uint)DCPU_RAM_WORDS - ram_dst;
+
+ // copy what fits before the end of ram
+ copy = len < fits ? len : fits;
+
+ memcpy(dcpu_vcpu_ram(vcpu) + ram_dst,
+ src, sizeof(dcpu_word) * copy);
+
+ // if overflow, copy rest to start of ram
+ if (copy < len)
+ memcpy(dcpu_vcpu_ram(vcpu),
+ src + sizeof(dcpu_word) * copy,
+ len - copy);
+}
+
+void dcpu_vcpu_copy_from_ram(const struct dcpu_vcpu *vcpu,
+ void *dst, dcpu_word ram_src, dcpu_word len)
+{
+ uint fits;
+ uint copy;
+
+ fits = (uint)DCPU_RAM_WORDS - ram_src;
+
+ // copy what fits before the end of ram
+ copy = len < fits ? len : fits;
+
+ memcpy(dst, dcpu_vcpu_ram(vcpu) + ram_src,
+ sizeof(dcpu_word) * copy);
+
+ // if overflow, copy rest from start of ram
+ if (copy < len)
+ memcpy(dst + sizeof(dcpu_word) * copy,
+ dcpu_vcpu_ram(vcpu),
+ len - copy);
+}
+
View
1  src/dcpu.c
@@ -34,6 +34,7 @@ int main(int argc, char *argv[])
dcpu_add_clock(vcpu);
dcpu_add_keyboard(vcpu);
+ dcpu_add_lem1802(vcpu);
return vcpu->ops.run(vcpu);
}

No commit comments for this range

Something went wrong with that request. Please try again.