Add ROM linked in read-only data section, at 6502's 0xc000-0xffff

This commit is contained in:
Satoshi N. M 2018-01-13 00:31:12 -08:00
parent 5ed79b17bb
commit fb7f66b717
3 changed files with 24 additions and 2 deletions

View File

@ -15,6 +15,8 @@ SRC = \
cdcacm.c \
main.c \
ROM = ../osi_bas/ROM.HEX
CROSS_COMPILE ?= arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
@ -38,6 +40,7 @@ host_clean:
-$(Q)$(RM) pill_6502.bin
OBJ = $(SRC:.c=.o)
OBJ += $(ROM:.HEX=.o)
pill_6502.elf: version.h $(OBJ)
@echo " LD $@"
@ -47,6 +50,12 @@ pill_6502.elf: version.h $(OBJ)
@echo " CC $<"
$(Q)$(CC) $(CFLAGS) -c $< -o $@
%.o: %.HEX
@echo " OBJCOPY $@.bin"
$(Q)$(OBJCOPY) -I ihex -O binary $^ $@.bin
@echo " OBJCOPY $@"
$(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata,alloc,load,readonly,data,contents $@.bin $@
%.bin: %.elf
@echo " OBJCOPY $@"
$(Q)$(OBJCOPY) -O binary $^ $@

View File

@ -30,6 +30,7 @@
#include <libopencm3/usb/cdc.h>
#include "fake6502.h"
#include "rom.h"
#include "cdcacm.h"
#include "version.h"
@ -137,12 +138,19 @@ uint8_t usbd_control_buffer[128];
// 6502 processor memory, 16KB (< 20KB)
uint8_t ram[0x4000];
// TODO: serial interface, 0xa000-0xbfff
uint8_t read6502(uint16_t address) {
// RAM
if (address < sizeof(ram)) {
return ram[address];
}
// TODO: serial interface, 0xa000-0xbfff
// TODO: ROM, 0xc000-0xffff
// ROM
if (address >= 0xc000) {
const uint8_t *rom = &_binary____osi_bas_ROM_o_bin_start;
return rom[address - 0xc000];
}
return 0xff;
}

5
src/rom.h Normal file
View File

@ -0,0 +1,5 @@
// Symbols exported by rom.o, see https://balau82.wordpress.com/2012/02/19/linking-a-binary-blob-with-gcc/
extern unsigned char _binary____osi_bas_ROM_o_bin_end;
extern unsigned char _binary____osi_bas_ROM_o_bin_size;
extern unsigned char _binary____osi_bas_ROM_o_bin_start;