├── .gitignore ├── Makefile ├── Makefile.lab ├── abstract-machine ├── .gitignore ├── Makefile ├── Makefile.app ├── Makefile.check ├── Makefile.compile ├── Makefile.lib ├── am │ ├── Makefile │ ├── am.h │ ├── amdev.h │ ├── arch │ │ ├── isa │ │ │ ├── x86.mk │ │ │ └── x86_64.mk │ │ ├── native.mk │ │ ├── x86-qemu.mk │ │ └── x86_64-qemu.mk │ ├── include │ │ ├── arch │ │ │ ├── native.h │ │ │ ├── x86-qemu.h │ │ │ └── x86_64-qemu.h │ │ └── x86.h │ └── src │ │ ├── native │ │ ├── cte.c │ │ ├── devices │ │ │ ├── input.c │ │ │ ├── timer.c │ │ │ └── video.c │ │ ├── ioe.c │ │ ├── mpe.c │ │ ├── platform.c │ │ ├── platform.h │ │ ├── trap.S │ │ ├── trm.c │ │ └── vme.c │ │ └── x86 │ │ └── qemu │ │ ├── boot │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── genboot.pl │ │ ├── main.c │ │ └── start.S │ │ ├── cte.c │ │ ├── ioe.c │ │ ├── mpe.c │ │ ├── start32.S │ │ ├── start64.S │ │ ├── trap32.S │ │ ├── trap64.S │ │ ├── trm.c │ │ ├── vme.c │ │ └── x86-qemu.h ├── apps │ ├── coremark │ │ ├── Makefile │ │ ├── include │ │ │ ├── core_portme.h │ │ │ └── coremark.h │ │ └── src │ │ │ ├── core_list_join.c │ │ │ ├── core_main.c │ │ │ ├── core_matrix.c │ │ │ ├── core_portme.c │ │ │ ├── core_state.c │ │ │ └── core_util.c │ ├── dhrystone │ │ ├── Makefile │ │ └── dry.c │ ├── fceux │ │ ├── Makefile │ │ └── src │ │ │ ├── boards │ │ │ ├── 01-222.cpp │ │ │ ├── 09-034a.cpp │ │ │ ├── 103.cpp │ │ │ ├── 106.cpp │ │ │ ├── 108.cpp │ │ │ ├── 112.cpp │ │ │ ├── 116.cpp │ │ │ ├── 117.cpp │ │ │ ├── 120.cpp │ │ │ ├── 121.cpp │ │ │ ├── 12in1.cpp │ │ │ ├── 15.cpp │ │ │ ├── 151.cpp │ │ │ ├── 156.cpp │ │ │ ├── 158B.cpp │ │ │ ├── 164.cpp │ │ │ ├── 168.cpp │ │ │ ├── 170.cpp │ │ │ ├── 175.cpp │ │ │ ├── 176.cpp │ │ │ ├── 177.cpp │ │ │ ├── 178.cpp │ │ │ ├── 18.cpp │ │ │ ├── 183.cpp │ │ │ ├── 185.cpp │ │ │ ├── 186.cpp │ │ │ ├── 187.cpp │ │ │ ├── 189.cpp │ │ │ ├── 190.cpp │ │ │ ├── 193.cpp │ │ │ ├── 199.cpp │ │ │ ├── 206.cpp │ │ │ ├── 208.cpp │ │ │ ├── 222.cpp │ │ │ ├── 225.cpp │ │ │ ├── 228.cpp │ │ │ ├── 230.cpp │ │ │ ├── 232.cpp │ │ │ ├── 234.cpp │ │ │ ├── 235.cpp │ │ │ ├── 244.cpp │ │ │ ├── 246.cpp │ │ │ ├── 252.cpp │ │ │ ├── 253.cpp │ │ │ ├── 28.cpp │ │ │ ├── 32.cpp │ │ │ ├── 33.cpp │ │ │ ├── 34.cpp │ │ │ ├── 36.cpp │ │ │ ├── 3d-block.cpp │ │ │ ├── 40.cpp │ │ │ ├── 41.cpp │ │ │ ├── 411120-c.cpp │ │ │ ├── 42.cpp │ │ │ ├── 43.cpp │ │ │ ├── 46.cpp │ │ │ ├── 50.cpp │ │ │ ├── 51.cpp │ │ │ ├── 57.cpp │ │ │ ├── 603-5052.cpp │ │ │ ├── 62.cpp │ │ │ ├── 65.cpp │ │ │ ├── 67.cpp │ │ │ ├── 68.cpp │ │ │ ├── 69.cpp │ │ │ ├── 71.cpp │ │ │ ├── 72.cpp │ │ │ ├── 77.cpp │ │ │ ├── 79.cpp │ │ │ ├── 80.cpp │ │ │ ├── 80013-B.cpp │ │ │ ├── 8157.cpp │ │ │ ├── 82.cpp │ │ │ ├── 8237.cpp │ │ │ ├── 830118C.cpp │ │ │ ├── 88.cpp │ │ │ ├── 8in1.cpp │ │ │ ├── 90.cpp │ │ │ ├── 91.cpp │ │ │ ├── 96.cpp │ │ │ ├── 99.cpp │ │ │ ├── BMW8544.cpp │ │ │ ├── F-15.cpp │ │ │ ├── __dummy_mapper.cpp │ │ │ ├── a9746.cpp │ │ │ ├── ac-08.cpp │ │ │ ├── addrlatch.cpp │ │ │ ├── ax5705.cpp │ │ │ ├── bandai.cpp │ │ │ ├── bb.cpp │ │ │ ├── bmc13in1jy110.cpp │ │ │ ├── bmc42in1r.cpp │ │ │ ├── bmc64in1nr.cpp │ │ │ ├── bmc70in1.cpp │ │ │ ├── bonza.cpp │ │ │ ├── bs-5.cpp │ │ │ ├── cheapocabra.cpp │ │ │ ├── cityfighter.cpp │ │ │ ├── coolboy.cpp │ │ │ ├── dance2000.cpp │ │ │ ├── datalatch.cpp │ │ │ ├── dream.cpp │ │ │ ├── edu2000.cpp │ │ │ ├── eh8813a.cpp │ │ │ ├── emu2413.c │ │ │ ├── emu2413.h │ │ │ ├── et-100.cpp │ │ │ ├── et-4320.cpp │ │ │ ├── famicombox.cpp │ │ │ ├── ffe.cpp │ │ │ ├── fk23c.cpp │ │ │ ├── ghostbusters63in1.cpp │ │ │ ├── gs-2004.cpp │ │ │ ├── gs-2013.cpp │ │ │ ├── h2288.cpp │ │ │ ├── hp10xx_hp20xx.cpp │ │ │ ├── hp898f.cpp │ │ │ ├── inlnsf.cpp │ │ │ ├── karaoke.cpp │ │ │ ├── kof97.cpp │ │ │ ├── ks7010.cpp │ │ │ ├── ks7012.cpp │ │ │ ├── ks7013.cpp │ │ │ ├── ks7016.cpp │ │ │ ├── ks7017.cpp │ │ │ ├── ks7030.cpp │ │ │ ├── ks7031.cpp │ │ │ ├── ks7032.cpp │ │ │ ├── ks7037.cpp │ │ │ ├── ks7057.cpp │ │ │ ├── le05.cpp │ │ │ ├── lh32.cpp │ │ │ ├── lh53.cpp │ │ │ ├── malee.cpp │ │ │ ├── mapinc.h │ │ │ ├── mihunche.cpp │ │ │ ├── mmc1.cpp │ │ │ ├── mmc2and4.cpp │ │ │ ├── mmc3.cpp │ │ │ ├── mmc3.h │ │ │ ├── mmc5.cpp │ │ │ ├── n106.cpp │ │ │ ├── n625092.cpp │ │ │ ├── novel.cpp │ │ │ ├── onebus.cpp │ │ │ ├── pec-586.cpp │ │ │ ├── rt-01.cpp │ │ │ ├── sa-9602b.cpp │ │ │ ├── sachen.cpp │ │ │ ├── sb-2000.cpp │ │ │ ├── sc-127.cpp │ │ │ ├── sheroes.cpp │ │ │ ├── sl1632.cpp │ │ │ ├── subor.cpp │ │ │ ├── super24.cpp │ │ │ ├── supervision.cpp │ │ │ ├── t-227-1.cpp │ │ │ ├── t-262.cpp │ │ │ ├── tengen.cpp │ │ │ ├── tf-1201.cpp │ │ │ ├── transformer.cpp │ │ │ ├── unrom512.cpp │ │ │ ├── vrc1.cpp │ │ │ ├── vrc2and4.cpp │ │ │ ├── vrc3.cpp │ │ │ ├── vrc5.cpp │ │ │ ├── vrc6.cpp │ │ │ ├── vrc7.cpp │ │ │ ├── vrc7p.cpp │ │ │ └── yoko.cpp │ │ │ ├── cart.cpp │ │ │ ├── cart.h │ │ │ ├── drawing.cpp │ │ │ ├── drawing.h │ │ │ ├── driver.h │ │ │ ├── drivers │ │ │ ├── common │ │ │ │ ├── vidblit.cpp │ │ │ │ └── vidblit.h │ │ │ └── sdl │ │ │ │ ├── dface.h │ │ │ │ ├── icon.xpm │ │ │ │ ├── input.cpp │ │ │ │ ├── input.h │ │ │ │ ├── keyscan.h │ │ │ │ ├── main.h │ │ │ │ ├── sdl-icon.h │ │ │ │ ├── sdl-throttle.cpp │ │ │ │ ├── sdl-video.cpp │ │ │ │ ├── sdl-video.h │ │ │ │ ├── sdl.cpp │ │ │ │ ├── sdl.h │ │ │ │ └── throttle.h │ │ │ ├── emufile.cpp │ │ │ ├── emufile.h │ │ │ ├── fceu.cpp │ │ │ ├── fceu.h │ │ │ ├── file.cpp │ │ │ ├── file.h │ │ │ ├── git.h │ │ │ ├── ines-bad.h │ │ │ ├── ines-correct.h │ │ │ ├── ines.cpp │ │ │ ├── ines.h │ │ │ ├── input.cpp │ │ │ ├── input.h │ │ │ ├── ops.inc │ │ │ ├── palette.cpp │ │ │ ├── palette.h │ │ │ ├── palettes │ │ │ ├── palettes.h │ │ │ ├── rp2c04001.h │ │ │ ├── rp2c04002.h │ │ │ ├── rp2c04003.h │ │ │ └── rp2c05004.h │ │ │ ├── ppu.cpp │ │ │ ├── ppu.h │ │ │ ├── pputile.inc │ │ │ ├── sound.h │ │ │ ├── state.h │ │ │ ├── types.h │ │ │ ├── unif.h │ │ │ ├── unused.cpp │ │ │ ├── utils │ │ │ ├── general.cpp │ │ │ ├── general.h │ │ │ ├── md5.cpp │ │ │ ├── md5.h │ │ │ ├── memory.cpp │ │ │ ├── memory.h │ │ │ └── valuearray.h │ │ │ ├── version.h │ │ │ ├── video.cpp │ │ │ ├── video.h │ │ │ ├── x6502.cpp │ │ │ ├── x6502.h │ │ │ ├── x6502abbrev.h │ │ │ └── x6502struct.h │ ├── litenes │ │ ├── Makefile │ │ ├── include │ │ │ ├── common.h │ │ │ ├── cpu-internal.h │ │ │ ├── cpu.h │ │ │ ├── fce.h │ │ │ ├── memory.h │ │ │ ├── mmc.h │ │ │ ├── ppu.h │ │ │ └── psg.h │ │ └── src │ │ │ ├── common.c │ │ │ ├── cpu-addressing.c │ │ │ ├── cpu.c │ │ │ ├── fce.c │ │ │ ├── memory.c │ │ │ ├── mmc.c │ │ │ ├── ppu.c │ │ │ └── psg.c │ └── microbench │ │ ├── Makefile │ │ ├── include │ │ └── benchmark.h │ │ └── src │ │ ├── 15pz │ │ ├── 15pz.cpp │ │ ├── heap.h │ │ └── puzzle.h │ │ ├── bench.c │ │ ├── bf │ │ └── bf.c │ │ ├── dinic │ │ └── dinic.cpp │ │ ├── fib │ │ └── fib.c │ │ ├── lzip │ │ ├── lzip.c │ │ ├── quicklz.c │ │ └── quicklz.h │ │ ├── md5 │ │ └── md5.c │ │ ├── qsort │ │ └── qsort.c │ │ ├── queen │ │ └── queen.c │ │ ├── sieve │ │ └── sieve.c │ │ └── ssort │ │ └── ssort.cpp ├── libs │ └── klib │ │ ├── Makefile │ │ ├── include │ │ ├── klib-macros.h │ │ └── klib.h │ │ └── src │ │ ├── cpp.c │ │ ├── int64.c │ │ ├── intlib.h │ │ ├── io.c │ │ ├── stdio.c │ │ ├── stdlib.c │ │ └── string.c ├── share │ └── games │ │ └── nes │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── build-roms.py │ │ └── rom │ │ └── mario.nes └── tests │ ├── amtest │ ├── Makefile │ ├── include │ │ └── amtest.h │ └── src │ │ ├── main.c │ │ └── tests │ │ ├── devscan.c │ │ ├── hello.c │ │ ├── intr.c │ │ ├── keyboard.c │ │ ├── mp.c │ │ ├── rtc.c │ │ ├── video.c │ │ └── vm.c │ └── klibtest │ ├── Makefile │ └── src │ ├── full-format-glibc.h │ ├── main.c │ ├── memory_test.c │ └── printf_test.c ├── amgame ├── .gitignore ├── 181220076.pdf ├── Makefile ├── include │ └── game.h └── src │ ├── game.c │ ├── keyboard.c │ └── video.c ├── crepl ├── Makefile └── crepl.c ├── frecov ├── .gitignore ├── Makefile └── frecov.c ├── kernel ├── 181220076.pdf ├── Makefile ├── analy.c ├── data_analize.c ├── framework │ ├── kernel.h │ ├── main.c │ └── user.h ├── include │ ├── common.h │ ├── debug.h │ └── devices.h ├── src │ ├── dev │ │ ├── dev.c │ │ ├── dev_input.c │ │ ├── dev_sd.c │ │ ├── dev_tty.c │ │ └── dev_video.c │ ├── kmt.c │ ├── os.c │ ├── pmm.c │ ├── sem.c │ └── spinlock.c └── tools │ ├── Makefile │ └── mkfs.c ├── libco ├── Makefile ├── co.c ├── co.h └── tests │ ├── Makefile │ ├── co-test.h │ └── main.c ├── libkvdb ├── Makefile ├── kvdb.c ├── kvdb.h ├── test │ └── main.c └── tests │ ├── kvdb-test.h │ └── main.c ├── pstree ├── Makefile └── pstree.c └── sperf ├── Makefile └── sperf.c /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.[oad] 3 | !.gitignore 4 | *~ 5 | a.out 6 | a.out-* 7 | *-32* 8 | *-64* 9 | /kernel/tools/mkfs 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **DO NOT MODIFY** 2 | 3 | ifeq ($(NAME),) 4 | $(error Should make in each lab's directory) 5 | endif 6 | 7 | SRCS := $(shell find . -maxdepth 1 -name "*.c") 8 | DEPS := $(shell find . -maxdepth 1 -name "*.h") $(SRCS) 9 | CFLAGS += -O1 -std=gnu11 -ggdb -Wall -Werror -Wno-unused-result -Wno-unused-value -Wno-unused-variable 10 | 11 | .PHONY: all git test clean commit-and-make 12 | 13 | .DEFAULT_GOAL := commit-and-make 14 | commit-and-make: git all 15 | 16 | $(NAME)-64: $(DEPS) # 64bit binary 17 | gcc -m64 $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) 18 | 19 | $(NAME)-32: $(DEPS) # 32bit binary 20 | gcc -m32 $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) 21 | 22 | $(NAME)-64.so: $(DEPS) # 64bit shared library 23 | gcc -fPIC -shared -m64 $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) 24 | 25 | $(NAME)-32.so: $(DEPS) # 32bit shared library 26 | gcc -fPIC -shared -m32 $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) 27 | 28 | clean: 29 | rm -f $(NAME)-64 $(NAME)-32 $(NAME)-64.so $(NAME)-32.so 30 | 31 | include ../Makefile.lab 32 | -------------------------------------------------------------------------------- /Makefile.lab: -------------------------------------------------------------------------------- 1 | # **DO NOT MODIFY** 2 | 3 | export COURSE := OS2020 4 | URL := 'http://ics.nju.edu.cn/%7ejyywiki' 5 | 6 | submit: clean-all 7 | @cd $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) && \ 8 | curl -sSL '$(URL)/submit.sh' | bash 9 | 10 | git: 11 | @git add $(shell find . -name "*.c") $(shell find . -name "*.h") -A --ignore-errors 12 | @while (test -e .git/index.lock); do sleep 0.1; done 13 | @(hostnamectl && uptime) | git commit -F - -q --author='tracer-nju ' --no-verify --allow-empty 14 | @sync 15 | 16 | .PHONY: clean-all 17 | 18 | clean-all: 19 | @make -C ../abstract-machine clean > /dev/null 20 | @find .. -type d -name build | xargs rm -rf 21 | -------------------------------------------------------------------------------- /abstract-machine/.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | !.gitignore 3 | *~ 4 | *.a 5 | *.o 6 | *.d 7 | __pycache__ 8 | *.pyc 9 | *.ini 10 | *.log 11 | tags 12 | cscope.* 13 | build/ 14 | -------------------------------------------------------------------------------- /abstract-machine/Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.check 2 | 3 | AM_HOME ?= $(shell pwd) 4 | 5 | default: 6 | @$(MAKE) -s -C am 7 | 8 | # clean everything 9 | ALLMAKE = $(dir $(shell find . -mindepth 2 -name "Makefile")) 10 | $(ALLMAKE): 11 | -@$(MAKE) -s -C $@ clean 12 | 13 | clean: $(ALLMAKE) 14 | 15 | .PHONY: default clean $(ALLMAKE) 16 | -------------------------------------------------------------------------------- /abstract-machine/Makefile.app: -------------------------------------------------------------------------------- 1 | APP_DIR ?= $(shell pwd) 2 | INC_DIR += $(APP_DIR)/include/ 3 | DST_DIR ?= $(APP_DIR)/build/$(ARCH)/ 4 | BINARY ?= $(APP_DIR)/build/$(NAME)-$(ARCH) 5 | BINARY_REL = $(shell realpath $(BINARY) --relative-to .) 6 | 7 | ## Paste in "Makefile.check" here 8 | include $(AM_HOME)/Makefile.check 9 | $(info # Building $(NAME) [$(ARCH)] with AM_HOME {$(AM_HOME)}) 10 | 11 | ## Default: Build a runnable image 12 | default: image 13 | 14 | LIBS += klib 15 | INC_DIR += $(addsuffix /include/, $(addprefix $(AM_HOME)/libs/, $(LIBS))) 16 | 17 | ## Paste in "Makefile.compile" here 18 | include $(AM_HOME)/Makefile.compile 19 | 20 | ## Produce a list of files to be linked: app objects, AM, and libraries 21 | LINK_LIBS = $(sort $(LIBS)) 22 | LINK_FILES = \ 23 | $(OBJS) \ 24 | $(AM_HOME)/am/build/am-$(ARCH).a \ 25 | $(addsuffix -$(ARCH).a, $(join \ 26 | $(addsuffix /build/, $(addprefix $(AM_HOME)/libs/, $(LINK_LIBS))), \ 27 | $(LINK_LIBS) \ 28 | )) 29 | 30 | $(OBJS): $(PREBUILD) 31 | image: $(OBJS) am $(LIBS) prompt 32 | prompt: $(OBJS) am $(LIBS) 33 | run: default 34 | 35 | prompt: 36 | @echo \# Creating binary image [$(ARCH)] 37 | 38 | clean: 39 | rm -rf $(APP_DIR)/build/ 40 | 41 | .PHONY: default run image prompt clean 42 | -------------------------------------------------------------------------------- /abstract-machine/Makefile.check: -------------------------------------------------------------------------------- 1 | ## Always build "default" 2 | .DEFAULT_GOAL = default 3 | 4 | ## Ignore checks for make clean 5 | ifneq ($(MAKECMDGOALS),clean) 6 | 7 | ## Check: Environment variable $AM_HOME must exist 8 | ifeq ($(AM_HOME),) 9 | $(error Environment variable AM_HOME must be defined.) 10 | endif 11 | 12 | ## Check: Environment variable $ARCH must be in the supported list 13 | ARCH ?= native 14 | ARCHS := $(basename $(notdir $(shell ls $(AM_HOME)/am/arch/*.mk))) 15 | ifeq ($(filter $(ARCHS), $(ARCH)), ) 16 | $(error Invalid ARCH. Supported: $(ARCHS)) 17 | endif 18 | 19 | ## ARCH=x86-qemu -> ISA=x86; PLATFORM=qemu 20 | ARCH_SPLIT = $(subst -, ,$(ARCH)) 21 | ISA ?= $(word 1,$(ARCH_SPLIT)) 22 | PLATFORM ?= $(word 2,$(ARCH_SPLIT)) 23 | 24 | include $(AM_HOME)/am/arch/$(ARCH).mk 25 | 26 | endif 27 | -------------------------------------------------------------------------------- /abstract-machine/Makefile.compile: -------------------------------------------------------------------------------- 1 | $(shell mkdir -p $(DST_DIR)) 2 | 3 | OBJS = $(addprefix $(DST_DIR)/, $(addsuffix .o, $(basename $(SRCS)))) 4 | AS = $(CROSS_COMPILE)gcc 5 | CC = $(CROSS_COMPILE)gcc 6 | CXX = $(CROSS_COMPILE)g++ 7 | LD = $(CROSS_COMPILE)ld 8 | OBJDUMP = $(CROSS_COMPILE)objdump 9 | OBJCOPY = $(CROSS_COMPILE)objcopy 10 | READELF = $(CROSS_COMPILE)readelf 11 | INCLUDES += $(addprefix -I, $(INC_DIR)) -I$(AM_HOME)/am/ 12 | INCLUDES += -I$(AM_HOME)/am/include 13 | CFLAGS += -O2 -MMD -Wall -Werror -ggdb $(INCLUDES) \ 14 | -D__ISA__=\"$(ISA)\" -D__ISA_$(shell echo $(ISA) | tr a-z A-Z)__ \ 15 | -D__ARCH__=$(ARCH) -D__ARCH_$(shell echo $(ARCH) | tr a-z A-Z | tr - _) \ 16 | -DISA_H=\"$(ISA).h\" \ 17 | -DARCH_H=\"arch/$(ARCH).h\" \ 18 | -fno-asynchronous-unwind-tables -fno-builtin -fno-stack-protector \ 19 | -Wno-main 20 | CXXFLAGS += $(CFLAGS) -ffreestanding -fno-rtti -fno-exceptions 21 | ASFLAGS += -MMD $(INCLUDES) 22 | 23 | ## Compliation rule for .c -> .o (using gcc) 24 | $(DST_DIR)/%.o: %.c 25 | @mkdir -p $(dir $@) && echo + CC $< 26 | @$(CC) -std=gnu11 $(CFLAGS) -c -o $@ $(realpath $<) 27 | 28 | ## Compliation rule for .cpp -> .o (using g++) 29 | $(DST_DIR)/%.o: %.cpp 30 | @mkdir -p $(dir $@) && echo + CXX $< 31 | @$(CXX) -std=c++11 $(CXXFLAGS) -c -o $@ $(realpath $<) 32 | 33 | ## Compliation rule for .S -> .o (using as) 34 | $(DST_DIR)/%.o: %.S 35 | @mkdir -p $(dir $@) && echo + AS $< 36 | @$(AS) $(ASFLAGS) -c -o $@ $(realpath $<) 37 | 38 | ## Paste in dependencies (gcc generated .d) here 39 | -include $(addprefix $(DST_DIR)/, $(addsuffix .d, $(basename $(SRCS)))) 40 | 41 | ## Compilation rules for libraries 42 | am: 43 | @$(MAKE) -s -C $(AM_HOME) 44 | 45 | $(sort $(LIBS)): %: 46 | @$(MAKE) -s -C $(AM_HOME)/libs/$* 47 | 48 | .PHONY: $(LIBS) am 49 | -------------------------------------------------------------------------------- /abstract-machine/Makefile.lib: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/Makefile.check 2 | $(info # Building lib-$(NAME) [$(ARCH)]) 3 | 4 | LIB_DIR ?= $(shell pwd) 5 | INC_DIR += $(LIB_DIR)/include/ 6 | DST_DIR ?= $(LIB_DIR)/build/$(ARCH)/ 7 | ARCHIVE ?= $(LIB_DIR)/build/$(NAME)-$(ARCH).a 8 | 9 | ## Default: Build a linkable archive (.a) 10 | default: $(ARCHIVE) 11 | 12 | INC_DIR += $(addsuffix /include/, $(addprefix $(AM_HOME)/libs/, $(LIBS))) 13 | CFLAGS += -fdata-sections -ffunction-sections -fno-builtin 14 | 15 | ## Paste in "Makefile.compile" here 16 | include $(AM_HOME)/Makefile.compile 17 | 18 | ## Compliation rule for objects -> .a (using ar) 19 | $(ARCHIVE): $(OBJS) 20 | @echo + AR "->" $(shell realpath $@ --relative-to .) 21 | @ar rcs $(ARCHIVE) $(OBJS) 22 | 23 | clean: 24 | rm -rf $(LIB_DIR)/build/ 25 | 26 | .PHONY: default clean 27 | -------------------------------------------------------------------------------- /abstract-machine/am/Makefile: -------------------------------------------------------------------------------- 1 | NAME := am 2 | LIBS := klib 3 | SRCS = $(addprefix src/, $(AM_SRCS)) 4 | 5 | include $(AM_HOME)/Makefile.lib 6 | -------------------------------------------------------------------------------- /abstract-machine/am/arch/isa/x86.mk: -------------------------------------------------------------------------------- 1 | CFLAGS += -m32 -fno-pic -fno-omit-frame-pointer -march=i386 2 | ASFLAGS += -m32 -fno-pic 3 | LDFLAGS += -melf_i386 4 | -------------------------------------------------------------------------------- /abstract-machine/am/arch/isa/x86_64.mk: -------------------------------------------------------------------------------- 1 | CFLAGS += -m64 -fPIC -mno-sse 2 | ASFLAGS += -m64 -fPIC 3 | LDFLAGS += -melf_x86_64 4 | -------------------------------------------------------------------------------- /abstract-machine/am/arch/native.mk: -------------------------------------------------------------------------------- 1 | AM_SRCS := native/trm.c \ 2 | native/ioe.c \ 3 | native/cte.c \ 4 | native/trap.S \ 5 | native/vme.c \ 6 | native/mpe.c \ 7 | native/platform.c \ 8 | native/devices/input.c \ 9 | native/devices/timer.c \ 10 | native/devices/video.c \ 11 | 12 | CFLAGS += -fpie 13 | ASFLAGS += -fpie -pie 14 | 15 | image: 16 | @echo + LD "->" $(BINARY_REL) 17 | @g++ -pie -o $(BINARY) -Wl,--whole-archive $(LINK_FILES) -Wl,-no-whole-archive -lSDL2 -lGL -lrt 18 | 19 | run: 20 | $(BINARY) 21 | -------------------------------------------------------------------------------- /abstract-machine/am/arch/x86-qemu.mk: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/am/arch/isa/x86.mk 2 | 3 | AM_SRCS := x86/qemu/start32.S \ 4 | x86/qemu/trap32.S \ 5 | x86/qemu/trm.c \ 6 | x86/qemu/cte.c \ 7 | x86/qemu/ioe.c \ 8 | x86/qemu/vme.c \ 9 | x86/qemu/mpe.c 10 | 11 | image: 12 | @make -s -C $(AM_HOME)/am/src/x86/qemu/boot 13 | @echo + LD "->" $(BINARY_REL).o 14 | @$(LD) $(LDFLAGS) -Ttext 0x00100000 -o $(BINARY).o $(LINK_FILES) 15 | @echo + CREATE "->" $(BINARY_REL) 16 | @( cat $(AM_HOME)/am/src/x86/qemu/boot/mbr; head -c 1024 /dev/zero; cat $(BINARY).o ) > $(BINARY) 17 | 18 | run: 19 | @( echo -n $(mainargs); ) | dd if=/dev/stdin of=$(BINARY) bs=512 count=2 seek=1 conv=notrunc status=none 20 | @qemu-system-i386 -serial stdio -machine accel=tcg -smp "$(smp)" -drive format=raw,file=$(BINARY) 21 | -------------------------------------------------------------------------------- /abstract-machine/am/arch/x86_64-qemu.mk: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/am/arch/isa/x86_64.mk 2 | 3 | AM_SRCS := x86/qemu/start64.S \ 4 | x86/qemu/trap64.S \ 5 | x86/qemu/trm.c \ 6 | x86/qemu/cte.c \ 7 | x86/qemu/ioe.c \ 8 | x86/qemu/vme.c \ 9 | x86/qemu/mpe.c 10 | 11 | image: 12 | @make -s -C $(AM_HOME)/am/src/x86/qemu/boot 13 | @echo + LD "->" $(BINARY_REL).o 14 | @$(LD) $(LDFLAGS) -N -Ttext-segment=0x00100000 -o $(BINARY).o $(LINK_FILES) 15 | @echo + CREATE "->" $(BINARY_REL) 16 | @( cat $(AM_HOME)/am/src/x86/qemu/boot/mbr; head -c 1024 /dev/zero; cat $(BINARY).o ) > $(BINARY) 17 | 18 | run: 19 | @( echo -n $(mainargs); ) | dd if=/dev/stdin of=$(BINARY) bs=512 count=2 seek=1 conv=notrunc status=none 20 | @qemu-system-x86_64 -serial stdio -machine accel=tcg -smp "$(smp)" -drive format=raw,file=$(BINARY) 21 | -------------------------------------------------------------------------------- /abstract-machine/am/include/arch/native.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_H__ 2 | #define __ARCH_H__ 3 | 4 | #ifndef __USE_GNU 5 | # define __USE_GNU 6 | #endif 7 | 8 | #include 9 | 10 | struct _Context { 11 | uintptr_t ksp; 12 | void *vm_head; 13 | ucontext_t uc; 14 | // skip the red zone of the stack frame, see the amd64 ABI manual for details 15 | uint8_t redzone[128]; 16 | }; 17 | 18 | #define GPR1 uc.uc_mcontext.gregs[REG_RDI] 19 | #define GPR2 uc.uc_mcontext.gregs[REG_RSI] 20 | #define GPR3 uc.uc_mcontext.gregs[REG_RDX] 21 | #define GPR4 uc.uc_mcontext.gregs[REG_RCX] 22 | #define GPRx uc.uc_mcontext.gregs[REG_RAX] 23 | 24 | #undef __USE_GNU 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /abstract-machine/am/include/arch/x86-qemu.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_H__ 2 | #define __ARCH_H__ 3 | 4 | struct _Context { 5 | void *uvm; 6 | uint32_t ds, eax, ebx, ecx, edx, 7 | esp0, esi, edi, ebp, 8 | eip, cs, eflags, esp, ss3; 9 | }; 10 | 11 | #define GPR1 eax 12 | #define GPR2 ebx 13 | #define GPR3 ecx 14 | #define GPR4 edx 15 | #define GPRx eax 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /abstract-machine/am/include/arch/x86_64-qemu.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_H__ 2 | #define __ARCH_H__ 3 | 4 | struct _Context { 5 | void *uvm; 6 | uint64_t rax, rbx, rcx, rdx, 7 | rbp, rsi, rdi, 8 | r8, r9, r10, r11, 9 | r12, r13, r14, r15, 10 | rip, cs, rflags, 11 | rsp, ss, rsp0; 12 | }; 13 | 14 | 15 | #define GPR1 rdi 16 | #define GPR2 rsi 17 | #define GPR3 rdx 18 | #define GPR4 rcx 19 | #define GPRx rax 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/devices/input.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../platform.h" 4 | 5 | #define KEYDOWN_MASK 0x8000 6 | 7 | #define KEY_QUEUE_LEN 1024 8 | static int key_queue[KEY_QUEUE_LEN] = {}; 9 | static int key_f = 0, key_r = 0; 10 | static SDL_mutex *key_queue_lock = NULL; 11 | 12 | #define XX(k) [SDL_SCANCODE_##k] = _KEY_##k, 13 | static int keymap[256] = { 14 | _KEYS(XX) 15 | }; 16 | 17 | static int event_thread(void *args) { 18 | SDL_Event event; 19 | while (1) { 20 | SDL_WaitEvent(&event); 21 | switch (event.type) { 22 | case SDL_QUIT: _halt(0); 23 | case SDL_KEYDOWN: 24 | case SDL_KEYUP: 25 | { 26 | SDL_Keysym k = event.key.keysym; 27 | int keydown = event.key.type == SDL_KEYDOWN; 28 | int scancode = k.scancode; 29 | if (keymap[scancode] != 0) { 30 | int am_code = keymap[scancode] | (keydown ? KEYDOWN_MASK : 0); 31 | SDL_LockMutex(key_queue_lock); 32 | key_queue[key_r] = am_code; 33 | key_r = (key_r + 1) % KEY_QUEUE_LEN; 34 | SDL_UnlockMutex(key_queue_lock); 35 | kill(getpid(), SIGUSR1); 36 | } 37 | } 38 | break; 39 | } 40 | } 41 | } 42 | 43 | void __am_input_init() { 44 | key_queue_lock = SDL_CreateMutex(); 45 | SDL_CreateThread(event_thread, "event thread", NULL); 46 | } 47 | 48 | size_t __am_input_read(uintptr_t reg, void *buf, size_t size) { 49 | switch (reg) { 50 | case _DEVREG_INPUT_KBD: { 51 | _DEV_INPUT_KBD_t *kbd = (_DEV_INPUT_KBD_t *)buf; 52 | int k = _KEY_NONE; 53 | 54 | SDL_LockMutex(key_queue_lock); 55 | if (key_f != key_r) { 56 | k = key_queue[key_f]; 57 | key_f = (key_f + 1) % KEY_QUEUE_LEN; 58 | } 59 | SDL_UnlockMutex(key_queue_lock); 60 | 61 | kbd->keydown = (k & KEYDOWN_MASK ? 1 : 0); 62 | kbd->keycode = k & ~KEYDOWN_MASK; 63 | 64 | return sizeof(_DEV_INPUT_KBD_t); 65 | } 66 | } 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/devices/timer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static struct timeval boot_time = {}; 8 | 9 | size_t __am_timer_read(uintptr_t reg, void *buf, size_t size) { 10 | switch (reg) { 11 | case _DEVREG_TIMER_UPTIME: { 12 | struct timeval now; 13 | gettimeofday(&now, NULL); 14 | long seconds = now.tv_sec - boot_time.tv_sec; 15 | long useconds = now.tv_usec - boot_time.tv_usec; 16 | _DEV_TIMER_UPTIME_t *uptime = (_DEV_TIMER_UPTIME_t *)buf; 17 | uptime->hi = 0; 18 | uptime->lo = seconds * 1000 + (useconds + 500) / 1000; 19 | return sizeof(_DEV_TIMER_UPTIME_t); 20 | } 21 | case _DEVREG_TIMER_DATE: { 22 | time_t t = time(NULL); 23 | struct tm *tm = localtime(&t); 24 | _DEV_TIMER_DATE_t *rtc = (_DEV_TIMER_DATE_t *)buf; 25 | rtc->second = tm->tm_sec; 26 | rtc->minute = tm->tm_min; 27 | rtc->hour = tm->tm_hour; 28 | rtc->day = tm->tm_mday; 29 | rtc->month = tm->tm_mon + 1; 30 | rtc->year = tm->tm_year + 1900; 31 | return sizeof(_DEV_TIMER_DATE_t); 32 | } 33 | } 34 | return 0; 35 | } 36 | 37 | void __am_timer_init() { 38 | gettimeofday(&boot_time, NULL); 39 | } 40 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/devices/video.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define W 400 6 | #define H 300 7 | #define FPS 60 8 | 9 | static SDL_Window *window = NULL; 10 | static SDL_Renderer *renderer = NULL; 11 | 12 | static SDL_Texture *texture = NULL; 13 | static uint32_t fb[W * H] = {}; 14 | 15 | static inline int min(int x, int y) { 16 | return (x < y) ? x : y; 17 | } 18 | 19 | static Uint32 texture_sync(Uint32 interval, void *param) { 20 | SDL_UpdateTexture(texture, NULL, fb, W * sizeof(Uint32)); 21 | SDL_RenderClear(renderer); 22 | SDL_RenderCopy(renderer, texture, NULL, NULL); 23 | SDL_RenderPresent(renderer); 24 | return interval; 25 | } 26 | 27 | void __am_video_init() { 28 | SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); 29 | SDL_CreateWindowAndRenderer(W * 2, H * 2, 0, &window, &renderer); 30 | SDL_SetWindowTitle(window, "Native Application"); 31 | texture = SDL_CreateTexture(renderer, 32 | SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, W, H); 33 | memset(fb, 0, W * H * sizeof(uint32_t)); 34 | SDL_AddTimer(1000 / FPS, texture_sync, NULL); 35 | } 36 | 37 | size_t __am_video_read(uintptr_t reg, void *buf, size_t size) { 38 | switch (reg) { 39 | case _DEVREG_VIDEO_INFO: { 40 | _DEV_VIDEO_INFO_t *info = (_DEV_VIDEO_INFO_t *)buf; 41 | info->width = W; 42 | info->height = H; 43 | return sizeof(_DEV_VIDEO_INFO_t); 44 | } 45 | } 46 | return 0; 47 | } 48 | 49 | size_t __am_video_write(uintptr_t reg, void *buf, size_t size) { 50 | switch (reg) { 51 | case _DEVREG_VIDEO_FBCTRL: { 52 | _DEV_VIDEO_FBCTRL_t *ctl = (_DEV_VIDEO_FBCTRL_t *)buf; 53 | int x = ctl->x, y = ctl->y, w = ctl->w, h = ctl->h; 54 | uint32_t *pixels = ctl->pixels; 55 | int cp_bytes = sizeof(uint32_t) * min(w, W - x); 56 | for (int j = 0; j < h && y + j < H; j ++) { 57 | memcpy(&fb[(y + j) * W + x], pixels, cp_bytes); 58 | pixels += w; 59 | } 60 | if (ctl->sync) { 61 | // do nothing, texture_sync() is called by SDL_timer 62 | } 63 | return size; 64 | } 65 | } 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/ioe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void __am_timer_init(); 5 | void __am_video_init(); 6 | void __am_input_init(); 7 | 8 | size_t __am_input_read(uintptr_t reg, void *buf, size_t size); 9 | size_t __am_timer_read(uintptr_t reg, void *buf, size_t size); 10 | size_t __am_video_read(uintptr_t reg, void *buf, size_t size); 11 | size_t __am_video_write(uintptr_t reg, void *buf, size_t size); 12 | 13 | static int init_flag = 0; 14 | 15 | int _ioe_init() { 16 | if (_cpu() != 0) return 0; 17 | init_flag ++; 18 | if (init_flag == 1) { 19 | // Calling fork() in MPE after SDL_Init() will cause trouble. 20 | // Postpone the ioe initialization to fix this issue. 21 | return 0; 22 | } 23 | 24 | __am_timer_init(); 25 | __am_video_init(); 26 | __am_input_init(); 27 | return 0; 28 | } 29 | 30 | size_t _io_read(uint32_t dev, uintptr_t reg, void *buf, size_t size) { 31 | if (init_flag == 1) { _ioe_init(); } 32 | switch (dev) { 33 | case _DEV_INPUT: return __am_input_read(reg, buf, size); 34 | case _DEV_TIMER: return __am_timer_read(reg, buf, size); 35 | case _DEV_VIDEO: return __am_video_read(reg, buf, size); 36 | } 37 | return 0; 38 | } 39 | 40 | size_t _io_write(uint32_t dev, uintptr_t reg, void *buf, size_t size) { 41 | if (init_flag == 1) { _ioe_init(); } 42 | switch (dev) { 43 | case _DEV_VIDEO: return __am_video_write(reg, buf, size); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/mpe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "platform.h" 3 | 4 | int __am_mpe_init = 0; 5 | 6 | int _mpe_init(void (*entry)()) { 7 | __am_mpe_init = 1; 8 | for (int i = 1; i < _ncpu(); i++) { 9 | if (fork() == 0) { 10 | thiscpu->cpuid = i; 11 | __am_init_timer_irq(); 12 | entry(); 13 | } 14 | } 15 | 16 | entry(); 17 | printf("MP entry should not return\n"); 18 | assert(0); 19 | return 0; 20 | } 21 | 22 | int _ncpu() { 23 | extern int __am_ncpu; 24 | return __am_ncpu; 25 | } 26 | 27 | int _cpu() { 28 | return thiscpu->cpuid; 29 | } 30 | 31 | intptr_t _atomic_xchg(volatile intptr_t *addr, intptr_t newval) { 32 | return atomic_exchange((atomic_intptr_t *)addr, newval); 33 | } 34 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLATFORM_H__ 2 | #define __PLATFORM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void __am_get_example_uc(_Context *r); 11 | void __am_get_intr_sigmask(sigset_t *s); 12 | int __am_is_sigmask_sti(sigset_t *s); 13 | void __am_init_timer_irq(); 14 | void __am_shm_mmap(void *va, void *pa, int prot); 15 | void __am_shm_munmap(void *va); 16 | 17 | // per-cpu structure 18 | typedef struct { 19 | void *vm_head; 20 | uintptr_t ksp; 21 | int cpuid; 22 | _Event ev; // similar to cause register in mips/riscv 23 | uint8_t sigstack[SIGSTKSZ]; 24 | } __am_cpu_t; 25 | extern __am_cpu_t *__am_cpu_struct; 26 | #define thiscpu __am_cpu_struct 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/trap.S: -------------------------------------------------------------------------------- 1 | .global __am_kcontext_start 2 | __am_kcontext_start: 3 | // rdi = arg, rsi = entry 4 | 5 | // (rsp + 8) should be multiple of 16 when 6 | // control is transfered to the function entry point. 7 | // See amd64 ABI manual for more details 8 | andq $0xfffffffffffffff0, %rsp 9 | call *%rsi 10 | call __am_panic_on_return 11 | -------------------------------------------------------------------------------- /abstract-machine/am/src/native/trm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void __am_platform_dummy(); 5 | void __am_exit_platform(int code); 6 | 7 | void _trm_init() { 8 | __am_platform_dummy(); 9 | } 10 | 11 | void _putc(char ch) { 12 | fputc(ch, stderr); 13 | } 14 | 15 | void _halt(int code) { 16 | printf("Exit (%d)\n", code); 17 | __am_exit_platform(code); 18 | printf("Should not reach here!\n"); 19 | while (1); 20 | } 21 | 22 | _Area _heap = {}; 23 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/boot/.gitignore: -------------------------------------------------------------------------------- 1 | /mbr 2 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/boot/Makefile: -------------------------------------------------------------------------------- 1 | $(info # Building bootblock [$(ARCH)]) 2 | 3 | mbr: start.S main.c 4 | @echo + CC start.S main.c 5 | @gcc -nostdlib -I$(AM_HOME)/am/include -Os start.S main.c -m32 -Ttext 0x7C00 -o bootblock.o 6 | @objcopy -S -O binary -j .text bootblock.o mbr 7 | @perl genboot.pl mbr 8 | 9 | clean: 10 | rm mbr -rf bootblock *.o 11 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/boot/genboot.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | open(SIG, $ARGV[0]) || die "open $ARGV[0]: $!"; 4 | 5 | $n = sysread(SIG, $buf, 1000); 6 | 7 | if($n > 510){ 8 | print STDERR "ERROR: boot block too large: $n bytes (max 510)\n"; 9 | exit 1; 10 | } 11 | 12 | $buf .= "\0" x (510-$n); 13 | $buf .= "\x55\xAA"; 14 | 15 | open(SIG, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; 16 | print SIG $buf; 17 | close SIG; 18 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/boot/start.S: -------------------------------------------------------------------------------- 1 | #define CR0_PE 0x00000001 2 | 3 | #define GDT_ENTRY(n) \ 4 | ((n) << 3) 5 | 6 | #define SEG_NULLASM \ 7 | .word 0, 0; \ 8 | .byte 0, 0, 0, 0 9 | 10 | #define SEG_ASM(type, base, lim) \ 11 | .word (((lim) >> 12) & 0xffff), ((base) & 0xffff); \ 12 | .byte (((base) >> 16) & 0xff), (0x90 | (type)), \ 13 | (0xC0 | (((lim) >> 28) & 0xf)), (((base) >> 24) & 0xff) 14 | 15 | .code16 16 | .globl _start 17 | _start: 18 | cli 19 | 20 | xorw %ax, %ax 21 | movw %ax, %ds 22 | movw %ax, %es 23 | movw %ax, %ss 24 | 25 | # Set a 640 x 480 x 32 video mode 26 | mov $0x4f01, %ax 27 | mov $0x0112, %cx 28 | mov $0x4000, %di 29 | int $0x10 30 | 31 | mov $0x4f02, %ax 32 | mov $0x4112, %bx 33 | int $0x10 34 | 35 | lgdt gdtdesc 36 | movl %cr0, %eax 37 | orl $CR0_PE, %eax 38 | movl %eax, %cr0 39 | ljmp $GDT_ENTRY(1), $start32 40 | 41 | .code32 42 | start32: 43 | movw $GDT_ENTRY(2), %ax 44 | movw %ax, %ds 45 | movw %ax, %es 46 | movw %ax, %ss 47 | 48 | movl $0xa000, %esp 49 | call load_kernel 50 | 51 | # GDT 52 | .p2align 2 53 | gdt: 54 | SEG_NULLASM 55 | SEG_ASM(0xA, 0x0, 0xffffffff) 56 | SEG_ASM(0x2, 0x0, 0xffffffff) 57 | 58 | gdtdesc: 59 | .word (gdtdesc - gdt - 1) 60 | .long gdt 61 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/mpe.c: -------------------------------------------------------------------------------- 1 | #include "x86-qemu.h" 2 | 3 | struct cpu_local __am_cpuinfo[MAX_CPU] = {}; 4 | static void (* volatile user_entry)(); 5 | static volatile intptr_t ap_ready = 0; 6 | 7 | static void call_user_entry() { 8 | user_entry(); 9 | panic("MPE entry should not return"); 10 | } 11 | 12 | int _mpe_init(void (*entry)()) { 13 | user_entry = entry; 14 | boot_record()->jmp_code = 0x000bfde9; // (16-bit) jmp (0x7c00) 15 | for (int cpu = 1; cpu < __am_ncpu; cpu++) { 16 | boot_record()->is_ap = 1; 17 | __am_lapic_bootap(cpu, (void *)boot_record()); 18 | while (_atomic_xchg(&ap_ready, 0) != 1) { 19 | pause(); 20 | } 21 | } 22 | call_user_entry(); 23 | return 0; 24 | } 25 | 26 | static void othercpu_entry() { 27 | __am_percpu_init(); 28 | _atomic_xchg(&ap_ready, 1); 29 | call_user_entry(); 30 | } 31 | 32 | void __am_othercpu_entry() { 33 | stack_switch_call(stack_top(&CPU->stack), othercpu_entry, 0); 34 | } 35 | 36 | int _ncpu() { 37 | return __am_ncpu; 38 | } 39 | 40 | int _cpu(void) { 41 | return __am_lapic[8] >> 24; 42 | } 43 | 44 | intptr_t _atomic_xchg(volatile intptr_t *addr, intptr_t newval) { 45 | return xchg(addr, newval); 46 | } 47 | 48 | void __am_stop_the_world() { 49 | boot_record()->jmp_code = 0x0000feeb; // (16-bit) jmp . 50 | for (int cpu = 0; cpu < __am_ncpu; cpu++) { 51 | if (cpu != _cpu()) { 52 | __am_lapic_bootap(cpu, (void *)boot_record()); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/start32.S: -------------------------------------------------------------------------------- 1 | #include "x86-qemu.h" 2 | 3 | .globl _start 4 | _start: 5 | pushl $MAINARG_ADDR 6 | pushl $0 7 | jmp _start_c 8 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/start64.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include "x86-qemu.h" 3 | 4 | .code32 5 | .globl _start 6 | _start: 7 | movl $(PDPT_ADDR | PTE_P | PTE_W), %eax 8 | cmpl (PML4_ADDR), %eax 9 | je .long_mode_init 10 | 11 | movl $(PDPT_ADDR | PTE_P | PTE_W), %eax 12 | movl %eax, (PML4_ADDR) 13 | 14 | movl $0, %ecx 15 | movl $512, %esi // 512 pages 16 | // | 17 | .loop: // x 18 | movl %ecx, %eax // | 19 | shll $30, %eax // | 20 | orl $(PTE_P | PTE_W | PTE_PS), %eax // 1 GiB page 21 | movl %eax, PDPT_ADDR(, %ecx, 8) 22 | 23 | movl %ecx, %eax 24 | shrl $2, %eax 25 | movl %eax, PDPT_ADDR + 4(, %ecx, 8) 26 | 27 | inc %ecx 28 | cmp %esi, %ecx 29 | jne .loop 30 | 31 | .long_mode_init: 32 | movl $PML4_ADDR, %eax 33 | movl %eax, %cr3 // %cr3 = PML4 base 34 | movl $CR4_PAE, %eax 35 | movl %eax, %cr4 // %cr4.PAE = 1 36 | movl $0xc0000080, %ecx 37 | rdmsr 38 | orl $0x100, %eax 39 | wrmsr // %EFER.LME = 1 40 | movl %cr0, %eax 41 | orl $CR0_PG, %eax 42 | movl %eax, %cr0 // %cr0.PG = 1 43 | lgdt gdt_ptr // bootstrap GDT 44 | ljmp $8, $_start64 // should not return 45 | 46 | .code64 47 | _start64: 48 | movw $0, %ax 49 | movw %ax, %ds 50 | movw %ax, %es 51 | movw %ax, %ss 52 | movw %ax, %fs 53 | movw %ax, %gs 54 | 55 | movq $MAINARG_ADDR, %rdi 56 | pushq $0 57 | jmp _start_c 58 | 59 | .align 16 60 | gdt_ptr: 61 | .word gdt64_end - gdt64_begin - 1 62 | .quad gdt64_begin 63 | 64 | gdt64_begin: 65 | .long 0x00000000 // 0: null desc 66 | .long 0x00000000 67 | .long 0x00000000 // 1: code 68 | .long 0x00209800 69 | gdt64_end: 70 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/trap32.S: -------------------------------------------------------------------------------- 1 | #include "x86-qemu.h" 2 | 3 | .globl __am_kcontext_start 4 | __am_kcontext_start: 5 | // eax = arg, ebx = entry 6 | pushl %eax 7 | pushl $__am_panic_on_return 8 | jmpl *%ebx 9 | 10 | trap: 11 | cli 12 | 13 | subl $20, %esp 14 | pushl %ebp 15 | pushl %edi 16 | pushl %esi 17 | pushl $0 18 | pushl %edx 19 | pushl %ecx 20 | pushl %ebx 21 | pushl %eax 22 | movw %ds, %ax 23 | pushl %eax 24 | pushl $0 25 | 26 | movw $KSEL(SEG_KDATA), %ax 27 | movw %ax, %ds 28 | movw %ax, %es 29 | movw %ax, %ss 30 | 31 | pushl %esp 32 | call __am_irq_handle 33 | 34 | .globl __am_iret 35 | __am_iret: 36 | addl $4, %esp 37 | popl %eax 38 | movl %eax, %esp 39 | 40 | addl $4, %esp 41 | popl %eax 42 | movw %ax, %ds 43 | movw %ax, %es 44 | 45 | cmpw $KSEL(SEG_KCODE), 36(%esp) 46 | je .kernel_iret 47 | 48 | .user_iret: 49 | popl %eax 50 | popl %ebx 51 | popl %ecx 52 | popl %edx 53 | addl $4, %esp 54 | popl %esi 55 | popl %edi 56 | popl %ebp 57 | iret 58 | 59 | .kernel_iret: 60 | popl %eax 61 | popl %ebx 62 | popl %ecx 63 | popl %edx 64 | addl $4, %esp 65 | 66 | /* stack frame: 67 | 28 ss 68 | 24 esp (not popped by iret when returning to ring0) 69 | 20 eflags ---> move to new-esp 70 | 16 cs 71 | 12 eip 72 | 8 ebp 73 | 4 edi 74 | 0 esi <--- %esp 75 | */ 76 | 77 | movl %esp, %ebp 78 | movl 24(%ebp), %edi // %edi is new-esp 79 | 80 | movl 20(%ebp), %esi; movl %esi, -4(%edi) 81 | movl 16(%ebp), %esi; movl %esi, -8(%edi) 82 | movl 12(%ebp), %esi; movl %esi, -12(%edi) 83 | movl 8(%ebp), %esi; movl %esi, -16(%edi) 84 | movl 4(%ebp), %esi; movl %esi, -20(%edi) 85 | movl 0(%ebp), %esi; movl %esi, -24(%edi) 86 | 87 | leal -24(%edi), %esp 88 | 89 | popl %esi 90 | popl %edi 91 | popl %ebp 92 | iret 93 | 94 | #define NOERR push $0 95 | #define ERR 96 | #define IRQ_DEF(id, dpl, err) \ 97 | .globl __am_irq##id; __am_irq##id: cli; err; push $id; jmp trap; 98 | IRQS(IRQ_DEF) 99 | .globl __am_irqall; __am_irqall: cli; push $0; push $-1; jmp trap; 100 | -------------------------------------------------------------------------------- /abstract-machine/am/src/x86/qemu/trap64.S: -------------------------------------------------------------------------------- 1 | #include "x86-qemu.h" 2 | 3 | .globl __am_kcontext_start 4 | __am_kcontext_start: 5 | // rdi = arg, rsi = entry 6 | pushq $__am_panic_on_return 7 | jmpq *%rsi 8 | 9 | trap: 10 | cli 11 | subq $48, %rsp 12 | pushq %r15 13 | pushq %r14 14 | pushq %r13 15 | pushq %r12 16 | pushq %r11 17 | pushq %r10 18 | pushq %r9 19 | pushq %r8 20 | pushq %rdi 21 | pushq %rsi 22 | pushq %rbp 23 | pushq %rdx 24 | pushq %rcx 25 | pushq %rbx 26 | pushq %rax 27 | pushq $0 // uvm, saved in __am_irq_handle 28 | 29 | movq %rsp, %rdi 30 | call __am_irq_handle 31 | 32 | .globl __am_iret 33 | __am_iret: 34 | movq %rdi, %rsp 35 | movq 160(%rsp), %rax 36 | movw %ax, %ds 37 | movw %ax, %es 38 | addq $8, %rsp 39 | popq %rax 40 | popq %rbx 41 | popq %rcx 42 | popq %rdx 43 | popq %rbp 44 | popq %rsi 45 | popq %rdi 46 | popq %r8 47 | popq %r9 48 | popq %r10 49 | popq %r11 50 | popq %r12 51 | popq %r13 52 | popq %r14 53 | popq %r15 54 | iretq 55 | 56 | #define NOERR push $0 57 | #define ERR 58 | #define IRQ_DEF(id, dpl, err) \ 59 | .globl __am_irq##id; __am_irq##id: cli; err; push $id; jmp trap; 60 | IRQS(IRQ_DEF) 61 | .globl __am_irqall; __am_irqall: cli; push $0; push $-1; jmp trap; 62 | -------------------------------------------------------------------------------- /abstract-machine/apps/coremark/Makefile: -------------------------------------------------------------------------------- 1 | NAME = coremark 2 | SRCS = $(shell find -L ./src/ -name "*.c") 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /abstract-machine/apps/dhrystone/Makefile: -------------------------------------------------------------------------------- 1 | NAME = dhrystone 2 | SRCS = dry.c 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/Makefile: -------------------------------------------------------------------------------- 1 | NAME := fceux 2 | 3 | ROM_PATH := $(AM_HOME)/share/games/nes 4 | ROMS := $(shell ls $(ROM_PATH)/rom/) 5 | ROM_SRC := $(addprefix $(ROM_PATH)/gen/, $(addsuffix .c, $(basename $(ROMS)))) 6 | FCEUX_SRC := $(shell find -L ./src/ -name "*.c" -o -name "*.cpp") 7 | 8 | INCLUDES += -I$(ROM_PATH)/gen/ 9 | SRCS := $(FCEUX_SRC) $(ROM_SRC) 10 | CFLAGS += -DPSS_STYLE=1 -DFRAMESKIP -D__NO_FILE_SYSTEM__ 11 | 12 | include $(AM_HOME)/Makefile.app 13 | 14 | $(FCEUX_SRC): $(ROM_SRC) 15 | $(ROM_SRC): rom 16 | .PHONY: rom 17 | rom: 18 | @make -C $(ROM_PATH) 19 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/108.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®, 1, "REG" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg8(0x6000, reg); 33 | setprg32(0x8000, ~0); 34 | setchr8(0); 35 | } 36 | 37 | static DECLFW(M108Write) { 38 | reg = V; 39 | Sync(); 40 | } 41 | 42 | static void M108Power(void) { 43 | Sync(); 44 | SetReadHandler(0x6000, 0x7FFF, CartBR); 45 | SetReadHandler(0x8000, 0xFFFF, CartBR); 46 | SetWriteHandler(0x8000, 0x8FFF, M108Write); // regular 108 47 | SetWriteHandler(0xF000, 0xFFFF, M108Write); // simplified Kaiser BB Hack 48 | } 49 | 50 | static void StateRestore(int version) { 51 | Sync(); 52 | } 53 | 54 | void Mapper108_Init(CartInfo *info) { 55 | info->Power = M108Power; 56 | GameStateRestore = StateRestore; 57 | AddExState(&StateRegs, ~0, 0, 0); 58 | } 59 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/120.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®, 1, "REG" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg8(0x6000, reg); 33 | setprg32(0x8000, 2); 34 | setchr8(0); 35 | } 36 | 37 | static DECLFW(M120Write) { 38 | if (A == 0x41FF) { 39 | reg = V & 7; 40 | Sync(); 41 | } 42 | } 43 | 44 | static void M120Power(void) { 45 | reg = 0; 46 | Sync(); 47 | SetReadHandler(0x6000, 0xFFFF, CartBR); 48 | SetWriteHandler(0x4100, 0x5FFF, M120Write); 49 | } 50 | 51 | static void StateRestore(int version) { 52 | Sync(); 53 | } 54 | 55 | void Mapper120_Init(CartInfo *info) { 56 | info->Power = M120Power; 57 | GameStateRestore = StateRestore; 58 | AddExState(&StateRegs, ~0, 0, 0); 59 | } 60 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/151.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 regs[8]; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { regs, 8, "REGS" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg8(0x8000, regs[0]); 33 | setprg8(0xA000, regs[2]); 34 | setprg8(0xC000, regs[4]); 35 | setprg8(0xE000, ~0); 36 | setchr4(0x0000, regs[6]); 37 | setchr4(0x1000, regs[7]); 38 | } 39 | 40 | static DECLFW(M151Write) { 41 | regs[(A >> 12) & 7] = V; 42 | Sync(); 43 | } 44 | 45 | static void M151Power(void) { 46 | Sync(); 47 | SetReadHandler(0x8000, 0xFFFF, CartBR); 48 | SetWriteHandler(0x8000, 0xFFFF, M151Write); 49 | } 50 | 51 | static void StateRestore(int version) { 52 | Sync(); 53 | } 54 | 55 | void Mapper151_Init(CartInfo *info) { 56 | info->Power = M151Power; 57 | GameStateRestore = StateRestore; 58 | AddExState(&StateRegs, ~0, 0, 0); 59 | } 60 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/158B.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2015 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * "Blood Of Jurassic" protected MMC3 based board (GD-98 Cart ID, 158B PCB ID) 21 | * 22 | */ 23 | 24 | #include "mapinc.h" 25 | #include "mmc3.h" 26 | 27 | static uint8 lut[8] = { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0F, 0x00 }; 28 | 29 | static void UNL158BPW(uint32 A, uint8 V) { 30 | if (EXPREGS[0] & 0x80) { 31 | uint32 bank = EXPREGS[0] & 7; 32 | if(EXPREGS[0] & 0x20) { // 32Kb mode 33 | setprg32(0x8000, bank >> 1); 34 | } else { // 16Kb mode 35 | setprg16(0x8000, bank); 36 | setprg16(0xC000, bank); 37 | } 38 | } else { 39 | setprg8(A, V & 0xF); 40 | } 41 | } 42 | 43 | static DECLFW(UNL158BProtWrite) { 44 | EXPREGS[A & 7] = V; 45 | switch(A & 7) { 46 | case 0: 47 | FixMMC3PRG(MMC3_cmd); 48 | break; 49 | case 7: 50 | FCEU_printf("UNK PROT WRITE\n"); 51 | break; 52 | } 53 | 54 | } 55 | 56 | static DECLFR(UNL158BProtRead) { 57 | return X.DB | lut[A & 7]; 58 | } 59 | 60 | static void UNL158BPower(void) { 61 | GenMMC3Power(); 62 | SetWriteHandler(0x5000, 0x5FFF, UNL158BProtWrite); 63 | SetReadHandler(0x5000, 0x5FFF, UNL158BProtRead); 64 | } 65 | 66 | void UNL158B_Init(CartInfo *info) { 67 | GenMMC3_Init(info, 128, 128, 0, 0); 68 | pwrap = UNL158BPW; 69 | info->Power = UNL158BPower; 70 | AddExState(EXPREGS, 8, 0, "EXPR"); 71 | } 72 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/170.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2011 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®, 1, "REGS" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg16(0x8000, 0); 33 | setprg16(0xc000, ~0); 34 | setchr8(0); 35 | } 36 | 37 | static DECLFW(M170ProtW) { 38 | reg = V << 1 & 0x80; 39 | } 40 | 41 | static DECLFR(M170ProtR) { 42 | return reg | (X.DB & 0x7F); 43 | } 44 | 45 | static void M170Power(void) { 46 | Sync(); 47 | SetWriteHandler(0x6502, 0x6502, M170ProtW); 48 | SetWriteHandler(0x7000, 0x7000, M170ProtW); 49 | SetReadHandler(0x7001, 0x7001, M170ProtR); 50 | SetReadHandler(0x7777, 0x7777, M170ProtR); 51 | SetReadHandler(0x8000, 0xFFFF, CartBR); 52 | } 53 | 54 | static void StateRestore(int version) { 55 | Sync(); 56 | } 57 | 58 | void Mapper170_Init(CartInfo *info) { 59 | info->Power = M170Power; 60 | GameStateRestore = StateRestore; 61 | AddExState(&StateRegs, ~0, 0, 0); 62 | } 63 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/175.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg, delay, mirr; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®, 1, "REG" }, 28 | { &mirr, 1, "MIRR" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setchr8(reg); 34 | if (!delay) { 35 | setprg16(0x8000, reg); 36 | setprg8(0xC000, reg << 1); 37 | } 38 | setprg8(0xE000, (reg << 1) + 1); 39 | setmirror(((mirr & 4) >> 2) ^ 1); 40 | } 41 | 42 | static DECLFW(M175Write1) { 43 | mirr = V; 44 | delay = 1; 45 | Sync(); 46 | } 47 | 48 | static DECLFW(M175Write2) { 49 | reg = V & 0x0F; 50 | delay = 1; 51 | Sync(); 52 | } 53 | 54 | static DECLFR(M175Read) { 55 | if (A == 0xFFFC) { 56 | delay = 0; 57 | Sync(); 58 | } 59 | return CartBR(A); 60 | } 61 | 62 | static void M175Power(void) { 63 | reg = mirr = delay = 0; 64 | SetReadHandler(0x8000, 0xFFFF, M175Read); 65 | SetWriteHandler(0x8000, 0x8000, M175Write1); 66 | SetWriteHandler(0xA000, 0xA000, M175Write2); 67 | Sync(); 68 | } 69 | 70 | static void StateRestore(int version) { 71 | Sync(); 72 | } 73 | 74 | void Mapper175_Init(CartInfo *info) { 75 | info->Power = M175Power; 76 | GameStateRestore = StateRestore; 77 | 78 | AddExState(&StateRegs, ~0, 0, 0); 79 | } 80 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/189.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | #include "mmc3.h" 23 | 24 | static void M189PW(uint32 A, uint8 V) { 25 | setprg32(0x8000, EXPREGS[0] & 7); 26 | } 27 | 28 | static DECLFW(M189Write) { 29 | EXPREGS[0] = V | (V >> 4); //actually, there is a two versions of 189 mapper with hi or lo bits bankswitching. 30 | FixMMC3PRG(MMC3_cmd); 31 | } 32 | 33 | static void M189Power(void) { 34 | EXPREGS[0] = EXPREGS[1] = 0; 35 | GenMMC3Power(); 36 | SetWriteHandler(0x4120, 0x7FFF, M189Write); 37 | } 38 | 39 | void Mapper189_Init(CartInfo *info) { 40 | GenMMC3_Init(info, 256, 256, 0, 0); 41 | pwrap = M189PW; 42 | info->Power = M189Power; 43 | AddExState(EXPREGS, 2, 0, "EXPR"); 44 | } 45 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/193.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2009 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg[8]; 24 | static uint8 mirror, cmd, bank; 25 | 26 | static SFORMAT StateRegs[] = 27 | { 28 | { &cmd, 1, "CMD" }, 29 | { &mirror, 1, "MIRR" }, 30 | { &bank, 1, "BANK" }, 31 | { reg, 8, "REGS" }, 32 | { 0 } 33 | }; 34 | 35 | static void Sync(void) { 36 | setmirror(mirror ^ 1); 37 | setprg8(0x8000, reg[3]); 38 | setprg8(0xA000, 0xD); 39 | setprg8(0xC000, 0xE); 40 | setprg8(0xE000, 0xF); 41 | setchr4(0x0000, reg[0] >> 2); 42 | setchr2(0x1000, reg[1] >> 1); 43 | setchr2(0x1800, reg[2] >> 1); 44 | } 45 | 46 | static DECLFW(M193Write) { 47 | reg[A & 3] = V; 48 | Sync(); 49 | } 50 | 51 | static void M193Power(void) { 52 | bank = 0; 53 | Sync(); 54 | SetWriteHandler(0x6000, 0x6003, M193Write); 55 | SetReadHandler(0x8000, 0xFFFF, CartBR); 56 | SetWriteHandler(0x8000, 0xFFFF, CartBW); 57 | } 58 | 59 | static void M193Reset(void) { 60 | } 61 | 62 | static void StateRestore(int version) { 63 | Sync(); 64 | } 65 | 66 | void Mapper193_Init(CartInfo *info) { 67 | info->Reset = M193Reset; 68 | info->Power = M193Power; 69 | GameStateRestore = StateRestore; 70 | AddExState(&StateRegs, ~0, 0, 0); 71 | } 72 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/206.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 cmd; 24 | static uint8 DRegs[8]; 25 | 26 | static SFORMAT StateRegs[] = 27 | { 28 | { &cmd, 1, "CMD" }, 29 | { DRegs, 8, "DREG" }, 30 | { 0 } 31 | }; 32 | 33 | static void Sync(void) { 34 | setchr2(0x0000, DRegs[0]); 35 | setchr2(0x0800, DRegs[1]); 36 | int x; 37 | for (x = 0; x < 4; x++) 38 | setchr1(0x1000 + (x << 10), DRegs[2 + x]); 39 | setprg8(0x8000, DRegs[6]); 40 | setprg8(0xa000, DRegs[7]); 41 | setprg8(0xc000, ~1); 42 | setprg8(0xe000, ~0); 43 | } 44 | 45 | static void StateRestore(int version) { 46 | Sync(); 47 | } 48 | 49 | static DECLFW(M206Write) { 50 | switch (A & 0x8001) { 51 | case 0x8000: cmd = V & 0x07; break; 52 | case 0x8001: 53 | if (cmd <= 0x05) 54 | V &= 0x3F; 55 | else 56 | V &= 0x0F; 57 | if (cmd <= 0x01) V >>= 1; 58 | DRegs[cmd & 0x07] = V; 59 | Sync(); 60 | break; 61 | } 62 | } 63 | 64 | static void M206Power(void) { 65 | cmd = 0; 66 | DRegs[6] = 0; 67 | DRegs[7] = 1; 68 | Sync(); 69 | SetReadHandler(0x8000, 0xFFFF, CartBR); 70 | SetWriteHandler(0x8000, 0xFFFF, M206Write); 71 | } 72 | 73 | 74 | void Mapper206_Init(CartInfo *info) { 75 | info->Power = M206Power; 76 | GameStateRestore = StateRestore; 77 | AddExState(&StateRegs, ~0, 0, 0); 78 | } 79 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/230.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * Copyright (C) 2009 qeed 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 + Contra Reset based custom mapper... 22 | * 23 | */ 24 | 25 | #include "mapinc.h" 26 | 27 | static uint8 latche, reset; 28 | static SFORMAT StateRegs[] = 29 | { 30 | { &reset, 1, "RST" }, 31 | { &latche, 1, "LATC" }, 32 | { 0 } 33 | }; 34 | 35 | static void Sync(void) { 36 | if(reset) { 37 | setprg16(0x8000, latche & 7); 38 | setprg16(0xC000, 7); 39 | setmirror(MI_V); 40 | } else { 41 | uint32 bank = (latche & 0x1F) + 8; 42 | if (latche & 0x20) { 43 | setprg16(0x8000, bank); 44 | setprg16(0xC000, bank); 45 | } else 46 | setprg32(0x8000, bank >> 1); 47 | setmirror((latche >> 6) & 1); 48 | } 49 | setchr8(0); 50 | } 51 | 52 | static DECLFW(M230Write) { 53 | latche = V; 54 | Sync(); 55 | } 56 | 57 | static void M230Reset(void) { 58 | reset ^= 1; 59 | Sync(); 60 | } 61 | 62 | static void M230Power(void) { 63 | latche = reset = 0; 64 | Sync(); 65 | SetWriteHandler(0x8000, 0xFFFF, M230Write); 66 | SetReadHandler(0x8000, 0xFFFF, CartBR); 67 | } 68 | 69 | static void StateRestore(int version) { 70 | Sync(); 71 | } 72 | 73 | void Mapper230_Init(CartInfo *info) { 74 | info->Power = M230Power; 75 | info->Reset = M230Reset; 76 | AddExState(&StateRegs, ~0, 0, 0); 77 | GameStateRestore = StateRestore; 78 | } 79 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/232.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 bank, preg; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { &bank, 1, "BANK" }, 27 | { &preg, 1, "PREG" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | // uint32 bbank = (bank & 0x18) >> 1; 33 | uint32 bbank = ((bank & 0x10) >> 2) | (bank & 8); // some dumps have bbanks swapped, if swap commands, 34 | // then all roms can be played, but with some swapped 35 | // games in menu. if not, some dumps are unplayable 36 | // make hard dump for both cart types to check 37 | setprg16(0x8000, bbank | (preg & 3)); 38 | setprg16(0xC000, bbank | 3); 39 | setchr8(0); 40 | } 41 | 42 | static DECLFW(M232WriteBank) { 43 | bank = V; 44 | Sync(); 45 | } 46 | 47 | static DECLFW(M232WritePreg) { 48 | preg = V; 49 | Sync(); 50 | } 51 | 52 | static void M232Power(void) { 53 | bank = preg = 0; 54 | Sync(); 55 | SetWriteHandler(0x8000, 0xBFFF, M232WriteBank); 56 | SetWriteHandler(0xC000, 0xFFFF, M232WritePreg); 57 | SetReadHandler(0x8000, 0xFFFF, CartBR); 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void Mapper232_Init(CartInfo *info) { 65 | info->Power = M232Power; 66 | AddExState(&StateRegs, ~0, 0, 0); 67 | GameStateRestore = StateRestore; 68 | } 69 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/234.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 bank, preg; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { &bank, 1, "BANK" }, 27 | { &preg, 1, "PREG" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | if (bank & 0x40) { 33 | setprg32(0x8000, (bank & 0xE) | (preg & 1)); 34 | setchr8(((bank & 0xE) << 2) | ((preg >> 4) & 7)); 35 | } else { 36 | setprg32(0x8000, bank & 0xF); 37 | setchr8(((bank & 0xF) << 2) | ((preg >> 4) & 3)); 38 | } 39 | setmirror((bank >> 7) ^ 1); 40 | } 41 | 42 | DECLFR(M234ReadBank) { 43 | uint8 r = CartBR(A); 44 | if (!bank) { 45 | bank = r; 46 | Sync(); 47 | } 48 | return r; 49 | } 50 | 51 | DECLFR(M234ReadPreg) { 52 | uint8 r = CartBR(A); 53 | preg = r; 54 | Sync(); 55 | return r; 56 | } 57 | 58 | static void M234Reset(void) { 59 | bank = preg = 0; 60 | Sync(); 61 | } 62 | 63 | static void M234Power(void) { 64 | M234Reset(); 65 | SetReadHandler(0x8000, 0xFFFF, CartBR); 66 | SetReadHandler(0xFF80, 0xFF9F, M234ReadBank); 67 | SetReadHandler(0xFFE8, 0xFFF7, M234ReadPreg); 68 | } 69 | 70 | static void StateRestore(int version) { 71 | Sync(); 72 | } 73 | 74 | void Mapper234_Init(CartInfo *info) { 75 | info->Power = M234Power; 76 | info->Reset = M234Reset; 77 | AddExState(&StateRegs, ~0, 0, 0); 78 | GameStateRestore = StateRestore; 79 | } 80 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/235.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint16 cmdreg; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { &cmdreg, 2, "CREG" }, 27 | { 0 } 28 | }; 29 | 30 | static void Sync(void) { 31 | if (cmdreg & 0x400) 32 | setmirror(MI_0); 33 | else 34 | setmirror(((cmdreg >> 13) & 1) ^ 1); 35 | if (cmdreg & 0x800) { 36 | setprg16(0x8000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); 37 | setprg16(0xC000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); 38 | } else 39 | setprg32(0x8000, ((cmdreg & 0x300) >> 4) | (cmdreg & 0x1F)); 40 | } 41 | 42 | static DECLFW(M235Write) { 43 | cmdreg = A; 44 | Sync(); 45 | } 46 | 47 | static void M235Power(void) { 48 | setchr8(0); 49 | SetWriteHandler(0x8000, 0xFFFF, M235Write); 50 | SetReadHandler(0x8000, 0xFFFF, CartBR); 51 | cmdreg = 0; 52 | Sync(); 53 | } 54 | 55 | static void M235Restore(int version) { 56 | Sync(); 57 | } 58 | 59 | void Mapper235_Init(CartInfo *info) { 60 | info->Power = M235Power; 61 | GameStateRestore = M235Restore; 62 | AddExState(&StateRegs, ~0, 0, 0); 63 | } 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/244.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 preg, creg; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { &preg, 1, "PREG" }, 27 | { &creg, 1, "CREG" }, 28 | { 0 } 29 | }; 30 | 31 | static uint8 prg_perm[4][4] = { 32 | { 0, 1, 2, 3, }, 33 | { 3, 2, 1, 0, }, 34 | { 0, 2, 1, 3, }, 35 | { 3, 1, 2, 0, }, 36 | }; 37 | 38 | static uint8 chr_perm[8][8] = { 39 | { 0, 1, 2, 3, 4, 5, 6, 7, }, 40 | { 0, 2, 1, 3, 4, 6, 5, 7, }, 41 | { 0, 1, 4, 5, 2, 3, 6, 7, }, 42 | { 0, 4, 1, 5, 2, 6, 3, 7, }, 43 | { 0, 4, 2, 6, 1, 5, 3, 7, }, 44 | { 0, 2, 4, 6, 1, 3, 5, 7, }, 45 | { 7, 6, 5, 4, 3, 2, 1, 0, }, 46 | { 7, 6, 5, 4, 3, 2, 1, 0, }, 47 | }; 48 | 49 | static void Sync(void) { 50 | setprg32(0x8000, preg); 51 | setchr8(creg); 52 | } 53 | 54 | static DECLFW(M244Write) { 55 | if (V & 8) 56 | creg = chr_perm[(V >> 4) & 7][V & 7]; 57 | else 58 | preg = prg_perm[(V >> 4) & 3][V & 3]; 59 | Sync(); 60 | } 61 | 62 | static void M244Power(void) { 63 | preg = creg = 0; 64 | Sync(); 65 | SetWriteHandler(0x8000, 0xFFFF, M244Write); 66 | SetReadHandler(0x8000, 0xFFFF, CartBR); 67 | } 68 | 69 | static void StateRestore(int version) { 70 | Sync(); 71 | } 72 | 73 | void Mapper244_Init(CartInfo *info) { 74 | info->Power = M244Power; 75 | AddExState(&StateRegs, ~0, 0, 0); 76 | GameStateRestore = StateRestore; 77 | } 78 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/36.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * TXC/Micro Genius simplified mapper 21 | */ 22 | 23 | #include "mapinc.h" 24 | 25 | static uint8 latche, mirr; 26 | 27 | static SFORMAT StateRegs[] = 28 | { 29 | { &latche, 1, "LATC" }, 30 | { &mirr, 1, "MIRR" }, 31 | { 0 } 32 | }; 33 | 34 | static void Sync(void) { 35 | setprg32(0x8000, latche >> 4); 36 | setchr8(latche & 0xf); 37 | } 38 | 39 | static DECLFW(M36Write) { 40 | 41 | switch((A>>12)&7) { // need to 4-in-1 MGC-26 BMC, doesnt break other games though 42 | case 0: mirr = MI_V; setmirror(mirr); break; 43 | case 4: mirr = MI_H; setmirror(mirr); break; 44 | } 45 | latche = V; 46 | Sync(); 47 | } 48 | 49 | static DECLFR(M36Read) { 50 | return latche; // Need by Strike Wolf, being simplified mapper, this cart still uses some TCX mapper features andrely on it 51 | } 52 | 53 | static void M36Power(void) { 54 | latche = 0; 55 | Sync(); 56 | SetReadHandler(0x4100, 0x4100, M36Read); 57 | SetReadHandler(0x8000, 0xFFFF, CartBR); 58 | SetWriteHandler(0x8000, 0xFFFE, M36Write); // Actually, BUS conflict there preventing from triggering the wrong banks 59 | } 60 | 61 | static void M36Restore(int version) { 62 | Sync(); 63 | } 64 | 65 | void Mapper36_Init(CartInfo *info) { 66 | info->Power = M36Power; 67 | GameStateRestore = M36Restore; 68 | AddExState(StateRegs, ~0, 0, 0); 69 | } 70 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/41.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 mainreg, chrreg, mirror; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { &mainreg, 1, "MREG" }, 28 | { &chrreg, 1, "CREG" }, 29 | { &mirror, 1, "MIRR" }, 30 | { 0 } 31 | }; 32 | 33 | static void Sync(void) { 34 | setprg32(0x8000, mainreg & 7); 35 | setchr8(chrreg); 36 | setmirror(mirror); 37 | } 38 | 39 | static DECLFW(M41Write0) { 40 | mainreg = A & 0xFF; 41 | mirror = ((A >> 5) & 1) ^ 1; 42 | chrreg = (chrreg & 3) | ((A >> 1) & 0xC); 43 | Sync(); 44 | } 45 | 46 | static DECLFW(M41Write1) { 47 | if (mainreg & 0x4) { 48 | chrreg = (chrreg & 0xC) | (A & 3); 49 | Sync(); 50 | } 51 | } 52 | 53 | static void M41Power(void) { 54 | mainreg = chrreg = 0; 55 | Sync(); 56 | SetReadHandler(0x8000, 0xFFFF, CartBR); 57 | SetWriteHandler(0x6000, 0x67FF, M41Write0); 58 | SetWriteHandler(0x8000, 0xFFFF, M41Write1); 59 | } 60 | 61 | static void StateRestore(int version) { 62 | Sync(); 63 | } 64 | 65 | void Mapper41_Init(CartInfo *info) { 66 | info->Power = M41Power; 67 | GameStateRestore = StateRestore; 68 | AddExState(&StateRegs, ~0, 0, 0); 69 | } 70 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/411120-c.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2008 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | // actually cart ID is 811120-C, sorry ;) K-3094 - another ID 22 | 23 | #include "mapinc.h" 24 | #include "mmc3.h" 25 | 26 | static uint8 reset_flag = 0; 27 | 28 | static void BMC411120CCW(uint32 A, uint8 V) { 29 | setchr1(A, V | ((EXPREGS[0] & 3) << 7)); 30 | } 31 | 32 | static void BMC411120CPW(uint32 A, uint8 V) { 33 | if (EXPREGS[0] & (8 | reset_flag)) 34 | setprg32(0x8000, ((EXPREGS[0] >> 4) & 3) | (0x0C)); 35 | else 36 | setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 3) << 4)); 37 | } 38 | 39 | static DECLFW(BMC411120CLoWrite) { 40 | EXPREGS[0] = A; 41 | FixMMC3PRG(MMC3_cmd); 42 | FixMMC3CHR(MMC3_cmd); 43 | } 44 | 45 | static void BMC411120CReset(void) { 46 | EXPREGS[0] = 0; 47 | reset_flag ^= 4; 48 | MMC3RegReset(); 49 | } 50 | 51 | static void BMC411120CPower(void) { 52 | EXPREGS[0] = 0; 53 | GenMMC3Power(); 54 | SetWriteHandler(0x6000, 0x7FFF, BMC411120CLoWrite); 55 | } 56 | 57 | void BMC411120C_Init(CartInfo *info) { 58 | GenMMC3_Init(info, 128, 128, 8, 0); 59 | pwrap = BMC411120CPW; 60 | cwrap = BMC411120CCW; 61 | info->Power = BMC411120CPower; 62 | info->Reset = BMC411120CReset; 63 | AddExState(EXPREGS, 1, 0, "EXPR"); 64 | } 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/46.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg0, reg1; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®0, 1, "REG0" }, 28 | { ®1, 1, "REG1" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setprg32(0x8000, (reg1 & 1) + ((reg0 & 0xF) << 1)); 34 | setchr8(((reg1 >> 4) & 7) + ((reg0 & 0xF0) >> 1)); 35 | } 36 | 37 | static DECLFW(M46Write0) { 38 | reg0 = V; 39 | Sync(); 40 | } 41 | 42 | static DECLFW(M46Write1) { 43 | reg1 = V; 44 | Sync(); 45 | } 46 | 47 | static void M46Power(void) { 48 | reg0 = reg1 = 0; 49 | Sync(); 50 | SetReadHandler(0x8000, 0xFFFF, CartBR); 51 | SetWriteHandler(0x6000, 0x7FFF, M46Write0); 52 | SetWriteHandler(0x8000, 0xFFFF, M46Write1); 53 | } 54 | 55 | static void M46Reset(void) { 56 | reg0 = reg1 = 0; 57 | Sync(); 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void Mapper46_Init(CartInfo *info) { 65 | info->Power = M46Power; 66 | info->Reset = M46Reset; 67 | GameStateRestore = StateRestore; 68 | AddExState(&StateRegs, ~0, 0, 0); 69 | } 70 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/603-5052.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | #include "mmc3.h" 23 | 24 | static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 }; 25 | 26 | static DECLFW(UNL6035052ProtWrite) { 27 | EXPREGS[0] = lut[V & 3]; 28 | } 29 | 30 | static DECLFR(UNL6035052ProtRead) { 31 | return EXPREGS[0]; 32 | } 33 | 34 | static void UNL6035052Power(void) { 35 | GenMMC3Power(); 36 | SetWriteHandler(0x4020, 0x7FFF, UNL6035052ProtWrite); 37 | SetReadHandler(0x4020, 0x7FFF, UNL6035052ProtRead); 38 | } 39 | 40 | void UNL6035052_Init(CartInfo *info) { 41 | GenMMC3_Init(info, 128, 256, 0, 0); 42 | info->Power = UNL6035052Power; 43 | AddExState(EXPREGS, 6, 0, "EXPR"); 44 | } 45 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/62.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 bank; 24 | static uint16 mode; 25 | static SFORMAT StateRegs[] = 26 | { 27 | { &bank, 1, "BANK" }, 28 | { &mode, 2, "MODE" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setchr8(((mode & 0x1F) << 2) | (bank & 0x03)); 34 | if (mode & 0x20) { 35 | setprg16(0x8000, (mode & 0x40) | ((mode >> 8) & 0x3F)); 36 | setprg16(0xc000, (mode & 0x40) | ((mode >> 8) & 0x3F)); 37 | } else 38 | setprg32(0x8000, ((mode & 0x40) | ((mode >> 8) & 0x3F)) >> 1); 39 | setmirror(((mode >> 7) & 1) ^ 1); 40 | } 41 | 42 | static DECLFW(M62Write) { 43 | mode = A & 0x3FFF; 44 | bank = V & 3; 45 | Sync(); 46 | } 47 | 48 | static void M62Power(void) { 49 | bank = mode = 0; 50 | Sync(); 51 | SetWriteHandler(0x8000, 0xFFFF, M62Write); 52 | SetReadHandler(0x8000, 0xFFFF, CartBR); 53 | } 54 | 55 | static void M62Reset(void) { 56 | bank = mode = 0; 57 | Sync(); 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void Mapper62_Init(CartInfo *info) { 65 | info->Power = M62Power; 66 | info->Reset = M62Reset; 67 | AddExState(&StateRegs, ~0, 0, 0); 68 | GameStateRestore = StateRestore; 69 | } 70 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/71.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 preg, mirr; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { &preg, 1, "PREG" }, 28 | { &mirr, 1, "MIRR" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setprg16(0x8000, preg); 34 | setprg16(0xC000, ~0); 35 | setchr8(0); 36 | if(mirr) 37 | setmirror(mirr); 38 | } 39 | 40 | static DECLFW(M71Write) { 41 | if ((A & 0xF000) == 0x9000) 42 | mirr = MI_0 + ((V >> 4) & 1); // 2-in-1, some carts are normal hardwire V/H mirror, some uses mapper selectable 0/1 mirror 43 | else 44 | preg = V; 45 | Sync(); 46 | } 47 | 48 | static void M71Power(void) { 49 | mirr = 0; 50 | Sync(); 51 | SetReadHandler(0x8000, 0xFFFF, CartBR); 52 | SetWriteHandler(0x8000, 0xFFFF, M71Write); 53 | } 54 | 55 | static void StateRestore(int version) { 56 | Sync(); 57 | } 58 | 59 | void Mapper71_Init(CartInfo *info) { 60 | info->Power = M71Power; 61 | GameStateRestore = StateRestore; 62 | 63 | AddExState(&StateRegs, ~0, 0, 0); 64 | } 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/72.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * Moero!! Pro Tennis have ADPCM codec on-board, PROM isn't dumped, emulation isn't 21 | * possible just now. 22 | */ 23 | 24 | #include "mapinc.h" 25 | 26 | static uint8 preg, creg; 27 | 28 | static SFORMAT StateRegs[] = 29 | { 30 | { &preg, 1, "PREG" }, 31 | { &creg, 1, "CREG" }, 32 | { 0 } 33 | }; 34 | 35 | static void Sync(void) { 36 | setprg16(0x8000, preg); 37 | setprg16(0xC000, ~0); 38 | setchr8(creg); 39 | } 40 | 41 | static DECLFW(M72Write) { 42 | if (V & 0x80) 43 | preg = V & 0xF; 44 | if (V & 0x40) 45 | creg = V & 0xF; 46 | Sync(); 47 | } 48 | 49 | static void M72Power(void) { 50 | Sync(); 51 | SetReadHandler(0x8000, 0xFFFF, CartBR); 52 | SetWriteHandler(0x6000, 0xFFFF, M72Write); 53 | } 54 | 55 | static void StateRestore(int version) { 56 | Sync(); 57 | } 58 | 59 | void Mapper72_Init(CartInfo *info) { 60 | info->Power = M72Power; 61 | GameStateRestore = StateRestore; 62 | 63 | AddExState(&StateRegs, ~0, 0, 0); 64 | } 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/77.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 latche; 24 | 25 | static uint8 *CHRRAM=NULL; 26 | static uint32 CHRRAMSIZE; 27 | 28 | static SFORMAT StateRegs[] = 29 | { 30 | { &latche, 1, "LATC" }, 31 | { 0 } 32 | }; 33 | 34 | static void Sync(void) { 35 | setprg32(0x8000, latche & 7); 36 | setchr2(0x0000, latche >> 4); 37 | setchr2r(0x10, 0x0800, 2); 38 | setchr4r(0x10, 0x1000, 0); 39 | } 40 | 41 | static DECLFW(M77Write) { 42 | latche = V; 43 | Sync(); 44 | } 45 | 46 | static void M77Power(void) { 47 | latche = 0; 48 | Sync(); 49 | SetReadHandler(0x8000, 0xFFFF, CartBR); 50 | SetWriteHandler(0x8000, 0xFFFF, M77Write); 51 | } 52 | 53 | static void M77Close(void) 54 | { 55 | if (CHRRAM) 56 | FCEU_gfree(CHRRAM); 57 | CHRRAM = NULL; 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void Mapper77_Init(CartInfo *info) { 65 | info->Power = M77Power; 66 | info->Close = M77Close; 67 | GameStateRestore = StateRestore; 68 | 69 | CHRRAMSIZE = 6 * 1024; 70 | CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); 71 | SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); 72 | AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); 73 | 74 | AddExState(&StateRegs, ~0, 0, 0); 75 | } 76 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/79.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * Copyright (C) 2002 Xodnizel 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "mapinc.h" 23 | 24 | static uint8 creg, preg; 25 | static SFORMAT StateRegs[] = 26 | { 27 | { &creg, 1, "CREG" }, 28 | { &preg, 1, "PREG" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setprg32(0x8000, preg); 34 | setchr8(creg); 35 | } 36 | 37 | static DECLFW(M79Write) { 38 | if ((A < 0x8000) && ((A ^ 0x4100) == 0)) { 39 | preg = (V >> 3) & 1; 40 | } 41 | creg = V & 7; 42 | Sync(); 43 | } 44 | 45 | static void M79Power(void) { 46 | preg = ~0; 47 | Sync(); 48 | SetWriteHandler(0x4100, 0x5FFF, M79Write); 49 | SetWriteHandler(0x8000, 0xFFFF, M79Write); 50 | SetReadHandler(0x8000, 0xFFFF, CartBR); 51 | } 52 | 53 | static void StateRestore(int version) { 54 | Sync(); 55 | } 56 | 57 | void Mapper79_Init(CartInfo *info) { 58 | info->Power = M79Power; 59 | AddExState(&StateRegs, ~0, 0, 0); 60 | GameStateRestore = StateRestore; 61 | } 62 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/80013-B.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2017 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 bios_prg, rom_prg, rom_mode, mirror; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { &bios_prg, 1, "BREG" }, 28 | { &rom_prg, 1, "RREG" }, 29 | { &rom_mode, 1, "RMODE" }, 30 | { 0 } 31 | }; 32 | 33 | static void Sync(void) { 34 | setchr8(0); 35 | if(rom_mode&2) { 36 | setprg16r(0,0x8000,(bios_prg&0xF)|(rom_prg&0x70)); 37 | } else { 38 | setprg16r(1,0x8000,bios_prg&3); 39 | } 40 | setprg16r(0,0xC000,rom_prg&0x7F); 41 | setmirror(((bios_prg>>4)&1)^1); 42 | } 43 | 44 | static DECLFW(BMC80013BWrite) { 45 | uint8 reg = (A>>13)&3; 46 | if(reg == 0) { 47 | bios_prg = V; 48 | } else { 49 | rom_prg = V; 50 | rom_mode = reg; 51 | } 52 | Sync(); 53 | } 54 | 55 | static void BMC80013BPower(void) { 56 | bios_prg=rom_prg=rom_mode=mirror=0; 57 | Sync(); 58 | SetReadHandler(0x8000, 0xFFFF, CartBR); 59 | SetWriteHandler(0x8000, 0xFFFF, BMC80013BWrite); 60 | } 61 | 62 | static void BMC80013BReset(void) { 63 | bios_prg=rom_prg=rom_mode=mirror=0; 64 | Sync(); 65 | } 66 | 67 | static void StateRestore(int version) { 68 | Sync(); 69 | } 70 | 71 | void BMC80013B_Init(CartInfo *info) { 72 | info->Reset = BMC80013BReset; 73 | info->Power = BMC80013BPower; 74 | GameStateRestore = StateRestore; 75 | AddExState(&StateRegs, ~0, 0, 0); 76 | } 77 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/830118C.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2008 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | // M-022 MMC3 based 830118C T-106 4M + 4M 22 | 23 | #include "mapinc.h" 24 | #include "mmc3.h" 25 | 26 | static void BMC830118CCW(uint32 A, uint8 V) { 27 | setchr1(A, (V & 0x7F) | ((EXPREGS[0] & 0x0c) << 5)); 28 | } 29 | 30 | static void BMC830118CPW(uint32 A, uint8 V) { 31 | if ((EXPREGS[0] & 0x0C) == 0x0C) { 32 | if (A == 0x8000) { 33 | setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); 34 | setprg8(0xC000, (V & 0x0F) | 0x32); 35 | } else if (A == 0xA000) { 36 | setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); 37 | setprg8(0xE000, (V & 0x0F) | 0x32); 38 | } 39 | } else { 40 | setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); 41 | } 42 | } 43 | 44 | static DECLFW(BMC830118CLoWrite) { 45 | EXPREGS[0] = V; 46 | FixMMC3PRG(MMC3_cmd); 47 | FixMMC3CHR(MMC3_cmd); 48 | } 49 | 50 | static void BMC830118CReset(void) { 51 | EXPREGS[0] = 0; 52 | MMC3RegReset(); 53 | } 54 | 55 | static void BMC830118CPower(void) { 56 | EXPREGS[0] = 0; 57 | GenMMC3Power(); 58 | SetWriteHandler(0x6800, 0x68FF, BMC830118CLoWrite); 59 | } 60 | 61 | void BMC830118C_Init(CartInfo *info) { 62 | GenMMC3_Init(info, 128, 128, 8, 0); 63 | pwrap = BMC830118CPW; 64 | cwrap = BMC830118CCW; 65 | info->Power = BMC830118CPower; 66 | info->Reset = BMC830118CReset; 67 | AddExState(EXPREGS, 1, 0, "EXPR"); 68 | } 69 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/8in1.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2016 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * 8-in-1 Rockin' Kats, Snake, (PCB marked as "8 in 1"), similar to 12IN1, 21 | * but with MMC3 on board, all games are hacked the same, Snake is buggy too! 22 | * 23 | * no reset-citcuit, so selected game can be reset, but to change it you must use power 24 | * 25 | */ 26 | 27 | #include "mapinc.h" 28 | #include "mmc3.h" 29 | 30 | static void BMC8IN1CW(uint32 A, uint8 V) { 31 | setchr1(A, ((EXPREGS[0] & 0xC) << 5) | (V & 0x7F)); 32 | } 33 | 34 | static void BMC8IN1PW(uint32 A, uint8 V) { 35 | if(EXPREGS[0] & 0x10) { // MMC3 mode 36 | setprg8(A, ((EXPREGS[0] & 0xC) << 2) | (V & 0xF)); 37 | } else { 38 | setprg32(0x8000, EXPREGS[0] & 0xF); 39 | } 40 | } 41 | 42 | static DECLFW(BMC8IN1Write) { 43 | if(A & 0x1000) { 44 | EXPREGS[0] = V; 45 | FixMMC3PRG(MMC3_cmd); 46 | FixMMC3CHR(MMC3_cmd); 47 | } else { 48 | if(A < 0xC000) 49 | MMC3_CMDWrite(A, V); 50 | else 51 | MMC3_IRQWrite(A, V); 52 | } 53 | } 54 | 55 | static void BMC8IN1Power(void) { 56 | EXPREGS[0] = 0; 57 | GenMMC3Power(); 58 | SetWriteHandler(0x8000, 0xFFFF, BMC8IN1Write); 59 | } 60 | 61 | void BMC8IN1_Init(CartInfo *info) { 62 | GenMMC3_Init(info, 128, 128, 0, 0); 63 | cwrap = BMC8IN1CW; 64 | pwrap = BMC8IN1PW; 65 | info->Power = BMC8IN1Power; 66 | AddExState(EXPREGS, 1, 0, "EXPR"); 67 | } 68 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/96.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 1998 BERO 5 | * Copyright (C) 2002 Xodnizel 6 | * Copyright (C) 2012 CaH4e3 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include "mapinc.h" 24 | 25 | static uint8 reg, ppulatch; 26 | 27 | static SFORMAT StateRegs[] = 28 | { 29 | { ®, 1, "REG" }, 30 | { &ppulatch, 1, "PPUL" }, 31 | { 0 } 32 | }; 33 | 34 | static void Sync(void) { 35 | setmirror(MI_0); 36 | setprg32(0x8000, reg & 3); 37 | setchr4(0x0000, (reg & 4) | ppulatch); 38 | setchr4(0x1000, (reg & 4) | 3); 39 | } 40 | 41 | static DECLFW(M96Write) { 42 | reg = V; 43 | Sync(); 44 | } 45 | 46 | static void M96Hook(uint32 A) { 47 | if ((A & 0x3000) == 0x2000) { 48 | ppulatch = (A >> 8) & 3; 49 | Sync(); 50 | } 51 | } 52 | 53 | static void M96Power(void) { 54 | reg = ppulatch = 0; 55 | Sync(); 56 | SetReadHandler(0x8000, 0xffff, CartBR); 57 | SetWriteHandler(0x8000, 0xffff, M96Write); 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void Mapper96_Init(CartInfo *info) { 65 | info->Power = M96Power; 66 | PPU_hook = M96Hook; 67 | GameStateRestore = StateRestore; 68 | AddExState(&StateRegs, ~0, 0, 0); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/ac-08.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2011 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg, mirr; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®, 1, "REG" }, 28 | { &mirr, 1, "MIRR" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setprg8(0x6000, reg); 34 | setprg32r(1, 0x8000, 0); 35 | setchr8(0); 36 | setmirror(mirr); 37 | } 38 | 39 | static DECLFW(AC08Mirr) { 40 | mirr = ((V & 8) >> 3) ^ 1; 41 | Sync(); 42 | } 43 | 44 | static DECLFW(AC08Write) { 45 | if (A == 0x8001) // Green Berret bank switching is only 100x xxxx xxxx xxx1 mask 46 | reg = (V >> 1) & 0xf; 47 | else 48 | reg = V & 0xf; // Sad But True, 2-in-1 mapper, Green Berret need value shifted left one byte, Castlevania doesn't 49 | Sync(); 50 | } 51 | 52 | static void AC08Power(void) { 53 | reg = 0; 54 | Sync(); 55 | SetReadHandler(0x6000, 0xFFFF, CartBR); 56 | SetWriteHandler(0x4025, 0x4025, AC08Mirr); 57 | SetWriteHandler(0x8000, 0xFFFF, AC08Write); 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void AC08_Init(CartInfo *info) { 65 | info->Power = AC08Power; 66 | GameStateRestore = StateRestore; 67 | AddExState(&StateRegs, ~0, 0, 0); 68 | } 69 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/bb.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg, chr; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { ®, 1, "REG" }, 28 | { &chr, 1, "CHR" }, 29 | { 0 } 30 | }; 31 | 32 | static void Sync(void) { 33 | setprg8(0x6000, reg & 3); 34 | setprg32(0x8000, ~0); 35 | setchr8(chr & 3); 36 | } 37 | 38 | static DECLFW(UNLBBWrite) { 39 | if ((A & 0x9000) == 0x8000) 40 | reg = chr = V; 41 | else 42 | chr = V & 1; // hacky hacky, ProWres simplified FDS conversion 2-in-1 mapper 43 | Sync(); 44 | } 45 | 46 | static void UNLBBPower(void) { 47 | chr = 0; 48 | reg = ~0; 49 | Sync(); 50 | SetReadHandler(0x6000, 0x7FFF, CartBR); 51 | SetReadHandler(0x8000, 0xFFFF, CartBR); 52 | SetWriteHandler(0x8000, 0xFFFF, UNLBBWrite); 53 | } 54 | 55 | static void StateRestore(int version) { 56 | Sync(); 57 | } 58 | 59 | void UNLBB_Init(CartInfo *info) { 60 | info->Power = UNLBBPower; 61 | GameStateRestore = StateRestore; 62 | AddExState(&StateRegs, ~0, 0, 0); 63 | } 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/dream.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 latche; 24 | 25 | static void Sync(void) { 26 | setprg16(0x8000, latche); 27 | setprg16(0xC000, 8); 28 | } 29 | 30 | static DECLFW(DREAMWrite) { 31 | latche = V & 7; 32 | Sync(); 33 | } 34 | 35 | static void DREAMPower(void) { 36 | latche = 0; 37 | Sync(); 38 | setchr8(0); 39 | SetReadHandler(0x8000, 0xFFFF, CartBR); 40 | SetWriteHandler(0x5020, 0x5020, DREAMWrite); 41 | } 42 | 43 | static void Restore(int version) { 44 | Sync(); 45 | } 46 | 47 | void DreamTech01_Init(CartInfo *info) { 48 | GameStateRestore = Restore; 49 | info->Power = DREAMPower; 50 | AddExState(&latche, 1, 0, "LATC"); 51 | } 52 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/gs-2004.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg, mirr; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { ®, 1, "REGS" }, 27 | { &mirr, 1, "MIRR" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg8r(1, 0x6000, 0); 33 | setprg32(0x8000, reg); 34 | setchr8(0); 35 | } 36 | 37 | static DECLFW(BMCGS2004Write) { 38 | reg = V; 39 | Sync(); 40 | } 41 | 42 | static void BMCGS2004Power(void) { 43 | reg = ~0; 44 | Sync(); 45 | SetReadHandler(0x6000, 0x7FFF, CartBR); 46 | SetReadHandler(0x8000, 0xFFFF, CartBR); 47 | SetWriteHandler(0x8000, 0xFFFF, BMCGS2004Write); 48 | } 49 | 50 | static void BMCGS2004Reset(void) { 51 | reg = ~0; 52 | } 53 | 54 | static void StateRestore(int version) { 55 | Sync(); 56 | } 57 | 58 | void BMCGS2004_Init(CartInfo *info) { 59 | info->Reset = BMCGS2004Reset; 60 | info->Power = BMCGS2004Power; 61 | GameStateRestore = StateRestore; 62 | AddExState(&StateRegs, ~0, 0, 0); 63 | } 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/gs-2013.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 reg, mirr; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { ®, 1, "REGS" }, 27 | { &mirr, 1, "MIRR" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg8r(0, 0x6000, ~0); 33 | setprg32r((reg & 8) >> 3, 0x8000, reg); 34 | setchr8(0); 35 | } 36 | 37 | static DECLFW(BMCGS2013Write) { 38 | reg = V; 39 | Sync(); 40 | } 41 | 42 | static void BMCGS2013Power(void) { 43 | reg = ~0; 44 | Sync(); 45 | SetReadHandler(0x6000, 0x7FFF, CartBR); 46 | SetReadHandler(0x8000, 0xFFFF, CartBR); 47 | SetWriteHandler(0x8000, 0xFFFF, BMCGS2013Write); 48 | } 49 | 50 | static void BMCGS2013Reset(void) { 51 | reg = ~0; 52 | } 53 | 54 | static void StateRestore(int version) { 55 | Sync(); 56 | } 57 | 58 | void BMCGS2013_Init(CartInfo *info) { 59 | info->Reset = BMCGS2013Reset; 60 | info->Power = BMCGS2013Power; 61 | GameStateRestore = StateRestore; 62 | AddExState(&StateRegs, ~0, 0, 0); 63 | } 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/h2288.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | #include "mmc3.h" 23 | 24 | extern uint8 m114_perm[8]; 25 | 26 | static void H2288PW(uint32 A, uint8 V) { 27 | if (EXPREGS[0] & 0x40) { 28 | uint8 bank = (EXPREGS[0] & 5) | ((EXPREGS[0] & 8) >> 2) | ((EXPREGS[0] & 0x20) >> 2); 29 | if (EXPREGS[0] & 2) 30 | setprg32(0x8000, bank >> 1); 31 | else{ 32 | setprg16(0x8000, bank); 33 | setprg16(0xC000, bank); 34 | } 35 | } else 36 | setprg8(A, V & 0x3F); 37 | } 38 | 39 | static DECLFW(H2288WriteHi) { 40 | switch (A & 0x8001) { 41 | case 0x8000: MMC3_CMDWrite(0x8000, (V & 0xC0) | (m114_perm[V & 7])); break; 42 | case 0x8001: MMC3_CMDWrite(0x8001, V); break; 43 | } 44 | } 45 | 46 | static DECLFW(H2288WriteLo) { 47 | if (A & 0x800) { 48 | if (A & 1) 49 | EXPREGS[1] = V; 50 | else 51 | EXPREGS[0] = V; 52 | FixMMC3PRG(MMC3_cmd); 53 | } 54 | } 55 | 56 | static void H2288Power(void) { 57 | EXPREGS[0] = EXPREGS[1] = 0; 58 | GenMMC3Power(); 59 | // SetReadHandler(0x5000,0x5FFF,H2288Read); 60 | SetReadHandler(0x8000, 0xFFFF, CartBR); 61 | SetWriteHandler(0x5000, 0x5FFF, H2288WriteLo); 62 | SetWriteHandler(0x8000, 0x9FFF, H2288WriteHi); 63 | } 64 | 65 | void UNLH2288_Init(CartInfo *info) { 66 | GenMMC3_Init(info, 256, 256, 0, 0); 67 | pwrap = H2288PW; 68 | info->Power = H2288Power; 69 | AddExState(EXPREGS, 2, 0, "EXPR"); 70 | } 71 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/hp898f.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2015 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 regs[2]; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { regs, 2, "REGS" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | uint8 chr = (regs[0] >> 4) & 7; 33 | uint8 prg = (regs[1] >> 3) & 7; 34 | uint8 dec = (regs[1] >> 4) & 4; 35 | setchr8(chr & (~(((regs[0] & 1) << 2) | (regs[0] & 2)))); 36 | setprg16(0x8000,prg & (~dec)); 37 | setprg16(0xC000,prg | dec); 38 | setmirror(regs[1] >> 7); 39 | } 40 | 41 | static DECLFW(HP898FWrite) { 42 | if((A & 0x6000) == 0x6000) { 43 | regs[(A & 4) >> 2] = V; 44 | Sync(); 45 | } 46 | } 47 | 48 | static void HP898FPower(void) { 49 | regs[0] = regs[1] = 0; 50 | Sync(); 51 | SetReadHandler(0x8000, 0xFFFF, CartBR); 52 | SetWriteHandler(0x6000, 0xFFFF, HP898FWrite); 53 | } 54 | 55 | static void HP898FReset(void) { 56 | regs[0] = regs[1] = 0; 57 | Sync(); 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void BMCHP898F_Init(CartInfo *info) { 65 | info->Reset = HP898FReset; 66 | info->Power = HP898FPower; 67 | GameStateRestore = StateRestore; 68 | AddExState(&StateRegs, ~0, 0, 0); 69 | } 70 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/inlnsf.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 regs[8]; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { regs, 8, "REGS" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | for (int i=0; i < 8; ++i) 33 | { 34 | setprg4(0x8000 + (0x1000 * i), regs[i]); 35 | } 36 | } 37 | 38 | static DECLFW(M31Write) { 39 | if (A >= 0x5000 && A <= 0x5FFF) 40 | { 41 | regs[A&7] = V; 42 | Sync(); 43 | } 44 | } 45 | 46 | static void M31Power(void) { 47 | setchr8(0); 48 | regs[7] = 0xFF; 49 | Sync(); 50 | SetReadHandler(0x8000, 0xffff, CartBR); 51 | SetWriteHandler(0x5000, 0x5fff, M31Write); 52 | } 53 | 54 | static void StateRestore(int version) { 55 | Sync(); 56 | } 57 | 58 | void Mapper31_Init(CartInfo *info) { 59 | info->Power = M31Power; 60 | GameStateRestore = StateRestore; 61 | AddExState(&StateRegs, ~0, 0, 0); 62 | } 63 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/karaoke.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | extern uint32 ROM_size; 24 | static uint8 latche; 25 | 26 | static void Sync(void) { 27 | if (latche) { 28 | if (latche & 0x10) 29 | setprg16(0x8000, (latche & 7)); 30 | else 31 | setprg16(0x8000, (latche & 7) | 8); 32 | } else 33 | setprg16(0x8000, 7 + (ROM_size >> 4)); 34 | } 35 | 36 | static DECLFW(M188Write) { 37 | latche = V; 38 | Sync(); 39 | } 40 | 41 | static DECLFR(ExtDev) { 42 | return(3); 43 | } 44 | 45 | static void Power(void) { 46 | latche = 0; 47 | Sync(); 48 | setchr8(0); 49 | setprg16(0xc000, 0x7); 50 | SetReadHandler(0x6000, 0x7FFF, ExtDev); 51 | SetReadHandler(0x8000, 0xFFFF, CartBR); 52 | SetWriteHandler(0x8000, 0xFFFF, M188Write); 53 | } 54 | 55 | static void StateRestore(int version) { 56 | Sync(); 57 | } 58 | 59 | void Mapper188_Init(CartInfo *info) { 60 | info->Power = Power; 61 | GameStateRestore = StateRestore; 62 | AddExState(&latche, 1, 0, "LATC"); 63 | } 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/kof97.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2005 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | #include "mmc3.h" 23 | 24 | static DECLFW(UNLKOF97CMDWrite) { 25 | V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); //76143502 26 | if (A == 0x9000) A = 0x8001; 27 | MMC3_CMDWrite(A, V); 28 | } 29 | 30 | static DECLFW(UNLKOF97IRQWrite) { 31 | V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); 32 | if (A == 0xD000) A = 0xC001; 33 | else if (A == 0xF000) A = 0xE001; 34 | MMC3_IRQWrite(A, V); 35 | } 36 | 37 | static void UNLKOF97Power(void) { 38 | GenMMC3Power(); 39 | SetWriteHandler(0x8000, 0xA000, UNLKOF97CMDWrite); 40 | SetWriteHandler(0xC000, 0xF000, UNLKOF97IRQWrite); 41 | } 42 | 43 | void UNLKOF97_Init(CartInfo *info) { 44 | GenMMC3_Init(info, 128, 256, 0, 0); 45 | info->Power = UNLKOF97Power; 46 | } 47 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/ks7013.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2011 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * Just another pirate cart with pirate mapper, instead of original MMC1 21 | * Kaiser Highway Star 22 | * 23 | */ 24 | 25 | #include "mapinc.h" 26 | 27 | static uint8 reg, mirr; 28 | 29 | static SFORMAT StateRegs[] = 30 | { 31 | { ®, 1, "REGS" }, 32 | { &mirr, 1, "MIRR" }, 33 | { 0 } 34 | }; 35 | 36 | static void Sync(void) { 37 | setprg16(0x8000, reg); 38 | setprg16(0xc000, ~0); 39 | setmirror(mirr); 40 | setchr8(0); 41 | } 42 | 43 | static DECLFW(UNLKS7013BLoWrite) { 44 | reg = V; 45 | Sync(); 46 | } 47 | 48 | static DECLFW(UNLKS7013BHiWrite) { 49 | mirr = (V & 1) ^ 1; 50 | Sync(); 51 | } 52 | 53 | static void UNLKS7013BPower(void) { 54 | reg = 0; 55 | mirr = 0; 56 | Sync(); 57 | SetWriteHandler(0x6000, 0x7FFF, UNLKS7013BLoWrite); 58 | SetReadHandler(0x8000, 0xFFFF, CartBR); 59 | SetWriteHandler(0x8000, 0xFFFF, UNLKS7013BHiWrite); 60 | } 61 | 62 | static void UNLKS7013BReset(void) { 63 | reg = 0; 64 | Sync(); 65 | } 66 | 67 | static void StateRestore(int version) { 68 | Sync(); 69 | } 70 | 71 | void UNLKS7013B_Init(CartInfo *info) { 72 | info->Power = UNLKS7013BPower; 73 | info->Reset = UNLKS7013BReset; 74 | 75 | GameStateRestore = StateRestore; 76 | AddExState(&StateRegs, ~0, 0, 0); 77 | } 78 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/ks7031.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * FDS Conversion 21 | * 22 | */ 23 | 24 | #include "mapinc.h" 25 | 26 | static uint8 reg[4]; 27 | 28 | static SFORMAT StateRegs[] = 29 | { 30 | { reg, 4, "REGS" }, 31 | { 0 } 32 | }; 33 | 34 | static void Sync(void) { 35 | setprg2(0x6000, reg[0]); 36 | setprg2(0x6800, reg[1]); 37 | setprg2(0x7000, reg[2]); 38 | setprg2(0x7800, reg[3]); 39 | 40 | setprg2(0x8000, 15); 41 | setprg2(0x8800, 14); 42 | setprg2(0x9000, 13); 43 | setprg2(0x9800, 12); 44 | setprg2(0xa000, 11); 45 | setprg2(0xa800, 10); 46 | setprg2(0xb000, 9); 47 | setprg2(0xb800, 8); 48 | 49 | setprg2(0xc000, 7); 50 | setprg2(0xc800, 6); 51 | setprg2(0xd000, 5); 52 | setprg2(0xd800, 4); 53 | setprg2(0xe000, 3); 54 | setprg2(0xe800, 2); 55 | setprg2(0xf000, 1); 56 | setprg2(0xf800, 0); 57 | 58 | setchr8(0); 59 | } 60 | 61 | static DECLFW(UNLKS7031Write) { 62 | reg[(A >> 11) & 3] = V; 63 | Sync(); 64 | } 65 | 66 | static void UNLKS7031Power(void) { 67 | Sync(); 68 | SetReadHandler(0x6000, 0xFFFF, CartBR); 69 | SetWriteHandler(0x8000, 0xffff, UNLKS7031Write); 70 | } 71 | 72 | static void StateRestore(int version) { 73 | Sync(); 74 | } 75 | 76 | void UNLKS7031_Init(CartInfo *info) { 77 | info->Power = UNLKS7031Power; 78 | GameStateRestore = StateRestore; 79 | AddExState(&StateRegs, ~0, 0, 0); 80 | } 81 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/le05.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2011 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * FDS Conversion 21 | * 22 | */ 23 | 24 | #include "mapinc.h" 25 | 26 | static uint8 chr; 27 | static SFORMAT StateRegs[] = 28 | { 29 | { &chr, 1, "CHR" }, 30 | { 0 } 31 | }; 32 | 33 | static void Sync(void) { 34 | setprg2r(0, 0xE000, 0); 35 | setprg2r(0, 0xE800, 0); 36 | setprg2r(0, 0xF000, 0); 37 | setprg2r(0, 0xF800, 0); 38 | 39 | setprg8r(1, 0x6000, 3); 40 | setprg8r(1, 0x8000, 0); 41 | setprg8r(1, 0xA000, 1); 42 | setprg8r(1, 0xC000, 2); 43 | 44 | setchr8(chr & 1); 45 | setmirror(MI_V); 46 | } 47 | 48 | static DECLFW(LE05Write) { 49 | chr = V; 50 | Sync(); 51 | } 52 | 53 | static void LE05Power(void) { 54 | Sync(); 55 | SetReadHandler(0x6000, 0xFFFF, CartBR); 56 | SetWriteHandler(0x8000, 0xFFFF, LE05Write); 57 | } 58 | 59 | void LE05_Init(CartInfo *info) { 60 | info->Power = LE05Power; 61 | AddExState(&StateRegs, ~0, 0, 0); 62 | } 63 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/lh32.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2007 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * FDS Conversion 21 | * 22 | */ 23 | 24 | #include "mapinc.h" 25 | 26 | static uint8 reg; 27 | static uint8 *WRAM = NULL; 28 | static uint32 WRAMSIZE; 29 | 30 | static SFORMAT StateRegs[] = 31 | { 32 | { ®, 1, "REG" }, 33 | { 0 } 34 | }; 35 | 36 | static void Sync(void) { 37 | setprg8(0x6000, reg); 38 | setprg8(0x8000, ~3); 39 | setprg8(0xa000, ~2); 40 | setprg8r(0x10, 0xc000, 0); 41 | setprg8(0xe000, ~0); 42 | setchr8(0); 43 | } 44 | 45 | static DECLFW(LH32Write) { 46 | reg = V; 47 | Sync(); 48 | } 49 | 50 | static void LH32Power(void) { 51 | Sync(); 52 | SetReadHandler(0x6000, 0xFFFF, CartBR); 53 | SetWriteHandler(0xC000, 0xDFFF, CartBW); 54 | SetWriteHandler(0x6000, 0x6000, LH32Write); 55 | FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); 56 | } 57 | 58 | static void LH32Close(void) { 59 | if (WRAM) 60 | FCEU_gfree(WRAM); 61 | WRAM = NULL; 62 | } 63 | 64 | static void StateRestore(int version) { 65 | Sync(); 66 | } 67 | 68 | void LH32_Init(CartInfo *info) { 69 | info->Power = LH32Power; 70 | info->Close = LH32Close; 71 | 72 | WRAMSIZE = 8192; 73 | WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); 74 | SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); 75 | AddExState(WRAM, WRAMSIZE, 0, "WRAM"); 76 | 77 | GameStateRestore = StateRestore; 78 | AddExState(&StateRegs, ~0, 0, 0); 79 | } 80 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/malee.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 WRAM[2048]; 24 | 25 | static void MALEEPower(void) { 26 | setprg2r(0x10, 0x7000, 0); 27 | SetReadHandler(0x8000, 0xFFFF, CartBR); 28 | SetReadHandler(0x6000, 0x67FF, CartBR); 29 | SetReadHandler(0x7000, 0x77FF, CartBR); 30 | SetWriteHandler(0x7000, 0x77FF, CartBW); 31 | setprg2r(1, 0x6000, 0); 32 | setprg32(0x8000, 0); 33 | setchr8(0); 34 | } 35 | 36 | void MALEE_Init(CartInfo *info) { 37 | info->Power = MALEEPower; 38 | FCEU_MemoryRand(WRAM,sizeof(WRAM),true); 39 | SetupCartPRGMapping(0x10, WRAM, 2048, 1); 40 | AddExState(WRAM, 2048, 0, "WRAM"); 41 | } 42 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/mapinc.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAPINC_H__ 2 | #define __MAPINC_H__ 3 | 4 | #include "../types.h" 5 | #include "../utils/memory.h" 6 | #include "../x6502.h" 7 | #include "../fceu.h" 8 | #include "../ppu.h" 9 | #include "../sound.h" 10 | #include "../state.h" 11 | #include "../cart.h" 12 | #include "../unif.h" 13 | 14 | void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/mihunche.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2013 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint16 latche; 24 | 25 | static SFORMAT StateRegs[] = 26 | { 27 | { &latche, 2, "LATC" }, 28 | { 0 } 29 | }; 30 | 31 | static void Sync(void) { 32 | setprg32(0x8000, 0); 33 | if(CHRsize[0] == 8192) { 34 | setchr4(0x0000, latche & 1); 35 | setchr4(0x1000, latche & 1); 36 | } else { 37 | setchr8(latche & 1); // actually, my bad, overdumped roms, the real CHR size if 8K 38 | } 39 | setmirror(MI_0 + (latche & 1)); 40 | } 41 | 42 | static DECLFW(UNLCC21Write1) { 43 | latche = A; 44 | Sync(); 45 | } 46 | 47 | static DECLFW(UNLCC21Write2) { 48 | latche = V; 49 | Sync(); 50 | } 51 | 52 | static void UNLCC21Power(void) { 53 | latche = 0; 54 | Sync(); 55 | SetReadHandler(0x8000, 0xFFFF, CartBR); 56 | SetWriteHandler(0x8001, 0xFFFF, UNLCC21Write1); 57 | SetWriteHandler(0x8000, 0x8000, UNLCC21Write2); // another one many-in-1 mapper, there is a lot of similar carts with little different wirings 58 | } 59 | 60 | static void StateRestore(int version) { 61 | Sync(); 62 | } 63 | 64 | void UNLCC21_Init(CartInfo *info) { 65 | info->Power = UNLCC21Power; 66 | GameStateRestore = StateRestore; 67 | AddExState(&StateRegs, ~0, 0, 0); 68 | } 69 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/mmc3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZRZ-Unknow/os-workbench/66ed9543bb060a8b77d446f303997138a0648a54/abstract-machine/apps/fceux/src/boards/mmc3.cpp -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/mmc3.h: -------------------------------------------------------------------------------- 1 | extern uint8 MMC3_cmd; 2 | extern uint8 mmc3opts; 3 | extern uint8 A000B; 4 | extern uint8 A001B; 5 | extern uint8 EXPREGS[8]; 6 | extern uint8 DRegBuf[8]; 7 | 8 | #undef IRQCount 9 | #undef IRQLatch 10 | #undef IRQa 11 | extern uint8 IRQCount,IRQLatch,IRQa; 12 | extern uint8 IRQReload; 13 | 14 | extern void (*pwrap)(uint32 A, uint8 V); 15 | extern void (*cwrap)(uint32 A, uint8 V); 16 | extern void (*mwrap)(uint8 V); 17 | 18 | void GenMMC3Power(void); 19 | void GenMMC3Restore(int version); 20 | void MMC3RegReset(void); 21 | void FixMMC3PRG(int V); 22 | void FixMMC3CHR(int V); 23 | DECLFW(MMC3_CMDWrite); 24 | DECLFW(MMC3_IRQWrite); 25 | 26 | void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); 27 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/novel.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 latch; 24 | 25 | static void DoNovel(void) { 26 | setprg32(0x8000, latch & 3); 27 | setchr8(latch & 7); 28 | } 29 | 30 | static DECLFW(NovelWrite) { 31 | latch = A & 0xFF; 32 | DoNovel(); 33 | } 34 | 35 | static void NovelReset(void) { 36 | SetWriteHandler(0x8000, 0xFFFF, NovelWrite); 37 | SetReadHandler(0x8000, 0xFFFF, CartBR); 38 | setprg32(0x8000, 0); 39 | setchr8(0); 40 | } 41 | 42 | static void NovelRestore(int version) { 43 | DoNovel(); 44 | } 45 | 46 | void Novel_Init(CartInfo *info) { 47 | AddExState(&latch, 1, 0, "L1"); 48 | info->Power = NovelReset; 49 | GameStateRestore = NovelRestore; 50 | } 51 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/onebus.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZRZ-Unknow/os-workbench/66ed9543bb060a8b77d446f303997138a0648a54/abstract-machine/apps/fceux/src/boards/onebus.cpp -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/rt-01.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2016 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * Test Ver. 1.01 Dlya Proverki TV Pristavok (RT-01, by SS aka Snake) 21 | * A simple board with 16K PRG ROM + 2K CHR ROM with no mapper, hardwired mirroring 22 | * PRG EPROM has copy protected areas with "weak bits", which is tested at some 23 | * points of the program. Trying to simalate "weak bits" behaviour 24 | * 25 | */ 26 | 27 | #include "mapinc.h" 28 | 29 | extern u64 xoroshiro128plus_next(); // deterministic random 30 | 31 | static DECLFR(UNLRT01Read) { 32 | // u16 i, prot_areas[2][2] = { 33 | // { 0x8E80, 0x8EFF }, 34 | // { 0xFE80, 0xFEFF }, 35 | // }; 36 | if(((A >= 0xCE80) && (A < 0xCF00)) || 37 | ((A >= 0xFE80) && (A < 0xFF00))) { 38 | return 0xF2 | (xoroshiro128plus_next() & 0x0D); 39 | } else 40 | return CartBR(A); 41 | } 42 | 43 | static void UNLRT01Power(void) { 44 | setprg16(0x8000, 0); 45 | setprg16(0xC000, 0); 46 | setchr2(0x0000,0); 47 | setchr2(0x0800,0); 48 | setchr2(0x1000,0); 49 | setchr2(0x1800,0); 50 | SetReadHandler(0x8000, 0xFFFF, UNLRT01Read); 51 | } 52 | 53 | void UNLRT01_Init(CartInfo *info) { 54 | info->Power = UNLRT01Power; 55 | } 56 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/sa-9602b.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | #include "mmc3.h" 23 | 24 | static void SA9602BPW(uint32 A, uint8 V) { 25 | setprg8r(EXPREGS[1], A, V & 0x3F); 26 | if (MMC3_cmd & 0x40) 27 | setprg8r(0, 0x8000, ~(1)); 28 | else 29 | setprg8r(0, 0xc000, ~(1)); 30 | setprg8r(0, 0xe000, ~(0)); 31 | } 32 | 33 | static DECLFW(SA9602BWrite) { 34 | switch (A & 0xe001) { 35 | case 0x8000: EXPREGS[0] = V; break; 36 | case 0x8001: 37 | if ((EXPREGS[0] & 7) < 6) { 38 | EXPREGS[1] = V >> 6; 39 | FixMMC3PRG(MMC3_cmd); 40 | } 41 | break; 42 | } 43 | MMC3_CMDWrite(A, V); 44 | } 45 | 46 | static void SA9602BPower(void) { 47 | EXPREGS[0] = EXPREGS[1] = 0; 48 | GenMMC3Power(); 49 | SetReadHandler(0x8000, 0xFFFF, CartBR); 50 | SetWriteHandler(0x8000, 0xBFFF, SA9602BWrite); 51 | } 52 | 53 | void SA9602B_Init(CartInfo *info) { 54 | GenMMC3_Init(info, 512, 0, 0, 0); 55 | pwrap = SA9602BPW; 56 | mmc3opts |= 2; 57 | info->SaveGame[0] = UNIFchrrama; 58 | info->SaveGameLen[0] = 32 * 1024; 59 | info->Power = SA9602BPower; 60 | AddExState(EXPREGS, 2, 0, "EXPR"); 61 | } 62 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/t-262.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2006 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "mapinc.h" 22 | 23 | static uint8 bank, base, lock, mirr, mode; 24 | static SFORMAT StateRegs[] = 25 | { 26 | { &bank, 1, "BANK" }, 27 | { &base, 1, "BASE" }, 28 | { &lock, 1, "LOCK" }, 29 | { &mirr, 1, "MIRR" }, 30 | { &mode, 1, "MODE" }, 31 | { 0 } 32 | }; 33 | 34 | static void Sync(void) { 35 | setchr8(0); 36 | setprg16(0x8000, base | bank); 37 | setprg16(0xC000, base | (mode ? bank : 7)); 38 | setmirror(mirr); 39 | } 40 | 41 | static DECLFW(BMCT262Write) { 42 | if (!lock) { 43 | base = ((A & 0x60) >> 2) | ((A & 0x100) >> 3); 44 | mode = A & 0x80; 45 | mirr = ((A & 2) >> 1) ^ 1; 46 | lock = (A & 0x2000) >> 13; 47 | } 48 | bank = V & 7; 49 | Sync(); 50 | } 51 | 52 | static void BMCT262Power(void) { 53 | lock = bank = base = mode = 0; 54 | Sync(); 55 | SetWriteHandler(0x8000, 0xFFFF, BMCT262Write); 56 | SetReadHandler(0x8000, 0xFFFF, CartBR); 57 | } 58 | 59 | static void BMCT262Reset(void) { 60 | lock = bank = base = mode = 0; 61 | Sync(); 62 | } 63 | 64 | static void BMCT262Restore(int version) { 65 | Sync(); 66 | } 67 | 68 | void BMCT262_Init(CartInfo *info) { 69 | info->Power = BMCT262Power; 70 | info->Reset = BMCT262Reset; 71 | GameStateRestore = BMCT262Restore; 72 | AddExState(&StateRegs, ~0, 0, 0); 73 | } 74 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/boards/vrc1.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2012 CaH4e3 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * VRC-1 21 | * 22 | */ 23 | 24 | #include "mapinc.h" 25 | 26 | static uint8 preg[3], creg[2], mode; 27 | static SFORMAT StateRegs[] = 28 | { 29 | { &mode, 1, "MODE" }, 30 | { creg, 2, "CREG" }, 31 | { preg, 3, "PREG" }, 32 | { 0 } 33 | }; 34 | 35 | static void Sync(void) { 36 | setprg8(0x8000, preg[0]); 37 | setprg8(0xA000, preg[1]); 38 | setprg8(0xC000, preg[2]); 39 | setprg8(0xE000, ~0); 40 | setchr4(0x0000, creg[0] | ((mode & 2) << 3)); 41 | setchr4(0x1000, creg[1] | ((mode & 4) << 2)); 42 | setmirror((mode & 1) ^ 1); 43 | } 44 | 45 | static DECLFW(M75Write) { 46 | switch (A & 0xF000) { 47 | case 0x8000: preg[0] = V; Sync(); break; 48 | case 0x9000: mode = V; Sync(); break; 49 | case 0xA000: preg[1] = V; Sync(); break; 50 | case 0xC000: preg[2] = V; Sync(); break; 51 | case 0xE000: creg[0] = V & 0xF; Sync(); break; 52 | case 0xF000: creg[1] = V & 0xF; Sync(); break; 53 | } 54 | } 55 | 56 | static void M75Power(void) { 57 | Sync(); 58 | SetWriteHandler(0x8000, 0xFFFF, M75Write); 59 | SetReadHandler(0x8000, 0xFFFF, CartBR); 60 | } 61 | 62 | static void StateRestore(int version) { 63 | Sync(); 64 | } 65 | 66 | void Mapper75_Init(CartInfo *info) { 67 | info->Power = M75Power; 68 | AddExState(&StateRegs, ~0, 0, 0); 69 | GameStateRestore = StateRestore; 70 | } 71 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drawing.h: -------------------------------------------------------------------------------- 1 | void DrawTextLineBG(uint8 *dest); 2 | void DrawMessage(bool beforeMovie); 3 | void FCEU_DrawRecordingStatus(uint8* XBuf); 4 | void FCEU_DrawNumberRow(uint8 *XBuf, int *nstatus, int cur); 5 | void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor); 6 | void DrawTextTransWH(uint8 *dest, int width, uint8 *textmsg, uint8 fgcolor, int max_w, int max_h, int border); 7 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/common/vidblit.h: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int eefx, int specfilt, int specfilteropt); 22 | void SetPaletteBlitToHigh(uint8 *src); 23 | void KillBlitToHigh(void); 24 | void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, int yscale); 25 | void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, int yscale, int efx, int special); 26 | 27 | void Blit32to24(uint32 *src, uint8 *dest, int xr, int yr, int dpitch); 28 | void Blit32to16(uint32 *src, uint16 *dest, int xr, int yr, int dpitch, 29 | int shiftr[3], int shiftl[3]); 30 | 31 | 32 | u32 ModernDeemphColorMap(u8* src, u8* srcbuf, int xscale, int yscale); -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/dface.h: -------------------------------------------------------------------------------- 1 | #include "input.h" 2 | 3 | void DoDriverArgs(void); 4 | 5 | int InitSound(); 6 | void WriteSound(int32 *Buffer, int Count); 7 | int KillSound(void); 8 | uint32 GetMaxSound(void); 9 | uint32 GetWriteSound(void); 10 | 11 | void SilenceSound(int s); /* DOS and SDL */ 12 | 13 | int InitJoysticks(void); 14 | int KillJoysticks(void); 15 | uint32 *GetJSOr(void); 16 | 17 | int InitVideo(FCEUGI *gi); 18 | int KillVideo(void); 19 | void BlitScreen(uint8 *XBuf); 20 | void LockConsole(void); 21 | void UnlockConsole(void); 22 | void ToggleFS(); /* SDL */ 23 | 24 | int LoadGame(const char *path); 25 | //int CloseGame(void); 26 | 27 | void Giggles(int); 28 | void DoFun(void); 29 | 30 | int FCEUD_NetworkConnect(void); 31 | 32 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/icon.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * icon_xpm[] = { 3 | "32 32 20 1", 4 | " c None", 5 | ". c #040204", 6 | "+ c #84A284", 7 | "@ c #C42204", 8 | "# c #8482C4", 9 | "$ c #FCFEFC", 10 | "% c #848284", 11 | "& c #648284", 12 | "* c #646284", 13 | "= c #444244", 14 | "- c #A4A284", 15 | "; c #C4A284", 16 | "> c #C48284", 17 | ", c #A4CAF4", 18 | "' c #244244", 19 | ") c #444204", 20 | "! c #442204", 21 | "~ c #446244", 22 | "{ c #646244", 23 | "] c #644244", 24 | " ", 25 | " ........ ", 26 | " ............... ", 27 | " ........................ ", 28 | " ...........................+ ", 29 | " ............@@..@@........... ", 30 | " .#............@@............$$ ", 31 | " .##..........@@.@.....$$%%%%$$ ", 32 | " &...........@....@$$$$$$%%&%$$ ", 33 | " *&...............$$$$$$$%%&%$$ ", 34 | " =&*.......-;;>;...$$,$$$%**&.. ", 35 | " '&&..............$$,,,%=)!~.. ", 36 | " ~&&............-%%##%*.~'=%& ", 37 | " *&&.....+%%****&&%%&*.&!!' ", 38 | " **&%&***********&&&*~{'= ", 39 | " ********=**~**~**~ ", 40 | " *****~******] ", 41 | " **~***]' ", 42 | " ~]== ", 43 | " ", 44 | " ..... .... .... .. ..@@ @@", 45 | " ..... .... .... .. ..@@@ @@@", 46 | " .. .. .. .. .. @@@ @@@ ", 47 | " .... .. .. .. .. @@@@@@ ", 48 | " .... .. ... .. .. @@@@ ", 49 | " .. .. ... .. .. @@@@ ", 50 | " .. .. .. .. .. @@@@@@ ", 51 | " .. .. .. .. .. @@@ @@@ ", 52 | " .. .... .... .....@@@ @@@", 53 | " .. .... .... ... @@ @@", 54 | " ", 55 | " "}; 56 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/input.h: -------------------------------------------------------------------------------- 1 | #ifndef _aosdfjk02fmasf 2 | #define _aosdfjk02fmasf 3 | 4 | #define MAXBUTTCONFIG 4 5 | typedef struct { 6 | uint8 ButtType[MAXBUTTCONFIG]; 7 | uint8 DeviceNum[MAXBUTTCONFIG]; 8 | uint16 ButtonNum[MAXBUTTCONFIG]; 9 | uint32 NumC; 10 | //uint64 DeviceID[MAXBUTTCONFIG]; /* TODO */ 11 | } ButtConfig; 12 | 13 | 14 | extern int NoWaiting; 15 | void ParseGIInput(FCEUGI *GI); 16 | int ButtonConfigBegin(); 17 | void ButtonConfigEnd(); 18 | void ConfigButton(char *text, ButtConfig *bc); 19 | int DWaitButton(const uint8 *text, ButtConfig *bc, int wb); 20 | 21 | #define BUTTC_KEYBOARD 0x00 22 | #define BUTTC_JOYSTICK 0x01 23 | #define BUTTC_MOUSE 0x02 24 | 25 | #define FCFGD_GAMEPAD 1 26 | #define FCFGD_POWERPAD 2 27 | #define FCFGD_HYPERSHOT 3 28 | #define FCFGD_QUIZKING 4 29 | 30 | #define SDL_FCEU_HOTKEY_EVENT SDL_USEREVENT 31 | 32 | void InitInputInterface(void); 33 | void InputUserActiveFix(void); 34 | 35 | extern bool replaceP2StartWithMicrophone; 36 | extern ButtConfig GamePadConfig[4][10]; 37 | //extern ButtConfig powerpadsc[2][12]; 38 | //extern ButtConfig QuizKingButtons[6]; 39 | //extern ButtConfig FTrainerButtons[12]; 40 | 41 | void IncreaseEmulationSpeed(void); 42 | void DecreaseEmulationSpeed(void); 43 | 44 | int DTestButtonJoy(ButtConfig *bc); 45 | 46 | void FCEUD_UpdateInput(void); 47 | 48 | void UpdateInput(); 49 | 50 | const char* ButtonName(const ButtConfig* bc, int which); 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/keyscan.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MKK(k) _KEY_##k 4 | #define MKK_COUNT 256 5 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/sdl-throttle.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Handles emulation speed throttling using the SDL timing functions. 3 | 4 | #include "sdl.h" 5 | #include "throttle.h" 6 | 7 | static uint64 Lasttime, Nexttime; 8 | static int32 desired_fps; 9 | static int InFrame; 10 | 11 | /** 12 | * Refreshes the FPS throttling variables. 13 | */ 14 | void 15 | RefreshThrottleFPS() 16 | { 17 | desired_fps = FCEUI_GetDesiredFPS(); 18 | 19 | Lasttime=0; 20 | Nexttime=0; 21 | InFrame=0; 22 | } 23 | 24 | /** 25 | * Perform FPS speed throttling by delaying until the next time slot. 26 | */ 27 | int 28 | SpeedThrottle() 29 | { 30 | uint64 time_left; 31 | uint64 cur_time = FCEUD_GetTime(); 32 | 33 | if(!Lasttime) 34 | Lasttime = cur_time; 35 | 36 | if(!InFrame) 37 | { 38 | InFrame = 1; 39 | Nexttime = Lasttime + 1000 / desired_fps; 40 | } 41 | 42 | if(cur_time >= Nexttime) 43 | time_left = 0; 44 | else 45 | time_left = Nexttime - cur_time; 46 | 47 | if(time_left > 50) 48 | { 49 | time_left = 50; 50 | /* In order to keep input responsive, don't wait too long at once */ 51 | /* 50 ms wait gives us a 20 Hz responsetime which is nice. */ 52 | } 53 | else 54 | InFrame = 0; 55 | 56 | //delay 57 | uint64 now; 58 | while ((now = FCEUD_GetTime()) - cur_time < time_left) 59 | ; 60 | 61 | if(!InFrame) 62 | { 63 | Lasttime = now; 64 | return 0; /* Done waiting */ 65 | } 66 | return 1; /* Must still wait some more */ 67 | } 68 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/sdl-video.h: -------------------------------------------------------------------------------- 1 | #ifndef __FCEU_SDL_VIDEO_H 2 | #define __FCEU_SDL_VIDEO_H 3 | 4 | uint32 PtoV(uint16 x, uint16 y); 5 | bool FCEUD_ShouldDrawInputAids(); 6 | bool FCEUI_AviDisableMovieMessages(); 7 | bool FCEUI_AviEnableHUDrecording(); 8 | void FCEUI_SetAviEnableHUDrecording(bool enable); 9 | bool FCEUI_AviDisableMovieMessages(); 10 | void FCEUI_SetAviDisableMovieMessages(bool disable); 11 | #endif 12 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/sdl.h: -------------------------------------------------------------------------------- 1 | #ifndef __FCEU_SDL_H 2 | #define __FCEU_SDL_H 3 | 4 | #include "main.h" 5 | #include "dface.h" 6 | #include "input.h" 7 | 8 | // I'm using this as a #define so the compiler can optimize the 9 | // modulo operation 10 | #define PERIODIC_SAVE_INTERVAL 5000 // milliseconds 11 | 12 | const int INVALID_STATE = 99; 13 | 14 | extern int noGui; 15 | extern int isloaded; 16 | 17 | extern int dendy; 18 | extern int pal_emulation; 19 | extern bool swapDuty; 20 | 21 | int LoadGame(const char *path); 22 | int CloseGame(void); 23 | void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); 24 | uint64 FCEUD_GetTime(); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/drivers/sdl/throttle.h: -------------------------------------------------------------------------------- 1 | void RefreshThrottleFPS(); 2 | int SpeedThrottle(void); 3 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/emufile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 DeSmuME team 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include "emufile.h" 24 | 25 | #ifdef __NO_FILE_SYSTEM__ 26 | 27 | #include "roms.h" // from $(AM_HOME)/share/games/nes/gen/ 28 | 29 | void EMUFILE_FILE::open(const char* fname, const char* mode) { 30 | struct rom *cur = &roms[0]; 31 | int found = 0; 32 | for (int i = 1; i < nroms; i++) { 33 | if (strcmp(roms[i].name, fname) == 0) { 34 | cur = &roms[i]; 35 | found = 1; 36 | } 37 | } 38 | 39 | if (found) { printf("Found ROM '%s'\n", fname); } 40 | else { printf("ROM '%s' not found, using default ROM '%s'\n", fname, cur->name); } 41 | 42 | this->data = (u8 *)cur->body; 43 | this->filesize = (int)*(cur->size); 44 | this->curpos = 0; 45 | this->fname = cur->name; 46 | strcpy(this->mode,mode); 47 | this->failbit = false; 48 | } 49 | 50 | #else 51 | 52 | void EMUFILE_FILE::open(const char* fname, const char* mode) 53 | { 54 | fp = fopen(fname,mode); 55 | if(!fp) 56 | { 57 | failbit = true; 58 | } 59 | this->fname = fname; 60 | strcpy(this->mode,mode); 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/palette.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | uint8 r,g,b; 3 | } pal; 4 | 5 | extern pal *palo; 6 | void FCEU_ResetPalette(void); 7 | 8 | void FCEU_ResetPalette(void); 9 | void FCEU_LoadGamePalette(void); 10 | void FCEU_DrawNTSCControlBars(uint8 *XBuf); 11 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/palettes/rp2c04001.h: -------------------------------------------------------------------------------- 1 | {0xfc, 0xc4, 0xd8}, 2 | {0x40, 0x88, 0xfc}, 3 | {0xd8, 0x28, 0x00}, 4 | {0x5c, 0x94, 0xfc}, 5 | {0x00, 0x80, 0x88}, 6 | {0x00, 0x44, 0x00}, 7 | {0x00, 0x00, 0x00}, 8 | {0xe4, 0x00, 0x58}, 9 | {0xfc, 0xfc, 0xfc}, 10 | {0x74, 0x74, 0x74}, 11 | {0xfc, 0x98, 0x38}, 12 | {0xa8, 0x00, 0x10}, 13 | {0x8c, 0x00, 0x74}, 14 | {0xfc, 0x98, 0x38}, 15 | {0x40, 0x2c, 0x00}, 16 | {0xfc, 0xfc, 0xfc}, 17 | {0x3c, 0xbc, 0xfc}, 18 | {0x00, 0x00, 0x00}, 19 | {0x00, 0x00, 0x00}, 20 | {0x80, 0xd0, 0x10}, 21 | {0x9c, 0xfc, 0xf0}, 22 | {0xc4, 0xd4, 0xfc}, 23 | {0xfc, 0xbc, 0xb0}, 24 | {0x20, 0x38, 0xec}, 25 | {0x00, 0x00, 0x00}, 26 | {0x58, 0xf8, 0x98}, 27 | {0x00, 0x00, 0x00}, 28 | {0x00, 0x00, 0x00}, 29 | {0xfc, 0xfc, 0xfc}, 30 | {0xbc, 0xbc, 0xbc}, 31 | {0xf4, 0x78, 0xfc}, 32 | {0x24, 0x18, 0x8c}, 33 | {0x00, 0x00, 0x00}, 34 | {0xa8, 0xe4, 0xfc}, 35 | {0x00, 0x00, 0x00}, 36 | {0x4c, 0xdc, 0x48}, 37 | {0x00, 0xe8, 0xd8}, 38 | {0x18, 0x3c, 0x5c}, 39 | {0x00, 0x00, 0x00}, 40 | {0x00, 0x00, 0x00}, 41 | {0x00, 0x00, 0x00}, 42 | {0x7c, 0x08, 0x00}, 43 | {0xfc, 0xc4, 0xfc}, 44 | {0xa4, 0x00, 0x00}, 45 | {0x80, 0x00, 0xf0}, 46 | {0x00, 0x00, 0xa8}, 47 | {0xfc, 0x74, 0x60}, 48 | {0x00, 0x00, 0x00}, 49 | {0x00, 0x00, 0x00}, 50 | {0x00, 0x94, 0x00}, 51 | {0xbc, 0xbc, 0xbc}, 52 | {0x00, 0x50, 0x00}, 53 | {0xe0, 0xfc, 0xa0}, 54 | {0x00, 0x00, 0x00}, 55 | {0xfc, 0xd8, 0xa8}, 56 | {0xc8, 0x4c, 0x0c}, 57 | {0x00, 0x00, 0x00}, 58 | {0x00, 0x70, 0xec}, 59 | {0x00, 0x44, 0x00}, 60 | {0x00, 0x00, 0x00}, 61 | {0xe0, 0xfc, 0xa0}, 62 | {0xfc, 0x74, 0xb4}, 63 | {0x88, 0x70, 0x00}, 64 | {0x00, 0x00, 0x00}, 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/palettes/rp2c04002.h: -------------------------------------------------------------------------------- 1 | {0x00, 0x00, 0x00}, 2 | {0xfc, 0x98, 0x38}, 3 | {0x88, 0x70, 0x00}, 4 | {0x00, 0x00, 0x00}, 5 | {0xa8, 0xf0, 0xbc}, 6 | {0xfc, 0x74, 0xb4}, 7 | {0x00, 0x00, 0x00}, 8 | {0xa8, 0xe4, 0xfc}, 9 | {0xd8, 0x28, 0x00}, 10 | {0x80, 0x00, 0xf0}, 11 | {0xfc, 0xe4, 0xa0}, 12 | {0xfc, 0xc4, 0xfc}, 13 | {0xfc, 0xfc, 0xfc}, 14 | {0x40, 0x88, 0xfc}, 15 | {0x00, 0x00, 0x00}, 16 | {0x00, 0x3c, 0x14}, 17 | {0x00, 0x00, 0x00}, 18 | {0x3c, 0xbc, 0xfc}, 19 | {0xa4, 0x00, 0x00}, 20 | {0x00, 0x00, 0x00}, 21 | {0x00, 0x90, 0x38}, 22 | {0x80, 0xd0, 0x10}, 23 | {0x00, 0x00, 0x00}, 24 | {0x5c, 0x94, 0xfc}, 25 | {0x00, 0x00, 0x00}, 26 | {0xf4, 0x78, 0xfc}, 27 | {0x00, 0x00, 0x00}, 28 | {0x58, 0xf8, 0x98}, 29 | {0x00, 0x00, 0x00}, 30 | {0x40, 0x2c, 0x00}, 31 | {0x00, 0x00, 0x00}, 32 | {0x44, 0x00, 0x9c}, 33 | {0x00, 0x00, 0x00}, 34 | {0xfc, 0xbc, 0xb0}, 35 | {0xfc, 0x74, 0x60}, 36 | {0xd4, 0xc8, 0xfc}, 37 | {0x00, 0x70, 0xec}, 38 | {0x00, 0x00, 0x00}, 39 | {0xbc, 0xbc, 0xbc}, 40 | {0x00, 0x00, 0xa8}, 41 | {0xbc, 0x00, 0xbc}, 42 | {0x00, 0x00, 0x00}, 43 | {0x74, 0x74, 0x74}, 44 | {0x00, 0x44, 0x00}, 45 | {0x20, 0x38, 0xec}, 46 | {0x00, 0x00, 0x00}, 47 | {0xfc, 0xd8, 0xa8}, 48 | {0xfc, 0xfc, 0xfc}, 49 | {0x00, 0x00, 0x00}, 50 | {0x00, 0x00, 0x00}, 51 | {0x4c, 0xdc, 0x48}, 52 | {0xc8, 0x4c, 0x0c}, 53 | {0x18, 0x3c, 0x5c}, 54 | {0x24, 0x18, 0x8c}, 55 | {0xe4, 0x00, 0x58}, 56 | {0x00, 0x94, 0x00}, 57 | {0x00, 0x00, 0x00}, 58 | {0x00, 0xe8, 0xd8}, 59 | {0x7c, 0x08, 0x00}, 60 | {0xfc, 0xd8, 0xa8}, 61 | {0x00, 0x00, 0x00}, 62 | {0xa8, 0x00, 0x10}, 63 | {0x00, 0x50, 0x00}, 64 | {0x74, 0x74, 0x74}, 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/palettes/rp2c04003.h: -------------------------------------------------------------------------------- 1 | {0x44, 0x00, 0x9c}, 2 | {0x00, 0x00, 0x00}, 3 | {0x00, 0x00, 0x00}, 4 | {0x74, 0x74, 0x74}, 5 | {0x00, 0xa8, 0x00}, 6 | {0xfc, 0xfc, 0xfc}, 7 | {0xa8, 0xe4, 0xfc}, 8 | {0x00, 0x44, 0x00}, 9 | {0x24, 0x18, 0x8c}, 10 | {0x00, 0x00, 0x00}, 11 | {0xfc, 0xbc, 0xb0}, 12 | {0x40, 0x2c, 0x00}, 13 | {0xe4, 0x00, 0x58}, 14 | {0x00, 0x00, 0x00}, 15 | {0x00, 0x00, 0x00}, 16 | {0xfc, 0xfc, 0xfc}, 17 | {0x5c, 0x94, 0xfc}, 18 | {0x00, 0x80, 0x88}, 19 | {0x00, 0x00, 0x00}, 20 | {0x20, 0x38, 0xec}, 21 | {0x00, 0x94, 0x00}, 22 | {0x88, 0x70, 0x00}, 23 | {0xc8, 0x4c, 0x0c}, 24 | {0x00, 0x90, 0x38}, 25 | {0x74, 0x74, 0x74}, 26 | {0x00, 0x00, 0x00}, 27 | {0x00, 0x00, 0x00}, 28 | {0x00, 0x00, 0xa8}, 29 | {0xd8, 0x28, 0x00}, 30 | {0xa4, 0x00, 0x00}, 31 | {0x00, 0x00, 0x00}, 32 | {0xfc, 0xc4, 0xd8}, 33 | {0x40, 0x88, 0xfc}, 34 | {0x00, 0x00, 0x00}, 35 | {0x00, 0x00, 0x00}, 36 | {0xfc, 0xd8, 0xa8}, 37 | {0x00, 0x00, 0x00}, 38 | {0xfc, 0x98, 0x38}, 39 | {0xfc, 0x74, 0x60}, 40 | {0xfc, 0xfc, 0xfc}, 41 | {0x80, 0xd0, 0x10}, 42 | {0x00, 0x00, 0x00}, 43 | {0x3c, 0xbc, 0xfc}, 44 | {0xf4, 0x78, 0xfc}, 45 | {0x00, 0x70, 0xec}, 46 | {0x00, 0x00, 0x00}, 47 | {0x00, 0x00, 0x00}, 48 | {0x00, 0x00, 0x00}, 49 | {0x00, 0xe8, 0xd8}, 50 | {0x00, 0x00, 0x00}, 51 | {0x00, 0x00, 0x00}, 52 | {0x00, 0x00, 0x00}, 53 | {0x7c, 0x08, 0x00}, 54 | {0x4c, 0xdc, 0x48}, 55 | {0xf0, 0xbc, 0x3c}, 56 | {0x00, 0x00, 0x00}, 57 | {0x00, 0x50, 0x00}, 58 | {0x00, 0x00, 0x00}, 59 | {0xc4, 0xd4, 0xfc}, 60 | {0xfc, 0xd8, 0xa8}, 61 | {0x80, 0x00, 0xf0}, 62 | {0x00, 0x00, 0x00}, 63 | {0x00, 0x00, 0x00}, 64 | {0x18, 0x3c, 0x5c}, 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/palettes/rp2c05004.h: -------------------------------------------------------------------------------- 1 | {0x88, 0x70, 0x00}, 2 | {0x00, 0x00, 0x00}, 3 | {0x00, 0x80, 0x88}, 4 | {0xf0, 0xbc, 0x3c}, 5 | {0x00, 0x00, 0x00}, 6 | {0x00, 0x00, 0x00}, 7 | {0x24, 0x18, 0x8c}, 8 | {0xc8, 0x4c, 0x0c}, 9 | {0xbc, 0xbc, 0xbc}, 10 | {0x00, 0x00, 0x00}, 11 | {0x4c, 0xdc, 0x48}, 12 | {0x00, 0x00, 0x00}, 13 | {0xfc, 0xbc, 0xb0}, 14 | {0xfc, 0xd8, 0xa8}, 15 | {0x00, 0xa8, 0x00}, 16 | {0x00, 0x00, 0x00}, 17 | {0xfc, 0x74, 0xb4}, 18 | {0x00, 0x00, 0x00}, 19 | {0x20, 0x38, 0xec}, 20 | {0x00, 0x00, 0x00}, 21 | {0x00, 0x00, 0x00}, 22 | {0x00, 0x00, 0x00}, 23 | {0x00, 0x00, 0x00}, 24 | {0xfc, 0x74, 0x60}, 25 | {0x00, 0x00, 0x00}, 26 | {0x00, 0x00, 0x00}, 27 | {0x5c, 0x94, 0xfc}, 28 | {0x00, 0x94, 0x00}, 29 | {0x00, 0x00, 0x00}, 30 | {0x00, 0x00, 0x00}, 31 | {0xa8, 0xf0, 0xbc}, 32 | {0x3c, 0xbc, 0xfc}, 33 | {0xa8, 0x00, 0x10}, 34 | {0x00, 0x50, 0x00}, 35 | {0x7c, 0x08, 0x00}, 36 | {0x00, 0x00, 0xa8}, 37 | {0x80, 0x00, 0xf0}, 38 | {0x00, 0x00, 0x00}, 39 | {0x74, 0x74, 0x74}, 40 | {0xe4, 0x00, 0x58}, 41 | {0x18, 0x3c, 0x5c}, 42 | {0x00, 0x00, 0x00}, 43 | {0x00, 0x70, 0xec}, 44 | {0x00, 0x00, 0x00}, 45 | {0x00, 0x00, 0x00}, 46 | {0xfc, 0xe4, 0xa0}, 47 | {0x00, 0x00, 0x00}, 48 | {0x00, 0x00, 0x00}, 49 | {0x00, 0x00, 0x00}, 50 | {0x00, 0x00, 0x00}, 51 | {0x40, 0x2c, 0x00}, 52 | {0xd8, 0x28, 0x00}, 53 | {0x00, 0x00, 0x00}, 54 | {0x00, 0x00, 0x00}, 55 | {0xfc, 0xfc, 0xfc}, 56 | {0x9c, 0xfc, 0xf0}, 57 | {0x00, 0x00, 0x00}, 58 | {0xfc, 0x98, 0x38}, 59 | {0x00, 0x00, 0x00}, 60 | {0xa8, 0xe4, 0xfc}, 61 | {0x80, 0xd0, 0x10}, 62 | {0x00, 0x00, 0x00}, 63 | {0xfc, 0xfc, 0xfc}, 64 | {0x00, 0x44, 0x00}, 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/ppu.h: -------------------------------------------------------------------------------- 1 | void FCEUPPU_Init(void); 2 | void FCEUPPU_Reset(void); 3 | void FCEUPPU_Power(void); 4 | int FCEUPPU_Loop(int skip); 5 | 6 | void FCEUPPU_LineUpdate(); 7 | void FCEUPPU_SetVideoSystem(int w); 8 | 9 | extern void (*PPU_hook)(uint32 A); 10 | extern void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void); 11 | 12 | int newppu_get_scanline(); 13 | int newppu_get_dot(); 14 | void newppu_hacky_emergency_reset(); 15 | 16 | /* For cart.c and banksw.h, mostly */ 17 | extern uint8 NTARAM[0x800], *vnapage[4]; 18 | extern uint8 PPUNTARAM; 19 | extern uint8 PPUCHRRAM; 20 | 21 | void FCEUPPU_SaveState(void); 22 | void FCEUPPU_LoadState(int version); 23 | uint32 FCEUPPU_PeekAddress(); 24 | uint8* FCEUPPU_GetCHR(uint32 vadr, uint32 refreshaddr); 25 | int FCEUPPU_GetAttr(int ntnum, int xt, int yt); 26 | void ppu_getScroll(int &xpos, int &ypos); 27 | 28 | 29 | #define FASTCALL 30 | 31 | void PPU_ResetHooks(); 32 | extern uint8 (FASTCALL *FFCEUX_PPURead)(uint32 A); 33 | extern void (*FFCEUX_PPUWrite)(uint32 A, uint8 V); 34 | extern uint8 FASTCALL FFCEUX_PPURead_Default(uint32 A); 35 | void FFCEUX_PPUWrite_Default(uint32 A, uint8 V); 36 | 37 | extern int g_rasterpos; 38 | extern uint8 PPU[4]; 39 | extern bool DMC_7bit; 40 | extern bool paldeemphswap; 41 | 42 | enum PPUPHASE { 43 | PPUPHASE_VBL, PPUPHASE_BG, PPUPHASE_OBJ 44 | }; 45 | 46 | extern PPUPHASE ppuphase; 47 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/pputile.inc: -------------------------------------------------------------------------------- 1 | uint8 *C; 2 | uint32 vadr; 3 | 4 | if (X1 >= 2) { 5 | uint16 *S = PALcache; 6 | uint32 pixdata; 7 | 8 | pixdata = ppulut1[(pshift[0] >> (8 - XOffset)) & 0xFF] | ppulut2[(pshift[1] >> (8 - XOffset)) & 0xFF]; 9 | 10 | pixdata |= ppulut3[XOffset | (atlatch << 3)]; 11 | 12 | uint16 *p = (uint16 *)P; 13 | p[0] = S[pixdata & 0xff]; 14 | pixdata >>= 8; 15 | p[1] = S[pixdata & 0xff]; 16 | pixdata >>= 8; 17 | p[2] = S[pixdata & 0xff]; 18 | pixdata >>= 8; 19 | p[3] = S[pixdata & 0xff]; 20 | 21 | P += 8; 22 | } 23 | 24 | vadr = (C0[RefreshAddr & 0x3ff] << 4) + vofs; // Fetch name table byte. 25 | 26 | if (RefreshAddr % 4 == 0) { 27 | uint8 zz = RefreshAddr >> 2; 28 | cc = (C0[0x3c0 | (zz & 0x7) | ((zz >> 2) & 0x38)] << 2) >> ((zz >> 2) & 0x4); // Fetch attribute table byte. 29 | } 30 | cc2 = (cc >> (RefreshAddr & 0x2)) & 0xc; 31 | 32 | atlatch >>= 2; 33 | atlatch |= cc2; 34 | 35 | pshift[0] <<= 8; 36 | pshift[1] <<= 8; 37 | 38 | 39 | C = VRAMADR(vadr); 40 | 41 | 42 | if(ScreenON) 43 | RENDER_LOGP(C); 44 | pshift[0] |= C[0]; 45 | if(ScreenON) 46 | RENDER_LOGP(C + 8); 47 | pshift[1] |= C[8]; 48 | 49 | if ((RefreshAddr & 0x1f) == 0x1f) { 50 | RefreshAddr ^= 0x41F; 51 | C0 = vnapage[(RefreshAddr >> 10) & 3]; 52 | } 53 | else 54 | RefreshAddr++; 55 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/state.h: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | struct SFORMAT 22 | { 23 | //a void* to the data or a void** to the data 24 | void *v; 25 | 26 | //size, plus flags 27 | uint32 s; 28 | 29 | //a string description of the element 30 | const char *desc; 31 | }; 32 | 33 | void ResetExState(void (*PreSave)(void),void (*PostSave)(void)); 34 | void AddExState(void *v, uint32 s, int type, const char *desc); 35 | 36 | //indicates that the value is a multibyte integer that needs to be put in the correct byte order 37 | #define FCEUSTATE_RLSB 0x80000000 38 | 39 | //void*v is actually a void** which will be indirected before reading 40 | #define FCEUSTATE_INDIRECT 0x40000000 41 | 42 | //all FCEUSTATE flags together so that we can mask them out and get the size 43 | #define FCEUSTATE_FLAGS (FCEUSTATE_RLSB|FCEUSTATE_INDIRECT) 44 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/unused.cpp: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "sound.h" 3 | 4 | uint32 soundtsoffs = 0; 5 | uint32 soundtsinc = 1; 6 | bool DMC_7bit = 0; 7 | EXPSOUND GameExpSound = {}; 8 | int32 WaveHi[40000] = {}; 9 | int32 Wave[2048+512] = {}; 10 | int32 nesincsize=0; 11 | uint8 *UNIFchrrama = 0; 12 | 13 | void AddExState(void *v, uint32 s, int type, const char *desc) { } 14 | void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p) { } 15 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/utils/general.cpp: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "../types.h" 22 | 23 | uint32 uppow2(uint32 n) 24 | { 25 | int x; 26 | 27 | for(x=31;x>=0;x--) 28 | if(n&(1< MD5DATA; 15 | 16 | void md5_starts( struct md5_context *ctx ); 17 | void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ); 18 | void md5_finish( struct md5_context *ctx, uint8 digest[16] ); 19 | 20 | /* Uses a static buffer, so beware of how it's used. */ 21 | char *md5_asciistr(MD5DATA& md5); 22 | 23 | #endif /* md5.h */ 24 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/utils/memory.h: -------------------------------------------------------------------------------- 1 | /* FCE Ultra - NES/Famicom Emulator 2 | * 3 | * Copyright notice for this file: 4 | * Copyright (C) 2002 Xodnizel 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* Various macros for faster memory stuff 22 | (at least that's the idea) 23 | */ 24 | 25 | #define FCEU_dwmemset(d,c,n) {int _x; for(_x=n-4;_x>=0;_x-=4) *(uint32 *)&(d)[_x]=c;} 26 | 27 | void *FCEU_malloc(uint32 size); // initialized to 0 28 | void *FCEU_gmalloc(uint32 size); // used by boards for WRAM etc, initialized to 0 (default) or other via RAMInitOption 29 | void FCEU_gfree(void *ptr); 30 | void FCEU_free(void *ptr); 31 | void FCEU_memmove(void *d, void *s, uint32 l); 32 | 33 | // wrapper for debugging when its needed, otherwise act like 34 | // normal malloc/free 35 | void *FCEU_dmalloc(uint32 size); 36 | void FCEU_dfree(void *ptr); 37 | -------------------------------------------------------------------------------- /abstract-machine/apps/fceux/src/utils/valuearray.h: -------------------------------------------------------------------------------- 1 | #ifndef _VALUEARRAY_H_ 2 | #define _VALUEARRAY_H_ 3 | 4 | template 5 | struct ValueArray 6 | { 7 | T data[N]; 8 | T &operator[](int index) { return data[index]; } 9 | static const int size = N; 10 | bool operator!=(ValueArray &other) { return !operator==(other); } 11 | bool operator==(ValueArray &other) 12 | { 13 | for(int i=0;i 5 | #include 6 | #include 7 | #include 8 | 9 | typedef uint8_t byte; 10 | typedef uint16_t word; 11 | typedef uint32_t dword; 12 | 13 | // Binary Operations 14 | bool common_bit_set(long long value, byte position); 15 | 16 | // Byte Bit Operations 17 | void common_set_bitb(byte *variable, byte position); 18 | void common_unset_bitb(byte *variable, byte position); 19 | void common_toggle_bitb(byte *variable, byte position); 20 | void common_modify_bitb(byte *variable, byte position, bool set); 21 | 22 | // Word Bit Operations 23 | void common_set_bitw(word *variable, byte position); 24 | void common_unset_bitw(word *variable, byte position); 25 | void common_toggle_bitw(word *variable, byte position); 26 | void common_modify_bitw(word *variable, byte position, bool set); 27 | 28 | // Double Word Bit Operations 29 | void common_set_bitd(dword *variable, byte position); 30 | void common_unset_bitd(dword *variable, byte position); 31 | void common_toggle_bitd(dword *variable, byte position); 32 | void common_modify_bitd(dword *variable, byte position, bool set); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/cpu-internal.h: -------------------------------------------------------------------------------- 1 | #ifndef CPU_INTERNAL_H 2 | #define CPU_INTERNAL_H 3 | 4 | #include "common.h" 5 | 6 | typedef enum { 7 | carry_flag = 0x01, 8 | zero_flag = 0x02, 9 | interrupt_flag = 0x04, 10 | decimal_flag = 0x08, 11 | break_flag = 0x10, 12 | unused_flag = 0x20, 13 | overflow_flag = 0x40, 14 | negative_flag = 0x80 15 | } cpu_p_flag; 16 | 17 | typedef enum { 18 | carry_bp = 0, 19 | zero_bp = 1, 20 | interrupt_bp = 2, 21 | decimal_bp = 3, 22 | break_bp = 4, 23 | unused_bp = 5, 24 | overflow_bp = 6, 25 | negative_bp = 7 26 | } cpu_p_bp; 27 | 28 | typedef struct { 29 | word PC; // Program Counter, 30 | byte SP; // Stack Pointer, 31 | byte A, X, Y; // Registers 32 | byte P; // Flag Register 33 | } CPU_STATE; 34 | 35 | extern CPU_STATE cpu; 36 | 37 | extern byte CPU_RAM[0x8000]; 38 | extern int op_value, op_address; // Arguments for current instruction 39 | extern int op_cycles; // Additional instruction cycles used (e.g. when paging occurs) 40 | 41 | byte cpu_ram_read(word address); 42 | void cpu_ram_write(word address, byte data); 43 | 44 | // Interrupt Addresses 45 | word cpu_nmi_interrupt_address(); 46 | word cpu_reset_interrupt_address(); 47 | word cpu_irq_interrupt_address(); 48 | 49 | // CPU Adressing Modes 50 | void cpu_address_implied(); 51 | void cpu_address_immediate(); 52 | void cpu_address_zero_page(); 53 | void cpu_address_zero_page_x(); 54 | void cpu_address_zero_page_y(); 55 | void cpu_address_absolute(); 56 | void cpu_address_absolute_x(); 57 | void cpu_address_absolute_y(); 58 | void cpu_address_relative(); 59 | void cpu_address_indirect(); 60 | void cpu_address_indirect_x(); 61 | void cpu_address_indirect_y(); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/cpu.h: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #ifndef CPU_H 4 | #define CPU_H 5 | 6 | byte cpu_ram_read(word address); 7 | void cpu_ram_write(word address, byte data); 8 | 9 | void cpu_init(); 10 | void cpu_reset(); 11 | void cpu_interrupt(); 12 | void cpu_run(long cycles); 13 | 14 | // CPU cycles that passed since power up 15 | unsigned long long cpu_clock(); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/fce.h: -------------------------------------------------------------------------------- 1 | #ifndef FCE_H 2 | #define FCE_H 3 | 4 | #include "common.h" 5 | 6 | #define FPS 60 7 | #define W 256 8 | #define H 240 9 | 10 | void fce_update_screen(); 11 | void draw(int x, int y, int idx); 12 | 13 | static const uint32_t palette[64] = { 14 | 0x808080, 0x0000BB, 0x3700BF, 0x8400A6, 0xBB006A, 0xB7001E, 0xB30000, 0x912600, 15 | 0x7B2B00, 0x003E00, 0x00480D, 0x003C22, 0x002F66, 0x000000, 0x050505, 0x050505, 16 | 0xC8C8C8, 0x0059FF, 0x443CFF, 0xB733CC, 0xFF33AA, 0xFF375E, 0xFF371A, 0xD54B00, 17 | 0xC46200, 0x3C7B00, 0x1E8415, 0x009566, 0x0084C4, 0x111111, 0x090909, 0x090909, 18 | 0xFFFFFF, 0x0095FF, 0x6F84FF, 0xD56FFF, 0xFF77CC, 0xFF6F99, 0xFF7B59, 0xFF915F, 19 | 0xFFA233, 0xA6BF00, 0x51D96A, 0x4DD5AE, 0x00D9FF, 0x666666, 0x0D0D0D, 0x0D0D0D, 20 | 0xFFFFFF, 0x84BFFF, 0xBBBBFF, 0xD0BBFF, 0xFFBFEA, 0xFFBFCC, 0xFFC4B7, 0xFFCCAE, 21 | 0xFFD9A2, 0xCCE199, 0xAEEEB7, 0xAAF7EE, 0xB3EEFF, 0xDDDDDD, 0x111111, 0x111111 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef MEM_H 2 | #define MEM_H 3 | 4 | #include "common.h" 5 | #include "mmc.h" 6 | 7 | // Single byte 8 | byte memory_readb(word address); 9 | void memory_writeb(word address, byte data); 10 | 11 | // Two bytes (word), LSB first 12 | word memory_readw(word address); 13 | void memory_writew(word address, word data); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/mmc.h: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | byte mmc_id; 4 | 5 | byte mmc_read(word address); 6 | void mmc_write(word address, byte data); 7 | void mmc_copy(word address, byte *source, int length); 8 | void mmc_append_chr_rom_page(byte *source); -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/ppu.h: -------------------------------------------------------------------------------- 1 | #ifndef PPU_H 2 | #define PPU_H 3 | 4 | #include "common.h" 5 | 6 | typedef struct { 7 | byte PPUCTRL; // $2000 write only 8 | byte PPUMASK; // $2001 write only 9 | byte PPUSTATUS; // $2002 read only 10 | byte OAMADDR; // $2003 write only 11 | byte OAMDATA; // $2004 12 | word PPUSCROLL; 13 | byte PPUSCROLL_X, PPUSCROLL_Y; // $2005 write only x2 14 | word PPUADDR; // $2006 write only x2 15 | word PPUDATA; // $2007 16 | 17 | bool scroll_received_x; 18 | bool addr_received_high_byte; 19 | bool ready; 20 | 21 | int mirroring, mirroring_xor; 22 | 23 | int x, scanline; 24 | } PPU_STATE; 25 | 26 | void ppu_init(); 27 | 28 | byte ppu_ram_read(word address); 29 | void ppu_ram_write(word address, byte data); 30 | byte ppu_io_read(word address); 31 | void ppu_io_write(word address, byte data); 32 | 33 | bool ppu_generates_nmi(); 34 | 35 | void ppu_set_mirroring(byte mirroring); 36 | 37 | void ppu_cycle(); 38 | void ppu_copy(word address, byte *source, int length); 39 | void ppu_sprram_write(byte data); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/include/psg.h: -------------------------------------------------------------------------------- 1 | #ifndef PSG_H 2 | #define PSG_H 3 | 4 | #include "common.h" 5 | 6 | byte psg_io_read(word address); 7 | void psg_io_write(word address, byte data); 8 | void psg_init(); 9 | void psg_detect_key(); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/src/common.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | bool common_bit_set(long long value, byte position) { return value & (1L << position); } 4 | 5 | // I could do this through non-void methods with returns in one copy, 6 | // but this variant is slightly faster, and needs less typing in client code 7 | #define M_common(SUFFIX, TYPE) \ 8 | void common_set_bit##SUFFIX(TYPE *variable, byte position) { *variable |= 1L << position; } \ 9 | void common_unset_bit##SUFFIX(TYPE *variable, byte position) { *variable &= ~(1L << position); } \ 10 | void common_toggle_bit##SUFFIX(TYPE *variable, byte position) { *variable ^= 1L << position; } \ 11 | void common_modify_bit##SUFFIX(TYPE *variable, byte position, bool set) \ 12 | { set ? common_set_bit##SUFFIX(variable, position) : common_unset_bit##SUFFIX(variable, position); } 13 | 14 | M_common(b, byte) 15 | M_common(w, word) 16 | M_common(d, dword) 17 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/src/memory.c: -------------------------------------------------------------------------------- 1 | #include "memory.h" 2 | #include "cpu.h" 3 | #include "ppu.h" 4 | #include "psg.h" 5 | 6 | byte memory_readb(word address) { 7 | switch (address >> 13) { 8 | case 0: return cpu_ram_read(address & 0x07FF); 9 | case 1: return ppu_io_read(address); 10 | case 2: return psg_io_read(address); 11 | case 3: return cpu_ram_read(address & 0x1FFF); 12 | default: return mmc_read(address); 13 | } 14 | } 15 | 16 | void memory_writeb(word address, byte data) { 17 | // DMA transfer 18 | int i; 19 | if (address == 0x4014) { 20 | for (i = 0; i < 256; i++) { 21 | ppu_sprram_write(cpu_ram_read((0x100 * data) + i)); 22 | } 23 | return; 24 | } 25 | switch (address >> 13) { 26 | case 0: return cpu_ram_write(address & 0x07FF, data); 27 | case 1: return ppu_io_write(address, data); 28 | case 2: return psg_io_write(address, data); 29 | case 3: return cpu_ram_write(address & 0x1FFF, data); 30 | default: return mmc_write(address, data); 31 | } 32 | } 33 | 34 | word memory_readw(word address) { 35 | return memory_readb(address) + (memory_readb(address + 1) << 8); 36 | } 37 | 38 | void memory_writew(word address, word data) { 39 | memory_writeb(address, data & 0xFF); 40 | memory_writeb(address + 1, data >> 8); 41 | } 42 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/src/mmc.c: -------------------------------------------------------------------------------- 1 | #include "mmc.h" 2 | #include "ppu.h" 3 | #include 4 | 5 | #define MMC_MAX_PAGE_COUNT 1 6 | 7 | static byte mmc_chr_pages[MMC_MAX_PAGE_COUNT][0x2000]; 8 | static int mmc_chr_pages_number; 9 | 10 | byte memory[0x10000]; 11 | 12 | byte mmc_read(word address) { 13 | return memory[address]; 14 | } 15 | 16 | void mmc_write(word address, byte data) { 17 | switch (mmc_id) { 18 | case 0x3: ppu_copy(0x0000, &mmc_chr_pages[data & 3][0], 0x2000); break; 19 | } 20 | memory[address] = data; 21 | } 22 | 23 | void mmc_copy(word address, byte *source, int length) { 24 | memcpy(&memory[address], source, length); 25 | } 26 | 27 | void mmc_append_chr_rom_page(byte *source) { 28 | assert(mmc_chr_pages_number < MMC_MAX_PAGE_COUNT); 29 | memcpy(&mmc_chr_pages[mmc_chr_pages_number++][0], source, 0x2000); 30 | } 31 | -------------------------------------------------------------------------------- /abstract-machine/apps/litenes/src/psg.c: -------------------------------------------------------------------------------- 1 | #include "psg.h" 2 | #include 3 | #include 4 | 5 | static int p = 10; 6 | static int key_state[256]; 7 | 8 | static int MAP[256] = { 9 | 0, // On/Off 10 | _KEY_J, // A 11 | _KEY_K, // B 12 | _KEY_U, // SELECT 13 | _KEY_I, // START 14 | _KEY_W, 15 | _KEY_S, 16 | _KEY_A, 17 | _KEY_D, 18 | 255, 19 | }; 20 | 21 | byte psg_io_read(word address) { 22 | // Joystick 1 23 | if (address == 0x4016) { 24 | if (p++ < 9) { 25 | return key_state[MAP[p]]; 26 | } 27 | } 28 | return 0; 29 | } 30 | 31 | void psg_io_write(word address, byte data) { 32 | static byte prev_write; 33 | if (address == 0x4016) { 34 | if ((data & 1) == 0 && prev_write == 1) { 35 | // strobe 36 | p = 0; 37 | } 38 | } 39 | prev_write = data & 1; 40 | } 41 | 42 | void psg_detect_key() { 43 | int key = read_key(); 44 | for (; key != _KEY_NONE; key = read_key()) { 45 | int down = (key & 0x8000) != 0; 46 | int code = key & ~0x8000; 47 | key_state[code] = down; 48 | } 49 | } 50 | 51 | void psg_init() { 52 | key_state[0] = 1; 53 | } 54 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/Makefile: -------------------------------------------------------------------------------- 1 | NAME = microbench 2 | SRCS = $(shell find -L ./src/ -name "*.c" -o -name "*.cpp") 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/src/15pz/15pz.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "puzzle.h" 3 | #include "heap.h" 4 | 5 | const int N = 4; 6 | 7 | static int PUZZLE_S[N*N] = { 8 | 1, 2, 3, 4, 9 | 5, 6, 7, 8, 10 | 9, 10, 0, 11, 11 | 13, 14, 15, 12, 12 | }; 13 | 14 | static int PUZZLE_M[N*N] = { 15 | 1, 2, 3, 4, 16 | 5, 6, 7, 8, 17 | 12, 0, 14, 13, 18 | 11, 15, 10, 9, 19 | }; 20 | 21 | static int PUZZLE_L[N*N] = { 22 | 0, 2, 3, 4, 23 | 9, 6, 7, 8, 24 | 5, 11, 10, 12, 25 | 1, 15, 13, 14, 26 | }; 27 | 28 | static int ans; 29 | 30 | extern "C" { 31 | 32 | void bench_15pz_prepare() { 33 | } 34 | 35 | void bench_15pz_run() { 36 | N_puzzle puzzle; 37 | int MAXN; 38 | 39 | switch (setting->size) { 40 | case 0: puzzle = N_puzzle(PUZZLE_S); MAXN = 10; break; 41 | case 1: puzzle = N_puzzle(PUZZLE_M); MAXN = 2048; break; 42 | case 2: puzzle = N_puzzle(PUZZLE_L); MAXN = 16384; break; 43 | default: assert(0); 44 | } 45 | assert(puzzle.solvable()); 46 | 47 | auto *heap = (Updatable_heap> *) bench_alloc(sizeof(Updatable_heap>)); 48 | heap->init(MAXN); 49 | heap->push( puzzle, 0 ); 50 | 51 | int n = 0; 52 | ans = -1; 53 | 54 | while( heap->size() != 0 && n != MAXN ) { 55 | N_puzzle top = heap->pop(); 56 | ++n; 57 | 58 | if ( top == N_puzzle::solution() ) { 59 | // We are done 60 | ans = heap->length(top) * n; 61 | return; 62 | } 63 | 64 | if ( top.tile_left_possible() ) { 65 | heap->push( top.tile_left(), heap->length( top ) + 1 ); 66 | } 67 | 68 | if ( top.tile_right_possible() ) { 69 | heap->push( top.tile_right(), heap->length( top ) + 1 ); 70 | } 71 | 72 | if ( top.tile_up_possible() ) { 73 | heap->push( top.tile_up(), heap->length( top ) + 1 ); 74 | } 75 | 76 | if ( top.tile_down_possible() ) { 77 | heap->push( top.tile_down(), heap->length( top ) + 1 ); 78 | } 79 | } 80 | } 81 | 82 | 83 | int bench_15pz_validate() { 84 | return (uint32_t)ans == setting->checksum; 85 | } 86 | 87 | } 88 | 89 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/src/fib/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // f(n) = (f(n-1) + f(n-2) + .. f(n-m)) mod 2^32 4 | 5 | #define N 2147483603 6 | static int M; 7 | 8 | static void put(uint32_t *m, int i, int j, uint32_t data) { 9 | m[i * M + j] = data; 10 | } 11 | 12 | static uint32_t get(uint32_t *m, int i, int j) { 13 | return m[i * M + j]; 14 | } 15 | 16 | static inline void mult(uint32_t *c, uint32_t *a, uint32_t *b) { 17 | for (int i = 0; i < M; i ++) 18 | for (int j = 0; j < M; j ++) { 19 | put(c, i, j, 0); 20 | for (int k = 0; k < M; k ++) { 21 | put(c, i, j, get(c, i, j) + get(a, i, k) * get(b, k, j)); 22 | } 23 | } 24 | } 25 | 26 | static inline void assign(uint32_t *a, uint32_t *b) { 27 | for (int i = 0; i < M; i ++) 28 | for (int j = 0; j < M; j ++) 29 | put(a, i, j, get(b, i, j)); 30 | } 31 | 32 | static uint32_t *A, *ans, *T, *tmp; 33 | 34 | void bench_fib_prepare() { 35 | M = setting->size; 36 | int sz = sizeof(uint32_t) * M * M; 37 | A = bench_alloc(sz); 38 | T = bench_alloc(sz); 39 | ans = bench_alloc(sz); 40 | tmp = bench_alloc(sz); 41 | } 42 | 43 | void bench_fib_run() { 44 | for (int i = 0; i < M; i ++) 45 | for (int j = 0; j < M; j ++) { 46 | uint32_t x = (i == M - 1 || j == i + 1); 47 | put(A, i, j, x); 48 | put(T, i, j, x); 49 | put(ans, i, j, i == j); 50 | } 51 | 52 | for (int n = N; n > 0; n >>= 1) { 53 | if (n & 1) { 54 | mult(tmp, ans, T); 55 | assign(ans, tmp); 56 | } 57 | mult(tmp, T, T); 58 | assign(T, tmp); 59 | } 60 | } 61 | 62 | int bench_fib_validate() { 63 | return get(ans, M-1, M-1) == setting->checksum; 64 | } 65 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/src/lzip/lzip.c: -------------------------------------------------------------------------------- 1 | #include "quicklz.h" 2 | #include 3 | 4 | static int SIZE; 5 | 6 | static qlz_state_compress *state; 7 | static char *blk; 8 | static char *compress; 9 | static int len; 10 | 11 | void bench_lzip_prepare() { 12 | SIZE = setting->size; 13 | bench_srand(1); 14 | state = bench_alloc(sizeof(qlz_state_compress)); 15 | blk = bench_alloc(SIZE); 16 | compress = bench_alloc(SIZE + 400); 17 | for (int i = 0; i < SIZE; i ++) { 18 | blk[i] = 'a' + bench_rand() % 26; 19 | } 20 | } 21 | 22 | void bench_lzip_run() { 23 | len = qlz_compress(blk, compress, SIZE, state); 24 | } 25 | 26 | int bench_lzip_validate() { 27 | return checksum(compress, compress + len) == setting->checksum; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/src/qsort/qsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int N, *data; 4 | 5 | void bench_qsort_prepare() { 6 | bench_srand(1); 7 | 8 | N = setting->size; 9 | 10 | data = bench_alloc(N * sizeof(int)); 11 | for (int i = 0; i < N; i ++) { 12 | int a = bench_rand(); 13 | int b = bench_rand(); 14 | data[i] = (a << 16) | b; 15 | } 16 | } 17 | 18 | static void swap(int *a, int *b) { 19 | int t = *a; 20 | *a = *b; 21 | *b = t; 22 | } 23 | 24 | static void myqsort(int *a, int l, int r) { 25 | if (l < r) { 26 | int p = a[l], pivot = l, j; 27 | for (j = l + 1; j < r; j ++) { 28 | if (a[j] < p) { 29 | swap(&a[++pivot], &a[j]); 30 | } 31 | } 32 | swap(&a[pivot], &a[l]); 33 | myqsort(a, l, pivot); 34 | myqsort(a, pivot + 1, r); 35 | } 36 | } 37 | 38 | void bench_qsort_run() { 39 | myqsort(data, 0, N); 40 | } 41 | 42 | int bench_qsort_validate() { 43 | return checksum(data, data + N) == setting->checksum; 44 | } 45 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/src/queen/queen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static unsigned int FULL; 4 | 5 | static unsigned int dfs(unsigned int row, unsigned int ld, unsigned int rd) { 6 | if (row == FULL) { 7 | return 1; 8 | } else { 9 | unsigned int pos = FULL & (~(row | ld | rd)), ans = 0; 10 | while (pos) { 11 | unsigned int p = (pos & (~pos + 1)); 12 | pos -= p; 13 | ans += dfs(row | p, (ld | p) << 1, (rd | p) >> 1); 14 | } 15 | return ans; 16 | } 17 | } 18 | 19 | static unsigned int ans; 20 | 21 | void bench_queen_prepare() { 22 | ans = 0; 23 | FULL = (1 << setting->size) - 1; 24 | } 25 | 26 | void bench_queen_run() { 27 | ans = dfs(0, 0, 0); 28 | } 29 | 30 | int bench_queen_validate() { 31 | return ans == setting->checksum; 32 | } 33 | -------------------------------------------------------------------------------- /abstract-machine/apps/microbench/src/sieve/sieve.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int N; 4 | 5 | static int ans; 6 | static uint32_t *primes; 7 | 8 | static inline int get(int n) { 9 | return (primes[n >> 5] >> (n & 31)) & 1; 10 | } 11 | 12 | static inline void clear(int n) { 13 | primes[n >> 5] &= ~(1ul << (n & 31)); 14 | } 15 | 16 | void bench_sieve_prepare() { 17 | N = setting->size; 18 | primes = (uint32_t*)bench_alloc(N / 8 + 128); 19 | for (int i = 0; i <= N / 32; i ++) { 20 | primes[i] = 0xffffffff; 21 | } 22 | } 23 | 24 | void bench_sieve_run() { 25 | for (int i = 1; i <= N; i ++) 26 | if (!get(i)) return; 27 | for (int i = 2; i * i <= N; i ++) { 28 | if (get(i)) { 29 | for (int j = i + i; j <= N; j += i) 30 | clear(j); 31 | } 32 | } 33 | ans = 0; 34 | for (int i = 2; i <= N; i ++) 35 | if (get(i)) { 36 | ans ++; 37 | } 38 | } 39 | 40 | int bench_sieve_validate() { 41 | return ans == setting->checksum; 42 | } 43 | -------------------------------------------------------------------------------- /abstract-machine/libs/klib/Makefile: -------------------------------------------------------------------------------- 1 | NAME = klib 2 | SRCS = $(shell find src/ -name "*.c") 3 | include $(AM_HOME)/Makefile.lib 4 | -------------------------------------------------------------------------------- /abstract-machine/libs/klib/include/klib-macros.h: -------------------------------------------------------------------------------- 1 | #ifndef __KLIB_MACROS_H__ 2 | #define __KLIB_MACROS_H__ 3 | 4 | #include 5 | 6 | #ifndef __cplusplus 7 | typedef uint8_t bool; 8 | #define false 0 9 | #define true 1 10 | #endif 11 | 12 | #define ROUNDUP(a, sz) ((((uintptr_t)a)+(sz)-1) & ~((sz)-1)) 13 | #define ROUNDDOWN(a, sz) ((((uintptr_t)a)) & ~((sz)-1)) 14 | 15 | #define LENGTH(arr) (sizeof(arr) / sizeof((arr)[0])) 16 | 17 | #define RANGE(st, ed) (_Area) { .start = (void *)(st), .end = (void *)(ed) } 18 | #define IN_RANGE(ptr, area) ((area).start <= (ptr) && (ptr) < (area).end) 19 | 20 | #define STRINGIFY(s) #s 21 | #define TOSTRING(s) STRINGIFY(s) 22 | 23 | #define _CONCAT(x, y) x ## y 24 | #define CONCAT(x, y) _CONCAT(x, y) 25 | 26 | #define static_assert(const_cond) \ 27 | static char CONCAT(_static_assert_, __LINE__) [(const_cond) ? 1 : -1] __attribute__((unused)) 28 | 29 | static inline void *upcast(uint32_t ptr) { 30 | return (void *)(uintptr_t)ptr; 31 | } 32 | 33 | static inline void putstr(const char *s) { 34 | while (*s) _putc(*s ++); 35 | } 36 | 37 | #define panic_on(cond, s) \ 38 | do { \ 39 | if (cond) { \ 40 | putstr("AM Panic: "); putstr(s); \ 41 | putstr(" @ " __FILE__ ":" TOSTRING(__LINE__) " \n"); \ 42 | _halt(1); \ 43 | } \ 44 | } while (0) 45 | 46 | #define panic(s) panic_on(1, s) 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /abstract-machine/libs/klib/src/cpp.c: -------------------------------------------------------------------------------- 1 | #include "klib.h" 2 | 3 | #ifndef __ISA_NATIVE__ 4 | 5 | void __dso_handle() { 6 | } 7 | 8 | void __cxa_guard_acquire() { 9 | } 10 | 11 | void __cxa_guard_release() { 12 | } 13 | 14 | 15 | void __cxa_atexit() { 16 | assert(0); 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /abstract-machine/libs/klib/src/io.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | uint32_t uptime() { 5 | _DEV_TIMER_UPTIME_t uptime; 6 | _io_read(_DEV_TIMER, _DEVREG_TIMER_UPTIME, &uptime, sizeof(uptime)); 7 | return uptime.lo; 8 | } 9 | 10 | void get_timeofday(void *rtc) { 11 | _io_read(_DEV_TIMER, _DEVREG_TIMER_DATE, rtc, sizeof(_DEV_TIMER_DATE_t)); 12 | } 13 | 14 | int read_key() { 15 | _DEV_INPUT_KBD_t key; 16 | _io_read(_DEV_INPUT, _DEVREG_INPUT_KBD, &key, sizeof(_DEV_INPUT_KBD_t)); 17 | int ret = key.keycode; 18 | if (key.keydown) ret |= 0x8000; 19 | return ret; 20 | } 21 | 22 | void draw_rect(uint32_t *pixels, int x, int y, int w, int h) { 23 | _DEV_VIDEO_FBCTRL_t ctl = (_DEV_VIDEO_FBCTRL_t) { 24 | .pixels = pixels, 25 | .x = x, .y = y, .w = w, .h = h, 26 | .sync = 0, 27 | }; 28 | _io_write(_DEV_VIDEO, _DEVREG_VIDEO_FBCTRL, &ctl, sizeof(ctl)); 29 | } 30 | 31 | void draw_sync() { 32 | _DEV_VIDEO_FBCTRL_t ctl; 33 | ctl.pixels = NULL; 34 | ctl.x = ctl.y = ctl.w = ctl.h = 0; 35 | ctl.sync = 1; 36 | _io_write(_DEV_VIDEO, _DEVREG_VIDEO_FBCTRL, &ctl, sizeof(ctl)); 37 | } 38 | 39 | int screen_width() { 40 | _DEV_VIDEO_INFO_t info; 41 | _io_read(_DEV_VIDEO, _DEVREG_VIDEO_INFO, &info, sizeof(info)); 42 | return info.width; 43 | } 44 | 45 | int screen_height() { 46 | _DEV_VIDEO_INFO_t info; 47 | _io_read(_DEV_VIDEO, _DEVREG_VIDEO_INFO, &info, sizeof(info)); 48 | return info.height; 49 | } 50 | -------------------------------------------------------------------------------- /abstract-machine/libs/klib/src/stdlib.c: -------------------------------------------------------------------------------- 1 | static unsigned long int next = 1; 2 | 3 | int rand(void) { 4 | // RAND_MAX assumed to be 32767 5 | next = next * 1103515245 + 12345; 6 | return (unsigned int)(next/65536) % 32768; 7 | } 8 | 9 | void srand(unsigned int seed) { 10 | next = seed; 11 | } -------------------------------------------------------------------------------- /abstract-machine/share/games/nes/.gitignore: -------------------------------------------------------------------------------- 1 | gen/ 2 | -------------------------------------------------------------------------------- /abstract-machine/share/games/nes/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | 3 | all: 4 | -python3 build-roms.py 5 | 6 | clean: 7 | -rm -rf gen 8 | -------------------------------------------------------------------------------- /abstract-machine/share/games/nes/build-roms.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | from pathlib import Path 5 | 6 | roms = [] 7 | cwd = Path('.') 8 | 9 | (cwd / 'gen').mkdir(exist_ok=True) 10 | 11 | for f in cwd.glob('rom/*.nes'): 12 | name = f.stem 13 | if not (cwd / 'gen' / f'{name}.c').exists(): 14 | os.system(f'xxd -i "{f}" > gen/{name}.c') 15 | roms.append(name) 16 | 17 | for f in cwd.glob('gen/*.c'): 18 | if f.stem not in roms: 19 | f.unlink() 20 | 21 | def h_file(): 22 | for name in roms: 23 | yield 'extern unsigned char rom_%s_nes[];' % (name) 24 | yield 'extern unsigned int rom_%s_nes_len;' % (name) 25 | yield ''' 26 | struct rom { 27 | const char *name; 28 | void *body; 29 | unsigned int *size; 30 | }; 31 | 32 | struct rom roms[] = {''' 33 | for name in roms: 34 | yield ' { .name = "%s", .body = rom_%s_nes, .size = &rom_%s_nes_len, },' % (name, name, name) 35 | yield '};' 36 | 37 | yield 'int nroms = %d;' % (len(roms)) 38 | 39 | with open('gen/roms.h', 'w') as fp: 40 | for line in h_file(): 41 | fp.write(line) 42 | fp.write('\n') 43 | -------------------------------------------------------------------------------- /abstract-machine/share/games/nes/rom/mario.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZRZ-Unknow/os-workbench/66ed9543bb060a8b77d446f303997138a0648a54/abstract-machine/share/games/nes/rom/mario.nes -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/Makefile: -------------------------------------------------------------------------------- 1 | NAME := amtest 2 | SRCS := $(shell find -L ./src/ -name "*.c") 3 | 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/include/amtest.h: -------------------------------------------------------------------------------- 1 | #ifndef __AMUNIT_H__ 2 | #define __AMUNIT_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define IOE ({ _ioe_init(); }) 9 | #define CTE(h) ({ _Context *h(_Event, _Context *); _cte_init(h); }) 10 | #define VME(f1, f2) ({ void *f1(size_t); void f2(void *); _vme_init(f1, f2); }) 11 | #define MPE ({ _mpe_init(entry); }) 12 | 13 | extern void (*entry)(); 14 | 15 | #define CASE(id, entry_, ...) \ 16 | case id: { \ 17 | void entry_(); \ 18 | entry = entry_; \ 19 | __VA_ARGS__; \ 20 | entry_(); \ 21 | break; \ 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void (*entry)() = NULL; // mp entry 4 | 5 | static const char *tests[256] = { 6 | ['h'] = "hello", 7 | ['H'] = "display this help message", 8 | ['i'] = "interrupt/yield test", 9 | ['d'] = "scan devices", 10 | ['m'] = "multiprocessor test", 11 | ['t'] = "real-time clock test", 12 | ['k'] = "readkey test", 13 | ['v'] = "display test", 14 | ['p'] = "x86 virtual memory test", 15 | }; 16 | 17 | int main(const char *args) { 18 | switch (args[0]) { 19 | CASE('h', hello); 20 | CASE('i', hello_intr, IOE, CTE(simple_trap)); 21 | CASE('d', devscan, IOE); 22 | CASE('m', mp_print, MPE); 23 | CASE('t', rtc_test, IOE); 24 | CASE('k', keyboard_test, IOE); 25 | CASE('v', video_test, IOE); 26 | CASE('p', vm_test, CTE(vm_handler), VME(simple_pgalloc, simple_pgfree)); 27 | case 'H': 28 | default: 29 | printf("Usage: make run mainargs=*\n"); 30 | for (int ch = 0; ch < 256; ch++) { 31 | if (tests[ch]) { 32 | printf(" %c: %s\n", ch, tests[ch]); 33 | } 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/src/tests/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void hello() { 4 | for (int i = 0; i < 10; i ++) { 5 | putstr("Hello, AM World @ " __ISA__ "\n"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/src/tests/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | _Context *simple_trap(_Event ev, _Context *ctx) { 4 | switch(ev.event) { 5 | case _EVENT_IRQ_TIMER: 6 | printf("t"); break; 7 | case _EVENT_IRQ_IODEV: 8 | printf("d"); read_key(); break; 9 | case _EVENT_YIELD: 10 | printf("y"); break; 11 | } 12 | return ctx; 13 | } 14 | 15 | void hello_intr() { 16 | printf("Hello, AM World @ " __ISA__ "\n"); 17 | printf(" t = timer, d = device, y = yield\n"); 18 | _intr_write(1); 19 | while (1) { 20 | for (volatile int i = 0; i < 10000000; i++) ; 21 | _yield(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/src/tests/keyboard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NAME(key) \ 5 | [_KEY_##key] = #key, 6 | 7 | const char *names[256] = { 8 | [_KEY_NONE] = "NONE", 9 | _KEYS(NAME) 10 | }; 11 | 12 | void keyboard_test() { 13 | printf("Try to press any key...\n"); 14 | while (1) { 15 | int key = read_key(); 16 | int down = 0; 17 | if (key & 0x8000) { 18 | key ^= 0x8000; 19 | down = 1; 20 | } 21 | if (key != _KEY_NONE) { 22 | printf("Get key: %d %s %s\n", key, names[key], down ? "down" : "up"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/src/tests/mp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void mp_print() { 4 | while (1) { 5 | printf("%d", _cpu()); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /abstract-machine/tests/amtest/src/tests/rtc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void rtc_test() { 5 | _DEV_TIMER_DATE_t rtc; 6 | int sec = 1; 7 | while (1) { 8 | while(uptime() < 1000 * sec) ; 9 | get_timeofday(&rtc); 10 | printf("%d-%d-%d %02d:%02d:%02d GMT (", rtc.year, rtc.month, rtc.day, rtc.hour, rtc.minute, rtc.second); 11 | if (sec == 1) { 12 | printf("%d second).\n", sec); 13 | } else { 14 | printf("%d seconds).\n", sec); 15 | } 16 | sec ++; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /abstract-machine/tests/klibtest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = klibtest 2 | SRCS = $(shell find -L ./src/ -name "*.c" -o -name "*.cpp") 3 | ARCH = x86-qemu 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /abstract-machine/tests/klibtest/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void printf_test(); 4 | void memory_test(); 5 | 6 | int main() { 7 | printf("Test start!\n"); 8 | printf_test(); 9 | memory_test(); 10 | printf("Test end!\n"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /amgame/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /amgame/181220076.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZRZ-Unknow/os-workbench/66ed9543bb060a8b77d446f303997138a0648a54/amgame/181220076.pdf -------------------------------------------------------------------------------- /amgame/Makefile: -------------------------------------------------------------------------------- 1 | NAME := amgame 2 | SRCS := $(shell find -L ./src/ -name "*.c") 3 | export MODULE := L0 4 | export AM_HOME := $(PWD)/../abstract-machine 5 | ifeq ($(ARCH),) 6 | export ARCH := x86_64-qemu 7 | endif 8 | 9 | include $(AM_HOME)/Makefile.app 10 | include ../Makefile.lab 11 | image: git 12 | -------------------------------------------------------------------------------- /amgame/include/game.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifndef bool 6 | #define bool int8_t 7 | #define false 0 8 | #define true 1 9 | #endif 10 | 11 | #define MAX_LEN 23 12 | #define SIDE 16 13 | #define NONE 0 14 | #define UP 1 15 | #define DOWN 2 16 | #define LEFT 3 17 | #define RIGHT 4 18 | 19 | #define BLACK 0x000000 20 | #define WHITE 0xffffff 21 | #define RED 0xc73e3a 22 | #define CHOCOLATE 0xd2691e 23 | #define PURPLE 0x800080 24 | #define GREEN 0x869900 25 | 26 | 27 | struct Node{ 28 | int x; 29 | int y; 30 | }; 31 | struct Snake{ 32 | int dire; 33 | int lenth; 34 | struct Node node[MAX_LEN]; 35 | }; 36 | 37 | void draw_snake(); 38 | void init(); 39 | void draw_food(); 40 | void splash(); 41 | static inline void puts(const char *s) { 42 | for (; *s; s++) _putc(*s); 43 | } 44 | #define Log(format, ...) \ 45 | printf("\33[0m[\33[1;35mLog\33[0m]\33[1;34m[%s,%d,%s] " format "\33[0m\n", \ 46 | __FILE__, __LINE__, __func__, ## __VA_ARGS__) 47 | 48 | -------------------------------------------------------------------------------- /amgame/src/keyboard.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_key() { 4 | _DEV_INPUT_KBD_t event = { .keycode = _KEY_NONE }; 5 | #define KEYNAME(key) \ 6 | [_KEY_##key] = #key, 7 | static const char *key_names[] = { 8 | _KEYS(KEYNAME) 9 | }; 10 | _io_read(_DEV_INPUT, _DEVREG_INPUT_KBD, &event, sizeof(event)); 11 | if (event.keycode != _KEY_NONE && event.keydown) { 12 | puts("Key pressed: "); 13 | puts(key_names[event.keycode]); 14 | printf(" %d\n",event.keycode); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /amgame/src/video.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern int w,h; 4 | extern int edge[4][2]; 5 | extern int food_1[2]; 6 | extern int food_2[2]; 7 | extern struct Snake snake; 8 | 9 | 10 | void init() { 11 | _DEV_VIDEO_INFO_t info = {0}; 12 | _io_read(_DEV_VIDEO, _DEVREG_VIDEO_INFO, &info, sizeof(info)); 13 | w = info.width; 14 | h = info.height; 15 | char ch[64]=""; 16 | sprintf(ch,"You Need To Get %d Score To Win The Game\n",(MAX_LEN-3)*100); 17 | printf("This Is A Gluttonous Snake Game\n"); 18 | printf("Press W,S,A,D To Control The Direction\nPress P/C To Pause Or Continue The Game\nPress R/Esc To Restart Or End The Game\nPress 1,2,3 To Switch The Snake's Speed\n"); 19 | printf(ch); 20 | printf("Good Luck!\n"); 21 | } 22 | 23 | static void draw_tile(int x, int y, int w, int h, uint32_t color) { 24 | uint32_t pixels[w * h]; // careful! stack is limited! 25 | _DEV_VIDEO_FBCTRL_t event = { 26 | .x = x, .y = y, .w = w, .h = h, .sync = 1, 27 | .pixels = pixels, 28 | }; 29 | for (int i = 0; i < w * h; i++) { 30 | pixels[i] = color; 31 | } 32 | _io_write(_DEV_VIDEO, _DEVREG_VIDEO_FBCTRL, &event, sizeof(event)); 33 | } 34 | void splash() { 35 | for (int x = 0; x <= w; x+=SIDE) { 36 | for (int y = 0; y<= h;y+=SIDE) { 37 | if(x==edge[0][0] || x>=edge[3][0] || y==edge[0][1] || y>=edge[3][1]) 38 | draw_tile(x,y,SIDE,SIDE,CHOCOLATE); 39 | else draw_tile(x, y, SIDE, SIDE,BLACK); 40 | } 41 | } 42 | } 43 | void draw_snake(){ 44 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | int main(){ 7 | FILE *fp=fopen("./a.txt","r"); 8 | char txt[4096*4]; 9 | fread(&txt[0],sizeof(txt),1,fp); 10 | fclose(fp); 11 | int count=0; 12 | int first=-1; 13 | for(int i=0;i5) {printf("%d,ccccccccccccccccccccccccccccccccccccc\n",i);assert(0);} 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /kernel/data_analize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(){ 7 | FILE *fp=fopen("./a.txt","r"); 8 | char txt[4096*4]; 9 | fread(&txt[0],sizeof(txt),1,fp); 10 | fclose(fp); 11 | int count=0; 12 | int first=-1; 13 | for(int i=0;i5) {printf("%d,ccccccccccccccccccccccccccccccccccccc\n",i);assert(0);} 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /kernel/framework/kernel.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MODULE(mod) \ 5 | typedef struct mod_##mod##_t mod_##mod##_t; \ 6 | extern mod_##mod##_t *mod; \ 7 | struct mod_##mod##_t 8 | 9 | #define MODULE_DEF(mod) \ 10 | extern mod_##mod##_t __##mod##_obj; \ 11 | mod_##mod##_t *mod = &__##mod##_obj; \ 12 | mod_##mod##_t __##mod##_obj 13 | 14 | typedef _Context *(*handler_t)(_Event, _Context *); 15 | MODULE(os) { 16 | void (*init)(); 17 | void (*run)(); 18 | _Context *(*trap)(_Event ev, _Context *context); 19 | void (*on_irq)(int seq, int event, handler_t handler); 20 | }; 21 | /* 22 | typedef struct mod_os_t mod_os_t; 23 | extern mod_os_t *mod; 24 | struct mod_os_t{ 25 | void (*init)(); 26 | void (*run)(); 27 | } 28 | */ 29 | 30 | MODULE(pmm) { 31 | void (*init)(); 32 | void *(*alloc)(size_t size); 33 | void (*free)(void *ptr); 34 | }; 35 | 36 | typedef struct task task_t; 37 | typedef struct spinlock spinlock_t; 38 | typedef struct semaphore sem_t; 39 | MODULE(kmt) { 40 | void (*init)(); 41 | int (*create)(task_t *task, const char *name, void (*entry)(void *arg), void *arg); 42 | void (*teardown)(task_t *task); 43 | void (*spin_init)(spinlock_t *lk, const char *name); 44 | void (*spin_lock)(spinlock_t *lk); 45 | void (*spin_unlock)(spinlock_t *lk); 46 | void (*sem_init)(sem_t *sem, const char *name, int value); 47 | void (*sem_wait)(sem_t *sem); 48 | void (*sem_signal)(sem_t *sem); 49 | }; 50 | 51 | struct ufs_stat; 52 | MODULE(vfs) { 53 | void (*init)(); 54 | int (*write)(int fd, void *buf, int count); 55 | int (*read)(int fd, void *buf, int count); 56 | int (*close)(int fd); 57 | int (*open)(const char *pathname, int flags); 58 | int (*lseek)(int fd, int offset, int whence); 59 | int (*link)(const char *oldpath, const char *newpath); 60 | int (*unlink)(const char *pathname); 61 | int (*fstat)(int fd, struct ufs_stat *buf); 62 | int (*mkdir)(const char *pathname); 63 | int (*chdir)(const char *path); 64 | int (*dup)(int fd); 65 | }; 66 | typedef struct device device_t; 67 | MODULE(dev) { 68 | void (*init)(); 69 | device_t *(*lookup)(const char *name); 70 | }; 71 | -------------------------------------------------------------------------------- /kernel/framework/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | _ioe_init(); 6 | _cte_init(os->trap); 7 | os->init(); 8 | _mpe_init(os->run); 9 | return 1; 10 | } 11 | -------------------------------------------------------------------------------- /kernel/framework/user.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define T_DIR 1 4 | #define T_FILE 2 5 | 6 | #define SEEK_CUR 0 7 | #define SEEK_SET 1 8 | #define SEEK_END 2 9 | 10 | #define O_RDONLY 00000000 11 | #define O_WRONLY 00000001 12 | #define O_RDWR 00000002 13 | #define O_CREAT 00000100 14 | 15 | struct ufs_stat { 16 | uint32_t id, type, size; 17 | }; 18 | 19 | struct ufs_dirent { 20 | uint32_t inode; 21 | char name[28]; 22 | } __attribute__((packed)); 23 | -------------------------------------------------------------------------------- /kernel/include/debug.h: -------------------------------------------------------------------------------- 1 | //#define DEBUG 2 | /*#ifdef DEBUG 3 | #define Log(format, ...) \ 4 | printf("\33[1;35m[%s,%d,%s] " format "\33[0m\n", \ 5 | __FILE__, __LINE__, __func__, ## __VA_ARGS__) 6 | #else*/ 7 | //#define Log(format,...) 8 | //#endif 9 | 10 | #define SLog(format,...) \ 11 | printf("\33[1;35m[%s,%d,%s] " format "\33[0m\n", \ 12 | __FILE__, __LINE__, __func__, ## __VA_ARGS__) 13 | #define Spanic(format,...) \ 14 | do { \ 15 | SLog("\33[1;31msystem panic: " format, ## __VA_ARGS__); \ 16 | _halt(1); \ 17 | } while (0) 18 | 19 | 20 | #ifdef assert 21 | # undef assert 22 | #endif 23 | #ifdef panic 24 | # undef panic 25 | #endif 26 | 27 | #define panic(format, ...) \ 28 | do { \ 29 | Log("\33[1;31msystem panic: " format, ## __VA_ARGS__); \ 30 | _halt(1); \ 31 | } while (0) 32 | 33 | #define assert(cond) \ 34 | do { \ 35 | if (!(cond)) { \ 36 | panic("Assertion failed: %s", #cond); \ 37 | } \ 38 | } while (0) 39 | 40 | #define TODO() panic("please implement me") 41 | -------------------------------------------------------------------------------- /kernel/src/dev/dev.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DEVICES(_) \ 4 | _(0, input_t, "input", 1, &input_ops) \ 5 | _(1, fb_t, "fb", 1, &fb_ops) \ 6 | _(2, tty_t, "tty1", 1, &tty_ops) \ 7 | _(3, tty_t, "tty2", 2, &tty_ops) \ 8 | _(4, sd_t, "sda", 1, &sd_ops) \ 9 | 10 | #define DEV_CNT(...) + 1 11 | device_t *devices[0 DEVICES(DEV_CNT)]; 12 | 13 | void *dev_malloc(size_t size) { 14 | static char dev_mem[8 << 20]; // 8 MiB reserved memory for devices 15 | static char *start = dev_mem; 16 | start += size; 17 | panic_on(start >= dev_mem + sizeof(dev_mem), "not enough device memory"); 18 | return start - size; 19 | } 20 | 21 | static device_t *dev_lookup(const char *name) { 22 | for (int i = 0; i < LENGTH(devices); i++) 23 | if (strcmp(devices[i]->name, name) == 0) 24 | return devices[i]; 25 | panic("lookup device failed."); 26 | return NULL; 27 | } 28 | 29 | static device_t *dev_create(size_t size, const char* name, int id, devops_t *ops) { 30 | device_t *dev = pmm->alloc(sizeof(device_t)); 31 | *dev = (device_t) { 32 | .name = name, 33 | .ptr = pmm->alloc(size), 34 | .id = id, 35 | .ops = ops, 36 | }; 37 | return dev; 38 | } 39 | 40 | void dev_input_task(); 41 | void dev_tty_task(); 42 | 43 | static void dev_init() { 44 | #define INIT(id, device_type, dev_name, dev_id, dev_ops) \ 45 | devices[id] = dev_create(sizeof(device_type), dev_name, dev_id, dev_ops); \ 46 | devices[id]->ops->init(devices[id]); 47 | 48 | DEVICES(INIT); 49 | 50 | kmt->create(pmm->alloc(sizeof(task_t)), "input-task", dev_input_task, NULL); 51 | kmt->create(pmm->alloc(sizeof(task_t)), "tty-task", dev_tty_task, NULL); 52 | } 53 | 54 | MODULE_DEF(dev) = { 55 | .init = dev_init, 56 | .lookup = dev_lookup, 57 | }; 58 | -------------------------------------------------------------------------------- /kernel/src/dev/dev_sd.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int sd_init(device_t *dev) { 4 | sd_t *sd = dev->ptr; 5 | _DEV_STORAGE_INFO_t info; 6 | if (_io_read(_DEV_STORAGE, _DEVREG_STORAGE_INFO, &info, sizeof(info)) <= 0) { 7 | dev->ptr = NULL; 8 | } else { 9 | sd->blkcnt = info.blkcnt; 10 | sd->blksz = info.blksz; 11 | sd->buf = pmm->alloc(sd->blksz); 12 | } 13 | return 0; 14 | } 15 | 16 | static void blk_read(void *buf, int blkno, int blkcnt) { 17 | _DEV_STORAGE_RDCTRL_t ctl; 18 | ctl.buf = buf; 19 | ctl.blkno = blkno; 20 | ctl.blkcnt = blkcnt; 21 | _io_write(_DEV_STORAGE, _DEVREG_STORAGE_RDCTRL, &ctl, sizeof(ctl)); 22 | } 23 | 24 | static void blk_write(void *buf, int blkno, int blkcnt) { 25 | _DEV_STORAGE_WRCTRL_t ctl; 26 | ctl.buf = buf; 27 | ctl.blkno = blkno; 28 | ctl.blkcnt = blkcnt; 29 | _io_write(_DEV_STORAGE, _DEVREG_STORAGE_WRCTRL, &ctl, sizeof(ctl)); 30 | } 31 | 32 | static ssize_t sd_read(device_t *dev, off_t offset, void *buf, size_t count) { 33 | sd_t *sd = dev->ptr; 34 | panic_on(!sd, "no disk"); 35 | uint32_t pos = 0; 36 | for (uint32_t st = ROUNDDOWN(offset, sd->blksz); pos < count; st = offset) { 37 | uint32_t n = sd->blksz - (offset - st); 38 | if (n > count - pos) n = count - pos; 39 | blk_read(sd->buf, st / sd->blksz, 1); 40 | memcpy((char *)buf + pos, sd->buf + offset - st, n); 41 | pos += n; 42 | offset = st + sd->blksz; 43 | } 44 | return pos; 45 | } 46 | 47 | static ssize_t sd_write(device_t *dev, off_t offset, const void *buf, size_t count) { 48 | sd_t *sd = dev->ptr; 49 | panic_on(!sd, "no disk"); 50 | uint32_t pos = 0; 51 | for (uint32_t st = ROUNDDOWN(offset, sd->blksz); pos < count; st = offset) { 52 | uint32_t n = sd->blksz - (offset - st); 53 | if (n > count - pos) n = count - pos; 54 | if (n < sd->blksz) { 55 | blk_read(sd->buf, st / sd->blksz, 1); 56 | } 57 | memcpy(sd->buf + offset - st, (char *)buf + pos, n); 58 | blk_write(sd->buf, st / sd->blksz, 1); 59 | pos += n; 60 | offset = st + sd->blksz; 61 | } 62 | return pos; 63 | } 64 | 65 | devops_t sd_ops = { 66 | .init = sd_init, 67 | .read = sd_read, 68 | .write = sd_write, 69 | }; 70 | -------------------------------------------------------------------------------- /kernel/src/sem.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define current cpu_task[_cpu()].current 4 | extern spinlock_t os_trap_lk; 5 | 6 | void sem_task_debug_print(sem_t *sem){ 7 | #ifdef DEBUG 8 | list_head *lh=sem->blocked_task.next; 9 | while(lh!=NULL){ 10 | 11 | task_t *task=list_entry(lh,task_t,sem_list); 12 | Log("task:%s,pid:%d,cpu:%d,status:%d,",task->name,task->pid,task->cpu,task->status); 13 | lh=lh->next; 14 | } 15 | #endif 16 | } 17 | 18 | void sem_init(sem_t *sem, const char *name, int value){ 19 | sem->name=name; 20 | sem->count=value; 21 | lock_init(&sem->lock,name); 22 | sem->blocked_task.prev=NULL; 23 | sem->blocked_task.next=NULL; 24 | } 25 | 26 | void sem_wait(sem_t *sem){ 27 | lock_acquire(&sem->lock); 28 | Assert(sem->count>=0,"sem %s count:%d",sem->name,sem->count); 29 | while(sem->count==0){ 30 | bool added=false; 31 | lock_acquire(&os_trap_lk); 32 | if(current->status==WAIT) added=true; 33 | else current->status=WAIT; 34 | //sem_task_debug_print(sem); 35 | lock_release(&os_trap_lk); 36 | //add current to sem->blocked_list 37 | if(added==false){ 38 | list_head *lh=&sem->blocked_task; 39 | while(lh->next!=NULL) lh=lh->next; 40 | lh->next=¤t->sem_list; 41 | current->sem_list.prev=lh; 42 | current->sem_list.next=NULL; 43 | } 44 | lock_release(&sem->lock); 45 | _yield(); 46 | lock_acquire(&sem->lock); 47 | } 48 | sem->count--; 49 | lock_release(&sem->lock); 50 | } 51 | 52 | void sem_signal(sem_t *sem){ 53 | lock_acquire(&sem->lock); 54 | sem->count++; 55 | if(sem->blocked_task.next!=NULL){ 56 | //delete the first task in sem->blocked_list 57 | int i=holding(&os_trap_lk); 58 | if(!i) lock_acquire(&os_trap_lk); 59 | list_head *lh=sem->blocked_task.next; 60 | task_t *task=list_entry(lh,task_t,sem_list); 61 | list_head *next=lh->next; 62 | sem->blocked_task.next=next; 63 | if(next) next->prev=&sem->blocked_task; 64 | task->sem_list.prev=NULL; 65 | task->sem_list.next=NULL; 66 | task->status=SLEEP; 67 | if(!i) lock_release(&os_trap_lk); 68 | } 69 | lock_release(&sem->lock); 70 | } -------------------------------------------------------------------------------- /kernel/src/spinlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int ncli[MAX_CPU]={0}; 4 | static int intena[MAX_CPU]={0}; 5 | 6 | void lock_init(spinlock_t *lk,const char *name){ 7 | lk->name=name; 8 | lk->locked=0; 9 | lk->cpu=-1; 10 | } 11 | 12 | void lock_acquire(spinlock_t *lk){ 13 | pushcli(); 14 | if(holding(lk)) Spanic("acquire,name:%s",lk->name); //当lk为1且cpu为当前cpu时,即禁止重入 15 | while(_atomic_xchg((intptr_t*)&lk->locked,1)!=0); 16 | __sync_synchronize(); 17 | lk->cpu=_cpu(); 18 | } 19 | 20 | void lock_release(spinlock_t *lk){ 21 | if(!holding(lk)) Spanic("release,name:%s",lk->name); //当lk为0或者 lk的cpu不为当前cpu 22 | lk->cpu=-1; 23 | __sync_synchronize(); 24 | _atomic_xchg((intptr_t*)&lk->locked,0); 25 | popcli(); 26 | } 27 | 28 | int holding(spinlock_t *lk){ 29 | int r; 30 | pushcli(); 31 | r=lk->locked && lk->cpu==_cpu(); 32 | popcli(); 33 | return r; 34 | } 35 | void pushcli(void){ 36 | int i=_intr_read(); 37 | _intr_write(0); 38 | if(ncli[_cpu()]==0) intena[_cpu()]= i; 39 | ncli[_cpu()]+=1; 40 | } 41 | 42 | void popcli(void){ 43 | if(_intr_read()) Spanic("popcli interruptible"); 44 | if(--ncli[_cpu()] <0 ) Spanic("popcli"); 45 | if(ncli[_cpu()]==0 && intena[_cpu()]) _intr_write(1); 46 | } -------------------------------------------------------------------------------- /kernel/tools/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | mkfs: mkfs.c 4 | gcc -O1 -Wall -Werror -o $@ -I../framework $< 5 | 6 | clean: 7 | rm -rf mkfs 8 | -------------------------------------------------------------------------------- /kernel/tools/mkfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define IMG_SIZE (64 * 1024 * 1024) 10 | 11 | int main(int argc, char *argv[]) { 12 | int fd; 13 | uint8_t *disk; 14 | 15 | // TODO: argument parsing 16 | 17 | assert((fd = open(argv[1], O_RDWR)) > 0); 18 | assert((ftruncate(fd, IMG_SIZE)) == 0); 19 | assert((disk = mmap(NULL, IMG_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) != (void *)-1); 20 | 21 | // TODO: mkfs 22 | 23 | munmap(disk, IMG_SIZE); 24 | close(fd); 25 | } 26 | -------------------------------------------------------------------------------- /libco/Makefile: -------------------------------------------------------------------------------- 1 | NAME := $(shell basename $(PWD)) 2 | export MODULE := M2 3 | all: $(NAME)-64.so $(NAME)-32.so 4 | CFLAGS += -U_FORTIFY_SOURCE 5 | 6 | include ../Makefile 7 | -------------------------------------------------------------------------------- /libco/co.h: -------------------------------------------------------------------------------- 1 | //#define DEBUG 2 | 3 | 4 | struct co* co_start(const char *name, void (*func)(void *), void *arg); 5 | void co_yield(); 6 | void co_wait(struct co *co); 7 | -------------------------------------------------------------------------------- /libco/tests/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test libco 2 | 3 | all: libco-test-64 libco-test-32 4 | 5 | test: libco all 6 | @echo "==== TEST 64 bit ====" 7 | @LD_LIBRARY_PATH=.. ./libco-test-64 8 | @echo "==== TEST 32 bit ====" 9 | @LD_LIBRARY_PATH=.. ./libco-test-32 10 | 11 | libco-test-64: main.c 12 | 13 | libco: 14 | @cd .. && make -s 15 | 16 | libco-test-64: main.c 17 | gcc -I.. -L.. -m64 main.c -o libco-test-64 -lco-64 18 | 19 | libco-test-32: main.c 20 | gcc -I.. -L.. -m32 main.c -o libco-test-32 -lco-32 21 | 22 | clean: 23 | rm -f libco-test-* 24 | -------------------------------------------------------------------------------- /libkvdb/Makefile: -------------------------------------------------------------------------------- 1 | NAME := $(shell basename $(PWD)) 2 | export MODULE := M6 3 | all: $(NAME)-64.so $(NAME)-32.so 4 | 5 | include ../Makefile 6 | -------------------------------------------------------------------------------- /libkvdb/kvdb.h: -------------------------------------------------------------------------------- 1 | struct kvdb; 2 | struct kvdb *kvdb_open(const char *filename); 3 | int kvdb_close(struct kvdb *db); 4 | int kvdb_put(struct kvdb *db, const char *key, const char *value); 5 | char *kvdb_get(struct kvdb *db, const char *key); 6 | -------------------------------------------------------------------------------- /libkvdb/test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | return 0; 5 | } -------------------------------------------------------------------------------- /libkvdb/tests/kvdb-test.h: -------------------------------------------------------------------------------- 1 | 2 | #include -------------------------------------------------------------------------------- /pstree/Makefile: -------------------------------------------------------------------------------- 1 | NAME := $(shell basename $(PWD)) 2 | export MODULE := M1 3 | all: $(NAME)-64 $(NAME)-32 4 | 5 | include ../Makefile 6 | -------------------------------------------------------------------------------- /sperf/Makefile: -------------------------------------------------------------------------------- 1 | NAME := $(shell basename $(PWD)) 2 | export MODULE := M3 3 | all: $(NAME)-64 $(NAME)-32 4 | 5 | include ../Makefile 6 | --------------------------------------------------------------------------------