User:Orby/Zahlen
General
C++
Config file
[main] core=/home/bob/zproc.so bus=/home/bob/zbus.so [core] boot=0xA000 -- processor settings [bus] device0=/home/bob/ram.so device1=/home/bob/hic1984.so device2=/home/bob/cart.so [ram] addr=0x0000 pages=1 [hic1984] addr=0x2000 resolution=640x480x32 [cart] addr=0xA000
Classes
ZahlenCore
ControllerHost(host_t host, int_t screen_width, int_t screen_height, int_t screen_bpp, void* screen_buffer, FUNC audio_write, FUNC audio_remaining) : AbstractHostControllerLogger(log_t logger, FUNC log) : AbstractLoggerControllerConfig(config_t config, FUNC config_get, FUNC config_set) : AbstractConfigControllerBus(bus_t bus, FUNC bus_read, FUNC bus_write) : AbstractBus- ZahlenProcessor() : AbstractProcessor
The Z1Processor class can be divided into subclasses, too.
- Z1Processor
- Z1Core(Z1State* state, AbstractBus* bus)
- int pmul();
- int mul();
- etc.
- Z1State
- push(Z1Matrix matrix)
- Z1Matrix pop()
- Z1Matrix peek()
- int get_ip();
- void set_ip(int ip)
- Z1Matrix(int width, int height, int type)
- int width()
- int height()
- int type()
- double* get()
- Z1Core(Z1State* state, AbstractBus* bus)
main.cpp
AbstractMachine* machine = new ZahlenMachine(); AbstractMainBoard* board = new ZahelnMainBoard(); AbstractProcessor* proc = new ProcessorPlugin("zproc.so"); AbstractBus* bus = new ZahlenBus(); AbstractDevice* devices[256]; devices[0] = new DevicePlugin("hic1984.so") devices[1] = NULL; AbstractLogger* logger = new ZahlenLogger(); AbstractConfig* config = new ZahlenConfig(); AbstractHost* host = new ZahlenHost(); machine->initiallize(host, config, logger, devices, bus, proc, board); machine->boot(); machine->cleanup();
Initialize and cleanup on machine call initialize and cleanup on all dependencies.
Abstract
- AbstractHost
- initiallize()
- void* load_library(char* filename)
- void* lookup_function(void* library, char* function)
- int fork()
- AbstractLogger
- initialize(AbstractHost* host)
- log(int level, char* msg)
- cleanup()
- AbstractConfig
- initialize(AbstractHost* host)
- char* get(char* section, char* id, char* default)
- set(char* section, char* id, char* value)
- cleanup()
- AbstractDevice
- initialize(AbstractHost* host, AbstractConfig* config, AbstractLogger* logger)
- tick()
- uint8_t read(int_t id, addr_t x)
- void write(int_t id, addr_t x, cell8_t data)
- addr_t base_address(int_t id)
- addr_t window_size(int_t id)
- int_t device_count()
- void cleanup()
- AbstractBus
- initialize(AbstractHost* host, AbstractConfig* config, AbstractLogger* logger, AbstractDevice** devices)
- tick()
- cell_t read(addr_t x)
- void write(addr_t x, cell_t data)
- cleanup()
- AbstractProcessor
- initialize(AbstractHost* host, AbstractConfig* config, AbstractLogger* logger, AbstractDevice** devices, AbstractBus* bus)
- tick()
- log_state()
- cleanup()
- AbstractMainBoard
- initialize(AbstractHost* host, AbstractConfig* config, AbstractLogger* logger, AbstractDevice** devices, AbstractBus* bus, AbstractProcessor* processor)
- boot()
- cleanup()
- AbstractMachine
- initialize(AbstractHost* host, AbstractConfig* config, AbstractLogger* logger, AbstractDevice** devices, AbstractBus* bus, AbstractProcessor* processor, AbstractMainBoard* board)
- Initializes all dependencies
- boot()
- Calls boot on main board
- cleanup()
- Cleans up all dependencies
- initialize(AbstractHost* host, AbstractConfig* config, AbstractLogger* logger, AbstractDevice** devices, AbstractBus* bus, AbstractProcessor* processor, AbstractMainBoard* board)
Concrete
- Zahlen
- place to put stuff that would normally go in main
ZahlenMachine: AbstractMachineZahlenMainBoard: AbstractMainBoardZahlenBus: AbstractBusZahlenLogger: AbstractLogger- ZahlenConfig : AbstractConfig
ProcessorPlugin: AbstractProcessorDevicePlugin: AbstractDeviceZahlenHost: AbstractHost
Library Interface
- Passed functions
- void log(void* logger, int level, char* msg)
- char* config_get(void* config, char* section, char* id, char* default)
- void config_set(void* config, char* section, char* id, char* value)
- data_t bus_read(void* bus, addr_t addr)
- void bus_write(void* bus, addr_t addr, data_t x)
- Processor Plugin
- proc_initialize(void* logger, log, void* config, config_get, config_set, void* bus, bus_read, bus_write)
- proc_tick()
- proc_log_state()
- proc_cleanup()
- Device Plugin
- dev_initialize(void* logger, log, void* config, config_get, config_set)
- dev_tick()
- data_t dev_read(int_t id, addr_t addr)
- void dev_write(int_t id, addr_t addr, data_t data)
- addr_t dev_base_addr(int_t id)
- addr_t dev_window_size(int_t id)
- int_t dev_device_count()
- dev_cleanup()
Thoughts
Notice that peripherals can also be of type AbstractMemory (read and write to port 0 - size and upper manager translate memory addresses). We need Video / Graphics / Input (maybe all same AbstractMemory plugin). Memory mapped disk i/o. Key buffer can be read from memory. TEXT MODE AND GRAPHICS MODE FOR VIDEO PLUGIN!
Introduce extended opcode in Zahlen for Lua calls.
Make Main Board first. Main board should be given an AbstractProcessor shared object and a AbstractMemory shared objects. Main Board will manage the configuration file.
TODO
- Update HIC1984 with text writing capabilities.
- Two registers: Index and Character.
- Characters will be represented by 8 x 16 glyphs.
- Index represents the position on the screen (32x8 chars = 0 - 255).
- Character reads the character at the index and increments index, or writes to the index and increments index.
- Write ZahlenCore
- 8 bit instructions
- Cart loader
- Initialize 0xC000 to 0x8000 and take call() out of initialize in LuaCore.
Z1
All instructions have been written. Time to test. Instructions needing unit testing:
- int count(int code, Z1State* state, AbstractBus* bus);
- int inc(int code, Z1State* state, AbstractBus* bus);
- int dec(int code, Z1State* state, AbstractBus* bus);
- int neg(int code, Z1State* state, AbstractBus* bus);
- int cast(int code, Z1State* state, AbstractBus* bus);
- int trans(int code, Z1State* state, AbstractBus* bus);
- int sign(int code, Z1State* state, AbstractBus* bus);
- int sin(int code, Z1State* state, AbstractBus* bus);
- int cos(int code, Z1State* state, AbstractBus* bus);
- int add(int code, Z1State* state, AbstractBus* bus);
- int sub(int code, Z1State* state, AbstractBus* bus);
- int mul(int code, Z1State* state, AbstractBus* bus);
- int pmul(int code, Z1State* state, AbstractBus* bus);
- int pdiv(int code, Z1State* state, AbstractBus* bus);
- int mod(int code, Z1State* state, AbstractBus* bus);
- int pow(int code, Z1State* state, AbstractBus* bus);
- int log(int code, Z1State* state, AbstractBus* bus);
- int car(int code, Z1State* state, AbstractBus* bus);
- int cons(int code, Z1State* state, AbstractBus* bus);
- int cond(int code, Z1State* state, AbstractBus* bus); // if
- int st(int code, Z1State* state, AbstractBus* bus);
- int ld(int code, Z1State* state, AbstractBus* bus);
- int swap(int code, Z1State* state, AbstractBus* bus);
- int drop(int code, Z1State* state, AbstractBus* bus);
- int dup(int code, Z1State* state, AbstractBus* bus);
- int rot(int code, Z1State* state, AbstractBus* bus);
- int push_short(int code, Z1State* state, AbstractBus* bus);
- int push_long(int code, Z1State* state, AbstractBus* bus);
- int nop(int code, Z1State* state, AbstractBus* bus);
RAM
0x0000 - 0x7EFF VRAM (256 x 127 x 8) 0x7F00 - 0x7F02 Sound registers 0x8000 - 0x8FFF Cartridge ROM 0x9000 - 0x9000 Cartridge Bank (R/W) 0x9001 - 0xBFFF Unused 0xC000 - 0xC001 Timer Interrupt (address stored here is called 60 times per second) 0xC002 - 0xFFFF Available RAM